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", },
96 { IH_ARCH_NDS32, "nds32", "NDS32", },
100 static const table_entry_t uimage_os[] = {
101 { IH_OS_INVALID, NULL, "Invalid OS", },
102 { IH_OS_LINUX, "linux", "Linux", },
103 #if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC)
104 { IH_OS_LYNXOS, "lynxos", "LynxOS", },
106 { IH_OS_NETBSD, "netbsd", "NetBSD", },
107 { IH_OS_OSE, "ose", "Enea OSE", },
108 { IH_OS_RTEMS, "rtems", "RTEMS", },
109 { IH_OS_U_BOOT, "u-boot", "U-Boot", },
110 #if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC)
111 { IH_OS_QNX, "qnx", "QNX", },
112 { IH_OS_VXWORKS, "vxworks", "VxWorks", },
114 #if defined(CONFIG_INTEGRITY) || defined(USE_HOSTCC)
115 { IH_OS_INTEGRITY,"integrity", "INTEGRITY", },
118 { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", },
119 { IH_OS_DELL, "dell", "Dell", },
120 { IH_OS_ESIX, "esix", "Esix", },
121 { IH_OS_FREEBSD, "freebsd", "FreeBSD", },
122 { IH_OS_IRIX, "irix", "Irix", },
123 { IH_OS_NCR, "ncr", "NCR", },
124 { IH_OS_OPENBSD, "openbsd", "OpenBSD", },
125 { IH_OS_PSOS, "psos", "pSOS", },
126 { IH_OS_SCO, "sco", "SCO", },
127 { IH_OS_SOLARIS, "solaris", "Solaris", },
128 { IH_OS_SVR4, "svr4", "SVR4", },
133 static const table_entry_t uimage_type[] = {
134 { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", },
135 { IH_TYPE_FIRMWARE, "firmware", "Firmware", },
136 { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", },
137 { IH_TYPE_KERNEL, "kernel", "Kernel Image", },
138 { IH_TYPE_MULTI, "multi", "Multi-File Image", },
139 { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", },
140 { IH_TYPE_SCRIPT, "script", "Script", },
141 { IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
142 { IH_TYPE_IMXIMAGE, "imximage", "Freescale i.MX Boot Image",},
143 { IH_TYPE_KWBIMAGE, "kwbimage", "Kirkwood Boot Image",},
144 { IH_TYPE_OMAPIMAGE, "omapimage", "TI OMAP SPL With GP CH",},
145 { IH_TYPE_UBLIMAGE, "ublimage", "Davinci UBL image",},
146 { IH_TYPE_INVALID, NULL, "Invalid Image", },
150 static const table_entry_t uimage_comp[] = {
151 { IH_COMP_NONE, "none", "uncompressed", },
152 { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", },
153 { IH_COMP_GZIP, "gzip", "gzip compressed", },
154 { IH_COMP_LZMA, "lzma", "lzma compressed", },
155 { IH_COMP_LZO, "lzo", "lzo compressed", },
159 uint32_t crc32 (uint32_t, const unsigned char *, uint);
160 uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint);
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 (const 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 (const 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));
193 * image_multi_count - get component (sub-image) count
194 * @hdr: pointer to the header of the multi component image
196 * image_multi_count() returns number of components in a multi
199 * Note: no checking of the image type is done, caller must pass
200 * a valid multi component image.
203 * number of components
205 ulong image_multi_count (const image_header_t *hdr)
210 /* get start of the image payload, which in case of multi
211 * component images that points to a table of component sizes */
212 size = (uint32_t *)image_get_data (hdr);
214 /* count non empty slots */
215 for (i = 0; size[i]; ++i)
222 * image_multi_getimg - get component data address and size
223 * @hdr: pointer to the header of the multi component image
224 * @idx: index of the requested component
225 * @data: pointer to a ulong variable, will hold component data address
226 * @len: pointer to a ulong variable, will hold component size
228 * image_multi_getimg() returns size and data address for the requested
229 * component in a multi component image.
231 * Note: no checking of the image type is done, caller must pass
232 * a valid multi component image.
235 * data address and size of the component, if idx is valid
236 * 0 in data and len, if idx is out of range
238 void image_multi_getimg (const image_header_t *hdr, ulong idx,
239 ulong *data, ulong *len)
243 ulong offset, count, img_data;
245 /* get number of component */
246 count = image_multi_count (hdr);
248 /* get start of the image payload, which in case of multi
249 * component images that points to a table of component sizes */
250 size = (uint32_t *)image_get_data (hdr);
252 /* get address of the proper component data start, which means
253 * skipping sizes table (add 1 for last, null entry) */
254 img_data = image_get_data (hdr) + (count + 1) * sizeof (uint32_t);
257 *len = uimage_to_cpu (size[idx]);
260 /* go over all indices preceding requested component idx */
261 for (i = 0; i < idx; i++) {
262 /* add up i-th component size, rounding up to 4 bytes */
263 offset += (uimage_to_cpu (size[i]) + 3) & ~3 ;
266 /* calculate idx-th component data address */
267 *data = img_data + offset;
274 static void image_print_type (const image_header_t *hdr)
276 const char *os, *arch, *type, *comp;
278 os = genimg_get_os_name (image_get_os (hdr));
279 arch = genimg_get_arch_name (image_get_arch (hdr));
280 type = genimg_get_type_name (image_get_type (hdr));
281 comp = genimg_get_comp_name (image_get_comp (hdr));
283 printf ("%s %s %s (%s)\n", arch, os, type, comp);
287 * image_print_contents - prints out the contents of the legacy format image
288 * @ptr: pointer to the legacy format image header
289 * @p: pointer to prefix string
291 * image_print_contents() formats a multi line legacy image contents description.
292 * The routine prints out all header fields followed by the size/offset data
293 * for MULTI/SCRIPT images.
296 * no returned results
298 void image_print_contents (const void *ptr)
300 const image_header_t *hdr = (const image_header_t *)ptr;
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 const image_header_t *image_get_ramdisk (ulong rd_addr, uint8_t arch,
369 const image_header_t *rd_hdr = (const 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(CONFIG_SYS_SDRAM_BASE)
430 return CONFIG_SYS_SDRAM_BASE;
431 #elif defined(CONFIG_ARM)
432 return gd->bd->bi_dram[0].start;
438 phys_size_t getenv_bootm_size(void)
441 char *s = getenv ("bootm_size");
443 tmp = (phys_size_t)simple_strtoull (s, NULL, 16);
446 s = getenv("bootm_low");
448 tmp = (phys_size_t)simple_strtoull (s, NULL, 16);
453 #if defined(CONFIG_ARM)
454 return gd->bd->bi_dram[0].size - tmp;
456 return gd->bd->bi_memsize - tmp;
460 phys_size_t getenv_bootm_mapsize(void)
463 char *s = getenv ("bootm_mapsize");
465 tmp = (phys_size_t)simple_strtoull (s, NULL, 16);
469 #if defined(CONFIG_SYS_BOOTMAPSZ)
470 return CONFIG_SYS_BOOTMAPSZ;
472 return getenv_bootm_size();
476 void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
481 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
483 size_t tail = (len > chunksz) ? chunksz : len;
485 memmove (to, from, tail);
490 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
491 memmove (to, from, len);
492 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
494 #endif /* !USE_HOSTCC */
496 void genimg_print_size (uint32_t size)
499 printf ("%d Bytes = ", size);
500 print_size (size, "\n");
502 printf ("%d Bytes = %.2f kB = %.2f MB\n",
503 size, (double)size / 1.024e3,
504 (double)size / 1.048576e6);
508 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
509 static void genimg_print_time (time_t timestamp)
514 to_tm (timestamp, &tm);
515 printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
516 tm.tm_year, tm.tm_mon, tm.tm_mday,
517 tm.tm_hour, tm.tm_min, tm.tm_sec);
519 printf ("%s", ctime(×tamp));
522 #endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */
525 * get_table_entry_name - translate entry id to long name
526 * @table: pointer to a translation table for entries of a specific type
527 * @msg: message to be returned when translation fails
528 * @id: entry id to be translated
530 * get_table_entry_name() will go over translation table trying to find
531 * entry that matches given id. If matching entry is found, its long
532 * name is returned to the caller.
535 * long entry name if translation succeeds
538 char *get_table_entry_name(const table_entry_t *table, char *msg, int id)
540 for (; table->id >= 0; ++table) {
542 #if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
545 return table->lname + gd->reloc_off;
551 const char *genimg_get_os_name (uint8_t os)
553 return (get_table_entry_name (uimage_os, "Unknown OS", os));
556 const char *genimg_get_arch_name (uint8_t arch)
558 return (get_table_entry_name (uimage_arch, "Unknown Architecture", arch));
561 const char *genimg_get_type_name (uint8_t type)
563 return (get_table_entry_name (uimage_type, "Unknown Image", type));
566 const char *genimg_get_comp_name (uint8_t comp)
568 return (get_table_entry_name (uimage_comp, "Unknown Compression", comp));
572 * get_table_entry_id - translate short entry name to id
573 * @table: pointer to a translation table for entries of a specific type
574 * @table_name: to be used in case of error
575 * @name: entry short name to be translated
577 * get_table_entry_id() will go over translation table trying to find
578 * entry that matches given short name. If matching entry is found,
579 * its id returned to the caller.
582 * entry id if translation succeeds
585 int get_table_entry_id(const table_entry_t *table,
586 const char *table_name, const char *name)
588 const table_entry_t *t;
592 for (t = table; t->id >= 0; ++t) {
593 if (t->sname && strcasecmp(t->sname, name) == 0)
597 fprintf (stderr, "\nInvalid %s Type - valid names are", table_name);
598 for (t = table; t->id >= 0; ++t) {
599 if (t->sname == NULL)
601 fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname);
604 fprintf (stderr, "\n");
606 for (t = table; t->id >= 0; ++t) {
607 #ifdef CONFIG_NEEDS_MANUAL_RELOC
608 if (t->sname && strcmp(t->sname + gd->reloc_off, name) == 0)
610 if (t->sname && strcmp(t->sname, name) == 0)
614 debug ("Invalid %s Type: %s\n", table_name, name);
615 #endif /* USE_HOSTCC */
619 int genimg_get_os_id (const char *name)
621 return (get_table_entry_id (uimage_os, "OS", name));
624 int genimg_get_arch_id (const char *name)
626 return (get_table_entry_id (uimage_arch, "CPU", name));
629 int genimg_get_type_id (const char *name)
631 return (get_table_entry_id (uimage_type, "Image", name));
634 int genimg_get_comp_id (const char *name)
636 return (get_table_entry_id (uimage_comp, "Compression", name));
641 * genimg_get_format - get image format type
642 * @img_addr: image start address
644 * genimg_get_format() checks whether provided address points to a valid
645 * legacy or FIT image.
647 * New uImage format and FDT blob are based on a libfdt. FDT blob
648 * may be passed directly or embedded in a FIT image. In both situations
649 * genimg_get_format() must be able to dectect libfdt header.
652 * image format type or IMAGE_FORMAT_INVALID if no image is present
654 int genimg_get_format (void *img_addr)
656 ulong format = IMAGE_FORMAT_INVALID;
657 const image_header_t *hdr;
658 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
662 hdr = (const image_header_t *)img_addr;
663 if (image_check_magic(hdr))
664 format = IMAGE_FORMAT_LEGACY;
665 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
667 fit_hdr = (char *)img_addr;
668 if (fdt_check_header (fit_hdr) == 0)
669 format = IMAGE_FORMAT_FIT;
677 * genimg_get_image - get image from special storage (if necessary)
678 * @img_addr: image start address
680 * genimg_get_image() checks if provided image start adddress is located
681 * in a dataflash storage. If so, image is moved to a system RAM memory.
684 * image start address after possible relocation from special storage
686 ulong genimg_get_image (ulong img_addr)
688 ulong ram_addr = img_addr;
690 #ifdef CONFIG_HAS_DATAFLASH
691 ulong h_size, d_size;
693 if (addr_dataflash (img_addr)){
694 /* ger RAM address */
695 ram_addr = CONFIG_SYS_LOAD_ADDR;
697 /* get header size */
698 h_size = image_get_header_size ();
699 #if defined(CONFIG_FIT)
700 if (sizeof(struct fdt_header) > h_size)
701 h_size = sizeof(struct fdt_header);
705 debug (" Reading image header from dataflash address "
706 "%08lx to RAM address %08lx\n", img_addr, ram_addr);
708 read_dataflash (img_addr, h_size, (char *)ram_addr);
711 switch (genimg_get_format ((void *)ram_addr)) {
712 case IMAGE_FORMAT_LEGACY:
713 d_size = image_get_data_size ((const image_header_t *)ram_addr);
714 debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n",
717 #if defined(CONFIG_FIT)
718 case IMAGE_FORMAT_FIT:
719 d_size = fit_get_size ((const void *)ram_addr) - h_size;
720 debug (" FIT/FDT format image found at 0x%08lx, size 0x%08lx\n",
725 printf (" No valid image found at 0x%08lx\n", img_addr);
729 /* read in image data */
730 debug (" Reading image remaining data from dataflash address "
731 "%08lx to RAM address %08lx\n", img_addr + h_size,
734 read_dataflash (img_addr + h_size, d_size,
735 (char *)(ram_addr + h_size));
738 #endif /* CONFIG_HAS_DATAFLASH */
744 * fit_has_config - check if there is a valid FIT configuration
745 * @images: pointer to the bootm command headers structure
747 * fit_has_config() checks if there is a FIT configuration in use
748 * (if FTI support is present).
751 * 0, no FIT support or no configuration found
752 * 1, configuration found
754 int genimg_has_config (bootm_headers_t *images)
756 #if defined(CONFIG_FIT)
757 if (images->fit_uname_cfg)
764 * boot_get_ramdisk - main ramdisk handling routine
765 * @argc: command argument count
766 * @argv: command argument list
767 * @images: pointer to the bootm images structure
768 * @arch: expected ramdisk architecture
769 * @rd_start: pointer to a ulong variable, will hold ramdisk start address
770 * @rd_end: pointer to a ulong variable, will hold ramdisk end
772 * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
773 * Curently supported are the following ramdisk sources:
774 * - multicomponent kernel/ramdisk image,
775 * - commandline provided address of decicated ramdisk image.
778 * 0, if ramdisk image was found and valid, or skiped
779 * rd_start and rd_end are set to ramdisk start/end addresses if
780 * ramdisk image is found and valid
782 * 1, if ramdisk image is found but corrupted, or invalid
783 * rd_start and rd_end are set to 0 if no ramdisk exists
785 int boot_get_ramdisk (int argc, char * const argv[], bootm_headers_t *images,
786 uint8_t arch, ulong *rd_start, ulong *rd_end)
788 ulong rd_addr, rd_load;
789 ulong rd_data, rd_len;
790 const image_header_t *rd_hdr;
791 #if defined(CONFIG_FIT)
793 const char *fit_uname_config = NULL;
794 const char *fit_uname_ramdisk = NULL;
806 * Look for a '-' which indicates to ignore the
809 if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) {
810 debug ("## Skipping init Ramdisk\n");
811 rd_len = rd_data = 0;
812 } else if (argc >= 3 || genimg_has_config (images)) {
813 #if defined(CONFIG_FIT)
816 * If the init ramdisk comes from the FIT image and
817 * the FIT image address is omitted in the command
818 * line argument, try to use os FIT image address or
819 * default load address.
821 if (images->fit_uname_os)
822 default_addr = (ulong)images->fit_hdr_os;
824 default_addr = load_addr;
826 if (fit_parse_conf (argv[2], default_addr,
827 &rd_addr, &fit_uname_config)) {
828 debug ("* ramdisk: config '%s' from image at 0x%08lx\n",
829 fit_uname_config, rd_addr);
830 } else if (fit_parse_subimage (argv[2], default_addr,
831 &rd_addr, &fit_uname_ramdisk)) {
832 debug ("* ramdisk: subimage '%s' from image at 0x%08lx\n",
833 fit_uname_ramdisk, rd_addr);
837 rd_addr = simple_strtoul(argv[2], NULL, 16);
838 debug ("* ramdisk: cmdline image address = 0x%08lx\n",
841 #if defined(CONFIG_FIT)
843 /* use FIT configuration provided in first bootm
846 rd_addr = (ulong)images->fit_hdr_os;
847 fit_uname_config = images->fit_uname_cfg;
848 debug ("* ramdisk: using config '%s' from image at 0x%08lx\n",
849 fit_uname_config, rd_addr);
852 * Check whether configuration has ramdisk defined,
853 * if not, don't try to use it, quit silently.
855 fit_hdr = (void *)rd_addr;
856 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
857 if (cfg_noffset < 0) {
858 debug ("* ramdisk: no such config\n");
862 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
863 if (rd_noffset < 0) {
864 debug ("* ramdisk: no ramdisk in config\n");
870 /* copy from dataflash if needed */
871 rd_addr = genimg_get_image (rd_addr);
874 * Check if there is an initrd image at the
875 * address provided in the second bootm argument
876 * check image type, for FIT images get FIT node.
878 switch (genimg_get_format ((void *)rd_addr)) {
879 case IMAGE_FORMAT_LEGACY:
880 printf ("## Loading init Ramdisk from Legacy "
881 "Image at %08lx ...\n", rd_addr);
883 show_boot_progress (9);
884 rd_hdr = image_get_ramdisk (rd_addr, arch,
890 rd_data = image_get_data (rd_hdr);
891 rd_len = image_get_data_size (rd_hdr);
892 rd_load = image_get_load (rd_hdr);
894 #if defined(CONFIG_FIT)
895 case IMAGE_FORMAT_FIT:
896 fit_hdr = (void *)rd_addr;
897 printf ("## Loading init Ramdisk from FIT "
898 "Image at %08lx ...\n", rd_addr);
900 show_boot_progress (120);
901 if (!fit_check_format (fit_hdr)) {
902 puts ("Bad FIT ramdisk image format!\n");
903 show_boot_progress (-120);
906 show_boot_progress (121);
908 if (!fit_uname_ramdisk) {
910 * no ramdisk image node unit name, try to get config
911 * node first. If config unit node name is NULL
912 * fit_conf_get_node() will try to find default config node
914 show_boot_progress (122);
915 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
916 if (cfg_noffset < 0) {
917 puts ("Could not find configuration node\n");
918 show_boot_progress (-122);
921 fit_uname_config = fdt_get_name (fit_hdr, cfg_noffset, NULL);
922 printf (" Using '%s' configuration\n", fit_uname_config);
924 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
925 fit_uname_ramdisk = fit_get_name (fit_hdr, rd_noffset, NULL);
927 /* get ramdisk component image node offset */
928 show_boot_progress (123);
929 rd_noffset = fit_image_get_node (fit_hdr, fit_uname_ramdisk);
931 if (rd_noffset < 0) {
932 puts ("Could not find subimage node\n");
933 show_boot_progress (-124);
937 printf (" Trying '%s' ramdisk subimage\n", fit_uname_ramdisk);
939 show_boot_progress (125);
940 if (!fit_check_ramdisk (fit_hdr, rd_noffset, arch, images->verify))
943 /* get ramdisk image data address and length */
944 if (fit_image_get_data (fit_hdr, rd_noffset, &data, &size)) {
945 puts ("Could not find ramdisk subimage data!\n");
946 show_boot_progress (-127);
949 show_boot_progress (128);
951 rd_data = (ulong)data;
954 if (fit_image_get_load (fit_hdr, rd_noffset, &rd_load)) {
955 puts ("Can't get ramdisk subimage load address!\n");
956 show_boot_progress (-129);
959 show_boot_progress (129);
961 images->fit_hdr_rd = fit_hdr;
962 images->fit_uname_rd = fit_uname_ramdisk;
963 images->fit_noffset_rd = rd_noffset;
967 puts ("Wrong Ramdisk Image Format\n");
968 rd_data = rd_len = rd_load = 0;
971 } else if (images->legacy_hdr_valid &&
972 image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
974 * Now check if we have a legacy mult-component image,
975 * get second entry data start address and len.
977 show_boot_progress (13);
978 printf ("## Loading init Ramdisk from multi component "
979 "Legacy Image at %08lx ...\n",
980 (ulong)images->legacy_hdr_os);
982 image_multi_getimg (images->legacy_hdr_os, 1, &rd_data, &rd_len);
987 show_boot_progress (14);
988 rd_len = rd_data = 0;
992 debug ("## No init Ramdisk\n");
995 *rd_end = rd_data + rd_len;
997 debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
1003 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
1005 * boot_ramdisk_high - relocate init ramdisk
1006 * @lmb: pointer to lmb handle, will be used for memory mgmt
1007 * @rd_data: ramdisk data start address
1008 * @rd_len: ramdisk data length
1009 * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
1010 * start address (after possible relocation)
1011 * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
1012 * end address (after possible relocation)
1014 * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
1015 * variable and if requested ramdisk data is moved to a specified location.
1017 * Initrd_start and initrd_end are set to final (after relocation) ramdisk
1018 * start/end addresses if ramdisk image start and len were provided,
1019 * otherwise set initrd_start and initrd_end set to zeros.
1025 int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
1026 ulong *initrd_start, ulong *initrd_end)
1030 int initrd_copy_to_ram = 1;
1032 if ((s = getenv ("initrd_high")) != NULL) {
1033 /* a value of "no" or a similar string will act like 0,
1034 * turning the "load high" feature off. This is intentional.
1036 initrd_high = simple_strtoul (s, NULL, 16);
1037 if (initrd_high == ~0)
1038 initrd_copy_to_ram = 0;
1040 /* not set, no restrictions to load high */
1045 #ifdef CONFIG_LOGBUFFER
1046 /* Prevent initrd from overwriting logbuffer */
1047 lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
1050 debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
1051 initrd_high, initrd_copy_to_ram);
1054 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
1055 debug (" in-place initrd\n");
1056 *initrd_start = rd_data;
1057 *initrd_end = rd_data + rd_len;
1058 lmb_reserve(lmb, rd_data, rd_len);
1061 *initrd_start = (ulong)lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
1063 *initrd_start = (ulong)lmb_alloc (lmb, rd_len, 0x1000);
1065 if (*initrd_start == 0) {
1066 puts ("ramdisk - allocation error\n");
1069 show_boot_progress (12);
1071 *initrd_end = *initrd_start + rd_len;
1072 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
1073 *initrd_start, *initrd_end);
1075 memmove_wd ((void *)*initrd_start,
1076 (void *)rd_data, rd_len, CHUNKSZ);
1084 debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
1085 *initrd_start, *initrd_end);
1092 #endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */
1094 #ifdef CONFIG_OF_LIBFDT
1095 static void fdt_error (const char *msg)
1099 puts (" - must RESET the board to recover.\n");
1102 static const image_header_t *image_get_fdt (ulong fdt_addr)
1104 const image_header_t *fdt_hdr = (const image_header_t *)fdt_addr;
1106 image_print_contents (fdt_hdr);
1108 puts (" Verifying Checksum ... ");
1109 if (!image_check_hcrc (fdt_hdr)) {
1110 fdt_error ("fdt header checksum invalid");
1114 if (!image_check_dcrc (fdt_hdr)) {
1115 fdt_error ("fdt checksum invalid");
1120 if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) {
1121 fdt_error ("uImage is not a fdt");
1124 if (image_get_comp (fdt_hdr) != IH_COMP_NONE) {
1125 fdt_error ("uImage is compressed");
1128 if (fdt_check_header ((char *)image_get_data (fdt_hdr)) != 0) {
1129 fdt_error ("uImage data is not a fdt");
1136 * fit_check_fdt - verify FIT format FDT subimage
1137 * @fit_hdr: pointer to the FIT header
1138 * fdt_noffset: FDT subimage node offset within FIT image
1139 * @verify: data CRC verification flag
1141 * fit_check_fdt() verifies integrity of the FDT subimage and from
1142 * specified FIT image.
1148 #if defined(CONFIG_FIT)
1149 static int fit_check_fdt (const void *fit, int fdt_noffset, int verify)
1151 fit_image_print (fit, fdt_noffset, " ");
1154 puts (" Verifying Hash Integrity ... ");
1155 if (!fit_image_check_hashes (fit, fdt_noffset)) {
1156 fdt_error ("Bad Data Hash");
1162 if (!fit_image_check_type (fit, fdt_noffset, IH_TYPE_FLATDT)) {
1163 fdt_error ("Not a FDT image");
1167 if (!fit_image_check_comp (fit, fdt_noffset, IH_COMP_NONE)) {
1168 fdt_error ("FDT image is compressed");
1174 #endif /* CONFIG_FIT */
1176 #ifndef CONFIG_SYS_FDT_PAD
1177 #define CONFIG_SYS_FDT_PAD 0x3000
1180 #if defined(CONFIG_OF_LIBFDT)
1182 * boot_fdt_add_mem_rsv_regions - Mark the memreserve sections as unusable
1183 * @lmb: pointer to lmb handle, will be used for memory mgmt
1184 * @fdt_blob: pointer to fdt blob base address
1186 * Adds the memreserve regions in the dtb to the lmb block. Adding the
1187 * memreserve regions prevents u-boot from using them to store the initrd
1190 void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob)
1192 uint64_t addr, size;
1195 if (fdt_check_header (fdt_blob) != 0)
1198 total = fdt_num_mem_rsv(fdt_blob);
1199 for (i = 0; i < total; i++) {
1200 if (fdt_get_mem_rsv(fdt_blob, i, &addr, &size) != 0)
1202 printf(" reserving fdt memory region: addr=%llx size=%llx\n",
1203 (unsigned long long)addr, (unsigned long long)size);
1204 lmb_reserve(lmb, addr, size);
1209 * boot_relocate_fdt - relocate flat device tree
1210 * @lmb: pointer to lmb handle, will be used for memory mgmt
1211 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1212 * @of_size: pointer to a ulong variable, will hold fdt length
1214 * boot_relocate_fdt() allocates a region of memory within the bootmap and
1215 * relocates the of_flat_tree into that region, even if the fdt is already in
1216 * the bootmap. It also expands the size of the fdt by CONFIG_SYS_FDT_PAD
1219 * of_flat_tree and of_size are set to final (after relocation) values
1225 int boot_relocate_fdt (struct lmb *lmb, char **of_flat_tree, ulong *of_size)
1227 void *fdt_blob = *of_flat_tree;
1232 int disable_relocation = 0;
1238 if (fdt_check_header (fdt_blob) != 0) {
1239 fdt_error ("image is not a fdt");
1243 /* position on a 4K boundary before the alloc_current */
1244 /* Pad the FDT by a specified amount */
1245 of_len = *of_size + CONFIG_SYS_FDT_PAD;
1247 /* If fdt_high is set use it to select the relocation address */
1248 fdt_high = getenv("fdt_high");
1250 void *desired_addr = (void *)simple_strtoul(fdt_high, NULL, 16);
1252 if (((ulong) desired_addr) == ~0UL) {
1253 /* All ones means use fdt in place */
1254 desired_addr = fdt_blob;
1255 disable_relocation = 1;
1259 (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
1263 if (desired_addr && of_start != desired_addr) {
1264 puts("Failed using fdt_high value for Device Tree");
1269 (void *)(ulong) lmb_alloc(lmb, of_len, 0x1000);
1273 (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
1274 getenv_bootm_mapsize()
1275 + getenv_bootm_low());
1278 if (of_start == 0) {
1279 puts("device tree - allocation error\n");
1283 if (disable_relocation) {
1284 /* We assume there is space after the existing fdt to use for padding */
1285 fdt_set_totalsize(of_start, of_len);
1286 printf(" Using Device Tree in place at %p, end %p\n",
1287 of_start, of_start + of_len - 1);
1289 debug ("## device tree at %p ... %p (len=%ld [0x%lX])\n",
1290 fdt_blob, fdt_blob + *of_size - 1, of_len, of_len);
1292 printf (" Loading Device Tree to %p, end %p ... ",
1293 of_start, of_start + of_len - 1);
1295 err = fdt_open_into (fdt_blob, of_start, of_len);
1297 fdt_error ("fdt move failed");
1303 *of_flat_tree = of_start;
1306 set_working_fdt_addr(*of_flat_tree);
1312 #endif /* CONFIG_OF_LIBFDT */
1315 * boot_get_fdt - main fdt handling routine
1316 * @argc: command argument count
1317 * @argv: command argument list
1318 * @images: pointer to the bootm images structure
1319 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1320 * @of_size: pointer to a ulong variable, will hold fdt length
1322 * boot_get_fdt() is responsible for finding a valid flat device tree image.
1323 * Curently supported are the following ramdisk sources:
1324 * - multicomponent kernel/ramdisk image,
1325 * - commandline provided address of decicated ramdisk image.
1328 * 0, if fdt image was found and valid, or skipped
1329 * of_flat_tree and of_size are set to fdt start address and length if
1330 * fdt image is found and valid
1332 * 1, if fdt image is found but corrupted
1333 * of_flat_tree and of_size are set to 0 if no fdt exists
1335 int boot_get_fdt (int flag, int argc, char * const argv[], bootm_headers_t *images,
1336 char **of_flat_tree, ulong *of_size)
1338 const image_header_t *fdt_hdr;
1340 char *fdt_blob = NULL;
1341 ulong image_start, image_end;
1342 ulong load_start, load_end;
1343 #if defined(CONFIG_FIT)
1345 const char *fit_uname_config = NULL;
1346 const char *fit_uname_fdt = NULL;
1354 *of_flat_tree = NULL;
1357 if (argc > 3 || genimg_has_config (images)) {
1358 #if defined(CONFIG_FIT)
1361 * If the FDT blob comes from the FIT image and the
1362 * FIT image address is omitted in the command line
1363 * argument, try to use ramdisk or os FIT image
1364 * address or default load address.
1366 if (images->fit_uname_rd)
1367 default_addr = (ulong)images->fit_hdr_rd;
1368 else if (images->fit_uname_os)
1369 default_addr = (ulong)images->fit_hdr_os;
1371 default_addr = load_addr;
1373 if (fit_parse_conf (argv[3], default_addr,
1374 &fdt_addr, &fit_uname_config)) {
1375 debug ("* fdt: config '%s' from image at 0x%08lx\n",
1376 fit_uname_config, fdt_addr);
1377 } else if (fit_parse_subimage (argv[3], default_addr,
1378 &fdt_addr, &fit_uname_fdt)) {
1379 debug ("* fdt: subimage '%s' from image at 0x%08lx\n",
1380 fit_uname_fdt, fdt_addr);
1384 fdt_addr = simple_strtoul(argv[3], NULL, 16);
1385 debug ("* fdt: cmdline image address = 0x%08lx\n",
1388 #if defined(CONFIG_FIT)
1390 /* use FIT configuration provided in first bootm
1393 fdt_addr = (ulong)images->fit_hdr_os;
1394 fit_uname_config = images->fit_uname_cfg;
1395 debug ("* fdt: using config '%s' from image at 0x%08lx\n",
1396 fit_uname_config, fdt_addr);
1399 * Check whether configuration has FDT blob defined,
1400 * if not quit silently.
1402 fit_hdr = (void *)fdt_addr;
1403 cfg_noffset = fit_conf_get_node (fit_hdr,
1405 if (cfg_noffset < 0) {
1406 debug ("* fdt: no such config\n");
1410 fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
1412 if (fdt_noffset < 0) {
1413 debug ("* fdt: no fdt in config\n");
1419 debug ("## Checking for 'FDT'/'FDT Image' at %08lx\n",
1422 /* copy from dataflash if needed */
1423 fdt_addr = genimg_get_image (fdt_addr);
1426 * Check if there is an FDT image at the
1427 * address provided in the second bootm argument
1428 * check image type, for FIT images get a FIT node.
1430 switch (genimg_get_format ((void *)fdt_addr)) {
1431 case IMAGE_FORMAT_LEGACY:
1432 /* verify fdt_addr points to a valid image header */
1433 printf ("## Flattened Device Tree from Legacy Image at %08lx\n",
1435 fdt_hdr = image_get_fdt (fdt_addr);
1440 * move image data to the load address,
1441 * make sure we don't overwrite initial image
1443 image_start = (ulong)fdt_hdr;
1444 image_end = image_get_image_end (fdt_hdr);
1446 load_start = image_get_load (fdt_hdr);
1447 load_end = load_start + image_get_data_size (fdt_hdr);
1449 if ((load_start < image_end) && (load_end > image_start)) {
1450 fdt_error ("fdt overwritten");
1454 debug (" Loading FDT from 0x%08lx to 0x%08lx\n",
1455 image_get_data (fdt_hdr), load_start);
1457 memmove ((void *)load_start,
1458 (void *)image_get_data (fdt_hdr),
1459 image_get_data_size (fdt_hdr));
1461 fdt_blob = (char *)load_start;
1463 case IMAGE_FORMAT_FIT:
1465 * This case will catch both: new uImage format
1466 * (libfdt based) and raw FDT blob (also libfdt
1469 #if defined(CONFIG_FIT)
1470 /* check FDT blob vs FIT blob */
1471 if (fit_check_format ((const void *)fdt_addr)) {
1475 fit_hdr = (void *)fdt_addr;
1476 printf ("## Flattened Device Tree from FIT Image at %08lx\n",
1479 if (!fit_uname_fdt) {
1481 * no FDT blob image node unit name,
1482 * try to get config node first. If
1483 * config unit node name is NULL
1484 * fit_conf_get_node() will try to
1485 * find default config node
1487 cfg_noffset = fit_conf_get_node (fit_hdr,
1490 if (cfg_noffset < 0) {
1491 fdt_error ("Could not find configuration node\n");
1495 fit_uname_config = fdt_get_name (fit_hdr,
1497 printf (" Using '%s' configuration\n",
1500 fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
1502 fit_uname_fdt = fit_get_name (fit_hdr,
1505 /* get FDT component image node offset */
1506 fdt_noffset = fit_image_get_node (fit_hdr,
1509 if (fdt_noffset < 0) {
1510 fdt_error ("Could not find subimage node\n");
1514 printf (" Trying '%s' FDT blob subimage\n",
1517 if (!fit_check_fdt (fit_hdr, fdt_noffset,
1521 /* get ramdisk image data address and length */
1522 if (fit_image_get_data (fit_hdr, fdt_noffset,
1524 fdt_error ("Could not find FDT subimage data");
1528 /* verift that image data is a proper FDT blob */
1529 if (fdt_check_header ((char *)data) != 0) {
1530 fdt_error ("Subimage data is not a FTD");
1535 * move image data to the load address,
1536 * make sure we don't overwrite initial image
1538 image_start = (ulong)fit_hdr;
1539 image_end = fit_get_end (fit_hdr);
1541 if (fit_image_get_load (fit_hdr, fdt_noffset,
1542 &load_start) == 0) {
1543 load_end = load_start + size;
1545 if ((load_start < image_end) &&
1546 (load_end > image_start)) {
1547 fdt_error ("FDT overwritten");
1551 printf (" Loading FDT from 0x%08lx to 0x%08lx\n",
1552 (ulong)data, load_start);
1554 memmove ((void *)load_start,
1555 (void *)data, size);
1557 fdt_blob = (char *)load_start;
1559 fdt_blob = (char *)data;
1562 images->fit_hdr_fdt = fit_hdr;
1563 images->fit_uname_fdt = fit_uname_fdt;
1564 images->fit_noffset_fdt = fdt_noffset;
1572 fdt_blob = (char *)fdt_addr;
1573 debug ("* fdt: raw FDT blob\n");
1574 printf ("## Flattened Device Tree blob at %08lx\n", (long)fdt_blob);
1578 puts ("ERROR: Did not find a cmdline Flattened Device Tree\n");
1582 printf(" Booting using the fdt blob at 0x%p\n", fdt_blob);
1584 } else if (images->legacy_hdr_valid &&
1585 image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1587 ulong fdt_data, fdt_len;
1590 * Now check if we have a legacy multi-component image,
1591 * get second entry data start address and len.
1593 printf ("## Flattened Device Tree from multi "
1594 "component Image at %08lX\n",
1595 (ulong)images->legacy_hdr_os);
1597 image_multi_getimg (images->legacy_hdr_os, 2, &fdt_data, &fdt_len);
1600 fdt_blob = (char *)fdt_data;
1601 printf(" Booting using the fdt at 0x%p\n", fdt_blob);
1603 if (fdt_check_header (fdt_blob) != 0) {
1604 fdt_error ("image is not a fdt");
1608 if (fdt_totalsize(fdt_blob) != fdt_len) {
1609 fdt_error ("fdt size != image size");
1613 debug ("## No Flattened Device Tree\n");
1617 debug ("## No Flattened Device Tree\n");
1621 *of_flat_tree = fdt_blob;
1622 *of_size = fdt_totalsize(fdt_blob);
1623 debug (" of_flat_tree at 0x%08lx size 0x%08lx\n",
1624 (ulong)*of_flat_tree, *of_size);
1633 #endif /* CONFIG_OF_LIBFDT */
1635 #ifdef CONFIG_SYS_BOOT_GET_CMDLINE
1637 * boot_get_cmdline - allocate and initialize kernel cmdline
1638 * @lmb: pointer to lmb handle, will be used for memory mgmt
1639 * @cmd_start: pointer to a ulong variable, will hold cmdline start
1640 * @cmd_end: pointer to a ulong variable, will hold cmdline end
1642 * boot_get_cmdline() allocates space for kernel command line below
1643 * BOOTMAPSZ + getenv_bootm_low() address. If "bootargs" U-boot environemnt
1644 * variable is present its contents is copied to allocated kernel
1651 int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end)
1656 cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf,
1657 getenv_bootm_mapsize() + getenv_bootm_low());
1659 if (cmdline == NULL)
1662 if ((s = getenv("bootargs")) == NULL)
1667 *cmd_start = (ulong) & cmdline[0];
1668 *cmd_end = *cmd_start + strlen(cmdline);
1670 debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
1674 #endif /* CONFIG_SYS_BOOT_GET_CMDLINE */
1676 #ifdef CONFIG_SYS_BOOT_GET_KBD
1678 * boot_get_kbd - allocate and initialize kernel copy of board info
1679 * @lmb: pointer to lmb handle, will be used for memory mgmt
1680 * @kbd: double pointer to board info data
1682 * boot_get_kbd() allocates space for kernel copy of board info data below
1683 * BOOTMAPSZ + getenv_bootm_low() address and kernel board info is initialized
1684 * with the current u-boot board info data.
1690 int boot_get_kbd (struct lmb *lmb, bd_t **kbd)
1692 *kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
1693 getenv_bootm_mapsize() + getenv_bootm_low());
1699 debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
1701 #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
1702 do_bdinfo(NULL, 0, 0, NULL);
1707 #endif /* CONFIG_SYS_BOOT_GET_KBD */
1708 #endif /* !USE_HOSTCC */
1710 #if defined(CONFIG_FIT)
1711 /*****************************************************************************/
1712 /* New uImage format routines */
1713 /*****************************************************************************/
1715 static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr,
1716 ulong *addr, const char **name)
1723 sep = strchr (spec, sepc);
1726 *addr = simple_strtoul (spec, NULL, 16);
1736 * fit_parse_conf - parse FIT configuration spec
1737 * @spec: input string, containing configuration spec
1738 * @add_curr: current image address (to be used as a possible default)
1739 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1741 * @conf_name double pointer to a char, will hold pointer to a configuration
1744 * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
1745 * where <addr> is a FIT image address that contains configuration
1746 * with a <conf> unit name.
1748 * Address part is optional, and if omitted default add_curr will
1752 * 1 if spec is a valid configuration string,
1753 * addr and conf_name are set accordingly
1756 inline int fit_parse_conf (const char *spec, ulong addr_curr,
1757 ulong *addr, const char **conf_name)
1759 return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
1763 * fit_parse_subimage - parse FIT subimage spec
1764 * @spec: input string, containing subimage spec
1765 * @add_curr: current image address (to be used as a possible default)
1766 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1768 * @image_name: double pointer to a char, will hold pointer to a subimage name
1770 * fit_parse_subimage() expects subimage spec in the for of
1771 * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
1772 * subimage with a <subimg> unit name.
1774 * Address part is optional, and if omitted default add_curr will
1778 * 1 if spec is a valid subimage string,
1779 * addr and image_name are set accordingly
1782 inline int fit_parse_subimage (const char *spec, ulong addr_curr,
1783 ulong *addr, const char **image_name)
1785 return fit_parse_spec (spec, ':', addr_curr, addr, image_name);
1787 #endif /* !USE_HOSTCC */
1789 static void fit_get_debug (const void *fit, int noffset,
1790 char *prop_name, int err)
1792 debug ("Can't get '%s' property from FIT 0x%08lx, "
1793 "node: offset %d, name %s (%s)\n",
1794 prop_name, (ulong)fit, noffset,
1795 fit_get_name (fit, noffset, NULL),
1796 fdt_strerror (err));
1800 * fit_print_contents - prints out the contents of the FIT format image
1801 * @fit: pointer to the FIT format image header
1802 * @p: pointer to prefix string
1804 * fit_print_contents() formats a multi line FIT image contents description.
1805 * The routine prints out FIT image properties (root node level) follwed by
1806 * the details of each component image.
1809 * no returned results
1811 void fit_print_contents (const void *fit)
1822 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1832 /* Root node properties */
1833 ret = fit_get_desc (fit, 0, &desc);
1834 printf ("%sFIT description: ", p);
1836 printf ("unavailable\n");
1838 printf ("%s\n", desc);
1840 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1841 ret = fit_get_timestamp (fit, 0, ×tamp);
1842 printf ("%sCreated: ", p);
1844 printf ("unavailable\n");
1846 genimg_print_time (timestamp);
1849 /* Find images parent node offset */
1850 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
1851 if (images_noffset < 0) {
1852 printf ("Can't find images parent node '%s' (%s)\n",
1853 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
1857 /* Process its subnodes, print out component images details */
1858 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
1859 (noffset >= 0) && (ndepth > 0);
1860 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1863 * Direct child node of the images parent node,
1864 * i.e. component image node.
1866 printf ("%s Image %u (%s)\n", p, count++,
1867 fit_get_name(fit, noffset, NULL));
1869 fit_image_print (fit, noffset, p);
1873 /* Find configurations parent node offset */
1874 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
1875 if (confs_noffset < 0) {
1876 debug ("Can't get configurations parent node '%s' (%s)\n",
1877 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
1881 /* get default configuration unit name from default property */
1882 uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL);
1884 printf ("%s Default Configuration: '%s'\n", p, uname);
1886 /* Process its subnodes, print out configurations details */
1887 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth);
1888 (noffset >= 0) && (ndepth > 0);
1889 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1892 * Direct child node of the configurations parent node,
1893 * i.e. configuration node.
1895 printf ("%s Configuration %u (%s)\n", p, count++,
1896 fit_get_name(fit, noffset, NULL));
1898 fit_conf_print (fit, noffset, p);
1904 * fit_image_print - prints out the FIT component image details
1905 * @fit: pointer to the FIT format image header
1906 * @image_noffset: offset of the component image node
1907 * @p: pointer to prefix string
1909 * fit_image_print() lists all mandatory properies for the processed component
1910 * image. If present, hash nodes are printed out as well. Load
1911 * address for images of type firmware is also printed out. Since the load
1912 * address is not mandatory for firmware images, it will be output as
1913 * "unavailable" when not present.
1916 * no returned results
1918 void fit_image_print (const void *fit, int image_noffset, const char *p)
1921 uint8_t type, arch, os, comp;
1929 /* Mandatory properties */
1930 ret = fit_get_desc (fit, image_noffset, &desc);
1931 printf ("%s Description: ", p);
1933 printf ("unavailable\n");
1935 printf ("%s\n", desc);
1937 fit_image_get_type (fit, image_noffset, &type);
1938 printf ("%s Type: %s\n", p, genimg_get_type_name (type));
1940 fit_image_get_comp (fit, image_noffset, &comp);
1941 printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp));
1943 ret = fit_image_get_data (fit, image_noffset, &data, &size);
1946 printf ("%s Data Start: ", p);
1948 printf ("unavailable\n");
1950 printf ("0x%08lx\n", (ulong)data);
1953 printf ("%s Data Size: ", p);
1955 printf ("unavailable\n");
1957 genimg_print_size (size);
1959 /* Remaining, type dependent properties */
1960 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
1961 (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
1962 (type == IH_TYPE_FLATDT)) {
1963 fit_image_get_arch (fit, image_noffset, &arch);
1964 printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch));
1967 if (type == IH_TYPE_KERNEL) {
1968 fit_image_get_os (fit, image_noffset, &os);
1969 printf ("%s OS: %s\n", p, genimg_get_os_name (os));
1972 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
1973 (type == IH_TYPE_FIRMWARE)) {
1974 ret = fit_image_get_load (fit, image_noffset, &load);
1975 printf ("%s Load Address: ", p);
1977 printf ("unavailable\n");
1979 printf ("0x%08lx\n", load);
1982 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
1983 fit_image_get_entry (fit, image_noffset, &entry);
1984 printf ("%s Entry Point: ", p);
1986 printf ("unavailable\n");
1988 printf ("0x%08lx\n", entry);
1991 /* Process all hash subnodes of the component image node */
1992 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
1993 (noffset >= 0) && (ndepth > 0);
1994 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1996 /* Direct child node of the component image node */
1997 fit_image_print_hash (fit, noffset, p);
2003 * fit_image_print_hash - prints out the hash node details
2004 * @fit: pointer to the FIT format image header
2005 * @noffset: offset of the hash node
2006 * @p: pointer to prefix string
2008 * fit_image_print_hash() lists properies for the processed hash node
2011 * no returned results
2013 void fit_image_print_hash (const void *fit, int noffset, const char *p)
2021 * Check subnode name, must be equal to "hash".
2022 * Multiple hash nodes require unique unit node
2023 * names, e.g. hash@1, hash@2, etc.
2025 if (strncmp (fit_get_name(fit, noffset, NULL),
2027 strlen(FIT_HASH_NODENAME)) != 0)
2030 debug ("%s Hash node: '%s'\n", p,
2031 fit_get_name (fit, noffset, NULL));
2033 printf ("%s Hash algo: ", p);
2034 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2035 printf ("invalid/unsupported\n");
2038 printf ("%s\n", algo);
2040 ret = fit_image_hash_get_value (fit, noffset, &value,
2042 printf ("%s Hash value: ", p);
2044 printf ("unavailable\n");
2046 for (i = 0; i < value_len; i++)
2047 printf ("%02x", value[i]);
2051 debug ("%s Hash len: %d\n", p, value_len);
2055 * fit_get_desc - get node description property
2056 * @fit: pointer to the FIT format image header
2057 * @noffset: node offset
2058 * @desc: double pointer to the char, will hold pointer to the descrption
2060 * fit_get_desc() reads description property from a given node, if
2061 * description is found pointer to it is returened in third call argument.
2067 int fit_get_desc (const void *fit, int noffset, char **desc)
2071 *desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len);
2072 if (*desc == NULL) {
2073 fit_get_debug (fit, noffset, FIT_DESC_PROP, len);
2081 * fit_get_timestamp - get node timestamp property
2082 * @fit: pointer to the FIT format image header
2083 * @noffset: node offset
2084 * @timestamp: pointer to the time_t, will hold read timestamp
2086 * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
2087 * is found and has a correct size its value is retured in third call
2092 * -1, on property read failure
2093 * -2, on wrong timestamp size
2095 int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp)
2100 data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len);
2102 fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len);
2105 if (len != sizeof (uint32_t)) {
2106 debug ("FIT timestamp with incorrect size of (%u)\n", len);
2110 *timestamp = uimage_to_cpu (*((uint32_t *)data));
2115 * fit_image_get_node - get node offset for component image of a given unit name
2116 * @fit: pointer to the FIT format image header
2117 * @image_uname: component image node unit name
2119 * fit_image_get_node() finds a component image (withing the '/images'
2120 * node) of a provided unit name. If image is found its node offset is
2121 * returned to the caller.
2124 * image node offset when found (>=0)
2125 * negative number on failure (FDT_ERR_* code)
2127 int fit_image_get_node (const void *fit, const char *image_uname)
2129 int noffset, images_noffset;
2131 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2132 if (images_noffset < 0) {
2133 debug ("Can't find images parent node '%s' (%s)\n",
2134 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2135 return images_noffset;
2138 noffset = fdt_subnode_offset (fit, images_noffset, image_uname);
2140 debug ("Can't get node offset for image unit name: '%s' (%s)\n",
2141 image_uname, fdt_strerror (noffset));
2148 * fit_image_get_os - get os id for a given component image node
2149 * @fit: pointer to the FIT format image header
2150 * @noffset: component image node offset
2151 * @os: pointer to the uint8_t, will hold os numeric id
2153 * fit_image_get_os() finds os property in a given component image node.
2154 * If the property is found, its (string) value is translated to the numeric
2155 * id which is returned to the caller.
2161 int fit_image_get_os (const void *fit, int noffset, uint8_t *os)
2166 /* Get OS name from property data */
2167 data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len);
2169 fit_get_debug (fit, noffset, FIT_OS_PROP, len);
2174 /* Translate OS name to id */
2175 *os = genimg_get_os_id (data);
2180 * fit_image_get_arch - get arch id for a given component image node
2181 * @fit: pointer to the FIT format image header
2182 * @noffset: component image node offset
2183 * @arch: pointer to the uint8_t, will hold arch numeric id
2185 * fit_image_get_arch() finds arch property in a given component image node.
2186 * If the property is found, its (string) value is translated to the numeric
2187 * id which is returned to the caller.
2193 int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch)
2198 /* Get architecture name from property data */
2199 data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len);
2201 fit_get_debug (fit, noffset, FIT_ARCH_PROP, len);
2206 /* Translate architecture name to id */
2207 *arch = genimg_get_arch_id (data);
2212 * fit_image_get_type - get type id for a given component image node
2213 * @fit: pointer to the FIT format image header
2214 * @noffset: component image node offset
2215 * @type: pointer to the uint8_t, will hold type numeric id
2217 * fit_image_get_type() finds type property in a given component image node.
2218 * If the property is found, its (string) value is translated to the numeric
2219 * id which is returned to the caller.
2225 int fit_image_get_type (const void *fit, int noffset, uint8_t *type)
2230 /* Get image type name from property data */
2231 data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len);
2233 fit_get_debug (fit, noffset, FIT_TYPE_PROP, len);
2238 /* Translate image type name to id */
2239 *type = genimg_get_type_id (data);
2244 * fit_image_get_comp - get comp id for a given component image node
2245 * @fit: pointer to the FIT format image header
2246 * @noffset: component image node offset
2247 * @comp: pointer to the uint8_t, will hold comp numeric id
2249 * fit_image_get_comp() finds comp property in a given component image node.
2250 * If the property is found, its (string) value is translated to the numeric
2251 * id which is returned to the caller.
2257 int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp)
2262 /* Get compression name from property data */
2263 data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len);
2265 fit_get_debug (fit, noffset, FIT_COMP_PROP, len);
2270 /* Translate compression name to id */
2271 *comp = genimg_get_comp_id (data);
2276 * fit_image_get_load - get load address property for a given component image node
2277 * @fit: pointer to the FIT format image header
2278 * @noffset: component image node offset
2279 * @load: pointer to the uint32_t, will hold load address
2281 * fit_image_get_load() finds load address property in a given component image node.
2282 * If the property is found, its value is returned to the caller.
2288 int fit_image_get_load (const void *fit, int noffset, ulong *load)
2291 const uint32_t *data;
2293 data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len);
2295 fit_get_debug (fit, noffset, FIT_LOAD_PROP, len);
2299 *load = uimage_to_cpu (*data);
2304 * fit_image_get_entry - get entry point address property for a given component image node
2305 * @fit: pointer to the FIT format image header
2306 * @noffset: component image node offset
2307 * @entry: pointer to the uint32_t, will hold entry point address
2309 * fit_image_get_entry() finds entry point address property in a given component image node.
2310 * If the property is found, its value is returned to the caller.
2316 int fit_image_get_entry (const void *fit, int noffset, ulong *entry)
2319 const uint32_t *data;
2321 data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len);
2323 fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len);
2327 *entry = uimage_to_cpu (*data);
2332 * fit_image_get_data - get data property and its size for a given component image node
2333 * @fit: pointer to the FIT format image header
2334 * @noffset: component image node offset
2335 * @data: double pointer to void, will hold data property's data address
2336 * @size: pointer to size_t, will hold data property's data size
2338 * fit_image_get_data() finds data property in a given component image node.
2339 * If the property is found its data start address and size are returned to
2346 int fit_image_get_data (const void *fit, int noffset,
2347 const void **data, size_t *size)
2351 *data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len);
2352 if (*data == NULL) {
2353 fit_get_debug (fit, noffset, FIT_DATA_PROP, len);
2363 * fit_image_hash_get_algo - get hash algorithm name
2364 * @fit: pointer to the FIT format image header
2365 * @noffset: hash node offset
2366 * @algo: double pointer to char, will hold pointer to the algorithm name
2368 * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
2369 * If the property is found its data start address is returned to the caller.
2375 int fit_image_hash_get_algo (const void *fit, int noffset, char **algo)
2379 *algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len);
2380 if (*algo == NULL) {
2381 fit_get_debug (fit, noffset, FIT_ALGO_PROP, len);
2389 * fit_image_hash_get_value - get hash value and length
2390 * @fit: pointer to the FIT format image header
2391 * @noffset: hash node offset
2392 * @value: double pointer to uint8_t, will hold address of a hash value data
2393 * @value_len: pointer to an int, will hold hash data length
2395 * fit_image_hash_get_value() finds hash value property in a given hash node.
2396 * If the property is found its data start address and size are returned to
2403 int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value,
2408 *value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len);
2409 if (*value == NULL) {
2410 fit_get_debug (fit, noffset, FIT_VALUE_PROP, len);
2420 * fit_set_timestamp - set node timestamp property
2421 * @fit: pointer to the FIT format image header
2422 * @noffset: node offset
2423 * @timestamp: timestamp value to be set
2425 * fit_set_timestamp() attempts to set timestamp property in the requested
2426 * node and returns operation status to the caller.
2430 * -1, on property read failure
2432 int fit_set_timestamp (void *fit, int noffset, time_t timestamp)
2437 t = cpu_to_uimage (timestamp);
2438 ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t,
2441 printf ("Can't set '%s' property for '%s' node (%s)\n",
2442 FIT_TIMESTAMP_PROP, fit_get_name (fit, noffset, NULL),
2443 fdt_strerror (ret));
2451 * calculate_hash - calculate and return hash for provided input data
2452 * @data: pointer to the input data
2453 * @data_len: data length
2454 * @algo: requested hash algorithm
2455 * @value: pointer to the char, will hold hash value data (caller must
2456 * allocate enough free space)
2457 * value_len: length of the calculated hash
2459 * calculate_hash() computes input data hash according to the requested algorithm.
2460 * Resulting hash value is placed in caller provided 'value' buffer, length
2461 * of the calculated hash is returned via value_len pointer argument.
2465 * -1, when algo is unsupported
2467 static int calculate_hash (const void *data, int data_len, const char *algo,
2468 uint8_t *value, int *value_len)
2470 if (strcmp (algo, "crc32") == 0 ) {
2471 *((uint32_t *)value) = crc32_wd (0, data, data_len,
2473 *((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value));
2475 } else if (strcmp (algo, "sha1") == 0 ) {
2476 sha1_csum_wd ((unsigned char *) data, data_len,
2477 (unsigned char *) value, CHUNKSZ_SHA1);
2479 } else if (strcmp (algo, "md5") == 0 ) {
2480 md5_wd ((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
2483 debug ("Unsupported hash alogrithm\n");
2491 * fit_set_hashes - process FIT component image nodes and calculate hashes
2492 * @fit: pointer to the FIT format image header
2494 * fit_set_hashes() adds hash values for all component images in the FIT blob.
2495 * Hashes are calculated for all component images which have hash subnodes
2496 * with algorithm property set to one of the supported hash algorithms.
2500 * libfdt error code, on failure
2502 int fit_set_hashes (void *fit)
2509 /* Find images parent node offset */
2510 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2511 if (images_noffset < 0) {
2512 printf ("Can't find images parent node '%s' (%s)\n",
2513 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2514 return images_noffset;
2517 /* Process its subnodes, print out component images details */
2518 for (ndepth = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
2519 (noffset >= 0) && (ndepth > 0);
2520 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2523 * Direct child node of the images parent node,
2524 * i.e. component image node.
2526 ret = fit_image_set_hashes (fit, noffset);
2536 * fit_image_set_hashes - calculate/set hashes for given component image node
2537 * @fit: pointer to the FIT format image header
2538 * @image_noffset: requested component image node
2540 * fit_image_set_hashes() adds hash values for an component image node. All
2541 * existing hash subnodes are checked, if algorithm property is set to one of
2542 * the supported hash algorithms, hash value is computed and corresponding
2543 * hash node property is set, for example:
2545 * Input component image node structure:
2547 * o image@1 (at image_noffset)
2548 * | - data = [binary data]
2552 * Output component image node structure:
2554 * o image@1 (at image_noffset)
2555 * | - data = [binary data]
2558 * |- value = sha1(data)
2564 int fit_image_set_hashes (void *fit, int image_noffset)
2569 uint8_t value[FIT_MAX_HASH_LEN];
2574 /* Get image data and data length */
2575 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
2576 printf ("Can't get image data/size\n");
2580 /* Process all hash subnodes of the component image node */
2581 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2582 (noffset >= 0) && (ndepth > 0);
2583 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2585 /* Direct child node of the component image node */
2588 * Check subnode name, must be equal to "hash".
2589 * Multiple hash nodes require unique unit node
2590 * names, e.g. hash@1, hash@2, etc.
2592 if (strncmp (fit_get_name(fit, noffset, NULL),
2594 strlen(FIT_HASH_NODENAME)) != 0) {
2595 /* Not a hash subnode, skip it */
2599 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2600 printf ("Can't get hash algo property for "
2601 "'%s' hash node in '%s' image node\n",
2602 fit_get_name (fit, noffset, NULL),
2603 fit_get_name (fit, image_noffset, NULL));
2607 if (calculate_hash (data, size, algo, value, &value_len)) {
2608 printf ("Unsupported hash algorithm (%s) for "
2609 "'%s' hash node in '%s' image node\n",
2610 algo, fit_get_name (fit, noffset, NULL),
2611 fit_get_name (fit, image_noffset, NULL));
2615 if (fit_image_hash_set_value (fit, noffset, value,
2617 printf ("Can't set hash value for "
2618 "'%s' hash node in '%s' image node\n",
2619 fit_get_name (fit, noffset, NULL),
2620 fit_get_name (fit, image_noffset, NULL));
2630 * fit_image_hash_set_value - set hash value in requested has node
2631 * @fit: pointer to the FIT format image header
2632 * @noffset: hash node offset
2633 * @value: hash value to be set
2634 * @value_len: hash value length
2636 * fit_image_hash_set_value() attempts to set hash value in a node at offset
2637 * given and returns operation status to the caller.
2643 int fit_image_hash_set_value (void *fit, int noffset, uint8_t *value,
2648 ret = fdt_setprop (fit, noffset, FIT_VALUE_PROP, value, value_len);
2650 printf ("Can't set hash '%s' property for '%s' node (%s)\n",
2651 FIT_VALUE_PROP, fit_get_name (fit, noffset, NULL),
2652 fdt_strerror (ret));
2658 #endif /* USE_HOSTCC */
2661 * fit_image_check_hashes - verify data intergity
2662 * @fit: pointer to the FIT format image header
2663 * @image_noffset: component image node offset
2665 * fit_image_check_hashes() goes over component image hash nodes,
2666 * re-calculates each data hash and compares with the value stored in hash
2670 * 1, if all hashes are valid
2671 * 0, otherwise (or on error)
2673 int fit_image_check_hashes (const void *fit, int image_noffset)
2680 uint8_t value[FIT_MAX_HASH_LEN];
2686 /* Get image data and data length */
2687 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
2688 printf ("Can't get image data/size\n");
2692 /* Process all hash subnodes of the component image node */
2693 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2694 (noffset >= 0) && (ndepth > 0);
2695 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2697 /* Direct child node of the component image node */
2700 * Check subnode name, must be equal to "hash".
2701 * Multiple hash nodes require unique unit node
2702 * names, e.g. hash@1, hash@2, etc.
2704 if (strncmp (fit_get_name(fit, noffset, NULL),
2706 strlen(FIT_HASH_NODENAME)) != 0)
2709 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2710 err_msg = " error!\nCan't get hash algo "
2714 printf ("%s", algo);
2716 if (fit_image_hash_get_value (fit, noffset, &fit_value,
2718 err_msg = " error!\nCan't get hash value "
2723 if (calculate_hash (data, size, algo, value, &value_len)) {
2724 err_msg = " error!\nUnsupported hash algorithm";
2728 if (value_len != fit_value_len) {
2729 err_msg = " error !\nBad hash value len";
2731 } else if (memcmp (value, fit_value, value_len) != 0) {
2732 err_msg = " error!\nBad hash value";
2742 printf ("%s for '%s' hash node in '%s' image node\n",
2743 err_msg, fit_get_name (fit, noffset, NULL),
2744 fit_get_name (fit, image_noffset, NULL));
2749 * fit_all_image_check_hashes - verify data intergity for all images
2750 * @fit: pointer to the FIT format image header
2752 * fit_all_image_check_hashes() goes over all images in the FIT and
2753 * for every images checks if all it's hashes are valid.
2756 * 1, if all hashes of all images are valid
2757 * 0, otherwise (or on error)
2759 int fit_all_image_check_hashes (const void *fit)
2766 /* Find images parent node offset */
2767 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2768 if (images_noffset < 0) {
2769 printf ("Can't find images parent node '%s' (%s)\n",
2770 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2774 /* Process all image subnodes, check hashes for each */
2775 printf ("## Checking hash(es) for FIT Image at %08lx ...\n",
2777 for (ndepth = 0, count = 0,
2778 noffset = fdt_next_node (fit, images_noffset, &ndepth);
2779 (noffset >= 0) && (ndepth > 0);
2780 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2783 * Direct child node of the images parent node,
2784 * i.e. component image node.
2786 printf (" Hash(es) for Image %u (%s): ", count++,
2787 fit_get_name (fit, noffset, NULL));
2789 if (!fit_image_check_hashes (fit, noffset))
2798 * fit_image_check_os - check whether image node is of a given os type
2799 * @fit: pointer to the FIT format image header
2800 * @noffset: component image node offset
2801 * @os: requested image os
2803 * fit_image_check_os() reads image os property and compares its numeric
2804 * id with the requested os. Comparison result is returned to the caller.
2807 * 1 if image is of given os type
2808 * 0 otherwise (or on error)
2810 int fit_image_check_os (const void *fit, int noffset, uint8_t os)
2814 if (fit_image_get_os (fit, noffset, &image_os))
2816 return (os == image_os);
2820 * fit_image_check_arch - check whether image node is of a given arch
2821 * @fit: pointer to the FIT format image header
2822 * @noffset: component image node offset
2823 * @arch: requested imagearch
2825 * fit_image_check_arch() reads image arch property and compares its numeric
2826 * id with the requested arch. Comparison result is returned to the caller.
2829 * 1 if image is of given arch
2830 * 0 otherwise (or on error)
2832 int fit_image_check_arch (const void *fit, int noffset, uint8_t arch)
2836 if (fit_image_get_arch (fit, noffset, &image_arch))
2838 return (arch == image_arch);
2842 * fit_image_check_type - check whether image node is of a given type
2843 * @fit: pointer to the FIT format image header
2844 * @noffset: component image node offset
2845 * @type: requested image type
2847 * fit_image_check_type() reads image type property and compares its numeric
2848 * id with the requested type. Comparison result is returned to the caller.
2851 * 1 if image is of given type
2852 * 0 otherwise (or on error)
2854 int fit_image_check_type (const void *fit, int noffset, uint8_t type)
2858 if (fit_image_get_type (fit, noffset, &image_type))
2860 return (type == image_type);
2864 * fit_image_check_comp - check whether image node uses given compression
2865 * @fit: pointer to the FIT format image header
2866 * @noffset: component image node offset
2867 * @comp: requested image compression type
2869 * fit_image_check_comp() reads image compression property and compares its
2870 * numeric id with the requested compression type. Comparison result is
2871 * returned to the caller.
2874 * 1 if image uses requested compression
2875 * 0 otherwise (or on error)
2877 int fit_image_check_comp (const void *fit, int noffset, uint8_t comp)
2881 if (fit_image_get_comp (fit, noffset, &image_comp))
2883 return (comp == image_comp);
2887 * fit_check_format - sanity check FIT image format
2888 * @fit: pointer to the FIT format image header
2890 * fit_check_format() runs a basic sanity FIT image verification.
2891 * Routine checks for mandatory properties, nodes, etc.
2897 int fit_check_format (const void *fit)
2899 /* mandatory / node 'description' property */
2900 if (fdt_getprop (fit, 0, FIT_DESC_PROP, NULL) == NULL) {
2901 debug ("Wrong FIT format: no description\n");
2905 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
2906 /* mandatory / node 'timestamp' property */
2907 if (fdt_getprop (fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
2908 debug ("Wrong FIT format: no timestamp\n");
2913 /* mandatory subimages parent '/images' node */
2914 if (fdt_path_offset (fit, FIT_IMAGES_PATH) < 0) {
2915 debug ("Wrong FIT format: no images parent node\n");
2923 * fit_conf_get_node - get node offset for configuration of a given unit name
2924 * @fit: pointer to the FIT format image header
2925 * @conf_uname: configuration node unit name
2927 * fit_conf_get_node() finds a configuration (withing the '/configurations'
2928 * parant node) of a provided unit name. If configuration is found its node offset
2929 * is returned to the caller.
2931 * When NULL is provided in second argument fit_conf_get_node() will search
2932 * for a default configuration node instead. Default configuration node unit name
2933 * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
2936 * configuration node offset when found (>=0)
2937 * negative number on failure (FDT_ERR_* code)
2939 int fit_conf_get_node (const void *fit, const char *conf_uname)
2941 int noffset, confs_noffset;
2944 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
2945 if (confs_noffset < 0) {
2946 debug ("Can't find configurations parent node '%s' (%s)\n",
2947 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
2948 return confs_noffset;
2951 if (conf_uname == NULL) {
2952 /* get configuration unit name from the default property */
2953 debug ("No configuration specified, trying default...\n");
2954 conf_uname = (char *)fdt_getprop (fit, confs_noffset, FIT_DEFAULT_PROP, &len);
2955 if (conf_uname == NULL) {
2956 fit_get_debug (fit, confs_noffset, FIT_DEFAULT_PROP, len);
2959 debug ("Found default configuration: '%s'\n", conf_uname);
2962 noffset = fdt_subnode_offset (fit, confs_noffset, conf_uname);
2964 debug ("Can't get node offset for configuration unit name: '%s' (%s)\n",
2965 conf_uname, fdt_strerror (noffset));
2971 static int __fit_conf_get_prop_node (const void *fit, int noffset,
2972 const char *prop_name)
2977 /* get kernel image unit name from configuration kernel property */
2978 uname = (char *)fdt_getprop (fit, noffset, prop_name, &len);
2982 return fit_image_get_node (fit, uname);
2986 * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
2987 * a given configuration
2988 * @fit: pointer to the FIT format image header
2989 * @noffset: configuration node offset
2991 * fit_conf_get_kernel_node() retrives kernel image node unit name from
2992 * configuration FIT_KERNEL_PROP property and translates it to the node
2996 * image node offset when found (>=0)
2997 * negative number on failure (FDT_ERR_* code)
2999 int fit_conf_get_kernel_node (const void *fit, int noffset)
3001 return __fit_conf_get_prop_node (fit, noffset, FIT_KERNEL_PROP);
3005 * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
3006 * a given configuration
3007 * @fit: pointer to the FIT format image header
3008 * @noffset: configuration node offset
3010 * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
3011 * configuration FIT_KERNEL_PROP property and translates it to the node
3015 * image node offset when found (>=0)
3016 * negative number on failure (FDT_ERR_* code)
3018 int fit_conf_get_ramdisk_node (const void *fit, int noffset)
3020 return __fit_conf_get_prop_node (fit, noffset, FIT_RAMDISK_PROP);
3024 * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
3025 * a given configuration
3026 * @fit: pointer to the FIT format image header
3027 * @noffset: configuration node offset
3029 * fit_conf_get_fdt_node() retrives fdt image node unit name from
3030 * configuration FIT_KERNEL_PROP property and translates it to the node
3034 * image node offset when found (>=0)
3035 * negative number on failure (FDT_ERR_* code)
3037 int fit_conf_get_fdt_node (const void *fit, int noffset)
3039 return __fit_conf_get_prop_node (fit, noffset, FIT_FDT_PROP);
3043 * fit_conf_print - prints out the FIT configuration details
3044 * @fit: pointer to the FIT format image header
3045 * @noffset: offset of the configuration node
3046 * @p: pointer to prefix string
3048 * fit_conf_print() lists all mandatory properies for the processed
3049 * configuration node.
3052 * no returned results
3054 void fit_conf_print (const void *fit, int noffset, const char *p)
3060 /* Mandatory properties */
3061 ret = fit_get_desc (fit, noffset, &desc);
3062 printf ("%s Description: ", p);
3064 printf ("unavailable\n");
3066 printf ("%s\n", desc);
3068 uname = (char *)fdt_getprop (fit, noffset, FIT_KERNEL_PROP, NULL);
3069 printf ("%s Kernel: ", p);
3071 printf ("unavailable\n");
3073 printf ("%s\n", uname);
3075 /* Optional properties */
3076 uname = (char *)fdt_getprop (fit, noffset, FIT_RAMDISK_PROP, NULL);
3078 printf ("%s Init Ramdisk: %s\n", p, uname);
3080 uname = (char *)fdt_getprop (fit, noffset, FIT_FDT_PROP, NULL);
3082 printf ("%s FDT: %s\n", p, uname);
3086 * fit_check_ramdisk - verify FIT format ramdisk subimage
3087 * @fit_hdr: pointer to the FIT ramdisk header
3088 * @rd_noffset: ramdisk subimage node offset within FIT image
3089 * @arch: requested ramdisk image architecture type
3090 * @verify: data CRC verification flag
3092 * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
3093 * specified FIT image.
3100 static int fit_check_ramdisk (const void *fit, int rd_noffset, uint8_t arch, int verify)
3102 fit_image_print (fit, rd_noffset, " ");
3105 puts (" Verifying Hash Integrity ... ");
3106 if (!fit_image_check_hashes (fit, rd_noffset)) {
3107 puts ("Bad Data Hash\n");
3108 show_boot_progress (-125);
3114 show_boot_progress (126);
3115 if (!fit_image_check_os (fit, rd_noffset, IH_OS_LINUX) ||
3116 !fit_image_check_arch (fit, rd_noffset, arch) ||
3117 !fit_image_check_type (fit, rd_noffset, IH_TYPE_RAMDISK)) {
3118 printf ("No Linux %s Ramdisk Image\n",
3119 genimg_get_arch_name(arch));
3120 show_boot_progress (-126);
3124 show_boot_progress (127);
3127 #endif /* USE_HOSTCC */
3128 #endif /* CONFIG_FIT */