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_INVALID, NULL, "Invalid Image", },
137 { IH_TYPE_IMXIMAGE, "imximage", "Freescale i.MX Boot Image",},
138 { IH_TYPE_KERNEL, "kernel", "Kernel Image", },
139 { IH_TYPE_KWBIMAGE, "kwbimage", "Kirkwood Boot Image",},
140 { IH_TYPE_MULTI, "multi", "Multi-File Image", },
141 { IH_TYPE_OMAPIMAGE, "omapimage", "TI OMAP SPL With GP CH",},
142 { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", },
143 { IH_TYPE_SCRIPT, "script", "Script", },
144 { IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
145 { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", },
146 { IH_TYPE_KWBIMAGE, "kwbimage", "Kirkwood Boot Image",},
147 { IH_TYPE_IMXIMAGE, "imximage", "Freescale i.MX Boot Image",},
148 { IH_TYPE_UBLIMAGE, "ublimage", "Davinci UBL image",},
152 static const table_entry_t uimage_comp[] = {
153 { IH_COMP_NONE, "none", "uncompressed", },
154 { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", },
155 { IH_COMP_GZIP, "gzip", "gzip compressed", },
156 { IH_COMP_LZMA, "lzma", "lzma compressed", },
157 { IH_COMP_LZO, "lzo", "lzo compressed", },
161 uint32_t crc32 (uint32_t, const unsigned char *, uint);
162 uint32_t crc32_wd (uint32_t, const unsigned char *, uint, uint);
163 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
164 static void genimg_print_time (time_t timestamp);
167 /*****************************************************************************/
168 /* Legacy format routines */
169 /*****************************************************************************/
170 int image_check_hcrc (const image_header_t *hdr)
173 ulong len = image_get_header_size ();
174 image_header_t header;
176 /* Copy header so we can blank CRC field for re-calculation */
177 memmove (&header, (char *)hdr, image_get_header_size ());
178 image_set_hcrc (&header, 0);
180 hcrc = crc32 (0, (unsigned char *)&header, len);
182 return (hcrc == image_get_hcrc (hdr));
185 int image_check_dcrc (const image_header_t *hdr)
187 ulong data = image_get_data (hdr);
188 ulong len = image_get_data_size (hdr);
189 ulong dcrc = crc32_wd (0, (unsigned char *)data, len, CHUNKSZ_CRC32);
191 return (dcrc == image_get_dcrc (hdr));
195 * image_multi_count - get component (sub-image) count
196 * @hdr: pointer to the header of the multi component image
198 * image_multi_count() returns number of components in a multi
201 * Note: no checking of the image type is done, caller must pass
202 * a valid multi component image.
205 * number of components
207 ulong image_multi_count (const image_header_t *hdr)
212 /* get start of the image payload, which in case of multi
213 * component images that points to a table of component sizes */
214 size = (uint32_t *)image_get_data (hdr);
216 /* count non empty slots */
217 for (i = 0; size[i]; ++i)
224 * image_multi_getimg - get component data address and size
225 * @hdr: pointer to the header of the multi component image
226 * @idx: index of the requested component
227 * @data: pointer to a ulong variable, will hold component data address
228 * @len: pointer to a ulong variable, will hold component size
230 * image_multi_getimg() returns size and data address for the requested
231 * component in a multi component image.
233 * Note: no checking of the image type is done, caller must pass
234 * a valid multi component image.
237 * data address and size of the component, if idx is valid
238 * 0 in data and len, if idx is out of range
240 void image_multi_getimg (const image_header_t *hdr, ulong idx,
241 ulong *data, ulong *len)
245 ulong offset, count, img_data;
247 /* get number of component */
248 count = image_multi_count (hdr);
250 /* get start of the image payload, which in case of multi
251 * component images that points to a table of component sizes */
252 size = (uint32_t *)image_get_data (hdr);
254 /* get address of the proper component data start, which means
255 * skipping sizes table (add 1 for last, null entry) */
256 img_data = image_get_data (hdr) + (count + 1) * sizeof (uint32_t);
259 *len = uimage_to_cpu (size[idx]);
262 /* go over all indices preceding requested component idx */
263 for (i = 0; i < idx; i++) {
264 /* add up i-th component size, rounding up to 4 bytes */
265 offset += (uimage_to_cpu (size[i]) + 3) & ~3 ;
268 /* calculate idx-th component data address */
269 *data = img_data + offset;
276 static void image_print_type (const image_header_t *hdr)
278 const char *os, *arch, *type, *comp;
280 os = genimg_get_os_name (image_get_os (hdr));
281 arch = genimg_get_arch_name (image_get_arch (hdr));
282 type = genimg_get_type_name (image_get_type (hdr));
283 comp = genimg_get_comp_name (image_get_comp (hdr));
285 printf ("%s %s %s (%s)\n", arch, os, type, comp);
289 * image_print_contents - prints out the contents of the legacy format image
290 * @ptr: pointer to the legacy format image header
291 * @p: pointer to prefix string
293 * image_print_contents() formats a multi line legacy image contents description.
294 * The routine prints out all header fields followed by the size/offset data
295 * for MULTI/SCRIPT images.
298 * no returned results
300 void image_print_contents (const void *ptr)
302 const image_header_t *hdr = (const image_header_t *)ptr;
311 printf ("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name (hdr));
312 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
313 printf ("%sCreated: ", p);
314 genimg_print_time ((time_t)image_get_time (hdr));
316 printf ("%sImage Type: ", p);
317 image_print_type (hdr);
318 printf ("%sData Size: ", p);
319 genimg_print_size (image_get_data_size (hdr));
320 printf ("%sLoad Address: %08x\n", p, image_get_load (hdr));
321 printf ("%sEntry Point: %08x\n", p, image_get_ep (hdr));
323 if (image_check_type (hdr, IH_TYPE_MULTI) ||
324 image_check_type (hdr, IH_TYPE_SCRIPT)) {
327 ulong count = image_multi_count (hdr);
329 printf ("%sContents:\n", p);
330 for (i = 0; i < count; i++) {
331 image_multi_getimg (hdr, i, &data, &len);
333 printf ("%s Image %d: ", p, i);
334 genimg_print_size (len);
336 if (image_check_type (hdr, IH_TYPE_SCRIPT) && i > 0) {
338 * the user may need to know offsets
339 * if planning to do something with
342 printf ("%s Offset = 0x%08lx\n", p, data);
351 * image_get_ramdisk - get and verify ramdisk image
352 * @rd_addr: ramdisk image start address
353 * @arch: expected ramdisk architecture
354 * @verify: checksum verification flag
356 * image_get_ramdisk() returns a pointer to the verified ramdisk image
357 * header. Routine receives image start address and expected architecture
358 * flag. Verification done covers data and header integrity and os/type/arch
361 * If dataflash support is enabled routine checks for dataflash addresses
362 * and handles required dataflash reads.
365 * pointer to a ramdisk image header, if image was found and valid
366 * otherwise, return NULL
368 static const image_header_t *image_get_ramdisk (ulong rd_addr, uint8_t arch,
371 const image_header_t *rd_hdr = (const image_header_t *)rd_addr;
373 if (!image_check_magic (rd_hdr)) {
374 puts ("Bad Magic Number\n");
375 show_boot_progress (-10);
379 if (!image_check_hcrc (rd_hdr)) {
380 puts ("Bad Header Checksum\n");
381 show_boot_progress (-11);
385 show_boot_progress (10);
386 image_print_contents (rd_hdr);
389 puts(" Verifying Checksum ... ");
390 if (!image_check_dcrc (rd_hdr)) {
391 puts ("Bad Data CRC\n");
392 show_boot_progress (-12);
398 show_boot_progress (11);
400 if (!image_check_os (rd_hdr, IH_OS_LINUX) ||
401 !image_check_arch (rd_hdr, arch) ||
402 !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) {
403 printf ("No Linux %s Ramdisk Image\n",
404 genimg_get_arch_name(arch));
405 show_boot_progress (-13);
411 #endif /* !USE_HOSTCC */
413 /*****************************************************************************/
414 /* Shared dual-format routines */
415 /*****************************************************************************/
417 int getenv_yesno (char *var)
419 char *s = getenv (var);
420 return (s && (*s == 'n')) ? 0 : 1;
423 ulong getenv_bootm_low(void)
425 char *s = getenv ("bootm_low");
427 ulong tmp = simple_strtoul (s, NULL, 16);
431 #if defined(CONFIG_SYS_SDRAM_BASE)
432 return CONFIG_SYS_SDRAM_BASE;
433 #elif defined(CONFIG_ARM)
434 return gd->bd->bi_dram[0].start;
440 phys_size_t getenv_bootm_size(void)
443 char *s = getenv ("bootm_size");
445 tmp = (phys_size_t)simple_strtoull (s, NULL, 16);
448 s = getenv("bootm_low");
450 tmp = (phys_size_t)simple_strtoull (s, NULL, 16);
455 #if defined(CONFIG_ARM)
456 return gd->bd->bi_dram[0].size - tmp;
458 return gd->bd->bi_memsize - tmp;
462 phys_size_t getenv_bootm_mapsize(void)
465 char *s = getenv ("bootm_mapsize");
467 tmp = (phys_size_t)simple_strtoull (s, NULL, 16);
471 #if defined(CONFIG_SYS_BOOTMAPSZ)
472 return CONFIG_SYS_BOOTMAPSZ;
474 return getenv_bootm_size();
478 void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
483 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
485 size_t tail = (len > chunksz) ? chunksz : len;
487 memmove (to, from, tail);
492 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
493 memmove (to, from, len);
494 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
496 #endif /* !USE_HOSTCC */
498 void genimg_print_size (uint32_t size)
501 printf ("%d Bytes = ", size);
502 print_size (size, "\n");
504 printf ("%d Bytes = %.2f kB = %.2f MB\n",
505 size, (double)size / 1.024e3,
506 (double)size / 1.048576e6);
510 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
511 static void genimg_print_time (time_t timestamp)
516 to_tm (timestamp, &tm);
517 printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
518 tm.tm_year, tm.tm_mon, tm.tm_mday,
519 tm.tm_hour, tm.tm_min, tm.tm_sec);
521 printf ("%s", ctime(×tamp));
524 #endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */
527 * get_table_entry_name - translate entry id to long name
528 * @table: pointer to a translation table for entries of a specific type
529 * @msg: message to be returned when translation fails
530 * @id: entry id to be translated
532 * get_table_entry_name() will go over translation table trying to find
533 * entry that matches given id. If matching entry is found, its long
534 * name is returned to the caller.
537 * long entry name if translation succeeds
540 char *get_table_entry_name(const table_entry_t *table, char *msg, int id)
542 for (; table->id >= 0; ++table) {
544 #if defined(USE_HOSTCC) || !defined(CONFIG_NEEDS_MANUAL_RELOC)
547 return table->lname + gd->reloc_off;
553 const char *genimg_get_os_name (uint8_t os)
555 return (get_table_entry_name (uimage_os, "Unknown OS", os));
558 const char *genimg_get_arch_name (uint8_t arch)
560 return (get_table_entry_name (uimage_arch, "Unknown Architecture", arch));
563 const char *genimg_get_type_name (uint8_t type)
565 return (get_table_entry_name (uimage_type, "Unknown Image", type));
568 const char *genimg_get_comp_name (uint8_t comp)
570 return (get_table_entry_name (uimage_comp, "Unknown Compression", comp));
574 * get_table_entry_id - translate short entry name to id
575 * @table: pointer to a translation table for entries of a specific type
576 * @table_name: to be used in case of error
577 * @name: entry short name to be translated
579 * get_table_entry_id() will go over translation table trying to find
580 * entry that matches given short name. If matching entry is found,
581 * its id returned to the caller.
584 * entry id if translation succeeds
587 int get_table_entry_id(const table_entry_t *table,
588 const char *table_name, const char *name)
590 const table_entry_t *t;
594 for (t = table; t->id >= 0; ++t) {
595 if (t->sname && strcasecmp(t->sname, name) == 0)
599 fprintf (stderr, "\nInvalid %s Type - valid names are", table_name);
600 for (t = table; t->id >= 0; ++t) {
601 if (t->sname == NULL)
603 fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname);
606 fprintf (stderr, "\n");
608 for (t = table; t->id >= 0; ++t) {
609 #ifdef CONFIG_NEEDS_MANUAL_RELOC
610 if (t->sname && strcmp(t->sname + gd->reloc_off, name) == 0)
612 if (t->sname && strcmp(t->sname, name) == 0)
616 debug ("Invalid %s Type: %s\n", table_name, name);
617 #endif /* USE_HOSTCC */
621 int genimg_get_os_id (const char *name)
623 return (get_table_entry_id (uimage_os, "OS", name));
626 int genimg_get_arch_id (const char *name)
628 return (get_table_entry_id (uimage_arch, "CPU", name));
631 int genimg_get_type_id (const char *name)
633 return (get_table_entry_id (uimage_type, "Image", name));
636 int genimg_get_comp_id (const char *name)
638 return (get_table_entry_id (uimage_comp, "Compression", name));
643 * genimg_get_format - get image format type
644 * @img_addr: image start address
646 * genimg_get_format() checks whether provided address points to a valid
647 * legacy or FIT image.
649 * New uImage format and FDT blob are based on a libfdt. FDT blob
650 * may be passed directly or embedded in a FIT image. In both situations
651 * genimg_get_format() must be able to dectect libfdt header.
654 * image format type or IMAGE_FORMAT_INVALID if no image is present
656 int genimg_get_format (void *img_addr)
658 ulong format = IMAGE_FORMAT_INVALID;
659 const image_header_t *hdr;
660 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
664 hdr = (const image_header_t *)img_addr;
665 if (image_check_magic(hdr))
666 format = IMAGE_FORMAT_LEGACY;
667 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
669 fit_hdr = (char *)img_addr;
670 if (fdt_check_header (fit_hdr) == 0)
671 format = IMAGE_FORMAT_FIT;
679 * genimg_get_image - get image from special storage (if necessary)
680 * @img_addr: image start address
682 * genimg_get_image() checks if provided image start adddress is located
683 * in a dataflash storage. If so, image is moved to a system RAM memory.
686 * image start address after possible relocation from special storage
688 ulong genimg_get_image (ulong img_addr)
690 ulong ram_addr = img_addr;
692 #ifdef CONFIG_HAS_DATAFLASH
693 ulong h_size, d_size;
695 if (addr_dataflash (img_addr)){
696 /* ger RAM address */
697 ram_addr = CONFIG_SYS_LOAD_ADDR;
699 /* get header size */
700 h_size = image_get_header_size ();
701 #if defined(CONFIG_FIT)
702 if (sizeof(struct fdt_header) > h_size)
703 h_size = sizeof(struct fdt_header);
707 debug (" Reading image header from dataflash address "
708 "%08lx to RAM address %08lx\n", img_addr, ram_addr);
710 read_dataflash (img_addr, h_size, (char *)ram_addr);
713 switch (genimg_get_format ((void *)ram_addr)) {
714 case IMAGE_FORMAT_LEGACY:
715 d_size = image_get_data_size ((const image_header_t *)ram_addr);
716 debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n",
719 #if defined(CONFIG_FIT)
720 case IMAGE_FORMAT_FIT:
721 d_size = fit_get_size ((const void *)ram_addr) - h_size;
722 debug (" FIT/FDT format image found at 0x%08lx, size 0x%08lx\n",
727 printf (" No valid image found at 0x%08lx\n", img_addr);
731 /* read in image data */
732 debug (" Reading image remaining data from dataflash address "
733 "%08lx to RAM address %08lx\n", img_addr + h_size,
736 read_dataflash (img_addr + h_size, d_size,
737 (char *)(ram_addr + h_size));
740 #endif /* CONFIG_HAS_DATAFLASH */
746 * fit_has_config - check if there is a valid FIT configuration
747 * @images: pointer to the bootm command headers structure
749 * fit_has_config() checks if there is a FIT configuration in use
750 * (if FTI support is present).
753 * 0, no FIT support or no configuration found
754 * 1, configuration found
756 int genimg_has_config (bootm_headers_t *images)
758 #if defined(CONFIG_FIT)
759 if (images->fit_uname_cfg)
766 * boot_get_ramdisk - main ramdisk handling routine
767 * @argc: command argument count
768 * @argv: command argument list
769 * @images: pointer to the bootm images structure
770 * @arch: expected ramdisk architecture
771 * @rd_start: pointer to a ulong variable, will hold ramdisk start address
772 * @rd_end: pointer to a ulong variable, will hold ramdisk end
774 * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
775 * Curently supported are the following ramdisk sources:
776 * - multicomponent kernel/ramdisk image,
777 * - commandline provided address of decicated ramdisk image.
780 * 0, if ramdisk image was found and valid, or skiped
781 * rd_start and rd_end are set to ramdisk start/end addresses if
782 * ramdisk image is found and valid
784 * 1, if ramdisk image is found but corrupted, or invalid
785 * rd_start and rd_end are set to 0 if no ramdisk exists
787 int boot_get_ramdisk (int argc, char * const argv[], bootm_headers_t *images,
788 uint8_t arch, ulong *rd_start, ulong *rd_end)
790 ulong rd_addr, rd_load;
791 ulong rd_data, rd_len;
792 const image_header_t *rd_hdr;
793 #if defined(CONFIG_FIT)
795 const char *fit_uname_config = NULL;
796 const char *fit_uname_ramdisk = NULL;
808 * Look for a '-' which indicates to ignore the
811 if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) {
812 debug ("## Skipping init Ramdisk\n");
813 rd_len = rd_data = 0;
814 } else if (argc >= 3 || genimg_has_config (images)) {
815 #if defined(CONFIG_FIT)
818 * If the init ramdisk comes from the FIT image and
819 * the FIT image address is omitted in the command
820 * line argument, try to use os FIT image address or
821 * default load address.
823 if (images->fit_uname_os)
824 default_addr = (ulong)images->fit_hdr_os;
826 default_addr = load_addr;
828 if (fit_parse_conf (argv[2], default_addr,
829 &rd_addr, &fit_uname_config)) {
830 debug ("* ramdisk: config '%s' from image at 0x%08lx\n",
831 fit_uname_config, rd_addr);
832 } else if (fit_parse_subimage (argv[2], default_addr,
833 &rd_addr, &fit_uname_ramdisk)) {
834 debug ("* ramdisk: subimage '%s' from image at 0x%08lx\n",
835 fit_uname_ramdisk, rd_addr);
839 rd_addr = simple_strtoul(argv[2], NULL, 16);
840 debug ("* ramdisk: cmdline image address = 0x%08lx\n",
843 #if defined(CONFIG_FIT)
845 /* use FIT configuration provided in first bootm
848 rd_addr = (ulong)images->fit_hdr_os;
849 fit_uname_config = images->fit_uname_cfg;
850 debug ("* ramdisk: using config '%s' from image at 0x%08lx\n",
851 fit_uname_config, rd_addr);
854 * Check whether configuration has ramdisk defined,
855 * if not, don't try to use it, quit silently.
857 fit_hdr = (void *)rd_addr;
858 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
859 if (cfg_noffset < 0) {
860 debug ("* ramdisk: no such config\n");
864 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
865 if (rd_noffset < 0) {
866 debug ("* ramdisk: no ramdisk in config\n");
872 /* copy from dataflash if needed */
873 rd_addr = genimg_get_image (rd_addr);
876 * Check if there is an initrd image at the
877 * address provided in the second bootm argument
878 * check image type, for FIT images get FIT node.
880 switch (genimg_get_format ((void *)rd_addr)) {
881 case IMAGE_FORMAT_LEGACY:
882 printf ("## Loading init Ramdisk from Legacy "
883 "Image at %08lx ...\n", rd_addr);
885 show_boot_progress (9);
886 rd_hdr = image_get_ramdisk (rd_addr, arch,
892 rd_data = image_get_data (rd_hdr);
893 rd_len = image_get_data_size (rd_hdr);
894 rd_load = image_get_load (rd_hdr);
896 #if defined(CONFIG_FIT)
897 case IMAGE_FORMAT_FIT:
898 fit_hdr = (void *)rd_addr;
899 printf ("## Loading init Ramdisk from FIT "
900 "Image at %08lx ...\n", rd_addr);
902 show_boot_progress (120);
903 if (!fit_check_format (fit_hdr)) {
904 puts ("Bad FIT ramdisk image format!\n");
905 show_boot_progress (-120);
908 show_boot_progress (121);
910 if (!fit_uname_ramdisk) {
912 * no ramdisk image node unit name, try to get config
913 * node first. If config unit node name is NULL
914 * fit_conf_get_node() will try to find default config node
916 show_boot_progress (122);
917 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
918 if (cfg_noffset < 0) {
919 puts ("Could not find configuration node\n");
920 show_boot_progress (-122);
923 fit_uname_config = fdt_get_name (fit_hdr, cfg_noffset, NULL);
924 printf (" Using '%s' configuration\n", fit_uname_config);
926 rd_noffset = fit_conf_get_ramdisk_node (fit_hdr, cfg_noffset);
927 fit_uname_ramdisk = fit_get_name (fit_hdr, rd_noffset, NULL);
929 /* get ramdisk component image node offset */
930 show_boot_progress (123);
931 rd_noffset = fit_image_get_node (fit_hdr, fit_uname_ramdisk);
933 if (rd_noffset < 0) {
934 puts ("Could not find subimage node\n");
935 show_boot_progress (-124);
939 printf (" Trying '%s' ramdisk subimage\n", fit_uname_ramdisk);
941 show_boot_progress (125);
942 if (!fit_check_ramdisk (fit_hdr, rd_noffset, arch, images->verify))
945 /* get ramdisk image data address and length */
946 if (fit_image_get_data (fit_hdr, rd_noffset, &data, &size)) {
947 puts ("Could not find ramdisk subimage data!\n");
948 show_boot_progress (-127);
951 show_boot_progress (128);
953 rd_data = (ulong)data;
956 if (fit_image_get_load (fit_hdr, rd_noffset, &rd_load)) {
957 puts ("Can't get ramdisk subimage load address!\n");
958 show_boot_progress (-129);
961 show_boot_progress (129);
963 images->fit_hdr_rd = fit_hdr;
964 images->fit_uname_rd = fit_uname_ramdisk;
965 images->fit_noffset_rd = rd_noffset;
969 puts ("Wrong Ramdisk Image Format\n");
970 rd_data = rd_len = rd_load = 0;
974 #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO)
976 * We need to copy the ramdisk to SRAM to let Linux boot
979 memmove ((void *)rd_load, (uchar *)rd_data, rd_len);
982 #endif /* CONFIG_B2 || CONFIG_EVB4510 || CONFIG_ARMADILLO */
984 } else if (images->legacy_hdr_valid &&
985 image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
987 * Now check if we have a legacy mult-component image,
988 * get second entry data start address and len.
990 show_boot_progress (13);
991 printf ("## Loading init Ramdisk from multi component "
992 "Legacy Image at %08lx ...\n",
993 (ulong)images->legacy_hdr_os);
995 image_multi_getimg (images->legacy_hdr_os, 1, &rd_data, &rd_len);
1000 show_boot_progress (14);
1001 rd_len = rd_data = 0;
1005 debug ("## No init Ramdisk\n");
1007 *rd_start = rd_data;
1008 *rd_end = rd_data + rd_len;
1010 debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
1011 *rd_start, *rd_end);
1016 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
1018 * boot_ramdisk_high - relocate init ramdisk
1019 * @lmb: pointer to lmb handle, will be used for memory mgmt
1020 * @rd_data: ramdisk data start address
1021 * @rd_len: ramdisk data length
1022 * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
1023 * start address (after possible relocation)
1024 * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
1025 * end address (after possible relocation)
1027 * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
1028 * variable and if requested ramdisk data is moved to a specified location.
1030 * Initrd_start and initrd_end are set to final (after relocation) ramdisk
1031 * start/end addresses if ramdisk image start and len were provided,
1032 * otherwise set initrd_start and initrd_end set to zeros.
1038 int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
1039 ulong *initrd_start, ulong *initrd_end)
1043 int initrd_copy_to_ram = 1;
1045 if ((s = getenv ("initrd_high")) != NULL) {
1046 /* a value of "no" or a similar string will act like 0,
1047 * turning the "load high" feature off. This is intentional.
1049 initrd_high = simple_strtoul (s, NULL, 16);
1050 if (initrd_high == ~0)
1051 initrd_copy_to_ram = 0;
1053 /* not set, no restrictions to load high */
1058 #ifdef CONFIG_LOGBUFFER
1059 /* Prevent initrd from overwriting logbuffer */
1060 lmb_reserve(lmb, logbuffer_base() - LOGBUFF_OVERHEAD, LOGBUFF_RESERVE);
1063 debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
1064 initrd_high, initrd_copy_to_ram);
1067 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
1068 debug (" in-place initrd\n");
1069 *initrd_start = rd_data;
1070 *initrd_end = rd_data + rd_len;
1071 lmb_reserve(lmb, rd_data, rd_len);
1074 *initrd_start = (ulong)lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
1076 *initrd_start = (ulong)lmb_alloc (lmb, rd_len, 0x1000);
1078 if (*initrd_start == 0) {
1079 puts ("ramdisk - allocation error\n");
1082 show_boot_progress (12);
1084 *initrd_end = *initrd_start + rd_len;
1085 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
1086 *initrd_start, *initrd_end);
1088 memmove_wd ((void *)*initrd_start,
1089 (void *)rd_data, rd_len, CHUNKSZ);
1097 debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
1098 *initrd_start, *initrd_end);
1105 #endif /* CONFIG_SYS_BOOT_RAMDISK_HIGH */
1107 #ifdef CONFIG_OF_LIBFDT
1108 static void fdt_error (const char *msg)
1112 puts (" - must RESET the board to recover.\n");
1115 static const image_header_t *image_get_fdt (ulong fdt_addr)
1117 const image_header_t *fdt_hdr = (const image_header_t *)fdt_addr;
1119 image_print_contents (fdt_hdr);
1121 puts (" Verifying Checksum ... ");
1122 if (!image_check_hcrc (fdt_hdr)) {
1123 fdt_error ("fdt header checksum invalid");
1127 if (!image_check_dcrc (fdt_hdr)) {
1128 fdt_error ("fdt checksum invalid");
1133 if (!image_check_type (fdt_hdr, IH_TYPE_FLATDT)) {
1134 fdt_error ("uImage is not a fdt");
1137 if (image_get_comp (fdt_hdr) != IH_COMP_NONE) {
1138 fdt_error ("uImage is compressed");
1141 if (fdt_check_header ((char *)image_get_data (fdt_hdr)) != 0) {
1142 fdt_error ("uImage data is not a fdt");
1149 * fit_check_fdt - verify FIT format FDT subimage
1150 * @fit_hdr: pointer to the FIT header
1151 * fdt_noffset: FDT subimage node offset within FIT image
1152 * @verify: data CRC verification flag
1154 * fit_check_fdt() verifies integrity of the FDT subimage and from
1155 * specified FIT image.
1161 #if defined(CONFIG_FIT)
1162 static int fit_check_fdt (const void *fit, int fdt_noffset, int verify)
1164 fit_image_print (fit, fdt_noffset, " ");
1167 puts (" Verifying Hash Integrity ... ");
1168 if (!fit_image_check_hashes (fit, fdt_noffset)) {
1169 fdt_error ("Bad Data Hash");
1175 if (!fit_image_check_type (fit, fdt_noffset, IH_TYPE_FLATDT)) {
1176 fdt_error ("Not a FDT image");
1180 if (!fit_image_check_comp (fit, fdt_noffset, IH_COMP_NONE)) {
1181 fdt_error ("FDT image is compressed");
1187 #endif /* CONFIG_FIT */
1189 #ifndef CONFIG_SYS_FDT_PAD
1190 #define CONFIG_SYS_FDT_PAD 0x3000
1193 #if defined(CONFIG_OF_LIBFDT)
1195 * boot_fdt_add_mem_rsv_regions - Mark the memreserve sections as unusable
1196 * @lmb: pointer to lmb handle, will be used for memory mgmt
1197 * @fdt_blob: pointer to fdt blob base address
1199 * Adds the memreserve regions in the dtb to the lmb block. Adding the
1200 * memreserve regions prevents u-boot from using them to store the initrd
1203 void boot_fdt_add_mem_rsv_regions(struct lmb *lmb, void *fdt_blob)
1205 uint64_t addr, size;
1208 if (fdt_check_header (fdt_blob) != 0)
1211 total = fdt_num_mem_rsv(fdt_blob);
1212 for (i = 0; i < total; i++) {
1213 if (fdt_get_mem_rsv(fdt_blob, i, &addr, &size) != 0)
1215 printf(" reserving fdt memory region: addr=%llx size=%llx\n",
1216 (unsigned long long)addr, (unsigned long long)size);
1217 lmb_reserve(lmb, addr, size);
1222 * boot_relocate_fdt - relocate flat device tree
1223 * @lmb: pointer to lmb handle, will be used for memory mgmt
1224 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1225 * @of_size: pointer to a ulong variable, will hold fdt length
1227 * boot_relocate_fdt() allocates a region of memory within the bootmap and
1228 * relocates the of_flat_tree into that region, even if the fdt is already in
1229 * the bootmap. It also expands the size of the fdt by CONFIG_SYS_FDT_PAD
1232 * of_flat_tree and of_size are set to final (after relocation) values
1238 int boot_relocate_fdt (struct lmb *lmb, char **of_flat_tree, ulong *of_size)
1240 void *fdt_blob = *of_flat_tree;
1245 int disable_relocation = 0;
1251 if (fdt_check_header (fdt_blob) != 0) {
1252 fdt_error ("image is not a fdt");
1256 /* position on a 4K boundary before the alloc_current */
1257 /* Pad the FDT by a specified amount */
1258 of_len = *of_size + CONFIG_SYS_FDT_PAD;
1260 /* If fdt_high is set use it to select the relocation address */
1261 fdt_high = getenv("fdt_high");
1263 void *desired_addr = (void *)simple_strtoul(fdt_high, NULL, 16);
1265 if (((ulong) desired_addr) == ~0UL) {
1266 /* All ones means use fdt in place */
1267 desired_addr = fdt_blob;
1268 disable_relocation = 1;
1272 (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
1276 if (desired_addr && of_start != desired_addr) {
1277 puts("Failed using fdt_high value for Device Tree");
1282 (void *)(ulong) lmb_alloc(lmb, of_len, 0x1000);
1286 (void *)(ulong) lmb_alloc_base(lmb, of_len, 0x1000,
1287 getenv_bootm_mapsize()
1288 + getenv_bootm_low());
1291 if (of_start == 0) {
1292 puts("device tree - allocation error\n");
1296 if (disable_relocation) {
1297 /* We assume there is space after the existing fdt to use for padding */
1298 fdt_set_totalsize(of_start, of_len);
1299 printf(" Using Device Tree in place at %p, end %p\n",
1300 of_start, of_start + of_len - 1);
1302 debug ("## device tree at %p ... %p (len=%ld [0x%lX])\n",
1303 fdt_blob, fdt_blob + *of_size - 1, of_len, of_len);
1305 printf (" Loading Device Tree to %p, end %p ... ",
1306 of_start, of_start + of_len - 1);
1308 err = fdt_open_into (fdt_blob, of_start, of_len);
1310 fdt_error ("fdt move failed");
1316 *of_flat_tree = of_start;
1319 set_working_fdt_addr(*of_flat_tree);
1325 #endif /* CONFIG_OF_LIBFDT */
1328 * boot_get_fdt - main fdt handling routine
1329 * @argc: command argument count
1330 * @argv: command argument list
1331 * @images: pointer to the bootm images structure
1332 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1333 * @of_size: pointer to a ulong variable, will hold fdt length
1335 * boot_get_fdt() is responsible for finding a valid flat device tree image.
1336 * Curently supported are the following ramdisk sources:
1337 * - multicomponent kernel/ramdisk image,
1338 * - commandline provided address of decicated ramdisk image.
1341 * 0, if fdt image was found and valid, or skipped
1342 * of_flat_tree and of_size are set to fdt start address and length if
1343 * fdt image is found and valid
1345 * 1, if fdt image is found but corrupted
1346 * of_flat_tree and of_size are set to 0 if no fdt exists
1348 int boot_get_fdt (int flag, int argc, char * const argv[], bootm_headers_t *images,
1349 char **of_flat_tree, ulong *of_size)
1351 const image_header_t *fdt_hdr;
1353 char *fdt_blob = NULL;
1354 ulong image_start, image_end;
1355 ulong load_start, load_end;
1356 #if defined(CONFIG_FIT)
1358 const char *fit_uname_config = NULL;
1359 const char *fit_uname_fdt = NULL;
1367 *of_flat_tree = NULL;
1370 if (argc > 3 || genimg_has_config (images)) {
1371 #if defined(CONFIG_FIT)
1374 * If the FDT blob comes from the FIT image and the
1375 * FIT image address is omitted in the command line
1376 * argument, try to use ramdisk or os FIT image
1377 * address or default load address.
1379 if (images->fit_uname_rd)
1380 default_addr = (ulong)images->fit_hdr_rd;
1381 else if (images->fit_uname_os)
1382 default_addr = (ulong)images->fit_hdr_os;
1384 default_addr = load_addr;
1386 if (fit_parse_conf (argv[3], default_addr,
1387 &fdt_addr, &fit_uname_config)) {
1388 debug ("* fdt: config '%s' from image at 0x%08lx\n",
1389 fit_uname_config, fdt_addr);
1390 } else if (fit_parse_subimage (argv[3], default_addr,
1391 &fdt_addr, &fit_uname_fdt)) {
1392 debug ("* fdt: subimage '%s' from image at 0x%08lx\n",
1393 fit_uname_fdt, fdt_addr);
1397 fdt_addr = simple_strtoul(argv[3], NULL, 16);
1398 debug ("* fdt: cmdline image address = 0x%08lx\n",
1401 #if defined(CONFIG_FIT)
1403 /* use FIT configuration provided in first bootm
1406 fdt_addr = (ulong)images->fit_hdr_os;
1407 fit_uname_config = images->fit_uname_cfg;
1408 debug ("* fdt: using config '%s' from image at 0x%08lx\n",
1409 fit_uname_config, fdt_addr);
1412 * Check whether configuration has FDT blob defined,
1413 * if not quit silently.
1415 fit_hdr = (void *)fdt_addr;
1416 cfg_noffset = fit_conf_get_node (fit_hdr,
1418 if (cfg_noffset < 0) {
1419 debug ("* fdt: no such config\n");
1423 fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
1425 if (fdt_noffset < 0) {
1426 debug ("* fdt: no fdt in config\n");
1432 debug ("## Checking for 'FDT'/'FDT Image' at %08lx\n",
1435 /* copy from dataflash if needed */
1436 fdt_addr = genimg_get_image (fdt_addr);
1439 * Check if there is an FDT image at the
1440 * address provided in the second bootm argument
1441 * check image type, for FIT images get a FIT node.
1443 switch (genimg_get_format ((void *)fdt_addr)) {
1444 case IMAGE_FORMAT_LEGACY:
1445 /* verify fdt_addr points to a valid image header */
1446 printf ("## Flattened Device Tree from Legacy Image at %08lx\n",
1448 fdt_hdr = image_get_fdt (fdt_addr);
1453 * move image data to the load address,
1454 * make sure we don't overwrite initial image
1456 image_start = (ulong)fdt_hdr;
1457 image_end = image_get_image_end (fdt_hdr);
1459 load_start = image_get_load (fdt_hdr);
1460 load_end = load_start + image_get_data_size (fdt_hdr);
1462 if ((load_start < image_end) && (load_end > image_start)) {
1463 fdt_error ("fdt overwritten");
1467 debug (" Loading FDT from 0x%08lx to 0x%08lx\n",
1468 image_get_data (fdt_hdr), load_start);
1470 memmove ((void *)load_start,
1471 (void *)image_get_data (fdt_hdr),
1472 image_get_data_size (fdt_hdr));
1474 fdt_blob = (char *)load_start;
1476 case IMAGE_FORMAT_FIT:
1478 * This case will catch both: new uImage format
1479 * (libfdt based) and raw FDT blob (also libfdt
1482 #if defined(CONFIG_FIT)
1483 /* check FDT blob vs FIT blob */
1484 if (fit_check_format ((const void *)fdt_addr)) {
1488 fit_hdr = (void *)fdt_addr;
1489 printf ("## Flattened Device Tree from FIT Image at %08lx\n",
1492 if (!fit_uname_fdt) {
1494 * no FDT blob image node unit name,
1495 * try to get config node first. If
1496 * config unit node name is NULL
1497 * fit_conf_get_node() will try to
1498 * find default config node
1500 cfg_noffset = fit_conf_get_node (fit_hdr,
1503 if (cfg_noffset < 0) {
1504 fdt_error ("Could not find configuration node\n");
1508 fit_uname_config = fdt_get_name (fit_hdr,
1510 printf (" Using '%s' configuration\n",
1513 fdt_noffset = fit_conf_get_fdt_node (fit_hdr,
1515 fit_uname_fdt = fit_get_name (fit_hdr,
1518 /* get FDT component image node offset */
1519 fdt_noffset = fit_image_get_node (fit_hdr,
1522 if (fdt_noffset < 0) {
1523 fdt_error ("Could not find subimage node\n");
1527 printf (" Trying '%s' FDT blob subimage\n",
1530 if (!fit_check_fdt (fit_hdr, fdt_noffset,
1534 /* get ramdisk image data address and length */
1535 if (fit_image_get_data (fit_hdr, fdt_noffset,
1537 fdt_error ("Could not find FDT subimage data");
1541 /* verift that image data is a proper FDT blob */
1542 if (fdt_check_header ((char *)data) != 0) {
1543 fdt_error ("Subimage data is not a FTD");
1548 * move image data to the load address,
1549 * make sure we don't overwrite initial image
1551 image_start = (ulong)fit_hdr;
1552 image_end = fit_get_end (fit_hdr);
1554 if (fit_image_get_load (fit_hdr, fdt_noffset,
1555 &load_start) == 0) {
1556 load_end = load_start + size;
1558 if ((load_start < image_end) &&
1559 (load_end > image_start)) {
1560 fdt_error ("FDT overwritten");
1564 printf (" Loading FDT from 0x%08lx to 0x%08lx\n",
1565 (ulong)data, load_start);
1567 memmove ((void *)load_start,
1568 (void *)data, size);
1570 fdt_blob = (char *)load_start;
1572 fdt_blob = (char *)data;
1575 images->fit_hdr_fdt = fit_hdr;
1576 images->fit_uname_fdt = fit_uname_fdt;
1577 images->fit_noffset_fdt = fdt_noffset;
1585 fdt_blob = (char *)fdt_addr;
1586 debug ("* fdt: raw FDT blob\n");
1587 printf ("## Flattened Device Tree blob at %08lx\n", (long)fdt_blob);
1591 puts ("ERROR: Did not find a cmdline Flattened Device Tree\n");
1595 printf (" Booting using the fdt blob at 0x%x\n", (int)fdt_blob);
1597 } else if (images->legacy_hdr_valid &&
1598 image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1600 ulong fdt_data, fdt_len;
1603 * Now check if we have a legacy multi-component image,
1604 * get second entry data start address and len.
1606 printf ("## Flattened Device Tree from multi "
1607 "component Image at %08lX\n",
1608 (ulong)images->legacy_hdr_os);
1610 image_multi_getimg (images->legacy_hdr_os, 2, &fdt_data, &fdt_len);
1613 fdt_blob = (char *)fdt_data;
1614 printf (" Booting using the fdt at 0x%x\n", (int)fdt_blob);
1616 if (fdt_check_header (fdt_blob) != 0) {
1617 fdt_error ("image is not a fdt");
1621 if (fdt_totalsize(fdt_blob) != fdt_len) {
1622 fdt_error ("fdt size != image size");
1626 debug ("## No Flattened Device Tree\n");
1630 debug ("## No Flattened Device Tree\n");
1634 *of_flat_tree = fdt_blob;
1635 *of_size = fdt_totalsize(fdt_blob);
1636 debug (" of_flat_tree at 0x%08lx size 0x%08lx\n",
1637 (ulong)*of_flat_tree, *of_size);
1646 #endif /* CONFIG_OF_LIBFDT */
1648 #ifdef CONFIG_SYS_BOOT_GET_CMDLINE
1650 * boot_get_cmdline - allocate and initialize kernel cmdline
1651 * @lmb: pointer to lmb handle, will be used for memory mgmt
1652 * @cmd_start: pointer to a ulong variable, will hold cmdline start
1653 * @cmd_end: pointer to a ulong variable, will hold cmdline end
1655 * boot_get_cmdline() allocates space for kernel command line below
1656 * BOOTMAPSZ + getenv_bootm_low() address. If "bootargs" U-boot environemnt
1657 * variable is present its contents is copied to allocated kernel
1664 int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end)
1669 cmdline = (char *)(ulong)lmb_alloc_base(lmb, CONFIG_SYS_BARGSIZE, 0xf,
1670 getenv_bootm_mapsize() + getenv_bootm_low());
1672 if (cmdline == NULL)
1675 if ((s = getenv("bootargs")) == NULL)
1680 *cmd_start = (ulong) & cmdline[0];
1681 *cmd_end = *cmd_start + strlen(cmdline);
1683 debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
1687 #endif /* CONFIG_SYS_BOOT_GET_CMDLINE */
1689 #ifdef CONFIG_SYS_BOOT_GET_KBD
1691 * boot_get_kbd - allocate and initialize kernel copy of board info
1692 * @lmb: pointer to lmb handle, will be used for memory mgmt
1693 * @kbd: double pointer to board info data
1695 * boot_get_kbd() allocates space for kernel copy of board info data below
1696 * BOOTMAPSZ + getenv_bootm_low() address and kernel board info is initialized
1697 * with the current u-boot board info data.
1703 int boot_get_kbd (struct lmb *lmb, bd_t **kbd)
1705 *kbd = (bd_t *)(ulong)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
1706 getenv_bootm_mapsize() + getenv_bootm_low());
1712 debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
1714 #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
1715 do_bdinfo(NULL, 0, 0, NULL);
1720 #endif /* CONFIG_SYS_BOOT_GET_KBD */
1721 #endif /* !USE_HOSTCC */
1723 #if defined(CONFIG_FIT)
1724 /*****************************************************************************/
1725 /* New uImage format routines */
1726 /*****************************************************************************/
1728 static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr,
1729 ulong *addr, const char **name)
1736 sep = strchr (spec, sepc);
1739 *addr = simple_strtoul (spec, NULL, 16);
1749 * fit_parse_conf - parse FIT configuration spec
1750 * @spec: input string, containing configuration spec
1751 * @add_curr: current image address (to be used as a possible default)
1752 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1754 * @conf_name double pointer to a char, will hold pointer to a configuration
1757 * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
1758 * where <addr> is a FIT image address that contains configuration
1759 * with a <conf> unit name.
1761 * Address part is optional, and if omitted default add_curr will
1765 * 1 if spec is a valid configuration string,
1766 * addr and conf_name are set accordingly
1769 inline int fit_parse_conf (const char *spec, ulong addr_curr,
1770 ulong *addr, const char **conf_name)
1772 return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
1776 * fit_parse_subimage - parse FIT subimage spec
1777 * @spec: input string, containing subimage spec
1778 * @add_curr: current image address (to be used as a possible default)
1779 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1781 * @image_name: double pointer to a char, will hold pointer to a subimage name
1783 * fit_parse_subimage() expects subimage spec in the for of
1784 * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
1785 * subimage with a <subimg> unit name.
1787 * Address part is optional, and if omitted default add_curr will
1791 * 1 if spec is a valid subimage string,
1792 * addr and image_name are set accordingly
1795 inline int fit_parse_subimage (const char *spec, ulong addr_curr,
1796 ulong *addr, const char **image_name)
1798 return fit_parse_spec (spec, ':', addr_curr, addr, image_name);
1800 #endif /* !USE_HOSTCC */
1802 static void fit_get_debug (const void *fit, int noffset,
1803 char *prop_name, int err)
1805 debug ("Can't get '%s' property from FIT 0x%08lx, "
1806 "node: offset %d, name %s (%s)\n",
1807 prop_name, (ulong)fit, noffset,
1808 fit_get_name (fit, noffset, NULL),
1809 fdt_strerror (err));
1813 * fit_print_contents - prints out the contents of the FIT format image
1814 * @fit: pointer to the FIT format image header
1815 * @p: pointer to prefix string
1817 * fit_print_contents() formats a multi line FIT image contents description.
1818 * The routine prints out FIT image properties (root node level) follwed by
1819 * the details of each component image.
1822 * no returned results
1824 void fit_print_contents (const void *fit)
1835 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1845 /* Root node properties */
1846 ret = fit_get_desc (fit, 0, &desc);
1847 printf ("%sFIT description: ", p);
1849 printf ("unavailable\n");
1851 printf ("%s\n", desc);
1853 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1854 ret = fit_get_timestamp (fit, 0, ×tamp);
1855 printf ("%sCreated: ", p);
1857 printf ("unavailable\n");
1859 genimg_print_time (timestamp);
1862 /* Find images parent node offset */
1863 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
1864 if (images_noffset < 0) {
1865 printf ("Can't find images parent node '%s' (%s)\n",
1866 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
1870 /* Process its subnodes, print out component images details */
1871 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
1872 (noffset >= 0) && (ndepth > 0);
1873 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1876 * Direct child node of the images parent node,
1877 * i.e. component image node.
1879 printf ("%s Image %u (%s)\n", p, count++,
1880 fit_get_name(fit, noffset, NULL));
1882 fit_image_print (fit, noffset, p);
1886 /* Find configurations parent node offset */
1887 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
1888 if (confs_noffset < 0) {
1889 debug ("Can't get configurations parent node '%s' (%s)\n",
1890 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
1894 /* get default configuration unit name from default property */
1895 uname = (char *)fdt_getprop (fit, noffset, FIT_DEFAULT_PROP, NULL);
1897 printf ("%s Default Configuration: '%s'\n", p, uname);
1899 /* Process its subnodes, print out configurations details */
1900 for (ndepth = 0, count = 0, noffset = fdt_next_node (fit, confs_noffset, &ndepth);
1901 (noffset >= 0) && (ndepth > 0);
1902 noffset = fdt_next_node (fit, noffset, &ndepth)) {
1905 * Direct child node of the configurations parent node,
1906 * i.e. configuration node.
1908 printf ("%s Configuration %u (%s)\n", p, count++,
1909 fit_get_name(fit, noffset, NULL));
1911 fit_conf_print (fit, noffset, p);
1917 * fit_image_print - prints out the FIT component image details
1918 * @fit: pointer to the FIT format image header
1919 * @image_noffset: offset of the component image node
1920 * @p: pointer to prefix string
1922 * fit_image_print() lists all mandatory properies for the processed component
1923 * image. If present, hash nodes are printed out as well. Load
1924 * address for images of type firmware is also printed out. Since the load
1925 * address is not mandatory for firmware images, it will be output as
1926 * "unavailable" when not present.
1929 * no returned results
1931 void fit_image_print (const void *fit, int image_noffset, const char *p)
1934 uint8_t type, arch, os, comp;
1942 /* Mandatory properties */
1943 ret = fit_get_desc (fit, image_noffset, &desc);
1944 printf ("%s Description: ", p);
1946 printf ("unavailable\n");
1948 printf ("%s\n", desc);
1950 fit_image_get_type (fit, image_noffset, &type);
1951 printf ("%s Type: %s\n", p, genimg_get_type_name (type));
1953 fit_image_get_comp (fit, image_noffset, &comp);
1954 printf ("%s Compression: %s\n", p, genimg_get_comp_name (comp));
1956 ret = fit_image_get_data (fit, image_noffset, &data, &size);
1959 printf ("%s Data Start: ", p);
1961 printf ("unavailable\n");
1963 printf ("0x%08lx\n", (ulong)data);
1966 printf ("%s Data Size: ", p);
1968 printf ("unavailable\n");
1970 genimg_print_size (size);
1972 /* Remaining, type dependent properties */
1973 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
1974 (type == IH_TYPE_RAMDISK) || (type == IH_TYPE_FIRMWARE) ||
1975 (type == IH_TYPE_FLATDT)) {
1976 fit_image_get_arch (fit, image_noffset, &arch);
1977 printf ("%s Architecture: %s\n", p, genimg_get_arch_name (arch));
1980 if (type == IH_TYPE_KERNEL) {
1981 fit_image_get_os (fit, image_noffset, &os);
1982 printf ("%s OS: %s\n", p, genimg_get_os_name (os));
1985 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE) ||
1986 (type == IH_TYPE_FIRMWARE)) {
1987 ret = fit_image_get_load (fit, image_noffset, &load);
1988 printf ("%s Load Address: ", p);
1990 printf ("unavailable\n");
1992 printf ("0x%08lx\n", load);
1995 if ((type == IH_TYPE_KERNEL) || (type == IH_TYPE_STANDALONE)) {
1996 fit_image_get_entry (fit, image_noffset, &entry);
1997 printf ("%s Entry Point: ", p);
1999 printf ("unavailable\n");
2001 printf ("0x%08lx\n", entry);
2004 /* Process all hash subnodes of the component image node */
2005 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2006 (noffset >= 0) && (ndepth > 0);
2007 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2009 /* Direct child node of the component image node */
2010 fit_image_print_hash (fit, noffset, p);
2016 * fit_image_print_hash - prints out the hash node details
2017 * @fit: pointer to the FIT format image header
2018 * @noffset: offset of the hash node
2019 * @p: pointer to prefix string
2021 * fit_image_print_hash() lists properies for the processed hash node
2024 * no returned results
2026 void fit_image_print_hash (const void *fit, int noffset, const char *p)
2034 * Check subnode name, must be equal to "hash".
2035 * Multiple hash nodes require unique unit node
2036 * names, e.g. hash@1, hash@2, etc.
2038 if (strncmp (fit_get_name(fit, noffset, NULL),
2040 strlen(FIT_HASH_NODENAME)) != 0)
2043 debug ("%s Hash node: '%s'\n", p,
2044 fit_get_name (fit, noffset, NULL));
2046 printf ("%s Hash algo: ", p);
2047 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2048 printf ("invalid/unsupported\n");
2051 printf ("%s\n", algo);
2053 ret = fit_image_hash_get_value (fit, noffset, &value,
2055 printf ("%s Hash value: ", p);
2057 printf ("unavailable\n");
2059 for (i = 0; i < value_len; i++)
2060 printf ("%02x", value[i]);
2064 debug ("%s Hash len: %d\n", p, value_len);
2068 * fit_get_desc - get node description property
2069 * @fit: pointer to the FIT format image header
2070 * @noffset: node offset
2071 * @desc: double pointer to the char, will hold pointer to the descrption
2073 * fit_get_desc() reads description property from a given node, if
2074 * description is found pointer to it is returened in third call argument.
2080 int fit_get_desc (const void *fit, int noffset, char **desc)
2084 *desc = (char *)fdt_getprop (fit, noffset, FIT_DESC_PROP, &len);
2085 if (*desc == NULL) {
2086 fit_get_debug (fit, noffset, FIT_DESC_PROP, len);
2094 * fit_get_timestamp - get node timestamp property
2095 * @fit: pointer to the FIT format image header
2096 * @noffset: node offset
2097 * @timestamp: pointer to the time_t, will hold read timestamp
2099 * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
2100 * is found and has a correct size its value is retured in third call
2105 * -1, on property read failure
2106 * -2, on wrong timestamp size
2108 int fit_get_timestamp (const void *fit, int noffset, time_t *timestamp)
2113 data = fdt_getprop (fit, noffset, FIT_TIMESTAMP_PROP, &len);
2115 fit_get_debug (fit, noffset, FIT_TIMESTAMP_PROP, len);
2118 if (len != sizeof (uint32_t)) {
2119 debug ("FIT timestamp with incorrect size of (%u)\n", len);
2123 *timestamp = uimage_to_cpu (*((uint32_t *)data));
2128 * fit_image_get_node - get node offset for component image of a given unit name
2129 * @fit: pointer to the FIT format image header
2130 * @image_uname: component image node unit name
2132 * fit_image_get_node() finds a component image (withing the '/images'
2133 * node) of a provided unit name. If image is found its node offset is
2134 * returned to the caller.
2137 * image node offset when found (>=0)
2138 * negative number on failure (FDT_ERR_* code)
2140 int fit_image_get_node (const void *fit, const char *image_uname)
2142 int noffset, images_noffset;
2144 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2145 if (images_noffset < 0) {
2146 debug ("Can't find images parent node '%s' (%s)\n",
2147 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2148 return images_noffset;
2151 noffset = fdt_subnode_offset (fit, images_noffset, image_uname);
2153 debug ("Can't get node offset for image unit name: '%s' (%s)\n",
2154 image_uname, fdt_strerror (noffset));
2161 * fit_image_get_os - get os id for a given component image node
2162 * @fit: pointer to the FIT format image header
2163 * @noffset: component image node offset
2164 * @os: pointer to the uint8_t, will hold os numeric id
2166 * fit_image_get_os() finds os property in a given component image node.
2167 * If the property is found, its (string) value is translated to the numeric
2168 * id which is returned to the caller.
2174 int fit_image_get_os (const void *fit, int noffset, uint8_t *os)
2179 /* Get OS name from property data */
2180 data = fdt_getprop (fit, noffset, FIT_OS_PROP, &len);
2182 fit_get_debug (fit, noffset, FIT_OS_PROP, len);
2187 /* Translate OS name to id */
2188 *os = genimg_get_os_id (data);
2193 * fit_image_get_arch - get arch id for a given component image node
2194 * @fit: pointer to the FIT format image header
2195 * @noffset: component image node offset
2196 * @arch: pointer to the uint8_t, will hold arch numeric id
2198 * fit_image_get_arch() finds arch property in a given component image node.
2199 * If the property is found, its (string) value is translated to the numeric
2200 * id which is returned to the caller.
2206 int fit_image_get_arch (const void *fit, int noffset, uint8_t *arch)
2211 /* Get architecture name from property data */
2212 data = fdt_getprop (fit, noffset, FIT_ARCH_PROP, &len);
2214 fit_get_debug (fit, noffset, FIT_ARCH_PROP, len);
2219 /* Translate architecture name to id */
2220 *arch = genimg_get_arch_id (data);
2225 * fit_image_get_type - get type id for a given component image node
2226 * @fit: pointer to the FIT format image header
2227 * @noffset: component image node offset
2228 * @type: pointer to the uint8_t, will hold type numeric id
2230 * fit_image_get_type() finds type property in a given component image node.
2231 * If the property is found, its (string) value is translated to the numeric
2232 * id which is returned to the caller.
2238 int fit_image_get_type (const void *fit, int noffset, uint8_t *type)
2243 /* Get image type name from property data */
2244 data = fdt_getprop (fit, noffset, FIT_TYPE_PROP, &len);
2246 fit_get_debug (fit, noffset, FIT_TYPE_PROP, len);
2251 /* Translate image type name to id */
2252 *type = genimg_get_type_id (data);
2257 * fit_image_get_comp - get comp id for a given component image node
2258 * @fit: pointer to the FIT format image header
2259 * @noffset: component image node offset
2260 * @comp: pointer to the uint8_t, will hold comp numeric id
2262 * fit_image_get_comp() finds comp property in a given component image node.
2263 * If the property is found, its (string) value is translated to the numeric
2264 * id which is returned to the caller.
2270 int fit_image_get_comp (const void *fit, int noffset, uint8_t *comp)
2275 /* Get compression name from property data */
2276 data = fdt_getprop (fit, noffset, FIT_COMP_PROP, &len);
2278 fit_get_debug (fit, noffset, FIT_COMP_PROP, len);
2283 /* Translate compression name to id */
2284 *comp = genimg_get_comp_id (data);
2289 * fit_image_get_load - get load address property for a given component image node
2290 * @fit: pointer to the FIT format image header
2291 * @noffset: component image node offset
2292 * @load: pointer to the uint32_t, will hold load address
2294 * fit_image_get_load() finds load address property in a given component image node.
2295 * If the property is found, its value is returned to the caller.
2301 int fit_image_get_load (const void *fit, int noffset, ulong *load)
2304 const uint32_t *data;
2306 data = fdt_getprop (fit, noffset, FIT_LOAD_PROP, &len);
2308 fit_get_debug (fit, noffset, FIT_LOAD_PROP, len);
2312 *load = uimage_to_cpu (*data);
2317 * fit_image_get_entry - get entry point address property for a given component image node
2318 * @fit: pointer to the FIT format image header
2319 * @noffset: component image node offset
2320 * @entry: pointer to the uint32_t, will hold entry point address
2322 * fit_image_get_entry() finds entry point address property in a given component image node.
2323 * If the property is found, its value is returned to the caller.
2329 int fit_image_get_entry (const void *fit, int noffset, ulong *entry)
2332 const uint32_t *data;
2334 data = fdt_getprop (fit, noffset, FIT_ENTRY_PROP, &len);
2336 fit_get_debug (fit, noffset, FIT_ENTRY_PROP, len);
2340 *entry = uimage_to_cpu (*data);
2345 * fit_image_get_data - get data property and its size for a given component image node
2346 * @fit: pointer to the FIT format image header
2347 * @noffset: component image node offset
2348 * @data: double pointer to void, will hold data property's data address
2349 * @size: pointer to size_t, will hold data property's data size
2351 * fit_image_get_data() finds data property in a given component image node.
2352 * If the property is found its data start address and size are returned to
2359 int fit_image_get_data (const void *fit, int noffset,
2360 const void **data, size_t *size)
2364 *data = fdt_getprop (fit, noffset, FIT_DATA_PROP, &len);
2365 if (*data == NULL) {
2366 fit_get_debug (fit, noffset, FIT_DATA_PROP, len);
2376 * fit_image_hash_get_algo - get hash algorithm name
2377 * @fit: pointer to the FIT format image header
2378 * @noffset: hash node offset
2379 * @algo: double pointer to char, will hold pointer to the algorithm name
2381 * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
2382 * If the property is found its data start address is returned to the caller.
2388 int fit_image_hash_get_algo (const void *fit, int noffset, char **algo)
2392 *algo = (char *)fdt_getprop (fit, noffset, FIT_ALGO_PROP, &len);
2393 if (*algo == NULL) {
2394 fit_get_debug (fit, noffset, FIT_ALGO_PROP, len);
2402 * fit_image_hash_get_value - get hash value and length
2403 * @fit: pointer to the FIT format image header
2404 * @noffset: hash node offset
2405 * @value: double pointer to uint8_t, will hold address of a hash value data
2406 * @value_len: pointer to an int, will hold hash data length
2408 * fit_image_hash_get_value() finds hash value property in a given hash node.
2409 * If the property is found its data start address and size are returned to
2416 int fit_image_hash_get_value (const void *fit, int noffset, uint8_t **value,
2421 *value = (uint8_t *)fdt_getprop (fit, noffset, FIT_VALUE_PROP, &len);
2422 if (*value == NULL) {
2423 fit_get_debug (fit, noffset, FIT_VALUE_PROP, len);
2433 * fit_set_timestamp - set node timestamp property
2434 * @fit: pointer to the FIT format image header
2435 * @noffset: node offset
2436 * @timestamp: timestamp value to be set
2438 * fit_set_timestamp() attempts to set timestamp property in the requested
2439 * node and returns operation status to the caller.
2443 * -1, on property read failure
2445 int fit_set_timestamp (void *fit, int noffset, time_t timestamp)
2450 t = cpu_to_uimage (timestamp);
2451 ret = fdt_setprop (fit, noffset, FIT_TIMESTAMP_PROP, &t,
2454 printf ("Can't set '%s' property for '%s' node (%s)\n",
2455 FIT_TIMESTAMP_PROP, fit_get_name (fit, noffset, NULL),
2456 fdt_strerror (ret));
2464 * calculate_hash - calculate and return hash for provided input data
2465 * @data: pointer to the input data
2466 * @data_len: data length
2467 * @algo: requested hash algorithm
2468 * @value: pointer to the char, will hold hash value data (caller must
2469 * allocate enough free space)
2470 * value_len: length of the calculated hash
2472 * calculate_hash() computes input data hash according to the requested algorithm.
2473 * Resulting hash value is placed in caller provided 'value' buffer, length
2474 * of the calculated hash is returned via value_len pointer argument.
2478 * -1, when algo is unsupported
2480 static int calculate_hash (const void *data, int data_len, const char *algo,
2481 uint8_t *value, int *value_len)
2483 if (strcmp (algo, "crc32") == 0 ) {
2484 *((uint32_t *)value) = crc32_wd (0, data, data_len,
2486 *((uint32_t *)value) = cpu_to_uimage (*((uint32_t *)value));
2488 } else if (strcmp (algo, "sha1") == 0 ) {
2489 sha1_csum_wd ((unsigned char *) data, data_len,
2490 (unsigned char *) value, CHUNKSZ_SHA1);
2492 } else if (strcmp (algo, "md5") == 0 ) {
2493 md5_wd ((unsigned char *)data, data_len, value, CHUNKSZ_MD5);
2496 debug ("Unsupported hash alogrithm\n");
2504 * fit_set_hashes - process FIT component image nodes and calculate hashes
2505 * @fit: pointer to the FIT format image header
2507 * fit_set_hashes() adds hash values for all component images in the FIT blob.
2508 * Hashes are calculated for all component images which have hash subnodes
2509 * with algorithm property set to one of the supported hash algorithms.
2513 * libfdt error code, on failure
2515 int fit_set_hashes (void *fit)
2522 /* Find images parent node offset */
2523 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2524 if (images_noffset < 0) {
2525 printf ("Can't find images parent node '%s' (%s)\n",
2526 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2527 return images_noffset;
2530 /* Process its subnodes, print out component images details */
2531 for (ndepth = 0, noffset = fdt_next_node (fit, images_noffset, &ndepth);
2532 (noffset >= 0) && (ndepth > 0);
2533 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2536 * Direct child node of the images parent node,
2537 * i.e. component image node.
2539 ret = fit_image_set_hashes (fit, noffset);
2549 * fit_image_set_hashes - calculate/set hashes for given component image node
2550 * @fit: pointer to the FIT format image header
2551 * @image_noffset: requested component image node
2553 * fit_image_set_hashes() adds hash values for an component image node. All
2554 * existing hash subnodes are checked, if algorithm property is set to one of
2555 * the supported hash algorithms, hash value is computed and corresponding
2556 * hash node property is set, for example:
2558 * Input component image node structure:
2560 * o image@1 (at image_noffset)
2561 * | - data = [binary data]
2565 * Output component image node structure:
2567 * o image@1 (at image_noffset)
2568 * | - data = [binary data]
2571 * |- value = sha1(data)
2577 int fit_image_set_hashes (void *fit, int image_noffset)
2582 uint8_t value[FIT_MAX_HASH_LEN];
2587 /* Get image data and data length */
2588 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
2589 printf ("Can't get image data/size\n");
2593 /* Process all hash subnodes of the component image node */
2594 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2595 (noffset >= 0) && (ndepth > 0);
2596 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2598 /* Direct child node of the component image node */
2601 * Check subnode name, must be equal to "hash".
2602 * Multiple hash nodes require unique unit node
2603 * names, e.g. hash@1, hash@2, etc.
2605 if (strncmp (fit_get_name(fit, noffset, NULL),
2607 strlen(FIT_HASH_NODENAME)) != 0) {
2608 /* Not a hash subnode, skip it */
2612 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2613 printf ("Can't get hash algo property for "
2614 "'%s' hash node in '%s' image node\n",
2615 fit_get_name (fit, noffset, NULL),
2616 fit_get_name (fit, image_noffset, NULL));
2620 if (calculate_hash (data, size, algo, value, &value_len)) {
2621 printf ("Unsupported hash algorithm (%s) for "
2622 "'%s' hash node in '%s' image node\n",
2623 algo, fit_get_name (fit, noffset, NULL),
2624 fit_get_name (fit, image_noffset, NULL));
2628 if (fit_image_hash_set_value (fit, noffset, value,
2630 printf ("Can't set hash value for "
2631 "'%s' hash node in '%s' image node\n",
2632 fit_get_name (fit, noffset, NULL),
2633 fit_get_name (fit, image_noffset, NULL));
2643 * fit_image_hash_set_value - set hash value in requested has node
2644 * @fit: pointer to the FIT format image header
2645 * @noffset: hash node offset
2646 * @value: hash value to be set
2647 * @value_len: hash value length
2649 * fit_image_hash_set_value() attempts to set hash value in a node at offset
2650 * given and returns operation status to the caller.
2656 int fit_image_hash_set_value (void *fit, int noffset, uint8_t *value,
2661 ret = fdt_setprop (fit, noffset, FIT_VALUE_PROP, value, value_len);
2663 printf ("Can't set hash '%s' property for '%s' node (%s)\n",
2664 FIT_VALUE_PROP, fit_get_name (fit, noffset, NULL),
2665 fdt_strerror (ret));
2671 #endif /* USE_HOSTCC */
2674 * fit_image_check_hashes - verify data intergity
2675 * @fit: pointer to the FIT format image header
2676 * @image_noffset: component image node offset
2678 * fit_image_check_hashes() goes over component image hash nodes,
2679 * re-calculates each data hash and compares with the value stored in hash
2683 * 1, if all hashes are valid
2684 * 0, otherwise (or on error)
2686 int fit_image_check_hashes (const void *fit, int image_noffset)
2693 uint8_t value[FIT_MAX_HASH_LEN];
2699 /* Get image data and data length */
2700 if (fit_image_get_data (fit, image_noffset, &data, &size)) {
2701 printf ("Can't get image data/size\n");
2705 /* Process all hash subnodes of the component image node */
2706 for (ndepth = 0, noffset = fdt_next_node (fit, image_noffset, &ndepth);
2707 (noffset >= 0) && (ndepth > 0);
2708 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2710 /* Direct child node of the component image node */
2713 * Check subnode name, must be equal to "hash".
2714 * Multiple hash nodes require unique unit node
2715 * names, e.g. hash@1, hash@2, etc.
2717 if (strncmp (fit_get_name(fit, noffset, NULL),
2719 strlen(FIT_HASH_NODENAME)) != 0)
2722 if (fit_image_hash_get_algo (fit, noffset, &algo)) {
2723 err_msg = " error!\nCan't get hash algo "
2727 printf ("%s", algo);
2729 if (fit_image_hash_get_value (fit, noffset, &fit_value,
2731 err_msg = " error!\nCan't get hash value "
2736 if (calculate_hash (data, size, algo, value, &value_len)) {
2737 err_msg = " error!\nUnsupported hash algorithm";
2741 if (value_len != fit_value_len) {
2742 err_msg = " error !\nBad hash value len";
2744 } else if (memcmp (value, fit_value, value_len) != 0) {
2745 err_msg = " error!\nBad hash value";
2755 printf ("%s for '%s' hash node in '%s' image node\n",
2756 err_msg, fit_get_name (fit, noffset, NULL),
2757 fit_get_name (fit, image_noffset, NULL));
2762 * fit_all_image_check_hashes - verify data intergity for all images
2763 * @fit: pointer to the FIT format image header
2765 * fit_all_image_check_hashes() goes over all images in the FIT and
2766 * for every images checks if all it's hashes are valid.
2769 * 1, if all hashes of all images are valid
2770 * 0, otherwise (or on error)
2772 int fit_all_image_check_hashes (const void *fit)
2779 /* Find images parent node offset */
2780 images_noffset = fdt_path_offset (fit, FIT_IMAGES_PATH);
2781 if (images_noffset < 0) {
2782 printf ("Can't find images parent node '%s' (%s)\n",
2783 FIT_IMAGES_PATH, fdt_strerror (images_noffset));
2787 /* Process all image subnodes, check hashes for each */
2788 printf ("## Checking hash(es) for FIT Image at %08lx ...\n",
2790 for (ndepth = 0, count = 0,
2791 noffset = fdt_next_node (fit, images_noffset, &ndepth);
2792 (noffset >= 0) && (ndepth > 0);
2793 noffset = fdt_next_node (fit, noffset, &ndepth)) {
2796 * Direct child node of the images parent node,
2797 * i.e. component image node.
2799 printf (" Hash(es) for Image %u (%s): ", count++,
2800 fit_get_name (fit, noffset, NULL));
2802 if (!fit_image_check_hashes (fit, noffset))
2811 * fit_image_check_os - check whether image node is of a given os type
2812 * @fit: pointer to the FIT format image header
2813 * @noffset: component image node offset
2814 * @os: requested image os
2816 * fit_image_check_os() reads image os property and compares its numeric
2817 * id with the requested os. Comparison result is returned to the caller.
2820 * 1 if image is of given os type
2821 * 0 otherwise (or on error)
2823 int fit_image_check_os (const void *fit, int noffset, uint8_t os)
2827 if (fit_image_get_os (fit, noffset, &image_os))
2829 return (os == image_os);
2833 * fit_image_check_arch - check whether image node is of a given arch
2834 * @fit: pointer to the FIT format image header
2835 * @noffset: component image node offset
2836 * @arch: requested imagearch
2838 * fit_image_check_arch() reads image arch property and compares its numeric
2839 * id with the requested arch. Comparison result is returned to the caller.
2842 * 1 if image is of given arch
2843 * 0 otherwise (or on error)
2845 int fit_image_check_arch (const void *fit, int noffset, uint8_t arch)
2849 if (fit_image_get_arch (fit, noffset, &image_arch))
2851 return (arch == image_arch);
2855 * fit_image_check_type - check whether image node is of a given type
2856 * @fit: pointer to the FIT format image header
2857 * @noffset: component image node offset
2858 * @type: requested image type
2860 * fit_image_check_type() reads image type property and compares its numeric
2861 * id with the requested type. Comparison result is returned to the caller.
2864 * 1 if image is of given type
2865 * 0 otherwise (or on error)
2867 int fit_image_check_type (const void *fit, int noffset, uint8_t type)
2871 if (fit_image_get_type (fit, noffset, &image_type))
2873 return (type == image_type);
2877 * fit_image_check_comp - check whether image node uses given compression
2878 * @fit: pointer to the FIT format image header
2879 * @noffset: component image node offset
2880 * @comp: requested image compression type
2882 * fit_image_check_comp() reads image compression property and compares its
2883 * numeric id with the requested compression type. Comparison result is
2884 * returned to the caller.
2887 * 1 if image uses requested compression
2888 * 0 otherwise (or on error)
2890 int fit_image_check_comp (const void *fit, int noffset, uint8_t comp)
2894 if (fit_image_get_comp (fit, noffset, &image_comp))
2896 return (comp == image_comp);
2900 * fit_check_format - sanity check FIT image format
2901 * @fit: pointer to the FIT format image header
2903 * fit_check_format() runs a basic sanity FIT image verification.
2904 * Routine checks for mandatory properties, nodes, etc.
2910 int fit_check_format (const void *fit)
2912 /* mandatory / node 'description' property */
2913 if (fdt_getprop (fit, 0, FIT_DESC_PROP, NULL) == NULL) {
2914 debug ("Wrong FIT format: no description\n");
2918 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
2919 /* mandatory / node 'timestamp' property */
2920 if (fdt_getprop (fit, 0, FIT_TIMESTAMP_PROP, NULL) == NULL) {
2921 debug ("Wrong FIT format: no timestamp\n");
2926 /* mandatory subimages parent '/images' node */
2927 if (fdt_path_offset (fit, FIT_IMAGES_PATH) < 0) {
2928 debug ("Wrong FIT format: no images parent node\n");
2936 * fit_conf_get_node - get node offset for configuration of a given unit name
2937 * @fit: pointer to the FIT format image header
2938 * @conf_uname: configuration node unit name
2940 * fit_conf_get_node() finds a configuration (withing the '/configurations'
2941 * parant node) of a provided unit name. If configuration is found its node offset
2942 * is returned to the caller.
2944 * When NULL is provided in second argument fit_conf_get_node() will search
2945 * for a default configuration node instead. Default configuration node unit name
2946 * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
2949 * configuration node offset when found (>=0)
2950 * negative number on failure (FDT_ERR_* code)
2952 int fit_conf_get_node (const void *fit, const char *conf_uname)
2954 int noffset, confs_noffset;
2957 confs_noffset = fdt_path_offset (fit, FIT_CONFS_PATH);
2958 if (confs_noffset < 0) {
2959 debug ("Can't find configurations parent node '%s' (%s)\n",
2960 FIT_CONFS_PATH, fdt_strerror (confs_noffset));
2961 return confs_noffset;
2964 if (conf_uname == NULL) {
2965 /* get configuration unit name from the default property */
2966 debug ("No configuration specified, trying default...\n");
2967 conf_uname = (char *)fdt_getprop (fit, confs_noffset, FIT_DEFAULT_PROP, &len);
2968 if (conf_uname == NULL) {
2969 fit_get_debug (fit, confs_noffset, FIT_DEFAULT_PROP, len);
2972 debug ("Found default configuration: '%s'\n", conf_uname);
2975 noffset = fdt_subnode_offset (fit, confs_noffset, conf_uname);
2977 debug ("Can't get node offset for configuration unit name: '%s' (%s)\n",
2978 conf_uname, fdt_strerror (noffset));
2984 static int __fit_conf_get_prop_node (const void *fit, int noffset,
2985 const char *prop_name)
2990 /* get kernel image unit name from configuration kernel property */
2991 uname = (char *)fdt_getprop (fit, noffset, prop_name, &len);
2995 return fit_image_get_node (fit, uname);
2999 * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
3000 * a given configuration
3001 * @fit: pointer to the FIT format image header
3002 * @noffset: configuration node offset
3004 * fit_conf_get_kernel_node() retrives kernel image node unit name from
3005 * configuration FIT_KERNEL_PROP property and translates it to the node
3009 * image node offset when found (>=0)
3010 * negative number on failure (FDT_ERR_* code)
3012 int fit_conf_get_kernel_node (const void *fit, int noffset)
3014 return __fit_conf_get_prop_node (fit, noffset, FIT_KERNEL_PROP);
3018 * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
3019 * a given configuration
3020 * @fit: pointer to the FIT format image header
3021 * @noffset: configuration node offset
3023 * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
3024 * configuration FIT_KERNEL_PROP property and translates it to the node
3028 * image node offset when found (>=0)
3029 * negative number on failure (FDT_ERR_* code)
3031 int fit_conf_get_ramdisk_node (const void *fit, int noffset)
3033 return __fit_conf_get_prop_node (fit, noffset, FIT_RAMDISK_PROP);
3037 * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
3038 * a given configuration
3039 * @fit: pointer to the FIT format image header
3040 * @noffset: configuration node offset
3042 * fit_conf_get_fdt_node() retrives fdt image node unit name from
3043 * configuration FIT_KERNEL_PROP property and translates it to the node
3047 * image node offset when found (>=0)
3048 * negative number on failure (FDT_ERR_* code)
3050 int fit_conf_get_fdt_node (const void *fit, int noffset)
3052 return __fit_conf_get_prop_node (fit, noffset, FIT_FDT_PROP);
3056 * fit_conf_print - prints out the FIT configuration details
3057 * @fit: pointer to the FIT format image header
3058 * @noffset: offset of the configuration node
3059 * @p: pointer to prefix string
3061 * fit_conf_print() lists all mandatory properies for the processed
3062 * configuration node.
3065 * no returned results
3067 void fit_conf_print (const void *fit, int noffset, const char *p)
3073 /* Mandatory properties */
3074 ret = fit_get_desc (fit, noffset, &desc);
3075 printf ("%s Description: ", p);
3077 printf ("unavailable\n");
3079 printf ("%s\n", desc);
3081 uname = (char *)fdt_getprop (fit, noffset, FIT_KERNEL_PROP, NULL);
3082 printf ("%s Kernel: ", p);
3084 printf ("unavailable\n");
3086 printf ("%s\n", uname);
3088 /* Optional properties */
3089 uname = (char *)fdt_getprop (fit, noffset, FIT_RAMDISK_PROP, NULL);
3091 printf ("%s Init Ramdisk: %s\n", p, uname);
3093 uname = (char *)fdt_getprop (fit, noffset, FIT_FDT_PROP, NULL);
3095 printf ("%s FDT: %s\n", p, uname);
3099 * fit_check_ramdisk - verify FIT format ramdisk subimage
3100 * @fit_hdr: pointer to the FIT ramdisk header
3101 * @rd_noffset: ramdisk subimage node offset within FIT image
3102 * @arch: requested ramdisk image architecture type
3103 * @verify: data CRC verification flag
3105 * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
3106 * specified FIT image.
3113 static int fit_check_ramdisk (const void *fit, int rd_noffset, uint8_t arch, int verify)
3115 fit_image_print (fit, rd_noffset, " ");
3118 puts (" Verifying Hash Integrity ... ");
3119 if (!fit_image_check_hashes (fit, rd_noffset)) {
3120 puts ("Bad Data Hash\n");
3121 show_boot_progress (-125);
3127 show_boot_progress (126);
3128 if (!fit_image_check_os (fit, rd_noffset, IH_OS_LINUX) ||
3129 !fit_image_check_arch (fit, rd_noffset, arch) ||
3130 !fit_image_check_type (fit, rd_noffset, IH_TYPE_RAMDISK)) {
3131 printf ("No Linux %s Ramdisk Image\n",
3132 genimg_get_arch_name(arch));
3133 show_boot_progress (-126);
3137 show_boot_progress (127);
3140 #endif /* USE_HOSTCC */
3141 #endif /* CONFIG_FIT */