2 * (C) Copyright 2008 Semihalf
4 * (C) Copyright 2000-2006
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 * const argv[]);
66 DECLARE_GLOBAL_DATA_PTR;
68 static const image_header_t* image_get_ramdisk (ulong rd_addr, uint8_t arch,
72 #include <u-boot/md5.h>
75 #endif /* !USE_HOSTCC*/
77 static const table_entry_t uimage_arch[] = {
78 { IH_ARCH_INVALID, NULL, "Invalid ARCH", },
79 { IH_ARCH_ALPHA, "alpha", "Alpha", },
80 { IH_ARCH_ARM, "arm", "ARM", },
81 { IH_ARCH_I386, "x86", "Intel x86", },
82 { IH_ARCH_IA64, "ia64", "IA64", },
83 { IH_ARCH_M68K, "m68k", "M68K", },
84 { IH_ARCH_MICROBLAZE, "microblaze", "MicroBlaze", },
85 { IH_ARCH_MIPS, "mips", "MIPS", },
86 { IH_ARCH_MIPS64, "mips64", "MIPS 64 Bit", },
87 { IH_ARCH_NIOS2, "nios2", "NIOS II", },
88 { IH_ARCH_PPC, "powerpc", "PowerPC", },
89 { IH_ARCH_PPC, "ppc", "PowerPC", },
90 { IH_ARCH_S390, "s390", "IBM S390", },
91 { IH_ARCH_SH, "sh", "SuperH", },
92 { IH_ARCH_SPARC, "sparc", "SPARC", },
93 { IH_ARCH_SPARC64, "sparc64", "SPARC 64 Bit", },
94 { IH_ARCH_BLACKFIN, "blackfin", "Blackfin", },
95 { IH_ARCH_AVR32, "avr32", "AVR32", },
99 static const table_entry_t uimage_os[] = {
100 { IH_OS_INVALID, NULL, "Invalid OS", },
101 { IH_OS_LINUX, "linux", "Linux", },
102 #if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC)
103 { IH_OS_LYNXOS, "lynxos", "LynxOS", },
105 { IH_OS_NETBSD, "netbsd", "NetBSD", },
106 { IH_OS_OSE, "ose", "Enea OSE", },
107 { IH_OS_RTEMS, "rtems", "RTEMS", },
108 { IH_OS_U_BOOT, "u-boot", "U-Boot", },
109 #if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC)
110 { IH_OS_QNX, "qnx", "QNX", },
111 { IH_OS_VXWORKS, "vxworks", "VxWorks", },
113 #if defined(CONFIG_INTEGRITY) || defined(USE_HOSTCC)
114 { IH_OS_INTEGRITY,"integrity", "INTEGRITY", },
117 { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", },
118 { IH_OS_DELL, "dell", "Dell", },
119 { IH_OS_ESIX, "esix", "Esix", },
120 { IH_OS_FREEBSD, "freebsd", "FreeBSD", },
121 { IH_OS_IRIX, "irix", "Irix", },
122 { IH_OS_NCR, "ncr", "NCR", },
123 { IH_OS_OPENBSD, "openbsd", "OpenBSD", },
124 { IH_OS_PSOS, "psos", "pSOS", },
125 { IH_OS_SCO, "sco", "SCO", },
126 { IH_OS_SOLARIS, "solaris", "Solaris", },
127 { IH_OS_SVR4, "svr4", "SVR4", },
132 static const table_entry_t uimage_type[] = {
133 { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", },
134 { IH_TYPE_FIRMWARE, "firmware", "Firmware", },
135 { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", },
136 { IH_TYPE_INVALID, NULL, "Invalid Image", },
137 { IH_TYPE_IMXIMAGE, "imximage", "Freescale i.MX Boot Image",},
138 { IH_TYPE_KERNEL, "kernel", "Kernel Image", },
139 { IH_TYPE_KWBIMAGE, "kwbimage", "Kirkwood Boot Image",},
140 { IH_TYPE_MULTI, "multi", "Multi-File Image", },
141 { IH_TYPE_OMAPIMAGE, "omapimage", "TI OMAP SPL With GP CH",},
142 { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", },
143 { IH_TYPE_SCRIPT, "script", "Script", },
144 { IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
145 { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", },
146 { IH_TYPE_KWBIMAGE, "kwbimage", "Kirkwood Boot Image",},
147 { IH_TYPE_IMXIMAGE, "imximage", "Freescale i.MX Boot Image",},
148 { IH_TYPE_UBLIMAGE, "ublimage", "Davinci UBL image",},
152 static const table_entry_t uimage_comp[] = {
153 { IH_COMP_NONE, "none", "uncompressed", },
154 { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", },
155 { IH_COMP_GZIP, "gzip", "gzip compressed", },
156 { IH_COMP_LZMA, "lzma", "lzma compressed", },
157 { IH_COMP_LZO, "lzo", "lzo compressed", },
161 uint32_t crc32 (uint32_t, const unsigned char *, uint);
162 uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint);
163 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
164 static void genimg_print_time (time_t timestamp);
167 /*****************************************************************************/
168 /* Legacy format routines */
169 /*****************************************************************************/
170 int image_check_hcrc (const image_header_t *hdr)
173 ulong len = image_get_header_size ();
174 image_header_t header;
176 /* Copy header so we can blank CRC field for re-calculation */
177 memmove (&header, (char *)hdr, image_get_header_size ());
178 image_set_hcrc (&header, 0);
180 hcrc = crc32 (0, (unsigned char *)&header, len);
182 return (hcrc == image_get_hcrc (hdr));
185 int image_check_dcrc (const image_header_t *hdr)
187 ulong data = image_get_data (hdr);
188 ulong len = image_get_data_size (hdr);
189 ulong dcrc = crc32_wd (0, (unsigned char *)data, len, CHUNKSZ_CRC32);
191 return (dcrc == image_get_dcrc (hdr));
195 * image_multi_count - get component (sub-image) count
196 * @hdr: pointer to the header of the multi component image
198 * image_multi_count() returns number of components in a multi
201 * Note: no checking of the image type is done, caller must pass
202 * a valid multi component image.
205 * number of components
207 ulong image_multi_count (const image_header_t *hdr)
212 /* get start of the image payload, which in case of multi
213 * component images that points to a table of component sizes */
214 size = (uint32_t *)image_get_data (hdr);
216 /* count non empty slots */
217 for (i = 0; size[i]; ++i)
224 * image_multi_getimg - get component data address and size
225 * @hdr: pointer to the header of the multi component image
226 * @idx: index of the requested component
227 * @data: pointer to a ulong variable, will hold component data address
228 * @len: pointer to a ulong variable, will hold component size
230 * image_multi_getimg() returns size and data address for the requested
231 * component in a multi component image.
233 * Note: no checking of the image type is done, caller must pass
234 * a valid multi component image.
237 * data address and size of the component, if idx is valid
238 * 0 in data and len, if idx is out of range
240 void image_multi_getimg (const image_header_t *hdr, ulong idx,
241 ulong *data, ulong *len)
245 ulong offset, count, img_data;
247 /* get number of component */
248 count = image_multi_count (hdr);
250 /* get start of the image payload, which in case of multi
251 * component images that points to a table of component sizes */
252 size = (uint32_t *)image_get_data (hdr);
254 /* get address of the proper component data start, which means
255 * skipping sizes table (add 1 for last, null entry) */
256 img_data = image_get_data (hdr) + (count + 1) * sizeof (uint32_t);
259 *len = uimage_to_cpu (size[idx]);
262 /* go over all indices preceding requested component idx */
263 for (i = 0; i < idx; i++) {
264 /* add up i-th component size, rounding up to 4 bytes */
265 offset += (uimage_to_cpu (size[i]) + 3) & ~3 ;
268 /* calculate idx-th component data address */
269 *data = img_data + offset;
276 static void image_print_type (const image_header_t *hdr)
278 const char *os, *arch, *type, *comp;
280 os = genimg_get_os_name (image_get_os (hdr));
281 arch = genimg_get_arch_name (image_get_arch (hdr));
282 type = genimg_get_type_name (image_get_type (hdr));
283 comp = genimg_get_comp_name (image_get_comp (hdr));
285 printf ("%s %s %s (%s)\n", arch, os, type, comp);
289 * image_print_contents - prints out the contents of the legacy format image
290 * @ptr: pointer to the legacy format image header
291 * @p: pointer to prefix string
293 * image_print_contents() formats a multi line legacy image contents description.
294 * The routine prints out all header fields followed by the size/offset data
295 * for MULTI/SCRIPT images.
298 * no returned results
300 void image_print_contents (const void *ptr)
302 const image_header_t *hdr = (const image_header_t *)ptr;
311 printf ("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name (hdr));
312 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
313 printf ("%sCreated: ", p);
314 genimg_print_time ((time_t)image_get_time (hdr));
316 printf ("%sImage Type: ", p);
317 image_print_type (hdr);
318 printf ("%sData Size: ", p);
319 genimg_print_size (image_get_data_size (hdr));
320 printf ("%sLoad Address: %08x\n", p, image_get_load (hdr));
321 printf ("%sEntry Point: %08x\n", p, image_get_ep (hdr));
323 if (image_check_type (hdr, IH_TYPE_MULTI) ||
324 image_check_type (hdr, IH_TYPE_SCRIPT)) {
327 ulong count = image_multi_count (hdr);
329 printf ("%sContents:\n", p);
330 for (i = 0; i < count; i++) {
331 image_multi_getimg (hdr, i, &data, &len);
333 printf ("%s Image %d: ", p, i);
334 genimg_print_size (len);
336 if (image_check_type (hdr, IH_TYPE_SCRIPT) && i > 0) {
338 * the user may need to know offsets
339 * if planning to do something with
342 printf ("%s Offset = 0x%08lx\n", p, data);
351 * image_get_ramdisk - get and verify ramdisk image
352 * @rd_addr: ramdisk image start address
353 * @arch: expected ramdisk architecture
354 * @verify: checksum verification flag
356 * image_get_ramdisk() returns a pointer to the verified ramdisk image
357 * header. Routine receives image start address and expected architecture
358 * flag. Verification done covers data and header integrity and os/type/arch
361 * If dataflash support is enabled routine checks for dataflash addresses
362 * and handles required dataflash reads.
365 * pointer to a ramdisk image header, if image was found and valid
366 * otherwise, return NULL
368 static const image_header_t *image_get_ramdisk (ulong rd_addr, uint8_t arch,
371 const image_header_t *rd_hdr = (const image_header_t *)rd_addr;
373 if (!image_check_magic (rd_hdr)) {
374 puts ("Bad Magic Number\n");
375 show_boot_progress (-10);
379 if (!image_check_hcrc (rd_hdr)) {
380 puts ("Bad Header Checksum\n");
381 show_boot_progress (-11);
385 show_boot_progress (10);
386 image_print_contents (rd_hdr);
389 puts(" Verifying Checksum ... ");
390 if (!image_check_dcrc (rd_hdr)) {
391 puts ("Bad Data CRC\n");
392 show_boot_progress (-12);
398 show_boot_progress (11);
400 if (!image_check_os (rd_hdr, IH_OS_LINUX) ||
401 !image_check_arch (rd_hdr, arch) ||
402 !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) {
403 printf ("No Linux %s Ramdisk Image\n",
404 genimg_get_arch_name(arch));
405 show_boot_progress (-13);
411 #endif /* !USE_HOSTCC */
413 /*****************************************************************************/
414 /* Shared dual-format routines */
415 /*****************************************************************************/
417 int getenv_yesno (char *var)
419 char *s = getenv (var);
420 return (s && (*s == 'n')) ? 0 : 1;
423 ulong getenv_bootm_low(void)
425 char *s = getenv ("bootm_low");
427 ulong tmp = simple_strtoul (s, NULL, 16);
431 #if defined(CONFIG_SYS_SDRAM_BASE)
432 return CONFIG_SYS_SDRAM_BASE;
433 #elif defined(CONFIG_ARM)
434 return gd->bd->bi_dram[0].start;
440 phys_size_t getenv_bootm_size(void)
443 char *s = getenv ("bootm_size");
445 tmp = (phys_size_t)simple_strtoull (s, NULL, 16);
448 s = getenv("bootm_low");
450 tmp = (phys_size_t)simple_strtoull (s, NULL, 16);
455 #if defined(CONFIG_ARM)
456 return gd->bd->bi_dram[0].size - tmp;
458 return gd->bd->bi_memsize - tmp;
462 phys_size_t getenv_bootm_mapsize(void)
465 char *s = getenv ("bootm_mapsize");
467 tmp = (phys_size_t)simple_strtoull (s, NULL, 16);
471 #if defined(CONFIG_SYS_BOOTMAPSZ)
472 return CONFIG_SYS_BOOTMAPSZ;
474 return getenv_bootm_size();
478 void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
483 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
485 size_t tail = (len > chunksz) ? chunksz : len;
487 memmove (to, from, tail);
492 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
493 memmove (to, from, len);
494 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
496 #endif /* !USE_HOSTCC */
498 void genimg_print_size (uint32_t size)
501 printf ("%d Bytes = ", size);
502 print_size (size, "\n");
504 printf ("%d Bytes = %.2f kB = %.2f MB\n",
505 size, (double)size / 1.024e3,
506 (double)size / 1.048576e6);
510 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
511 static void genimg_print_time (time_t timestamp)
516 to_tm (timestamp, &tm);
517 printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
518 tm.tm_year, tm.tm_mon, tm.tm_mday,
519 tm.tm_hour, tm.tm_min, tm.tm_sec);
521 printf ("%s", ctime(×tamp));
524 #endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */
527 * get_table_entry_name - translate entry id to long name
528 * @table: pointer to a translation table for entries of a specific type
529 * @msg: message to be returned when translation fails
530 * @id: entry id to be translated
532 * get_table_entry_name() will go over translation table trying to find
533 * entry that matches given id. If matching entry is found, its long
534 * name is returned to the caller.
537 * long entry name if translation succeeds
540 char *get_table_entry_name(const table_entry_t *table, char *msg, int id)
542 for (; table->id >= 0; ++table) {
544 #if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
547 return table->lname + gd->reloc_off;
553 const char *genimg_get_os_name (uint8_t os)
555 return (get_table_entry_name (uimage_os, "Unknown OS", os));
558 const char *genimg_get_arch_name (uint8_t arch)
560 return (get_table_entry_name (uimage_arch, "Unknown Architecture", arch));
563 const char *genimg_get_type_name (uint8_t type)
565 return (get_table_entry_name (uimage_type, "Unknown Image", type));
568 const char *genimg_get_comp_name (uint8_t comp)
570 return (get_table_entry_name (uimage_comp, "Unknown Compression", comp));
574 * get_table_entry_id - translate short entry name to id
575 * @table: pointer to a translation table for entries of a specific type
576 * @table_name: to be used in case of error
577 * @name: entry short name to be translated
579 * get_table_entry_id() will go over translation table trying to find
580 * entry that matches given short name. If matching entry is found,
581 * its id returned to the caller.
584 * entry id if translation succeeds
587 int get_table_entry_id(const table_entry_t *table,
588 const char *table_name, const char *name)
590 const table_entry_t *t;
594 for (t = table; t->id >= 0; ++t) {
595 if (t->sname && strcasecmp(t->sname, name) == 0)
599 fprintf (stderr, "\nInvalid %s Type - valid names are", table_name);
600 for (t = table; t->id >= 0; ++t) {
601 if (t->sname == NULL)
603 fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname);
606 fprintf (stderr, "\n");
608 for (t = table; t->id >= 0; ++t) {
609 #ifdef CONFIG_NEEDS_MANUAL_RELOC
610 if (t->sname && strcmp(t->sname + gd->reloc_off, name) == 0)
612 if (t->sname && strcmp(t->sname, name) == 0)
616 debug ("Invalid %s Type: %s\n", table_name, name);
617 #endif /* USE_HOSTCC */
621 int genimg_get_os_id (const char *name)
623 return (get_table_entry_id (uimage_os, "OS", name));
626 int genimg_get_arch_id (const char *name)
628 return (get_table_entry_id (uimage_arch, "CPU", name));
631 int genimg_get_type_id (const char *name)
633 return (get_table_entry_id (uimage_type, "Image", name));
636 int genimg_get_comp_id (const char *name)
638 return (get_table_entry_id (uimage_comp, "Compression", name));
643 * genimg_get_format - get image format type
644 * @img_addr: image start address
646 * genimg_get_format() checks whether provided address points to a valid
647 * legacy or FIT image.
649 * New uImage format and FDT blob are based on a libfdt. FDT blob
650 * may be passed directly or embedded in a FIT image. In both situations
651 * genimg_get_format() must be able to dectect libfdt header.
654 * image format type or IMAGE_FORMAT_INVALID if no image is present
656 int genimg_get_format (void *img_addr)
658 ulong format = IMAGE_FORMAT_INVALID;
659 const image_header_t *hdr;
660 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
664 hdr = (const image_header_t *)img_addr;
665 if (image_check_magic(hdr))
666 format = IMAGE_FORMAT_LEGACY;
667 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
669 fit_hdr = (char *)img_addr;
670 if (fdt_check_header (fit_hdr) == 0)
671 format = IMAGE_FORMAT_FIT;
679 * genimg_get_image - get image from special storage (if necessary)
680 * @img_addr: image start address
682 * genimg_get_image() checks if provided image start adddress is located
683 * in a dataflash storage. If so, image is moved to a system RAM memory.
686 * image start address after possible relocation from special storage
688 ulong genimg_get_image (ulong img_addr)
690 ulong ram_addr = img_addr;
692 #ifdef CONFIG_HAS_DATAFLASH
693 ulong h_size, d_size;
695 if (addr_dataflash (img_addr)){
696 /* ger RAM address */
697 ram_addr = CONFIG_SYS_LOAD_ADDR;
699 /* get header size */
700 h_size = image_get_header_size ();
701 #if defined(CONFIG_FIT)
702 if (sizeof(struct fdt_header) > h_size)
703 h_size = sizeof(struct fdt_header);
707 debug (" Reading image header from dataflash address "
708 "%08lx to RAM address %08lx\n", img_addr, ram_addr);
710 read_dataflash (img_addr, h_size, (char *)ram_addr);
713 switch (genimg_get_format ((void *)ram_addr)) {
714 case IMAGE_FORMAT_LEGACY:
715 d_size = image_get_data_size ((const image_header_t *)ram_addr);
716 debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n",
719 #if defined(CONFIG_FIT)
720 case IMAGE_FORMAT_FIT:
721 d_size = fit_get_size ((const void *)ram_addr) - h_size;
722 debug (" FIT/FDT format image found at 0x%08lx, size 0x%08lx\n",
727 printf (" No valid image found at 0x%08lx\n", img_addr);
731 /* read in image data */
732 debug (" Reading image remaining data from dataflash address "
733 "%08lx to RAM address %08lx\n", img_addr + h_size,
736 read_dataflash (img_addr + h_size, d_size,
737 (char *)(ram_addr + h_size));
740 #endif /* CONFIG_HAS_DATAFLASH */
746 * fit_has_config - check if there is a valid FIT configuration
747 * @images: pointer to the bootm command headers structure
749 * fit_has_config() checks if there is a FIT configuration in use
750 * (if FTI support is present).
753 * 0, no FIT support or no configuration found
754 * 1, configuration found
756 int genimg_has_config (bootm_headers_t *images)
758 #if defined(CONFIG_FIT)
759 if (images->fit_uname_cfg)
766 * boot_get_ramdisk - main ramdisk handling routine
767 * @argc: command argument count
768 * @argv: command argument list
769 * @images: pointer to the bootm images structure
770 * @arch: expected ramdisk architecture
771 * @rd_start: pointer to a ulong variable, will hold ramdisk start address
772 * @rd_end: pointer to a ulong variable, will hold ramdisk end
774 * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
775 * Curently supported are the following ramdisk sources:
776 * - multicomponent kernel/ramdisk image,
777 * - commandline provided address of decicated ramdisk image.
780 * 0, if ramdisk image was found and valid, or skiped
781 * rd_start and rd_end are set to ramdisk start/end addresses if
782 * ramdisk image is found and valid
784 * 1, if ramdisk image is found but corrupted, or invalid
785 * rd_start and rd_end are set to 0 if no ramdisk exists
787 int boot_get_ramdisk (int argc, char * const argv[], bootm_headers_t *images,
788 uint8_t arch, ulong *rd_start, ulong *rd_end)
790 ulong rd_addr, rd_load;
791 ulong rd_data, rd_len;
792 const image_header_t *rd_hdr;
793 #if defined(CONFIG_FIT)
795 const char *fit_uname_config = NULL;
796 const char *fit_uname_ramdisk = NULL;
808 * Look for a '-' which indicates to ignore the
811 if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) {
812 debug ("## Skipping init Ramdisk\n");
813 rd_len = rd_data = 0;
814 } else if (argc >= 3 || genimg_has_config (images)) {
815 #if defined(CONFIG_FIT)
818 * If the init ramdisk comes from the FIT image and
819 * the FIT image address is omitted in the command
820 * line argument, try to use os FIT image address or
821 * default load address.
823 if (images->fit_uname_os)
824 default_addr = (ulong)images->fit_hdr_os;
826 default_addr = load_addr;
828 if (fit_parse_conf (argv[2], default_addr,
829 &rd_addr, &fit_uname_config)) {
830 debug ("* ramdisk: config '%s' from image at 0x%08lx\n",
831 fit_uname_config, rd_addr);
832 } else if (fit_parse_subimage (argv[2], default_addr,
833 &rd_addr, &fit_uname_ramdisk)) {
834 debug ("* ramdisk: subimage '%s' from image at 0x%08lx\n",
835 fit_uname_ramdisk, rd_addr);
839 rd_addr = simple_strtoul(argv[2], NULL, 16);
840 debug ("* ramdisk: cmdline image address = 0x%08lx\n",
843 #if defined(CONFIG_FIT)
845 /* use FIT configuration provided in first bootm
848 rd_addr = (ulong)images->fit_hdr_os;
849 fit_uname_config = images->fit_uname_cfg;
850 debug ("* ramdisk: using config '%s' from image at 0x%08lx\n",
851 fit_uname_config, rd_addr);
854 * Check whether configuration has ramdisk defined,
855 * if not, don't try to use it, quit silently.
857 fit_hdr = (void *)rd_addr;
858 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
859 if (cfg_noffset < 0) {
860 debug ("* ramdisk: no such config\n");
864 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
865 if (rd_noffset < 0) {
866 debug ("* ramdisk: no ramdisk in config\n");
872 /* copy from dataflash if needed */
873 rd_addr = genimg_get_image (rd_addr);
876 * Check if there is an initrd image at the
877 * address provided in the second bootm argument
878 * check image type, for FIT images get FIT node.
880 switch (genimg_get_format ((void *)rd_addr)) {
881 case IMAGE_FORMAT_LEGACY:
882 printf ("## Loading init Ramdisk from Legacy "
883 "Image at %08lx ...\n", rd_addr);
885 show_boot_progress (9);
886 rd_hdr = image_get_ramdisk (rd_addr, arch,
892 rd_data = image_get_data (rd_hdr);
893 rd_len = image_get_data_size (rd_hdr);
894 rd_load = image_get_load (rd_hdr);
896 #if defined(CONFIG_FIT)
897 case IMAGE_FORMAT_FIT:
898 fit_hdr = (void *)rd_addr;
899 printf ("## Loading init Ramdisk from FIT "
900 "Image at %08lx ...\n", rd_addr);
902 show_boot_progress (120);
903 if (!fit_check_format (fit_hdr)) {
904 puts ("Bad FIT ramdisk image format!\n");
905 show_boot_progress (-120);
908 show_boot_progress (121);
910 if (!fit_uname_ramdisk) {
912 * no ramdisk image node unit name, try to get config
913 * node first. If config unit node name is NULL
914 * fit_conf_get_node() will try to find default config node
916 show_boot_progress (122);
917 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
918 if (cfg_noffset < 0) {
919 puts ("Could not find configuration node\n");
920 show_boot_progress (-122);
923 fit_uname_config = fdt_get_name (fit_hdr, cfg_noffset, NULL);
924 printf (" Using '%s' configuration\n", fit_uname_config);
926 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
927 fit_uname_ramdisk = fit_get_name (fit_hdr, rd_noffset, NULL);
929 /* get ramdisk component image node offset */
930 show_boot_progress (123);
931 rd_noffset = fit_image_get_node (fit_hdr, fit_uname_ramdisk);
933 if (rd_noffset < 0) {
934 puts ("Could not find subimage node\n");
935 show_boot_progress (-124);
939 printf (" Trying '%s' ramdisk subimage\n", fit_uname_ramdisk);
941 show_boot_progress (125);
942 if (!fit_check_ramdisk (fit_hdr, rd_noffset, arch, images->verify))
945 /* get ramdisk image data address and length */
946 if (fit_image_get_data (fit_hdr, rd_noffset, &data, &size)) {
947 puts ("Could not find ramdisk subimage data!\n");
948 show_boot_progress (-127);
951 show_boot_progress (128);
953 rd_data = (ulong)data;
956 if (fit_image_get_load (fit_hdr, rd_noffset, &rd_load)) {
957 puts ("Can't get ramdisk subimage load address!\n");
958 show_boot_progress (-129);
961 show_boot_progress (129);
963 images->fit_hdr_rd = fit_hdr;
964 images->fit_uname_rd = fit_uname_ramdisk;
965 images->fit_noffset_rd = rd_noffset;
969 puts ("Wrong Ramdisk Image Format\n");
970 rd_data = rd_len = rd_load = 0;
973 } else if (images->legacy_hdr_valid &&
974 image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
976 * Now check if we have a legacy mult-component image,
977 * get second entry data start address and len.
979 show_boot_progress (13);
980 printf ("## Loading init Ramdisk from multi component "
981 "Legacy Image at %08lx ...\n",
982 (ulong)images->legacy_hdr_os);
984 image_multi_getimg (images->legacy_hdr_os, 1, &rd_data, &rd_len);
989 show_boot_progress (14);
990 rd_len = rd_data = 0;
994 debug ("## No init Ramdisk\n");
997 *rd_end = rd_data + rd_len;
999 debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
1000 *rd_start, *rd_end);
1005 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
1007 * boot_ramdisk_high - relocate init ramdisk
1008 * @lmb: pointer to lmb handle, will be used for memory mgmt
1009 * @rd_data: ramdisk data start address
1010 * @rd_len: ramdisk data length
1011 * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
1012 * start address (after possible relocation)
1013 * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
1014 * end address (after possible relocation)
1016 * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
1017 * variable and if requested ramdisk data is moved to a specified location.
1019 * Initrd_start and initrd_end are set to final (after relocation) ramdisk
1020 * start/end addresses if ramdisk image start and len were provided,
1021 * otherwise set initrd_start and initrd_end set to zeros.
1027 int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
1028 ulong *initrd_start, ulong *initrd_end)
1032 int initrd_copy_to_ram = 1;
1034 if ((s = getenv ("initrd_high")) != NULL) {
1035 /* a value of "no" or a similar string will act like 0,
1036 * turning the "load high" feature off. This is intentional.
1038 initrd_high = simple_strtoul (s, NULL, 16);
1039 if (initrd_high == ~0)
1040 initrd_copy_to_ram = 0;
1042 /* not set, no restrictions to load high */
1047 #ifdef CONFIG_LOGBUFFER
1048 /* Prevent initrd from overwriting logbuffer */
1049 lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
1052 debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
1053 initrd_high, initrd_copy_to_ram);
1056 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
1057 debug (" in-place initrd\n");
1058 *initrd_start = rd_data;
1059 *initrd_end = rd_data + rd_len;
1060 lmb_reserve(lmb, rd_data, rd_len);
1063 *initrd_start = (ulong)lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
1065 *initrd_start = (ulong)lmb_alloc (lmb, rd_len, 0x1000);
1067 if (*initrd_start == 0) {
1068 puts ("ramdisk - allocation error\n");
1071 show_boot_progress (12);
1073 *initrd_end = *initrd_start + rd_len;
1074 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
1075 *initrd_start, *initrd_end);
1077 memmove_wd ((void *)*initrd_start,
1078 (void *)rd_data, rd_len, CHUNKSZ);
1086 debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
1087 *initrd_start, *initrd_end);
1094 #endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */
1096 #ifdef CONFIG_OF_LIBFDT
1097 static void fdt_error (const char *msg)
1101 puts (" - must RESET the board to recover.\n");
1104 static const image_header_t *image_get_fdt (ulong fdt_addr)
1106 const image_header_t *fdt_hdr = (const image_header_t *)fdt_addr;
1108 image_print_contents (fdt_hdr);
1110 puts (" Verifying Checksum ... ");
1111 if (!image_check_hcrc (fdt_hdr)) {
1112 fdt_error ("fdt header checksum invalid");
1116 if (!image_check_dcrc (fdt_hdr)) {
1117 fdt_error ("fdt checksum invalid");
1122 if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) {
1123 fdt_error ("uImage is not a fdt");
1126 if (image_get_comp (fdt_hdr) != IH_COMP_NONE) {
1127 fdt_error ("uImage is compressed");
1130 if (fdt_check_header ((char *)image_get_data (fdt_hdr)) != 0) {
1131 fdt_error ("uImage data is not a fdt");
1138 * fit_check_fdt - verify FIT format FDT subimage
1139 * @fit_hdr: pointer to the FIT header
1140 * fdt_noffset: FDT subimage node offset within FIT image
1141 * @verify: data CRC verification flag
1143 * fit_check_fdt() verifies integrity of the FDT subimage and from
1144 * specified FIT image.
1150 #if defined(CONFIG_FIT)
1151 static int fit_check_fdt (const void *fit, int fdt_noffset, int verify)
1153 fit_image_print (fit, fdt_noffset, " ");
1156 puts (" Verifying Hash Integrity ... ");
1157 if (!fit_image_check_hashes (fit, fdt_noffset)) {
1158 fdt_error ("Bad Data Hash");
1164 if (!fit_image_check_type (fit, fdt_noffset, IH_TYPE_FLATDT)) {
1165 fdt_error ("Not a FDT image");
1169 if (!fit_image_check_comp (fit, fdt_noffset, IH_COMP_NONE)) {
1170 fdt_error ("FDT image is compressed");
1176 #endif /* CONFIG_FIT */
1178 #ifndef CONFIG_SYS_FDT_PAD
1179 #define CONFIG_SYS_FDT_PAD 0x3000
1182 #if defined(CONFIG_OF_LIBFDT)
1184 * boot_fdt_add_mem_rsv_regions - Mark the memreserve sections as unusable
1185 * @lmb: pointer to lmb handle, will be used for memory mgmt
1186 * @fdt_blob: pointer to fdt blob base address
1188 * Adds the memreserve regions in the dtb to the lmb block. Adding the
1189 * memreserve regions prevents u-boot from using them to store the initrd
1192 void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob)
1194 uint64_t addr, size;
1197 if (fdt_check_header (fdt_blob) != 0)
1200 total = fdt_num_mem_rsv(fdt_blob);
1201 for (i = 0; i < total; i++) {
1202 if (fdt_get_mem_rsv(fdt_blob, i, &addr, &size) != 0)
1204 printf(" reserving fdt memory region: addr=%llx size=%llx\n",
1205 (unsigned long long)addr, (unsigned long long)size);
1206 lmb_reserve(lmb, addr, size);
1211 * boot_relocate_fdt - relocate flat device tree
1212 * @lmb: pointer to lmb handle, will be used for memory mgmt
1213 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1214 * @of_size: pointer to a ulong variable, will hold fdt length
1216 * boot_relocate_fdt() allocates a region of memory within the bootmap and
1217 * relocates the of_flat_tree into that region, even if the fdt is already in
1218 * the bootmap. It also expands the size of the fdt by CONFIG_SYS_FDT_PAD
1221 * of_flat_tree and of_size are set to final (after relocation) values
1227 int boot_relocate_fdt (struct lmb *lmb, char **of_flat_tree, ulong *of_size)
1229 void *fdt_blob = *of_flat_tree;
1234 int disable_relocation = 0;
1240 if (fdt_check_header (fdt_blob) != 0) {
1241 fdt_error ("image is not a fdt");
1245 /* position on a 4K boundary before the alloc_current */
1246 /* Pad the FDT by a specified amount */
1247 of_len = *of_size + CONFIG_SYS_FDT_PAD;
1249 /* If fdt_high is set use it to select the relocation address */
1250 fdt_high = getenv("fdt_high");
1252 void *desired_addr = (void *)simple_strtoul(fdt_high, NULL, 16);
1254 if (((ulong) desired_addr) == ~0UL) {
1255 /* All ones means use fdt in place */
1256 desired_addr = fdt_blob;
1257 disable_relocation = 1;
1261 (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
1265 if (desired_addr && of_start != desired_addr) {
1266 puts("Failed using fdt_high value for Device Tree");
1271 (void *)(ulong) lmb_alloc(lmb, of_len, 0x1000);
1275 (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
1276 getenv_bootm_mapsize()
1277 + getenv_bootm_low());
1280 if (of_start == 0) {
1281 puts("device tree - allocation error\n");
1285 if (disable_relocation) {
1286 /* We assume there is space after the existing fdt to use for padding */
1287 fdt_set_totalsize(of_start, of_len);
1288 printf(" Using Device Tree in place at %p, end %p\n",
1289 of_start, of_start + of_len - 1);
1291 debug ("## device tree at %p ... %p (len=%ld [0x%lX])\n",
1292 fdt_blob, fdt_blob + *of_size - 1, of_len, of_len);
1294 printf (" Loading Device Tree to %p, end %p ... ",
1295 of_start, of_start + of_len - 1);
1297 err = fdt_open_into (fdt_blob, of_start, of_len);
1299 fdt_error ("fdt move failed");
1305 *of_flat_tree = of_start;
1308 set_working_fdt_addr(*of_flat_tree);
1314 #endif /* CONFIG_OF_LIBFDT */
1317 * boot_get_fdt - main fdt handling routine
1318 * @argc: command argument count
1319 * @argv: command argument list
1320 * @images: pointer to the bootm images structure
1321 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1322 * @of_size: pointer to a ulong variable, will hold fdt length
1324 * boot_get_fdt() is responsible for finding a valid flat device tree image.
1325 * Curently supported are the following ramdisk sources:
1326 * - multicomponent kernel/ramdisk image,
1327 * - commandline provided address of decicated ramdisk image.
1330 * 0, if fdt image was found and valid, or skipped
1331 * of_flat_tree and of_size are set to fdt start address and length if
1332 * fdt image is found and valid
1334 * 1, if fdt image is found but corrupted
1335 * of_flat_tree and of_size are set to 0 if no fdt exists
1337 int boot_get_fdt (int flag, int argc, char * const argv[], bootm_headers_t *images,
1338 char **of_flat_tree, ulong *of_size)
1340 const image_header_t *fdt_hdr;
1342 char *fdt_blob = NULL;
1343 ulong image_start, image_end;
1344 ulong load_start, load_end;
1345 #if defined(CONFIG_FIT)
1347 const char *fit_uname_config = NULL;
1348 const char *fit_uname_fdt = NULL;
1356 *of_flat_tree = NULL;
1359 if (argc > 3 || genimg_has_config (images)) {
1360 #if defined(CONFIG_FIT)
1363 * If the FDT blob comes from the FIT image and the
1364 * FIT image address is omitted in the command line
1365 * argument, try to use ramdisk or os FIT image
1366 * address or default load address.
1368 if (images->fit_uname_rd)
1369 default_addr = (ulong)images->fit_hdr_rd;
1370 else if (images->fit_uname_os)
1371 default_addr = (ulong)images->fit_hdr_os;
1373 default_addr = load_addr;
1375 if (fit_parse_conf (argv[3], default_addr,
1376 &fdt_addr, &fit_uname_config)) {
1377 debug ("* fdt: config '%s' from image at 0x%08lx\n",
1378 fit_uname_config, fdt_addr);
1379 } else if (fit_parse_subimage (argv[3], default_addr,
1380 &fdt_addr, &fit_uname_fdt)) {
1381 debug ("* fdt: subimage '%s' from image at 0x%08lx\n",
1382 fit_uname_fdt, fdt_addr);
1386 fdt_addr = simple_strtoul(argv[3], NULL, 16);
1387 debug ("* fdt: cmdline image address = 0x%08lx\n",
1390 #if defined(CONFIG_FIT)
1392 /* use FIT configuration provided in first bootm
1395 fdt_addr = (ulong)images->fit_hdr_os;
1396 fit_uname_config = images->fit_uname_cfg;
1397 debug ("* fdt: using config '%s' from image at 0x%08lx\n",
1398 fit_uname_config, fdt_addr);
1401 * Check whether configuration has FDT blob defined,
1402 * if not quit silently.
1404 fit_hdr = (void *)fdt_addr;
1405 cfg_noffset = fit_conf_get_node (fit_hdr,
1407 if (cfg_noffset < 0) {
1408 debug ("* fdt: no such config\n");
1412 fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
1414 if (fdt_noffset < 0) {
1415 debug ("* fdt: no fdt in config\n");
1421 debug ("## Checking for 'FDT'/'FDT Image' at %08lx\n",
1424 /* copy from dataflash if needed */
1425 fdt_addr = genimg_get_image (fdt_addr);
1428 * Check if there is an FDT image at the
1429 * address provided in the second bootm argument
1430 * check image type, for FIT images get a FIT node.
1432 switch (genimg_get_format ((void *)fdt_addr)) {
1433 case IMAGE_FORMAT_LEGACY:
1434 /* verify fdt_addr points to a valid image header */
1435 printf ("## Flattened Device Tree from Legacy Image at %08lx\n",
1437 fdt_hdr = image_get_fdt (fdt_addr);
1442 * move image data to the load address,
1443 * make sure we don't overwrite initial image
1445 image_start = (ulong)fdt_hdr;
1446 image_end = image_get_image_end (fdt_hdr);
1448 load_start = image_get_load (fdt_hdr);
1449 load_end = load_start + image_get_data_size (fdt_hdr);
1451 if ((load_start < image_end) && (load_end > image_start)) {
1452 fdt_error ("fdt overwritten");
1456 debug (" Loading FDT from 0x%08lx to 0x%08lx\n",
1457 image_get_data (fdt_hdr), load_start);
1459 memmove ((void *)load_start,
1460 (void *)image_get_data (fdt_hdr),
1461 image_get_data_size (fdt_hdr));
1463 fdt_blob = (char *)load_start;
1465 case IMAGE_FORMAT_FIT:
1467 * This case will catch both: new uImage format
1468 * (libfdt based) and raw FDT blob (also libfdt
1471 #if defined(CONFIG_FIT)
1472 /* check FDT blob vs FIT blob */
1473 if (fit_check_format ((const void *)fdt_addr)) {
1477 fit_hdr = (void *)fdt_addr;
1478 printf ("## Flattened Device Tree from FIT Image at %08lx\n",
1481 if (!fit_uname_fdt) {
1483 * no FDT blob image node unit name,
1484 * try to get config node first. If
1485 * config unit node name is NULL
1486 * fit_conf_get_node() will try to
1487 * find default config node
1489 cfg_noffset = fit_conf_get_node (fit_hdr,
1492 if (cfg_noffset < 0) {
1493 fdt_error ("Could not find configuration node\n");
1497 fit_uname_config = fdt_get_name (fit_hdr,
1499 printf (" Using '%s' configuration\n",
1502 fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
1504 fit_uname_fdt = fit_get_name (fit_hdr,
1507 /* get FDT component image node offset */
1508 fdt_noffset = fit_image_get_node (fit_hdr,
1511 if (fdt_noffset < 0) {
1512 fdt_error ("Could not find subimage node\n");
1516 printf (" Trying '%s' FDT blob subimage\n",
1519 if (!fit_check_fdt (fit_hdr, fdt_noffset,
1523 /* get ramdisk image data address and length */
1524 if (fit_image_get_data (fit_hdr, fdt_noffset,
1526 fdt_error ("Could not find FDT subimage data");
1530 /* verift that image data is a proper FDT blob */
1531 if (fdt_check_header ((char *)data) != 0) {
1532 fdt_error ("Subimage data is not a FTD");
1537 * move image data to the load address,
1538 * make sure we don't overwrite initial image
1540 image_start = (ulong)fit_hdr;
1541 image_end = fit_get_end (fit_hdr);
1543 if (fit_image_get_load (fit_hdr, fdt_noffset,
1544 &load_start) == 0) {
1545 load_end = load_start + size;
1547 if ((load_start < image_end) &&
1548 (load_end > image_start)) {
1549 fdt_error ("FDT overwritten");
1553 printf (" Loading FDT from 0x%08lx to 0x%08lx\n",
1554 (ulong)data, load_start);
1556 memmove ((void *)load_start,
1557 (void *)data, size);
1559 fdt_blob = (char *)load_start;
1561 fdt_blob = (char *)data;
1564 images->fit_hdr_fdt = fit_hdr;
1565 images->fit_uname_fdt = fit_uname_fdt;
1566 images->fit_noffset_fdt = fdt_noffset;
1574 fdt_blob = (char *)fdt_addr;
1575 debug ("* fdt: raw FDT blob\n");
1576 printf ("## Flattened Device Tree blob at %08lx\n", (long)fdt_blob);
1580 puts ("ERROR: Did not find a cmdline Flattened Device Tree\n");
1584 printf (" Booting using the fdt blob at 0x%x\n", (int)fdt_blob);
1586 } else if (images->legacy_hdr_valid &&
1587 image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1589 ulong fdt_data, fdt_len;
1592 * Now check if we have a legacy multi-component image,
1593 * get second entry data start address and len.
1595 printf ("## Flattened Device Tree from multi "
1596 "component Image at %08lX\n",
1597 (ulong)images->legacy_hdr_os);
1599 image_multi_getimg (images->legacy_hdr_os, 2, &fdt_data, &fdt_len);
1602 fdt_blob = (char *)fdt_data;
1603 printf (" Booting using the fdt at 0x%x\n", (int)fdt_blob);
1605 if (fdt_check_header (fdt_blob) != 0) {
1606 fdt_error ("image is not a fdt");
1610 if (fdt_totalsize(fdt_blob) != fdt_len) {
1611 fdt_error ("fdt size != image size");
1615 debug ("## No Flattened Device Tree\n");
1619 debug ("## No Flattened Device Tree\n");
1623 *of_flat_tree = fdt_blob;
1624 *of_size = fdt_totalsize(fdt_blob);
1625 debug (" of_flat_tree at 0x%08lx size 0x%08lx\n",
1626 (ulong)*of_flat_tree, *of_size);
1635 #endif /* CONFIG_OF_LIBFDT */
1637 #ifdef CONFIG_SYS_BOOT_GET_CMDLINE
1639 * boot_get_cmdline - allocate and initialize kernel cmdline
1640 * @lmb: pointer to lmb handle, will be used for memory mgmt
1641 * @cmd_start: pointer to a ulong variable, will hold cmdline start
1642 * @cmd_end: pointer to a ulong variable, will hold cmdline end
1644 * boot_get_cmdline() allocates space for kernel command line below
1645 * BOOTMAPSZ + getenv_bootm_low() address. If "bootargs" U-boot environemnt
1646 * variable is present its contents is copied to allocated kernel
1653 int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end)
1658 cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf,
1659 getenv_bootm_mapsize() + getenv_bootm_low());
1661 if (cmdline == NULL)
1664 if ((s = getenv("bootargs")) == NULL)
1669 *cmd_start = (ulong) & cmdline[0];
1670 *cmd_end = *cmd_start + strlen(cmdline);
1672 debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
1676 #endif /* CONFIG_SYS_BOOT_GET_CMDLINE */
1678 #ifdef CONFIG_SYS_BOOT_GET_KBD
1680 * boot_get_kbd - allocate and initialize kernel copy of board info
1681 * @lmb: pointer to lmb handle, will be used for memory mgmt
1682 * @kbd: double pointer to board info data
1684 * boot_get_kbd() allocates space for kernel copy of board info data below
1685 * BOOTMAPSZ + getenv_bootm_low() address and kernel board info is initialized
1686 * with the current u-boot board info data.
1692 int boot_get_kbd (struct lmb *lmb, bd_t **kbd)
1694 *kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
1695 getenv_bootm_mapsize() + getenv_bootm_low());
1701 debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
1703 #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
1704 do_bdinfo(NULL, 0, 0, NULL);
1709 #endif /* CONFIG_SYS_BOOT_GET_KBD */
1710 #endif /* !USE_HOSTCC */
1712 #if defined(CONFIG_FIT)
1713 /*****************************************************************************/
1714 /* New uImage format routines */
1715 /*****************************************************************************/
1717 static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr,
1718 ulong *addr, const char **name)
1725 sep = strchr (spec, sepc);
1728 *addr = simple_strtoul (spec, NULL, 16);
1738 * fit_parse_conf - parse FIT configuration spec
1739 * @spec: input string, containing configuration spec
1740 * @add_curr: current image address (to be used as a possible default)
1741 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1743 * @conf_name double pointer to a char, will hold pointer to a configuration
1746 * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
1747 * where <addr> is a FIT image address that contains configuration
1748 * with a <conf> unit name.
1750 * Address part is optional, and if omitted default add_curr will
1754 * 1 if spec is a valid configuration string,
1755 * addr and conf_name are set accordingly
1758 inline int fit_parse_conf (const char *spec, ulong addr_curr,
1759 ulong *addr, const char **conf_name)
1761 return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
1765 * fit_parse_subimage - parse FIT subimage spec
1766 * @spec: input string, containing subimage spec
1767 * @add_curr: current image address (to be used as a possible default)
1768 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1770 * @image_name: double pointer to a char, will hold pointer to a subimage name
1772 * fit_parse_subimage() expects subimage spec in the for of
1773 * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
1774 * subimage with a <subimg> unit name.
1776 * Address part is optional, and if omitted default add_curr will
1780 * 1 if spec is a valid subimage string,
1781 * addr and image_name are set accordingly
1784 inline int fit_parse_subimage (const char *spec, ulong addr_curr,
1785 ulong *addr, const char **image_name)
1787 return fit_parse_spec (spec, ':', addr_curr, addr, image_name);
1789 #endif /* !USE_HOSTCC */
1791 static void fit_get_debug (const void *fit, int noffset,
1792 char *prop_name, int err)
1794 debug ("Can't get '%s' property from FIT 0x%08lx, "
1795 "node: offset %d, name %s (%s)\n",
1796 prop_name, (ulong)fit, noffset,
1797 fit_get_name (fit, noffset, NULL),
1798 fdt_strerror (err));
1802 * fit_print_contents - prints out the contents of the FIT format image
1803 * @fit: pointer to the FIT format image header
1804 * @p: pointer to prefix string
1806 * fit_print_contents() formats a multi line FIT image contents description.
1807 * The routine prints out FIT image properties (root node level) follwed by
1808 * the details of each component image.
1811 * no returned results
1813 void fit_print_contents (const void *fit)
1824 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1834 /* Root node properties */
1835 ret = fit_get_desc (fit, 0, &desc);
1836 printf ("%sFIT description: ", p);
1838 printf ("unavailable\n");
1840 printf ("%s\n", desc);
1842 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1843 ret = fit_get_timestamp (fit, 0, ×tamp);
1844 printf ("%sCreated: ", p);
1846 printf ("unavailable\n");
1848 genimg_print_time (timestamp);
1851 /* Find images parent node offset */
1852 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
1853 if (images_noffset < 0) {
1854 printf ("Can't find images parent node '%s' (%s)\n",
1855 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
1859 /* Process its subnodes, print out component images details */
1860 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
1861 (noffset >= 0) && (ndepth > 0);
1862 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1865 * Direct child node of the images parent node,
1866 * i.e. component image node.
1868 printf ("%s Image %u (%s)\n", p, count++,
1869 fit_get_name(fit, noffset, NULL));
1871 fit_image_print (fit, noffset, p);
1875 /* Find configurations parent node offset */
1876 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
1877 if (confs_noffset < 0) {
1878 debug ("Can't get configurations parent node '%s' (%s)\n",
1879 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
1883 /* get default configuration unit name from default property */
1884 uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL);
1886 printf ("%s Default Configuration: '%s'\n", p, uname);
1888 /* Process its subnodes, print out configurations details */
1889 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth);
1890 (noffset >= 0) && (ndepth > 0);
1891 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1894 * Direct child node of the configurations parent node,
1895 * i.e. configuration node.
1897 printf ("%s Configuration %u (%s)\n", p, count++,
1898 fit_get_name(fit, noffset, NULL));
1900 fit_conf_print (fit, noffset, p);
1906 * fit_image_print - prints out the FIT component image details
1907 * @fit: pointer to the FIT format image header
1908 * @image_noffset: offset of the component image node
1909 * @p: pointer to prefix string
1911 * fit_image_print() lists all mandatory properies for the processed component
1912 * image. If present, hash nodes are printed out as well. Load
1913 * address for images of type firmware is also printed out. Since the load
1914 * address is not mandatory for firmware images, it will be output as
1915 * "unavailable" when not present.
1918 * no returned results
1920 void fit_image_print (const void *fit, int image_noffset, const char *p)
1923 uint8_t type, arch, os, comp;
1931 /* Mandatory properties */
1932 ret = fit_get_desc (fit, image_noffset, &desc);
1933 printf ("%s Description: ", p);
1935 printf ("unavailable\n");
1937 printf ("%s\n", desc);
1939 fit_image_get_type (fit, image_noffset, &type);
1940 printf ("%s Type: %s\n", p, genimg_get_type_name (type));
1942 fit_image_get_comp (fit, image_noffset, &comp);
1943 printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp));
1945 ret = fit_image_get_data (fit, image_noffset, &data, &size);
1948 printf ("%s Data Start: ", p);
1950 printf ("unavailable\n");
1952 printf ("0x%08lx\n", (ulong)data);
1955 printf ("%s Data Size: ", p);
1957 printf ("unavailable\n");
1959 genimg_print_size (size);
1961 /* Remaining, type dependent properties */
1962 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
1963 (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
1964 (type == IH_TYPE_FLATDT)) {
1965 fit_image_get_arch (fit, image_noffset, &arch);
1966 printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch));
1969 if (type == IH_TYPE_KERNEL) {
1970 fit_image_get_os (fit, image_noffset, &os);
1971 printf ("%s OS: %s\n", p, genimg_get_os_name (os));
1974 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
1975 (type == IH_TYPE_FIRMWARE)) {
1976 ret = fit_image_get_load (fit, image_noffset, &load);
1977 printf ("%s Load Address: ", p);
1979 printf ("unavailable\n");
1981 printf ("0x%08lx\n", load);
1984 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
1985 fit_image_get_entry (fit, image_noffset, &entry);
1986 printf ("%s Entry Point: ", p);
1988 printf ("unavailable\n");
1990 printf ("0x%08lx\n", entry);
1993 /* Process all hash subnodes of the component image node */
1994 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
1995 (noffset >= 0) && (ndepth > 0);
1996 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1998 /* Direct child node of the component image node */
1999 fit_image_print_hash (fit, noffset, p);
2005 * fit_image_print_hash - prints out the hash node details
2006 * @fit: pointer to the FIT format image header
2007 * @noffset: offset of the hash node
2008 * @p: pointer to prefix string
2010 * fit_image_print_hash() lists properies for the processed hash node
2013 * no returned results
2015 void fit_image_print_hash (const void *fit, int noffset, const char *p)
2023 * Check subnode name, must be equal to "hash".
2024 * Multiple hash nodes require unique unit node
2025 * names, e.g. hash@1, hash@2, etc.
2027 if (strncmp (fit_get_name(fit, noffset, NULL),
2029 strlen(FIT_HASH_NODENAME)) != 0)
2032 debug ("%s Hash node: '%s'\n", p,
2033 fit_get_name (fit, noffset, NULL));
2035 printf ("%s Hash algo: ", p);
2036 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2037 printf ("invalid/unsupported\n");
2040 printf ("%s\n", algo);
2042 ret = fit_image_hash_get_value (fit, noffset, &value,
2044 printf ("%s Hash value: ", p);
2046 printf ("unavailable\n");
2048 for (i = 0; i < value_len; i++)
2049 printf ("%02x", value[i]);
2053 debug ("%s Hash len: %d\n", p, value_len);
2057 * fit_get_desc - get node description property
2058 * @fit: pointer to the FIT format image header
2059 * @noffset: node offset
2060 * @desc: double pointer to the char, will hold pointer to the descrption
2062 * fit_get_desc() reads description property from a given node, if
2063 * description is found pointer to it is returened in third call argument.
2069 int fit_get_desc (const void *fit, int noffset, char **desc)
2073 *desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len);
2074 if (*desc == NULL) {
2075 fit_get_debug (fit, noffset, FIT_DESC_PROP, len);
2083 * fit_get_timestamp - get node timestamp property
2084 * @fit: pointer to the FIT format image header
2085 * @noffset: node offset
2086 * @timestamp: pointer to the time_t, will hold read timestamp
2088 * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
2089 * is found and has a correct size its value is retured in third call
2094 * -1, on property read failure
2095 * -2, on wrong timestamp size
2097 int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp)
2102 data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len);
2104 fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len);
2107 if (len != sizeof (uint32_t)) {
2108 debug ("FIT timestamp with incorrect size of (%u)\n", len);
2112 *timestamp = uimage_to_cpu (*((uint32_t *)data));
2117 * fit_image_get_node - get node offset for component image of a given unit name
2118 * @fit: pointer to the FIT format image header
2119 * @image_uname: component image node unit name
2121 * fit_image_get_node() finds a component image (withing the '/images'
2122 * node) of a provided unit name. If image is found its node offset is
2123 * returned to the caller.
2126 * image node offset when found (>=0)
2127 * negative number on failure (FDT_ERR_* code)
2129 int fit_image_get_node (const void *fit, const char *image_uname)
2131 int noffset, images_noffset;
2133 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2134 if (images_noffset < 0) {
2135 debug ("Can't find images parent node '%s' (%s)\n",
2136 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2137 return images_noffset;
2140 noffset = fdt_subnode_offset (fit, images_noffset, image_uname);
2142 debug ("Can't get node offset for image unit name: '%s' (%s)\n",
2143 image_uname, fdt_strerror (noffset));
2150 * fit_image_get_os - get os id for a given component image node
2151 * @fit: pointer to the FIT format image header
2152 * @noffset: component image node offset
2153 * @os: pointer to the uint8_t, will hold os numeric id
2155 * fit_image_get_os() finds os property in a given component image node.
2156 * If the property is found, its (string) value is translated to the numeric
2157 * id which is returned to the caller.
2163 int fit_image_get_os (const void *fit, int noffset, uint8_t *os)
2168 /* Get OS name from property data */
2169 data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len);
2171 fit_get_debug (fit, noffset, FIT_OS_PROP, len);
2176 /* Translate OS name to id */
2177 *os = genimg_get_os_id (data);
2182 * fit_image_get_arch - get arch id for a given component image node
2183 * @fit: pointer to the FIT format image header
2184 * @noffset: component image node offset
2185 * @arch: pointer to the uint8_t, will hold arch numeric id
2187 * fit_image_get_arch() finds arch property in a given component image node.
2188 * If the property is found, its (string) value is translated to the numeric
2189 * id which is returned to the caller.
2195 int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch)
2200 /* Get architecture name from property data */
2201 data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len);
2203 fit_get_debug (fit, noffset, FIT_ARCH_PROP, len);
2208 /* Translate architecture name to id */
2209 *arch = genimg_get_arch_id (data);
2214 * fit_image_get_type - get type id for a given component image node
2215 * @fit: pointer to the FIT format image header
2216 * @noffset: component image node offset
2217 * @type: pointer to the uint8_t, will hold type numeric id
2219 * fit_image_get_type() finds type property in a given component image node.
2220 * If the property is found, its (string) value is translated to the numeric
2221 * id which is returned to the caller.
2227 int fit_image_get_type (const void *fit, int noffset, uint8_t *type)
2232 /* Get image type name from property data */
2233 data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len);
2235 fit_get_debug (fit, noffset, FIT_TYPE_PROP, len);
2240 /* Translate image type name to id */
2241 *type = genimg_get_type_id (data);
2246 * fit_image_get_comp - get comp id for a given component image node
2247 * @fit: pointer to the FIT format image header
2248 * @noffset: component image node offset
2249 * @comp: pointer to the uint8_t, will hold comp numeric id
2251 * fit_image_get_comp() finds comp property in a given component image node.
2252 * If the property is found, its (string) value is translated to the numeric
2253 * id which is returned to the caller.
2259 int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp)
2264 /* Get compression name from property data */
2265 data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len);
2267 fit_get_debug (fit, noffset, FIT_COMP_PROP, len);
2272 /* Translate compression name to id */
2273 *comp = genimg_get_comp_id (data);
2278 * fit_image_get_load - get load address property for a given component image node
2279 * @fit: pointer to the FIT format image header
2280 * @noffset: component image node offset
2281 * @load: pointer to the uint32_t, will hold load address
2283 * fit_image_get_load() finds load address property in a given component image node.
2284 * If the property is found, its value is returned to the caller.
2290 int fit_image_get_load (const void *fit, int noffset, ulong *load)
2293 const uint32_t *data;
2295 data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len);
2297 fit_get_debug (fit, noffset, FIT_LOAD_PROP, len);
2301 *load = uimage_to_cpu (*data);
2306 * fit_image_get_entry - get entry point address property for a given component image node
2307 * @fit: pointer to the FIT format image header
2308 * @noffset: component image node offset
2309 * @entry: pointer to the uint32_t, will hold entry point address
2311 * fit_image_get_entry() finds entry point address property in a given component image node.
2312 * If the property is found, its value is returned to the caller.
2318 int fit_image_get_entry (const void *fit, int noffset, ulong *entry)
2321 const uint32_t *data;
2323 data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len);
2325 fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len);
2329 *entry = uimage_to_cpu (*data);
2334 * fit_image_get_data - get data property and its size for a given component image node
2335 * @fit: pointer to the FIT format image header
2336 * @noffset: component image node offset
2337 * @data: double pointer to void, will hold data property's data address
2338 * @size: pointer to size_t, will hold data property's data size
2340 * fit_image_get_data() finds data property in a given component image node.
2341 * If the property is found its data start address and size are returned to
2348 int fit_image_get_data (const void *fit, int noffset,
2349 const void **data, size_t *size)
2353 *data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len);
2354 if (*data == NULL) {
2355 fit_get_debug (fit, noffset, FIT_DATA_PROP, len);
2365 * fit_image_hash_get_algo - get hash algorithm name
2366 * @fit: pointer to the FIT format image header
2367 * @noffset: hash node offset
2368 * @algo: double pointer to char, will hold pointer to the algorithm name
2370 * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
2371 * If the property is found its data start address is returned to the caller.
2377 int fit_image_hash_get_algo (const void *fit, int noffset, char **algo)
2381 *algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len);
2382 if (*algo == NULL) {
2383 fit_get_debug (fit, noffset, FIT_ALGO_PROP, len);
2391 * fit_image_hash_get_value - get hash value and length
2392 * @fit: pointer to the FIT format image header
2393 * @noffset: hash node offset
2394 * @value: double pointer to uint8_t, will hold address of a hash value data
2395 * @value_len: pointer to an int, will hold hash data length
2397 * fit_image_hash_get_value() finds hash value property in a given hash node.
2398 * If the property is found its data start address and size are returned to
2405 int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value,
2410 *value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len);
2411 if (*value == NULL) {
2412 fit_get_debug (fit, noffset, FIT_VALUE_PROP, len);
2422 * fit_set_timestamp - set node timestamp property
2423 * @fit: pointer to the FIT format image header
2424 * @noffset: node offset
2425 * @timestamp: timestamp value to be set
2427 * fit_set_timestamp() attempts to set timestamp property in the requested
2428 * node and returns operation status to the caller.
2432 * -1, on property read failure
2434 int fit_set_timestamp (void *fit, int noffset, time_t timestamp)
2439 t = cpu_to_uimage (timestamp);
2440 ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t,
2443 printf ("Can't set '%s' property for '%s' node (%s)\n",
2444 FIT_TIMESTAMP_PROP, fit_get_name (fit, noffset, NULL),
2445 fdt_strerror (ret));
2453 * calculate_hash - calculate and return hash for provided input data
2454 * @data: pointer to the input data
2455 * @data_len: data length
2456 * @algo: requested hash algorithm
2457 * @value: pointer to the char, will hold hash value data (caller must
2458 * allocate enough free space)
2459 * value_len: length of the calculated hash
2461 * calculate_hash() computes input data hash according to the requested algorithm.
2462 * Resulting hash value is placed in caller provided 'value' buffer, length
2463 * of the calculated hash is returned via value_len pointer argument.
2467 * -1, when algo is unsupported
2469 static int calculate_hash (const void *data, int data_len, const char *algo,
2470 uint8_t *value, int *value_len)
2472 if (strcmp (algo, "crc32") == 0 ) {
2473 *((uint32_t *)value) = crc32_wd (0, data, data_len,
2475 *((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value));
2477 } else if (strcmp (algo, "sha1") == 0 ) {
2478 sha1_csum_wd ((unsigned char *) data, data_len,
2479 (unsigned char *) value, CHUNKSZ_SHA1);
2481 } else if (strcmp (algo, "md5") == 0 ) {
2482 md5_wd ((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
2485 debug ("Unsupported hash alogrithm\n");
2493 * fit_set_hashes - process FIT component image nodes and calculate hashes
2494 * @fit: pointer to the FIT format image header
2496 * fit_set_hashes() adds hash values for all component images in the FIT blob.
2497 * Hashes are calculated for all component images which have hash subnodes
2498 * with algorithm property set to one of the supported hash algorithms.
2502 * libfdt error code, on failure
2504 int fit_set_hashes (void *fit)
2511 /* Find images parent node offset */
2512 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2513 if (images_noffset < 0) {
2514 printf ("Can't find images parent node '%s' (%s)\n",
2515 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2516 return images_noffset;
2519 /* Process its subnodes, print out component images details */
2520 for (ndepth = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
2521 (noffset >= 0) && (ndepth > 0);
2522 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2525 * Direct child node of the images parent node,
2526 * i.e. component image node.
2528 ret = fit_image_set_hashes (fit, noffset);
2538 * fit_image_set_hashes - calculate/set hashes for given component image node
2539 * @fit: pointer to the FIT format image header
2540 * @image_noffset: requested component image node
2542 * fit_image_set_hashes() adds hash values for an component image node. All
2543 * existing hash subnodes are checked, if algorithm property is set to one of
2544 * the supported hash algorithms, hash value is computed and corresponding
2545 * hash node property is set, for example:
2547 * Input component image node structure:
2549 * o image@1 (at image_noffset)
2550 * | - data = [binary data]
2554 * Output component image node structure:
2556 * o image@1 (at image_noffset)
2557 * | - data = [binary data]
2560 * |- value = sha1(data)
2566 int fit_image_set_hashes (void *fit, int image_noffset)
2571 uint8_t value[FIT_MAX_HASH_LEN];
2576 /* Get image data and data length */
2577 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
2578 printf ("Can't get image data/size\n");
2582 /* Process all hash subnodes of the component image node */
2583 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2584 (noffset >= 0) && (ndepth > 0);
2585 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2587 /* Direct child node of the component image node */
2590 * Check subnode name, must be equal to "hash".
2591 * Multiple hash nodes require unique unit node
2592 * names, e.g. hash@1, hash@2, etc.
2594 if (strncmp (fit_get_name(fit, noffset, NULL),
2596 strlen(FIT_HASH_NODENAME)) != 0) {
2597 /* Not a hash subnode, skip it */
2601 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2602 printf ("Can't get hash algo property for "
2603 "'%s' hash node in '%s' image node\n",
2604 fit_get_name (fit, noffset, NULL),
2605 fit_get_name (fit, image_noffset, NULL));
2609 if (calculate_hash (data, size, algo, value, &value_len)) {
2610 printf ("Unsupported hash algorithm (%s) for "
2611 "'%s' hash node in '%s' image node\n",
2612 algo, fit_get_name (fit, noffset, NULL),
2613 fit_get_name (fit, image_noffset, NULL));
2617 if (fit_image_hash_set_value (fit, noffset, value,
2619 printf ("Can't set hash value for "
2620 "'%s' hash node in '%s' image node\n",
2621 fit_get_name (fit, noffset, NULL),
2622 fit_get_name (fit, image_noffset, NULL));
2632 * fit_image_hash_set_value - set hash value in requested has node
2633 * @fit: pointer to the FIT format image header
2634 * @noffset: hash node offset
2635 * @value: hash value to be set
2636 * @value_len: hash value length
2638 * fit_image_hash_set_value() attempts to set hash value in a node at offset
2639 * given and returns operation status to the caller.
2645 int fit_image_hash_set_value (void *fit, int noffset, uint8_t *value,
2650 ret = fdt_setprop (fit, noffset, FIT_VALUE_PROP, value, value_len);
2652 printf ("Can't set hash '%s' property for '%s' node (%s)\n",
2653 FIT_VALUE_PROP, fit_get_name (fit, noffset, NULL),
2654 fdt_strerror (ret));
2660 #endif /* USE_HOSTCC */
2663 * fit_image_check_hashes - verify data intergity
2664 * @fit: pointer to the FIT format image header
2665 * @image_noffset: component image node offset
2667 * fit_image_check_hashes() goes over component image hash nodes,
2668 * re-calculates each data hash and compares with the value stored in hash
2672 * 1, if all hashes are valid
2673 * 0, otherwise (or on error)
2675 int fit_image_check_hashes (const void *fit, int image_noffset)
2682 uint8_t value[FIT_MAX_HASH_LEN];
2688 /* Get image data and data length */
2689 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
2690 printf ("Can't get image data/size\n");
2694 /* Process all hash subnodes of the component image node */
2695 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2696 (noffset >= 0) && (ndepth > 0);
2697 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2699 /* Direct child node of the component image node */
2702 * Check subnode name, must be equal to "hash".
2703 * Multiple hash nodes require unique unit node
2704 * names, e.g. hash@1, hash@2, etc.
2706 if (strncmp (fit_get_name(fit, noffset, NULL),
2708 strlen(FIT_HASH_NODENAME)) != 0)
2711 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2712 err_msg = " error!\nCan't get hash algo "
2716 printf ("%s", algo);
2718 if (fit_image_hash_get_value (fit, noffset, &fit_value,
2720 err_msg = " error!\nCan't get hash value "
2725 if (calculate_hash (data, size, algo, value, &value_len)) {
2726 err_msg = " error!\nUnsupported hash algorithm";
2730 if (value_len != fit_value_len) {
2731 err_msg = " error !\nBad hash value len";
2733 } else if (memcmp (value, fit_value, value_len) != 0) {
2734 err_msg = " error!\nBad hash value";
2744 printf ("%s for '%s' hash node in '%s' image node\n",
2745 err_msg, fit_get_name (fit, noffset, NULL),
2746 fit_get_name (fit, image_noffset, NULL));
2751 * fit_all_image_check_hashes - verify data intergity for all images
2752 * @fit: pointer to the FIT format image header
2754 * fit_all_image_check_hashes() goes over all images in the FIT and
2755 * for every images checks if all it's hashes are valid.
2758 * 1, if all hashes of all images are valid
2759 * 0, otherwise (or on error)
2761 int fit_all_image_check_hashes (const void *fit)
2768 /* Find images parent node offset */
2769 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2770 if (images_noffset < 0) {
2771 printf ("Can't find images parent node '%s' (%s)\n",
2772 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2776 /* Process all image subnodes, check hashes for each */
2777 printf ("## Checking hash(es) for FIT Image at %08lx ...\n",
2779 for (ndepth = 0, count = 0,
2780 noffset = fdt_next_node (fit, images_noffset, &ndepth);
2781 (noffset >= 0) && (ndepth > 0);
2782 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2785 * Direct child node of the images parent node,
2786 * i.e. component image node.
2788 printf (" Hash(es) for Image %u (%s): ", count++,
2789 fit_get_name (fit, noffset, NULL));
2791 if (!fit_image_check_hashes (fit, noffset))
2800 * fit_image_check_os - check whether image node is of a given os type
2801 * @fit: pointer to the FIT format image header
2802 * @noffset: component image node offset
2803 * @os: requested image os
2805 * fit_image_check_os() reads image os property and compares its numeric
2806 * id with the requested os. Comparison result is returned to the caller.
2809 * 1 if image is of given os type
2810 * 0 otherwise (or on error)
2812 int fit_image_check_os (const void *fit, int noffset, uint8_t os)
2816 if (fit_image_get_os (fit, noffset, &image_os))
2818 return (os == image_os);
2822 * fit_image_check_arch - check whether image node is of a given arch
2823 * @fit: pointer to the FIT format image header
2824 * @noffset: component image node offset
2825 * @arch: requested imagearch
2827 * fit_image_check_arch() reads image arch property and compares its numeric
2828 * id with the requested arch. Comparison result is returned to the caller.
2831 * 1 if image is of given arch
2832 * 0 otherwise (or on error)
2834 int fit_image_check_arch (const void *fit, int noffset, uint8_t arch)
2838 if (fit_image_get_arch (fit, noffset, &image_arch))
2840 return (arch == image_arch);
2844 * fit_image_check_type - check whether image node is of a given type
2845 * @fit: pointer to the FIT format image header
2846 * @noffset: component image node offset
2847 * @type: requested image type
2849 * fit_image_check_type() reads image type property and compares its numeric
2850 * id with the requested type. Comparison result is returned to the caller.
2853 * 1 if image is of given type
2854 * 0 otherwise (or on error)
2856 int fit_image_check_type (const void *fit, int noffset, uint8_t type)
2860 if (fit_image_get_type (fit, noffset, &image_type))
2862 return (type == image_type);
2866 * fit_image_check_comp - check whether image node uses given compression
2867 * @fit: pointer to the FIT format image header
2868 * @noffset: component image node offset
2869 * @comp: requested image compression type
2871 * fit_image_check_comp() reads image compression property and compares its
2872 * numeric id with the requested compression type. Comparison result is
2873 * returned to the caller.
2876 * 1 if image uses requested compression
2877 * 0 otherwise (or on error)
2879 int fit_image_check_comp (const void *fit, int noffset, uint8_t comp)
2883 if (fit_image_get_comp (fit, noffset, &image_comp))
2885 return (comp == image_comp);
2889 * fit_check_format - sanity check FIT image format
2890 * @fit: pointer to the FIT format image header
2892 * fit_check_format() runs a basic sanity FIT image verification.
2893 * Routine checks for mandatory properties, nodes, etc.
2899 int fit_check_format (const void *fit)
2901 /* mandatory / node 'description' property */
2902 if (fdt_getprop (fit, 0, FIT_DESC_PROP, NULL) == NULL) {
2903 debug ("Wrong FIT format: no description\n");
2907 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
2908 /* mandatory / node 'timestamp' property */
2909 if (fdt_getprop (fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
2910 debug ("Wrong FIT format: no timestamp\n");
2915 /* mandatory subimages parent '/images' node */
2916 if (fdt_path_offset (fit, FIT_IMAGES_PATH) < 0) {
2917 debug ("Wrong FIT format: no images parent node\n");
2925 * fit_conf_get_node - get node offset for configuration of a given unit name
2926 * @fit: pointer to the FIT format image header
2927 * @conf_uname: configuration node unit name
2929 * fit_conf_get_node() finds a configuration (withing the '/configurations'
2930 * parant node) of a provided unit name. If configuration is found its node offset
2931 * is returned to the caller.
2933 * When NULL is provided in second argument fit_conf_get_node() will search
2934 * for a default configuration node instead. Default configuration node unit name
2935 * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
2938 * configuration node offset when found (>=0)
2939 * negative number on failure (FDT_ERR_* code)
2941 int fit_conf_get_node (const void *fit, const char *conf_uname)
2943 int noffset, confs_noffset;
2946 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
2947 if (confs_noffset < 0) {
2948 debug ("Can't find configurations parent node '%s' (%s)\n",
2949 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
2950 return confs_noffset;
2953 if (conf_uname == NULL) {
2954 /* get configuration unit name from the default property */
2955 debug ("No configuration specified, trying default...\n");
2956 conf_uname = (char *)fdt_getprop (fit, confs_noffset, FIT_DEFAULT_PROP, &len);
2957 if (conf_uname == NULL) {
2958 fit_get_debug (fit, confs_noffset, FIT_DEFAULT_PROP, len);
2961 debug ("Found default configuration: '%s'\n", conf_uname);
2964 noffset = fdt_subnode_offset (fit, confs_noffset, conf_uname);
2966 debug ("Can't get node offset for configuration unit name: '%s' (%s)\n",
2967 conf_uname, fdt_strerror (noffset));
2973 static int __fit_conf_get_prop_node (const void *fit, int noffset,
2974 const char *prop_name)
2979 /* get kernel image unit name from configuration kernel property */
2980 uname = (char *)fdt_getprop (fit, noffset, prop_name, &len);
2984 return fit_image_get_node (fit, uname);
2988 * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
2989 * a given configuration
2990 * @fit: pointer to the FIT format image header
2991 * @noffset: configuration node offset
2993 * fit_conf_get_kernel_node() retrives kernel image node unit name from
2994 * configuration FIT_KERNEL_PROP property and translates it to the node
2998 * image node offset when found (>=0)
2999 * negative number on failure (FDT_ERR_* code)
3001 int fit_conf_get_kernel_node (const void *fit, int noffset)
3003 return __fit_conf_get_prop_node (fit, noffset, FIT_KERNEL_PROP);
3007 * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
3008 * a given configuration
3009 * @fit: pointer to the FIT format image header
3010 * @noffset: configuration node offset
3012 * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
3013 * configuration FIT_KERNEL_PROP property and translates it to the node
3017 * image node offset when found (>=0)
3018 * negative number on failure (FDT_ERR_* code)
3020 int fit_conf_get_ramdisk_node (const void *fit, int noffset)
3022 return __fit_conf_get_prop_node (fit, noffset, FIT_RAMDISK_PROP);
3026 * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
3027 * a given configuration
3028 * @fit: pointer to the FIT format image header
3029 * @noffset: configuration node offset
3031 * fit_conf_get_fdt_node() retrives fdt image node unit name from
3032 * configuration FIT_KERNEL_PROP property and translates it to the node
3036 * image node offset when found (>=0)
3037 * negative number on failure (FDT_ERR_* code)
3039 int fit_conf_get_fdt_node (const void *fit, int noffset)
3041 return __fit_conf_get_prop_node (fit, noffset, FIT_FDT_PROP);
3045 * fit_conf_print - prints out the FIT configuration details
3046 * @fit: pointer to the FIT format image header
3047 * @noffset: offset of the configuration node
3048 * @p: pointer to prefix string
3050 * fit_conf_print() lists all mandatory properies for the processed
3051 * configuration node.
3054 * no returned results
3056 void fit_conf_print (const void *fit, int noffset, const char *p)
3062 /* Mandatory properties */
3063 ret = fit_get_desc (fit, noffset, &desc);
3064 printf ("%s Description: ", p);
3066 printf ("unavailable\n");
3068 printf ("%s\n", desc);
3070 uname = (char *)fdt_getprop (fit, noffset, FIT_KERNEL_PROP, NULL);
3071 printf ("%s Kernel: ", p);
3073 printf ("unavailable\n");
3075 printf ("%s\n", uname);
3077 /* Optional properties */
3078 uname = (char *)fdt_getprop (fit, noffset, FIT_RAMDISK_PROP, NULL);
3080 printf ("%s Init Ramdisk: %s\n", p, uname);
3082 uname = (char *)fdt_getprop (fit, noffset, FIT_FDT_PROP, NULL);
3084 printf ("%s FDT: %s\n", p, uname);
3088 * fit_check_ramdisk - verify FIT format ramdisk subimage
3089 * @fit_hdr: pointer to the FIT ramdisk header
3090 * @rd_noffset: ramdisk subimage node offset within FIT image
3091 * @arch: requested ramdisk image architecture type
3092 * @verify: data CRC verification flag
3094 * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
3095 * specified FIT image.
3102 static int fit_check_ramdisk (const void *fit, int rd_noffset, uint8_t arch, int verify)
3104 fit_image_print (fit, rd_noffset, " ");
3107 puts (" Verifying Hash Integrity ... ");
3108 if (!fit_image_check_hashes (fit, rd_noffset)) {
3109 puts ("Bad Data Hash\n");
3110 show_boot_progress (-125);
3116 show_boot_progress (126);
3117 if (!fit_image_check_os (fit, rd_noffset, IH_OS_LINUX) ||
3118 !fit_image_check_arch (fit, rd_noffset, arch) ||
3119 !fit_image_check_type (fit, rd_noffset, IH_TYPE_RAMDISK)) {
3120 printf ("No Linux %s Ramdisk Image\n",
3121 genimg_get_arch_name(arch));
3122 show_boot_progress (-126);
3126 show_boot_progress (127);
3129 #endif /* USE_HOSTCC */
3130 #endif /* CONFIG_FIT */