Skip to contentSkip to conversation

patchset6 - new uImage format low level API

PATCH New Marian Balakowicz 4 participants 15 messages Feb 29, 2008 – Mar 3, 2008 Kbuild

lore
Share & tools
lore
#0 lore raw

cover 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.

#1 lore raw

PATCH 1/8 Update naming convention for bootm/uImage related code

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.

---

 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(-)
board/cray/L1/L1.c +1 -1
index c00acc8..77f7f48 100644
@@ -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;
 	}
board/esd/common/auto_update.c +3 -3
index 976707d..1bf81c6 100644
@@ -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;
 	}
board/mcc200/auto_update.c +3 -3
index fcae35a..5580c11 100644
@@ -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;
 	}
board/mpl/common/common_util.c +2 -2
index fffd25c..785d204 100644
@@ -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;
 	}
board/siemens/common/fpga.c +2 -2
index a9a6dfe..48c1850 100644
@@ -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;
 	}
board/trab/auto_update.c +4 -4
index 8f67535..fa08bff 100644
@@ -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;
 	}
common/cmd_autoscript.c +2 -2
index f9ab1d9..60ffc7d 100644
@@ -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;
 		}
common/cmd_bootm.c +18 -18
index 8595ef6..10403aa 100644
@@ -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;
common/cmd_doc.c +1 -1
index 3358b04..293b1aa 100644
@@ -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;
 
common/cmd_fdc.c +1 -1
index b6e023a..80301b9 100644
@@ -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)) {
common/cmd_fpga.c +1 -1
index 10199f5..0bb82f6 100644
@@ -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;
common/cmd_ide.c +1 -1
index bef04db..79b7dfb 100644
@@ -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;
 
common/cmd_nand.c +2 -2
index b099afe..86959dc 100644
@@ -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;
 
common/cmd_scsi.c +1 -1
index 42b3072..7868805 100644
@@ -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;
 
common/cmd_usb.c +1 -1
index ad3873c..8ee7d27 100644
@@ -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;
 
common/cmd_ximg.c +3 -3
index 4dadc37..360b05e 100644
@@ -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");
common/image.c +218 -211

603 lines not on this page · raw message

include/image.h +39 -33

120 lines not on this page · raw message

lib_arm/bootm.c +1 -1
index 77d35fc..865e711 100644
@@ -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);
lib_avr32/bootm.c +1 -1
index 918e4cf..e8e537a 100644
@@ -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);
lib_i386/bootm.c +1 -1
index 89a423c..76bcf6c 100644
@@ -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) {
lib_m68k/bootm.c +5 -4
index e12d1d4..fba7499 100644
@@ -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;
 
lib_mips/bootm.c +1 -1
index 39869c1..b336a36 100644
@@ -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);
lib_ppc/bootm.c +12 -12
index 1afef46..8974ccd 100644
@@ -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)
 {
tools/mkimage.c +2 -2
index 8ced970..5119bc7 100644
@@ -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);
#2 lore raw

PATCH 2/8 Share common uImage code between mkimage and U-boot

In reply to Marian Balakowicz

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()

---

 common/image.c  |  341 +++++++++++++++++++++++++++++++++++++++----------------
 include/image.h |   21 ++-
 tools/mkimage.c |  244 ++-------------------------------------
 3 files changed, 267 insertions(+), 339 deletions(-)
common/image.c +244 -97
index 99ed3b8..421a474 100644
@@ -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(&timestamp));
 #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 */
include/image.h +13 -8
index b520691..ed79552 100644
@@ -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_) */
 /*******************************************************************/
tools/mkimage.c +10 -234

286 lines not on this page · raw message

#3 lore raw

PATCH 3/8 Fix component handling for legacy multi component images

In reply to Marian Balakowicz

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.

---

 common/image.c |   16 ++++++++--------
 1 files changed, 8 insertions(+), 8 deletions(-)
common/image.c +8 -8
index 421a474..3911b2f 100644
@@ -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 */
#4 lore raw

PATCH 4/8 Add sha1.o object to mkimage binary build

In reply to Marian Balakowicz

From: Bartlomiej Sieka <[email protected]>

---

 tools/Makefile  |    2 +-
 tools/mkimage.h |    1 +
 2 files changed, 2 insertions(+), 1 deletions(-)
tools/Makefile +1 -1
index cbfca6d..0cc4cc9 100644
@@ -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) $@
 
tools/mkimage.h +1 -0
index 8b05bb1..a01977e 100644
@@ -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>
#5 lore raw

PATCH 5/8 Add libfdt support to mkimage

In reply to Marian Balakowicz

From: Bartlomiej Sieka <[email protected]>

---

 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
Makefile +3 -0
index bacea3e..adfef9b 100644
@@ -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
include/libfdt_env.h +4 -0
index 78f7258..98c522a 100644
@@ -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 */
 
libfdt/fdt.c +4 -0
index 586a361..071470d 100644
@@ -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"
 
libfdt/fdt_ro.c +4 -0
index 12a37d5..1ae3a55 100644
@@ -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"
 
