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 image_header_t* image_get_ramdisk (ulong rd_addr, uint8_t arch,
72 #include <u-boot/md5.h>
75 #endif /* !USE_HOSTCC*/
77 typedef struct table_entry {
78 int id; /* as defined in image.h */
79 char *sname; /* short (input) name */
80 char *lname; /* long (output) name */
83 static table_entry_t uimage_arch[] = {
84 { IH_ARCH_INVALID, NULL, "Invalid ARCH", },
85 { IH_ARCH_ALPHA, "alpha", "Alpha", },
86 { IH_ARCH_ARM, "arm", "ARM", },
87 { IH_ARCH_I386, "x86", "Intel x86", },
88 { IH_ARCH_IA64, "ia64", "IA64", },
89 { IH_ARCH_M68K, "m68k", "M68K", },
90 { IH_ARCH_MICROBLAZE, "microblaze", "MicroBlaze", },
91 { IH_ARCH_MIPS, "mips", "MIPS", },
92 { IH_ARCH_MIPS64, "mips64", "MIPS 64 Bit", },
93 { IH_ARCH_NIOS, "nios", "NIOS", },
94 { IH_ARCH_NIOS2, "nios2", "NIOS II", },
95 { IH_ARCH_PPC, "powerpc", "PowerPC", },
96 { IH_ARCH_PPC, "ppc", "PowerPC", },
97 { IH_ARCH_S390, "s390", "IBM S390", },
98 { IH_ARCH_SH, "sh", "SuperH", },
99 { IH_ARCH_SPARC, "sparc", "SPARC", },
100 { IH_ARCH_SPARC64, "sparc64", "SPARC 64 Bit", },
101 { IH_ARCH_BLACKFIN, "blackfin", "Blackfin", },
102 { IH_ARCH_AVR32, "avr32", "AVR32", },
106 static table_entry_t uimage_os[] = {
107 { IH_OS_INVALID, NULL, "Invalid OS", },
108 { IH_OS_LINUX, "linux", "Linux", },
109 #if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC)
110 { IH_OS_LYNXOS, "lynxos", "LynxOS", },
112 { IH_OS_NETBSD, "netbsd", "NetBSD", },
113 { IH_OS_RTEMS, "rtems", "RTEMS", },
114 { IH_OS_U_BOOT, "u-boot", "U-Boot", },
115 #if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC)
116 { IH_OS_QNX, "qnx", "QNX", },
117 { IH_OS_VXWORKS, "vxworks", "VxWorks", },
120 { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", },
121 { IH_OS_DELL, "dell", "Dell", },
122 { IH_OS_ESIX, "esix", "Esix", },
123 { IH_OS_FREEBSD, "freebsd", "FreeBSD", },
124 { IH_OS_IRIX, "irix", "Irix", },
125 { IH_OS_NCR, "ncr", "NCR", },
126 { IH_OS_OPENBSD, "openbsd", "OpenBSD", },
127 { IH_OS_PSOS, "psos", "pSOS", },
128 { IH_OS_SCO, "sco", "SCO", },
129 { IH_OS_SOLARIS, "solaris", "Solaris", },
130 { IH_OS_SVR4, "svr4", "SVR4", },
135 static table_entry_t uimage_type[] = {
136 { IH_TYPE_INVALID, NULL, "Invalid Image", },
137 { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", },
138 { IH_TYPE_FIRMWARE, "firmware", "Firmware", },
139 { IH_TYPE_KERNEL, "kernel", "Kernel Image", },
140 { IH_TYPE_MULTI, "multi", "Multi-File Image", },
141 { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", },
142 { IH_TYPE_SCRIPT, "script", "Script", },
143 { IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
144 { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", },
148 static table_entry_t uimage_comp[] = {
149 { IH_COMP_NONE, "none", "uncompressed", },
150 { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", },
151 { IH_COMP_GZIP, "gzip", "gzip compressed", },
155 uint32_t crc32 (uint32_t, const unsigned char *, uint);
156 uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint);
157 static void genimg_print_size (uint32_t size);
158 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
159 static void genimg_print_time (time_t timestamp);
162 /*****************************************************************************/
163 /* Legacy format routines */
164 /*****************************************************************************/
165 int image_check_hcrc (image_header_t *hdr)
168 ulong len = image_get_header_size ();
169 image_header_t header;
171 /* Copy header so we can blank CRC field for re-calculation */
172 memmove (&header, (char *)hdr, image_get_header_size ());
173 image_set_hcrc (&header, 0);
175 hcrc = crc32 (0, (unsigned char *)&header, len);
177 return (hcrc == image_get_hcrc (hdr));
180 int image_check_dcrc (image_header_t *hdr)
182 ulong data = image_get_data (hdr);
183 ulong len = image_get_data_size (hdr);
184 ulong dcrc = crc32_wd (0, (unsigned char *)data, len, CHUNKSZ_CRC32);
186 return (dcrc == image_get_dcrc (hdr));
190 * image_multi_count - get component (sub-image) count
191 * @hdr: pointer to the header of the multi component image
193 * image_multi_count() returns number of components in a multi
196 * Note: no checking of the image type is done, caller must pass
197 * a valid multi component image.
200 * number of components
202 ulong image_multi_count (image_header_t *hdr)
207 /* get start of the image payload, which in case of multi
208 * component images that points to a table of component sizes */
209 size = (uint32_t *)image_get_data (hdr);
211 /* count non empty slots */
212 for (i = 0; size[i]; ++i)
219 * image_multi_getimg - get component data address and size
220 * @hdr: pointer to the header of the multi component image
221 * @idx: index of the requested component
222 * @data: pointer to a ulong variable, will hold component data address
223 * @len: pointer to a ulong variable, will hold component size
225 * image_multi_getimg() returns size and data address for the requested
226 * component in a multi component image.
228 * Note: no checking of the image type is done, caller must pass
229 * a valid multi component image.
232 * data address and size of the component, if idx is valid
233 * 0 in data and len, if idx is out of range
235 void image_multi_getimg (image_header_t *hdr, ulong idx,
236 ulong *data, ulong *len)
240 ulong offset, count, img_data;
242 /* get number of component */
243 count = image_multi_count (hdr);
245 /* get start of the image payload, which in case of multi
246 * component images that points to a table of component sizes */
247 size = (uint32_t *)image_get_data (hdr);
249 /* get address of the proper component data start, which means
250 * skipping sizes table (add 1 for last, null entry) */
251 img_data = image_get_data (hdr) + (count + 1) * sizeof (uint32_t);
254 *len = uimage_to_cpu (size[idx]);
257 /* go over all indices preceding requested component idx */
258 for (i = 0; i < idx; i++) {
259 /* add up i-th component size, rounding up to 4 bytes */
260 offset += (uimage_to_cpu (size[i]) + 3) & ~3 ;
263 /* calculate idx-th component data address */
264 *data = img_data + offset;
271 static void image_print_type (image_header_t *hdr)
273 const char *os, *arch, *type, *comp;
275 os = genimg_get_os_name (image_get_os (hdr));
276 arch = genimg_get_arch_name (image_get_arch (hdr));
277 type = genimg_get_type_name (image_get_type (hdr));
278 comp = genimg_get_comp_name (image_get_comp (hdr));
280 printf ("%s %s %s (%s)\n", arch, os, type, comp);
284 * image_print_contents - prints out the contents of the legacy format image
285 * @hdr: pointer to the legacy format image header
286 * @p: pointer to prefix string
288 * image_print_contents() formats a multi line legacy image contents description.
289 * The routine prints out all header fields followed by the size/offset data
290 * for MULTI/SCRIPT images.
293 * no returned results
295 void image_print_contents (image_header_t *hdr)
305 printf ("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name (hdr));
306 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
307 printf ("%sCreated: ", p);
308 genimg_print_time ((time_t)image_get_time (hdr));
310 printf ("%sImage Type: ", p);
311 image_print_type (hdr);
312 printf ("%sData Size: ", p);
313 genimg_print_size (image_get_data_size (hdr));
314 printf ("%sLoad Address: %08x\n", p, image_get_load (hdr));
315 printf ("%sEntry Point: %08x\n", p, image_get_ep (hdr));
317 if (image_check_type (hdr, IH_TYPE_MULTI) ||
318 image_check_type (hdr, IH_TYPE_SCRIPT)) {
321 ulong count = image_multi_count (hdr);
323 printf ("%sContents:\n", p);
324 for (i = 0; i < count; i++) {
325 image_multi_getimg (hdr, i, &data, &len);
327 printf ("%s Image %d: ", p, i);
328 genimg_print_size (len);
330 if (image_check_type (hdr, IH_TYPE_SCRIPT) && i > 0) {
332 * the user may need to know offsets
333 * if planning to do something with
336 printf ("%s Offset = 0x%08lx\n", p, data);
345 * image_get_ramdisk - get and verify ramdisk image
346 * @rd_addr: ramdisk image start address
347 * @arch: expected ramdisk architecture
348 * @verify: checksum verification flag
350 * image_get_ramdisk() returns a pointer to the verified ramdisk image
351 * header. Routine receives image start address and expected architecture
352 * flag. Verification done covers data and header integrity and os/type/arch
355 * If dataflash support is enabled routine checks for dataflash addresses
356 * and handles required dataflash reads.
359 * pointer to a ramdisk image header, if image was found and valid
360 * otherwise, return NULL
362 static image_header_t* image_get_ramdisk (ulong rd_addr, uint8_t arch,
365 image_header_t *rd_hdr = (image_header_t *)rd_addr;
367 if (!image_check_magic (rd_hdr)) {
368 puts ("Bad Magic Number\n");
369 show_boot_progress (-10);
373 if (!image_check_hcrc (rd_hdr)) {
374 puts ("Bad Header Checksum\n");
375 show_boot_progress (-11);
379 show_boot_progress (10);
380 image_print_contents (rd_hdr);
383 puts(" Verifying Checksum ... ");
384 if (!image_check_dcrc (rd_hdr)) {
385 puts ("Bad Data CRC\n");
386 show_boot_progress (-12);
392 show_boot_progress (11);
394 if (!image_check_os (rd_hdr, IH_OS_LINUX) ||
395 !image_check_arch (rd_hdr, arch) ||
396 !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) {
397 printf ("No Linux %s Ramdisk Image\n",
398 genimg_get_arch_name(arch));
399 show_boot_progress (-13);
405 #endif /* !USE_HOSTCC */
407 /*****************************************************************************/
408 /* Shared dual-format routines */
409 /*****************************************************************************/
411 int getenv_yesno (char *var)
413 char *s = getenv (var);
414 return (s && (*s == 'n')) ? 0 : 1;
417 ulong getenv_bootm_low(void)
419 char *s = getenv ("bootm_low");
421 ulong tmp = simple_strtoul (s, NULL, 16);
425 #if defined(CFG_SDRAM_BASE)
426 return CFG_SDRAM_BASE;
427 #elif defined(CONFIG_ARM)
428 return gd->bd->bi_dram[0].start;
434 phys_size_t getenv_bootm_size(void)
436 char *s = getenv ("bootm_size");
439 #ifdef CFG_64BIT_STRTOUL
440 tmp = (phys_size_t)simple_strtoull (s, NULL, 16);
442 tmp = (phys_size_t)simple_strtoul (s, NULL, 16);
447 #if defined(CONFIG_ARM)
448 return gd->bd->bi_dram[0].size;
450 return gd->bd->bi_memsize;
454 void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
456 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
458 size_t tail = (len > chunksz) ? chunksz : len;
460 memmove (to, from, tail);
465 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
466 memmove (to, from, len);
467 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
469 #endif /* !USE_HOSTCC */
471 static void genimg_print_size (uint32_t size)
474 printf ("%d Bytes = ", size);
475 print_size (size, "\n");
477 printf ("%d Bytes = %.2f kB = %.2f MB\n",
478 size, (double)size / 1.024e3,
479 (double)size / 1.048576e6);
483 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
484 static void genimg_print_time (time_t timestamp)
489 to_tm (timestamp, &tm);
490 printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
491 tm.tm_year, tm.tm_mon, tm.tm_mday,
492 tm.tm_hour, tm.tm_min, tm.tm_sec);
494 printf ("%s", ctime(×tamp));
497 #endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */
500 * get_table_entry_name - translate entry id to long name
501 * @table: pointer to a translation table for entries of a specific type
502 * @msg: message to be returned when translation fails
503 * @id: entry id to be translated
505 * get_table_entry_name() will go over translation table trying to find
506 * entry that matches given id. If matching entry is found, its long
507 * name is returned to the caller.
510 * long entry name if translation succeeds
513 static char *get_table_entry_name (table_entry_t *table, char *msg, int id)
515 for (; table->id >= 0; ++table) {
517 return (table->lname);
522 const char *genimg_get_os_name (uint8_t os)
524 return (get_table_entry_name (uimage_os, "Unknown OS", os));
527 const char *genimg_get_arch_name (uint8_t arch)
529 return (get_table_entry_name (uimage_arch, "Unknown Architecture", arch));
532 const char *genimg_get_type_name (uint8_t type)
534 return (get_table_entry_name (uimage_type, "Unknown Image", type));
537 const char *genimg_get_comp_name (uint8_t comp)
539 return (get_table_entry_name (uimage_comp, "Unknown Compression", comp));
543 * get_table_entry_id - translate short entry name to id
544 * @table: pointer to a translation table for entries of a specific type
545 * @table_name: to be used in case of error
546 * @name: entry short name to be translated
548 * get_table_entry_id() will go over translation table trying to find
549 * entry that matches given short name. If matching entry is found,
550 * its id returned to the caller.
553 * entry id if translation succeeds
556 static int get_table_entry_id (table_entry_t *table,
557 const char *table_name, const char *name)
563 for (t = table; t->id >= 0; ++t) {
564 if (t->sname && strcasecmp(t->sname, name) == 0)
568 fprintf (stderr, "\nInvalid %s Type - valid names are", table_name);
569 for (t = table; t->id >= 0; ++t) {
570 if (t->sname == NULL)
572 fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname);
575 fprintf (stderr, "\n");
577 for (t = table; t->id >= 0; ++t) {
578 if (t->sname && strcmp(t->sname, name) == 0)
581 debug ("Invalid %s Type: %s\n", table_name, name);
582 #endif /* USE_HOSTCC */
586 int genimg_get_os_id (const char *name)
588 return (get_table_entry_id (uimage_os, "OS", name));
591 int genimg_get_arch_id (const char *name)
593 return (get_table_entry_id (uimage_arch, "CPU", name));
596 int genimg_get_type_id (const char *name)
598 return (get_table_entry_id (uimage_type, "Image", name));
601 int genimg_get_comp_id (const char *name)
603 return (get_table_entry_id (uimage_comp, "Compression", name));
608 * genimg_get_format - get image format type
609 * @img_addr: image start address
611 * genimg_get_format() checks whether provided address points to a valid
612 * legacy or FIT image.
614 * New uImage format and FDT blob are based on a libfdt. FDT blob
615 * may be passed directly or embedded in a FIT image. In both situations
616 * genimg_get_format() must be able to dectect libfdt header.
619 * image format type or IMAGE_FORMAT_INVALID if no image is present
621 int genimg_get_format (void *img_addr)
623 ulong format = IMAGE_FORMAT_INVALID;
625 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
629 hdr = (image_header_t *)img_addr;
630 if (image_check_magic(hdr))
631 format = IMAGE_FORMAT_LEGACY;
632 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
634 fit_hdr = (char *)img_addr;
635 if (fdt_check_header (fit_hdr) == 0)
636 format = IMAGE_FORMAT_FIT;
644 * genimg_get_image - get image from special storage (if necessary)
645 * @img_addr: image start address
647 * genimg_get_image() checks if provided image start adddress is located
648 * in a dataflash storage. If so, image is moved to a system RAM memory.
651 * image start address after possible relocation from special storage
653 ulong genimg_get_image (ulong img_addr)
655 ulong ram_addr = img_addr;
657 #ifdef CONFIG_HAS_DATAFLASH
658 ulong h_size, d_size;
660 if (addr_dataflash (img_addr)){
661 /* ger RAM address */
662 ram_addr = CFG_LOAD_ADDR;
664 /* get header size */
665 h_size = image_get_header_size ();
666 #if defined(CONFIG_FIT)
667 if (sizeof(struct fdt_header) > h_size)
668 h_size = sizeof(struct fdt_header);
672 debug (" Reading image header from dataflash address "
673 "%08lx to RAM address %08lx\n", img_addr, ram_addr);
675 read_dataflash (img_addr, h_size, (char *)ram_addr);
678 switch (genimg_get_format ((void *)ram_addr)) {
679 case IMAGE_FORMAT_LEGACY:
680 d_size = image_get_data_size ((image_header_t *)ram_addr);
681 debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n",
684 #if defined(CONFIG_FIT)
685 case IMAGE_FORMAT_FIT:
686 d_size = fit_get_size ((const void *)ram_addr) - h_size;
687 debug (" FIT/FDT format image found at 0x%08lx, size 0x%08lx\n",
692 printf (" No valid image found at 0x%08lx\n", img_addr);
696 /* read in image data */
697 debug (" Reading image remaining data from dataflash address "
698 "%08lx to RAM address %08lx\n", img_addr + h_size,
701 read_dataflash (img_addr + h_size, d_size,
702 (char *)(ram_addr + h_size));
705 #endif /* CONFIG_HAS_DATAFLASH */
711 * fit_has_config - check if there is a valid FIT configuration
712 * @images: pointer to the bootm command headers structure
714 * fit_has_config() checks if there is a FIT configuration in use
715 * (if FTI support is present).
718 * 0, no FIT support or no configuration found
719 * 1, configuration found
721 int genimg_has_config (bootm_headers_t *images)
723 #if defined(CONFIG_FIT)
724 if (images->fit_uname_cfg)
731 * boot_get_ramdisk - main ramdisk handling routine
732 * @argc: command argument count
733 * @argv: command argument list
734 * @images: pointer to the bootm images structure
735 * @arch: expected ramdisk architecture
736 * @rd_start: pointer to a ulong variable, will hold ramdisk start address
737 * @rd_end: pointer to a ulong variable, will hold ramdisk end
739 * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
740 * Curently supported are the following ramdisk sources:
741 * - multicomponent kernel/ramdisk image,
742 * - commandline provided address of decicated ramdisk image.
745 * 0, if ramdisk image was found and valid, or skiped
746 * rd_start and rd_end are set to ramdisk start/end addresses if
747 * ramdisk image is found and valid
749 * 1, if ramdisk image is found but corrupted, or invalid
750 * rd_start and rd_end are set to 0 if no ramdisk exists
752 int boot_get_ramdisk (int argc, char *argv[], bootm_headers_t *images,
753 uint8_t arch, ulong *rd_start, ulong *rd_end)
755 ulong rd_addr, rd_load;
756 ulong rd_data, rd_len;
757 image_header_t *rd_hdr;
758 #if defined(CONFIG_FIT)
760 const char *fit_uname_config = NULL;
761 const char *fit_uname_ramdisk = NULL;
773 * Look for a '-' which indicates to ignore the
776 if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) {
777 debug ("## Skipping init Ramdisk\n");
778 rd_len = rd_data = 0;
779 } else if (argc >= 3 || genimg_has_config (images)) {
780 #if defined(CONFIG_FIT)
783 * If the init ramdisk comes from the FIT image and
784 * the FIT image address is omitted in the command
785 * line argument, try to use os FIT image address or
786 * default load address.
788 if (images->fit_uname_os)
789 default_addr = (ulong)images->fit_hdr_os;
791 default_addr = load_addr;
793 if (fit_parse_conf (argv[2], default_addr,
794 &rd_addr, &fit_uname_config)) {
795 debug ("* ramdisk: config '%s' from image at 0x%08lx\n",
796 fit_uname_config, rd_addr);
797 } else if (fit_parse_subimage (argv[2], default_addr,
798 &rd_addr, &fit_uname_ramdisk)) {
799 debug ("* ramdisk: subimage '%s' from image at 0x%08lx\n",
800 fit_uname_ramdisk, rd_addr);
804 rd_addr = simple_strtoul(argv[2], NULL, 16);
805 debug ("* ramdisk: cmdline image address = 0x%08lx\n",
808 #if defined(CONFIG_FIT)
810 /* use FIT configuration provided in first bootm
813 rd_addr = (ulong)images->fit_hdr_os;
814 fit_uname_config = images->fit_uname_cfg;
815 debug ("* ramdisk: using config '%s' from image at 0x%08lx\n",
816 fit_uname_config, rd_addr);
819 * Check whether configuration has ramdisk defined,
820 * if not, don't try to use it, quit silently.
822 fit_hdr = (void *)rd_addr;
823 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
824 if (cfg_noffset < 0) {
825 debug ("* ramdisk: no such config\n");
829 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
830 if (rd_noffset < 0) {
831 debug ("* ramdisk: no ramdisk in config\n");
837 /* copy from dataflash if needed */
838 rd_addr = genimg_get_image (rd_addr);
841 * Check if there is an initrd image at the
842 * address provided in the second bootm argument
843 * check image type, for FIT images get FIT node.
845 switch (genimg_get_format ((void *)rd_addr)) {
846 case IMAGE_FORMAT_LEGACY:
847 printf ("## Loading init Ramdisk from Legacy "
848 "Image at %08lx ...\n", rd_addr);
850 show_boot_progress (9);
851 rd_hdr = image_get_ramdisk (rd_addr, arch,
857 rd_data = image_get_data (rd_hdr);
858 rd_len = image_get_data_size (rd_hdr);
859 rd_load = image_get_load (rd_hdr);
861 #if defined(CONFIG_FIT)
862 case IMAGE_FORMAT_FIT:
863 fit_hdr = (void *)rd_addr;
864 printf ("## Loading init Ramdisk from FIT "
865 "Image at %08lx ...\n", rd_addr);
867 show_boot_progress (120);
868 if (!fit_check_format (fit_hdr)) {
869 puts ("Bad FIT ramdisk image format!\n");
870 show_boot_progress (-120);
873 show_boot_progress (121);
875 if (!fit_uname_ramdisk) {
877 * no ramdisk image node unit name, try to get config
878 * node first. If config unit node name is NULL
879 * fit_conf_get_node() will try to find default config node
881 show_boot_progress (122);
882 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
883 if (cfg_noffset < 0) {
884 puts ("Could not find configuration node\n");
885 show_boot_progress (-122);
888 fit_uname_config = fdt_get_name (fit_hdr, cfg_noffset, NULL);
889 printf (" Using '%s' configuration\n", fit_uname_config);
891 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
892 fit_uname_ramdisk = fit_get_name (fit_hdr, rd_noffset, NULL);
894 /* get ramdisk component image node offset */
895 show_boot_progress (123);
896 rd_noffset = fit_image_get_node (fit_hdr, fit_uname_ramdisk);
898 if (rd_noffset < 0) {
899 puts ("Could not find subimage node\n");
900 show_boot_progress (-124);
904 printf (" Trying '%s' ramdisk subimage\n", fit_uname_ramdisk);
906 show_boot_progress (125);
907 if (!fit_check_ramdisk (fit_hdr, rd_noffset, arch, images->verify))
910 /* get ramdisk image data address and length */
911 if (fit_image_get_data (fit_hdr, rd_noffset, &data, &size)) {
912 puts ("Could not find ramdisk subimage data!\n");
913 show_boot_progress (-127);
916 show_boot_progress (128);
918 rd_data = (ulong)data;
921 if (fit_image_get_load (fit_hdr, rd_noffset, &rd_load)) {
922 puts ("Can't get ramdisk subimage load address!\n");
923 show_boot_progress (-129);
926 show_boot_progress (129);
928 images->fit_hdr_rd = fit_hdr;
929 images->fit_uname_rd = fit_uname_ramdisk;
930 images->fit_noffset_rd = rd_noffset;
934 puts ("Wrong Ramdisk Image Format\n");
935 rd_data = rd_len = rd_load = 0;
939 #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO)
941 * We need to copy the ramdisk to SRAM to let Linux boot
944 memmove ((void *)rd_load, (uchar *)rd_data, rd_len);
947 #endif /* CONFIG_B2 || CONFIG_EVB4510 || CONFIG_ARMADILLO */
949 } else if (images->legacy_hdr_valid &&
950 image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
952 * Now check if we have a legacy mult-component image,
953 * get second entry data start address and len.
955 show_boot_progress (13);
956 printf ("## Loading init Ramdisk from multi component "
957 "Legacy Image at %08lx ...\n",
958 (ulong)images->legacy_hdr_os);
960 image_multi_getimg (images->legacy_hdr_os, 1, &rd_data, &rd_len);
965 show_boot_progress (14);
966 rd_len = rd_data = 0;
970 debug ("## No init Ramdisk\n");
973 *rd_end = rd_data + rd_len;
975 debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
981 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
983 * boot_ramdisk_high - relocate init ramdisk
984 * @lmb: pointer to lmb handle, will be used for memory mgmt
985 * @rd_data: ramdisk data start address
986 * @rd_len: ramdisk data length
987 * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
988 * start address (after possible relocation)
989 * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
990 * end address (after possible relocation)
992 * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
993 * variable and if requested ramdisk data is moved to a specified location.
995 * Initrd_start and initrd_end are set to final (after relocation) ramdisk
996 * start/end addresses if ramdisk image start and len were provided,
997 * otherwise set initrd_start and initrd_end set to zeros.
1003 int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
1004 ulong *initrd_start, ulong *initrd_end)
1008 int initrd_copy_to_ram = 1;
1010 if ((s = getenv ("initrd_high")) != NULL) {
1011 /* a value of "no" or a similar string will act like 0,
1012 * turning the "load high" feature off. This is intentional.
1014 initrd_high = simple_strtoul (s, NULL, 16);
1015 if (initrd_high == ~0)
1016 initrd_copy_to_ram = 0;
1018 /* not set, no restrictions to load high */
1023 #ifdef CONFIG_LOGBUFFER
1024 /* Prevent initrd from overwriting logbuffer */
1025 lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
1028 debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
1029 initrd_high, initrd_copy_to_ram);
1032 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
1033 debug (" in-place initrd\n");
1034 *initrd_start = rd_data;
1035 *initrd_end = rd_data + rd_len;
1036 lmb_reserve(lmb, rd_data, rd_len);
1039 *initrd_start = (ulong)lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
1041 *initrd_start = (ulong)lmb_alloc (lmb, rd_len, 0x1000);
1043 if (*initrd_start == 0) {
1044 puts ("ramdisk - allocation error\n");
1047 show_boot_progress (12);
1049 *initrd_end = *initrd_start + rd_len;
1050 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
1051 *initrd_start, *initrd_end);
1053 memmove_wd ((void *)*initrd_start,
1054 (void *)rd_data, rd_len, CHUNKSZ);
1062 debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
1063 *initrd_start, *initrd_end);
1071 #ifdef CONFIG_OF_LIBFDT
1072 static void fdt_error (const char *msg)
1076 puts (" - must RESET the board to recover.\n");
1079 static image_header_t *image_get_fdt (ulong fdt_addr)
1081 image_header_t *fdt_hdr = (image_header_t *)fdt_addr;
1083 image_print_contents (fdt_hdr);
1085 puts (" Verifying Checksum ... ");
1086 if (!image_check_hcrc (fdt_hdr)) {
1087 fdt_error ("fdt header checksum invalid");
1091 if (!image_check_dcrc (fdt_hdr)) {
1092 fdt_error ("fdt checksum invalid");
1097 if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) {
1098 fdt_error ("uImage is not a fdt");
1101 if (image_get_comp (fdt_hdr) != IH_COMP_NONE) {
1102 fdt_error ("uImage is compressed");
1105 if (fdt_check_header ((char *)image_get_data (fdt_hdr)) != 0) {
1106 fdt_error ("uImage data is not a fdt");
1113 * fit_check_fdt - verify FIT format FDT subimage
1114 * @fit_hdr: pointer to the FIT header
1115 * fdt_noffset: FDT subimage node offset within FIT image
1116 * @verify: data CRC verification flag
1118 * fit_check_fdt() verifies integrity of the FDT subimage and from
1119 * specified FIT image.
1125 #if defined(CONFIG_FIT)
1126 static int fit_check_fdt (const void *fit, int fdt_noffset, int verify)
1128 fit_image_print (fit, fdt_noffset, " ");
1131 puts (" Verifying Hash Integrity ... ");
1132 if (!fit_image_check_hashes (fit, fdt_noffset)) {
1133 fdt_error ("Bad Data Hash");
1139 if (!fit_image_check_type (fit, fdt_noffset, IH_TYPE_FLATDT)) {
1140 fdt_error ("Not a FDT image");
1144 if (!fit_image_check_comp (fit, fdt_noffset, IH_COMP_NONE)) {
1145 fdt_error ("FDT image is compressed");
1151 #endif /* CONFIG_FIT */
1154 #define CFG_FDT_PAD 0x3000
1158 * boot_relocate_fdt - relocate flat device tree
1159 * @lmb: pointer to lmb handle, will be used for memory mgmt
1160 * @bootmap_base: base address of the bootmap region
1161 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1162 * @of_size: pointer to a ulong variable, will hold fdt length
1164 * boot_relocate_fdt() determines if the of_flat_tree address is within
1165 * the bootmap and if not relocates it into that region
1167 * of_flat_tree and of_size are set to final (after relocation) values
1173 int boot_relocate_fdt (struct lmb *lmb, ulong bootmap_base,
1174 char **of_flat_tree, ulong *of_size)
1176 char *fdt_blob = *of_flat_tree;
1184 if (fdt_check_header (fdt_blob) != 0) {
1185 fdt_error ("image is not a fdt");
1189 #ifndef CFG_NO_FLASH
1190 /* move the blob if it is in flash (set relocate) */
1191 if (addr2info ((ulong)fdt_blob) != NULL)
1196 * The blob needs to be inside the boot mapping.
1198 if (fdt_blob < (char *)bootmap_base)
1201 if ((fdt_blob + *of_size + CFG_FDT_PAD) >=
1202 ((char *)CFG_BOOTMAPSZ + bootmap_base))
1205 /* move flattend device tree if needed */
1210 /* position on a 4K boundary before the alloc_current */
1211 /* Pad the FDT by a specified amount */
1212 of_len = *of_size + CFG_FDT_PAD;
1213 of_start = (unsigned long)lmb_alloc_base(lmb, of_len, 0x1000,
1214 (CFG_BOOTMAPSZ + bootmap_base));
1216 if (of_start == 0) {
1217 puts("device tree - allocation error\n");
1221 debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
1222 (ulong)fdt_blob, (ulong)fdt_blob + *of_size - 1,
1225 printf (" Loading Device Tree to %08lx, end %08lx ... ",
1226 of_start, of_start + of_len - 1);
1228 err = fdt_open_into (fdt_blob, (void *)of_start, of_len);
1230 fdt_error ("fdt move failed");
1235 *of_flat_tree = (char *)of_start;
1238 *of_flat_tree = fdt_blob;
1239 of_len = (CFG_BOOTMAPSZ + bootmap_base) - (ulong)fdt_blob;
1240 lmb_reserve(lmb, (ulong)fdt_blob, of_len);
1241 fdt_set_totalsize(*of_flat_tree, of_len);
1246 set_working_fdt_addr(*of_flat_tree);
1254 * boot_get_fdt - main fdt handling routine
1255 * @argc: command argument count
1256 * @argv: command argument list
1257 * @images: pointer to the bootm images structure
1258 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1259 * @of_size: pointer to a ulong variable, will hold fdt length
1261 * boot_get_fdt() is responsible for finding a valid flat device tree image.
1262 * Curently supported are the following ramdisk sources:
1263 * - multicomponent kernel/ramdisk image,
1264 * - commandline provided address of decicated ramdisk image.
1267 * 0, if fdt image was found and valid, or skipped
1268 * of_flat_tree and of_size are set to fdt start address and length if
1269 * fdt image is found and valid
1271 * 1, if fdt image is found but corrupted
1272 * of_flat_tree and of_size are set to 0 if no fdt exists
1274 int boot_get_fdt (int flag, int argc, char *argv[], bootm_headers_t *images,
1275 char **of_flat_tree, ulong *of_size)
1278 image_header_t *fdt_hdr;
1279 char *fdt_blob = NULL;
1280 ulong image_start, image_end;
1281 ulong load_start, load_end;
1282 #if defined(CONFIG_FIT)
1284 const char *fit_uname_config = NULL;
1285 const char *fit_uname_fdt = NULL;
1293 *of_flat_tree = NULL;
1296 if (argc > 3 || genimg_has_config (images)) {
1297 #if defined(CONFIG_FIT)
1300 * If the FDT blob comes from the FIT image and the
1301 * FIT image address is omitted in the command line
1302 * argument, try to use ramdisk or os FIT image
1303 * address or default load address.
1305 if (images->fit_uname_rd)
1306 default_addr = (ulong)images->fit_hdr_rd;
1307 else if (images->fit_uname_os)
1308 default_addr = (ulong)images->fit_hdr_os;
1310 default_addr = load_addr;
1312 if (fit_parse_conf (argv[3], default_addr,
1313 &fdt_addr, &fit_uname_config)) {
1314 debug ("* fdt: config '%s' from image at 0x%08lx\n",
1315 fit_uname_config, fdt_addr);
1316 } else if (fit_parse_subimage (argv[3], default_addr,
1317 &fdt_addr, &fit_uname_fdt)) {
1318 debug ("* fdt: subimage '%s' from image at 0x%08lx\n",
1319 fit_uname_fdt, fdt_addr);
1323 fdt_addr = simple_strtoul(argv[3], NULL, 16);
1324 debug ("* fdt: cmdline image address = 0x%08lx\n",
1327 #if defined(CONFIG_FIT)
1329 /* use FIT configuration provided in first bootm
1332 fdt_addr = (ulong)images->fit_hdr_os;
1333 fit_uname_config = images->fit_uname_cfg;
1334 debug ("* fdt: using config '%s' from image at 0x%08lx\n",
1335 fit_uname_config, fdt_addr);
1338 * Check whether configuration has FDT blob defined,
1339 * if not quit silently.
1341 fit_hdr = (void *)fdt_addr;
1342 cfg_noffset = fit_conf_get_node (fit_hdr,
1344 if (cfg_noffset < 0) {
1345 debug ("* fdt: no such config\n");
1349 fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
1351 if (fdt_noffset < 0) {
1352 debug ("* fdt: no fdt in config\n");
1358 debug ("## Checking for 'FDT'/'FDT Image' at %08lx\n",
1361 /* copy from dataflash if needed */
1362 fdt_addr = genimg_get_image (fdt_addr);
1365 * Check if there is an FDT image at the
1366 * address provided in the second bootm argument
1367 * check image type, for FIT images get a FIT node.
1369 switch (genimg_get_format ((void *)fdt_addr)) {
1370 case IMAGE_FORMAT_LEGACY:
1371 /* verify fdt_addr points to a valid image header */
1372 printf ("## Flattened Device Tree from Legacy Image at %08lx\n",
1374 fdt_hdr = image_get_fdt (fdt_addr);
1379 * move image data to the load address,
1380 * make sure we don't overwrite initial image
1382 image_start = (ulong)fdt_hdr;
1383 image_end = image_get_image_end (fdt_hdr);
1385 load_start = image_get_load (fdt_hdr);
1386 load_end = load_start + image_get_data_size (fdt_hdr);
1388 if ((load_start < image_end) && (load_end > image_start)) {
1389 fdt_error ("fdt overwritten");
1393 debug (" Loading FDT from 0x%08lx to 0x%08lx\n",
1394 image_get_data (fdt_hdr), load_start);
1396 memmove ((void *)load_start,
1397 (void *)image_get_data (fdt_hdr),
1398 image_get_data_size (fdt_hdr));
1400 fdt_blob = (char *)load_start;
1402 case IMAGE_FORMAT_FIT:
1404 * This case will catch both: new uImage format
1405 * (libfdt based) and raw FDT blob (also libfdt
1408 #if defined(CONFIG_FIT)
1409 /* check FDT blob vs FIT blob */
1410 if (fit_check_format ((const void *)fdt_addr)) {
1414 fit_hdr = (void *)fdt_addr;
1415 printf ("## Flattened Device Tree from FIT Image at %08lx\n",
1418 if (!fit_uname_fdt) {
1420 * no FDT blob image node unit name,
1421 * try to get config node first. If
1422 * config unit node name is NULL
1423 * fit_conf_get_node() will try to
1424 * find default config node
1426 cfg_noffset = fit_conf_get_node (fit_hdr,
1429 if (cfg_noffset < 0) {
1430 fdt_error ("Could not find configuration node\n");
1434 fit_uname_config = fdt_get_name (fit_hdr,
1436 printf (" Using '%s' configuration\n",
1439 fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
1441 fit_uname_fdt = fit_get_name (fit_hdr,
1444 /* get FDT component image node offset */
1445 fdt_noffset = fit_image_get_node (fit_hdr,
1448 if (fdt_noffset < 0) {
1449 fdt_error ("Could not find subimage node\n");
1453 printf (" Trying '%s' FDT blob subimage\n",
1456 if (!fit_check_fdt (fit_hdr, fdt_noffset,
1460 /* get ramdisk image data address and length */
1461 if (fit_image_get_data (fit_hdr, fdt_noffset,
1463 fdt_error ("Could not find FDT subimage data");
1467 /* verift that image data is a proper FDT blob */
1468 if (fdt_check_header ((char *)data) != 0) {
1469 fdt_error ("Subimage data is not a FTD");
1474 * move image data to the load address,
1475 * make sure we don't overwrite initial image
1477 image_start = (ulong)fit_hdr;
1478 image_end = fit_get_end (fit_hdr);
1480 if (fit_image_get_load (fit_hdr, fdt_noffset,
1481 &load_start) == 0) {
1482 load_end = load_start + size;
1484 if ((load_start < image_end) &&
1485 (load_end > image_start)) {
1486 fdt_error ("FDT overwritten");
1490 printf (" Loading FDT from 0x%08lx to 0x%08lx\n",
1491 (ulong)data, load_start);
1493 memmove ((void *)load_start,
1494 (void *)data, size);
1496 fdt_blob = (char *)load_start;
1498 fdt_blob = (char *)data;
1501 images->fit_hdr_fdt = fit_hdr;
1502 images->fit_uname_fdt = fit_uname_fdt;
1503 images->fit_noffset_fdt = fdt_noffset;
1511 fdt_blob = (char *)fdt_addr;
1512 debug ("* fdt: raw FDT blob\n");
1513 printf ("## Flattened Device Tree blob at %08lx\n", (long)fdt_blob);
1517 puts ("ERROR: Did not find a cmdline Flattened Device Tree\n");
1521 printf (" Booting using the fdt blob at 0x%x\n", (int)fdt_blob);
1523 } else if (images->legacy_hdr_valid &&
1524 image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1526 ulong fdt_data, fdt_len;
1529 * Now check if we have a legacy multi-component image,
1530 * get second entry data start address and len.
1532 printf ("## Flattened Device Tree from multi "
1533 "component Image at %08lX\n",
1534 (ulong)images->legacy_hdr_os);
1536 image_multi_getimg (images->legacy_hdr_os, 2, &fdt_data, &fdt_len);
1539 fdt_blob = (char *)fdt_data;
1540 printf (" Booting using the fdt at 0x%x\n", (int)fdt_blob);
1542 if (fdt_check_header (fdt_blob) != 0) {
1543 fdt_error ("image is not a fdt");
1547 if (be32_to_cpu (fdt_totalsize (fdt_blob)) != fdt_len) {
1548 fdt_error ("fdt size != image size");
1552 debug ("## No Flattened Device Tree\n");
1556 debug ("## No Flattened Device Tree\n");
1560 *of_flat_tree = fdt_blob;
1561 *of_size = be32_to_cpu (fdt_totalsize (fdt_blob));
1562 debug (" of_flat_tree at 0x%08lx size 0x%08lx\n",
1563 *of_flat_tree, *of_size);
1572 #endif /* CONFIG_OF_LIBFDT */
1575 * boot_get_cmdline - allocate and initialize kernel cmdline
1576 * @lmb: pointer to lmb handle, will be used for memory mgmt
1577 * @cmd_start: pointer to a ulong variable, will hold cmdline start
1578 * @cmd_end: pointer to a ulong variable, will hold cmdline end
1579 * @bootmap_base: ulong variable, holds offset in physical memory to
1582 * boot_get_cmdline() allocates space for kernel command line below
1583 * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt
1584 * variable is present its contents is copied to allocated kernel
1591 int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end,
1597 cmdline = (char *)(ulong)lmb_alloc_base(lmb, CFG_BARGSIZE, 0xf,
1598 CFG_BOOTMAPSZ + bootmap_base);
1600 if (cmdline == NULL)
1603 if ((s = getenv("bootargs")) == NULL)
1608 *cmd_start = (ulong) & cmdline[0];
1609 *cmd_end = *cmd_start + strlen(cmdline);
1611 debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
1617 * boot_get_kbd - allocate and initialize kernel copy of board info
1618 * @lmb: pointer to lmb handle, will be used for memory mgmt
1619 * @kbd: double pointer to board info data
1620 * @bootmap_base: ulong variable, holds offset in physical memory to
1623 * boot_get_kbd() allocates space for kernel copy of board info data below
1624 * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with
1625 * the current u-boot board info data.
1631 int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base)
1633 *kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
1634 CFG_BOOTMAPSZ + bootmap_base);
1640 debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
1642 #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
1643 do_bdinfo(NULL, 0, 0, NULL);
1648 #endif /* CONFIG_PPC || CONFIG_M68K */
1649 #endif /* !USE_HOSTCC */
1651 #if defined(CONFIG_FIT)
1652 /*****************************************************************************/
1653 /* New uImage format routines */
1654 /*****************************************************************************/
1656 static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr,
1657 ulong *addr, const char **name)
1664 sep = strchr (spec, sepc);
1667 *addr = simple_strtoul (spec, NULL, 16);
1677 * fit_parse_conf - parse FIT configuration spec
1678 * @spec: input string, containing configuration spec
1679 * @add_curr: current image address (to be used as a possible default)
1680 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1682 * @conf_name double pointer to a char, will hold pointer to a configuration
1685 * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
1686 * where <addr> is a FIT image address that contains configuration
1687 * with a <conf> unit name.
1689 * Address part is optional, and if omitted default add_curr will
1693 * 1 if spec is a valid configuration string,
1694 * addr and conf_name are set accordingly
1697 inline int fit_parse_conf (const char *spec, ulong addr_curr,
1698 ulong *addr, const char **conf_name)
1700 return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
1704 * fit_parse_subimage - parse FIT subimage spec
1705 * @spec: input string, containing subimage spec
1706 * @add_curr: current image address (to be used as a possible default)
1707 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1709 * @image_name: double pointer to a char, will hold pointer to a subimage name
1711 * fit_parse_subimage() expects subimage spec in the for of
1712 * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
1713 * subimage with a <subimg> unit name.
1715 * Address part is optional, and if omitted default add_curr will
1719 * 1 if spec is a valid subimage string,
1720 * addr and image_name are set accordingly
1723 inline int fit_parse_subimage (const char *spec, ulong addr_curr,
1724 ulong *addr, const char **image_name)
1726 return fit_parse_spec (spec, ':', addr_curr, addr, image_name);
1728 #endif /* !USE_HOSTCC */
1730 static void fit_get_debug (const void *fit, int noffset,
1731 char *prop_name, int err)
1733 debug ("Can't get '%s' property from FIT 0x%08lx, "
1734 "node: offset %d, name %s (%s)\n",
1735 prop_name, (ulong)fit, noffset,
1736 fit_get_name (fit, noffset, NULL),
1737 fdt_strerror (err));
1741 * fit_print_contents - prints out the contents of the FIT format image
1742 * @fit: pointer to the FIT format image header
1743 * @p: pointer to prefix string
1745 * fit_print_contents() formats a multi line FIT image contents description.
1746 * The routine prints out FIT image properties (root node level) follwed by
1747 * the details of each component image.
1750 * no returned results
1752 void fit_print_contents (const void *fit)
1763 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1773 /* Root node properties */
1774 ret = fit_get_desc (fit, 0, &desc);
1775 printf ("%sFIT description: ", p);
1777 printf ("unavailable\n");
1779 printf ("%s\n", desc);
1781 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1782 ret = fit_get_timestamp (fit, 0, ×tamp);
1783 printf ("%sCreated: ", p);
1785 printf ("unavailable\n");
1787 genimg_print_time (timestamp);
1790 /* Find images parent node offset */
1791 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
1792 if (images_noffset < 0) {
1793 printf ("Can't find images parent node '%s' (%s)\n",
1794 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
1798 /* Process its subnodes, print out component images details */
1799 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
1800 (noffset >= 0) && (ndepth > 0);
1801 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1804 * Direct child node of the images parent node,
1805 * i.e. component image node.
1807 printf ("%s Image %u (%s)\n", p, count++,
1808 fit_get_name(fit, noffset, NULL));
1810 fit_image_print (fit, noffset, p);
1814 /* Find configurations parent node offset */
1815 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
1816 if (confs_noffset < 0) {
1817 debug ("Can't get configurations parent node '%s' (%s)\n",
1818 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
1822 /* get default configuration unit name from default property */
1823 uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL);
1825 printf ("%s Default Configuration: '%s'\n", p, uname);
1827 /* Process its subnodes, print out configurations details */
1828 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth);
1829 (noffset >= 0) && (ndepth > 0);
1830 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1833 * Direct child node of the configurations parent node,
1834 * i.e. configuration node.
1836 printf ("%s Configuration %u (%s)\n", p, count++,
1837 fit_get_name(fit, noffset, NULL));
1839 fit_conf_print (fit, noffset, p);
1845 * fit_image_print - prints out the FIT component image details
1846 * @fit: pointer to the FIT format image header
1847 * @image_noffset: offset of the component image node
1848 * @p: pointer to prefix string
1850 * fit_image_print() lists all mandatory properies for the processed component
1851 * image. If present, hash nodes are printed out as well.
1854 * no returned results
1856 void fit_image_print (const void *fit, int image_noffset, const char *p)
1859 uint8_t type, arch, os, comp;
1867 /* Mandatory properties */
1868 ret = fit_get_desc (fit, image_noffset, &desc);
1869 printf ("%s Description: ", p);
1871 printf ("unavailable\n");
1873 printf ("%s\n", desc);
1875 fit_image_get_type (fit, image_noffset, &type);
1876 printf ("%s Type: %s\n", p, genimg_get_type_name (type));
1878 fit_image_get_comp (fit, image_noffset, &comp);
1879 printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp));
1881 ret = fit_image_get_data (fit, image_noffset, &data, &size);
1884 printf ("%s Data Start: ", p);
1886 printf ("unavailable\n");
1888 printf ("0x%08lx\n", (ulong)data);
1891 printf ("%s Data Size: ", p);
1893 printf ("unavailable\n");
1895 genimg_print_size (size);
1897 /* Remaining, type dependent properties */
1898 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
1899 (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
1900 (type == IH_TYPE_FLATDT)) {
1901 fit_image_get_arch (fit, image_noffset, &arch);
1902 printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch));
1905 if (type == IH_TYPE_KERNEL) {
1906 fit_image_get_os (fit, image_noffset, &os);
1907 printf ("%s OS: %s\n", p, genimg_get_os_name (os));
1910 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
1911 ret = fit_image_get_load (fit, image_noffset, &load);
1912 printf ("%s Load Address: ", p);
1914 printf ("unavailable\n");
1916 printf ("0x%08lx\n", load);
1918 fit_image_get_entry (fit, image_noffset, &entry);
1919 printf ("%s Entry Point: ", p);
1921 printf ("unavailable\n");
1923 printf ("0x%08lx\n", entry);
1926 /* Process all hash subnodes of the component image node */
1927 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
1928 (noffset >= 0) && (ndepth > 0);
1929 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1931 /* Direct child node of the component image node */
1932 fit_image_print_hash (fit, noffset, p);
1938 * fit_image_print_hash - prints out the hash node details
1939 * @fit: pointer to the FIT format image header
1940 * @noffset: offset of the hash node
1941 * @p: pointer to prefix string
1943 * fit_image_print_hash() lists properies for the processed hash node
1946 * no returned results
1948 void fit_image_print_hash (const void *fit, int noffset, const char *p)
1956 * Check subnode name, must be equal to "hash".
1957 * Multiple hash nodes require unique unit node
1958 * names, e.g. hash@1, hash@2, etc.
1960 if (strncmp (fit_get_name(fit, noffset, NULL),
1962 strlen(FIT_HASH_NODENAME)) != 0)
1965 debug ("%s Hash node: '%s'\n", p,
1966 fit_get_name (fit, noffset, NULL));
1968 printf ("%s Hash algo: ", p);
1969 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
1970 printf ("invalid/unsupported\n");
1973 printf ("%s\n", algo);
1975 ret = fit_image_hash_get_value (fit, noffset, &value,
1977 printf ("%s Hash value: ", p);
1979 printf ("unavailable\n");
1981 for (i = 0; i < value_len; i++)
1982 printf ("%02x", value[i]);
1986 debug ("%s Hash len: %d\n", p, value_len);
1990 * fit_get_desc - get node description property
1991 * @fit: pointer to the FIT format image header
1992 * @noffset: node offset
1993 * @desc: double pointer to the char, will hold pointer to the descrption
1995 * fit_get_desc() reads description property from a given node, if
1996 * description is found pointer to it is returened in third call argument.
2002 int fit_get_desc (const void *fit, int noffset, char **desc)
2006 *desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len);
2007 if (*desc == NULL) {
2008 fit_get_debug (fit, noffset, FIT_DESC_PROP, len);
2016 * fit_get_timestamp - get node timestamp property
2017 * @fit: pointer to the FIT format image header
2018 * @noffset: node offset
2019 * @timestamp: pointer to the time_t, will hold read timestamp
2021 * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
2022 * is found and has a correct size its value is retured in third call
2027 * -1, on property read failure
2028 * -2, on wrong timestamp size
2030 int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp)
2035 data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len);
2037 fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len);
2040 if (len != sizeof (uint32_t)) {
2041 debug ("FIT timestamp with incorrect size of (%u)\n", len);
2045 *timestamp = uimage_to_cpu (*((uint32_t *)data));
2050 * fit_image_get_node - get node offset for component image of a given unit name
2051 * @fit: pointer to the FIT format image header
2052 * @image_uname: component image node unit name
2054 * fit_image_get_node() finds a component image (withing the '/images'
2055 * node) of a provided unit name. If image is found its node offset is
2056 * returned to the caller.
2059 * image node offset when found (>=0)
2060 * negative number on failure (FDT_ERR_* code)
2062 int fit_image_get_node (const void *fit, const char *image_uname)
2064 int noffset, images_noffset;
2066 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2067 if (images_noffset < 0) {
2068 debug ("Can't find images parent node '%s' (%s)\n",
2069 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2070 return images_noffset;
2073 noffset = fdt_subnode_offset (fit, images_noffset, image_uname);
2075 debug ("Can't get node offset for image unit name: '%s' (%s)\n",
2076 image_uname, fdt_strerror (noffset));
2083 * fit_image_get_os - get os id for a given component image node
2084 * @fit: pointer to the FIT format image header
2085 * @noffset: component image node offset
2086 * @os: pointer to the uint8_t, will hold os numeric id
2088 * fit_image_get_os() finds os property in a given component image node.
2089 * If the property is found, its (string) value is translated to the numeric
2090 * id which is returned to the caller.
2096 int fit_image_get_os (const void *fit, int noffset, uint8_t *os)
2101 /* Get OS name from property data */
2102 data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len);
2104 fit_get_debug (fit, noffset, FIT_OS_PROP, len);
2109 /* Translate OS name to id */
2110 *os = genimg_get_os_id (data);
2115 * fit_image_get_arch - get arch id for a given component image node
2116 * @fit: pointer to the FIT format image header
2117 * @noffset: component image node offset
2118 * @arch: pointer to the uint8_t, will hold arch numeric id
2120 * fit_image_get_arch() finds arch property in a given component image node.
2121 * If the property is found, its (string) value is translated to the numeric
2122 * id which is returned to the caller.
2128 int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch)
2133 /* Get architecture name from property data */
2134 data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len);
2136 fit_get_debug (fit, noffset, FIT_ARCH_PROP, len);
2141 /* Translate architecture name to id */
2142 *arch = genimg_get_arch_id (data);
2147 * fit_image_get_type - get type id for a given component image node
2148 * @fit: pointer to the FIT format image header
2149 * @noffset: component image node offset
2150 * @type: pointer to the uint8_t, will hold type numeric id
2152 * fit_image_get_type() finds type property in a given component image node.
2153 * If the property is found, its (string) value is translated to the numeric
2154 * id which is returned to the caller.
2160 int fit_image_get_type (const void *fit, int noffset, uint8_t *type)
2165 /* Get image type name from property data */
2166 data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len);
2168 fit_get_debug (fit, noffset, FIT_TYPE_PROP, len);
2173 /* Translate image type name to id */
2174 *type = genimg_get_type_id (data);
2179 * fit_image_get_comp - get comp id for a given component image node
2180 * @fit: pointer to the FIT format image header
2181 * @noffset: component image node offset
2182 * @comp: pointer to the uint8_t, will hold comp numeric id
2184 * fit_image_get_comp() finds comp property in a given component image node.
2185 * If the property is found, its (string) value is translated to the numeric
2186 * id which is returned to the caller.
2192 int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp)
2197 /* Get compression name from property data */
2198 data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len);
2200 fit_get_debug (fit, noffset, FIT_COMP_PROP, len);
2205 /* Translate compression name to id */
2206 *comp = genimg_get_comp_id (data);
2211 * fit_image_get_load - get load address property for a given component image node
2212 * @fit: pointer to the FIT format image header
2213 * @noffset: component image node offset
2214 * @load: pointer to the uint32_t, will hold load address
2216 * fit_image_get_load() finds load address property in a given component image node.
2217 * If the property is found, its value is returned to the caller.
2223 int fit_image_get_load (const void *fit, int noffset, ulong *load)
2226 const uint32_t *data;
2228 data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len);
2230 fit_get_debug (fit, noffset, FIT_LOAD_PROP, len);
2234 *load = uimage_to_cpu (*data);
2239 * fit_image_get_entry - get entry point address property for a given component image node
2240 * @fit: pointer to the FIT format image header
2241 * @noffset: component image node offset
2242 * @entry: pointer to the uint32_t, will hold entry point address
2244 * fit_image_get_entry() finds entry point address property in a given component image node.
2245 * If the property is found, its value is returned to the caller.
2251 int fit_image_get_entry (const void *fit, int noffset, ulong *entry)
2254 const uint32_t *data;
2256 data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len);
2258 fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len);
2262 *entry = uimage_to_cpu (*data);
2267 * fit_image_get_data - get data property and its size for a given component image node
2268 * @fit: pointer to the FIT format image header
2269 * @noffset: component image node offset
2270 * @data: double pointer to void, will hold data property's data address
2271 * @size: pointer to size_t, will hold data property's data size
2273 * fit_image_get_data() finds data property in a given component image node.
2274 * If the property is found its data start address and size are returned to
2281 int fit_image_get_data (const void *fit, int noffset,
2282 const void **data, size_t *size)
2286 *data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len);
2287 if (*data == NULL) {
2288 fit_get_debug (fit, noffset, FIT_DATA_PROP, len);
2298 * fit_image_hash_get_algo - get hash algorithm name
2299 * @fit: pointer to the FIT format image header
2300 * @noffset: hash node offset
2301 * @algo: double pointer to char, will hold pointer to the algorithm name
2303 * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
2304 * If the property is found its data start address is returned to the caller.
2310 int fit_image_hash_get_algo (const void *fit, int noffset, char **algo)
2314 *algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len);
2315 if (*algo == NULL) {
2316 fit_get_debug (fit, noffset, FIT_ALGO_PROP, len);
2324 * fit_image_hash_get_value - get hash value and length
2325 * @fit: pointer to the FIT format image header
2326 * @noffset: hash node offset
2327 * @value: double pointer to uint8_t, will hold address of a hash value data
2328 * @value_len: pointer to an int, will hold hash data length
2330 * fit_image_hash_get_value() finds hash value property in a given hash node.
2331 * If the property is found its data start address and size are returned to
2338 int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value,
2343 *value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len);
2344 if (*value == NULL) {
2345 fit_get_debug (fit, noffset, FIT_VALUE_PROP, len);
2355 * fit_set_timestamp - set node timestamp property
2356 * @fit: pointer to the FIT format image header
2357 * @noffset: node offset
2358 * @timestamp: timestamp value to be set
2360 * fit_set_timestamp() attempts to set timestamp property in the requested
2361 * node and returns operation status to the caller.
2365 * -1, on property read failure
2367 int fit_set_timestamp (void *fit, int noffset, time_t timestamp)
2372 t = cpu_to_uimage (timestamp);
2373 ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t,
2376 printf ("Can't set '%s' property for '%s' node (%s)\n",
2377 FIT_TIMESTAMP_PROP, fit_get_name (fit, noffset, NULL),
2378 fdt_strerror (ret));
2386 * calculate_hash - calculate and return hash for provided input data
2387 * @data: pointer to the input data
2388 * @data_len: data length
2389 * @algo: requested hash algorithm
2390 * @value: pointer to the char, will hold hash value data (caller must
2391 * allocate enough free space)
2392 * value_len: length of the calculated hash
2394 * calculate_hash() computes input data hash according to the requested algorithm.
2395 * Resulting hash value is placed in caller provided 'value' buffer, length
2396 * of the calculated hash is returned via value_len pointer argument.
2400 * -1, when algo is unsupported
2402 static int calculate_hash (const void *data, int data_len, const char *algo,
2403 uint8_t *value, int *value_len)
2405 if (strcmp (algo, "crc32") == 0 ) {
2406 *((uint32_t *)value) = crc32_wd (0, data, data_len,
2408 *((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value));
2410 } else if (strcmp (algo, "sha1") == 0 ) {
2411 sha1_csum_wd ((unsigned char *) data, data_len,
2412 (unsigned char *) value, CHUNKSZ_SHA1);
2414 } else if (strcmp (algo, "md5") == 0 ) {
2415 md5_wd ((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
2418 debug ("Unsupported hash alogrithm\n");
2426 * fit_set_hashes - process FIT component image nodes and calculate hashes
2427 * @fit: pointer to the FIT format image header
2429 * fit_set_hashes() adds hash values for all component images in the FIT blob.
2430 * Hashes are calculated for all component images which have hash subnodes
2431 * with algorithm property set to one of the supported hash algorithms.
2435 * libfdt error code, on failure
2437 int fit_set_hashes (void *fit)
2444 /* Find images parent node offset */
2445 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2446 if (images_noffset < 0) {
2447 printf ("Can't find images parent node '%s' (%s)\n",
2448 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2449 return images_noffset;
2452 /* Process its subnodes, print out component images details */
2453 for (ndepth = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
2454 (noffset >= 0) && (ndepth > 0);
2455 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2458 * Direct child node of the images parent node,
2459 * i.e. component image node.
2461 ret = fit_image_set_hashes (fit, noffset);
2471 * fit_image_set_hashes - calculate/set hashes for given component image node
2472 * @fit: pointer to the FIT format image header
2473 * @image_noffset: requested component image node
2475 * fit_image_set_hashes() adds hash values for an component image node. All
2476 * existing hash subnodes are checked, if algorithm property is set to one of
2477 * the supported hash algorithms, hash value is computed and corresponding
2478 * hash node property is set, for example:
2480 * Input component image node structure:
2482 * o image@1 (at image_noffset)
2483 * | - data = [binary data]
2487 * Output component image node structure:
2489 * o image@1 (at image_noffset)
2490 * | - data = [binary data]
2493 * |- value = sha1(data)
2499 int fit_image_set_hashes (void *fit, int image_noffset)
2504 uint8_t value[FIT_MAX_HASH_LEN];
2509 /* Get image data and data length */
2510 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
2511 printf ("Can't get image data/size\n");
2515 /* Process all hash subnodes of the component image node */
2516 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2517 (noffset >= 0) && (ndepth > 0);
2518 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2520 /* Direct child node of the component image node */
2523 * Check subnode name, must be equal to "hash".
2524 * Multiple hash nodes require unique unit node
2525 * names, e.g. hash@1, hash@2, etc.
2527 if (strncmp (fit_get_name(fit, noffset, NULL),
2529 strlen(FIT_HASH_NODENAME)) != 0) {
2530 /* Not a hash subnode, skip it */
2534 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2535 printf ("Can't get hash algo property for "
2536 "'%s' hash node in '%s' image node\n",
2537 fit_get_name (fit, noffset, NULL),
2538 fit_get_name (fit, image_noffset, NULL));
2542 if (calculate_hash (data, size, algo, value, &value_len)) {
2543 printf ("Unsupported hash algorithm (%s) for "
2544 "'%s' hash node in '%s' image node\n",
2545 algo, fit_get_name (fit, noffset, NULL),
2546 fit_get_name (fit, image_noffset, NULL));
2550 if (fit_image_hash_set_value (fit, noffset, value,
2552 printf ("Can't set hash value for "
2553 "'%s' hash node in '%s' image node\n",
2554 fit_get_name (fit, noffset, NULL),
2555 fit_get_name (fit, image_noffset, NULL));
2565 * fit_image_hash_set_value - set hash value in requested has node
2566 * @fit: pointer to the FIT format image header
2567 * @noffset: hash node offset
2568 * @value: hash value to be set
2569 * @value_len: hash value length
2571 * fit_image_hash_set_value() attempts to set hash value in a node at offset
2572 * given and returns operation status to the caller.
2578 int fit_image_hash_set_value (void *fit, int noffset, uint8_t *value,
2583 ret = fdt_setprop (fit, noffset, FIT_VALUE_PROP, value, value_len);
2585 printf ("Can't set hash '%s' property for '%s' node (%s)\n",
2586 FIT_VALUE_PROP, fit_get_name (fit, noffset, NULL),
2587 fdt_strerror (ret));
2593 #endif /* USE_HOSTCC */
2596 * fit_image_check_hashes - verify data intergity
2597 * @fit: pointer to the FIT format image header
2598 * @image_noffset: component image node offset
2600 * fit_image_check_hashes() goes over component image hash nodes,
2601 * re-calculates each data hash and compares with the value stored in hash
2605 * 1, if all hashes are valid
2606 * 0, otherwise (or on error)
2608 int fit_image_check_hashes (const void *fit, int image_noffset)
2615 uint8_t value[FIT_MAX_HASH_LEN];
2621 /* Get image data and data length */
2622 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
2623 printf ("Can't get image data/size\n");
2627 /* Process all hash subnodes of the component image node */
2628 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2629 (noffset >= 0) && (ndepth > 0);
2630 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2632 /* Direct child node of the component image node */
2635 * Check subnode name, must be equal to "hash".
2636 * Multiple hash nodes require unique unit node
2637 * names, e.g. hash@1, hash@2, etc.
2639 if (strncmp (fit_get_name(fit, noffset, NULL),
2641 strlen(FIT_HASH_NODENAME)) != 0)
2644 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2645 err_msg = "Can't get hash algo property";
2648 printf ("%s", algo);
2650 if (fit_image_hash_get_value (fit, noffset, &fit_value,
2652 err_msg = "Can't get hash value property";
2656 if (calculate_hash (data, size, algo, value, &value_len)) {
2657 err_msg = "Unsupported hash algorithm";
2661 if (value_len != fit_value_len) {
2662 err_msg = "Bad hash value len";
2664 } else if (memcmp (value, fit_value, value_len) != 0) {
2665 err_msg = "Bad hash value";
2675 printf ("%s for '%s' hash node in '%s' image node\n",
2676 err_msg, fit_get_name (fit, noffset, NULL),
2677 fit_get_name (fit, image_noffset, NULL));
2682 * fit_image_check_os - check whether image node is of a given os type
2683 * @fit: pointer to the FIT format image header
2684 * @noffset: component image node offset
2685 * @os: requested image os
2687 * fit_image_check_os() reads image os property and compares its numeric
2688 * id with the requested os. Comparison result is returned to the caller.
2691 * 1 if image is of given os type
2692 * 0 otherwise (or on error)
2694 int fit_image_check_os (const void *fit, int noffset, uint8_t os)
2698 if (fit_image_get_os (fit, noffset, &image_os))
2700 return (os == image_os);
2704 * fit_image_check_arch - check whether image node is of a given arch
2705 * @fit: pointer to the FIT format image header
2706 * @noffset: component image node offset
2707 * @arch: requested imagearch
2709 * fit_image_check_arch() reads image arch property and compares its numeric
2710 * id with the requested arch. Comparison result is returned to the caller.
2713 * 1 if image is of given arch
2714 * 0 otherwise (or on error)
2716 int fit_image_check_arch (const void *fit, int noffset, uint8_t arch)
2720 if (fit_image_get_arch (fit, noffset, &image_arch))
2722 return (arch == image_arch);
2726 * fit_image_check_type - check whether image node is of a given type
2727 * @fit: pointer to the FIT format image header
2728 * @noffset: component image node offset
2729 * @type: requested image type
2731 * fit_image_check_type() reads image type property and compares its numeric
2732 * id with the requested type. Comparison result is returned to the caller.
2735 * 1 if image is of given type
2736 * 0 otherwise (or on error)
2738 int fit_image_check_type (const void *fit, int noffset, uint8_t type)
2742 if (fit_image_get_type (fit, noffset, &image_type))
2744 return (type == image_type);
2748 * fit_image_check_comp - check whether image node uses given compression
2749 * @fit: pointer to the FIT format image header
2750 * @noffset: component image node offset
2751 * @comp: requested image compression type
2753 * fit_image_check_comp() reads image compression property and compares its
2754 * numeric id with the requested compression type. Comparison result is
2755 * returned to the caller.
2758 * 1 if image uses requested compression
2759 * 0 otherwise (or on error)
2761 int fit_image_check_comp (const void *fit, int noffset, uint8_t comp)
2765 if (fit_image_get_comp (fit, noffset, &image_comp))
2767 return (comp == image_comp);
2771 * fit_check_format - sanity check FIT image format
2772 * @fit: pointer to the FIT format image header
2774 * fit_check_format() runs a basic sanity FIT image verification.
2775 * Routine checks for mandatory properties, nodes, etc.
2781 int fit_check_format (const void *fit)
2783 /* mandatory / node 'description' property */
2784 if (fdt_getprop (fit, 0, FIT_DESC_PROP, NULL) == NULL) {
2785 debug ("Wrong FIT format: no description\n");
2789 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
2790 /* mandatory / node 'timestamp' property */
2791 if (fdt_getprop (fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
2792 debug ("Wrong FIT format: no description\n");
2797 /* mandatory subimages parent '/images' node */
2798 if (fdt_path_offset (fit, FIT_IMAGES_PATH) < 0) {
2799 debug ("Wrong FIT format: no images parent node\n");
2807 * fit_conf_get_node - get node offset for configuration of a given unit name
2808 * @fit: pointer to the FIT format image header
2809 * @conf_uname: configuration node unit name
2811 * fit_conf_get_node() finds a configuration (withing the '/configurations'
2812 * parant node) of a provided unit name. If configuration is found its node offset
2813 * is returned to the caller.
2815 * When NULL is provided in second argument fit_conf_get_node() will search
2816 * for a default configuration node instead. Default configuration node unit name
2817 * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
2820 * configuration node offset when found (>=0)
2821 * negative number on failure (FDT_ERR_* code)
2823 int fit_conf_get_node (const void *fit, const char *conf_uname)
2825 int noffset, confs_noffset;
2828 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
2829 if (confs_noffset < 0) {
2830 debug ("Can't find configurations parent node '%s' (%s)\n",
2831 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
2832 return confs_noffset;
2835 if (conf_uname == NULL) {
2836 /* get configuration unit name from the default property */
2837 debug ("No configuration specified, trying default...\n");
2838 conf_uname = (char *)fdt_getprop (fit, confs_noffset, FIT_DEFAULT_PROP, &len);
2839 if (conf_uname == NULL) {
2840 fit_get_debug (fit, confs_noffset, FIT_DEFAULT_PROP, len);
2843 debug ("Found default configuration: '%s'\n", conf_uname);
2846 noffset = fdt_subnode_offset (fit, confs_noffset, conf_uname);
2848 debug ("Can't get node offset for configuration unit name: '%s' (%s)\n",
2849 conf_uname, fdt_strerror (noffset));
2855 static int __fit_conf_get_prop_node (const void *fit, int noffset,
2856 const char *prop_name)
2861 /* get kernel image unit name from configuration kernel property */
2862 uname = (char *)fdt_getprop (fit, noffset, prop_name, &len);
2866 return fit_image_get_node (fit, uname);
2870 * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
2871 * a given configuration
2872 * @fit: pointer to the FIT format image header
2873 * @noffset: configuration node offset
2875 * fit_conf_get_kernel_node() retrives kernel image node unit name from
2876 * configuration FIT_KERNEL_PROP property and translates it to the node
2880 * image node offset when found (>=0)
2881 * negative number on failure (FDT_ERR_* code)
2883 int fit_conf_get_kernel_node (const void *fit, int noffset)
2885 return __fit_conf_get_prop_node (fit, noffset, FIT_KERNEL_PROP);
2889 * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
2890 * a given configuration
2891 * @fit: pointer to the FIT format image header
2892 * @noffset: configuration node offset
2894 * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
2895 * configuration FIT_KERNEL_PROP property and translates it to the node
2899 * image node offset when found (>=0)
2900 * negative number on failure (FDT_ERR_* code)
2902 int fit_conf_get_ramdisk_node (const void *fit, int noffset)
2904 return __fit_conf_get_prop_node (fit, noffset, FIT_RAMDISK_PROP);
2908 * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
2909 * a given configuration
2910 * @fit: pointer to the FIT format image header
2911 * @noffset: configuration node offset
2913 * fit_conf_get_fdt_node() retrives fdt image node unit name from
2914 * configuration FIT_KERNEL_PROP property and translates it to the node
2918 * image node offset when found (>=0)
2919 * negative number on failure (FDT_ERR_* code)
2921 int fit_conf_get_fdt_node (const void *fit, int noffset)
2923 return __fit_conf_get_prop_node (fit, noffset, FIT_FDT_PROP);
2927 * fit_conf_print - prints out the FIT configuration details
2928 * @fit: pointer to the FIT format image header
2929 * @noffset: offset of the configuration node
2930 * @p: pointer to prefix string
2932 * fit_conf_print() lists all mandatory properies for the processed
2933 * configuration node.
2936 * no returned results
2938 void fit_conf_print (const void *fit, int noffset, const char *p)
2944 /* Mandatory properties */
2945 ret = fit_get_desc (fit, noffset, &desc);
2946 printf ("%s Description: ", p);
2948 printf ("unavailable\n");
2950 printf ("%s\n", desc);
2952 uname = (char *)fdt_getprop (fit, noffset, FIT_KERNEL_PROP, NULL);
2953 printf ("%s Kernel: ", p);
2955 printf ("unavailable\n");
2957 printf ("%s\n", uname);
2959 /* Optional properties */
2960 uname = (char *)fdt_getprop (fit, noffset, FIT_RAMDISK_PROP, NULL);
2962 printf ("%s Init Ramdisk: %s\n", p, uname);
2964 uname = (char *)fdt_getprop (fit, noffset, FIT_FDT_PROP, NULL);
2966 printf ("%s FDT: %s\n", p, uname);
2970 * fit_check_ramdisk - verify FIT format ramdisk subimage
2971 * @fit_hdr: pointer to the FIT ramdisk header
2972 * @rd_noffset: ramdisk subimage node offset within FIT image
2973 * @arch: requested ramdisk image architecture type
2974 * @verify: data CRC verification flag
2976 * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
2977 * specified FIT image.
2984 static int fit_check_ramdisk (const void *fit, int rd_noffset, uint8_t arch, int verify)
2986 fit_image_print (fit, rd_noffset, " ");
2989 puts (" Verifying Hash Integrity ... ");
2990 if (!fit_image_check_hashes (fit, rd_noffset)) {
2991 puts ("Bad Data Hash\n");
2992 show_boot_progress (-125);
2998 show_boot_progress (126);
2999 if (!fit_image_check_os (fit, rd_noffset, IH_OS_LINUX) ||
3000 !fit_image_check_arch (fit, rd_noffset, arch) ||
3001 !fit_image_check_type (fit, rd_noffset, IH_TYPE_RAMDISK)) {
3002 printf ("No Linux %s Ramdisk Image\n",
3003 genimg_get_arch_name(arch));
3004 show_boot_progress (-126);
3008 show_boot_progress (127);
3011 #endif /* USE_HOSTCC */
3012 #endif /* CONFIG_FIT */