mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 1/1] arm: fix zImage support when a oftree is concatenated
Date: Sat,  7 Apr 2012 19:15:54 +0200	[thread overview]
Message-ID: <1333818954-3029-1-git-send-email-plagnioj@jcrosoft.com> (raw)

When a oftree is concatenated,the zImage is bigger than the size specified in
the zImage header. Detect it copy the full zImage into the memory.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/lib/bootm.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c
index defc89b..26833bd 100644
--- a/arch/arm/lib/bootm.c
+++ b/arch/arm/lib/bootm.c
@@ -125,6 +125,7 @@ struct zimage_header {
 
 static int do_bootz_linux(struct image_data *data)
 {
+	struct stat st;
 	int fd, ret, swap = 0;
 	struct zimage_header __header, *header;
 	void *zimage;
@@ -171,7 +172,10 @@ static int do_bootz_linux(struct image_data *data)
 	if (swap)
 		end = swab32(end);
 
-	data->os_res = request_sdram_region("zimage", load_address, end);
+	if (stat(data->os_file, &st) < 0)
+		st.st_size = end;
+
+	data->os_res = request_sdram_region("zimage", load_address, st.st_size);
 	if (!data->os_res) {
 		ret = -ENOMEM;
 		goto err_out;
@@ -181,15 +185,18 @@ static int do_bootz_linux(struct image_data *data)
 
 	memcpy(zimage, header, sizeof(*header));
 
-	ret = read_full(fd, zimage + sizeof(*header), end - sizeof(*header));
+	ret = read_full(fd, zimage + sizeof(*header), st.st_size - sizeof(*header));
 	if (ret < 0)
 		goto err_out;
-	if (ret < end - sizeof(*header)) {
+	if (ret < st.st_size - sizeof(*header)) {
 		printf("premature end of image\n");
 		ret = -EIO;
 		goto err_out;
 	}
 
+	if (file_detect_type(zimage + end) == filetype_oftree)
+		pr_info("zImage: concatenated oftree detected\n");
+
 	if (swap) {
 		void *ptr;
 		for (ptr = zimage; ptr < zimage + end; ptr += 4)
-- 
1.7.9.1


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

             reply	other threads:[~2012-04-07 17:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-07 17:15 Jean-Christophe PLAGNIOL-VILLARD [this message]
2012-04-10  7:53 ` Sascha Hauer

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=1333818954-3029-1-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --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