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 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
44 #if defined(CONFIG_FIT) || defined (CONFIG_OF_LIBFDT)
47 #include <fdt_support.h>
50 #if defined(CONFIG_FIT)
51 #include <u-boot/md5.h>
54 static int fit_check_ramdisk (const void *fit, int os_noffset,
55 uint8_t arch, int verify);
59 extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
62 DECLARE_GLOBAL_DATA_PTR;
64 static image_header_t* image_get_ramdisk (ulong rd_addr, uint8_t arch,
68 #include <u-boot/md5.h>
71 #endif /* !USE_HOSTCC*/
73 typedef struct table_entry {
74 int id; /* as defined in image.h */
75 char *sname; /* short (input) name */
76 char *lname; /* long (output) name */
79 static table_entry_t uimage_arch[] = {
80 { IH_ARCH_INVALID, NULL, "Invalid ARCH", },
81 { IH_ARCH_ALPHA, "alpha", "Alpha", },
82 { IH_ARCH_ARM, "arm", "ARM", },
83 { IH_ARCH_I386, "x86", "Intel x86", },
84 { IH_ARCH_IA64, "ia64", "IA64", },
85 { IH_ARCH_M68K, "m68k", "M68K", },
86 { IH_ARCH_MICROBLAZE, "microblaze", "MicroBlaze", },
87 { IH_ARCH_MIPS, "mips", "MIPS", },
88 { IH_ARCH_MIPS64, "mips64", "MIPS 64 Bit", },
89 { IH_ARCH_NIOS, "nios", "NIOS", },
90 { IH_ARCH_NIOS2, "nios2", "NIOS II", },
91 { IH_ARCH_PPC, "powerpc", "PowerPC", },
92 { IH_ARCH_PPC, "ppc", "PowerPC", },
93 { IH_ARCH_S390, "s390", "IBM S390", },
94 { IH_ARCH_SH, "sh", "SuperH", },
95 { IH_ARCH_SPARC, "sparc", "SPARC", },
96 { IH_ARCH_SPARC64, "sparc64", "SPARC 64 Bit", },
97 { IH_ARCH_BLACKFIN, "blackfin", "Blackfin", },
98 { IH_ARCH_AVR32, "avr32", "AVR32", },
102 static table_entry_t uimage_os[] = {
103 { IH_OS_INVALID, NULL, "Invalid OS", },
104 #if defined(CONFIG_ARTOS) || defined(USE_HOSTCC)
105 { IH_OS_ARTOS, "artos", "ARTOS", },
107 { IH_OS_LINUX, "linux", "Linux", },
108 #if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC)
109 { IH_OS_LYNXOS, "lynxos", "LynxOS", },
111 { IH_OS_NETBSD, "netbsd", "NetBSD", },
112 { IH_OS_RTEMS, "rtems", "RTEMS", },
113 { IH_OS_U_BOOT, "u-boot", "U-Boot", },
114 #if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC)
115 { IH_OS_QNX, "qnx", "QNX", },
116 { IH_OS_VXWORKS, "vxworks", "VxWorks", },
119 { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", },
120 { IH_OS_DELL, "dell", "Dell", },
121 { IH_OS_ESIX, "esix", "Esix", },
122 { IH_OS_FREEBSD, "freebsd", "FreeBSD", },
123 { IH_OS_IRIX, "irix", "Irix", },
124 { IH_OS_NCR, "ncr", "NCR", },
125 { IH_OS_OPENBSD, "openbsd", "OpenBSD", },
126 { IH_OS_PSOS, "psos", "pSOS", },
127 { IH_OS_SCO, "sco", "SCO", },
128 { IH_OS_SOLARIS, "solaris", "Solaris", },
129 { IH_OS_SVR4, "svr4", "SVR4", },
134 static table_entry_t uimage_type[] = {
135 { IH_TYPE_INVALID, NULL, "Invalid Image", },
136 { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", },
137 { IH_TYPE_FIRMWARE, "firmware", "Firmware", },
138 { IH_TYPE_KERNEL, "kernel", "Kernel Image", },
139 { IH_TYPE_MULTI, "multi", "Multi-File Image", },
140 { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", },
141 { IH_TYPE_SCRIPT, "script", "Script", },
142 { IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
143 { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", },
147 static table_entry_t uimage_comp[] = {
148 { IH_COMP_NONE, "none", "uncompressed", },
149 { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", },
150 { IH_COMP_GZIP, "gzip", "gzip compressed", },
154 uint32_t crc32 (uint32_t, const unsigned char *, uint);
155 uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint);
156 static void genimg_print_size (uint32_t size);
157 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
158 static void genimg_print_time (time_t timestamp);
161 /*****************************************************************************/
162 /* Legacy format routines */
163 /*****************************************************************************/
164 int image_check_hcrc (image_header_t *hdr)
167 ulong len = image_get_header_size ();
168 image_header_t header;
170 /* Copy header so we can blank CRC field for re-calculation */
171 memmove (&header, (char *)hdr, image_get_header_size ());
172 image_set_hcrc (&header, 0);
174 hcrc = crc32 (0, (unsigned char *)&header, len);
176 return (hcrc == image_get_hcrc (hdr));
179 int image_check_dcrc (image_header_t *hdr)
181 ulong data = image_get_data (hdr);
182 ulong len = image_get_data_size (hdr);
183 ulong dcrc = crc32_wd (0, (unsigned char *)data, len, CHUNKSZ_CRC32);
185 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 ulong getenv_bootm_size(void)
436 char *s = getenv ("bootm_size");
438 ulong tmp = simple_strtoul (s, NULL, 16);
442 #if defined(CONFIG_ARM)
443 return gd->bd->bi_dram[0].size;
445 return gd->bd->bi_memsize;
449 void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
451 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
453 size_t tail = (len > chunksz) ? chunksz : len;
455 memmove (to, from, tail);
460 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
461 memmove (to, from, len);
462 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
464 #endif /* !USE_HOSTCC */
466 static void genimg_print_size (uint32_t size)
469 printf ("%d Bytes = ", size);
470 print_size (size, "\n");
472 printf ("%d Bytes = %.2f kB = %.2f MB\n",
473 size, (double)size / 1.024e3,
474 (double)size / 1.048576e6);
478 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
479 static void genimg_print_time (time_t timestamp)
484 to_tm (timestamp, &tm);
485 printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
486 tm.tm_year, tm.tm_mon, tm.tm_mday,
487 tm.tm_hour, tm.tm_min, tm.tm_sec);
489 printf ("%s", ctime(×tamp));
492 #endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */
495 * get_table_entry_name - translate entry id to long name
496 * @table: pointer to a translation table for entries of a specific type
497 * @msg: message to be returned when translation fails
498 * @id: entry id to be translated
500 * get_table_entry_name() will go over translation table trying to find
501 * entry that matches given id. If matching entry is found, its long
502 * name is returned to the caller.
505 * long entry name if translation succeeds
508 static char *get_table_entry_name (table_entry_t *table, char *msg, int id)
510 for (; table->id >= 0; ++table) {
512 return (table->lname);
517 const char *genimg_get_os_name (uint8_t os)
519 return (get_table_entry_name (uimage_os, "Unknown OS", os));
522 const char *genimg_get_arch_name (uint8_t arch)
524 return (get_table_entry_name (uimage_arch, "Unknown Architecture", arch));
527 const char *genimg_get_type_name (uint8_t type)
529 return (get_table_entry_name (uimage_type, "Unknown Image", type));
532 const char *genimg_get_comp_name (uint8_t comp)
534 return (get_table_entry_name (uimage_comp, "Unknown Compression", comp));
538 * get_table_entry_id - translate short entry name to id
539 * @table: pointer to a translation table for entries of a specific type
540 * @table_name: to be used in case of error
541 * @name: entry short name to be translated
543 * get_table_entry_id() will go over translation table trying to find
544 * entry that matches given short name. If matching entry is found,
545 * its id returned to the caller.
548 * entry id if translation succeeds
551 static int get_table_entry_id (table_entry_t *table,
552 const char *table_name, const char *name)
558 for (t = table; t->id >= 0; ++t) {
559 if (t->sname && strcasecmp(t->sname, name) == 0)
563 fprintf (stderr, "\nInvalid %s Type - valid names are", table_name);
564 for (t = table; t->id >= 0; ++t) {
565 if (t->sname == NULL)
567 fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname);
570 fprintf (stderr, "\n");
572 for (t = table; t->id >= 0; ++t) {
573 if (t->sname && strcmp(t->sname, name) == 0)
576 debug ("Invalid %s Type: %s\n", table_name, name);
577 #endif /* USE_HOSTCC */
581 int genimg_get_os_id (const char *name)
583 return (get_table_entry_id (uimage_os, "OS", name));
586 int genimg_get_arch_id (const char *name)
588 return (get_table_entry_id (uimage_arch, "CPU", name));
591 int genimg_get_type_id (const char *name)
593 return (get_table_entry_id (uimage_type, "Image", name));
596 int genimg_get_comp_id (const char *name)
598 return (get_table_entry_id (uimage_comp, "Compression", name));
603 * genimg_get_format - get image format type
604 * @img_addr: image start address
606 * genimg_get_format() checks whether provided address points to a valid
607 * legacy or FIT image.
609 * New uImage format and FDT blob are based on a libfdt. FDT blob
610 * may be passed directly or embedded in a FIT image. In both situations
611 * genimg_get_format() must be able to dectect libfdt header.
614 * image format type or IMAGE_FORMAT_INVALID if no image is present
616 int genimg_get_format (void *img_addr)
618 ulong format = IMAGE_FORMAT_INVALID;
620 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
624 hdr = (image_header_t *)img_addr;
625 if (image_check_magic(hdr))
626 format = IMAGE_FORMAT_LEGACY;
627 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
629 fit_hdr = (char *)img_addr;
630 if (fdt_check_header (fit_hdr) == 0)
631 format = IMAGE_FORMAT_FIT;
639 * genimg_get_image - get image from special storage (if necessary)
640 * @img_addr: image start address
642 * genimg_get_image() checks if provided image start adddress is located
643 * in a dataflash storage. If so, image is moved to a system RAM memory.
646 * image start address after possible relocation from special storage
648 ulong genimg_get_image (ulong img_addr)
650 ulong ram_addr = img_addr;
652 #ifdef CONFIG_HAS_DATAFLASH
653 ulong h_size, d_size;
655 if (addr_dataflash (img_addr)){
656 /* ger RAM address */
657 ram_addr = CFG_LOAD_ADDR;
659 /* get header size */
660 h_size = image_get_header_size ();
661 #if defined(CONFIG_FIT)
662 if (sizeof(struct fdt_header) > h_size)
663 h_size = sizeof(struct fdt_header);
667 debug (" Reading image header from dataflash address "
668 "%08lx to RAM address %08lx\n", img_addr, ram_addr);
670 read_dataflash (img_addr, h_size, (char *)ram_addr);
673 switch (genimg_get_format ((void *)ram_addr)) {
674 case IMAGE_FORMAT_LEGACY:
675 d_size = image_get_data_size ((image_header_t *)ram_addr);
676 debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n",
679 #if defined(CONFIG_FIT)
680 case IMAGE_FORMAT_FIT:
681 d_size = fit_get_size ((const void *)ram_addr) - h_size;
682 debug (" FIT/FDT format image found at 0x%08lx, size 0x%08lx\n",
687 printf (" No valid image found at 0x%08lx\n", img_addr);
691 /* read in image data */
692 debug (" Reading image remaining data from dataflash address "
693 "%08lx to RAM address %08lx\n", img_addr + h_size,
696 read_dataflash (img_addr + h_size, d_size,
697 (char *)(ram_addr + h_size));
700 #endif /* CONFIG_HAS_DATAFLASH */
706 * fit_has_config - check if there is a valid FIT configuration
707 * @images: pointer to the bootm command headers structure
709 * fit_has_config() checks if there is a FIT configuration in use
710 * (if FTI support is present).
713 * 0, no FIT support or no configuration found
714 * 1, configuration found
716 int genimg_has_config (bootm_headers_t *images)
718 #if defined(CONFIG_FIT)
719 if (images->fit_uname_cfg)
726 * boot_get_ramdisk - main ramdisk handling routine
727 * @argc: command argument count
728 * @argv: command argument list
729 * @images: pointer to the bootm images structure
730 * @arch: expected ramdisk architecture
731 * @rd_start: pointer to a ulong variable, will hold ramdisk start address
732 * @rd_end: pointer to a ulong variable, will hold ramdisk end
734 * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
735 * Curently supported are the following ramdisk sources:
736 * - multicomponent kernel/ramdisk image,
737 * - commandline provided address of decicated ramdisk image.
740 * 0, if ramdisk image was found and valid, or skiped
741 * rd_start and rd_end are set to ramdisk start/end addresses if
742 * ramdisk image is found and valid
744 * 1, if ramdisk image is found but corrupted
745 * rd_start and rd_end are set to 0 if no ramdisk exists
747 int boot_get_ramdisk (int argc, char *argv[], bootm_headers_t *images,
748 uint8_t arch, ulong *rd_start, ulong *rd_end)
750 ulong rd_addr, rd_load;
751 ulong rd_data, rd_len;
752 image_header_t *rd_hdr;
753 #if defined(CONFIG_FIT)
755 const char *fit_uname_config = NULL;
756 const char *fit_uname_ramdisk = NULL;
768 * Look for a '-' which indicates to ignore the
771 if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) {
772 debug ("## Skipping init Ramdisk\n");
773 rd_len = rd_data = 0;
774 } else if (argc >= 3 || genimg_has_config (images)) {
775 #if defined(CONFIG_FIT)
778 * If the init ramdisk comes from the FIT image and
779 * the FIT image address is omitted in the command
780 * line argument, try to use os FIT image address or
781 * default load address.
783 if (images->fit_uname_os)
784 default_addr = (ulong)images->fit_hdr_os;
786 default_addr = load_addr;
788 if (fit_parse_conf (argv[2], default_addr,
789 &rd_addr, &fit_uname_config)) {
790 debug ("* ramdisk: config '%s' from image at 0x%08lx\n",
791 fit_uname_config, rd_addr);
792 } else if (fit_parse_subimage (argv[2], default_addr,
793 &rd_addr, &fit_uname_ramdisk)) {
794 debug ("* ramdisk: subimage '%s' from image at 0x%08lx\n",
795 fit_uname_ramdisk, rd_addr);
799 rd_addr = simple_strtoul(argv[2], NULL, 16);
800 debug ("* ramdisk: cmdline image address = 0x%08lx\n",
803 #if defined(CONFIG_FIT)
805 /* use FIT configuration provided in first bootm
808 rd_addr = (ulong)images->fit_hdr_os;
809 fit_uname_config = images->fit_uname_cfg;
810 debug ("* ramdisk: using config '%s' from image at 0x%08lx\n",
811 fit_uname_config, rd_addr);
814 * Check whether configuration has ramdisk defined,
815 * if not, don't try to use it, quit silently.
817 fit_hdr = (void *)rd_addr;
818 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
819 if (cfg_noffset < 0) {
820 debug ("* ramdisk: no such config\n");
824 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
825 if (rd_noffset < 0) {
826 debug ("* ramdisk: no ramdisk in config\n");
832 /* copy from dataflash if needed */
833 rd_addr = genimg_get_image (rd_addr);
836 * Check if there is an initrd image at the
837 * address provided in the second bootm argument
838 * check image type, for FIT images get FIT node.
840 switch (genimg_get_format ((void *)rd_addr)) {
841 case IMAGE_FORMAT_LEGACY:
842 printf ("## Loading init Ramdisk from Legacy "
843 "Image at %08lx ...\n", rd_addr);
845 show_boot_progress (9);
846 rd_hdr = image_get_ramdisk (rd_addr, arch,
852 rd_data = image_get_data (rd_hdr);
853 rd_len = image_get_data_size (rd_hdr);
854 rd_load = image_get_load (rd_hdr);
856 #if defined(CONFIG_FIT)
857 case IMAGE_FORMAT_FIT:
858 fit_hdr = (void *)rd_addr;
859 printf ("## Loading init Ramdisk from FIT "
860 "Image at %08lx ...\n", rd_addr);
862 show_boot_progress (120);
863 if (!fit_check_format (fit_hdr)) {
864 puts ("Bad FIT ramdisk image format!\n");
865 show_boot_progress (-120);
868 show_boot_progress (121);
870 if (!fit_uname_ramdisk) {
872 * no ramdisk image node unit name, try to get config
873 * node first. If config unit node name is NULL
874 * fit_conf_get_node() will try to find default config node
876 show_boot_progress (122);
877 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
878 if (cfg_noffset < 0) {
879 puts ("Could not find configuration node\n");
880 show_boot_progress (-122);
883 fit_uname_config = fdt_get_name (fit_hdr, cfg_noffset, NULL);
884 printf (" Using '%s' configuration\n", fit_uname_config);
886 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
887 fit_uname_ramdisk = fit_get_name (fit_hdr, rd_noffset, NULL);
889 /* get ramdisk component image node offset */
890 show_boot_progress (123);
891 rd_noffset = fit_image_get_node (fit_hdr, fit_uname_ramdisk);
893 if (rd_noffset < 0) {
894 puts ("Could not find subimage node\n");
895 show_boot_progress (-124);
899 printf (" Trying '%s' ramdisk subimage\n", fit_uname_ramdisk);
901 show_boot_progress (125);
902 if (!fit_check_ramdisk (fit_hdr, rd_noffset, arch, images->verify))
905 /* get ramdisk image data address and length */
906 if (fit_image_get_data (fit_hdr, rd_noffset, &data, &size)) {
907 puts ("Could not find ramdisk subimage data!\n");
908 show_boot_progress (-127);
911 show_boot_progress (128);
913 rd_data = (ulong)data;
916 if (fit_image_get_load (fit_hdr, rd_noffset, &rd_load)) {
917 puts ("Can't get ramdisk subimage load address!\n");
918 show_boot_progress (-129);
921 show_boot_progress (129);
923 images->fit_hdr_rd = fit_hdr;
924 images->fit_uname_rd = fit_uname_ramdisk;
925 images->fit_noffset_rd = rd_noffset;
929 puts ("Wrong Ramdisk Image Format\n");
930 rd_data = rd_len = rd_load = 0;
933 #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO)
935 * We need to copy the ramdisk to SRAM to let Linux boot
938 memmove ((void *)rd_load, (uchar *)rd_data, rd_len);
941 #endif /* CONFIG_B2 || CONFIG_EVB4510 || CONFIG_ARMADILLO */
943 } else if (images->legacy_hdr_valid &&
944 image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
946 * Now check if we have a legacy mult-component image,
947 * get second entry data start address and len.
949 show_boot_progress (13);
950 printf ("## Loading init Ramdisk from multi component "
951 "Legacy Image at %08lx ...\n",
952 (ulong)images->legacy_hdr_os);
954 image_multi_getimg (images->legacy_hdr_os, 1, &rd_data, &rd_len);
959 show_boot_progress (14);
960 rd_len = rd_data = 0;
964 debug ("## No init Ramdisk\n");
967 *rd_end = rd_data + rd_len;
969 debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
975 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
977 * boot_ramdisk_high - relocate init ramdisk
978 * @lmb: pointer to lmb handle, will be used for memory mgmt
979 * @rd_data: ramdisk data start address
980 * @rd_len: ramdisk data length
981 * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
982 * start address (after possible relocation)
983 * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
984 * end address (after possible relocation)
986 * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
987 * variable and if requested ramdisk data is moved to a specified location.
989 * Initrd_start and initrd_end are set to final (after relocation) ramdisk
990 * start/end addresses if ramdisk image start and len were provided,
991 * otherwise set initrd_start and initrd_end set to zeros.
997 int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
998 ulong *initrd_start, ulong *initrd_end)
1002 int initrd_copy_to_ram = 1;
1004 if ((s = getenv ("initrd_high")) != NULL) {
1005 /* a value of "no" or a similar string will act like 0,
1006 * turning the "load high" feature off. This is intentional.
1008 initrd_high = simple_strtoul (s, NULL, 16);
1009 if (initrd_high == ~0)
1010 initrd_copy_to_ram = 0;
1012 /* not set, no restrictions to load high */
1016 debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
1017 initrd_high, initrd_copy_to_ram);
1020 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
1021 debug (" in-place initrd\n");
1022 *initrd_start = rd_data;
1023 *initrd_end = rd_data + rd_len;
1024 lmb_reserve(lmb, rd_data, rd_len);
1027 *initrd_start = lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
1029 *initrd_start = lmb_alloc (lmb, rd_len, 0x1000);
1031 if (*initrd_start == 0) {
1032 puts ("ramdisk - allocation error\n");
1035 show_boot_progress (12);
1037 *initrd_end = *initrd_start + rd_len;
1038 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
1039 *initrd_start, *initrd_end);
1041 memmove_wd ((void *)*initrd_start,
1042 (void *)rd_data, rd_len, CHUNKSZ);
1050 debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
1051 *initrd_start, *initrd_end);
1060 * boot_get_cmdline - allocate and initialize kernel cmdline
1061 * @lmb: pointer to lmb handle, will be used for memory mgmt
1062 * @cmd_start: pointer to a ulong variable, will hold cmdline start
1063 * @cmd_end: pointer to a ulong variable, will hold cmdline end
1064 * @bootmap_base: ulong variable, holds offset in physical memory to
1067 * boot_get_cmdline() allocates space for kernel command line below
1068 * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt
1069 * variable is present its contents is copied to allocated kernel
1076 int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end,
1082 cmdline = (char *)lmb_alloc_base(lmb, CFG_BARGSIZE, 0xf,
1083 CFG_BOOTMAPSZ + bootmap_base);
1085 if (cmdline == NULL)
1088 if ((s = getenv("bootargs")) == NULL)
1093 *cmd_start = (ulong) & cmdline[0];
1094 *cmd_end = *cmd_start + strlen(cmdline);
1096 debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
1102 * boot_get_kbd - allocate and initialize kernel copy of board info
1103 * @lmb: pointer to lmb handle, will be used for memory mgmt
1104 * @kbd: double pointer to board info data
1105 * @bootmap_base: ulong variable, holds offset in physical memory to
1108 * boot_get_kbd() allocates space for kernel copy of board info data below
1109 * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with
1110 * the current u-boot board info data.
1116 int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base)
1118 *kbd = (bd_t *)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
1119 CFG_BOOTMAPSZ + bootmap_base);
1125 debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
1127 #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
1128 do_bdinfo(NULL, 0, 0, NULL);
1133 #endif /* CONFIG_PPC || CONFIG_M68K */
1134 #endif /* !USE_HOSTCC */
1136 #if defined(CONFIG_FIT)
1137 /*****************************************************************************/
1138 /* New uImage format routines */
1139 /*****************************************************************************/
1141 static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr,
1142 ulong *addr, const char **name)
1149 sep = strchr (spec, sepc);
1152 *addr = simple_strtoul (spec, NULL, 16);
1162 * fit_parse_conf - parse FIT configuration spec
1163 * @spec: input string, containing configuration spec
1164 * @add_curr: current image address (to be used as a possible default)
1165 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1167 * @conf_name double pointer to a char, will hold pointer to a configuration
1170 * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
1171 * where <addr> is a FIT image address that contains configuration
1172 * with a <conf> unit name.
1174 * Address part is optional, and if omitted default add_curr will
1178 * 1 if spec is a valid configuration string,
1179 * addr and conf_name are set accordingly
1182 inline int fit_parse_conf (const char *spec, ulong addr_curr,
1183 ulong *addr, const char **conf_name)
1185 return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
1189 * fit_parse_subimage - parse FIT subimage spec
1190 * @spec: input string, containing subimage spec
1191 * @add_curr: current image address (to be used as a possible default)
1192 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1194 * @image_name: double pointer to a char, will hold pointer to a subimage name
1196 * fit_parse_subimage() expects subimage spec in the for of
1197 * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
1198 * subimage with a <subimg> unit name.
1200 * Address part is optional, and if omitted default add_curr will
1204 * 1 if spec is a valid subimage string,
1205 * addr and image_name are set accordingly
1208 inline int fit_parse_subimage (const char *spec, ulong addr_curr,
1209 ulong *addr, const char **image_name)
1211 return fit_parse_spec (spec, ':', addr_curr, addr, image_name);
1213 #endif /* !USE_HOSTCC */
1215 static void fit_get_debug (const void *fit, int noffset,
1216 char *prop_name, int err)
1218 debug ("Can't get '%s' property from FIT 0x%08lx, "
1219 "node: offset %d, name %s (%s)\n",
1220 prop_name, (ulong)fit, noffset,
1221 fit_get_name (fit, noffset, NULL),
1222 fdt_strerror (err));
1226 * fit_print_contents - prints out the contents of the FIT format image
1227 * @fit: pointer to the FIT format image header
1228 * @p: pointer to prefix string
1230 * fit_print_contents() formats a multi line FIT image contents description.
1231 * The routine prints out FIT image properties (root node level) follwed by
1232 * the details of each component image.
1235 * no returned results
1237 void fit_print_contents (const void *fit)
1248 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1258 /* Root node properties */
1259 ret = fit_get_desc (fit, 0, &desc);
1260 printf ("%sFIT description: ", p);
1262 printf ("unavailable\n");
1264 printf ("%s\n", desc);
1266 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1267 ret = fit_get_timestamp (fit, 0, ×tamp);
1268 printf ("%sCreated: ", p);
1270 printf ("unavailable\n");
1272 genimg_print_time (timestamp);
1275 /* Find images parent node offset */
1276 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
1277 if (images_noffset < 0) {
1278 printf ("Can't find images parent node '%s' (%s)\n",
1279 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
1283 /* Process its subnodes, print out component images details */
1284 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
1285 (noffset >= 0) && (ndepth > 0);
1286 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1289 * Direct child node of the images parent node,
1290 * i.e. component image node.
1292 printf ("%s Image %u (%s)\n", p, count++,
1293 fit_get_name(fit, noffset, NULL));
1295 fit_image_print (fit, noffset, p);
1299 /* Find configurations parent node offset */
1300 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
1301 if (confs_noffset < 0) {
1302 debug ("Can't get configurations parent node '%s' (%s)\n",
1303 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
1307 /* get default configuration unit name from default property */
1308 uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL);
1310 printf ("%s Default Configuration: '%s'\n", p, uname);
1312 /* Process its subnodes, print out configurations details */
1313 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth);
1314 (noffset >= 0) && (ndepth > 0);
1315 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1318 * Direct child node of the configurations parent node,
1319 * i.e. configuration node.
1321 printf ("%s Configuration %u (%s)\n", p, count++,
1322 fit_get_name(fit, noffset, NULL));
1324 fit_conf_print (fit, noffset, p);
1330 * fit_image_print - prints out the FIT component image details
1331 * @fit: pointer to the FIT format image header
1332 * @image_noffset: offset of the component image node
1333 * @p: pointer to prefix string
1335 * fit_image_print() lists all mandatory properies for the processed component
1336 * image. If present, hash nodes are printed out as well.
1339 * no returned results
1341 void fit_image_print (const void *fit, int image_noffset, const char *p)
1344 uint8_t type, arch, os, comp;
1352 /* Mandatory properties */
1353 ret = fit_get_desc (fit, image_noffset, &desc);
1354 printf ("%s Description: ", p);
1356 printf ("unavailable\n");
1358 printf ("%s\n", desc);
1360 fit_image_get_type (fit, image_noffset, &type);
1361 printf ("%s Type: %s\n", p, genimg_get_type_name (type));
1363 fit_image_get_comp (fit, image_noffset, &comp);
1364 printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp));
1366 ret = fit_image_get_data (fit, image_noffset, &data, &size);
1369 printf ("%s Data Start: ", p);
1371 printf ("unavailable\n");
1373 printf ("0x%08lx\n", (ulong)data);
1376 printf ("%s Data Size: ", p);
1378 printf ("unavailable\n");
1380 genimg_print_size (size);
1382 /* Remaining, type dependent properties */
1383 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
1384 (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
1385 (type == IH_TYPE_FLATDT)) {
1386 fit_image_get_arch (fit, image_noffset, &arch);
1387 printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch));
1390 if (type == IH_TYPE_KERNEL) {
1391 fit_image_get_os (fit, image_noffset, &os);
1392 printf ("%s OS: %s\n", p, genimg_get_os_name (os));
1395 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
1396 ret = fit_image_get_load (fit, image_noffset, &load);
1397 printf ("%s Load Address: ", p);
1399 printf ("unavailable\n");
1401 printf ("0x%08lx\n", load);
1403 fit_image_get_entry (fit, image_noffset, &entry);
1404 printf ("%s Entry Point: ", p);
1406 printf ("unavailable\n");
1408 printf ("0x%08lx\n", entry);
1411 /* Process all hash subnodes of the component image node */
1412 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
1413 (noffset >= 0) && (ndepth > 0);
1414 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1416 /* Direct child node of the component image node */
1417 fit_image_print_hash (fit, noffset, p);
1423 * fit_image_print_hash - prints out the hash node details
1424 * @fit: pointer to the FIT format image header
1425 * @noffset: offset of the hash node
1426 * @p: pointer to prefix string
1428 * fit_image_print_hash() lists properies for the processed hash node
1431 * no returned results
1433 void fit_image_print_hash (const void *fit, int noffset, const char *p)
1441 * Check subnode name, must be equal to "hash".
1442 * Multiple hash nodes require unique unit node
1443 * names, e.g. hash@1, hash@2, etc.
1445 if (strncmp (fit_get_name(fit, noffset, NULL),
1447 strlen(FIT_HASH_NODENAME)) != 0)
1450 debug ("%s Hash node: '%s'\n", p,
1451 fit_get_name (fit, noffset, NULL));
1453 printf ("%s Hash algo: ", p);
1454 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
1455 printf ("invalid/unsupported\n");
1458 printf ("%s\n", algo);
1460 ret = fit_image_hash_get_value (fit, noffset, &value,
1462 printf ("%s Hash value: ", p);
1464 printf ("unavailable\n");
1466 for (i = 0; i < value_len; i++)
1467 printf ("%02x", value[i]);
1471 debug ("%s Hash len: %d\n", p, value_len);
1475 * fit_get_desc - get node description property
1476 * @fit: pointer to the FIT format image header
1477 * @noffset: node offset
1478 * @desc: double pointer to the char, will hold pointer to the descrption
1480 * fit_get_desc() reads description property from a given node, if
1481 * description is found pointer to it is returened in third call argument.
1487 int fit_get_desc (const void *fit, int noffset, char **desc)
1491 *desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len);
1492 if (*desc == NULL) {
1493 fit_get_debug (fit, noffset, FIT_DESC_PROP, len);
1501 * fit_get_timestamp - get node timestamp property
1502 * @fit: pointer to the FIT format image header
1503 * @noffset: node offset
1504 * @timestamp: pointer to the time_t, will hold read timestamp
1506 * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
1507 * is found and has a correct size its value is retured in third call
1512 * -1, on property read failure
1513 * -2, on wrong timestamp size
1515 int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp)
1520 data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len);
1522 fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len);
1525 if (len != sizeof (uint32_t)) {
1526 debug ("FIT timestamp with incorrect size of (%u)\n", len);
1530 *timestamp = uimage_to_cpu (*((uint32_t *)data));
1535 * fit_image_get_node - get node offset for component image of a given unit name
1536 * @fit: pointer to the FIT format image header
1537 * @image_uname: component image node unit name
1539 * fit_image_get_node() finds a component image (withing the '/images'
1540 * node) of a provided unit name. If image is found its node offset is
1541 * returned to the caller.
1544 * image node offset when found (>=0)
1545 * negative number on failure (FDT_ERR_* code)
1547 int fit_image_get_node (const void *fit, const char *image_uname)
1549 int noffset, images_noffset;
1551 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
1552 if (images_noffset < 0) {
1553 debug ("Can't find images parent node '%s' (%s)\n",
1554 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
1555 return images_noffset;
1558 noffset = fdt_subnode_offset (fit, images_noffset, image_uname);
1560 debug ("Can't get node offset for image unit name: '%s' (%s)\n",
1561 image_uname, fdt_strerror (noffset));
1568 * fit_image_get_os - get os id for a given component image node
1569 * @fit: pointer to the FIT format image header
1570 * @noffset: component image node offset
1571 * @os: pointer to the uint8_t, will hold os numeric id
1573 * fit_image_get_os() finds os property in a given component image node.
1574 * If the property is found, its (string) value is translated to the numeric
1575 * id which is returned to the caller.
1581 int fit_image_get_os (const void *fit, int noffset, uint8_t *os)
1586 /* Get OS name from property data */
1587 data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len);
1589 fit_get_debug (fit, noffset, FIT_OS_PROP, len);
1594 /* Translate OS name to id */
1595 *os = genimg_get_os_id (data);
1600 * fit_image_get_arch - get arch id for a given component image node
1601 * @fit: pointer to the FIT format image header
1602 * @noffset: component image node offset
1603 * @arch: pointer to the uint8_t, will hold arch numeric id
1605 * fit_image_get_arch() finds arch property in a given component image node.
1606 * If the property is found, its (string) value is translated to the numeric
1607 * id which is returned to the caller.
1613 int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch)
1618 /* Get architecture name from property data */
1619 data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len);
1621 fit_get_debug (fit, noffset, FIT_ARCH_PROP, len);
1626 /* Translate architecture name to id */
1627 *arch = genimg_get_arch_id (data);
1632 * fit_image_get_type - get type id for a given component image node
1633 * @fit: pointer to the FIT format image header
1634 * @noffset: component image node offset
1635 * @type: pointer to the uint8_t, will hold type numeric id
1637 * fit_image_get_type() finds type property in a given component image node.
1638 * If the property is found, its (string) value is translated to the numeric
1639 * id which is returned to the caller.
1645 int fit_image_get_type (const void *fit, int noffset, uint8_t *type)
1650 /* Get image type name from property data */
1651 data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len);
1653 fit_get_debug (fit, noffset, FIT_TYPE_PROP, len);
1658 /* Translate image type name to id */
1659 *type = genimg_get_type_id (data);
1664 * fit_image_get_comp - get comp id for a given component image node
1665 * @fit: pointer to the FIT format image header
1666 * @noffset: component image node offset
1667 * @comp: pointer to the uint8_t, will hold comp numeric id
1669 * fit_image_get_comp() finds comp property in a given component image node.
1670 * If the property is found, its (string) value is translated to the numeric
1671 * id which is returned to the caller.
1677 int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp)
1682 /* Get compression name from property data */
1683 data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len);
1685 fit_get_debug (fit, noffset, FIT_COMP_PROP, len);
1690 /* Translate compression name to id */
1691 *comp = genimg_get_comp_id (data);
1696 * fit_image_get_load - get load address property for a given component image node
1697 * @fit: pointer to the FIT format image header
1698 * @noffset: component image node offset
1699 * @load: pointer to the uint32_t, will hold load address
1701 * fit_image_get_load() finds load address property in a given component image node.
1702 * If the property is found, its value is returned to the caller.
1708 int fit_image_get_load (const void *fit, int noffset, ulong *load)
1711 const uint32_t *data;
1713 data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len);
1715 fit_get_debug (fit, noffset, FIT_LOAD_PROP, len);
1719 *load = uimage_to_cpu (*data);
1724 * fit_image_get_entry - get entry point address property for a given component image node
1725 * @fit: pointer to the FIT format image header
1726 * @noffset: component image node offset
1727 * @entry: pointer to the uint32_t, will hold entry point address
1729 * fit_image_get_entry() finds entry point address property in a given component image node.
1730 * If the property is found, its value is returned to the caller.
1736 int fit_image_get_entry (const void *fit, int noffset, ulong *entry)
1739 const uint32_t *data;
1741 data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len);
1743 fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len);
1747 *entry = uimage_to_cpu (*data);
1752 * fit_image_get_data - get data property and its size for a given component image node
1753 * @fit: pointer to the FIT format image header
1754 * @noffset: component image node offset
1755 * @data: double pointer to void, will hold data property's data address
1756 * @size: pointer to size_t, will hold data property's data size
1758 * fit_image_get_data() finds data property in a given component image node.
1759 * If the property is found its data start address and size are returned to
1766 int fit_image_get_data (const void *fit, int noffset,
1767 const void **data, size_t *size)
1771 *data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len);
1772 if (*data == NULL) {
1773 fit_get_debug (fit, noffset, FIT_DATA_PROP, len);
1783 * fit_image_hash_get_algo - get hash algorithm name
1784 * @fit: pointer to the FIT format image header
1785 * @noffset: hash node offset
1786 * @algo: double pointer to char, will hold pointer to the algorithm name
1788 * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
1789 * If the property is found its data start address is returned to the caller.
1795 int fit_image_hash_get_algo (const void *fit, int noffset, char **algo)
1799 *algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len);
1800 if (*algo == NULL) {
1801 fit_get_debug (fit, noffset, FIT_ALGO_PROP, len);
1809 * fit_image_hash_get_value - get hash value and length
1810 * @fit: pointer to the FIT format image header
1811 * @noffset: hash node offset
1812 * @value: double pointer to uint8_t, will hold address of a hash value data
1813 * @value_len: pointer to an int, will hold hash data length
1815 * fit_image_hash_get_value() finds hash value property in a given hash node.
1816 * If the property is found its data start address and size are returned to
1823 int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value,
1828 *value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len);
1829 if (*value == NULL) {
1830 fit_get_debug (fit, noffset, FIT_VALUE_PROP, len);
1840 * fit_set_timestamp - set node timestamp property
1841 * @fit: pointer to the FIT format image header
1842 * @noffset: node offset
1843 * @timestamp: timestamp value to be set
1845 * fit_set_timestamp() attempts to set timestamp property in the requested
1846 * node and returns operation status to the caller.
1850 * -1, on property read failure
1852 int fit_set_timestamp (void *fit, int noffset, time_t timestamp)
1857 t = cpu_to_uimage (timestamp);
1858 ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t,
1861 printf ("Can't set '%s' property for '%s' node (%s)\n",
1862 FIT_TIMESTAMP_PROP, fit_get_name (fit, noffset, NULL),
1863 fdt_strerror (ret));
1871 * calculate_hash - calculate and return hash for provided input data
1872 * @data: pointer to the input data
1873 * @data_len: data length
1874 * @algo: requested hash algorithm
1875 * @value: pointer to the char, will hold hash value data (caller must
1876 * allocate enough free space)
1877 * value_len: length of the calculated hash
1879 * calculate_hash() computes input data hash according to the requested algorithm.
1880 * Resulting hash value is placed in caller provided 'value' buffer, length
1881 * of the calculated hash is returned via value_len pointer argument.
1885 * -1, when algo is unsupported
1887 static int calculate_hash (const void *data, int data_len, const char *algo,
1888 uint8_t *value, int *value_len)
1890 if (strcmp (algo, "crc32") == 0 ) {
1891 *((uint32_t *)value) = crc32_wd (0, data, data_len,
1893 *((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value));
1895 } else if (strcmp (algo, "sha1") == 0 ) {
1896 sha1_csum_wd ((unsigned char *) data, data_len,
1897 (unsigned char *) value, CHUNKSZ_SHA1);
1899 } else if (strcmp (algo, "md5") == 0 ) {
1900 md5_wd ((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
1903 debug ("Unsupported hash alogrithm\n");
1911 * fit_set_hashes - process FIT component image nodes and calculate hashes
1912 * @fit: pointer to the FIT format image header
1914 * fit_set_hashes() adds hash values for all component images in the FIT blob.
1915 * Hashes are calculated for all component images which have hash subnodes
1916 * with algorithm property set to one of the supported hash algorithms.
1920 * libfdt error code, on failure
1922 int fit_set_hashes (void *fit)
1929 /* Find images parent node offset */
1930 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
1931 if (images_noffset < 0) {
1932 printf ("Can't find images parent node '%s' (%s)\n",
1933 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
1934 return images_noffset;
1937 /* Process its subnodes, print out component images details */
1938 for (ndepth = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
1939 (noffset >= 0) && (ndepth > 0);
1940 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1943 * Direct child node of the images parent node,
1944 * i.e. component image node.
1946 ret = fit_image_set_hashes (fit, noffset);
1956 * fit_image_set_hashes - calculate/set hashes for given component image node
1957 * @fit: pointer to the FIT format image header
1958 * @image_noffset: requested component image node
1960 * fit_image_set_hashes() adds hash values for an component image node. All
1961 * existing hash subnodes are checked, if algorithm property is set to one of
1962 * the supported hash algorithms, hash value is computed and corresponding
1963 * hash node property is set, for example:
1965 * Input component image node structure:
1967 * o image@1 (at image_noffset)
1968 * | - data = [binary data]
1972 * Output component image node structure:
1974 * o image@1 (at image_noffset)
1975 * | - data = [binary data]
1978 * |- value = sha1(data)
1984 int fit_image_set_hashes (void *fit, int image_noffset)
1989 uint8_t value[FIT_MAX_HASH_LEN];
1994 /* Get image data and data length */
1995 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
1996 printf ("Can't get image data/size\n");
2000 /* Process all hash subnodes of the component image node */
2001 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2002 (noffset >= 0) && (ndepth > 0);
2003 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2005 /* Direct child node of the component image node */
2008 * Check subnode name, must be equal to "hash".
2009 * Multiple hash nodes require unique unit node
2010 * names, e.g. hash@1, hash@2, etc.
2012 if (strncmp (fit_get_name(fit, noffset, NULL),
2014 strlen(FIT_HASH_NODENAME)) != 0) {
2015 /* Not a hash subnode, skip it */
2019 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2020 printf ("Can't get hash algo property for "
2021 "'%s' hash node in '%s' image node\n",
2022 fit_get_name (fit, noffset, NULL),
2023 fit_get_name (fit, image_noffset, NULL));
2027 if (calculate_hash (data, size, algo, value, &value_len)) {
2028 printf ("Unsupported hash algorithm (%s) for "
2029 "'%s' hash node in '%s' image node\n",
2030 algo, fit_get_name (fit, noffset, NULL),
2031 fit_get_name (fit, image_noffset, NULL));
2035 if (fit_image_hash_set_value (fit, noffset, value,
2037 printf ("Can't set hash value for "
2038 "'%s' hash node in '%s' image node\n",
2039 fit_get_name (fit, noffset, NULL),
2040 fit_get_name (fit, image_noffset, NULL));
2050 * fit_image_hash_set_value - set hash value in requested has node
2051 * @fit: pointer to the FIT format image header
2052 * @noffset: hash node offset
2053 * @value: hash value to be set
2054 * @value_len: hash value length
2056 * fit_image_hash_set_value() attempts to set hash value in a node at offset
2057 * given and returns operation status to the caller.
2063 int fit_image_hash_set_value (void *fit, int noffset, uint8_t *value,
2068 ret = fdt_setprop (fit, noffset, FIT_VALUE_PROP, value, value_len);
2070 printf ("Can't set hash '%s' property for '%s' node (%s)\n",
2071 FIT_VALUE_PROP, fit_get_name (fit, noffset, NULL),
2072 fdt_strerror (ret));
2078 #endif /* USE_HOSTCC */
2081 * fit_image_check_hashes - verify data intergity
2082 * @fit: pointer to the FIT format image header
2083 * @image_noffset: component image node offset
2085 * fit_image_check_hashes() goes over component image hash nodes,
2086 * re-calculates each data hash and compares with the value stored in hash
2090 * 1, if all hashes are valid
2091 * 0, otherwise (or on error)
2093 int fit_image_check_hashes (const void *fit, int image_noffset)
2100 uint8_t value[FIT_MAX_HASH_LEN];
2106 /* Get image data and data length */
2107 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
2108 printf ("Can't get image data/size\n");
2112 /* Process all hash subnodes of the component image node */
2113 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2114 (noffset >= 0) && (ndepth > 0);
2115 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2117 /* Direct child node of the component image node */
2120 * Check subnode name, must be equal to "hash".
2121 * Multiple hash nodes require unique unit node
2122 * names, e.g. hash@1, hash@2, etc.
2124 if (strncmp (fit_get_name(fit, noffset, NULL),
2126 strlen(FIT_HASH_NODENAME)) != 0)
2129 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2130 err_msg = "Can't get hash algo property";
2133 printf ("%s", algo);
2135 if (fit_image_hash_get_value (fit, noffset, &fit_value,
2137 err_msg = "Can't get hash value property";
2141 if (calculate_hash (data, size, algo, value, &value_len)) {
2142 err_msg = "Unsupported hash algorithm";
2146 if (value_len != fit_value_len) {
2147 err_msg = "Bad hash value len";
2149 } else if (memcmp (value, fit_value, value_len) != 0) {
2150 err_msg = "Bad hash value";
2160 printf ("%s for '%s' hash node in '%s' image node\n",
2161 err_msg, fit_get_name (fit, noffset, NULL),
2162 fit_get_name (fit, image_noffset, NULL));
2167 * fit_image_check_os - check whether image node is of a given os type
2168 * @fit: pointer to the FIT format image header
2169 * @noffset: component image node offset
2170 * @os: requested image os
2172 * fit_image_check_os() reads image os property and compares its numeric
2173 * id with the requested os. Comparison result is returned to the caller.
2176 * 1 if image is of given os type
2177 * 0 otherwise (or on error)
2179 int fit_image_check_os (const void *fit, int noffset, uint8_t os)
2183 if (fit_image_get_os (fit, noffset, &image_os))
2185 return (os == image_os);
2189 * fit_image_check_arch - check whether image node is of a given arch
2190 * @fit: pointer to the FIT format image header
2191 * @noffset: component image node offset
2192 * @arch: requested imagearch
2194 * fit_image_check_arch() reads image arch property and compares its numeric
2195 * id with the requested arch. Comparison result is returned to the caller.
2198 * 1 if image is of given arch
2199 * 0 otherwise (or on error)
2201 int fit_image_check_arch (const void *fit, int noffset, uint8_t arch)
2205 if (fit_image_get_arch (fit, noffset, &image_arch))
2207 return (arch == image_arch);
2211 * fit_image_check_type - check whether image node is of a given type
2212 * @fit: pointer to the FIT format image header
2213 * @noffset: component image node offset
2214 * @type: requested image type
2216 * fit_image_check_type() reads image type property and compares its numeric
2217 * id with the requested type. Comparison result is returned to the caller.
2220 * 1 if image is of given type
2221 * 0 otherwise (or on error)
2223 int fit_image_check_type (const void *fit, int noffset, uint8_t type)
2227 if (fit_image_get_type (fit, noffset, &image_type))
2229 return (type == image_type);
2233 * fit_image_check_comp - check whether image node uses given compression
2234 * @fit: pointer to the FIT format image header
2235 * @noffset: component image node offset
2236 * @comp: requested image compression type
2238 * fit_image_check_comp() reads image compression property and compares its
2239 * numeric id with the requested compression type. Comparison result is
2240 * returned to the caller.
2243 * 1 if image uses requested compression
2244 * 0 otherwise (or on error)
2246 int fit_image_check_comp (const void *fit, int noffset, uint8_t comp)
2250 if (fit_image_get_comp (fit, noffset, &image_comp))
2252 return (comp == image_comp);
2256 * fit_check_format - sanity check FIT image format
2257 * @fit: pointer to the FIT format image header
2259 * fit_check_format() runs a basic sanity FIT image verification.
2260 * Routine checks for mandatory properties, nodes, etc.
2266 int fit_check_format (const void *fit)
2268 /* mandatory / node 'description' property */
2269 if (fdt_getprop (fit, 0, FIT_DESC_PROP, NULL) == NULL) {
2270 debug ("Wrong FIT format: no description\n");
2274 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
2275 /* mandatory / node 'timestamp' property */
2276 if (fdt_getprop (fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
2277 debug ("Wrong FIT format: no description\n");
2282 /* mandatory subimages parent '/images' node */
2283 if (fdt_path_offset (fit, FIT_IMAGES_PATH) < 0) {
2284 debug ("Wrong FIT format: no images parent node\n");
2292 * fit_conf_get_node - get node offset for configuration of a given unit name
2293 * @fit: pointer to the FIT format image header
2294 * @conf_uname: configuration node unit name
2296 * fit_conf_get_node() finds a configuration (withing the '/configurations'
2297 * parant node) of a provided unit name. If configuration is found its node offset
2298 * is returned to the caller.
2300 * When NULL is provided in second argument fit_conf_get_node() will search
2301 * for a default configuration node instead. Default configuration node unit name
2302 * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
2305 * configuration node offset when found (>=0)
2306 * negative number on failure (FDT_ERR_* code)
2308 int fit_conf_get_node (const void *fit, const char *conf_uname)
2310 int noffset, confs_noffset;
2313 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
2314 if (confs_noffset < 0) {
2315 debug ("Can't find configurations parent node '%s' (%s)\n",
2316 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
2317 return confs_noffset;
2320 if (conf_uname == NULL) {
2321 /* get configuration unit name from the default property */
2322 debug ("No configuration specified, trying default...\n");
2323 conf_uname = (char *)fdt_getprop (fit, confs_noffset, FIT_DEFAULT_PROP, &len);
2324 if (conf_uname == NULL) {
2325 fit_get_debug (fit, confs_noffset, FIT_DEFAULT_PROP, len);
2328 debug ("Found default configuration: '%s'\n", conf_uname);
2331 noffset = fdt_subnode_offset (fit, confs_noffset, conf_uname);
2333 debug ("Can't get node offset for configuration unit name: '%s' (%s)\n",
2334 conf_uname, fdt_strerror (noffset));
2340 static int __fit_conf_get_prop_node (const void *fit, int noffset,
2341 const char *prop_name)
2346 /* get kernel image unit name from configuration kernel property */
2347 uname = (char *)fdt_getprop (fit, noffset, prop_name, &len);
2351 return fit_image_get_node (fit, uname);
2355 * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
2356 * a given configuration
2357 * @fit: pointer to the FIT format image header
2358 * @noffset: configuration node offset
2360 * fit_conf_get_kernel_node() retrives kernel image node unit name from
2361 * configuration FIT_KERNEL_PROP property and translates it to the node
2365 * image node offset when found (>=0)
2366 * negative number on failure (FDT_ERR_* code)
2368 int fit_conf_get_kernel_node (const void *fit, int noffset)
2370 return __fit_conf_get_prop_node (fit, noffset, FIT_KERNEL_PROP);
2374 * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
2375 * a given configuration
2376 * @fit: pointer to the FIT format image header
2377 * @noffset: configuration node offset
2379 * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
2380 * configuration FIT_KERNEL_PROP property and translates it to the node
2384 * image node offset when found (>=0)
2385 * negative number on failure (FDT_ERR_* code)
2387 int fit_conf_get_ramdisk_node (const void *fit, int noffset)
2389 return __fit_conf_get_prop_node (fit, noffset, FIT_RAMDISK_PROP);
2393 * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
2394 * a given configuration
2395 * @fit: pointer to the FIT format image header
2396 * @noffset: configuration node offset
2398 * fit_conf_get_fdt_node() retrives fdt image node unit name from
2399 * configuration FIT_KERNEL_PROP property and translates it to the node
2403 * image node offset when found (>=0)
2404 * negative number on failure (FDT_ERR_* code)
2406 int fit_conf_get_fdt_node (const void *fit, int noffset)
2408 return __fit_conf_get_prop_node (fit, noffset, FIT_FDT_PROP);
2412 * fit_conf_print - prints out the FIT configuration details
2413 * @fit: pointer to the FIT format image header
2414 * @noffset: offset of the configuration node
2415 * @p: pointer to prefix string
2417 * fit_conf_print() lists all mandatory properies for the processed
2418 * configuration node.
2421 * no returned results
2423 void fit_conf_print (const void *fit, int noffset, const char *p)
2429 /* Mandatory properties */
2430 ret = fit_get_desc (fit, noffset, &desc);
2431 printf ("%s Description: ", p);
2433 printf ("unavailable\n");
2435 printf ("%s\n", desc);
2437 uname = (char *)fdt_getprop (fit, noffset, FIT_KERNEL_PROP, NULL);
2438 printf ("%s Kernel: ", p);
2440 printf ("unavailable\n");
2442 printf ("%s\n", uname);
2444 /* Optional properties */
2445 uname = (char *)fdt_getprop (fit, noffset, FIT_RAMDISK_PROP, NULL);
2447 printf ("%s Init Ramdisk: %s\n", p, uname);
2449 uname = (char *)fdt_getprop (fit, noffset, FIT_FDT_PROP, NULL);
2451 printf ("%s FDT: %s\n", p, uname);
2455 * fit_check_ramdisk - verify FIT format ramdisk subimage
2456 * @fit_hdr: pointer to the FIT ramdisk header
2457 * @rd_noffset: ramdisk subimage node offset within FIT image
2458 * @arch: requested ramdisk image architecture type
2459 * @verify: data CRC verification flag
2461 * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
2462 * specified FIT image.
2469 static int fit_check_ramdisk (const void *fit, int rd_noffset, uint8_t arch, int verify)
2471 fit_image_print (fit, rd_noffset, " ");
2474 puts (" Verifying Hash Integrity ... ");
2475 if (!fit_image_check_hashes (fit, rd_noffset)) {
2476 puts ("Bad Data Hash\n");
2477 show_boot_progress (-125);
2483 show_boot_progress (126);
2484 if (!fit_image_check_os (fit, rd_noffset, IH_OS_LINUX) ||
2485 !fit_image_check_arch (fit, rd_noffset, arch) ||
2486 !fit_image_check_type (fit, rd_noffset, IH_TYPE_RAMDISK)) {
2487 printf ("No Linux %s Ramdisk Image\n",
2488 genimg_get_arch_name(arch));
2489 show_boot_progress (-126);
2493 show_boot_progress (127);
2496 #endif /* USE_HOSTCC */
2497 #endif /* CONFIG_FIT */