2 * (C) Copyright 2008 Semihalf
4 * (C) Copyright 2000-2006
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #ifdef CONFIG_SHOW_BOOT_PROGRESS
31 #include <status_led.h>
34 #ifdef CONFIG_HAS_DATAFLASH
35 #include <dataflash.h>
38 #ifdef CONFIG_LOGBUFFER
42 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
48 #if defined(CONFIG_FIT) || defined (CONFIG_OF_LIBFDT)
51 #include <fdt_support.h>
54 #if defined(CONFIG_FIT)
55 #include <u-boot/md5.h>
58 static int fit_check_ramdisk (const void *fit, int os_noffset,
59 uint8_t arch, int verify);
63 extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * 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_KERNEL, "kernel", "Kernel Image", },
137 { IH_TYPE_MULTI, "multi", "Multi-File Image", },
138 { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", },
139 { IH_TYPE_SCRIPT, "script", "Script", },
140 { IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
141 { IH_TYPE_IMXIMAGE, "imximage", "Freescale i.MX Boot Image",},
142 { IH_TYPE_KWBIMAGE, "kwbimage", "Kirkwood Boot Image",},
143 { IH_TYPE_OMAPIMAGE, "omapimage", "TI OMAP SPL With GP CH",},
144 { IH_TYPE_UBLIMAGE, "ublimage", "Davinci UBL image",},
145 { IH_TYPE_INVALID, NULL, "Invalid Image", },
149 static const table_entry_t uimage_comp[] = {
150 { IH_COMP_NONE, "none", "uncompressed", },
151 { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", },
152 { IH_COMP_GZIP, "gzip", "gzip compressed", },
153 { IH_COMP_LZMA, "lzma", "lzma compressed", },
154 { IH_COMP_LZO, "lzo", "lzo compressed", },
158 uint32_t crc32 (uint32_t, const unsigned char *, uint);
159 uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint);
160 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
161 static void genimg_print_time (time_t timestamp);
164 /*****************************************************************************/
165 /* Legacy format routines */
166 /*****************************************************************************/
167 int image_check_hcrc (const image_header_t *hdr)
170 ulong len = image_get_header_size ();
171 image_header_t header;
173 /* Copy header so we can blank CRC field for re-calculation */
174 memmove (&header, (char *)hdr, image_get_header_size ());
175 image_set_hcrc (&header, 0);
177 hcrc = crc32 (0, (unsigned char *)&header, len);
179 return (hcrc == image_get_hcrc (hdr));
182 int image_check_dcrc (const image_header_t *hdr)
184 ulong data = image_get_data (hdr);
185 ulong len = image_get_data_size (hdr);
186 ulong dcrc = crc32_wd (0, (unsigned char *)data, len, CHUNKSZ_CRC32);
188 return (dcrc == image_get_dcrc (hdr));
192 * image_multi_count - get component (sub-image) count
193 * @hdr: pointer to the header of the multi component image
195 * image_multi_count() returns number of components in a multi
198 * Note: no checking of the image type is done, caller must pass
199 * a valid multi component image.
202 * number of components
204 ulong image_multi_count (const image_header_t *hdr)
209 /* get start of the image payload, which in case of multi
210 * component images that points to a table of component sizes */
211 size = (uint32_t *)image_get_data (hdr);
213 /* count non empty slots */
214 for (i = 0; size[i]; ++i)
221 * image_multi_getimg - get component data address and size
222 * @hdr: pointer to the header of the multi component image
223 * @idx: index of the requested component
224 * @data: pointer to a ulong variable, will hold component data address
225 * @len: pointer to a ulong variable, will hold component size
227 * image_multi_getimg() returns size and data address for the requested
228 * component in a multi component image.
230 * Note: no checking of the image type is done, caller must pass
231 * a valid multi component image.
234 * data address and size of the component, if idx is valid
235 * 0 in data and len, if idx is out of range
237 void image_multi_getimg (const image_header_t *hdr, ulong idx,
238 ulong *data, ulong *len)
242 ulong offset, count, img_data;
244 /* get number of component */
245 count = image_multi_count (hdr);
247 /* get start of the image payload, which in case of multi
248 * component images that points to a table of component sizes */
249 size = (uint32_t *)image_get_data (hdr);
251 /* get address of the proper component data start, which means
252 * skipping sizes table (add 1 for last, null entry) */
253 img_data = image_get_data (hdr) + (count + 1) * sizeof (uint32_t);
256 *len = uimage_to_cpu (size[idx]);
259 /* go over all indices preceding requested component idx */
260 for (i = 0; i < idx; i++) {
261 /* add up i-th component size, rounding up to 4 bytes */
262 offset += (uimage_to_cpu (size[i]) + 3) & ~3 ;
265 /* calculate idx-th component data address */
266 *data = img_data + offset;
273 static void image_print_type (const image_header_t *hdr)
275 const char *os, *arch, *type, *comp;
277 os = genimg_get_os_name (image_get_os (hdr));
278 arch = genimg_get_arch_name (image_get_arch (hdr));
279 type = genimg_get_type_name (image_get_type (hdr));
280 comp = genimg_get_comp_name (image_get_comp (hdr));
282 printf ("%s %s %s (%s)\n", arch, os, type, comp);
286 * image_print_contents - prints out the contents of the legacy format image
287 * @ptr: pointer to the legacy format image header
288 * @p: pointer to prefix string
290 * image_print_contents() formats a multi line legacy image contents description.
291 * The routine prints out all header fields followed by the size/offset data
292 * for MULTI/SCRIPT images.
295 * no returned results
297 void image_print_contents (const void *ptr)
299 const image_header_t *hdr = (const image_header_t *)ptr;
308 printf ("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name (hdr));
309 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
310 printf ("%sCreated: ", p);
311 genimg_print_time ((time_t)image_get_time (hdr));
313 printf ("%sImage Type: ", p);
314 image_print_type (hdr);
315 printf ("%sData Size: ", p);
316 genimg_print_size (image_get_data_size (hdr));
317 printf ("%sLoad Address: %08x\n", p, image_get_load (hdr));
318 printf ("%sEntry Point: %08x\n", p, image_get_ep (hdr));
320 if (image_check_type (hdr, IH_TYPE_MULTI) ||
321 image_check_type (hdr, IH_TYPE_SCRIPT)) {
324 ulong count = image_multi_count (hdr);
326 printf ("%sContents:\n", p);
327 for (i = 0; i < count; i++) {
328 image_multi_getimg (hdr, i, &data, &len);
330 printf ("%s Image %d: ", p, i);
331 genimg_print_size (len);
333 if (image_check_type (hdr, IH_TYPE_SCRIPT) && i > 0) {
335 * the user may need to know offsets
336 * if planning to do something with
339 printf ("%s Offset = 0x%08lx\n", p, data);
348 * image_get_ramdisk - get and verify ramdisk image
349 * @rd_addr: ramdisk image start address
350 * @arch: expected ramdisk architecture
351 * @verify: checksum verification flag
353 * image_get_ramdisk() returns a pointer to the verified ramdisk image
354 * header. Routine receives image start address and expected architecture
355 * flag. Verification done covers data and header integrity and os/type/arch
358 * If dataflash support is enabled routine checks for dataflash addresses
359 * and handles required dataflash reads.
362 * pointer to a ramdisk image header, if image was found and valid
363 * otherwise, return NULL
365 static const image_header_t *image_get_ramdisk (ulong rd_addr, uint8_t arch,
368 const image_header_t *rd_hdr = (const image_header_t *)rd_addr;
370 if (!image_check_magic (rd_hdr)) {
371 puts ("Bad Magic Number\n");
372 show_boot_progress (-10);
376 if (!image_check_hcrc (rd_hdr)) {
377 puts ("Bad Header Checksum\n");
378 show_boot_progress (-11);
382 show_boot_progress (10);
383 image_print_contents (rd_hdr);
386 puts(" Verifying Checksum ... ");
387 if (!image_check_dcrc (rd_hdr)) {
388 puts ("Bad Data CRC\n");
389 show_boot_progress (-12);
395 show_boot_progress (11);
397 if (!image_check_os (rd_hdr, IH_OS_LINUX) ||
398 !image_check_arch (rd_hdr, arch) ||
399 !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) {
400 printf ("No Linux %s Ramdisk Image\n",
401 genimg_get_arch_name(arch));
402 show_boot_progress (-13);
408 #endif /* !USE_HOSTCC */
410 /*****************************************************************************/
411 /* Shared dual-format routines */
412 /*****************************************************************************/
414 int getenv_yesno (char *var)
416 char *s = getenv (var);
417 return (s && (*s == 'n')) ? 0 : 1;
420 ulong getenv_bootm_low(void)
422 char *s = getenv ("bootm_low");
424 ulong tmp = simple_strtoul (s, NULL, 16);
428 #if defined(CONFIG_SYS_SDRAM_BASE)
429 return CONFIG_SYS_SDRAM_BASE;
430 #elif defined(CONFIG_ARM)
431 return gd->bd->bi_dram[0].start;
437 phys_size_t getenv_bootm_size(void)
440 char *s = getenv ("bootm_size");
442 tmp = (phys_size_t)simple_strtoull (s, NULL, 16);
445 s = getenv("bootm_low");
447 tmp = (phys_size_t)simple_strtoull (s, NULL, 16);
452 #if defined(CONFIG_ARM)
453 return gd->bd->bi_dram[0].size - tmp;
455 return gd->bd->bi_memsize - tmp;
459 phys_size_t getenv_bootm_mapsize(void)
462 char *s = getenv ("bootm_mapsize");
464 tmp = (phys_size_t)simple_strtoull (s, NULL, 16);
468 #if defined(CONFIG_SYS_BOOTMAPSZ)
469 return CONFIG_SYS_BOOTMAPSZ;
471 return getenv_bootm_size();
475 void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
480 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
482 size_t tail = (len > chunksz) ? chunksz : len;
484 memmove (to, from, tail);
489 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
490 memmove (to, from, len);
491 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
493 #endif /* !USE_HOSTCC */
495 void genimg_print_size (uint32_t size)
498 printf ("%d Bytes = ", size);
499 print_size (size, "\n");
501 printf ("%d Bytes = %.2f kB = %.2f MB\n",
502 size, (double)size / 1.024e3,
503 (double)size / 1.048576e6);
507 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
508 static void genimg_print_time (time_t timestamp)
513 to_tm (timestamp, &tm);
514 printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
515 tm.tm_year, tm.tm_mon, tm.tm_mday,
516 tm.tm_hour, tm.tm_min, tm.tm_sec);
518 printf ("%s", ctime(×tamp));
521 #endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */
524 * get_table_entry_name - translate entry id to long name
525 * @table: pointer to a translation table for entries of a specific type
526 * @msg: message to be returned when translation fails
527 * @id: entry id to be translated
529 * get_table_entry_name() will go over translation table trying to find
530 * entry that matches given id. If matching entry is found, its long
531 * name is returned to the caller.
534 * long entry name if translation succeeds
537 char *get_table_entry_name(const table_entry_t *table, char *msg, int id)
539 for (; table->id >= 0; ++table) {
541 #if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
544 return table->lname + gd->reloc_off;
550 const char *genimg_get_os_name (uint8_t os)
552 return (get_table_entry_name (uimage_os, "Unknown OS", os));
555 const char *genimg_get_arch_name (uint8_t arch)
557 return (get_table_entry_name (uimage_arch, "Unknown Architecture", arch));
560 const char *genimg_get_type_name (uint8_t type)
562 return (get_table_entry_name (uimage_type, "Unknown Image", type));
565 const char *genimg_get_comp_name (uint8_t comp)
567 return (get_table_entry_name (uimage_comp, "Unknown Compression", comp));
571 * get_table_entry_id - translate short entry name to id
572 * @table: pointer to a translation table for entries of a specific type
573 * @table_name: to be used in case of error
574 * @name: entry short name to be translated
576 * get_table_entry_id() will go over translation table trying to find
577 * entry that matches given short name. If matching entry is found,
578 * its id returned to the caller.
581 * entry id if translation succeeds
584 int get_table_entry_id(const table_entry_t *table,
585 const char *table_name, const char *name)
587 const table_entry_t *t;
591 for (t = table; t->id >= 0; ++t) {
592 if (t->sname && strcasecmp(t->sname, name) == 0)
596 fprintf (stderr, "\nInvalid %s Type - valid names are", table_name);
597 for (t = table; t->id >= 0; ++t) {
598 if (t->sname == NULL)
600 fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname);
603 fprintf (stderr, "\n");
605 for (t = table; t->id >= 0; ++t) {
606 #ifdef CONFIG_NEEDS_MANUAL_RELOC
607 if (t->sname && strcmp(t->sname + gd->reloc_off, name) == 0)
609 if (t->sname && strcmp(t->sname, name) == 0)
613 debug ("Invalid %s Type: %s\n", table_name, name);
614 #endif /* USE_HOSTCC */
618 int genimg_get_os_id (const char *name)
620 return (get_table_entry_id (uimage_os, "OS", name));
623 int genimg_get_arch_id (const char *name)
625 return (get_table_entry_id (uimage_arch, "CPU", name));
628 int genimg_get_type_id (const char *name)
630 return (get_table_entry_id (uimage_type, "Image", name));
633 int genimg_get_comp_id (const char *name)
635 return (get_table_entry_id (uimage_comp, "Compression", name));
640 * genimg_get_format - get image format type
641 * @img_addr: image start address
643 * genimg_get_format() checks whether provided address points to a valid
644 * legacy or FIT image.
646 * New uImage format and FDT blob are based on a libfdt. FDT blob
647 * may be passed directly or embedded in a FIT image. In both situations
648 * genimg_get_format() must be able to dectect libfdt header.
651 * image format type or IMAGE_FORMAT_INVALID if no image is present
653 int genimg_get_format (void *img_addr)
655 ulong format = IMAGE_FORMAT_INVALID;
656 const image_header_t *hdr;
657 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
661 hdr = (const image_header_t *)img_addr;
662 if (image_check_magic(hdr))
663 format = IMAGE_FORMAT_LEGACY;
664 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
666 fit_hdr = (char *)img_addr;
667 if (fdt_check_header (fit_hdr) == 0)
668 format = IMAGE_FORMAT_FIT;
676 * genimg_get_image - get image from special storage (if necessary)
677 * @img_addr: image start address
679 * genimg_get_image() checks if provided image start adddress is located
680 * in a dataflash storage. If so, image is moved to a system RAM memory.
683 * image start address after possible relocation from special storage
685 ulong genimg_get_image (ulong img_addr)
687 ulong ram_addr = img_addr;
689 #ifdef CONFIG_HAS_DATAFLASH
690 ulong h_size, d_size;
692 if (addr_dataflash (img_addr)){
693 /* ger RAM address */
694 ram_addr = CONFIG_SYS_LOAD_ADDR;
696 /* get header size */
697 h_size = image_get_header_size ();
698 #if defined(CONFIG_FIT)
699 if (sizeof(struct fdt_header) > h_size)
700 h_size = sizeof(struct fdt_header);
704 debug (" Reading image header from dataflash address "
705 "%08lx to RAM address %08lx\n", img_addr, ram_addr);
707 read_dataflash (img_addr, h_size, (char *)ram_addr);
710 switch (genimg_get_format ((void *)ram_addr)) {
711 case IMAGE_FORMAT_LEGACY:
712 d_size = image_get_data_size ((const image_header_t *)ram_addr);
713 debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n",
716 #if defined(CONFIG_FIT)
717 case IMAGE_FORMAT_FIT:
718 d_size = fit_get_size ((const void *)ram_addr) - h_size;
719 debug (" FIT/FDT format image found at 0x%08lx, size 0x%08lx\n",
724 printf (" No valid image found at 0x%08lx\n", img_addr);
728 /* read in image data */
729 debug (" Reading image remaining data from dataflash address "
730 "%08lx to RAM address %08lx\n", img_addr + h_size,
733 read_dataflash (img_addr + h_size, d_size,
734 (char *)(ram_addr + h_size));
737 #endif /* CONFIG_HAS_DATAFLASH */
743 * fit_has_config - check if there is a valid FIT configuration
744 * @images: pointer to the bootm command headers structure
746 * fit_has_config() checks if there is a FIT configuration in use
747 * (if FTI support is present).
750 * 0, no FIT support or no configuration found
751 * 1, configuration found
753 int genimg_has_config (bootm_headers_t *images)
755 #if defined(CONFIG_FIT)
756 if (images->fit_uname_cfg)
763 * boot_get_ramdisk - main ramdisk handling routine
764 * @argc: command argument count
765 * @argv: command argument list
766 * @images: pointer to the bootm images structure
767 * @arch: expected ramdisk architecture
768 * @rd_start: pointer to a ulong variable, will hold ramdisk start address
769 * @rd_end: pointer to a ulong variable, will hold ramdisk end
771 * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
772 * Curently supported are the following ramdisk sources:
773 * - multicomponent kernel/ramdisk image,
774 * - commandline provided address of decicated ramdisk image.
777 * 0, if ramdisk image was found and valid, or skiped
778 * rd_start and rd_end are set to ramdisk start/end addresses if
779 * ramdisk image is found and valid
781 * 1, if ramdisk image is found but corrupted, or invalid
782 * rd_start and rd_end are set to 0 if no ramdisk exists
784 int boot_get_ramdisk (int argc, char * const argv[], bootm_headers_t *images,
785 uint8_t arch, ulong *rd_start, ulong *rd_end)
787 ulong rd_addr, rd_load;
788 ulong rd_data, rd_len;
789 const image_header_t *rd_hdr;
790 #if defined(CONFIG_FIT)
792 const char *fit_uname_config = NULL;
793 const char *fit_uname_ramdisk = NULL;
805 * Look for a '-' which indicates to ignore the
808 if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) {
809 debug ("## Skipping init Ramdisk\n");
810 rd_len = rd_data = 0;
811 } else if (argc >= 3 || genimg_has_config (images)) {
812 #if defined(CONFIG_FIT)
815 * If the init ramdisk comes from the FIT image and
816 * the FIT image address is omitted in the command
817 * line argument, try to use os FIT image address or
818 * default load address.
820 if (images->fit_uname_os)
821 default_addr = (ulong)images->fit_hdr_os;
823 default_addr = load_addr;
825 if (fit_parse_conf (argv[2], default_addr,
826 &rd_addr, &fit_uname_config)) {
827 debug ("* ramdisk: config '%s' from image at 0x%08lx\n",
828 fit_uname_config, rd_addr);
829 } else if (fit_parse_subimage (argv[2], default_addr,
830 &rd_addr, &fit_uname_ramdisk)) {
831 debug ("* ramdisk: subimage '%s' from image at 0x%08lx\n",
832 fit_uname_ramdisk, rd_addr);
836 rd_addr = simple_strtoul(argv[2], NULL, 16);
837 debug ("* ramdisk: cmdline image address = 0x%08lx\n",
840 #if defined(CONFIG_FIT)
842 /* use FIT configuration provided in first bootm
845 rd_addr = (ulong)images->fit_hdr_os;
846 fit_uname_config = images->fit_uname_cfg;
847 debug ("* ramdisk: using config '%s' from image at 0x%08lx\n",
848 fit_uname_config, rd_addr);
851 * Check whether configuration has ramdisk defined,
852 * if not, don't try to use it, quit silently.
854 fit_hdr = (void *)rd_addr;
855 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
856 if (cfg_noffset < 0) {
857 debug ("* ramdisk: no such config\n");
861 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
862 if (rd_noffset < 0) {
863 debug ("* ramdisk: no ramdisk in config\n");
869 /* copy from dataflash if needed */
870 rd_addr = genimg_get_image (rd_addr);
873 * Check if there is an initrd image at the
874 * address provided in the second bootm argument
875 * check image type, for FIT images get FIT node.
877 switch (genimg_get_format ((void *)rd_addr)) {
878 case IMAGE_FORMAT_LEGACY:
879 printf ("## Loading init Ramdisk from Legacy "
880 "Image at %08lx ...\n", rd_addr);
882 show_boot_progress (9);
883 rd_hdr = image_get_ramdisk (rd_addr, arch,
889 rd_data = image_get_data (rd_hdr);
890 rd_len = image_get_data_size (rd_hdr);
891 rd_load = image_get_load (rd_hdr);
893 #if defined(CONFIG_FIT)
894 case IMAGE_FORMAT_FIT:
895 fit_hdr = (void *)rd_addr;
896 printf ("## Loading init Ramdisk from FIT "
897 "Image at %08lx ...\n", rd_addr);
899 show_boot_progress (120);
900 if (!fit_check_format (fit_hdr)) {
901 puts ("Bad FIT ramdisk image format!\n");
902 show_boot_progress (-120);
905 show_boot_progress (121);
907 if (!fit_uname_ramdisk) {
909 * no ramdisk image node unit name, try to get config
910 * node first. If config unit node name is NULL
911 * fit_conf_get_node() will try to find default config node
913 show_boot_progress (122);
914 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
915 if (cfg_noffset < 0) {
916 puts ("Could not find configuration node\n");
917 show_boot_progress (-122);
920 fit_uname_config = fdt_get_name (fit_hdr, cfg_noffset, NULL);
921 printf (" Using '%s' configuration\n", fit_uname_config);
923 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
924 fit_uname_ramdisk = fit_get_name (fit_hdr, rd_noffset, NULL);
926 /* get ramdisk component image node offset */
927 show_boot_progress (123);
928 rd_noffset = fit_image_get_node (fit_hdr, fit_uname_ramdisk);
930 if (rd_noffset < 0) {
931 puts ("Could not find subimage node\n");
932 show_boot_progress (-124);
936 printf (" Trying '%s' ramdisk subimage\n", fit_uname_ramdisk);
938 show_boot_progress (125);
939 if (!fit_check_ramdisk (fit_hdr, rd_noffset, arch, images->verify))
942 /* get ramdisk image data address and length */
943 if (fit_image_get_data (fit_hdr, rd_noffset, &data, &size)) {
944 puts ("Could not find ramdisk subimage data!\n");
945 show_boot_progress (-127);
948 show_boot_progress (128);
950 rd_data = (ulong)data;
953 if (fit_image_get_load (fit_hdr, rd_noffset, &rd_load)) {
954 puts ("Can't get ramdisk subimage load address!\n");
955 show_boot_progress (-129);
958 show_boot_progress (129);
960 images->fit_hdr_rd = fit_hdr;
961 images->fit_uname_rd = fit_uname_ramdisk;
962 images->fit_noffset_rd = rd_noffset;
966 puts ("Wrong Ramdisk Image Format\n");
967 rd_data = rd_len = rd_load = 0;
970 } else if (images->legacy_hdr_valid &&
971 image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
973 * Now check if we have a legacy mult-component image,
974 * get second entry data start address and len.
976 show_boot_progress (13);
977 printf ("## Loading init Ramdisk from multi component "
978 "Legacy Image at %08lx ...\n",
979 (ulong)images->legacy_hdr_os);
981 image_multi_getimg (images->legacy_hdr_os, 1, &rd_data, &rd_len);
986 show_boot_progress (14);
987 rd_len = rd_data = 0;
991 debug ("## No init Ramdisk\n");
994 *rd_end = rd_data + rd_len;
996 debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
1002 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
1004 * boot_ramdisk_high - relocate init ramdisk
1005 * @lmb: pointer to lmb handle, will be used for memory mgmt
1006 * @rd_data: ramdisk data start address
1007 * @rd_len: ramdisk data length
1008 * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
1009 * start address (after possible relocation)
1010 * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
1011 * end address (after possible relocation)
1013 * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
1014 * variable and if requested ramdisk data is moved to a specified location.
1016 * Initrd_start and initrd_end are set to final (after relocation) ramdisk
1017 * start/end addresses if ramdisk image start and len were provided,
1018 * otherwise set initrd_start and initrd_end set to zeros.
1024 int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
1025 ulong *initrd_start, ulong *initrd_end)
1029 int initrd_copy_to_ram = 1;
1031 if ((s = getenv ("initrd_high")) != NULL) {
1032 /* a value of "no" or a similar string will act like 0,
1033 * turning the "load high" feature off. This is intentional.
1035 initrd_high = simple_strtoul (s, NULL, 16);
1036 if (initrd_high == ~0)
1037 initrd_copy_to_ram = 0;
1039 /* not set, no restrictions to load high */
1044 #ifdef CONFIG_LOGBUFFER
1045 /* Prevent initrd from overwriting logbuffer */
1046 lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
1049 debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
1050 initrd_high, initrd_copy_to_ram);
1053 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
1054 debug (" in-place initrd\n");
1055 *initrd_start = rd_data;
1056 *initrd_end = rd_data + rd_len;
1057 lmb_reserve(lmb, rd_data, rd_len);
1060 *initrd_start = (ulong)lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
1062 *initrd_start = (ulong)lmb_alloc (lmb, rd_len, 0x1000);
1064 if (*initrd_start == 0) {
1065 puts ("ramdisk - allocation error\n");
1068 show_boot_progress (12);
1070 *initrd_end = *initrd_start + rd_len;
1071 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
1072 *initrd_start, *initrd_end);
1074 memmove_wd ((void *)*initrd_start,
1075 (void *)rd_data, rd_len, CHUNKSZ);
1083 debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
1084 *initrd_start, *initrd_end);
1091 #endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */
1093 #ifdef CONFIG_OF_LIBFDT
1094 static void fdt_error (const char *msg)
1098 puts (" - must RESET the board to recover.\n");
1101 static const image_header_t *image_get_fdt (ulong fdt_addr)
1103 const image_header_t *fdt_hdr = (const image_header_t *)fdt_addr;
1105 image_print_contents (fdt_hdr);
1107 puts (" Verifying Checksum ... ");
1108 if (!image_check_hcrc (fdt_hdr)) {
1109 fdt_error ("fdt header checksum invalid");
1113 if (!image_check_dcrc (fdt_hdr)) {
1114 fdt_error ("fdt checksum invalid");
1119 if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) {
1120 fdt_error ("uImage is not a fdt");
1123 if (image_get_comp (fdt_hdr) != IH_COMP_NONE) {
1124 fdt_error ("uImage is compressed");
1127 if (fdt_check_header ((char *)image_get_data (fdt_hdr)) != 0) {
1128 fdt_error ("uImage data is not a fdt");
1135 * fit_check_fdt - verify FIT format FDT subimage
1136 * @fit_hdr: pointer to the FIT header
1137 * fdt_noffset: FDT subimage node offset within FIT image
1138 * @verify: data CRC verification flag
1140 * fit_check_fdt() verifies integrity of the FDT subimage and from
1141 * specified FIT image.
1147 #if defined(CONFIG_FIT)
1148 static int fit_check_fdt (const void *fit, int fdt_noffset, int verify)
1150 fit_image_print (fit, fdt_noffset, " ");
1153 puts (" Verifying Hash Integrity ... ");
1154 if (!fit_image_check_hashes (fit, fdt_noffset)) {
1155 fdt_error ("Bad Data Hash");
1161 if (!fit_image_check_type (fit, fdt_noffset, IH_TYPE_FLATDT)) {
1162 fdt_error ("Not a FDT image");
1166 if (!fit_image_check_comp (fit, fdt_noffset, IH_COMP_NONE)) {
1167 fdt_error ("FDT image is compressed");
1173 #endif /* CONFIG_FIT */
1175 #ifndef CONFIG_SYS_FDT_PAD
1176 #define CONFIG_SYS_FDT_PAD 0x3000
1179 #if defined(CONFIG_OF_LIBFDT)
1181 * boot_fdt_add_mem_rsv_regions - Mark the memreserve sections as unusable
1182 * @lmb: pointer to lmb handle, will be used for memory mgmt
1183 * @fdt_blob: pointer to fdt blob base address
1185 * Adds the memreserve regions in the dtb to the lmb block. Adding the
1186 * memreserve regions prevents u-boot from using them to store the initrd
1189 void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob)
1191 uint64_t addr, size;
1194 if (fdt_check_header (fdt_blob) != 0)
1197 total = fdt_num_mem_rsv(fdt_blob);
1198 for (i = 0; i < total; i++) {
1199 if (fdt_get_mem_rsv(fdt_blob, i, &addr, &size) != 0)
1201 printf(" reserving fdt memory region: addr=%llx size=%llx\n",
1202 (unsigned long long)addr, (unsigned long long)size);
1203 lmb_reserve(lmb, addr, size);
1208 * boot_relocate_fdt - relocate flat device tree
1209 * @lmb: pointer to lmb handle, will be used for memory mgmt
1210 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1211 * @of_size: pointer to a ulong variable, will hold fdt length
1213 * boot_relocate_fdt() allocates a region of memory within the bootmap and
1214 * relocates the of_flat_tree into that region, even if the fdt is already in
1215 * the bootmap. It also expands the size of the fdt by CONFIG_SYS_FDT_PAD
1218 * of_flat_tree and of_size are set to final (after relocation) values
1224 int boot_relocate_fdt (struct lmb *lmb, char **of_flat_tree, ulong *of_size)
1226 void *fdt_blob = *of_flat_tree;
1231 int disable_relocation = 0;
1237 if (fdt_check_header (fdt_blob) != 0) {
1238 fdt_error ("image is not a fdt");
1242 /* position on a 4K boundary before the alloc_current */
1243 /* Pad the FDT by a specified amount */
1244 of_len = *of_size + CONFIG_SYS_FDT_PAD;
1246 /* If fdt_high is set use it to select the relocation address */
1247 fdt_high = getenv("fdt_high");
1249 void *desired_addr = (void *)simple_strtoul(fdt_high, NULL, 16);
1251 if (((ulong) desired_addr) == ~0UL) {
1252 /* All ones means use fdt in place */
1253 desired_addr = fdt_blob;
1254 disable_relocation = 1;
1258 (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
1262 if (desired_addr && of_start != desired_addr) {
1263 puts("Failed using fdt_high value for Device Tree");
1268 (void *)(ulong) lmb_alloc(lmb, of_len, 0x1000);
1272 (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
1273 getenv_bootm_mapsize()
1274 + getenv_bootm_low());
1277 if (of_start == 0) {
1278 puts("device tree - allocation error\n");
1282 if (disable_relocation) {
1283 /* We assume there is space after the existing fdt to use for padding */
1284 fdt_set_totalsize(of_start, of_len);
1285 printf(" Using Device Tree in place at %p, end %p\n",
1286 of_start, of_start + of_len - 1);
1288 debug ("## device tree at %p ... %p (len=%ld [0x%lX])\n",
1289 fdt_blob, fdt_blob + *of_size - 1, of_len, of_len);
1291 printf (" Loading Device Tree to %p, end %p ... ",
1292 of_start, of_start + of_len - 1);
1294 err = fdt_open_into (fdt_blob, of_start, of_len);
1296 fdt_error ("fdt move failed");
1302 *of_flat_tree = of_start;
1305 set_working_fdt_addr(*of_flat_tree);
1311 #endif /* CONFIG_OF_LIBFDT */
1314 * boot_get_fdt - main fdt handling routine
1315 * @argc: command argument count
1316 * @argv: command argument list
1317 * @images: pointer to the bootm images structure
1318 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1319 * @of_size: pointer to a ulong variable, will hold fdt length
1321 * boot_get_fdt() is responsible for finding a valid flat device tree image.
1322 * Curently supported are the following ramdisk sources:
1323 * - multicomponent kernel/ramdisk image,
1324 * - commandline provided address of decicated ramdisk image.
1327 * 0, if fdt image was found and valid, or skipped
1328 * of_flat_tree and of_size are set to fdt start address and length if
1329 * fdt image is found and valid
1331 * 1, if fdt image is found but corrupted
1332 * of_flat_tree and of_size are set to 0 if no fdt exists
1334 int boot_get_fdt (int flag, int argc, char * const argv[], bootm_headers_t *images,
1335 char **of_flat_tree, ulong *of_size)
1337 const image_header_t *fdt_hdr;
1339 char *fdt_blob = NULL;
1340 ulong image_start, image_end;
1341 ulong load_start, load_end;
1342 #if defined(CONFIG_FIT)
1344 const char *fit_uname_config = NULL;
1345 const char *fit_uname_fdt = NULL;
1353 *of_flat_tree = NULL;
1356 if (argc > 3 || genimg_has_config (images)) {
1357 #if defined(CONFIG_FIT)
1360 * If the FDT blob comes from the FIT image and the
1361 * FIT image address is omitted in the command line
1362 * argument, try to use ramdisk or os FIT image
1363 * address or default load address.
1365 if (images->fit_uname_rd)
1366 default_addr = (ulong)images->fit_hdr_rd;
1367 else if (images->fit_uname_os)
1368 default_addr = (ulong)images->fit_hdr_os;
1370 default_addr = load_addr;
1372 if (fit_parse_conf (argv[3], default_addr,
1373 &fdt_addr, &fit_uname_config)) {
1374 debug ("* fdt: config '%s' from image at 0x%08lx\n",
1375 fit_uname_config, fdt_addr);
1376 } else if (fit_parse_subimage (argv[3], default_addr,
1377 &fdt_addr, &fit_uname_fdt)) {
1378 debug ("* fdt: subimage '%s' from image at 0x%08lx\n",
1379 fit_uname_fdt, fdt_addr);
1383 fdt_addr = simple_strtoul(argv[3], NULL, 16);
1384 debug ("* fdt: cmdline image address = 0x%08lx\n",
1387 #if defined(CONFIG_FIT)
1389 /* use FIT configuration provided in first bootm
1392 fdt_addr = (ulong)images->fit_hdr_os;
1393 fit_uname_config = images->fit_uname_cfg;
1394 debug ("* fdt: using config '%s' from image at 0x%08lx\n",
1395 fit_uname_config, fdt_addr);
1398 * Check whether configuration has FDT blob defined,
1399 * if not quit silently.
1401 fit_hdr = (void *)fdt_addr;
1402 cfg_noffset = fit_conf_get_node (fit_hdr,
1404 if (cfg_noffset < 0) {
1405 debug ("* fdt: no such config\n");
1409 fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
1411 if (fdt_noffset < 0) {
1412 debug ("* fdt: no fdt in config\n");
1418 debug ("## Checking for 'FDT'/'FDT Image' at %08lx\n",
1421 /* copy from dataflash if needed */
1422 fdt_addr = genimg_get_image (fdt_addr);
1425 * Check if there is an FDT image at the
1426 * address provided in the second bootm argument
1427 * check image type, for FIT images get a FIT node.
1429 switch (genimg_get_format ((void *)fdt_addr)) {
1430 case IMAGE_FORMAT_LEGACY:
1431 /* verify fdt_addr points to a valid image header */
1432 printf ("## Flattened Device Tree from Legacy Image at %08lx\n",
1434 fdt_hdr = image_get_fdt (fdt_addr);
1439 * move image data to the load address,
1440 * make sure we don't overwrite initial image
1442 image_start = (ulong)fdt_hdr;
1443 image_end = image_get_image_end (fdt_hdr);
1445 load_start = image_get_load (fdt_hdr);
1446 load_end = load_start + image_get_data_size (fdt_hdr);
1448 if ((load_start < image_end) && (load_end > image_start)) {
1449 fdt_error ("fdt overwritten");
1453 debug (" Loading FDT from 0x%08lx to 0x%08lx\n",
1454 image_get_data (fdt_hdr), load_start);
1456 memmove ((void *)load_start,
1457 (void *)image_get_data (fdt_hdr),
1458 image_get_data_size (fdt_hdr));
1460 fdt_blob = (char *)load_start;
1462 case IMAGE_FORMAT_FIT:
1464 * This case will catch both: new uImage format
1465 * (libfdt based) and raw FDT blob (also libfdt
1468 #if defined(CONFIG_FIT)
1469 /* check FDT blob vs FIT blob */
1470 if (fit_check_format ((const void *)fdt_addr)) {
1474 fit_hdr = (void *)fdt_addr;
1475 printf ("## Flattened Device Tree from FIT Image at %08lx\n",
1478 if (!fit_uname_fdt) {
1480 * no FDT blob image node unit name,
1481 * try to get config node first. If
1482 * config unit node name is NULL
1483 * fit_conf_get_node() will try to
1484 * find default config node
1486 cfg_noffset = fit_conf_get_node (fit_hdr,
1489 if (cfg_noffset < 0) {
1490 fdt_error ("Could not find configuration node\n");
1494 fit_uname_config = fdt_get_name (fit_hdr,
1496 printf (" Using '%s' configuration\n",
1499 fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
1501 fit_uname_fdt = fit_get_name (fit_hdr,
1504 /* get FDT component image node offset */
1505 fdt_noffset = fit_image_get_node (fit_hdr,
1508 if (fdt_noffset < 0) {
1509 fdt_error ("Could not find subimage node\n");
1513 printf (" Trying '%s' FDT blob subimage\n",
1516 if (!fit_check_fdt (fit_hdr, fdt_noffset,
1520 /* get ramdisk image data address and length */
1521 if (fit_image_get_data (fit_hdr, fdt_noffset,
1523 fdt_error ("Could not find FDT subimage data");
1527 /* verift that image data is a proper FDT blob */
1528 if (fdt_check_header ((char *)data) != 0) {
1529 fdt_error ("Subimage data is not a FTD");
1534 * move image data to the load address,
1535 * make sure we don't overwrite initial image
1537 image_start = (ulong)fit_hdr;
1538 image_end = fit_get_end (fit_hdr);
1540 if (fit_image_get_load (fit_hdr, fdt_noffset,
1541 &load_start) == 0) {
1542 load_end = load_start + size;
1544 if ((load_start < image_end) &&
1545 (load_end > image_start)) {
1546 fdt_error ("FDT overwritten");
1550 printf (" Loading FDT from 0x%08lx to 0x%08lx\n",
1551 (ulong)data, load_start);
1553 memmove ((void *)load_start,
1554 (void *)data, size);
1556 fdt_blob = (char *)load_start;
1558 fdt_blob = (char *)data;
1561 images->fit_hdr_fdt = fit_hdr;
1562 images->fit_uname_fdt = fit_uname_fdt;
1563 images->fit_noffset_fdt = fdt_noffset;
1571 fdt_blob = (char *)fdt_addr;
1572 debug ("* fdt: raw FDT blob\n");
1573 printf ("## Flattened Device Tree blob at %08lx\n", (long)fdt_blob);
1577 puts ("ERROR: Did not find a cmdline Flattened Device Tree\n");
1581 printf (" Booting using the fdt blob at 0x%x\n", (int)fdt_blob);
1583 } else if (images->legacy_hdr_valid &&
1584 image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1586 ulong fdt_data, fdt_len;
1589 * Now check if we have a legacy multi-component image,
1590 * get second entry data start address and len.
1592 printf ("## Flattened Device Tree from multi "
1593 "component Image at %08lX\n",
1594 (ulong)images->legacy_hdr_os);
1596 image_multi_getimg (images->legacy_hdr_os, 2, &fdt_data, &fdt_len);
1599 fdt_blob = (char *)fdt_data;
1600 printf (" Booting using the fdt at 0x%x\n", (int)fdt_blob);
1602 if (fdt_check_header (fdt_blob) != 0) {
1603 fdt_error ("image is not a fdt");
1607 if (fdt_totalsize(fdt_blob) != fdt_len) {
1608 fdt_error ("fdt size != image size");
1612 debug ("## No Flattened Device Tree\n");
1616 debug ("## No Flattened Device Tree\n");
1620 *of_flat_tree = fdt_blob;
1621 *of_size = fdt_totalsize(fdt_blob);
1622 debug (" of_flat_tree at 0x%08lx size 0x%08lx\n",
1623 (ulong)*of_flat_tree, *of_size);
1632 #endif /* CONFIG_OF_LIBFDT */
1634 #ifdef CONFIG_SYS_BOOT_GET_CMDLINE
1636 * boot_get_cmdline - allocate and initialize kernel cmdline
1637 * @lmb: pointer to lmb handle, will be used for memory mgmt
1638 * @cmd_start: pointer to a ulong variable, will hold cmdline start
1639 * @cmd_end: pointer to a ulong variable, will hold cmdline end
1641 * boot_get_cmdline() allocates space for kernel command line below
1642 * BOOTMAPSZ + getenv_bootm_low() address. If "bootargs" U-boot environemnt
1643 * variable is present its contents is copied to allocated kernel
1650 int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end)
1655 cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf,
1656 getenv_bootm_mapsize() + getenv_bootm_low());
1658 if (cmdline == NULL)
1661 if ((s = getenv("bootargs")) == NULL)
1666 *cmd_start = (ulong) & cmdline[0];
1667 *cmd_end = *cmd_start + strlen(cmdline);
1669 debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
1673 #endif /* CONFIG_SYS_BOOT_GET_CMDLINE */
1675 #ifdef CONFIG_SYS_BOOT_GET_KBD
1677 * boot_get_kbd - allocate and initialize kernel copy of board info
1678 * @lmb: pointer to lmb handle, will be used for memory mgmt
1679 * @kbd: double pointer to board info data
1681 * boot_get_kbd() allocates space for kernel copy of board info data below
1682 * BOOTMAPSZ + getenv_bootm_low() address and kernel board info is initialized
1683 * with the current u-boot board info data.
1689 int boot_get_kbd (struct lmb *lmb, bd_t **kbd)
1691 *kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
1692 getenv_bootm_mapsize() + getenv_bootm_low());
1698 debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
1700 #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
1701 do_bdinfo(NULL, 0, 0, NULL);
1706 #endif /* CONFIG_SYS_BOOT_GET_KBD */
1707 #endif /* !USE_HOSTCC */
1709 #if defined(CONFIG_FIT)
1710 /*****************************************************************************/
1711 /* New uImage format routines */
1712 /*****************************************************************************/
1714 static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr,
1715 ulong *addr, const char **name)
1722 sep = strchr (spec, sepc);
1725 *addr = simple_strtoul (spec, NULL, 16);
1735 * fit_parse_conf - parse FIT configuration spec
1736 * @spec: input string, containing configuration spec
1737 * @add_curr: current image address (to be used as a possible default)
1738 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1740 * @conf_name double pointer to a char, will hold pointer to a configuration
1743 * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
1744 * where <addr> is a FIT image address that contains configuration
1745 * with a <conf> unit name.
1747 * Address part is optional, and if omitted default add_curr will
1751 * 1 if spec is a valid configuration string,
1752 * addr and conf_name are set accordingly
1755 inline int fit_parse_conf (const char *spec, ulong addr_curr,
1756 ulong *addr, const char **conf_name)
1758 return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
1762 * fit_parse_subimage - parse FIT subimage spec
1763 * @spec: input string, containing subimage spec
1764 * @add_curr: current image address (to be used as a possible default)
1765 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1767 * @image_name: double pointer to a char, will hold pointer to a subimage name
1769 * fit_parse_subimage() expects subimage spec in the for of
1770 * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
1771 * subimage with a <subimg> unit name.
1773 * Address part is optional, and if omitted default add_curr will
1777 * 1 if spec is a valid subimage string,
1778 * addr and image_name are set accordingly
1781 inline int fit_parse_subimage (const char *spec, ulong addr_curr,
1782 ulong *addr, const char **image_name)
1784 return fit_parse_spec (spec, ':', addr_curr, addr, image_name);
1786 #endif /* !USE_HOSTCC */
1788 static void fit_get_debug (const void *fit, int noffset,
1789 char *prop_name, int err)
1791 debug ("Can't get '%s' property from FIT 0x%08lx, "
1792 "node: offset %d, name %s (%s)\n",
1793 prop_name, (ulong)fit, noffset,
1794 fit_get_name (fit, noffset, NULL),
1795 fdt_strerror (err));
1799 * fit_print_contents - prints out the contents of the FIT format image
1800 * @fit: pointer to the FIT format image header
1801 * @p: pointer to prefix string
1803 * fit_print_contents() formats a multi line FIT image contents description.
1804 * The routine prints out FIT image properties (root node level) follwed by
1805 * the details of each component image.
1808 * no returned results
1810 void fit_print_contents (const void *fit)
1821 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1831 /* Root node properties */
1832 ret = fit_get_desc (fit, 0, &desc);
1833 printf ("%sFIT description: ", p);
1835 printf ("unavailable\n");
1837 printf ("%s\n", desc);
1839 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1840 ret = fit_get_timestamp (fit, 0, ×tamp);
1841 printf ("%sCreated: ", p);
1843 printf ("unavailable\n");
1845 genimg_print_time (timestamp);
1848 /* Find images parent node offset */
1849 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
1850 if (images_noffset < 0) {
1851 printf ("Can't find images parent node '%s' (%s)\n",
1852 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
1856 /* Process its subnodes, print out component images details */
1857 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
1858 (noffset >= 0) && (ndepth > 0);
1859 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1862 * Direct child node of the images parent node,
1863 * i.e. component image node.
1865 printf ("%s Image %u (%s)\n", p, count++,
1866 fit_get_name(fit, noffset, NULL));
1868 fit_image_print (fit, noffset, p);
1872 /* Find configurations parent node offset */
1873 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
1874 if (confs_noffset < 0) {
1875 debug ("Can't get configurations parent node '%s' (%s)\n",
1876 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
1880 /* get default configuration unit name from default property */
1881 uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL);
1883 printf ("%s Default Configuration: '%s'\n", p, uname);
1885 /* Process its subnodes, print out configurations details */
1886 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth);
1887 (noffset >= 0) && (ndepth > 0);
1888 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1891 * Direct child node of the configurations parent node,
1892 * i.e. configuration node.
1894 printf ("%s Configuration %u (%s)\n", p, count++,
1895 fit_get_name(fit, noffset, NULL));
1897 fit_conf_print (fit, noffset, p);
1903 * fit_image_print - prints out the FIT component image details
1904 * @fit: pointer to the FIT format image header
1905 * @image_noffset: offset of the component image node
1906 * @p: pointer to prefix string
1908 * fit_image_print() lists all mandatory properies for the processed component
1909 * image. If present, hash nodes are printed out as well. Load
1910 * address for images of type firmware is also printed out. Since the load
1911 * address is not mandatory for firmware images, it will be output as
1912 * "unavailable" when not present.
1915 * no returned results
1917 void fit_image_print (const void *fit, int image_noffset, const char *p)
1920 uint8_t type, arch, os, comp;
1928 /* Mandatory properties */
1929 ret = fit_get_desc (fit, image_noffset, &desc);
1930 printf ("%s Description: ", p);
1932 printf ("unavailable\n");
1934 printf ("%s\n", desc);
1936 fit_image_get_type (fit, image_noffset, &type);
1937 printf ("%s Type: %s\n", p, genimg_get_type_name (type));
1939 fit_image_get_comp (fit, image_noffset, &comp);
1940 printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp));
1942 ret = fit_image_get_data (fit, image_noffset, &data, &size);
1945 printf ("%s Data Start: ", p);
1947 printf ("unavailable\n");
1949 printf ("0x%08lx\n", (ulong)data);
1952 printf ("%s Data Size: ", p);
1954 printf ("unavailable\n");
1956 genimg_print_size (size);
1958 /* Remaining, type dependent properties */
1959 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
1960 (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
1961 (type == IH_TYPE_FLATDT)) {
1962 fit_image_get_arch (fit, image_noffset, &arch);
1963 printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch));
1966 if (type == IH_TYPE_KERNEL) {
1967 fit_image_get_os (fit, image_noffset, &os);
1968 printf ("%s OS: %s\n", p, genimg_get_os_name (os));
1971 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
1972 (type == IH_TYPE_FIRMWARE)) {
1973 ret = fit_image_get_load (fit, image_noffset, &load);
1974 printf ("%s Load Address: ", p);
1976 printf ("unavailable\n");
1978 printf ("0x%08lx\n", load);
1981 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
1982 fit_image_get_entry (fit, image_noffset, &entry);
1983 printf ("%s Entry Point: ", p);
1985 printf ("unavailable\n");
1987 printf ("0x%08lx\n", entry);
1990 /* Process all hash subnodes of the component image node */
1991 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
1992 (noffset >= 0) && (ndepth > 0);
1993 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1995 /* Direct child node of the component image node */
1996 fit_image_print_hash (fit, noffset, p);
2002 * fit_image_print_hash - prints out the hash node details
2003 * @fit: pointer to the FIT format image header
2004 * @noffset: offset of the hash node
2005 * @p: pointer to prefix string
2007 * fit_image_print_hash() lists properies for the processed hash node
2010 * no returned results
2012 void fit_image_print_hash (const void *fit, int noffset, const char *p)
2020 * Check subnode name, must be equal to "hash".
2021 * Multiple hash nodes require unique unit node
2022 * names, e.g. hash@1, hash@2, etc.
2024 if (strncmp (fit_get_name(fit, noffset, NULL),
2026 strlen(FIT_HASH_NODENAME)) != 0)
2029 debug ("%s Hash node: '%s'\n", p,
2030 fit_get_name (fit, noffset, NULL));
2032 printf ("%s Hash algo: ", p);
2033 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2034 printf ("invalid/unsupported\n");
2037 printf ("%s\n", algo);
2039 ret = fit_image_hash_get_value (fit, noffset, &value,
2041 printf ("%s Hash value: ", p);
2043 printf ("unavailable\n");
2045 for (i = 0; i < value_len; i++)
2046 printf ("%02x", value[i]);
2050 debug ("%s Hash len: %d\n", p, value_len);
2054 * fit_get_desc - get node description property
2055 * @fit: pointer to the FIT format image header
2056 * @noffset: node offset
2057 * @desc: double pointer to the char, will hold pointer to the descrption
2059 * fit_get_desc() reads description property from a given node, if
2060 * description is found pointer to it is returened in third call argument.
2066 int fit_get_desc (const void *fit, int noffset, char **desc)
2070 *desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len);
2071 if (*desc == NULL) {
2072 fit_get_debug (fit, noffset, FIT_DESC_PROP, len);
2080 * fit_get_timestamp - get node timestamp property
2081 * @fit: pointer to the FIT format image header
2082 * @noffset: node offset
2083 * @timestamp: pointer to the time_t, will hold read timestamp
2085 * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
2086 * is found and has a correct size its value is retured in third call
2091 * -1, on property read failure
2092 * -2, on wrong timestamp size
2094 int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp)
2099 data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len);
2101 fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len);
2104 if (len != sizeof (uint32_t)) {
2105 debug ("FIT timestamp with incorrect size of (%u)\n", len);
2109 *timestamp = uimage_to_cpu (*((uint32_t *)data));
2114 * fit_image_get_node - get node offset for component image of a given unit name
2115 * @fit: pointer to the FIT format image header
2116 * @image_uname: component image node unit name
2118 * fit_image_get_node() finds a component image (withing the '/images'
2119 * node) of a provided unit name. If image is found its node offset is
2120 * returned to the caller.
2123 * image node offset when found (>=0)
2124 * negative number on failure (FDT_ERR_* code)
2126 int fit_image_get_node (const void *fit, const char *image_uname)
2128 int noffset, images_noffset;
2130 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2131 if (images_noffset < 0) {
2132 debug ("Can't find images parent node '%s' (%s)\n",
2133 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2134 return images_noffset;
2137 noffset = fdt_subnode_offset (fit, images_noffset, image_uname);
2139 debug ("Can't get node offset for image unit name: '%s' (%s)\n",
2140 image_uname, fdt_strerror (noffset));
2147 * fit_image_get_os - get os id for a given component image node
2148 * @fit: pointer to the FIT format image header
2149 * @noffset: component image node offset
2150 * @os: pointer to the uint8_t, will hold os numeric id
2152 * fit_image_get_os() finds os property in a given component image node.
2153 * If the property is found, its (string) value is translated to the numeric
2154 * id which is returned to the caller.
2160 int fit_image_get_os (const void *fit, int noffset, uint8_t *os)
2165 /* Get OS name from property data */
2166 data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len);
2168 fit_get_debug (fit, noffset, FIT_OS_PROP, len);
2173 /* Translate OS name to id */
2174 *os = genimg_get_os_id (data);
2179 * fit_image_get_arch - get arch id for a given component image node
2180 * @fit: pointer to the FIT format image header
2181 * @noffset: component image node offset
2182 * @arch: pointer to the uint8_t, will hold arch numeric id
2184 * fit_image_get_arch() finds arch property in a given component image node.
2185 * If the property is found, its (string) value is translated to the numeric
2186 * id which is returned to the caller.
2192 int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch)
2197 /* Get architecture name from property data */
2198 data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len);
2200 fit_get_debug (fit, noffset, FIT_ARCH_PROP, len);
2205 /* Translate architecture name to id */
2206 *arch = genimg_get_arch_id (data);
2211 * fit_image_get_type - get type id for a given component image node
2212 * @fit: pointer to the FIT format image header
2213 * @noffset: component image node offset
2214 * @type: pointer to the uint8_t, will hold type numeric id
2216 * fit_image_get_type() finds type property in a given component image node.
2217 * If the property is found, its (string) value is translated to the numeric
2218 * id which is returned to the caller.
2224 int fit_image_get_type (const void *fit, int noffset, uint8_t *type)
2229 /* Get image type name from property data */
2230 data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len);
2232 fit_get_debug (fit, noffset, FIT_TYPE_PROP, len);
2237 /* Translate image type name to id */
2238 *type = genimg_get_type_id (data);
2243 * fit_image_get_comp - get comp id for a given component image node
2244 * @fit: pointer to the FIT format image header
2245 * @noffset: component image node offset
2246 * @comp: pointer to the uint8_t, will hold comp numeric id
2248 * fit_image_get_comp() finds comp property in a given component image node.
2249 * If the property is found, its (string) value is translated to the numeric
2250 * id which is returned to the caller.
2256 int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp)
2261 /* Get compression name from property data */
2262 data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len);
2264 fit_get_debug (fit, noffset, FIT_COMP_PROP, len);
2269 /* Translate compression name to id */
2270 *comp = genimg_get_comp_id (data);
2275 * fit_image_get_load - get load address property for a given component image node
2276 * @fit: pointer to the FIT format image header
2277 * @noffset: component image node offset
2278 * @load: pointer to the uint32_t, will hold load address
2280 * fit_image_get_load() finds load address property in a given component image node.
2281 * If the property is found, its value is returned to the caller.
2287 int fit_image_get_load (const void *fit, int noffset, ulong *load)
2290 const uint32_t *data;
2292 data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len);
2294 fit_get_debug (fit, noffset, FIT_LOAD_PROP, len);
2298 *load = uimage_to_cpu (*data);
2303 * fit_image_get_entry - get entry point address property for a given component image node
2304 * @fit: pointer to the FIT format image header
2305 * @noffset: component image node offset
2306 * @entry: pointer to the uint32_t, will hold entry point address
2308 * fit_image_get_entry() finds entry point address property in a given component image node.
2309 * If the property is found, its value is returned to the caller.
2315 int fit_image_get_entry (const void *fit, int noffset, ulong *entry)
2318 const uint32_t *data;
2320 data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len);
2322 fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len);
2326 *entry = uimage_to_cpu (*data);
2331 * fit_image_get_data - get data property and its size for a given component image node
2332 * @fit: pointer to the FIT format image header
2333 * @noffset: component image node offset
2334 * @data: double pointer to void, will hold data property's data address
2335 * @size: pointer to size_t, will hold data property's data size
2337 * fit_image_get_data() finds data property in a given component image node.
2338 * If the property is found its data start address and size are returned to
2345 int fit_image_get_data (const void *fit, int noffset,
2346 const void **data, size_t *size)
2350 *data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len);
2351 if (*data == NULL) {
2352 fit_get_debug (fit, noffset, FIT_DATA_PROP, len);
2362 * fit_image_hash_get_algo - get hash algorithm name
2363 * @fit: pointer to the FIT format image header
2364 * @noffset: hash node offset
2365 * @algo: double pointer to char, will hold pointer to the algorithm name
2367 * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
2368 * If the property is found its data start address is returned to the caller.
2374 int fit_image_hash_get_algo (const void *fit, int noffset, char **algo)
2378 *algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len);
2379 if (*algo == NULL) {
2380 fit_get_debug (fit, noffset, FIT_ALGO_PROP, len);
2388 * fit_image_hash_get_value - get hash value and length
2389 * @fit: pointer to the FIT format image header
2390 * @noffset: hash node offset
2391 * @value: double pointer to uint8_t, will hold address of a hash value data
2392 * @value_len: pointer to an int, will hold hash data length
2394 * fit_image_hash_get_value() finds hash value property in a given hash node.
2395 * If the property is found its data start address and size are returned to
2402 int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value,
2407 *value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len);
2408 if (*value == NULL) {
2409 fit_get_debug (fit, noffset, FIT_VALUE_PROP, len);
2419 * fit_set_timestamp - set node timestamp property
2420 * @fit: pointer to the FIT format image header
2421 * @noffset: node offset
2422 * @timestamp: timestamp value to be set
2424 * fit_set_timestamp() attempts to set timestamp property in the requested
2425 * node and returns operation status to the caller.
2429 * -1, on property read failure
2431 int fit_set_timestamp (void *fit, int noffset, time_t timestamp)
2436 t = cpu_to_uimage (timestamp);
2437 ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t,
2440 printf ("Can't set '%s' property for '%s' node (%s)\n",
2441 FIT_TIMESTAMP_PROP, fit_get_name (fit, noffset, NULL),
2442 fdt_strerror (ret));
2450 * calculate_hash - calculate and return hash for provided input data
2451 * @data: pointer to the input data
2452 * @data_len: data length
2453 * @algo: requested hash algorithm
2454 * @value: pointer to the char, will hold hash value data (caller must
2455 * allocate enough free space)
2456 * value_len: length of the calculated hash
2458 * calculate_hash() computes input data hash according to the requested algorithm.
2459 * Resulting hash value is placed in caller provided 'value' buffer, length
2460 * of the calculated hash is returned via value_len pointer argument.
2464 * -1, when algo is unsupported
2466 static int calculate_hash (const void *data, int data_len, const char *algo,
2467 uint8_t *value, int *value_len)
2469 if (strcmp (algo, "crc32") == 0 ) {
2470 *((uint32_t *)value) = crc32_wd (0, data, data_len,
2472 *((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value));
2474 } else if (strcmp (algo, "sha1") == 0 ) {
2475 sha1_csum_wd ((unsigned char *) data, data_len,
2476 (unsigned char *) value, CHUNKSZ_SHA1);
2478 } else if (strcmp (algo, "md5") == 0 ) {
2479 md5_wd ((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
2482 debug ("Unsupported hash alogrithm\n");
2490 * fit_set_hashes - process FIT component image nodes and calculate hashes
2491 * @fit: pointer to the FIT format image header
2493 * fit_set_hashes() adds hash values for all component images in the FIT blob.
2494 * Hashes are calculated for all component images which have hash subnodes
2495 * with algorithm property set to one of the supported hash algorithms.
2499 * libfdt error code, on failure
2501 int fit_set_hashes (void *fit)
2508 /* Find images parent node offset */
2509 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2510 if (images_noffset < 0) {
2511 printf ("Can't find images parent node '%s' (%s)\n",
2512 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2513 return images_noffset;
2516 /* Process its subnodes, print out component images details */
2517 for (ndepth = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
2518 (noffset >= 0) && (ndepth > 0);
2519 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2522 * Direct child node of the images parent node,
2523 * i.e. component image node.
2525 ret = fit_image_set_hashes (fit, noffset);
2535 * fit_image_set_hashes - calculate/set hashes for given component image node
2536 * @fit: pointer to the FIT format image header
2537 * @image_noffset: requested component image node
2539 * fit_image_set_hashes() adds hash values for an component image node. All
2540 * existing hash subnodes are checked, if algorithm property is set to one of
2541 * the supported hash algorithms, hash value is computed and corresponding
2542 * hash node property is set, for example:
2544 * Input component image node structure:
2546 * o image@1 (at image_noffset)
2547 * | - data = [binary data]
2551 * Output component image node structure:
2553 * o image@1 (at image_noffset)
2554 * | - data = [binary data]
2557 * |- value = sha1(data)
2563 int fit_image_set_hashes (void *fit, int image_noffset)
2568 uint8_t value[FIT_MAX_HASH_LEN];
2573 /* Get image data and data length */
2574 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
2575 printf ("Can't get image data/size\n");
2579 /* Process all hash subnodes of the component image node */
2580 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2581 (noffset >= 0) && (ndepth > 0);
2582 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2584 /* Direct child node of the component image node */
2587 * Check subnode name, must be equal to "hash".
2588 * Multiple hash nodes require unique unit node
2589 * names, e.g. hash@1, hash@2, etc.
2591 if (strncmp (fit_get_name(fit, noffset, NULL),
2593 strlen(FIT_HASH_NODENAME)) != 0) {
2594 /* Not a hash subnode, skip it */
2598 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2599 printf ("Can't get hash algo property for "
2600 "'%s' hash node in '%s' image node\n",
2601 fit_get_name (fit, noffset, NULL),
2602 fit_get_name (fit, image_noffset, NULL));
2606 if (calculate_hash (data, size, algo, value, &value_len)) {
2607 printf ("Unsupported hash algorithm (%s) for "
2608 "'%s' hash node in '%s' image node\n",
2609 algo, fit_get_name (fit, noffset, NULL),
2610 fit_get_name (fit, image_noffset, NULL));
2614 if (fit_image_hash_set_value (fit, noffset, value,
2616 printf ("Can't set hash value for "
2617 "'%s' hash node in '%s' image node\n",
2618 fit_get_name (fit, noffset, NULL),
2619 fit_get_name (fit, image_noffset, NULL));
2629 * fit_image_hash_set_value - set hash value in requested has node
2630 * @fit: pointer to the FIT format image header
2631 * @noffset: hash node offset
2632 * @value: hash value to be set
2633 * @value_len: hash value length
2635 * fit_image_hash_set_value() attempts to set hash value in a node at offset
2636 * given and returns operation status to the caller.
2642 int fit_image_hash_set_value (void *fit, int noffset, uint8_t *value,
2647 ret = fdt_setprop (fit, noffset, FIT_VALUE_PROP, value, value_len);
2649 printf ("Can't set hash '%s' property for '%s' node (%s)\n",
2650 FIT_VALUE_PROP, fit_get_name (fit, noffset, NULL),
2651 fdt_strerror (ret));
2657 #endif /* USE_HOSTCC */
2660 * fit_image_check_hashes - verify data intergity
2661 * @fit: pointer to the FIT format image header
2662 * @image_noffset: component image node offset
2664 * fit_image_check_hashes() goes over component image hash nodes,
2665 * re-calculates each data hash and compares with the value stored in hash
2669 * 1, if all hashes are valid
2670 * 0, otherwise (or on error)
2672 int fit_image_check_hashes (const void *fit, int image_noffset)
2679 uint8_t value[FIT_MAX_HASH_LEN];
2685 /* Get image data and data length */
2686 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
2687 printf ("Can't get image data/size\n");
2691 /* Process all hash subnodes of the component image node */
2692 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2693 (noffset >= 0) && (ndepth > 0);
2694 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2696 /* Direct child node of the component image node */
2699 * Check subnode name, must be equal to "hash".
2700 * Multiple hash nodes require unique unit node
2701 * names, e.g. hash@1, hash@2, etc.
2703 if (strncmp (fit_get_name(fit, noffset, NULL),
2705 strlen(FIT_HASH_NODENAME)) != 0)
2708 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2709 err_msg = " error!\nCan't get hash algo "
2713 printf ("%s", algo);
2715 if (fit_image_hash_get_value (fit, noffset, &fit_value,
2717 err_msg = " error!\nCan't get hash value "
2722 if (calculate_hash (data, size, algo, value, &value_len)) {
2723 err_msg = " error!\nUnsupported hash algorithm";
2727 if (value_len != fit_value_len) {
2728 err_msg = " error !\nBad hash value len";
2730 } else if (memcmp (value, fit_value, value_len) != 0) {
2731 err_msg = " error!\nBad hash value";
2741 printf ("%s for '%s' hash node in '%s' image node\n",
2742 err_msg, fit_get_name (fit, noffset, NULL),
2743 fit_get_name (fit, image_noffset, NULL));
2748 * fit_all_image_check_hashes - verify data intergity for all images
2749 * @fit: pointer to the FIT format image header
2751 * fit_all_image_check_hashes() goes over all images in the FIT and
2752 * for every images checks if all it's hashes are valid.
2755 * 1, if all hashes of all images are valid
2756 * 0, otherwise (or on error)
2758 int fit_all_image_check_hashes (const void *fit)
2765 /* Find images parent node offset */
2766 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2767 if (images_noffset < 0) {
2768 printf ("Can't find images parent node '%s' (%s)\n",
2769 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2773 /* Process all image subnodes, check hashes for each */
2774 printf ("## Checking hash(es) for FIT Image at %08lx ...\n",
2776 for (ndepth = 0, count = 0,
2777 noffset = fdt_next_node (fit, images_noffset, &ndepth);
2778 (noffset >= 0) && (ndepth > 0);
2779 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2782 * Direct child node of the images parent node,
2783 * i.e. component image node.
2785 printf (" Hash(es) for Image %u (%s): ", count++,
2786 fit_get_name (fit, noffset, NULL));
2788 if (!fit_image_check_hashes (fit, noffset))
2797 * fit_image_check_os - check whether image node is of a given os type
2798 * @fit: pointer to the FIT format image header
2799 * @noffset: component image node offset
2800 * @os: requested image os
2802 * fit_image_check_os() reads image os property and compares its numeric
2803 * id with the requested os. Comparison result is returned to the caller.
2806 * 1 if image is of given os type
2807 * 0 otherwise (or on error)
2809 int fit_image_check_os (const void *fit, int noffset, uint8_t os)
2813 if (fit_image_get_os (fit, noffset, &image_os))
2815 return (os == image_os);
2819 * fit_image_check_arch - check whether image node is of a given arch
2820 * @fit: pointer to the FIT format image header
2821 * @noffset: component image node offset
2822 * @arch: requested imagearch
2824 * fit_image_check_arch() reads image arch property and compares its numeric
2825 * id with the requested arch. Comparison result is returned to the caller.
2828 * 1 if image is of given arch
2829 * 0 otherwise (or on error)
2831 int fit_image_check_arch (const void *fit, int noffset, uint8_t arch)
2835 if (fit_image_get_arch (fit, noffset, &image_arch))
2837 return (arch == image_arch);
2841 * fit_image_check_type - check whether image node is of a given type
2842 * @fit: pointer to the FIT format image header
2843 * @noffset: component image node offset
2844 * @type: requested image type
2846 * fit_image_check_type() reads image type property and compares its numeric
2847 * id with the requested type. Comparison result is returned to the caller.
2850 * 1 if image is of given type
2851 * 0 otherwise (or on error)
2853 int fit_image_check_type (const void *fit, int noffset, uint8_t type)
2857 if (fit_image_get_type (fit, noffset, &image_type))
2859 return (type == image_type);
2863 * fit_image_check_comp - check whether image node uses given compression
2864 * @fit: pointer to the FIT format image header
2865 * @noffset: component image node offset
2866 * @comp: requested image compression type
2868 * fit_image_check_comp() reads image compression property and compares its
2869 * numeric id with the requested compression type. Comparison result is
2870 * returned to the caller.
2873 * 1 if image uses requested compression
2874 * 0 otherwise (or on error)
2876 int fit_image_check_comp (const void *fit, int noffset, uint8_t comp)
2880 if (fit_image_get_comp (fit, noffset, &image_comp))
2882 return (comp == image_comp);
2886 * fit_check_format - sanity check FIT image format
2887 * @fit: pointer to the FIT format image header
2889 * fit_check_format() runs a basic sanity FIT image verification.
2890 * Routine checks for mandatory properties, nodes, etc.
2896 int fit_check_format (const void *fit)
2898 /* mandatory / node 'description' property */
2899 if (fdt_getprop (fit, 0, FIT_DESC_PROP, NULL) == NULL) {
2900 debug ("Wrong FIT format: no description\n");
2904 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
2905 /* mandatory / node 'timestamp' property */
2906 if (fdt_getprop (fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
2907 debug ("Wrong FIT format: no timestamp\n");
2912 /* mandatory subimages parent '/images' node */
2913 if (fdt_path_offset (fit, FIT_IMAGES_PATH) < 0) {
2914 debug ("Wrong FIT format: no images parent node\n");
2922 * fit_conf_get_node - get node offset for configuration of a given unit name
2923 * @fit: pointer to the FIT format image header
2924 * @conf_uname: configuration node unit name
2926 * fit_conf_get_node() finds a configuration (withing the '/configurations'
2927 * parant node) of a provided unit name. If configuration is found its node offset
2928 * is returned to the caller.
2930 * When NULL is provided in second argument fit_conf_get_node() will search
2931 * for a default configuration node instead. Default configuration node unit name
2932 * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
2935 * configuration node offset when found (>=0)
2936 * negative number on failure (FDT_ERR_* code)
2938 int fit_conf_get_node (const void *fit, const char *conf_uname)
2940 int noffset, confs_noffset;
2943 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
2944 if (confs_noffset < 0) {
2945 debug ("Can't find configurations parent node '%s' (%s)\n",
2946 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
2947 return confs_noffset;
2950 if (conf_uname == NULL) {
2951 /* get configuration unit name from the default property */
2952 debug ("No configuration specified, trying default...\n");
2953 conf_uname = (char *)fdt_getprop (fit, confs_noffset, FIT_DEFAULT_PROP, &len);
2954 if (conf_uname == NULL) {
2955 fit_get_debug (fit, confs_noffset, FIT_DEFAULT_PROP, len);
2958 debug ("Found default configuration: '%s'\n", conf_uname);
2961 noffset = fdt_subnode_offset (fit, confs_noffset, conf_uname);
2963 debug ("Can't get node offset for configuration unit name: '%s' (%s)\n",
2964 conf_uname, fdt_strerror (noffset));
2970 static int __fit_conf_get_prop_node (const void *fit, int noffset,
2971 const char *prop_name)
2976 /* get kernel image unit name from configuration kernel property */
2977 uname = (char *)fdt_getprop (fit, noffset, prop_name, &len);
2981 return fit_image_get_node (fit, uname);
2985 * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
2986 * a given configuration
2987 * @fit: pointer to the FIT format image header
2988 * @noffset: configuration node offset
2990 * fit_conf_get_kernel_node() retrives kernel image node unit name from
2991 * configuration FIT_KERNEL_PROP property and translates it to the node
2995 * image node offset when found (>=0)
2996 * negative number on failure (FDT_ERR_* code)
2998 int fit_conf_get_kernel_node (const void *fit, int noffset)
3000 return __fit_conf_get_prop_node (fit, noffset, FIT_KERNEL_PROP);
3004 * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
3005 * a given configuration
3006 * @fit: pointer to the FIT format image header
3007 * @noffset: configuration node offset
3009 * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
3010 * configuration FIT_KERNEL_PROP property and translates it to the node
3014 * image node offset when found (>=0)
3015 * negative number on failure (FDT_ERR_* code)
3017 int fit_conf_get_ramdisk_node (const void *fit, int noffset)
3019 return __fit_conf_get_prop_node (fit, noffset, FIT_RAMDISK_PROP);
3023 * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
3024 * a given configuration
3025 * @fit: pointer to the FIT format image header
3026 * @noffset: configuration node offset
3028 * fit_conf_get_fdt_node() retrives fdt image node unit name from
3029 * configuration FIT_KERNEL_PROP property and translates it to the node
3033 * image node offset when found (>=0)
3034 * negative number on failure (FDT_ERR_* code)
3036 int fit_conf_get_fdt_node (const void *fit, int noffset)
3038 return __fit_conf_get_prop_node (fit, noffset, FIT_FDT_PROP);
3042 * fit_conf_print - prints out the FIT configuration details
3043 * @fit: pointer to the FIT format image header
3044 * @noffset: offset of the configuration node
3045 * @p: pointer to prefix string
3047 * fit_conf_print() lists all mandatory properies for the processed
3048 * configuration node.
3051 * no returned results
3053 void fit_conf_print (const void *fit, int noffset, const char *p)
3059 /* Mandatory properties */
3060 ret = fit_get_desc (fit, noffset, &desc);
3061 printf ("%s Description: ", p);
3063 printf ("unavailable\n");
3065 printf ("%s\n", desc);
3067 uname = (char *)fdt_getprop (fit, noffset, FIT_KERNEL_PROP, NULL);
3068 printf ("%s Kernel: ", p);
3070 printf ("unavailable\n");
3072 printf ("%s\n", uname);
3074 /* Optional properties */
3075 uname = (char *)fdt_getprop (fit, noffset, FIT_RAMDISK_PROP, NULL);
3077 printf ("%s Init Ramdisk: %s\n", p, uname);
3079 uname = (char *)fdt_getprop (fit, noffset, FIT_FDT_PROP, NULL);
3081 printf ("%s FDT: %s\n", p, uname);
3085 * fit_check_ramdisk - verify FIT format ramdisk subimage
3086 * @fit_hdr: pointer to the FIT ramdisk header
3087 * @rd_noffset: ramdisk subimage node offset within FIT image
3088 * @arch: requested ramdisk image architecture type
3089 * @verify: data CRC verification flag
3091 * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
3092 * specified FIT image.
3099 static int fit_check_ramdisk (const void *fit, int rd_noffset, uint8_t arch, int verify)
3101 fit_image_print (fit, rd_noffset, " ");
3104 puts (" Verifying Hash Integrity ... ");
3105 if (!fit_image_check_hashes (fit, rd_noffset)) {
3106 puts ("Bad Data Hash\n");
3107 show_boot_progress (-125);
3113 show_boot_progress (126);
3114 if (!fit_image_check_os (fit, rd_noffset, IH_OS_LINUX) ||
3115 !fit_image_check_arch (fit, rd_noffset, arch) ||
3116 !fit_image_check_type (fit, rd_noffset, IH_TYPE_RAMDISK)) {
3117 printf ("No Linux %s Ramdisk Image\n",
3118 genimg_get_arch_name(arch));
3119 show_boot_progress (-126);
3123 show_boot_progress (127);
3126 #endif /* USE_HOSTCC */
3127 #endif /* CONFIG_FIT */