]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
SPL: Let spl_parse_image_header() return value
authorMarek Vasut <marex@denx.de>
Thu, 28 Apr 2016 22:44:54 +0000 (00:44 +0200)
committerStefano Babic <sbabic@denx.de>
Tue, 17 May 2016 15:52:20 +0000 (17:52 +0200)
Allow the spl_parse_image_header() to return value. This is convenient
for controlling the SPL boot flow if the loaded image is corrupted.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Fabio Estevam <fabio.estevam@nxp.com>
Cc: Peng Fan <van.freenix@gmail.com>
Cc: Stefano Babic <sbabic@denx.de>
Cc: Tom Rini <trini@konsulko.com>
common/spl/spl.c
common/spl/spl_ext.c
common/spl/spl_fat.c
common/spl/spl_mmc.c
common/spl/spl_nand.c
common/spl/spl_net.c
common/spl/spl_nor.c
common/spl/spl_onenand.c
common/spl/spl_ymodem.c
drivers/mtd/spi/spi_spl_load.c
include/spl.h

index 82e7f58e80f028f7517ec52bd0d73566dae82d28..72596195163da5101d7bbbe43422cee67a61c65d 100644 (file)
@@ -73,7 +73,7 @@ void spl_set_header_raw_uboot(void)
        spl_image.name = "U-Boot";
 }
 
-void spl_parse_image_header(const struct image_header *header)
+int spl_parse_image_header(const struct image_header *header)
 {
        u32 header_size = sizeof(struct image_header);
 
@@ -118,6 +118,7 @@ void spl_parse_image_header(const struct image_header *header)
                spl_set_header_raw_uboot();
 #endif
        }
+       return 0;
 }
 
 __weak void __noreturn jump_to_image_no_args(struct spl_image_info *spl_image)
index b77dbf4d0ca11b8235629e8d6d4b85dfaaaf1a1a..ade5496600930c4f2a84ac76d1a9467576dcb3fa 100644 (file)
@@ -48,7 +48,11 @@ int spl_load_image_ext(struct blk_desc *block_dev,
                goto end;
        }
 
-       spl_parse_image_header(header);
+       err = spl_parse_image_header(header);
+       if (err < 0) {
+               puts("spl: ext4fs_read failed\n");
+               goto end;
+       }
 
        err = ext4fs_read((char *)spl_image.load_addr, filelen, &actlen);
 
