2 * (C) Copyright 2000-2009
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * SPDX-License-Identifier: GPL-2.0+
17 #include <u-boot/zlib.h>
19 #include <environment.h>
21 #include <linux/ctype.h>
22 #include <asm/byteorder.h>
24 #include <linux/compiler.h>
26 #if defined(CONFIG_BOOTM_VXWORKS) && \
27 (defined(CONFIG_PPC) || defined(CONFIG_ARM))
31 #if defined(CONFIG_CMD_USB)
35 #if defined(CONFIG_OF_LIBFDT)
37 #include <fdt_support.h>
41 #include <lzma/LzmaTypes.h>
42 #include <lzma/LzmaDec.h>
43 #include <lzma/LzmaTools.h>
44 #endif /* CONFIG_LZMA */
47 #include <linux/lzo.h>
48 #endif /* CONFIG_LZO */
50 DECLARE_GLOBAL_DATA_PTR;
52 #ifndef CONFIG_SYS_BOOTM_LEN
53 #define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
57 extern void bz_internal_error(int);
60 #if defined(CONFIG_CMD_IMI)
61 static int image_info(unsigned long addr);
64 #if defined(CONFIG_CMD_IMLS)
66 #include <mtd/cfi_flash.h>
67 extern flash_info_t flash_info[]; /* info for FLASH chips */
70 #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
71 static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
74 #include <linux/err.h>
77 #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
78 static void fixup_silent_linux(void);
81 static int do_bootm_standalone(int flag, int argc, char * const argv[],
82 bootm_headers_t *images);
84 static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
85 char * const argv[], bootm_headers_t *images,
86 ulong *os_data, ulong *os_len);
89 * Continue booting an OS image; caller already has:
90 * - copied image header to global variable `header'
91 * - checked header magic number, checksums (both header & image),
92 * - verified image architecture (PPC) and type (KERNEL or MULTI),
93 * - loaded (first part of) image to header load address,
94 * - disabled interrupts.
96 * @flag: Flags indicating what to do (BOOTM_STATE_...)
97 * @argc: Number of arguments. Note that the arguments are shifted down
98 * so that 0 is the first argument not processed by U-Boot, and
99 * argc is adjusted accordingly. This avoids confusion as to how
100 * many arguments are available for the OS.
101 * @images: Pointers to os/initrd/fdt
102 * @return 1 on error. On success the OS boots so this function does
105 typedef int boot_os_fn(int flag, int argc, char * const argv[],
106 bootm_headers_t *images);
108 #ifdef CONFIG_BOOTM_LINUX
109 extern boot_os_fn do_bootm_linux;
111 #ifdef CONFIG_BOOTM_NETBSD
112 static boot_os_fn do_bootm_netbsd;
114 #if defined(CONFIG_LYNXKDI)
115 static boot_os_fn do_bootm_lynxkdi;
116 extern void lynxkdi_boot(image_header_t *);
118 #ifdef CONFIG_BOOTM_RTEMS
119 static boot_os_fn do_bootm_rtems;
121 #if defined(CONFIG_BOOTM_OSE)
122 static boot_os_fn do_bootm_ose;
124 #if defined(CONFIG_BOOTM_PLAN9)
125 static boot_os_fn do_bootm_plan9;
127 #if defined(CONFIG_BOOTM_VXWORKS) && \
128 (defined(CONFIG_PPC) || defined(CONFIG_ARM))
129 static boot_os_fn do_bootm_vxworks;
131 #if defined(CONFIG_CMD_ELF)
132 static boot_os_fn do_bootm_qnxelf;
133 int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
134 int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
136 #if defined(CONFIG_INTEGRITY)
137 static boot_os_fn do_bootm_integrity;
140 static boot_os_fn *boot_os[] = {
141 [IH_OS_U_BOOT] = do_bootm_standalone,
142 #ifdef CONFIG_BOOTM_LINUX
143 [IH_OS_LINUX] = do_bootm_linux,
145 #ifdef CONFIG_BOOTM_NETBSD
146 [IH_OS_NETBSD] = do_bootm_netbsd,
148 #ifdef CONFIG_LYNXKDI
149 [IH_OS_LYNXOS] = do_bootm_lynxkdi,
151 #ifdef CONFIG_BOOTM_RTEMS
152 [IH_OS_RTEMS] = do_bootm_rtems,
154 #if defined(CONFIG_BOOTM_OSE)
155 [IH_OS_OSE] = do_bootm_ose,
157 #if defined(CONFIG_BOOTM_PLAN9)
158 [IH_OS_PLAN9] = do_bootm_plan9,
160 #if defined(CONFIG_BOOTM_VXWORKS) && \
161 (defined(CONFIG_PPC) || defined(CONFIG_ARM))
162 [IH_OS_VXWORKS] = do_bootm_vxworks,
164 #if defined(CONFIG_CMD_ELF)
165 [IH_OS_QNX] = do_bootm_qnxelf,
167 #ifdef CONFIG_INTEGRITY
168 [IH_OS_INTEGRITY] = do_bootm_integrity,
172 bootm_headers_t images; /* pointers to os/initrd/fdt images */
174 /* Allow for arch specific config before we boot */
175 static void __arch_preboot_os(void)
177 /* please define platform specific arch_preboot_os() */
179 void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
181 #define IH_INITRD_ARCH IH_ARCH_DEFAULT
184 static void boot_start_lmb(bootm_headers_t *images)
187 phys_size_t mem_size;
189 lmb_init(&images->lmb);
191 mem_start = getenv_bootm_low();
192 mem_size = getenv_bootm_size();
194 lmb_add(&images->lmb, (phys_addr_t)mem_start, mem_size);
196 arch_lmb_reserve(&images->lmb);
197 board_lmb_reserve(&images->lmb);
200 #define lmb_reserve(lmb, base, size)
201 static inline void boot_start_lmb(bootm_headers_t *images) { }
204 static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
206 memset((void *)&images, 0, sizeof(images));
207 images.verify = getenv_yesno("verify");
209 boot_start_lmb(&images);
211 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_START, "bootm_start");
212 images.state = BOOTM_STATE_START;
217 static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,
221 bool ep_found = false;
223 /* get kernel image header, start address and length */
224 os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
225 &images, &images.os.image_start, &images.os.image_len);
226 if (images.os.image_len == 0) {
227 puts("ERROR: can't get kernel image!\n");
231 /* get image parameters */
232 switch (genimg_get_format(os_hdr)) {
233 #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
234 case IMAGE_FORMAT_LEGACY:
235 images.os.type = image_get_type(os_hdr);
236 images.os.comp = image_get_comp(os_hdr);
237 images.os.os = image_get_os(os_hdr);
239 images.os.end = image_get_image_end(os_hdr);
240 images.os.load = image_get_load(os_hdr);
243 #if defined(CONFIG_FIT)
244 case IMAGE_FORMAT_FIT:
245 if (fit_image_get_type(images.fit_hdr_os,
246 images.fit_noffset_os, &images.os.type)) {
247 puts("Can't get image type!\n");
248 bootstage_error(BOOTSTAGE_ID_FIT_TYPE);
252 if (fit_image_get_comp(images.fit_hdr_os,
253 images.fit_noffset_os, &images.os.comp)) {
254 puts("Can't get image compression!\n");
255 bootstage_error(BOOTSTAGE_ID_FIT_COMPRESSION);
259 if (fit_image_get_os(images.fit_hdr_os,
260 images.fit_noffset_os, &images.os.os)) {
261 puts("Can't get image OS!\n");
262 bootstage_error(BOOTSTAGE_ID_FIT_OS);
266 images.os.end = fit_get_end(images.fit_hdr_os);
268 if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os,
270 puts("Can't get image load address!\n");
271 bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR);
276 #ifdef CONFIG_ANDROID_BOOT_IMAGE
277 case IMAGE_FORMAT_ANDROID:
278 images.os.type = IH_TYPE_KERNEL;
279 images.os.comp = IH_COMP_NONE;
280 images.os.os = IH_OS_LINUX;
281 images.ep = images.os.load;
284 images.os.end = android_image_get_end(os_hdr);
285 images.os.load = android_image_get_kload(os_hdr);
289 puts("ERROR: unknown image format type!\n");
293 /* find kernel entry point */
294 if (images.legacy_hdr_valid) {
295 images.ep = image_get_ep(&images.legacy_hdr_os_copy);
296 #if defined(CONFIG_FIT)
297 } else if (images.fit_uname_os) {
300 ret = fit_image_get_entry(images.fit_hdr_os,
301 images.fit_noffset_os, &images.ep);
303 puts("Can't get entry point property!\n");
307 } else if (!ep_found) {
308 puts("Could not find kernel entry point!\n");
312 if (images.os.type == IH_TYPE_KERNEL_NOLOAD) {
313 images.os.load = images.os.image_start;
314 images.ep += images.os.load;
317 images.os.start = (ulong)os_hdr;
322 static int bootm_find_ramdisk(int flag, int argc, char * const argv[])
327 ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH,
328 &images.rd_start, &images.rd_end);
330 puts("Ramdisk image is corrupt or invalid\n");
337 #if defined(CONFIG_OF_LIBFDT)
338 static int bootm_find_fdt(int flag, int argc, char * const argv[])
342 /* find flattened device tree */
343 ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, &images,
344 &images.ft_addr, &images.ft_len);
346 puts("Could not find a valid device tree\n");
350 set_working_fdt_addr(images.ft_addr);
356 static int bootm_find_other(cmd_tbl_t *cmdtp, int flag, int argc,
359 if (((images.os.type == IH_TYPE_KERNEL) ||
360 (images.os.type == IH_TYPE_KERNEL_NOLOAD) ||
361 (images.os.type == IH_TYPE_MULTI)) &&
362 (images.os.os == IH_OS_LINUX ||
363 images.os.os == IH_OS_VXWORKS)) {
364 if (bootm_find_ramdisk(flag, argc, argv))
367 #if defined(CONFIG_OF_LIBFDT)
368 if (bootm_find_fdt(flag, argc, argv))
376 #define BOOTM_ERR_RESET -1
377 #define BOOTM_ERR_OVERLAP -2
378 #define BOOTM_ERR_UNIMPLEMENTED -3
379 static int bootm_load_os(bootm_headers_t *images, unsigned long *load_end,
382 image_info_t os = images->os;
383 uint8_t comp = os.comp;
384 ulong load = os.load;
385 ulong blob_start = os.start;
386 ulong blob_end = os.end;
387 ulong image_start = os.image_start;
388 ulong image_len = os.image_len;
389 __maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN;
391 void *load_buf, *image_buf;
392 #if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
394 #endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
396 const char *type_name = genimg_get_type_name(os.type);
398 load_buf = map_sysmem(load, unc_len);
399 image_buf = map_sysmem(image_start, image_len);
402 if (load == image_start) {
403 printf(" XIP %s ... ", type_name);
406 printf(" Loading %s ... ", type_name);
407 memmove_wd(load_buf, image_buf, image_len, CHUNKSZ);
409 *load_end = load + image_len;
413 printf(" Uncompressing %s ... ", type_name);
414 if (gunzip(load_buf, unc_len, image_buf, &image_len) != 0) {
415 puts("GUNZIP: uncompress, out-of-mem or overwrite "
416 "error - must RESET board to recover\n");
418 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
419 return BOOTM_ERR_RESET;
422 *load_end = load + image_len;
424 #endif /* CONFIG_GZIP */
427 printf(" Uncompressing %s ... ", type_name);
429 * If we've got less than 4 MB of malloc() space,
430 * use slower decompression algorithm which requires
431 * at most 2300 KB of memory.
433 int i = BZ2_bzBuffToBuffDecompress(load_buf, &unc_len,
434 image_buf, image_len,
435 CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
437 printf("BUNZIP2: uncompress or overwrite error %d "
438 "- must RESET board to recover\n", i);
440 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
441 return BOOTM_ERR_RESET;
444 *load_end = load + unc_len;
446 #endif /* CONFIG_BZIP2 */
449 SizeT lzma_len = unc_len;
450 printf(" Uncompressing %s ... ", type_name);
452 ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len,
453 image_buf, image_len);
456 printf("LZMA: uncompress or overwrite error %d "
457 "- must RESET board to recover\n", ret);
458 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
459 return BOOTM_ERR_RESET;
461 *load_end = load + unc_len;
464 #endif /* CONFIG_LZMA */
467 size_t size = unc_len;
469 printf(" Uncompressing %s ... ", type_name);
471 ret = lzop_decompress(image_buf, image_len, load_buf, &size);
472 if (ret != LZO_E_OK) {
473 printf("LZO: uncompress or overwrite error %d "
474 "- must RESET board to recover\n", ret);
476 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
477 return BOOTM_ERR_RESET;
480 *load_end = load + size;
483 #endif /* CONFIG_LZO */
485 printf("Unimplemented compression type %d\n", comp);
486 return BOOTM_ERR_UNIMPLEMENTED;
489 flush_cache(load, (*load_end - load) * sizeof(ulong));
492 debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
493 bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED);
495 if (!no_overlap && (load < blob_end) && (*load_end > blob_start)) {
496 debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n",
497 blob_start, blob_end);
498 debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load,
501 /* Check what type of image this is. */
502 if (images->legacy_hdr_valid) {
503 if (image_get_type(&images->legacy_hdr_os_copy)
505 puts("WARNING: legacy format multi component image overwritten\n");
506 return BOOTM_ERR_OVERLAP;
508 puts("ERROR: new format image overwritten - must RESET the board to recover\n");
509 bootstage_error(BOOTSTAGE_ID_OVERWRITTEN);
510 return BOOTM_ERR_RESET;
517 static int do_bootm_standalone(int flag, int argc, char * const argv[],
518 bootm_headers_t *images)
521 int (*appl)(int, char * const []);
523 /* Don't start if "autostart" is set to "no" */
524 if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
525 setenv_hex("filesize", images->os.image_len);
528 appl = (int (*)(int, char * const []))images->ep;
533 /* we overload the cmd field with our state machine info instead of a
534 * function pointer */
535 static cmd_tbl_t cmd_bootm_sub[] = {
536 U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
537 U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
538 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
539 U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
541 #ifdef CONFIG_OF_LIBFDT
542 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
544 U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
545 U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
546 U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
547 U_BOOT_CMD_MKENT(fake, 0, 1, (void *)BOOTM_STATE_OS_FAKE_GO, "", ""),
548 U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
551 static int boot_selected_os(int argc, char * const argv[], int state,
552 bootm_headers_t *images, boot_os_fn *boot_fn)
555 boot_fn(state, argc, argv, images);
557 /* Stand-alone may return when 'autostart' is 'no' */
558 if (images->os.type == IH_TYPE_STANDALONE ||
559 state == BOOTM_STATE_OS_FAKE_GO) /* We expect to return */
561 bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED);
563 puts("\n## Control returned to monitor - resetting...\n");
565 return BOOTM_ERR_RESET;
569 * bootm_disable_interrupts() - Disable interrupts in preparation for load/boot
571 * @return interrupt flag (0 if interrupts were disabled, non-zero if they were
574 static ulong bootm_disable_interrupts(void)
579 * We have reached the point of no return: we are going to
580 * overwrite all exception vector code, so we cannot easily
581 * recover from any failures any more...
583 iflag = disable_interrupts();
584 #ifdef CONFIG_NETCONSOLE
585 /* Stop the ethernet stack if NetConsole could have left it up */
587 eth_unregister(eth_get_dev());
590 #if defined(CONFIG_CMD_USB)
592 * turn off USB to prevent the host controller from writing to the
593 * SDRAM while Linux is booting. This could happen (at least for OHCI
594 * controller), because the HCCA (Host Controller Communication Area)
595 * lies within the SDRAM and the host controller writes continously to
596 * this area (as busmaster!). The HccaFrameNumber is for example
597 * updated every 1 ms within the HCCA structure in SDRAM! For more
598 * details see the OpenHCI specification.
606 * Execute selected states of the bootm command.
608 * Note the arguments to this state must be the first argument, Any 'bootm'
609 * or sub-command arguments must have already been taken.
611 * Note that if states contains more than one flag it MUST contain
612 * BOOTM_STATE_START, since this handles and consumes the command line args.
614 * Also note that aside from boot_os_fn functions and bootm_load_os no other
615 * functions we store the return value of in 'ret' may use a negative return
616 * value, without special handling.
618 * @param cmdtp Pointer to bootm command table entry
619 * @param flag Command flags (CMD_FLAG_...)
620 * @param argc Number of subcommand arguments (0 = no arguments)
621 * @param argv Arguments
622 * @param states Mask containing states to run (BOOTM_STATE_...)
623 * @param images Image header information
624 * @param boot_progress 1 to show boot progress, 0 to not do this
625 * @return 0 if ok, something else on error. Some errors will cause this
626 * function to perform a reboot! If states contains BOOTM_STATE_OS_GO
627 * then the intent is to boot an OS, so this function will not return
628 * unless the image type is standalone.
630 static int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc,
631 char * const argv[], int states, bootm_headers_t *images,
636 int ret = 0, need_boot_fn;
638 images->state |= states;
641 * Work through the states and see how far we get. We stop on
644 if (states & BOOTM_STATE_START)
645 ret = bootm_start(cmdtp, flag, argc, argv);
647 if (!ret && (states & BOOTM_STATE_FINDOS))
648 ret = bootm_find_os(cmdtp, flag, argc, argv);
650 if (!ret && (states & BOOTM_STATE_FINDOTHER)) {
651 ret = bootm_find_other(cmdtp, flag, argc, argv);
652 argc = 0; /* consume the args */
656 if (!ret && (states & BOOTM_STATE_LOADOS)) {
659 iflag = bootm_disable_interrupts();
660 ret = bootm_load_os(images, &load_end, 0);
662 lmb_reserve(&images->lmb, images->os.load,
663 (load_end - images->os.load));
664 else if (ret && ret != BOOTM_ERR_OVERLAP)
666 else if (ret == BOOTM_ERR_OVERLAP)
668 #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
669 if (images->os.os == IH_OS_LINUX)
670 fixup_silent_linux();
674 /* Relocate the ramdisk */
675 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
676 if (!ret && (states & BOOTM_STATE_RAMDISK)) {
677 ulong rd_len = images->rd_end - images->rd_start;
679 ret = boot_ramdisk_high(&images->lmb, images->rd_start,
680 rd_len, &images->initrd_start, &images->initrd_end);
682 setenv_hex("initrd_start", images->initrd_start);
683 setenv_hex("initrd_end", images->initrd_end);
687 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_LMB)
688 if (!ret && (states & BOOTM_STATE_FDT)) {
689 boot_fdt_add_mem_rsv_regions(&images->lmb, images->ft_addr);
690 ret = boot_relocate_fdt(&images->lmb, &images->ft_addr,
695 /* From now on, we need the OS boot function */
698 boot_fn = boot_os[images->os.os];
699 need_boot_fn = states & (BOOTM_STATE_OS_CMDLINE |
700 BOOTM_STATE_OS_BD_T | BOOTM_STATE_OS_PREP |
701 BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO);
702 if (boot_fn == NULL && need_boot_fn) {
705 printf("ERROR: booting os '%s' (%d) is not supported\n",
706 genimg_get_os_name(images->os.os), images->os.os);
707 bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS);
711 /* Call various other states that are not generally used */
712 if (!ret && (states & BOOTM_STATE_OS_CMDLINE))
713 ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, images);
714 if (!ret && (states & BOOTM_STATE_OS_BD_T))
715 ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images);
716 if (!ret && (states & BOOTM_STATE_OS_PREP))
717 ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, images);
720 /* Pretend to run the OS, then run a user command */
721 if (!ret && (states & BOOTM_STATE_OS_FAKE_GO)) {
722 char *cmd_list = getenv("fakegocmd");
724 ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_FAKE_GO,
726 if (!ret && cmd_list)
727 ret = run_command_list(cmd_list, -1, flag);
731 /* Check for unsupported subcommand. */
733 puts("subcommand not supported\n");
737 /* Now run the OS! We hope this doesn't return */
738 if (!ret && (states & BOOTM_STATE_OS_GO))
739 ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_GO,
742 /* Deal with any fallout */
747 if (ret == BOOTM_ERR_UNIMPLEMENTED)
748 bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL);
749 else if (ret == BOOTM_ERR_RESET)
750 do_reset(cmdtp, flag, argc, argv);
755 static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
762 c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
766 state = (long)c->cmd;
767 if (state == BOOTM_STATE_START)
768 state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER;
770 /* Unrecognized command */
771 return CMD_RET_USAGE;
774 if (state != BOOTM_STATE_START && images.state >= state) {
775 printf("Trying to execute a command out of order\n");
776 return CMD_RET_USAGE;
779 ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0);
784 /*******************************************************************/
785 /* bootm - boot application image from image in memory */
786 /*******************************************************************/
788 int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
790 #ifdef CONFIG_NEEDS_MANUAL_RELOC
791 static int relocated = 0;
796 /* relocate boot function table */
797 for (i = 0; i < ARRAY_SIZE(boot_os); i++)
798 if (boot_os[i] != NULL)
799 boot_os[i] += gd->reloc_off;
801 /* relocate names of sub-command table */
802 for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++)
803 cmd_bootm_sub[i].name += gd->reloc_off;
809 /* determine if we have a sub command */
814 simple_strtoul(argv[0], &endp, 16);
815 /* endp pointing to NULL means that argv[0] was just a
816 * valid number, pass it along to the normal bootm processing
818 * If endp is ':' or '#' assume a FIT identifier so pass
819 * along for normal processing.
821 * Right now we assume the first arg should never be '-'
823 if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
824 return do_bootm_subcommand(cmdtp, flag, argc, argv);
827 return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START |
828 BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER |
830 #if defined(CONFIG_PPC) || defined(CONFIG_MIPS)
831 BOOTM_STATE_OS_CMDLINE |
833 BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
834 BOOTM_STATE_OS_GO, &images, 1);
837 int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
839 const char *ep = getenv("autostart");
841 if (ep && !strcmp(ep, "yes")) {
843 local_args[0] = (char *)cmd;
844 local_args[1] = NULL;
845 printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
846 return do_bootm(cmdtp, 0, 1, local_args);
852 #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
854 * image_get_kernel - verify legacy format kernel image
855 * @img_addr: in RAM address of the legacy format image to be verified
856 * @verify: data CRC verification flag
858 * image_get_kernel() verifies legacy image integrity and returns pointer to
859 * legacy image header if image verification was completed successfully.
862 * pointer to a legacy image header if valid image was found
863 * otherwise return NULL
865 static image_header_t *image_get_kernel(ulong img_addr, int verify)
867 image_header_t *hdr = (image_header_t *)img_addr;
869 if (!image_check_magic(hdr)) {
870 puts("Bad Magic Number\n");
871 bootstage_error(BOOTSTAGE_ID_CHECK_MAGIC);
874 bootstage_mark(BOOTSTAGE_ID_CHECK_HEADER);
876 if (!image_check_hcrc(hdr)) {
877 puts("Bad Header Checksum\n");
878 bootstage_error(BOOTSTAGE_ID_CHECK_HEADER);
882 bootstage_mark(BOOTSTAGE_ID_CHECK_CHECKSUM);
883 image_print_contents(hdr);
886 puts(" Verifying Checksum ... ");
887 if (!image_check_dcrc(hdr)) {
888 printf("Bad Data CRC\n");
889 bootstage_error(BOOTSTAGE_ID_CHECK_CHECKSUM);
894 bootstage_mark(BOOTSTAGE_ID_CHECK_ARCH);
896 if (!image_check_target_arch(hdr)) {
897 printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr));
898 bootstage_error(BOOTSTAGE_ID_CHECK_ARCH);
906 * boot_get_kernel - find kernel image
907 * @os_data: pointer to a ulong variable, will hold os data start address
908 * @os_len: pointer to a ulong variable, will hold os data length
910 * boot_get_kernel() tries to find a kernel image, verifies its integrity
911 * and locates kernel data.
914 * pointer to image header if valid image was found, plus kernel start
915 * address and length, otherwise NULL
917 static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
918 char * const argv[], bootm_headers_t *images, ulong *os_data,
921 #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
926 #if defined(CONFIG_FIT)
927 const char *fit_uname_config = NULL;
928 const char *fit_uname_kernel = NULL;
932 /* find out kernel image address */
934 img_addr = load_addr;
935 debug("* kernel: default image load address = 0x%08lx\n",
937 #if defined(CONFIG_FIT)
938 } else if (fit_parse_conf(argv[0], load_addr, &img_addr,
939 &fit_uname_config)) {
940 debug("* kernel: config '%s' from image at 0x%08lx\n",
941 fit_uname_config, img_addr);
942 } else if (fit_parse_subimage(argv[0], load_addr, &img_addr,
943 &fit_uname_kernel)) {
944 debug("* kernel: subimage '%s' from image at 0x%08lx\n",
945 fit_uname_kernel, img_addr);
948 img_addr = simple_strtoul(argv[0], NULL, 16);
949 debug("* kernel: cmdline image address = 0x%08lx\n", img_addr);
952 bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC);
954 /* copy from dataflash if needed */
955 img_addr = genimg_get_image(img_addr);
957 /* check image type, for FIT images get FIT kernel node */
958 *os_data = *os_len = 0;
959 buf = map_sysmem(img_addr, 0);
960 switch (genimg_get_format(buf)) {
961 #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
962 case IMAGE_FORMAT_LEGACY:
963 printf("## Booting kernel from Legacy Image at %08lx ...\n",
965 hdr = image_get_kernel(img_addr, images->verify);
968 bootstage_mark(BOOTSTAGE_ID_CHECK_IMAGETYPE);
970 /* get os_data and os_len */
971 switch (image_get_type(hdr)) {
973 case IH_TYPE_KERNEL_NOLOAD:
974 *os_data = image_get_data(hdr);
975 *os_len = image_get_data_size(hdr);
978 image_multi_getimg(hdr, 0, os_data, os_len);
980 case IH_TYPE_STANDALONE:
981 *os_data = image_get_data(hdr);
982 *os_len = image_get_data_size(hdr);
985 printf("Wrong Image Type for %s command\n",
987 bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE);
992 * copy image header to allow for image overwrites during
993 * kernel decompression.
995 memmove(&images->legacy_hdr_os_copy, hdr,
996 sizeof(image_header_t));
998 /* save pointer to image header */
999 images->legacy_hdr_os = hdr;
1001 images->legacy_hdr_valid = 1;
1002 bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE);
1005 #if defined(CONFIG_FIT)
1006 case IMAGE_FORMAT_FIT:
1007 os_noffset = fit_image_load(images, FIT_KERNEL_PROP,
1009 &fit_uname_kernel, &fit_uname_config,
1010 IH_ARCH_DEFAULT, IH_TYPE_KERNEL,
1011 BOOTSTAGE_ID_FIT_KERNEL_START,
1012 FIT_LOAD_IGNORED, os_data, os_len);
1016 images->fit_hdr_os = map_sysmem(img_addr, 0);
1017 images->fit_uname_os = fit_uname_kernel;
1018 images->fit_uname_cfg = fit_uname_config;
1019 images->fit_noffset_os = os_noffset;
1022 #ifdef CONFIG_ANDROID_BOOT_IMAGE
1023 case IMAGE_FORMAT_ANDROID:
1024 printf("## Booting Android Image at 0x%08lx ...\n", img_addr);
1025 if (android_image_get_kernel((void *)img_addr, images->verify,
1031 printf("Wrong Image Format for %s command\n", cmdtp->name);
1032 bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO);
1036 debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
1037 *os_data, *os_len, *os_len);
1042 #ifdef CONFIG_SYS_LONGHELP
1043 static char bootm_help_text[] =
1044 "[addr [arg ...]]\n - boot application image stored in memory\n"
1045 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
1046 "\t'arg' can be the address of an initrd image\n"
1047 #if defined(CONFIG_OF_LIBFDT)
1048 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
1049 "\ta third argument is required which is the address of the\n"
1050 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1051 "\tuse a '-' for the second argument. If you do not pass a third\n"
1052 "\ta bd_info struct will be passed instead\n"
1054 #if defined(CONFIG_FIT)
1055 "\t\nFor the new multi component uImage format (FIT) addresses\n"
1056 "\tmust be extened to include component or configuration unit name:\n"
1057 "\taddr:<subimg_uname> - direct component image specification\n"
1058 "\taddr#<conf_uname> - configuration specification\n"
1059 "\tUse iminfo command to get the list of existing component\n"
1060 "\timages and configurations.\n"
1062 "\nSub-commands to do part of the bootm sequence. The sub-commands "
1064 "issued in the order below (it's ok to not issue all sub-commands):\n"
1065 "\tstart [addr [arg ...]]\n"
1066 "\tloados - load OS image\n"
1067 #if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH)
1068 "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
1070 #if defined(CONFIG_OF_LIBFDT)
1071 "\tfdt - relocate flat device tree\n"
1073 "\tcmdline - OS specific command line processing/setup\n"
1074 "\tbdt - OS specific bd_t processing\n"
1075 "\tprep - OS specific prep before relocation or go\n"
1080 bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
1081 "boot application image from memory", bootm_help_text
1084 /*******************************************************************/
1085 /* bootd - boot default image */
1086 /*******************************************************************/
1087 #if defined(CONFIG_CMD_BOOTD)
1088 int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1092 if (run_command(getenv("bootcmd"), flag) < 0)
1098 boot, 1, 1, do_bootd,
1099 "boot default, i.e., run 'bootcmd'",
1103 /* keep old command name "bootd" for backward compatibility */
1105 bootd, 1, 1, do_bootd,
1106 "boot default, i.e., run 'bootcmd'",
1113 /*******************************************************************/
1114 /* iminfo - print header info for a requested image */
1115 /*******************************************************************/
1116 #if defined(CONFIG_CMD_IMI)
1117 static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1124 return image_info(load_addr);
1127 for (arg = 1; arg < argc; ++arg) {
1128 addr = simple_strtoul(argv[arg], NULL, 16);
1129 if (image_info(addr) != 0)
1135 static int image_info(ulong addr)
1137 void *hdr = (void *)addr;
1139 printf("\n## Checking Image at %08lx ...\n", addr);
1141 switch (genimg_get_format(hdr)) {
1142 #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
1143 case IMAGE_FORMAT_LEGACY:
1144 puts(" Legacy image found\n");
1145 if (!image_check_magic(hdr)) {
1146 puts(" Bad Magic Number\n");
1150 if (!image_check_hcrc(hdr)) {
1151 puts(" Bad Header Checksum\n");
1155 image_print_contents(hdr);
1157 puts(" Verifying Checksum ... ");
1158 if (!image_check_dcrc(hdr)) {
1159 puts(" Bad Data CRC\n");
1165 #if defined(CONFIG_FIT)
1166 case IMAGE_FORMAT_FIT:
1167 puts(" FIT image found\n");
1169 if (!fit_check_format(hdr)) {
1170 puts("Bad FIT image format!\n");
1174 fit_print_contents(hdr);
1176 if (!fit_all_image_verify(hdr)) {
1177 puts("Bad hash in FIT image!\n");
1184 puts("Unknown image format!\n");
1192 iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
1193 "print header information for application image",
1195 " - print header information for application image starting at\n"
1196 " address 'addr' in memory; this includes verification of the\n"
1197 " image contents (magic number, header and payload checksums)"
1202 /*******************************************************************/
1203 /* imls - list all images found in flash */
1204 /*******************************************************************/
1205 #if defined(CONFIG_CMD_IMLS)
1206 static int do_imls_nor(void)
1212 for (i = 0, info = &flash_info[0];
1213 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
1215 if (info->flash_id == FLASH_UNKNOWN)
1217 for (j = 0; j < info->sector_count; ++j) {
1219 hdr = (void *)info->start[j];
1223 switch (genimg_get_format(hdr)) {
1224 #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
1225 case IMAGE_FORMAT_LEGACY:
1226 if (!image_check_hcrc(hdr))
1229 printf("Legacy Image at %08lX:\n", (ulong)hdr);
1230 image_print_contents(hdr);
1232 puts(" Verifying Checksum ... ");
1233 if (!image_check_dcrc(hdr)) {
1234 puts("Bad Data CRC\n");
1240 #if defined(CONFIG_FIT)
1241 case IMAGE_FORMAT_FIT:
1242 if (!fit_check_format(hdr))
1245 printf("FIT Image at %08lX:\n", (ulong)hdr);
1246 fit_print_contents(hdr);
1261 #if defined(CONFIG_CMD_IMLS_NAND)
1262 static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off,
1268 imgdata = malloc(len);
1270 printf("May be a Legacy Image at NAND device %d offset %08llX:\n",
1272 printf(" Low memory(cannot allocate memory for image)\n");
1276 ret = nand_read_skip_bad(nand, off, &len,
1278 if (ret < 0 && ret != -EUCLEAN) {
1283 if (!image_check_hcrc(imgdata)) {
1288 printf("Legacy Image at NAND device %d offset %08llX:\n",
1290 image_print_contents(imgdata);
1292 puts(" Verifying Checksum ... ");
1293 if (!image_check_dcrc(imgdata))
1294 puts("Bad Data CRC\n");
1303 static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off,
1309 imgdata = malloc(len);
1311 printf("May be a FIT Image at NAND device %d offset %08llX:\n",
1313 printf(" Low memory(cannot allocate memory for image)\n");
1317 ret = nand_read_skip_bad(nand, off, &len,
1319 if (ret < 0 && ret != -EUCLEAN) {
1324 if (!fit_check_format(imgdata)) {
1329 printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off);
1331 fit_print_contents(imgdata);
1337 static int do_imls_nand(void)
1340 int nand_dev = nand_curr_device;
1345 if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) {
1346 puts("\nNo NAND devices available\n");
1352 for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) {
1353 nand = &nand_info[nand_dev];
1354 if (!nand->name || !nand->size)
1357 for (off = 0; off < nand->size; off += nand->erasesize) {
1358 const image_header_t *header;
1361 if (nand_block_isbad(nand, off))
1364 len = sizeof(buffer);
1366 ret = nand_read(nand, off, &len, (u8 *)buffer);
1367 if (ret < 0 && ret != -EUCLEAN) {
1368 printf("NAND read error %d at offset %08llX\n",
1373 switch (genimg_get_format(buffer)) {
1374 #if defined(CONFIG_IMAGE_FORMAT_LEGACY)
1375 case IMAGE_FORMAT_LEGACY:
1376 header = (const image_header_t *)buffer;
1378 len = image_get_image_size(header);
1379 nand_imls_legacyimage(nand, nand_dev, off, len);
1382 #if defined(CONFIG_FIT)
1383 case IMAGE_FORMAT_FIT:
1384 len = fit_get_size(buffer);
1385 nand_imls_fitimage(nand, nand_dev, off, len);
1396 #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
1397 static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1399 int ret_nor = 0, ret_nand = 0;
1401 #if defined(CONFIG_CMD_IMLS)
1402 ret_nor = do_imls_nor();
1405 #if defined(CONFIG_CMD_IMLS_NAND)
1406 ret_nand = do_imls_nand();
1419 imls, 1, 1, do_imls,
1420 "list all images found in flash",
1422 " - Prints information about all images found at sector/block\n"
1423 " boundaries in nor/nand flash."
1427 /*******************************************************************/
1428 /* helper routines */
1429 /*******************************************************************/
1430 #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
1432 #define CONSOLE_ARG "console="
1433 #define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1)
1435 static void fixup_silent_linux(void)
1438 const char *env_val;
1439 char *cmdline = getenv("bootargs");
1443 * Only fix cmdline when requested. The environment variable can be:
1445 * no - we never fixup
1446 * yes - we always fixup
1447 * unset - we rely on the console silent flag
1449 want_silent = getenv_yesno("silent_linux");
1450 if (want_silent == 0)
1452 else if (want_silent == -1 && !(gd->flags & GD_FLG_SILENT))
1455 debug("before silent fix-up: %s\n", cmdline);
1456 if (cmdline && (cmdline[0] != '\0')) {
1457 char *start = strstr(cmdline, CONSOLE_ARG);
1459 /* Allocate space for maximum possible new command line */
1460 buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_LEN + 1);
1462 debug("%s: out of memory\n", __func__);
1467 char *end = strchr(start, ' ');
1468 int num_start_bytes = start - cmdline + CONSOLE_ARG_LEN;
1470 strncpy(buf, cmdline, num_start_bytes);
1472 strcpy(buf + num_start_bytes, end);
1474 buf[num_start_bytes] = '\0';
1476 sprintf(buf, "%s %s", cmdline, CONSOLE_ARG);
1481 env_val = CONSOLE_ARG;
1484 setenv("bootargs", env_val);
1485 debug("after silent fix-up: %s\n", env_val);
1488 #endif /* CONFIG_SILENT_CONSOLE */
1490 #if defined(CONFIG_BOOTM_NETBSD) || defined(CONFIG_BOOTM_PLAN9)
1491 static void copy_args(char *dest, int argc, char * const argv[], char delim)
1495 for (i = 0; i < argc; i++) {
1498 strcpy(dest, argv[i]);
1499 dest += strlen(argv[i]);
1504 /*******************************************************************/
1505 /* OS booting routines */
1506 /*******************************************************************/
1508 #ifdef CONFIG_BOOTM_NETBSD
1509 static int do_bootm_netbsd(int flag, int argc, char * const argv[],
1510 bootm_headers_t *images)
1512 void (*loader)(bd_t *, image_header_t *, char *, char *);
1513 image_header_t *os_hdr, *hdr;
1514 ulong kernel_data, kernel_len;
1518 if (flag != BOOTM_STATE_OS_GO)
1521 #if defined(CONFIG_FIT)
1522 if (!images->legacy_hdr_valid) {
1523 fit_unsupported_reset("NetBSD");
1527 hdr = images->legacy_hdr_os;
1530 * Booting a (NetBSD) kernel image
1532 * This process is pretty similar to a standalone application:
1533 * The (first part of an multi-) image must be a stage-2 loader,
1534 * which in turn is responsible for loading & invoking the actual
1535 * kernel. The only differences are the parameters being passed:
1536 * besides the board info strucure, the loader expects a command
1537 * line, the name of the console device, and (optionally) the
1538 * address of the original image header.
1541 if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1542 image_multi_getimg(hdr, 1, &kernel_data, &kernel_len);
1548 #if defined(CONFIG_8xx_CONS_SMC1)
1550 #elif defined(CONFIG_8xx_CONS_SMC2)
1552 #elif defined(CONFIG_8xx_CONS_SCC2)
1554 #elif defined(CONFIG_8xx_CONS_SCC3)
1562 for (i = 0, len = 0; i < argc; i += 1)
1563 len += strlen(argv[i]) + 1;
1564 cmdline = malloc(len);
1565 copy_args(cmdline, argc, argv, ' ');
1566 } else if ((cmdline = getenv("bootargs")) == NULL) {
1570 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
1572 printf("## Transferring control to NetBSD stage-2 loader "
1573 "(at address %08lx) ...\n",
1576 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1579 * NetBSD Stage-2 Loader Parameters:
1580 * arg[0]: pointer to board info data
1581 * arg[1]: image load address
1582 * arg[2]: char pointer to the console device to use
1583 * arg[3]: char pointer to the boot arguments
1585 (*loader)(gd->bd, os_hdr, consdev, cmdline);
1589 #endif /* CONFIG_BOOTM_NETBSD*/
1591 #ifdef CONFIG_LYNXKDI
1592 static int do_bootm_lynxkdi(int flag, int argc, char * const argv[],
1593 bootm_headers_t *images)
1595 image_header_t *hdr = &images->legacy_hdr_os_copy;
1597 if (flag != BOOTM_STATE_OS_GO)
1600 #if defined(CONFIG_FIT)
1601 if (!images->legacy_hdr_valid) {
1602 fit_unsupported_reset("Lynx");
1607 lynxkdi_boot((image_header_t *)hdr);
1611 #endif /* CONFIG_LYNXKDI */
1613 #ifdef CONFIG_BOOTM_RTEMS
1614 static int do_bootm_rtems(int flag, int argc, char * const argv[],
1615 bootm_headers_t *images)
1617 void (*entry_point)(bd_t *);
1619 if (flag != BOOTM_STATE_OS_GO)
1622 #if defined(CONFIG_FIT)
1623 if (!images->legacy_hdr_valid) {
1624 fit_unsupported_reset("RTEMS");
1629 entry_point = (void (*)(bd_t *))images->ep;
1631 printf("## Transferring control to RTEMS (at address %08lx) ...\n",
1632 (ulong)entry_point);
1634 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1638 * r3: ptr to board info data
1640 (*entry_point)(gd->bd);
1644 #endif /* CONFIG_BOOTM_RTEMS */
1646 #if defined(CONFIG_BOOTM_OSE)
1647 static int do_bootm_ose(int flag, int argc, char * const argv[],
1648 bootm_headers_t *images)
1650 void (*entry_point)(void);
1652 if (flag != BOOTM_STATE_OS_GO)
1655 #if defined(CONFIG_FIT)
1656 if (!images->legacy_hdr_valid) {
1657 fit_unsupported_reset("OSE");
1662 entry_point = (void (*)(void))images->ep;
1664 printf("## Transferring control to OSE (at address %08lx) ...\n",
1665 (ulong)entry_point);
1667 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1677 #endif /* CONFIG_BOOTM_OSE */
1679 #if defined(CONFIG_BOOTM_PLAN9)
1680 static int do_bootm_plan9(int flag, int argc, char * const argv[],
1681 bootm_headers_t *images)
1683 void (*entry_point)(void);
1686 if (flag != BOOTM_STATE_OS_GO)
1689 #if defined(CONFIG_FIT)
1690 if (!images->legacy_hdr_valid) {
1691 fit_unsupported_reset("Plan 9");
1696 /* See README.plan9 */
1697 s = getenv("confaddr");
1699 char *confaddr = (char *)simple_strtoul(s, NULL, 16);
1702 copy_args(confaddr, argc, argv, '\n');
1704 s = getenv("bootargs");
1706 strcpy(confaddr, s);
1710 entry_point = (void (*)(void))images->ep;
1712 printf("## Transferring control to Plan 9 (at address %08lx) ...\n",
1713 (ulong)entry_point);
1715 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1718 * Plan 9 Parameters:
1725 #endif /* CONFIG_BOOTM_PLAN9 */
1727 #if defined(CONFIG_BOOTM_VXWORKS) && \
1728 (defined(CONFIG_PPC) || defined(CONFIG_ARM))
1730 void do_bootvx_fdt(bootm_headers_t *images)
1732 #if defined(CONFIG_OF_LIBFDT)
1735 ulong of_size = images->ft_len;
1736 char **of_flat_tree = &images->ft_addr;
1737 struct lmb *lmb = &images->lmb;
1739 if (*of_flat_tree) {
1740 boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree);
1742 ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size);
1746 ret = fdt_add_subnode(*of_flat_tree, 0, "chosen");
1747 if ((ret >= 0 || ret == -FDT_ERR_EXISTS)) {
1748 bootline = getenv("bootargs");
1750 ret = fdt_find_and_setprop(*of_flat_tree,
1751 "/chosen", "bootargs",
1753 strlen(bootline) + 1, 1);
1755 printf("## ERROR: %s : %s\n", __func__,
1761 printf("## ERROR: %s : %s\n", __func__,
1768 boot_prep_vxworks(images);
1770 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1772 #if defined(CONFIG_OF_LIBFDT)
1773 printf("## Starting vxWorks at 0x%08lx, device tree at 0x%08lx ...\n",
1774 (ulong)images->ep, (ulong)*of_flat_tree);
1776 printf("## Starting vxWorks at 0x%08lx\n", (ulong)images->ep);
1779 boot_jump_vxworks(images);
1781 puts("## vxWorks terminated\n");
1784 static int do_bootm_vxworks(int flag, int argc, char * const argv[],
1785 bootm_headers_t *images)
1787 if (flag != BOOTM_STATE_OS_GO)
1790 #if defined(CONFIG_FIT)
1791 if (!images->legacy_hdr_valid) {
1792 fit_unsupported_reset("VxWorks");
1797 do_bootvx_fdt(images);
1803 #if defined(CONFIG_CMD_ELF)
1804 static int do_bootm_qnxelf(int flag, int argc, char * const argv[],
1805 bootm_headers_t *images)
1807 char *local_args[2];
1810 if (flag != BOOTM_STATE_OS_GO)
1813 #if defined(CONFIG_FIT)
1814 if (!images->legacy_hdr_valid) {
1815 fit_unsupported_reset("QNX");
1820 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1821 local_args[0] = argv[0];
1822 local_args[1] = str; /* and provide it via the arguments */
1823 do_bootelf(NULL, 0, 2, local_args);
1829 #ifdef CONFIG_INTEGRITY
1830 static int do_bootm_integrity(int flag, int argc, char * const argv[],
1831 bootm_headers_t *images)
1833 void (*entry_point)(void);
1835 if (flag != BOOTM_STATE_OS_GO)
1838 #if defined(CONFIG_FIT)
1839 if (!images->legacy_hdr_valid) {
1840 fit_unsupported_reset("INTEGRITY");
1845 entry_point = (void (*)(void))images->ep;
1847 printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
1848 (ulong)entry_point);
1850 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1853 * INTEGRITY Parameters:
1862 #ifdef CONFIG_CMD_BOOTZ
1864 int __weak bootz_setup(ulong image, ulong *start, ulong *end)
1866 /* Please define bootz_setup() for your platform */
1868 puts("Your platform's zImage format isn't supported yet!\n");
1873 * zImage booting support
1875 static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
1876 char * const argv[], bootm_headers_t *images)
1879 ulong zi_start, zi_end;
1881 ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
1884 /* Setup Linux kernel zImage entry point */
1886 images->ep = load_addr;
1887 debug("* kernel: default image load address = 0x%08lx\n",
1890 images->ep = simple_strtoul(argv[0], NULL, 16);
1891 debug("* kernel: cmdline image address = 0x%08lx\n",
1895 ret = bootz_setup(images->ep, &zi_start, &zi_end);
1899 lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
1902 * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
1903 * have a header that provide this informaiton.
1905 if (bootm_find_ramdisk(flag, argc, argv))
1908 #if defined(CONFIG_OF_LIBFDT)
1909 if (bootm_find_fdt(flag, argc, argv))
1916 int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1920 /* Consume 'bootz' */
1923 if (bootz_start(cmdtp, flag, argc, argv, &images))
1927 * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
1928 * disable interrupts ourselves
1930 bootm_disable_interrupts();
1932 images.os.os = IH_OS_LINUX;
1933 ret = do_bootm_states(cmdtp, flag, argc, argv,
1934 BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
1941 #ifdef CONFIG_SYS_LONGHELP
1942 static char bootz_help_text[] =
1943 "[addr [initrd[:size]] [fdt]]\n"
1944 " - boot Linux zImage stored in memory\n"
1945 "\tThe argument 'initrd' is optional and specifies the address\n"
1946 "\tof the initrd in memory. The optional argument ':size' allows\n"
1947 "\tspecifying the size of RAW initrd.\n"
1948 #if defined(CONFIG_OF_LIBFDT)
1949 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
1950 "\ta third argument is required which is the address of the\n"
1951 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1952 "\tuse a '-' for the second argument. If you do not pass a third\n"
1953 "\ta bd_info struct will be passed instead\n"
1959 bootz, CONFIG_SYS_MAXARGS, 1, do_bootz,
1960 "boot Linux zImage image from memory", bootz_help_text
1962 #endif /* CONFIG_CMD_BOOTZ */