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,
32 #ifdef CONFIG_SHOW_BOOT_PROGRESS
33 #include <status_led.h>
36 #ifdef CONFIG_HAS_DATAFLASH
37 #include <dataflash.h>
40 #ifdef CONFIG_LOGBUFFER
44 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
48 #if defined(CONFIG_FIT)
51 #include <fdt_support.h>
55 extern int do_bdinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
58 DECLARE_GLOBAL_DATA_PTR;
60 static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag,
61 int argc, char *argv[],
62 ulong rd_addr, uint8_t arch, int verify);
65 #endif /* !USE_HOSTCC*/
69 typedef struct table_entry {
70 int id; /* as defined in image.h */
71 char *sname; /* short (input) name */
72 char *lname; /* long (output) name */
75 static table_entry_t uimage_arch[] = {
76 { IH_ARCH_INVALID, NULL, "Invalid ARCH", },
77 { IH_ARCH_ALPHA, "alpha", "Alpha", },
78 { IH_ARCH_ARM, "arm", "ARM", },
79 { IH_ARCH_I386, "x86", "Intel x86", },
80 { IH_ARCH_IA64, "ia64", "IA64", },
81 { IH_ARCH_M68K, "m68k", "M68K", },
82 { IH_ARCH_MICROBLAZE, "microblaze", "MicroBlaze", },
83 { IH_ARCH_MIPS, "mips", "MIPS", },
84 { IH_ARCH_MIPS64, "mips64", "MIPS 64 Bit", },
85 { IH_ARCH_NIOS, "nios", "NIOS", },
86 { IH_ARCH_NIOS2, "nios2", "NIOS II", },
87 { IH_ARCH_PPC, "ppc", "PowerPC", },
88 { IH_ARCH_S390, "s390", "IBM S390", },
89 { IH_ARCH_SH, "sh", "SuperH", },
90 { IH_ARCH_SPARC, "sparc", "SPARC", },
91 { IH_ARCH_SPARC64, "sparc64", "SPARC 64 Bit", },
92 { IH_ARCH_BLACKFIN, "blackfin", "Blackfin", },
93 { IH_ARCH_AVR32, "avr32", "AVR32", },
97 static table_entry_t uimage_os[] = {
98 { IH_OS_INVALID, NULL, "Invalid OS", },
99 #if defined(CONFIG_ARTOS) || defined(USE_HOSTCC)
100 { IH_OS_ARTOS, "artos", "ARTOS", },
102 { IH_OS_LINUX, "linux", "Linux", },
103 #if defined(CONFIG_LYNXKDI) || defined(USE_HOSTCC)
104 { IH_OS_LYNXOS, "lynxos", "LynxOS", },
106 { IH_OS_NETBSD, "netbsd", "NetBSD", },
107 { IH_OS_RTEMS, "rtems", "RTEMS", },
108 { IH_OS_U_BOOT, "u-boot", "U-Boot", },
109 #if defined(CONFIG_CMD_ELF) || defined(USE_HOSTCC)
110 { IH_OS_QNX, "qnx", "QNX", },
111 { IH_OS_VXWORKS, "vxworks", "VxWorks", },
114 { IH_OS_4_4BSD, "4_4bsd", "4_4BSD", },
115 { IH_OS_DELL, "dell", "Dell", },
116 { IH_OS_ESIX, "esix", "Esix", },
117 { IH_OS_FREEBSD, "freebsd", "FreeBSD", },
118 { IH_OS_IRIX, "irix", "Irix", },
119 { IH_OS_NCR, "ncr", "NCR", },
120 { IH_OS_OPENBSD, "openbsd", "OpenBSD", },
121 { IH_OS_PSOS, "psos", "pSOS", },
122 { IH_OS_SCO, "sco", "SCO", },
123 { IH_OS_SOLARIS, "solaris", "Solaris", },
124 { IH_OS_SVR4, "svr4", "SVR4", },
129 static table_entry_t uimage_type[] = {
130 { IH_TYPE_INVALID, NULL, "Invalid Image", },
131 { IH_TYPE_FILESYSTEM, "filesystem", "Filesystem Image", },
132 { IH_TYPE_FIRMWARE, "firmware", "Firmware", },
133 { IH_TYPE_KERNEL, "kernel", "Kernel Image", },
134 { IH_TYPE_MULTI, "multi", "Multi-File Image", },
135 { IH_TYPE_RAMDISK, "ramdisk", "RAMDisk Image", },
136 { IH_TYPE_SCRIPT, "script", "Script", },
137 { IH_TYPE_STANDALONE, "standalone", "Standalone Program", },
138 { IH_TYPE_FLATDT, "flat_dt", "Flat Device Tree", },
142 static table_entry_t uimage_comp[] = {
143 { IH_COMP_NONE, "none", "uncompressed", },
144 { IH_COMP_BZIP2, "bzip2", "bzip2 compressed", },
145 { IH_COMP_GZIP, "gzip", "gzip compressed", },
149 unsigned long crc32 (unsigned long, const unsigned char *, unsigned int);
150 static void genimg_print_size (uint32_t size);
151 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
152 static void genimg_print_time (time_t timestamp);
155 /*****************************************************************************/
156 /* Legacy format routines */
157 /*****************************************************************************/
158 int image_check_hcrc (image_header_t *hdr)
161 ulong len = image_get_header_size ();
162 image_header_t header;
164 /* Copy header so we can blank CRC field for re-calculation */
165 memmove (&header, (char *)hdr, image_get_header_size ());
166 image_set_hcrc (&header, 0);
168 hcrc = crc32 (0, (unsigned char *)&header, len);
170 return (hcrc == image_get_hcrc (hdr));
173 int image_check_dcrc (image_header_t *hdr)
175 ulong data = image_get_data (hdr);
176 ulong len = image_get_data_size (hdr);
177 ulong dcrc = crc32 (0, (unsigned char *)data, len);
179 return (dcrc == image_get_dcrc (hdr));
183 int image_check_dcrc_wd (image_header_t *hdr, ulong chunksz)
186 ulong len = image_get_data_size (hdr);
187 ulong data = image_get_data (hdr);
189 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
191 ulong edata = cdata + len;
193 while (cdata < edata) {
194 ulong chunk = edata - cdata;
198 dcrc = crc32 (dcrc, (unsigned char *)cdata, chunk);
204 dcrc = crc32 (0, (unsigned char *)data, len);
207 return (dcrc == image_get_dcrc (hdr));
209 #endif /* !USE_HOSTCC */
212 * image_multi_count - get component (sub-image) count
213 * @hdr: pointer to the header of the multi component image
215 * image_multi_count() returns number of components in a multi
218 * Note: no checking of the image type is done, caller must pass
219 * a valid multi component image.
222 * number of components
224 ulong image_multi_count (image_header_t *hdr)
229 /* get start of the image payload, which in case of multi
230 * component images that points to a table of component sizes */
231 size = (ulong *)image_get_data (hdr);
233 /* count non empty slots */
234 for (i = 0; size[i]; ++i)
241 * image_multi_getimg - get component data address and size
242 * @hdr: pointer to the header of the multi component image
243 * @idx: index of the requested component
244 * @data: pointer to a ulong variable, will hold component data address
245 * @len: pointer to a ulong variable, will hold component size
247 * image_multi_getimg() returns size and data address for the requested
248 * component in a multi component image.
250 * Note: no checking of the image type is done, caller must pass
251 * a valid multi component image.
254 * data address and size of the component, if idx is valid
255 * 0 in data and len, if idx is out of range
257 void image_multi_getimg (image_header_t *hdr, ulong idx,
258 ulong *data, ulong *len)
262 ulong offset, tail, count, img_data;
264 /* get number of component */
265 count = image_multi_count (hdr);
267 /* get start of the image payload, which in case of multi
268 * component images that points to a table of component sizes */
269 size = (ulong *)image_get_data (hdr);
271 /* get address of the proper component data start, which means
272 * skipping sizes table (add 1 for last, null entry) */
273 img_data = image_get_data (hdr) + (count + 1) * sizeof (ulong);
280 /* go over all indices preceding requested component idx */
281 for (i = 0; i < idx; i++) {
282 /* add up i-th component size */
285 /* add up alignment for i-th component */
286 tail += (4 - size[i] % 4);
289 /* calculate idx-th component data address */
290 *data = img_data + offset + tail;
297 static void image_print_type (image_header_t *hdr)
299 const char *os, *arch, *type, *comp;
301 os = genimg_get_os_name (image_get_os (hdr));
302 arch = genimg_get_arch_name (image_get_arch (hdr));
303 type = genimg_get_type_name (image_get_type (hdr));
304 comp = genimg_get_comp_name (image_get_comp (hdr));
306 printf ("%s %s %s (%s)\n", arch, os, type, comp);
309 static void __image_print_contents (image_header_t *hdr, const char *p)
311 printf ("%sImage Name: %.*s\n", p, IH_NMLEN, image_get_name (hdr));
312 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
313 printf ("%sCreated: ", p);
314 genimg_print_time ((time_t)image_get_time (hdr));
316 printf ("%sImage Type: ", p);
317 image_print_type (hdr);
318 printf ("%sData Size: ", p);
319 genimg_print_size (image_get_data_size (hdr));
320 printf ("%sLoad Address: %08x\n", p, image_get_load (hdr));
321 printf ("%sEntry Point: %08x\n", p, image_get_ep (hdr));
323 if (image_check_type (hdr, IH_TYPE_MULTI) ||
324 image_check_type (hdr, IH_TYPE_SCRIPT)) {
327 ulong count = image_multi_count (hdr);
329 printf ("%sContents:\n", p);
330 for (i = 0; i < count; i++) {
331 image_multi_getimg (hdr, i, &data, &len);
333 printf ("%s Image %d: ", p, i);
334 genimg_print_size (len);
336 if (image_check_type (hdr, IH_TYPE_SCRIPT) && i > 0) {
338 * the user may need to know offsets
339 * if planning to do something with
342 printf ("%s Offset = 0x%08lx\n", p, data);
348 inline void image_print_contents (image_header_t *hdr)
350 __image_print_contents (hdr, " ");
353 inline void image_print_contents_noindent (image_header_t *hdr)
355 __image_print_contents (hdr, "");
360 * image_get_ramdisk - get and verify ramdisk image
361 * @cmdtp: command table pointer
362 * @flag: command flag
363 * @argc: command argument count
364 * @argv: command argument list
365 * @rd_addr: ramdisk image start address
366 * @arch: expected ramdisk architecture
367 * @verify: checksum verification flag
369 * image_get_ramdisk() returns a pointer to the verified ramdisk image
370 * header. Routine receives image start address and expected architecture
371 * flag. Verification done covers data and header integrity and os/type/arch
374 * If dataflash support is enabled routine checks for dataflash addresses
375 * and handles required dataflash reads.
378 * pointer to a ramdisk image header, if image was found and valid
379 * otherwise, return NULL
381 static image_header_t* image_get_ramdisk (cmd_tbl_t *cmdtp, int flag,
382 int argc, char *argv[],
383 ulong rd_addr, uint8_t arch, int verify)
385 image_header_t *rd_hdr;
387 show_boot_progress (9);
388 rd_hdr = (image_header_t *)rd_addr;
390 if (!image_check_magic (rd_hdr)) {
391 puts ("Bad Magic Number\n");
392 show_boot_progress (-10);
396 if (!image_check_hcrc (rd_hdr)) {
397 puts ("Bad Header Checksum\n");
398 show_boot_progress (-11);
402 show_boot_progress (10);
403 image_print_contents (rd_hdr);
406 puts(" Verifying Checksum ... ");
407 if (!image_check_dcrc_wd (rd_hdr, CHUNKSZ)) {
408 puts ("Bad Data CRC\n");
409 show_boot_progress (-12);
415 show_boot_progress (11);
417 if (!image_check_os (rd_hdr, IH_OS_LINUX) ||
418 !image_check_arch (rd_hdr, arch) ||
419 !image_check_type (rd_hdr, IH_TYPE_RAMDISK)) {
420 printf ("No Linux %s Ramdisk Image\n",
421 genimg_get_arch_name(arch));
422 show_boot_progress (-13);
428 #endif /* !USE_HOSTCC */
430 /*****************************************************************************/
431 /* Shared dual-format routines */
432 /*****************************************************************************/
434 int getenv_verify (void)
436 char *s = getenv ("verify");
437 return (s && (*s == 'n')) ? 0 : 1;
440 int getenv_autostart (void)
442 char *s = getenv ("autostart");
443 return (s && (*s == 'n')) ? 0 : 1;
446 ulong getenv_bootm_low(void)
448 char *s = getenv ("bootm_low");
450 ulong tmp = simple_strtoul (s, NULL, 16);
454 #ifdef CFG_SDRAM_BASE
455 return CFG_SDRAM_BASE;
461 ulong getenv_bootm_size(void)
463 char *s = getenv ("bootm_size");
465 ulong tmp = simple_strtoul (s, NULL, 16);
469 return gd->bd->bi_memsize;
472 void memmove_wd (void *to, void *from, size_t len, ulong chunksz)
474 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
476 size_t tail = (len > chunksz) ? chunksz : len;
478 memmove (to, from, tail);
483 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
484 memmove (to, from, len);
485 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
487 #endif /* !USE_HOSTCC */
489 static void genimg_print_size (uint32_t size)
492 printf ("%d Bytes = ", size);
493 print_size (size, "\n");
495 printf ("%d Bytes = %.2f kB = %.2f MB\n",
496 size, (double)size / 1.024e3,
497 (double)size / 1.048576e6);
501 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE) || defined(USE_HOSTCC)
502 static void genimg_print_time (time_t timestamp)
507 to_tm (timestamp, &tm);
508 printf ("%4d-%02d-%02d %2d:%02d:%02d UTC\n",
509 tm.tm_year, tm.tm_mon, tm.tm_mday,
510 tm.tm_hour, tm.tm_min, tm.tm_sec);
512 printf ("%s", ctime(×tamp));
515 #endif /* CONFIG_TIMESTAMP || CONFIG_CMD_DATE || USE_HOSTCC */
518 * get_table_entry_name - translate entry id to long name
519 * @table: pointer to a translation table for entries of a specific type
520 * @msg: message to be returned when translation fails
521 * @id: entry id to be translated
523 * get_table_entry_name() will go over translation table trying to find
524 * entry that matches given id. If matching entry is found, its long
525 * name is returned to the caller.
528 * long entry name if translation succeeds
531 static char *get_table_entry_name (table_entry_t *table, char *msg, int id)
533 for (; table->id >= 0; ++table) {
535 return (table->lname);
540 const char *genimg_get_os_name (uint8_t os)
542 return (get_table_entry_name (uimage_os, "Unknown OS", os));
545 const char *genimg_get_arch_name (uint8_t arch)
547 return (get_table_entry_name (uimage_arch, "Unknown Architecture", arch));
550 const char *genimg_get_type_name (uint8_t type)
552 return (get_table_entry_name (uimage_type, "Unknown Image", type));
555 const char *genimg_get_comp_name (uint8_t comp)
557 return (get_table_entry_name (uimage_comp, "Unknown Compression", comp));
561 * get_table_entry_id - translate short entry name to id
562 * @table: pointer to a translation table for entries of a specific type
563 * @table_name: to be used in case of error
564 * @name: entry short name to be translated
566 * get_table_entry_id() will go over translation table trying to find
567 * entry that matches given short name. If matching entry is found,
568 * its id returned to the caller.
571 * entry id if translation succeeds
574 static int get_table_entry_id (table_entry_t *table,
575 const char *table_name, const char *name)
581 for (t = table; t->id >= 0; ++t) {
582 if (t->sname && strcasecmp(t->sname, name) == 0)
586 fprintf (stderr, "\nInvalid %s Type - valid names are", table_name);
587 for (t = table; t->id >= 0; ++t) {
588 if (t->sname == NULL)
590 fprintf (stderr, "%c %s", (first) ? ':' : ',', t->sname);
593 fprintf (stderr, "\n");
595 for (t = table; t->id >= 0; ++t) {
596 if (t->sname && strcmp(t->sname, name) == 0)
599 debug ("Invalid %s Type: %s\n", table_name, name);
600 #endif /* USE_HOSTCC */
604 int genimg_get_os_id (const char *name)
606 return (get_table_entry_id (uimage_os, "OS", name));
609 int genimg_get_arch_id (const char *name)
611 return (get_table_entry_id (uimage_arch, "CPU", name));
614 int genimg_get_type_id (const char *name)
616 return (get_table_entry_id (uimage_type, "Image", name));
619 int genimg_get_comp_id (const char *name)
621 return (get_table_entry_id (uimage_comp, "Compression", name));
626 * genimg_get_format - get image format type
627 * @img_addr: image start address
629 * genimg_get_format() checks whether provided address points to a valid
630 * legacy or FIT image.
632 * New uImage format and FDT blob are based on a libfdt. FDT blob
633 * may be passed directly or embedded in a FIT image. In both situations
634 * genimg_get_format() must be able to dectect libfdt header.
637 * image format type or IMAGE_FORMAT_INVALID if no image is present
639 int genimg_get_format (void *img_addr)
641 ulong format = IMAGE_FORMAT_INVALID;
643 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
647 hdr = (image_header_t *)img_addr;
648 if (image_check_magic(hdr))
649 format = IMAGE_FORMAT_LEGACY;
650 #if defined(CONFIG_FIT) || defined(CONFIG_OF_LIBFDT)
652 fit_hdr = (char *)img_addr;
653 if (fdt_check_header (fit_hdr) == 0)
654 format = IMAGE_FORMAT_FIT;
662 * genimg_get_image - get image from special storage (if necessary)
663 * @img_addr: image start address
665 * genimg_get_image() checks if provided image start adddress is located
666 * in a dataflash storage. If so, image is moved to a system RAM memory.
669 * image start address after possible relocation from special storage
671 ulong genimg_get_image (ulong img_addr)
673 ulong ram_addr = img_addr;
675 #ifdef CONFIG_HAS_DATAFLASH
676 ulong h_size, d_size;
678 if (addr_dataflash (img_addr)){
679 /* ger RAM address */
680 ram_addr = CFG_LOAD_ADDR;
682 /* get header size */
683 h_size = image_get_header_size ();
684 #if defined(CONFIG_FIT)
685 if (sizeof(struct fdt_header) > h_size)
686 h_size = sizeof(struct fdt_header);
690 debug (" Reading image header from dataflash address "
691 "%08lx to RAM address %08lx\n", img_addr, ram_addr);
693 read_dataflash (img_addr, h_size, (char *)ram_addr);
696 switch (genimg_get_format ((void *)ram_addr)) {
697 case IMAGE_FORMAT_LEGACY:
698 d_size = image_get_data_size ((image_header_t *)ram_addr);
699 debug (" Legacy format image found at 0x%08lx, size 0x%08lx\n",
702 #if defined(CONFIG_FIT)
703 case IMAGE_FORMAT_FIT:
704 d_size = fdt_totalsize((void *)ram_addr) - h_size;
705 debug (" FIT/FDT format image found at 0x%08lx, size 0x%08lx\n",
710 printf (" No valid image found at 0x%08lx\n", img_addr);
714 /* read in image data */
715 debug (" Reading image remaining data from dataflash address "
716 "%08lx to RAM address %08lx\n", img_addr + h_size,
719 read_dataflash (img_addr + h_size, d_size,
720 (char *)(ram_addr + h_size));
723 #endif /* CONFIG_HAS_DATAFLASH */
729 * boot_get_ramdisk - main ramdisk handling routine
730 * @cmdtp: command table pointer
731 * @flag: command flag
732 * @argc: command argument count
733 * @argv: command argument list
734 * @images: pointer to the bootm images structure
735 * @arch: expected ramdisk architecture
736 * @rd_start: pointer to a ulong variable, will hold ramdisk start address
737 * @rd_end: pointer to a ulong variable, will hold ramdisk end
739 * boot_get_ramdisk() is responsible for finding a valid ramdisk image.
740 * Curently supported are the following ramdisk sources:
741 * - multicomponent kernel/ramdisk image,
742 * - commandline provided address of decicated ramdisk image.
745 * rd_start and rd_end are set to ramdisk start/end addresses if
746 * ramdisk image is found and valid
747 * rd_start and rd_end are set to 0 if no ramdisk exists
748 * return 1 if ramdisk image is found but corrupted
750 int boot_get_ramdisk (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
751 bootm_headers_t *images, uint8_t arch,
752 ulong *rd_start, ulong *rd_end)
754 ulong rd_addr, rd_load;
755 ulong rd_data, rd_len;
756 image_header_t *rd_hdr;
757 #if defined(CONFIG_FIT)
759 const char *fit_uname_config = NULL;
760 const char *fit_uname_ramdisk = NULL;
765 * Look for a '-' which indicates to ignore the
768 if ((argc >= 3) && (strcmp(argv[2], "-") == 0)) {
769 debug ("## Skipping init Ramdisk\n");
770 rd_len = rd_data = 0;
771 } else if (argc >= 3) {
772 #if defined(CONFIG_FIT)
774 * If the init ramdisk comes from the FIT image and the FIT image
775 * address is omitted in the command line argument, try to use
776 * os FIT image address or default load address.
778 if (images->fit_uname_os)
779 default_addr = (ulong)images->fit_hdr_os;
781 default_addr = load_addr;
783 if (fit_parse_conf (argv[2], default_addr,
784 &rd_addr, &fit_uname_config)) {
785 debug ("* ramdisk: config '%s' from image at 0x%08lx\n",
786 fit_uname_config, rd_addr);
787 } else if (fit_parse_subimage (argv[2], default_addr,
788 &rd_addr, &fit_uname_ramdisk)) {
789 debug ("* ramdisk: subimage '%s' from image at 0x%08lx\n",
790 fit_uname_ramdisk, rd_addr);
794 rd_addr = simple_strtoul(argv[2], NULL, 16);
795 debug ("* ramdisk: cmdline image address = 0x%08lx\n",
799 /* copy from dataflash if needed */
800 printf ("## Loading init Ramdisk Image at %08lx ...\n",
802 rd_addr = genimg_get_image (rd_addr);
805 * Check if there is an initrd image at the
806 * address provided in the second bootm argument
807 * check image type, for FIT images get FIT node.
809 switch (genimg_get_format ((void *)rd_addr)) {
810 case IMAGE_FORMAT_LEGACY:
812 debug ("* ramdisk: legacy format image\n");
814 rd_hdr = image_get_ramdisk (cmdtp, flag, argc, argv,
815 rd_addr, arch, images->verify);
817 if (rd_hdr == NULL) {
823 rd_data = image_get_data (rd_hdr);
824 rd_len = image_get_data_size (rd_hdr);
825 rd_load = image_get_load (rd_hdr);
827 #if defined(CONFIG_FIT)
828 case IMAGE_FORMAT_FIT:
829 fit_hdr = (void *)rd_addr;
830 debug ("* ramdisk: FIT format image\n");
831 fit_unsupported_reset ("ramdisk");
835 printf ("Wrong Image Format for %s command\n",
837 rd_data = rd_len = 0;
840 #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || defined(CONFIG_ARMADILLO)
842 * We need to copy the ramdisk to SRAM to let Linux boot
845 memmove ((void *)rd_load, (uchar *)rd_data, rd_len);
848 #endif /* CONFIG_B2 || CONFIG_EVB4510 || CONFIG_ARMADILLO */
850 } else if (images->legacy_hdr_valid &&
851 image_check_type (images->legacy_hdr_os, IH_TYPE_MULTI)) {
853 * Now check if we have a legacy mult-component image,
854 * get second entry data start address and len.
856 show_boot_progress (13);
857 printf ("## Loading init Ramdisk from multi component "
858 "Image at %08lx ...\n",
859 (ulong)images->legacy_hdr_os);
861 image_multi_getimg (images->legacy_hdr_os, 1, &rd_data, &rd_len);
866 show_boot_progress (14);
867 rd_len = rd_data = 0;
871 debug ("## No init Ramdisk\n");
876 *rd_end = rd_data + rd_len;
878 debug (" ramdisk start = 0x%08lx, ramdisk end = 0x%08lx\n",
884 #if defined(CONFIG_PPC) || defined(CONFIG_M68K)
886 * boot_ramdisk_high - relocate init ramdisk
887 * @lmb: pointer to lmb handle, will be used for memory mgmt
888 * @rd_data: ramdisk data start address
889 * @rd_len: ramdisk data length
890 * @initrd_start: pointer to a ulong variable, will hold final init ramdisk
891 * start address (after possible relocation)
892 * @initrd_end: pointer to a ulong variable, will hold final init ramdisk
893 * end address (after possible relocation)
895 * boot_ramdisk_high() takes a relocation hint from "initrd_high" environement
896 * variable and if requested ramdisk data is moved to a specified location.
898 * Initrd_start and initrd_end are set to final (after relocation) ramdisk
899 * start/end addresses if ramdisk image start and len were provided,
900 * otherwise set initrd_start and initrd_end set to zeros.
906 int boot_ramdisk_high (struct lmb *lmb, ulong rd_data, ulong rd_len,
907 ulong *initrd_start, ulong *initrd_end)
911 int initrd_copy_to_ram = 1;
913 if ((s = getenv ("initrd_high")) != NULL) {
914 /* a value of "no" or a similar string will act like 0,
915 * turning the "load high" feature off. This is intentional.
917 initrd_high = simple_strtoul (s, NULL, 16);
918 if (initrd_high == ~0)
919 initrd_copy_to_ram = 0;
921 /* not set, no restrictions to load high */
925 debug ("## initrd_high = 0x%08lx, copy_to_ram = %d\n",
926 initrd_high, initrd_copy_to_ram);
929 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
930 debug (" in-place initrd\n");
931 *initrd_start = rd_data;
932 *initrd_end = rd_data + rd_len;
933 lmb_reserve(lmb, rd_data, rd_len);
936 *initrd_start = lmb_alloc_base (lmb, rd_len, 0x1000, initrd_high);
938 *initrd_start = lmb_alloc (lmb, rd_len, 0x1000);
940 if (*initrd_start == 0) {
941 puts ("ramdisk - allocation error\n");
944 show_boot_progress (12);
946 *initrd_end = *initrd_start + rd_len;
947 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
948 *initrd_start, *initrd_end);
950 memmove_wd ((void *)*initrd_start,
951 (void *)rd_data, rd_len, CHUNKSZ);
959 debug (" ramdisk load start = 0x%08lx, ramdisk load end = 0x%08lx\n",
960 *initrd_start, *initrd_end);
969 * boot_get_cmdline - allocate and initialize kernel cmdline
970 * @lmb: pointer to lmb handle, will be used for memory mgmt
971 * @cmd_start: pointer to a ulong variable, will hold cmdline start
972 * @cmd_end: pointer to a ulong variable, will hold cmdline end
973 * @bootmap_base: ulong variable, holds offset in physical memory to
976 * boot_get_cmdline() allocates space for kernel command line below
977 * BOOTMAPSZ + bootmap_base address. If "bootargs" U-boot environemnt
978 * variable is present its contents is copied to allocated kernel
985 int boot_get_cmdline (struct lmb *lmb, ulong *cmd_start, ulong *cmd_end,
991 cmdline = (char *)lmb_alloc_base(lmb, CFG_BARGSIZE, 0xf,
992 CFG_BOOTMAPSZ + bootmap_base);
997 if ((s = getenv("bootargs")) == NULL)
1002 *cmd_start = (ulong) & cmdline[0];
1003 *cmd_end = *cmd_start + strlen(cmdline);
1005 debug ("## cmdline at 0x%08lx ... 0x%08lx\n", *cmd_start, *cmd_end);
1011 * boot_get_kbd - allocate and initialize kernel copy of board info
1012 * @lmb: pointer to lmb handle, will be used for memory mgmt
1013 * @kbd: double pointer to board info data
1014 * @bootmap_base: ulong variable, holds offset in physical memory to
1017 * boot_get_kbd() allocates space for kernel copy of board info data below
1018 * BOOTMAPSZ + bootmap_base address and kernel board info is initialized with
1019 * the current u-boot board info data.
1025 int boot_get_kbd (struct lmb *lmb, bd_t **kbd, ulong bootmap_base)
1027 *kbd = (bd_t *)lmb_alloc_base(lmb, sizeof(bd_t), 0xf,
1028 CFG_BOOTMAPSZ + bootmap_base);
1034 debug ("## kernel board info at 0x%08lx\n", (ulong)*kbd);
1036 #if defined(DEBUG) && defined(CONFIG_CMD_BDI)
1037 do_bdinfo(NULL, 0, 0, NULL);
1042 #endif /* CONFIG_PPC || CONFIG_M68K */
1044 #if defined(CONFIG_FIT)
1045 /*****************************************************************************/
1046 /* New uImage format routines */
1047 /*****************************************************************************/
1048 static int fit_parse_spec (const char *spec, char sepc, ulong addr_curr,
1049 ulong *addr, const char **name)
1056 sep = strchr (spec, sepc);
1059 *addr = simple_strtoul (spec, NULL, 16);
1069 * fit_parse_conf - parse FIT configuration spec
1070 * @spec: input string, containing configuration spec
1071 * @add_curr: current image address (to be used as a possible default)
1072 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1074 * @conf_name double pointer to a char, will hold pointer to a configuration
1077 * fit_parse_conf() expects configuration spec in the for of [<addr>]#<conf>,
1078 * where <addr> is a FIT image address that contains configuration
1079 * with a <conf> unit name.
1081 * Address part is optional, and if omitted default add_curr will
1085 * 1 if spec is a valid configuration string,
1086 * addr and conf_name are set accordingly
1089 inline int fit_parse_conf (const char *spec, ulong addr_curr,
1090 ulong *addr, const char **conf_name)
1092 return fit_parse_spec (spec, '#', addr_curr, addr, conf_name);
1096 * fit_parse_subimage - parse FIT subimage spec
1097 * @spec: input string, containing subimage spec
1098 * @add_curr: current image address (to be used as a possible default)
1099 * @addr: pointer to a ulong variable, will hold FIT image address of a given
1101 * @image_name: double pointer to a char, will hold pointer to a subimage name
1103 * fit_parse_subimage() expects subimage spec in the for of
1104 * [<addr>]:<subimage>, where <addr> is a FIT image address that contains
1105 * subimage with a <subimg> unit name.
1107 * Address part is optional, and if omitted default add_curr will
1111 * 1 if spec is a valid subimage string,
1112 * addr and image_name are set accordingly
1115 inline int fit_parse_subimage (const char *spec, ulong addr_curr,
1116 ulong *addr, const char **image_name)
1118 return fit_parse_spec (spec, ':', addr_curr, addr, image_name);
1121 #endif /* CONFIG_FIT */
1122 #endif /* !USE_HOSTCC */