* [PATCH 1/1] arm: fix zImage support when a oftree is concatenated
@ 2012-04-07 17:15 Jean-Christophe PLAGNIOL-VILLARD
2012-04-10 7:53 ` Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-07 17:15 UTC (permalink / raw)
To: barebox
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 1/1] arm: fix zImage support when a oftree is concatenated
2012-04-07 17:15 [PATCH 1/1] arm: fix zImage support when a oftree is concatenated Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-10 7:53 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2012-04-10 7:53 UTC (permalink / raw)
To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox
On Sat, Apr 07, 2012 at 07:15:54PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> 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.
This patch has two problems. I intentionally did not depend on the size
returned by stat:
- Some tftp servers do not support returning the size
- When the zImage is on a flash partition always the whole partition
will be read even if the zImage is much smaller.
I suggest going another way here. Read the zImage as we do now and try
to read further. If it succeeds and the result is a devicetree then read
it. The devicetree also contains a totalsize field (see include/fdt.h)
Sascha
>
> 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
>
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-04-10 7:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-07 17:15 [PATCH 1/1] arm: fix zImage support when a oftree is concatenated Jean-Christophe PLAGNIOL-VILLARD
2012-04-10 7:53 ` Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox