]> git.sur5r.net Git - u-boot/commitdiff
bootm: make use of legacy image format configurable
authorHeiko Schocher <hs@denx.de>
Wed, 28 May 2014 09:33:33 +0000 (11:33 +0200)
committerTom Rini <trini@ti.com>
Thu, 5 Jun 2014 18:44:56 +0000 (14:44 -0400)
make the use of legacy image format configurable through
the config define CONFIG_IMAGE_FORMAT_LEGACY.

When relying on signed FIT images with required signature check
the legacy image format should be disabled. Therefore introduce
this new define and enable legacy image format if CONFIG_FIT_SIGNATURE
is not set. If CONFIG_FIT_SIGNATURE is set disable per default
the legacy image format.

Signed-off-by: Heiko Schocher <hs@denx.de>
Cc: Simon Glass <sjg@chromium.org>
Cc: Lars Steubesand <lars.steubesand@philips.com>
Cc: Mike Pearce <mike@kaew.be>
Cc: Wolfgang Denk <wd@denx.de>
Cc: Tom Rini <trini@ti.com>
Cc: Michal Simek <monstr@monstr.eu>
Acked-by: Simon Glass <sjg@chromium.org>
14 files changed:
README
common/cmd_bootm.c
common/cmd_disk.c
common/cmd_fdc.c
common/cmd_fpga.c
common/cmd_nand.c
common/cmd_source.c
common/cmd_ximg.c
common/image-fdt.c
common/image.c
doc/uImage.FIT/signature.txt
include/config_fallbacks.h
include/configs/zynq-common.h
include/image.h

diff --git a/README b/README
index 256d6ecc65a09c008bdd8a431fbec1aea37e7ac5..a248ab5d39fc85438ba4adc6ffd0141a5dffd99c 100644 (file)
--- a/README
+++ b/README
@@ -3200,6 +3200,19 @@ FIT uImage format:
  -150  common/cmd_nand.c       Incorrect FIT image format
   151  common/cmd_nand.c       FIT image format OK
 
+- legacy image format:
+               CONFIG_IMAGE_FORMAT_LEGACY
+               enables the legacy image format support in U-Boot.
+
+               Default:
+               enabled if CONFIG_FIT_SIGNATURE is not defined.
+
+               CONFIG_DISABLE_IMAGE_LEGACY
+               disable the legacy image format
+
+               This define is introduced, as the legacy image format is
+               enabled per default for backward compatibility.
+
 - FIT image support:
                CONFIG_FIT
                Enable support for the FIT uImage format.
@@ -3216,6 +3229,11 @@ FIT uImage format:
                using a hash signed and verified using RSA. See
                doc/uImage.FIT/signature.txt for more details.
 
+               WARNING: When relying on signed FIT images with required
+               signature check the legacy image format is default
+               disabled. If a board need legacy image format support
+               enable this through CONFIG_IMAGE_FORMAT_LEGACY
+
 - Standalone program support:
                CONFIG_STANDALONE_LOAD_ADDR
 
index 449bb363f554a622d11834dbc149b2951185c6c1..9b11c0ea18e64b6f09baceb9c1bd778d43afb832 100644 (file)
@@ -230,6 +230,7 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,
 
        /* get image parameters */
        switch (genimg_get_format(os_hdr)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        case IMAGE_FORMAT_LEGACY:
                images.os.type = image_get_type(os_hdr);
                images.os.comp = image_get_comp(os_hdr);
@@ -238,6 +239,7 @@ static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,
                images.os.end = image_get_image_end(os_hdr);
                images.os.load = image_get_load(os_hdr);
                break;
+#endif
 #if defined(CONFIG_FIT)
        case IMAGE_FORMAT_FIT:
                if (fit_image_get_type(images.fit_hdr_os,
@@ -847,6 +849,7 @@ int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
        return 0;
 }
 
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
 /**
  * image_get_kernel - verify legacy format kernel image
  * @img_addr: in RAM address of the legacy format image to be verified
@@ -897,6 +900,7 @@ static image_header_t *image_get_kernel(ulong img_addr, int verify)
        }
        return hdr;
 }
+#endif
 
 /**
  * boot_get_kernel - find kernel image
@@ -914,7 +918,9 @@ static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
                char * const argv[], bootm_headers_t *images, ulong *os_data,
                ulong *os_len)
 {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        image_header_t  *hdr;
+#endif
        ulong           img_addr;
        const void *buf;
 #if defined(CONFIG_FIT)
@@ -952,6 +958,7 @@ static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
        *os_data = *os_len = 0;
        buf = map_sysmem(img_addr, 0);
        switch (genimg_get_format(buf)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        case IMAGE_FORMAT_LEGACY:
                printf("## Booting kernel from Legacy Image at %08lx ...\n",
                                img_addr);
@@ -994,6 +1001,7 @@ static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
                images->legacy_hdr_valid = 1;
                bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE);
                break;
+#endif
 #if defined(CONFIG_FIT)
        case IMAGE_FORMAT_FIT:
                os_noffset = fit_image_load(images, FIT_KERNEL_PROP,
@@ -1131,6 +1139,7 @@ static int image_info(ulong addr)
        printf("\n## Checking Image at %08lx ...\n", addr);
 
        switch (genimg_get_format(hdr)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        case IMAGE_FORMAT_LEGACY:
                puts("   Legacy image found\n");
                if (!image_check_magic(hdr)) {
@@ -1152,6 +1161,7 @@ static int image_info(ulong addr)
                }
                puts("OK\n");
                return 0;
+#endif
 #if defined(CONFIG_FIT)
        case IMAGE_FORMAT_FIT:
                puts("   FIT image found\n");
@@ -1211,6 +1221,7 @@ static int do_imls_nor(void)
                                goto next_sector;
 
                        switch (genimg_get_format(hdr)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
                        case IMAGE_FORMAT_LEGACY:
                                if (!image_check_hcrc(hdr))
                                        goto next_sector;
@@ -1225,6 +1236,7 @@ static int do_imls_nor(void)
                                        puts("OK\n");
                                }
                                break;
+#endif
 #if defined(CONFIG_FIT)
                        case IMAGE_FORMAT_FIT:
                                if (!fit_check_format(hdr))
@@ -1359,12 +1371,14 @@ static int do_imls_nand(void)
                        }
 
                        switch (genimg_get_format(buffer)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
                        case IMAGE_FORMAT_LEGACY:
                                header = (const image_header_t *)buffer;
 
                                len = image_get_image_size(header);
                                nand_imls_legacyimage(nand, nand_dev, off, len);
                                break;
+#endif
 #if defined(CONFIG_FIT)
                        case IMAGE_FORMAT_FIT:
                                len = fit_get_size(buffer);
index 3e457f672e12b63f3e18a7080269ca5a13978946..8a1fda9f68a412a0afa232df5a6e3c0ed7d69890 100644 (file)
@@ -17,7 +17,9 @@ int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
        ulong addr = CONFIG_SYS_LOAD_ADDR;
        ulong cnt;
        disk_partition_t info;
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        image_header_t *hdr;
+#endif
        block_dev_desc_t *dev_desc;
 
 #if defined(CONFIG_FIT)
@@ -62,6 +64,7 @@ int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
        bootstage_mark(BOOTSTAGE_ID_IDE_PART_READ);
 
        switch (genimg_get_format((void *) addr)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        case IMAGE_FORMAT_LEGACY:
                hdr = (image_header_t *) addr;
 
@@ -78,6 +81,7 @@ int common_diskboot(cmd_tbl_t *cmdtp, const char *intf, int argc,
 
                cnt = image_get_image_size(hdr);
                break;
+#endif
 #if defined(CONFIG_FIT)
        case IMAGE_FORMAT_FIT:
                fit_hdr = (const void *) addr;
index 1cfb656bc07216304014852de1f2d980db03753f..5766b5650b6a64d9dc2f81ceaa99bc48fba1cb71 100644 (file)
@@ -635,7 +635,9 @@ int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        FD_GEO_STRUCT *pFG = (FD_GEO_STRUCT *)floppy_type;
        FDC_COMMAND_STRUCT *pCMD = &cmd;
        unsigned long addr,imsize;
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        image_header_t *hdr;  /* used for fdc boot */
+#endif
        unsigned char boot_drive;
        int i,nrofblk;
 #if defined(CONFIG_FIT)
@@ -689,12 +691,14 @@ int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
        }
 
        switch (genimg_get_format ((void *)addr)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        case IMAGE_FORMAT_LEGACY:
                hdr = (image_header_t *)addr;
                image_print_contents (hdr);
 
                imsize = image_get_image_size (hdr);
                break;
+#endif
 #if defined(CONFIG_FIT)
        case IMAGE_FORMAT_FIT:
                fit_hdr = (const void *)addr;
index bda5c8f798085093a603ee239c2d6ecc54641a58..8c5bf440fbb0903e9798242dcc131e630ba51e7f 100644 (file)
@@ -201,6 +201,7 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 #if defined(CONFIG_CMD_FPGA_LOADMK)
        case FPGA_LOADMK:
                switch (genimg_get_format(fpga_data)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
                case IMAGE_FORMAT_LEGACY:
                        {
                                image_header_t *hdr =
@@ -229,6 +230,7 @@ int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
                                               BIT_FULL);
                        }
                        break;
+#endif
 #if defined(CONFIG_FIT)
                case IMAGE_FORMAT_FIT:
                        {
index a84f7dc2d1fd301adff83aae7d8a41ad1b8acdf7..f9ced9d74cb0a5ff207c25d470eb6a45655688b2 100644 (file)
@@ -898,7 +898,9 @@ static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand,
        int r;
        char *s;
        size_t cnt;
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        image_header_t *hdr;
+#endif
 #if defined(CONFIG_FIT)
        const void *fit_hdr = NULL;
 #endif
@@ -924,6 +926,7 @@ static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand,
        bootstage_mark(BOOTSTAGE_ID_NAND_HDR_READ);
 
        switch (genimg_get_format ((void *)addr)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        case IMAGE_FORMAT_LEGACY:
                hdr = (image_header_t *)addr;
 
@@ -932,6 +935,7 @@ static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand,
 
                cnt = image_get_image_size (hdr);
                break;
+#endif
 #if defined(CONFIG_FIT)
        case IMAGE_FORMAT_FIT:
                fit_hdr = (const void *)addr;
index 54ffd16470e8c9d0c43ba1c209fee241163bdcd1..f3e9e605e17b6c65b756f163a692334c983eadb1 100644 (file)
@@ -29,7 +29,9 @@ int
 source (ulong addr, const char *fit_uname)
 {
        ulong           len;
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        const image_header_t *hdr;
+#endif
        ulong           *data;
        int             verify;
        void *buf;
@@ -44,6 +46,7 @@ source (ulong addr, const char *fit_uname)
 
        buf = map_sysmem(addr, 0);
        switch (genimg_get_format(buf)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        case IMAGE_FORMAT_LEGACY:
                hdr = buf;
 
@@ -84,6 +87,7 @@ source (ulong addr, const char *fit_uname)
                 */
                while (*data++);
                break;
+#endif
 #if defined(CONFIG_FIT)
        case IMAGE_FORMAT_FIT:
                if (fit_uname == NULL) {
index 65a8319662f13a18450f9c03a77b885590ee45ff..ae2714d3728021bdc0d262f2bbe3b4cb54fcfe52 100644 (file)
@@ -32,10 +32,13 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 {
        ulong           addr = load_addr;
        ulong           dest = 0;
-       ulong           data, len, count;
+       ulong           data, len;
        int             verify;
        int             part = 0;
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
+       ulong           count;
        image_header_t  *hdr = NULL;
+#endif
 #if defined(CONFIG_FIT)
        const char      *uname = NULL;
        const void*     fit_hdr;
@@ -64,6 +67,7 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
        }
 
        switch (genimg_get_format((void *)addr)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        case IMAGE_FORMAT_LEGACY:
 
                printf("## Copying part %d from legacy image "
@@ -114,6 +118,7 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 
                image_multi_getimg(hdr, part, &data, &len);
                break;
+#endif
 #if defined(CONFIG_FIT)
        case IMAGE_FORMAT_FIT:
                if (uname == NULL) {
@@ -211,7 +216,7 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
                        }
                        break;
 #endif
-#if defined(CONFIG_BZIP2)
+#if defined(CONFIG_BZIP2) && defined(CONFIG_IMAGE_FORMAT_LEGACY)
                case IH_COMP_BZIP2:
                        {
                                int i;
index 5d64009df7d5bf49f70d990b7e3390313aac0acb..ac4563f4a70f70d2e801edafe9dafb4b478517db 100644 (file)
@@ -29,6 +29,7 @@ static void fdt_error(const char *msg)
        puts(" - must RESET the board to recover.\n");
 }
 
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
 static const image_header_t *image_get_fdt(ulong fdt_addr)
 {
        const image_header_t *fdt_hdr = map_sysmem(fdt_addr, 0);
@@ -61,6 +62,7 @@ static const image_header_t *image_get_fdt(ulong fdt_addr)
        }
        return fdt_hdr;
 }
+#endif
 
 /**
  * boot_fdt_add_mem_rsv_regions - Mark the memreserve sections as unusable
@@ -220,11 +222,13 @@ error:
 int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
                bootm_headers_t *images, char **of_flat_tree, ulong *of_size)
 {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        const image_header_t *fdt_hdr;
+       ulong           load, load_end;
+       ulong           image_start, image_data, image_end;
+#endif
        ulong           fdt_addr;
        char            *fdt_blob = NULL;
-       ulong           image_start, image_data, image_end;
-       ulong           load, load_end;
        void            *buf;
 #if defined(CONFIG_FIT)
        const char      *fit_uname_config = images->fit_uname_cfg;
@@ -298,6 +302,7 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
                 */
                buf = map_sysmem(fdt_addr, 0);
                switch (genimg_get_format(buf)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
                case IMAGE_FORMAT_LEGACY:
                        /* verify fdt_addr points to a valid image header */
                        printf("## Flattened Device Tree from Legacy Image at %08lx\n",
@@ -337,6 +342,7 @@ int boot_get_fdt(int flag, int argc, char * const argv[], uint8_t arch,
 
                        fdt_addr = load;
                        break;
+#endif
                case IMAGE_FORMAT_FIT:
                        /*
                         * This case will catch both: new uImage format
index 26eb89a2b29b56875736f78acdaccae4c3ebf883..f33b17522a89e2cc47628685c5cb401e3f0f5cc1 100644 (file)
@@ -44,8 +44,10 @@ extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 
 DECLARE_GLOBAL_DATA_PTR;
 
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
 static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch,
                                                int verify);
+#endif
 #else
 #include "mkimage.h"
 #include <u-boot/md5.h>
@@ -330,6 +332,7 @@ void image_print_contents(const void *ptr)
 
 
 #ifndef USE_HOSTCC
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
 /**
  * image_get_ramdisk - get and verify ramdisk image
  * @rd_addr: ramdisk image start address
@@ -391,6 +394,7 @@ static const image_header_t *image_get_ramdisk(ulong rd_addr, uint8_t arch,
 
        return rd_hdr;
 }
+#endif
 #endif /* !USE_HOSTCC */
 
 /*****************************************************************************/
@@ -654,22 +658,23 @@ int genimg_get_comp_id(const char *name)
  */
 int genimg_get_format(const void *img_addr)
 {
-       ulong format = IMAGE_FORMAT_INVALID;
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        const image_header_t *hdr;
 
        hdr = (const image_header_t *)img_addr;
        if (image_check_magic(hdr))
-               format = IMAGE_FORMAT_LEGACY;
+               return IMAGE_FORMAT_LEGACY;
+#endif
 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
-       else if (fdt_check_header(img_addr) == 0)
-               format = IMAGE_FORMAT_FIT;
+       if (fdt_check_header(img_addr) == 0)
+               return IMAGE_FORMAT_FIT;
 #endif
 #ifdef CONFIG_ANDROID_BOOT_IMAGE
-       else if (android_image_check_header(img_addr) == 0)
-               format = IMAGE_FORMAT_ANDROID;
+       if (android_image_check_header(img_addr) == 0)
+               return IMAGE_FORMAT_ANDROID;
 #endif
 
-       return format;
+       return IMAGE_FORMAT_INVALID;
 }
 
 /**
@@ -711,12 +716,14 @@ ulong genimg_get_image(ulong img_addr)
 
                /* get data size */
                switch (genimg_get_format(buf)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
                case IMAGE_FORMAT_LEGACY:
                        d_size = image_get_data_size(buf);
                        debug("   Legacy format image found at 0x%08lx, "
                                        "size 0x%08lx\n",
                                        ram_addr, d_size);
                        break;
+#endif
 #if defined(CONFIG_FIT)
                case IMAGE_FORMAT_FIT:
                        d_size = fit_get_size(buf) - h_size;
@@ -792,7 +799,9 @@ int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
 {
        ulong rd_addr, rd_load;
        ulong rd_data, rd_len;
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
        const image_header_t *rd_hdr;
+#endif
        void *buf;
 #ifdef CONFIG_SUPPORT_RAW_INITRD
        char *end;
@@ -875,6 +884,7 @@ int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
                 */
                buf = map_sysmem(rd_addr, 0);
                switch (genimg_get_format(buf)) {
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
                case IMAGE_FORMAT_LEGACY:
                        printf("## Loading init Ramdisk from Legacy "
                                        "Image at %08lx ...\n", rd_addr);
@@ -890,6 +900,7 @@ int boot_get_ramdisk(int argc, char * const argv[], bootm_headers_t *images,
                        rd_len = image_get_data_size(rd_hdr);
                        rd_load = image_get_load(rd_hdr);
                        break;
+#endif
 #if defined(CONFIG_FIT)
                case IMAGE_FORMAT_FIT:
                        rd_noffset = fit_image_load(images, FIT_RAMDISK_PROP,
index 95020377055d259a2b9e285b178371fccefc3ea3..672dc3536f53af5bb3bcc9e4efd383c36b081c00 100644 (file)
@@ -328,6 +328,9 @@ be enabled:
 CONFIG_FIT_SIGNATURE - enable signing and verfication in FITs
 CONFIG_RSA - enable RSA algorithm for signing
 
+WARNING: When relying on signed FIT images with required signature check
+the legacy image format is default disabled by not defining
+CONFIG_IMAGE_FORMAT_LEGACY
 
 Testing
 -------
index b304a4103def4c334347fb9f66542411422b13cb..76818f673f2810c69520067a7a10e2b34ed4515a 100644 (file)
 #define CONFIG_SYS_HZ          1000
 #endif
 
+#ifndef CONFIG_FIT_SIGNATURE
+#define CONFIG_IMAGE_FORMAT_LEGACY
+#endif
+
+#ifdef CONFIG_DISABLE_IMAGE_LEGACY
+#undef CONFIG_IMAGE_FORMAT_LEGACY
+#endif
+
 #endif /* __CONFIG_FALLBACKS_H */
index dc5bc22ce9714dc09cc5757e74506cdf0b585bf2..fa252c0b13e53610057d5f62345b2edb13fc3a27 100644 (file)
 /* FIT support */
 #define CONFIG_FIT
 #define CONFIG_FIT_VERBOSE     1 /* enable fit_format_{error,warning}() */
+#define CONFIG_IMAGE_FORMAT_LEGACY /* enable also legacy image format */
 
 /* FDT support */
 #define CONFIG_OF_CONTROL
index 41e56abe15ce22e9244fc5ab348b26025f6463cd..132abdf05595051d5e48ffc982f5429ba377ee1a 100644 (file)
@@ -412,7 +412,9 @@ enum fit_load_op {
 #ifndef USE_HOSTCC
 /* Image format types, returned by _get_format() routine */
 #define IMAGE_FORMAT_INVALID   0x00
+#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
 #define IMAGE_FORMAT_LEGACY    0x01    /* legacy image_header based format */
+#endif
 #define IMAGE_FORMAT_FIT       0x02    /* new, libfdt based format */
 #define IMAGE_FORMAT_ANDROID   0x03    /* Android boot image */