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,
31 #ifdef CONFIG_SHOW_BOOT_PROGRESS
32 #include <status_led.h>
35 #ifdef CONFIG_HAS_DATAFLASH
36 #include <dataflash.h>
39 #ifdef CONFIG_LOGBUFFER
43 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
49 #if defined(CONFIG_FIT) || defined (CONFIG_OF_LIBFDT)
52 #include <fdt_support.h>
55 #if defined(CONFIG_FIT)
56 #include <u-boot/md5.h>
59 static int fit_check_ramdisk (const void *fit
, int os_noffset
,
60 uint8_t arch
, int verify
);
64 extern int do_bdinfo(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
67 DECLARE_GLOBAL_DATA_PTR
;
69 static image_header_t
* image_get_ramdisk (ulong rd_addr
, uint8_t arch
,
73 #include <u-boot/md5.h>
76 #endif /* !USE_HOSTCC*/
78 typedef struct table_entry
{
79 int id
; /* as defined in image.h */
80 char *sname
; /* short (input) name */
81 char *lname
; /* long (output) name */
84 static table_entry_t uimage_arch
[] = {
85 { IH_ARCH_INVALID
, NULL
, "Invalid ARCH", },
86 { IH_ARCH_ALPHA
, "alpha", "Alpha", },
87 { IH_ARCH_ARM
, "arm", "ARM", },
88 { IH_ARCH_I386
, "x86", "Intel x86", },
89 { IH_ARCH_IA64
, "ia64", "IA64", },
90 { IH_ARCH_M68K
, "m68k", "M68K", },
91 { IH_ARCH_MICROBLAZE
, "microblaze", "MicroBlaze", },
92 { IH_ARCH_MIPS
, "mips", "MIPS", },
93 { IH_ARCH_MIPS64
, "mips64", "MIPS 64 Bit", },
94 { IH_ARCH_NIOS
, "nios", "NIOS", },
95 { IH_ARCH_NIOS2
, "nios2", "NIOS II", },
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 #if defined(CONFIG_ARTOS) || defined(USE_HOSTCC)
109 { IH_OS_ARTOS
, "artos", "ARTOS", },
111 { IH_OS_LINUX
, "linux", "Linux", },
112 #if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC)
113 { IH_OS_LYNXOS
, "lynxos", "LynxOS", },
115 { IH_OS_NETBSD
, "netbsd", "NetBSD", },
116 { IH_OS_RTEMS
, "rtems", "RTEMS", },
117 { IH_OS_U_BOOT
, "u-boot", "U-Boot", },
118 #if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC)
119 { IH_OS_QNX
, "qnx", "QNX", },
120 { IH_OS_VXWORKS
, "vxworks", "VxWorks", },
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", },
158 uint32_t crc32 (uint32_t, const unsigned char *, uint
);
159 uint32_t crc32_wd (uint32_t, const unsigned char *, uint
, uint
);
160 static void genimg_print_size (uint32_t size
);
161 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
162 static void genimg_print_time (time_t timestamp
);
165 /*****************************************************************************/
166 /* Legacy format routines */
167 /*****************************************************************************/
168 int image_check_hcrc (image_header_t
*hdr
)
171 ulong len
= image_get_header_size ();
172 image_header_t header
;
174 /* Copy header so we can blank CRC field for re-calculation */
175 memmove (&header
, (char *)hdr
, image_get_header_size ());
176 image_set_hcrc (&header
, 0);
178 hcrc
= crc32 (0, (unsigned char *)&header
, len
);
180 return (hcrc
== image_get_hcrc (hdr
));
183 int image_check_dcrc (image_header_t
*hdr
)
185 ulong data
= image_get_data (hdr
);
186 ulong len
= image_get_data_size (hdr
);
187 ulong dcrc
= crc32_wd (0, (unsigned char *)data
, len
, CHUNKSZ_CRC32
);
189 return (dcrc
== image_get_dcrc (hdr
));
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
, tail
, 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
]);
262 /* go over all indices preceding requested component idx */
263 for (i
= 0; i
< idx
; i
++) {
264 /* add up i-th component size */
265 offset
+= uimage_to_cpu (size
[i
]);
267 /* add up alignment for i-th component */
268 tail
+= (4 - uimage_to_cpu (size
[i
]) % 4);
271 /* calculate idx-th component data address */
272 *data
= img_data
+ offset
+ tail
;
279 static void image_print_type (image_header_t
*hdr
)
281 const char *os
, *arch
, *type
, *comp
;
283 os
= genimg_get_os_name (image_get_os (hdr
));
284 arch
= genimg_get_arch_name (image_get_arch (hdr
));
285 type
= genimg_get_type_name (image_get_type (hdr
));
286 comp
= genimg_get_comp_name (image_get_comp (hdr
));
288 printf ("%s %s %s (%s)\n", arch
, os
, type
, comp
);
292 * image_print_contents - prints out the contents of the legacy format image
293 * @hdr: pointer to the legacy format image header
294 * @p: pointer to prefix string
296 * image_print_contents() formats a multi line legacy image contents description.
297 * The routine prints out all header fields followed by the size/offset data
298 * for MULTI/SCRIPT images.
301 * no returned results
303 void image_print_contents (image_header_t
*hdr
)
313 printf ("%sImage Name: %.*s\n", p
, IH_NMLEN
, image_get_name (hdr
));
314 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
315 printf ("%sCreated: ", p
);
316 genimg_print_time ((time_t)image_get_time (hdr
));
318 printf ("%sImage Type: ", p
);
319 image_print_type (hdr
);
320 printf ("%sData Size: ", p
);
321 genimg_print_size (image_get_data_size (hdr
));
322 printf ("%sLoad Address: %08x\n", p
, image_get_load (hdr
));
323 printf ("%sEntry Point: %08x\n", p
, image_get_ep (hdr
));
325 if (image_check_type (hdr
, IH_TYPE_MULTI
) ||
326 image_check_type (hdr
, IH_TYPE_SCRIPT
)) {
329 ulong count
= image_multi_count (hdr
);
331 printf ("%sContents:\n", p
);
332 for (i
= 0; i
< count
; i
++) {
333 image_multi_getimg (hdr
, i
, &data
, &len
);
335 printf ("%s Image %d: ", p
, i
);
336 genimg_print_size (len
);
338 if (image_check_type (hdr
, IH_TYPE_SCRIPT
) && i
> 0) {
340 * the user may need to know offsets
341 * if planning to do something with
344 printf ("%s Offset = 0x%08lx\n", p
, data
);
353 * image_get_ramdisk - get and verify ramdisk image
354 * @rd_addr: ramdisk image start address
355 * @arch: expected ramdisk architecture
356 * @verify: checksum verification flag
358 * image_get_ramdisk() returns a pointer to the verified ramdisk image
359 * header. Routine receives image start address and expected architecture
360 * flag. Verification done covers data and header integrity and os/type/arch
363 * If dataflash support is enabled routine checks for dataflash addresses
364 * and handles required dataflash reads.
367 * pointer to a ramdisk image header, if image was found and valid
368 * otherwise, return NULL
370 static image_header_t
* image_get_ramdisk (ulong rd_addr
, uint8_t arch
,
373 image_header_t
*rd_hdr
= (image_header_t
*)rd_addr
;
375 if (!image_check_magic (rd_hdr
)) {
376 puts ("Bad Magic Number\n");
377 show_boot_progress (-10);
381 if (!image_check_hcrc (rd_hdr
)) {
382 puts ("Bad Header Checksum\n");
383 show_boot_progress (-11);
387 show_boot_progress (10);
388 image_print_contents (rd_hdr
);
391 puts(" Verifying Checksum ... ");
392 if (!image_check_dcrc (rd_hdr
)) {
393 puts ("Bad Data CRC\n");
394 show_boot_progress (-12);
400 show_boot_progress (11);
402 if (!image_check_os (rd_hdr
, IH_OS_LINUX
) ||
403 !image_check_arch (rd_hdr
, arch
) ||
404 !image_check_type (rd_hdr
, IH_TYPE_RAMDISK
)) {
405 printf ("No Linux %s Ramdisk Image\n",
406 genimg_get_arch_name(arch
));
407 show_boot_progress (-13);
413 #endif /* !USE_HOSTCC */
415 /*****************************************************************************/
416 /* Shared dual-format routines */
417 /*****************************************************************************/
419 int getenv_yesno (char *var
)
421 char *s
= getenv (var
);
422 return (s
&& (*s
== 'n')) ? 0 : 1;
425 ulong
getenv_bootm_low(void)
427 char *s
= getenv ("bootm_low");
429 ulong tmp
= simple_strtoul (s
, NULL
, 16);
433 #if defined(CFG_SDRAM_BASE)
434 return CFG_SDRAM_BASE
;
435 #elif defined(CONFIG_ARM)
436 return gd
->bd
->bi_dram
[0].start
;
442 ulong
getenv_bootm_size(void)
444 char *s
= getenv ("bootm_size");
446 ulong tmp
= simple_strtoul (s
, NULL
, 16);
450 #if defined(CONFIG_ARM)
451 return gd
->bd
->bi_dram
[0].size
;
453 return gd
->bd
->bi_memsize
;
457 void memmove_wd (void *to
, void *from
, size_t len
, ulong chunksz
)
459 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
461 size_t tail
= (len
> chunksz
) ? chunksz
: len
;
463 memmove (to
, from
, tail
);
468 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
469 memmove (to
, from
, len
);
470 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
472 #endif /* !USE_HOSTCC */
474 static void genimg_print_size (uint32_t size
)
477 printf ("%d Bytes = ", size
);
478 print_size (size
, "\n");
480 printf ("%d Bytes = %.2f kB = %.2f MB\n",
481 size
, (double)size
/ 1.024e3
,
482 (double)size
/ 1.048576e6
);
486 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
487 static void genimg_print_time (time_t timestamp
)
492 to_tm (timestamp
, &tm
);
493 printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
494 tm
.tm_year
, tm
.tm_mon
, tm
.tm_mday
,
495 tm
.tm_hour
, tm
.tm_min
, tm
.tm_sec
);
497 printf ("%s", ctime(×tamp
));
500 #endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */
503 * get_table_entry_name - translate entry id to long name
504 * @table: pointer to a translation table for entries of a specific type
505 * @msg: message to be returned when translation fails
506 * @id: entry id to be translated
508 * get_table_entry_name() will go over translation table trying to find
509 * entry that matches given id. If matching entry is found, its long
510 * name is returned to the caller.
513 * long entry name if translation succeeds
516 static char *get_table_entry_name (table_entry_t
*table
, char *msg
, int id
)
518 for (; table
->id
>= 0; ++table
) {
520 return (table
->lname
);
525 const char *genimg_get_os_name (uint8_t os
)
527 return (get_table_entry_name (uimage_os
, "Unknown OS", os
));
530 const char *genimg_get_arch_name (uint8_t arch
)
532 return (get_table_entry_name (uimage_arch
, "Unknown Architecture", arch
));
535 const char *genimg_get_type_name (uint8_t type
)
537 return (get_table_entry_name (uimage_type
, "Unknown Image", type
));
540 const char *genimg_get_comp_name (uint8_t comp
)
542 return (get_table_entry_name (uimage_comp
, "Unknown Compression", comp
));
546 * get_table_entry_id - translate short entry name to id
547 * @table: pointer to a translation table for entries of a specific type
548 * @table_name: to be used in case of error
549 * @name: entry short name to be translated
551 * get_table_entry_id() will go over translation table trying to find
552 * entry that matches given short name. If matching entry is found,
553 * its id returned to the caller.
556 * entry id if translation succeeds
559 static int get_table_entry_id (table_entry_t
*table
,
560 const char *table_name
, const char *name
)
566 for (t
= table
; t
->id
>= 0; ++t
) {
567 if (t
->sname
&& strcasecmp(t
->sname
, name
) == 0)
571 fprintf (stderr
, "\nInvalid %s Type - valid names are", table_name
);
572 for (t
= table
; t
->id
>= 0; ++t
) {
573 if (t
->sname
== NULL
)
575 fprintf (stderr
, "%c %s", (first
) ? ':' : ',', t
->sname
);
578 fprintf (stderr
, "\n");
580 for (t
= table
; t
->id
>= 0; ++t
) {
581 if (t
->sname
&& strcmp(t
->sname
, name
) == 0)
584 debug ("Invalid %s Type: %s\n", table_name
, name
);
585 #endif /* USE_HOSTCC */
589 int genimg_get_os_id (const char *name
)
591 return (get_table_entry_id (uimage_os
, "OS", name
));
594 int genimg_get_arch_id (const char *name
)
596 return (get_table_entry_id (uimage_arch
, "CPU", name
));
599 int genimg_get_type_id (const char *name
)
601 return (get_table_entry_id (uimage_type
, "Image", name
));
604 int genimg_get_comp_id (const char *name
)
606 return (get_table_entry_id (uimage_comp
, "Compression", name
));
611 * genimg_get_format - get image format type
612 * @img_addr: image start address
614 * genimg_get_format() checks whether provided address points to a valid
615 * legacy or FIT image.
617 * New uImage format and FDT blob are based on a libfdt. FDT blob
618 * may be passed directly or embedded in a FIT image. In both situations
619 * genimg_get_format() must be able to dectect libfdt header.
622 * image format type or IMAGE_FORMAT_INVALID if no image is present
624 int genimg_get_format (void *img_addr
)
626 ulong format
= IMAGE_FORMAT_INVALID
;
628 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
632 hdr
= (image_header_t
*)img_addr
;
633 if (image_check_magic(hdr
))
634 format
= IMAGE_FORMAT_LEGACY
;
635 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
637 fit_hdr
= (char *)img_addr
;
638 if (fdt_check_header (fit_hdr
) == 0)
639 format
= IMAGE_FORMAT_FIT
;
647 * genimg_get_image - get image from special storage (if necessary)
648 * @img_addr: image start address
650 * genimg_get_image() checks if provided image start adddress is located
651 * in a dataflash storage. If so, image is moved to a system RAM memory.
654 * image start address after possible relocation from special storage
656 ulong
genimg_get_image (ulong img_addr
)
658 ulong ram_addr
= img_addr
;
660 #ifdef CONFIG_HAS_DATAFLASH
661 ulong h_size
, d_size
;
663 if (addr_dataflash (img_addr
)){
664 /* ger RAM address */
665 ram_addr
= CFG_LOAD_ADDR
;
667 /* get header size */
668 h_size
= image_get_header_size ();
669 #if defined(CONFIG_FIT)
670 if (sizeof(struct fdt_header
) > h_size
)
671 h_size
= sizeof(struct fdt_header
);
675 debug (" Reading image header from dataflash address "
676 "%08lx to RAM address %08lx\n", img_addr
, ram_addr
);
678 read_dataflash (img_addr
, h_size
, (char *)ram_addr
);
681 switch (genimg_get_format ((void *)ram_addr
)) {
682 case IMAGE_FORMAT_LEGACY
:
683 d_size
= image_get_data_size ((image_header_t
*)ram_addr
);
684 debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n",
687 #if defined(CONFIG_FIT)
688 case IMAGE_FORMAT_FIT
:
689 d_size
= fit_get_size ((const void *)ram_addr
) - h_size
;
690 debug (" FIT/FDT format image found at 0x%08lx, size 0x%08lx\n",
695 printf (" No valid image found at 0x%08lx\n", img_addr
);
699 /* read in image data */
700 debug (" Reading image remaining data from dataflash address "
701 "%08lx to RAM address %08lx\n", img_addr
+ h_size
,
704 read_dataflash (img_addr
+ h_size
, d_size
,
705 (char *)(ram_addr
+ h_size
));
708 #endif /* CONFIG_HAS_DATAFLASH */
714 * fit_has_config - check if there is a valid FIT configuration
715 * @images: pointer to the bootm command headers structure
717 * fit_has_config() checks if there is a FIT configuration in use
718 * (if FTI support is present).
721 * 0, no FIT support or no configuration found
722 * 1, configuration found
724 int genimg_has_config (bootm_headers_t
*images
)
726 #if defined(CONFIG_FIT)
727 if (images
->fit_uname_cfg
)
734 * boot_get_ramdisk - main ramdisk handling routine
735 * @argc: command argument count
736 * @argv: command argument list
737 * @images: pointer to the bootm images structure
738 * @arch: expected ramdisk architecture
739 * @rd_start: pointer to a ulong variable, will hold ramdisk start address
740 * @rd_end: pointer to a ulong variable, will hold ramdisk end
742 * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
743 * Curently supported are the following ramdisk sources:
744 * - multicomponent kernel/ramdisk image,
745 * - commandline provided address of decicated ramdisk image.
748 * 0, if ramdisk image was found and valid, or skiped
749 * rd_start and rd_end are set to ramdisk start/end addresses if
750 * ramdisk image is found and valid
752 * 1, if ramdisk image is found but corrupted
753 * rd_start and rd_end are set to 0 if no ramdisk exists
755 int boot_get_ramdisk (int argc
, char *argv
[], bootm_headers_t
*images
,
756 uint8_t arch
, ulong
*rd_start
, ulong
*rd_end
)
758 ulong rd_addr
, rd_load
;
759 ulong rd_data
, rd_len
;
760 image_header_t
*rd_hdr
;
761 #if defined(CONFIG_FIT)
763 const char *fit_uname_config
= NULL
;
764 const char *fit_uname_ramdisk
= NULL
;
776 * Look for a '-' which indicates to ignore the
779 if ((argc
>= 3) && (strcmp(argv
[2], "-") == 0)) {
780 debug ("## Skipping init Ramdisk\n");
781 rd_len
= rd_data
= 0;
782 } else if (argc
>= 3 || genimg_has_config (images
)) {
783 #if defined(CONFIG_FIT)
786 * If the init ramdisk comes from the FIT image and
787 * the FIT image address is omitted in the command
788 * line argument, try to use os FIT image address or
789 * default load address.
791 if (images
->fit_uname_os
)
792 default_addr
= (ulong
)images
->fit_hdr_os
;
794 default_addr
= load_addr
;
796 if (fit_parse_conf (argv
[2], default_addr
,
797 &rd_addr
, &fit_uname_config
)) {
798 debug ("* ramdisk: config '%s' from image at 0x%08lx\n",
799 fit_uname_config
, rd_addr
);
800 } else if (fit_parse_subimage (argv
[2], default_addr
,
801 &rd_addr
, &fit_uname_ramdisk
)) {
802 debug ("* ramdisk: subimage '%s' from image at 0x%08lx\n",
803 fit_uname_ramdisk
, rd_addr
);
807 rd_addr
= simple_strtoul(argv
[2], NULL
, 16);
808 debug ("* ramdisk: cmdline image address = 0x%08lx\n",
811 #if defined(CONFIG_FIT)
813 /* use FIT configuration provided in first bootm
816 rd_addr
= (ulong
)images
->fit_hdr_os
;
817 fit_uname_config
= images
->fit_uname_cfg
;
818 debug ("* ramdisk: using config '%s' from image at 0x%08lx\n",
819 fit_uname_config
, rd_addr
);
822 * Check whether configuration has ramdisk defined,
823 * if not, don't try to use it, quit silently.
825 fit_hdr
= (void *)rd_addr
;
826 cfg_noffset
= fit_conf_get_node (fit_hdr
, fit_uname_config
);
827 if (cfg_noffset
< 0) {
828 debug ("* ramdisk: no such config\n");
832 rd_noffset
= fit_conf_get_ramdisk_node (fit_hdr
, cfg_noffset
);
833 if (rd_noffset
< 0) {
834 debug ("* ramdisk: no ramdisk in config\n");
840 /* copy from dataflash if needed */
841 rd_addr
= genimg_get_image (rd_addr
);
844 * Check if there is an initrd image at the
845 * address provided in the second bootm argument
846 * check image type, for FIT images get FIT node.
848 switch (genimg_get_format ((void *)rd_addr
)) {
849 case IMAGE_FORMAT_LEGACY
:
850 printf ("## Loading init Ramdisk from Legacy "
851 "Image at %08lx ...\n", rd_addr
);
853 show_boot_progress (9);
854 rd_hdr
= image_get_ramdisk (rd_addr
, arch
,
860 rd_data
= image_get_data (rd_hdr
);
861 rd_len
= image_get_data_size (rd_hdr
);
862 rd_load
= image_get_load (rd_hdr
);
864 #if defined(CONFIG_FIT)
865 case IMAGE_FORMAT_FIT
:
866 fit_hdr
= (void *)rd_addr
;
867 printf ("## Loading init Ramdisk from FIT "
868 "Image at %08lx ...\n", rd_addr
);
870 show_boot_progress (120);
871 if (!fit_check_format (fit_hdr
)) {
872 puts ("Bad FIT ramdisk image format!\n");
873 show_boot_progress (-120);
876 show_boot_progress (121);
878 if (!fit_uname_ramdisk
) {
880 * no ramdisk image node unit name, try to get config
881 * node first. If config unit node name is NULL
882 * fit_conf_get_node() will try to find default config node
884 show_boot_progress (122);
885 cfg_noffset
= fit_conf_get_node (fit_hdr
, fit_uname_config
);
886 if (cfg_noffset
< 0) {
887 puts ("Could not find configuration node\n");
888 show_boot_progress (-122);
891 fit_uname_config
= fdt_get_name (fit_hdr
, cfg_noffset
, NULL
);
892 printf (" Using '%s' configuration\n", fit_uname_config
);
894 rd_noffset
= fit_conf_get_ramdisk_node (fit_hdr
, cfg_noffset
);
895 fit_uname_ramdisk
= fit_get_name (fit_hdr
, rd_noffset
, NULL
);
897 /* get ramdisk component image node offset */
898 show_boot_progress (123);
899 rd_noffset
= fit_image_get_node (fit_hdr
, fit_uname_ramdisk
);
901 if (rd_noffset
< 0) {
902 puts ("Could not find subimage node\n");
903 show_boot_progress (-124);
907 printf (" Trying '%s' ramdisk subimage\n", fit_uname_ramdisk
);
909 show_boot_progress (125);
910 if (!fit_check_ramdisk (fit_hdr
, rd_noffset
, arch
, images
->verify
))
913 /* get ramdisk image data address and length */
914 if (fit_image_get_data (fit_hdr
, rd_noffset
, &data
, &size
)) {
915 puts ("Could not find ramdisk subimage data!\n");
916 show_boot_progress (-127);
919 show_boot_progress (128);
921 rd_data
= (ulong
)data
;
924 if (fit_image_get_load (fit_hdr
, rd_noffset
, &rd_load
)) {
925 puts ("Can't get ramdisk subimage load address!\n");
926 show_boot_progress (-129);
929 show_boot_progress (129);
931 images
->fit_hdr_rd
= fit_hdr
;
932 images
->fit_uname_rd
= fit_uname_ramdisk
;
933 images
->fit_noffset_rd
= rd_noffset
;
937 puts ("Wrong Ramdisk Image Format\n");
938 rd_data
= rd_len
= rd_load
= 0;
941 #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO)
943 * We need to copy the ramdisk to SRAM to let Linux boot
946 memmove ((void *)rd_load
, (uchar
*)rd_data
, rd_len
);
949 #endif /* CONFIG_B2 || CONFIG_EVB4510 || CONFIG_ARMADILLO */
951 } else if (images
->legacy_hdr_valid
&&
952 image_check_type (&images
->legacy_hdr_os_copy
, IH_TYPE_MULTI
)) {
954 * Now check if we have a legacy mult-component image,
955 * get second entry data start address and len.
957 show_boot_progress (13);
958 printf ("## Loading init Ramdisk from multi component "
959 "Legacy Image at %08lx ...\n",
960 (ulong
)images
->legacy_hdr_os
);
962 image_multi_getimg (images
->legacy_hdr_os
, 1, &rd_data
, &rd_len
);
967 show_boot_progress (14);
968 rd_len
= rd_data
= 0;
972 debug ("## No init Ramdisk\n");
975 *rd_end
= rd_data
+ rd_len
;
977 debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
983 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
985 * boot_ramdisk_high - relocate init ramdisk
986 * @lmb: pointer to lmb handle, will be used for memory mgmt
987 * @rd_data: ramdisk data start address
988 * @rd_len: ramdisk data length
989 * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
990 * start address (after possible relocation)
991 * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
992 * end address (after possible relocation)
994 * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
995 * variable and if requested ramdisk data is moved to a specified location.
997 * Initrd_start and initrd_end are set to final (after relocation) ramdisk
998 * start/end addresses if ramdisk image start and len were provided,
999 * otherwise set initrd_start and initrd_end set to zeros.
1005 int boot_ramdisk_high (struct lmb
*lmb
, ulong rd_data
, ulong rd_len
,
1006 ulong
*initrd_start
, ulong
*initrd_end
)
1010 int initrd_copy_to_ram
= 1;
1012 if ((s
= getenv ("initrd_high")) != NULL
) {
1013 /* a value of "no" or a similar string will act like 0,
1014 * turning the "load high" feature off. This is intentional.
1016 initrd_high
= simple_strtoul (s
, NULL
, 16);
1017 if (initrd_high
== ~0)
1018 initrd_copy_to_ram
= 0;
1020 /* not set, no restrictions to load high */
1024 debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
1025 initrd_high
, initrd_copy_to_ram
);
1028 if (!initrd_copy_to_ram
) { /* zero-copy ramdisk support */
1029 debug (" in-place initrd\n");
1030 *initrd_start
= rd_data
;
1031 *initrd_end
= rd_data
+ rd_len
;
1032 lmb_reserve(lmb
, rd_data
, rd_len
);
1035 *initrd_start
= lmb_alloc_base (lmb
, rd_len
, 0x1000, initrd_high
);
1037 *initrd_start
= lmb_alloc (lmb
, rd_len
, 0x1000);
1039 if (*initrd_start
== 0) {
1040 puts ("ramdisk - allocation error\n");
1043 show_boot_progress (12);
1045 *initrd_end
= *initrd_start
+ rd_len
;
1046 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
1047 *initrd_start
, *initrd_end
);
1049 memmove_wd ((void *)*initrd_start
,
1050 (void *)rd_data
, rd_len
, CHUNKSZ
);
1058 debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
1059 *initrd_start
, *initrd_end
);
1068 * boot_get_cmdline - allocate and initialize kernel cmdline
1069 * @lmb: pointer to lmb handle, will be used for memory mgmt
1070 * @cmd_start: pointer to a ulong variable, will hold cmdline start
1071 * @cmd_end: pointer to a ulong variable, will hold cmdline end
1072 * @bootmap_base: ulong variable, holds offset in physical memory to
1075 * boot_get_cmdline() allocates space for kernel command line below
1076 * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt
1077 * variable is present its contents is copied to allocated kernel
1084 int boot_get_cmdline (struct lmb
*lmb
, ulong
*cmd_start
, ulong
*cmd_end
,
1090 cmdline
= (char *)lmb_alloc_base(lmb
, CFG_BARGSIZE
, 0xf,
1091 CFG_BOOTMAPSZ
+ bootmap_base
);
1093 if (cmdline
== NULL
)
1096 if ((s
= getenv("bootargs")) == NULL
)
1101 *cmd_start
= (ulong
) & cmdline
[0];
1102 *cmd_end
= *cmd_start
+ strlen(cmdline
);
1104 debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start
, *cmd_end
);
1110 * boot_get_kbd - allocate and initialize kernel copy of board info
1111 * @lmb: pointer to lmb handle, will be used for memory mgmt
1112 * @kbd: double pointer to board info data
1113 * @bootmap_base: ulong variable, holds offset in physical memory to
1116 * boot_get_kbd() allocates space for kernel copy of board info data below
1117 * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with
1118 * the current u-boot board info data.
1124 int boot_get_kbd (struct lmb
*lmb
, bd_t
**kbd
, ulong bootmap_base
)
1126 *kbd
= (bd_t
*)lmb_alloc_base(lmb
, sizeof(bd_t
), 0xf,
1127 CFG_BOOTMAPSZ
+ bootmap_base
);
1133 debug ("## kernel board info at 0x%08lx\n", (ulong
)*kbd
);
1135 #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
1136 do_bdinfo(NULL
, 0, 0, NULL
);
1141 #endif /* CONFIG_PPC || CONFIG_M68K */
1142 #endif /* !USE_HOSTCC */
1144 #if defined(CONFIG_FIT)
1145 /*****************************************************************************/
1146 /* New uImage format routines */
1147 /*****************************************************************************/
1149 static int fit_parse_spec (const char *spec
, char sepc
, ulong addr_curr
,
1150 ulong
*addr
, const char **name
)
1157 sep
= strchr (spec
, sepc
);
1160 *addr
= simple_strtoul (spec
, NULL
, 16);
1170 * fit_parse_conf - parse FIT configuration spec
1171 * @spec: input string, containing configuration spec
1172 * @add_curr: current image address (to be used as a possible default)
1173 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1175 * @conf_name double pointer to a char, will hold pointer to a configuration
1178 * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
1179 * where <addr> is a FIT image address that contains configuration
1180 * with a <conf> unit name.
1182 * Address part is optional, and if omitted default add_curr will
1186 * 1 if spec is a valid configuration string,
1187 * addr and conf_name are set accordingly
1190 inline int fit_parse_conf (const char *spec
, ulong addr_curr
,
1191 ulong
*addr
, const char **conf_name
)
1193 return fit_parse_spec (spec
, '#', addr_curr
, addr
, conf_name
);
1197 * fit_parse_subimage - parse FIT subimage spec
1198 * @spec: input string, containing subimage spec
1199 * @add_curr: current image address (to be used as a possible default)
1200 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1202 * @image_name: double pointer to a char, will hold pointer to a subimage name
1204 * fit_parse_subimage() expects subimage spec in the for of
1205 * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
1206 * subimage with a <subimg> unit name.
1208 * Address part is optional, and if omitted default add_curr will
1212 * 1 if spec is a valid subimage string,
1213 * addr and image_name are set accordingly
1216 inline int fit_parse_subimage (const char *spec
, ulong addr_curr
,
1217 ulong
*addr
, const char **image_name
)
1219 return fit_parse_spec (spec
, ':', addr_curr
, addr
, image_name
);
1221 #endif /* !USE_HOSTCC */
1223 static void fit_get_debug (const void *fit
, int noffset
,
1224 char *prop_name
, int err
)
1226 debug ("Can't get '%s' property from FIT 0x%08lx, "
1227 "node: offset %d, name %s (%s)\n",
1228 prop_name
, (ulong
)fit
, noffset
,
1229 fit_get_name (fit
, noffset
, NULL
),
1230 fdt_strerror (err
));
1234 * fit_print_contents - prints out the contents of the FIT format image
1235 * @fit: pointer to the FIT format image header
1236 * @p: pointer to prefix string
1238 * fit_print_contents() formats a multi line FIT image contents description.
1239 * The routine prints out FIT image properties (root node level) follwed by
1240 * the details of each component image.
1243 * no returned results
1245 void fit_print_contents (const void *fit
)
1256 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1266 /* Root node properties */
1267 ret
= fit_get_desc (fit
, 0, &desc
);
1268 printf ("%sFIT description: ", p
);
1270 printf ("unavailable\n");
1272 printf ("%s\n", desc
);
1274 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
1275 ret
= fit_get_timestamp (fit
, 0, ×tamp
);
1276 printf ("%sCreated: ", p
);
1278 printf ("unavailable\n");
1280 genimg_print_time (timestamp
);
1283 /* Find images parent node offset */
1284 images_noffset
= fdt_path_offset (fit
, FIT_IMAGES_PATH
);
1285 if (images_noffset
< 0) {
1286 printf ("Can't find images parent node '%s' (%s)\n",
1287 FIT_IMAGES_PATH
, fdt_strerror (images_noffset
));
1291 /* Process its subnodes, print out component images details */
1292 for (ndepth
= 0, count
= 0, noffset
= fdt_next_node (fit
, images_noffset
, &ndepth
);
1293 (noffset
>= 0) && (ndepth
> 0);
1294 noffset
= fdt_next_node (fit
, noffset
, &ndepth
)) {
1297 * Direct child node of the images parent node,
1298 * i.e. component image node.
1300 printf ("%s Image %u (%s)\n", p
, count
++,
1301 fit_get_name(fit
, noffset
, NULL
));
1303 fit_image_print (fit
, noffset
, p
);
1307 /* Find configurations parent node offset */
1308 confs_noffset
= fdt_path_offset (fit
, FIT_CONFS_PATH
);
1309 if (confs_noffset
< 0) {
1310 debug ("Can't get configurations parent node '%s' (%s)\n",
1311 FIT_CONFS_PATH
, fdt_strerror (confs_noffset
));
1315 /* get default configuration unit name from default property */
1316 uname
= (char *)fdt_getprop (fit
, noffset
, FIT_DEFAULT_PROP
, NULL
);
1318 printf ("%s Default Configuration: '%s'\n", p
, uname
);
1320 /* Process its subnodes, print out configurations details */
1321 for (ndepth
= 0, count
= 0, noffset
= fdt_next_node (fit
, confs_noffset
, &ndepth
);
1322 (noffset
>= 0) && (ndepth
> 0);
1323 noffset
= fdt_next_node (fit
, noffset
, &ndepth
)) {
1326 * Direct child node of the configurations parent node,
1327 * i.e. configuration node.
1329 printf ("%s Configuration %u (%s)\n", p
, count
++,
1330 fit_get_name(fit
, noffset
, NULL
));
1332 fit_conf_print (fit
, noffset
, p
);
1338 * fit_image_print - prints out the FIT component image details
1339 * @fit: pointer to the FIT format image header
1340 * @image_noffset: offset of the component image node
1341 * @p: pointer to prefix string
1343 * fit_image_print() lists all mandatory properies for the processed component
1344 * image. If present, hash nodes are printed out as well.
1347 * no returned results
1349 void fit_image_print (const void *fit
, int image_noffset
, const char *p
)
1352 uint8_t type
, arch
, os
, comp
;
1360 /* Mandatory properties */
1361 ret
= fit_get_desc (fit
, image_noffset
, &desc
);
1362 printf ("%s Description: ", p
);
1364 printf ("unavailable\n");
1366 printf ("%s\n", desc
);
1368 fit_image_get_type (fit
, image_noffset
, &type
);
1369 printf ("%s Type: %s\n", p
, genimg_get_type_name (type
));
1371 fit_image_get_comp (fit
, image_noffset
, &comp
);
1372 printf ("%s Compression: %s\n", p
, genimg_get_comp_name (comp
));
1374 ret
= fit_image_get_data (fit
, image_noffset
, &data
, &size
);
1377 printf ("%s Data Start: ", p
);
1379 printf ("unavailable\n");
1381 printf ("0x%08lx\n", (ulong
)data
);
1384 printf ("%s Data Size: ", p
);
1386 printf ("unavailable\n");
1388 genimg_print_size (size
);
1390 /* Remaining, type dependent properties */
1391 if ((type
== IH_TYPE_KERNEL
) || (type
== IH_TYPE_STANDALONE
) ||
1392 (type
== IH_TYPE_RAMDISK
) || (type
== IH_TYPE_FIRMWARE
) ||
1393 (type
== IH_TYPE_FLATDT
)) {
1394 fit_image_get_arch (fit
, image_noffset
, &arch
);
1395 printf ("%s Architecture: %s\n", p
, genimg_get_arch_name (arch
));
1398 if (type
== IH_TYPE_KERNEL
) {
1399 fit_image_get_os (fit
, image_noffset
, &os
);
1400 printf ("%s OS: %s\n", p
, genimg_get_os_name (os
));
1403 if ((type
== IH_TYPE_KERNEL
) || (type
== IH_TYPE_STANDALONE
)) {
1404 ret
= fit_image_get_load (fit
, image_noffset
, &load
);
1405 printf ("%s Load Address: ", p
);
1407 printf ("unavailable\n");
1409 printf ("0x%08lx\n", load
);
1411 fit_image_get_entry (fit
, image_noffset
, &entry
);
1412 printf ("%s Entry Point: ", p
);
1414 printf ("unavailable\n");
1416 printf ("0x%08lx\n", entry
);
1419 /* Process all hash subnodes of the component image node */
1420 for (ndepth
= 0, noffset
= fdt_next_node (fit
, image_noffset
, &ndepth
);
1421 (noffset
>= 0) && (ndepth
> 0);
1422 noffset
= fdt_next_node (fit
, noffset
, &ndepth
)) {
1424 /* Direct child node of the component image node */
1425 fit_image_print_hash (fit
, noffset
, p
);
1431 * fit_image_print_hash - prints out the hash node details
1432 * @fit: pointer to the FIT format image header
1433 * @noffset: offset of the hash node
1434 * @p: pointer to prefix string
1436 * fit_image_print_hash() lists properies for the processed hash node
1439 * no returned results
1441 void fit_image_print_hash (const void *fit
, int noffset
, const char *p
)
1449 * Check subnode name, must be equal to "hash".
1450 * Multiple hash nodes require unique unit node
1451 * names, e.g. hash@1, hash@2, etc.
1453 if (strncmp (fit_get_name(fit
, noffset
, NULL
),
1455 strlen(FIT_HASH_NODENAME
)) != 0)
1458 debug ("%s Hash node: '%s'\n", p
,
1459 fit_get_name (fit
, noffset
, NULL
));
1461 printf ("%s Hash algo: ", p
);
1462 if (fit_image_hash_get_algo (fit
, noffset
, &algo
)) {
1463 printf ("invalid/unsupported\n");
1466 printf ("%s\n", algo
);
1468 ret
= fit_image_hash_get_value (fit
, noffset
, &value
,
1470 printf ("%s Hash value: ", p
);
1472 printf ("unavailable\n");
1474 for (i
= 0; i
< value_len
; i
++)
1475 printf ("%02x", value
[i
]);
1479 debug ("%s Hash len: %d\n", p
, value_len
);
1483 * fit_get_desc - get node description property
1484 * @fit: pointer to the FIT format image header
1485 * @noffset: node offset
1486 * @desc: double pointer to the char, will hold pointer to the descrption
1488 * fit_get_desc() reads description property from a given node, if
1489 * description is found pointer to it is returened in third call argument.
1495 int fit_get_desc (const void *fit
, int noffset
, char **desc
)
1499 *desc
= (char *)fdt_getprop (fit
, noffset
, FIT_DESC_PROP
, &len
);
1500 if (*desc
== NULL
) {
1501 fit_get_debug (fit
, noffset
, FIT_DESC_PROP
, len
);
1509 * fit_get_timestamp - get node timestamp property
1510 * @fit: pointer to the FIT format image header
1511 * @noffset: node offset
1512 * @timestamp: pointer to the time_t, will hold read timestamp
1514 * fit_get_timestamp() reads timestamp poperty from given node, if timestamp
1515 * is found and has a correct size its value is retured in third call
1520 * -1, on property read failure
1521 * -2, on wrong timestamp size
1523 int fit_get_timestamp (const void *fit
, int noffset
, time_t *timestamp
)
1528 data
= fdt_getprop (fit
, noffset
, FIT_TIMESTAMP_PROP
, &len
);
1530 fit_get_debug (fit
, noffset
, FIT_TIMESTAMP_PROP
, len
);
1533 if (len
!= sizeof (uint32_t)) {
1534 debug ("FIT timestamp with incorrect size of (%u)\n", len
);
1538 *timestamp
= uimage_to_cpu (*((uint32_t *)data
));
1543 * fit_image_get_node - get node offset for component image of a given unit name
1544 * @fit: pointer to the FIT format image header
1545 * @image_uname: component image node unit name
1547 * fit_image_get_node() finds a component image (withing the '/images'
1548 * node) of a provided unit name. If image is found its node offset is
1549 * returned to the caller.
1552 * image node offset when found (>=0)
1553 * negative number on failure (FDT_ERR_* code)
1555 int fit_image_get_node (const void *fit
, const char *image_uname
)
1557 int noffset
, images_noffset
;
1559 images_noffset
= fdt_path_offset (fit
, FIT_IMAGES_PATH
);
1560 if (images_noffset
< 0) {
1561 debug ("Can't find images parent node '%s' (%s)\n",
1562 FIT_IMAGES_PATH
, fdt_strerror (images_noffset
));
1563 return images_noffset
;
1566 noffset
= fdt_subnode_offset (fit
, images_noffset
, image_uname
);
1568 debug ("Can't get node offset for image unit name: '%s' (%s)\n",
1569 image_uname
, fdt_strerror (noffset
));
1576 * fit_image_get_os - get os id for a given component image node
1577 * @fit: pointer to the FIT format image header
1578 * @noffset: component image node offset
1579 * @os: pointer to the uint8_t, will hold os numeric id
1581 * fit_image_get_os() finds os property in a given component image node.
1582 * If the property is found, its (string) value is translated to the numeric
1583 * id which is returned to the caller.
1589 int fit_image_get_os (const void *fit
, int noffset
, uint8_t *os
)
1594 /* Get OS name from property data */
1595 data
= fdt_getprop (fit
, noffset
, FIT_OS_PROP
, &len
);
1597 fit_get_debug (fit
, noffset
, FIT_OS_PROP
, len
);
1602 /* Translate OS name to id */
1603 *os
= genimg_get_os_id (data
);
1608 * fit_image_get_arch - get arch id for a given component image node
1609 * @fit: pointer to the FIT format image header
1610 * @noffset: component image node offset
1611 * @arch: pointer to the uint8_t, will hold arch numeric id
1613 * fit_image_get_arch() finds arch property in a given component image node.
1614 * If the property is found, its (string) value is translated to the numeric
1615 * id which is returned to the caller.
1621 int fit_image_get_arch (const void *fit
, int noffset
, uint8_t *arch
)
1626 /* Get architecture name from property data */
1627 data
= fdt_getprop (fit
, noffset
, FIT_ARCH_PROP
, &len
);
1629 fit_get_debug (fit
, noffset
, FIT_ARCH_PROP
, len
);
1634 /* Translate architecture name to id */
1635 *arch
= genimg_get_arch_id (data
);
1640 * fit_image_get_type - get type id for a given component image node
1641 * @fit: pointer to the FIT format image header
1642 * @noffset: component image node offset
1643 * @type: pointer to the uint8_t, will hold type numeric id
1645 * fit_image_get_type() finds type property in a given component image node.
1646 * If the property is found, its (string) value is translated to the numeric
1647 * id which is returned to the caller.
1653 int fit_image_get_type (const void *fit
, int noffset
, uint8_t *type
)
1658 /* Get image type name from property data */
1659 data
= fdt_getprop (fit
, noffset
, FIT_TYPE_PROP
, &len
);
1661 fit_get_debug (fit
, noffset
, FIT_TYPE_PROP
, len
);
1666 /* Translate image type name to id */
1667 *type
= genimg_get_type_id (data
);
1672 * fit_image_get_comp - get comp id for a given component image node
1673 * @fit: pointer to the FIT format image header
1674 * @noffset: component image node offset
1675 * @comp: pointer to the uint8_t, will hold comp numeric id
1677 * fit_image_get_comp() finds comp property in a given component image node.
1678 * If the property is found, its (string) value is translated to the numeric
1679 * id which is returned to the caller.
1685 int fit_image_get_comp (const void *fit
, int noffset
, uint8_t *comp
)
1690 /* Get compression name from property data */
1691 data
= fdt_getprop (fit
, noffset
, FIT_COMP_PROP
, &len
);
1693 fit_get_debug (fit
, noffset
, FIT_COMP_PROP
, len
);
1698 /* Translate compression name to id */
1699 *comp
= genimg_get_comp_id (data
);
1704 * fit_image_get_load - get load address property for a given component image node
1705 * @fit: pointer to the FIT format image header
1706 * @noffset: component image node offset
1707 * @load: pointer to the uint32_t, will hold load address
1709 * fit_image_get_load() finds load address property in a given component image node.
1710 * If the property is found, its value is returned to the caller.
1716 int fit_image_get_load (const void *fit
, int noffset
, ulong
*load
)
1719 const uint32_t *data
;
1721 data
= fdt_getprop (fit
, noffset
, FIT_LOAD_PROP
, &len
);
1723 fit_get_debug (fit
, noffset
, FIT_LOAD_PROP
, len
);
1727 *load
= uimage_to_cpu (*data
);
1732 * fit_image_get_entry - get entry point address property for a given component image node
1733 * @fit: pointer to the FIT format image header
1734 * @noffset: component image node offset
1735 * @entry: pointer to the uint32_t, will hold entry point address
1737 * fit_image_get_entry() finds entry point address property in a given component image node.
1738 * If the property is found, its value is returned to the caller.
1744 int fit_image_get_entry (const void *fit
, int noffset
, ulong
*entry
)
1747 const uint32_t *data
;
1749 data
= fdt_getprop (fit
, noffset
, FIT_ENTRY_PROP
, &len
);
1751 fit_get_debug (fit
, noffset
, FIT_ENTRY_PROP
, len
);
1755 *entry
= uimage_to_cpu (*data
);
1760 * fit_image_get_data - get data property and its size for a given component image node
1761 * @fit: pointer to the FIT format image header
1762 * @noffset: component image node offset
1763 * @data: double pointer to void, will hold data property's data address
1764 * @size: pointer to size_t, will hold data property's data size
1766 * fit_image_get_data() finds data property in a given component image node.
1767 * If the property is found its data start address and size are returned to
1774 int fit_image_get_data (const void *fit
, int noffset
,
1775 const void **data
, size_t *size
)
1779 *data
= fdt_getprop (fit
, noffset
, FIT_DATA_PROP
, &len
);
1780 if (*data
== NULL
) {
1781 fit_get_debug (fit
, noffset
, FIT_DATA_PROP
, len
);
1791 * fit_image_hash_get_algo - get hash algorithm name
1792 * @fit: pointer to the FIT format image header
1793 * @noffset: hash node offset
1794 * @algo: double pointer to char, will hold pointer to the algorithm name
1796 * fit_image_hash_get_algo() finds hash algorithm property in a given hash node.
1797 * If the property is found its data start address is returned to the caller.
1803 int fit_image_hash_get_algo (const void *fit
, int noffset
, char **algo
)
1807 *algo
= (char *)fdt_getprop (fit
, noffset
, FIT_ALGO_PROP
, &len
);
1808 if (*algo
== NULL
) {
1809 fit_get_debug (fit
, noffset
, FIT_ALGO_PROP
, len
);
1817 * fit_image_hash_get_value - get hash value and length
1818 * @fit: pointer to the FIT format image header
1819 * @noffset: hash node offset
1820 * @value: double pointer to uint8_t, will hold address of a hash value data
1821 * @value_len: pointer to an int, will hold hash data length
1823 * fit_image_hash_get_value() finds hash value property in a given hash node.
1824 * If the property is found its data start address and size are returned to
1831 int fit_image_hash_get_value (const void *fit
, int noffset
, uint8_t **value
,
1836 *value
= (uint8_t *)fdt_getprop (fit
, noffset
, FIT_VALUE_PROP
, &len
);
1837 if (*value
== NULL
) {
1838 fit_get_debug (fit
, noffset
, FIT_VALUE_PROP
, len
);
1848 * fit_set_timestamp - set node timestamp property
1849 * @fit: pointer to the FIT format image header
1850 * @noffset: node offset
1851 * @timestamp: timestamp value to be set
1853 * fit_set_timestamp() attempts to set timestamp property in the requested
1854 * node and returns operation status to the caller.
1858 * -1, on property read failure
1860 int fit_set_timestamp (void *fit
, int noffset
, time_t timestamp
)
1865 t
= cpu_to_uimage (timestamp
);
1866 ret
= fdt_setprop (fit
, noffset
, FIT_TIMESTAMP_PROP
, &t
,
1869 printf ("Can't set '%s' property for '%s' node (%s)\n",
1870 FIT_TIMESTAMP_PROP
, fit_get_name (fit
, noffset
, NULL
),
1871 fdt_strerror (ret
));
1879 * calculate_hash - calculate and return hash for provided input data
1880 * @data: pointer to the input data
1881 * @data_len: data length
1882 * @algo: requested hash algorithm
1883 * @value: pointer to the char, will hold hash value data (caller must
1884 * allocate enough free space)
1885 * value_len: length of the calculated hash
1887 * calculate_hash() computes input data hash according to the requested algorithm.
1888 * Resulting hash value is placed in caller provided 'value' buffer, length
1889 * of the calculated hash is returned via value_len pointer argument.
1893 * -1, when algo is unsupported
1895 static int calculate_hash (const void *data
, int data_len
, const char *algo
,
1896 uint8_t *value
, int *value_len
)
1898 if (strcmp (algo
, "crc32") == 0 ) {
1899 *((uint32_t *)value
) = crc32_wd (0, data
, data_len
,
1901 *((uint32_t *)value
) = cpu_to_uimage (*((uint32_t *)value
));
1903 } else if (strcmp (algo
, "sha1") == 0 ) {
1904 sha1_csum_wd ((unsigned char *) data
, data_len
,
1905 (unsigned char *) value
, CHUNKSZ_SHA1
);
1907 } else if (strcmp (algo
, "md5") == 0 ) {
1908 md5_wd ((unsigned char *)data
, data_len
, value
, CHUNKSZ_MD5
);
1911 debug ("Unsupported hash alogrithm\n");
1919 * fit_set_hashes - process FIT component image nodes and calculate hashes
1920 * @fit: pointer to the FIT format image header
1922 * fit_set_hashes() adds hash values for all component images in the FIT blob.
1923 * Hashes are calculated for all component images which have hash subnodes
1924 * with algorithm property set to one of the supported hash algorithms.
1928 * libfdt error code, on failure
1930 int fit_set_hashes (void *fit
)
1937 /* Find images parent node offset */
1938 images_noffset
= fdt_path_offset (fit
, FIT_IMAGES_PATH
);
1939 if (images_noffset
< 0) {
1940 printf ("Can't find images parent node '%s' (%s)\n",
1941 FIT_IMAGES_PATH
, fdt_strerror (images_noffset
));
1942 return images_noffset
;
1945 /* Process its subnodes, print out component images details */
1946 for (ndepth
= 0, noffset
= fdt_next_node (fit
, images_noffset
, &ndepth
);
1947 (noffset
>= 0) && (ndepth
> 0);
1948 noffset
= fdt_next_node (fit
, noffset
, &ndepth
)) {
1951 * Direct child node of the images parent node,
1952 * i.e. component image node.
1954 ret
= fit_image_set_hashes (fit
, noffset
);
1964 * fit_image_set_hashes - calculate/set hashes for given component image node
1965 * @fit: pointer to the FIT format image header
1966 * @image_noffset: requested component image node
1968 * fit_image_set_hashes() adds hash values for an component image node. All
1969 * existing hash subnodes are checked, if algorithm property is set to one of
1970 * the supported hash algorithms, hash value is computed and corresponding
1971 * hash node property is set, for example:
1973 * Input component image node structure:
1975 * o image@1 (at image_noffset)
1976 * | - data = [binary data]
1980 * Output component image node structure:
1982 * o image@1 (at image_noffset)
1983 * | - data = [binary data]
1986 * |- value = sha1(data)
1992 int fit_image_set_hashes (void *fit
, int image_noffset
)
1997 uint8_t value
[FIT_MAX_HASH_LEN
];
2002 /* Get image data and data length */
2003 if (fit_image_get_data (fit
, image_noffset
, &data
, &size
)) {
2004 printf ("Can't get image data/size\n");
2008 /* Process all hash subnodes of the component image node */
2009 for (ndepth
= 0, noffset
= fdt_next_node (fit
, image_noffset
, &ndepth
);
2010 (noffset
>= 0) && (ndepth
> 0);
2011 noffset
= fdt_next_node (fit
, noffset
, &ndepth
)) {
2013 /* Direct child node of the component image node */
2016 * Check subnode name, must be equal to "hash".
2017 * Multiple hash nodes require unique unit node
2018 * names, e.g. hash@1, hash@2, etc.
2020 if (strncmp (fit_get_name(fit
, noffset
, NULL
),
2022 strlen(FIT_HASH_NODENAME
)) != 0) {
2023 /* Not a hash subnode, skip it */
2027 if (fit_image_hash_get_algo (fit
, noffset
, &algo
)) {
2028 printf ("Can't get hash algo property for "
2029 "'%s' hash node in '%s' image node\n",
2030 fit_get_name (fit
, noffset
, NULL
),
2031 fit_get_name (fit
, image_noffset
, NULL
));
2035 if (calculate_hash (data
, size
, algo
, value
, &value_len
)) {
2036 printf ("Unsupported hash algorithm (%s) for "
2037 "'%s' hash node in '%s' image node\n",
2038 algo
, fit_get_name (fit
, noffset
, NULL
),
2039 fit_get_name (fit
, image_noffset
, NULL
));
2043 if (fit_image_hash_set_value (fit
, noffset
, value
,
2045 printf ("Can't set hash value for "
2046 "'%s' hash node in '%s' image node\n",
2047 fit_get_name (fit
, noffset
, NULL
),
2048 fit_get_name (fit
, image_noffset
, NULL
));
2058 * fit_image_hash_set_value - set hash value in requested has node
2059 * @fit: pointer to the FIT format image header
2060 * @noffset: hash node offset
2061 * @value: hash value to be set
2062 * @value_len: hash value length
2064 * fit_image_hash_set_value() attempts to set hash value in a node at offset
2065 * given and returns operation status to the caller.
2071 int fit_image_hash_set_value (void *fit
, int noffset
, uint8_t *value
,
2076 ret
= fdt_setprop (fit
, noffset
, FIT_VALUE_PROP
, value
, value_len
);
2078 printf ("Can't set hash '%s' property for '%s' node (%s)\n",
2079 FIT_VALUE_PROP
, fit_get_name (fit
, noffset
, NULL
),
2080 fdt_strerror (ret
));
2086 #endif /* USE_HOSTCC */
2089 * fit_image_check_hashes - verify data intergity
2090 * @fit: pointer to the FIT format image header
2091 * @image_noffset: component image node offset
2093 * fit_image_check_hashes() goes over component image hash nodes,
2094 * re-calculates each data hash and compares with the value stored in hash
2098 * 1, if all hashes are valid
2099 * 0, otherwise (or on error)
2101 int fit_image_check_hashes (const void *fit
, int image_noffset
)
2108 uint8_t value
[FIT_MAX_HASH_LEN
];
2114 /* Get image data and data length */
2115 if (fit_image_get_data (fit
, image_noffset
, &data
, &size
)) {
2116 printf ("Can't get image data/size\n");
2120 /* Process all hash subnodes of the component image node */
2121 for (ndepth
= 0, noffset
= fdt_next_node (fit
, image_noffset
, &ndepth
);
2122 (noffset
>= 0) && (ndepth
> 0);
2123 noffset
= fdt_next_node (fit
, noffset
, &ndepth
)) {
2125 /* Direct child node of the component image node */
2128 * Check subnode name, must be equal to "hash".
2129 * Multiple hash nodes require unique unit node
2130 * names, e.g. hash@1, hash@2, etc.
2132 if (strncmp (fit_get_name(fit
, noffset
, NULL
),
2134 strlen(FIT_HASH_NODENAME
)) != 0)
2137 if (fit_image_hash_get_algo (fit
, noffset
, &algo
)) {
2138 err_msg
= "Can't get hash algo property";
2141 printf ("%s", algo
);
2143 if (fit_image_hash_get_value (fit
, noffset
, &fit_value
,
2145 err_msg
= "Can't get hash value property";
2149 if (calculate_hash (data
, size
, algo
, value
, &value_len
)) {
2150 err_msg
= "Unsupported hash algorithm";
2154 if (value_len
!= fit_value_len
) {
2155 err_msg
= "Bad hash value len";
2157 } else if (memcmp (value
, fit_value
, value_len
) != 0) {
2158 err_msg
= "Bad hash value";
2168 printf ("%s for '%s' hash node in '%s' image node\n",
2169 err_msg
, fit_get_name (fit
, noffset
, NULL
),
2170 fit_get_name (fit
, image_noffset
, NULL
));
2175 * fit_image_check_os - check whether image node is of a given os type
2176 * @fit: pointer to the FIT format image header
2177 * @noffset: component image node offset
2178 * @os: requested image os
2180 * fit_image_check_os() reads image os property and compares its numeric
2181 * id with the requested os. Comparison result is returned to the caller.
2184 * 1 if image is of given os type
2185 * 0 otherwise (or on error)
2187 int fit_image_check_os (const void *fit
, int noffset
, uint8_t os
)
2191 if (fit_image_get_os (fit
, noffset
, &image_os
))
2193 return (os
== image_os
);
2197 * fit_image_check_arch - check whether image node is of a given arch
2198 * @fit: pointer to the FIT format image header
2199 * @noffset: component image node offset
2200 * @arch: requested imagearch
2202 * fit_image_check_arch() reads image arch property and compares its numeric
2203 * id with the requested arch. Comparison result is returned to the caller.
2206 * 1 if image is of given arch
2207 * 0 otherwise (or on error)
2209 int fit_image_check_arch (const void *fit
, int noffset
, uint8_t arch
)
2213 if (fit_image_get_arch (fit
, noffset
, &image_arch
))
2215 return (arch
== image_arch
);
2219 * fit_image_check_type - check whether image node is of a given type
2220 * @fit: pointer to the FIT format image header
2221 * @noffset: component image node offset
2222 * @type: requested image type
2224 * fit_image_check_type() reads image type property and compares its numeric
2225 * id with the requested type. Comparison result is returned to the caller.
2228 * 1 if image is of given type
2229 * 0 otherwise (or on error)
2231 int fit_image_check_type (const void *fit
, int noffset
, uint8_t type
)
2235 if (fit_image_get_type (fit
, noffset
, &image_type
))
2237 return (type
== image_type
);
2241 * fit_image_check_comp - check whether image node uses given compression
2242 * @fit: pointer to the FIT format image header
2243 * @noffset: component image node offset
2244 * @comp: requested image compression type
2246 * fit_image_check_comp() reads image compression property and compares its
2247 * numeric id with the requested compression type. Comparison result is
2248 * returned to the caller.
2251 * 1 if image uses requested compression
2252 * 0 otherwise (or on error)
2254 int fit_image_check_comp (const void *fit
, int noffset
, uint8_t comp
)
2258 if (fit_image_get_comp (fit
, noffset
, &image_comp
))
2260 return (comp
== image_comp
);
2264 * fit_check_format - sanity check FIT image format
2265 * @fit: pointer to the FIT format image header
2267 * fit_check_format() runs a basic sanity FIT image verification.
2268 * Routine checks for mandatory properties, nodes, etc.
2274 int fit_check_format (const void *fit
)
2276 /* mandatory / node 'description' property */
2277 if (fdt_getprop (fit
, 0, FIT_DESC_PROP
, NULL
) == NULL
) {
2278 debug ("Wrong FIT format: no description\n");
2282 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
2283 /* mandatory / node 'timestamp' property */
2284 if (fdt_getprop (fit
, 0, FIT_TIMESTAMP_PROP
, NULL
) == NULL
) {
2285 debug ("Wrong FIT format: no description\n");
2290 /* mandatory subimages parent '/images' node */
2291 if (fdt_path_offset (fit
, FIT_IMAGES_PATH
) < 0) {
2292 debug ("Wrong FIT format: no images parent node\n");
2300 * fit_conf_get_node - get node offset for configuration of a given unit name
2301 * @fit: pointer to the FIT format image header
2302 * @conf_uname: configuration node unit name
2304 * fit_conf_get_node() finds a configuration (withing the '/configurations'
2305 * parant node) of a provided unit name. If configuration is found its node offset
2306 * is returned to the caller.
2308 * When NULL is provided in second argument fit_conf_get_node() will search
2309 * for a default configuration node instead. Default configuration node unit name
2310 * is retrived from FIT_DEFAULT_PROP property of the '/configurations' node.
2313 * configuration node offset when found (>=0)
2314 * negative number on failure (FDT_ERR_* code)
2316 int fit_conf_get_node (const void *fit
, const char *conf_uname
)
2318 int noffset
, confs_noffset
;
2321 confs_noffset
= fdt_path_offset (fit
, FIT_CONFS_PATH
);
2322 if (confs_noffset
< 0) {
2323 debug ("Can't find configurations parent node '%s' (%s)\n",
2324 FIT_CONFS_PATH
, fdt_strerror (confs_noffset
));
2325 return confs_noffset
;
2328 if (conf_uname
== NULL
) {
2329 /* get configuration unit name from the default property */
2330 debug ("No configuration specified, trying default...\n");
2331 conf_uname
= (char *)fdt_getprop (fit
, confs_noffset
, FIT_DEFAULT_PROP
, &len
);
2332 if (conf_uname
== NULL
) {
2333 fit_get_debug (fit
, confs_noffset
, FIT_DEFAULT_PROP
, len
);
2336 debug ("Found default configuration: '%s'\n", conf_uname
);
2339 noffset
= fdt_subnode_offset (fit
, confs_noffset
, conf_uname
);
2341 debug ("Can't get node offset for configuration unit name: '%s' (%s)\n",
2342 conf_uname
, fdt_strerror (noffset
));
2348 static int __fit_conf_get_prop_node (const void *fit
, int noffset
,
2349 const char *prop_name
)
2354 /* get kernel image unit name from configuration kernel property */
2355 uname
= (char *)fdt_getprop (fit
, noffset
, prop_name
, &len
);
2359 return fit_image_get_node (fit
, uname
);
2363 * fit_conf_get_kernel_node - get kernel image node offset that corresponds to
2364 * a given configuration
2365 * @fit: pointer to the FIT format image header
2366 * @noffset: configuration node offset
2368 * fit_conf_get_kernel_node() retrives kernel image node unit name from
2369 * configuration FIT_KERNEL_PROP property and translates it to the node
2373 * image node offset when found (>=0)
2374 * negative number on failure (FDT_ERR_* code)
2376 int fit_conf_get_kernel_node (const void *fit
, int noffset
)
2378 return __fit_conf_get_prop_node (fit
, noffset
, FIT_KERNEL_PROP
);
2382 * fit_conf_get_ramdisk_node - get ramdisk image node offset that corresponds to
2383 * a given configuration
2384 * @fit: pointer to the FIT format image header
2385 * @noffset: configuration node offset
2387 * fit_conf_get_ramdisk_node() retrives ramdisk image node unit name from
2388 * configuration FIT_KERNEL_PROP property and translates it to the node
2392 * image node offset when found (>=0)
2393 * negative number on failure (FDT_ERR_* code)
2395 int fit_conf_get_ramdisk_node (const void *fit
, int noffset
)
2397 return __fit_conf_get_prop_node (fit
, noffset
, FIT_RAMDISK_PROP
);
2401 * fit_conf_get_fdt_node - get fdt image node offset that corresponds to
2402 * a given configuration
2403 * @fit: pointer to the FIT format image header
2404 * @noffset: configuration node offset
2406 * fit_conf_get_fdt_node() retrives fdt image node unit name from
2407 * configuration FIT_KERNEL_PROP property and translates it to the node
2411 * image node offset when found (>=0)
2412 * negative number on failure (FDT_ERR_* code)
2414 int fit_conf_get_fdt_node (const void *fit
, int noffset
)
2416 return __fit_conf_get_prop_node (fit
, noffset
, FIT_FDT_PROP
);
2420 * fit_conf_print - prints out the FIT configuration details
2421 * @fit: pointer to the FIT format image header
2422 * @noffset: offset of the configuration node
2423 * @p: pointer to prefix string
2425 * fit_conf_print() lists all mandatory properies for the processed
2426 * configuration node.
2429 * no returned results
2431 void fit_conf_print (const void *fit
, int noffset
, const char *p
)
2437 /* Mandatory properties */
2438 ret
= fit_get_desc (fit
, noffset
, &desc
);
2439 printf ("%s Description: ", p
);
2441 printf ("unavailable\n");
2443 printf ("%s\n", desc
);
2445 uname
= (char *)fdt_getprop (fit
, noffset
, FIT_KERNEL_PROP
, NULL
);
2446 printf ("%s Kernel: ", p
);
2448 printf ("unavailable\n");
2450 printf ("%s\n", uname
);
2452 /* Optional properties */
2453 uname
= (char *)fdt_getprop (fit
, noffset
, FIT_RAMDISK_PROP
, NULL
);
2455 printf ("%s Init Ramdisk: %s\n", p
, uname
);
2457 uname
= (char *)fdt_getprop (fit
, noffset
, FIT_FDT_PROP
, NULL
);
2459 printf ("%s FDT: %s\n", p
, uname
);
2463 * fit_check_ramdisk - verify FIT format ramdisk subimage
2464 * @fit_hdr: pointer to the FIT ramdisk header
2465 * @rd_noffset: ramdisk subimage node offset within FIT image
2466 * @arch: requested ramdisk image architecture type
2467 * @verify: data CRC verification flag
2469 * fit_check_ramdisk() verifies integrity of the ramdisk subimage and from
2470 * specified FIT image.
2477 static int fit_check_ramdisk (const void *fit
, int rd_noffset
, uint8_t arch
, int verify
)
2479 fit_image_print (fit
, rd_noffset
, " ");
2482 puts (" Verifying Hash Integrity ... ");
2483 if (!fit_image_check_hashes (fit
, rd_noffset
)) {
2484 puts ("Bad Data Hash\n");
2485 show_boot_progress (-125);
2491 show_boot_progress (126);
2492 if (!fit_image_check_os (fit
, rd_noffset
, IH_OS_LINUX
) ||
2493 !fit_image_check_arch (fit
, rd_noffset
, arch
) ||
2494 !fit_image_check_type (fit
, rd_noffset
, IH_TYPE_RAMDISK
)) {
2495 printf ("No Linux %s Ramdisk Image\n",
2496 genimg_get_arch_name(arch
));
2497 show_boot_progress (-126);
2501 show_boot_progress (127);
2504 #endif /* USE_HOSTCC */
2505 #endif /* CONFIG_FIT */