diff options
author | Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com> | 2012-04-13 12:12:25 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2012-04-13 14:43:40 +0200 |
commit | a448a796dab88af32517783894577186bed6810e (patch) | |
tree | 5ba928ad7c74e734c8b753766fb087be4e54bed5 /arch | |
parent | afb03d7a554a2911a3742e316f011319fcb416f1 (diff) | |
download | barebox-a448a796dab88af32517783894577186bed6810e.tar.gz barebox-a448a796dab88af32517783894577186bed6810e.tar.xz |
arm: fix zImage support when a oftree is concatenated
When a oftree is concatenated,the zImage is bigger than the size specified in
the zImage header. Detect it and copy it too.
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/arm/lib/bootm.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/arch/arm/lib/bootm.c b/arch/arm/lib/bootm.c index ac83ec7a30..26053dcdde 100644 --- a/arch/arm/lib/bootm.c +++ b/arch/arm/lib/bootm.c @@ -14,6 +14,7 @@ #include <sizes.h> #include <libbb.h> #include <magicvar.h> +#include <libfdt.h> #include <asm/byteorder.h> #include <asm/setup.h> @@ -124,6 +125,70 @@ struct zimage_header { #define ZIMAGE_MAGIC 0x016F2818 +static int do_bootz_linux_fdt(int fd, struct image_data *data) +{ + struct fdt_header __header, *header; + struct resource *r = data->os_res; + struct resource *of_res = data->os_res; + void *oftree; + int ret; + + u32 end; + + header = &__header; + ret = read(fd, header, sizeof(*header)); + if (ret < sizeof(*header)) + return ret; + + if (file_detect_type(header) != filetype_oftree) + return -ENXIO; + + end = be32_to_cpu(header->totalsize); + + if (IS_BUILTIN(CONFIG_OFTREE)) { + oftree = malloc(end + 0x8000); + if (!oftree) { + perror("zImage: oftree malloc"); + return -ENOMEM; + } + } else { + + of_res = request_sdram_region("oftree", r->start + r->size, end); + if (!of_res) { + perror("zImage: oftree request_sdram_region"); + return -ENOMEM; + } + + oftree = (void*)of_res->start; + } + + memcpy(oftree, header, sizeof(*header)); + + end -= sizeof(*header); + + ret = read_full(fd, oftree + sizeof(*header), end); + if (ret < 0) + return ret; + if (ret < end) { + printf("premature end of image\n"); + return -EIO; + } + + if (IS_BUILTIN(CONFIG_OFTREE)) { + fdt_open_into(oftree, oftree, end + 0x8000); + + ret = of_fix_tree(oftree); + if (ret) + return ret; + + data->oftree = oftree; + } + + pr_info("zImage: concatenated oftree detected\n"); + + return 0; +} + static int do_bootz_linux(struct image_data *data) { int fd, ret, swap = 0; @@ -197,6 +262,10 @@ static int do_bootz_linux(struct image_data *data) *(u32 *)ptr = swab32(*(u32 *)ptr); } + ret = do_bootz_linux_fdt(fd, data); + if (ret && ret != -ENXIO) + return ret; + return __do_bootm_linux(data, swap); err_out: |