2 * (C) Copyright 2008 Semihalf
4 * (C) Copyright 2000-2006
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #ifdef CONFIG_SHOW_BOOT_PROGRESS
31 #include <status_led.h>
34 #ifdef CONFIG_HAS_DATAFLASH
35 #include <dataflash.h>
38 #ifdef CONFIG_LOGBUFFER
42 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
48 #if defined(CONFIG_FIT) || defined (CONFIG_OF_LIBFDT)
51 #include <fdt_support.h>
54 #if defined(CONFIG_FIT)
55 #include <u-boot/md5.h>
58 static int fit_check_ramdisk (const void *fit, int os_noffset,
59 uint8_t arch, int verify);
63 extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
66 DECLARE_GLOBAL_DATA_PTR;
68 static const image_header_t* image_get_ramdisk (ulong rd_addr, uint8_t arch,
72 #include <u-boot/md5.h>
75 #endif /* !USE_HOSTCC*/
77 static table_entry_t uimage_arch[] = {
78 { IH_ARCH_INVALID, NULL, "Invalid ARCH", },
79 { IH_ARCH_ALPHA, "alpha", "Alpha", },
80 { IH_ARCH_ARM, "arm", "ARM", },
81 { IH_ARCH_I386, "x86", "Intel x86", },
82 { IH_ARCH_IA64, "ia64", "IA64", },
83 { IH_ARCH_M68K, "m68k", "M68K", },
84 { IH_ARCH_MICROBLAZE, "microblaze", "MicroBlaze", },
85 { IH_ARCH_MIPS, "mips", "MIPS", },
86 { IH_ARCH_MIPS64, "mips64", "MIPS 64 Bit", },
87 { IH_ARCH_NIOS, "nios", "NIOS", },
88 { IH_ARCH_NIOS2, "nios2", "NIOS II", },
89 { IH_ARCH_PPC, "powerpc", "PowerPC", },
90 { IH_ARCH_PPC, "ppc", "PowerPC", },
91 { IH_ARCH_S390, "s390", "IBM S390", },
92 { IH_ARCH_SH, "sh", "SuperH", },
93 { IH_ARCH_SPARC, "sparc", "SPARC", },
94 { IH_ARCH_SPARC64, "sparc64", "SPARC 64 Bit", },
95 { IH_ARCH_BLACKFIN, "blackfin", "Blackfin", },
96 { IH_ARCH_AVR32, "avr32", "AVR32", },
100 static table_entry_t uimage_os[] = {
101 { IH_OS_INVALID, NULL, "Invalid OS", },
102 { IH_OS_LINUX, "linux", "Linux", },
103 #if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC)
104 { IH_OS_LYNXOS, "lynxos", "LynxOS", },
106 { IH_OS_NETBSD, "netbsd", "NetBSD", },
107 { IH_OS_RTEMS, "rtems", "RTEMS", },
108 { IH_OS_U_BOOT, "u-boot", "U-Boot", },
109 #if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC)
110 { IH_OS_QNX, "qnx", "QNX", },
111 { IH_OS_VXWORKS, "vxworks", "VxWorks", },
113 #if defined(CONFIG_INTEGRITY) || defined(USE_HOSTCC)
114 { IH_OS_INTEGRITY,"integrity", "INTEGRITY", },
117 { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", },
118 { IH_OS_DELL, "dell", "Dell", },
119 { IH_OS_ESIX, "esix", "Esix", },
120 { IH_OS_FREEBSD, "freebsd", "FreeBSD", },
121 { IH_OS_IRIX, "irix", "Irix", },
122 { IH_OS_NCR, "ncr", "NCR", },
123 { IH_OS_OPENBSD, "openbsd", "OpenBSD", },
124 { IH_OS_PSOS, "psos", "pSOS", },
125 { IH_OS_SCO, "sco", "SCO", },
126 { IH_OS_SOLARIS, "solaris", "Solaris", },
127 { IH_OS_SVR4, "svr4", "SVR4", },
132 static table_entry_t uimage_type[] = {
133 { IH_TYPE_INVALID, NULL, "Invalid Image", },
134 { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", },
135 { IH_TYPE_FIRMWARE, "firmware", "Firmware", },
136 { IH_TYPE_KERNEL, "kernel", "Kernel Image", },
137 { IH_TYPE_MULTI, "multi", "Multi-File Image", },
138 { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", },
139 { IH_TYPE_SCRIPT, "script", "Script", },
140 { IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
141 { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", },
145 static table_entry_t uimage_comp[] = {
146 { IH_COMP_NONE, "none", "uncompressed", },
147 { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", },
148 { IH_COMP_GZIP, "gzip", "gzip compressed", },
149 { IH_COMP_LZMA, "lzma", "lzma compressed", },
153 uint32_t crc32 (uint32_t, const unsigned char *, uint);
154 uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint);
155 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
156 static void genimg_print_time (time_t timestamp);
159 /*****************************************************************************/
160 /* Legacy format routines */
161 /*****************************************************************************/
162 int image_check_hcrc (const image_header_t *hdr)
165 ulong len = image_get_header_size ();
166 image_header_t header;
168 /* Copy header so we can blank CRC field for re-calculation */
169 memmove (&header, (char *)hdr, image_get_header_size ());
170 image_set_hcrc (&header, 0);
172 hcrc = crc32 (0, (unsigned char *)&header, len);
174 return (hcrc == image_get_hcrc (hdr));
177 int image_check_dcrc (const image_header_t *hdr)
179 ulong data = image_get_data (hdr);
180 ulong len = image_get_data_size (hdr);
181 ulong dcrc = crc32_wd (0, (unsigned char *)data, len, CHUNKSZ_CRC32);
183 return (dcrc == image_get_dcrc (hdr));
187 * image_multi_count - get component (sub-image) count
188 * @hdr: pointer to the header of the multi component image
190 * image_multi_count() returns number of components in a multi
193 * Note: no checking of the image type is done, caller must pass
194 * a valid multi component image.
197 * number of components
199 ulong image_multi_count (const image_header_t *hdr)
204 /* get start of the image payload, which in case of multi
205 * component images that points to a table of component sizes */
206 size = (uint32_t *)image_get_data (hdr);
208 /* count non empty slots */
209 for (i = 0; size[i]; ++i)
216 * image_multi_getimg - get component data address and size
217 * @hdr: pointer to the header of the multi component image
218 * @idx: index of the requested component
219 * @data: pointer to a ulong variable, will hold component data address
220 * @len: pointer to a ulong variable, will hold component size
222 * image_multi_getimg() returns size and data address for the requested
223 * component in a multi component image.
225 * Note: no checking of the image type is done, caller must pass
226 * a valid multi component image.
229 * data address and size of the component, if idx is valid
230 * 0 in data and len, if idx is out of range
232 void image_multi_getimg (const image_header_t *hdr, ulong idx,
233 ulong *data, ulong *len)
237 ulong offset, count, img_data;
239 /* get number of component */
240 count = image_multi_count (hdr);
242 /* get start of the image payload, which in case of multi
243 * component images that points to a table of component sizes */
244 size = (uint32_t *)image_get_data (hdr);
246 /* get address of the proper component data start, which means
247 * skipping sizes table (add 1 for last, null entry) */
248 img_data = image_get_data (hdr) + (count + 1) * sizeof (uint32_t);
251 *len = uimage_to_cpu (size[idx]);
254 /* go over all indices preceding requested component idx */
255 for (i = 0; i < idx; i++) {
256 /* add up i-th component size, rounding up to 4 bytes */
257 offset += (uimage_to_cpu (size[i]) + 3) & ~3 ;
260 /* calculate idx-th component data address */
261 *data = img_data + offset;
268 static void image_print_type (const image_header_t *hdr)
270 const char *os, *arch, *type, *comp;
272 os = genimg_get_os_name (image_get_os (hdr));
273 arch = genimg_get_arch_name (image_get_arch (hdr));
274 type = genimg_get_type_name (image_get_type (hdr));
275 comp = genimg_get_comp_name (image_get_comp (hdr));
277 printf ("%s %s %s (%s)\n", arch, os, type, comp);
281 * image_print_contents - prints out the contents of the legacy format image
282 * @ptr: pointer to the legacy format image header
283 * @p: pointer to prefix string
285 * image_print_contents() formats a multi line legacy image contents description.
286 * The routine prints out all header fields followed by the size/offset data
287 * for MULTI/SCRIPT images.
290 * no returned results
292 void image_print_contents (const void *ptr)
294 const image_header_t *hdr = (const image_header_t *)ptr;
303 printf ("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name (hdr));
304 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
305 printf ("%sCreated: ", p);
306 genimg_print_time ((time_t)image_get_time (hdr));
308 printf ("%sImage Type: ", p);
309 image_print_type (hdr);
310 printf ("%sData Size: ", p);
311 genimg_print_size (image_get_data_size (hdr));
312 printf ("%sLoad Address: %08x\n", p, image_get_load (hdr));
313 printf ("%sEntry Point: %08x\n", p, image_get_ep (hdr));
315 if (image_check_type (hdr, IH_TYPE_MULTI) ||
316 image_check_type (hdr, IH_TYPE_SCRIPT)) {
319 ulong count = image_multi_count (hdr);
321 printf ("%sContents:\n", p);
322 for (i = 0; i < count; i++) {
323 image_multi_getimg (hdr, i, &data, &len);
325 printf ("%s Image %d: ", p, i);
326 genimg_print_size (len);
328 if (image_check_type (hdr, IH_TYPE_SCRIPT) && i > 0) {
330 * the user may need to know offsets
331 * if planning to do something with
334 printf ("%s Offset = 0x%08lx\n", p, data);
343 * image_get_ramdisk - get and verify ramdisk image
344 * @rd_addr: ramdisk image start address
345 * @arch: expected ramdisk architecture
346 * @verify: checksum verification flag
348 * image_get_ramdisk() returns a pointer to the verified ramdisk image
349 * header. Routine receives image start address and expected architecture
350 * flag. Verification done covers data and header integrity and os/type/arch
353 * If dataflash support is enabled routine checks for dataflash addresses
354 * and handles required dataflash reads.
357 * pointer to a ramdisk image header, if image was found and valid
358 * otherwise, return NULL
360 static const image_header_t *image_get_ramdisk (ulong rd_addr, uint8_t arch,
363 const image_header_t *rd_hdr = (const image_header_t *)rd_addr;
365 if (!image_check_magic (rd_hdr)) {
366 puts ("Bad Magic Number\n");
367 show_boot_progress (-10);
371 if (!image_check_hcrc (rd_hdr)) {
372 puts ("Bad Header Checksum\n");
373 show_boot_progress (-11);
377 show_boot_progress (10);
378 image_print_contents (rd_hdr);
381 puts(" Verifying Checksum ... ");
382 if (!image_check_dcrc (rd_hdr)) {
383 puts ("Bad Data CRC\n");
384 show_boot_progress (-12);
390 show_boot_progress (11);
392 if (!image_check_os (rd_hdr, IH_OS_LINUX) ||
393 !image_check_arch (rd_hdr, arch) ||
394 !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) {
395 printf ("No Linux %s Ramdisk Image\n",
396 genimg_get_arch_name(arch));
397 show_boot_progress (-13);
403 #endif /* !USE_HOSTCC */
405 /*****************************************************************************/
406 /* Shared dual-format routines */
407 /*****************************************************************************/
409 int getenv_yesno (char *var)
411 char *s = getenv (var);
412 return (s && (*s == 'n')) ? 0 : 1;
415 ulong getenv_bootm_low(void)
417 char *s = getenv ("bootm_low");
419 ulong tmp = simple_strtoul (s, NULL, 16);
423 #if defined(CONFIG_SYS_SDRAM_BASE)
424 return CONFIG_SYS_SDRAM_BASE;
425 #elif defined(CONFIG_ARM)
426 return gd->bd->bi_dram[0].start;
432 phys_size_t getenv_bootm_size(void)
434 char *s = getenv ("bootm_size");
437 #ifdef CONFIG_SYS_64BIT_STRTOUL
438 tmp = (phys_size_t)simple_strtoull (s, NULL, 16);
440 tmp = (phys_size_t)simple_strtoul (s, NULL, 16);
445 #if defined(CONFIG_ARM)
446 return gd->bd->bi_dram[0].size;
448 return gd->bd->bi_memsize;
452 void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
454 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
456 size_t tail = (len > chunksz) ? chunksz : len;
458 memmove (to, from, tail);
463 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
464 memmove (to, from, len);
465 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
467 #endif /* !USE_HOSTCC */
469 void genimg_print_size (uint32_t size)
472 printf ("%d Bytes = ", size);
473 print_size (size, "\n");
475 printf ("%d Bytes = %.2f kB = %.2f MB\n",
476 size, (double)size / 1.024e3,
477 (double)size / 1.048576e6);
481 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
482 static void genimg_print_time (time_t timestamp)
487 to_tm (timestamp, &tm);
488 printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
489 tm.tm_year, tm.tm_mon, tm.tm_mday,
490 tm.tm_hour, tm.tm_min, tm.tm_sec);
492 printf ("%s", ctime(×tamp));
495 #endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */
498 * get_table_entry_name - translate entry id to long name
499 * @table: pointer to a translation table for entries of a specific type
500 * @msg: message to be returned when translation fails
501 * @id: entry id to be translated
503 * get_table_entry_name() will go over translation table trying to find
504 * entry that matches given id. If matching entry is found, its long
505 * name is returned to the caller.
508 * long entry name if translation succeeds
511 char *get_table_entry_name (table_entry_t *table, char *msg, int id)
513 for (; table->id >= 0; ++table) {
518 return table->lname + gd->reloc_off;
524 const char *genimg_get_os_name (uint8_t os)
526 return (get_table_entry_name (uimage_os, "Unknown OS", os));
529 const char *genimg_get_arch_name (uint8_t arch)
531 return (get_table_entry_name (uimage_arch, "Unknown Architecture", arch));
534 const char *genimg_get_type_name (uint8_t type)
536 return (get_table_entry_name (uimage_type, "Unknown Image", type));
539 const char *genimg_get_comp_name (uint8_t comp)
541 return (get_table_entry_name (uimage_comp, "Unknown Compression", comp));
545 * get_table_entry_id - translate short entry name to id
546 * @table: pointer to a translation table for entries of a specific type
547 * @table_name: to be used in case of error
548 * @name: entry short name to be translated
550 * get_table_entry_id() will go over translation table trying to find
551 * entry that matches given short name. If matching entry is found,
552 * its id returned to the caller.
555 * entry id if translation succeeds
558 int get_table_entry_id (table_entry_t *table,
559 const char *table_name, const char *name)
565 for (t = table; t->id >= 0; ++t) {
566 if (t->sname && strcasecmp(t->sname, name) == 0)
570 fprintf (stderr, "\nInvalid %s Type - valid names are", table_name);
571 for (t = table; t->id >= 0; ++t) {
572 if (t->sname == NULL)
574 fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname);
577 fprintf (stderr, "\n");
579 for (t = table; t->id >= 0; ++t) {
580 if (t->sname && strcmp(t->sname + gd->reloc_off, name) == 0)
583 debug ("Invalid %s Type: %s\n", table_name, name);
584 #endif /* USE_HOSTCC */
588 int genimg_get_os_id (const char *name)
590 return (get_table_entry_id (uimage_os, "OS", name));
593 int genimg_get_arch_id (const char *name)
595 return (get_table_entry_id (uimage_arch, "CPU", name));
598 int genimg_get_type_id (const char *name)
600 return (get_table_entry_id (uimage_type, "Image", name));
603 int genimg_get_comp_id (const char *name)
605 return (get_table_entry_id (uimage_comp, "Compression", name));
610 * genimg_get_format - get image format type
611 * @img_addr: image start address
613 * genimg_get_format() checks whether provided address points to a valid
614 * legacy or FIT image.
616 * New uImage format and FDT blob are based on a libfdt. FDT blob
617 * may be passed directly or embedded in a FIT image. In both situations
618 * genimg_get_format() must be able to dectect libfdt header.
621 * image format type or IMAGE_FORMAT_INVALID if no image is present
623 int genimg_get_format (void *img_addr)
625 ulong format = IMAGE_FORMAT_INVALID;
626 const image_header_t *hdr;
627 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
631 hdr = (const image_header_t *)img_addr;
632 if (image_check_magic(hdr))
633 format = IMAGE_FORMAT_LEGACY;
634 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
636 fit_hdr = (char *)img_addr;
637 if (fdt_check_header (fit_hdr) == 0)
638 format = IMAGE_FORMAT_FIT;
646 * genimg_get_image - get image from special storage (if necessary)
647 * @img_addr: image start address
649 * genimg_get_image() checks if provided image start adddress is located
650 * in a dataflash storage. If so, image is moved to a system RAM memory.
653 * image start address after possible relocation from special storage
655 ulong genimg_get_image (ulong img_addr)
657 ulong ram_addr = img_addr;
659 #ifdef CONFIG_HAS_DATAFLASH
660 ulong h_size, d_size;
662 if (addr_dataflash (img_addr)){
663 /* ger RAM address */
664 ram_addr = CONFIG_SYS_LOAD_ADDR;
666 /* get header size */
667 h_size = image_get_header_size ();
668 #if defined(CONFIG_FIT)
669 if (sizeof(struct fdt_header) > h_size)
670 h_size = sizeof(struct fdt_header);
674 debug (" Reading image header from dataflash address "
675 "%08lx to RAM address %08lx\n", img_addr, ram_addr);
677 read_dataflash (img_addr, h_size, (char *)ram_addr);
680 switch (genimg_get_format ((void *)ram_addr)) {
681 case IMAGE_FORMAT_LEGACY:
682 d_size = image_get_data_size ((const image_header_t *)ram_addr);
683 debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n",
686 #if defined(CONFIG_FIT)
687 case IMAGE_FORMAT_FIT:
688 d_size = fit_get_size ((const void *)ram_addr) - h_size;
689 debug (" FIT/FDT format image found at 0x%08lx, size 0x%08lx\n",
694 printf (" No valid image found at 0x%08lx\n", img_addr);
698 /* read in image data */
699 debug (" Reading image remaining data from dataflash address "
700 "%08lx to RAM address %08lx\n", img_addr + h_size,
703 read_dataflash (img_addr + h_size, d_size,
704 (char *)(ram_addr + h_size));
707 #endif /* CONFIG_HAS_DATAFLASH */
713 * fit_has_config - check if there is a valid FIT configuration
714 * @images: pointer to the bootm command headers structure
716 * fit_has_config() checks if there is a FIT configuration in use
717 * (if FTI support is present).
720 * 0, no FIT support or no configuration found
721 * 1, configuration found
723 int genimg_has_config (bootm_headers_t *images)
725 #if defined(CONFIG_FIT)
726 if (images->fit_uname_cfg)
733 * boot_get_ramdisk - main ramdisk handling routine
734 * @argc: command argument count
735 * @argv: command argument list
736 * @images: pointer to the bootm images structure
737 * @arch: expected ramdisk architecture
738 * @rd_start: pointer to a ulong variable, will hold ramdisk start address
739 * @rd_end: pointer to a ulong variable, will hold ramdisk end
741 * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
742 * Curently supported are the following ramdisk sources:
743 * - multicomponent kernel/ramdisk image,
744 * - commandline provided address of decicated ramdisk image.
747 * 0, if ramdisk image was found and valid, or skiped
748 * rd_start and rd_end are set to ramdisk start/end addresses if
749 * ramdisk image is found and valid
751 * 1, if ramdisk image is found but corrupted, or invalid
752 * rd_start and rd_end are set to 0 if no ramdisk exists
754 int boot_get_ramdisk (int argc, char *argv[], bootm_headers_t *images,
755 uint8_t arch, ulong *rd_start, ulong *rd_end)
757 ulong rd_addr, rd_load;
758 ulong rd_data, rd_len;
759 const image_header_t *rd_hdr;
760 #if defined(CONFIG_FIT)
762 const char *fit_uname_config = NULL;
763 const char *fit_uname_ramdisk = NULL;
775 * Look for a '-' which indicates to ignore the
778 if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) {
779 debug ("## Skipping init Ramdisk\n");
780 rd_len = rd_data = 0;
781 } else if (argc >= 3 || genimg_has_config (images)) {
782 #if defined(CONFIG_FIT)
785 * If the init ramdisk comes from the FIT image and
786 * the FIT image address is omitted in the command
787 * line argument, try to use os FIT image address or
788 * default load address.
790 if (images->fit_uname_os)
791 default_addr = (ulong)images->fit_hdr_os;
793 default_addr = load_addr;
795 if (fit_parse_conf (argv[2], default_addr,
796 &rd_addr, &fit_uname_config)) {
797 debug ("* ramdisk: config '%s' from image at 0x%08lx\n",
798 fit_uname_config, rd_addr);
799 } else if (fit_parse_subimage (argv[2], default_addr,
800 &rd_addr, &fit_uname_ramdisk)) {
801 debug ("* ramdisk: subimage '%s' from image at 0x%08lx\n",
802 fit_uname_ramdisk, rd_addr);
806 rd_addr = simple_strtoul(argv[2], NULL, 16);
807 debug ("* ramdisk: cmdline image address = 0x%08lx\n",
810 #if defined(CONFIG_FIT)
812 /* use FIT configuration provided in first bootm
815 rd_addr = (ulong)images->fit_hdr_os;
816 fit_uname_config = images->fit_uname_cfg;
817 debug ("* ramdisk: using config '%s' from image at 0x%08lx\n",
818 fit_uname_config, rd_addr);
821 * Check whether configuration has ramdisk defined,
822 * if not, don't try to use it, quit silently.
824 fit_hdr = (void *)rd_addr;
825 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
826 if (cfg_noffset < 0) {
827 debug ("* ramdisk: no such config\n");
831 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
832 if (rd_noffset < 0) {
833 debug ("* ramdisk: no ramdisk in config\n");
839 /* copy from dataflash if needed */
840 rd_addr = genimg_get_image (rd_addr);
843 * Check if there is an initrd image at the
844 * address provided in the second bootm argument
845 * check image type, for FIT images get FIT node.
847 switch (genimg_get_format ((void *)rd_addr)) {
848 case IMAGE_FORMAT_LEGACY:
849 printf ("## Loading init Ramdisk from Legacy "
850 "Image at %08lx ...\n", rd_addr);
852 show_boot_progress (9);
853 rd_hdr = image_get_ramdisk (rd_addr, arch,
859 rd_data = image_get_data (rd_hdr);
860 rd_len = image_get_data_size (rd_hdr);
861 rd_load = image_get_load (rd_hdr);
863 #if defined(CONFIG_FIT)
864 case IMAGE_FORMAT_FIT:
865 fit_hdr = (void *)rd_addr;
866 printf ("## Loading init Ramdisk from FIT "
867 "Image at %08lx ...\n", rd_addr);
869 show_boot_progress (120);
870 if (!fit_check_format (fit_hdr)) {
871 puts ("Bad FIT ramdisk image format!\n");
872 show_boot_progress (-120);
875 show_boot_progress (121);
877 if (!fit_uname_ramdisk) {
879 * no ramdisk image node unit name, try to get config
880 * node first. If config unit node name is NULL
881 * fit_conf_get_node() will try to find default config node
883 show_boot_progress (122);
884 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
885 if (cfg_noffset < 0) {
886 puts ("Could not find configuration node\n");
887 show_boot_progress (-122);
890 fit_uname_config = fdt_get_name (fit_hdr, cfg_noffset, NULL);
891 printf (" Using '%s' configuration\n", fit_uname_config);
893 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
894 fit_uname_ramdisk = fit_get_name (fit_hdr, rd_noffset, NULL);
896 /* get ramdisk component image node offset */
897 show_boot_progress (123);
898 rd_noffset = fit_image_get_node (fit_hdr, fit_uname_ramdisk);
900 if (rd_noffset < 0) {
901 puts ("Could not find subimage node\n");
902 show_boot_progress (-124);
906 printf (" Trying '%s' ramdisk subimage\n", fit_uname_ramdisk);
908 show_boot_progress (125);
909 if (!fit_check_ramdisk (fit_hdr, rd_noffset, arch, images->verify))
912 /* get ramdisk image data address and length */
913 if (fit_image_get_data (fit_hdr, rd_noffset, &data, &size)) {
914 puts ("Could not find ramdisk subimage data!\n");
915 show_boot_progress (-127);
918 show_boot_progress (128);
920 rd_data = (ulong)data;
923 if (fit_image_get_load (fit_hdr, rd_noffset, &rd_load)) {
924 puts ("Can't get ramdisk subimage load address!\n");
925 show_boot_progress (-129);
928 show_boot_progress (129);
930 images->fit_hdr_rd = fit_hdr;
931 images->fit_uname_rd = fit_uname_ramdisk;
932 images->fit_noffset_rd = rd_noffset;
936 puts ("Wrong Ramdisk Image Format\n");
937 rd_data = rd_len = rd_load = 0;
941 #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO)
943 * We need to copy the ramdisk to SRAM to let Linux boot
946 memmove ((void *)rd_load, (uchar *)rd_data, rd_len);
949 #endif /* CONFIG_B2 || CONFIG_EVB4510 || CONFIG_ARMADILLO */
951 } else if (images->legacy_hdr_valid &&
952 image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
954 * Now check if we have a legacy mult-component image,
955 * get second entry data start address and len.
957 show_boot_progress (13);
958 printf ("## Loading init Ramdisk from multi component "
959 "Legacy Image at %08lx ...\n",
960 (ulong)images->legacy_hdr_os);
962 image_multi_getimg (images->legacy_hdr_os, 1, &rd_data, &rd_len);
967 show_boot_progress (14);
968 rd_len = rd_data = 0;
972 debug ("## No init Ramdisk\n");
975 *rd_end = rd_data + rd_len;
977 debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
983 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
985 * boot_ramdisk_high - relocate init ramdisk
986 * @lmb: pointer to lmb handle, will be used for memory mgmt
987 * @rd_data: ramdisk data start address
988 * @rd_len: ramdisk data length
989 * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
990 * start address (after possible relocation)
991 * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
992 * end address (after possible relocation)
994 * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
995 * variable and if requested ramdisk data is moved to a specified location.
997 * Initrd_start and initrd_end are set to final (after relocation) ramdisk
998 * start/end addresses if ramdisk image start and len were provided,
999 * otherwise set initrd_start and initrd_end set to zeros.
1005 int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
1006 ulong *initrd_start, ulong *initrd_end)
1010 int initrd_copy_to_ram = 1;
1012 if ((s = getenv ("initrd_high")) != NULL) {
1013 /* a value of "no" or a similar string will act like 0,
1014 * turning the "load high" feature off. This is intentional.
1016 initrd_high = simple_strtoul (s, NULL, 16);
1017 if (initrd_high == ~0)
1018 initrd_copy_to_ram = 0;
1020 /* not set, no restrictions to load high */
1025 #ifdef CONFIG_LOGBUFFER
1026 /* Prevent initrd from overwriting logbuffer */
1027 lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
1030 debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
1031 initrd_high, initrd_copy_to_ram);
1034 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
1035 debug (" in-place initrd\n");
1036 *initrd_start = rd_data;
1037 *initrd_end = rd_data + rd_len;
1038 lmb_reserve(lmb, rd_data, rd_len);
1041 *initrd_start = (ulong)lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
1043 *initrd_start = (ulong)lmb_alloc (lmb, rd_len, 0x1000);
1045 if (*initrd_start == 0) {
1046 puts ("ramdisk - allocation error\n");
1049 show_boot_progress (12);
1051 *initrd_end = *initrd_start + rd_len;
1052 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
1053 *initrd_start, *initrd_end);
1055 memmove_wd ((void *)*initrd_start,
1056 (void *)rd_data, rd_len, CHUNKSZ);
1064 debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
1065 *initrd_start, *initrd_end);
1072 #endif /* defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC) */
1074 #ifdef CONFIG_OF_LIBFDT
1075 static void fdt_error (const char *msg)
1079 puts (" - must RESET the board to recover.\n");
1082 static const image_header_t *image_get_fdt (ulong fdt_addr)
1084 const image_header_t *fdt_hdr = (const image_header_t *)fdt_addr;
1086 image_print_contents (fdt_hdr);
1088 puts (" Verifying Checksum ... ");
1089 if (!image_check_hcrc (fdt_hdr)) {
1090 fdt_error ("fdt header checksum invalid");
1094 if (!image_check_dcrc (fdt_hdr)) {
1095 fdt_error ("fdt checksum invalid");
1100 if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) {
1101 fdt_error ("uImage is not a fdt");
1104 if (image_get_comp (fdt_hdr) != IH_COMP_NONE) {
1105 fdt_error ("uImage is compressed");
1108 if (fdt_check_header ((char *)image_get_data (fdt_hdr)) != 0) {
1109 fdt_error ("uImage data is not a fdt");
1116 * fit_check_fdt - verify FIT format FDT subimage
1117 * @fit_hdr: pointer to the FIT header
1118 * fdt_noffset: FDT subimage node offset within FIT image
1119 * @verify: data CRC verification flag
1121 * fit_check_fdt() verifies integrity of the FDT subimage and from
1122 * specified FIT image.
1128 #if defined(CONFIG_FIT)
1129 static int fit_check_fdt (const void *fit, int fdt_noffset, int verify)
1131 fit_image_print (fit, fdt_noffset, " ");
1134 puts (" Verifying Hash Integrity ... ");
1135 if (!fit_image_check_hashes (fit, fdt_noffset)) {
1136 fdt_error ("Bad Data Hash");
1142 if (!fit_image_check_type (fit, fdt_noffset, IH_TYPE_FLATDT)) {
1143 fdt_error ("Not a FDT image");
1147 if (!fit_image_check_comp (fit, fdt_noffset, IH_COMP_NONE)) {
1148 fdt_error ("FDT image is compressed");
1154 #endif /* CONFIG_FIT */
1156 #ifndef CONFIG_SYS_FDT_PAD
1157 #define CONFIG_SYS_FDT_PAD 0x3000
1161 * boot_relocate_fdt - relocate flat device tree
1162 * @lmb: pointer to lmb handle, will be used for memory mgmt
1163 * @bootmap_base: base address of the bootmap region
1164 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1165 * @of_size: pointer to a ulong variable, will hold fdt length
1167 * boot_relocate_fdt() determines if the of_flat_tree address is within
1168 * the bootmap and if not relocates it into that region
1170 * of_flat_tree and of_size are set to final (after relocation) values
1176 int boot_relocate_fdt (struct lmb *lmb, ulong bootmap_base,
1177 char **of_flat_tree, ulong *of_size)
1179 char *fdt_blob = *of_flat_tree;
1187 if (fdt_check_header (fdt_blob) != 0) {
1188 fdt_error ("image is not a fdt");
1192 #ifndef CONFIG_SYS_NO_FLASH
1193 /* move the blob if it is in flash (set relocate) */
1194 if (addr2info ((ulong)fdt_blob) != NULL)
1199 * The blob needs to be inside the boot mapping.
1201 if (fdt_blob < (char *)bootmap_base)
1204 if ((fdt_blob + *of_size + CONFIG_SYS_FDT_PAD) >=
1205 ((char *)CONFIG_SYS_BOOTMAPSZ + bootmap_base))
1208 /* move flattend device tree if needed */
1213 /* position on a 4K boundary before the alloc_current */
1214 /* Pad the FDT by a specified amount */
1215 of_len = *of_size + CONFIG_SYS_FDT_PAD;
1216 of_start = (unsigned long)lmb_alloc_base(lmb, of_len, 0x1000,
1217 (CONFIG_SYS_BOOTMAPSZ + bootmap_base));
1219 if (of_start == 0) {
1220 puts("device tree - allocation error\n");
1224 debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
1225 (ulong)fdt_blob, (ulong)fdt_blob + *of_size - 1,
1228 printf (" Loading Device Tree to %08lx, end %08lx ... ",
1229 of_start, of_start + of_len - 1);
1231 err = fdt_open_into (fdt_blob, (void *)of_start, of_len);
1233 fdt_error ("fdt move failed");
1238 *of_flat_tree = (char *)of_start;
1241 *of_flat_tree = fdt_blob;
1242 of_len = (CONFIG_SYS_BOOTMAPSZ + bootmap_base) - (ulong)fdt_blob;
1243 lmb_reserve(lmb, (ulong)fdt_blob, of_len);
1244 fdt_set_totalsize(*of_flat_tree, of_len);
1249 set_working_fdt_addr(*of_flat_tree);
1257 * boot_get_fdt - main fdt handling routine
1258 * @argc: command argument count
1259 * @argv: command argument list
1260 * @images: pointer to the bootm images structure
1261 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1262 * @of_size: pointer to a ulong variable, will hold fdt length
1264 * boot_get_fdt() is responsible for finding a valid flat device tree image.
1265 * Curently supported are the following ramdisk sources:
1266 * - multicomponent kernel/ramdisk image,
1267 * - commandline provided address of decicated ramdisk image.
1270 * 0, if fdt image was found and valid, or skipped
1271 * of_flat_tree and of_size are set to fdt start address and length if
1272 * fdt image is found and valid
1274 * 1, if fdt image is found but corrupted
1275 * of_flat_tree and of_size are set to 0 if no fdt exists
1277 int boot_get_fdt (int flag, int argc, char *argv[], bootm_headers_t *images,
1278 char **of_flat_tree, ulong *of_size)
1280 const image_header_t *fdt_hdr;
1282 char *fdt_blob = NULL;
1283 ulong image_start, image_end;
1284 ulong load_start, load_end;
1285 #if defined(CONFIG_FIT)
1287 const char *fit_uname_config = NULL;
1288 const char *fit_uname_fdt = NULL;
1296 *of_flat_tree = NULL;
1299 if (argc > 3 || genimg_has_config (images)) {
1300 #if defined(CONFIG_FIT)
1303 * If the FDT blob comes from the FIT image and the
1304 * FIT image address is omitted in the command line
1305 * argument, try to use ramdisk or os FIT image
1306 * address or default load address.
1308 if (images->fit_uname_rd)
1309 default_addr = (ulong)images->fit_hdr_rd;
1310 else if (images->fit_uname_os)
1311 default_addr = (ulong)images->fit_hdr_os;
1313 default_addr = load_addr;
1315 if (fit_parse_conf (argv[3], default_addr,
1316 &fdt_addr, &fit_uname_config)) {
1317 debug ("* fdt: config '%s' from image at 0x%08lx\n",
1318 fit_uname_config, fdt_addr);
1319 } else if (fit_parse_subimage (argv[3], default_addr,
1320 &fdt_addr, &fit_uname_fdt)) {
1321 debug ("* fdt: subimage '%s' from image at 0x%08lx\n",
1322 fit_uname_fdt, fdt_addr);
1326 fdt_addr = simple_strtoul(argv[3], NULL, 16);
1327 debug ("* fdt: cmdline image address = 0x%08lx\n",
1330 #if defined(CONFIG_FIT)
1332 /* use FIT configuration provided in first bootm
1335 fdt_addr = (ulong)images->fit_hdr_os;
1336 fit_uname_config = images->fit_uname_cfg;
1337 debug ("* fdt: using config '%s' from image at 0x%08lx\n",
1338 fit_uname_config, fdt_addr);
1341 * Check whether configuration has FDT blob defined,
1342 * if not quit silently.
1344 fit_hdr = (void *)fdt_addr;
1345 cfg_noffset = fit_conf_get_node (fit_hdr,
1347 if (cfg_noffset < 0) {
1348 debug ("* fdt: no such config\n");
1352 fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
1354 if (fdt_noffset < 0) {
1355 debug ("* fdt: no fdt in config\n");
1361 debug ("## Checking for 'FDT'/'FDT Image' at %08lx\n",
1364 /* copy from dataflash if needed */
1365 fdt_addr = genimg_get_image (fdt_addr);
1368 * Check if there is an FDT image at the
1369 * address provided in the second bootm argument
1370 * check image type, for FIT images get a FIT node.
1372 switch (genimg_get_format ((void *)fdt_addr)) {
1373 case IMAGE_FORMAT_LEGACY:
1374 /* verify fdt_addr points to a valid image header */
1375 printf ("## Flattened Device Tree from Legacy Image at %08lx\n",
1377 fdt_hdr = image_get_fdt (fdt_addr);
1382 * move image data to the load address,
1383 * make sure we don't overwrite initial image
1385 image_start = (ulong)fdt_hdr;
1386 image_end = image_get_image_end (fdt_hdr);
1388 load_start = image_get_load (fdt_hdr);
1389 load_end = load_start + image_get_data_size (fdt_hdr);
1391 if ((load_start < image_end) && (load_end > image_start)) {
1392 fdt_error ("fdt overwritten");
1396 debug (" Loading FDT from 0x%08lx to 0x%08lx\n",
1397 image_get_data (fdt_hdr), load_start);
1399 memmove ((void *)load_start,
1400 (void *)image_get_data (fdt_hdr),
1401 image_get_data_size (fdt_hdr));
1403 fdt_blob = (char *)load_start;
1405 case IMAGE_FORMAT_FIT:
1407 * This case will catch both: new uImage format
1408 * (libfdt based) and raw FDT blob (also libfdt
1411 #if defined(CONFIG_FIT)
1412 /* check FDT blob vs FIT blob */
1413 if (fit_check_format ((const void *)fdt_addr)) {
1417 fit_hdr = (void *)fdt_addr;
1418 printf ("## Flattened Device Tree from FIT Image at %08lx\n",
1421 if (!fit_uname_fdt) {
1423 * no FDT blob image node unit name,
1424 * try to get config node first. If
1425 * config unit node name is NULL
1426 * fit_conf_get_node() will try to
1427 * find default config node
1429 cfg_noffset = fit_conf_get_node (fit_hdr,
1432 if (cfg_noffset < 0) {
1433 fdt_error ("Could not find configuration node\n");
1437 fit_uname_config = fdt_get_name (fit_hdr,
1439 printf (" Using '%s' configuration\n",
1442 fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
1444 fit_uname_fdt = fit_get_name (fit_hdr,
1447 /* get FDT component image node offset */
1448 fdt_noffset = fit_image_get_node (fit_hdr,
1451 if (fdt_noffset < 0) {
1452 fdt_error ("Could not find subimage node\n");
1456 printf (" Trying '%s' FDT blob subimage\n",
1459 if (!fit_check_fdt (fit_hdr, fdt_noffset,
1463 /* get ramdisk image data address and length */
1464 if (fit_image_get_data (fit_hdr, fdt_noffset,
1466 fdt_error ("Could not find FDT subimage data");
1470 /* verift that image data is a proper FDT blob */
1471 if (fdt_check_header ((char *)data) != 0) {
1472 fdt_error ("Subimage data is not a FTD");
1477 * move image data to the load address,
1478 * make sure we don't overwrite initial image
1480 image_start = (ulong)fit_hdr;
1481 image_end = fit_get_end (fit_hdr);
1483 if (fit_image_get_load (fit_hdr, fdt_noffset,
1484 &load_start) == 0) {
1485 load_end = load_start + size;
1487 if ((load_start < image_end) &&
1488 (load_end > image_start)) {
1489 fdt_error ("FDT overwritten");
1493 printf (" Loading FDT from 0x%08lx to 0x%08lx\n",
1494 (ulong)data, load_start);
1496 memmove ((void *)load_start,
1497 (void *)data, size);
1499 fdt_blob = (char *)load_start;
1501 fdt_blob = (char *)data;
1504 images->fit_hdr_fdt = fit_hdr;
1505 images->fit_uname_fdt = fit_uname_fdt;
1506 images->fit_noffset_fdt = fdt_noffset;
1514 fdt_blob = (char *)fdt_addr;
1515 debug ("* fdt: raw FDT blob\n");
1516 printf ("## Flattened Device Tree blob at %08lx\n", (long)fdt_blob);
1520 puts ("ERROR: Did not find a cmdline Flattened Device Tree\n");
1524 printf (" Booting using the fdt blob at 0x%x\n", (int)fdt_blob);
1526 } else if (images->legacy_hdr_valid &&
1527 image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1529 ulong fdt_data, fdt_len;
1532 * Now check if we have a legacy multi-component image,
1533 * get second entry data start address and len.
1535 printf ("## Flattened Device Tree from multi "
1536 "component Image at %08lX\n",
1537 (ulong)images->legacy_hdr_os);
1539 image_multi_getimg (images->legacy_hdr_os, 2, &fdt_data, &fdt_len);
1542 fdt_blob = (char *)fdt_data;
1543 printf (" Booting using the fdt at 0x%x\n", (int)fdt_blob);
1545 if (fdt_check_header (fdt_blob) != 0) {
1546 fdt_error ("image is not a fdt");
1550 if (be32_to_cpu (fdt_totalsize (fdt_blob)) != fdt_len) {
1551 fdt_error ("fdt size != image size");
1555 debug ("## No Flattened Device Tree\n");
1559 debug ("## No Flattened Device Tree\n");
1563 *of_flat_tree = fdt_blob;
1564 *of_size = be32_to_cpu (fdt_totalsize (fdt_blob));
1565 debug (" of_flat_tree at 0x%08lx size 0x%08lx\n",
1566 (ulong)*of_flat_tree, *of_size);
1575 #endif /* CONFIG_OF_LIBFDT */
1577 #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
1579 * boot_get_cmdline - allocate and initialize kernel cmdline
1580 * @lmb: pointer to lmb handle, will be used for memory mgmt
1581 * @cmd_start: pointer to a ulong variable, will hold cmdline start
1582 * @cmd_end: pointer to a ulong variable, will hold cmdline end
1583 * @bootmap_base: ulong variable, holds offset in physical memory to
1586 * boot_get_cmdline() allocates space for kernel command line below
1587 * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt
1588 * variable is present its contents is copied to allocated kernel
1595 int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end,
1601 cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf,
1602 CONFIG_SYS_BOOTMAPSZ + bootmap_base);
1604 if (cmdline == NULL)
1607 if ((s = getenv("bootargs")) == NULL)
1612 *cmd_start = (ulong) & cmdline[0];
1613 *cmd_end = *cmd_start + strlen(cmdline);
1615 debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
1621 * boot_get_kbd - allocate and initialize kernel copy of board info
1622 * @lmb: pointer to lmb handle, will be used for memory mgmt
1623 * @kbd: double pointer to board info data
1624 * @bootmap_base: ulong variable, holds offset in physical memory to
1627 * boot_get_kbd() allocates space for kernel copy of board info data below
1628 * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with
1629 * the current u-boot board info data.
1635 int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base)
1637 *kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
1638 CONFIG_SYS_BOOTMAPSZ + bootmap_base);
1644 debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
1646 #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
1647 do_bdinfo(NULL, 0, 0, NULL);
1652 #endif /* CONFIG_PPC || CONFIG_M68K */
1653 #endif /* !USE_HOSTCC */
1655 #if defined(CONFIG_FIT)
1656 /*****************************************************************************/
1657 /* New uImage format routines */
1658 /*****************************************************************************/
1660 static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr,
1661 ulong *addr, const char **name)
1668 sep = strchr (spec, sepc);
1671 *addr = simple_strtoul (spec, NULL, 16);
1681 * fit_parse_conf - parse FIT configuration spec
1682 * @spec: input string, containing configuration spec
1683 * @add_curr: current image address (to be used as a possible default)
1684 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1686 * @conf_name double pointer to a char, will hold pointer to a configuration
1689 * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
1690 * where <addr> is a FIT image address that contains configuration
1691 * with a <conf> unit name.
1693 * Address part is optional, and if omitted default add_curr will
1697 * 1 if spec is a valid configuration string,
1698 * addr and conf_name are set accordingly
1701 inline int fit_parse_conf (const char *spec, ulong addr_curr,
1702 ulong *addr, const char **conf_name)
1704 return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
1708 * fit_parse_subimage - parse FIT subimage spec
1709 * @spec: input string, containing subimage spec
1710 * @add_curr: current image address (to be used as a possible default)
1711 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1713 * @image_name: double pointer to a char, will hold pointer to a subimage name
1715 * fit_parse_subimage() expects subimage spec in the for of
1716 * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
1717 * subimage with a <subimg> unit name.
1719 * Address part is optional, and if omitted default add_curr will
1723 * 1 if spec is a valid subimage string,
1724 * addr and image_name are set accordingly
1727 inline int fit_parse_subimage (const char *spec, ulong addr_curr,
1728 ulong *addr, const char **image_name)
1730 return fit_parse_spec (spec, ':', addr_curr, addr, image_name);
1732 #endif /* !USE_HOSTCC */
1734 static void fit_get_debug (const void *fit, int noffset,
1735 char *prop_name, int err)
1737 debug ("Can't get '%s' property from FIT 0x%08lx, "
1738 "node: offset %d, name %s (%s)\n",
1739 prop_name, (ulong)fit, noffset,
1740 fit_get_name (fit, noffset, NULL),
1741 fdt_strerror (err));
1745 * fit_print_contents - prints out the contents of the FIT format image
1746 * @fit: pointer to the FIT format image header
1747 * @p: pointer to prefix string
1749 * fit_print_contents() formats a multi line FIT image contents description.
1750 * The routine prints out FIT image properties (root node level) follwed by
1751 * the details of each component image.
1754 * no returned results
1756 void fit_print_contents (const void *fit)
1767 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1777 /* Root node properties */
1778 ret = fit_get_desc (fit, 0, &desc);
1779 printf ("%sFIT description: ", p);
1781 printf ("unavailable\n");
1783 printf ("%s\n", desc);
1785 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1786 ret = fit_get_timestamp (fit, 0, ×tamp);
1787 printf ("%sCreated: ", p);
1789 printf ("unavailable\n");
1791 genimg_print_time (timestamp);
1794 /* Find images parent node offset */
1795 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
1796 if (images_noffset < 0) {
1797 printf ("Can't find images parent node '%s' (%s)\n",
1798 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
1802 /* Process its subnodes, print out component images details */
1803 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
1804 (noffset >= 0) && (ndepth > 0);
1805 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1808 * Direct child node of the images parent node,
1809 * i.e. component image node.
1811 printf ("%s Image %u (%s)\n", p, count++,
1812 fit_get_name(fit, noffset, NULL));
1814 fit_image_print (fit, noffset, p);
1818 /* Find configurations parent node offset */
1819 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
1820 if (confs_noffset < 0) {
1821 debug ("Can't get configurations parent node '%s' (%s)\n",
1822 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
1826 /* get default configuration unit name from default property */
1827 uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL);
1829 printf ("%s Default Configuration: '%s'\n", p, uname);
1831 /* Process its subnodes, print out configurations details */
1832 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth);
1833 (noffset >= 0) && (ndepth > 0);
1834 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1837 * Direct child node of the configurations parent node,
1838 * i.e. configuration node.
1840 printf ("%s Configuration %u (%s)\n", p, count++,
1841 fit_get_name(fit, noffset, NULL));
1843 fit_conf_print (fit, noffset, p);
1849 * fit_image_print - prints out the FIT component image details
1850 * @fit: pointer to the FIT format image header
1851 * @image_noffset: offset of the component image node
1852 * @p: pointer to prefix string
1854 * fit_image_print() lists all mandatory properies for the processed component
1855 * image. If present, hash nodes are printed out as well. Load
1856 * address for images of type firmware is also printed out. Since the load
1857 * address is not mandatory for firmware images, it will be output as
1858 * "unavailable" when not present.
1861 * no returned results
1863 void fit_image_print (const void *fit, int image_noffset, const char *p)
1866 uint8_t type, arch, os, comp;
1874 /* Mandatory properties */
1875 ret = fit_get_desc (fit, image_noffset, &desc);
1876 printf ("%s Description: ", p);
1878 printf ("unavailable\n");
1880 printf ("%s\n", desc);
1882 fit_image_get_type (fit, image_noffset, &type);
1883 printf ("%s Type: %s\n", p, genimg_get_type_name (type));
1885 fit_image_get_comp (fit, image_noffset, &comp);
1886 printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp));
1888 ret = fit_image_get_data (fit, image_noffset, &data, &size);
1891 printf ("%s Data Start: ", p);
1893 printf ("unavailable\n");
1895 printf ("0x%08lx\n", (ulong)data);
1898 printf ("%s Data Size: ", p);
1900 printf ("unavailable\n");
1902 genimg_print_size (size);
1904 /* Remaining, type dependent properties */
1905 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
1906 (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
1907 (type == IH_TYPE_FLATDT)) {
1908 fit_image_get_arch (fit, image_noffset, &arch);
1909 printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch));
1912 if (type == IH_TYPE_KERNEL) {
1913 fit_image_get_os (fit, image_noffset, &os);
1914 printf ("%s OS: %s\n", p, genimg_get_os_name (os));
1917 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
1918 (type == IH_TYPE_FIRMWARE)) {
1919 ret = fit_image_get_load (fit, image_noffset, &load);
1920 printf ("%s Load Address: ", p);
1922 printf ("unavailable\n");
1924 printf ("0x%08lx\n", load);
1927 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
1928 fit_image_get_entry (fit, image_noffset, &entry);
1929 printf ("%s Entry Point: ", p);
1931 printf ("unavailable\n");
1933 printf ("0x%08lx\n", entry);
1936 /* Process all hash subnodes of the component image node */
1937 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
1938 (noffset >= 0) && (ndepth > 0);
1939 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1941 /* Direct child node of the component image node */
1942 fit_image_print_hash (fit, noffset, p);
1948 * fit_image_print_hash - prints out the hash node details
1949 * @fit: pointer to the FIT format image header
1950 * @noffset: offset of the hash node
1951 * @p: pointer to prefix string
1953 * fit_image_print_hash() lists properies for the processed hash node
1956 * no returned results
1958 void fit_image_print_hash (const void *fit, int noffset, const char *p)
1966 * Check subnode name, must be equal to "hash".
1967 * Multiple hash nodes require unique unit node
1968 * names, e.g. hash@1, hash@2, etc.
1970 if (strncmp (fit_get_name(fit, noffset, NULL),
1972 strlen(FIT_HASH_NODENAME)) != 0)
1975 debug ("%s Hash node: '%s'\n", p,
1976 fit_get_name (fit, noffset, NULL));
1978 printf ("%s Hash algo: ", p);
1979 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
1980 printf ("invalid/unsupported\n");
1983 printf ("%s\n", algo);
1985 ret = fit_image_hash_get_value (fit, noffset, &value,
1987 printf ("%s Hash value: ", p);
1989 printf ("unavailable\n");
1991 for (i = 0; i < value_len; i++)
1992 printf ("%02x", value[i]);
1996 debug ("%s Hash len: %d\n", p, value_len);
2000 * fit_get_desc - get node description property
2001 * @fit: pointer to the FIT format image header
2002 * @noffset: node offset
2003 * @desc: double pointer to the char, will hold pointer to the descrption
2005 * fit_get_desc() reads description property from a given node, if
2006 * description is found pointer to it is returened in third call argument.
2012 int fit_get_desc (const void *fit, int noffset, char **desc)
2016 *desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len);
2017 if (*desc == NULL) {
2018 fit_get_debug (fit, noffset, FIT_DESC_PROP, len);
2026 * fit_get_timestamp - get node timestamp property
2027 * @fit: pointer to the FIT format image header
2028 * @noffset: node offset
2029 * @timestamp: pointer to the time_t, will hold read timestamp
2031 * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
2032 * is found and has a correct size its value is retured in third call
2037 * -1, on property read failure
2038 * -2, on wrong timestamp size
2040 int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp)
2045 data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len);
2047 fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len);
2050 if (len != sizeof (uint32_t)) {
2051 debug ("FIT timestamp with incorrect size of (%u)\n", len);
2055 *timestamp = uimage_to_cpu (*((uint32_t *)data));
2060 * fit_image_get_node - get node offset for component image of a given unit name
2061 * @fit: pointer to the FIT format image header
2062 * @image_uname: component image node unit name
2064 * fit_image_get_node() finds a component image (withing the '/images'
2065 * node) of a provided unit name. If image is found its node offset is
2066 * returned to the caller.
2069 * image node offset when found (>=0)
2070 * negative number on failure (FDT_ERR_* code)
2072 int fit_image_get_node (const void *fit, const char *image_uname)
2074 int noffset, images_noffset;
2076 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2077 if (images_noffset < 0) {
2078 debug ("Can't find images parent node '%s' (%s)\n",
2079 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2080 return images_noffset;
2083 noffset = fdt_subnode_offset (fit, images_noffset, image_uname);
2085 debug ("Can't get node offset for image unit name: '%s' (%s)\n",
2086 image_uname, fdt_strerror (noffset));
2093 * fit_image_get_os - get os id for a given component image node
2094 * @fit: pointer to the FIT format image header
2095 * @noffset: component image node offset
2096 * @os: pointer to the uint8_t, will hold os numeric id
2098 * fit_image_get_os() finds os property in a given component image node.
2099 * If the property is found, its (string) value is translated to the numeric
2100 * id which is returned to the caller.
2106 int fit_image_get_os (const void *fit, int noffset, uint8_t *os)
2111 /* Get OS name from property data */
2112 data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len);
2114 fit_get_debug (fit, noffset, FIT_OS_PROP, len);
2119 /* Translate OS name to id */
2120 *os = genimg_get_os_id (data);
2125 * fit_image_get_arch - get arch id for a given component image node
2126 * @fit: pointer to the FIT format image header
2127 * @noffset: component image node offset
2128 * @arch: pointer to the uint8_t, will hold arch numeric id
2130 * fit_image_get_arch() finds arch property in a given component image node.
2131 * If the property is found, its (string) value is translated to the numeric
2132 * id which is returned to the caller.
2138 int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch)
2143 /* Get architecture name from property data */
2144 data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len);
2146 fit_get_debug (fit, noffset, FIT_ARCH_PROP, len);
2151 /* Translate architecture name to id */
2152 *arch = genimg_get_arch_id (data);
2157 * fit_image_get_type - get type id for a given component image node
2158 * @fit: pointer to the FIT format image header
2159 * @noffset: component image node offset
2160 * @type: pointer to the uint8_t, will hold type numeric id
2162 * fit_image_get_type() finds type property in a given component image node.
2163 * If the property is found, its (string) value is translated to the numeric
2164 * id which is returned to the caller.
2170 int fit_image_get_type (const void *fit, int noffset, uint8_t *type)
2175 /* Get image type name from property data */
2176 data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len);
2178 fit_get_debug (fit, noffset, FIT_TYPE_PROP, len);
2183 /* Translate image type name to id */
2184 *type = genimg_get_type_id (data);
2189 * fit_image_get_comp - get comp id for a given component image node
2190 * @fit: pointer to the FIT format image header
2191 * @noffset: component image node offset
2192 * @comp: pointer to the uint8_t, will hold comp numeric id
2194 * fit_image_get_comp() finds comp property in a given component image node.
2195 * If the property is found, its (string) value is translated to the numeric
2196 * id which is returned to the caller.
2202 int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp)
2207 /* Get compression name from property data */
2208 data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len);
2210 fit_get_debug (fit, noffset, FIT_COMP_PROP, len);
2215 /* Translate compression name to id */
2216 *comp = genimg_get_comp_id (data);
2221 * fit_image_get_load - get load address property for a given component image node
2222 * @fit: pointer to the FIT format image header
2223 * @noffset: component image node offset
2224 * @load: pointer to the uint32_t, will hold load address
2226 * fit_image_get_load() finds load address property in a given component image node.
2227 * If the property is found, its value is returned to the caller.
2233 int fit_image_get_load (const void *fit, int noffset, ulong *load)
2236 const uint32_t *data;
2238 data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len);
2240 fit_get_debug (fit, noffset, FIT_LOAD_PROP, len);
2244 *load = uimage_to_cpu (*data);
2249 * fit_image_get_entry - get entry point address property for a given component image node
2250 * @fit: pointer to the FIT format image header
2251 * @noffset: component image node offset
2252 * @entry: pointer to the uint32_t, will hold entry point address
2254 * fit_image_get_entry() finds entry point address property in a given component image node.
2255 * If the property is found, its value is returned to the caller.
2261 int fit_image_get_entry (const void *fit, int noffset, ulong *entry)
2264 const uint32_t *data;
2266 data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len);
2268 fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len);
2272 *entry = uimage_to_cpu (*data);
2277 * fit_image_get_data - get data property and its size for a given component image node
2278 * @fit: pointer to the FIT format image header
2279 * @noffset: component image node offset
2280 * @data: double pointer to void, will hold data property's data address
2281 * @size: pointer to size_t, will hold data property's data size
2283 * fit_image_get_data() finds data property in a given component image node.
2284 * If the property is found its data start address and size are returned to
2291 int fit_image_get_data (const void *fit, int noffset,
2292 const void **data, size_t *size)
2296 *data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len);
2297 if (*data == NULL) {
2298 fit_get_debug (fit, noffset, FIT_DATA_PROP, len);
2308 * fit_image_hash_get_algo - get hash algorithm name
2309 * @fit: pointer to the FIT format image header
2310 * @noffset: hash node offset
2311 * @algo: double pointer to char, will hold pointer to the algorithm name
2313 * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
2314 * If the property is found its data start address is returned to the caller.
2320 int fit_image_hash_get_algo (const void *fit, int noffset, char **algo)
2324 *algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len);
2325 if (*algo == NULL) {
2326 fit_get_debug (fit, noffset, FIT_ALGO_PROP, len);
2334 * fit_image_hash_get_value - get hash value and length
2335 * @fit: pointer to the FIT format image header
2336 * @noffset: hash node offset
2337 * @value: double pointer to uint8_t, will hold address of a hash value data
2338 * @value_len: pointer to an int, will hold hash data length
2340 * fit_image_hash_get_value() finds hash value property in a given hash node.
2341 * If the property is found its data start address and size are returned to
2348 int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value,
2353 *value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len);
2354 if (*value == NULL) {
2355 fit_get_debug (fit, noffset, FIT_VALUE_PROP, len);
2365 * fit_set_timestamp - set node timestamp property
2366 * @fit: pointer to the FIT format image header
2367 * @noffset: node offset
2368 * @timestamp: timestamp value to be set
2370 * fit_set_timestamp() attempts to set timestamp property in the requested
2371 * node and returns operation status to the caller.
2375 * -1, on property read failure
2377 int fit_set_timestamp (void *fit, int noffset, time_t timestamp)
2382 t = cpu_to_uimage (timestamp);
2383 ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t,
2386 printf ("Can't set '%s' property for '%s' node (%s)\n",
2387 FIT_TIMESTAMP_PROP, fit_get_name (fit, noffset, NULL),
2388 fdt_strerror (ret));
2396 * calculate_hash - calculate and return hash for provided input data
2397 * @data: pointer to the input data
2398 * @data_len: data length
2399 * @algo: requested hash algorithm
2400 * @value: pointer to the char, will hold hash value data (caller must
2401 * allocate enough free space)
2402 * value_len: length of the calculated hash
2404 * calculate_hash() computes input data hash according to the requested algorithm.
2405 * Resulting hash value is placed in caller provided 'value' buffer, length
2406 * of the calculated hash is returned via value_len pointer argument.
2410 * -1, when algo is unsupported
2412 static int calculate_hash (const void *data, int data_len, const char *algo,
2413 uint8_t *value, int *value_len)
2415 if (strcmp (algo, "crc32") == 0 ) {
2416 *((uint32_t *)value) = crc32_wd (0, data, data_len,
2418 *((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value));
2420 } else if (strcmp (algo, "sha1") == 0 ) {
2421 sha1_csum_wd ((unsigned char *) data, data_len,
2422 (unsigned char *) value, CHUNKSZ_SHA1);
2424 } else if (strcmp (algo, "md5") == 0 ) {
2425 md5_wd ((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
2428 debug ("Unsupported hash alogrithm\n");
2436 * fit_set_hashes - process FIT component image nodes and calculate hashes
2437 * @fit: pointer to the FIT format image header
2439 * fit_set_hashes() adds hash values for all component images in the FIT blob.
2440 * Hashes are calculated for all component images which have hash subnodes
2441 * with algorithm property set to one of the supported hash algorithms.
2445 * libfdt error code, on failure
2447 int fit_set_hashes (void *fit)
2454 /* Find images parent node offset */
2455 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2456 if (images_noffset < 0) {
2457 printf ("Can't find images parent node '%s' (%s)\n",
2458 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2459 return images_noffset;
2462 /* Process its subnodes, print out component images details */
2463 for (ndepth = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
2464 (noffset >= 0) && (ndepth > 0);
2465 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2468 * Direct child node of the images parent node,
2469 * i.e. component image node.
2471 ret = fit_image_set_hashes (fit, noffset);
2481 * fit_image_set_hashes - calculate/set hashes for given component image node
2482 * @fit: pointer to the FIT format image header
2483 * @image_noffset: requested component image node
2485 * fit_image_set_hashes() adds hash values for an component image node. All
2486 * existing hash subnodes are checked, if algorithm property is set to one of
2487 * the supported hash algorithms, hash value is computed and corresponding
2488 * hash node property is set, for example:
2490 * Input component image node structure:
2492 * o image@1 (at image_noffset)
2493 * | - data = [binary data]
2497 * Output component image node structure:
2499 * o image@1 (at image_noffset)
2500 * | - data = [binary data]
2503 * |- value = sha1(data)
2509 int fit_image_set_hashes (void *fit, int image_noffset)
2514 uint8_t value[FIT_MAX_HASH_LEN];
2519 /* Get image data and data length */
2520 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
2521 printf ("Can't get image data/size\n");
2525 /* Process all hash subnodes of the component image node */
2526 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2527 (noffset >= 0) && (ndepth > 0);
2528 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2530 /* Direct child node of the component image node */
2533 * Check subnode name, must be equal to "hash".
2534 * Multiple hash nodes require unique unit node
2535 * names, e.g. hash@1, hash@2, etc.
2537 if (strncmp (fit_get_name(fit, noffset, NULL),
2539 strlen(FIT_HASH_NODENAME)) != 0) {
2540 /* Not a hash subnode, skip it */
2544 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2545 printf ("Can't get hash algo property for "
2546 "'%s' hash node in '%s' image node\n",
2547 fit_get_name (fit, noffset, NULL),
2548 fit_get_name (fit, image_noffset, NULL));
2552 if (calculate_hash (data, size, algo, value, &value_len)) {
2553 printf ("Unsupported hash algorithm (%s) for "
2554 "'%s' hash node in '%s' image node\n",
2555 algo, fit_get_name (fit, noffset, NULL),
2556 fit_get_name (fit, image_noffset, NULL));
2560 if (fit_image_hash_set_value (fit, noffset, value,
2562 printf ("Can't set hash value for "
2563 "'%s' hash node in '%s' image node\n",
2564 fit_get_name (fit, noffset, NULL),
2565 fit_get_name (fit, image_noffset, NULL));
2575 * fit_image_hash_set_value - set hash value in requested has node
2576 * @fit: pointer to the FIT format image header
2577 * @noffset: hash node offset
2578 * @value: hash value to be set
2579 * @value_len: hash value length
2581 * fit_image_hash_set_value() attempts to set hash value in a node at offset
2582 * given and returns operation status to the caller.
2588 int fit_image_hash_set_value (void *fit, int noffset, uint8_t *value,
2593 ret = fdt_setprop (fit, noffset, FIT_VALUE_PROP, value, value_len);
2595 printf ("Can't set hash '%s' property for '%s' node (%s)\n",
2596 FIT_VALUE_PROP, fit_get_name (fit, noffset, NULL),
2597 fdt_strerror (ret));
2603 #endif /* USE_HOSTCC */
2606 * fit_image_check_hashes - verify data intergity
2607 * @fit: pointer to the FIT format image header
2608 * @image_noffset: component image node offset
2610 * fit_image_check_hashes() goes over component image hash nodes,
2611 * re-calculates each data hash and compares with the value stored in hash
2615 * 1, if all hashes are valid
2616 * 0, otherwise (or on error)
2618 int fit_image_check_hashes (const void *fit, int image_noffset)
2625 uint8_t value[FIT_MAX_HASH_LEN];
2631 /* Get image data and data length */
2632 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
2633 printf ("Can't get image data/size\n");
2637 /* Process all hash subnodes of the component image node */
2638 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2639 (noffset >= 0) && (ndepth > 0);
2640 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2642 /* Direct child node of the component image node */
2645 * Check subnode name, must be equal to "hash".
2646 * Multiple hash nodes require unique unit node
2647 * names, e.g. hash@1, hash@2, etc.
2649 if (strncmp (fit_get_name(fit, noffset, NULL),
2651 strlen(FIT_HASH_NODENAME)) != 0)
2654 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2655 err_msg = " error!\nCan't get hash algo "
2659 printf ("%s", algo);
2661 if (fit_image_hash_get_value (fit, noffset, &fit_value,
2663 err_msg = " error!\nCan't get hash value "
2668 if (calculate_hash (data, size, algo, value, &value_len)) {
2669 err_msg = " error!\nUnsupported hash algorithm";
2673 if (value_len != fit_value_len) {
2674 err_msg = " error !\nBad hash value len";
2676 } else if (memcmp (value, fit_value, value_len) != 0) {
2677 err_msg = " error!\nBad hash value";
2687 printf ("%s for '%s' hash node in '%s' image node\n",
2688 err_msg, fit_get_name (fit, noffset, NULL),
2689 fit_get_name (fit, image_noffset, NULL));
2694 * fit_all_image_check_hashes - verify data intergity for all images
2695 * @fit: pointer to the FIT format image header
2697 * fit_all_image_check_hashes() goes over all images in the FIT and
2698 * for every images checks if all it's hashes are valid.
2701 * 1, if all hashes of all images are valid
2702 * 0, otherwise (or on error)
2704 int fit_all_image_check_hashes (const void *fit)
2711 /* Find images parent node offset */
2712 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2713 if (images_noffset < 0) {
2714 printf ("Can't find images parent node '%s' (%s)\n",
2715 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2719 /* Process all image subnodes, check hashes for each */
2720 printf ("## Checking hash(es) for FIT Image at %08lx ...\n",
2722 for (ndepth = 0, count = 0,
2723 noffset = fdt_next_node (fit, images_noffset, &ndepth);
2724 (noffset >= 0) && (ndepth > 0);
2725 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2728 * Direct child node of the images parent node,
2729 * i.e. component image node.
2731 printf (" Hash(es) for Image %u (%s): ", count++,
2732 fit_get_name (fit, noffset, NULL));
2734 if (!fit_image_check_hashes (fit, noffset))
2743 * fit_image_check_os - check whether image node is of a given os type
2744 * @fit: pointer to the FIT format image header
2745 * @noffset: component image node offset
2746 * @os: requested image os
2748 * fit_image_check_os() reads image os property and compares its numeric
2749 * id with the requested os. Comparison result is returned to the caller.
2752 * 1 if image is of given os type
2753 * 0 otherwise (or on error)
2755 int fit_image_check_os (const void *fit, int noffset, uint8_t os)
2759 if (fit_image_get_os (fit, noffset, &image_os))
2761 return (os == image_os);
2765 * fit_image_check_arch - check whether image node is of a given arch
2766 * @fit: pointer to the FIT format image header
2767 * @noffset: component image node offset
2768 * @arch: requested imagearch
2770 * fit_image_check_arch() reads image arch property and compares its numeric
2771 * id with the requested arch. Comparison result is returned to the caller.
2774 * 1 if image is of given arch
2775 * 0 otherwise (or on error)
2777 int fit_image_check_arch (const void *fit, int noffset, uint8_t arch)
2781 if (fit_image_get_arch (fit, noffset, &image_arch))
2783 return (arch == image_arch);
2787 * fit_image_check_type - check whether image node is of a given type
2788 * @fit: pointer to the FIT format image header
2789 * @noffset: component image node offset
2790 * @type: requested image type
2792 * fit_image_check_type() reads image type property and compares its numeric
2793 * id with the requested type. Comparison result is returned to the caller.
2796 * 1 if image is of given type
2797 * 0 otherwise (or on error)
2799 int fit_image_check_type (const void *fit, int noffset, uint8_t type)
2803 if (fit_image_get_type (fit, noffset, &image_type))
2805 return (type == image_type);
2809 * fit_image_check_comp - check whether image node uses given compression
2810 * @fit: pointer to the FIT format image header
2811 * @noffset: component image node offset
2812 * @comp: requested image compression type
2814 * fit_image_check_comp() reads image compression property and compares its
2815 * numeric id with the requested compression type. Comparison result is
2816 * returned to the caller.
2819 * 1 if image uses requested compression
2820 * 0 otherwise (or on error)
2822 int fit_image_check_comp (const void *fit, int noffset, uint8_t comp)
2826 if (fit_image_get_comp (fit, noffset, &image_comp))
2828 return (comp == image_comp);
2832 * fit_check_format - sanity check FIT image format
2833 * @fit: pointer to the FIT format image header
2835 * fit_check_format() runs a basic sanity FIT image verification.
2836 * Routine checks for mandatory properties, nodes, etc.
2842 int fit_check_format (const void *fit)
2844 /* mandatory / node 'description' property */
2845 if (fdt_getprop (fit, 0, FIT_DESC_PROP, NULL) == NULL) {
2846 debug ("Wrong FIT format: no description\n");
2850 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
2851 /* mandatory / node 'timestamp' property */
2852 if (fdt_getprop (fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
2853 debug ("Wrong FIT format: no timestamp\n");
2858 /* mandatory subimages parent '/images' node */
2859 if (fdt_path_offset (fit, FIT_IMAGES_PATH) < 0) {
2860 debug ("Wrong FIT format: no images parent node\n");
2868 * fit_conf_get_node - get node offset for configuration of a given unit name
2869 * @fit: pointer to the FIT format image header
2870 * @conf_uname: configuration node unit name
2872 * fit_conf_get_node() finds a configuration (withing the '/configurations'
2873 * parant node) of a provided unit name. If configuration is found its node offset
2874 * is returned to the caller.
2876 * When NULL is provided in second argument fit_conf_get_node() will search
2877 * for a default configuration node instead. Default configuration node unit name
2878 * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
2881 * configuration node offset when found (>=0)
2882 * negative number on failure (FDT_ERR_* code)
2884 int fit_conf_get_node (const void *fit, const char *conf_uname)
2886 int noffset, confs_noffset;
2889 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
2890 if (confs_noffset < 0) {
2891 debug ("Can't find configurations parent node '%s' (%s)\n",
2892 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
2893 return confs_noffset;
2896 if (conf_uname == NULL) {
2897 /* get configuration unit name from the default property */
2898 debug ("No configuration specified, trying default...\n");
2899 conf_uname = (char *)fdt_getprop (fit, confs_noffset, FIT_DEFAULT_PROP, &len);
2900 if (conf_uname == NULL) {
2901 fit_get_debug (fit, confs_noffset, FIT_DEFAULT_PROP, len);
2904 debug ("Found default configuration: '%s'\n", conf_uname);
2907 noffset = fdt_subnode_offset (fit, confs_noffset, conf_uname);
2909 debug ("Can't get node offset for configuration unit name: '%s' (%s)\n",
2910 conf_uname, fdt_strerror (noffset));
2916 static int __fit_conf_get_prop_node (const void *fit, int noffset,
2917 const char *prop_name)
2922 /* get kernel image unit name from configuration kernel property */
2923 uname = (char *)fdt_getprop (fit, noffset, prop_name, &len);
2927 return fit_image_get_node (fit, uname);
2931 * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
2932 * a given configuration
2933 * @fit: pointer to the FIT format image header
2934 * @noffset: configuration node offset
2936 * fit_conf_get_kernel_node() retrives kernel image node unit name from
2937 * configuration FIT_KERNEL_PROP property and translates it to the node
2941 * image node offset when found (>=0)
2942 * negative number on failure (FDT_ERR_* code)
2944 int fit_conf_get_kernel_node (const void *fit, int noffset)
2946 return __fit_conf_get_prop_node (fit, noffset, FIT_KERNEL_PROP);
2950 * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
2951 * a given configuration
2952 * @fit: pointer to the FIT format image header
2953 * @noffset: configuration node offset
2955 * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
2956 * configuration FIT_KERNEL_PROP property and translates it to the node
2960 * image node offset when found (>=0)
2961 * negative number on failure (FDT_ERR_* code)
2963 int fit_conf_get_ramdisk_node (const void *fit, int noffset)
2965 return __fit_conf_get_prop_node (fit, noffset, FIT_RAMDISK_PROP);
2969 * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
2970 * a given configuration
2971 * @fit: pointer to the FIT format image header
2972 * @noffset: configuration node offset
2974 * fit_conf_get_fdt_node() retrives fdt image node unit name from
2975 * configuration FIT_KERNEL_PROP property and translates it to the node
2979 * image node offset when found (>=0)
2980 * negative number on failure (FDT_ERR_* code)
2982 int fit_conf_get_fdt_node (const void *fit, int noffset)
2984 return __fit_conf_get_prop_node (fit, noffset, FIT_FDT_PROP);
2988 * fit_conf_print - prints out the FIT configuration details
2989 * @fit: pointer to the FIT format image header
2990 * @noffset: offset of the configuration node
2991 * @p: pointer to prefix string
2993 * fit_conf_print() lists all mandatory properies for the processed
2994 * configuration node.
2997 * no returned results
2999 void fit_conf_print (const void *fit, int noffset, const char *p)
3005 /* Mandatory properties */
3006 ret = fit_get_desc (fit, noffset, &desc);
3007 printf ("%s Description: ", p);
3009 printf ("unavailable\n");
3011 printf ("%s\n", desc);
3013 uname = (char *)fdt_getprop (fit, noffset, FIT_KERNEL_PROP, NULL);
3014 printf ("%s Kernel: ", p);
3016 printf ("unavailable\n");
3018 printf ("%s\n", uname);
3020 /* Optional properties */
3021 uname = (char *)fdt_getprop (fit, noffset, FIT_RAMDISK_PROP, NULL);
3023 printf ("%s Init Ramdisk: %s\n", p, uname);
3025 uname = (char *)fdt_getprop (fit, noffset, FIT_FDT_PROP, NULL);
3027 printf ("%s FDT: %s\n", p, uname);
3031 * fit_check_ramdisk - verify FIT format ramdisk subimage
3032 * @fit_hdr: pointer to the FIT ramdisk header
3033 * @rd_noffset: ramdisk subimage node offset within FIT image
3034 * @arch: requested ramdisk image architecture type
3035 * @verify: data CRC verification flag
3037 * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
3038 * specified FIT image.
3045 static int fit_check_ramdisk (const void *fit, int rd_noffset, uint8_t arch, int verify)
3047 fit_image_print (fit, rd_noffset, " ");
3050 puts (" Verifying Hash Integrity ... ");
3051 if (!fit_image_check_hashes (fit, rd_noffset)) {
3052 puts ("Bad Data Hash\n");
3053 show_boot_progress (-125);
3059 show_boot_progress (126);
3060 if (!fit_image_check_os (fit, rd_noffset, IH_OS_LINUX) ||
3061 !fit_image_check_arch (fit, rd_noffset, arch) ||
3062 !fit_image_check_type (fit, rd_noffset, IH_TYPE_RAMDISK)) {
3063 printf ("No Linux %s Ramdisk Image\n",
3064 genimg_get_arch_name(arch));
3065 show_boot_progress (-126);
3069 show_boot_progress (127);
3072 #endif /* USE_HOSTCC */
3073 #endif /* CONFIG_FIT */