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>
39 #include <linux/compiler.h>
41 #if defined(CONFIG_CMD_USB)
45 #ifdef CONFIG_SYS_HUSH_PARSER
49 #if defined(CONFIG_OF_LIBFDT)
52 #include <fdt_support.h>
56 #include <lzma/LzmaTypes.h>
57 #include <lzma/LzmaDec.h>
58 #include <lzma/LzmaTools.h>
59 #endif /* CONFIG_LZMA */
62 #include <linux/lzo.h>
63 #endif /* CONFIG_LZO */
65 DECLARE_GLOBAL_DATA_PTR;
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 #include <mtd/cfi_flash.h>
82 extern flash_info_t flash_info[]; /* info for FLASH chips */
83 static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
86 #ifdef CONFIG_SILENT_CONSOLE
87 static void fixup_silent_linux(void);
90 static image_header_t *image_get_kernel(ulong img_addr, int verify);
91 #if defined(CONFIG_FIT)
92 static int fit_check_kernel(const void *fit, int os_noffset, int verify);
95 static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
96 char * const argv[], bootm_headers_t *images,
97 ulong *os_data, ulong *os_len);
100 * Continue booting an OS image; caller already has:
101 * - copied image header to global variable `header'
102 * - checked header magic number, checksums (both header & image),
103 * - verified image architecture (PPC) and type (KERNEL or MULTI),
104 * - loaded (first part of) image to header load address,
105 * - disabled interrupts.
107 typedef int boot_os_fn(int flag, int argc, char * const argv[],
108 bootm_headers_t *images); /* pointers to os/initrd/fdt */
110 #ifdef CONFIG_BOOTM_LINUX
111 extern boot_os_fn do_bootm_linux;
113 #ifdef CONFIG_BOOTM_NETBSD
114 static boot_os_fn do_bootm_netbsd;
116 #if defined(CONFIG_LYNXKDI)
117 static boot_os_fn do_bootm_lynxkdi;
118 extern void lynxkdi_boot(image_header_t *);
120 #ifdef CONFIG_BOOTM_RTEMS
121 static boot_os_fn do_bootm_rtems;
123 #if defined(CONFIG_BOOTM_OSE)
124 static boot_os_fn do_bootm_ose;
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 * const argv[]);
130 int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
132 #if defined(CONFIG_INTEGRITY)
133 static boot_os_fn do_bootm_integrity;
136 static 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_BOOTM_OSE)
150 [IH_OS_OSE] = do_bootm_ose,
152 #if defined(CONFIG_CMD_ELF)
153 [IH_OS_VXWORKS] = do_bootm_vxworks,
154 [IH_OS_QNX] = do_bootm_qnxelf,
156 #ifdef CONFIG_INTEGRITY
157 [IH_OS_INTEGRITY] = do_bootm_integrity,
161 bootm_headers_t images; /* pointers to os/initrd/fdt images */
163 /* Allow for arch specific config before we boot */
164 void __arch_preboot_os(void)
166 /* please define platform specific arch_preboot_os() */
168 void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
170 #define IH_INITRD_ARCH IH_ARCH_DEFAULT
172 static void bootm_start_lmb(void)
176 phys_size_t mem_size;
178 lmb_init(&images.lmb);
180 mem_start = getenv_bootm_low();
181 mem_size = getenv_bootm_size();
183 lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
185 arch_lmb_reserve(&images.lmb);
186 board_lmb_reserve(&images.lmb);
188 # define lmb_reserve(lmb, base, size)
192 static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
197 memset((void *)&images, 0, sizeof(images));
198 images.verify = getenv_yesno("verify");
202 /* get kernel image header, start address and length */
203 os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
204 &images, &images.os.image_start, &images.os.image_len);
205 if (images.os.image_len == 0) {
206 puts("ERROR: can't get kernel image!\n");
210 /* get image parameters */
211 switch (genimg_get_format(os_hdr)) {
212 case IMAGE_FORMAT_LEGACY:
213 images.os.type = image_get_type(os_hdr);
214 images.os.comp = image_get_comp(os_hdr);
215 images.os.os = image_get_os(os_hdr);
217 images.os.end = image_get_image_end(os_hdr);
218 images.os.load = image_get_load(os_hdr);
220 #if defined(CONFIG_FIT)
221 case IMAGE_FORMAT_FIT:
222 if (fit_image_get_type(images.fit_hdr_os,
223 images.fit_noffset_os, &images.os.type)) {
224 puts("Can't get image type!\n");
225 show_boot_progress(-109);
229 if (fit_image_get_comp(images.fit_hdr_os,
230 images.fit_noffset_os, &images.os.comp)) {
231 puts("Can't get image compression!\n");
232 show_boot_progress(-110);
236 if (fit_image_get_os(images.fit_hdr_os,
237 images.fit_noffset_os, &images.os.os)) {
238 puts("Can't get image OS!\n");
239 show_boot_progress(-111);
243 images.os.end = fit_get_end(images.fit_hdr_os);
245 if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os,
247 puts("Can't get image load address!\n");
248 show_boot_progress(-112);
254 puts("ERROR: unknown image format type!\n");
258 /* find kernel entry point */
259 if (images.legacy_hdr_valid) {
260 images.ep = image_get_ep(&images.legacy_hdr_os_copy);
261 #if defined(CONFIG_FIT)
262 } else if (images.fit_uname_os) {
263 ret = fit_image_get_entry(images.fit_hdr_os,
264 images.fit_noffset_os, &images.ep);
266 puts("Can't get entry point property!\n");
271 puts("Could not find kernel entry point!\n");
275 if (((images.os.type == IH_TYPE_KERNEL) ||
276 (images.os.type == IH_TYPE_MULTI)) &&
277 (images.os.os == IH_OS_LINUX)) {
279 ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH,
280 &images.rd_start, &images.rd_end);
282 puts("Ramdisk image is corrupt or invalid\n");
286 #if defined(CONFIG_OF_LIBFDT)
287 /* find flattened device tree */
288 ret = boot_get_fdt(flag, argc, argv, &images,
289 &images.ft_addr, &images.ft_len);
291 puts("Could not find a valid device tree\n");
295 set_working_fdt_addr(images.ft_addr);
299 images.os.start = (ulong)os_hdr;
300 images.state = BOOTM_STATE_START;
305 #define BOOTM_ERR_RESET -1
306 #define BOOTM_ERR_OVERLAP -2
307 #define BOOTM_ERR_UNIMPLEMENTED -3
308 static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
310 uint8_t comp = os.comp;
311 ulong load = os.load;
312 ulong blob_start = os.start;
313 ulong blob_end = os.end;
314 ulong image_start = os.image_start;
315 ulong image_len = os.image_len;
316 __maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN;
317 #if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
319 #endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
321 const char *type_name = genimg_get_type_name(os.type);
325 if (load == blob_start || load == image_start) {
326 printf(" XIP %s ... ", type_name);
328 printf(" Loading %s ... ", type_name);
329 memmove_wd((void *)load, (void *)image_start,
332 *load_end = load + image_len;
337 printf(" Uncompressing %s ... ", type_name);
338 if (gunzip((void *)load, unc_len,
339 (uchar *)image_start, &image_len) != 0) {
340 puts("GUNZIP: uncompress, out-of-mem or overwrite "
341 "error - must RESET board to recover\n");
343 show_boot_progress(-6);
344 return BOOTM_ERR_RESET;
347 *load_end = load + image_len;
349 #endif /* CONFIG_GZIP */
352 printf(" Uncompressing %s ... ", type_name);
354 * If we've got less than 4 MB of malloc() space,
355 * use slower decompression algorithm which requires
356 * at most 2300 KB of memory.
358 int i = BZ2_bzBuffToBuffDecompress((char *)load,
359 &unc_len, (char *)image_start, image_len,
360 CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
362 printf("BUNZIP2: uncompress or overwrite error %d "
363 "- must RESET board to recover\n", i);
365 show_boot_progress(-6);
366 return BOOTM_ERR_RESET;
369 *load_end = load + unc_len;
371 #endif /* CONFIG_BZIP2 */
374 SizeT lzma_len = unc_len;
375 printf(" Uncompressing %s ... ", type_name);
377 ret = lzmaBuffToBuffDecompress(
378 (unsigned char *)load, &lzma_len,
379 (unsigned char *)image_start, image_len);
382 printf("LZMA: uncompress or overwrite error %d "
383 "- must RESET board to recover\n", ret);
384 show_boot_progress(-6);
385 return BOOTM_ERR_RESET;
387 *load_end = load + unc_len;
390 #endif /* CONFIG_LZMA */
393 printf(" Uncompressing %s ... ", type_name);
395 ret = lzop_decompress((const unsigned char *)image_start,
396 image_len, (unsigned char *)load,
398 if (ret != LZO_E_OK) {
399 printf("LZO: uncompress or overwrite error %d "
400 "- must RESET board to recover\n", ret);
402 show_boot_progress(-6);
403 return BOOTM_ERR_RESET;
406 *load_end = load + unc_len;
408 #endif /* CONFIG_LZO */
410 printf("Unimplemented compression type %d\n", comp);
411 return BOOTM_ERR_UNIMPLEMENTED;
414 flush_cache(load, (*load_end - load) * sizeof(ulong));
417 debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
419 show_boot_progress(7);
421 if ((load < blob_end) && (*load_end > blob_start)) {
422 debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n",
423 blob_start, blob_end);
424 debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load,
427 return BOOTM_ERR_OVERLAP;
433 static int bootm_start_standalone(ulong iflag, int argc, char * const argv[])
436 int (*appl)(int, char * const []);
438 /* Don't start if "autostart" is set to "no" */
439 if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
441 sprintf(buf, "%lX", images.os.image_len);
442 setenv("filesize", buf);
445 appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep);
446 (*appl)(argc-1, &argv[1]);
450 /* we overload the cmd field with our state machine info instead of a
451 * function pointer */
452 static cmd_tbl_t cmd_bootm_sub[] = {
453 U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
454 U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
455 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
456 U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
458 #ifdef CONFIG_OF_LIBFDT
459 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
461 U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
462 U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
463 U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
464 U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
467 int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
475 c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
478 state = (long)c->cmd;
480 /* treat start special since it resets the state machine */
481 if (state == BOOTM_STATE_START) {
484 return bootm_start(cmdtp, flag, argc, argv);
487 /* Unrecognized command */
488 return cmd_usage(cmdtp);
491 if (images.state >= state) {
492 printf("Trying to execute a command out of order\n");
493 return cmd_usage(cmdtp);
496 images.state |= state;
497 boot_fn = boot_os[images.os.os];
501 case BOOTM_STATE_START:
502 /* should never occur */
504 case BOOTM_STATE_LOADOS:
505 ret = bootm_load_os(images.os, &load_end, 0);
509 lmb_reserve(&images.lmb, images.os.load,
510 (load_end - images.os.load));
512 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
513 case BOOTM_STATE_RAMDISK:
515 ulong rd_len = images.rd_end - images.rd_start;
518 ret = boot_ramdisk_high(&images.lmb, images.rd_start,
519 rd_len, &images.initrd_start, &images.initrd_end);
523 sprintf(str, "%lx", images.initrd_start);
524 setenv("initrd_start", str);
525 sprintf(str, "%lx", images.initrd_end);
526 setenv("initrd_end", str);
530 #if defined(CONFIG_OF_LIBFDT)
531 case BOOTM_STATE_FDT:
533 boot_fdt_add_mem_rsv_regions(&images.lmb,
535 ret = boot_relocate_fdt(&images.lmb,
536 &images.ft_addr, &images.ft_len);
540 case BOOTM_STATE_OS_CMDLINE:
541 ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, &images);
543 printf("cmdline subcommand not supported\n");
545 case BOOTM_STATE_OS_BD_T:
546 ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, &images);
548 printf("bdt subcommand not supported\n");
550 case BOOTM_STATE_OS_PREP:
551 ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, &images);
553 printf("prep subcommand not supported\n");
555 case BOOTM_STATE_OS_GO:
556 disable_interrupts();
558 boot_fn(BOOTM_STATE_OS_GO, argc, argv, &images);
565 /*******************************************************************/
566 /* bootm - boot application image from image in memory */
567 /*******************************************************************/
569 int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
575 #ifdef CONFIG_NEEDS_MANUAL_RELOC
576 static int relocated = 0;
578 /* relocate boot function table */
581 for (i = 0; i < ARRAY_SIZE(boot_os); i++)
582 if (boot_os[i] != NULL)
583 boot_os[i] += gd->reloc_off;
588 /* determine if we have a sub command */
592 simple_strtoul(argv[1], &endp, 16);
593 /* endp pointing to NULL means that argv[1] was just a
594 * valid number, pass it along to the normal bootm processing
596 * If endp is ':' or '#' assume a FIT identifier so pass
597 * along for normal processing.
599 * Right now we assume the first arg should never be '-'
601 if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
602 return do_bootm_subcommand(cmdtp, flag, argc, argv);
605 if (bootm_start(cmdtp, flag, argc, argv))
609 * We have reached the point of no return: we are going to
610 * overwrite all exception vector code, so we cannot easily
611 * recover from any failures any more...
613 iflag = disable_interrupts();
615 #if defined(CONFIG_CMD_USB)
617 * turn off USB to prevent the host controller from writing to the
618 * SDRAM while Linux is booting. This could happen (at least for OHCI
619 * controller), because the HCCA (Host Controller Communication Area)
620 * lies within the SDRAM and the host controller writes continously to
621 * this area (as busmaster!). The HccaFrameNumber is for example
622 * updated every 1 ms within the HCCA structure in SDRAM! For more
623 * details see the OpenHCI specification.
628 ret = bootm_load_os(images.os, &load_end, 1);
631 if (ret == BOOTM_ERR_RESET)
632 do_reset(cmdtp, flag, argc, argv);
633 if (ret == BOOTM_ERR_OVERLAP) {
634 if (images.legacy_hdr_valid) {
636 hdr = &images.legacy_hdr_os_copy;
637 if (image_get_type(hdr) == IH_TYPE_MULTI)
638 puts("WARNING: legacy format multi "
642 puts("ERROR: new format image overwritten - "
643 "must RESET the board to recover\n");
644 show_boot_progress(-113);
645 do_reset(cmdtp, flag, argc, argv);
648 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
651 show_boot_progress(-7);
656 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
658 if (images.os.type == IH_TYPE_STANDALONE) {
661 /* This may return when 'autostart' is 'no' */
662 bootm_start_standalone(iflag, argc, argv);
666 show_boot_progress(8);
668 #ifdef CONFIG_SILENT_CONSOLE
669 if (images.os.os == IH_OS_LINUX)
670 fixup_silent_linux();
673 boot_fn = boot_os[images.os.os];
675 if (boot_fn == NULL) {
678 printf("ERROR: booting os '%s' (%d) is not supported\n",
679 genimg_get_os_name(images.os.os), images.os.os);
680 show_boot_progress(-8);
686 boot_fn(0, argc, argv, &images);
688 show_boot_progress(-9);
690 puts("\n## Control returned to monitor - resetting...\n");
692 do_reset(cmdtp, flag, argc, argv);
697 int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
699 const char *ep = getenv("autostart");
701 if (ep && !strcmp(ep, "yes")) {
703 local_args[0] = (char *)cmd;
704 local_args[1] = NULL;
705 printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
706 return do_bootm(cmdtp, 0, 1, local_args);
713 * image_get_kernel - verify legacy format kernel image
714 * @img_addr: in RAM address of the legacy format image to be verified
715 * @verify: data CRC verification flag
717 * image_get_kernel() verifies legacy image integrity and returns pointer to
718 * legacy image header if image verification was completed successfully.
721 * pointer to a legacy image header if valid image was found
722 * otherwise return NULL
724 static image_header_t *image_get_kernel(ulong img_addr, int verify)
726 image_header_t *hdr = (image_header_t *)img_addr;
728 if (!image_check_magic(hdr)) {
729 puts("Bad Magic Number\n");
730 show_boot_progress(-1);
733 show_boot_progress(2);
735 if (!image_check_hcrc(hdr)) {
736 puts("Bad Header Checksum\n");
737 show_boot_progress(-2);
741 show_boot_progress(3);
742 image_print_contents(hdr);
745 puts(" Verifying Checksum ... ");
746 if (!image_check_dcrc(hdr)) {
747 printf("Bad Data CRC\n");
748 show_boot_progress(-3);
753 show_boot_progress(4);
755 if (!image_check_target_arch(hdr)) {
756 printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr));
757 show_boot_progress(-4);
764 * fit_check_kernel - verify FIT format kernel subimage
765 * @fit_hdr: pointer to the FIT image header
766 * os_noffset: kernel subimage node offset within FIT image
767 * @verify: data CRC verification flag
769 * fit_check_kernel() verifies integrity of the kernel subimage and from
770 * specified FIT image.
776 #if defined(CONFIG_FIT)
777 static int fit_check_kernel(const void *fit, int os_noffset, int verify)
779 fit_image_print(fit, os_noffset, " ");
782 puts(" Verifying Hash Integrity ... ");
783 if (!fit_image_check_hashes(fit, os_noffset)) {
784 puts("Bad Data Hash\n");
785 show_boot_progress(-104);
790 show_boot_progress(105);
792 if (!fit_image_check_target_arch(fit, os_noffset)) {
793 puts("Unsupported Architecture\n");
794 show_boot_progress(-105);
798 show_boot_progress(106);
799 if (!fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL)) {
800 puts("Not a kernel image\n");
801 show_boot_progress(-106);
805 show_boot_progress(107);
808 #endif /* CONFIG_FIT */
811 * boot_get_kernel - find kernel image
812 * @os_data: pointer to a ulong variable, will hold os data start address
813 * @os_len: pointer to a ulong variable, will hold os data length
815 * boot_get_kernel() tries to find a kernel image, verifies its integrity
816 * and locates kernel data.
819 * pointer to image header if valid image was found, plus kernel start
820 * address and length, otherwise NULL
822 static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
823 char * const argv[], bootm_headers_t *images, ulong *os_data,
828 #if defined(CONFIG_FIT)
830 const char *fit_uname_config = NULL;
831 const char *fit_uname_kernel = NULL;
838 /* find out kernel image address */
840 img_addr = load_addr;
841 debug("* kernel: default image load address = 0x%08lx\n",
843 #if defined(CONFIG_FIT)
844 } else if (fit_parse_conf(argv[1], load_addr, &img_addr,
845 &fit_uname_config)) {
846 debug("* kernel: config '%s' from image at 0x%08lx\n",
847 fit_uname_config, img_addr);
848 } else if (fit_parse_subimage(argv[1], load_addr, &img_addr,
849 &fit_uname_kernel)) {
850 debug("* kernel: subimage '%s' from image at 0x%08lx\n",
851 fit_uname_kernel, img_addr);
854 img_addr = simple_strtoul(argv[1], NULL, 16);
855 debug("* kernel: cmdline image address = 0x%08lx\n", img_addr);
858 show_boot_progress(1);
860 /* copy from dataflash if needed */
861 img_addr = genimg_get_image(img_addr);
863 /* check image type, for FIT images get FIT kernel node */
864 *os_data = *os_len = 0;
865 switch (genimg_get_format((void *)img_addr)) {
866 case IMAGE_FORMAT_LEGACY:
867 printf("## Booting kernel from Legacy Image at %08lx ...\n",
869 hdr = image_get_kernel(img_addr, images->verify);
872 show_boot_progress(5);
874 /* get os_data and os_len */
875 switch (image_get_type(hdr)) {
877 *os_data = image_get_data(hdr);
878 *os_len = image_get_data_size(hdr);
881 image_multi_getimg(hdr, 0, os_data, os_len);
883 case IH_TYPE_STANDALONE:
884 *os_data = image_get_data(hdr);
885 *os_len = image_get_data_size(hdr);
888 printf("Wrong Image Type for %s command\n",
890 show_boot_progress(-5);
895 * copy image header to allow for image overwrites during
896 * kernel decompression.
898 memmove(&images->legacy_hdr_os_copy, hdr,
899 sizeof(image_header_t));
901 /* save pointer to image header */
902 images->legacy_hdr_os = hdr;
904 images->legacy_hdr_valid = 1;
905 show_boot_progress(6);
907 #if defined(CONFIG_FIT)
908 case IMAGE_FORMAT_FIT:
909 fit_hdr = (void *)img_addr;
910 printf("## Booting kernel from FIT Image at %08lx ...\n",
913 if (!fit_check_format(fit_hdr)) {
914 puts("Bad FIT kernel image format!\n");
915 show_boot_progress(-100);
918 show_boot_progress(100);
920 if (!fit_uname_kernel) {
922 * no kernel image node unit name, try to get config
923 * node first. If config unit node name is NULL
924 * fit_conf_get_node() will try to find default config
927 show_boot_progress(101);
928 cfg_noffset = fit_conf_get_node(fit_hdr,
930 if (cfg_noffset < 0) {
931 show_boot_progress(-101);
934 /* save configuration uname provided in the first
937 images->fit_uname_cfg = fdt_get_name(fit_hdr,
940 printf(" Using '%s' configuration\n",
941 images->fit_uname_cfg);
942 show_boot_progress(103);
944 os_noffset = fit_conf_get_kernel_node(fit_hdr,
946 fit_uname_kernel = fit_get_name(fit_hdr, os_noffset,
949 /* get kernel component image node offset */
950 show_boot_progress(102);
951 os_noffset = fit_image_get_node(fit_hdr,
954 if (os_noffset < 0) {
955 show_boot_progress(-103);
959 printf(" Trying '%s' kernel subimage\n", fit_uname_kernel);
961 show_boot_progress(104);
962 if (!fit_check_kernel(fit_hdr, os_noffset, images->verify))
965 /* get kernel image data address and length */
966 if (fit_image_get_data(fit_hdr, os_noffset, &data, &len)) {
967 puts("Could not find kernel subimage data!\n");
968 show_boot_progress(-107);
971 show_boot_progress(108);
974 *os_data = (ulong)data;
975 images->fit_hdr_os = fit_hdr;
976 images->fit_uname_os = fit_uname_kernel;
977 images->fit_noffset_os = os_noffset;
981 printf("Wrong Image Format for %s command\n", cmdtp->name);
982 show_boot_progress(-108);
986 debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
987 *os_data, *os_len, *os_len);
989 return (void *)img_addr;
993 bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
994 "boot application image from memory",
995 "[addr [arg ...]]\n - boot application image stored in memory\n"
996 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
997 "\t'arg' can be the address of an initrd image\n"
998 #if defined(CONFIG_OF_LIBFDT)
999 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
1000 "\ta third argument is required which is the address of the\n"
1001 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1002 "\tuse a '-' for the second argument. If you do not pass a third\n"
1003 "\ta bd_info struct will be passed instead\n"
1005 #if defined(CONFIG_FIT)
1006 "\t\nFor the new multi component uImage format (FIT) addresses\n"
1007 "\tmust be extened to include component or configuration unit name:\n"
1008 "\taddr:<subimg_uname> - direct component image specification\n"
1009 "\taddr#<conf_uname> - configuration specification\n"
1010 "\tUse iminfo command to get the list of existing component\n"
1011 "\timages and configurations.\n"
1013 "\nSub-commands to do part of the bootm sequence. The sub-commands "
1015 "issued in the order below (it's ok to not issue all sub-commands):\n"
1016 "\tstart [addr [arg ...]]\n"
1017 "\tloados - load OS image\n"
1018 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
1019 "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
1021 #if defined(CONFIG_OF_LIBFDT)
1022 "\tfdt - relocate flat device tree\n"
1024 "\tcmdline - OS specific command line processing/setup\n"
1025 "\tbdt - OS specific bd_t processing\n"
1026 "\tprep - OS specific prep before relocation or go\n"
1030 /*******************************************************************/
1031 /* bootd - boot default image */
1032 /*******************************************************************/
1033 #if defined(CONFIG_CMD_BOOTD)
1034 int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1038 #ifndef CONFIG_SYS_HUSH_PARSER
1039 if (run_command(getenv("bootcmd"), flag) < 0)
1042 if (parse_string_outer(getenv("bootcmd"),
1043 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
1050 boot, 1, 1, do_bootd,
1051 "boot default, i.e., run 'bootcmd'",
1055 /* keep old command name "bootd" for backward compatibility */
1057 bootd, 1, 1, do_bootd,
1058 "boot default, i.e., run 'bootcmd'",
1065 /*******************************************************************/
1066 /* iminfo - print header info for a requested image */
1067 /*******************************************************************/
1068 #if defined(CONFIG_CMD_IMI)
1069 int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1076 return image_info(load_addr);
1079 for (arg = 1; arg < argc; ++arg) {
1080 addr = simple_strtoul(argv[arg], NULL, 16);
1081 if (image_info(addr) != 0)
1087 static int image_info(ulong addr)
1089 void *hdr = (void *)addr;
1091 printf("\n## Checking Image at %08lx ...\n", addr);
1093 switch (genimg_get_format(hdr)) {
1094 case IMAGE_FORMAT_LEGACY:
1095 puts(" Legacy image found\n");
1096 if (!image_check_magic(hdr)) {
1097 puts(" Bad Magic Number\n");
1101 if (!image_check_hcrc(hdr)) {
1102 puts(" Bad Header Checksum\n");
1106 image_print_contents(hdr);
1108 puts(" Verifying Checksum ... ");
1109 if (!image_check_dcrc(hdr)) {
1110 puts(" Bad Data CRC\n");
1115 #if defined(CONFIG_FIT)
1116 case IMAGE_FORMAT_FIT:
1117 puts(" FIT image found\n");
1119 if (!fit_check_format(hdr)) {
1120 puts("Bad FIT image format!\n");
1124 fit_print_contents(hdr);
1126 if (!fit_all_image_check_hashes(hdr)) {
1127 puts("Bad hash in FIT image!\n");
1134 puts("Unknown image format!\n");
1142 iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
1143 "print header information for application image",
1145 " - print header information for application image starting at\n"
1146 " address 'addr' in memory; this includes verification of the\n"
1147 " image contents (magic number, header and payload checksums)"
1152 /*******************************************************************/
1153 /* imls - list all images found in flash */
1154 /*******************************************************************/
1155 #if defined(CONFIG_CMD_IMLS)
1156 int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1162 for (i = 0, info = &flash_info[0];
1163 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
1165 if (info->flash_id == FLASH_UNKNOWN)
1167 for (j = 0; j < info->sector_count; ++j) {
1169 hdr = (void *)info->start[j];
1173 switch (genimg_get_format(hdr)) {
1174 case IMAGE_FORMAT_LEGACY:
1175 if (!image_check_hcrc(hdr))
1178 printf("Legacy Image at %08lX:\n", (ulong)hdr);
1179 image_print_contents(hdr);
1181 puts(" Verifying Checksum ... ");
1182 if (!image_check_dcrc(hdr)) {
1183 puts("Bad Data CRC\n");
1188 #if defined(CONFIG_FIT)
1189 case IMAGE_FORMAT_FIT:
1190 if (!fit_check_format(hdr))
1193 printf("FIT Image at %08lX:\n", (ulong)hdr);
1194 fit_print_contents(hdr);
1210 imls, 1, 1, do_imls,
1211 "list all images found in flash",
1213 " - Prints information about all images found at sector\n"
1214 " boundaries in flash."
1218 /*******************************************************************/
1219 /* helper routines */
1220 /*******************************************************************/
1221 #ifdef CONFIG_SILENT_CONSOLE
1222 static void fixup_silent_linux(void)
1224 char buf[256], *start, *end;
1225 char *cmdline = getenv("bootargs");
1227 /* Only fix cmdline when requested */
1228 if (!(gd->flags & GD_FLG_SILENT))
1231 debug("before silent fix-up: %s\n", cmdline);
1233 start = strstr(cmdline, "console=");
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 * const 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 "
1330 "(at address %08lx) ...\n",
1333 show_boot_progress(15);
1336 * NetBSD Stage-2 Loader Parameters:
1337 * r3: ptr to board info data
1339 * r5: console device
1340 * r6: boot args string
1342 (*loader)(gd->bd, os_hdr, consdev, cmdline);
1346 #endif /* CONFIG_BOOTM_NETBSD*/
1348 #ifdef CONFIG_LYNXKDI
1349 static int do_bootm_lynxkdi(int flag, int argc, char * const argv[],
1350 bootm_headers_t *images)
1352 image_header_t *hdr = &images->legacy_hdr_os_copy;
1354 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1357 #if defined(CONFIG_FIT)
1358 if (!images->legacy_hdr_valid) {
1359 fit_unsupported_reset("Lynx");
1364 lynxkdi_boot((image_header_t *)hdr);
1368 #endif /* CONFIG_LYNXKDI */
1370 #ifdef CONFIG_BOOTM_RTEMS
1371 static int do_bootm_rtems(int flag, int argc, char * const argv[],
1372 bootm_headers_t *images)
1374 void (*entry_point)(bd_t *);
1376 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1379 #if defined(CONFIG_FIT)
1380 if (!images->legacy_hdr_valid) {
1381 fit_unsupported_reset("RTEMS");
1386 entry_point = (void (*)(bd_t *))images->ep;
1388 printf("## Transferring control to RTEMS (at address %08lx) ...\n",
1389 (ulong)entry_point);
1391 show_boot_progress(15);
1395 * r3: ptr to board info data
1397 (*entry_point)(gd->bd);
1401 #endif /* CONFIG_BOOTM_RTEMS */
1403 #if defined(CONFIG_BOOTM_OSE)
1404 static int do_bootm_ose(int flag, int argc, char * const argv[],
1405 bootm_headers_t *images)
1407 void (*entry_point)(void);
1409 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1412 #if defined(CONFIG_FIT)
1413 if (!images->legacy_hdr_valid) {
1414 fit_unsupported_reset("OSE");
1419 entry_point = (void (*)(void))images->ep;
1421 printf("## Transferring control to OSE (at address %08lx) ...\n",
1422 (ulong)entry_point);
1424 show_boot_progress(15);
1434 #endif /* CONFIG_BOOTM_OSE */
1436 #if defined(CONFIG_CMD_ELF)
1437 static int do_bootm_vxworks(int flag, int argc, char * const argv[],
1438 bootm_headers_t *images)
1442 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1445 #if defined(CONFIG_FIT)
1446 if (!images->legacy_hdr_valid) {
1447 fit_unsupported_reset("VxWorks");
1452 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1453 setenv("loadaddr", str);
1454 do_bootvx(NULL, 0, 0, NULL);
1459 static int do_bootm_qnxelf(int flag, int argc, char * const argv[],
1460 bootm_headers_t *images)
1462 char *local_args[2];
1465 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1468 #if defined(CONFIG_FIT)
1469 if (!images->legacy_hdr_valid) {
1470 fit_unsupported_reset("QNX");
1475 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1476 local_args[0] = argv[0];
1477 local_args[1] = str; /* and provide it via the arguments */
1478 do_bootelf(NULL, 0, 2, local_args);
1484 #ifdef CONFIG_INTEGRITY
1485 static int do_bootm_integrity(int flag, int argc, char * const argv[],
1486 bootm_headers_t *images)
1488 void (*entry_point)(void);
1490 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1493 #if defined(CONFIG_FIT)
1494 if (!images->legacy_hdr_valid) {
1495 fit_unsupported_reset("INTEGRITY");
1500 entry_point = (void (*)(void))images->ep;
1502 printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
1503 (ulong)entry_point);
1505 show_boot_progress(15);
1508 * INTEGRITY Parameters: