2 * (C) Copyright 2008 Semihalf
4 * (C) Copyright 2000-2006
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 * See file CREDITS for list of people who contributed to this
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #ifdef CONFIG_SHOW_BOOT_PROGRESS
31 #include <status_led.h>
34 #ifdef CONFIG_HAS_DATAFLASH
35 #include <dataflash.h>
38 #ifdef CONFIG_LOGBUFFER
42 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
48 #if defined(CONFIG_FIT) || defined (CONFIG_OF_LIBFDT)
51 #include <fdt_support.h>
54 #if defined(CONFIG_FIT)
55 #include <u-boot/md5.h>
58 static int fit_check_ramdisk (const void *fit
, int os_noffset
,
59 uint8_t arch
, int verify
);
63 extern int do_bdinfo(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
66 DECLARE_GLOBAL_DATA_PTR
;
68 static image_header_t
* image_get_ramdisk (ulong rd_addr
, uint8_t arch
,
72 #include <u-boot/md5.h>
75 #endif /* !USE_HOSTCC*/
77 typedef struct table_entry
{
78 int id
; /* as defined in image.h */
79 char *sname
; /* short (input) name */
80 char *lname
; /* long (output) name */
83 static table_entry_t uimage_arch
[] = {
84 { IH_ARCH_INVALID
, NULL
, "Invalid ARCH", },
85 { IH_ARCH_ALPHA
, "alpha", "Alpha", },
86 { IH_ARCH_ARM
, "arm", "ARM", },
87 { IH_ARCH_I386
, "x86", "Intel x86", },
88 { IH_ARCH_IA64
, "ia64", "IA64", },
89 { IH_ARCH_M68K
, "m68k", "M68K", },
90 { IH_ARCH_MICROBLAZE
, "microblaze", "MicroBlaze", },
91 { IH_ARCH_MIPS
, "mips", "MIPS", },
92 { IH_ARCH_MIPS64
, "mips64", "MIPS 64 Bit", },
93 { IH_ARCH_NIOS
, "nios", "NIOS", },
94 { IH_ARCH_NIOS2
, "nios2", "NIOS II", },
95 { IH_ARCH_PPC
, "powerpc", "PowerPC", },
96 { IH_ARCH_PPC
, "ppc", "PowerPC", },
97 { IH_ARCH_S390
, "s390", "IBM S390", },
98 { IH_ARCH_SH
, "sh", "SuperH", },
99 { IH_ARCH_SPARC
, "sparc", "SPARC", },
100 { IH_ARCH_SPARC64
, "sparc64", "SPARC 64 Bit", },
101 { IH_ARCH_BLACKFIN
, "blackfin", "Blackfin", },
102 { IH_ARCH_AVR32
, "avr32", "AVR32", },
106 static table_entry_t uimage_os
[] = {
107 { IH_OS_INVALID
, NULL
, "Invalid OS", },
108 { IH_OS_LINUX
, "linux", "Linux", },
109 #if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC)
110 { IH_OS_LYNXOS
, "lynxos", "LynxOS", },
112 { IH_OS_NETBSD
, "netbsd", "NetBSD", },
113 { IH_OS_RTEMS
, "rtems", "RTEMS", },
114 { IH_OS_U_BOOT
, "u-boot", "U-Boot", },
115 #if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC)
116 { IH_OS_QNX
, "qnx", "QNX", },
117 { IH_OS_VXWORKS
, "vxworks", "VxWorks", },
119 #if defined(CONFIG_INTEGRITY) || defined(USE_HOSTCC)
120 { IH_OS_INTEGRITY
,"integrity", "INTEGRITY", },
123 { IH_OS_4_4BSD
, "4_4bsd", "4_4BSD", },
124 { IH_OS_DELL
, "dell", "Dell", },
125 { IH_OS_ESIX
, "esix", "Esix", },
126 { IH_OS_FREEBSD
, "freebsd", "FreeBSD", },
127 { IH_OS_IRIX
, "irix", "Irix", },
128 { IH_OS_NCR
, "ncr", "NCR", },
129 { IH_OS_OPENBSD
, "openbsd", "OpenBSD", },
130 { IH_OS_PSOS
, "psos", "pSOS", },
131 { IH_OS_SCO
, "sco", "SCO", },
132 { IH_OS_SOLARIS
, "solaris", "Solaris", },
133 { IH_OS_SVR4
, "svr4", "SVR4", },
138 static table_entry_t uimage_type
[] = {
139 { IH_TYPE_INVALID
, NULL
, "Invalid Image", },
140 { IH_TYPE_FILESYSTEM
, "filesystem", "Filesystem Image", },
141 { IH_TYPE_FIRMWARE
, "firmware", "Firmware", },
142 { IH_TYPE_KERNEL
, "kernel", "Kernel Image", },
143 { IH_TYPE_MULTI
, "multi", "Multi-File Image", },
144 { IH_TYPE_RAMDISK
, "ramdisk", "RAMDisk Image", },
145 { IH_TYPE_SCRIPT
, "script", "Script", },
146 { IH_TYPE_STANDALONE
, "standalone", "Standalone Program", },
147 { IH_TYPE_FLATDT
, "flat_dt", "Flat Device Tree", },
151 static table_entry_t uimage_comp
[] = {
152 { IH_COMP_NONE
, "none", "uncompressed", },
153 { IH_COMP_BZIP2
, "bzip2", "bzip2 compressed", },
154 { IH_COMP_GZIP
, "gzip", "gzip compressed", },
155 { IH_COMP_LZMA
, "lzma", "lzma compressed", },
159 uint32_t crc32 (uint32_t, const unsigned char *, uint
);
160 uint32_t crc32_wd (uint32_t, const unsigned char *, uint
, uint
);
161 static void genimg_print_size (uint32_t size
);
162 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
163 static void genimg_print_time (time_t timestamp
);
166 /*****************************************************************************/
167 /* Legacy format routines */
168 /*****************************************************************************/
169 int image_check_hcrc (image_header_t
*hdr
)
172 ulong len
= image_get_header_size ();
173 image_header_t header
;
175 /* Copy header so we can blank CRC field for re-calculation */
176 memmove (&header
, (char *)hdr
, image_get_header_size ());
177 image_set_hcrc (&header
, 0);
179 hcrc
= crc32 (0, (unsigned char *)&header
, len
);
181 return (hcrc
== image_get_hcrc (hdr
));
184 int image_check_dcrc (image_header_t
*hdr
)
186 ulong data
= image_get_data (hdr
);
187 ulong len
= image_get_data_size (hdr
);
188 ulong dcrc
= crc32_wd (0, (unsigned char *)data
, len
, CHUNKSZ_CRC32
);
190 return (dcrc
== image_get_dcrc (hdr
));
194 * image_multi_count - get component (sub-image) count
195 * @hdr: pointer to the header of the multi component image
197 * image_multi_count() returns number of components in a multi
200 * Note: no checking of the image type is done, caller must pass
201 * a valid multi component image.
204 * number of components
206 ulong
image_multi_count (image_header_t
*hdr
)
211 /* get start of the image payload, which in case of multi
212 * component images that points to a table of component sizes */
213 size
= (uint32_t *)image_get_data (hdr
);
215 /* count non empty slots */
216 for (i
= 0; size
[i
]; ++i
)
223 * image_multi_getimg - get component data address and size
224 * @hdr: pointer to the header of the multi component image
225 * @idx: index of the requested component
226 * @data: pointer to a ulong variable, will hold component data address
227 * @len: pointer to a ulong variable, will hold component size
229 * image_multi_getimg() returns size and data address for the requested
230 * component in a multi component image.
232 * Note: no checking of the image type is done, caller must pass
233 * a valid multi component image.
236 * data address and size of the component, if idx is valid
237 * 0 in data and len, if idx is out of range
239 void image_multi_getimg (image_header_t
*hdr
, ulong idx
,
240 ulong
*data
, ulong
*len
)
244 ulong offset
, count
, img_data
;
246 /* get number of component */
247 count
= image_multi_count (hdr
);
249 /* get start of the image payload, which in case of multi
250 * component images that points to a table of component sizes */
251 size
= (uint32_t *)image_get_data (hdr
);
253 /* get address of the proper component data start, which means
254 * skipping sizes table (add 1 for last, null entry) */
255 img_data
= image_get_data (hdr
) + (count
+ 1) * sizeof (uint32_t);
258 *len
= uimage_to_cpu (size
[idx
]);
261 /* go over all indices preceding requested component idx */
262 for (i
= 0; i
< idx
; i
++) {
263 /* add up i-th component size, rounding up to 4 bytes */
264 offset
+= (uimage_to_cpu (size
[i
]) + 3) & ~3 ;
267 /* calculate idx-th component data address */
268 *data
= img_data
+ offset
;
275 static void image_print_type (image_header_t
*hdr
)
277 const char *os
, *arch
, *type
, *comp
;
279 os
= genimg_get_os_name (image_get_os (hdr
));
280 arch
= genimg_get_arch_name (image_get_arch (hdr
));
281 type
= genimg_get_type_name (image_get_type (hdr
));
282 comp
= genimg_get_comp_name (image_get_comp (hdr
));
284 printf ("%s %s %s (%s)\n", arch
, os
, type
, comp
);
288 * image_print_contents - prints out the contents of the legacy format image
289 * @hdr: pointer to the legacy format image header
290 * @p: pointer to prefix string
292 * image_print_contents() formats a multi line legacy image contents description.
293 * The routine prints out all header fields followed by the size/offset data
294 * for MULTI/SCRIPT images.
297 * no returned results
299 void image_print_contents (image_header_t
*hdr
)
309 printf ("%sImage Name: %.*s\n", p
, IH_NMLEN
, image_get_name (hdr
));
310 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
311 printf ("%sCreated: ", p
);
312 genimg_print_time ((time_t)image_get_time (hdr
));
314 printf ("%sImage Type: ", p
);
315 image_print_type (hdr
);
316 printf ("%sData Size: ", p
);
317 genimg_print_size (image_get_data_size (hdr
));
318 printf ("%sLoad Address: %08x\n", p
, image_get_load (hdr
));
319 printf ("%sEntry Point: %08x\n", p
, image_get_ep (hdr
));
321 if (image_check_type (hdr
, IH_TYPE_MULTI
) ||
322 image_check_type (hdr
, IH_TYPE_SCRIPT
)) {
325 ulong count
= image_multi_count (hdr
);
327 printf ("%sContents:\n", p
);
328 for (i
= 0; i
< count
; i
++) {
329 image_multi_getimg (hdr
, i
, &data
, &len
);
331 printf ("%s Image %d: ", p
, i
);
332 genimg_print_size (len
);
334 if (image_check_type (hdr
, IH_TYPE_SCRIPT
) && i
> 0) {
336 * the user may need to know offsets
337 * if planning to do something with
340 printf ("%s Offset = 0x%08lx\n", p
, data
);
349 * image_get_ramdisk - get and verify ramdisk image
350 * @rd_addr: ramdisk image start address
351 * @arch: expected ramdisk architecture
352 * @verify: checksum verification flag
354 * image_get_ramdisk() returns a pointer to the verified ramdisk image
355 * header. Routine receives image start address and expected architecture
356 * flag. Verification done covers data and header integrity and os/type/arch
359 * If dataflash support is enabled routine checks for dataflash addresses
360 * and handles required dataflash reads.
363 * pointer to a ramdisk image header, if image was found and valid
364 * otherwise, return NULL
366 static image_header_t
* image_get_ramdisk (ulong rd_addr
, uint8_t arch
,
369 image_header_t
*rd_hdr
= (image_header_t
*)rd_addr
;
371 if (!image_check_magic (rd_hdr
)) {
372 puts ("Bad Magic Number\n");
373 show_boot_progress (-10);
377 if (!image_check_hcrc (rd_hdr
)) {
378 puts ("Bad Header Checksum\n");
379 show_boot_progress (-11);
383 show_boot_progress (10);
384 image_print_contents (rd_hdr
);
387 puts(" Verifying Checksum ... ");
388 if (!image_check_dcrc (rd_hdr
)) {
389 puts ("Bad Data CRC\n");
390 show_boot_progress (-12);
396 show_boot_progress (11);
398 if (!image_check_os (rd_hdr
, IH_OS_LINUX
) ||
399 !image_check_arch (rd_hdr
, arch
) ||
400 !image_check_type (rd_hdr
, IH_TYPE_RAMDISK
)) {
401 printf ("No Linux %s Ramdisk Image\n",
402 genimg_get_arch_name(arch
));
403 show_boot_progress (-13);
409 #endif /* !USE_HOSTCC */
411 /*****************************************************************************/
412 /* Shared dual-format routines */
413 /*****************************************************************************/
415 int getenv_yesno (char *var
)
417 char *s
= getenv (var
);
418 return (s
&& (*s
== 'n')) ? 0 : 1;
421 ulong
getenv_bootm_low(void)
423 char *s
= getenv ("bootm_low");
425 ulong tmp
= simple_strtoul (s
, NULL
, 16);
429 #if defined(CONFIG_SYS_SDRAM_BASE)
430 return CONFIG_SYS_SDRAM_BASE
;
431 #elif defined(CONFIG_ARM)
432 return gd
->bd
->bi_dram
[0].start
;
438 phys_size_t
getenv_bootm_size(void)
440 char *s
= getenv ("bootm_size");
443 #ifdef CONFIG_SYS_64BIT_STRTOUL
444 tmp
= (phys_size_t
)simple_strtoull (s
, NULL
, 16);
446 tmp
= (phys_size_t
)simple_strtoul (s
, NULL
, 16);
451 #if defined(CONFIG_ARM)
452 return gd
->bd
->bi_dram
[0].size
;
454 return gd
->bd
->bi_memsize
;
458 void memmove_wd (void *to
, void *from
, size_t len
, ulong chunksz
)
460 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
462 size_t tail
= (len
> chunksz
) ? chunksz
: len
;
464 memmove (to
, from
, tail
);
469 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
470 memmove (to
, from
, len
);
471 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
473 #endif /* !USE_HOSTCC */
475 static void genimg_print_size (uint32_t size
)
478 printf ("%d Bytes = ", size
);
479 print_size (size
, "\n");
481 printf ("%d Bytes = %.2f kB = %.2f MB\n",
482 size
, (double)size
/ 1.024e3
,
483 (double)size
/ 1.048576e6
);
487 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
488 static void genimg_print_time (time_t timestamp
)
493 to_tm (timestamp
, &tm
);
494 printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
495 tm
.tm_year
, tm
.tm_mon
, tm
.tm_mday
,
496 tm
.tm_hour
, tm
.tm_min
, tm
.tm_sec
);
498 printf ("%s", ctime(×tamp
));
501 #endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */
504 * get_table_entry_name - translate entry id to long name
505 * @table: pointer to a translation table for entries of a specific type
506 * @msg: message to be returned when translation fails
507 * @id: entry id to be translated
509 * get_table_entry_name() will go over translation table trying to find
510 * entry that matches given id. If matching entry is found, its long
511 * name is returned to the caller.
514 * long entry name if translation succeeds
517 static char *get_table_entry_name (table_entry_t
*table
, char *msg
, int id
)
519 for (; table
->id
>= 0; ++table
) {
521 return (table
->lname
);
526 const char *genimg_get_os_name (uint8_t os
)
528 return (get_table_entry_name (uimage_os
, "Unknown OS", os
));
531 const char *genimg_get_arch_name (uint8_t arch
)
533 return (get_table_entry_name (uimage_arch
, "Unknown Architecture", arch
));
536 const char *genimg_get_type_name (uint8_t type
)
538 return (get_table_entry_name (uimage_type
, "Unknown Image", type
));
541 const char *genimg_get_comp_name (uint8_t comp
)
543 return (get_table_entry_name (uimage_comp
, "Unknown Compression", comp
));
547 * get_table_entry_id - translate short entry name to id
548 * @table: pointer to a translation table for entries of a specific type
549 * @table_name: to be used in case of error
550 * @name: entry short name to be translated
552 * get_table_entry_id() will go over translation table trying to find
553 * entry that matches given short name. If matching entry is found,
554 * its id returned to the caller.
557 * entry id if translation succeeds
560 static int get_table_entry_id (table_entry_t
*table
,
561 const char *table_name
, const char *name
)
567 for (t
= table
; t
->id
>= 0; ++t
) {
568 if (t
->sname
&& strcasecmp(t
->sname
, name
) == 0)
572 fprintf (stderr
, "\nInvalid %s Type - valid names are", table_name
);
573 for (t
= table
; t
->id
>= 0; ++t
) {
574 if (t
->sname
== NULL
)
576 fprintf (stderr
, "%c %s", (first
) ? ':' : ',', t
->sname
);
579 fprintf (stderr
, "\n");
581 for (t
= table
; t
->id
>= 0; ++t
) {
582 if (t
->sname
&& strcmp(t
->sname
, name
) == 0)
585 debug ("Invalid %s Type: %s\n", table_name
, name
);
586 #endif /* USE_HOSTCC */
590 int genimg_get_os_id (const char *name
)
592 return (get_table_entry_id (uimage_os
, "OS", name
));
595 int genimg_get_arch_id (const char *name
)
597 return (get_table_entry_id (uimage_arch
, "CPU", name
));
600 int genimg_get_type_id (const char *name
)
602 return (get_table_entry_id (uimage_type
, "Image", name
));
605 int genimg_get_comp_id (const char *name
)
607 return (get_table_entry_id (uimage_comp
, "Compression", name
));
612 * genimg_get_format - get image format type
613 * @img_addr: image start address
615 * genimg_get_format() checks whether provided address points to a valid
616 * legacy or FIT image.
618 * New uImage format and FDT blob are based on a libfdt. FDT blob
619 * may be passed directly or embedded in a FIT image. In both situations
620 * genimg_get_format() must be able to dectect libfdt header.
623 * image format type or IMAGE_FORMAT_INVALID if no image is present
625 int genimg_get_format (void *img_addr
)
627 ulong format
= IMAGE_FORMAT_INVALID
;
629 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
633 hdr
= (image_header_t
*)img_addr
;
634 if (image_check_magic(hdr
))
635 format
= IMAGE_FORMAT_LEGACY
;
636 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
638 fit_hdr
= (char *)img_addr
;
639 if (fdt_check_header (fit_hdr
) == 0)
640 format
= IMAGE_FORMAT_FIT
;
648 * genimg_get_image - get image from special storage (if necessary)
649 * @img_addr: image start address
651 * genimg_get_image() checks if provided image start adddress is located
652 * in a dataflash storage. If so, image is moved to a system RAM memory.
655 * image start address after possible relocation from special storage
657 ulong
genimg_get_image (ulong img_addr
)
659 ulong ram_addr
= img_addr
;
661 #ifdef CONFIG_HAS_DATAFLASH
662 ulong h_size
, d_size
;
664 if (addr_dataflash (img_addr
)){
665 /* ger RAM address */
666 ram_addr
= CONFIG_SYS_LOAD_ADDR
;
668 /* get header size */
669 h_size
= image_get_header_size ();
670 #if defined(CONFIG_FIT)
671 if (sizeof(struct fdt_header
) > h_size
)
672 h_size
= sizeof(struct fdt_header
);
676 debug (" Reading image header from dataflash address "
677 "%08lx to RAM address %08lx\n", img_addr
, ram_addr
);
679 read_dataflash (img_addr
, h_size
, (char *)ram_addr
);
682 switch (genimg_get_format ((void *)ram_addr
)) {
683 case IMAGE_FORMAT_LEGACY
:
684 d_size
= image_get_data_size ((image_header_t
*)ram_addr
);
685 debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n",
688 #if defined(CONFIG_FIT)
689 case IMAGE_FORMAT_FIT
:
690 d_size
= fit_get_size ((const void *)ram_addr
) - h_size
;
691 debug (" FIT/FDT format image found at 0x%08lx, size 0x%08lx\n",
696 printf (" No valid image found at 0x%08lx\n", img_addr
);
700 /* read in image data */
701 debug (" Reading image remaining data from dataflash address "
702 "%08lx to RAM address %08lx\n", img_addr
+ h_size
,
705 read_dataflash (img_addr
+ h_size
, d_size
,
706 (char *)(ram_addr
+ h_size
));
709 #endif /* CONFIG_HAS_DATAFLASH */
715 * fit_has_config - check if there is a valid FIT configuration
716 * @images: pointer to the bootm command headers structure
718 * fit_has_config() checks if there is a FIT configuration in use
719 * (if FTI support is present).
722 * 0, no FIT support or no configuration found
723 * 1, configuration found
725 int genimg_has_config (bootm_headers_t
*images
)
727 #if defined(CONFIG_FIT)
728 if (images
->fit_uname_cfg
)
735 * boot_get_ramdisk - main ramdisk handling routine
736 * @argc: command argument count
737 * @argv: command argument list
738 * @images: pointer to the bootm images structure
739 * @arch: expected ramdisk architecture
740 * @rd_start: pointer to a ulong variable, will hold ramdisk start address
741 * @rd_end: pointer to a ulong variable, will hold ramdisk end
743 * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
744 * Curently supported are the following ramdisk sources:
745 * - multicomponent kernel/ramdisk image,
746 * - commandline provided address of decicated ramdisk image.
749 * 0, if ramdisk image was found and valid, or skiped
750 * rd_start and rd_end are set to ramdisk start/end addresses if
751 * ramdisk image is found and valid
753 * 1, if ramdisk image is found but corrupted, or invalid
754 * rd_start and rd_end are set to 0 if no ramdisk exists
756 int boot_get_ramdisk (int argc
, char *argv
[], bootm_headers_t
*images
,
757 uint8_t arch
, ulong
*rd_start
, ulong
*rd_end
)
759 ulong rd_addr
, rd_load
;
760 ulong rd_data
, rd_len
;
761 image_header_t
*rd_hdr
;
762 #if defined(CONFIG_FIT)
764 const char *fit_uname_config
= NULL
;
765 const char *fit_uname_ramdisk
= NULL
;
777 * Look for a '-' which indicates to ignore the
780 if ((argc
>= 3) && (strcmp(argv
[2], "-") == 0)) {
781 debug ("## Skipping init Ramdisk\n");
782 rd_len
= rd_data
= 0;
783 } else if (argc
>= 3 || genimg_has_config (images
)) {
784 #if defined(CONFIG_FIT)
787 * If the init ramdisk comes from the FIT image and
788 * the FIT image address is omitted in the command
789 * line argument, try to use os FIT image address or
790 * default load address.
792 if (images
->fit_uname_os
)
793 default_addr
= (ulong
)images
->fit_hdr_os
;
795 default_addr
= load_addr
;
797 if (fit_parse_conf (argv
[2], default_addr
,
798 &rd_addr
, &fit_uname_config
)) {
799 debug ("* ramdisk: config '%s' from image at 0x%08lx\n",
800 fit_uname_config
, rd_addr
);
801 } else if (fit_parse_subimage (argv
[2], default_addr
,
802 &rd_addr
, &fit_uname_ramdisk
)) {
803 debug ("* ramdisk: subimage '%s' from image at 0x%08lx\n",
804 fit_uname_ramdisk
, rd_addr
);
808 rd_addr
= simple_strtoul(argv
[2], NULL
, 16);
809 debug ("* ramdisk: cmdline image address = 0x%08lx\n",
812 #if defined(CONFIG_FIT)
814 /* use FIT configuration provided in first bootm
817 rd_addr
= (ulong
)images
->fit_hdr_os
;
818 fit_uname_config
= images
->fit_uname_cfg
;
819 debug ("* ramdisk: using config '%s' from image at 0x%08lx\n",
820 fit_uname_config
, rd_addr
);
823 * Check whether configuration has ramdisk defined,
824 * if not, don't try to use it, quit silently.
826 fit_hdr
= (void *)rd_addr
;
827 cfg_noffset
= fit_conf_get_node (fit_hdr
, fit_uname_config
);
828 if (cfg_noffset
< 0) {
829 debug ("* ramdisk: no such config\n");
833 rd_noffset
= fit_conf_get_ramdisk_node (fit_hdr
, cfg_noffset
);
834 if (rd_noffset
< 0) {
835 debug ("* ramdisk: no ramdisk in config\n");
841 /* copy from dataflash if needed */
842 rd_addr
= genimg_get_image (rd_addr
);
845 * Check if there is an initrd image at the
846 * address provided in the second bootm argument
847 * check image type, for FIT images get FIT node.
849 switch (genimg_get_format ((void *)rd_addr
)) {
850 case IMAGE_FORMAT_LEGACY
:
851 printf ("## Loading init Ramdisk from Legacy "
852 "Image at %08lx ...\n", rd_addr
);
854 show_boot_progress (9);
855 rd_hdr
= image_get_ramdisk (rd_addr
, arch
,
861 rd_data
= image_get_data (rd_hdr
);
862 rd_len
= image_get_data_size (rd_hdr
);
863 rd_load
= image_get_load (rd_hdr
);
865 #if defined(CONFIG_FIT)
866 case IMAGE_FORMAT_FIT
:
867 fit_hdr
= (void *)rd_addr
;
868 printf ("## Loading init Ramdisk from FIT "
869 "Image at %08lx ...\n", rd_addr
);
871 show_boot_progress (120);
872 if (!fit_check_format (fit_hdr
)) {
873 puts ("Bad FIT ramdisk image format!\n");
874 show_boot_progress (-120);
877 show_boot_progress (121);
879 if (!fit_uname_ramdisk
) {
881 * no ramdisk image node unit name, try to get config
882 * node first. If config unit node name is NULL
883 * fit_conf_get_node() will try to find default config node
885 show_boot_progress (122);
886 cfg_noffset
= fit_conf_get_node (fit_hdr
, fit_uname_config
);
887 if (cfg_noffset
< 0) {
888 puts ("Could not find configuration node\n");
889 show_boot_progress (-122);
892 fit_uname_config
= fdt_get_name (fit_hdr
, cfg_noffset
, NULL
);
893 printf (" Using '%s' configuration\n", fit_uname_config
);
895 rd_noffset
= fit_conf_get_ramdisk_node (fit_hdr
, cfg_noffset
);
896 fit_uname_ramdisk
= fit_get_name (fit_hdr
, rd_noffset
, NULL
);
898 /* get ramdisk component image node offset */
899 show_boot_progress (123);
900 rd_noffset
= fit_image_get_node (fit_hdr
, fit_uname_ramdisk
);
902 if (rd_noffset
< 0) {
903 puts ("Could not find subimage node\n");
904 show_boot_progress (-124);
908 printf (" Trying '%s' ramdisk subimage\n", fit_uname_ramdisk
);
910 show_boot_progress (125);
911 if (!fit_check_ramdisk (fit_hdr
, rd_noffset
, arch
, images
->verify
))
914 /* get ramdisk image data address and length */
915 if (fit_image_get_data (fit_hdr
, rd_noffset
, &data
, &size
)) {
916 puts ("Could not find ramdisk subimage data!\n");
917 show_boot_progress (-127);
920 show_boot_progress (128);
922 rd_data
= (ulong
)data
;
925 if (fit_image_get_load (fit_hdr
, rd_noffset
, &rd_load
)) {
926 puts ("Can't get ramdisk subimage load address!\n");
927 show_boot_progress (-129);
930 show_boot_progress (129);
932 images
->fit_hdr_rd
= fit_hdr
;
933 images
->fit_uname_rd
= fit_uname_ramdisk
;
934 images
->fit_noffset_rd
= rd_noffset
;
938 puts ("Wrong Ramdisk Image Format\n");
939 rd_data
= rd_len
= rd_load
= 0;
943 #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO)
945 * We need to copy the ramdisk to SRAM to let Linux boot
948 memmove ((void *)rd_load
, (uchar
*)rd_data
, rd_len
);
951 #endif /* CONFIG_B2 || CONFIG_EVB4510 || CONFIG_ARMADILLO */
953 } else if (images
->legacy_hdr_valid
&&
954 image_check_type (&images
->legacy_hdr_os_copy
, IH_TYPE_MULTI
)) {
956 * Now check if we have a legacy mult-component image,
957 * get second entry data start address and len.
959 show_boot_progress (13);
960 printf ("## Loading init Ramdisk from multi component "
961 "Legacy Image at %08lx ...\n",
962 (ulong
)images
->legacy_hdr_os
);
964 image_multi_getimg (images
->legacy_hdr_os
, 1, &rd_data
, &rd_len
);
969 show_boot_progress (14);
970 rd_len
= rd_data
= 0;
974 debug ("## No init Ramdisk\n");
977 *rd_end
= rd_data
+ rd_len
;
979 debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
985 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
987 * boot_ramdisk_high - relocate init ramdisk
988 * @lmb: pointer to lmb handle, will be used for memory mgmt
989 * @rd_data: ramdisk data start address
990 * @rd_len: ramdisk data length
991 * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
992 * start address (after possible relocation)
993 * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
994 * end address (after possible relocation)
996 * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
997 * variable and if requested ramdisk data is moved to a specified location.
999 * Initrd_start and initrd_end are set to final (after relocation) ramdisk
1000 * start/end addresses if ramdisk image start and len were provided,
1001 * otherwise set initrd_start and initrd_end set to zeros.
1007 int boot_ramdisk_high (struct lmb
*lmb
, ulong rd_data
, ulong rd_len
,
1008 ulong
*initrd_start
, ulong
*initrd_end
)
1012 int initrd_copy_to_ram
= 1;
1014 if ((s
= getenv ("initrd_high")) != NULL
) {
1015 /* a value of "no" or a similar string will act like 0,
1016 * turning the "load high" feature off. This is intentional.
1018 initrd_high
= simple_strtoul (s
, NULL
, 16);
1019 if (initrd_high
== ~0)
1020 initrd_copy_to_ram
= 0;
1022 /* not set, no restrictions to load high */
1027 #ifdef CONFIG_LOGBUFFER
1028 /* Prevent initrd from overwriting logbuffer */
1029 lmb_reserve(lmb
, logbuffer_base() - LOGBUFF_OVERHEAD
, LOGBUFF_RESERVE
);
1032 debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
1033 initrd_high
, initrd_copy_to_ram
);
1036 if (!initrd_copy_to_ram
) { /* zero-copy ramdisk support */
1037 debug (" in-place initrd\n");
1038 *initrd_start
= rd_data
;
1039 *initrd_end
= rd_data
+ rd_len
;
1040 lmb_reserve(lmb
, rd_data
, rd_len
);
1043 *initrd_start
= (ulong
)lmb_alloc_base (lmb
, rd_len
, 0x1000, initrd_high
);
1045 *initrd_start
= (ulong
)lmb_alloc (lmb
, rd_len
, 0x1000);
1047 if (*initrd_start
== 0) {
1048 puts ("ramdisk - allocation error\n");
1051 show_boot_progress (12);
1053 *initrd_end
= *initrd_start
+ rd_len
;
1054 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
1055 *initrd_start
, *initrd_end
);
1057 memmove_wd ((void *)*initrd_start
,
1058 (void *)rd_data
, rd_len
, CHUNKSZ
);
1066 debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
1067 *initrd_start
, *initrd_end
);
1075 #ifdef CONFIG_OF_LIBFDT
1076 static void fdt_error (const char *msg
)
1080 puts (" - must RESET the board to recover.\n");
1083 static image_header_t
*image_get_fdt (ulong fdt_addr
)
1085 image_header_t
*fdt_hdr
= (image_header_t
*)fdt_addr
;
1087 image_print_contents (fdt_hdr
);
1089 puts (" Verifying Checksum ... ");
1090 if (!image_check_hcrc (fdt_hdr
)) {
1091 fdt_error ("fdt header checksum invalid");
1095 if (!image_check_dcrc (fdt_hdr
)) {
1096 fdt_error ("fdt checksum invalid");
1101 if (!image_check_type (fdt_hdr
, IH_TYPE_FLATDT
)) {
1102 fdt_error ("uImage is not a fdt");
1105 if (image_get_comp (fdt_hdr
) != IH_COMP_NONE
) {
1106 fdt_error ("uImage is compressed");
1109 if (fdt_check_header ((char *)image_get_data (fdt_hdr
)) != 0) {
1110 fdt_error ("uImage data is not a fdt");
1117 * fit_check_fdt - verify FIT format FDT subimage
1118 * @fit_hdr: pointer to the FIT header
1119 * fdt_noffset: FDT subimage node offset within FIT image
1120 * @verify: data CRC verification flag
1122 * fit_check_fdt() verifies integrity of the FDT subimage and from
1123 * specified FIT image.
1129 #if defined(CONFIG_FIT)
1130 static int fit_check_fdt (const void *fit
, int fdt_noffset
, int verify
)
1132 fit_image_print (fit
, fdt_noffset
, " ");
1135 puts (" Verifying Hash Integrity ... ");
1136 if (!fit_image_check_hashes (fit
, fdt_noffset
)) {
1137 fdt_error ("Bad Data Hash");
1143 if (!fit_image_check_type (fit
, fdt_noffset
, IH_TYPE_FLATDT
)) {
1144 fdt_error ("Not a FDT image");
1148 if (!fit_image_check_comp (fit
, fdt_noffset
, IH_COMP_NONE
)) {
1149 fdt_error ("FDT image is compressed");
1155 #endif /* CONFIG_FIT */
1157 #ifndef CONFIG_SYS_FDT_PAD
1158 #define CONFIG_SYS_FDT_PAD 0x3000
1162 * boot_relocate_fdt - relocate flat device tree
1163 * @lmb: pointer to lmb handle, will be used for memory mgmt
1164 * @bootmap_base: base address of the bootmap region
1165 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1166 * @of_size: pointer to a ulong variable, will hold fdt length
1168 * boot_relocate_fdt() determines if the of_flat_tree address is within
1169 * the bootmap and if not relocates it into that region
1171 * of_flat_tree and of_size are set to final (after relocation) values
1177 int boot_relocate_fdt (struct lmb
*lmb
, ulong bootmap_base
,
1178 char **of_flat_tree
, ulong
*of_size
)
1180 char *fdt_blob
= *of_flat_tree
;
1188 if (fdt_check_header (fdt_blob
) != 0) {
1189 fdt_error ("image is not a fdt");
1193 #ifndef CONFIG_SYS_NO_FLASH
1194 /* move the blob if it is in flash (set relocate) */
1195 if (addr2info ((ulong
)fdt_blob
) != NULL
)
1200 * The blob needs to be inside the boot mapping.
1202 if (fdt_blob
< (char *)bootmap_base
)
1205 if ((fdt_blob
+ *of_size
+ CONFIG_SYS_FDT_PAD
) >=
1206 ((char *)CONFIG_SYS_BOOTMAPSZ
+ bootmap_base
))
1209 /* move flattend device tree if needed */
1214 /* position on a 4K boundary before the alloc_current */
1215 /* Pad the FDT by a specified amount */
1216 of_len
= *of_size
+ CONFIG_SYS_FDT_PAD
;
1217 of_start
= (unsigned long)lmb_alloc_base(lmb
, of_len
, 0x1000,
1218 (CONFIG_SYS_BOOTMAPSZ
+ bootmap_base
));
1220 if (of_start
== 0) {
1221 puts("device tree - allocation error\n");
1225 debug ("## device tree at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
1226 (ulong
)fdt_blob
, (ulong
)fdt_blob
+ *of_size
- 1,
1229 printf (" Loading Device Tree to %08lx, end %08lx ... ",
1230 of_start
, of_start
+ of_len
- 1);
1232 err
= fdt_open_into (fdt_blob
, (void *)of_start
, of_len
);
1234 fdt_error ("fdt move failed");
1239 *of_flat_tree
= (char *)of_start
;
1242 *of_flat_tree
= fdt_blob
;
1243 of_len
= (CONFIG_SYS_BOOTMAPSZ
+ bootmap_base
) - (ulong
)fdt_blob
;
1244 lmb_reserve(lmb
, (ulong
)fdt_blob
, of_len
);
1245 fdt_set_totalsize(*of_flat_tree
, of_len
);
1250 set_working_fdt_addr(*of_flat_tree
);
1258 * boot_get_fdt - main fdt handling routine
1259 * @argc: command argument count
1260 * @argv: command argument list
1261 * @images: pointer to the bootm images structure
1262 * @of_flat_tree: pointer to a char* variable, will hold fdt start address
1263 * @of_size: pointer to a ulong variable, will hold fdt length
1265 * boot_get_fdt() is responsible for finding a valid flat device tree image.
1266 * Curently supported are the following ramdisk sources:
1267 * - multicomponent kernel/ramdisk image,
1268 * - commandline provided address of decicated ramdisk image.
1271 * 0, if fdt image was found and valid, or skipped
1272 * of_flat_tree and of_size are set to fdt start address and length if
1273 * fdt image is found and valid
1275 * 1, if fdt image is found but corrupted
1276 * of_flat_tree and of_size are set to 0 if no fdt exists
1278 int boot_get_fdt (int flag
, int argc
, char *argv
[], bootm_headers_t
*images
,
1279 char **of_flat_tree
, ulong
*of_size
)
1282 image_header_t
*fdt_hdr
;
1283 char *fdt_blob
= NULL
;
1284 ulong image_start
, image_end
;
1285 ulong load_start
, load_end
;
1286 #if defined(CONFIG_FIT)
1288 const char *fit_uname_config
= NULL
;
1289 const char *fit_uname_fdt
= NULL
;
1297 *of_flat_tree
= NULL
;
1300 if (argc
> 3 || genimg_has_config (images
)) {
1301 #if defined(CONFIG_FIT)
1304 * If the FDT blob comes from the FIT image and the
1305 * FIT image address is omitted in the command line
1306 * argument, try to use ramdisk or os FIT image
1307 * address or default load address.
1309 if (images
->fit_uname_rd
)
1310 default_addr
= (ulong
)images
->fit_hdr_rd
;
1311 else if (images
->fit_uname_os
)
1312 default_addr
= (ulong
)images
->fit_hdr_os
;
1314 default_addr
= load_addr
;
1316 if (fit_parse_conf (argv
[3], default_addr
,
1317 &fdt_addr
, &fit_uname_config
)) {
1318 debug ("* fdt: config '%s' from image at 0x%08lx\n",
1319 fit_uname_config
, fdt_addr
);
1320 } else if (fit_parse_subimage (argv
[3], default_addr
,
1321 &fdt_addr
, &fit_uname_fdt
)) {
1322 debug ("* fdt: subimage '%s' from image at 0x%08lx\n",
1323 fit_uname_fdt
, fdt_addr
);
1327 fdt_addr
= simple_strtoul(argv
[3], NULL
, 16);
1328 debug ("* fdt: cmdline image address = 0x%08lx\n",
1331 #if defined(CONFIG_FIT)
1333 /* use FIT configuration provided in first bootm
1336 fdt_addr
= (ulong
)images
->fit_hdr_os
;
1337 fit_uname_config
= images
->fit_uname_cfg
;
1338 debug ("* fdt: using config '%s' from image at 0x%08lx\n",
1339 fit_uname_config
, fdt_addr
);
1342 * Check whether configuration has FDT blob defined,
1343 * if not quit silently.
1345 fit_hdr
= (void *)fdt_addr
;
1346 cfg_noffset
= fit_conf_get_node (fit_hdr
,
1348 if (cfg_noffset
< 0) {
1349 debug ("* fdt: no such config\n");
1353 fdt_noffset
= fit_conf_get_fdt_node (fit_hdr
,
1355 if (fdt_noffset
< 0) {
1356 debug ("* fdt: no fdt in config\n");
1362 debug ("## Checking for 'FDT'/'FDT Image' at %08lx\n",
1365 /* copy from dataflash if needed */
1366 fdt_addr
= genimg_get_image (fdt_addr
);
1369 * Check if there is an FDT image at the
1370 * address provided in the second bootm argument
1371 * check image type, for FIT images get a FIT node.
1373 switch (genimg_get_format ((void *)fdt_addr
)) {
1374 case IMAGE_FORMAT_LEGACY
:
1375 /* verify fdt_addr points to a valid image header */
1376 printf ("## Flattened Device Tree from Legacy Image at %08lx\n",
1378 fdt_hdr
= image_get_fdt (fdt_addr
);
1383 * move image data to the load address,
1384 * make sure we don't overwrite initial image
1386 image_start
= (ulong
)fdt_hdr
;
1387 image_end
= image_get_image_end (fdt_hdr
);
1389 load_start
= image_get_load (fdt_hdr
);
1390 load_end
= load_start
+ image_get_data_size (fdt_hdr
);
1392 if ((load_start
< image_end
) && (load_end
> image_start
)) {
1393 fdt_error ("fdt overwritten");
1397 debug (" Loading FDT from 0x%08lx to 0x%08lx\n",
1398 image_get_data (fdt_hdr
), load_start
);
1400 memmove ((void *)load_start
,
1401 (void *)image_get_data (fdt_hdr
),
1402 image_get_data_size (fdt_hdr
));
1404 fdt_blob
= (char *)load_start
;
1406 case IMAGE_FORMAT_FIT
:
1408 * This case will catch both: new uImage format
1409 * (libfdt based) and raw FDT blob (also libfdt
1412 #if defined(CONFIG_FIT)
1413 /* check FDT blob vs FIT blob */
1414 if (fit_check_format ((const void *)fdt_addr
)) {
1418 fit_hdr
= (void *)fdt_addr
;
1419 printf ("## Flattened Device Tree from FIT Image at %08lx\n",
1422 if (!fit_uname_fdt
) {
1424 * no FDT blob image node unit name,
1425 * try to get config node first. If
1426 * config unit node name is NULL
1427 * fit_conf_get_node() will try to
1428 * find default config node
1430 cfg_noffset
= fit_conf_get_node (fit_hdr
,
1433 if (cfg_noffset
< 0) {
1434 fdt_error ("Could not find configuration node\n");
1438 fit_uname_config
= fdt_get_name (fit_hdr
,
1440 printf (" Using '%s' configuration\n",
1443 fdt_noffset
= fit_conf_get_fdt_node (fit_hdr
,
1445 fit_uname_fdt
= fit_get_name (fit_hdr
,
1448 /* get FDT component image node offset */
1449 fdt_noffset
= fit_image_get_node (fit_hdr
,
1452 if (fdt_noffset
< 0) {
1453 fdt_error ("Could not find subimage node\n");
1457 printf (" Trying '%s' FDT blob subimage\n",
1460 if (!fit_check_fdt (fit_hdr
, fdt_noffset
,
1464 /* get ramdisk image data address and length */
1465 if (fit_image_get_data (fit_hdr
, fdt_noffset
,
1467 fdt_error ("Could not find FDT subimage data");
1471 /* verift that image data is a proper FDT blob */
1472 if (fdt_check_header ((char *)data
) != 0) {
1473 fdt_error ("Subimage data is not a FTD");
1478 * move image data to the load address,
1479 * make sure we don't overwrite initial image
1481 image_start
= (ulong
)fit_hdr
;
1482 image_end
= fit_get_end (fit_hdr
);
1484 if (fit_image_get_load (fit_hdr
, fdt_noffset
,
1485 &load_start
) == 0) {
1486 load_end
= load_start
+ size
;
1488 if ((load_start
< image_end
) &&
1489 (load_end
> image_start
)) {
1490 fdt_error ("FDT overwritten");
1494 printf (" Loading FDT from 0x%08lx to 0x%08lx\n",
1495 (ulong
)data
, load_start
);
1497 memmove ((void *)load_start
,
1498 (void *)data
, size
);
1500 fdt_blob
= (char *)load_start
;
1502 fdt_blob
= (char *)data
;
1505 images
->fit_hdr_fdt
= fit_hdr
;
1506 images
->fit_uname_fdt
= fit_uname_fdt
;
1507 images
->fit_noffset_fdt
= fdt_noffset
;
1515 fdt_blob
= (char *)fdt_addr
;
1516 debug ("* fdt: raw FDT blob\n");
1517 printf ("## Flattened Device Tree blob at %08lx\n", (long)fdt_blob
);
1521 puts ("ERROR: Did not find a cmdline Flattened Device Tree\n");
1525 printf (" Booting using the fdt blob at 0x%x\n", (int)fdt_blob
);
1527 } else if (images
->legacy_hdr_valid
&&
1528 image_check_type (&images
->legacy_hdr_os_copy
, IH_TYPE_MULTI
)) {
1530 ulong fdt_data
, fdt_len
;
1533 * Now check if we have a legacy multi-component image,
1534 * get second entry data start address and len.
1536 printf ("## Flattened Device Tree from multi "
1537 "component Image at %08lX\n",
1538 (ulong
)images
->legacy_hdr_os
);
1540 image_multi_getimg (images
->legacy_hdr_os
, 2, &fdt_data
, &fdt_len
);
1543 fdt_blob
= (char *)fdt_data
;
1544 printf (" Booting using the fdt at 0x%x\n", (int)fdt_blob
);
1546 if (fdt_check_header (fdt_blob
) != 0) {
1547 fdt_error ("image is not a fdt");
1551 if (be32_to_cpu (fdt_totalsize (fdt_blob
)) != fdt_len
) {
1552 fdt_error ("fdt size != image size");
1556 debug ("## No Flattened Device Tree\n");
1560 debug ("## No Flattened Device Tree\n");
1564 *of_flat_tree
= fdt_blob
;
1565 *of_size
= be32_to_cpu (fdt_totalsize (fdt_blob
));
1566 debug (" of_flat_tree at 0x%08lx size 0x%08lx\n",
1567 (ulong
)*of_flat_tree
, *of_size
);
1576 #endif /* CONFIG_OF_LIBFDT */
1579 * boot_get_cmdline - allocate and initialize kernel cmdline
1580 * @lmb: pointer to lmb handle, will be used for memory mgmt
1581 * @cmd_start: pointer to a ulong variable, will hold cmdline start
1582 * @cmd_end: pointer to a ulong variable, will hold cmdline end
1583 * @bootmap_base: ulong variable, holds offset in physical memory to
1586 * boot_get_cmdline() allocates space for kernel command line below
1587 * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt
1588 * variable is present its contents is copied to allocated kernel
1595 int boot_get_cmdline (struct lmb
*lmb
, ulong
*cmd_start
, ulong
*cmd_end
,
1601 cmdline
= (char *)(ulong
)lmb_alloc_base(lmb
, CONFIG_SYS_BARGSIZE
, 0xf,
1602 CONFIG_SYS_BOOTMAPSZ
+ bootmap_base
);
1604 if (cmdline
== NULL
)
1607 if ((s
= getenv("bootargs")) == NULL
)
1612 *cmd_start
= (ulong
) & cmdline
[0];
1613 *cmd_end
= *cmd_start
+ strlen(cmdline
);
1615 debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start
, *cmd_end
);
1621 * boot_get_kbd - allocate and initialize kernel copy of board info
1622 * @lmb: pointer to lmb handle, will be used for memory mgmt
1623 * @kbd: double pointer to board info data
1624 * @bootmap_base: ulong variable, holds offset in physical memory to
1627 * boot_get_kbd() allocates space for kernel copy of board info data below
1628 * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with
1629 * the current u-boot board info data.
1635 int boot_get_kbd (struct lmb
*lmb
, bd_t
**kbd
, ulong bootmap_base
)
1637 *kbd
= (bd_t
*)(ulong
)lmb_alloc_base(lmb
, sizeof(bd_t
), 0xf,
1638 CONFIG_SYS_BOOTMAPSZ
+ bootmap_base
);
1644 debug ("## kernel board info at 0x%08lx\n", (ulong
)*kbd
);
1646 #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
1647 do_bdinfo(NULL
, 0, 0, NULL
);
1652 #endif /* CONFIG_PPC || CONFIG_M68K */
1653 #endif /* !USE_HOSTCC */
1655 #if defined(CONFIG_FIT)
1656 /*****************************************************************************/
1657 /* New uImage format routines */
1658 /*****************************************************************************/
1660 static int fit_parse_spec (const char *spec
, char sepc
, ulong addr_curr
,
1661 ulong
*addr
, const char **name
)
1668 sep
= strchr (spec
, sepc
);
1671 *addr
= simple_strtoul (spec
, NULL
, 16);
1681 * fit_parse_conf - parse FIT configuration spec
1682 * @spec: input string, containing configuration spec
1683 * @add_curr: current image address (to be used as a possible default)
1684 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1686 * @conf_name double pointer to a char, will hold pointer to a configuration
1689 * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
1690 * where <addr> is a FIT image address that contains configuration
1691 * with a <conf> unit name.
1693 * Address part is optional, and if omitted default add_curr will
1697 * 1 if spec is a valid configuration string,
1698 * addr and conf_name are set accordingly
1701 inline int fit_parse_conf (const char *spec
, ulong addr_curr
,
1702 ulong
*addr
, const char **conf_name
)
1704 return fit_parse_spec (spec
, '#', addr_curr
, addr
, conf_name
);
1708 * fit_parse_subimage - parse FIT subimage spec
1709 * @spec: input string, containing subimage spec
1710 * @add_curr: current image address (to be used as a possible default)
1711 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1713 * @image_name: double pointer to a char, will hold pointer to a subimage name
1715 * fit_parse_subimage() expects subimage spec in the for of
1716 * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
1717 * subimage with a <subimg> unit name.
1719 * Address part is optional, and if omitted default add_curr will
1723 * 1 if spec is a valid subimage string,
1724 * addr and image_name are set accordingly
1727 inline int fit_parse_subimage (const char *spec
, ulong addr_curr
,
1728 ulong
*addr
, const char **image_name
)
1730 return fit_parse_spec (spec
, ':', addr_curr
, addr
, image_name
);
1732 #endif /* !USE_HOSTCC */
1734 static void fit_get_debug (const void *fit
, int noffset
,
1735 char *prop_name
, int err
)
1737 debug ("Can't get '%s' property from FIT 0x%08lx, "
1738 "node: offset %d, name %s (%s)\n",
1739 prop_name
, (ulong
)fit
, noffset
,
1740 fit_get_name (fit
, noffset
, NULL
),
1741 fdt_strerror (err
));
1745 * fit_print_contents - prints out the contents of the FIT format image
1746 * @fit: pointer to the FIT format image header
1747 * @p: pointer to prefix string
1749 * fit_print_contents() formats a multi line FIT image contents description.
1750 * The routine prints out FIT image properties (root node level) follwed by
1751 * the details of each component image.
1754 * no returned results
1756 void fit_print_contents (const void *fit
)
1767 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1777 /* Root node properties */
1778 ret
= fit_get_desc (fit
, 0, &desc
);
1779 printf ("%sFIT description: ", p
);
1781 printf ("unavailable\n");
1783 printf ("%s\n", desc
);
1785 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1786 ret
= fit_get_timestamp (fit
, 0, ×tamp
);
1787 printf ("%sCreated: ", p
);
1789 printf ("unavailable\n");
1791 genimg_print_time (timestamp
);
1794 /* Find images parent node offset */
1795 images_noffset
= fdt_path_offset (fit
, FIT_IMAGES_PATH
);
1796 if (images_noffset
< 0) {
1797 printf ("Can't find images parent node '%s' (%s)\n",
1798 FIT_IMAGES_PATH
, fdt_strerror (images_noffset
));
1802 /* Process its subnodes, print out component images details */
1803 for (ndepth
= 0, count
= 0, noffset
= fdt_next_node (fit
, images_noffset
, &ndepth
);
1804 (noffset
>= 0) && (ndepth
> 0);
1805 noffset
= fdt_next_node (fit
, noffset
, &ndepth
)) {
1808 * Direct child node of the images parent node,
1809 * i.e. component image node.
1811 printf ("%s Image %u (%s)\n", p
, count
++,
1812 fit_get_name(fit
, noffset
, NULL
));
1814 fit_image_print (fit
, noffset
, p
);
1818 /* Find configurations parent node offset */
1819 confs_noffset
= fdt_path_offset (fit
, FIT_CONFS_PATH
);
1820 if (confs_noffset
< 0) {
1821 debug ("Can't get configurations parent node '%s' (%s)\n",
1822 FIT_CONFS_PATH
, fdt_strerror (confs_noffset
));
1826 /* get default configuration unit name from default property */
1827 uname
= (char *)fdt_getprop (fit
, noffset
, FIT_DEFAULT_PROP
, NULL
);
1829 printf ("%s Default Configuration: '%s'\n", p
, uname
);
1831 /* Process its subnodes, print out configurations details */
1832 for (ndepth
= 0, count
= 0, noffset
= fdt_next_node (fit
, confs_noffset
, &ndepth
);
1833 (noffset
>= 0) && (ndepth
> 0);
1834 noffset
= fdt_next_node (fit
, noffset
, &ndepth
)) {
1837 * Direct child node of the configurations parent node,
1838 * i.e. configuration node.
1840 printf ("%s Configuration %u (%s)\n", p
, count
++,
1841 fit_get_name(fit
, noffset
, NULL
));
1843 fit_conf_print (fit
, noffset
, p
);
1849 * fit_image_print - prints out the FIT component image details
1850 * @fit: pointer to the FIT format image header
1851 * @image_noffset: offset of the component image node
1852 * @p: pointer to prefix string
1854 * fit_image_print() lists all mandatory properies for the processed component
1855 * image. If present, hash nodes are printed out as well. Load
1856 * address for images of type firmware is also printed out. Since the load
1857 * address is not mandatory for firmware images, it will be output as
1858 * "unavailable" when not present.
1861 * no returned results
1863 void fit_image_print (const void *fit
, int image_noffset
, const char *p
)
1866 uint8_t type
, arch
, os
, comp
;
1874 /* Mandatory properties */
1875 ret
= fit_get_desc (fit
, image_noffset
, &desc
);
1876 printf ("%s Description: ", p
);
1878 printf ("unavailable\n");
1880 printf ("%s\n", desc
);
1882 fit_image_get_type (fit
, image_noffset
, &type
);
1883 printf ("%s Type: %s\n", p
, genimg_get_type_name (type
));
1885 fit_image_get_comp (fit
, image_noffset
, &comp
);
1886 printf ("%s Compression: %s\n", p
, genimg_get_comp_name (comp
));
1888 ret
= fit_image_get_data (fit
, image_noffset
, &data
, &size
);
1891 printf ("%s Data Start: ", p
);
1893 printf ("unavailable\n");
1895 printf ("0x%08lx\n", (ulong
)data
);
1898 printf ("%s Data Size: ", p
);
1900 printf ("unavailable\n");
1902 genimg_print_size (size
);
1904 /* Remaining, type dependent properties */
1905 if ((type
== IH_TYPE_KERNEL
) || (type
== IH_TYPE_STANDALONE
) ||
1906 (type
== IH_TYPE_RAMDISK
) || (type
== IH_TYPE_FIRMWARE
) ||
1907 (type
== IH_TYPE_FLATDT
)) {
1908 fit_image_get_arch (fit
, image_noffset
, &arch
);
1909 printf ("%s Architecture: %s\n", p
, genimg_get_arch_name (arch
));
1912 if (type
== IH_TYPE_KERNEL
) {
1913 fit_image_get_os (fit
, image_noffset
, &os
);
1914 printf ("%s OS: %s\n", p
, genimg_get_os_name (os
));
1917 if ((type
== IH_TYPE_KERNEL
) || (type
== IH_TYPE_STANDALONE
) ||
1918 (type
== IH_TYPE_FIRMWARE
)) {
1919 ret
= fit_image_get_load (fit
, image_noffset
, &load
);
1920 printf ("%s Load Address: ", p
);
1922 printf ("unavailable\n");
1924 printf ("0x%08lx\n", load
);
1927 if ((type
== IH_TYPE_KERNEL
) || (type
== IH_TYPE_STANDALONE
)) {
1928 fit_image_get_entry (fit
, image_noffset
, &entry
);
1929 printf ("%s Entry Point: ", p
);
1931 printf ("unavailable\n");
1933 printf ("0x%08lx\n", entry
);
1936 /* Process all hash subnodes of the component image node */
1937 for (ndepth
= 0, noffset
= fdt_next_node (fit
, image_noffset
, &ndepth
);
1938 (noffset
>= 0) && (ndepth
> 0);
1939 noffset
= fdt_next_node (fit
, noffset
, &ndepth
)) {
1941 /* Direct child node of the component image node */
1942 fit_image_print_hash (fit
, noffset
, p
);
1948 * fit_image_print_hash - prints out the hash node details
1949 * @fit: pointer to the FIT format image header
1950 * @noffset: offset of the hash node
1951 * @p: pointer to prefix string
1953 * fit_image_print_hash() lists properies for the processed hash node
1956 * no returned results
1958 void fit_image_print_hash (const void *fit
, int noffset
, const char *p
)
1966 * Check subnode name, must be equal to "hash".
1967 * Multiple hash nodes require unique unit node
1968 * names, e.g. hash@1, hash@2, etc.
1970 if (strncmp (fit_get_name(fit
, noffset
, NULL
),
1972 strlen(FIT_HASH_NODENAME
)) != 0)
1975 debug ("%s Hash node: '%s'\n", p
,
1976 fit_get_name (fit
, noffset
, NULL
));
1978 printf ("%s Hash algo: ", p
);
1979 if (fit_image_hash_get_algo (fit
, noffset
, &algo
)) {
1980 printf ("invalid/unsupported\n");
1983 printf ("%s\n", algo
);
1985 ret
= fit_image_hash_get_value (fit
, noffset
, &value
,
1987 printf ("%s Hash value: ", p
);
1989 printf ("unavailable\n");
1991 for (i
= 0; i
< value_len
; i
++)
1992 printf ("%02x", value
[i
]);
1996 debug ("%s Hash len: %d\n", p
, value_len
);
2000 * fit_get_desc - get node description property
2001 * @fit: pointer to the FIT format image header
2002 * @noffset: node offset
2003 * @desc: double pointer to the char, will hold pointer to the descrption
2005 * fit_get_desc() reads description property from a given node, if
2006 * description is found pointer to it is returened in third call argument.
2012 int fit_get_desc (const void *fit
, int noffset
, char **desc
)
2016 *desc
= (char *)fdt_getprop (fit
, noffset
, FIT_DESC_PROP
, &len
);
2017 if (*desc
== NULL
) {
2018 fit_get_debug (fit
, noffset
, FIT_DESC_PROP
, len
);
2026 * fit_get_timestamp - get node timestamp property
2027 * @fit: pointer to the FIT format image header
2028 * @noffset: node offset
2029 * @timestamp: pointer to the time_t, will hold read timestamp
2031 * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
2032 * is found and has a correct size its value is retured in third call
2037 * -1, on property read failure
2038 * -2, on wrong timestamp size
2040 int fit_get_timestamp (const void *fit
, int noffset
, time_t *timestamp
)
2045 data
= fdt_getprop (fit
, noffset
, FIT_TIMESTAMP_PROP
, &len
);
2047 fit_get_debug (fit
, noffset
, FIT_TIMESTAMP_PROP
, len
);
2050 if (len
!= sizeof (uint32_t)) {
2051 debug ("FIT timestamp with incorrect size of (%u)\n", len
);
2055 *timestamp
= uimage_to_cpu (*((uint32_t *)data
));
2060 * fit_image_get_node - get node offset for component image of a given unit name
2061 * @fit: pointer to the FIT format image header
2062 * @image_uname: component image node unit name
2064 * fit_image_get_node() finds a component image (withing the '/images'
2065 * node) of a provided unit name. If image is found its node offset is
2066 * returned to the caller.
2069 * image node offset when found (>=0)
2070 * negative number on failure (FDT_ERR_* code)
2072 int fit_image_get_node (const void *fit
, const char *image_uname
)
2074 int noffset
, images_noffset
;
2076 images_noffset
= fdt_path_offset (fit
, FIT_IMAGES_PATH
);
2077 if (images_noffset
< 0) {
2078 debug ("Can't find images parent node '%s' (%s)\n",
2079 FIT_IMAGES_PATH
, fdt_strerror (images_noffset
));
2080 return images_noffset
;
2083 noffset
= fdt_subnode_offset (fit
, images_noffset
, image_uname
);
2085 debug ("Can't get node offset for image unit name: '%s' (%s)\n",
2086 image_uname
, fdt_strerror (noffset
));
2093 * fit_image_get_os - get os id for a given component image node
2094 * @fit: pointer to the FIT format image header
2095 * @noffset: component image node offset
2096 * @os: pointer to the uint8_t, will hold os numeric id
2098 * fit_image_get_os() finds os property in a given component image node.
2099 * If the property is found, its (string) value is translated to the numeric
2100 * id which is returned to the caller.
2106 int fit_image_get_os (const void *fit
, int noffset
, uint8_t *os
)
2111 /* Get OS name from property data */
2112 data
= fdt_getprop (fit
, noffset
, FIT_OS_PROP
, &len
);
2114 fit_get_debug (fit
, noffset
, FIT_OS_PROP
, len
);
2119 /* Translate OS name to id */
2120 *os
= genimg_get_os_id (data
);
2125 * fit_image_get_arch - get arch id for a given component image node
2126 * @fit: pointer to the FIT format image header
2127 * @noffset: component image node offset
2128 * @arch: pointer to the uint8_t, will hold arch numeric id
2130 * fit_image_get_arch() finds arch property in a given component image node.
2131 * If the property is found, its (string) value is translated to the numeric
2132 * id which is returned to the caller.
2138 int fit_image_get_arch (const void *fit
, int noffset
, uint8_t *arch
)
2143 /* Get architecture name from property data */
2144 data
= fdt_getprop (fit
, noffset
, FIT_ARCH_PROP
, &len
);
2146 fit_get_debug (fit
, noffset
, FIT_ARCH_PROP
, len
);
2151 /* Translate architecture name to id */
2152 *arch
= genimg_get_arch_id (data
);
2157 * fit_image_get_type - get type id for a given component image node
2158 * @fit: pointer to the FIT format image header
2159 * @noffset: component image node offset
2160 * @type: pointer to the uint8_t, will hold type numeric id
2162 * fit_image_get_type() finds type property in a given component image node.
2163 * If the property is found, its (string) value is translated to the numeric
2164 * id which is returned to the caller.
2170 int fit_image_get_type (const void *fit
, int noffset
, uint8_t *type
)
2175 /* Get image type name from property data */
2176 data
= fdt_getprop (fit
, noffset
, FIT_TYPE_PROP
, &len
);
2178 fit_get_debug (fit
, noffset
, FIT_TYPE_PROP
, len
);
2183 /* Translate image type name to id */
2184 *type
= genimg_get_type_id (data
);
2189 * fit_image_get_comp - get comp id for a given component image node
2190 * @fit: pointer to the FIT format image header
2191 * @noffset: component image node offset
2192 * @comp: pointer to the uint8_t, will hold comp numeric id
2194 * fit_image_get_comp() finds comp property in a given component image node.
2195 * If the property is found, its (string) value is translated to the numeric
2196 * id which is returned to the caller.
2202 int fit_image_get_comp (const void *fit
, int noffset
, uint8_t *comp
)
2207 /* Get compression name from property data */
2208 data
= fdt_getprop (fit
, noffset
, FIT_COMP_PROP
, &len
);
2210 fit_get_debug (fit
, noffset
, FIT_COMP_PROP
, len
);
2215 /* Translate compression name to id */
2216 *comp
= genimg_get_comp_id (data
);
2221 * fit_image_get_load - get load address property for a given component image node
2222 * @fit: pointer to the FIT format image header
2223 * @noffset: component image node offset
2224 * @load: pointer to the uint32_t, will hold load address
2226 * fit_image_get_load() finds load address property in a given component image node.
2227 * If the property is found, its value is returned to the caller.
2233 int fit_image_get_load (const void *fit
, int noffset
, ulong
*load
)
2236 const uint32_t *data
;
2238 data
= fdt_getprop (fit
, noffset
, FIT_LOAD_PROP
, &len
);
2240 fit_get_debug (fit
, noffset
, FIT_LOAD_PROP
, len
);
2244 *load
= uimage_to_cpu (*data
);
2249 * fit_image_get_entry - get entry point address property for a given component image node
2250 * @fit: pointer to the FIT format image header
2251 * @noffset: component image node offset
2252 * @entry: pointer to the uint32_t, will hold entry point address
2254 * fit_image_get_entry() finds entry point address property in a given component image node.
2255 * If the property is found, its value is returned to the caller.
2261 int fit_image_get_entry (const void *fit
, int noffset
, ulong
*entry
)
2264 const uint32_t *data
;
2266 data
= fdt_getprop (fit
, noffset
, FIT_ENTRY_PROP
, &len
);
2268 fit_get_debug (fit
, noffset
, FIT_ENTRY_PROP
, len
);
2272 *entry
= uimage_to_cpu (*data
);
2277 * fit_image_get_data - get data property and its size for a given component image node
2278 * @fit: pointer to the FIT format image header
2279 * @noffset: component image node offset
2280 * @data: double pointer to void, will hold data property's data address
2281 * @size: pointer to size_t, will hold data property's data size
2283 * fit_image_get_data() finds data property in a given component image node.
2284 * If the property is found its data start address and size are returned to
2291 int fit_image_get_data (const void *fit
, int noffset
,
2292 const void **data
, size_t *size
)
2296 *data
= fdt_getprop (fit
, noffset
, FIT_DATA_PROP
, &len
);
2297 if (*data
== NULL
) {
2298 fit_get_debug (fit
, noffset
, FIT_DATA_PROP
, len
);
2308 * fit_image_hash_get_algo - get hash algorithm name
2309 * @fit: pointer to the FIT format image header
2310 * @noffset: hash node offset
2311 * @algo: double pointer to char, will hold pointer to the algorithm name
2313 * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
2314 * If the property is found its data start address is returned to the caller.
2320 int fit_image_hash_get_algo (const void *fit
, int noffset
, char **algo
)
2324 *algo
= (char *)fdt_getprop (fit
, noffset
, FIT_ALGO_PROP
, &len
);
2325 if (*algo
== NULL
) {
2326 fit_get_debug (fit
, noffset
, FIT_ALGO_PROP
, len
);
2334 * fit_image_hash_get_value - get hash value and length
2335 * @fit: pointer to the FIT format image header
2336 * @noffset: hash node offset
2337 * @value: double pointer to uint8_t, will hold address of a hash value data
2338 * @value_len: pointer to an int, will hold hash data length
2340 * fit_image_hash_get_value() finds hash value property in a given hash node.
2341 * If the property is found its data start address and size are returned to
2348 int fit_image_hash_get_value (const void *fit
, int noffset
, uint8_t **value
,
2353 *value
= (uint8_t *)fdt_getprop (fit
, noffset
, FIT_VALUE_PROP
, &len
);
2354 if (*value
== NULL
) {
2355 fit_get_debug (fit
, noffset
, FIT_VALUE_PROP
, len
);
2365 * fit_set_timestamp - set node timestamp property
2366 * @fit: pointer to the FIT format image header
2367 * @noffset: node offset
2368 * @timestamp: timestamp value to be set
2370 * fit_set_timestamp() attempts to set timestamp property in the requested
2371 * node and returns operation status to the caller.
2375 * -1, on property read failure
2377 int fit_set_timestamp (void *fit
, int noffset
, time_t timestamp
)
2382 t
= cpu_to_uimage (timestamp
);
2383 ret
= fdt_setprop (fit
, noffset
, FIT_TIMESTAMP_PROP
, &t
,
2386 printf ("Can't set '%s' property for '%s' node (%s)\n",
2387 FIT_TIMESTAMP_PROP
, fit_get_name (fit
, noffset
, NULL
),
2388 fdt_strerror (ret
));
2396 * calculate_hash - calculate and return hash for provided input data
2397 * @data: pointer to the input data
2398 * @data_len: data length
2399 * @algo: requested hash algorithm
2400 * @value: pointer to the char, will hold hash value data (caller must
2401 * allocate enough free space)
2402 * value_len: length of the calculated hash
2404 * calculate_hash() computes input data hash according to the requested algorithm.
2405 * Resulting hash value is placed in caller provided 'value' buffer, length
2406 * of the calculated hash is returned via value_len pointer argument.
2410 * -1, when algo is unsupported
2412 static int calculate_hash (const void *data
, int data_len
, const char *algo
,
2413 uint8_t *value
, int *value_len
)
2415 if (strcmp (algo
, "crc32") == 0 ) {
2416 *((uint32_t *)value
) = crc32_wd (0, data
, data_len
,
2418 *((uint32_t *)value
) = cpu_to_uimage (*((uint32_t *)value
));
2420 } else if (strcmp (algo
, "sha1") == 0 ) {
2421 sha1_csum_wd ((unsigned char *) data
, data_len
,
2422 (unsigned char *) value
, CHUNKSZ_SHA1
);
2424 } else if (strcmp (algo
, "md5") == 0 ) {
2425 md5_wd ((unsigned char *)data
, data_len
, value
, CHUNKSZ_MD5
);
2428 debug ("Unsupported hash alogrithm\n");
2436 * fit_set_hashes - process FIT component image nodes and calculate hashes
2437 * @fit: pointer to the FIT format image header
2439 * fit_set_hashes() adds hash values for all component images in the FIT blob.
2440 * Hashes are calculated for all component images which have hash subnodes
2441 * with algorithm property set to one of the supported hash algorithms.
2445 * libfdt error code, on failure
2447 int fit_set_hashes (void *fit
)
2454 /* Find images parent node offset */
2455 images_noffset
= fdt_path_offset (fit
, FIT_IMAGES_PATH
);
2456 if (images_noffset
< 0) {
2457 printf ("Can't find images parent node '%s' (%s)\n",
2458 FIT_IMAGES_PATH
, fdt_strerror (images_noffset
));
2459 return images_noffset
;
2462 /* Process its subnodes, print out component images details */
2463 for (ndepth
= 0, noffset
= fdt_next_node (fit
, images_noffset
, &ndepth
);
2464 (noffset
>= 0) && (ndepth
> 0);
2465 noffset
= fdt_next_node (fit
, noffset
, &ndepth
)) {
2468 * Direct child node of the images parent node,
2469 * i.e. component image node.
2471 ret
= fit_image_set_hashes (fit
, noffset
);
2481 * fit_image_set_hashes - calculate/set hashes for given component image node
2482 * @fit: pointer to the FIT format image header
2483 * @image_noffset: requested component image node
2485 * fit_image_set_hashes() adds hash values for an component image node. All
2486 * existing hash subnodes are checked, if algorithm property is set to one of
2487 * the supported hash algorithms, hash value is computed and corresponding
2488 * hash node property is set, for example:
2490 * Input component image node structure:
2492 * o image@1 (at image_noffset)
2493 * | - data = [binary data]
2497 * Output component image node structure:
2499 * o image@1 (at image_noffset)
2500 * | - data = [binary data]
2503 * |- value = sha1(data)
2509 int fit_image_set_hashes (void *fit
, int image_noffset
)
2514 uint8_t value
[FIT_MAX_HASH_LEN
];
2519 /* Get image data and data length */
2520 if (fit_image_get_data (fit
, image_noffset
, &data
, &size
)) {
2521 printf ("Can't get image data/size\n");
2525 /* Process all hash subnodes of the component image node */
2526 for (ndepth
= 0, noffset
= fdt_next_node (fit
, image_noffset
, &ndepth
);
2527 (noffset
>= 0) && (ndepth
> 0);
2528 noffset
= fdt_next_node (fit
, noffset
, &ndepth
)) {
2530 /* Direct child node of the component image node */
2533 * Check subnode name, must be equal to "hash".
2534 * Multiple hash nodes require unique unit node
2535 * names, e.g. hash@1, hash@2, etc.
2537 if (strncmp (fit_get_name(fit
, noffset
, NULL
),
2539 strlen(FIT_HASH_NODENAME
)) != 0) {
2540 /* Not a hash subnode, skip it */
2544 if (fit_image_hash_get_algo (fit
, noffset
, &algo
)) {
2545 printf ("Can't get hash algo property for "
2546 "'%s' hash node in '%s' image node\n",
2547 fit_get_name (fit
, noffset
, NULL
),
2548 fit_get_name (fit
, image_noffset
, NULL
));
2552 if (calculate_hash (data
, size
, algo
, value
, &value_len
)) {
2553 printf ("Unsupported hash algorithm (%s) for "
2554 "'%s' hash node in '%s' image node\n",
2555 algo
, fit_get_name (fit
, noffset
, NULL
),
2556 fit_get_name (fit
, image_noffset
, NULL
));
2560 if (fit_image_hash_set_value (fit
, noffset
, value
,
2562 printf ("Can't set hash value for "
2563 "'%s' hash node in '%s' image node\n",
2564 fit_get_name (fit
, noffset
, NULL
),
2565 fit_get_name (fit
, image_noffset
, NULL
));
2575 * fit_image_hash_set_value - set hash value in requested has node
2576 * @fit: pointer to the FIT format image header
2577 * @noffset: hash node offset
2578 * @value: hash value to be set
2579 * @value_len: hash value length
2581 * fit_image_hash_set_value() attempts to set hash value in a node at offset
2582 * given and returns operation status to the caller.
2588 int fit_image_hash_set_value (void *fit
, int noffset
, uint8_t *value
,
2593 ret
= fdt_setprop (fit
, noffset
, FIT_VALUE_PROP
, value
, value_len
);
2595 printf ("Can't set hash '%s' property for '%s' node (%s)\n",
2596 FIT_VALUE_PROP
, fit_get_name (fit
, noffset
, NULL
),
2597 fdt_strerror (ret
));
2603 #endif /* USE_HOSTCC */
2606 * fit_image_check_hashes - verify data intergity
2607 * @fit: pointer to the FIT format image header
2608 * @image_noffset: component image node offset
2610 * fit_image_check_hashes() goes over component image hash nodes,
2611 * re-calculates each data hash and compares with the value stored in hash
2615 * 1, if all hashes are valid
2616 * 0, otherwise (or on error)
2618 int fit_image_check_hashes (const void *fit
, int image_noffset
)
2625 uint8_t value
[FIT_MAX_HASH_LEN
];
2631 /* Get image data and data length */
2632 if (fit_image_get_data (fit
, image_noffset
, &data
, &size
)) {
2633 printf ("Can't get image data/size\n");
2637 /* Process all hash subnodes of the component image node */
2638 for (ndepth
= 0, noffset
= fdt_next_node (fit
, image_noffset
, &ndepth
);
2639 (noffset
>= 0) && (ndepth
> 0);
2640 noffset
= fdt_next_node (fit
, noffset
, &ndepth
)) {
2642 /* Direct child node of the component image node */
2645 * Check subnode name, must be equal to "hash".
2646 * Multiple hash nodes require unique unit node
2647 * names, e.g. hash@1, hash@2, etc.
2649 if (strncmp (fit_get_name(fit
, noffset
, NULL
),
2651 strlen(FIT_HASH_NODENAME
)) != 0)
2654 if (fit_image_hash_get_algo (fit
, noffset
, &algo
)) {
2655 err_msg
= " error!\nCan't get hash algo "
2659 printf ("%s", algo
);
2661 if (fit_image_hash_get_value (fit
, noffset
, &fit_value
,
2663 err_msg
= " error!\nCan't get hash value "
2668 if (calculate_hash (data
, size
, algo
, value
, &value_len
)) {
2669 err_msg
= " error!\nUnsupported hash algorithm";
2673 if (value_len
!= fit_value_len
) {
2674 err_msg
= " error !\nBad hash value len";
2676 } else if (memcmp (value
, fit_value
, value_len
) != 0) {
2677 err_msg
= " error!\nBad hash value";
2687 printf ("%s for '%s' hash node in '%s' image node\n",
2688 err_msg
, fit_get_name (fit
, noffset
, NULL
),
2689 fit_get_name (fit
, image_noffset
, NULL
));
2694 * fit_all_image_check_hashes - verify data intergity for all images
2695 * @fit: pointer to the FIT format image header
2697 * fit_all_image_check_hashes() goes over all images in the FIT and
2698 * for every images checks if all it's hashes are valid.
2701 * 1, if all hashes of all images are valid
2702 * 0, otherwise (or on error)
2704 int fit_all_image_check_hashes (const void *fit
)
2711 /* Find images parent node offset */
2712 images_noffset
= fdt_path_offset (fit
, FIT_IMAGES_PATH
);
2713 if (images_noffset
< 0) {
2714 printf ("Can't find images parent node '%s' (%s)\n",
2715 FIT_IMAGES_PATH
, fdt_strerror (images_noffset
));
2719 /* Process all image subnodes, check hashes for each */
2720 printf ("## Checking hash(es) for FIT Image at %08lx ...\n",
2722 for (ndepth
= 0, count
= 0,
2723 noffset
= fdt_next_node (fit
, images_noffset
, &ndepth
);
2724 (noffset
>= 0) && (ndepth
> 0);
2725 noffset
= fdt_next_node (fit
, noffset
, &ndepth
)) {
2728 * Direct child node of the images parent node,
2729 * i.e. component image node.
2731 printf (" Hash(es) for Image %u (%s): ", count
++,
2732 fit_get_name (fit
, noffset
, NULL
));
2734 if (!fit_image_check_hashes (fit
, noffset
))
2743 * fit_image_check_os - check whether image node is of a given os type
2744 * @fit: pointer to the FIT format image header
2745 * @noffset: component image node offset
2746 * @os: requested image os
2748 * fit_image_check_os() reads image os property and compares its numeric
2749 * id with the requested os. Comparison result is returned to the caller.
2752 * 1 if image is of given os type
2753 * 0 otherwise (or on error)
2755 int fit_image_check_os (const void *fit
, int noffset
, uint8_t os
)
2759 if (fit_image_get_os (fit
, noffset
, &image_os
))
2761 return (os
== image_os
);
2765 * fit_image_check_arch - check whether image node is of a given arch
2766 * @fit: pointer to the FIT format image header
2767 * @noffset: component image node offset
2768 * @arch: requested imagearch
2770 * fit_image_check_arch() reads image arch property and compares its numeric
2771 * id with the requested arch. Comparison result is returned to the caller.
2774 * 1 if image is of given arch
2775 * 0 otherwise (or on error)
2777 int fit_image_check_arch (const void *fit
, int noffset
, uint8_t arch
)
2781 if (fit_image_get_arch (fit
, noffset
, &image_arch
))
2783 return (arch
== image_arch
);
2787 * fit_image_check_type - check whether image node is of a given type
2788 * @fit: pointer to the FIT format image header
2789 * @noffset: component image node offset
2790 * @type: requested image type
2792 * fit_image_check_type() reads image type property and compares its numeric
2793 * id with the requested type. Comparison result is returned to the caller.
2796 * 1 if image is of given type
2797 * 0 otherwise (or on error)
2799 int fit_image_check_type (const void *fit
, int noffset
, uint8_t type
)
2803 if (fit_image_get_type (fit
, noffset
, &image_type
))
2805 return (type
== image_type
);
2809 * fit_image_check_comp - check whether image node uses given compression
2810 * @fit: pointer to the FIT format image header
2811 * @noffset: component image node offset
2812 * @comp: requested image compression type
2814 * fit_image_check_comp() reads image compression property and compares its
2815 * numeric id with the requested compression type. Comparison result is
2816 * returned to the caller.
2819 * 1 if image uses requested compression
2820 * 0 otherwise (or on error)
2822 int fit_image_check_comp (const void *fit
, int noffset
, uint8_t comp
)
2826 if (fit_image_get_comp (fit
, noffset
, &image_comp
))
2828 return (comp
== image_comp
);
2832 * fit_check_format - sanity check FIT image format
2833 * @fit: pointer to the FIT format image header
2835 * fit_check_format() runs a basic sanity FIT image verification.
2836 * Routine checks for mandatory properties, nodes, etc.
2842 int fit_check_format (const void *fit
)
2844 /* mandatory / node 'description' property */
2845 if (fdt_getprop (fit
, 0, FIT_DESC_PROP
, NULL
) == NULL
) {
2846 debug ("Wrong FIT format: no description\n");
2850 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
2851 /* mandatory / node 'timestamp' property */
2852 if (fdt_getprop (fit
, 0, FIT_TIMESTAMP_PROP
, NULL
) == NULL
) {
2853 debug ("Wrong FIT format: no timestamp\n");
2858 /* mandatory subimages parent '/images' node */
2859 if (fdt_path_offset (fit
, FIT_IMAGES_PATH
) < 0) {
2860 debug ("Wrong FIT format: no images parent node\n");
2868 * fit_conf_get_node - get node offset for configuration of a given unit name
2869 * @fit: pointer to the FIT format image header
2870 * @conf_uname: configuration node unit name
2872 * fit_conf_get_node() finds a configuration (withing the '/configurations'
2873 * parant node) of a provided unit name. If configuration is found its node offset
2874 * is returned to the caller.
2876 * When NULL is provided in second argument fit_conf_get_node() will search
2877 * for a default configuration node instead. Default configuration node unit name
2878 * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
2881 * configuration node offset when found (>=0)
2882 * negative number on failure (FDT_ERR_* code)
2884 int fit_conf_get_node (const void *fit
, const char *conf_uname
)
2886 int noffset
, confs_noffset
;
2889 confs_noffset
= fdt_path_offset (fit
, FIT_CONFS_PATH
);
2890 if (confs_noffset
< 0) {
2891 debug ("Can't find configurations parent node '%s' (%s)\n",
2892 FIT_CONFS_PATH
, fdt_strerror (confs_noffset
));
2893 return confs_noffset
;
2896 if (conf_uname
== NULL
) {
2897 /* get configuration unit name from the default property */
2898 debug ("No configuration specified, trying default...\n");
2899 conf_uname
= (char *)fdt_getprop (fit
, confs_noffset
, FIT_DEFAULT_PROP
, &len
);
2900 if (conf_uname
== NULL
) {
2901 fit_get_debug (fit
, confs_noffset
, FIT_DEFAULT_PROP
, len
);
2904 debug ("Found default configuration: '%s'\n", conf_uname
);
2907 noffset
= fdt_subnode_offset (fit
, confs_noffset
, conf_uname
);
2909 debug ("Can't get node offset for configuration unit name: '%s' (%s)\n",
2910 conf_uname
, fdt_strerror (noffset
));
2916 static int __fit_conf_get_prop_node (const void *fit
, int noffset
,
2917 const char *prop_name
)
2922 /* get kernel image unit name from configuration kernel property */
2923 uname
= (char *)fdt_getprop (fit
, noffset
, prop_name
, &len
);
2927 return fit_image_get_node (fit
, uname
);
2931 * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
2932 * a given configuration
2933 * @fit: pointer to the FIT format image header
2934 * @noffset: configuration node offset
2936 * fit_conf_get_kernel_node() retrives kernel image node unit name from
2937 * configuration FIT_KERNEL_PROP property and translates it to the node
2941 * image node offset when found (>=0)
2942 * negative number on failure (FDT_ERR_* code)
2944 int fit_conf_get_kernel_node (const void *fit
, int noffset
)
2946 return __fit_conf_get_prop_node (fit
, noffset
, FIT_KERNEL_PROP
);
2950 * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
2951 * a given configuration
2952 * @fit: pointer to the FIT format image header
2953 * @noffset: configuration node offset
2955 * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
2956 * configuration FIT_KERNEL_PROP property and translates it to the node
2960 * image node offset when found (>=0)
2961 * negative number on failure (FDT_ERR_* code)
2963 int fit_conf_get_ramdisk_node (const void *fit
, int noffset
)
2965 return __fit_conf_get_prop_node (fit
, noffset
, FIT_RAMDISK_PROP
);
2969 * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
2970 * a given configuration
2971 * @fit: pointer to the FIT format image header
2972 * @noffset: configuration node offset
2974 * fit_conf_get_fdt_node() retrives fdt image node unit name from
2975 * configuration FIT_KERNEL_PROP property and translates it to the node
2979 * image node offset when found (>=0)
2980 * negative number on failure (FDT_ERR_* code)
2982 int fit_conf_get_fdt_node (const void *fit
, int noffset
)
2984 return __fit_conf_get_prop_node (fit
, noffset
, FIT_FDT_PROP
);
2988 * fit_conf_print - prints out the FIT configuration details
2989 * @fit: pointer to the FIT format image header
2990 * @noffset: offset of the configuration node
2991 * @p: pointer to prefix string
2993 * fit_conf_print() lists all mandatory properies for the processed
2994 * configuration node.
2997 * no returned results
2999 void fit_conf_print (const void *fit
, int noffset
, const char *p
)
3005 /* Mandatory properties */
3006 ret
= fit_get_desc (fit
, noffset
, &desc
);
3007 printf ("%s Description: ", p
);
3009 printf ("unavailable\n");
3011 printf ("%s\n", desc
);
3013 uname
= (char *)fdt_getprop (fit
, noffset
, FIT_KERNEL_PROP
, NULL
);
3014 printf ("%s Kernel: ", p
);
3016 printf ("unavailable\n");
3018 printf ("%s\n", uname
);
3020 /* Optional properties */
3021 uname
= (char *)fdt_getprop (fit
, noffset
, FIT_RAMDISK_PROP
, NULL
);
3023 printf ("%s Init Ramdisk: %s\n", p
, uname
);
3025 uname
= (char *)fdt_getprop (fit
, noffset
, FIT_FDT_PROP
, NULL
);
3027 printf ("%s FDT: %s\n", p
, uname
);
3031 * fit_check_ramdisk - verify FIT format ramdisk subimage
3032 * @fit_hdr: pointer to the FIT ramdisk header
3033 * @rd_noffset: ramdisk subimage node offset within FIT image
3034 * @arch: requested ramdisk image architecture type
3035 * @verify: data CRC verification flag
3037 * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
3038 * specified FIT image.
3045 static int fit_check_ramdisk (const void *fit
, int rd_noffset
, uint8_t arch
, int verify
)
3047 fit_image_print (fit
, rd_noffset
, " ");
3050 puts (" Verifying Hash Integrity ... ");
3051 if (!fit_image_check_hashes (fit
, rd_noffset
)) {
3052 puts ("Bad Data Hash\n");
3053 show_boot_progress (-125);
3059 show_boot_progress (126);
3060 if (!fit_image_check_os (fit
, rd_noffset
, IH_OS_LINUX
) ||
3061 !fit_image_check_arch (fit
, rd_noffset
, arch
) ||
3062 !fit_image_check_type (fit
, rd_noffset
, IH_TYPE_RAMDISK
)) {
3063 printf ("No Linux %s Ramdisk Image\n",
3064 genimg_get_arch_name(arch
));
3065 show_boot_progress (-126);
3069 show_boot_progress (127);
3072 #endif /* USE_HOSTCC */
3073 #endif /* CONFIG_FIT */