Skip to content
Snippets Groups Projects
image.c 82.1 KiB
Newer Older
  • Learn to ignore specific revisions
  •  * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
     *      start address (after possible relocation)
     * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
     *      end address (after possible relocation)
     *
    
     * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
    
     * variable and if requested ramdisk data is moved to a specified location.
     *
    
     * Initrd_start and initrd_end are set to final (after relocation) ramdisk
     * start/end addresses if ramdisk image start and len were provided,
     * otherwise set initrd_start and initrd_end set to zeros.
     *
    
    int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
    
    		  ulong *initrd_start, ulong *initrd_end)
    
    {
    	char	*s;
    	ulong	initrd_high;
    	int	initrd_copy_to_ram = 1;
    
    	if ((s = getenv ("initrd_high")) != NULL) {
    		/* a value of "no" or a similar string will act like 0,
    		 * turning the "load high" feature off. This is intentional.
    		 */
    		initrd_high = simple_strtoul (s, NULL, 16);
    		if (initrd_high == ~0)
    			initrd_copy_to_ram = 0;
    	} else {
    		/* not set, no restrictions to load high */
    		initrd_high = ~0;
    	}
    
    
    
    #ifdef CONFIG_LOGBUFFER
    	/* Prevent initrd from overwriting logbuffer */
    	lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
    #endif
    
    
    	debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
    			initrd_high, initrd_copy_to_ram);
    
    	if (rd_data) {
    		if (!initrd_copy_to_ram) {	/* zero-copy ramdisk support */
    			debug ("   in-place initrd\n");
    			*initrd_start = rd_data;
    			*initrd_end = rd_data + rd_len;
    
    			lmb_reserve(lmb, rd_data, rd_len);
    
    			if (initrd_high)
    
    				*initrd_start = (ulong)lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
    
    				*initrd_start = (ulong)lmb_alloc (lmb, rd_len, 0x1000);
    
    
    			if (*initrd_start == 0) {
    
    				puts ("ramdisk - allocation error\n");
    
    			}
    			show_boot_progress (12);
    
    			*initrd_end = *initrd_start + rd_len;
    			printf ("   Loading Ramdisk to %08lx, end %08lx ... ",
    					*initrd_start, *initrd_end);
    
    
    					(void *)rd_data, rd_len, CHUNKSZ);
    
    			puts ("OK\n");
    		}
    	} else {
    		*initrd_start = 0;
    		*initrd_end = 0;
    	}
    	debug ("   ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
    			*initrd_start, *initrd_end);
    
    #endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */
    
    #ifdef CONFIG_OF_LIBFDT
    static void fdt_error (const char *msg)
    {
    	puts ("ERROR: ");
    	puts (msg);
    	puts (" - must RESET the board to recover.\n");
    }
    
    
    static const image_header_t *image_get_fdt (ulong fdt_addr)
    
    	const image_header_t *fdt_hdr = (const image_header_t *)fdt_addr;
    
    
    	image_print_contents (fdt_hdr);
    
    	puts ("   Verifying Checksum ... ");
    	if (!image_check_hcrc (fdt_hdr)) {
    		fdt_error ("fdt header checksum invalid");
    		return NULL;
    	}
    
    	if (!image_check_dcrc (fdt_hdr)) {
    		fdt_error ("fdt checksum invalid");
    		return NULL;
    	}
    	puts ("OK\n");
    
    	if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) {
    		fdt_error ("uImage is not a fdt");
    		return NULL;
    	}
    	if (image_get_comp (fdt_hdr) != IH_COMP_NONE) {
    		fdt_error ("uImage is compressed");
    		return NULL;
    	}
    	if (fdt_check_header ((char *)image_get_data (fdt_hdr)) != 0) {
    		fdt_error ("uImage data is not a fdt");
    		return NULL;
    	}
    	return fdt_hdr;
    }
    
    /**
     * fit_check_fdt - verify FIT format FDT subimage
     * @fit_hdr: pointer to the FIT  header
     * fdt_noffset: FDT subimage node offset within FIT image
     * @verify: data CRC verification flag
     *
     * fit_check_fdt() verifies integrity of the FDT subimage and from
     * specified FIT image.
     *
     * returns:
     *     1, on success
     *     0, on failure
     */
    #if defined(CONFIG_FIT)
    static int fit_check_fdt (const void *fit, int fdt_noffset, int verify)
    {
    	fit_image_print (fit, fdt_noffset, "   ");
    
    	if (verify) {
    		puts ("   Verifying Hash Integrity ... ");
    		if (!fit_image_check_hashes (fit, fdt_noffset)) {
    			fdt_error ("Bad Data Hash");
    			return 0;
    		}
    		puts ("OK\n");
    	}
    
    	if (!fit_image_check_type (fit, fdt_noffset, IH_TYPE_FLATDT)) {
    		fdt_error ("Not a FDT image");
    		return 0;
    	}
    
    	if (!fit_image_check_comp (fit, fdt_noffset, IH_COMP_NONE)) {
    		fdt_error ("FDT image is compressed");
    		return 0;
    	}
    
    	return 1;
    }
    #endif /* CONFIG_FIT */
    
    
    #ifndef CONFIG_SYS_FDT_PAD
    #define CONFIG_SYS_FDT_PAD 0x3000
    
    #endif
    
    /**
     * boot_relocate_fdt - relocate flat device tree
     * @lmb: pointer to lmb handle, will be used for memory mgmt
     * @of_flat_tree: pointer to a char* variable, will hold fdt start address
     * @of_size: pointer to a ulong variable, will hold fdt length
     *
    
     * boot_relocate_fdt() allocates a region of memory within the bootmap and
     * relocates the of_flat_tree into that region, even if the fdt is already in
     * the bootmap.  It also expands the size of the fdt by CONFIG_SYS_FDT_PAD
     * bytes.
    
     *
     * of_flat_tree and of_size are set to final (after relocation) values
     *
     * returns:
     *      0 - success
     *      1 - failure
     */
    
    #if defined(CONFIG_SYS_BOOTMAPSZ)
    
    int boot_relocate_fdt (struct lmb *lmb, char **of_flat_tree, ulong *of_size)
    
    	void	*fdt_blob = *of_flat_tree;
    	void	*of_start = 0;
    
    	ulong	of_len = 0;
    
    
    	/* nothing to do */
    	if (*of_size == 0)
    		return 0;
    
    	if (fdt_check_header (fdt_blob) != 0) {
    		fdt_error ("image is not a fdt");
    		goto error;
    	}
    
    
    	/* position on a 4K boundary before the alloc_current */
    	/* Pad the FDT by a specified amount */
    	of_len = *of_size + CONFIG_SYS_FDT_PAD;
    	of_start = (void *)(unsigned long)lmb_alloc_base(lmb, of_len, 0x1000,
    
    			CONFIG_SYS_BOOTMAPSZ + getenv_bootm_low());
    
    	if (of_start == 0) {
    		puts("device tree - allocation error\n");
    		goto error;
    	}
    
    	debug ("## device tree at %p ... %p (len=%ld [0x%lX])\n",
    		fdt_blob, fdt_blob + *of_size - 1, of_len, of_len);
    
    	printf ("   Loading Device Tree to %p, end %p ... ",
    		of_start, of_start + of_len - 1);
    
    	err = fdt_open_into (fdt_blob, of_start, of_len);
    	if (err != 0) {
    		fdt_error ("fdt move failed");
    		goto error;
    
    	puts ("OK\n");
    
    	*of_flat_tree = of_start;
    	*of_size = of_len;
    
    	set_working_fdt_addr(*of_flat_tree);
    
    #endif /* CONFIG_SYS_BOOTMAPSZ */
    
    
    /**
     * boot_get_fdt - main fdt handling routine
     * @argc: command argument count
     * @argv: command argument list
     * @images: pointer to the bootm images structure
     * @of_flat_tree: pointer to a char* variable, will hold fdt start address
     * @of_size: pointer to a ulong variable, will hold fdt length
     *
     * boot_get_fdt() is responsible for finding a valid flat device tree image.
     * Curently supported are the following ramdisk sources:
     *      - multicomponent kernel/ramdisk image,
     *      - commandline provided address of decicated ramdisk image.
     *
     * returns:
     *     0, if fdt image was found and valid, or skipped
     *     of_flat_tree and of_size are set to fdt start address and length if
     *     fdt image is found and valid
     *
     *     1, if fdt image is found but corrupted
     *     of_flat_tree and of_size are set to 0 if no fdt exists
     */
    
    int boot_get_fdt (int flag, int argc, char * const argv[], bootm_headers_t *images,
    
    		char **of_flat_tree, ulong *of_size)
    {
    
    	const image_header_t *fdt_hdr;
    
    	ulong		fdt_addr;
    	char		*fdt_blob = NULL;
    	ulong		image_start, image_end;
    	ulong		load_start, load_end;
    #if defined(CONFIG_FIT)
    	void		*fit_hdr;
    	const char	*fit_uname_config = NULL;
    	const char	*fit_uname_fdt = NULL;
    	ulong		default_addr;
    	int		cfg_noffset;
    	int		fdt_noffset;
    	const void	*data;
    	size_t		size;
    #endif
    
    	*of_flat_tree = NULL;
    	*of_size = 0;
    
    	if (argc > 3 || genimg_has_config (images)) {
    #if defined(CONFIG_FIT)
    		if (argc > 3) {
    			/*
    			 * If the FDT blob comes from the FIT image and the
    			 * FIT image address is omitted in the command line
    			 * argument, try to use ramdisk or os FIT image
    			 * address or default load address.
    			 */
    			if (images->fit_uname_rd)
    				default_addr = (ulong)images->fit_hdr_rd;
    			else if (images->fit_uname_os)
    				default_addr = (ulong)images->fit_hdr_os;
    			else
    				default_addr = load_addr;
    
    			if (fit_parse_conf (argv[3], default_addr,
    						&fdt_addr, &fit_uname_config)) {
    				debug ("*  fdt: config '%s' from image at 0x%08lx\n",
    						fit_uname_config, fdt_addr);
    			} else if (fit_parse_subimage (argv[3], default_addr,
    						&fdt_addr, &fit_uname_fdt)) {
    				debug ("*  fdt: subimage '%s' from image at 0x%08lx\n",
    						fit_uname_fdt, fdt_addr);
    			} else
    #endif
    			{
    				fdt_addr = simple_strtoul(argv[3], NULL, 16);
    				debug ("*  fdt: cmdline image address = 0x%08lx\n",
    						fdt_addr);
    			}
    #if defined(CONFIG_FIT)
    		} else {
    			/* use FIT configuration provided in first bootm
    			 * command argument
    			 */
    			fdt_addr = (ulong)images->fit_hdr_os;
    			fit_uname_config = images->fit_uname_cfg;
    			debug ("*  fdt: using config '%s' from image at 0x%08lx\n",
    					fit_uname_config, fdt_addr);
    
    			/*
    			 * Check whether configuration has FDT blob defined,
    			 * if not quit silently.
    			 */
    			fit_hdr = (void *)fdt_addr;
    			cfg_noffset = fit_conf_get_node (fit_hdr,
    					fit_uname_config);
    			if (cfg_noffset < 0) {
    				debug ("*  fdt: no such config\n");
    				return 0;
    			}
    
    			fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
    					cfg_noffset);
    			if (fdt_noffset < 0) {
    				debug ("*  fdt: no fdt in config\n");
    				return 0;
    			}
    		}
    #endif
    
    		debug ("## Checking for 'FDT'/'FDT Image' at %08lx\n",
    				fdt_addr);
    
    		/* copy from dataflash if needed */
    		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 (genimg_get_format ((void *)fdt_addr)) {
    		case IMAGE_FORMAT_LEGACY:
    			/* verify fdt_addr points to a valid image header */
    			printf ("## Flattened Device Tree from Legacy Image at %08lx\n",
    					fdt_addr);
    			fdt_hdr = image_get_fdt (fdt_addr);
    			if (!fdt_hdr)
    				goto error;
    
    			/*
    			 * move image data to the load address,
    			 * make sure we don't overwrite initial image
    			 */
    			image_start = (ulong)fdt_hdr;
    			image_end = image_get_image_end (fdt_hdr);
    
    			load_start = image_get_load (fdt_hdr);
    			load_end = load_start + image_get_data_size (fdt_hdr);
    
    			if ((load_start < image_end) && (load_end > image_start)) {
    				fdt_error ("fdt overwritten");
    				goto error;
    			}
    
    			debug ("   Loading FDT from 0x%08lx to 0x%08lx\n",
    					image_get_data (fdt_hdr), load_start);
    
    			memmove ((void *)load_start,
    					(void *)image_get_data (fdt_hdr),
    					image_get_data_size (fdt_hdr));
    
    			fdt_blob = (char *)load_start;
    			break;
    		case IMAGE_FORMAT_FIT:
    			/*
    			 * This case will catch both: new uImage format
    			 * (libfdt based) and raw FDT blob (also libfdt
    			 * based).
    			 */
    #if defined(CONFIG_FIT)
    			/* check FDT blob vs FIT blob */
    			if (fit_check_format ((const void *)fdt_addr)) {
    				/*
    				 * FIT image
    				 */
    				fit_hdr = (void *)fdt_addr;
    				printf ("## Flattened Device Tree from FIT Image at %08lx\n",
    						fdt_addr);
    
    				if (!fit_uname_fdt) {
    					/*
    					 * no FDT blob image node unit name,
    					 * try to get config node first. If
    					 * config unit node name is NULL
    					 * fit_conf_get_node() will try to
    					 * find default config node
    					 */
    					cfg_noffset = fit_conf_get_node (fit_hdr,
    							fit_uname_config);
    
    					if (cfg_noffset < 0) {
    						fdt_error ("Could not find configuration node\n");
    						goto error;
    					}
    
    					fit_uname_config = fdt_get_name (fit_hdr,
    							cfg_noffset, NULL);
    					printf ("   Using '%s' configuration\n",
    							fit_uname_config);
    
    					fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
    							cfg_noffset);
    					fit_uname_fdt = fit_get_name (fit_hdr,
    							fdt_noffset, NULL);
    				} else {
    					/* get FDT component image node offset */
    					fdt_noffset = fit_image_get_node (fit_hdr,
    							fit_uname_fdt);
    				}
    				if (fdt_noffset < 0) {
    					fdt_error ("Could not find subimage node\n");
    					goto error;
    				}
    
    				printf ("   Trying '%s' FDT blob subimage\n",
    						fit_uname_fdt);
    
    				if (!fit_check_fdt (fit_hdr, fdt_noffset,
    							images->verify))
    					goto error;
    
    				/* get ramdisk image data address and length */
    				if (fit_image_get_data (fit_hdr, fdt_noffset,
    							&data, &size)) {
    					fdt_error ("Could not find FDT subimage data");
    					goto error;
    				}
    
    				/* verift that image data is a proper FDT blob */
    				if (fdt_check_header ((char *)data) != 0) {
    					fdt_error ("Subimage data is not a FTD");
    					goto error;
    				}
    
    				/*
    				 * move image data to the load address,
    				 * make sure we don't overwrite initial image
    				 */
    				image_start = (ulong)fit_hdr;
    				image_end = fit_get_end (fit_hdr);
    
    				if (fit_image_get_load (fit_hdr, fdt_noffset,
    							&load_start) == 0) {
    					load_end = load_start + size;
    
    					if ((load_start < image_end) &&
    							(load_end > image_start)) {
    						fdt_error ("FDT overwritten");
    						goto error;
    					}
    
    					printf ("   Loading FDT from 0x%08lx to 0x%08lx\n",
    							(ulong)data, load_start);
    
    					memmove ((void *)load_start,
    							(void *)data, size);
    
    					fdt_blob = (char *)load_start;
    				} else {
    					fdt_blob = (char *)data;
    				}
    
    				images->fit_hdr_fdt = fit_hdr;
    				images->fit_uname_fdt = fit_uname_fdt;
    				images->fit_noffset_fdt = fdt_noffset;
    				break;
    			} else
    #endif
    			{
    				/*
    				 * FDT blob
    				 */
    				fdt_blob = (char *)fdt_addr;
    				debug ("*  fdt: raw FDT blob\n");
    				printf ("## Flattened Device Tree blob at %08lx\n", (long)fdt_blob);
    			}
    			break;
    		default:
    
    			puts ("ERROR: Did not find a cmdline Flattened Device Tree\n");
    
    			goto error;
    		}
    
    		printf ("   Booting using the fdt blob at 0x%x\n", (int)fdt_blob);
    
    	} else if (images->legacy_hdr_valid &&
    			image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
    
    		ulong fdt_data, fdt_len;
    
    		/*
    		 * Now check if we have a legacy multi-component image,
    		 * get second entry data start address and len.
    		 */
    		printf ("## Flattened Device Tree from multi "
    			"component Image at %08lX\n",
    			(ulong)images->legacy_hdr_os);
    
    		image_multi_getimg (images->legacy_hdr_os, 2, &fdt_data, &fdt_len);
    		if (fdt_len) {
    
    			fdt_blob = (char *)fdt_data;
    			printf ("   Booting using the fdt at 0x%x\n", (int)fdt_blob);
    
    			if (fdt_check_header (fdt_blob) != 0) {
    				fdt_error ("image is not a fdt");
    				goto error;
    			}
    
    
    			if (fdt_totalsize(fdt_blob) != fdt_len) {
    
    				fdt_error ("fdt size != image size");
    				goto error;
    			}
    		} else {
    			debug ("## No Flattened Device Tree\n");
    			return 0;
    		}
    	} else {
    		debug ("## No Flattened Device Tree\n");
    		return 0;
    	}
    
    	*of_flat_tree = fdt_blob;
    
    	*of_size = fdt_totalsize(fdt_blob);
    
    	debug ("   of_flat_tree at 0x%08lx size 0x%08lx\n",
    
    			(ulong)*of_flat_tree, *of_size);
    
    
    	return 0;
    
    error:
    	*of_flat_tree = 0;
    	*of_size = 0;
    	return 1;
    }
    #endif /* CONFIG_OF_LIBFDT */
    
    
    #ifdef CONFIG_SYS_BOOT_GET_CMDLINE
    
     * boot_get_cmdline - allocate and initialize kernel cmdline
    
     * @lmb: pointer to lmb handle, will be used for memory mgmt
    
     * @cmd_start: pointer to a ulong variable, will hold cmdline start
     * @cmd_end: pointer to a ulong variable, will hold cmdline end
     *
    
     * boot_get_cmdline() allocates space for kernel command line below
    
     * BOOTMAPSZ + getenv_bootm_low() address. If "bootargs" U-boot environemnt
    
     * variable is present its contents is copied to allocated kernel
     * command line.
     *
     * returns:
    
     *      0 - success
     *     -1 - failure
    
    int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end)
    
    	cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf,
    
    				     CONFIG_SYS_BOOTMAPSZ + getenv_bootm_low());
    
    
    	if (cmdline == NULL)
    		return -1;
    
    
    	if ((s = getenv("bootargs")) == NULL)
    		s = "";
    
    	strcpy(cmdline, s);
    
    	*cmd_start = (ulong) & cmdline[0];
    	*cmd_end = *cmd_start + strlen(cmdline);
    
    	debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
    
    
    #endif /* CONFIG_SYS_BOOT_GET_CMDLINE */
    
    #ifdef CONFIG_SYS_BOOT_GET_KBD
    
     * boot_get_kbd - allocate and initialize kernel copy of board info
    
     * @lmb: pointer to lmb handle, will be used for memory mgmt
    
     * @kbd: double pointer to board info data
     *
    
     * boot_get_kbd() allocates space for kernel copy of board info data below
    
     * BOOTMAPSZ + getenv_bootm_low() address and kernel board info is initialized
     * with the current u-boot board info data.
    
     *      0 - success
     *     -1 - failure
    
    int boot_get_kbd (struct lmb *lmb, bd_t **kbd)
    
    	*kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
    
    				     CONFIG_SYS_BOOTMAPSZ + getenv_bootm_low());
    
    	if (*kbd == NULL)
    		return -1;
    
    
    	**kbd = *(gd->bd);
    
    	debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
    
    #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
    	do_bdinfo(NULL, 0, 0, NULL);
    #endif
    
    
    #endif /* CONFIG_SYS_BOOT_GET_KBD */
    
    #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)
    {
    	const char *sep;
    
    	*addr = addr_curr;
    	*name = NULL;
    
    	sep = strchr (spec, sepc);
    	if (sep) {
    		if (sep - spec > 0)
    			*addr = simple_strtoul (spec, NULL, 16);
    
    		*name = sep + 1;
    		return 1;
    	}
    
    	return 0;
    }
    
    /**
     * fit_parse_conf - parse FIT configuration spec
     * @spec: input string, containing configuration spec
     * @add_curr: current image address (to be used as a possible default)
     * @addr: pointer to a ulong variable, will hold FIT image address of a given
     * configuration
     * @conf_name double pointer to a char, will hold pointer to a configuration
     * unit name
     *
     * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
     * where <addr> is a FIT image address that contains configuration
     * with a <conf> unit name.
     *
     * Address part is optional, and if omitted default add_curr will
     * be used instead.
     *
     * returns:
     *     1 if spec is a valid configuration string,
     *     addr and conf_name are set accordingly
     *     0 otherwise
     */
    inline int fit_parse_conf (const char *spec, ulong addr_curr,
    		ulong *addr, const char **conf_name)
    {
    	return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
    }
    
    /**
     * fit_parse_subimage - parse FIT subimage spec
     * @spec: input string, containing subimage spec
     * @add_curr: current image address (to be used as a possible default)
     * @addr: pointer to a ulong variable, will hold FIT image address of a given
     * subimage
     * @image_name: double pointer to a char, will hold pointer to a subimage name
     *
     * fit_parse_subimage() expects subimage spec in the for of
     * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
     * subimage with a <subimg> unit name.
     *
     * Address part is optional, and if omitted default add_curr will
     * be used instead.
     *
     * returns:
     *     1 if spec is a valid subimage string,
     *     addr and image_name are set accordingly
     *     0 otherwise
     */
    inline int fit_parse_subimage (const char *spec, ulong addr_curr,
    		ulong *addr, const char **image_name)
    {
    	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,
    		fit_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
     */
    
    void fit_print_contents (const void *fit)
    
    {
    	char *desc;
    	char *uname;
    	int images_noffset;
    	int confs_noffset;
    	int noffset;
    	int ndepth;
    	int count = 0;
    	int ret;
    
    	const char *p;
    
    #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
    	time_t timestamp;
    #endif
    
    
    #ifdef USE_HOSTCC
    	p = "";
    #else
    	p = "   ";
    #endif
    
    
    	/* Root node properties */
    	ret = fit_get_desc (fit, 0, &desc);
    	printf ("%sFIT description: ", p);
    	if (ret)
    		printf ("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 ("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++,
    					fit_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++,
    					fit_get_name(fit, noffset, NULL));
    
    			fit_conf_print (fit, noffset, p);
    		}
    	}
    }
    
    /**
     * 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. Load
     * address for images of type firmware is also printed out. Since the load
     * address is not mandatory for firmware images, it will be output as
     * "unavailable" when not present.
    
     *
     * 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;
    	ulong 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 ("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);
    
    #ifndef USE_HOSTCC
    	printf ("%s  Data Start:   ", p);
    	if (ret)
    		printf ("unavailable\n");
    	else
    		printf ("0x%08lx\n", (ulong)data);
    #endif
    
    	printf ("%s  Data Size:    ", p);
    	if (ret)
    		printf ("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) ||
    		(type == IH_TYPE_FIRMWARE)) {
    
    		ret = fit_image_get_load (fit, image_noffset, &load);
    		printf ("%s  Load Address: ", p);
    		if (ret)
    			printf ("unavailable\n");
    		else
    			printf ("0x%08lx\n", load);
    
    	if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
    
    		fit_image_get_entry (fit, image_noffset, &entry);
    		printf ("%s  Entry Point:  ", p);
    		if (ret)
    			printf ("unavailable\n");
    		else
    			printf ("0x%08lx\n", entry);
    	}
    
    	/* Process all hash subnodes of the component image node */
    	for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
    	     (noffset >= 0) && (ndepth > 0);
    	     noffset = fdt_next_node (fit, noffset, &ndepth)) {
    		if (ndepth == 1) {
    			/* Direct child node of the component image node */
    			fit_image_print_hash (fit, noffset, p);
    		}
    	}
    }
    
    /**
     * fit_image_print_hash - prints out the hash node details
     * @fit: pointer to the FIT format image header
     * @noffset: offset of the hash node
     * @p: pointer to prefix string
     *
     * fit_image_print_hash() lists properies for the processed hash node
     *
     * returns:
     *     no returned results
     */
    void fit_image_print_hash (const void *fit, int noffset, const char *p)
    {
    	char *algo;
    	uint8_t *value;
    	int value_len;
    	int i, ret;
    
    	/*
    	 * Check subnode name, must be equal to "hash".
    	 * Multiple hash nodes require unique unit node
    	 * names, e.g. hash@1, hash@2, etc.
    	 */
    	if (strncmp (fit_get_name(fit, noffset, NULL),
    			FIT_HASH_NODENAME,
    			strlen(FIT_HASH_NODENAME)) != 0)
    		return;
    
    	debug ("%s  Hash node:    '%s'\n", p,
    			fit_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_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);