2 * (C) Copyright 2000-2009
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
33 #include <u-boot/zlib.h>
35 #include <environment.h>
37 #include <linux/ctype.h>
38 #include <asm/byteorder.h>
40 #if defined(CONFIG_CMD_USB)
44 #ifdef CONFIG_SYS_HUSH_PARSER
48 #if defined(CONFIG_OF_LIBFDT)
51 #include <fdt_support.h>
55 #include <lzma/LzmaTypes.h>
56 #include <lzma/LzmaDec.h>
57 #include <lzma/LzmaTools.h>
58 #endif /* CONFIG_LZMA */
61 #include <linux/lzo.h>
62 #endif /* CONFIG_LZO */
64 DECLARE_GLOBAL_DATA_PTR;
66 extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
67 #ifndef CONFIG_SYS_BOOTM_LEN
68 #define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
72 extern void bz_internal_error(int);
75 #if defined(CONFIG_CMD_IMI)
76 static int image_info (unsigned long addr);
79 #if defined(CONFIG_CMD_IMLS)
81 extern flash_info_t flash_info[]; /* info for FLASH chips */
82 static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
85 #ifdef CONFIG_SILENT_CONSOLE
86 static void fixup_silent_linux (void);
89 static image_header_t *image_get_kernel (ulong img_addr, int verify);
90 #if defined(CONFIG_FIT)
91 static int fit_check_kernel (const void *fit, int os_noffset, int verify);
94 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
95 bootm_headers_t *images, ulong *os_data, ulong *os_len);
96 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
99 * Continue booting an OS image; caller already has:
100 * - copied image header to global variable `header'
101 * - checked header magic number, checksums (both header & image),
102 * - verified image architecture (PPC) and type (KERNEL or MULTI),
103 * - loaded (first part of) image to header load address,
104 * - disabled interrupts.
106 typedef int boot_os_fn (int flag, int argc, char *argv[],
107 bootm_headers_t *images); /* pointers to os/initrd/fdt */
109 #define CONFIG_BOOTM_LINUX 1
110 #define CONFIG_BOOTM_NETBSD 1
111 #define CONFIG_BOOTM_RTEMS 1
113 #ifdef CONFIG_BOOTM_LINUX
114 extern boot_os_fn do_bootm_linux;
116 #ifdef CONFIG_BOOTM_NETBSD
117 static boot_os_fn do_bootm_netbsd;
119 #if defined(CONFIG_LYNXKDI)
120 static boot_os_fn do_bootm_lynxkdi;
121 extern void lynxkdi_boot (image_header_t *);
123 #ifdef CONFIG_BOOTM_RTEMS
124 static boot_os_fn do_bootm_rtems;
126 #if defined(CONFIG_CMD_ELF)
127 static boot_os_fn do_bootm_vxworks;
128 static boot_os_fn do_bootm_qnxelf;
129 int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
130 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
132 #if defined(CONFIG_INTEGRITY)
133 static boot_os_fn do_bootm_integrity;
136 boot_os_fn * boot_os[] = {
137 #ifdef CONFIG_BOOTM_LINUX
138 [IH_OS_LINUX] = do_bootm_linux,
140 #ifdef CONFIG_BOOTM_NETBSD
141 [IH_OS_NETBSD] = do_bootm_netbsd,
143 #ifdef CONFIG_LYNXKDI
144 [IH_OS_LYNXOS] = do_bootm_lynxkdi,
146 #ifdef CONFIG_BOOTM_RTEMS
147 [IH_OS_RTEMS] = do_bootm_rtems,
149 #if defined(CONFIG_CMD_ELF)
150 [IH_OS_VXWORKS] = do_bootm_vxworks,
151 [IH_OS_QNX] = do_bootm_qnxelf,
153 #ifdef CONFIG_INTEGRITY
154 [IH_OS_INTEGRITY] = do_bootm_integrity,
158 ulong load_addr = CONFIG_SYS_LOAD_ADDR; /* Default Load Address */
159 static bootm_headers_t images; /* pointers to os/initrd/fdt images */
161 void __board_lmb_reserve(struct lmb *lmb)
163 /* please define platform specific board_lmb_reserve() */
165 void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
167 void __arch_lmb_reserve(struct lmb *lmb)
169 /* please define platform specific arch_lmb_reserve() */
171 void arch_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__arch_lmb_reserve")));
173 /* Allow for arch specific config before we boot */
174 void __arch_preboot_os(void)
176 /* please define platform specific arch_preboot_os() */
178 void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
181 #define IH_INITRD_ARCH IH_ARCH_ARM
182 #elif defined(__avr32__)
183 #define IH_INITRD_ARCH IH_ARCH_AVR32
184 #elif defined(__bfin__)
185 #define IH_INITRD_ARCH IH_ARCH_BLACKFIN
186 #elif defined(__I386__)
187 #define IH_INITRD_ARCH IH_ARCH_I386
188 #elif defined(__M68K__)
189 #define IH_INITRD_ARCH IH_ARCH_M68K
190 #elif defined(__microblaze__)
191 #define IH_INITRD_ARCH IH_ARCH_MICROBLAZE
192 #elif defined(__mips__)
193 #define IH_INITRD_ARCH IH_ARCH_MIPS
194 #elif defined(__nios__)
195 #define IH_INITRD_ARCH IH_ARCH_NIOS
196 #elif defined(__nios2__)
197 #define IH_INITRD_ARCH IH_ARCH_NIOS2
198 #elif defined(__PPC__)
199 #define IH_INITRD_ARCH IH_ARCH_PPC
200 #elif defined(__sh__)
201 #define IH_INITRD_ARCH IH_ARCH_SH
202 #elif defined(__sparc__)
203 #define IH_INITRD_ARCH IH_ARCH_SPARC
205 # error Unknown CPU type
208 static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
211 phys_size_t mem_size;
215 memset ((void *)&images, 0, sizeof (images));
216 images.verify = getenv_yesno ("verify");
218 lmb_init(&images.lmb);
220 mem_start = getenv_bootm_low();
221 mem_size = getenv_bootm_size();
223 lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
225 arch_lmb_reserve(&images.lmb);
226 board_lmb_reserve(&images.lmb);
228 /* get kernel image header, start address and length */
229 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
230 &images, &images.os.image_start, &images.os.image_len);
231 if (images.os.image_len == 0) {
232 puts ("ERROR: can't get kernel image!\n");
236 /* get image parameters */
237 switch (genimg_get_format (os_hdr)) {
238 case IMAGE_FORMAT_LEGACY:
239 images.os.type = image_get_type (os_hdr);
240 images.os.comp = image_get_comp (os_hdr);
241 images.os.os = image_get_os (os_hdr);
243 images.os.end = image_get_image_end (os_hdr);
244 images.os.load = image_get_load (os_hdr);
246 #if defined(CONFIG_FIT)
247 case IMAGE_FORMAT_FIT:
248 if (fit_image_get_type (images.fit_hdr_os,
249 images.fit_noffset_os, &images.os.type)) {
250 puts ("Can't get image type!\n");
251 show_boot_progress (-109);
255 if (fit_image_get_comp (images.fit_hdr_os,
256 images.fit_noffset_os, &images.os.comp)) {
257 puts ("Can't get image compression!\n");
258 show_boot_progress (-110);
262 if (fit_image_get_os (images.fit_hdr_os,
263 images.fit_noffset_os, &images.os.os)) {
264 puts ("Can't get image OS!\n");
265 show_boot_progress (-111);
269 images.os.end = fit_get_end (images.fit_hdr_os);
271 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
273 puts ("Can't get image load address!\n");
274 show_boot_progress (-112);
280 puts ("ERROR: unknown image format type!\n");
284 /* find kernel entry point */
285 if (images.legacy_hdr_valid) {
286 images.ep = image_get_ep (&images.legacy_hdr_os_copy);
287 #if defined(CONFIG_FIT)
288 } else if (images.fit_uname_os) {
289 ret = fit_image_get_entry (images.fit_hdr_os,
290 images.fit_noffset_os, &images.ep);
292 puts ("Can't get entry point property!\n");
297 puts ("Could not find kernel entry point!\n");
301 if (images.os.os == IH_OS_LINUX) {
303 ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
304 &images.rd_start, &images.rd_end);
306 puts ("Ramdisk image is corrupt or invalid\n");
310 #if defined(CONFIG_OF_LIBFDT)
311 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
312 /* find flattened device tree */
313 ret = boot_get_fdt (flag, argc, argv, &images,
314 &images.ft_addr, &images.ft_len);
316 puts ("Could not find a valid device tree\n");
320 set_working_fdt_addr(images.ft_addr);
325 images.os.start = (ulong)os_hdr;
326 images.state = BOOTM_STATE_START;
331 #define BOOTM_ERR_RESET -1
332 #define BOOTM_ERR_OVERLAP -2
333 #define BOOTM_ERR_UNIMPLEMENTED -3
334 static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
336 uint8_t comp = os.comp;
337 ulong load = os.load;
338 ulong blob_start = os.start;
339 ulong blob_end = os.end;
340 ulong image_start = os.image_start;
341 ulong image_len = os.image_len;
342 uint unc_len = CONFIG_SYS_BOOTM_LEN;
344 const char *type_name = genimg_get_type_name (os.type);
348 if (load == blob_start) {
349 printf (" XIP %s ... ", type_name);
351 printf (" Loading %s ... ", type_name);
353 if (load != image_start) {
354 memmove_wd ((void *)load,
355 (void *)image_start, image_len, CHUNKSZ);
358 *load_end = load + image_len;
362 printf (" Uncompressing %s ... ", type_name);
363 if (gunzip ((void *)load, unc_len,
364 (uchar *)image_start, &image_len) != 0) {
365 puts ("GUNZIP: uncompress, out-of-mem or overwrite error "
366 "- must RESET board to recover\n");
368 show_boot_progress (-6);
369 return BOOTM_ERR_RESET;
372 *load_end = load + image_len;
376 printf (" Uncompressing %s ... ", type_name);
378 * If we've got less than 4 MB of malloc() space,
379 * use slower decompression algorithm which requires
380 * at most 2300 KB of memory.
382 int i = BZ2_bzBuffToBuffDecompress ((char*)load,
383 &unc_len, (char *)image_start, image_len,
384 CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
386 printf ("BUNZIP2: uncompress or overwrite error %d "
387 "- must RESET board to recover\n", i);
389 show_boot_progress (-6);
390 return BOOTM_ERR_RESET;
393 *load_end = load + unc_len;
395 #endif /* CONFIG_BZIP2 */
398 printf (" Uncompressing %s ... ", type_name);
400 int ret = lzmaBuffToBuffDecompress(
401 (unsigned char *)load, &unc_len,
402 (unsigned char *)image_start, image_len);
404 printf ("LZMA: uncompress or overwrite error %d "
405 "- must RESET board to recover\n", ret);
406 show_boot_progress (-6);
407 return BOOTM_ERR_RESET;
409 *load_end = load + unc_len;
411 #endif /* CONFIG_LZMA */
414 printf (" Uncompressing %s ... ", type_name);
416 int ret = lzop_decompress((const unsigned char *)image_start,
417 image_len, (unsigned char *)load,
419 if (ret != LZO_E_OK) {
420 printf ("LZO: uncompress or overwrite error %d "
421 "- must RESET board to recover\n", ret);
423 show_boot_progress (-6);
424 return BOOTM_ERR_RESET;
427 *load_end = load + unc_len;
429 #endif /* CONFIG_LZO */
431 printf ("Unimplemented compression type %d\n", comp);
432 return BOOTM_ERR_UNIMPLEMENTED;
435 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
437 show_boot_progress (7);
439 if ((load < blob_end) && (*load_end > blob_start)) {
440 debug ("images.os.start = 0x%lX, images.os.end = 0x%lx\n", blob_start, blob_end);
441 debug ("images.os.load = 0x%lx, load_end = 0x%lx\n", load, *load_end);
443 return BOOTM_ERR_OVERLAP;
449 static int bootm_start_standalone(ulong iflag, int argc, char *argv[])
452 int (*appl)(int, char *[]);
454 /* Don't start if "autostart" is set to "no" */
455 if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
457 sprintf(buf, "%lX", images.os.image_len);
458 setenv("filesize", buf);
461 appl = (int (*)(int, char *[]))ntohl(images.ep);
462 (*appl)(argc-1, &argv[1]);
467 /* we overload the cmd field with our state machine info instead of a
468 * function pointer */
469 cmd_tbl_t cmd_bootm_sub[] = {
470 U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
471 U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
472 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
473 U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
475 #ifdef CONFIG_OF_LIBFDT
476 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
478 U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
479 U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
480 U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
481 U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
484 int do_bootm_subcommand (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
491 c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
496 /* treat start special since it resets the state machine */
497 if (state == BOOTM_STATE_START) {
500 return bootm_start(cmdtp, flag, argc, argv);
503 /* Unrecognized command */
509 if (images.state >= state) {
510 printf ("Trying to execute a command out of order\n");
515 images.state |= state;
516 boot_fn = boot_os[images.os.os];
520 case BOOTM_STATE_START:
521 /* should never occur */
523 case BOOTM_STATE_LOADOS:
524 ret = bootm_load_os(images.os, &load_end, 0);
528 lmb_reserve(&images.lmb, images.os.load,
529 (load_end - images.os.load));
531 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
532 case BOOTM_STATE_RAMDISK:
534 ulong rd_len = images.rd_end - images.rd_start;
537 ret = boot_ramdisk_high(&images.lmb, images.rd_start,
538 rd_len, &images.initrd_start, &images.initrd_end);
542 sprintf(str, "%lx", images.initrd_start);
543 setenv("initrd_start", str);
544 sprintf(str, "%lx", images.initrd_end);
545 setenv("initrd_end", str);
549 #ifdef CONFIG_OF_LIBFDT
550 case BOOTM_STATE_FDT:
552 ulong bootmap_base = getenv_bootm_low();
553 ret = boot_relocate_fdt(&images.lmb, bootmap_base,
554 &images.ft_addr, &images.ft_len);
558 case BOOTM_STATE_OS_CMDLINE:
559 ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, &images);
561 printf ("cmdline subcommand not supported\n");
563 case BOOTM_STATE_OS_BD_T:
564 ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, &images);
566 printf ("bdt subcommand not supported\n");
568 case BOOTM_STATE_OS_PREP:
569 ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, &images);
571 printf ("prep subcommand not supported\n");
573 case BOOTM_STATE_OS_GO:
574 disable_interrupts();
576 boot_fn(BOOTM_STATE_OS_GO, argc, argv, &images);
583 /*******************************************************************/
584 /* bootm - boot application image from image in memory */
585 /*******************************************************************/
587 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
593 #ifndef CONFIG_RELOC_FIXUP_WORKS
594 static int relocated = 0;
596 /* relocate boot function table */
599 for (i = 0; i < ARRAY_SIZE(boot_os); i++)
600 if (boot_os[i] != NULL)
601 boot_os[i] += gd->reloc_off;
606 /* determine if we have a sub command */
610 simple_strtoul(argv[1], &endp, 16);
611 /* endp pointing to NULL means that argv[1] was just a
612 * valid number, pass it along to the normal bootm processing
614 * If endp is ':' or '#' assume a FIT identifier so pass
615 * along for normal processing.
617 * Right now we assume the first arg should never be '-'
619 if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
620 return do_bootm_subcommand(cmdtp, flag, argc, argv);
623 if (bootm_start(cmdtp, flag, argc, argv))
627 * We have reached the point of no return: we are going to
628 * overwrite all exception vector code, so we cannot easily
629 * recover from any failures any more...
631 iflag = disable_interrupts();
633 #if defined(CONFIG_CMD_USB)
635 * turn off USB to prevent the host controller from writing to the
636 * SDRAM while Linux is booting. This could happen (at least for OHCI
637 * controller), because the HCCA (Host Controller Communication Area)
638 * lies within the SDRAM and the host controller writes continously to
639 * this area (as busmaster!). The HccaFrameNumber is for example
640 * updated every 1 ms within the HCCA structure in SDRAM! For more
641 * details see the OpenHCI specification.
646 #ifdef CONFIG_AMIGAONEG3SE
648 * We've possible left the caches enabled during
649 * bios emulation, so turn them off again
655 ret = bootm_load_os(images.os, &load_end, 1);
658 if (ret == BOOTM_ERR_RESET)
659 do_reset (cmdtp, flag, argc, argv);
660 if (ret == BOOTM_ERR_OVERLAP) {
661 if (images.legacy_hdr_valid) {
662 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
663 puts ("WARNING: legacy format multi component "
664 "image overwritten\n");
666 puts ("ERROR: new format image overwritten - "
667 "must RESET the board to recover\n");
668 show_boot_progress (-113);
669 do_reset (cmdtp, flag, argc, argv);
672 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
675 show_boot_progress (-7);
680 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
682 if (images.os.type == IH_TYPE_STANDALONE) {
685 /* This may return when 'autostart' is 'no' */
686 bootm_start_standalone(iflag, argc, argv);
690 show_boot_progress (8);
692 #ifdef CONFIG_SILENT_CONSOLE
693 if (images.os.os == IH_OS_LINUX)
694 fixup_silent_linux();
697 boot_fn = boot_os[images.os.os];
699 if (boot_fn == NULL) {
702 printf ("ERROR: booting os '%s' (%d) is not supported\n",
703 genimg_get_os_name(images.os.os), images.os.os);
704 show_boot_progress (-8);
710 boot_fn(0, argc, argv, &images);
712 show_boot_progress (-9);
714 puts ("\n## Control returned to monitor - resetting...\n");
716 do_reset (cmdtp, flag, argc, argv);
722 * image_get_kernel - verify legacy format kernel image
723 * @img_addr: in RAM address of the legacy format image to be verified
724 * @verify: data CRC verification flag
726 * image_get_kernel() verifies legacy image integrity and returns pointer to
727 * legacy image header if image verification was completed successfully.
730 * pointer to a legacy image header if valid image was found
731 * otherwise return NULL
733 static image_header_t *image_get_kernel (ulong img_addr, int verify)
735 image_header_t *hdr = (image_header_t *)img_addr;
737 if (!image_check_magic(hdr)) {
738 puts ("Bad Magic Number\n");
739 show_boot_progress (-1);
742 show_boot_progress (2);
744 if (!image_check_hcrc (hdr)) {
745 puts ("Bad Header Checksum\n");
746 show_boot_progress (-2);
750 show_boot_progress (3);
751 image_print_contents (hdr);
754 puts (" Verifying Checksum ... ");
755 if (!image_check_dcrc (hdr)) {
756 printf ("Bad Data CRC\n");
757 show_boot_progress (-3);
762 show_boot_progress (4);
764 if (!image_check_target_arch (hdr)) {
765 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
766 show_boot_progress (-4);
773 * fit_check_kernel - verify FIT format kernel subimage
774 * @fit_hdr: pointer to the FIT image header
775 * os_noffset: kernel subimage node offset within FIT image
776 * @verify: data CRC verification flag
778 * fit_check_kernel() verifies integrity of the kernel subimage and from
779 * specified FIT image.
785 #if defined (CONFIG_FIT)
786 static int fit_check_kernel (const void *fit, int os_noffset, int verify)
788 fit_image_print (fit, os_noffset, " ");
791 puts (" Verifying Hash Integrity ... ");
792 if (!fit_image_check_hashes (fit, os_noffset)) {
793 puts ("Bad Data Hash\n");
794 show_boot_progress (-104);
799 show_boot_progress (105);
801 if (!fit_image_check_target_arch (fit, os_noffset)) {
802 puts ("Unsupported Architecture\n");
803 show_boot_progress (-105);
807 show_boot_progress (106);
808 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
809 puts ("Not a kernel image\n");
810 show_boot_progress (-106);
814 show_boot_progress (107);
817 #endif /* CONFIG_FIT */
820 * boot_get_kernel - find kernel image
821 * @os_data: pointer to a ulong variable, will hold os data start address
822 * @os_len: pointer to a ulong variable, will hold os data length
824 * boot_get_kernel() tries to find a kernel image, verifies its integrity
825 * and locates kernel data.
828 * pointer to image header if valid image was found, plus kernel start
829 * address and length, otherwise NULL
831 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
832 bootm_headers_t *images, ulong *os_data, ulong *os_len)
836 #if defined(CONFIG_FIT)
838 const char *fit_uname_config = NULL;
839 const char *fit_uname_kernel = NULL;
846 /* find out kernel image address */
848 img_addr = load_addr;
849 debug ("* kernel: default image load address = 0x%08lx\n",
851 #if defined(CONFIG_FIT)
852 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
853 &fit_uname_config)) {
854 debug ("* kernel: config '%s' from image at 0x%08lx\n",
855 fit_uname_config, img_addr);
856 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
857 &fit_uname_kernel)) {
858 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
859 fit_uname_kernel, img_addr);
862 img_addr = simple_strtoul(argv[1], NULL, 16);
863 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
866 show_boot_progress (1);
868 /* copy from dataflash if needed */
869 img_addr = genimg_get_image (img_addr);
871 /* check image type, for FIT images get FIT kernel node */
872 *os_data = *os_len = 0;
873 switch (genimg_get_format ((void *)img_addr)) {
874 case IMAGE_FORMAT_LEGACY:
875 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
877 hdr = image_get_kernel (img_addr, images->verify);
880 show_boot_progress (5);
882 /* get os_data and os_len */
883 switch (image_get_type (hdr)) {
885 *os_data = image_get_data (hdr);
886 *os_len = image_get_data_size (hdr);
889 image_multi_getimg (hdr, 0, os_data, os_len);
891 case IH_TYPE_STANDALONE:
893 hdr->ih_load = htonl(simple_strtoul(argv[2], NULL, 16));
895 *os_data = image_get_data (hdr);
896 *os_len = image_get_data_size (hdr);
899 printf ("Wrong Image Type for %s command\n", cmdtp->name);
900 show_boot_progress (-5);
905 * copy image header to allow for image overwrites during kernel
908 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
910 /* save pointer to image header */
911 images->legacy_hdr_os = hdr;
913 images->legacy_hdr_valid = 1;
914 show_boot_progress (6);
916 #if defined(CONFIG_FIT)
917 case IMAGE_FORMAT_FIT:
918 fit_hdr = (void *)img_addr;
919 printf ("## Booting kernel from FIT Image at %08lx ...\n",
922 if (!fit_check_format (fit_hdr)) {
923 puts ("Bad FIT kernel image format!\n");
924 show_boot_progress (-100);
927 show_boot_progress (100);
929 if (!fit_uname_kernel) {
931 * no kernel image node unit name, try to get config
932 * node first. If config unit node name is NULL
933 * fit_conf_get_node() will try to find default config node
935 show_boot_progress (101);
936 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
937 if (cfg_noffset < 0) {
938 show_boot_progress (-101);
941 /* save configuration uname provided in the first
944 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
945 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
946 show_boot_progress (103);
948 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
949 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
951 /* get kernel component image node offset */
952 show_boot_progress (102);
953 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
955 if (os_noffset < 0) {
956 show_boot_progress (-103);
960 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
962 show_boot_progress (104);
963 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
966 /* get kernel image data address and length */
967 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
968 puts ("Could not find kernel subimage data!\n");
969 show_boot_progress (-107);
972 show_boot_progress (108);
975 *os_data = (ulong)data;
976 images->fit_hdr_os = fit_hdr;
977 images->fit_uname_os = fit_uname_kernel;
978 images->fit_noffset_os = os_noffset;
982 printf ("Wrong Image Format for %s command\n", cmdtp->name);
983 show_boot_progress (-108);
987 debug (" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
988 *os_data, *os_len, *os_len);
990 return (void *)img_addr;
994 bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
995 "boot application image from memory",
996 "[addr [arg ...]]\n - boot application image stored in memory\n"
997 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
998 "\t'arg' can be the address of an initrd image\n"
999 #if defined(CONFIG_OF_LIBFDT)
1000 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
1001 "\ta third argument is required which is the address of the\n"
1002 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1003 "\tuse a '-' for the second argument. If you do not pass a third\n"
1004 "\ta bd_info struct will be passed instead\n"
1006 #if defined(CONFIG_FIT)
1007 "\t\nFor the new multi component uImage format (FIT) addresses\n"
1008 "\tmust be extened to include component or configuration unit name:\n"
1009 "\taddr:<subimg_uname> - direct component image specification\n"
1010 "\taddr#<conf_uname> - configuration specification\n"
1011 "\tUse iminfo command to get the list of existing component\n"
1012 "\timages and configurations.\n"
1014 "\nSub-commands to do part of the bootm sequence. The sub-commands "
1016 "issued in the order below (it's ok to not issue all sub-commands):\n"
1017 "\tstart [addr [arg ...]]\n"
1018 "\tloados - load OS image\n"
1019 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
1020 "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
1022 #if defined(CONFIG_OF_LIBFDT)
1023 "\tfdt - relocate flat device tree\n"
1025 "\tbdt - OS specific bd_t processing\n"
1026 "\tcmdline - OS specific command line processing/setup\n"
1027 "\tprep - OS specific prep before relocation or go\n"
1031 /*******************************************************************/
1032 /* bootd - boot default image */
1033 /*******************************************************************/
1034 #if defined(CONFIG_CMD_BOOTD)
1035 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1039 #ifndef CONFIG_SYS_HUSH_PARSER
1040 if (run_command (getenv ("bootcmd"), flag) < 0)
1043 if (parse_string_outer (getenv ("bootcmd"),
1044 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
1051 boot, 1, 1, do_bootd,
1052 "boot default, i.e., run 'bootcmd'",
1056 /* keep old command name "bootd" for backward compatibility */
1058 bootd, 1, 1, do_bootd,
1059 "boot default, i.e., run 'bootcmd'",
1066 /*******************************************************************/
1067 /* iminfo - print header info for a requested image */
1068 /*******************************************************************/
1069 #if defined(CONFIG_CMD_IMI)
1070 int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1077 return image_info (load_addr);
1080 for (arg = 1; arg < argc; ++arg) {
1081 addr = simple_strtoul (argv[arg], NULL, 16);
1082 if (image_info (addr) != 0)
1088 static int image_info (ulong addr)
1090 void *hdr = (void *)addr;
1092 printf ("\n## Checking Image at %08lx ...\n", addr);
1094 switch (genimg_get_format (hdr)) {
1095 case IMAGE_FORMAT_LEGACY:
1096 puts (" Legacy image found\n");
1097 if (!image_check_magic (hdr)) {
1098 puts (" Bad Magic Number\n");
1102 if (!image_check_hcrc (hdr)) {
1103 puts (" Bad Header Checksum\n");
1107 image_print_contents (hdr);
1109 puts (" Verifying Checksum ... ");
1110 if (!image_check_dcrc (hdr)) {
1111 puts (" Bad Data CRC\n");
1116 #if defined(CONFIG_FIT)
1117 case IMAGE_FORMAT_FIT:
1118 puts (" FIT image found\n");
1120 if (!fit_check_format (hdr)) {
1121 puts ("Bad FIT image format!\n");
1125 fit_print_contents (hdr);
1127 if (!fit_all_image_check_hashes (hdr)) {
1128 puts ("Bad hash in FIT image!\n");
1135 puts ("Unknown image format!\n");
1143 iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
1144 "print header information for application image",
1146 " - print header information for application image starting at\n"
1147 " address 'addr' in memory; this includes verification of the\n"
1148 " image contents (magic number, header and payload checksums)"
1153 /*******************************************************************/
1154 /* imls - list all images found in flash */
1155 /*******************************************************************/
1156 #if defined(CONFIG_CMD_IMLS)
1157 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1163 for (i = 0, info = &flash_info[0];
1164 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
1166 if (info->flash_id == FLASH_UNKNOWN)
1168 for (j = 0; j < info->sector_count; ++j) {
1170 hdr = (void *)info->start[j];
1174 switch (genimg_get_format (hdr)) {
1175 case IMAGE_FORMAT_LEGACY:
1176 if (!image_check_hcrc (hdr))
1179 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
1180 image_print_contents (hdr);
1182 puts (" Verifying Checksum ... ");
1183 if (!image_check_dcrc (hdr)) {
1184 puts ("Bad Data CRC\n");
1189 #if defined(CONFIG_FIT)
1190 case IMAGE_FORMAT_FIT:
1191 if (!fit_check_format (hdr))
1194 printf ("FIT Image at %08lX:\n", (ulong)hdr);
1195 fit_print_contents (hdr);
1211 imls, 1, 1, do_imls,
1212 "list all images found in flash",
1214 " - Prints information about all images found at sector\n"
1215 " boundaries in flash."
1219 /*******************************************************************/
1220 /* helper routines */
1221 /*******************************************************************/
1222 #ifdef CONFIG_SILENT_CONSOLE
1223 static void fixup_silent_linux ()
1225 char buf[256], *start, *end;
1226 char *cmdline = getenv ("bootargs");
1228 /* Only fix cmdline when requested */
1229 if (!(gd->flags & GD_FLG_SILENT))
1232 debug ("before silent fix-up: %s\n", cmdline);
1234 if ((start = strstr (cmdline, "console=")) != NULL) {
1235 end = strchr (start, ' ');
1236 strncpy (buf, cmdline, (start - cmdline + 8));
1238 strcpy (buf + (start - cmdline + 8), end);
1240 buf[start - cmdline + 8] = '\0';
1242 strcpy (buf, cmdline);
1243 strcat (buf, " console=");
1246 strcpy (buf, "console=");
1249 setenv ("bootargs", buf);
1250 debug ("after silent fix-up: %s\n", buf);
1252 #endif /* CONFIG_SILENT_CONSOLE */
1255 /*******************************************************************/
1256 /* OS booting routines */
1257 /*******************************************************************/
1259 #ifdef CONFIG_BOOTM_NETBSD
1260 static int do_bootm_netbsd (int flag, int argc, char *argv[],
1261 bootm_headers_t *images)
1263 void (*loader)(bd_t *, image_header_t *, char *, char *);
1264 image_header_t *os_hdr, *hdr;
1265 ulong kernel_data, kernel_len;
1269 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1272 #if defined(CONFIG_FIT)
1273 if (!images->legacy_hdr_valid) {
1274 fit_unsupported_reset ("NetBSD");
1278 hdr = images->legacy_hdr_os;
1281 * Booting a (NetBSD) kernel image
1283 * This process is pretty similar to a standalone application:
1284 * The (first part of an multi-) image must be a stage-2 loader,
1285 * which in turn is responsible for loading & invoking the actual
1286 * kernel. The only differences are the parameters being passed:
1287 * besides the board info strucure, the loader expects a command
1288 * line, the name of the console device, and (optionally) the
1289 * address of the original image header.
1292 if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1293 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
1299 #if defined (CONFIG_8xx_CONS_SMC1)
1301 #elif defined (CONFIG_8xx_CONS_SMC2)
1303 #elif defined (CONFIG_8xx_CONS_SCC2)
1305 #elif defined (CONFIG_8xx_CONS_SCC3)
1313 for (i = 2, len = 0; i < argc; i += 1)
1314 len += strlen (argv[i]) + 1;
1315 cmdline = malloc (len);
1317 for (i = 2, len = 0; i < argc; i += 1) {
1319 cmdline[len++] = ' ';
1320 strcpy (&cmdline[len], argv[i]);
1321 len += strlen (argv[i]);
1323 } else if ((cmdline = getenv ("bootargs")) == NULL) {
1327 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
1329 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
1332 show_boot_progress (15);
1335 * NetBSD Stage-2 Loader Parameters:
1336 * r3: ptr to board info data
1338 * r5: console device
1339 * r6: boot args string
1341 (*loader) (gd->bd, os_hdr, consdev, cmdline);
1345 #endif /* CONFIG_BOOTM_NETBSD*/
1347 #ifdef CONFIG_LYNXKDI
1348 static int do_bootm_lynxkdi (int flag, int argc, char *argv[],
1349 bootm_headers_t *images)
1351 image_header_t *hdr = &images->legacy_hdr_os_copy;
1353 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1356 #if defined(CONFIG_FIT)
1357 if (!images->legacy_hdr_valid) {
1358 fit_unsupported_reset ("Lynx");
1363 lynxkdi_boot ((image_header_t *)hdr);
1367 #endif /* CONFIG_LYNXKDI */
1369 #ifdef CONFIG_BOOTM_RTEMS
1370 static int do_bootm_rtems (int flag, int argc, char *argv[],
1371 bootm_headers_t *images)
1373 void (*entry_point)(bd_t *);
1375 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1378 #if defined(CONFIG_FIT)
1379 if (!images->legacy_hdr_valid) {
1380 fit_unsupported_reset ("RTEMS");
1385 entry_point = (void (*)(bd_t *))images->ep;
1387 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1388 (ulong)entry_point);
1390 show_boot_progress (15);
1394 * r3: ptr to board info data
1396 (*entry_point)(gd->bd);
1400 #endif /* CONFIG_BOOTM_RTEMS */
1402 #if defined(CONFIG_CMD_ELF)
1403 static int do_bootm_vxworks (int flag, int argc, char *argv[],
1404 bootm_headers_t *images)
1408 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1411 #if defined(CONFIG_FIT)
1412 if (!images->legacy_hdr_valid) {
1413 fit_unsupported_reset ("VxWorks");
1418 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1419 setenv("loadaddr", str);
1420 do_bootvx(NULL, 0, 0, NULL);
1425 static int do_bootm_qnxelf(int flag, int argc, char *argv[],
1426 bootm_headers_t *images)
1428 char *local_args[2];
1431 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1434 #if defined(CONFIG_FIT)
1435 if (!images->legacy_hdr_valid) {
1436 fit_unsupported_reset ("QNX");
1441 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1442 local_args[0] = argv[0];
1443 local_args[1] = str; /* and provide it via the arguments */
1444 do_bootelf(NULL, 0, 2, local_args);
1450 #ifdef CONFIG_INTEGRITY
1451 static int do_bootm_integrity (int flag, int argc, char *argv[],
1452 bootm_headers_t *images)
1454 void (*entry_point)(void);
1456 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1459 #if defined(CONFIG_FIT)
1460 if (!images->legacy_hdr_valid) {
1461 fit_unsupported_reset ("INTEGRITY");
1466 entry_point = (void (*)(void))images->ep;
1468 printf ("## Transferring control to INTEGRITY (at address %08lx) ...\n",
1469 (ulong)entry_point);
1471 show_boot_progress (15);
1474 * INTEGRITY Parameters: