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", },
142 { IH_TYPE_KWBIMAGE, "kwbimage", "Kirkwood Boot Image",},
146 static table_entry_t uimage_comp[] = {
147 { IH_COMP_NONE, "none", "uncompressed", },
148 { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", },
149 { IH_COMP_GZIP, "gzip", "gzip compressed", },
150 { IH_COMP_LZMA, "lzma", "lzma compressed", },
154 uint32_t crc32 (uint32_t, const unsigned char *, uint);
155 uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint);
156 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
157 static void genimg_print_time (time_t timestamp);
160 /*****************************************************************************/
161 /* Legacy format routines */
162 /*****************************************************************************/
163 int image_check_hcrc (const image_header_t *hdr)
166 ulong len = image_get_header_size ();
167 image_header_t header;
169 /* Copy header so we can blank CRC field for re-calculation */
170 memmove (&header, (char *)hdr, image_get_header_size ());
171 image_set_hcrc (&header, 0);
173 hcrc = crc32 (0, (unsigned char *)&header, len);
175 return (hcrc == image_get_hcrc (hdr));
178 int image_check_dcrc (const image_header_t *hdr)
180 ulong data = image_get_data (hdr);
181 ulong len = image_get_data_size (hdr);
182 ulong dcrc = crc32_wd (0, (unsigned char *)data, len, CHUNKSZ_CRC32);
184 return (dcrc == image_get_dcrc (hdr));
188 * image_multi_count - get component (sub-image) count
189 * @hdr: pointer to the header of the multi component image
191 * image_multi_count() returns number of components in a multi
194 * Note: no checking of the image type is done, caller must pass
195 * a valid multi component image.
198 * number of components
200 ulong image_multi_count (const image_header_t *hdr)
205 /* get start of the image payload, which in case of multi
206 * component images that points to a table of component sizes */
207 size = (uint32_t *)image_get_data (hdr);
209 /* count non empty slots */
210 for (i = 0; size[i]; ++i)
217 * image_multi_getimg - get component data address and size
218 * @hdr: pointer to the header of the multi component image
219 * @idx: index of the requested component
220 * @data: pointer to a ulong variable, will hold component data address
221 * @len: pointer to a ulong variable, will hold component size
223 * image_multi_getimg() returns size and data address for the requested
224 * component in a multi component image.
226 * Note: no checking of the image type is done, caller must pass
227 * a valid multi component image.
230 * data address and size of the component, if idx is valid
231 * 0 in data and len, if idx is out of range
233 void image_multi_getimg (const image_header_t *hdr, ulong idx,
234 ulong *data, ulong *len)
238 ulong offset, count, img_data;
240 /* get number of component */
241 count = image_multi_count (hdr);
243 /* get start of the image payload, which in case of multi
244 * component images that points to a table of component sizes */
245 size = (uint32_t *)image_get_data (hdr);
247 /* get address of the proper component data start, which means
248 * skipping sizes table (add 1 for last, null entry) */
249 img_data = image_get_data (hdr) + (count + 1) * sizeof (uint32_t);
252 *len = uimage_to_cpu (size[idx]);
255 /* go over all indices preceding requested component idx */
256 for (i = 0; i < idx; i++) {
257 /* add up i-th component size, rounding up to 4 bytes */
258 offset += (uimage_to_cpu (size[i]) + 3) & ~3 ;
261 /* calculate idx-th component data address */
262 *data = img_data + offset;
269 static void image_print_type (const image_header_t *hdr)
271 const char *os, *arch, *type, *comp;
273 os = genimg_get_os_name (image_get_os (hdr));
274 arch = genimg_get_arch_name (image_get_arch (hdr));
275 type = genimg_get_type_name (image_get_type (hdr));
276 comp = genimg_get_comp_name (image_get_comp (hdr));
278 printf ("%s %s %s (%s)\n", arch, os, type, comp);
282 * image_print_contents - prints out the contents of the legacy format image
283 * @ptr: pointer to the legacy format image header
284 * @p: pointer to prefix string
286 * image_print_contents() formats a multi line legacy image contents description.
287 * The routine prints out all header fields followed by the size/offset data
288 * for MULTI/SCRIPT images.
291 * no returned results
293 void image_print_contents (const void *ptr)
295 const image_header_t *hdr = (const image_header_t *)ptr;
304 printf ("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name (hdr));
305 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
306 printf ("%sCreated: ", p);
307 genimg_print_time ((time_t)image_get_time (hdr));
309 printf ("%sImage Type: ", p);
310 image_print_type (hdr);
311 printf ("%sData Size: ", p);
312 genimg_print_size (image_get_data_size (hdr));
313 printf ("%sLoad Address: %08x\n", p, image_get_load (hdr));
314 printf ("%sEntry Point: %08x\n", p, image_get_ep (hdr));
316 if (image_check_type (hdr, IH_TYPE_MULTI) ||
317 image_check_type (hdr, IH_TYPE_SCRIPT)) {
320 ulong count = image_multi_count (hdr);
322 printf ("%sContents:\n", p);
323 for (i = 0; i < count; i++) {
324 image_multi_getimg (hdr, i, &data, &len);
326 printf ("%s Image %d: ", p, i);
327 genimg_print_size (len);
329 if (image_check_type (hdr, IH_TYPE_SCRIPT) && i > 0) {
331 * the user may need to know offsets
332 * if planning to do something with
335 printf ("%s Offset = 0x%08lx\n", p, data);
344 * image_get_ramdisk - get and verify ramdisk image
345 * @rd_addr: ramdisk image start address
346 * @arch: expected ramdisk architecture
347 * @verify: checksum verification flag
349 * image_get_ramdisk() returns a pointer to the verified ramdisk image
350 * header. Routine receives image start address and expected architecture
351 * flag. Verification done covers data and header integrity and os/type/arch
354 * If dataflash support is enabled routine checks for dataflash addresses
355 * and handles required dataflash reads.
358 * pointer to a ramdisk image header, if image was found and valid
359 * otherwise, return NULL
361 static const image_header_t *image_get_ramdisk (ulong rd_addr, uint8_t arch,
364 const image_header_t *rd_hdr = (const image_header_t *)rd_addr;
366 if (!image_check_magic (rd_hdr)) {
367 puts ("Bad Magic Number\n");
368 show_boot_progress (-10);
372 if (!image_check_hcrc (rd_hdr)) {
373 puts ("Bad Header Checksum\n");
374 show_boot_progress (-11);
378 show_boot_progress (10);
379 image_print_contents (rd_hdr);
382 puts(" Verifying Checksum ... ");
383 if (!image_check_dcrc (rd_hdr)) {
384 puts ("Bad Data CRC\n");
385 show_boot_progress (-12);
391 show_boot_progress (11);
393 if (!image_check_os (rd_hdr, IH_OS_LINUX) ||
394 !image_check_arch (rd_hdr, arch) ||
395 !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) {
396 printf ("No Linux %s Ramdisk Image\n",
397 genimg_get_arch_name(arch));
398 show_boot_progress (-13);
404 #endif /* !USE_HOSTCC */
406 /*****************************************************************************/
407 /* Shared dual-format routines */
408 /*****************************************************************************/
410 int getenv_yesno (char *var)
412 char *s = getenv (var);
413 return (s && (*s == 'n')) ? 0 : 1;
416 ulong getenv_bootm_low(void)
418 char *s = getenv ("bootm_low");
420 ulong tmp = simple_strtoul (s, NULL, 16);
424 #if defined(CONFIG_SYS_SDRAM_BASE)
425 return CONFIG_SYS_SDRAM_BASE;
426 #elif defined(CONFIG_ARM)
427 return gd->bd->bi_dram[0].start;
433 phys_size_t getenv_bootm_size(void)
435 char *s = getenv ("bootm_size");
438 #ifdef CONFIG_SYS_64BIT_STRTOUL
439 tmp = (phys_size_t)simple_strtoull (s, NULL, 16);
441 tmp = (phys_size_t)simple_strtoul (s, NULL, 16);
446 #if defined(CONFIG_ARM)
447 return gd->bd->bi_dram[0].size;
449 return gd->bd->bi_memsize;
453 void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
455 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
457 size_t tail = (len > chunksz) ? chunksz : len;
459 memmove (to, from, tail);
464 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
465 memmove (to, from, len);
466 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
468 #endif /* !USE_HOSTCC */
470 void genimg_print_size (uint32_t size)
473 printf ("%d Bytes = ", size);
474 print_size (size, "\n");
476 printf ("%d Bytes = %.2f kB = %.2f MB\n",
477 size, (double)size / 1.024e3,
478 (double)size / 1.048576e6);
482 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
483 static void genimg_print_time (time_t timestamp)
488 to_tm (timestamp, &tm);
489 printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
490 tm.tm_year, tm.tm_mon, tm.tm_mday,
491 tm.tm_hour, tm.tm_min, tm.tm_sec);
493 printf ("%s", ctime(×tamp));
496 #endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */
499 * get_table_entry_name - translate entry id to long name
500 * @table: pointer to a translation table for entries of a specific type
501 * @msg: message to be returned when translation fails
502 * @id: entry id to be translated
504 * get_table_entry_name() will go over translation table trying to find
505 * entry that matches given id. If matching entry is found, its long
506 * name is returned to the caller.
509 * long entry name if translation succeeds
512 char *get_table_entry_name (table_entry_t *table, char *msg, int id)
514 for (; table->id >= 0; ++table) {
519 return table->lname + gd->reloc_off;
525 const char *genimg_get_os_name (uint8_t os)
527 return (get_table_entry_name (uimage_os, "Unknown OS", os));
530 const char *genimg_get_arch_name (uint8_t arch)
532 return (get_table_entry_name (uimage_arch, "Unknown Architecture", arch));
535 const char *genimg_get_type_name (uint8_t type)
537 return (get_table_entry_name (uimage_type, "Unknown Image", type));
540 const char *genimg_get_comp_name (uint8_t comp)
542 return (get_table_entry_name (uimage_comp, "Unknown Compression", comp));
546 * get_table_entry_id - translate short entry name to id
547 * @table: pointer to a translation table for entries of a specific type
548 * @table_name: to be used in case of error
549 * @name: entry short name to be translated
551 * get_table_entry_id() will go over translation table trying to find
552 * entry that matches given short name. If matching entry is found,
553 * its id returned to the caller.
556 * entry id if translation succeeds
559 int get_table_entry_id (table_entry_t *table,
560 const char *table_name, const char *name)
566 for (t = table; t->id >= 0; ++t) {
567 if (t->sname && strcasecmp(t->sname, name) == 0)
571 fprintf (stderr, "\nInvalid %s Type - valid names are", table_name);
572 for (t = table; t->id >= 0; ++t) {
573 if (t->sname == NULL)
575 fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname);
578 fprintf (stderr, "\n");
580 for (t = table; t->id >= 0; ++t) {
581 if (t->sname && strcmp(t->sname + gd->reloc_off, name) == 0)
584 debug ("Invalid %s Type: %s\n", table_name, name);
585 #endif /* USE_HOSTCC */
589 int genimg_get_os_id (const char *name)
591 return (get_table_entry_id (uimage_os, "OS", name));
594 int genimg_get_arch_id (const char *name)
596 return (get_table_entry_id (uimage_arch, "CPU", name));
599 int genimg_get_type_id (const char *name)
601 return (get_table_entry_id (uimage_type, "Image", name));
604 int genimg_get_comp_id (const char *name)
606 return (get_table_entry_id (uimage_comp, "Compression", name));
611 * genimg_get_format - get image format type
612 * @img_addr: image start address
614 * genimg_get_format() checks whether provided address points to a valid
615 * legacy or FIT image.
617 * New uImage format and FDT blob are based on a libfdt. FDT blob
618 * may be passed directly or embedded in a FIT image. In both situations
619 * genimg_get_format() must be able to dectect libfdt header.
622 * image format type or IMAGE_FORMAT_INVALID if no image is present
624 int genimg_get_format (void *img_addr)
626 ulong format = IMAGE_FORMAT_INVALID;
627 const image_header_t *hdr;
628 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
632 hdr = (const image_header_t *)img_addr;
633 if (image_check_magic(hdr))
634 format = IMAGE_FORMAT_LEGACY;
635 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
637 fit_hdr = (char *)img_addr;
638 if (fdt_check_header (fit_hdr) == 0)
639 format = IMAGE_FORMAT_FIT;
647 * genimg_get_image - get image from special storage (if necessary)
648 * @img_addr: image start address
650 * genimg_get_image() checks if provided image start adddress is located
651 * in a dataflash storage. If so, image is moved to a system RAM memory.
654 * image start address after possible relocation from special storage
656 ulong genimg_get_image (ulong img_addr)
658 ulong ram_addr = img_addr;
660 #ifdef CONFIG_HAS_DATAFLASH
661 ulong h_size, d_size;
663 if (addr_dataflash (img_addr)){
664 /* ger RAM address */
665 ram_addr = CONFIG_SYS_LOAD_ADDR;
667 /* get header size */
668 h_size = image_get_header_size ();
669 #if defined(CONFIG_FIT)
670 if (sizeof(struct fdt_header) > h_size)
671 h_size = sizeof(struct fdt_header);
675 debug (" Reading image header from dataflash address "
676 "%08lx to RAM address %08lx\n", img_addr, ram_addr);
678 read_dataflash (img_addr, h_size, (char *)ram_addr);
681 switch (genimg_get_format ((void *)ram_addr)) {
682 case IMAGE_FORMAT_LEGACY:
683 d_size = image_get_data_size ((const image_header_t *)ram_addr);
684 debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n",
687 #if defined(CONFIG_FIT)
688 case IMAGE_FORMAT_FIT:
689 d_size = fit_get_size ((const void *)ram_addr) - h_size;
690 debug (" FIT/FDT format image found at 0x%08lx, size 0x%08lx\n",
695 printf (" No valid image found at 0x%08lx\n", img_addr);
699 /* read in image data */
700 debug (" Reading image remaining data from dataflash address "
701 "%08lx to RAM address %08lx\n", img_addr + h_size,
704 read_dataflash (img_addr + h_size, d_size,
705 (char *)(ram_addr + h_size));
708 #endif /* CONFIG_HAS_DATAFLASH */
714 * fit_has_config - check if there is a valid FIT configuration
715 * @images: pointer to the bootm command headers structure
717 * fit_has_config() checks if there is a FIT configuration in use
718 * (if FTI support is present).
721 * 0, no FIT support or no configuration found
722 * 1, configuration found
724 int genimg_has_config (bootm_headers_t *images)
726 #if defined(CONFIG_FIT)
727 if (images->fit_uname_cfg)
734 * boot_get_ramdisk - main ramdisk handling routine
735 * @argc: command argument count
736 * @argv: command argument list
737 * @images: pointer to the bootm images structure
738 * @arch: expected ramdisk architecture
739 * @rd_start: pointer to a ulong variable, will hold ramdisk start address
740 * @rd_end: pointer to a ulong variable, will hold ramdisk end
742 * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
743 * Curently supported are the following ramdisk sources:
744 * - multicomponent kernel/ramdisk image,
745 * - commandline provided address of decicated ramdisk image.
748 * 0, if ramdisk image was found and valid, or skiped
749 * rd_start and rd_end are set to ramdisk start/end addresses if
750 * ramdisk image is found and valid
752 * 1, if ramdisk image is found but corrupted, or invalid
753 * rd_start and rd_end are set to 0 if no ramdisk exists
755 int boot_get_ramdisk (int argc, char *argv[], bootm_headers_t *images,
756 uint8_t arch, ulong *rd_start, ulong *rd_end)
758 ulong rd_addr, rd_load;
759 ulong rd_data, rd_len;
760 const image_header_t *rd_hdr;
761 #if defined(CONFIG_FIT)
763 const char *fit_uname_config = NULL;
764 const char *fit_uname_ramdisk = NULL;
776 * Look for a '-' which indicates to ignore the
779 if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) {
780 debug ("## Skipping init Ramdisk\n");
781 rd_len = rd_data = 0;
782 } else if (argc >= 3 || genimg_has_config (images)) {
783 #if defined(CONFIG_FIT)
786 * If the init ramdisk comes from the FIT image and
787 * the FIT image address is omitted in the command
788 * line argument, try to use os FIT image address or
789 * default load address.
791 if (images->fit_uname_os)
792 default_addr = (ulong)images->fit_hdr_os;
794 default_addr = load_addr;
796 if (fit_parse_conf (argv[2], default_addr,
797 &rd_addr, &fit_uname_config)) {
798 debug ("* ramdisk: config '%s' from image at 0x%08lx\n",
799 fit_uname_config, rd_addr);
800 } else if (fit_parse_subimage (argv[2], default_addr,
801 &rd_addr, &fit_uname_ramdisk)) {
802 debug ("* ramdisk: subimage '%s' from image at 0x%08lx\n",
803 fit_uname_ramdisk, rd_addr);
807 rd_addr = simple_strtoul(argv[2], NULL, 16);
808 debug ("* ramdisk: cmdline image address = 0x%08lx\n",
811 #if defined(CONFIG_FIT)
813 /* use FIT configuration provided in first bootm
816 rd_addr = (ulong)images->fit_hdr_os;
817 fit_uname_config = images->fit_uname_cfg;
818 debug ("* ramdisk: using config '%s' from image at 0x%08lx\n",
819 fit_uname_config, rd_addr);
822 * Check whether configuration has ramdisk defined,
823 * if not, don't try to use it, quit silently.
825 fit_hdr = (void *)rd_addr;
826 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
827 if (cfg_noffset < 0) {
828 debug ("* ramdisk: no such config\n");
832 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
833 if (rd_noffset < 0) {
834 debug ("* ramdisk: no ramdisk in config\n");
840 /* copy from dataflash if needed */
841 rd_addr = genimg_get_image (rd_addr);
844 * Check if there is an initrd image at the
845 * address provided in the second bootm argument
846 * check image type, for FIT images get FIT node.
848 switch (genimg_get_format ((void *)rd_addr)) {
849 case IMAGE_FORMAT_LEGACY:
850 printf ("## Loading init Ramdisk from Legacy "
851 "Image at %08lx ...\n", rd_addr);
853 show_boot_progress (9);
854 rd_hdr = image_get_ramdisk (rd_addr, arch,
860 rd_data = image_get_data (rd_hdr);
861 rd_len = image_get_data_size (rd_hdr);
862 rd_load = image_get_load (rd_hdr);
864 #if defined(CONFIG_FIT)
865 case IMAGE_FORMAT_FIT:
866 fit_hdr = (void *)rd_addr;
867 printf ("## Loading init Ramdisk from FIT "
868 "Image at %08lx ...\n", rd_addr);
870 show_boot_progress (120);
871 if (!fit_check_format (fit_hdr)) {
872 puts ("Bad FIT ramdisk image format!\n");
873 show_boot_progress (-120);
876 show_boot_progress (121);
878 if (!fit_uname_ramdisk) {
880 * no ramdisk image node unit name, try to get config
881 * node first. If config unit node name is NULL
882 * fit_conf_get_node() will try to find default config node
884 show_boot_progress (122);
885 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
886 if (cfg_noffset < 0) {
887 puts ("Could not find configuration node\n");
888 show_boot_progress (-122);
891 fit_uname_config = fdt_get_name (fit_hdr, cfg_noffset, NULL);
892 printf (" Using '%s' configuration\n", fit_uname_config);
894 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
895 fit_uname_ramdisk = fit_get_name (fit_hdr, rd_noffset, NULL);
897 /* get ramdisk component image node offset */
898 show_boot_progress (123);
899 rd_noffset = fit_image_get_node (fit_hdr, fit_uname_ramdisk);
901 if (rd_noffset < 0) {
902 puts ("Could not find subimage node\n");
903 show_boot_progress (-124);
907 printf (" Trying '%s' ramdisk subimage\n", fit_uname_ramdisk);
909 show_boot_progress (125);
910 if (!fit_check_ramdisk (fit_hdr, rd_noffset, arch, images->verify))
913 /* get ramdisk image data address and length */
914 if (fit_image_get_data (fit_hdr, rd_noffset, &data, &size)) {
915 puts ("Could not find ramdisk subimage data!\n");
916 show_boot_progress (-127);
919 show_boot_progress (128);
921 rd_data = (ulong)data;
924 if (fit_image_get_load (fit_hdr, rd_noffset, &rd_load)) {
925 puts ("Can't get ramdisk subimage load address!\n");
926 show_boot_progress (-129);
929 show_boot_progress (129);
931 images->fit_hdr_rd = fit_hdr;
932 images->fit_uname_rd = fit_uname_ramdisk;
933 images->fit_noffset_rd = rd_noffset;
937 puts ("Wrong Ramdisk Image Format\n");
938 rd_data = rd_len = rd_load = 0;
942 #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO)
944 * We need to copy the ramdisk to SRAM to let Linux boot
947 memmove ((void *)rd_load, (uchar *)rd_data, rd_len);
950 #endif /* CONFIG_B2 || CONFIG_EVB4510 || CONFIG_ARMADILLO */
952 } else if (images->legacy_hdr_valid &&
953 image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
955 * Now check if we have a legacy mult-component image,
956 * get second entry data start address and len.
958 show_boot_progress (13);
959 printf ("## Loading init Ramdisk from multi component "
960 "Legacy Image at %08lx ...\n",
961 (ulong)images->legacy_hdr_os);
963 image_multi_getimg (images->legacy_hdr_os, 1, &rd_data, &rd_len);
968 show_boot_progress (14);
969 rd_len = rd_data = 0;
973 debug ("## No init Ramdisk\n");
976 *rd_end = rd_data + rd_len;
978 debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
984 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
986 * boot_ramdisk_high - relocate init ramdisk
987 * @lmb: pointer to lmb handle, will be used for memory mgmt
988 * @rd_data: ramdisk data start address
989 * @rd_len: ramdisk data length
990 * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
991 * start address (after possible relocation)
992 * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
993 * end address (after possible relocation)
995 * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
996 * variable and if requested ramdisk data is moved to a specified location.
998 * Initrd_start and initrd_end are set to final (after relocation) ramdisk
999 * start/end addresses if ramdisk image start and len were provided,
1000 * otherwise set initrd_start and initrd_end set to zeros.
1006 int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
1007 ulong *initrd_start, ulong *initrd_end)
1011 int initrd_copy_to_ram = 1;
1013 if ((s = getenv ("initrd_high")) != NULL) {
1014 /* a value of "no" or a similar string will act like 0,
1015 * turning the "load high" feature off. This is intentional.
1017 initrd_high = simple_strtoul (s, NULL, 16);
1018 if (initrd_high == ~0)
1019 initrd_copy_to_ram = 0;
1021 /* not set, no restrictions to load high */
1026 #ifdef CONFIG_LOGBUFFER
1027 /* Prevent initrd from overwriting logbuffer */
1028 lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
1031 debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
1032 initrd_high, initrd_copy_to_ram);
1035 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
1036 debug (" in-place initrd\n");
1037 *initrd_start = rd_data;
1038 *initrd_end = rd_data + rd_len;
1039 lmb_reserve(lmb, rd_data, rd_len);
1042 *initrd_start = (ulong)lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
1044 *initrd_start = (ulong)lmb_alloc (lmb, rd_len, 0x1000);
1046 if (*initrd_start == 0) {
1047 puts ("ramdisk - allocation error\n");
1050 show_boot_progress (12);
1052 *initrd_end = *initrd_start + rd_len;
1053 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
1054 *initrd_start, *initrd_end);
1056 memmove_wd ((void *)*initrd_start,
1057 (void *)rd_data, rd_len, CHUNKSZ);
1065 debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
1066 *initrd_start, *initrd_end);
1073 #endif /* defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC) */
1075 #ifdef CONFIG_OF_LIBFDT
1076 static void fdt_error (const char *msg)
1080 puts (" - must RESET the board to recover.\n");
1083 static const image_header_t *image_get_fdt (ulong fdt_addr)
1085 const image_header_t *fdt_hdr = (const image_header_t *)fdt_addr;
1087 image_print_contents (fdt_hdr);
1089 puts (" Verifying Checksum ... ");
1090 if (!image_check_hcrc (fdt_hdr)) {
1091 fdt_error ("fdt header checksum invalid");
1095 if (!image_check_dcrc (fdt_hdr)) {
1096 fdt_error ("fdt checksum invalid");
1101 if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) {
1102 fdt_error ("uImage is not a fdt");
1105 if (image_get_comp (fdt_hdr) != IH_COMP_NONE) {
1106 fdt_error ("uImage is compressed");
1109 if (fdt_check_header ((char *)image_get_data (fdt_hdr)) != 0) {
1110 fdt_error ("uImage data is not a fdt");
1117 * fit_check_fdt - verify FIT format FDT subimage
1118 * @fit_hdr: pointer to the FIT header
1119 * fdt_noffset: FDT subimage node offset within FIT image
1120 * @verify: data CRC verification flag
1122 * fit_check_fdt() verifies integrity of the FDT subimage and from
1123 * specified FIT image.
1129 #if defined(CONFIG_FIT)
1130 static int fit_check_fdt (const void *fit, int fdt_noffset, int verify)
1132 fit_image_print (fit, fdt_noffset, " ");
1135 puts (" Verifying Hash Integrity ... ");
1136 if (!fit_image_check_hashes (fit, fdt_noffset)) {
1137 fdt_error ("Bad Data Hash");
1143 if (!fit_image_check_type (fit, fdt_noffset, IH_TYPE_FLATDT)) {
1144 fdt_error ("Not a FDT image");
1148 if (!fit_image_check_comp (fit, fdt_noffset, IH_COMP_NONE)) {
1149 fdt_error ("FDT image is compressed");
1155 #endif /* CONFIG_FIT */
1157 #ifndef CONFIG_SYS_FDT_PAD
1158 #define CONFIG_SYS_FDT_PAD 0x3000
1162 * boot_relocate_fdt - relocate flat device tree
1163 * @lmb: pointer to lmb handle, will be used for memory mgmt
1164 * @bootmap_base: base address of the bootmap region
1165 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1166 * @of_size: pointer to a ulong variable, will hold fdt length
1168 * boot_relocate_fdt() determines if the of_flat_tree address is within
1169 * the bootmap and if not relocates it into that region
1171 * of_flat_tree and of_size are set to final (after relocation) values
1177 int boot_relocate_fdt (struct lmb *lmb, ulong bootmap_base,
1178 char **of_flat_tree, ulong *of_size)
1180 char *fdt_blob = *of_flat_tree;
1188 if (fdt_check_header (fdt_blob) != 0) {
1189 fdt_error ("image is not a fdt");
1193 #ifndef CONFIG_SYS_NO_FLASH
1194 /* move the blob if it is in flash (set relocate) */
1195 if (addr2info ((ulong)fdt_blob) != NULL)
1200 * The blob needs to be inside the boot mapping.
1202 if (fdt_blob < (char *)bootmap_base)
1205 if ((fdt_blob + *of_size + CONFIG_SYS_FDT_PAD) >=
1206 ((char *)CONFIG_SYS_BOOTMAPSZ + bootmap_base))
1209 /* move flattend device tree if needed */
1214 /* position on a 4K boundary before the alloc_current */
1215 /* Pad the FDT by a specified amount */
1216 of_len = *of_size + CONFIG_SYS_FDT_PAD;
1217 of_start = (unsigned long)lmb_alloc_base(lmb, of_len, 0x1000,
1218 (CONFIG_SYS_BOOTMAPSZ + bootmap_base));
1220 if (of_start == 0) {
1221 puts("device tree - allocation error\n");
1225 debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
1226 (ulong)fdt_blob, (ulong)fdt_blob + *of_size - 1,
1229 printf (" Loading Device Tree to %08lx, end %08lx ... ",
1230 of_start, of_start + of_len - 1);
1232 err = fdt_open_into (fdt_blob, (void *)of_start, of_len);
1234 fdt_error ("fdt move failed");
1239 *of_flat_tree = (char *)of_start;
1242 *of_flat_tree = fdt_blob;
1243 of_len = (CONFIG_SYS_BOOTMAPSZ + bootmap_base) - (ulong)fdt_blob;
1244 lmb_reserve(lmb, (ulong)fdt_blob, of_len);
1245 fdt_set_totalsize(*of_flat_tree, of_len);
1250 set_working_fdt_addr(*of_flat_tree);
1258 * boot_get_fdt - main fdt handling routine
1259 * @argc: command argument count
1260 * @argv: command argument list
1261 * @images: pointer to the bootm images structure
1262 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1263 * @of_size: pointer to a ulong variable, will hold fdt length
1265 * boot_get_fdt() is responsible for finding a valid flat device tree image.
1266 * Curently supported are the following ramdisk sources:
1267 * - multicomponent kernel/ramdisk image,
1268 * - commandline provided address of decicated ramdisk image.
1271 * 0, if fdt image was found and valid, or skipped
1272 * of_flat_tree and of_size are set to fdt start address and length if
1273 * fdt image is found and valid
1275 * 1, if fdt image is found but corrupted
1276 * of_flat_tree and of_size are set to 0 if no fdt exists
1278 int boot_get_fdt (int flag, int argc, char *argv[], bootm_headers_t *images,
1279 char **of_flat_tree, ulong *of_size)
1281 const image_header_t *fdt_hdr;
1283 char *fdt_blob = NULL;
1284 ulong image_start, image_end;
1285 ulong load_start, load_end;
1286 #if defined(CONFIG_FIT)
1288 const char *fit_uname_config = NULL;
1289 const char *fit_uname_fdt = NULL;
1297 *of_flat_tree = NULL;
1300 if (argc > 3 || genimg_has_config (images)) {
1301 #if defined(CONFIG_FIT)
1304 * If the FDT blob comes from the FIT image and the
1305 * FIT image address is omitted in the command line
1306 * argument, try to use ramdisk or os FIT image
1307 * address or default load address.
1309 if (images->fit_uname_rd)
1310 default_addr = (ulong)images->fit_hdr_rd;
1311 else if (images->fit_uname_os)
1312 default_addr = (ulong)images->fit_hdr_os;
1314 default_addr = load_addr;
1316 if (fit_parse_conf (argv[3], default_addr,
1317 &fdt_addr, &fit_uname_config)) {
1318 debug ("* fdt: config '%s' from image at 0x%08lx\n",
1319 fit_uname_config, fdt_addr);
1320 } else if (fit_parse_subimage (argv[3], default_addr,
1321 &fdt_addr, &fit_uname_fdt)) {
1322 debug ("* fdt: subimage '%s' from image at 0x%08lx\n",
1323 fit_uname_fdt, fdt_addr);
1327 fdt_addr = simple_strtoul(argv[3], NULL, 16);
1328 debug ("* fdt: cmdline image address = 0x%08lx\n",
1331 #if defined(CONFIG_FIT)
1333 /* use FIT configuration provided in first bootm
1336 fdt_addr = (ulong)images->fit_hdr_os;
1337 fit_uname_config = images->fit_uname_cfg;
1338 debug ("* fdt: using config '%s' from image at 0x%08lx\n",
1339 fit_uname_config, fdt_addr);
1342 * Check whether configuration has FDT blob defined,
1343 * if not quit silently.
1345 fit_hdr = (void *)fdt_addr;
1346 cfg_noffset = fit_conf_get_node (fit_hdr,
1348 if (cfg_noffset < 0) {
1349 debug ("* fdt: no such config\n");
1353 fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
1355 if (fdt_noffset < 0) {
1356 debug ("* fdt: no fdt in config\n");
1362 debug ("## Checking for 'FDT'/'FDT Image' at %08lx\n",
1365 /* copy from dataflash if needed */
1366 fdt_addr = genimg_get_image (fdt_addr);
1369 * Check if there is an FDT image at the
1370 * address provided in the second bootm argument
1371 * check image type, for FIT images get a FIT node.
1373 switch (genimg_get_format ((void *)fdt_addr)) {
1374 case IMAGE_FORMAT_LEGACY:
1375 /* verify fdt_addr points to a valid image header */
1376 printf ("## Flattened Device Tree from Legacy Image at %08lx\n",
1378 fdt_hdr = image_get_fdt (fdt_addr);
1383 * move image data to the load address,
1384 * make sure we don't overwrite initial image
1386 image_start = (ulong)fdt_hdr;
1387 image_end = image_get_image_end (fdt_hdr);
1389 load_start = image_get_load (fdt_hdr);
1390 load_end = load_start + image_get_data_size (fdt_hdr);
1392 if ((load_start < image_end) && (load_end > image_start)) {
1393 fdt_error ("fdt overwritten");
1397 debug (" Loading FDT from 0x%08lx to 0x%08lx\n",
1398 image_get_data (fdt_hdr), load_start);
1400 memmove ((void *)load_start,
1401 (void *)image_get_data (fdt_hdr),
1402 image_get_data_size (fdt_hdr));
1404 fdt_blob = (char *)load_start;
1406 case IMAGE_FORMAT_FIT:
1408 * This case will catch both: new uImage format
1409 * (libfdt based) and raw FDT blob (also libfdt
1412 #if defined(CONFIG_FIT)
1413 /* check FDT blob vs FIT blob */
1414 if (fit_check_format ((const void *)fdt_addr)) {
1418 fit_hdr = (void *)fdt_addr;
1419 printf ("## Flattened Device Tree from FIT Image at %08lx\n",
1422 if (!fit_uname_fdt) {
1424 * no FDT blob image node unit name,
1425 * try to get config node first. If
1426 * config unit node name is NULL
1427 * fit_conf_get_node() will try to
1428 * find default config node
1430 cfg_noffset = fit_conf_get_node (fit_hdr,
1433 if (cfg_noffset < 0) {
1434 fdt_error ("Could not find configuration node\n");
1438 fit_uname_config = fdt_get_name (fit_hdr,
1440 printf (" Using '%s' configuration\n",
1443 fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
1445 fit_uname_fdt = fit_get_name (fit_hdr,
1448 /* get FDT component image node offset */
1449 fdt_noffset = fit_image_get_node (fit_hdr,
1452 if (fdt_noffset < 0) {
1453 fdt_error ("Could not find subimage node\n");
1457 printf (" Trying '%s' FDT blob subimage\n",
1460 if (!fit_check_fdt (fit_hdr, fdt_noffset,
1464 /* get ramdisk image data address and length */
1465 if (fit_image_get_data (fit_hdr, fdt_noffset,
1467 fdt_error ("Could not find FDT subimage data");
1471 /* verift that image data is a proper FDT blob */
1472 if (fdt_check_header ((char *)data) != 0) {
1473 fdt_error ("Subimage data is not a FTD");
1478 * move image data to the load address,
1479 * make sure we don't overwrite initial image
1481 image_start = (ulong)fit_hdr;
1482 image_end = fit_get_end (fit_hdr);
1484 if (fit_image_get_load (fit_hdr, fdt_noffset,
1485 &load_start) == 0) {
1486 load_end = load_start + size;
1488 if ((load_start < image_end) &&
1489 (load_end > image_start)) {
1490 fdt_error ("FDT overwritten");
1494 printf (" Loading FDT from 0x%08lx to 0x%08lx\n",
1495 (ulong)data, load_start);
1497 memmove ((void *)load_start,
1498 (void *)data, size);
1500 fdt_blob = (char *)load_start;
1502 fdt_blob = (char *)data;
1505 images->fit_hdr_fdt = fit_hdr;
1506 images->fit_uname_fdt = fit_uname_fdt;
1507 images->fit_noffset_fdt = fdt_noffset;
1515 fdt_blob = (char *)fdt_addr;
1516 debug ("* fdt: raw FDT blob\n");
1517 printf ("## Flattened Device Tree blob at %08lx\n", (long)fdt_blob);
1521 puts ("ERROR: Did not find a cmdline Flattened Device Tree\n");
1525 printf (" Booting using the fdt blob at 0x%x\n", (int)fdt_blob);
1527 } else if (images->legacy_hdr_valid &&
1528 image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1530 ulong fdt_data, fdt_len;
1533 * Now check if we have a legacy multi-component image,
1534 * get second entry data start address and len.
1536 printf ("## Flattened Device Tree from multi "
1537 "component Image at %08lX\n",
1538 (ulong)images->legacy_hdr_os);
1540 image_multi_getimg (images->legacy_hdr_os, 2, &fdt_data, &fdt_len);
1543 fdt_blob = (char *)fdt_data;
1544 printf (" Booting using the fdt at 0x%x\n", (int)fdt_blob);
1546 if (fdt_check_header (fdt_blob) != 0) {
1547 fdt_error ("image is not a fdt");
1551 if (be32_to_cpu (fdt_totalsize (fdt_blob)) != fdt_len) {
1552 fdt_error ("fdt size != image size");
1556 debug ("## No Flattened Device Tree\n");
1560 debug ("## No Flattened Device Tree\n");
1564 *of_flat_tree = fdt_blob;
1565 *of_size = be32_to_cpu (fdt_totalsize (fdt_blob));
1566 debug (" of_flat_tree at 0x%08lx size 0x%08lx\n",
1567 (ulong)*of_flat_tree, *of_size);
1576 #endif /* CONFIG_OF_LIBFDT */
1578 #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
1580 * boot_get_cmdline - allocate and initialize kernel cmdline
1581 * @lmb: pointer to lmb handle, will be used for memory mgmt
1582 * @cmd_start: pointer to a ulong variable, will hold cmdline start
1583 * @cmd_end: pointer to a ulong variable, will hold cmdline end
1584 * @bootmap_base: ulong variable, holds offset in physical memory to
1587 * boot_get_cmdline() allocates space for kernel command line below
1588 * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt
1589 * variable is present its contents is copied to allocated kernel
1596 int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end,
1602 cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf,
1603 CONFIG_SYS_BOOTMAPSZ + bootmap_base);
1605 if (cmdline == NULL)
1608 if ((s = getenv("bootargs")) == NULL)
1613 *cmd_start = (ulong) & cmdline[0];
1614 *cmd_end = *cmd_start + strlen(cmdline);
1616 debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
1622 * boot_get_kbd - allocate and initialize kernel copy of board info
1623 * @lmb: pointer to lmb handle, will be used for memory mgmt
1624 * @kbd: double pointer to board info data
1625 * @bootmap_base: ulong variable, holds offset in physical memory to
1628 * boot_get_kbd() allocates space for kernel copy of board info data below
1629 * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with
1630 * the current u-boot board info data.
1636 int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base)
1638 *kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
1639 CONFIG_SYS_BOOTMAPSZ + bootmap_base);
1645 debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
1647 #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
1648 do_bdinfo(NULL, 0, 0, NULL);
1653 #endif /* CONFIG_PPC || CONFIG_M68K */
1654 #endif /* !USE_HOSTCC */
1656 #if defined(CONFIG_FIT)
1657 /*****************************************************************************/
1658 /* New uImage format routines */
1659 /*****************************************************************************/
1661 static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr,
1662 ulong *addr, const char **name)
1669 sep = strchr (spec, sepc);
1672 *addr = simple_strtoul (spec, NULL, 16);
1682 * fit_parse_conf - parse FIT configuration spec
1683 * @spec: input string, containing configuration spec
1684 * @add_curr: current image address (to be used as a possible default)
1685 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1687 * @conf_name double pointer to a char, will hold pointer to a configuration
1690 * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
1691 * where <addr> is a FIT image address that contains configuration
1692 * with a <conf> unit name.
1694 * Address part is optional, and if omitted default add_curr will
1698 * 1 if spec is a valid configuration string,
1699 * addr and conf_name are set accordingly
1702 inline int fit_parse_conf (const char *spec, ulong addr_curr,
1703 ulong *addr, const char **conf_name)
1705 return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
1709 * fit_parse_subimage - parse FIT subimage spec
1710 * @spec: input string, containing subimage spec
1711 * @add_curr: current image address (to be used as a possible default)
1712 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1714 * @image_name: double pointer to a char, will hold pointer to a subimage name
1716 * fit_parse_subimage() expects subimage spec in the for of
1717 * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
1718 * subimage with a <subimg> unit name.
1720 * Address part is optional, and if omitted default add_curr will
1724 * 1 if spec is a valid subimage string,
1725 * addr and image_name are set accordingly
1728 inline int fit_parse_subimage (const char *spec, ulong addr_curr,
1729 ulong *addr, const char **image_name)
1731 return fit_parse_spec (spec, ':', addr_curr, addr, image_name);
1733 #endif /* !USE_HOSTCC */
1735 static void fit_get_debug (const void *fit, int noffset,
1736 char *prop_name, int err)
1738 debug ("Can't get '%s' property from FIT 0x%08lx, "
1739 "node: offset %d, name %s (%s)\n",
1740 prop_name, (ulong)fit, noffset,
1741 fit_get_name (fit, noffset, NULL),
1742 fdt_strerror (err));
1746 * fit_print_contents - prints out the contents of the FIT format image
1747 * @fit: pointer to the FIT format image header
1748 * @p: pointer to prefix string
1750 * fit_print_contents() formats a multi line FIT image contents description.
1751 * The routine prints out FIT image properties (root node level) follwed by
1752 * the details of each component image.
1755 * no returned results
1757 void fit_print_contents (const void *fit)
1768 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1778 /* Root node properties */
1779 ret = fit_get_desc (fit, 0, &desc);
1780 printf ("%sFIT description: ", p);
1782 printf ("unavailable\n");
1784 printf ("%s\n", desc);
1786 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1787 ret = fit_get_timestamp (fit, 0, ×tamp);
1788 printf ("%sCreated: ", p);
1790 printf ("unavailable\n");
1792 genimg_print_time (timestamp);
1795 /* Find images parent node offset */
1796 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
1797 if (images_noffset < 0) {
1798 printf ("Can't find images parent node '%s' (%s)\n",
1799 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
1803 /* Process its subnodes, print out component images details */
1804 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
1805 (noffset >= 0) && (ndepth > 0);
1806 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1809 * Direct child node of the images parent node,
1810 * i.e. component image node.
1812 printf ("%s Image %u (%s)\n", p, count++,
1813 fit_get_name(fit, noffset, NULL));
1815 fit_image_print (fit, noffset, p);
1819 /* Find configurations parent node offset */
1820 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
1821 if (confs_noffset < 0) {
1822 debug ("Can't get configurations parent node '%s' (%s)\n",
1823 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
1827 /* get default configuration unit name from default property */
1828 uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL);
1830 printf ("%s Default Configuration: '%s'\n", p, uname);
1832 /* Process its subnodes, print out configurations details */
1833 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth);
1834 (noffset >= 0) && (ndepth > 0);
1835 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1838 * Direct child node of the configurations parent node,
1839 * i.e. configuration node.
1841 printf ("%s Configuration %u (%s)\n", p, count++,
1842 fit_get_name(fit, noffset, NULL));
1844 fit_conf_print (fit, noffset, p);
1850 * fit_image_print - prints out the FIT component image details
1851 * @fit: pointer to the FIT format image header
1852 * @image_noffset: offset of the component image node
1853 * @p: pointer to prefix string
1855 * fit_image_print() lists all mandatory properies for the processed component
1856 * image. If present, hash nodes are printed out as well. Load
1857 * address for images of type firmware is also printed out. Since the load
1858 * address is not mandatory for firmware images, it will be output as
1859 * "unavailable" when not present.
1862 * no returned results
1864 void fit_image_print (const void *fit, int image_noffset, const char *p)
1867 uint8_t type, arch, os, comp;
1875 /* Mandatory properties */
1876 ret = fit_get_desc (fit, image_noffset, &desc);
1877 printf ("%s Description: ", p);
1879 printf ("unavailable\n");
1881 printf ("%s\n", desc);
1883 fit_image_get_type (fit, image_noffset, &type);
1884 printf ("%s Type: %s\n", p, genimg_get_type_name (type));
1886 fit_image_get_comp (fit, image_noffset, &comp);
1887 printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp));
1889 ret = fit_image_get_data (fit, image_noffset, &data, &size);
1892 printf ("%s Data Start: ", p);
1894 printf ("unavailable\n");
1896 printf ("0x%08lx\n", (ulong)data);
1899 printf ("%s Data Size: ", p);
1901 printf ("unavailable\n");
1903 genimg_print_size (size);
1905 /* Remaining, type dependent properties */
1906 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
1907 (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
1908 (type == IH_TYPE_FLATDT)) {
1909 fit_image_get_arch (fit, image_noffset, &arch);
1910 printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch));
1913 if (type == IH_TYPE_KERNEL) {
1914 fit_image_get_os (fit, image_noffset, &os);
1915 printf ("%s OS: %s\n", p, genimg_get_os_name (os));
1918 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
1919 (type == IH_TYPE_FIRMWARE)) {
1920 ret = fit_image_get_load (fit, image_noffset, &load);
1921 printf ("%s Load Address: ", p);
1923 printf ("unavailable\n");
1925 printf ("0x%08lx\n", load);
1928 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
1929 fit_image_get_entry (fit, image_noffset, &entry);
1930 printf ("%s Entry Point: ", p);
1932 printf ("unavailable\n");
1934 printf ("0x%08lx\n", entry);
1937 /* Process all hash subnodes of the component image node */
1938 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
1939 (noffset >= 0) && (ndepth > 0);
1940 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1942 /* Direct child node of the component image node */
1943 fit_image_print_hash (fit, noffset, p);
1949 * fit_image_print_hash - prints out the hash node details
1950 * @fit: pointer to the FIT format image header
1951 * @noffset: offset of the hash node
1952 * @p: pointer to prefix string
1954 * fit_image_print_hash() lists properies for the processed hash node
1957 * no returned results
1959 void fit_image_print_hash (const void *fit, int noffset, const char *p)
1967 * Check subnode name, must be equal to "hash".
1968 * Multiple hash nodes require unique unit node
1969 * names, e.g. hash@1, hash@2, etc.
1971 if (strncmp (fit_get_name(fit, noffset, NULL),
1973 strlen(FIT_HASH_NODENAME)) != 0)
1976 debug ("%s Hash node: '%s'\n", p,
1977 fit_get_name (fit, noffset, NULL));
1979 printf ("%s Hash algo: ", p);
1980 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
1981 printf ("invalid/unsupported\n");
1984 printf ("%s\n", algo);
1986 ret = fit_image_hash_get_value (fit, noffset, &value,
1988 printf ("%s Hash value: ", p);
1990 printf ("unavailable\n");
1992 for (i = 0; i < value_len; i++)
1993 printf ("%02x", value[i]);
1997 debug ("%s Hash len: %d\n", p, value_len);
2001 * fit_get_desc - get node description property
2002 * @fit: pointer to the FIT format image header
2003 * @noffset: node offset
2004 * @desc: double pointer to the char, will hold pointer to the descrption
2006 * fit_get_desc() reads description property from a given node, if
2007 * description is found pointer to it is returened in third call argument.
2013 int fit_get_desc (const void *fit, int noffset, char **desc)
2017 *desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len);
2018 if (*desc == NULL) {
2019 fit_get_debug (fit, noffset, FIT_DESC_PROP, len);
2027 * fit_get_timestamp - get node timestamp property
2028 * @fit: pointer to the FIT format image header
2029 * @noffset: node offset
2030 * @timestamp: pointer to the time_t, will hold read timestamp
2032 * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
2033 * is found and has a correct size its value is retured in third call
2038 * -1, on property read failure
2039 * -2, on wrong timestamp size
2041 int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp)
2046 data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len);
2048 fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len);
2051 if (len != sizeof (uint32_t)) {
2052 debug ("FIT timestamp with incorrect size of (%u)\n", len);
2056 *timestamp = uimage_to_cpu (*((uint32_t *)data));
2061 * fit_image_get_node - get node offset for component image of a given unit name
2062 * @fit: pointer to the FIT format image header
2063 * @image_uname: component image node unit name
2065 * fit_image_get_node() finds a component image (withing the '/images'
2066 * node) of a provided unit name. If image is found its node offset is
2067 * returned to the caller.
2070 * image node offset when found (>=0)
2071 * negative number on failure (FDT_ERR_* code)
2073 int fit_image_get_node (const void *fit, const char *image_uname)
2075 int noffset, images_noffset;
2077 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2078 if (images_noffset < 0) {
2079 debug ("Can't find images parent node '%s' (%s)\n",
2080 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2081 return images_noffset;
2084 noffset = fdt_subnode_offset (fit, images_noffset, image_uname);
2086 debug ("Can't get node offset for image unit name: '%s' (%s)\n",
2087 image_uname, fdt_strerror (noffset));
2094 * fit_image_get_os - get os id for a given component image node
2095 * @fit: pointer to the FIT format image header
2096 * @noffset: component image node offset
2097 * @os: pointer to the uint8_t, will hold os numeric id
2099 * fit_image_get_os() finds os property in a given component image node.
2100 * If the property is found, its (string) value is translated to the numeric
2101 * id which is returned to the caller.
2107 int fit_image_get_os (const void *fit, int noffset, uint8_t *os)
2112 /* Get OS name from property data */
2113 data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len);
2115 fit_get_debug (fit, noffset, FIT_OS_PROP, len);
2120 /* Translate OS name to id */
2121 *os = genimg_get_os_id (data);
2126 * fit_image_get_arch - get arch id for a given component image node
2127 * @fit: pointer to the FIT format image header
2128 * @noffset: component image node offset
2129 * @arch: pointer to the uint8_t, will hold arch numeric id
2131 * fit_image_get_arch() finds arch property in a given component image node.
2132 * If the property is found, its (string) value is translated to the numeric
2133 * id which is returned to the caller.
2139 int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch)
2144 /* Get architecture name from property data */
2145 data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len);
2147 fit_get_debug (fit, noffset, FIT_ARCH_PROP, len);
2152 /* Translate architecture name to id */
2153 *arch = genimg_get_arch_id (data);
2158 * fit_image_get_type - get type id for a given component image node
2159 * @fit: pointer to the FIT format image header
2160 * @noffset: component image node offset
2161 * @type: pointer to the uint8_t, will hold type numeric id
2163 * fit_image_get_type() finds type property in a given component image node.
2164 * If the property is found, its (string) value is translated to the numeric
2165 * id which is returned to the caller.
2171 int fit_image_get_type (const void *fit, int noffset, uint8_t *type)
2176 /* Get image type name from property data */
2177 data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len);
2179 fit_get_debug (fit, noffset, FIT_TYPE_PROP, len);
2184 /* Translate image type name to id */
2185 *type = genimg_get_type_id (data);
2190 * fit_image_get_comp - get comp id for a given component image node
2191 * @fit: pointer to the FIT format image header
2192 * @noffset: component image node offset
2193 * @comp: pointer to the uint8_t, will hold comp numeric id
2195 * fit_image_get_comp() finds comp property in a given component image node.
2196 * If the property is found, its (string) value is translated to the numeric
2197 * id which is returned to the caller.
2203 int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp)
2208 /* Get compression name from property data */
2209 data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len);
2211 fit_get_debug (fit, noffset, FIT_COMP_PROP, len);
2216 /* Translate compression name to id */
2217 *comp = genimg_get_comp_id (data);
2222 * fit_image_get_load - get load address property for a given component image node
2223 * @fit: pointer to the FIT format image header
2224 * @noffset: component image node offset
2225 * @load: pointer to the uint32_t, will hold load address
2227 * fit_image_get_load() finds load address property in a given component image node.
2228 * If the property is found, its value is returned to the caller.
2234 int fit_image_get_load (const void *fit, int noffset, ulong *load)
2237 const uint32_t *data;
2239 data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len);
2241 fit_get_debug (fit, noffset, FIT_LOAD_PROP, len);
2245 *load = uimage_to_cpu (*data);
2250 * fit_image_get_entry - get entry point address property for a given component image node
2251 * @fit: pointer to the FIT format image header
2252 * @noffset: component image node offset
2253 * @entry: pointer to the uint32_t, will hold entry point address
2255 * fit_image_get_entry() finds entry point address property in a given component image node.
2256 * If the property is found, its value is returned to the caller.
2262 int fit_image_get_entry (const void *fit, int noffset, ulong *entry)
2265 const uint32_t *data;
2267 data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len);
2269 fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len);
2273 *entry = uimage_to_cpu (*data);
2278 * fit_image_get_data - get data property and its size for a given component image node
2279 * @fit: pointer to the FIT format image header
2280 * @noffset: component image node offset
2281 * @data: double pointer to void, will hold data property's data address
2282 * @size: pointer to size_t, will hold data property's data size
2284 * fit_image_get_data() finds data property in a given component image node.
2285 * If the property is found its data start address and size are returned to
2292 int fit_image_get_data (const void *fit, int noffset,
2293 const void **data, size_t *size)
2297 *data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len);
2298 if (*data == NULL) {
2299 fit_get_debug (fit, noffset, FIT_DATA_PROP, len);
2309 * fit_image_hash_get_algo - get hash algorithm name
2310 * @fit: pointer to the FIT format image header
2311 * @noffset: hash node offset
2312 * @algo: double pointer to char, will hold pointer to the algorithm name
2314 * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
2315 * If the property is found its data start address is returned to the caller.
2321 int fit_image_hash_get_algo (const void *fit, int noffset, char **algo)
2325 *algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len);
2326 if (*algo == NULL) {
2327 fit_get_debug (fit, noffset, FIT_ALGO_PROP, len);
2335 * fit_image_hash_get_value - get hash value and length
2336 * @fit: pointer to the FIT format image header
2337 * @noffset: hash node offset
2338 * @value: double pointer to uint8_t, will hold address of a hash value data
2339 * @value_len: pointer to an int, will hold hash data length
2341 * fit_image_hash_get_value() finds hash value property in a given hash node.
2342 * If the property is found its data start address and size are returned to
2349 int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value,
2354 *value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len);
2355 if (*value == NULL) {
2356 fit_get_debug (fit, noffset, FIT_VALUE_PROP, len);
2366 * fit_set_timestamp - set node timestamp property
2367 * @fit: pointer to the FIT format image header
2368 * @noffset: node offset
2369 * @timestamp: timestamp value to be set
2371 * fit_set_timestamp() attempts to set timestamp property in the requested
2372 * node and returns operation status to the caller.
2376 * -1, on property read failure
2378 int fit_set_timestamp (void *fit, int noffset, time_t timestamp)
2383 t = cpu_to_uimage (timestamp);
2384 ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t,
2387 printf ("Can't set '%s' property for '%s' node (%s)\n",
2388 FIT_TIMESTAMP_PROP, fit_get_name (fit, noffset, NULL),
2389 fdt_strerror (ret));
2397 * calculate_hash - calculate and return hash for provided input data
2398 * @data: pointer to the input data
2399 * @data_len: data length
2400 * @algo: requested hash algorithm
2401 * @value: pointer to the char, will hold hash value data (caller must
2402 * allocate enough free space)
2403 * value_len: length of the calculated hash
2405 * calculate_hash() computes input data hash according to the requested algorithm.
2406 * Resulting hash value is placed in caller provided 'value' buffer, length
2407 * of the calculated hash is returned via value_len pointer argument.
2411 * -1, when algo is unsupported
2413 static int calculate_hash (const void *data, int data_len, const char *algo,
2414 uint8_t *value, int *value_len)
2416 if (strcmp (algo, "crc32") == 0 ) {
2417 *((uint32_t *)value) = crc32_wd (0, data, data_len,
2419 *((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value));
2421 } else if (strcmp (algo, "sha1") == 0 ) {
2422 sha1_csum_wd ((unsigned char *) data, data_len,
2423 (unsigned char *) value, CHUNKSZ_SHA1);
2425 } else if (strcmp (algo, "md5") == 0 ) {
2426 md5_wd ((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
2429 debug ("Unsupported hash alogrithm\n");
2437 * fit_set_hashes - process FIT component image nodes and calculate hashes
2438 * @fit: pointer to the FIT format image header
2440 * fit_set_hashes() adds hash values for all component images in the FIT blob.
2441 * Hashes are calculated for all component images which have hash subnodes
2442 * with algorithm property set to one of the supported hash algorithms.
2446 * libfdt error code, on failure
2448 int fit_set_hashes (void *fit)
2455 /* Find images parent node offset */
2456 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2457 if (images_noffset < 0) {
2458 printf ("Can't find images parent node '%s' (%s)\n",
2459 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2460 return images_noffset;
2463 /* Process its subnodes, print out component images details */
2464 for (ndepth = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
2465 (noffset >= 0) && (ndepth > 0);
2466 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2469 * Direct child node of the images parent node,
2470 * i.e. component image node.
2472 ret = fit_image_set_hashes (fit, noffset);
2482 * fit_image_set_hashes - calculate/set hashes for given component image node
2483 * @fit: pointer to the FIT format image header
2484 * @image_noffset: requested component image node
2486 * fit_image_set_hashes() adds hash values for an component image node. All
2487 * existing hash subnodes are checked, if algorithm property is set to one of
2488 * the supported hash algorithms, hash value is computed and corresponding
2489 * hash node property is set, for example:
2491 * Input component image node structure:
2493 * o image@1 (at image_noffset)
2494 * | - data = [binary data]
2498 * Output component image node structure:
2500 * o image@1 (at image_noffset)
2501 * | - data = [binary data]
2504 * |- value = sha1(data)
2510 int fit_image_set_hashes (void *fit, int image_noffset)
2515 uint8_t value[FIT_MAX_HASH_LEN];
2520 /* Get image data and data length */
2521 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
2522 printf ("Can't get image data/size\n");
2526 /* Process all hash subnodes of the component image node */
2527 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2528 (noffset >= 0) && (ndepth > 0);
2529 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2531 /* Direct child node of the component image node */
2534 * Check subnode name, must be equal to "hash".
2535 * Multiple hash nodes require unique unit node
2536 * names, e.g. hash@1, hash@2, etc.
2538 if (strncmp (fit_get_name(fit, noffset, NULL),
2540 strlen(FIT_HASH_NODENAME)) != 0) {
2541 /* Not a hash subnode, skip it */
2545 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2546 printf ("Can't get hash algo property for "
2547 "'%s' hash node in '%s' image node\n",
2548 fit_get_name (fit, noffset, NULL),
2549 fit_get_name (fit, image_noffset, NULL));
2553 if (calculate_hash (data, size, algo, value, &value_len)) {
2554 printf ("Unsupported hash algorithm (%s) for "
2555 "'%s' hash node in '%s' image node\n",
2556 algo, fit_get_name (fit, noffset, NULL),
2557 fit_get_name (fit, image_noffset, NULL));
2561 if (fit_image_hash_set_value (fit, noffset, value,
2563 printf ("Can't set hash value for "
2564 "'%s' hash node in '%s' image node\n",
2565 fit_get_name (fit, noffset, NULL),
2566 fit_get_name (fit, image_noffset, NULL));
2576 * fit_image_hash_set_value - set hash value in requested has node
2577 * @fit: pointer to the FIT format image header
2578 * @noffset: hash node offset
2579 * @value: hash value to be set
2580 * @value_len: hash value length
2582 * fit_image_hash_set_value() attempts to set hash value in a node at offset
2583 * given and returns operation status to the caller.
2589 int fit_image_hash_set_value (void *fit, int noffset, uint8_t *value,
2594 ret = fdt_setprop (fit, noffset, FIT_VALUE_PROP, value, value_len);
2596 printf ("Can't set hash '%s' property for '%s' node (%s)\n",
2597 FIT_VALUE_PROP, fit_get_name (fit, noffset, NULL),
2598 fdt_strerror (ret));
2604 #endif /* USE_HOSTCC */
2607 * fit_image_check_hashes - verify data intergity
2608 * @fit: pointer to the FIT format image header
2609 * @image_noffset: component image node offset
2611 * fit_image_check_hashes() goes over component image hash nodes,
2612 * re-calculates each data hash and compares with the value stored in hash
2616 * 1, if all hashes are valid
2617 * 0, otherwise (or on error)
2619 int fit_image_check_hashes (const void *fit, int image_noffset)
2626 uint8_t value[FIT_MAX_HASH_LEN];
2632 /* Get image data and data length */
2633 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
2634 printf ("Can't get image data/size\n");
2638 /* Process all hash subnodes of the component image node */
2639 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2640 (noffset >= 0) && (ndepth > 0);
2641 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2643 /* Direct child node of the component image node */
2646 * Check subnode name, must be equal to "hash".
2647 * Multiple hash nodes require unique unit node
2648 * names, e.g. hash@1, hash@2, etc.
2650 if (strncmp (fit_get_name(fit, noffset, NULL),
2652 strlen(FIT_HASH_NODENAME)) != 0)
2655 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2656 err_msg = " error!\nCan't get hash algo "
2660 printf ("%s", algo);
2662 if (fit_image_hash_get_value (fit, noffset, &fit_value,
2664 err_msg = " error!\nCan't get hash value "
2669 if (calculate_hash (data, size, algo, value, &value_len)) {
2670 err_msg = " error!\nUnsupported hash algorithm";
2674 if (value_len != fit_value_len) {
2675 err_msg = " error !\nBad hash value len";
2677 } else if (memcmp (value, fit_value, value_len) != 0) {
2678 err_msg = " error!\nBad hash value";
2688 printf ("%s for '%s' hash node in '%s' image node\n",
2689 err_msg, fit_get_name (fit, noffset, NULL),
2690 fit_get_name (fit, image_noffset, NULL));
2695 * fit_all_image_check_hashes - verify data intergity for all images
2696 * @fit: pointer to the FIT format image header
2698 * fit_all_image_check_hashes() goes over all images in the FIT and
2699 * for every images checks if all it's hashes are valid.
2702 * 1, if all hashes of all images are valid
2703 * 0, otherwise (or on error)
2705 int fit_all_image_check_hashes (const void *fit)
2712 /* Find images parent node offset */
2713 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2714 if (images_noffset < 0) {
2715 printf ("Can't find images parent node '%s' (%s)\n",
2716 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2720 /* Process all image subnodes, check hashes for each */
2721 printf ("## Checking hash(es) for FIT Image at %08lx ...\n",
2723 for (ndepth = 0, count = 0,
2724 noffset = fdt_next_node (fit, images_noffset, &ndepth);
2725 (noffset >= 0) && (ndepth > 0);
2726 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2729 * Direct child node of the images parent node,
2730 * i.e. component image node.
2732 printf (" Hash(es) for Image %u (%s): ", count++,
2733 fit_get_name (fit, noffset, NULL));
2735 if (!fit_image_check_hashes (fit, noffset))
2744 * fit_image_check_os - check whether image node is of a given os type
2745 * @fit: pointer to the FIT format image header
2746 * @noffset: component image node offset
2747 * @os: requested image os
2749 * fit_image_check_os() reads image os property and compares its numeric
2750 * id with the requested os. Comparison result is returned to the caller.
2753 * 1 if image is of given os type
2754 * 0 otherwise (or on error)
2756 int fit_image_check_os (const void *fit, int noffset, uint8_t os)
2760 if (fit_image_get_os (fit, noffset, &image_os))
2762 return (os == image_os);
2766 * fit_image_check_arch - check whether image node is of a given arch
2767 * @fit: pointer to the FIT format image header
2768 * @noffset: component image node offset
2769 * @arch: requested imagearch
2771 * fit_image_check_arch() reads image arch property and compares its numeric
2772 * id with the requested arch. Comparison result is returned to the caller.
2775 * 1 if image is of given arch
2776 * 0 otherwise (or on error)
2778 int fit_image_check_arch (const void *fit, int noffset, uint8_t arch)
2782 if (fit_image_get_arch (fit, noffset, &image_arch))
2784 return (arch == image_arch);
2788 * fit_image_check_type - check whether image node is of a given type
2789 * @fit: pointer to the FIT format image header
2790 * @noffset: component image node offset
2791 * @type: requested image type
2793 * fit_image_check_type() reads image type property and compares its numeric
2794 * id with the requested type. Comparison result is returned to the caller.
2797 * 1 if image is of given type
2798 * 0 otherwise (or on error)
2800 int fit_image_check_type (const void *fit, int noffset, uint8_t type)
2804 if (fit_image_get_type (fit, noffset, &image_type))
2806 return (type == image_type);
2810 * fit_image_check_comp - check whether image node uses given compression
2811 * @fit: pointer to the FIT format image header
2812 * @noffset: component image node offset
2813 * @comp: requested image compression type
2815 * fit_image_check_comp() reads image compression property and compares its
2816 * numeric id with the requested compression type. Comparison result is
2817 * returned to the caller.
2820 * 1 if image uses requested compression
2821 * 0 otherwise (or on error)
2823 int fit_image_check_comp (const void *fit, int noffset, uint8_t comp)
2827 if (fit_image_get_comp (fit, noffset, &image_comp))
2829 return (comp == image_comp);
2833 * fit_check_format - sanity check FIT image format
2834 * @fit: pointer to the FIT format image header
2836 * fit_check_format() runs a basic sanity FIT image verification.
2837 * Routine checks for mandatory properties, nodes, etc.
2843 int fit_check_format (const void *fit)
2845 /* mandatory / node 'description' property */
2846 if (fdt_getprop (fit, 0, FIT_DESC_PROP, NULL) == NULL) {
2847 debug ("Wrong FIT format: no description\n");
2851 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
2852 /* mandatory / node 'timestamp' property */
2853 if (fdt_getprop (fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
2854 debug ("Wrong FIT format: no timestamp\n");
2859 /* mandatory subimages parent '/images' node */
2860 if (fdt_path_offset (fit, FIT_IMAGES_PATH) < 0) {
2861 debug ("Wrong FIT format: no images parent node\n");
2869 * fit_conf_get_node - get node offset for configuration of a given unit name
2870 * @fit: pointer to the FIT format image header
2871 * @conf_uname: configuration node unit name
2873 * fit_conf_get_node() finds a configuration (withing the '/configurations'
2874 * parant node) of a provided unit name. If configuration is found its node offset
2875 * is returned to the caller.
2877 * When NULL is provided in second argument fit_conf_get_node() will search
2878 * for a default configuration node instead. Default configuration node unit name
2879 * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
2882 * configuration node offset when found (>=0)
2883 * negative number on failure (FDT_ERR_* code)
2885 int fit_conf_get_node (const void *fit, const char *conf_uname)
2887 int noffset, confs_noffset;
2890 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
2891 if (confs_noffset < 0) {
2892 debug ("Can't find configurations parent node '%s' (%s)\n",
2893 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
2894 return confs_noffset;
2897 if (conf_uname == NULL) {
2898 /* get configuration unit name from the default property */
2899 debug ("No configuration specified, trying default...\n");
2900 conf_uname = (char *)fdt_getprop (fit, confs_noffset, FIT_DEFAULT_PROP, &len);
2901 if (conf_uname == NULL) {
2902 fit_get_debug (fit, confs_noffset, FIT_DEFAULT_PROP, len);
2905 debug ("Found default configuration: '%s'\n", conf_uname);
2908 noffset = fdt_subnode_offset (fit, confs_noffset, conf_uname);
2910 debug ("Can't get node offset for configuration unit name: '%s' (%s)\n",
2911 conf_uname, fdt_strerror (noffset));
2917 static int __fit_conf_get_prop_node (const void *fit, int noffset,
2918 const char *prop_name)
2923 /* get kernel image unit name from configuration kernel property */
2924 uname = (char *)fdt_getprop (fit, noffset, prop_name, &len);
2928 return fit_image_get_node (fit, uname);
2932 * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
2933 * a given configuration
2934 * @fit: pointer to the FIT format image header
2935 * @noffset: configuration node offset
2937 * fit_conf_get_kernel_node() retrives kernel image node unit name from
2938 * configuration FIT_KERNEL_PROP property and translates it to the node
2942 * image node offset when found (>=0)
2943 * negative number on failure (FDT_ERR_* code)
2945 int fit_conf_get_kernel_node (const void *fit, int noffset)
2947 return __fit_conf_get_prop_node (fit, noffset, FIT_KERNEL_PROP);
2951 * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
2952 * a given configuration
2953 * @fit: pointer to the FIT format image header
2954 * @noffset: configuration node offset
2956 * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
2957 * configuration FIT_KERNEL_PROP property and translates it to the node
2961 * image node offset when found (>=0)
2962 * negative number on failure (FDT_ERR_* code)
2964 int fit_conf_get_ramdisk_node (const void *fit, int noffset)
2966 return __fit_conf_get_prop_node (fit, noffset, FIT_RAMDISK_PROP);
2970 * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
2971 * a given configuration
2972 * @fit: pointer to the FIT format image header
2973 * @noffset: configuration node offset
2975 * fit_conf_get_fdt_node() retrives fdt image node unit name from
2976 * configuration FIT_KERNEL_PROP property and translates it to the node
2980 * image node offset when found (>=0)
2981 * negative number on failure (FDT_ERR_* code)
2983 int fit_conf_get_fdt_node (const void *fit, int noffset)
2985 return __fit_conf_get_prop_node (fit, noffset, FIT_FDT_PROP);
2989 * fit_conf_print - prints out the FIT configuration details
2990 * @fit: pointer to the FIT format image header
2991 * @noffset: offset of the configuration node
2992 * @p: pointer to prefix string
2994 * fit_conf_print() lists all mandatory properies for the processed
2995 * configuration node.
2998 * no returned results
3000 void fit_conf_print (const void *fit, int noffset, const char *p)
3006 /* Mandatory properties */
3007 ret = fit_get_desc (fit, noffset, &desc);
3008 printf ("%s Description: ", p);
3010 printf ("unavailable\n");
3012 printf ("%s\n", desc);
3014 uname = (char *)fdt_getprop (fit, noffset, FIT_KERNEL_PROP, NULL);
3015 printf ("%s Kernel: ", p);
3017 printf ("unavailable\n");
3019 printf ("%s\n", uname);
3021 /* Optional properties */
3022 uname = (char *)fdt_getprop (fit, noffset, FIT_RAMDISK_PROP, NULL);
3024 printf ("%s Init Ramdisk: %s\n", p, uname);
3026 uname = (char *)fdt_getprop (fit, noffset, FIT_FDT_PROP, NULL);
3028 printf ("%s FDT: %s\n", p, uname);
3032 * fit_check_ramdisk - verify FIT format ramdisk subimage
3033 * @fit_hdr: pointer to the FIT ramdisk header
3034 * @rd_noffset: ramdisk subimage node offset within FIT image
3035 * @arch: requested ramdisk image architecture type
3036 * @verify: data CRC verification flag
3038 * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
3039 * specified FIT image.
3046 static int fit_check_ramdisk (const void *fit, int rd_noffset, uint8_t arch, int verify)
3048 fit_image_print (fit, rd_noffset, " ");
3051 puts (" Verifying Hash Integrity ... ");
3052 if (!fit_image_check_hashes (fit, rd_noffset)) {
3053 puts ("Bad Data Hash\n");
3054 show_boot_progress (-125);
3060 show_boot_progress (126);
3061 if (!fit_image_check_os (fit, rd_noffset, IH_OS_LINUX) ||
3062 !fit_image_check_arch (fit, rd_noffset, arch) ||
3063 !fit_image_check_type (fit, rd_noffset, IH_TYPE_RAMDISK)) {
3064 printf ("No Linux %s Ramdisk Image\n",
3065 genimg_get_arch_name(arch));
3066 show_boot_progress (-126);
3070 show_boot_progress (127);
3073 #endif /* USE_HOSTCC */
3074 #endif /* CONFIG_FIT */