libfdt/fdt_rw.c +4 -0
index 6673f8e..2fb81dd 100644
@@ -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"
 
libfdt/fdt_strerror.c +4 -0
index f9d32ef..abf792e 100644
@@ -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"
 
libfdt/fdt_wip.c +4 -0
index 88e24b8..24e1724 100644
@@ -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"
 
tools/.gitignore +7 -0
index c33679a..0ce2e77 100644
@@ -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
tools/Makefile +48 -3

89 lines not on this page · raw message

tools/fdt_host.h new file +28 -0
new file mode 100644
index 0000000..085013e
@@ -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__ */
tools/mkimage.h +1 -0
index a01977e..cdd52bc 100644
@@ -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>
#6 lore raw

PATCH 5/8 Add libfdt support to mkimage

Quoted 5 lines · Marian Balakowicz

From: Bartlomiej Sieka <[email protected]>

---

Quoted 13 lines
 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

#7 lore raw

PATCH 5/8 Add libfdt support to mkimage

Quoted 21 lines · Jerry Van Baren
Quoted 5 lines · Marian Balakowicz

From: Bartlomiej Sieka <[email protected]>

---

Quoted 14 lines
 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
Quoted 5 lines

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.

#8 lore raw

PATCH 5/8 Add libfdt support to mkimage

In reply to Jerry Van Baren
Quoted 20 lines · Jerry Van Baren
Quoted 5 lines · Marian Balakowicz

From: Bartlomiej Sieka <[email protected]>

---

Quoted 13 lines
 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
Quoted 9 lines

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 at 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

#9 lore raw

PATCH 6/8 libfdt: Add and use a node iteration helper function.

In reply to Marian Balakowicz

From: David Gibson <[email protected]>

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.

---

 include/libfdt.h |    6 +
 libfdt/fdt.c     |   41 +++++++++
 libfdt/fdt_ro.c  |  258 ++++++++++++++++++------------------------------------
 3 files changed, 131 insertions(+), 174 deletions(-)
include/libfdt.h +6 -0
index 6c05236..3a64d0b 100644
@@ -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                                                  */
 /**********************************************************************/
 
libfdt/fdt.c +41 -0

47 lines not on this page · raw message

libfdt/fdt_ro.c +84 -174

337 lines not on this page · raw message

#10 lore raw

PATCH 6/8 libfdt: Add and use a node iteration helper function.

Quoted 7 lines · Marian Balakowicz

From: David Gibson <[email protected]>

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.

Quoted 7 lines

---

 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.

<http://www.denx.de/cgi-bin/gitweb.cgi?p=u-boot/u-boot-fdt.git;a=commit;h=162fa0021d04495f1e514d2b50f28dddd031f688>

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

#11 lore raw

PATCH 6/8 libfdt: Add and use a node iteration helper function.

Hi Jerry,

Quoted 17 lines · Jerry Van Baren
Quoted 15 lines · Marian Balakowicz

From: David Gibson <[email protected]>

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.

---

 include/libfdt.h |    6 +
 libfdt/fdt.c     |   41 +++++++++
 libfdt/fdt_ro.c  |  258
++++++++++++++++++------------------------------------
 3 files changed, 131 insertions(+), 174 deletions(-)

...

Quoted 7 lines

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.

<http://www.denx.de/cgi-bin/gitweb.cgi?p=u-boot/u-boot-fdt.git;a=commit;h=162fa0021d04495f1e514d2b50f28dddd031f688>

Quoted 7 lines

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.

#12 lore raw

PATCH 6/8 libfdt: Add and use a node iteration helper function.

Quoted 3 lines · Marian Balakowicz

Hi Jerry,

Jerry Van Baren wrote:

[snip]

Quoted 8 lines
Quoted 7 lines

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.)

Quoted 6 lines

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

#13 lore raw

PATCH 7/8 Fix FDT blob totalsize calculation in boot_relocate_fdt()

In reply to Marian Balakowicz

Do not use global fdt blob pointer, calculate blob size from routine argument blob pointer.

---

 lib_ppc/bootm.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
lib_ppc/bootm.c +1 -1
index 8974ccd..7977157 100644
@@ -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) {
#14 lore raw

PATCH 8/8 New uImage low-level API

In reply to Marian Balakowicz

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

---

 common/image.c  | 1181 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 include/image.h |  107 +++++
 tools/mkimage.h |    8 
 3 files changed, 1291 insertions(+), 5 deletions(-)
common/image.c +1178 -3
index 3911b2f..adf9fbc 100644
@@ -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, &timestamp);
+	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 at 1, hash at 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 at 1 (at image_noffset)
+ *   | - data = [binary data]
+ *   o hash at 1
+ *     |- algo = "sha1"
+ *
+ * Output component image node structure:
+ *
+ * o image at 1 (at image_noffset)
+ *   | - data = [binary data]
+ *   o hash at 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 at 1, hash at 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 at 1, hash at 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 */
include/image.h +105 -2

140 lines not on this page · raw message

tools/mkimage.h +8 -0
index cdd52bc..41cd156 100644
@@ -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