index d761b264c139aba5c0229af4d02139e6626660eb..338ea2f092b8dc9b250626efc91d44e68716e199 100644 (file)
@@ -57,7 +57,9 @@ int spl_load_image_fat(struct blk_desc *block_dev,
        if (err <= 0)
                goto end;
 
-       spl_parse_image_header(header);
+       err = spl_parse_image_header(header);
+       if (err <= 0)
+               goto end;
 
        err = file_fat_read(filename, (u8 *)spl_image.load_addr, 0);
 
index 8d588d13a365cae687437a58606069f27509d465..360c754050f2821c479056d8f32830461a957cfe 100644 (file)
@@ -23,8 +23,12 @@ static int mmc_load_legacy(struct mmc *mmc, ulong sector,
 {
        u32 image_size_sectors;
        unsigned long count;
+       int ret;
+
+       ret = spl_parse_image_header(header);
+       if (ret)
+               return ret;
 
-       spl_parse_image_header(header);
        /* convert size to sectors - round up */
        image_size_sectors = (spl_image.size + mmc->read_bl_len - 1) /
                             mmc->read_bl_len;
index 79388ff326a828f89eea814edf66e7b03d7ac5a2..bbd95469870f29ee07edfbf860349d598991ed3f 100644 (file)
@@ -32,7 +32,10 @@ static int spl_nand_load_element(int offset, struct image_header *header)
        if (err)
                return err;
 
-       spl_parse_image_header(header);
+       err = spl_parse_image_header(header);
+       if (err)
+               return err;
+
        return nand_spl_load_image(offset, spl_image.size,
                                   (void *)(unsigned long)spl_image.load_addr);
 }
@@ -77,7 +80,9 @@ int spl_nand_load_image(void)
                /* load linux */
                nand_spl_load_image(CONFIG_SYS_NAND_SPL_KERNEL_OFFS,
                        sizeof(*header), (void *)header);
-               spl_parse_image_header(header);
+               err = spl_parse_image_header(header);
+               if (err)
+                       return err;
                if (header->ih_os == IH_OS_LINUX) {
                        /* happy - was a linux */
                        err = nand_spl_load_image(
index 63b20d820008eee3febf7b6065712c3f43e8eff5..ae71d26f0a61e730d88f6c0e93fc1358a6c5ec5a 100644 (file)
@@ -34,7 +34,5 @@ int spl_net_load_image(const char *device)
                printf("Problem booting with BOOTP\n");
                return rv;
        }
-       spl_parse_image_header((struct image_header *)load_addr);
-
-       return 0;
+       return spl_parse_image_header((struct image_header *)load_addr);
 }
index d0bd0b05333ba3bcb993f9bd9908efb5c9a16dc0..da2422f30515ac07d1af7161ac7ae906783de3f7 100644 (file)
@@ -9,6 +9,7 @@
 
 int spl_nor_load_image(void)
 {
+       int ret;
        /*
         * Loading of the payload to SDRAM is done with skipping of
         * the mkimage header in this SPL NOR driver
@@ -28,7 +29,9 @@ int spl_nor_load_image(void)
                if (image_get_os(header) == IH_OS_LINUX) {
                        /* happy - was a Linux */
 
-                       spl_parse_image_header(header);
+                       ret = spl_parse_image_header(header);
+                       if (ret)
+                               return ret;
 
                        memcpy((void *)spl_image.load_addr,
                               (void *)(CONFIG_SYS_OS_BASE +
@@ -56,8 +59,10 @@ int spl_nor_load_image(void)
         * Load real U-Boot from its location in NOR flash to its
         * defined location in SDRAM
         */
-       spl_parse_image_header(
+       ret = spl_parse_image_header(
                        (const struct image_header *)CONFIG_SYS_UBOOT_BASE);
+       if (ret)
+               return ret;
 
        memcpy((void *)(unsigned long)spl_image.load_addr,
               (void *)(CONFIG_SYS_UBOOT_BASE + sizeof(struct image_header)),
index af7d82eb62f39959c1a2b194ec879e11fb0c9bb5..1a28a84e4407a252706a2a3eb4870dd72b39503f 100644 (file)
@@ -17,6 +17,7 @@
 int spl_onenand_load_image(void)
 {
        struct image_header *header;
+       int ret;
 
        debug("spl: onenand\n");
 
@@ -25,7 +26,9 @@ int spl_onenand_load_image(void)
        /* Load u-boot */
        onenand_spl_load_image(CONFIG_SYS_ONENAND_U_BOOT_OFFS,
                CONFIG_SYS_ONENAND_PAGE_SIZE, (void *)header);
-       spl_parse_image_header(header);
+       ret = spl_parse_image_header(header);
+       if (ret)
+               return ret;
        onenand_spl_load_image(CONFIG_SYS_ONENAND_U_BOOT_OFFS,
                spl_image.size, (void *)spl_image.load_addr);
 
index 380d8ddf52831a0b175a10838fcc2274d6190e48..4f26ea5d21d94dc9a24858fd66780325ebb534b3 100644 (file)
@@ -40,8 +40,11 @@ int spl_ymodem_load_image(void)
        if (!ret) {
                while ((res =
                        xyzModem_stream_read(buf, BUF_SIZE, &err)) > 0) {
-                       if (addr == 0)
-                               spl_parse_image_header((struct image_header *)buf);
+                       if (addr == 0) {
+                               ret = spl_parse_image_header((struct image_header *)buf);
+                               if (ret)
+                                       return ret;
+                       }
                        store_addr = addr + spl_image.load_addr;
                        size += res;
                        addr += res;
index ca56fe9015834ed71e7e92d6725c5325505105ad..46c98a9ceead26be3fca6eb8195f2a448fa1fb58 100644 (file)
@@ -23,6 +23,8 @@
 static int spi_load_image_os(struct spi_flash *flash,
                             struct image_header *header)
 {
+       int err;
+
        /* Read for a header, parse or error out. */
        spi_flash_read(flash, CONFIG_SYS_SPI_KERNEL_OFFS, 0x40,
                       (void *)header);
@@ -30,7 +32,9 @@ static int spi_load_image_os(struct spi_flash *flash,
        if (image_get_magic(header) != IH_MAGIC)
                return -1;
 
-       spl_parse_image_header(header);
+       err = spl_parse_image_header(header);
+       if (err)
+               return err;
 
        spi_flash_read(flash, CONFIG_SYS_SPI_KERNEL_OFFS,
                       spl_image.size, (void *)spl_image.load_addr);
@@ -81,7 +85,9 @@ int spl_spi_load_image(void)
                if (err)
                        return err;
 
-               spl_parse_image_header(header);
+               err = spl_parse_image_header(header);
+               if (err)
+                       return err;
                err = spi_flash_read(flash, CONFIG_SYS_SPI_U_BOOT_OFFS,
                               spl_image.size, (void *)spl_image.load_addr);
        }
index de4f70a377313bec73e9cee638d67a1ce09b61e4..7edfab46dcd1ea44b039fb2172fe9c17ea173d18 100644 (file)
@@ -56,7 +56,7 @@ void preloader_console_init(void);
 u32 spl_boot_device(void);
 u32 spl_boot_mode(void);
 void spl_set_header_raw_uboot(void);
-void spl_parse_image_header(const struct image_header *header);
+int spl_parse_image_header(const struct image_header *header);
 void spl_board_prepare_for_linux(void);
 void __noreturn jump_to_image_linux(void *arg);
 int spl_start_uboot(void);