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 #ifndef CONFIG_SYS_BOOTM_LEN
67 #define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
71 extern void bz_internal_error(int);
74 #if defined(CONFIG_CMD_IMI)
75 static int image_info(unsigned long addr);
78 #if defined(CONFIG_CMD_IMLS)
80 #include <mtd/cfi_flash.h>
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 * const 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,
95 char * const argv[], bootm_headers_t *images,
96 ulong *os_data, ulong *os_len);
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 * const argv[],
107 bootm_headers_t *images); /* pointers to os/initrd/fdt */
109 #ifdef CONFIG_BOOTM_LINUX
110 extern boot_os_fn do_bootm_linux;
112 #ifdef CONFIG_BOOTM_NETBSD
113 static boot_os_fn do_bootm_netbsd;
115 #if defined(CONFIG_LYNXKDI)
116 static boot_os_fn do_bootm_lynxkdi;
117 extern void lynxkdi_boot(image_header_t *);
119 #ifdef CONFIG_BOOTM_RTEMS
120 static boot_os_fn do_bootm_rtems;
122 #if defined(CONFIG_BOOTM_OSE)
123 static boot_os_fn do_bootm_ose;
125 #if defined(CONFIG_CMD_ELF)
126 static boot_os_fn do_bootm_vxworks;
127 static boot_os_fn do_bootm_qnxelf;
128 int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
129 int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
131 #if defined(CONFIG_INTEGRITY)
132 static boot_os_fn do_bootm_integrity;
135 static boot_os_fn *boot_os[] = {
136 #ifdef CONFIG_BOOTM_LINUX
137 [IH_OS_LINUX] = do_bootm_linux,
139 #ifdef CONFIG_BOOTM_NETBSD
140 [IH_OS_NETBSD] = do_bootm_netbsd,
142 #ifdef CONFIG_LYNXKDI
143 [IH_OS_LYNXOS] = do_bootm_lynxkdi,
145 #ifdef CONFIG_BOOTM_RTEMS
146 [IH_OS_RTEMS] = do_bootm_rtems,
148 #if defined(CONFIG_BOOTM_OSE)
149 [IH_OS_OSE] = do_bootm_ose,
151 #if defined(CONFIG_CMD_ELF)
152 [IH_OS_VXWORKS] = do_bootm_vxworks,
153 [IH_OS_QNX] = do_bootm_qnxelf,
155 #ifdef CONFIG_INTEGRITY
156 [IH_OS_INTEGRITY] = do_bootm_integrity,
160 bootm_headers_t images; /* pointers to os/initrd/fdt images */
162 /* Allow for arch specific config before we boot */
163 void __arch_preboot_os(void)
165 /* please define platform specific arch_preboot_os() */
167 void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
169 #define IH_INITRD_ARCH IH_ARCH_DEFAULT
171 static void bootm_start_lmb(void)
175 phys_size_t mem_size;
177 lmb_init(&images.lmb);
179 mem_start = getenv_bootm_low();
180 mem_size = getenv_bootm_size();
182 lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
184 arch_lmb_reserve(&images.lmb);
185 board_lmb_reserve(&images.lmb);
187 # define lmb_reserve(lmb, base, size)
191 static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
196 memset((void *)&images, 0, sizeof(images));
197 images.verify = getenv_yesno("verify");
201 /* get kernel image header, start address and length */
202 os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
203 &images, &images.os.image_start, &images.os.image_len);
204 if (images.os.image_len == 0) {
205 puts("ERROR: can't get kernel image!\n");
209 /* get image parameters */
210 switch (genimg_get_format(os_hdr)) {
211 case IMAGE_FORMAT_LEGACY:
212 images.os.type = image_get_type(os_hdr);
213 images.os.comp = image_get_comp(os_hdr);
214 images.os.os = image_get_os(os_hdr);
216 images.os.end = image_get_image_end(os_hdr);
217 images.os.load = image_get_load(os_hdr);
219 #if defined(CONFIG_FIT)
220 case IMAGE_FORMAT_FIT:
221 if (fit_image_get_type(images.fit_hdr_os,
222 images.fit_noffset_os, &images.os.type)) {
223 puts("Can't get image type!\n");
224 show_boot_progress(-109);
228 if (fit_image_get_comp(images.fit_hdr_os,
229 images.fit_noffset_os, &images.os.comp)) {
230 puts("Can't get image compression!\n");
231 show_boot_progress(-110);
235 if (fit_image_get_os(images.fit_hdr_os,
236 images.fit_noffset_os, &images.os.os)) {
237 puts("Can't get image OS!\n");
238 show_boot_progress(-111);
242 images.os.end = fit_get_end(images.fit_hdr_os);
244 if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os,
246 puts("Can't get image load address!\n");
247 show_boot_progress(-112);
253 puts("ERROR: unknown image format type!\n");
257 /* find kernel entry point */
258 if (images.legacy_hdr_valid) {
259 images.ep = image_get_ep(&images.legacy_hdr_os_copy);
260 #if defined(CONFIG_FIT)
261 } else if (images.fit_uname_os) {
262 ret = fit_image_get_entry(images.fit_hdr_os,
263 images.fit_noffset_os, &images.ep);
265 puts("Can't get entry point property!\n");
270 puts("Could not find kernel entry point!\n");
274 if (((images.os.type == IH_TYPE_KERNEL) ||
275 (images.os.type == IH_TYPE_MULTI)) &&
276 (images.os.os == IH_OS_LINUX)) {
278 ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH,
279 &images.rd_start, &images.rd_end);
281 puts("Ramdisk image is corrupt or invalid\n");
285 #if defined(CONFIG_OF_LIBFDT)
286 /* find flattened device tree */
287 ret = boot_get_fdt(flag, argc, argv, &images,
288 &images.ft_addr, &images.ft_len);
290 puts("Could not find a valid device tree\n");
294 set_working_fdt_addr(images.ft_addr);
298 images.os.start = (ulong)os_hdr;
299 images.state = BOOTM_STATE_START;
304 #define BOOTM_ERR_RESET -1
305 #define BOOTM_ERR_OVERLAP -2
306 #define BOOTM_ERR_UNIMPLEMENTED -3
307 static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
309 uint8_t comp = os.comp;
310 ulong load = os.load;
311 ulong blob_start = os.start;
312 ulong blob_end = os.end;
313 ulong image_start = os.image_start;
314 ulong image_len = os.image_len;
315 uint unc_len = CONFIG_SYS_BOOTM_LEN;
316 #if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
318 #endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
320 const char *type_name = genimg_get_type_name(os.type);
324 if (load == blob_start || load == image_start) {
325 printf(" XIP %s ... ", type_name);
327 printf(" Loading %s ... ", type_name);
328 memmove_wd((void *)load, (void *)image_start,
331 *load_end = load + image_len;
336 printf(" Uncompressing %s ... ", type_name);
337 if (gunzip((void *)load, unc_len,
338 (uchar *)image_start, &image_len) != 0) {
339 puts("GUNZIP: uncompress, out-of-mem or overwrite "
340 "error - must RESET board to recover\n");
342 show_boot_progress(-6);
343 return BOOTM_ERR_RESET;
346 *load_end = load + image_len;
348 #endif /* CONFIG_GZIP */
351 printf(" Uncompressing %s ... ", type_name);
353 * If we've got less than 4 MB of malloc() space,
354 * use slower decompression algorithm which requires
355 * at most 2300 KB of memory.
357 int i = BZ2_bzBuffToBuffDecompress((char *)load,
358 &unc_len, (char *)image_start, image_len,
359 CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
361 printf("BUNZIP2: uncompress or overwrite error %d "
362 "- must RESET board to recover\n", i);
364 show_boot_progress(-6);
365 return BOOTM_ERR_RESET;
368 *load_end = load + unc_len;
370 #endif /* CONFIG_BZIP2 */
373 SizeT lzma_len = unc_len;
374 printf(" Uncompressing %s ... ", type_name);
376 ret = lzmaBuffToBuffDecompress(
377 (unsigned char *)load, &lzma_len,
378 (unsigned char *)image_start, image_len);
381 printf("LZMA: uncompress or overwrite error %d "
382 "- must RESET board to recover\n", ret);
383 show_boot_progress(-6);
384 return BOOTM_ERR_RESET;
386 *load_end = load + unc_len;
389 #endif /* CONFIG_LZMA */
392 printf(" Uncompressing %s ... ", type_name);
394 ret = lzop_decompress((const unsigned char *)image_start,
395 image_len, (unsigned char *)load,
397 if (ret != LZO_E_OK) {
398 printf("LZO: uncompress or overwrite error %d "
399 "- must RESET board to recover\n", ret);
401 show_boot_progress(-6);
402 return BOOTM_ERR_RESET;
405 *load_end = load + unc_len;
407 #endif /* CONFIG_LZO */
409 printf("Unimplemented compression type %d\n", comp);
410 return BOOTM_ERR_UNIMPLEMENTED;
413 flush_cache(load, (*load_end - load) * sizeof(ulong));
416 debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
418 show_boot_progress(7);
420 if ((load < blob_end) && (*load_end > blob_start)) {
421 debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n",
422 blob_start, blob_end);
423 debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load,
426 return BOOTM_ERR_OVERLAP;
432 static int bootm_start_standalone(ulong iflag, int argc, char * const argv[])
435 int (*appl)(int, char * const []);
437 /* Don't start if "autostart" is set to "no" */
438 if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
440 sprintf(buf, "%lX", images.os.image_len);
441 setenv("filesize", buf);
444 appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep);
445 (*appl)(argc-1, &argv[1]);
449 /* we overload the cmd field with our state machine info instead of a
450 * function pointer */
451 static cmd_tbl_t cmd_bootm_sub[] = {
452 U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
453 U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
454 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
455 U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
457 #ifdef CONFIG_OF_LIBFDT
458 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
460 U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
461 U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
462 U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
463 U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
466 int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
474 c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
477 state = (long)c->cmd;
479 /* treat start special since it resets the state machine */
480 if (state == BOOTM_STATE_START) {
483 return bootm_start(cmdtp, flag, argc, argv);
486 /* Unrecognized command */
487 return cmd_usage(cmdtp);
490 if (images.state >= state) {
491 printf("Trying to execute a command out of order\n");
492 return cmd_usage(cmdtp);
495 images.state |= state;
496 boot_fn = boot_os[images.os.os];
500 case BOOTM_STATE_START:
501 /* should never occur */
503 case BOOTM_STATE_LOADOS:
504 ret = bootm_load_os(images.os, &load_end, 0);
508 lmb_reserve(&images.lmb, images.os.load,
509 (load_end - images.os.load));
511 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
512 case BOOTM_STATE_RAMDISK:
514 ulong rd_len = images.rd_end - images.rd_start;
517 ret = boot_ramdisk_high(&images.lmb, images.rd_start,
518 rd_len, &images.initrd_start, &images.initrd_end);
522 sprintf(str, "%lx", images.initrd_start);
523 setenv("initrd_start", str);
524 sprintf(str, "%lx", images.initrd_end);
525 setenv("initrd_end", str);
529 #if defined(CONFIG_OF_LIBFDT)
530 case BOOTM_STATE_FDT:
532 boot_fdt_add_mem_rsv_regions(&images.lmb,
534 ret = boot_relocate_fdt(&images.lmb,
535 &images.ft_addr, &images.ft_len);
539 case BOOTM_STATE_OS_CMDLINE:
540 ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, &images);
542 printf("cmdline subcommand not supported\n");
544 case BOOTM_STATE_OS_BD_T:
545 ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, &images);
547 printf("bdt subcommand not supported\n");
549 case BOOTM_STATE_OS_PREP:
550 ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, &images);
552 printf("prep subcommand not supported\n");
554 case BOOTM_STATE_OS_GO:
555 disable_interrupts();
557 boot_fn(BOOTM_STATE_OS_GO, argc, argv, &images);
564 /*******************************************************************/
565 /* bootm - boot application image from image in memory */
566 /*******************************************************************/
568 int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
574 #ifdef CONFIG_NEEDS_MANUAL_RELOC
575 static int relocated = 0;
577 /* relocate boot function table */
580 for (i = 0; i < ARRAY_SIZE(boot_os); i++)
581 if (boot_os[i] != NULL)
582 boot_os[i] += gd->reloc_off;
587 /* determine if we have a sub command */
591 simple_strtoul(argv[1], &endp, 16);
592 /* endp pointing to NULL means that argv[1] was just a
593 * valid number, pass it along to the normal bootm processing
595 * If endp is ':' or '#' assume a FIT identifier so pass
596 * along for normal processing.
598 * Right now we assume the first arg should never be '-'
600 if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
601 return do_bootm_subcommand(cmdtp, flag, argc, argv);
604 if (bootm_start(cmdtp, flag, argc, argv))
608 * We have reached the point of no return: we are going to
609 * overwrite all exception vector code, so we cannot easily
610 * recover from any failures any more...
612 iflag = disable_interrupts();
614 #if defined(CONFIG_CMD_USB)
616 * turn off USB to prevent the host controller from writing to the
617 * SDRAM while Linux is booting. This could happen (at least for OHCI
618 * controller), because the HCCA (Host Controller Communication Area)
619 * lies within the SDRAM and the host controller writes continously to
620 * this area (as busmaster!). The HccaFrameNumber is for example
621 * updated every 1 ms within the HCCA structure in SDRAM! For more
622 * details see the OpenHCI specification.
627 ret = bootm_load_os(images.os, &load_end, 1);
630 if (ret == BOOTM_ERR_RESET)
631 do_reset(cmdtp, flag, argc, argv);
632 if (ret == BOOTM_ERR_OVERLAP) {
633 if (images.legacy_hdr_valid) {
635 hdr = &images.legacy_hdr_os_copy;
636 if (image_get_type(hdr) == IH_TYPE_MULTI)
637 puts("WARNING: legacy format multi "
641 puts("ERROR: new format image overwritten - "
642 "must RESET the board to recover\n");
643 show_boot_progress(-113);
644 do_reset(cmdtp, flag, argc, argv);
647 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
650 show_boot_progress(-7);
655 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
657 if (images.os.type == IH_TYPE_STANDALONE) {
660 /* This may return when 'autostart' is 'no' */
661 bootm_start_standalone(iflag, argc, argv);
665 show_boot_progress(8);
667 #ifdef CONFIG_SILENT_CONSOLE
668 if (images.os.os == IH_OS_LINUX)
669 fixup_silent_linux();
672 boot_fn = boot_os[images.os.os];
674 if (boot_fn == NULL) {
677 printf("ERROR: booting os '%s' (%d) is not supported\n",
678 genimg_get_os_name(images.os.os), images.os.os);
679 show_boot_progress(-8);
685 boot_fn(0, argc, argv, &images);
687 show_boot_progress(-9);
689 puts("\n## Control returned to monitor - resetting...\n");
691 do_reset(cmdtp, flag, argc, argv);
696 int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
698 const char *ep = getenv("autostart");
700 if (ep && !strcmp(ep, "yes")) {
702 local_args[0] = (char *)cmd;
703 local_args[1] = NULL;
704 printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
705 return do_bootm(cmdtp, 0, 1, local_args);
712 * image_get_kernel - verify legacy format kernel image
713 * @img_addr: in RAM address of the legacy format image to be verified
714 * @verify: data CRC verification flag
716 * image_get_kernel() verifies legacy image integrity and returns pointer to
717 * legacy image header if image verification was completed successfully.
720 * pointer to a legacy image header if valid image was found
721 * otherwise return NULL
723 static image_header_t *image_get_kernel(ulong img_addr, int verify)
725 image_header_t *hdr = (image_header_t *)img_addr;
727 if (!image_check_magic(hdr)) {
728 puts("Bad Magic Number\n");
729 show_boot_progress(-1);
732 show_boot_progress(2);
734 if (!image_check_hcrc(hdr)) {
735 puts("Bad Header Checksum\n");
736 show_boot_progress(-2);
740 show_boot_progress(3);
741 image_print_contents(hdr);
744 puts(" Verifying Checksum ... ");
745 if (!image_check_dcrc(hdr)) {
746 printf("Bad Data CRC\n");
747 show_boot_progress(-3);
752 show_boot_progress(4);
754 if (!image_check_target_arch(hdr)) {
755 printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr));
756 show_boot_progress(-4);
763 * fit_check_kernel - verify FIT format kernel subimage
764 * @fit_hdr: pointer to the FIT image header
765 * os_noffset: kernel subimage node offset within FIT image
766 * @verify: data CRC verification flag
768 * fit_check_kernel() verifies integrity of the kernel subimage and from
769 * specified FIT image.
775 #if defined(CONFIG_FIT)
776 static int fit_check_kernel(const void *fit, int os_noffset, int verify)
778 fit_image_print(fit, os_noffset, " ");
781 puts(" Verifying Hash Integrity ... ");
782 if (!fit_image_check_hashes(fit, os_noffset)) {
783 puts("Bad Data Hash\n");
784 show_boot_progress(-104);
789 show_boot_progress(105);
791 if (!fit_image_check_target_arch(fit, os_noffset)) {
792 puts("Unsupported Architecture\n");
793 show_boot_progress(-105);
797 show_boot_progress(106);
798 if (!fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL)) {
799 puts("Not a kernel image\n");
800 show_boot_progress(-106);
804 show_boot_progress(107);
807 #endif /* CONFIG_FIT */
810 * boot_get_kernel - find kernel image
811 * @os_data: pointer to a ulong variable, will hold os data start address
812 * @os_len: pointer to a ulong variable, will hold os data length
814 * boot_get_kernel() tries to find a kernel image, verifies its integrity
815 * and locates kernel data.
818 * pointer to image header if valid image was found, plus kernel start
819 * address and length, otherwise NULL
821 static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
822 char * const argv[], bootm_headers_t *images, ulong *os_data,
827 #if defined(CONFIG_FIT)
829 const char *fit_uname_config = NULL;
830 const char *fit_uname_kernel = NULL;
837 /* find out kernel image address */
839 img_addr = load_addr;
840 debug("* kernel: default image load address = 0x%08lx\n",
842 #if defined(CONFIG_FIT)
843 } else if (fit_parse_conf(argv[1], load_addr, &img_addr,
844 &fit_uname_config)) {
845 debug("* kernel: config '%s' from image at 0x%08lx\n",
846 fit_uname_config, img_addr);
847 } else if (fit_parse_subimage(argv[1], load_addr, &img_addr,
848 &fit_uname_kernel)) {
849 debug("* kernel: subimage '%s' from image at 0x%08lx\n",
850 fit_uname_kernel, img_addr);
853 img_addr = simple_strtoul(argv[1], NULL, 16);
854 debug("* kernel: cmdline image address = 0x%08lx\n", img_addr);
857 show_boot_progress(1);
859 /* copy from dataflash if needed */
860 img_addr = genimg_get_image(img_addr);
862 /* check image type, for FIT images get FIT kernel node */
863 *os_data = *os_len = 0;
864 switch (genimg_get_format((void *)img_addr)) {
865 case IMAGE_FORMAT_LEGACY:
866 printf("## Booting kernel from Legacy Image at %08lx ...\n",
868 hdr = image_get_kernel(img_addr, images->verify);
871 show_boot_progress(5);
873 /* get os_data and os_len */
874 switch (image_get_type(hdr)) {
876 *os_data = image_get_data(hdr);
877 *os_len = image_get_data_size(hdr);
880 image_multi_getimg(hdr, 0, os_data, os_len);
882 case IH_TYPE_STANDALONE:
883 *os_data = image_get_data(hdr);
884 *os_len = image_get_data_size(hdr);
887 printf("Wrong Image Type for %s command\n",
889 show_boot_progress(-5);
894 * copy image header to allow for image overwrites during
895 * kernel decompression.
897 memmove(&images->legacy_hdr_os_copy, hdr,
898 sizeof(image_header_t));
900 /* save pointer to image header */
901 images->legacy_hdr_os = hdr;
903 images->legacy_hdr_valid = 1;
904 show_boot_progress(6);
906 #if defined(CONFIG_FIT)
907 case IMAGE_FORMAT_FIT:
908 fit_hdr = (void *)img_addr;
909 printf("## Booting kernel from FIT Image at %08lx ...\n",
912 if (!fit_check_format(fit_hdr)) {
913 puts("Bad FIT kernel image format!\n");
914 show_boot_progress(-100);
917 show_boot_progress(100);
919 if (!fit_uname_kernel) {
921 * no kernel image node unit name, try to get config
922 * node first. If config unit node name is NULL
923 * fit_conf_get_node() will try to find default config
926 show_boot_progress(101);
927 cfg_noffset = fit_conf_get_node(fit_hdr,
929 if (cfg_noffset < 0) {
930 show_boot_progress(-101);
933 /* save configuration uname provided in the first
936 images->fit_uname_cfg = fdt_get_name(fit_hdr,
939 printf(" Using '%s' configuration\n",
940 images->fit_uname_cfg);
941 show_boot_progress(103);
943 os_noffset = fit_conf_get_kernel_node(fit_hdr,
945 fit_uname_kernel = fit_get_name(fit_hdr, os_noffset,
948 /* get kernel component image node offset */
949 show_boot_progress(102);
950 os_noffset = fit_image_get_node(fit_hdr,
953 if (os_noffset < 0) {
954 show_boot_progress(-103);
958 printf(" Trying '%s' kernel subimage\n", fit_uname_kernel);
960 show_boot_progress(104);
961 if (!fit_check_kernel(fit_hdr, os_noffset, images->verify))
964 /* get kernel image data address and length */
965 if (fit_image_get_data(fit_hdr, os_noffset, &data, &len)) {
966 puts("Could not find kernel subimage data!\n");
967 show_boot_progress(-107);
970 show_boot_progress(108);
973 *os_data = (ulong)data;
974 images->fit_hdr_os = fit_hdr;
975 images->fit_uname_os = fit_uname_kernel;
976 images->fit_noffset_os = os_noffset;
980 printf("Wrong Image Format for %s command\n", cmdtp->name);
981 show_boot_progress(-108);
985 debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
986 *os_data, *os_len, *os_len);
988 return (void *)img_addr;
992 bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
993 "boot application image from memory",
994 "[addr [arg ...]]\n - boot application image stored in memory\n"
995 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
996 "\t'arg' can be the address of an initrd image\n"
997 #if defined(CONFIG_OF_LIBFDT)
998 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
999 "\ta third argument is required which is the address of the\n"
1000 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1001 "\tuse a '-' for the second argument. If you do not pass a third\n"
1002 "\ta bd_info struct will be passed instead\n"
1004 #if defined(CONFIG_FIT)
1005 "\t\nFor the new multi component uImage format (FIT) addresses\n"
1006 "\tmust be extened to include component or configuration unit name:\n"
1007 "\taddr:<subimg_uname> - direct component image specification\n"
1008 "\taddr#<conf_uname> - configuration specification\n"
1009 "\tUse iminfo command to get the list of existing component\n"
1010 "\timages and configurations.\n"
1012 "\nSub-commands to do part of the bootm sequence. The sub-commands "
1014 "issued in the order below (it's ok to not issue all sub-commands):\n"
1015 "\tstart [addr [arg ...]]\n"
1016 "\tloados - load OS image\n"
1017 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
1018 "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
1020 #if defined(CONFIG_OF_LIBFDT)
1021 "\tfdt - relocate flat device tree\n"
1023 "\tcmdline - OS specific command line processing/setup\n"
1024 "\tbdt - OS specific bd_t processing\n"
1025 "\tprep - OS specific prep before relocation or go\n"
1029 /*******************************************************************/
1030 /* bootd - boot default image */
1031 /*******************************************************************/
1032 #if defined(CONFIG_CMD_BOOTD)
1033 int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1037 #ifndef CONFIG_SYS_HUSH_PARSER
1038 if (run_command(getenv("bootcmd"), flag) < 0)
1041 if (parse_string_outer(getenv("bootcmd"),
1042 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
1049 boot, 1, 1, do_bootd,
1050 "boot default, i.e., run 'bootcmd'",
1054 /* keep old command name "bootd" for backward compatibility */
1056 bootd, 1, 1, do_bootd,
1057 "boot default, i.e., run 'bootcmd'",
1064 /*******************************************************************/
1065 /* iminfo - print header info for a requested image */
1066 /*******************************************************************/
1067 #if defined(CONFIG_CMD_IMI)
1068 int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1075 return image_info(load_addr);
1078 for (arg = 1; arg < argc; ++arg) {
1079 addr = simple_strtoul(argv[arg], NULL, 16);
1080 if (image_info(addr) != 0)
1086 static int image_info(ulong addr)
1088 void *hdr = (void *)addr;
1090 printf("\n## Checking Image at %08lx ...\n", addr);
1092 switch (genimg_get_format(hdr)) {
1093 case IMAGE_FORMAT_LEGACY:
1094 puts(" Legacy image found\n");
1095 if (!image_check_magic(hdr)) {
1096 puts(" Bad Magic Number\n");
1100 if (!image_check_hcrc(hdr)) {
1101 puts(" Bad Header Checksum\n");
1105 image_print_contents(hdr);
1107 puts(" Verifying Checksum ... ");
1108 if (!image_check_dcrc(hdr)) {
1109 puts(" Bad Data CRC\n");
1114 #if defined(CONFIG_FIT)
1115 case IMAGE_FORMAT_FIT:
1116 puts(" FIT image found\n");
1118 if (!fit_check_format(hdr)) {
1119 puts("Bad FIT image format!\n");
1123 fit_print_contents(hdr);
1125 if (!fit_all_image_check_hashes(hdr)) {
1126 puts("Bad hash in FIT image!\n");
1133 puts("Unknown image format!\n");
1141 iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
1142 "print header information for application image",
1144 " - print header information for application image starting at\n"
1145 " address 'addr' in memory; this includes verification of the\n"
1146 " image contents (magic number, header and payload checksums)"
1151 /*******************************************************************/
1152 /* imls - list all images found in flash */
1153 /*******************************************************************/
1154 #if defined(CONFIG_CMD_IMLS)
1155 int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1161 for (i = 0, info = &flash_info[0];
1162 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
1164 if (info->flash_id == FLASH_UNKNOWN)
1166 for (j = 0; j < info->sector_count; ++j) {
1168 hdr = (void *)info->start[j];
1172 switch (genimg_get_format(hdr)) {
1173 case IMAGE_FORMAT_LEGACY:
1174 if (!image_check_hcrc(hdr))
1177 printf("Legacy Image at %08lX:\n", (ulong)hdr);
1178 image_print_contents(hdr);
1180 puts(" Verifying Checksum ... ");
1181 if (!image_check_dcrc(hdr)) {
1182 puts("Bad Data CRC\n");
1187 #if defined(CONFIG_FIT)
1188 case IMAGE_FORMAT_FIT:
1189 if (!fit_check_format(hdr))
1192 printf("FIT Image at %08lX:\n", (ulong)hdr);
1193 fit_print_contents(hdr);
1209 imls, 1, 1, do_imls,
1210 "list all images found in flash",
1212 " - Prints information about all images found at sector\n"
1213 " boundaries in flash."
1217 /*******************************************************************/
1218 /* helper routines */
1219 /*******************************************************************/
1220 #ifdef CONFIG_SILENT_CONSOLE
1221 static void fixup_silent_linux(void)
1223 char buf[256], *start, *end;
1224 char *cmdline = getenv("bootargs");
1226 /* Only fix cmdline when requested */
1227 if (!(gd->flags & GD_FLG_SILENT))
1230 debug("before silent fix-up: %s\n", cmdline);
1232 start = strstr(cmdline, "console=");
1234 end = strchr(start, ' ');
1235 strncpy(buf, cmdline, (start - cmdline + 8));
1237 strcpy(buf + (start - cmdline + 8), end);
1239 buf[start - cmdline + 8] = '\0';
1241 strcpy(buf, cmdline);
1242 strcat(buf, " console=");
1245 strcpy(buf, "console=");
1248 setenv("bootargs", buf);
1249 debug("after silent fix-up: %s\n", buf);
1251 #endif /* CONFIG_SILENT_CONSOLE */
1254 /*******************************************************************/
1255 /* OS booting routines */
1256 /*******************************************************************/
1258 #ifdef CONFIG_BOOTM_NETBSD
1259 static int do_bootm_netbsd(int flag, int argc, char * const argv[],
1260 bootm_headers_t *images)
1262 void (*loader)(bd_t *, image_header_t *, char *, char *);
1263 image_header_t *os_hdr, *hdr;
1264 ulong kernel_data, kernel_len;
1268 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1271 #if defined(CONFIG_FIT)
1272 if (!images->legacy_hdr_valid) {
1273 fit_unsupported_reset("NetBSD");
1277 hdr = images->legacy_hdr_os;
1280 * Booting a (NetBSD) kernel image
1282 * This process is pretty similar to a standalone application:
1283 * The (first part of an multi-) image must be a stage-2 loader,
1284 * which in turn is responsible for loading & invoking the actual
1285 * kernel. The only differences are the parameters being passed:
1286 * besides the board info strucure, the loader expects a command
1287 * line, the name of the console device, and (optionally) the
1288 * address of the original image header.
1291 if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1292 image_multi_getimg(hdr, 1, &kernel_data, &kernel_len);
1298 #if defined(CONFIG_8xx_CONS_SMC1)
1300 #elif defined(CONFIG_8xx_CONS_SMC2)
1302 #elif defined(CONFIG_8xx_CONS_SCC2)
1304 #elif defined(CONFIG_8xx_CONS_SCC3)
1312 for (i = 2, len = 0; i < argc; i += 1)
1313 len += strlen(argv[i]) + 1;
1314 cmdline = malloc(len);
1316 for (i = 2, len = 0; i < argc; i += 1) {
1318 cmdline[len++] = ' ';
1319 strcpy(&cmdline[len], argv[i]);
1320 len += strlen(argv[i]);
1322 } else if ((cmdline = getenv("bootargs")) == NULL) {
1326 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
1328 printf("## Transferring control to NetBSD stage-2 loader "
1329 "(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 * const 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 * const 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_BOOTM_OSE)
1403 static int do_bootm_ose(int flag, int argc, char * const argv[],
1404 bootm_headers_t *images)
1406 void (*entry_point)(void);
1408 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1411 #if defined(CONFIG_FIT)
1412 if (!images->legacy_hdr_valid) {
1413 fit_unsupported_reset("OSE");
1418 entry_point = (void (*)(void))images->ep;
1420 printf("## Transferring control to OSE (at address %08lx) ...\n",
1421 (ulong)entry_point);
1423 show_boot_progress(15);
1433 #endif /* CONFIG_BOOTM_OSE */
1435 #if defined(CONFIG_CMD_ELF)
1436 static int do_bootm_vxworks(int flag, int argc, char * const argv[],
1437 bootm_headers_t *images)
1441 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1444 #if defined(CONFIG_FIT)
1445 if (!images->legacy_hdr_valid) {
1446 fit_unsupported_reset("VxWorks");
1451 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1452 setenv("loadaddr", str);
1453 do_bootvx(NULL, 0, 0, NULL);
1458 static int do_bootm_qnxelf(int flag, int argc, char * const argv[],
1459 bootm_headers_t *images)
1461 char *local_args[2];
1464 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1467 #if defined(CONFIG_FIT)
1468 if (!images->legacy_hdr_valid) {
1469 fit_unsupported_reset("QNX");
1474 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1475 local_args[0] = argv[0];
1476 local_args[1] = str; /* and provide it via the arguments */
1477 do_bootelf(NULL, 0, 2, local_args);
1483 #ifdef CONFIG_INTEGRITY
1484 static int do_bootm_integrity(int flag, int argc, char * const argv[],
1485 bootm_headers_t *images)
1487 void (*entry_point)(void);
1489 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1492 #if defined(CONFIG_FIT)
1493 if (!images->legacy_hdr_valid) {
1494 fit_unsupported_reset("INTEGRITY");
1499 entry_point = (void (*)(void))images->ep;
1501 printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
1502 (ulong)entry_point);
1504 show_boot_progress(15);
1507 * INTEGRITY Parameters: