mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 4/4] defaultenv: Align defaultenv array
Date: Thu, 20 Feb 2014 14:49:29 +0100	[thread overview]
Message-ID: <1392904169-786-4-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1392904169-786-1-git-send-email-s.hauer@pengutronix.de>

The default environment buffer is an unsigned char array and thus
may be unaligned. Some decompression algorithms expect the buffer
to be sufficiently aligned for u32 accesses. We make this sure by
copying the default env to a temporary buffer. Instead of doing this
just add a __aligned(4) to the default environment.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/Makefile  |  2 +-
 common/startup.c | 11 +----------
 2 files changed, 2 insertions(+), 11 deletions(-)

diff --git a/common/Makefile b/common/Makefile
index 3cfaae2..a52e96b 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -77,7 +77,7 @@ $(obj)/barebox_default_env: FORCE
 	$(call cmd,envs)
 
 quiet_cmd_env_h = ENVH    $@
-cmd_env_h = cat $< | (cd $(obj) && $(objtree)/scripts/bin2c default_environment) > $@; \
+cmd_env_h = cat $< | (cd $(obj) && $(objtree)/scripts/bin2c "__aligned(4) default_environment") > $@; \
 	echo "static const int default_environment_uncompress_size=`stat -c%s $(obj)/barebox_default_env`;" >> $@
 
 $(obj)/barebox_default_env.h: $(obj)/barebox_default_env$(DEFAULT_COMPRESSION_SUFFIX) FORCE
diff --git a/common/startup.c b/common/startup.c
index 4bc5628..6847b61 100644
--- a/common/startup.c
+++ b/common/startup.c
@@ -53,21 +53,12 @@ static int register_default_env(void)
 	void *defaultenv;
 
 	if (!IS_ENABLED(CONFIG_DEFAULT_COMPRESSION_NONE)) {
-		void *tmp = malloc(default_environment_size);
-
-		if (!tmp)
-			return -ENOMEM;
-
-		memcpy(tmp, default_environment, default_environment_size);
 
 		defaultenv = xzalloc(default_environment_uncompress_size);
 
-		ret = uncompress(tmp, default_environment_size,
+		ret = uncompress(default_environment, default_environment_size,
 				NULL, NULL,
 				defaultenv, NULL, uncompress_err_stdout);
-
-		free(tmp);
-
 		if (ret) {
 			free(defaultenv);
 			return ret;
-- 
1.8.5.3


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

      parent reply	other threads:[~2014-02-20 13:49 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-20 13:49 [PATCH 1/4] filetype: Add detection for barebox environment Sascha Hauer
2014-02-20 13:49 ` [PATCH 2/4] environment: constify arguments Sascha Hauer
2014-02-20 13:49 ` [PATCH 3/4] environment: Add function to load envfs from buffer Sascha Hauer
2014-02-20 15:16   ` Alexander Aring
2014-02-22 18:28     ` Sascha Hauer
2014-02-22 19:40       ` Alexander Aring
2014-02-20 13:49 ` Sascha Hauer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1392904169-786-4-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox