[U-Boot-Users] [PATCH 0/8] [new uImage] patchset6 - new uImage format low level API

This patch series defines a API for new uImage format that will be used in the following patchsets adding new uImage support to mkimage and U-boot. The API changes are preceded by mkimage/U-boot common code refactoring and mkimage build modifications adding SHA1 and libfdt support.
Included in the patchset are also fixes to the problems found in boot_relocate_fdt(), image_multi_count() and image_multi_getimg().
Changes are based on the current TOT of u-boot-testing#new-image branch. Please review and provide comments.
Bartlomiej Sieka (2): [new uImage] Add libfdt support to mkimage [new uImage] Add sha1.o object to mkimage binary build
David Gibson (1): libfdt: Add and use a node iteration helper function.
Marian Balakowicz (5): [new uImage] New uImage low-level API [new uImage] Fix FDT blob totalsize calculation in boot_relocate_fdt() [new uImage] Fix component handling for legacy multi component images [new uImage] Share common uImage code between mkimage and U-boot [new uImage] Update naming convention for bootm/uImage related code
Cheers, m.

This patch introduces the following prefix convention for the image format handling and bootm related code:
genimg_ - dual format shared code image_ - legacy uImage format specific code fit_ - new uImage format specific code boot_ - booting process related code
Related routines are renamed and a few pieces of code are moved around and re-grouped.
Signed-off-by: Marian Balakowicz m8@semihalf.com ---
board/cray/L1/L1.c | 2 board/esd/common/auto_update.c | 6 - board/mcc200/auto_update.c | 6 - board/mpl/common/common_util.c | 4 board/siemens/common/fpga.c | 4 board/trab/auto_update.c | 8 - common/cmd_autoscript.c | 4 common/cmd_bootm.c | 36 ++- common/cmd_doc.c | 2 common/cmd_fdc.c | 2 common/cmd_fpga.c | 2 common/cmd_ide.c | 2 common/cmd_nand.c | 4 common/cmd_scsi.c | 2 common/cmd_usb.c | 2 common/cmd_ximg.c | 6 - common/image.c | 429 ++++++++++++++++++++-------------------- include/image.h | 72 ++++--- lib_arm/bootm.c | 2 lib_avr32/bootm.c | 2 lib_i386/bootm.c | 2 lib_m68k/bootm.c | 9 - lib_mips/bootm.c | 2 lib_ppc/bootm.c | 24 +- tools/mkimage.c | 4 25 files changed, 326 insertions(+), 312 deletions(-)
diff --git a/board/cray/L1/L1.c b/board/cray/L1/L1.c index c00acc8..77f7f48 100644 --- a/board/cray/L1/L1.c +++ b/board/cray/L1/L1.c @@ -141,7 +141,7 @@ int misc_init_r (void)
hdr = (image_header_t *) (CFG_MONITOR_BASE - image_get_header_size ()); #if defined(CONFIG_FIT) - if (gen_image_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { + if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { puts ("Non legacy image format not supported\n"); return -1; } diff --git a/board/esd/common/auto_update.c b/board/esd/common/auto_update.c index 976707d..1bf81c6 100644 --- a/board/esd/common/auto_update.c +++ b/board/esd/common/auto_update.c @@ -92,7 +92,7 @@ int au_check_cksum_valid(int i, long nbytes)
hdr = (image_header_t *)LOAD_ADDR; #if defined(CONFIG_FIT) - if (gen_image_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { + if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { puts ("Non legacy image format not supported\n"); return -1; } @@ -125,7 +125,7 @@ int au_check_header_valid(int i, long nbytes)
hdr = (image_header_t *)LOAD_ADDR; #if defined(CONFIG_FIT) - if (gen_image_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { + if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { puts ("Non legacy image format not supported\n"); return -1; } @@ -197,7 +197,7 @@ int au_do_update(int i, long sz)
hdr = (image_header_t *)LOAD_ADDR; #if defined(CONFIG_FIT) - if (gen_image_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { + if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { puts ("Non legacy image format not supported\n"); return -1; } diff --git a/board/mcc200/auto_update.c b/board/mcc200/auto_update.c index fcae35a..5580c11 100644 --- a/board/mcc200/auto_update.c +++ b/board/mcc200/auto_update.c @@ -144,7 +144,7 @@ int au_check_cksum_valid(int idx, long nbytes)
hdr = (image_header_t *)LOAD_ADDR; #if defined(CONFIG_FIT) - if (gen_image_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { + if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { puts ("Non legacy image format not supported\n"); return -1; } @@ -169,7 +169,7 @@ int au_check_header_valid(int idx, long nbytes)
hdr = (image_header_t *)LOAD_ADDR; #if defined(CONFIG_FIT) - if (gen_image_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { + if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { puts ("Non legacy image format not supported\n"); return -1; } @@ -247,7 +247,7 @@ int au_do_update(int idx, long sz)
hdr = (image_header_t *)LOAD_ADDR; #if defined(CONFIG_FIT) - if (gen_image_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { + if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { puts ("Non legacy image format not supported\n"); return -1; } diff --git a/board/mpl/common/common_util.c b/board/mpl/common/common_util.c index fffd25c..785d204 100644 --- a/board/mpl/common/common_util.c +++ b/board/mpl/common/common_util.c @@ -74,7 +74,7 @@ mpl_prg(uchar *src, ulong size) info = &flash_info[0];
#if defined(CONFIG_PIP405) || defined(CONFIG_MIP405) || defined(CONFIG_PATI) - if (image_to_cpu (magic[0]) != IH_MAGIC) { + if (uimage_to_cpu (magic[0]) != IH_MAGIC) { puts("Bad Magic number\n"); return -1; } @@ -182,7 +182,7 @@ mpl_prg_image(uchar *ld_addr) int rc;
#if defined(CONFIG_FIT) - if (gen_image_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { + if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { puts ("Non legacy image format not supported\n"); return -1; } diff --git a/board/siemens/common/fpga.c b/board/siemens/common/fpga.c index a9a6dfe..48c1850 100644 --- a/board/siemens/common/fpga.c +++ b/board/siemens/common/fpga.c @@ -138,7 +138,7 @@ static int fpga_load (fpga_t* fpga, ulong addr, int checkall) int verify, i;
#if defined(CONFIG_FIT) - if (gen_image_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { + if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { puts ("Non legacy image format not supported\n"); return -1; } @@ -341,7 +341,7 @@ int fpga_init (void)
hdr = (image_header_t *)addr; #if defined(CONFIG_FIT) - if (gen_image_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { + if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { puts ("Non legacy image format not supported\n"); return -1; } diff --git a/board/trab/auto_update.c b/board/trab/auto_update.c index 8f67535..fa08bff 100644 --- a/board/trab/auto_update.c +++ b/board/trab/auto_update.c @@ -212,7 +212,7 @@ au_check_cksum_valid(int idx, long nbytes)
hdr = (image_header_t *)LOAD_ADDR; #if defined(CONFIG_FIT) - if (gen_image_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { + if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { puts ("Non legacy image format not supported\n"); return -1; } @@ -241,7 +241,7 @@ au_check_header_valid(int idx, long nbytes)
hdr = (image_header_t *)LOAD_ADDR; #if defined(CONFIG_FIT) - if (gen_image_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { + if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { puts ("Non legacy image format not supported\n"); return -1; } @@ -341,7 +341,7 @@ au_do_update(int idx, long sz)
hdr = (image_header_t *)LOAD_ADDR; #if defined(CONFIG_FIT) - if (gen_image_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { + if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { puts ("Non legacy image format not supported\n"); return -1; } @@ -437,7 +437,7 @@ au_update_eeprom(int idx)
hdr = (image_header_t *)LOAD_ADDR; #if defined(CONFIG_FIT) - if (gen_image_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { + if (genimg_get_format ((void *)hdr) != IMAGE_FORMAT_LEGACY) { puts ("Non legacy image format not supported\n"); return -1; } diff --git a/common/cmd_autoscript.c b/common/cmd_autoscript.c index f9ab1d9..60ffc7d 100644 --- a/common/cmd_autoscript.c +++ b/common/cmd_autoscript.c @@ -61,7 +61,7 @@ autoscript (ulong addr)
verify = getenv_verify ();
- switch (gen_image_get_format ((void *)addr)) { + switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr;
@@ -90,7 +90,7 @@ autoscript (ulong addr) /* get length of script */ data = (ulong *)image_get_data (hdr);
- if ((len = image_to_cpu (*data)) == 0) { + if ((len = uimage_to_cpu (*data)) == 0) { puts ("Empty Script\n"); return 1; } diff --git a/common/cmd_bootm.c b/common/cmd_bootm.c index 8595ef6..10403aa 100644 --- a/common/cmd_bootm.c +++ b/common/cmd_bootm.c @@ -66,7 +66,7 @@ static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); static void fixup_silent_linux (void); #endif
-static void *get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[], +static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[], bootm_headers_t *images, ulong *os_data, ulong *os_len); extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
@@ -143,7 +143,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) board_lmb_reserve(&lmb);
/* get kernel image header, start address and length */ - os_hdr = get_kernel (cmdtp, flag, argc, argv, + os_hdr = boot_get_kernel (cmdtp, flag, argc, argv, &images, &os_data, &os_len); if (os_len == 0) return 1; @@ -151,7 +151,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) show_boot_progress (6);
/* get image parameters */ - switch (gen_image_get_format (os_hdr)) { + switch (genimg_get_format (os_hdr)) { case IMAGE_FORMAT_LEGACY: type = image_get_type (os_hdr); comp = image_get_comp (os_hdr); @@ -172,7 +172,7 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
image_start = (ulong)os_hdr; load_end = 0; - type_name = image_get_type_name (type); + type_name = genimg_get_type_name (type);
/* * We have reached the point of no return: we are going to @@ -309,16 +309,16 @@ int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) }
/** - * get_kernel - find kernel image - * @os_data: pointer to a ulong variable, will hold os data start address - * @os_len: pointer to a ulong variable, will hold os data length + * image_get_kernel - verify legacy format kernel image + * @img_addr: in RAM address of the legacy format image to be verified + * @verify: data CRC verification flag * - * get_kernel() tries to find a kernel image, verifies its integrity - * and locates kernel data. + * image_get_kernel() verifies legacy image integrity and returns pointer to + * legacy image header if image verification was completed successfully. * * returns: - * pointer to image header if valid image was found, plus kernel start - * address and length, otherwise NULL + * pointer to a legacy image header if valid image was found + * otherwise return NULL */ static image_header_t *image_get_kernel (ulong img_addr, int verify) { @@ -360,18 +360,18 @@ static image_header_t *image_get_kernel (ulong img_addr, int verify) }
/** - * get_kernel - find kernel image + * boot_get_kernel - find kernel image * @os_data: pointer to a ulong variable, will hold os data start address * @os_len: pointer to a ulong variable, will hold os data length * - * get_kernel() tries to find a kernel image, verifies its integrity + * boot_get_kernel() tries to find a kernel image, verifies its integrity * and locates kernel data. * * returns: * pointer to image header if valid image was found, plus kernel start * address and length, otherwise NULL */ -static void *get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], +static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], bootm_headers_t *images, ulong *os_data, ulong *os_len) { image_header_t *hdr; @@ -406,10 +406,10 @@ static void *get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], printf ("## Booting kernel image at %08lx ...\n", img_addr);
/* copy from dataflash if needed */ - img_addr = gen_get_image (img_addr); + img_addr = genimg_get_image (img_addr);
/* check image type, for FIT images get FIT kernel node */ - switch (gen_image_get_format ((void *)img_addr)) { + switch (genimg_get_format ((void *)img_addr)) { case IMAGE_FORMAT_LEGACY:
debug ("* kernel: legacy format image\n"); @@ -531,7 +531,7 @@ static int image_info (ulong addr)
printf ("\n## Checking Image at %08lx ...\n", addr);
- switch (gen_image_get_format (hdr)) { + switch (genimg_get_format (hdr)) { case IMAGE_FORMAT_LEGACY: puts (" Legacy image found\n"); if (!image_check_magic (hdr)) { @@ -599,7 +599,7 @@ int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) if (!hdr) goto next_sector;
- switch (gen_image_get_format (hdr)) { + switch (genimg_get_format (hdr)) { case IMAGE_FORMAT_LEGACY: if (!image_check_magic (hdr)) goto next_sector; diff --git a/common/cmd_doc.c b/common/cmd_doc.c index 3358b04..293b1aa 100644 --- a/common/cmd_doc.c +++ b/common/cmd_doc.c @@ -261,7 +261,7 @@ int do_docboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } show_boot_progress (38);
- switch (gen_image_get_format ((void *)addr)) { + switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr;
diff --git a/common/cmd_fdc.c b/common/cmd_fdc.c index b6e023a..80301b9 100644 --- a/common/cmd_fdc.c +++ b/common/cmd_fdc.c @@ -836,7 +836,7 @@ int do_fdcboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 1; }
- switch (gen_image_get_format ((void *)addr)) { + switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr; if (!image_check_magic (hdr)) { diff --git a/common/cmd_fpga.c b/common/cmd_fpga.c index 10199f5..0bb82f6 100644 --- a/common/cmd_fpga.c +++ b/common/cmd_fpga.c @@ -216,7 +216,7 @@ int do_fpga (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) break;
case FPGA_LOADMK: - switch (gen_image_get_format (fpga_data)) { + switch (genimg_get_format (fpga_data)) { case IMAGE_FORMAT_LEGACY: { image_header_t *hdr = (image_header_t *)fpga_data; diff --git a/common/cmd_ide.c b/common/cmd_ide.c index bef04db..79b7dfb 100644 --- a/common/cmd_ide.c +++ b/common/cmd_ide.c @@ -446,7 +446,7 @@ int do_diskboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } show_boot_progress (48);
- switch (gen_image_get_format ((void *)addr)) { + switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr;
diff --git a/common/cmd_nand.c b/common/cmd_nand.c index b099afe..86959dc 100644 --- a/common/cmd_nand.c +++ b/common/cmd_nand.c @@ -512,7 +512,7 @@ static int nand_load_image(cmd_tbl_t *cmdtp, nand_info_t *nand, } show_boot_progress (56);
- switch (gen_image_get_format ((void *)addr)) { + switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr;
@@ -994,7 +994,7 @@ int do_nandboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) } show_boot_progress (56);
- switch (gen_image_get_format ((void *)addr)) { + switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr;
diff --git a/common/cmd_scsi.c b/common/cmd_scsi.c index 42b3072..7868805 100644 --- a/common/cmd_scsi.c +++ b/common/cmd_scsi.c @@ -273,7 +273,7 @@ int do_scsiboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 1; }
- switch (gen_image_get_format ((void *)addr)) { + switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr;
diff --git a/common/cmd_usb.c b/common/cmd_usb.c index ad3873c..8ee7d27 100644 --- a/common/cmd_usb.c +++ b/common/cmd_usb.c @@ -386,7 +386,7 @@ int do_usbboot (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) return 1; }
- switch (gen_image_get_format ((void *)addr)) { + switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY: hdr = (image_header_t *)addr;
diff --git a/common/cmd_ximg.c b/common/cmd_ximg.c index 4dadc37..360b05e 100644 --- a/common/cmd_ximg.c +++ b/common/cmd_ximg.c @@ -57,7 +57,7 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) }
- switch (gen_image_get_format ((void *)addr)) { + switch (genimg_get_format ((void *)addr)) { case IMAGE_FORMAT_LEGACY:
printf("## Copying from legacy image at %08lx ...\n", addr); @@ -104,7 +104,7 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) data += 4; if (argc > 2 && part > i) { u_long tail; - len = image_to_cpu (len_ptr[i]); + len = uimage_to_cpu (len_ptr[i]); tail = len % 4; data += len; if (tail) { @@ -116,7 +116,7 @@ do_imgextract(cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) printf("Bad Image Part\n"); return 1; } - len = image_to_cpu (len_ptr[part]); + len = uimage_to_cpu (len_ptr[part]); #if defined(CONFIG_FIT) case IMAGE_FORMAT_FIT: fit_unsupported ("imxtract"); diff --git a/common/image.c b/common/image.c index 9e446fa..99ed3b8 100644 --- a/common/image.c +++ b/common/image.c @@ -68,6 +68,9 @@ static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag,
unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);
+/*****************************************************************************/ +/* Legacy format routines */ +/*****************************************************************************/ int image_check_hcrc (image_header_t *hdr) { ulong hcrc; @@ -120,61 +123,6 @@ int image_check_dcrc_wd (image_header_t *hdr, ulong chunksz) return (dcrc == image_get_dcrc (hdr)); }
-int getenv_verify (void) -{ - char *s = getenv ("verify"); - return (s && (*s == 'n')) ? 0 : 1; -} - -int getenv_autostart (void) -{ - char *s = getenv ("autostart"); - return (s && (*s == 'n')) ? 0 : 1; -} - -ulong getenv_bootm_low(void) -{ - char *s = getenv ("bootm_low"); - if (s) { - ulong tmp = simple_strtoul (s, NULL, 16); - return tmp; - } - -#ifdef CFG_SDRAM_BASE - return CFG_SDRAM_BASE; -#else - return 0; -#endif -} - -ulong getenv_bootm_size(void) -{ - char *s = getenv ("bootm_size"); - if (s) { - ulong tmp = simple_strtoul (s, NULL, 16); - return tmp; - } - - return gd->bd->bi_memsize; -} - -void memmove_wd (void *to, void *from, size_t len, ulong chunksz) -{ -#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) - while (len > 0) { - size_t tail = (len > chunksz) ? chunksz : len; - WATCHDOG_RESET (); - memmove (to, from, tail); - to += tail; - from += tail; - len -= tail; - } -#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ - memmove (to, from, len); -#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ -} -#endif /* USE_HOSTCC */ - /** * image_multi_count - get component (sub-image) count * @hdr: pointer to the header of the multi component image @@ -262,7 +210,185 @@ void image_multi_getimg (image_header_t *hdr, ulong idx, }
#ifndef USE_HOSTCC -const char* image_get_os_name (uint8_t os) +static void image_print_type (image_header_t *hdr) +{ + const char *os, *arch, *type, *comp; + + os = genimg_get_os_name (image_get_os (hdr)); + arch = genimg_get_arch_name (image_get_arch (hdr)); + type = genimg_get_type_name (image_get_type (hdr)); + comp = genimg_get_comp_name (image_get_comp (hdr)); + + printf ("%s %s %s (%s)", arch, os, type, comp); +} + +void image_print_contents (image_header_t *hdr) +{ +#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) + time_t timestamp = (time_t)image_get_time (hdr); + struct rtc_time tm; +#endif + + printf (" Image Name: %.*s\n", IH_NMLEN, image_get_name (hdr)); + +#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) + to_tm (timestamp, &tm); + printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n", + tm.tm_year, tm.tm_mon, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec); +#endif + puts (" Image Type: "); + image_print_type (hdr); + + printf ("\n Data Size: %d Bytes = ", image_get_data_size (hdr)); + print_size (image_get_data_size (hdr), "\n"); + printf (" Load Address: %08x\n" + " Entry Point: %08x\n", + image_get_load (hdr), image_get_ep (hdr)); + + if (image_check_type (hdr, IH_TYPE_MULTI)) { + int i; + ulong data, len; + ulong count = image_multi_count (hdr); + + puts (" Contents:\n"); + for (i = 0; i < count; i++) { + image_multi_getimg (hdr, i, &data, &len); + printf (" Image %d: %8ld Bytes = ", i, len); + print_size (len, "\n"); + } + } +} + +/** + * image_get_ramdisk - get and verify ramdisk image + * @cmdtp: command table pointer + * @flag: command flag + * @argc: command argument count + * @argv: command argument list + * @rd_addr: ramdisk image start address + * @arch: expected ramdisk architecture + * @verify: checksum verification flag + * + * image_get_ramdisk() returns a pointer to the verified ramdisk image + * header. Routine receives image start address and expected architecture + * flag. Verification done covers data and header integrity and os/type/arch + * fields checking. + * + * If dataflash support is enabled routine checks for dataflash addresses + * and handles required dataflash reads. + * + * returns: + * pointer to a ramdisk image header, if image was found and valid + * otherwise, return NULL + */ +static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag, + int argc, char *argv[], + ulong rd_addr, uint8_t arch, int verify) +{ + image_header_t *rd_hdr; + + show_boot_progress (9); + rd_hdr = (image_header_t *)rd_addr; + + if (!image_check_magic (rd_hdr)) { + puts ("Bad Magic Number\n"); + show_boot_progress (-10); + return NULL; + } + + if (!image_check_hcrc (rd_hdr)) { + puts ("Bad Header Checksum\n"); + show_boot_progress (-11); + return NULL; + } + + show_boot_progress (10); + image_print_contents (rd_hdr); + + if (verify) { + puts(" Verifying Checksum ... "); + if (!image_check_dcrc_wd (rd_hdr, CHUNKSZ)) { + puts ("Bad Data CRC\n"); + show_boot_progress (-12); + return NULL; + } + puts("OK\n"); + } + + show_boot_progress (11); + + if (!image_check_os (rd_hdr, IH_OS_LINUX) || + !image_check_arch (rd_hdr, arch) || + !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) { + printf ("No Linux %s Ramdisk Image\n", + genimg_get_arch_name(arch)); + show_boot_progress (-13); + return NULL; + } + + return rd_hdr; +} + +/*****************************************************************************/ +/* Shared dual-format routines */ +/*****************************************************************************/ +int getenv_verify (void) +{ + char *s = getenv ("verify"); + return (s && (*s == 'n')) ? 0 : 1; +} + +int getenv_autostart (void) +{ + char *s = getenv ("autostart"); + return (s && (*s == 'n')) ? 0 : 1; +} + +ulong getenv_bootm_low(void) +{ + char *s = getenv ("bootm_low"); + if (s) { + ulong tmp = simple_strtoul (s, NULL, 16); + return tmp; + } + +#ifdef CFG_SDRAM_BASE + return CFG_SDRAM_BASE; +#else + return 0; +#endif +} + +ulong getenv_bootm_size(void) +{ + char *s = getenv ("bootm_size"); + if (s) { + ulong tmp = simple_strtoul (s, NULL, 16); + return tmp; + } + + return gd->bd->bi_memsize; +} + +void memmove_wd (void *to, void *from, size_t len, ulong chunksz) +{ +#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) + while (len > 0) { + size_t tail = (len > chunksz) ? chunksz : len; + WATCHDOG_RESET (); + memmove (to, from, tail); + to += tail; + from += tail; + len -= tail; + } +#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */ + memmove (to, from, len); +#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ +} +#endif /* USE_HOSTCC */ + +const char* genimg_get_os_name (uint8_t os) { const char *name;
@@ -286,7 +412,7 @@ const char* image_get_os_name (uint8_t os) return name; }
-const char* image_get_arch_name (uint8_t arch) +const char* genimg_get_arch_name (uint8_t arch) { const char *name;
@@ -315,7 +441,7 @@ const char* image_get_arch_name (uint8_t arch) return name; }
-const char* image_get_type_name (uint8_t type) +const char* genimg_get_type_name (uint8_t type) { const char *name;
@@ -334,7 +460,7 @@ const char* image_get_type_name (uint8_t type) return name; }
-const char* image_get_comp_name (uint8_t comp) +const char* genimg_get_comp_name (uint8_t comp) { const char *name;
@@ -348,71 +474,21 @@ const char* image_get_comp_name (uint8_t comp) return name; }
-static void image_print_type (image_header_t *hdr) -{ - const char *os, *arch, *type, *comp; - - os = image_get_os_name (image_get_os (hdr)); - arch = image_get_arch_name (image_get_arch (hdr)); - type = image_get_type_name (image_get_type (hdr)); - comp = image_get_comp_name (image_get_comp (hdr)); - - printf ("%s %s %s (%s)", arch, os, type, comp); -} - -void image_print_contents (image_header_t *hdr) -{ -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) - time_t timestamp = (time_t)image_get_time (hdr); - struct rtc_time tm; -#endif - - printf (" Image Name: %.*s\n", IH_NMLEN, image_get_name (hdr)); - -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) - to_tm (timestamp, &tm); - printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n", - tm.tm_year, tm.tm_mon, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec); -#endif - puts (" Image Type: "); - image_print_type (hdr); - - printf ("\n Data Size: %d Bytes = ", image_get_data_size (hdr)); - print_size (image_get_data_size (hdr), "\n"); - printf (" Load Address: %08x\n" - " Entry Point: %08x\n", - image_get_load (hdr), image_get_ep (hdr)); - - if (image_check_type (hdr, IH_TYPE_MULTI)) { - int i; - ulong data, len; - ulong count = image_multi_count (hdr); - - puts (" Contents:\n"); - for (i = 0; i < count; i++) { - image_multi_getimg (hdr, i, &data, &len); - printf (" Image %d: %8ld Bytes = ", i, len); - print_size (len, "\n"); - } - } -} - /** - * gen_image_get_format - get image format type + * genimg_get_format - get image format type * @img_addr: image start address * - * gen_image_get_format() checks whether provided address points to a valid + * genimg_get_format() checks whether provided address points to a valid * legacy or FIT image. * * New uImage format and FDT blob are based on a libfdt. FDT blob * may be passed directly or embedded in a FIT image. In both situations - * gen_image_get_format() must be able to dectect libfdt header. + * genimg_get_format() must be able to dectect libfdt header. * * returns: * image format type or IMAGE_FORMAT_INVALID if no image is present */ -int gen_image_get_format (void *img_addr) +int genimg_get_format (void *img_addr) { ulong format = IMAGE_FORMAT_INVALID; image_header_t *hdr; @@ -435,16 +511,16 @@ int gen_image_get_format (void *img_addr) }
/** - * gen_get_image - get image from special storage (if necessary) + * genimg_get_image - get image from special storage (if necessary) * @img_addr: image start address * - * gen_get_image() checks if provided image start adddress is located + * genimg_get_image() checks if provided image start adddress is located * in a dataflash storage. If so, image is moved to a system RAM memory. * * returns: * image start address after possible relocation from special storage */ -ulong gen_get_image (ulong img_addr) +ulong genimg_get_image (ulong img_addr) { ulong ram_addr = img_addr;
@@ -469,7 +545,7 @@ ulong gen_get_image (ulong img_addr) read_dataflash (img_addr, h_size, (char *)ram_addr);
/* get data size */ - switch (gen_image_get_format ((void *)ram_addr)) { + switch (genimg_get_format ((void *)ram_addr)) { case IMAGE_FORMAT_LEGACY: d_size = image_get_data_size ((image_header_t *)ram_addr); debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n", @@ -502,77 +578,7 @@ ulong gen_get_image (ulong img_addr) }
/** - * image_get_ramdisk - get and verify ramdisk image - * @cmdtp: command table pointer - * @flag: command flag - * @argc: command argument count - * @argv: command argument list - * @rd_addr: ramdisk image start address - * @arch: expected ramdisk architecture - * @verify: checksum verification flag - * - * image_get_ramdisk() returns a pointer to the verified ramdisk image - * header. Routine receives image start address and expected architecture - * flag. Verification done covers data and header integrity and os/type/arch - * fields checking. - * - * If dataflash support is enabled routine checks for dataflash addresses - * and handles required dataflash reads. - * - * returns: - * pointer to a ramdisk image header, if image was found and valid - * otherwise, return NULL - */ -static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag, - int argc, char *argv[], - ulong rd_addr, uint8_t arch, int verify) -{ - image_header_t *rd_hdr; - - show_boot_progress (9); - rd_hdr = (image_header_t *)rd_addr; - - if (!image_check_magic (rd_hdr)) { - puts ("Bad Magic Number\n"); - show_boot_progress (-10); - return NULL; - } - - if (!image_check_hcrc (rd_hdr)) { - puts ("Bad Header Checksum\n"); - show_boot_progress (-11); - return NULL; - } - - show_boot_progress (10); - image_print_contents (rd_hdr); - - if (verify) { - puts(" Verifying Checksum ... "); - if (!image_check_dcrc_wd (rd_hdr, CHUNKSZ)) { - puts ("Bad Data CRC\n"); - show_boot_progress (-12); - return NULL; - } - puts("OK\n"); - } - - show_boot_progress (11); - - if (!image_check_os (rd_hdr, IH_OS_LINUX) || - !image_check_arch (rd_hdr, arch) || - !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) { - printf ("No Linux %s Ramdisk Image\n", - image_get_arch_name(arch)); - show_boot_progress (-13); - return NULL; - } - - return rd_hdr; -} - -/** - * get_ramdisk - main ramdisk handling routine + * boot_get_ramdisk - main ramdisk handling routine * @cmdtp: command table pointer * @flag: command flag * @argc: command argument count @@ -582,7 +588,7 @@ static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag, * @rd_start: pointer to a ulong variable, will hold ramdisk start address * @rd_end: pointer to a ulong variable, will hold ramdisk end * - * get_ramdisk() is responsible for finding a valid ramdisk image. + * boot_get_ramdisk() is responsible for finding a valid ramdisk image. * Curently supported are the following ramdisk sources: * - multicomponent kernel/ramdisk image, * - commandline provided address of decicated ramdisk image. @@ -593,7 +599,7 @@ static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag, * rd_start and rd_end are set to 0 if no ramdisk exists * return 1 if ramdisk image is found but corrupted */ -int get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], +int boot_get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], bootm_headers_t *images, uint8_t arch, ulong *rd_start, ulong *rd_end) { @@ -645,14 +651,14 @@ int get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], /* copy from dataflash if needed */ printf ("## Loading init Ramdisk Image at %08lx ...\n", rd_addr); - rd_addr = gen_get_image (rd_addr); + rd_addr = genimg_get_image (rd_addr);
/* * Check if there is an initrd image at the * address provided in the second bootm argument * check image type, for FIT images get FIT node. */ - switch (gen_image_get_format ((void *)rd_addr)) { + switch (genimg_get_format ((void *)rd_addr)) { case IMAGE_FORMAT_LEGACY:
debug ("* ramdisk: legacy format image\n"); @@ -729,7 +735,7 @@ int get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
#if defined(CONFIG_PPC) || defined(CONFIG_M68K) /** - * ramdisk_high - relocate init ramdisk + * boot_ramdisk_high - relocate init ramdisk * @lmb: pointer to lmb handle, will be used for memory mgmt * @rd_data: ramdisk data start address * @rd_len: ramdisk data length @@ -738,18 +744,18 @@ int get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], * @initrd_end: pointer to a ulong variable, will hold final init ramdisk * end address (after possible relocation) * - * ramdisk_high() takes a relocation hint from "initrd_high" environement + * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement * variable and if requested ramdisk data is moved to a specified location. * + * Initrd_start and initrd_end are set to final (after relocation) ramdisk + * start/end addresses if ramdisk image start and len were provided, + * otherwise set initrd_start and initrd_end set to zeros. + * * returns: - * - initrd_start and initrd_end are set to final (after relocation) ramdisk - * start/end addresses if ramdisk image start and len were provided - * otherwise set initrd_start and initrd_end set to zeros - * - returns: - * 0 - success - * -1 - failure + * 0 - success + * -1 - failure */ -int ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len, +int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len, ulong *initrd_start, ulong *initrd_end) { char *s; @@ -779,12 +785,12 @@ int ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len, lmb_reserve(lmb, rd_data, rd_len); } else { if (initrd_high) - *initrd_start = lmb_alloc_base(lmb, rd_len, 0x1000, initrd_high); + *initrd_start = lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high); else - *initrd_start = lmb_alloc(lmb, rd_len, 0x1000); + *initrd_start = lmb_alloc (lmb, rd_len, 0x1000);
if (*initrd_start == 0) { - puts("ramdisk - allocation error\n"); + puts ("ramdisk - allocation error\n"); goto error; } show_boot_progress (12); @@ -793,7 +799,7 @@ int ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len, printf (" Loading Ramdisk to %08lx, end %08lx ... ", *initrd_start, *initrd_end);
- memmove_wd((void *)*initrd_start, + memmove_wd ((void *)*initrd_start, (void *)rd_data, rd_len, CHUNKSZ);
puts ("OK\n"); @@ -804,6 +810,7 @@ int ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len, } debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n", *initrd_start, *initrd_end); + return 0;
error: @@ -811,14 +818,14 @@ error: }
/** - * get_boot_cmdline - allocate and initialize kernel cmdline + * boot_get_cmdline - allocate and initialize kernel cmdline * @lmb: pointer to lmb handle, will be used for memory mgmt * @cmd_start: pointer to a ulong variable, will hold cmdline start * @cmd_end: pointer to a ulong variable, will hold cmdline end * @bootmap_base: ulong variable, holds offset in physical memory to * base of bootmap * - * get_boot_cmdline() allocates space for kernel command line below + * boot_get_cmdline() allocates space for kernel command line below * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt * variable is present its contents is copied to allocated kernel * command line. @@ -827,7 +834,7 @@ error: * 0 - success * -1 - failure */ -int get_boot_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end, +int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end, ulong bootmap_base) { char *cmdline; @@ -853,13 +860,13 @@ int get_boot_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end, }
/** - * get_boot_kbd - allocate and initialize kernel copy of board info + * boot_get_kbd - allocate and initialize kernel copy of board info * @lmb: pointer to lmb handle, will be used for memory mgmt * @kbd: double pointer to board info data * @bootmap_base: ulong variable, holds offset in physical memory to * base of bootmap * - * get_boot_kbd() allocates space for kernel copy of board info data below + * boot_get_kbd() allocates space for kernel copy of board info data below * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with * the current u-boot board info data. * @@ -867,7 +874,7 @@ int get_boot_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end, * 0 - success * -1 - failure */ -int get_boot_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base) +int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base) { *kbd = (bd_t *)lmb_alloc_base(lmb, sizeof(bd_t), 0xf, CFG_BOOTMAPSZ + bootmap_base); diff --git a/include/image.h b/include/image.h index ee692ac..b520691 100644 --- a/include/image.h +++ b/include/image.h @@ -161,9 +161,9 @@ #define IH_NMLEN 32 /* Image Name Length */
/* - * all data in network byte order (aka natural aka bigendian) + * Legacy format image header, + * all data in network byte order (aka natural aka bigendian). */ - typedef struct image_header { uint32_t ih_magic; /* Image Header Magic Number */ uint32_t ih_hcrc; /* Image Header CRC Checksum */ @@ -186,7 +186,7 @@ typedef struct image_header { typedef struct bootm_headers { /* * Legacy os image header, if it is a multi component image - * then get_ramdisk() and get_fdt() will attempt to get + * then boot_get_ramdisk() and get_fdt() will attempt to get * data from second and third component accordingly. */ image_header_t *legacy_hdr_os; @@ -216,9 +216,40 @@ typedef struct bootm_headers { */ #define CHUNKSZ (64 * 1024)
-#define image_to_cpu(x) ntohl(x) -#define cpu_to_image(x) htonl(x) +#define uimage_to_cpu(x) ntohl(x) +#define cpu_to_uimage(x) htonl(x) + +#ifndef USE_HOSTCC +/* Image format types, returned by _get_format() routine */ +#define IMAGE_FORMAT_INVALID 0x00 +#define IMAGE_FORMAT_LEGACY 0x01 /* legacy image_header based format */ +#define IMAGE_FORMAT_FIT 0x02 /* new, libfdt based format */ + +int genimg_get_format (void *img_addr); +ulong genimg_get_image (ulong img_addr); + +const char* genimg_get_os_name (uint8_t os); +const char* genimg_get_arch_name (uint8_t arch); +const char* genimg_get_type_name (uint8_t type); +const char* genimg_get_comp_name (uint8_t comp); + +int boot_get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], + bootm_headers_t *images, uint8_t arch, + ulong *rd_start, ulong *rd_end); + +#if defined(CONFIG_PPC) || defined(CONFIG_M68K) +int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len, + ulong *initrd_start, ulong *initrd_end); + +int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end, + ulong bootmap_base); +int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base); +#endif /* CONFIG_PPC || CONFIG_M68K */ +#endif /* USE_HOSTCC */
+/*******************************************************************/ +/* Legacy format specific code (prefixed with image_) */ +/*******************************************************************/ static inline uint32_t image_get_header_size (void) { return (sizeof (image_header_t)); @@ -227,7 +258,7 @@ static inline uint32_t image_get_header_size (void) #define image_get_hdr_l(f) \ static inline uint32_t image_get_##f(image_header_t *hdr) \ { \ - return image_to_cpu (hdr->ih_##f); \ + return uimage_to_cpu (hdr->ih_##f); \ } image_get_hdr_l (magic); image_get_hdr_l (hcrc); @@ -285,7 +316,7 @@ static inline ulong image_get_image_end (image_header_t *hdr) #define image_set_hdr_l(f) \ static inline void image_set_##f(image_header_t *hdr, uint32_t val) \ { \ - hdr->ih_##f = cpu_to_image (val); \ + hdr->ih_##f = cpu_to_uimage (val); \ } image_set_hdr_l (magic); image_set_hdr_l (hcrc); @@ -375,33 +406,10 @@ static inline int image_check_target_arch (image_header_t *hdr) return 1; }
-const char* image_get_os_name (uint8_t os); -const char* image_get_arch_name (uint8_t arch); -const char* image_get_type_name (uint8_t type); -const char* image_get_comp_name (uint8_t comp); void image_print_contents (image_header_t *hdr);
-#define IMAGE_FORMAT_INVALID 0x00 -#define IMAGE_FORMAT_LEGACY 0x01 /* legacy image_header based format */ -#define IMAGE_FORMAT_FIT 0x02 /* new, libfdt based format */ - -int gen_image_get_format (void *img_addr); -ulong gen_get_image (ulong img_addr); - -int get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], - bootm_headers_t *images, uint8_t arch, - ulong *rd_start, ulong *rd_end); - -#if defined(CONFIG_PPC) || defined(CONFIG_M68K) -int ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len, - ulong *initrd_start, ulong *initrd_end); -int get_boot_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end, - ulong bootmap_base); -int get_boot_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base); -#endif /* CONFIG_PPC || CONFIG_M68K */ - /*******************************************************************/ -/* New uImage format */ +/* New uImage format specific code (prefixed with fit_) */ /*******************************************************************/ #if defined(CONFIG_FIT) inline int fit_parse_conf (const char *spec, ulong addr_curr, @@ -422,9 +430,7 @@ inline int fit_parse_subimage (const char *spec, ulong addr_curr, #define fit_unsupported(msg) #define fit_unsupported_reset(msg) #endif /* CONFIG_FIT_VERBOSE */ - #endif /* CONFIG_FIT */ - #endif /* USE_HOSTCC */
#endif /* __IMAGE_H__ */ diff --git a/lib_arm/bootm.c b/lib_arm/bootm.c index 77d35fc..865e711 100644 --- a/lib_arm/bootm.c +++ b/lib_arm/bootm.c @@ -95,7 +95,7 @@ void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], printf ("Using machid 0x%x from environment\n", machid); }
- get_ramdisk (cmdtp, flag, argc, argv, images, + boot_get_ramdisk (cmdtp, flag, argc, argv, images, IH_ARCH_ARM, &initrd_start, &initrd_end);
show_boot_progress (15); diff --git a/lib_avr32/bootm.c b/lib_avr32/bootm.c index 918e4cf..e8e537a 100644 --- a/lib_avr32/bootm.c +++ b/lib_avr32/bootm.c @@ -196,7 +196,7 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], } theKernel = (void *)ep;
- get_ramdisk (cmdtp, flag, argc, argv, images, + boot_get_ramdisk (cmdtp, flag, argc, argv, images, IH_ARCH_AVR32, &initrd_start, &initrd_end);
show_boot_progress (15); diff --git a/lib_i386/bootm.c b/lib_i386/bootm.c index 89a423c..76bcf6c 100644 --- a/lib_i386/bootm.c +++ b/lib_i386/bootm.c @@ -40,7 +40,7 @@ void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], ulong ep; image_header_t *hdr;
- get_ramdisk (cmdtp, flag, argc, argv, images, + boot_get_ramdisk (cmdtp, flag, argc, argv, images, IH_ARCH_I386, &initrd_start, &initrd_end);
if (images->legacy_hdr_valid) { diff --git a/lib_m68k/bootm.c b/lib_m68k/bootm.c index e12d1d4..fba7499 100644 --- a/lib_m68k/bootm.c +++ b/lib_m68k/bootm.c @@ -82,14 +82,14 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, lmb_reserve(lmb, sp, (CFG_SDRAM_BASE + gd->ram_size - sp));
/* allocate space and init command line */ - ret = get_boot_cmdline (lmb, &cmd_start, &cmd_end, bootmap_base); + ret = boot_get_cmdline (lmb, &cmd_start, &cmd_end, bootmap_base); if (ret) { puts("ERROR with allocation of cmdline\n"); goto error; }
/* allocate space for kernel copy of board info */ - ret = get_boot_kbd (lmb, &kbd, bootmap_base); + ret = boot_get_kbd (lmb, &kbd, bootmap_base); if (ret) { puts("ERROR with allocation of kernel bd\n"); goto error; @@ -111,14 +111,15 @@ void do_bootm_linux(cmd_tbl_t * cmdtp, int flag, kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))ep;
/* find ramdisk */ - ret = get_ramdisk (cmdtp, flag, argc, argv, images, + ret = boot_get_ramdisk (cmdtp, flag, argc, argv, images, IH_ARCH_M68K, &rd_data_start, &rd_data_end);
if (ret) goto error;
rd_len = rd_data_end - rd_data_start; - ret = ramdisk_high (lmb, rd_data_start, rd_len, &initrd_start, &initrd_end); + ret = boot_ramdisk_high (lmb, rd_data_start, rd_len, + &initrd_start, &initrd_end); if (ret) goto error;
diff --git a/lib_mips/bootm.c b/lib_mips/bootm.c index 39869c1..b336a36 100644 --- a/lib_mips/bootm.c +++ b/lib_mips/bootm.c @@ -68,7 +68,7 @@ void do_bootm_linux (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[], } theKernel = (void (*)(int, char **, char **, int *))ep;
- get_ramdisk (cmdtp, flag, argc, argv, images, + boot_get_ramdisk (cmdtp, flag, argc, argv, images, IH_ARCH_MIPS, &initrd_start, &initrd_end);
show_boot_progress (15); diff --git a/lib_ppc/bootm.c b/lib_ppc/bootm.c index 1afef46..8974ccd 100644 --- a/lib_ppc/bootm.c +++ b/lib_ppc/bootm.c @@ -41,9 +41,9 @@ #include <fdt_support.h>
static void fdt_error (const char *msg); -static int get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], +static int boot_get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], bootm_headers_t *images, char **of_flat_tree, ulong *of_size); -static int fdt_relocate (struct lmb *lmb, ulong bootmap_base, +static int boot_relocate_fdt (struct lmb *lmb, ulong bootmap_base, cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], char **of_flat_tree, ulong *of_size); #endif @@ -122,7 +122,7 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
#if defined(CONFIG_OF_LIBFDT) /* find flattened device tree */ - ret = get_fdt (cmdtp, flag, argc, argv, images, &of_flat_tree, &of_size); + ret = boot_get_fdt (cmdtp, flag, argc, argv, images, &of_flat_tree, &of_size);
if (ret) goto error; @@ -130,14 +130,14 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
if (!of_size) { /* allocate space and init command line */ - ret = get_boot_cmdline (lmb, &cmd_start, &cmd_end, bootmap_base); + ret = boot_get_cmdline (lmb, &cmd_start, &cmd_end, bootmap_base); if (ret) { puts("ERROR with allocation of cmdline\n"); goto error; }
/* allocate space for kernel copy of board info */ - ret = get_boot_kbd (lmb, &kbd, bootmap_base); + ret = boot_get_kbd (lmb, &kbd, bootmap_base); if (ret) { puts("ERROR with allocation of kernel bd\n"); goto error; @@ -160,7 +160,7 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))ep;
/* find ramdisk */ - ret = get_ramdisk (cmdtp, flag, argc, argv, images, + ret = boot_get_ramdisk (cmdtp, flag, argc, argv, images, IH_ARCH_PPC, &rd_data_start, &rd_data_end);
if (ret) @@ -169,7 +169,7 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], rd_len = rd_data_end - rd_data_start;
#if defined(CONFIG_OF_LIBFDT) - ret = fdt_relocate (lmb, bootmap_base, + ret = boot_relocate_fdt (lmb, bootmap_base, cmdtp, flag, argc, argv, &of_flat_tree, &of_size);
/* @@ -201,7 +201,7 @@ do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], } #endif /* CONFIG_OF_LIBFDT */
- ret = ramdisk_high (lmb, rd_data_start, rd_len, &initrd_start, &initrd_end); + ret = boot_ramdisk_high (lmb, rd_data_start, rd_len, &initrd_start, &initrd_end); if (ret) goto error;
@@ -354,7 +354,7 @@ static image_header_t *image_get_fdt (ulong fdt_addr) return fdt_hdr; }
-static int get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], +static int boot_get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], bootm_headers_t *images, char **of_flat_tree, ulong *of_size) { ulong fdt_addr; @@ -403,14 +403,14 @@ static int get_fdt (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], fdt_addr);
/* copy from dataflash if needed */ - fdt_addr = gen_get_image (fdt_addr); + fdt_addr = genimg_get_image (fdt_addr);
/* * Check if there is an FDT image at the * address provided in the second bootm argument * check image type, for FIT images get a FIT node. */ - switch (gen_image_get_format ((void *)fdt_addr)) { + switch (genimg_get_format ((void *)fdt_addr)) { case IMAGE_FORMAT_LEGACY: debug ("* fdt: legacy format image\n");
@@ -527,7 +527,7 @@ error: return 1; }
-static int fdt_relocate (struct lmb *lmb, ulong bootmap_base, +static int boot_relocate_fdt (struct lmb *lmb, ulong bootmap_base, cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], char **of_flat_tree, ulong *of_size) { diff --git a/tools/mkimage.c b/tools/mkimage.c index 8ced970..5119bc7 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -361,7 +361,7 @@ NXTARG: ; cmdname, file, strerror(errno)); exit (EXIT_FAILURE); } - size = cpu_to_image (sbuf.st_size); + size = cpu_to_uimage (sbuf.st_size); } else { size = 0; } @@ -604,7 +604,7 @@ print_header (image_header_t *hdr) pos = image_get_header_size () + ptrs * sizeof(long); printf ("Contents:\n"); for (i=0; len_ptr[i]; ++i) { - size = image_to_cpu (len_ptr[i]); + size = uimage_to_cpu (len_ptr[i]);
printf (" Image %d: %8d Bytes = %4d kB = %d MB\n", i, size, size>>10, size>>20);

This patch adds the following common routines:
1) Dedicated mkimage print_header() is replaced with common image_print_contents() image_print_contents_noindent()
2) Common os/arch/type/comp fields name <--> id translation routines genimg_get_os_name() genimg_get_arch_name() genimg_get_type_name() genimg_get_comp_name() genimg_get_os_id() genimg_get_arch_id() genimg_get_type_id() genimg_get_comp_id()
Signed-off-by: Marian Balakowicz m8@semihalf.com ---
common/image.c | 341 +++++++++++++++++++++++++++++++++++++++---------------- include/image.h | 21 ++- tools/mkimage.c | 244 ++------------------------------------- 3 files changed, 267 insertions(+), 339 deletions(-)
diff --git a/common/image.c b/common/image.c index 99ed3b8..421a474 100644 --- a/common/image.c +++ b/common/image.c @@ -62,11 +62,95 @@ static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag, ulong rd_addr, uint8_t arch, int verify); #else #include "mkimage.h" -#endif /* USE_HOSTCC*/ +#endif /* !USE_HOSTCC*/
#include <image.h>
+typedef struct table_entry { + int id; /* as defined in image.h */ + char *sname; /* short (input) name */ + char *lname; /* long (output) name */ +} table_entry_t; + +static table_entry_t uimage_arch[] = { + { IH_ARCH_INVALID, NULL, "Invalid ARCH", }, + { IH_ARCH_ALPHA, "alpha", "Alpha", }, + { IH_ARCH_ARM, "arm", "ARM", }, + { IH_ARCH_I386, "x86", "Intel x86", }, + { IH_ARCH_IA64, "ia64", "IA64", }, + { IH_ARCH_M68K, "m68k", "M68K", }, + { IH_ARCH_MICROBLAZE, "microblaze", "MicroBlaze", }, + { IH_ARCH_MIPS, "mips", "MIPS", }, + { IH_ARCH_MIPS64, "mips64", "MIPS 64 Bit", }, + { IH_ARCH_NIOS, "nios", "NIOS", }, + { IH_ARCH_NIOS2, "nios2", "NIOS II", }, + { IH_ARCH_PPC, "ppc", "PowerPC", }, + { IH_ARCH_S390, "s390", "IBM S390", }, + { IH_ARCH_SH, "sh", "SuperH", }, + { IH_ARCH_SPARC, "sparc", "SPARC", }, + { IH_ARCH_SPARC64, "sparc64", "SPARC 64 Bit", }, + { IH_ARCH_BLACKFIN, "blackfin", "Blackfin", }, + { IH_ARCH_AVR32, "avr32", "AVR32", }, + { -1, "", "", }, +}; + +static table_entry_t uimage_os[] = { + { IH_OS_INVALID, NULL, "Invalid OS", }, +#if defined(CONFIG_ARTOS) || defined(USE_HOSTCC) + { IH_OS_ARTOS, "artos", "ARTOS", }, +#endif + { IH_OS_LINUX, "linux", "Linux", }, +#if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC) + { IH_OS_LYNXOS, "lynxos", "LynxOS", }, +#endif + { IH_OS_NETBSD, "netbsd", "NetBSD", }, + { IH_OS_RTEMS, "rtems", "RTEMS", }, + { IH_OS_U_BOOT, "u-boot", "U-Boot", }, +#if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC) + { IH_OS_QNX, "qnx", "QNX", }, + { IH_OS_VXWORKS, "vxworks", "VxWorks", }, +#endif +#ifdef USE_HOSTCC + { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", }, + { IH_OS_DELL, "dell", "Dell", }, + { IH_OS_ESIX, "esix", "Esix", }, + { IH_OS_FREEBSD, "freebsd", "FreeBSD", }, + { IH_OS_IRIX, "irix", "Irix", }, + { IH_OS_NCR, "ncr", "NCR", }, + { IH_OS_OPENBSD, "openbsd", "OpenBSD", }, + { IH_OS_PSOS, "psos", "pSOS", }, + { IH_OS_SCO, "sco", "SCO", }, + { IH_OS_SOLARIS, "solaris", "Solaris", }, + { IH_OS_SVR4, "svr4", "SVR4", }, +#endif + { -1, "", "", }, +}; + +static table_entry_t uimage_type[] = { + { IH_TYPE_INVALID, NULL, "Invalid Image", }, + { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", }, + { IH_TYPE_FIRMWARE, "firmware", "Firmware", }, + { IH_TYPE_KERNEL, "kernel", "Kernel Image", }, + { IH_TYPE_MULTI, "multi", "Multi-File Image", }, + { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", }, + { IH_TYPE_SCRIPT, "script", "Script", }, + { IH_TYPE_STANDALONE, "standalone", "Standalone Program", }, + { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", }, + { -1, "", "", }, +}; + +static table_entry_t uimage_comp[] = { + { IH_COMP_NONE, "none", "uncompressed", }, + { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", }, + { IH_COMP_GZIP, "gzip", "gzip compressed", }, + { -1, "", "", }, +}; + unsigned long crc32 (unsigned long, const unsigned char *, unsigned int); +static void genimg_print_size (uint32_t size); +#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) +static void genimg_print_time (time_t timestamp); +#endif
/*****************************************************************************/ /* Legacy format routines */ @@ -122,6 +206,7 @@ int image_check_dcrc_wd (image_header_t *hdr, ulong chunksz)
return (dcrc == image_get_dcrc (hdr)); } +#endif /* !USE_HOSTCC */
/** * image_multi_count - get component (sub-image) count @@ -209,7 +294,6 @@ void image_multi_getimg (image_header_t *hdr, ulong idx, } }
-#ifndef USE_HOSTCC static void image_print_type (image_header_t *hdr) { const char *os, *arch, *type, *comp; @@ -219,47 +303,59 @@ static void image_print_type (image_header_t *hdr) type = genimg_get_type_name (image_get_type (hdr)); comp = genimg_get_comp_name (image_get_comp (hdr));
- printf ("%s %s %s (%s)", arch, os, type, comp); + printf ("%s %s %s (%s)\n", arch, os, type, comp); }
-void image_print_contents (image_header_t *hdr) +static void __image_print_contents (image_header_t *hdr, const char *p) { -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) - time_t timestamp = (time_t)image_get_time (hdr); - struct rtc_time tm; -#endif - - printf (" Image Name: %.*s\n", IH_NMLEN, image_get_name (hdr)); - -#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) - to_tm (timestamp, &tm); - printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n", - tm.tm_year, tm.tm_mon, tm.tm_mday, - tm.tm_hour, tm.tm_min, tm.tm_sec); + printf ("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name (hdr)); +#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) + printf ("%sCreated: ", p); + genimg_print_time ((time_t)image_get_time (hdr)); #endif - puts (" Image Type: "); + printf ("%sImage Type: ", p); image_print_type (hdr); + printf ("%sData Size: ", p); + genimg_print_size (image_get_data_size (hdr)); + printf ("%sLoad Address: %08x\n", p, image_get_load (hdr)); + printf ("%sEntry Point: %08x\n", p, image_get_ep (hdr));
- printf ("\n Data Size: %d Bytes = ", image_get_data_size (hdr)); - print_size (image_get_data_size (hdr), "\n"); - printf (" Load Address: %08x\n" - " Entry Point: %08x\n", - image_get_load (hdr), image_get_ep (hdr)); - - if (image_check_type (hdr, IH_TYPE_MULTI)) { + if (image_check_type (hdr, IH_TYPE_MULTI) || + image_check_type (hdr, IH_TYPE_SCRIPT)) { int i; ulong data, len; ulong count = image_multi_count (hdr);
- puts (" Contents:\n"); + printf ("%sContents:\n", p); for (i = 0; i < count; i++) { image_multi_getimg (hdr, i, &data, &len); - printf (" Image %d: %8ld Bytes = ", i, len); - print_size (len, "\n"); + + printf ("%s Image %d: ", p, i); + genimg_print_size (len); + + if (image_check_type (hdr, IH_TYPE_SCRIPT) && i > 0) { + /* + * the user may need to know offsets + * if planning to do something with + * multiple files + */ + printf ("%s Offset = 0x%08lx\n", p, data); + } } } }
+inline void image_print_contents (image_header_t *hdr) +{ + __image_print_contents (hdr, " "); +} + +inline void image_print_contents_noindent (image_header_t *hdr) +{ + __image_print_contents (hdr, ""); +} + +#ifndef USE_HOSTCC /** * image_get_ramdisk - get and verify ramdisk image * @cmdtp: command table pointer @@ -329,10 +425,12 @@ static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag,
return rd_hdr; } +#endif /* !USE_HOSTCC */
/*****************************************************************************/ /* Shared dual-format routines */ /*****************************************************************************/ +#ifndef USE_HOSTCC int getenv_verify (void) { char *s = getenv ("verify"); @@ -386,94 +484,144 @@ void memmove_wd (void *to, void *from, size_t len, ulong chunksz) memmove (to, from, len); #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */ } -#endif /* USE_HOSTCC */ +#endif /* !USE_HOSTCC */
-const char* genimg_get_os_name (uint8_t os) +static void genimg_print_size (uint32_t size) { - const char *name; - - switch (os) { - case IH_OS_INVALID: name = "Invalid OS"; break; - case IH_OS_NETBSD: name = "NetBSD"; break; - case IH_OS_LINUX: name = "Linux"; break; - case IH_OS_VXWORKS: name = "VxWorks"; break; - case IH_OS_QNX: name = "QNX"; break; - case IH_OS_U_BOOT: name = "U-Boot"; break; - case IH_OS_RTEMS: name = "RTEMS"; break; -#ifdef CONFIG_ARTOS - case IH_OS_ARTOS: name = "ARTOS"; break; +#ifndef USE_HOSTCC + printf ("%d Bytes = ", size); + print_size (size, "\n"); +#else + printf ("%d Bytes = %.2f kB = %.2f MB\n", + size, (double)size / 1.024e3, + (double)size / 1.048576e6); #endif -#ifdef CONFIG_LYNXKDI - case IH_OS_LYNXOS: name = "LynxOS"; break; +} + +#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) +static void genimg_print_time (time_t timestamp) +{ +#ifndef USE_HOSTCC + struct rtc_time tm; + + to_tm (timestamp, &tm); + printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n", + tm.tm_year, tm.tm_mon, tm.tm_mday, + tm.tm_hour, tm.tm_min, tm.tm_sec); +#else + printf ("%s", ctime(×tamp)); #endif - default: name = "Unknown OS"; break; - } +} +#endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */
- return name; -} - -const char* genimg_get_arch_name (uint8_t arch) -{ - const char *name; - - switch (arch) { - case IH_ARCH_INVALID: name = "Invalid Architecture"; break; - case IH_ARCH_ALPHA: name = "Alpha"; break; - case IH_ARCH_ARM: name = "ARM"; break; - case IH_ARCH_AVR32: name = "AVR32"; break; - case IH_ARCH_BLACKFIN: name = "Blackfin"; break; - case IH_ARCH_I386: name = "Intel x86"; break; - case IH_ARCH_IA64: name = "IA64"; break; - case IH_ARCH_M68K: name = "M68K"; break; - case IH_ARCH_MICROBLAZE:name = "Microblaze"; break; - case IH_ARCH_MIPS64: name = "MIPS 64 Bit"; break; - case IH_ARCH_MIPS: name = "MIPS"; break; - case IH_ARCH_NIOS2: name = "Nios-II"; break; - case IH_ARCH_NIOS: name = "Nios"; break; - case IH_ARCH_PPC: name = "PowerPC"; break; - case IH_ARCH_S390: name = "IBM S390"; break; - case IH_ARCH_SH: name = "SuperH"; break; - case IH_ARCH_SPARC64: name = "SPARC 64 Bit"; break; - case IH_ARCH_SPARC: name = "SPARC"; break; - default: name = "Unknown Architecture"; break; +/** + * get_table_entry_name - translate entry id to long name + * @table: pointer to a translation table for entries of a specific type + * @msg: message to be returned when translation fails + * @id: entry id to be translated + * + * get_table_entry_name() will go over translation table trying to find + * entry that matches given id. If matching entry is found, its long + * name is returned to the caller. + * + * returns: + * long entry name if translation succeeds + * msg otherwise + */ +static char *get_table_entry_name (table_entry_t *table, char *msg, int id) +{ + for (; table->id >= 0; ++table) { + if (table->id == id) + return (table->lname); } + return (msg); +}
- return name; +const char *genimg_get_os_name (uint8_t os) +{ + return (get_table_entry_name (uimage_os, "Unknown OS", os)); }
-const char* genimg_get_type_name (uint8_t type) +const char *genimg_get_arch_name (uint8_t arch) { - const char *name; + return (get_table_entry_name (uimage_arch, "Unknown Architecture", arch)); +}
- switch (type) { - case IH_TYPE_INVALID: name = "Invalid Image"; break; - case IH_TYPE_STANDALONE:name = "Standalone Program"; break; - case IH_TYPE_KERNEL: name = "Kernel Image"; break; - case IH_TYPE_RAMDISK: name = "RAMDisk Image"; break; - case IH_TYPE_MULTI: name = "Multi-File Image"; break; - case IH_TYPE_FIRMWARE: name = "Firmware"; break; - case IH_TYPE_SCRIPT: name = "Script"; break; - case IH_TYPE_FLATDT: name = "Flat Device Tree"; break; - default: name = "Unknown Image"; break; - } +const char *genimg_get_type_name (uint8_t type) +{ + return (get_table_entry_name (uimage_type, "Unknown Image", type)); +}
- return name; +const char *genimg_get_comp_name (uint8_t comp) +{ + return (get_table_entry_name (uimage_comp, "Unknown Compression", comp)); }
-const char* genimg_get_comp_name (uint8_t comp) +/** + * get_table_entry_id - translate short entry name to id + * @table: pointer to a translation table for entries of a specific type + * @table_name: to be used in case of error + * @name: entry short name to be translated + * + * get_table_entry_id() will go over translation table trying to find + * entry that matches given short name. If matching entry is found, + * its id returned to the caller. + * + * returns: + * entry id if translation succeeds + * -1 otherwise + */ +static int get_table_entry_id (table_entry_t *table, + const char *table_name, const char *name) { - const char *name; + table_entry_t *t; +#ifdef USE_HOSTCC + int first = 1;
- switch (comp) { - case IH_COMP_NONE: name = "uncompressed"; break; - case IH_COMP_GZIP: name = "gzip compressed"; break; - case IH_COMP_BZIP2: name = "bzip2 compressed"; break; - default: name = "unknown compression"; break; + for (t = table; t->id >= 0; ++t) { + if (t->sname && strcasecmp(t->sname, name) == 0) + return (t->id); }
- return name; + fprintf (stderr, "\nInvalid %s Type - valid names are", table_name); + for (t = table; t->id >= 0; ++t) { + if (t->sname == NULL) + continue; + fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname); + first = 0; + } + fprintf (stderr, "\n"); +#else + for (t = table; t->id >= 0; ++t) { + if (t->sname && strcmp(t->sname, name) == 0) + return (t->id); + } + debug ("Invalid %s Type: %s\n", table_name, name); +#endif /* USE_HOSTCC */ + return (-1); +} + +int genimg_get_os_id (const char *name) +{ + return (get_table_entry_id (uimage_os, "OS", name)); +} + +int genimg_get_arch_id (const char *name) +{ + return (get_table_entry_id (uimage_arch, "CPU", name)); }
+int genimg_get_type_id (const char *name) +{ + return (get_table_entry_id (uimage_type, "Image", name)); +} + +int genimg_get_comp_id (const char *name) +{ + return (get_table_entry_id (uimage_comp, "Compression", name)); +} + +#ifndef USE_HOSTCC /** * genimg_get_format - get image format type * @img_addr: image start address @@ -971,5 +1119,4 @@ inline int fit_parse_subimage (const char *spec, ulong addr_curr, }
#endif /* CONFIG_FIT */ - -#endif /* USE_HOSTCC */ +#endif /* !USE_HOSTCC */ diff --git a/include/image.h b/include/image.h index b520691..ed79552 100644 --- a/include/image.h +++ b/include/image.h @@ -219,6 +219,15 @@ typedef struct bootm_headers { #define uimage_to_cpu(x) ntohl(x) #define cpu_to_uimage(x) htonl(x)
+const char *genimg_get_os_name (uint8_t os); +const char *genimg_get_arch_name (uint8_t arch); +const char *genimg_get_type_name (uint8_t type); +const char *genimg_get_comp_name (uint8_t comp); +int genimg_get_os_id (const char *name); +int genimg_get_arch_id (const char *name); +int genimg_get_type_id (const char *name); +int genimg_get_comp_id (const char *name); + #ifndef USE_HOSTCC /* Image format types, returned by _get_format() routine */ #define IMAGE_FORMAT_INVALID 0x00 @@ -228,11 +237,6 @@ typedef struct bootm_headers { int genimg_get_format (void *img_addr); ulong genimg_get_image (ulong img_addr);
-const char* genimg_get_os_name (uint8_t os); -const char* genimg_get_arch_name (uint8_t arch); -const char* genimg_get_type_name (uint8_t type); -const char* genimg_get_comp_name (uint8_t comp); - int boot_get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[], bootm_headers_t *images, uint8_t arch, ulong *rd_start, ulong *rd_end); @@ -245,7 +249,7 @@ int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end, ulong bootmap_base); int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base); #endif /* CONFIG_PPC || CONFIG_M68K */ -#endif /* USE_HOSTCC */ +#endif /* !USE_HOSTCC */
/*******************************************************************/ /* Legacy format specific code (prefixed with image_) */ @@ -373,6 +377,9 @@ ulong image_multi_count (image_header_t *hdr); void image_multi_getimg (image_header_t *hdr, ulong idx, ulong *data, ulong *len);
+inline void image_print_contents (image_header_t *hdr); +inline void image_print_contents_noindent (image_header_t *hdr); + #ifndef USE_HOSTCC static inline int image_check_target_arch (image_header_t *hdr) { @@ -406,8 +413,6 @@ static inline int image_check_target_arch (image_header_t *hdr) return 1; }
-void image_print_contents (image_header_t *hdr); - /*******************************************************************/ /* New uImage format specific code (prefixed with fit_) */ /*******************************************************************/ diff --git a/tools/mkimage.c b/tools/mkimage.c index 5119bc7..5cb2bc7 100644 --- a/tools/mkimage.c +++ b/tools/mkimage.c @@ -29,100 +29,13 @@ extern int errno; #define MAP_FAILED (-1) #endif
-char *cmdname; - -extern unsigned long crc32 (unsigned long crc, const char *buf, unsigned int len); - -typedef struct table_entry { - int val; /* as defined in image.h */ - char *sname; /* short (input) name */ - char *lname; /* long (output) name */ -} table_entry_t; - -table_entry_t arch_name[] = { - { IH_ARCH_INVALID, NULL, "Invalid CPU", }, - { IH_ARCH_ALPHA, "alpha", "Alpha", }, - { IH_ARCH_ARM, "arm", "ARM", }, - { IH_ARCH_I386, "x86", "Intel x86", }, - { IH_ARCH_IA64, "ia64", "IA64", }, - { IH_ARCH_M68K, "m68k", "MC68000", }, - { IH_ARCH_MICROBLAZE, "microblaze", "MicroBlaze", }, - { IH_ARCH_MIPS, "mips", "MIPS", }, - { IH_ARCH_MIPS64, "mips64", "MIPS 64 Bit", }, - { IH_ARCH_NIOS, "nios", "NIOS", }, - { IH_ARCH_NIOS2, "nios2", "NIOS II", }, - { IH_ARCH_PPC, "ppc", "PowerPC", }, - { IH_ARCH_S390, "s390", "IBM S390", }, - { IH_ARCH_SH, "sh", "SuperH", }, - { IH_ARCH_SPARC, "sparc", "SPARC", }, - { IH_ARCH_SPARC64, "sparc64", "SPARC 64 Bit", }, - { IH_ARCH_BLACKFIN, "blackfin", "Blackfin", }, - { IH_ARCH_AVR32, "avr32", "AVR32", }, - { -1, "", "", }, -}; - -table_entry_t os_name[] = { - { IH_OS_INVALID, NULL, "Invalid OS", }, - { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", }, - { IH_OS_ARTOS, "artos", "ARTOS", }, - { IH_OS_DELL, "dell", "Dell", }, - { IH_OS_ESIX, "esix", "Esix", }, - { IH_OS_FREEBSD, "freebsd", "FreeBSD", }, - { IH_OS_IRIX, "irix", "Irix", }, - { IH_OS_LINUX, "linux", "Linux", }, - { IH_OS_LYNXOS, "lynxos", "LynxOS", }, - { IH_OS_NCR, "ncr", "NCR", }, - { IH_OS_NETBSD, "netbsd", "NetBSD", }, - { IH_OS_OPENBSD, "openbsd", "OpenBSD", }, - { IH_OS_PSOS, "psos", "pSOS", }, - { IH_OS_QNX, "qnx", "QNX", }, - { IH_OS_RTEMS, "rtems", "RTEMS", }, - { IH_OS_SCO, "sco", "SCO", }, - { IH_OS_SOLARIS, "solaris", "Solaris", }, - { IH_OS_SVR4, "svr4", "SVR4", }, - { IH_OS_U_BOOT, "u-boot", "U-Boot", }, - { IH_OS_VXWORKS, "vxworks", "VxWorks", }, - { -1, "", "", }, -}; - -table_entry_t type_name[] = { - { IH_TYPE_INVALID, NULL, "Invalid Image", }, - { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", }, - { IH_TYPE_FIRMWARE, "firmware", "Firmware", }, - { IH_TYPE_KERNEL, "kernel", "Kernel Image", }, - { IH_TYPE_MULTI, "multi", "Multi-File Image", }, - { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", }, - { IH_TYPE_SCRIPT, "script", "Script", }, - { IH_TYPE_STANDALONE, "standalone", "Standalone Program", }, - { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", }, - { -1, "", "", }, -}; - -table_entry_t comp_name[] = { - { IH_COMP_NONE, "none", "uncompressed", }, - { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", }, - { IH_COMP_GZIP, "gzip", "gzip compressed", }, - { -1, "", "", }, -}; - -static void copy_file (int, const char *, int); -static void usage (void); -static void print_header (image_header_t *); -static void print_type (image_header_t *); -static char *put_table_entry (table_entry_t *, char *, int); -static char *put_arch (int); -static char *put_type (int); -static char *put_os (int); -static char *put_comp (int); -static int get_table_entry (table_entry_t *, char *, char *); -static int get_arch(char *); -static int get_comp(char *); -static int get_os (char *); -static int get_type(char *); - +extern unsigned long crc32 (unsigned long crc, const char *buf, unsigned int len); +static void copy_file (int, const char *, int); +static void usage (void);
char *datafile; char *imagefile; +char *cmdname;
int dflag = 0; int eflag = 0; @@ -160,22 +73,22 @@ main (int argc, char **argv) break; case 'A': if ((--argc <= 0) || - (opt_arch = get_arch(*++argv)) < 0) + (opt_arch = genimg_get_arch_id (*++argv)) < 0) usage (); goto NXTARG; case 'C': if ((--argc <= 0) || - (opt_comp = get_comp(*++argv)) < 0) + (opt_comp = genimg_get_comp_id (*++argv)) < 0) usage (); goto NXTARG; case 'O': if ((--argc <= 0) || - (opt_os = get_os(*++argv)) < 0) + (opt_os = genimg_get_os_id (*++argv)) < 0) usage (); goto NXTARG; case 'T': if ((--argc <= 0) || - (opt_type = get_type(*++argv)) < 0) + (opt_type = genimg_get_type_id (*++argv)) < 0) usage (); goto NXTARG;
@@ -323,7 +236,7 @@ NXTARG: ; }
/* for multi-file images we need the data part, too */ - print_header ((image_header_t *)ptr); + image_print_contents_noindent ((image_header_t *)ptr);
(void) munmap((void *)ptr, sbuf.st_size); (void) close (ifd); @@ -448,7 +361,7 @@ NXTARG: ;
image_set_hcrc (hdr, checksum);
- print_header (hdr); + image_print_contents_noindent (hdr);
(void) munmap((void *)ptr, sbuf.st_size);
@@ -570,140 +483,3 @@ usage () ); exit (EXIT_FAILURE); } - -static void -print_header (image_header_t *hdr) -{ - time_t timestamp; - uint32_t size; - - timestamp = (time_t)image_get_time (hdr); - size = image_get_data_size (hdr); - - printf ("Image Name: %.*s\n", IH_NMLEN, image_get_name (hdr)); - printf ("Created: %s", ctime(×tamp)); - printf ("Image Type: "); print_type(hdr); - printf ("Data Size: %d Bytes = %.2f kB = %.2f MB\n", - size, (double)size / 1.024e3, (double)size / 1.048576e6 ); - printf ("Load Address: 0x%08X\n", image_get_load (hdr)); - printf ("Entry Point: 0x%08X\n", image_get_ep (hdr)); - - if (image_check_type (hdr, IH_TYPE_MULTI) || - image_check_type (hdr, IH_TYPE_SCRIPT)) { - int i, ptrs; - uint32_t pos; - uint32_t *len_ptr = (uint32_t *) ( - (unsigned long)hdr + image_get_header_size () - ); - - /* determine number of images first (to calculate image offsets) */ - for (i=0; len_ptr[i]; ++i) /* null pointer terminates list */ - ; - ptrs = i; /* null pointer terminates list */ - - pos = image_get_header_size () + ptrs * sizeof(long); - printf ("Contents:\n"); - for (i=0; len_ptr[i]; ++i) { - size = uimage_to_cpu (len_ptr[i]); - - printf (" Image %d: %8d Bytes = %4d kB = %d MB\n", - i, size, size>>10, size>>20); - if (image_check_type (hdr, IH_TYPE_SCRIPT) && i > 0) { - /* - * the user may need to know offsets - * if planning to do something with - * multiple files - */ - printf (" Offset = %08X\n", pos); - } - /* copy_file() will pad the first files to even word align */ - size += 3; - size &= ~3; - pos += size; - } - } -} - - -static void -print_type (image_header_t *hdr) -{ - printf ("%s %s %s (%s)\n", - put_arch (image_get_arch (hdr)), - put_os (image_get_os (hdr)), - put_type (image_get_type (hdr)), - put_comp (image_get_comp (hdr)) - ); -} - -static char *put_arch (int arch) -{ - return (put_table_entry(arch_name, "Unknown Architecture", arch)); -} - -static char *put_os (int os) -{ - return (put_table_entry(os_name, "Unknown OS", os)); -} - -static char *put_type (int type) -{ - return (put_table_entry(type_name, "Unknown Image", type)); -} - -static char *put_comp (int comp) -{ - return (put_table_entry(comp_name, "Unknown Compression", comp)); -} - -static char *put_table_entry (table_entry_t *table, char *msg, int type) -{ - for (; table->val>=0; ++table) { - if (table->val == type) - return (table->lname); - } - return (msg); -} - -static int get_arch(char *name) -{ - return (get_table_entry(arch_name, "CPU", name)); -} - - -static int get_comp(char *name) -{ - return (get_table_entry(comp_name, "Compression", name)); -} - - -static int get_os (char *name) -{ - return (get_table_entry(os_name, "OS", name)); -} - - -static int get_type(char *name) -{ - return (get_table_entry(type_name, "Image", name)); -} - -static int get_table_entry (table_entry_t *table, char *msg, char *name) -{ - table_entry_t *t; - int first = 1; - - for (t=table; t->val>=0; ++t) { - if (t->sname && strcasecmp(t->sname, name)==0) - return (t->val); - } - fprintf (stderr, "\nInvalid %s Type - valid names are", msg); - for (t=table; t->val>=0; ++t) { - if (t->sname == NULL) - continue; - fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname); - first = 0; - } - fprintf (stderr, "\n"); - return (-1); -}

Use uint32_t when accessing size table in image_multi_count() and image_multi_getimg() for multi component images.
Add missing uimage_to_cpu() endianness conversion.
Signed-off-by: Marian Balakowicz m8@semihalf.com ---
common/image.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/common/image.c b/common/image.c index 421a474..3911b2f 100644 --- a/common/image.c +++ b/common/image.c @@ -224,11 +224,11 @@ int image_check_dcrc_wd (image_header_t *hdr, ulong chunksz) ulong image_multi_count (image_header_t *hdr) { ulong i, count = 0; - ulong *size; + uint32_t *size;
/* get start of the image payload, which in case of multi * component images that points to a table of component sizes */ - size = (ulong *)image_get_data (hdr); + size = (uint32_t *)image_get_data (hdr);
/* count non empty slots */ for (i = 0; size[i]; ++i) @@ -258,7 +258,7 @@ void image_multi_getimg (image_header_t *hdr, ulong idx, ulong *data, ulong *len) { int i; - ulong *size; + uint32_t *size; ulong offset, tail, count, img_data;
/* get number of component */ @@ -266,24 +266,24 @@ void image_multi_getimg (image_header_t *hdr, ulong idx,
/* get start of the image payload, which in case of multi * component images that points to a table of component sizes */ - size = (ulong *)image_get_data (hdr); + size = (uint32_t *)image_get_data (hdr);
/* get address of the proper component data start, which means * skipping sizes table (add 1 for last, null entry) */ - img_data = image_get_data (hdr) + (count + 1) * sizeof (ulong); + img_data = image_get_data (hdr) + (count + 1) * sizeof (uint32_t);
if (idx < count) { - *len = size[idx]; + *len = uimage_to_cpu (size[idx]); offset = 0; tail = 0;
/* go over all indices preceding requested component idx */ for (i = 0; i < idx; i++) { /* add up i-th component size */ - offset += size[i]; + offset += uimage_to_cpu (size[i]);
/* add up alignment for i-th component */ - tail += (4 - size[i] % 4); + tail += (4 - uimage_to_cpu (size[i]) % 4); }
/* calculate idx-th component data address */

From: Bartlomiej Sieka tur@semihalf.com
Signed-off-by: Bartlomiej Sieka tur@semihalf.com ---
tools/Makefile | 2 +- tools/mkimage.h | 1 + 2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/tools/Makefile b/tools/Makefile index cbfca6d..0cc4cc9 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -137,7 +137,7 @@ $(obj)img2srec$(SFX): $(obj)img2srec.o $(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^ $(STRIP) $@
-$(obj)mkimage$(SFX): $(obj)mkimage.o $(obj)crc32.o $(obj)image.o +$(obj)mkimage$(SFX): $(obj)mkimage.o $(obj)crc32.o $(obj)image.o $(obj)sha1.o $(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^ $(STRIP) $@
diff --git a/tools/mkimage.h b/tools/mkimage.h index 8b05bb1..a01977e 100644 --- a/tools/mkimage.h +++ b/tools/mkimage.h @@ -32,6 +32,7 @@ #include <sys/stat.h> #include <time.h> #include <unistd.h> +#include <sha1.h>
#if defined(__BEOS__) || defined(__NetBSD__) || defined(__APPLE__) #include <inttypes.h>

From: Bartlomiej Sieka tur@semihalf.com
Signed-off-by: Bartlomiej Sieka tur@semihalf.com ---
Makefile | 3 +++ include/libfdt_env.h | 4 ++++ libfdt/fdt.c | 4 ++++ libfdt/fdt_ro.c | 4 ++++ libfdt/fdt_rw.c | 4 ++++ libfdt/fdt_strerror.c | 4 ++++ libfdt/fdt_wip.c | 4 ++++ tools/.gitignore | 7 +++++++ tools/Makefile | 51 ++++++++++++++++++++++++++++++++++++++++++++++--- tools/fdt_host.h | 28 +++++++++++++++++++++++++++ tools/mkimage.h | 1 + 11 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 tools/fdt_host.h
diff --git a/Makefile b/Makefile index bacea3e..adfef9b 100644 --- a/Makefile +++ b/Makefile @@ -2927,6 +2927,9 @@ clobber: clean @rm -f $(obj)u-boot $(obj)u-boot.map $(obj)u-boot.hex $(ALL) @rm -f $(obj)tools/crc32.c $(obj)tools/environment.c $(obj)tools/env/crc32.c @rm -f $(obj)tools/sha1.c $(obj)tools/image.c + @rm -f $(obj)tools/fdt.c $(obj)tools/fdt_ro.c $(obj)tools/fdt_rw.c + @rm -f $(obj)tools/fdt_strerror.c $(obj)tools/fdt_wip.c + @rm -f $(obj)tools/libfdt_internal.h @rm -f $(obj)tools/inca-swap-bytes $(obj)cpu/mpc824x/bedbug_603e.c @rm -f $(obj)include/asm/proc $(obj)include/asm/arch $(obj)include/asm @[ ! -d $(obj)nand_spl ] || find $(obj)nand_spl -lname "*" -print | xargs rm -f diff --git a/include/libfdt_env.h b/include/libfdt_env.h index 78f7258..98c522a 100644 --- a/include/libfdt_env.h +++ b/include/libfdt_env.h @@ -24,7 +24,11 @@ #include <stddef.h> #include <linux/types.h> #include <asm/byteorder.h> +#ifdef USE_HOSTCC +#include <string.h> +#else #include <linux/string.h> +#endif /* USE_HOSTCC */
extern struct fdt_header *fdt; /* Pointer to the working fdt */
diff --git a/libfdt/fdt.c b/libfdt/fdt.c index 586a361..071470d 100644 --- a/libfdt/fdt.c +++ b/libfdt/fdt.c @@ -50,8 +50,12 @@ */ #include "libfdt_env.h"
+#ifndef USE_HOSTCC #include <fdt.h> #include <libfdt.h> +#else +#include "fdt_host.h" +#endif
#include "libfdt_internal.h"
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index 12a37d5..1ae3a55 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -50,8 +50,12 @@ */ #include "libfdt_env.h"
+#ifndef USE_HOSTCC #include <fdt.h> #include <libfdt.h> +#else +#include "fdt_host.h" +#endif
#include "libfdt_internal.h"
diff --git a/libfdt/fdt_rw.c b/libfdt/fdt_rw.c index 6673f8e..2fb81dd 100644 --- a/libfdt/fdt_rw.c +++ b/libfdt/fdt_rw.c @@ -50,8 +50,12 @@ */ #include "libfdt_env.h"
+#ifndef USE_HOSTCC #include <fdt.h> #include <libfdt.h> +#else +#include "fdt_host.h" +#endif
#include "libfdt_internal.h"
diff --git a/libfdt/fdt_strerror.c b/libfdt/fdt_strerror.c index f9d32ef..abf792e 100644 --- a/libfdt/fdt_strerror.c +++ b/libfdt/fdt_strerror.c @@ -50,8 +50,12 @@ */ #include "libfdt_env.h"
+#ifndef USE_HOSTCC #include <fdt.h> #include <libfdt.h> +#else +#include "fdt_host.h" +#endif
#include "libfdt_internal.h"
diff --git a/libfdt/fdt_wip.c b/libfdt/fdt_wip.c index 88e24b8..24e1724 100644 --- a/libfdt/fdt_wip.c +++ b/libfdt/fdt_wip.c @@ -50,8 +50,12 @@ */ #include "libfdt_env.h"
+#ifndef USE_HOSTCC #include <fdt.h> #include <libfdt.h> +#else +#include "fdt_host.h" +#endif
#include "libfdt_internal.h"
diff --git a/tools/.gitignore b/tools/.gitignore index c33679a..0ce2e77 100644 --- a/tools/.gitignore +++ b/tools/.gitignore @@ -7,3 +7,10 @@ /mkimage /sha1.c /ubsha1 +/image.c +/fdt.c +/fdt_ro.c +/fdt_rw.c +/fdt_strerror.c +/fdt_wip.c +/libfdt_internal.h diff --git a/tools/Makefile b/tools/Makefile index 0cc4cc9..aa4af18 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -37,6 +37,8 @@ endif #OBJ_FILES += mpc86x_clk.o #endif
+LIBFDT_OBJ_FILES = fdt.o fdt_ro.o fdt_rw.o fdt_strerror.o fdt_wip.o + LOGO_H = $(OBJTREE)/include/bmp_logo.h
ifeq ($(LOGO_BMP),) @@ -120,6 +122,10 @@ CPPFLAGS = -idirafter $(SRCTREE)/include \ -idirafter $(OBJTREE)/include \ -DTEXT_BASE=$(TEXT_BASE) -DUSE_HOSTCC CFLAGS = $(HOST_CFLAGS) $(CPPFLAGS) -O + +# No -pedantic switch to avoid libfdt compilation warnings +FIT_CFLAGS = -Wall $(CPPFLAGS) -O + AFLAGS = -D__ASSEMBLY__ $(CPPFLAGS) CC = $(HOSTCC) STRIP = $(HOSTSTRIP) @@ -137,7 +143,7 @@ $(obj)img2srec$(SFX): $(obj)img2srec.o $(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^ $(STRIP) $@
-$(obj)mkimage$(SFX): $(obj)mkimage.o $(obj)crc32.o $(obj)image.o $(obj)sha1.o +$(obj)mkimage$(SFX): $(obj)mkimage.o $(obj)crc32.o $(obj)image.o $(obj)sha1.o $(LIBFDT_OBJ_FILES) $(CC) $(CFLAGS) $(HOST_LDFLAGS) -o $@ $^ $(STRIP) $@
@@ -174,10 +180,10 @@ $(obj)sha1.o: $(obj)sha1.c $(CC) -g $(CFLAGS) -c -o $@ $<
$(obj)image.o: $(obj)image.c - $(CC) -g $(CFLAGS) -c -o $@ $< + $(CC) -g $(FIT_CFLAGS) -c -o $@ $<
$(obj)mkimage.o: $(src)mkimage.c - $(CC) -g $(CFLAGS) -c -o $@ $< + $(CC) -g $(FIT_CFLAGS) -c -o $@ $<
$(obj)ncb.o: $(src)ncb.c $(CC) -g $(CFLAGS) -c -o $@ $< @@ -191,6 +197,21 @@ $(obj)inca-swap-bytes.o: $(src)inca-swap-bytes.c $(obj)mpc86x_clk.o: $(src)mpc86x_clk.c $(CC) -g $(CFLAGS) -c -o $@ $<
+$(obj)fdt.o: $(obj)fdt.c + $(CC) -g $(FIT_CFLAGS) -c -o $@ $< + +$(obj)fdt_ro.o: $(obj)fdt_ro.c + $(CC) -g $(FIT_CFLAGS) -c -o $@ $< + +$(obj)fdt_rw.o: $(obj)fdt_rw.c + $(CC) -g $(FIT_CFLAGS) -c -o $@ $< + +$(obj)fdt_strerror.o: $(obj)fdt_strerror.c + $(CC) -g $(FIT_CFLAGS) -c -o $@ $< + +$(obj)fdt_wip.o: $(obj)fdt_wip.c + $(CC) -g $(FIT_CFLAGS) -c -o $@ $< + subdirs: ifeq ($(TOOLSUBDIRS),) @: @@ -224,6 +245,30 @@ $(obj)image.c: @rm -f $(obj)image.c ln -s $(src)../common/image.c $(obj)image.c
+$(obj)fdt.c: libfdt_internal.h + @rm -f $(obj)fdt.c + ln -s $(src)../libfdt/fdt.c $(obj)fdt.c + +$(obj)fdt_ro.c: libfdt_internal.h + @rm -f $(obj)fdt_ro.c + ln -s $(src)../libfdt/fdt_ro.c $(obj)fdt_ro.c + +$(obj)fdt_rw.c: libfdt_internal.h + @rm -f $(obj)fdt_rw.c + ln -s $(src)../libfdt/fdt_rw.c $(obj)fdt_rw.c + +$(obj)fdt_strerror.c: libfdt_internal.h + @rm -f $(obj)fdt_strerror.c + ln -s $(src)../libfdt/fdt_strerror.c $(obj)fdt_strerror.c + +$(obj)fdt_wip.c: libfdt_internal.h + @rm -f $(obj)fdt_wip.c + ln -s $(src)../libfdt/fdt_wip.c $(obj)fdt_wip.c + +$(obj)libfdt_internal.h: + @rm -f $(obj)libfdt_internal.h + ln -s $(src)../libfdt/libfdt_internal.h $(obj)libfdt_internal.h + $(LOGO_H): $(obj)bmp_logo $(LOGO_BMP) $(obj)./bmp_logo $(LOGO_BMP) >$@
diff --git a/tools/fdt_host.h b/tools/fdt_host.h new file mode 100644 index 0000000..085013e --- /dev/null +++ b/tools/fdt_host.h @@ -0,0 +1,28 @@ +/* + * (C) Copyright 2008 Semihalf + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + */ + +#ifndef __FDT_HOST_H__ +#define __FDT_HOST_H__ + +/* Make sure to include u-boot version of libfdt include files */ +#include "../include/fdt.h" +#include "../include/libfdt.h" +#include "../include/fdt_support.h" + +#endif /* __FDT_HOST_H__ */ diff --git a/tools/mkimage.h b/tools/mkimage.h index a01977e..cdd52bc 100644 --- a/tools/mkimage.h +++ b/tools/mkimage.h @@ -33,6 +33,7 @@ #include <time.h> #include <unistd.h> #include <sha1.h> +#include "fdt_host.h"
#if defined(__BEOS__) || defined(__NetBSD__) || defined(__APPLE__) #include <inttypes.h>

Marian Balakowicz wrote:
From: Bartlomiej Sieka tur@semihalf.com
Signed-off-by: Bartlomiej Sieka tur@semihalf.com
Makefile | 3 +++ include/libfdt_env.h | 4 ++++ libfdt/fdt.c | 4 ++++ libfdt/fdt_ro.c | 4 ++++ libfdt/fdt_rw.c | 4 ++++ libfdt/fdt_strerror.c | 4 ++++ libfdt/fdt_wip.c | 4 ++++ tools/.gitignore | 7 +++++++ tools/Makefile | 51 ++++++++++++++++++++++++++++++++++++++++++++++--- tools/fdt_host.h | 28 +++++++++++++++++++++++++++ tools/mkimage.h | 1 + 11 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 tools/fdt_host.h
Arrrr, I'm not wild about this, but I cannot suggest a better way. :-(
All these (trivial) touches to libfdt/* are annoying and could cause patch tracking of the dtc/libfdt source to break. I guess that is the risk we live with unless or until someone comes up with a better way. :-(
Best regards, gvb

Jerry Van Baren wrote:
Marian Balakowicz wrote:
From: Bartlomiej Sieka tur@semihalf.com
Signed-off-by: Bartlomiej Sieka tur@semihalf.com
Makefile | 3 +++ include/libfdt_env.h | 4 ++++ libfdt/fdt.c | 4 ++++ libfdt/fdt_ro.c | 4 ++++ libfdt/fdt_rw.c | 4 ++++ libfdt/fdt_strerror.c | 4 ++++ libfdt/fdt_wip.c | 4 ++++ tools/.gitignore | 7 +++++++ tools/Makefile | 51 ++++++++++++++++++++++++++++++++++++++++++++++--- tools/fdt_host.h | 28 +++++++++++++++++++++++++++ tools/mkimage.h | 1 + 11 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 tools/fdt_host.h
Arrrr, I'm not wild about this, but I cannot suggest a better way. :-(
All these (trivial) touches to libfdt/* are annoying and could cause patch tracking of the dtc/libfdt source to break. I guess that is the risk we live with unless or until someone comes up with a better way. :-(
Right, this is ugly, I don't like that solution either. I'd be glad to have something cleaner but I spent a few moments on it and can't figure out anything better and simple enough.
Cheers, m.

Jerry Van Baren wrote:
Marian Balakowicz wrote:
From: Bartlomiej Sieka tur@semihalf.com
Signed-off-by: Bartlomiej Sieka tur@semihalf.com
Makefile | 3 +++ include/libfdt_env.h | 4 ++++ libfdt/fdt.c | 4 ++++ libfdt/fdt_ro.c | 4 ++++ libfdt/fdt_rw.c | 4 ++++ libfdt/fdt_strerror.c | 4 ++++ libfdt/fdt_wip.c | 4 ++++ tools/.gitignore | 7 +++++++ tools/Makefile | 51 ++++++++++++++++++++++++++++++++++++++++++++++--- tools/fdt_host.h | 28 +++++++++++++++++++++++++++ tools/mkimage.h | 1 + 11 files changed, 111 insertions(+), 3 deletions(-) create mode 100644 tools/fdt_host.h
Arrrr, I'm not wild about this, but I cannot suggest a better way. :-(
All these (trivial) touches to libfdt/* are annoying and could cause patch tracking of the dtc/libfdt source to break. I guess that is the risk we live with unless or until someone comes up with a better way. :-(
Best regards, gvb
Well, the obvious approach would be to format up the patches and submit them to the linuxppc-dev@ozlabs.org list along with an explanation as to why the libfdt changes are needed, make sure they are compatible with the kernel code as well. We'll see how badly Gibson chokes, and if the libfdt maintainer takes 'em. :-)
jdl

From: David Gibson david@gibson.dropbear.id.au
This patch adds an fdt_next_node() function which can be used to iterate through nodes of the tree while keeping track of depth. This function is used to simplify the iteration code in a lot of other functions, and is also exported for use by library users.
Signed-off-by: David Gibson david@gibson.dropbear.id.au ---
include/libfdt.h | 6 + libfdt/fdt.c | 41 +++++++++ libfdt/fdt_ro.c | 258 ++++++++++++++++++------------------------------------ 3 files changed, 131 insertions(+), 174 deletions(-)
diff --git a/include/libfdt.h b/include/libfdt.h index 6c05236..3a64d0b 100644 --- a/include/libfdt.h +++ b/include/libfdt.h @@ -131,6 +131,12 @@ static inline void *fdt_offset_ptr_w(void *fdt, int offset, int checklen) uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset);
/**********************************************************************/ +/* Traversal functions */ +/**********************************************************************/ + +int fdt_next_node(const void *fdt, int offset, int *depth); + +/**********************************************************************/ /* General functions */ /**********************************************************************/
diff --git a/libfdt/fdt.c b/libfdt/fdt.c index 071470d..660e2c1 100644 --- a/libfdt/fdt.c +++ b/libfdt/fdt.c @@ -133,6 +133,47 @@ uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset) return tag; }
+int fdt_next_node(const void *fdt, int offset, int *depth) +{ + int nextoffset = 0; + uint32_t tag; + + if (offset >= 0) { + tag = fdt_next_tag(fdt, offset, &nextoffset); + if (tag != FDT_BEGIN_NODE) + return -FDT_ERR_BADOFFSET; + } + + do { + offset = nextoffset; + tag = fdt_next_tag(fdt, offset, &nextoffset); + + switch (tag) { + case FDT_PROP: + case FDT_NOP: + break; + + case FDT_BEGIN_NODE: + if (depth) + (*depth)++; + break; + + case FDT_END_NODE: + if (depth) + (*depth)--; + break; + + case FDT_END: + return -FDT_ERR_NOTFOUND; + + default: + return -FDT_ERR_BADSTRUCTURE; + } + } while (tag != FDT_BEGIN_NODE); + + return offset; +} + const char *_fdt_find_string(const char *strtab, int tabsize, const char *s) { int len = strlen(s) + 1; diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c index 1ae3a55..031a15f 100644 --- a/libfdt/fdt_ro.c +++ b/libfdt/fdt_ro.c @@ -69,7 +69,7 @@ static int nodename_eq(const void *fdt, int offset, const char *s, int len) { - const char *p = fdt_offset_ptr(fdt, offset, len+1); + const char *p = fdt_offset_ptr(fdt, offset + FDT_TAGSIZE, len+1);
if (! p) /* short match */ @@ -108,50 +108,24 @@ int fdt_num_mem_rsv(const void *fdt) return i; }
-int fdt_subnode_offset_namelen(const void *fdt, int parentoffset, +int fdt_subnode_offset_namelen(const void *fdt, int offset, const char *name, int namelen) { - int level = 0; - uint32_t tag; - int offset, nextoffset; + int depth;
CHECK_HEADER(fdt);
- tag = fdt_next_tag(fdt, parentoffset, &nextoffset); - if (tag != FDT_BEGIN_NODE) - return -FDT_ERR_BADOFFSET; - - do { - offset = nextoffset; - tag = fdt_next_tag(fdt, offset, &nextoffset); - - switch (tag) { - case FDT_END: - return -FDT_ERR_TRUNCATED; - - case FDT_BEGIN_NODE: - level++; - if (level != 1) - continue; - if (nodename_eq(fdt, offset+FDT_TAGSIZE, name, namelen)) - /* Found it! */ - return offset; - break; - - case FDT_END_NODE: - level--; - break; - - case FDT_PROP: - case FDT_NOP: - break; - - default: - return -FDT_ERR_BADSTRUCTURE; - } - } while (level >= 0); + for (depth = 0; + offset >= 0; + offset = fdt_next_node(fdt, offset, &depth)) { + if (depth < 0) + return -FDT_ERR_NOTFOUND; + else if ((depth == 1) + && nodename_eq(fdt, offset, name, namelen)) + return offset; + }
- return -FDT_ERR_NOTFOUND; + return offset; /* error */ }
int fdt_subnode_offset(const void *fdt, int parentoffset, @@ -311,76 +285,61 @@ uint32_t fdt_get_phandle(const void *fdt, int nodeoffset)
int fdt_get_path(const void *fdt, int nodeoffset, char *buf, int buflen) { - uint32_t tag; - int p = 0, overflow = 0; - int offset, nextoffset, namelen; + int pdepth = 0, p = 0; + int offset, depth, namelen; const char *name;
CHECK_HEADER(fdt);
- tag = fdt_next_tag(fdt, 0, &nextoffset); - if (tag != FDT_BEGIN_NODE) - return -FDT_ERR_BADSTRUCTURE; - if (buflen < 2) return -FDT_ERR_NOSPACE; - buf[0] = '/'; - p = 1;
- while (nextoffset <= nodeoffset) { - offset = nextoffset; - tag = fdt_next_tag(fdt, offset, &nextoffset); - switch (tag) { - case FDT_END: - return -FDT_ERR_BADOFFSET; + for (offset = 0, depth = 0; + (offset >= 0) && (offset <= nodeoffset); + offset = fdt_next_node(fdt, offset, &depth)) { + if (pdepth < depth) + continue; /* overflowed buffer */
- case FDT_BEGIN_NODE: - name = fdt_get_name(fdt, offset, &namelen); - if (!name) - return namelen; - if (overflow || ((p + namelen + 1) > buflen)) { - overflow++; - break; - } + while (pdepth > depth) { + do { + p--; + } while (buf[p-1] != '/'); + pdepth--; + } + + name = fdt_get_name(fdt, offset, &namelen); + if (!name) + return namelen; + if ((p + namelen + 1) <= buflen) { memcpy(buf + p, name, namelen); p += namelen; buf[p++] = '/'; - break; - - case FDT_END_NODE: - if (overflow) { - overflow--; - break; - } - do { - p--; - } while (buf[p-1] != '/'); - break; + pdepth++; + }
- case FDT_PROP: - case FDT_NOP: - break; + if (offset == nodeoffset) { + if (pdepth < (depth + 1)) + return -FDT_ERR_NOSPACE;
- default: - return -FDT_ERR_BADSTRUCTURE; + if (p > 1) /* special case so that root path is "/", not "" */ + p--; + buf[p] = '\0'; + return p; } }
- if (overflow) - return -FDT_ERR_NOSPACE; + if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0)) + return -FDT_ERR_BADOFFSET; + else if (offset == -FDT_ERR_BADOFFSET) + return -FDT_ERR_BADSTRUCTURE;
- if (p > 1) /* special case so that root path is "/", not "" */ - p--; - buf[p] = '\0'; - return p; + return offset; /* error from fdt_next_node() */ }
int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset, int supernodedepth, int *nodedepth) { - int level = -1; - uint32_t tag; - int offset, nextoffset = 0; + int offset, depth; int supernodeoffset = -FDT_ERR_INTERNAL;
CHECK_HEADER(fdt); @@ -388,38 +347,29 @@ int fdt_supernode_atdepth_offset(const void *fdt, int nodeoffset, if (supernodedepth < 0) return -FDT_ERR_NOTFOUND;
- do { - offset = nextoffset; - tag = fdt_next_tag(fdt, offset, &nextoffset); - switch (tag) { - case FDT_END: - return -FDT_ERR_BADOFFSET; - - case FDT_BEGIN_NODE: - level++; - if (level == supernodedepth) - supernodeoffset = offset; - break; - - case FDT_END_NODE: - level--; - break; + for (offset = 0, depth = 0; + (offset >= 0) && (offset <= nodeoffset); + offset = fdt_next_node(fdt, offset, &depth)) { + if (depth == supernodedepth) + supernodeoffset = offset;
- case FDT_PROP: - case FDT_NOP: - break; + if (offset == nodeoffset) { + if (nodedepth) + *nodedepth = depth;
- default: - return -FDT_ERR_BADSTRUCTURE; + if (supernodedepth > depth) + return -FDT_ERR_NOTFOUND; + else + return supernodeoffset; } - } while (offset < nodeoffset); + }
- if (nodedepth) - *nodedepth = level; + if ((offset == -FDT_ERR_NOTFOUND) || (offset >= 0)) + return -FDT_ERR_BADOFFSET; + else if (offset == -FDT_ERR_BADOFFSET) + return -FDT_ERR_BADSTRUCTURE;
- if (supernodedepth > level) - return -FDT_ERR_NOTFOUND; - return supernodeoffset; + return offset; /* error from fdt_next_node() */ }
int fdt_node_depth(const void *fdt, int nodeoffset) @@ -447,51 +397,27 @@ int fdt_node_offset_by_prop_value(const void *fdt, int startoffset, const char *propname, const void *propval, int proplen) { - uint32_t tag; - int offset, nextoffset; + int offset; const void *val; int len;
CHECK_HEADER(fdt);
- if (startoffset >= 0) { - tag = fdt_next_tag(fdt, startoffset, &nextoffset); - if (tag != FDT_BEGIN_NODE) - return -FDT_ERR_BADOFFSET; - } else { - nextoffset = 0; - } - /* FIXME: The algorithm here is pretty horrible: we scan each * property of a node in fdt_getprop(), then if that didn't * find what we want, we scan over them again making our way * to the next node. Still it's the easiest to implement * approach; performance can come later. */ - do { - offset = nextoffset; - tag = fdt_next_tag(fdt, offset, &nextoffset); - - switch (tag) { - case FDT_BEGIN_NODE: - val = fdt_getprop(fdt, offset, propname, &len); - if (val - && (len == proplen) - && (memcmp(val, propval, len) == 0)) - return offset; - break; - - case FDT_PROP: - case FDT_END: - case FDT_END_NODE: - case FDT_NOP: - break; - - default: - return -FDT_ERR_BADSTRUCTURE; - } - } while (tag != FDT_END); + for (offset = fdt_next_node(fdt, startoffset, NULL); + offset >= 0; + offset = fdt_next_node(fdt, offset, NULL)) { + val = fdt_getprop(fdt, offset, propname, &len); + if (val && (len == proplen) + && (memcmp(val, propval, len) == 0)) + return offset; + }
- return -FDT_ERR_NOTFOUND; + return offset; /* error from fdt_next_node() */ }
int fdt_node_offset_by_phandle(const void *fdt, uint32_t phandle) @@ -557,31 +483,15 @@ int fdt_node_offset_by_compatible(const void *fdt, int startoffset, * that didn't find what we want, we scan over them again * making our way to the next node. Still it's the easiest to * implement approach; performance can come later. */ - do { - offset = nextoffset; - tag = fdt_next_tag(fdt, offset, &nextoffset); - - switch (tag) { - case FDT_BEGIN_NODE: - err = fdt_node_check_compatible(fdt, offset, - compatible); - if ((err < 0) - && (err != -FDT_ERR_NOTFOUND)) - return err; - else if (err == 0) - return offset; - break; - - case FDT_PROP: - case FDT_END: - case FDT_END_NODE: - case FDT_NOP: - break; - - default: - return -FDT_ERR_BADSTRUCTURE; - } - } while (tag != FDT_END); + for (offset = fdt_next_node(fdt, startoffset, NULL); + offset >= 0; + offset = fdt_next_node(fdt, offset, NULL)) { + err = fdt_node_check_compatible(fdt, offset, compatible); + if ((err < 0) && (err != -FDT_ERR_NOTFOUND)) + return err; + else if (err == 0) + return offset; + }
- return -FDT_ERR_NOTFOUND; + return offset; /* error from fdt_next_node() */ }

Marian Balakowicz wrote:
From: David Gibson david@gibson.dropbear.id.au
This patch adds an fdt_next_node() function which can be used to iterate through nodes of the tree while keeping track of depth. This function is used to simplify the iteration code in a lot of other functions, and is also exported for use by library users.
Signed-off-by: David Gibson david@gibson.dropbear.id.au
include/libfdt.h | 6 + libfdt/fdt.c | 41 +++++++++ libfdt/fdt_ro.c | 258 ++++++++++++++++++------------------------------------ 3 files changed, 131 insertions(+), 174 deletions(-)
Hi Marian,
I've picked up this patchset, along with two other libfdt patchsets, in the u-boot-fdt subrepo. I am holding back the changes for the next merge window.
Did you cherry-pick this out of the u-boot-fdt subrepo or apply it yourself from David's patch?
I don't know how git will react if we both apply the same patch, possibly differently. (I applied it by hand editing the patch to change the include/libfdt.h path and then using git-am to apply it. I presume you either cherry-picked my application or did the same.)
Best regards, gvb

Hi Jerry,
Jerry Van Baren wrote:
Marian Balakowicz wrote:
From: David Gibson david@gibson.dropbear.id.au
This patch adds an fdt_next_node() function which can be used to iterate through nodes of the tree while keeping track of depth. This function is used to simplify the iteration code in a lot of other functions, and is also exported for use by library users.
Signed-off-by: David Gibson david@gibson.dropbear.id.au
include/libfdt.h | 6 + libfdt/fdt.c | 41 +++++++++ libfdt/fdt_ro.c | 258 ++++++++++++++++++------------------------------------ 3 files changed, 131 insertions(+), 174 deletions(-)
...
I've picked up this patchset, along with two other libfdt patchsets, in the u-boot-fdt subrepo. I am holding back the changes for the next merge window.
Did you cherry-pick this out of the u-boot-fdt subrepo or apply it yourself from David's patch?
I don't know how git will react if we both apply the same patch, possibly differently. (I applied it by hand editing the patch to change the include/libfdt.h path and then using git-am to apply it. I presume you either cherry-picked my application or did the same.)
I've seen the patch on the ml, but than noticed it's already in the custodian repo, so I took the easier approach and cherry picked from u-boot-fdt.
Cheers, m.

Marian Balakowicz wrote:
Hi Jerry,
Jerry Van Baren wrote:
[snip]
Did you cherry-pick this out of the u-boot-fdt subrepo or apply it yourself from David's patch?
I don't know how git will react if we both apply the same patch, possibly differently. (I applied it by hand editing the patch to change the include/libfdt.h path and then using git-am to apply it. I presume you either cherry-picked my application or did the same.)
I've seen the patch on the ml, but than noticed it's already in the custodian repo, so I took the easier approach and cherry picked from u-boot-fdt.
Cheers, m.
Excellent. Git should have no problem sorting that out (I've swapped patches with Kim with no problems).
Best regards, gvb

Do not use global fdt blob pointer, calculate blob size from routine argument blob pointer.
Signed-off-by: Marian Balakowicz m8@semihalf.com ---
lib_ppc/bootm.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/lib_ppc/bootm.c b/lib_ppc/bootm.c index 8974ccd..7977157 100644 --- a/lib_ppc/bootm.c +++ b/lib_ppc/bootm.c @@ -557,7 +557,7 @@ static int boot_relocate_fdt (struct lmb *lmb, ulong bootmap_base, if (fdt_blob >= (char *)CFG_BOOTMAPSZ) relocate = 1;
- of_len = be32_to_cpu (fdt_totalsize (fdt)); + of_len = be32_to_cpu (fdt_totalsize (fdt_blob));
/* move flattend device tree if needed */ if (relocate) {

Add FDT-based functions for handling new format component images, configurations, node operations, property get/set, etc.
fit_ - routines handling global new format uImage operations like get/set top level property, process all nodes, etc. fit_image_ - routines handling component images subnodes fit_conf_ - routines handling configurations node
Signed-off-by: Bartlomiej Sieka tur@semihalf.com Signed-off-by: Marian Balakowicz m8@semihalf.com ---
common/image.c | 1181 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/image.h | 107 +++++ tools/mkimage.h | 8 3 files changed, 1291 insertions(+), 5 deletions(-)
diff --git a/common/image.c b/common/image.c index 3911b2f..adf9fbc 100644 --- a/common/image.c +++ b/common/image.c @@ -45,10 +45,13 @@ #include <rtc.h> #endif
+#include <image.h> + #if defined(CONFIG_FIT) #include <fdt.h> #include <libfdt.h> #include <fdt_support.h> +#include <sha1.h> #endif
#ifdef CONFIG_CMD_BDI @@ -62,9 +65,9 @@ static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag, ulong rd_addr, uint8_t arch, int verify); #else #include "mkimage.h" -#endif /* !USE_HOSTCC*/ - +#include <time.h> #include <image.h> +#endif /* !USE_HOSTCC*/
typedef struct table_entry { int id; /* as defined in image.h */ @@ -306,6 +309,18 @@ static void image_print_type (image_header_t *hdr) printf ("%s %s %s (%s)\n", arch, os, type, comp); }
+/** + * __image_print_contents - prints out the contents of the legacy format image + * @hdr: pointer to the legacy format image header + * @p: pointer to prefix string + * + * __image_print_contents() formats a multi line legacy image contents description. + * The routine prints out all header fields followed by the size/offset data + * for MULTI/SCRIPT images. + * + * returns: + * no returned results + */ static void __image_print_contents (image_header_t *hdr, const char *p) { printf ("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name (hdr)); @@ -1040,11 +1055,13 @@ int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base) return 0; } #endif /* CONFIG_PPC || CONFIG_M68K */ +#endif /* !USE_HOSTCC */
#if defined(CONFIG_FIT) /*****************************************************************************/ /* New uImage format routines */ /*****************************************************************************/ +#ifndef USE_HOSTCC static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr, ulong *addr, const char **name) { @@ -1117,6 +1134,1164 @@ inline int fit_parse_subimage (const char *spec, ulong addr_curr, { return fit_parse_spec (spec, ':', addr_curr, addr, image_name); } +#endif /* !USE_HOSTCC */ + +static void fit_get_debug (const void *fit, int noffset, + char *prop_name, int err) +{ + debug ("Can't get '%s' property from FIT 0x%08lx, " + "node: offset %d, name %s (%s)\n", + prop_name, (ulong)fit, noffset, + fdt_get_name (fit, noffset, NULL), + fdt_strerror (err)); +} + +/** + * __fit_print_contents - prints out the contents of the FIT format image + * @fit: pointer to the FIT format image header + * @p: pointer to prefix string + * + * __fit_print_contents() formats a multi line FIT image contents description. + * The routine prints out FIT image properties (root node level) follwed by + * the details of each component image. + * + * returns: + * no returned results + */ +static void __fit_print_contents (const void *fit, const char *p) +{ + char *desc; + char *uname; + int images_noffset; + int confs_noffset; + int noffset; + int ndepth; + int count = 0; + int ret; +#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) + time_t timestamp; +#endif + + /* Root node properties */ + ret = fit_get_desc (fit, 0, &desc); + printf ("%sFIT description: ", p); + if (ret) + printf ("description unavailable\n"); + else + printf ("%s\n", desc); + +#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC) + ret = fit_get_timestamp (fit, 0, ×tamp); + printf ("%sCreated: ", p); + if (ret) + printf ("timestamp unavailable\n"); + else + genimg_print_time (timestamp); +#endif + + /* Find images parent node offset */ + images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH); + if (images_noffset < 0) { + printf ("Can't find images parent node '%s' (%s)\n", + FIT_IMAGES_PATH, fdt_strerror (images_noffset)); + return; + } + + /* Process its subnodes, print out component images details */ + for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth); + (noffset >= 0) && (ndepth > 0); + noffset = fdt_next_node (fit, noffset, &ndepth)) { + if (ndepth == 1) { + /* + * Direct child node of the images parent node, + * i.e. component image node. + */ + printf ("%s Image %u (%s)\n", p, count++, + fdt_get_name(fit, noffset, NULL)); + + fit_image_print (fit, noffset, p); + } + } + + /* Find configurations parent node offset */ + confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH); + if (confs_noffset < 0) { + debug ("Can't get configurations parent node '%s' (%s)\n", + FIT_CONFS_PATH, fdt_strerror (confs_noffset)); + return; + } + + /* get default configuration unit name from default property */ + uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL); + if (uname) + printf ("%s Default Configuration: '%s'\n", p, uname); + + /* Process its subnodes, print out configurations details */ + for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth); + (noffset >= 0) && (ndepth > 0); + noffset = fdt_next_node (fit, noffset, &ndepth)) { + if (ndepth == 1) { + /* + * Direct child node of the configurations parent node, + * i.e. configuration node. + */ + printf ("%s Configuration %u (%s)\n", p, count++, + fdt_get_name(fit, noffset, NULL)); + + fit_conf_print (fit, noffset, p); + } + } +} + +inline void fit_print_contents (const void *fit) +{ + __fit_print_contents (fit, " "); +} + +inline void fit_print_contents_noindent (const void *fit) +{ + __fit_print_contents (fit, ""); +}
+/** + * fit_image_print - prints out the FIT component image details + * @fit: pointer to the FIT format image header + * @image_noffset: offset of the component image node + * @p: pointer to prefix string + * + * fit_image_print() lists all mandatory properies for the processed component + * image. If present, hash nodes are printed out as well. + * + * returns: + * no returned results + */ +void fit_image_print (const void *fit, int image_noffset, const char *p) +{ + char *desc; + uint8_t type, arch, os, comp; + size_t size; + uint32_t load, entry; + const void *data; + int noffset; + int ndepth; + int ret; + + /* Mandatory properties */ + ret = fit_get_desc (fit, image_noffset, &desc); + printf ("%s Description: ", p); + if (ret) + printf ("description unavailable\n"); + else + printf ("%s\n", desc); + + fit_image_get_type (fit, image_noffset, &type); + printf ("%s Type: %s\n", p, genimg_get_type_name (type)); + + fit_image_get_comp (fit, image_noffset, &comp); + printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp)); + + ret = fit_image_get_data (fit, image_noffset, &data, &size); + printf ("%s Data Size: ", p); + if (ret) + printf ("size unavailable\n"); + else + genimg_print_size (size); + + /* Remaining, type dependent properties */ + if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) || + (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) || + (type == IH_TYPE_FLATDT)) { + fit_image_get_arch (fit, image_noffset, &arch); + printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch)); + } + + if (type == IH_TYPE_KERNEL) { + fit_image_get_os (fit, image_noffset, &os); + printf ("%s OS: %s\n", p, genimg_get_os_name (os)); + } + + if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) { + ret = fit_image_get_load (fit, image_noffset, &load); + printf ("%s Load Address: ", p); + if (ret) + printf ("load address unavailable\n"); + else + printf ("0x%08X\n", load); + + fit_image_get_entry (fit, image_noffset, &entry); + printf ("%s Entry Point: ", p); + if (ret) + printf ("entry point unavailable\n"); + else + printf ("0x%08X\n", entry); + } + + /* Process all hash subnodes of the component image node */ + for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth); + (noffset >= 0) && (ndepth > 0); + noffset = fdt_next_node (fit, noffset, &ndepth)) { + if (ndepth == 1) { + /* Direct child node of the component image node */ + fit_image_print_hash (fit, noffset, p); + } + } +} + +/** + * fit_image_print_hash - prints out the hash node details + * @fit: pointer to the FIT format image header + * @noffset: offset of the hash node + * @p: pointer to prefix string + * + * fit_image_print_hash() lists properies for the processed hash node + * + * returns: + * no returned results + */ +void fit_image_print_hash (const void *fit, int noffset, const char *p) +{ + char *algo; + uint8_t *value; + int value_len; + int i, ret; + + /* + * Check subnode name, must be equal to "hash". + * Multiple hash nodes require unique unit node + * names, e.g. hash@1, hash@2, etc. + */ + if (strncmp (fdt_get_name(fit, noffset, NULL), + FIT_HASH_NODENAME, + strlen(FIT_HASH_NODENAME)) != 0) + return; + + debug ("%s Hash node: '%s'\n", p, + fdt_get_name (fit, noffset, NULL)); + + printf ("%s Hash algo: ", p); + if (fit_image_hash_get_algo (fit, noffset, &algo)) { + printf ("invalid/unsupported\n"); + return; + } + printf ("%s\n", algo); + + ret = fit_image_hash_get_value (fit, noffset, &value, + &value_len); + printf ("%s Hash value: ", p); + if (ret) { + printf ("unavailable\n"); + } else { + for (i = 0; i < value_len; i++) + printf ("%02x", value[i]); + printf ("\n"); + } + + debug ("%s Hash len: %d\n", p, value_len); +} + +/** + * fit_get_end - get FIT image end + * @fit: pointer to the FIT format image header + * + * returns: + * the end address of the FIT image in memory + */ +ulong fit_get_end (const void *fit) +{ + return (ulong)fit + fdt_totalsize (fit); +} + +/** + * fit_get_desc - get node description property + * @fit: pointer to the FIT format image header + * @noffset: node offset + * @desc: double pointer to the char, will hold pointer to the descrption + * + * fit_get_desc() reads description property from a given node, if + * description is found pointer to it is returened in third call argument. + * + * returns: + * 0, on success + * -1, on failure + */ +int fit_get_desc (const void *fit, int noffset, char **desc) +{ + int len; + + *desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len); + if (*desc == NULL) { + fit_get_debug (fit, noffset, FIT_DESC_PROP, len); + return -1; + } + + return 0; +} + +/** + * fit_get_timestamp - get node timestamp property + * @fit: pointer to the FIT format image header + * @noffset: node offset + * @timestamp: pointer to the time_t, will hold read timestamp + * + * fit_get_timestamp() reads timestamp poperty from given node, if timestamp + * is found and has a correct size its value is retured in third call + * argument. + * + * returns: + * 0, on success + * -1, on property read failure + * -2, on wrong timestamp size + */ +int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp) +{ + int len; + const void *data; + + data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len); + if (data == NULL) { + fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len); + return -1; + } + if (len != sizeof (uint32_t)) { + debug ("FIT timestamp with incorrect size of (%u)\n", len); + return -2; + } + + *timestamp = uimage_to_cpu (*((uint32_t *)data)); + return 0; +} + +/** + * fit_image_get_node - get node offset for component image of a given unit name + * @fit: pointer to the FIT format image header + * @image_uname: component image node unit name + * + * fit_image_get_node() finds a component image (withing the '/images' + * node) of a provided unit name. If image is found its node offset is + * returned to the caller. + * + * returns: + * image node offset when found (>=0) + * negative number on failure (FDT_ERR_* code) + */ +int fit_image_get_node (const void *fit, const char *image_uname) +{ + int noffset, images_noffset; + + images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH); + if (images_noffset < 0) { + debug ("Can't find images parent node '%s' (%s)\n", + FIT_IMAGES_PATH, fdt_strerror (images_noffset)); + return images_noffset; + } + + noffset = fdt_subnode_offset (fit, images_noffset, image_uname); + if (noffset < 0) { + debug ("Can't get node offset for image unit name: '%s' (%s)\n", + image_uname, fdt_strerror (noffset)); + } + + return noffset; +} + +/** + * fit_image_get_os - get os id for a given component image node + * @fit: pointer to the FIT format image header + * @noffset: component image node offset + * @os: pointer to the uint8_t, will hold os numeric id + * + * fit_image_get_os() finds os property in a given component image node. + * If the property is found, its (string) value is translated to the numeric + * id which is returned to the caller. + * + * returns: + * 0, on success + * -1, on failure + */ +int fit_image_get_os (const void *fit, int noffset, uint8_t *os) +{ + int len; + const void *data; + + /* Get OS name from property data */ + data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len); + if (data == NULL) { + fit_get_debug (fit, noffset, FIT_OS_PROP, len); + *os = -1; + return -1; + } + + /* Translate OS name to id */ + *os = genimg_get_os_id (data); + return 0; +} + +/** + * fit_image_get_arch - get arch id for a given component image node + * @fit: pointer to the FIT format image header + * @noffset: component image node offset + * @arch: pointer to the uint8_t, will hold arch numeric id + * + * fit_image_get_arch() finds arch property in a given component image node. + * If the property is found, its (string) value is translated to the numeric + * id which is returned to the caller. + * + * returns: + * 0, on success + * -1, on failure + */ +int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch) +{ + int len; + const void *data; + + /* Get architecture name from property data */ + data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len); + if (data == NULL) { + fit_get_debug (fit, noffset, FIT_ARCH_PROP, len); + *arch = -1; + return -1; + } + + /* Translate architecture name to id */ + *arch = genimg_get_arch_id (data); + return 0; +} + +/** + * fit_image_get_type - get type id for a given component image node + * @fit: pointer to the FIT format image header + * @noffset: component image node offset + * @type: pointer to the uint8_t, will hold type numeric id + * + * fit_image_get_type() finds type property in a given component image node. + * If the property is found, its (string) value is translated to the numeric + * id which is returned to the caller. + * + * returns: + * 0, on success + * -1, on failure + */ +int fit_image_get_type (const void *fit, int noffset, uint8_t *type) +{ + int len; + const void *data; + + /* Get image type name from property data */ + data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len); + if (data == NULL) { + fit_get_debug (fit, noffset, FIT_TYPE_PROP, len); + *type = -1; + return -1; + } + + /* Translate image type name to id */ + *type = genimg_get_type_id (data); + return 0; +} + +/** + * fit_image_get_comp - get comp id for a given component image node + * @fit: pointer to the FIT format image header + * @noffset: component image node offset + * @comp: pointer to the uint8_t, will hold comp numeric id + * + * fit_image_get_comp() finds comp property in a given component image node. + * If the property is found, its (string) value is translated to the numeric + * id which is returned to the caller. + * + * returns: + * 0, on success + * -1, on failure + */ +int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp) +{ + int len; + const void *data; + + /* Get compression name from property data */ + data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len); + if (data == NULL) { + fit_get_debug (fit, noffset, FIT_COMP_PROP, len); + *comp = -1; + return -1; + } + + /* Translate compression name to id */ + *comp = genimg_get_comp_id (data); + return 0; +} + +/** + * fit_image_get_load - get load address property for a given component image node + * @fit: pointer to the FIT format image header + * @noffset: component image node offset + * @load: pointer to the uint32_t, will hold load address + * + * fit_image_get_load() finds load address property in a given component image node. + * If the property is found, its value is returned to the caller. + * + * returns: + * 0, on success + * -1, on failure + */ +int fit_image_get_load (const void *fit, int noffset, uint32_t *load) +{ + int len; + const void *data; + + data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len); + if (data == NULL) { + fit_get_debug (fit, noffset, FIT_LOAD_PROP, len); + return -1; + } + + *load = uimage_to_cpu (*((uint32_t *)data)); + return 0; +} + +/** + * fit_image_get_entry - get entry point address property for a given component image node + * @fit: pointer to the FIT format image header + * @noffset: component image node offset + * @entry: pointer to the uint32_t, will hold entry point address + * + * fit_image_get_entry() finds entry point address property in a given component image node. + * If the property is found, its value is returned to the caller. + * + * returns: + * 0, on success + * -1, on failure + */ +int fit_image_get_entry (const void *fit, int noffset, uint32_t *entry) +{ + int len; + const void *data; + + data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len); + if (data == NULL) { + fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len); + return -1; + } + + *entry = uimage_to_cpu (*((uint32_t *)data)); + return 0; +} + +/** + * fit_image_get_data - get data property and its size for a given component image node + * @fit: pointer to the FIT format image header + * @noffset: component image node offset + * @data: double pointer to void, will hold data property's data address + * @size: pointer to size_t, will hold data property's data size + * + * fit_image_get_data() finds data property in a given component image node. + * If the property is found its data start address and size are returned to + * the caller. + * + * returns: + * 0, on success + * -1, on failure + */ +int fit_image_get_data (const void *fit, int noffset, + const void **data, size_t *size) +{ + int len; + + *data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len); + if (*data == NULL) { + fit_get_debug (fit, noffset, FIT_DATA_PROP, len); + *size = 0; + return -1; + } + + *size = len; + return 0; +} + +/** + * fit_image_hash_get_algo - get hash algorithm name + * @fit: pointer to the FIT format image header + * @noffset: hash node offset + * @algo: double pointer to char, will hold pointer to the algorithm name + * + * fit_image_hash_get_algo() finds hash algorithm property in a given hash node. + * If the property is found its data start address is returned to the caller. + * + * returns: + * 0, on success + * -1, on failure + */ +int fit_image_hash_get_algo (const void *fit, int noffset, char **algo) +{ + int len; + + *algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len); + if (*algo == NULL) { + fit_get_debug (fit, noffset, FIT_ALGO_PROP, len); + return -1; + } + + return 0; +} + +/** + * fit_image_hash_get_value - get hash value and length + * @fit: pointer to the FIT format image header + * @noffset: hash node offset + * @value: double pointer to uint8_t, will hold address of a hash value data + * @value_len: pointer to an int, will hold hash data length + * + * fit_image_hash_get_value() finds hash value property in a given hash node. + * If the property is found its data start address and size are returned to + * the caller. + * + * returns: + * 0, on success + * -1, on failure + */ +int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value, + int *value_len) +{ + int len; + + *value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len); + if (*value == NULL) { + fit_get_debug (fit, noffset, FIT_VALUE_PROP, len); + *value_len = 0; + return -1; + } + + *value_len = len; + return 0; +} + +/** + * fit_set_timestamp - set node timestamp property + * @fit: pointer to the FIT format image header + * @noffset: node offset + * @timestamp: timestamp value to be set + * + * fit_set_timestamp() attempts to set timestamp property in the requested + * node and returns operation status to the caller. + * + * returns: + * 0, on success + * -1, on property read failure + */ +int fit_set_timestamp (void *fit, int noffset, time_t timestamp) +{ + uint32_t t; + int ret; + + t = cpu_to_uimage (timestamp); + ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t, + sizeof (uint32_t)); + if (ret) { + printf ("Can't set '%s' property for '%s' node (%s)\n", + FIT_TIMESTAMP_PROP, fdt_get_name (fit, noffset, NULL), + fdt_strerror (ret)); + return -1; + } + + return 0; +} + +/** + * calculate_hash - calculate and return hash for provided input data + * @data: pointer to the input data + * @data_len: data length + * @algo: requested hash algorithm + * @value: pointer to the char, will hold hash value data (caller must + * allocate enough free space) + * value_len: length of the calculated hash + * + * calculate_hash() computes input data hash according to the requested algorithm. + * Resulting hash value is placed in caller provided 'value' buffer, length + * of the calculated hash is returned via value_len pointer argument. + * + * returns: + * 0, on success + * -1, when algo is unsupported + */ +static int calculate_hash (const void *data, int data_len, const char *algo, + uint8_t *value, int *value_len) +{ + if (strcmp (algo, "crc32") == 0 ) { + *((uint32_t *)value) = crc32 (0, data, data_len); + *((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value)); + *value_len = 4; + } else if (strcmp (algo, "sha1") == 0 ) { + sha1_csum ((unsigned char *) data, data_len, + (unsigned char *) value); + *value_len = 20; + } else if (strcmp (algo, "md5") == 0 ) { + printf ("MD5 not supported\n"); + *value_len = 0; + } else { + debug ("Unsupported hash alogrithm\n"); + return -1; + } + return 0; +} + +#ifdef USE_HOSTCC +/** + * fit_set_hashes - process FIT component image nodes and calculate hashes + * @fit: pointer to the FIT format image header + * + * fit_set_hashes() adds hash values for all component images in the FIT blob. + * Hashes are calculated for all component images which have hash subnodes + * with algorithm property set to one of the supported hash algorithms. + * + * returns + * 0, on success + * libfdt error code, on failure + */ +int fit_set_hashes (void *fit) +{ + int images_noffset; + int noffset; + int ndepth; + int ret; + + /* Find images parent node offset */ + images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH); + if (images_noffset < 0) { + printf ("Can't find images parent node '%s' (%s)\n", + FIT_IMAGES_PATH, fdt_strerror (images_noffset)); + return images_noffset; + } + + /* Process its subnodes, print out component images details */ + for (ndepth = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth); + (noffset >= 0) && (ndepth > 0); + noffset = fdt_next_node (fit, noffset, &ndepth)) { + if (ndepth == 1) { + /* + * Direct child node of the images parent node, + * i.e. component image node. + */ + ret = fit_image_set_hashes (fit, noffset); + if (ret) + return ret; + } + } + + return 0; +} + +/** + * fit_image_set_hashes - calculate/set hashes for given component image node + * @fit: pointer to the FIT format image header + * @image_noffset: requested component image node + * + * fit_image_set_hashes() adds hash values for an component image node. All + * existing hash subnodes are checked, if algorithm property is set to one of + * the supported hash algorithms, hash value is computed and corresponding + * hash node property is set, for example: + * + * Input component image node structure: + * + * o image@1 (at image_noffset) + * | - data = [binary data] + * o hash@1 + * |- algo = "sha1" + * + * Output component image node structure: + * + * o image@1 (at image_noffset) + * | - data = [binary data] + * o hash@1 + * |- algo = "sha1" + * |- value = sha1(data) + * + * returns: + * 0 on sucess + * <0 on failure + */ +int fit_image_set_hashes (void *fit, int image_noffset) +{ + const void *data; + size_t size; + char *algo; + uint8_t value[FIT_MAX_HASH_LEN]; + int value_len; + int noffset; + int ndepth; + + /* Get image data and data length */ + if (fit_image_get_data (fit, image_noffset, &data, &size)) { + printf ("Can't get image data/size\n"); + return -1; + } + + /* Process all hash subnodes of the component image node */ + for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth); + (noffset >= 0) && (ndepth > 0); + noffset = fdt_next_node (fit, noffset, &ndepth)) { + if (ndepth == 1) { + /* Direct child node of the component image node */ + + /* + * Check subnode name, must be equal to "hash". + * Multiple hash nodes require unique unit node + * names, e.g. hash@1, hash@2, etc. + */ + if (strncmp (fdt_get_name(fit, noffset, NULL), + FIT_HASH_NODENAME, + strlen(FIT_HASH_NODENAME)) != 0) { + /* Not a hash subnode, skip it */ + continue; + } + + if (fit_image_hash_get_algo (fit, noffset, &algo)) { + printf ("Can't get hash algo property for " + "'%s' hash node in '%s' image node\n", + fdt_get_name (fit, noffset, NULL), + fdt_get_name (fit, image_noffset, NULL)); + return -1; + } + + if (calculate_hash (data, size, algo, value, &value_len)) { + printf ("Unsupported hash algorithm (%s) for " + "'%s' hash node in '%s' image node\n", + algo, fdt_get_name (fit, noffset, NULL), + fdt_get_name (fit, image_noffset, NULL)); + return -1; + } + + if (fit_image_hash_set_value (fit, noffset, value, + value_len)) { + printf ("Can't set hash value for " + "'%s' hash node in '%s' image node\n", + fdt_get_name (fit, noffset, NULL), + fdt_get_name (fit, image_noffset, NULL)); + return -1; + } + } + } + + return 0; +} + +/** + * fit_image_hash_set_value - set hash value in requested has node + * @fit: pointer to the FIT format image header + * @noffset: hash node offset + * @value: hash value to be set + * @value_len: hash value length + * + * fit_image_hash_set_value() attempts to set hash value in a node at offset + * given and returns operation status to the caller. + * + * returns + * 0, on success + * -1, on failure + */ +int fit_image_hash_set_value (void *fit, int noffset, uint8_t *value, + int value_len) +{ + int ret; + + ret = fdt_setprop (fit, noffset, FIT_VALUE_PROP, value, value_len); + if (ret) { + printf ("Can't set hash '%s' property for '%s' node (%s)\n", + FIT_VALUE_PROP, fdt_get_name (fit, noffset, NULL), + fdt_strerror (ret)); + return -1; + } + + return 0; +} +#endif /* USE_HOSTCC */ + +/** + * fit_image_check_hashes - verify data intergity + * @fit: pointer to the FIT format image header + * @image_noffset: component image node offset + * + * fit_image_check_hashes() goes over component image hash nodes, + * re-calculates each data hash and compares with the value stored in hash + * node. + * + * returns: + * 1, if all hashes are valid + * 0, otherwise (or on error) + */ +int fit_image_check_hashes (const void *fit, int image_noffset) +{ + const void *data; + size_t size; + char *algo; + uint8_t *fit_value; + int fit_value_len; + uint8_t value[FIT_MAX_HASH_LEN]; + int value_len; + int noffset; + int ndepth; + + /* Get image data and data length */ + if (fit_image_get_data (fit, image_noffset, &data, &size)) { + printf ("Can't get image data/size\n"); + return -1; + } + + /* Process all hash subnodes of the component image node */ + for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth); + (noffset >= 0) && (ndepth > 0); + noffset = fdt_next_node (fit, noffset, &ndepth)) { + if (ndepth == 1) { + /* Direct child node of the component image node */ + + /* + * Check subnode name, must be equal to "hash". + * Multiple hash nodes require unique unit node + * names, e.g. hash@1, hash@2, etc. + */ + if (strncmp (fdt_get_name(fit, noffset, NULL), + FIT_HASH_NODENAME, + strlen(FIT_HASH_NODENAME)) != 0) + continue; + + + if (fit_image_hash_get_algo (fit, noffset, &algo)) { + printf ("Can't get hash algo property for " + "'%s' hash node in '%s' image node\n", + fdt_get_name (fit, noffset, NULL), + fdt_get_name (fit, image_noffset, NULL)); + return -1; + } + + if (fit_image_hash_get_value (fit, noffset, &fit_value, + &fit_value_len)) { + printf ("Can't get hash value property for " + "'%s' hash node in '%s' image node\n", + fdt_get_name (fit, noffset, NULL), + fdt_get_name (fit, image_noffset, NULL)); + return 0; + } + + if (calculate_hash (data, size, algo, value, &value_len)) { + printf ("Unsupported hash algorithm (%s) for " + "'%s' hash node in '%s' image node\n", + algo, fdt_get_name (fit, noffset, NULL), + fdt_get_name (fit, image_noffset, NULL)); + return -1; + } + + if (value_len != fit_value_len) + return 0; + else if (memcmp (value, fit_value, value_len) != 0) + return 0; + } + } + + return 1; +} + +/** + * fit_image_check_arch - check whether image node is of a given arch + * @fit: pointer to the FIT format image header + * @noffset: component image node offset + * @arch: requested imagearch + * + * fit_image_check_arch() reads image arch property and compares its numeric + * id with the requested arch. Comparison result is returned to the caller. + * + * returns: + * 1 if image is of given arch + * 0 otherwise (or on error) + */ +int fit_image_check_arch (const void *fit, int noffset, uint8_t arch) +{ + uint8_t image_arch; + + if (fit_image_get_arch (fit, noffset, &image_arch)) + return 0; + return (arch == image_arch); +} + +/** + * fit_image_check_type - check whether image node is of a given type + * @fit: pointer to the FIT format image header + * @noffset: component image node offset + * @type: requested image type + * + * fit_image_check_type() reads image type property and compares its numeric + * id with the requested type. Comparison result is returned to the caller. + * + * returns: + * 1 if image is of given type + * 0 otherwise (or on error) + */ +int fit_image_check_type (const void *fit, int noffset, uint8_t type) +{ + uint8_t image_type; + + if (fit_image_get_type (fit, noffset, &image_type)) + return 0; + return (type == image_type); +} + +/** + * fit_conf_get_node - get node offset for configuration of a given unit name + * @fit: pointer to the FIT format image header + * @conf_uname: configuration node unit name + * + * fit_conf_get_node() finds a configuration (withing the '/configurations' + * parant node) of a provided unit name. If configuration is found its node offset + * is returned to the caller. + * + * When NULL is provided in second argument fit_conf_get_node() will search + * for a default configuration node instead. Default configuration node unit name + * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node. + * + * returns: + * configuration node offset when found (>=0) + * negative number on failure (FDT_ERR_* code) + */ +int fit_conf_get_node (const void *fit, const char *conf_uname) +{ + int noffset, confs_noffset; + int len; + + confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH); + if (confs_noffset < 0) { + debug ("Can't find configurations parent node '%s' (%s)\n", + FIT_CONFS_PATH, fdt_strerror (confs_noffset)); + return confs_noffset; + } + + if (conf_uname == NULL) { + /* get configuration unit name from the default property */ + conf_uname = (char *)fdt_getprop (fit, confs_noffset, FIT_DEFAULT_PROP, &len); + if (conf_uname == NULL) { + fit_get_debug (fit, confs_noffset, FIT_DEFAULT_PROP, len); + return len; + } + } + + noffset = fdt_subnode_offset (fit, confs_noffset, conf_uname); + if (noffset < 0) { + debug ("Can't get node offset for configuration unit name: '%s' (%s)\n", + conf_uname, fdt_strerror (noffset)); + } + + return noffset; +} + +static int __fit_conf_get_prop_node (const void *fit, int noffset, + const char *prop_name) +{ + char *uname; + int len; + + /* get kernel image unit name from configuration kernel property */ + uname = (char *)fdt_getprop (fit, noffset, prop_name, &len); + if (uname == NULL) + return len; + + return fit_image_get_node (fit, uname); +} + +/** + * fit_conf_get_kernel_node - get kernel image node offset that corresponds to + * a given configuration + * @fit: pointer to the FIT format image header + * @noffset: configuration node offset + * + * fit_conf_get_kernel_node() retrives kernel image node unit name from + * configuration FIT_KERNEL_PROP property and translates it to the node + * offset. + * + * returns: + * image node offset when found (>=0) + * negative number on failure (FDT_ERR_* code) + */ +int fit_conf_get_kernel_node (const void *fit, int noffset) +{ + return __fit_conf_get_prop_node (fit, noffset, FIT_KERNEL_PROP); +} + +/** + * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to + * a given configuration + * @fit: pointer to the FIT format image header + * @noffset: configuration node offset + * + * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from + * configuration FIT_KERNEL_PROP property and translates it to the node + * offset. + * + * returns: + * image node offset when found (>=0) + * negative number on failure (FDT_ERR_* code) + */ +int fit_conf_get_ramdisk_node (const void *fit, int noffset) +{ + return __fit_conf_get_prop_node (fit, noffset, FIT_RAMDISK_PROP); +} + +/** + * fit_conf_get_fdt_node - get fdt image node offset that corresponds to + * a given configuration + * @fit: pointer to the FIT format image header + * @noffset: configuration node offset + * + * fit_conf_get_fdt_node() retrives fdt image node unit name from + * configuration FIT_KERNEL_PROP property and translates it to the node + * offset. + * + * returns: + * image node offset when found (>=0) + * negative number on failure (FDT_ERR_* code) + */ +int fit_conf_get_fdt_node (const void *fit, int noffset) +{ + return __fit_conf_get_prop_node (fit, noffset, FIT_FDT_PROP); +} + +/** + * fit_conf_print - prints out the FIT configuration details + * @fit: pointer to the FIT format image header + * @conf_noffset: offset of the configuration node + * @p: pointer to prefix string + * + * fit_conf_print() lists all mandatory properies for the processed + * configuration node. + * + * returns: + * no returned results + */ +void fit_conf_print (const void *fit, int noffset, const char *p) +{ + char *desc; + char *uname; + int ret; + + /* Mandatory properties */ + ret = fit_get_desc (fit, noffset, &desc); + printf ("%s Description: ", p); + if (ret) + printf ("description unavailable\n"); + else + printf ("%s\n", desc); + + uname = (char *)fdt_getprop (fit, noffset, FIT_KERNEL_PROP, NULL); + printf ("%s Kernel: ", p); + if (uname == NULL) + printf ("description unavailable\n"); + else + printf ("%s\n", uname); + + /* Optional properties */ + uname = (char *)fdt_getprop (fit, noffset, FIT_RAMDISK_PROP, NULL); + if (uname) + printf ("%s Init Ramdisk: %s\n", p, uname); + + uname = (char *)fdt_getprop (fit, noffset, FIT_FDT_PROP, NULL); + if (uname) + printf ("%s FDT: %s\n", p, uname); +} #endif /* CONFIG_FIT */ -#endif /* !USE_HOSTCC */ diff --git a/include/image.h b/include/image.h index ed79552..b2221a2 100644 --- a/include/image.h +++ b/include/image.h @@ -40,6 +40,7 @@ #include <lmb.h> #include <linux/string.h> #include <asm/u-boot.h> +#endif /* USE_HOSTCC */
/* new uImage format support enabled by default */ #define CONFIG_FIT 1 @@ -51,7 +52,6 @@ #if defined(CONFIG_FIT) && !defined(CONFIG_OF_LIBFDT) #error "CONFIG_OF_LIBFDT not enabled, required by CONFIG_FIT!" #endif -#endif /* USE_HOSTCC */
/* * Operating System Codes @@ -412,16 +412,120 @@ static inline int image_check_target_arch (image_header_t *hdr)
return 1; } +#endif /* USE_HOSTCC */
/*******************************************************************/ /* New uImage format specific code (prefixed with fit_) */ /*******************************************************************/ #if defined(CONFIG_FIT) + +#define FIT_IMAGES_PATH "/images" +#define FIT_CONFS_PATH "/configurations" + +/* hash node */ +#define FIT_HASH_NODENAME "hash" +#define FIT_ALGO_PROP "algo" +#define FIT_VALUE_PROP "value" + +/* image node */ +#define FIT_DATA_PROP "data" +#define FIT_TIMESTAMP_PROP "timestamp" +#define FIT_DESC_PROP "description" +#define FIT_ARCH_PROP "arch" +#define FIT_TYPE_PROP "type" +#define FIT_OS_PROP "os" +#define FIT_COMP_PROP "compression" +#define FIT_ENTRY_PROP "entry" +#define FIT_LOAD_PROP "load" + +/* configuration node */ +#define FIT_KERNEL_PROP "kernel" +#define FIT_RAMDISK_PROP "ramdisk" +#define FIT_FDT_PROP "fdt" +#define FIT_DEFAULT_PROP "default" + +#define FIT_MAX_HASH_LEN 20 /* max(crc32_len(4), sha1_len(20)) */ + +/* cmdline argument format parsing */ inline int fit_parse_conf (const char *spec, ulong addr_curr, ulong *addr, const char **conf_name); inline int fit_parse_subimage (const char *spec, ulong addr_curr, ulong *addr, const char **image_name);
+inline void fit_print_contents (const void *fit); +inline void fit_print_contents_noindent (const void *fit); +void fit_image_print (const void *fit, int noffset, const char *p); +void fit_image_print_hash (const void *fit, int noffset, const char *p); + +ulong fit_get_end (const void *fit); +int fit_get_desc (const void *fit, int noffset, char **desc); +int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp); + +int fit_image_get_node (const void *fit, const char *image_uname); +int fit_image_get_os (const void *fit, int noffset, uint8_t *os); +int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch); +int fit_image_get_type (const void *fit, int noffset, uint8_t *type); +int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp); +int fit_image_get_load (const void *fit, int noffset, uint32_t *load); +int fit_image_get_entry (const void *fit, int noffset, uint32_t *entry); +int fit_image_get_data (const void *fit, int noffset, + const void **data, size_t *size); + +int fit_image_hash_get_algo (const void *fit, int noffset, char **algo); +int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value, + int *value_len); + +int fit_set_timestamp (void *fit, int noffset, time_t timestamp); +int fit_set_hashes (void *fit); +int fit_image_set_hashes (void *fit, int image_noffset); +int fit_image_hash_set_value (void *fit, int noffset, uint8_t *value, + int value_len); + +int fit_image_check_hashes (const void *fit, int noffset); +int fit_image_check_arch (const void *fit, int noffset, uint8_t arch); +int fit_image_check_type (const void *fit, int noffset, uint8_t type); + +int fit_conf_get_node (const void *fit, const char *conf_uname); +int fit_conf_get_kernel_node (const void *fit, int noffset); +int fit_conf_get_ramdisk_node (const void *fit, int noffset); +int fit_conf_get_fdt_node (const void *fit, int noffset); + +void fit_conf_print (const void *fit, int noffset, const char *p); + +#ifndef USE_HOSTCC +static inline int fit_image_check_target_arch (const void *fdt, int node) +{ +#if defined(__ARM__) + if (!fit_image_check_arch (fdt, node, IH_ARCH_ARM)) +#elif defined(__avr32__) + if (!fit_image_check_arch (fdt, node, IH_ARCH_AVR32)) +#elif defined(__bfin__) + if (!fit_image_check_arch (fdt, node, IH_ARCH_BLACKFIN)) +#elif defined(__I386__) + if (!fit_image_check_arch (fdt, node, IH_ARCH_I386)) +#elif defined(__M68K__) + if (!fit_image_check_arch (fdt, node, IH_ARCH_M68K)) +#elif defined(__microblaze__) + if (!fit_image_check_arch (fdt, node, IH_ARCH_MICROBLAZE)) +#elif defined(__mips__) + if (!fit_image_check_arch (fdt, node, IH_ARCH_MIPS)) +#elif defined(__nios__) + if (!fit_image_check_arch (fdt, node, IH_ARCH_NIOS)) +#elif defined(__nios2__) + if (!fit_image_check_arch (fdt, node, IH_ARCH_NIOS2)) +#elif defined(__PPC__) + if (!fit_image_check_arch (fdt, node, IH_ARCH_PPC)) +#elif defined(__sh__) + if (!fit_image_check_arch (fdt, node, IH_ARCH_SH)) +#else +# error Unknown CPU type +#endif + return 0; + + return 1; +} +#endif /* USE_HOSTCC */ + #ifdef CONFIG_FIT_VERBOSE #define fit_unsupported(msg) printf ("! %s:%d " \ "FIT images not supported for '%s'\n", \ @@ -436,6 +540,5 @@ inline int fit_parse_subimage (const char *spec, ulong addr_curr, #define fit_unsupported_reset(msg) #endif /* CONFIG_FIT_VERBOSE */ #endif /* CONFIG_FIT */ -#endif /* USE_HOSTCC */
#endif /* __IMAGE_H__ */ diff --git a/tools/mkimage.h b/tools/mkimage.h index cdd52bc..41cd156 100644 --- a/tools/mkimage.h +++ b/tools/mkimage.h @@ -35,6 +35,14 @@ #include <sha1.h> #include "fdt_host.h"
+#define MKIMAGE_DEBUG + +#ifdef MKIMAGE_DEBUG +#define debug(fmt,args...) printf (fmt ,##args) +#else +#define debug(fmt,args...) +#endif /* MKIMAGE_DEBUG */ + #if defined(__BEOS__) || defined(__NetBSD__) || defined(__APPLE__) #include <inttypes.h> #endif
participants (4)
-
Jerry Van Baren
-
Jerry Van Baren
-
Jon Loeliger
-
Marian Balakowicz