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 #if defined(CONFIG_ARTOS) || defined(USE_HOSTCC)
109 { IH_OS_ARTOS, "artos", "ARTOS", },
111 { IH_OS_LINUX, "linux", "Linux", },
112 #if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC)
113 { IH_OS_LYNXOS, "lynxos", "LynxOS", },
115 { IH_OS_NETBSD, "netbsd", "NetBSD", },
116 { IH_OS_RTEMS, "rtems", "RTEMS", },
117 { IH_OS_U_BOOT, "u-boot", "U-Boot", },
118 #if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC)
119 { IH_OS_QNX, "qnx", "QNX", },
120 { IH_OS_VXWORKS, "vxworks", "VxWorks", },
123 { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", },
124 { IH_OS_DELL, "dell", "Dell", },
125 { IH_OS_ESIX, "esix", "Esix", },
126 { IH_OS_FREEBSD, "freebsd", "FreeBSD", },
127 { IH_OS_IRIX, "irix", "Irix", },
128 { IH_OS_NCR, "ncr", "NCR", },
129 { IH_OS_OPENBSD, "openbsd", "OpenBSD", },
130 { IH_OS_PSOS, "psos", "pSOS", },
131 { IH_OS_SCO, "sco", "SCO", },
132 { IH_OS_SOLARIS, "solaris", "Solaris", },
133 { IH_OS_SVR4, "svr4", "SVR4", },
138 static table_entry_t uimage_type[] = {
139 { IH_TYPE_INVALID, NULL, "Invalid Image", },
140 { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", },
141 { IH_TYPE_FIRMWARE, "firmware", "Firmware", },
142 { IH_TYPE_KERNEL, "kernel", "Kernel Image", },
143 { IH_TYPE_MULTI, "multi", "Multi-File Image", },
144 { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", },
145 { IH_TYPE_SCRIPT, "script", "Script", },
146 { IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
147 { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", },
151 static table_entry_t uimage_comp[] = {
152 { IH_COMP_NONE, "none", "uncompressed", },
153 { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", },
154 { IH_COMP_GZIP, "gzip", "gzip compressed", },
158 uint32_t crc32 (uint32_t, const unsigned char *, uint);
159 uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint);
160 static void genimg_print_size (uint32_t size);
161 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
162 static void genimg_print_time (time_t timestamp);
165 /*****************************************************************************/
166 /* Legacy format routines */
167 /*****************************************************************************/
168 int image_check_hcrc (image_header_t *hdr)
171 ulong len = image_get_header_size ();
172 image_header_t header;
174 /* Copy header so we can blank CRC field for re-calculation */
175 memmove (&header, (char *)hdr, image_get_header_size ());
176 image_set_hcrc (&header, 0);
178 hcrc = crc32 (0, (unsigned char *)&header, len);
180 return (hcrc == image_get_hcrc (hdr));
183 int image_check_dcrc (image_header_t *hdr)
185 ulong data = image_get_data (hdr);
186 ulong len = image_get_data_size (hdr);
187 ulong dcrc = crc32_wd (0, (unsigned char *)data, len, CHUNKSZ_CRC32);
189 return (dcrc == image_get_dcrc (hdr));
194 * image_multi_count - get component (sub-image) count
195 * @hdr: pointer to the header of the multi component image
197 * image_multi_count() returns number of components in a multi
200 * Note: no checking of the image type is done, caller must pass
201 * a valid multi component image.
204 * number of components
206 ulong image_multi_count (image_header_t *hdr)
211 /* get start of the image payload, which in case of multi
212 * component images that points to a table of component sizes */
213 size = (uint32_t *)image_get_data (hdr);
215 /* count non empty slots */
216 for (i = 0; size[i]; ++i)
223 * image_multi_getimg - get component data address and size
224 * @hdr: pointer to the header of the multi component image
225 * @idx: index of the requested component
226 * @data: pointer to a ulong variable, will hold component data address
227 * @len: pointer to a ulong variable, will hold component size
229 * image_multi_getimg() returns size and data address for the requested
230 * component in a multi component image.
232 * Note: no checking of the image type is done, caller must pass
233 * a valid multi component image.
236 * data address and size of the component, if idx is valid
237 * 0 in data and len, if idx is out of range
239 void image_multi_getimg (image_header_t *hdr, ulong idx,
240 ulong *data, ulong *len)
244 ulong offset, count, img_data;
246 /* get number of component */
247 count = image_multi_count (hdr);
249 /* get start of the image payload, which in case of multi
250 * component images that points to a table of component sizes */
251 size = (uint32_t *)image_get_data (hdr);
253 /* get address of the proper component data start, which means
254 * skipping sizes table (add 1 for last, null entry) */
255 img_data = image_get_data (hdr) + (count + 1) * sizeof (uint32_t);
258 *len = uimage_to_cpu (size[idx]);
261 /* go over all indices preceding requested component idx */
262 for (i = 0; i < idx; i++) {
263 /* add up i-th component size, rounding up to 4 bytes */
264 offset += (uimage_to_cpu (size[i]) + 3) & ~3 ;
267 /* calculate idx-th component data address */
268 *data = img_data + offset;
275 static void image_print_type (image_header_t *hdr)
277 const char *os, *arch, *type, *comp;
279 os = genimg_get_os_name (image_get_os (hdr));
280 arch = genimg_get_arch_name (image_get_arch (hdr));
281 type = genimg_get_type_name (image_get_type (hdr));
282 comp = genimg_get_comp_name (image_get_comp (hdr));
284 printf ("%s %s %s (%s)\n", arch, os, type, comp);
288 * image_print_contents - prints out the contents of the legacy format image
289 * @hdr: pointer to the legacy format image header
290 * @p: pointer to prefix string
292 * image_print_contents() formats a multi line legacy image contents description.
293 * The routine prints out all header fields followed by the size/offset data
294 * for MULTI/SCRIPT images.
297 * no returned results
299 void image_print_contents (image_header_t *hdr)
309 printf ("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name (hdr));
310 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
311 printf ("%sCreated: ", p);
312 genimg_print_time ((time_t)image_get_time (hdr));
314 printf ("%sImage Type: ", p);
315 image_print_type (hdr);
316 printf ("%sData Size: ", p);
317 genimg_print_size (image_get_data_size (hdr));
318 printf ("%sLoad Address: %08x\n", p, image_get_load (hdr));
319 printf ("%sEntry Point: %08x\n", p, image_get_ep (hdr));
321 if (image_check_type (hdr, IH_TYPE_MULTI) ||
322 image_check_type (hdr, IH_TYPE_SCRIPT)) {
325 ulong count = image_multi_count (hdr);
327 printf ("%sContents:\n", p);
328 for (i = 0; i < count; i++) {
329 image_multi_getimg (hdr, i, &data, &len);
331 printf ("%s Image %d: ", p, i);
332 genimg_print_size (len);
334 if (image_check_type (hdr, IH_TYPE_SCRIPT) && i > 0) {
336 * the user may need to know offsets
337 * if planning to do something with
340 printf ("%s Offset = 0x%08lx\n", p, data);
349 * image_get_ramdisk - get and verify ramdisk image
350 * @rd_addr: ramdisk image start address
351 * @arch: expected ramdisk architecture
352 * @verify: checksum verification flag
354 * image_get_ramdisk() returns a pointer to the verified ramdisk image
355 * header. Routine receives image start address and expected architecture
356 * flag. Verification done covers data and header integrity and os/type/arch
359 * If dataflash support is enabled routine checks for dataflash addresses
360 * and handles required dataflash reads.
363 * pointer to a ramdisk image header, if image was found and valid
364 * otherwise, return NULL
366 static image_header_t* image_get_ramdisk (ulong rd_addr, uint8_t arch,
369 image_header_t *rd_hdr = (image_header_t *)rd_addr;
371 if (!image_check_magic (rd_hdr)) {
372 puts ("Bad Magic Number\n");
373 show_boot_progress (-10);
377 if (!image_check_hcrc (rd_hdr)) {
378 puts ("Bad Header Checksum\n");
379 show_boot_progress (-11);
383 show_boot_progress (10);
384 image_print_contents (rd_hdr);
387 puts(" Verifying Checksum ... ");
388 if (!image_check_dcrc (rd_hdr)) {
389 puts ("Bad Data CRC\n");
390 show_boot_progress (-12);
396 show_boot_progress (11);
398 if (!image_check_os (rd_hdr, IH_OS_LINUX) ||
399 !image_check_arch (rd_hdr, arch) ||
400 !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) {
401 printf ("No Linux %s Ramdisk Image\n",
402 genimg_get_arch_name(arch));
403 show_boot_progress (-13);
409 #endif /* !USE_HOSTCC */
411 /*****************************************************************************/
412 /* Shared dual-format routines */
413 /*****************************************************************************/
415 int getenv_yesno (char *var)
417 char *s = getenv (var);
418 return (s && (*s == 'n')) ? 0 : 1;
421 ulong getenv_bootm_low(void)
423 char *s = getenv ("bootm_low");
425 ulong tmp = simple_strtoul (s, NULL, 16);
429 #if defined(CFG_SDRAM_BASE)
430 return CFG_SDRAM_BASE;
431 #elif defined(CONFIG_ARM)
432 return gd->bd->bi_dram[0].start;
438 ulong getenv_bootm_size(void)
440 char *s = getenv ("bootm_size");
442 ulong tmp = simple_strtoul (s, NULL, 16);
446 #if defined(CONFIG_ARM)
447 return gd->bd->bi_dram[0].size;
449 return gd->bd->bi_memsize;
453 void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
455 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
457 size_t tail = (len > chunksz) ? chunksz : len;
459 memmove (to, from, tail);
464 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
465 memmove (to, from, len);
466 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
468 #endif /* !USE_HOSTCC */
470 static void genimg_print_size (uint32_t size)
473 printf ("%d Bytes = ", size);
474 print_size (size, "\n");
476 printf ("%d Bytes = %.2f kB = %.2f MB\n",
477 size, (double)size / 1.024e3,
478 (double)size / 1.048576e6);
482 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
483 static void genimg_print_time (time_t timestamp)
488 to_tm (timestamp, &tm);
489 printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
490 tm.tm_year, tm.tm_mon, tm.tm_mday,
491 tm.tm_hour, tm.tm_min, tm.tm_sec);
493 printf ("%s", ctime(×tamp));
496 #endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */
499 * get_table_entry_name - translate entry id to long name
500 * @table: pointer to a translation table for entries of a specific type
501 * @msg: message to be returned when translation fails
502 * @id: entry id to be translated
504 * get_table_entry_name() will go over translation table trying to find
505 * entry that matches given id. If matching entry is found, its long
506 * name is returned to the caller.
509 * long entry name if translation succeeds
512 static char *get_table_entry_name (table_entry_t *table, char *msg, int id)
514 for (; table->id >= 0; ++table) {
516 return (table->lname);
521 const char *genimg_get_os_name (uint8_t os)
523 return (get_table_entry_name (uimage_os, "Unknown OS", os));
526 const char *genimg_get_arch_name (uint8_t arch)
528 return (get_table_entry_name (uimage_arch, "Unknown Architecture", arch));
531 const char *genimg_get_type_name (uint8_t type)
533 return (get_table_entry_name (uimage_type, "Unknown Image", type));
536 const char *genimg_get_comp_name (uint8_t comp)
538 return (get_table_entry_name (uimage_comp, "Unknown Compression", comp));
542 * get_table_entry_id - translate short entry name to id
543 * @table: pointer to a translation table for entries of a specific type
544 * @table_name: to be used in case of error
545 * @name: entry short name to be translated
547 * get_table_entry_id() will go over translation table trying to find
548 * entry that matches given short name. If matching entry is found,
549 * its id returned to the caller.
552 * entry id if translation succeeds
555 static int get_table_entry_id (table_entry_t *table,
556 const char *table_name, const char *name)
562 for (t = table; t->id >= 0; ++t) {
563 if (t->sname && strcasecmp(t->sname, name) == 0)
567 fprintf (stderr, "\nInvalid %s Type - valid names are", table_name);
568 for (t = table; t->id >= 0; ++t) {
569 if (t->sname == NULL)
571 fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname);
574 fprintf (stderr, "\n");
576 for (t = table; t->id >= 0; ++t) {
577 if (t->sname && strcmp(t->sname, name) == 0)
580 debug ("Invalid %s Type: %s\n", table_name, name);
581 #endif /* USE_HOSTCC */
585 int genimg_get_os_id (const char *name)
587 return (get_table_entry_id (uimage_os, "OS", name));
590 int genimg_get_arch_id (const char *name)
592 return (get_table_entry_id (uimage_arch, "CPU", name));
595 int genimg_get_type_id (const char *name)
597 return (get_table_entry_id (uimage_type, "Image", name));
600 int genimg_get_comp_id (const char *name)
602 return (get_table_entry_id (uimage_comp, "Compression", name));
607 * genimg_get_format - get image format type
608 * @img_addr: image start address
610 * genimg_get_format() checks whether provided address points to a valid
611 * legacy or FIT image.
613 * New uImage format and FDT blob are based on a libfdt. FDT blob
614 * may be passed directly or embedded in a FIT image. In both situations
615 * genimg_get_format() must be able to dectect libfdt header.
618 * image format type or IMAGE_FORMAT_INVALID if no image is present
620 int genimg_get_format (void *img_addr)
622 ulong format = IMAGE_FORMAT_INVALID;
624 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
628 hdr = (image_header_t *)img_addr;
629 if (image_check_magic(hdr))
630 format = IMAGE_FORMAT_LEGACY;
631 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
633 fit_hdr = (char *)img_addr;
634 if (fdt_check_header (fit_hdr) == 0)
635 format = IMAGE_FORMAT_FIT;
643 * genimg_get_image - get image from special storage (if necessary)
644 * @img_addr: image start address
646 * genimg_get_image() checks if provided image start adddress is located
647 * in a dataflash storage. If so, image is moved to a system RAM memory.
650 * image start address after possible relocation from special storage
652 ulong genimg_get_image (ulong img_addr)
654 ulong ram_addr = img_addr;
656 #ifdef CONFIG_HAS_DATAFLASH
657 ulong h_size, d_size;
659 if (addr_dataflash (img_addr)){
660 /* ger RAM address */
661 ram_addr = CFG_LOAD_ADDR;
663 /* get header size */
664 h_size = image_get_header_size ();
665 #if defined(CONFIG_FIT)
666 if (sizeof(struct fdt_header) > h_size)
667 h_size = sizeof(struct fdt_header);
671 debug (" Reading image header from dataflash address "
672 "%08lx to RAM address %08lx\n", img_addr, ram_addr);
674 read_dataflash (img_addr, h_size, (char *)ram_addr);
677 switch (genimg_get_format ((void *)ram_addr)) {
678 case IMAGE_FORMAT_LEGACY:
679 d_size = image_get_data_size ((image_header_t *)ram_addr);
680 debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n",
683 #if defined(CONFIG_FIT)
684 case IMAGE_FORMAT_FIT:
685 d_size = fit_get_size ((const void *)ram_addr) - h_size;
686 debug (" FIT/FDT format image found at 0x%08lx, size 0x%08lx\n",
691 printf (" No valid image found at 0x%08lx\n", img_addr);
695 /* read in image data */
696 debug (" Reading image remaining data from dataflash address "
697 "%08lx to RAM address %08lx\n", img_addr + h_size,
700 read_dataflash (img_addr + h_size, d_size,
701 (char *)(ram_addr + h_size));
704 #endif /* CONFIG_HAS_DATAFLASH */
710 * fit_has_config - check if there is a valid FIT configuration
711 * @images: pointer to the bootm command headers structure
713 * fit_has_config() checks if there is a FIT configuration in use
714 * (if FTI support is present).
717 * 0, no FIT support or no configuration found
718 * 1, configuration found
720 int genimg_has_config (bootm_headers_t *images)
722 #if defined(CONFIG_FIT)
723 if (images->fit_uname_cfg)
730 * boot_get_ramdisk - main ramdisk handling routine
731 * @argc: command argument count
732 * @argv: command argument list
733 * @images: pointer to the bootm images structure
734 * @arch: expected ramdisk architecture
735 * @rd_start: pointer to a ulong variable, will hold ramdisk start address
736 * @rd_end: pointer to a ulong variable, will hold ramdisk end
738 * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
739 * Curently supported are the following ramdisk sources:
740 * - multicomponent kernel/ramdisk image,
741 * - commandline provided address of decicated ramdisk image.
744 * 0, if ramdisk image was found and valid, or skiped
745 * rd_start and rd_end are set to ramdisk start/end addresses if
746 * ramdisk image is found and valid
748 * 1, if ramdisk image is found but corrupted
749 * rd_start and rd_end are set to 0 if no ramdisk exists
751 int boot_get_ramdisk (int argc, char *argv[], bootm_headers_t *images,
752 uint8_t arch, ulong *rd_start, ulong *rd_end)
754 ulong rd_addr, rd_load;
755 ulong rd_data, rd_len;
756 image_header_t *rd_hdr;
757 #if defined(CONFIG_FIT)
759 const char *fit_uname_config = NULL;
760 const char *fit_uname_ramdisk = NULL;
772 * Look for a '-' which indicates to ignore the
775 if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) {
776 debug ("## Skipping init Ramdisk\n");
777 rd_len = rd_data = 0;
778 } else if (argc >= 3 || genimg_has_config (images)) {
779 #if defined(CONFIG_FIT)
782 * If the init ramdisk comes from the FIT image and
783 * the FIT image address is omitted in the command
784 * line argument, try to use os FIT image address or
785 * default load address.
787 if (images->fit_uname_os)
788 default_addr = (ulong)images->fit_hdr_os;
790 default_addr = load_addr;
792 if (fit_parse_conf (argv[2], default_addr,
793 &rd_addr, &fit_uname_config)) {
794 debug ("* ramdisk: config '%s' from image at 0x%08lx\n",
795 fit_uname_config, rd_addr);
796 } else if (fit_parse_subimage (argv[2], default_addr,
797 &rd_addr, &fit_uname_ramdisk)) {
798 debug ("* ramdisk: subimage '%s' from image at 0x%08lx\n",
799 fit_uname_ramdisk, rd_addr);
803 rd_addr = simple_strtoul(argv[2], NULL, 16);
804 debug ("* ramdisk: cmdline image address = 0x%08lx\n",
807 #if defined(CONFIG_FIT)
809 /* use FIT configuration provided in first bootm
812 rd_addr = (ulong)images->fit_hdr_os;
813 fit_uname_config = images->fit_uname_cfg;
814 debug ("* ramdisk: using config '%s' from image at 0x%08lx\n",
815 fit_uname_config, rd_addr);
818 * Check whether configuration has ramdisk defined,
819 * if not, don't try to use it, quit silently.
821 fit_hdr = (void *)rd_addr;
822 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
823 if (cfg_noffset < 0) {
824 debug ("* ramdisk: no such config\n");
828 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
829 if (rd_noffset < 0) {
830 debug ("* ramdisk: no ramdisk in config\n");
836 /* copy from dataflash if needed */
837 rd_addr = genimg_get_image (rd_addr);
840 * Check if there is an initrd image at the
841 * address provided in the second bootm argument
842 * check image type, for FIT images get FIT node.
844 switch (genimg_get_format ((void *)rd_addr)) {
845 case IMAGE_FORMAT_LEGACY:
846 printf ("## Loading init Ramdisk from Legacy "
847 "Image at %08lx ...\n", rd_addr);
849 show_boot_progress (9);
850 rd_hdr = image_get_ramdisk (rd_addr, arch,
856 rd_data = image_get_data (rd_hdr);
857 rd_len = image_get_data_size (rd_hdr);
858 rd_load = image_get_load (rd_hdr);
860 #if defined(CONFIG_FIT)
861 case IMAGE_FORMAT_FIT:
862 fit_hdr = (void *)rd_addr;
863 printf ("## Loading init Ramdisk from FIT "
864 "Image at %08lx ...\n", rd_addr);
866 show_boot_progress (120);
867 if (!fit_check_format (fit_hdr)) {
868 puts ("Bad FIT ramdisk image format!\n");
869 show_boot_progress (-120);
872 show_boot_progress (121);
874 if (!fit_uname_ramdisk) {
876 * no ramdisk image node unit name, try to get config
877 * node first. If config unit node name is NULL
878 * fit_conf_get_node() will try to find default config node
880 show_boot_progress (122);
881 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
882 if (cfg_noffset < 0) {
883 puts ("Could not find configuration node\n");
884 show_boot_progress (-122);
887 fit_uname_config = fdt_get_name (fit_hdr, cfg_noffset, NULL);
888 printf (" Using '%s' configuration\n", fit_uname_config);
890 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
891 fit_uname_ramdisk = fit_get_name (fit_hdr, rd_noffset, NULL);
893 /* get ramdisk component image node offset */
894 show_boot_progress (123);
895 rd_noffset = fit_image_get_node (fit_hdr, fit_uname_ramdisk);
897 if (rd_noffset < 0) {
898 puts ("Could not find subimage node\n");
899 show_boot_progress (-124);
903 printf (" Trying '%s' ramdisk subimage\n", fit_uname_ramdisk);
905 show_boot_progress (125);
906 if (!fit_check_ramdisk (fit_hdr, rd_noffset, arch, images->verify))
909 /* get ramdisk image data address and length */
910 if (fit_image_get_data (fit_hdr, rd_noffset, &data, &size)) {
911 puts ("Could not find ramdisk subimage data!\n");
912 show_boot_progress (-127);
915 show_boot_progress (128);
917 rd_data = (ulong)data;
920 if (fit_image_get_load (fit_hdr, rd_noffset, &rd_load)) {
921 puts ("Can't get ramdisk subimage load address!\n");
922 show_boot_progress (-129);
925 show_boot_progress (129);
927 images->fit_hdr_rd = fit_hdr;
928 images->fit_uname_rd = fit_uname_ramdisk;
929 images->fit_noffset_rd = rd_noffset;
933 puts ("Wrong Ramdisk Image Format\n");
934 rd_data = rd_len = rd_load = 0;
937 #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO)
939 * We need to copy the ramdisk to SRAM to let Linux boot
942 memmove ((void *)rd_load, (uchar *)rd_data, rd_len);
945 #endif /* CONFIG_B2 || CONFIG_EVB4510 || CONFIG_ARMADILLO */
947 } else if (images->legacy_hdr_valid &&
948 image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
950 * Now check if we have a legacy mult-component image,
951 * get second entry data start address and len.
953 show_boot_progress (13);
954 printf ("## Loading init Ramdisk from multi component "
955 "Legacy Image at %08lx ...\n",
956 (ulong)images->legacy_hdr_os);
958 image_multi_getimg (images->legacy_hdr_os, 1, &rd_data, &rd_len);
963 show_boot_progress (14);
964 rd_len = rd_data = 0;
968 debug ("## No init Ramdisk\n");
971 *rd_end = rd_data + rd_len;
973 debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
979 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
981 * boot_ramdisk_high - relocate init ramdisk
982 * @lmb: pointer to lmb handle, will be used for memory mgmt
983 * @rd_data: ramdisk data start address
984 * @rd_len: ramdisk data length
985 * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
986 * start address (after possible relocation)
987 * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
988 * end address (after possible relocation)
990 * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
991 * variable and if requested ramdisk data is moved to a specified location.
993 * Initrd_start and initrd_end are set to final (after relocation) ramdisk
994 * start/end addresses if ramdisk image start and len were provided,
995 * otherwise set initrd_start and initrd_end set to zeros.
1001 int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
1002 ulong *initrd_start, ulong *initrd_end)
1006 int initrd_copy_to_ram = 1;
1008 if ((s = getenv ("initrd_high")) != NULL) {
1009 /* a value of "no" or a similar string will act like 0,
1010 * turning the "load high" feature off. This is intentional.
1012 initrd_high = simple_strtoul (s, NULL, 16);
1013 if (initrd_high == ~0)
1014 initrd_copy_to_ram = 0;
1016 /* not set, no restrictions to load high */
1020 /* Prevent initrd from overwriting logbuffer */
1021 lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
1023 debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
1024 initrd_high, initrd_copy_to_ram);
1027 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
1028 debug (" in-place initrd\n");
1029 *initrd_start = rd_data;
1030 *initrd_end = rd_data + rd_len;
1031 lmb_reserve(lmb, rd_data, rd_len);
1034 *initrd_start = lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
1036 *initrd_start = lmb_alloc (lmb, rd_len, 0x1000);
1038 if (*initrd_start == 0) {
1039 puts ("ramdisk - allocation error\n");
1042 show_boot_progress (12);
1044 *initrd_end = *initrd_start + rd_len;
1045 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
1046 *initrd_start, *initrd_end);
1048 memmove_wd ((void *)*initrd_start,
1049 (void *)rd_data, rd_len, CHUNKSZ);
1057 debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
1058 *initrd_start, *initrd_end);
1067 * boot_get_cmdline - allocate and initialize kernel cmdline
1068 * @lmb: pointer to lmb handle, will be used for memory mgmt
1069 * @cmd_start: pointer to a ulong variable, will hold cmdline start
1070 * @cmd_end: pointer to a ulong variable, will hold cmdline end
1071 * @bootmap_base: ulong variable, holds offset in physical memory to
1074 * boot_get_cmdline() allocates space for kernel command line below
1075 * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt
1076 * variable is present its contents is copied to allocated kernel
1083 int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end,
1089 cmdline = (char *)lmb_alloc_base(lmb, CFG_BARGSIZE, 0xf,
1090 CFG_BOOTMAPSZ + bootmap_base);
1092 if (cmdline == NULL)
1095 if ((s = getenv("bootargs")) == NULL)
1100 *cmd_start = (ulong) & cmdline[0];
1101 *cmd_end = *cmd_start + strlen(cmdline);
1103 debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
1109 * boot_get_kbd - allocate and initialize kernel copy of board info
1110 * @lmb: pointer to lmb handle, will be used for memory mgmt
1111 * @kbd: double pointer to board info data
1112 * @bootmap_base: ulong variable, holds offset in physical memory to
1115 * boot_get_kbd() allocates space for kernel copy of board info data below
1116 * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with
1117 * the current u-boot board info data.
1123 int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base)
1125 *kbd = (bd_t *)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
1126 CFG_BOOTMAPSZ + bootmap_base);
1132 debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
1134 #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
1135 do_bdinfo(NULL, 0, 0, NULL);
1140 #endif /* CONFIG_PPC || CONFIG_M68K */
1141 #endif /* !USE_HOSTCC */
1143 #if defined(CONFIG_FIT)
1144 /*****************************************************************************/
1145 /* New uImage format routines */
1146 /*****************************************************************************/
1148 static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr,
1149 ulong *addr, const char **name)
1156 sep = strchr (spec, sepc);
1159 *addr = simple_strtoul (spec, NULL, 16);
1169 * fit_parse_conf - parse FIT configuration spec
1170 * @spec: input string, containing configuration spec
1171 * @add_curr: current image address (to be used as a possible default)
1172 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1174 * @conf_name double pointer to a char, will hold pointer to a configuration
1177 * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
1178 * where <addr> is a FIT image address that contains configuration
1179 * with a <conf> unit name.
1181 * Address part is optional, and if omitted default add_curr will
1185 * 1 if spec is a valid configuration string,
1186 * addr and conf_name are set accordingly
1189 inline int fit_parse_conf (const char *spec, ulong addr_curr,
1190 ulong *addr, const char **conf_name)
1192 return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
1196 * fit_parse_subimage - parse FIT subimage spec
1197 * @spec: input string, containing subimage spec
1198 * @add_curr: current image address (to be used as a possible default)
1199 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1201 * @image_name: double pointer to a char, will hold pointer to a subimage name
1203 * fit_parse_subimage() expects subimage spec in the for of
1204 * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
1205 * subimage with a <subimg> unit name.
1207 * Address part is optional, and if omitted default add_curr will
1211 * 1 if spec is a valid subimage string,
1212 * addr and image_name are set accordingly
1215 inline int fit_parse_subimage (const char *spec, ulong addr_curr,
1216 ulong *addr, const char **image_name)
1218 return fit_parse_spec (spec, ':', addr_curr, addr, image_name);
1220 #endif /* !USE_HOSTCC */
1222 static void fit_get_debug (const void *fit, int noffset,
1223 char *prop_name, int err)
1225 debug ("Can't get '%s' property from FIT 0x%08lx, "
1226 "node: offset %d, name %s (%s)\n",
1227 prop_name, (ulong)fit, noffset,
1228 fit_get_name (fit, noffset, NULL),
1229 fdt_strerror (err));
1233 * fit_print_contents - prints out the contents of the FIT format image
1234 * @fit: pointer to the FIT format image header
1235 * @p: pointer to prefix string
1237 * fit_print_contents() formats a multi line FIT image contents description.
1238 * The routine prints out FIT image properties (root node level) follwed by
1239 * the details of each component image.
1242 * no returned results
1244 void fit_print_contents (const void *fit)
1255 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1265 /* Root node properties */
1266 ret = fit_get_desc (fit, 0, &desc);
1267 printf ("%sFIT description: ", p);
1269 printf ("unavailable\n");
1271 printf ("%s\n", desc);
1273 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1274 ret = fit_get_timestamp (fit, 0, ×tamp);
1275 printf ("%sCreated: ", p);
1277 printf ("unavailable\n");
1279 genimg_print_time (timestamp);
1282 /* Find images parent node offset */
1283 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
1284 if (images_noffset < 0) {
1285 printf ("Can't find images parent node '%s' (%s)\n",
1286 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
1290 /* Process its subnodes, print out component images details */
1291 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
1292 (noffset >= 0) && (ndepth > 0);
1293 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1296 * Direct child node of the images parent node,
1297 * i.e. component image node.
1299 printf ("%s Image %u (%s)\n", p, count++,
1300 fit_get_name(fit, noffset, NULL));
1302 fit_image_print (fit, noffset, p);
1306 /* Find configurations parent node offset */
1307 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
1308 if (confs_noffset < 0) {
1309 debug ("Can't get configurations parent node '%s' (%s)\n",
1310 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
1314 /* get default configuration unit name from default property */
1315 uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL);
1317 printf ("%s Default Configuration: '%s'\n", p, uname);
1319 /* Process its subnodes, print out configurations details */
1320 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth);
1321 (noffset >= 0) && (ndepth > 0);
1322 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1325 * Direct child node of the configurations parent node,
1326 * i.e. configuration node.
1328 printf ("%s Configuration %u (%s)\n", p, count++,
1329 fit_get_name(fit, noffset, NULL));
1331 fit_conf_print (fit, noffset, p);
1337 * fit_image_print - prints out the FIT component image details
1338 * @fit: pointer to the FIT format image header
1339 * @image_noffset: offset of the component image node
1340 * @p: pointer to prefix string
1342 * fit_image_print() lists all mandatory properies for the processed component
1343 * image. If present, hash nodes are printed out as well.
1346 * no returned results
1348 void fit_image_print (const void *fit, int image_noffset, const char *p)
1351 uint8_t type, arch, os, comp;
1359 /* Mandatory properties */
1360 ret = fit_get_desc (fit, image_noffset, &desc);
1361 printf ("%s Description: ", p);
1363 printf ("unavailable\n");
1365 printf ("%s\n", desc);
1367 fit_image_get_type (fit, image_noffset, &type);
1368 printf ("%s Type: %s\n", p, genimg_get_type_name (type));
1370 fit_image_get_comp (fit, image_noffset, &comp);
1371 printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp));
1373 ret = fit_image_get_data (fit, image_noffset, &data, &size);
1376 printf ("%s Data Start: ", p);
1378 printf ("unavailable\n");
1380 printf ("0x%08lx\n", (ulong)data);
1383 printf ("%s Data Size: ", p);
1385 printf ("unavailable\n");
1387 genimg_print_size (size);
1389 /* Remaining, type dependent properties */
1390 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
1391 (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
1392 (type == IH_TYPE_FLATDT)) {
1393 fit_image_get_arch (fit, image_noffset, &arch);
1394 printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch));
1397 if (type == IH_TYPE_KERNEL) {
1398 fit_image_get_os (fit, image_noffset, &os);
1399 printf ("%s OS: %s\n", p, genimg_get_os_name (os));
1402 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
1403 ret = fit_image_get_load (fit, image_noffset, &load);
1404 printf ("%s Load Address: ", p);
1406 printf ("unavailable\n");
1408 printf ("0x%08lx\n", load);
1410 fit_image_get_entry (fit, image_noffset, &entry);
1411 printf ("%s Entry Point: ", p);
1413 printf ("unavailable\n");
1415 printf ("0x%08lx\n", entry);
1418 /* Process all hash subnodes of the component image node */
1419 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
1420 (noffset >= 0) && (ndepth > 0);
1421 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1423 /* Direct child node of the component image node */
1424 fit_image_print_hash (fit, noffset, p);
1430 * fit_image_print_hash - prints out the hash node details
1431 * @fit: pointer to the FIT format image header
1432 * @noffset: offset of the hash node
1433 * @p: pointer to prefix string
1435 * fit_image_print_hash() lists properies for the processed hash node
1438 * no returned results
1440 void fit_image_print_hash (const void *fit, int noffset, const char *p)
1448 * Check subnode name, must be equal to "hash".
1449 * Multiple hash nodes require unique unit node
1450 * names, e.g. hash@1, hash@2, etc.
1452 if (strncmp (fit_get_name(fit, noffset, NULL),
1454 strlen(FIT_HASH_NODENAME)) != 0)
1457 debug ("%s Hash node: '%s'\n", p,
1458 fit_get_name (fit, noffset, NULL));
1460 printf ("%s Hash algo: ", p);
1461 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
1462 printf ("invalid/unsupported\n");
1465 printf ("%s\n", algo);
1467 ret = fit_image_hash_get_value (fit, noffset, &value,
1469 printf ("%s Hash value: ", p);
1471 printf ("unavailable\n");
1473 for (i = 0; i < value_len; i++)
1474 printf ("%02x", value[i]);
1478 debug ("%s Hash len: %d\n", p, value_len);
1482 * fit_get_desc - get node description property
1483 * @fit: pointer to the FIT format image header
1484 * @noffset: node offset
1485 * @desc: double pointer to the char, will hold pointer to the descrption
1487 * fit_get_desc() reads description property from a given node, if
1488 * description is found pointer to it is returened in third call argument.
1494 int fit_get_desc (const void *fit, int noffset, char **desc)
1498 *desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len);
1499 if (*desc == NULL) {
1500 fit_get_debug (fit, noffset, FIT_DESC_PROP, len);
1508 * fit_get_timestamp - get node timestamp property
1509 * @fit: pointer to the FIT format image header
1510 * @noffset: node offset
1511 * @timestamp: pointer to the time_t, will hold read timestamp
1513 * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
1514 * is found and has a correct size its value is retured in third call
1519 * -1, on property read failure
1520 * -2, on wrong timestamp size
1522 int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp)
1527 data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len);
1529 fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len);
1532 if (len != sizeof (uint32_t)) {
1533 debug ("FIT timestamp with incorrect size of (%u)\n", len);
1537 *timestamp = uimage_to_cpu (*((uint32_t *)data));
1542 * fit_image_get_node - get node offset for component image of a given unit name
1543 * @fit: pointer to the FIT format image header
1544 * @image_uname: component image node unit name
1546 * fit_image_get_node() finds a component image (withing the '/images'
1547 * node) of a provided unit name. If image is found its node offset is
1548 * returned to the caller.
1551 * image node offset when found (>=0)
1552 * negative number on failure (FDT_ERR_* code)
1554 int fit_image_get_node (const void *fit, const char *image_uname)
1556 int noffset, images_noffset;
1558 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
1559 if (images_noffset < 0) {
1560 debug ("Can't find images parent node '%s' (%s)\n",
1561 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
1562 return images_noffset;
1565 noffset = fdt_subnode_offset (fit, images_noffset, image_uname);
1567 debug ("Can't get node offset for image unit name: '%s' (%s)\n",
1568 image_uname, fdt_strerror (noffset));
1575 * fit_image_get_os - get os id for a given component image node
1576 * @fit: pointer to the FIT format image header
1577 * @noffset: component image node offset
1578 * @os: pointer to the uint8_t, will hold os numeric id
1580 * fit_image_get_os() finds os property in a given component image node.
1581 * If the property is found, its (string) value is translated to the numeric
1582 * id which is returned to the caller.
1588 int fit_image_get_os (const void *fit, int noffset, uint8_t *os)
1593 /* Get OS name from property data */
1594 data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len);
1596 fit_get_debug (fit, noffset, FIT_OS_PROP, len);
1601 /* Translate OS name to id */
1602 *os = genimg_get_os_id (data);
1607 * fit_image_get_arch - get arch id for a given component image node
1608 * @fit: pointer to the FIT format image header
1609 * @noffset: component image node offset
1610 * @arch: pointer to the uint8_t, will hold arch numeric id
1612 * fit_image_get_arch() finds arch property in a given component image node.
1613 * If the property is found, its (string) value is translated to the numeric
1614 * id which is returned to the caller.
1620 int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch)
1625 /* Get architecture name from property data */
1626 data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len);
1628 fit_get_debug (fit, noffset, FIT_ARCH_PROP, len);
1633 /* Translate architecture name to id */
1634 *arch = genimg_get_arch_id (data);
1639 * fit_image_get_type - get type id for a given component image node
1640 * @fit: pointer to the FIT format image header
1641 * @noffset: component image node offset
1642 * @type: pointer to the uint8_t, will hold type numeric id
1644 * fit_image_get_type() finds type property in a given component image node.
1645 * If the property is found, its (string) value is translated to the numeric
1646 * id which is returned to the caller.
1652 int fit_image_get_type (const void *fit, int noffset, uint8_t *type)
1657 /* Get image type name from property data */
1658 data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len);
1660 fit_get_debug (fit, noffset, FIT_TYPE_PROP, len);
1665 /* Translate image type name to id */
1666 *type = genimg_get_type_id (data);
1671 * fit_image_get_comp - get comp id for a given component image node
1672 * @fit: pointer to the FIT format image header
1673 * @noffset: component image node offset
1674 * @comp: pointer to the uint8_t, will hold comp numeric id
1676 * fit_image_get_comp() finds comp property in a given component image node.
1677 * If the property is found, its (string) value is translated to the numeric
1678 * id which is returned to the caller.
1684 int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp)
1689 /* Get compression name from property data */
1690 data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len);
1692 fit_get_debug (fit, noffset, FIT_COMP_PROP, len);
1697 /* Translate compression name to id */
1698 *comp = genimg_get_comp_id (data);
1703 * fit_image_get_load - get load address property for a given component image node
1704 * @fit: pointer to the FIT format image header
1705 * @noffset: component image node offset
1706 * @load: pointer to the uint32_t, will hold load address
1708 * fit_image_get_load() finds load address property in a given component image node.
1709 * If the property is found, its value is returned to the caller.
1715 int fit_image_get_load (const void *fit, int noffset, ulong *load)
1718 const uint32_t *data;
1720 data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len);
1722 fit_get_debug (fit, noffset, FIT_LOAD_PROP, len);
1726 *load = uimage_to_cpu (*data);
1731 * fit_image_get_entry - get entry point address property for a given component image node
1732 * @fit: pointer to the FIT format image header
1733 * @noffset: component image node offset
1734 * @entry: pointer to the uint32_t, will hold entry point address
1736 * fit_image_get_entry() finds entry point address property in a given component image node.
1737 * If the property is found, its value is returned to the caller.
1743 int fit_image_get_entry (const void *fit, int noffset, ulong *entry)
1746 const uint32_t *data;
1748 data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len);
1750 fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len);
1754 *entry = uimage_to_cpu (*data);
1759 * fit_image_get_data - get data property and its size for a given component image node
1760 * @fit: pointer to the FIT format image header
1761 * @noffset: component image node offset
1762 * @data: double pointer to void, will hold data property's data address
1763 * @size: pointer to size_t, will hold data property's data size
1765 * fit_image_get_data() finds data property in a given component image node.
1766 * If the property is found its data start address and size are returned to
1773 int fit_image_get_data (const void *fit, int noffset,
1774 const void **data, size_t *size)
1778 *data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len);
1779 if (*data == NULL) {
1780 fit_get_debug (fit, noffset, FIT_DATA_PROP, len);
1790 * fit_image_hash_get_algo - get hash algorithm name
1791 * @fit: pointer to the FIT format image header
1792 * @noffset: hash node offset
1793 * @algo: double pointer to char, will hold pointer to the algorithm name
1795 * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
1796 * If the property is found its data start address is returned to the caller.
1802 int fit_image_hash_get_algo (const void *fit, int noffset, char **algo)
1806 *algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len);
1807 if (*algo == NULL) {
1808 fit_get_debug (fit, noffset, FIT_ALGO_PROP, len);
1816 * fit_image_hash_get_value - get hash value and length
1817 * @fit: pointer to the FIT format image header
1818 * @noffset: hash node offset
1819 * @value: double pointer to uint8_t, will hold address of a hash value data
1820 * @value_len: pointer to an int, will hold hash data length
1822 * fit_image_hash_get_value() finds hash value property in a given hash node.
1823 * If the property is found its data start address and size are returned to
1830 int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value,
1835 *value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len);
1836 if (*value == NULL) {
1837 fit_get_debug (fit, noffset, FIT_VALUE_PROP, len);
1847 * fit_set_timestamp - set node timestamp property
1848 * @fit: pointer to the FIT format image header
1849 * @noffset: node offset
1850 * @timestamp: timestamp value to be set
1852 * fit_set_timestamp() attempts to set timestamp property in the requested
1853 * node and returns operation status to the caller.
1857 * -1, on property read failure
1859 int fit_set_timestamp (void *fit, int noffset, time_t timestamp)
1864 t = cpu_to_uimage (timestamp);
1865 ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t,
1868 printf ("Can't set '%s' property for '%s' node (%s)\n",
1869 FIT_TIMESTAMP_PROP, fit_get_name (fit, noffset, NULL),
1870 fdt_strerror (ret));
1878 * calculate_hash - calculate and return hash for provided input data
1879 * @data: pointer to the input data
1880 * @data_len: data length
1881 * @algo: requested hash algorithm
1882 * @value: pointer to the char, will hold hash value data (caller must
1883 * allocate enough free space)
1884 * value_len: length of the calculated hash
1886 * calculate_hash() computes input data hash according to the requested algorithm.
1887 * Resulting hash value is placed in caller provided 'value' buffer, length
1888 * of the calculated hash is returned via value_len pointer argument.
1892 * -1, when algo is unsupported
1894 static int calculate_hash (const void *data, int data_len, const char *algo,
1895 uint8_t *value, int *value_len)
1897 if (strcmp (algo, "crc32") == 0 ) {
1898 *((uint32_t *)value) = crc32_wd (0, data, data_len,
1900 *((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value));
1902 } else if (strcmp (algo, "sha1") == 0 ) {
1903 sha1_csum_wd ((unsigned char *) data, data_len,
1904 (unsigned char *) value, CHUNKSZ_SHA1);
1906 } else if (strcmp (algo, "md5") == 0 ) {
1907 md5_wd ((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
1910 debug ("Unsupported hash alogrithm\n");
1918 * fit_set_hashes - process FIT component image nodes and calculate hashes
1919 * @fit: pointer to the FIT format image header
1921 * fit_set_hashes() adds hash values for all component images in the FIT blob.
1922 * Hashes are calculated for all component images which have hash subnodes
1923 * with algorithm property set to one of the supported hash algorithms.
1927 * libfdt error code, on failure
1929 int fit_set_hashes (void *fit)
1936 /* Find images parent node offset */
1937 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
1938 if (images_noffset < 0) {
1939 printf ("Can't find images parent node '%s' (%s)\n",
1940 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
1941 return images_noffset;
1944 /* Process its subnodes, print out component images details */
1945 for (ndepth = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
1946 (noffset >= 0) && (ndepth > 0);
1947 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1950 * Direct child node of the images parent node,
1951 * i.e. component image node.
1953 ret = fit_image_set_hashes (fit, noffset);
1963 * fit_image_set_hashes - calculate/set hashes for given component image node
1964 * @fit: pointer to the FIT format image header
1965 * @image_noffset: requested component image node
1967 * fit_image_set_hashes() adds hash values for an component image node. All
1968 * existing hash subnodes are checked, if algorithm property is set to one of
1969 * the supported hash algorithms, hash value is computed and corresponding
1970 * hash node property is set, for example:
1972 * Input component image node structure:
1974 * o image@1 (at image_noffset)
1975 * | - data = [binary data]
1979 * Output component image node structure:
1981 * o image@1 (at image_noffset)
1982 * | - data = [binary data]
1985 * |- value = sha1(data)
1991 int fit_image_set_hashes (void *fit, int image_noffset)
1996 uint8_t value[FIT_MAX_HASH_LEN];
2001 /* Get image data and data length */
2002 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
2003 printf ("Can't get image data/size\n");
2007 /* Process all hash subnodes of the component image node */
2008 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2009 (noffset >= 0) && (ndepth > 0);
2010 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2012 /* Direct child node of the component image node */
2015 * Check subnode name, must be equal to "hash".
2016 * Multiple hash nodes require unique unit node
2017 * names, e.g. hash@1, hash@2, etc.
2019 if (strncmp (fit_get_name(fit, noffset, NULL),
2021 strlen(FIT_HASH_NODENAME)) != 0) {
2022 /* Not a hash subnode, skip it */
2026 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2027 printf ("Can't get hash algo property for "
2028 "'%s' hash node in '%s' image node\n",
2029 fit_get_name (fit, noffset, NULL),
2030 fit_get_name (fit, image_noffset, NULL));
2034 if (calculate_hash (data, size, algo, value, &value_len)) {
2035 printf ("Unsupported hash algorithm (%s) for "
2036 "'%s' hash node in '%s' image node\n",
2037 algo, fit_get_name (fit, noffset, NULL),
2038 fit_get_name (fit, image_noffset, NULL));
2042 if (fit_image_hash_set_value (fit, noffset, value,
2044 printf ("Can't set hash value for "
2045 "'%s' hash node in '%s' image node\n",
2046 fit_get_name (fit, noffset, NULL),
2047 fit_get_name (fit, image_noffset, NULL));
2057 * fit_image_hash_set_value - set hash value in requested has node
2058 * @fit: pointer to the FIT format image header
2059 * @noffset: hash node offset
2060 * @value: hash value to be set
2061 * @value_len: hash value length
2063 * fit_image_hash_set_value() attempts to set hash value in a node at offset
2064 * given and returns operation status to the caller.
2070 int fit_image_hash_set_value (void *fit, int noffset, uint8_t *value,
2075 ret = fdt_setprop (fit, noffset, FIT_VALUE_PROP, value, value_len);
2077 printf ("Can't set hash '%s' property for '%s' node (%s)\n",
2078 FIT_VALUE_PROP, fit_get_name (fit, noffset, NULL),
2079 fdt_strerror (ret));
2085 #endif /* USE_HOSTCC */
2088 * fit_image_check_hashes - verify data intergity
2089 * @fit: pointer to the FIT format image header
2090 * @image_noffset: component image node offset
2092 * fit_image_check_hashes() goes over component image hash nodes,
2093 * re-calculates each data hash and compares with the value stored in hash
2097 * 1, if all hashes are valid
2098 * 0, otherwise (or on error)
2100 int fit_image_check_hashes (const void *fit, int image_noffset)
2107 uint8_t value[FIT_MAX_HASH_LEN];
2113 /* Get image data and data length */
2114 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
2115 printf ("Can't get image data/size\n");
2119 /* Process all hash subnodes of the component image node */
2120 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2121 (noffset >= 0) && (ndepth > 0);
2122 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2124 /* Direct child node of the component image node */
2127 * Check subnode name, must be equal to "hash".
2128 * Multiple hash nodes require unique unit node
2129 * names, e.g. hash@1, hash@2, etc.
2131 if (strncmp (fit_get_name(fit, noffset, NULL),
2133 strlen(FIT_HASH_NODENAME)) != 0)
2136 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2137 err_msg = "Can't get hash algo property";
2140 printf ("%s", algo);
2142 if (fit_image_hash_get_value (fit, noffset, &fit_value,
2144 err_msg = "Can't get hash value property";
2148 if (calculate_hash (data, size, algo, value, &value_len)) {
2149 err_msg = "Unsupported hash algorithm";
2153 if (value_len != fit_value_len) {
2154 err_msg = "Bad hash value len";
2156 } else if (memcmp (value, fit_value, value_len) != 0) {
2157 err_msg = "Bad hash value";
2167 printf ("%s for '%s' hash node in '%s' image node\n",
2168 err_msg, fit_get_name (fit, noffset, NULL),
2169 fit_get_name (fit, image_noffset, NULL));
2174 * fit_image_check_os - check whether image node is of a given os type
2175 * @fit: pointer to the FIT format image header
2176 * @noffset: component image node offset
2177 * @os: requested image os
2179 * fit_image_check_os() reads image os property and compares its numeric
2180 * id with the requested os. Comparison result is returned to the caller.
2183 * 1 if image is of given os type
2184 * 0 otherwise (or on error)
2186 int fit_image_check_os (const void *fit, int noffset, uint8_t os)
2190 if (fit_image_get_os (fit, noffset, &image_os))
2192 return (os == image_os);
2196 * fit_image_check_arch - check whether image node is of a given arch
2197 * @fit: pointer to the FIT format image header
2198 * @noffset: component image node offset
2199 * @arch: requested imagearch
2201 * fit_image_check_arch() reads image arch property and compares its numeric
2202 * id with the requested arch. Comparison result is returned to the caller.
2205 * 1 if image is of given arch
2206 * 0 otherwise (or on error)
2208 int fit_image_check_arch (const void *fit, int noffset, uint8_t arch)
2212 if (fit_image_get_arch (fit, noffset, &image_arch))
2214 return (arch == image_arch);
2218 * fit_image_check_type - check whether image node is of a given type
2219 * @fit: pointer to the FIT format image header
2220 * @noffset: component image node offset
2221 * @type: requested image type
2223 * fit_image_check_type() reads image type property and compares its numeric
2224 * id with the requested type. Comparison result is returned to the caller.
2227 * 1 if image is of given type
2228 * 0 otherwise (or on error)
2230 int fit_image_check_type (const void *fit, int noffset, uint8_t type)
2234 if (fit_image_get_type (fit, noffset, &image_type))
2236 return (type == image_type);
2240 * fit_image_check_comp - check whether image node uses given compression
2241 * @fit: pointer to the FIT format image header
2242 * @noffset: component image node offset
2243 * @comp: requested image compression type
2245 * fit_image_check_comp() reads image compression property and compares its
2246 * numeric id with the requested compression type. Comparison result is
2247 * returned to the caller.
2250 * 1 if image uses requested compression
2251 * 0 otherwise (or on error)
2253 int fit_image_check_comp (const void *fit, int noffset, uint8_t comp)
2257 if (fit_image_get_comp (fit, noffset, &image_comp))
2259 return (comp == image_comp);
2263 * fit_check_format - sanity check FIT image format
2264 * @fit: pointer to the FIT format image header
2266 * fit_check_format() runs a basic sanity FIT image verification.
2267 * Routine checks for mandatory properties, nodes, etc.
2273 int fit_check_format (const void *fit)
2275 /* mandatory / node 'description' property */
2276 if (fdt_getprop (fit, 0, FIT_DESC_PROP, NULL) == NULL) {
2277 debug ("Wrong FIT format: no description\n");
2281 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
2282 /* mandatory / node 'timestamp' property */
2283 if (fdt_getprop (fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
2284 debug ("Wrong FIT format: no description\n");
2289 /* mandatory subimages parent '/images' node */
2290 if (fdt_path_offset (fit, FIT_IMAGES_PATH) < 0) {
2291 debug ("Wrong FIT format: no images parent node\n");
2299 * fit_conf_get_node - get node offset for configuration of a given unit name
2300 * @fit: pointer to the FIT format image header
2301 * @conf_uname: configuration node unit name
2303 * fit_conf_get_node() finds a configuration (withing the '/configurations'
2304 * parant node) of a provided unit name. If configuration is found its node offset
2305 * is returned to the caller.
2307 * When NULL is provided in second argument fit_conf_get_node() will search
2308 * for a default configuration node instead. Default configuration node unit name
2309 * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
2312 * configuration node offset when found (>=0)
2313 * negative number on failure (FDT_ERR_* code)
2315 int fit_conf_get_node (const void *fit, const char *conf_uname)
2317 int noffset, confs_noffset;
2320 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
2321 if (confs_noffset < 0) {
2322 debug ("Can't find configurations parent node '%s' (%s)\n",
2323 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
2324 return confs_noffset;
2327 if (conf_uname == NULL) {
2328 /* get configuration unit name from the default property */
2329 debug ("No configuration specified, trying default...\n");
2330 conf_uname = (char *)fdt_getprop (fit, confs_noffset, FIT_DEFAULT_PROP, &len);
2331 if (conf_uname == NULL) {
2332 fit_get_debug (fit, confs_noffset, FIT_DEFAULT_PROP, len);
2335 debug ("Found default configuration: '%s'\n", conf_uname);
2338 noffset = fdt_subnode_offset (fit, confs_noffset, conf_uname);
2340 debug ("Can't get node offset for configuration unit name: '%s' (%s)\n",
2341 conf_uname, fdt_strerror (noffset));
2347 static int __fit_conf_get_prop_node (const void *fit, int noffset,
2348 const char *prop_name)
2353 /* get kernel image unit name from configuration kernel property */
2354 uname = (char *)fdt_getprop (fit, noffset, prop_name, &len);
2358 return fit_image_get_node (fit, uname);
2362 * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
2363 * a given configuration
2364 * @fit: pointer to the FIT format image header
2365 * @noffset: configuration node offset
2367 * fit_conf_get_kernel_node() retrives kernel image node unit name from
2368 * configuration FIT_KERNEL_PROP property and translates it to the node
2372 * image node offset when found (>=0)
2373 * negative number on failure (FDT_ERR_* code)
2375 int fit_conf_get_kernel_node (const void *fit, int noffset)
2377 return __fit_conf_get_prop_node (fit, noffset, FIT_KERNEL_PROP);
2381 * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
2382 * a given configuration
2383 * @fit: pointer to the FIT format image header
2384 * @noffset: configuration node offset
2386 * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
2387 * configuration FIT_KERNEL_PROP property and translates it to the node
2391 * image node offset when found (>=0)
2392 * negative number on failure (FDT_ERR_* code)
2394 int fit_conf_get_ramdisk_node (const void *fit, int noffset)
2396 return __fit_conf_get_prop_node (fit, noffset, FIT_RAMDISK_PROP);
2400 * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
2401 * a given configuration
2402 * @fit: pointer to the FIT format image header
2403 * @noffset: configuration node offset
2405 * fit_conf_get_fdt_node() retrives fdt image node unit name from
2406 * configuration FIT_KERNEL_PROP property and translates it to the node
2410 * image node offset when found (>=0)
2411 * negative number on failure (FDT_ERR_* code)
2413 int fit_conf_get_fdt_node (const void *fit, int noffset)
2415 return __fit_conf_get_prop_node (fit, noffset, FIT_FDT_PROP);
2419 * fit_conf_print - prints out the FIT configuration details
2420 * @fit: pointer to the FIT format image header
2421 * @noffset: offset of the configuration node
2422 * @p: pointer to prefix string
2424 * fit_conf_print() lists all mandatory properies for the processed
2425 * configuration node.
2428 * no returned results
2430 void fit_conf_print (const void *fit, int noffset, const char *p)
2436 /* Mandatory properties */
2437 ret = fit_get_desc (fit, noffset, &desc);
2438 printf ("%s Description: ", p);
2440 printf ("unavailable\n");
2442 printf ("%s\n", desc);
2444 uname = (char *)fdt_getprop (fit, noffset, FIT_KERNEL_PROP, NULL);
2445 printf ("%s Kernel: ", p);
2447 printf ("unavailable\n");
2449 printf ("%s\n", uname);
2451 /* Optional properties */
2452 uname = (char *)fdt_getprop (fit, noffset, FIT_RAMDISK_PROP, NULL);
2454 printf ("%s Init Ramdisk: %s\n", p, uname);
2456 uname = (char *)fdt_getprop (fit, noffset, FIT_FDT_PROP, NULL);
2458 printf ("%s FDT: %s\n", p, uname);
2462 * fit_check_ramdisk - verify FIT format ramdisk subimage
2463 * @fit_hdr: pointer to the FIT ramdisk header
2464 * @rd_noffset: ramdisk subimage node offset within FIT image
2465 * @arch: requested ramdisk image architecture type
2466 * @verify: data CRC verification flag
2468 * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
2469 * specified FIT image.
2476 static int fit_check_ramdisk (const void *fit, int rd_noffset, uint8_t arch, int verify)
2478 fit_image_print (fit, rd_noffset, " ");
2481 puts (" Verifying Hash Integrity ... ");
2482 if (!fit_image_check_hashes (fit, rd_noffset)) {
2483 puts ("Bad Data Hash\n");
2484 show_boot_progress (-125);
2490 show_boot_progress (126);
2491 if (!fit_image_check_os (fit, rd_noffset, IH_OS_LINUX) ||
2492 !fit_image_check_arch (fit, rd_noffset, arch) ||
2493 !fit_image_check_type (fit, rd_noffset, IH_TYPE_RAMDISK)) {
2494 printf ("No Linux %s Ramdisk Image\n",
2495 genimg_get_arch_name(arch));
2496 show_boot_progress (-126);
2500 show_boot_progress (127);
2503 #endif /* USE_HOSTCC */
2504 #endif /* CONFIG_FIT */