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 #ifdef CONFIG_SYS_HUSH_PARSER
39 #if defined(CONFIG_OF_LIBFDT)
41 #include <fdt_support.h>
45 #include <lzma/LzmaTypes.h>
46 #include <lzma/LzmaDec.h>
47 #include <lzma/LzmaTools.h>
48 #endif /* CONFIG_LZMA */
51 #include <linux/lzo.h>
52 #endif /* CONFIG_LZO */
54 DECLARE_GLOBAL_DATA_PTR
;
56 #ifndef CONFIG_SYS_BOOTM_LEN
57 #define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
61 extern void bz_internal_error(int);
64 #if defined(CONFIG_CMD_IMI)
65 static int image_info(unsigned long addr
);
68 #if defined(CONFIG_CMD_IMLS)
70 #include <mtd/cfi_flash.h>
71 extern flash_info_t flash_info
[]; /* info for FLASH chips */
74 #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
75 static int do_imls(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[]);
78 #include <linux/err.h>
81 #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
82 static void fixup_silent_linux(void);
85 static const void *boot_get_kernel(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
86 char * const argv
[], bootm_headers_t
*images
,
87 ulong
*os_data
, ulong
*os_len
);
90 * Continue booting an OS image; caller already has:
91 * - copied image header to global variable `header'
92 * - checked header magic number, checksums (both header & image),
93 * - verified image architecture (PPC) and type (KERNEL or MULTI),
94 * - loaded (first part of) image to header load address,
95 * - disabled interrupts.
97 * @flag: Flags indicating what to do (BOOTM_STATE_...)
98 * @argc: Number of arguments. Note that the arguments are shifted down
99 * so that 0 is the first argument not processed by U-Boot, and
100 * argc is adjusted accordingly. This avoids confusion as to how
101 * many arguments are available for the OS.
102 * @images: Pointers to os/initrd/fdt
103 * @return 1 on error. On success the OS boots so this function does
106 typedef int boot_os_fn(int flag
, int argc
, char * const argv
[],
107 bootm_headers_t
*images
);
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_BOOTM_PLAN9)
126 static boot_os_fn do_bootm_plan9
;
128 #if defined(CONFIG_BOOTM_VXWORKS) && \
129 (defined(CONFIG_PPC) || defined(CONFIG_ARM))
130 static boot_os_fn do_bootm_vxworks
;
132 #if defined(CONFIG_CMD_ELF)
133 static boot_os_fn do_bootm_qnxelf
;
134 int do_bootvx(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[]);
135 int do_bootelf(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[]);
137 #if defined(CONFIG_INTEGRITY)
138 static boot_os_fn do_bootm_integrity
;
141 static boot_os_fn
*boot_os
[] = {
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
,
222 /* get kernel image header, start address and length */
223 os_hdr
= boot_get_kernel(cmdtp
, flag
, argc
, argv
,
224 &images
, &images
.os
.image_start
, &images
.os
.image_len
);
225 if (images
.os
.image_len
== 0) {
226 puts("ERROR: can't get kernel image!\n");
230 /* get image parameters */
231 switch (genimg_get_format(os_hdr
)) {
232 case IMAGE_FORMAT_LEGACY
:
233 images
.os
.type
= image_get_type(os_hdr
);
234 images
.os
.comp
= image_get_comp(os_hdr
);
235 images
.os
.os
= image_get_os(os_hdr
);
237 images
.os
.end
= image_get_image_end(os_hdr
);
238 images
.os
.load
= image_get_load(os_hdr
);
240 #if defined(CONFIG_FIT)
241 case IMAGE_FORMAT_FIT
:
242 if (fit_image_get_type(images
.fit_hdr_os
,
243 images
.fit_noffset_os
, &images
.os
.type
)) {
244 puts("Can't get image type!\n");
245 bootstage_error(BOOTSTAGE_ID_FIT_TYPE
);
249 if (fit_image_get_comp(images
.fit_hdr_os
,
250 images
.fit_noffset_os
, &images
.os
.comp
)) {
251 puts("Can't get image compression!\n");
252 bootstage_error(BOOTSTAGE_ID_FIT_COMPRESSION
);
256 if (fit_image_get_os(images
.fit_hdr_os
,
257 images
.fit_noffset_os
, &images
.os
.os
)) {
258 puts("Can't get image OS!\n");
259 bootstage_error(BOOTSTAGE_ID_FIT_OS
);
263 images
.os
.end
= fit_get_end(images
.fit_hdr_os
);
265 if (fit_image_get_load(images
.fit_hdr_os
, images
.fit_noffset_os
,
267 puts("Can't get image load address!\n");
268 bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR
);
274 puts("ERROR: unknown image format type!\n");
278 /* find kernel entry point */
279 if (images
.legacy_hdr_valid
) {
280 images
.ep
= image_get_ep(&images
.legacy_hdr_os_copy
);
281 #if defined(CONFIG_FIT)
282 } else if (images
.fit_uname_os
) {
285 ret
= fit_image_get_entry(images
.fit_hdr_os
,
286 images
.fit_noffset_os
, &images
.ep
);
288 puts("Can't get entry point property!\n");
293 puts("Could not find kernel entry point!\n");
297 if (images
.os
.type
== IH_TYPE_KERNEL_NOLOAD
) {
298 images
.os
.load
= images
.os
.image_start
;
299 images
.ep
+= images
.os
.load
;
302 images
.os
.start
= (ulong
)os_hdr
;
307 static int bootm_find_ramdisk(int flag
, int argc
, char * const argv
[])
312 ret
= boot_get_ramdisk(argc
, argv
, &images
, IH_INITRD_ARCH
,
313 &images
.rd_start
, &images
.rd_end
);
315 puts("Ramdisk image is corrupt or invalid\n");
322 #if defined(CONFIG_OF_LIBFDT)
323 static int bootm_find_fdt(int flag
, int argc
, char * const argv
[])
327 /* find flattened device tree */
328 ret
= boot_get_fdt(flag
, argc
, argv
, IH_ARCH_DEFAULT
, &images
,
329 &images
.ft_addr
, &images
.ft_len
);
331 puts("Could not find a valid device tree\n");
335 set_working_fdt_addr(images
.ft_addr
);
341 static int bootm_find_other(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
344 if (((images
.os
.type
== IH_TYPE_KERNEL
) ||
345 (images
.os
.type
== IH_TYPE_KERNEL_NOLOAD
) ||
346 (images
.os
.type
== IH_TYPE_MULTI
)) &&
347 (images
.os
.os
== IH_OS_LINUX
||
348 images
.os
.os
== IH_OS_VXWORKS
)) {
349 if (bootm_find_ramdisk(flag
, argc
, argv
))
352 #if defined(CONFIG_OF_LIBFDT)
353 if (bootm_find_fdt(flag
, argc
, argv
))
361 #define BOOTM_ERR_RESET -1
362 #define BOOTM_ERR_OVERLAP -2
363 #define BOOTM_ERR_UNIMPLEMENTED -3
364 static int bootm_load_os(bootm_headers_t
*images
, unsigned long *load_end
,
367 image_info_t os
= images
->os
;
368 uint8_t comp
= os
.comp
;
369 ulong load
= os
.load
;
370 ulong blob_start
= os
.start
;
371 ulong blob_end
= os
.end
;
372 ulong image_start
= os
.image_start
;
373 ulong image_len
= os
.image_len
;
374 __maybe_unused uint unc_len
= CONFIG_SYS_BOOTM_LEN
;
376 void *load_buf
, *image_buf
;
377 #if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
379 #endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
381 const char *type_name
= genimg_get_type_name(os
.type
);
383 load_buf
= map_sysmem(load
, unc_len
);
384 image_buf
= map_sysmem(image_start
, image_len
);
387 if (load
== blob_start
|| load
== image_start
) {
388 printf(" XIP %s ... ", type_name
);
391 printf(" Loading %s ... ", type_name
);
392 memmove_wd(load_buf
, image_buf
, image_len
, CHUNKSZ
);
394 *load_end
= load
+ image_len
;
398 printf(" Uncompressing %s ... ", type_name
);
399 if (gunzip(load_buf
, unc_len
, image_buf
, &image_len
) != 0) {
400 puts("GUNZIP: uncompress, out-of-mem or overwrite "
401 "error - must RESET board to recover\n");
403 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE
);
404 return BOOTM_ERR_RESET
;
407 *load_end
= load
+ image_len
;
409 #endif /* CONFIG_GZIP */
412 printf(" Uncompressing %s ... ", type_name
);
414 * If we've got less than 4 MB of malloc() space,
415 * use slower decompression algorithm which requires
416 * at most 2300 KB of memory.
418 int i
= BZ2_bzBuffToBuffDecompress(load_buf
, &unc_len
,
419 image_buf
, image_len
,
420 CONFIG_SYS_MALLOC_LEN
< (4096 * 1024), 0);
422 printf("BUNZIP2: uncompress or overwrite error %d "
423 "- must RESET board to recover\n", i
);
425 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE
);
426 return BOOTM_ERR_RESET
;
429 *load_end
= load
+ unc_len
;
431 #endif /* CONFIG_BZIP2 */
434 SizeT lzma_len
= unc_len
;
435 printf(" Uncompressing %s ... ", type_name
);
437 ret
= lzmaBuffToBuffDecompress(load_buf
, &lzma_len
,
438 image_buf
, image_len
);
441 printf("LZMA: uncompress or overwrite error %d "
442 "- must RESET board to recover\n", ret
);
443 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE
);
444 return BOOTM_ERR_RESET
;
446 *load_end
= load
+ unc_len
;
449 #endif /* CONFIG_LZMA */
454 printf(" Uncompressing %s ... ", type_name
);
456 ret
= lzop_decompress(image_buf
, image_len
, load_buf
, &size
);
457 if (ret
!= LZO_E_OK
) {
458 printf("LZO: uncompress or overwrite error %d "
459 "- must RESET board to recover\n", ret
);
461 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE
);
462 return BOOTM_ERR_RESET
;
465 *load_end
= load
+ size
;
468 #endif /* CONFIG_LZO */
470 printf("Unimplemented compression type %d\n", comp
);
471 return BOOTM_ERR_UNIMPLEMENTED
;
474 flush_cache(load
, (*load_end
- load
) * sizeof(ulong
));
477 debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load
, *load_end
);
478 bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED
);
480 if (!no_overlap
&& (load
< blob_end
) && (*load_end
> blob_start
)) {
481 debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n",
482 blob_start
, blob_end
);
483 debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load
,
486 /* Check what type of image this is. */
487 if (images
->legacy_hdr_valid
) {
488 if (image_get_type(&images
->legacy_hdr_os_copy
)
490 puts("WARNING: legacy format multi component image overwritten\n");
491 return BOOTM_ERR_OVERLAP
;
493 puts("ERROR: new format image overwritten - must RESET the board to recover\n");
494 bootstage_error(BOOTSTAGE_ID_OVERWRITTEN
);
495 return BOOTM_ERR_RESET
;
502 static int bootm_start_standalone(int argc
, char * const argv
[])
505 int (*appl
)(int, char * const []);
507 /* Don't start if "autostart" is set to "no" */
508 if (((s
= getenv("autostart")) != NULL
) && (strcmp(s
, "no") == 0)) {
509 setenv_hex("filesize", images
.os
.image_len
);
512 appl
= (int (*)(int, char * const []))(ulong
)ntohl(images
.ep
);
517 /* we overload the cmd field with our state machine info instead of a
518 * function pointer */
519 static cmd_tbl_t cmd_bootm_sub
[] = {
520 U_BOOT_CMD_MKENT(start
, 0, 1, (void *)BOOTM_STATE_START
, "", ""),
521 U_BOOT_CMD_MKENT(loados
, 0, 1, (void *)BOOTM_STATE_LOADOS
, "", ""),
522 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
523 U_BOOT_CMD_MKENT(ramdisk
, 0, 1, (void *)BOOTM_STATE_RAMDISK
, "", ""),
525 #ifdef CONFIG_OF_LIBFDT
526 U_BOOT_CMD_MKENT(fdt
, 0, 1, (void *)BOOTM_STATE_FDT
, "", ""),
528 U_BOOT_CMD_MKENT(cmdline
, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE
, "", ""),
529 U_BOOT_CMD_MKENT(bdt
, 0, 1, (void *)BOOTM_STATE_OS_BD_T
, "", ""),
530 U_BOOT_CMD_MKENT(prep
, 0, 1, (void *)BOOTM_STATE_OS_PREP
, "", ""),
531 U_BOOT_CMD_MKENT(fake
, 0, 1, (void *)BOOTM_STATE_OS_FAKE_GO
, "", ""),
532 U_BOOT_CMD_MKENT(go
, 0, 1, (void *)BOOTM_STATE_OS_GO
, "", ""),
535 static int boot_selected_os(int argc
, char * const argv
[], int state
,
536 bootm_headers_t
*images
, boot_os_fn
*boot_fn
)
538 if (images
->os
.type
== IH_TYPE_STANDALONE
) {
539 /* This may return when 'autostart' is 'no' */
540 bootm_start_standalone(argc
, argv
);
544 boot_fn(state
, argc
, argv
, images
);
545 if (state
== BOOTM_STATE_OS_FAKE_GO
) /* We expect to return */
547 bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED
);
549 puts("\n## Control returned to monitor - resetting...\n");
551 return BOOTM_ERR_RESET
;
555 * bootm_disable_interrupts() - Disable interrupts in preparation for load/boot
557 * @return interrupt flag (0 if interrupts were disabled, non-zero if they were
560 static ulong
bootm_disable_interrupts(void)
565 * We have reached the point of no return: we are going to
566 * overwrite all exception vector code, so we cannot easily
567 * recover from any failures any more...
569 iflag
= disable_interrupts();
570 #ifdef CONFIG_NETCONSOLE
571 /* Stop the ethernet stack if NetConsole could have left it up */
573 eth_unregister(eth_get_dev());
576 #if defined(CONFIG_CMD_USB)
578 * turn off USB to prevent the host controller from writing to the
579 * SDRAM while Linux is booting. This could happen (at least for OHCI
580 * controller), because the HCCA (Host Controller Communication Area)
581 * lies within the SDRAM and the host controller writes continously to
582 * this area (as busmaster!). The HccaFrameNumber is for example
583 * updated every 1 ms within the HCCA structure in SDRAM! For more
584 * details see the OpenHCI specification.
592 * Execute selected states of the bootm command.
594 * Note the arguments to this state must be the first argument, Any 'bootm'
595 * or sub-command arguments must have already been taken.
597 * Note that if states contains more than one flag it MUST contain
598 * BOOTM_STATE_START, since this handles and consumes the command line args.
600 * Also note that aside from boot_os_fn functions and bootm_load_os no other
601 * functions we store the return value of in 'ret' may use a negative return
602 * value, without special handling.
604 * @param cmdtp Pointer to bootm command table entry
605 * @param flag Command flags (CMD_FLAG_...)
606 * @param argc Number of subcommand arguments (0 = no arguments)
607 * @param argv Arguments
608 * @param states Mask containing states to run (BOOTM_STATE_...)
609 * @param images Image header information
610 * @param boot_progress 1 to show boot progress, 0 to not do this
611 * @return 0 if ok, something else on error. Some errors will cause this
612 * function to perform a reboot! If states contains BOOTM_STATE_OS_GO
613 * then the intent is to boot an OS, so this function will not return
614 * unless the image type is standalone.
616 static int do_bootm_states(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
617 char * const argv
[], int states
, bootm_headers_t
*images
,
622 int ret
= 0, need_boot_fn
;
624 images
->state
|= states
;
627 * Work through the states and see how far we get. We stop on
630 if (states
& BOOTM_STATE_START
)
631 ret
= bootm_start(cmdtp
, flag
, argc
, argv
);
633 if (!ret
&& (states
& BOOTM_STATE_FINDOS
))
634 ret
= bootm_find_os(cmdtp
, flag
, argc
, argv
);
636 if (!ret
&& (states
& BOOTM_STATE_FINDOTHER
)) {
637 ret
= bootm_find_other(cmdtp
, flag
, argc
, argv
);
638 argc
= 0; /* consume the args */
642 if (!ret
&& (states
& BOOTM_STATE_LOADOS
)) {
645 iflag
= bootm_disable_interrupts();
646 ret
= bootm_load_os(images
, &load_end
, 0);
648 lmb_reserve(&images
->lmb
, images
->os
.load
,
649 (load_end
- images
->os
.load
));
650 else if (ret
&& ret
!= BOOTM_ERR_OVERLAP
)
652 else if (ret
== BOOTM_ERR_OVERLAP
)
654 #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
655 if (images
->os
.os
== IH_OS_LINUX
)
656 fixup_silent_linux();
660 /* Relocate the ramdisk */
661 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
662 if (!ret
&& (states
& BOOTM_STATE_RAMDISK
)) {
663 ulong rd_len
= images
->rd_end
- images
->rd_start
;
665 ret
= boot_ramdisk_high(&images
->lmb
, images
->rd_start
,
666 rd_len
, &images
->initrd_start
, &images
->initrd_end
);
668 setenv_hex("initrd_start", images
->initrd_start
);
669 setenv_hex("initrd_end", images
->initrd_end
);
673 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_LMB)
674 if (!ret
&& (states
& BOOTM_STATE_FDT
)) {
675 boot_fdt_add_mem_rsv_regions(&images
->lmb
, images
->ft_addr
);
676 ret
= boot_relocate_fdt(&images
->lmb
, &images
->ft_addr
,
681 /* From now on, we need the OS boot function */
684 boot_fn
= boot_os
[images
->os
.os
];
685 need_boot_fn
= states
& (BOOTM_STATE_OS_CMDLINE
|
686 BOOTM_STATE_OS_BD_T
| BOOTM_STATE_OS_PREP
|
687 BOOTM_STATE_OS_FAKE_GO
| BOOTM_STATE_OS_GO
);
688 if (boot_fn
== NULL
&& need_boot_fn
) {
691 printf("ERROR: booting os '%s' (%d) is not supported\n",
692 genimg_get_os_name(images
->os
.os
), images
->os
.os
);
693 bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS
);
697 /* Call various other states that are not generally used */
698 if (!ret
&& (states
& BOOTM_STATE_OS_CMDLINE
))
699 ret
= boot_fn(BOOTM_STATE_OS_CMDLINE
, argc
, argv
, images
);
700 if (!ret
&& (states
& BOOTM_STATE_OS_BD_T
))
701 ret
= boot_fn(BOOTM_STATE_OS_BD_T
, argc
, argv
, images
);
702 if (!ret
&& (states
& BOOTM_STATE_OS_PREP
))
703 ret
= boot_fn(BOOTM_STATE_OS_PREP
, argc
, argv
, images
);
706 /* Pretend to run the OS, then run a user command */
707 if (!ret
&& (states
& BOOTM_STATE_OS_FAKE_GO
)) {
708 char *cmd_list
= getenv("fakegocmd");
710 ret
= boot_selected_os(argc
, argv
, BOOTM_STATE_OS_FAKE_GO
,
712 if (!ret
&& cmd_list
)
713 ret
= run_command_list(cmd_list
, -1, flag
);
717 /* Check for unsupported subcommand. */
719 puts("subcommand not supported\n");
723 /* Now run the OS! We hope this doesn't return */
724 if (!ret
&& (states
& BOOTM_STATE_OS_GO
))
725 ret
= boot_selected_os(argc
, argv
, BOOTM_STATE_OS_GO
,
728 /* Deal with any fallout */
733 if (ret
== BOOTM_ERR_UNIMPLEMENTED
)
734 bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL
);
735 else if (ret
== BOOTM_ERR_RESET
)
736 do_reset(cmdtp
, flag
, argc
, argv
);
741 static int do_bootm_subcommand(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
748 c
= find_cmd_tbl(argv
[0], &cmd_bootm_sub
[0], ARRAY_SIZE(cmd_bootm_sub
));
752 state
= (long)c
->cmd
;
753 if (state
== BOOTM_STATE_START
)
754 state
|= BOOTM_STATE_FINDOS
| BOOTM_STATE_FINDOTHER
;
756 /* Unrecognized command */
757 return CMD_RET_USAGE
;
760 if (state
!= BOOTM_STATE_START
&& images
.state
>= state
) {
761 printf("Trying to execute a command out of order\n");
762 return CMD_RET_USAGE
;
765 ret
= do_bootm_states(cmdtp
, flag
, argc
, argv
, state
, &images
, 0);
770 /*******************************************************************/
771 /* bootm - boot application image from image in memory */
772 /*******************************************************************/
774 int do_bootm(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
776 #ifdef CONFIG_NEEDS_MANUAL_RELOC
777 static int relocated
= 0;
782 /* relocate boot function table */
783 for (i
= 0; i
< ARRAY_SIZE(boot_os
); i
++)
784 if (boot_os
[i
] != NULL
)
785 boot_os
[i
] += gd
->reloc_off
;
787 /* relocate names of sub-command table */
788 for (i
= 0; i
< ARRAY_SIZE(cmd_bootm_sub
); i
++)
789 cmd_bootm_sub
[i
].name
+= gd
->reloc_off
;
795 /* determine if we have a sub command */
800 simple_strtoul(argv
[0], &endp
, 16);
801 /* endp pointing to NULL means that argv[0] was just a
802 * valid number, pass it along to the normal bootm processing
804 * If endp is ':' or '#' assume a FIT identifier so pass
805 * along for normal processing.
807 * Right now we assume the first arg should never be '-'
809 if ((*endp
!= 0) && (*endp
!= ':') && (*endp
!= '#'))
810 return do_bootm_subcommand(cmdtp
, flag
, argc
, argv
);
813 return do_bootm_states(cmdtp
, flag
, argc
, argv
, BOOTM_STATE_START
|
814 BOOTM_STATE_FINDOS
| BOOTM_STATE_FINDOTHER
|
816 #if defined(CONFIG_PPC) || defined(CONFIG_MIPS)
817 BOOTM_STATE_OS_CMDLINE
|
819 BOOTM_STATE_OS_PREP
| BOOTM_STATE_OS_FAKE_GO
|
820 BOOTM_STATE_OS_GO
, &images
, 1);
823 int bootm_maybe_autostart(cmd_tbl_t
*cmdtp
, const char *cmd
)
825 const char *ep
= getenv("autostart");
827 if (ep
&& !strcmp(ep
, "yes")) {
829 local_args
[0] = (char *)cmd
;
830 local_args
[1] = NULL
;
831 printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr
);
832 return do_bootm(cmdtp
, 0, 1, local_args
);
839 * image_get_kernel - verify legacy format kernel image
840 * @img_addr: in RAM address of the legacy format image to be verified
841 * @verify: data CRC verification flag
843 * image_get_kernel() verifies legacy image integrity and returns pointer to
844 * legacy image header if image verification was completed successfully.
847 * pointer to a legacy image header if valid image was found
848 * otherwise return NULL
850 static image_header_t
*image_get_kernel(ulong img_addr
, int verify
)
852 image_header_t
*hdr
= (image_header_t
*)img_addr
;
854 if (!image_check_magic(hdr
)) {
855 puts("Bad Magic Number\n");
856 bootstage_error(BOOTSTAGE_ID_CHECK_MAGIC
);
859 bootstage_mark(BOOTSTAGE_ID_CHECK_HEADER
);
861 if (!image_check_hcrc(hdr
)) {
862 puts("Bad Header Checksum\n");
863 bootstage_error(BOOTSTAGE_ID_CHECK_HEADER
);
867 bootstage_mark(BOOTSTAGE_ID_CHECK_CHECKSUM
);
868 image_print_contents(hdr
);
871 puts(" Verifying Checksum ... ");
872 if (!image_check_dcrc(hdr
)) {
873 printf("Bad Data CRC\n");
874 bootstage_error(BOOTSTAGE_ID_CHECK_CHECKSUM
);
879 bootstage_mark(BOOTSTAGE_ID_CHECK_ARCH
);
881 if (!image_check_target_arch(hdr
)) {
882 printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr
));
883 bootstage_error(BOOTSTAGE_ID_CHECK_ARCH
);
890 * boot_get_kernel - find kernel image
891 * @os_data: pointer to a ulong variable, will hold os data start address
892 * @os_len: pointer to a ulong variable, will hold os data length
894 * boot_get_kernel() tries to find a kernel image, verifies its integrity
895 * and locates kernel data.
898 * pointer to image header if valid image was found, plus kernel start
899 * address and length, otherwise NULL
901 static const void *boot_get_kernel(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
902 char * const argv
[], bootm_headers_t
*images
, ulong
*os_data
,
908 #if defined(CONFIG_FIT)
909 const char *fit_uname_config
= NULL
;
910 const char *fit_uname_kernel
= NULL
;
914 /* find out kernel image address */
916 img_addr
= load_addr
;
917 debug("* kernel: default image load address = 0x%08lx\n",
919 #if defined(CONFIG_FIT)
920 } else if (fit_parse_conf(argv
[0], load_addr
, &img_addr
,
921 &fit_uname_config
)) {
922 debug("* kernel: config '%s' from image at 0x%08lx\n",
923 fit_uname_config
, img_addr
);
924 } else if (fit_parse_subimage(argv
[0], load_addr
, &img_addr
,
925 &fit_uname_kernel
)) {
926 debug("* kernel: subimage '%s' from image at 0x%08lx\n",
927 fit_uname_kernel
, img_addr
);
930 img_addr
= simple_strtoul(argv
[0], NULL
, 16);
931 debug("* kernel: cmdline image address = 0x%08lx\n", img_addr
);
934 bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC
);
936 /* copy from dataflash if needed */
937 img_addr
= genimg_get_image(img_addr
);
939 /* check image type, for FIT images get FIT kernel node */
940 *os_data
= *os_len
= 0;
941 buf
= map_sysmem(img_addr
, 0);
942 switch (genimg_get_format(buf
)) {
943 case IMAGE_FORMAT_LEGACY
:
944 printf("## Booting kernel from Legacy Image at %08lx ...\n",
946 hdr
= image_get_kernel(img_addr
, images
->verify
);
949 bootstage_mark(BOOTSTAGE_ID_CHECK_IMAGETYPE
);
951 /* get os_data and os_len */
952 switch (image_get_type(hdr
)) {
954 case IH_TYPE_KERNEL_NOLOAD
:
955 *os_data
= image_get_data(hdr
);
956 *os_len
= image_get_data_size(hdr
);
959 image_multi_getimg(hdr
, 0, os_data
, os_len
);
961 case IH_TYPE_STANDALONE
:
962 *os_data
= image_get_data(hdr
);
963 *os_len
= image_get_data_size(hdr
);
966 printf("Wrong Image Type for %s command\n",
968 bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE
);
973 * copy image header to allow for image overwrites during
974 * kernel decompression.
976 memmove(&images
->legacy_hdr_os_copy
, hdr
,
977 sizeof(image_header_t
));
979 /* save pointer to image header */
980 images
->legacy_hdr_os
= hdr
;
982 images
->legacy_hdr_valid
= 1;
983 bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE
);
985 #if defined(CONFIG_FIT)
986 case IMAGE_FORMAT_FIT
:
987 os_noffset
= fit_image_load(images
, FIT_KERNEL_PROP
,
989 &fit_uname_kernel
, &fit_uname_config
,
990 IH_ARCH_DEFAULT
, IH_TYPE_KERNEL
,
991 BOOTSTAGE_ID_FIT_KERNEL_START
,
992 FIT_LOAD_IGNORED
, os_data
, os_len
);
996 images
->fit_hdr_os
= map_sysmem(img_addr
, 0);
997 images
->fit_uname_os
= fit_uname_kernel
;
998 images
->fit_uname_cfg
= fit_uname_config
;
999 images
->fit_noffset_os
= os_noffset
;
1003 printf("Wrong Image Format for %s command\n", cmdtp
->name
);
1004 bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO
);
1008 debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
1009 *os_data
, *os_len
, *os_len
);
1014 #ifdef CONFIG_SYS_LONGHELP
1015 static char bootm_help_text
[] =
1016 "[addr [arg ...]]\n - boot application image stored in memory\n"
1017 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
1018 "\t'arg' can be the address of an initrd image\n"
1019 #if defined(CONFIG_OF_LIBFDT)
1020 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
1021 "\ta third argument is required which is the address of the\n"
1022 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1023 "\tuse a '-' for the second argument. If you do not pass a third\n"
1024 "\ta bd_info struct will be passed instead\n"
1026 #if defined(CONFIG_FIT)
1027 "\t\nFor the new multi component uImage format (FIT) addresses\n"
1028 "\tmust be extened to include component or configuration unit name:\n"
1029 "\taddr:<subimg_uname> - direct component image specification\n"
1030 "\taddr#<conf_uname> - configuration specification\n"
1031 "\tUse iminfo command to get the list of existing component\n"
1032 "\timages and configurations.\n"
1034 "\nSub-commands to do part of the bootm sequence. The sub-commands "
1036 "issued in the order below (it's ok to not issue all sub-commands):\n"
1037 "\tstart [addr [arg ...]]\n"
1038 "\tloados - load OS image\n"
1039 #if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH)
1040 "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
1042 #if defined(CONFIG_OF_LIBFDT)
1043 "\tfdt - relocate flat device tree\n"
1045 "\tcmdline - OS specific command line processing/setup\n"
1046 "\tbdt - OS specific bd_t processing\n"
1047 "\tprep - OS specific prep before relocation or go\n"
1052 bootm
, CONFIG_SYS_MAXARGS
, 1, do_bootm
,
1053 "boot application image from memory", bootm_help_text
1056 /*******************************************************************/
1057 /* bootd - boot default image */
1058 /*******************************************************************/
1059 #if defined(CONFIG_CMD_BOOTD)
1060 int do_bootd(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
1064 if (run_command(getenv("bootcmd"), flag
) < 0)
1070 boot
, 1, 1, do_bootd
,
1071 "boot default, i.e., run 'bootcmd'",
1075 /* keep old command name "bootd" for backward compatibility */
1077 bootd
, 1, 1, do_bootd
,
1078 "boot default, i.e., run 'bootcmd'",
1085 /*******************************************************************/
1086 /* iminfo - print header info for a requested image */
1087 /*******************************************************************/
1088 #if defined(CONFIG_CMD_IMI)
1089 static int do_iminfo(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
1096 return image_info(load_addr
);
1099 for (arg
= 1; arg
< argc
; ++arg
) {
1100 addr
= simple_strtoul(argv
[arg
], NULL
, 16);
1101 if (image_info(addr
) != 0)
1107 static int image_info(ulong addr
)
1109 void *hdr
= (void *)addr
;
1111 printf("\n## Checking Image at %08lx ...\n", addr
);
1113 switch (genimg_get_format(hdr
)) {
1114 case IMAGE_FORMAT_LEGACY
:
1115 puts(" Legacy image found\n");
1116 if (!image_check_magic(hdr
)) {
1117 puts(" Bad Magic Number\n");
1121 if (!image_check_hcrc(hdr
)) {
1122 puts(" Bad Header Checksum\n");
1126 image_print_contents(hdr
);
1128 puts(" Verifying Checksum ... ");
1129 if (!image_check_dcrc(hdr
)) {
1130 puts(" Bad Data CRC\n");
1135 #if defined(CONFIG_FIT)
1136 case IMAGE_FORMAT_FIT
:
1137 puts(" FIT image found\n");
1139 if (!fit_check_format(hdr
)) {
1140 puts("Bad FIT image format!\n");
1144 fit_print_contents(hdr
);
1146 if (!fit_all_image_verify(hdr
)) {
1147 puts("Bad hash in FIT image!\n");
1154 puts("Unknown image format!\n");
1162 iminfo
, CONFIG_SYS_MAXARGS
, 1, do_iminfo
,
1163 "print header information for application image",
1165 " - print header information for application image starting at\n"
1166 " address 'addr' in memory; this includes verification of the\n"
1167 " image contents (magic number, header and payload checksums)"
1172 /*******************************************************************/
1173 /* imls - list all images found in flash */
1174 /*******************************************************************/
1175 #if defined(CONFIG_CMD_IMLS)
1176 static int do_imls_nor(void)
1182 for (i
= 0, info
= &flash_info
[0];
1183 i
< CONFIG_SYS_MAX_FLASH_BANKS
; ++i
, ++info
) {
1185 if (info
->flash_id
== FLASH_UNKNOWN
)
1187 for (j
= 0; j
< info
->sector_count
; ++j
) {
1189 hdr
= (void *)info
->start
[j
];
1193 switch (genimg_get_format(hdr
)) {
1194 case IMAGE_FORMAT_LEGACY
:
1195 if (!image_check_hcrc(hdr
))
1198 printf("Legacy Image at %08lX:\n", (ulong
)hdr
);
1199 image_print_contents(hdr
);
1201 puts(" Verifying Checksum ... ");
1202 if (!image_check_dcrc(hdr
)) {
1203 puts("Bad Data CRC\n");
1208 #if defined(CONFIG_FIT)
1209 case IMAGE_FORMAT_FIT
:
1210 if (!fit_check_format(hdr
))
1213 printf("FIT Image at %08lX:\n", (ulong
)hdr
);
1214 fit_print_contents(hdr
);
1229 #if defined(CONFIG_CMD_IMLS_NAND)
1230 static int nand_imls_legacyimage(nand_info_t
*nand
, int nand_dev
, loff_t off
,
1236 imgdata
= malloc(len
);
1238 printf("May be a Legacy Image at NAND device %d offset %08llX:\n",
1240 printf(" Low memory(cannot allocate memory for image)\n");
1244 ret
= nand_read_skip_bad(nand
, off
, &len
,
1246 if (ret
< 0 && ret
!= -EUCLEAN
) {
1251 if (!image_check_hcrc(imgdata
)) {
1256 printf("Legacy Image at NAND device %d offset %08llX:\n",
1258 image_print_contents(imgdata
);
1260 puts(" Verifying Checksum ... ");
1261 if (!image_check_dcrc(imgdata
))
1262 puts("Bad Data CRC\n");
1271 static int nand_imls_fitimage(nand_info_t
*nand
, int nand_dev
, loff_t off
,
1277 imgdata
= malloc(len
);
1279 printf("May be a FIT Image at NAND device %d offset %08llX:\n",
1281 printf(" Low memory(cannot allocate memory for image)\n");
1285 ret
= nand_read_skip_bad(nand
, off
, &len
,
1287 if (ret
< 0 && ret
!= -EUCLEAN
) {
1292 if (!fit_check_format(imgdata
)) {
1297 printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev
, off
);
1299 fit_print_contents(imgdata
);
1305 static int do_imls_nand(void)
1308 int nand_dev
= nand_curr_device
;
1313 if (nand_dev
< 0 || nand_dev
>= CONFIG_SYS_MAX_NAND_DEVICE
) {
1314 puts("\nNo NAND devices available\n");
1320 for (nand_dev
= 0; nand_dev
< CONFIG_SYS_MAX_NAND_DEVICE
; nand_dev
++) {
1321 nand
= &nand_info
[nand_dev
];
1322 if (!nand
->name
|| !nand
->size
)
1325 for (off
= 0; off
< nand
->size
; off
+= nand
->erasesize
) {
1326 const image_header_t
*header
;
1329 if (nand_block_isbad(nand
, off
))
1332 len
= sizeof(buffer
);
1334 ret
= nand_read(nand
, off
, &len
, (u8
*)buffer
);
1335 if (ret
< 0 && ret
!= -EUCLEAN
) {
1336 printf("NAND read error %d at offset %08llX\n",
1341 switch (genimg_get_format(buffer
)) {
1342 case IMAGE_FORMAT_LEGACY
:
1343 header
= (const image_header_t
*)buffer
;
1345 len
= image_get_image_size(header
);
1346 nand_imls_legacyimage(nand
, nand_dev
, off
, len
);
1348 #if defined(CONFIG_FIT)
1349 case IMAGE_FORMAT_FIT
:
1350 len
= fit_get_size(buffer
);
1351 nand_imls_fitimage(nand
, nand_dev
, off
, len
);
1362 #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
1363 static int do_imls(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
1365 int ret_nor
= 0, ret_nand
= 0;
1367 #if defined(CONFIG_CMD_IMLS)
1368 ret_nor
= do_imls_nor();
1371 #if defined(CONFIG_CMD_IMLS_NAND)
1372 ret_nand
= do_imls_nand();
1385 imls
, 1, 1, do_imls
,
1386 "list all images found in flash",
1388 " - Prints information about all images found at sector/block\n"
1389 " boundaries in nor/nand flash."
1393 /*******************************************************************/
1394 /* helper routines */
1395 /*******************************************************************/
1396 #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
1398 #define CONSOLE_ARG "console="
1399 #define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1)
1401 static void fixup_silent_linux(void)
1404 const char *env_val
;
1405 char *cmdline
= getenv("bootargs");
1409 * Only fix cmdline when requested. The environment variable can be:
1411 * no - we never fixup
1412 * yes - we always fixup
1413 * unset - we rely on the console silent flag
1415 want_silent
= getenv_yesno("silent_linux");
1416 if (want_silent
== 0)
1418 else if (want_silent
== -1 && !(gd
->flags
& GD_FLG_SILENT
))
1421 debug("before silent fix-up: %s\n", cmdline
);
1422 if (cmdline
&& (cmdline
[0] != '\0')) {
1423 char *start
= strstr(cmdline
, CONSOLE_ARG
);
1425 /* Allocate space for maximum possible new command line */
1426 buf
= malloc(strlen(cmdline
) + 1 + CONSOLE_ARG_LEN
+ 1);
1428 debug("%s: out of memory\n", __func__
);
1433 char *end
= strchr(start
, ' ');
1434 int num_start_bytes
= start
- cmdline
+ CONSOLE_ARG_LEN
;
1436 strncpy(buf
, cmdline
, num_start_bytes
);
1438 strcpy(buf
+ num_start_bytes
, end
);
1440 buf
[num_start_bytes
] = '\0';
1442 sprintf(buf
, "%s %s", cmdline
, CONSOLE_ARG
);
1447 env_val
= CONSOLE_ARG
;
1450 setenv("bootargs", env_val
);
1451 debug("after silent fix-up: %s\n", env_val
);
1454 #endif /* CONFIG_SILENT_CONSOLE */
1456 #if defined(CONFIG_BOOTM_NETBSD) || defined(CONFIG_BOOTM_PLAN9)
1457 static void copy_args(char *dest
, int argc
, char * const argv
[], char delim
)
1461 for (i
= 0; i
< argc
; i
++) {
1464 strcpy(dest
, argv
[i
]);
1465 dest
+= strlen(argv
[i
]);
1470 /*******************************************************************/
1471 /* OS booting routines */
1472 /*******************************************************************/
1474 #ifdef CONFIG_BOOTM_NETBSD
1475 static int do_bootm_netbsd(int flag
, int argc
, char * const argv
[],
1476 bootm_headers_t
*images
)
1478 void (*loader
)(bd_t
*, image_header_t
*, char *, char *);
1479 image_header_t
*os_hdr
, *hdr
;
1480 ulong kernel_data
, kernel_len
;
1484 if (flag
!= BOOTM_STATE_OS_GO
)
1487 #if defined(CONFIG_FIT)
1488 if (!images
->legacy_hdr_valid
) {
1489 fit_unsupported_reset("NetBSD");
1493 hdr
= images
->legacy_hdr_os
;
1496 * Booting a (NetBSD) kernel image
1498 * This process is pretty similar to a standalone application:
1499 * The (first part of an multi-) image must be a stage-2 loader,
1500 * which in turn is responsible for loading & invoking the actual
1501 * kernel. The only differences are the parameters being passed:
1502 * besides the board info strucure, the loader expects a command
1503 * line, the name of the console device, and (optionally) the
1504 * address of the original image header.
1507 if (image_check_type(&images
->legacy_hdr_os_copy
, IH_TYPE_MULTI
)) {
1508 image_multi_getimg(hdr
, 1, &kernel_data
, &kernel_len
);
1514 #if defined(CONFIG_8xx_CONS_SMC1)
1516 #elif defined(CONFIG_8xx_CONS_SMC2)
1518 #elif defined(CONFIG_8xx_CONS_SCC2)
1520 #elif defined(CONFIG_8xx_CONS_SCC3)
1528 for (i
= 0, len
= 0; i
< argc
; i
+= 1)
1529 len
+= strlen(argv
[i
]) + 1;
1530 cmdline
= malloc(len
);
1531 copy_args(cmdline
, argc
, argv
, ' ');
1532 } else if ((cmdline
= getenv("bootargs")) == NULL
) {
1536 loader
= (void (*)(bd_t
*, image_header_t
*, char *, char *))images
->ep
;
1538 printf("## Transferring control to NetBSD stage-2 loader "
1539 "(at address %08lx) ...\n",
1542 bootstage_mark(BOOTSTAGE_ID_RUN_OS
);
1545 * NetBSD Stage-2 Loader Parameters:
1546 * arg[0]: pointer to board info data
1547 * arg[1]: image load address
1548 * arg[2]: char pointer to the console device to use
1549 * arg[3]: char pointer to the boot arguments
1551 (*loader
)(gd
->bd
, os_hdr
, consdev
, cmdline
);
1555 #endif /* CONFIG_BOOTM_NETBSD*/
1557 #ifdef CONFIG_LYNXKDI
1558 static int do_bootm_lynxkdi(int flag
, int argc
, char * const argv
[],
1559 bootm_headers_t
*images
)
1561 image_header_t
*hdr
= &images
->legacy_hdr_os_copy
;
1563 if (flag
!= BOOTM_STATE_OS_GO
)
1566 #if defined(CONFIG_FIT)
1567 if (!images
->legacy_hdr_valid
) {
1568 fit_unsupported_reset("Lynx");
1573 lynxkdi_boot((image_header_t
*)hdr
);
1577 #endif /* CONFIG_LYNXKDI */
1579 #ifdef CONFIG_BOOTM_RTEMS
1580 static int do_bootm_rtems(int flag
, int argc
, char * const argv
[],
1581 bootm_headers_t
*images
)
1583 void (*entry_point
)(bd_t
*);
1585 if (flag
!= BOOTM_STATE_OS_GO
)
1588 #if defined(CONFIG_FIT)
1589 if (!images
->legacy_hdr_valid
) {
1590 fit_unsupported_reset("RTEMS");
1595 entry_point
= (void (*)(bd_t
*))images
->ep
;
1597 printf("## Transferring control to RTEMS (at address %08lx) ...\n",
1598 (ulong
)entry_point
);
1600 bootstage_mark(BOOTSTAGE_ID_RUN_OS
);
1604 * r3: ptr to board info data
1606 (*entry_point
)(gd
->bd
);
1610 #endif /* CONFIG_BOOTM_RTEMS */
1612 #if defined(CONFIG_BOOTM_OSE)
1613 static int do_bootm_ose(int flag
, int argc
, char * const argv
[],
1614 bootm_headers_t
*images
)
1616 void (*entry_point
)(void);
1618 if (flag
!= BOOTM_STATE_OS_GO
)
1621 #if defined(CONFIG_FIT)
1622 if (!images
->legacy_hdr_valid
) {
1623 fit_unsupported_reset("OSE");
1628 entry_point
= (void (*)(void))images
->ep
;
1630 printf("## Transferring control to OSE (at address %08lx) ...\n",
1631 (ulong
)entry_point
);
1633 bootstage_mark(BOOTSTAGE_ID_RUN_OS
);
1643 #endif /* CONFIG_BOOTM_OSE */
1645 #if defined(CONFIG_BOOTM_PLAN9)
1646 static int do_bootm_plan9(int flag
, int argc
, char * const argv
[],
1647 bootm_headers_t
*images
)
1649 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("Plan 9");
1662 /* See README.plan9 */
1663 s
= getenv("confaddr");
1665 char *confaddr
= (char *)simple_strtoul(s
, NULL
, 16);
1668 copy_args(confaddr
, argc
, argv
, '\n');
1670 s
= getenv("bootargs");
1672 strcpy(confaddr
, s
);
1676 entry_point
= (void (*)(void))images
->ep
;
1678 printf("## Transferring control to Plan 9 (at address %08lx) ...\n",
1679 (ulong
)entry_point
);
1681 bootstage_mark(BOOTSTAGE_ID_RUN_OS
);
1684 * Plan 9 Parameters:
1691 #endif /* CONFIG_BOOTM_PLAN9 */
1693 #if defined(CONFIG_BOOTM_VXWORKS) && \
1694 (defined(CONFIG_PPC) || defined(CONFIG_ARM))
1696 void do_bootvx_fdt(bootm_headers_t
*images
)
1698 #if defined(CONFIG_OF_LIBFDT)
1701 ulong of_size
= images
->ft_len
;
1702 char **of_flat_tree
= &images
->ft_addr
;
1703 struct lmb
*lmb
= &images
->lmb
;
1705 if (*of_flat_tree
) {
1706 boot_fdt_add_mem_rsv_regions(lmb
, *of_flat_tree
);
1708 ret
= boot_relocate_fdt(lmb
, of_flat_tree
, &of_size
);
1712 ret
= fdt_add_subnode(*of_flat_tree
, 0, "chosen");
1713 if ((ret
>= 0 || ret
== -FDT_ERR_EXISTS
)) {
1714 bootline
= getenv("bootargs");
1716 ret
= fdt_find_and_setprop(*of_flat_tree
,
1717 "/chosen", "bootargs",
1719 strlen(bootline
) + 1, 1);
1721 printf("## ERROR: %s : %s\n", __func__
,
1727 printf("## ERROR: %s : %s\n", __func__
,
1734 boot_prep_vxworks(images
);
1736 bootstage_mark(BOOTSTAGE_ID_RUN_OS
);
1738 #if defined(CONFIG_OF_LIBFDT)
1739 printf("## Starting vxWorks at 0x%08lx, device tree at 0x%08lx ...\n",
1740 (ulong
)images
->ep
, (ulong
)*of_flat_tree
);
1742 printf("## Starting vxWorks at 0x%08lx\n", (ulong
)images
->ep
);
1745 boot_jump_vxworks(images
);
1747 puts("## vxWorks terminated\n");
1750 static int do_bootm_vxworks(int flag
, int argc
, char * const argv
[],
1751 bootm_headers_t
*images
)
1753 if (flag
!= BOOTM_STATE_OS_GO
)
1756 #if defined(CONFIG_FIT)
1757 if (!images
->legacy_hdr_valid
) {
1758 fit_unsupported_reset("VxWorks");
1763 do_bootvx_fdt(images
);
1769 #if defined(CONFIG_CMD_ELF)
1770 static int do_bootm_qnxelf(int flag
, int argc
, char * const argv
[],
1771 bootm_headers_t
*images
)
1773 char *local_args
[2];
1776 if (flag
!= BOOTM_STATE_OS_GO
)
1779 #if defined(CONFIG_FIT)
1780 if (!images
->legacy_hdr_valid
) {
1781 fit_unsupported_reset("QNX");
1786 sprintf(str
, "%lx", images
->ep
); /* write entry-point into string */
1787 local_args
[0] = argv
[0];
1788 local_args
[1] = str
; /* and provide it via the arguments */
1789 do_bootelf(NULL
, 0, 2, local_args
);
1795 #ifdef CONFIG_INTEGRITY
1796 static int do_bootm_integrity(int flag
, int argc
, char * const argv
[],
1797 bootm_headers_t
*images
)
1799 void (*entry_point
)(void);
1801 if (flag
!= BOOTM_STATE_OS_GO
)
1804 #if defined(CONFIG_FIT)
1805 if (!images
->legacy_hdr_valid
) {
1806 fit_unsupported_reset("INTEGRITY");
1811 entry_point
= (void (*)(void))images
->ep
;
1813 printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
1814 (ulong
)entry_point
);
1816 bootstage_mark(BOOTSTAGE_ID_RUN_OS
);
1819 * INTEGRITY Parameters:
1828 #ifdef CONFIG_CMD_BOOTZ
1830 int __weak
bootz_setup(ulong image
, ulong
*start
, ulong
*end
)
1832 /* Please define bootz_setup() for your platform */
1834 puts("Your platform's zImage format isn't supported yet!\n");
1839 * zImage booting support
1841 static int bootz_start(cmd_tbl_t
*cmdtp
, int flag
, int argc
,
1842 char * const argv
[], bootm_headers_t
*images
)
1845 ulong zi_start
, zi_end
;
1847 ret
= do_bootm_states(cmdtp
, flag
, argc
, argv
, BOOTM_STATE_START
,
1850 /* Setup Linux kernel zImage entry point */
1852 images
->ep
= load_addr
;
1853 debug("* kernel: default image load address = 0x%08lx\n",
1856 images
->ep
= simple_strtoul(argv
[0], NULL
, 16);
1857 debug("* kernel: cmdline image address = 0x%08lx\n",
1861 ret
= bootz_setup(images
->ep
, &zi_start
, &zi_end
);
1865 lmb_reserve(&images
->lmb
, images
->ep
, zi_end
- zi_start
);
1868 * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
1869 * have a header that provide this informaiton.
1871 if (bootm_find_ramdisk(flag
, argc
, argv
))
1874 #if defined(CONFIG_OF_LIBFDT)
1875 if (bootm_find_fdt(flag
, argc
, argv
))
1882 int do_bootz(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
1886 /* Consume 'bootz' */
1889 if (bootz_start(cmdtp
, flag
, argc
, argv
, &images
))
1893 * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
1894 * disable interrupts ourselves
1896 bootm_disable_interrupts();
1898 images
.os
.os
= IH_OS_LINUX
;
1899 ret
= do_bootm_states(cmdtp
, flag
, argc
, argv
,
1900 BOOTM_STATE_OS_PREP
| BOOTM_STATE_OS_FAKE_GO
|
1907 #ifdef CONFIG_SYS_LONGHELP
1908 static char bootz_help_text
[] =
1909 "[addr [initrd[:size]] [fdt]]\n"
1910 " - boot Linux zImage stored in memory\n"
1911 "\tThe argument 'initrd' is optional and specifies the address\n"
1912 "\tof the initrd in memory. The optional argument ':size' allows\n"
1913 "\tspecifying the size of RAW initrd.\n"
1914 #if defined(CONFIG_OF_LIBFDT)
1915 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
1916 "\ta third argument is required which is the address of the\n"
1917 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1918 "\tuse a '-' for the second argument. If you do not pass a third\n"
1919 "\ta bd_info struct will be passed instead\n"
1925 bootz
, CONFIG_SYS_MAXARGS
, 1, do_bootz
,
1926 "boot Linux zImage image from memory", bootz_help_text
1928 #endif /* CONFIG_CMD_BOOTZ */