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 #include <linux/compiler.h>
42 #if defined(CONFIG_CMD_USB)
46 #ifdef CONFIG_SYS_HUSH_PARSER
50 #if defined(CONFIG_OF_LIBFDT)
52 #include <fdt_support.h>
56 #include <lzma/LzmaTypes.h>
57 #include <lzma/LzmaDec.h>
58 #include <lzma/LzmaTools.h>
59 #endif /* CONFIG_LZMA */
62 #include <linux/lzo.h>
63 #endif /* CONFIG_LZO */
65 DECLARE_GLOBAL_DATA_PTR;
67 #ifndef CONFIG_SYS_BOOTM_LEN
68 #define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
72 extern void bz_internal_error(int);
75 #if defined(CONFIG_CMD_IMI)
76 static int image_info(unsigned long addr);
79 #if defined(CONFIG_CMD_IMLS)
81 #include <mtd/cfi_flash.h>
82 extern flash_info_t flash_info[]; /* info for FLASH chips */
85 #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
86 static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
89 #include <linux/err.h>
92 #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
93 static void fixup_silent_linux(void);
96 static image_header_t *image_get_kernel(ulong img_addr, int verify);
97 #if defined(CONFIG_FIT)
98 static int fit_check_kernel(const void *fit, int os_noffset, int verify);
101 static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
102 char * const argv[], bootm_headers_t *images,
103 ulong *os_data, ulong *os_len);
106 * Continue booting an OS image; caller already has:
107 * - copied image header to global variable `header'
108 * - checked header magic number, checksums (both header & image),
109 * - verified image architecture (PPC) and type (KERNEL or MULTI),
110 * - loaded (first part of) image to header load address,
111 * - disabled interrupts.
113 typedef int boot_os_fn(int flag, int argc, char * const argv[],
114 bootm_headers_t *images); /* pointers to os/initrd/fdt */
116 #ifdef CONFIG_BOOTM_LINUX
117 extern boot_os_fn do_bootm_linux;
119 #ifdef CONFIG_BOOTM_NETBSD
120 static boot_os_fn do_bootm_netbsd;
122 #if defined(CONFIG_LYNXKDI)
123 static boot_os_fn do_bootm_lynxkdi;
124 extern void lynxkdi_boot(image_header_t *);
126 #ifdef CONFIG_BOOTM_RTEMS
127 static boot_os_fn do_bootm_rtems;
129 #if defined(CONFIG_BOOTM_OSE)
130 static boot_os_fn do_bootm_ose;
132 #if defined(CONFIG_BOOTM_PLAN9)
133 static boot_os_fn do_bootm_plan9;
135 #if defined(CONFIG_CMD_ELF)
136 static boot_os_fn do_bootm_vxworks;
137 static boot_os_fn do_bootm_qnxelf;
138 int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
139 int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
141 #if defined(CONFIG_INTEGRITY)
142 static boot_os_fn do_bootm_integrity;
145 static boot_os_fn *boot_os[] = {
146 #ifdef CONFIG_BOOTM_LINUX
147 [IH_OS_LINUX] = do_bootm_linux,
149 #ifdef CONFIG_BOOTM_NETBSD
150 [IH_OS_NETBSD] = do_bootm_netbsd,
152 #ifdef CONFIG_LYNXKDI
153 [IH_OS_LYNXOS] = do_bootm_lynxkdi,
155 #ifdef CONFIG_BOOTM_RTEMS
156 [IH_OS_RTEMS] = do_bootm_rtems,
158 #if defined(CONFIG_BOOTM_OSE)
159 [IH_OS_OSE] = do_bootm_ose,
161 #if defined(CONFIG_BOOTM_PLAN9)
162 [IH_OS_PLAN9] = do_bootm_plan9,
164 #if defined(CONFIG_CMD_ELF)
165 [IH_OS_VXWORKS] = do_bootm_vxworks,
166 [IH_OS_QNX] = do_bootm_qnxelf,
168 #ifdef CONFIG_INTEGRITY
169 [IH_OS_INTEGRITY] = do_bootm_integrity,
173 bootm_headers_t images; /* pointers to os/initrd/fdt images */
175 /* Allow for arch specific config before we boot */
176 static void __arch_preboot_os(void)
178 /* please define platform specific arch_preboot_os() */
180 void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
182 #define IH_INITRD_ARCH IH_ARCH_DEFAULT
185 static void boot_start_lmb(bootm_headers_t *images)
188 phys_size_t mem_size;
190 lmb_init(&images->lmb);
192 mem_start = getenv_bootm_low();
193 mem_size = getenv_bootm_size();
195 lmb_add(&images->lmb, (phys_addr_t)mem_start, mem_size);
197 arch_lmb_reserve(&images->lmb);
198 board_lmb_reserve(&images->lmb);
201 #define lmb_reserve(lmb, base, size)
202 static inline void boot_start_lmb(bootm_headers_t *images) { }
205 static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
210 memset((void *)&images, 0, sizeof(images));
211 images.verify = getenv_yesno("verify");
213 boot_start_lmb(&images);
215 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_START, "bootm_start");
217 /* get kernel image header, start address and length */
218 os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
219 &images, &images.os.image_start, &images.os.image_len);
220 if (images.os.image_len == 0) {
221 puts("ERROR: can't get kernel image!\n");
225 /* get image parameters */
226 switch (genimg_get_format(os_hdr)) {
227 case IMAGE_FORMAT_LEGACY:
228 images.os.type = image_get_type(os_hdr);
229 images.os.comp = image_get_comp(os_hdr);
230 images.os.os = image_get_os(os_hdr);
232 images.os.end = image_get_image_end(os_hdr);
233 images.os.load = image_get_load(os_hdr);
235 #if defined(CONFIG_FIT)
236 case IMAGE_FORMAT_FIT:
237 if (fit_image_get_type(images.fit_hdr_os,
238 images.fit_noffset_os, &images.os.type)) {
239 puts("Can't get image type!\n");
240 bootstage_error(BOOTSTAGE_ID_FIT_TYPE);
244 if (fit_image_get_comp(images.fit_hdr_os,
245 images.fit_noffset_os, &images.os.comp)) {
246 puts("Can't get image compression!\n");
247 bootstage_error(BOOTSTAGE_ID_FIT_COMPRESSION);
251 if (fit_image_get_os(images.fit_hdr_os,
252 images.fit_noffset_os, &images.os.os)) {
253 puts("Can't get image OS!\n");
254 bootstage_error(BOOTSTAGE_ID_FIT_OS);
258 images.os.end = fit_get_end(images.fit_hdr_os);
260 if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os,
262 puts("Can't get image load address!\n");
263 bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR);
269 puts("ERROR: unknown image format type!\n");
273 /* find kernel entry point */
274 if (images.legacy_hdr_valid) {
275 images.ep = image_get_ep(&images.legacy_hdr_os_copy);
276 #if defined(CONFIG_FIT)
277 } else if (images.fit_uname_os) {
278 ret = fit_image_get_entry(images.fit_hdr_os,
279 images.fit_noffset_os, &images.ep);
281 puts("Can't get entry point property!\n");
286 puts("Could not find kernel entry point!\n");
290 if (images.os.type == IH_TYPE_KERNEL_NOLOAD) {
291 images.os.load = images.os.image_start;
292 images.ep += images.os.load;
295 if (((images.os.type == IH_TYPE_KERNEL) ||
296 (images.os.type == IH_TYPE_KERNEL_NOLOAD) ||
297 (images.os.type == IH_TYPE_MULTI)) &&
298 (images.os.os == IH_OS_LINUX)) {
300 ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH,
301 &images.rd_start, &images.rd_end);
303 puts("Ramdisk image is corrupt or invalid\n");
307 #if defined(CONFIG_OF_LIBFDT)
308 /* find flattened device tree */
309 ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, &images,
310 &images.ft_addr, &images.ft_len);
312 puts("Could not find a valid device tree\n");
316 set_working_fdt_addr(images.ft_addr);
320 images.os.start = (ulong)os_hdr;
321 images.state = BOOTM_STATE_START;
326 #define BOOTM_ERR_RESET -1
327 #define BOOTM_ERR_OVERLAP -2
328 #define BOOTM_ERR_UNIMPLEMENTED -3
329 static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
331 uint8_t comp = os.comp;
332 ulong load = os.load;
333 ulong blob_start = os.start;
334 ulong blob_end = os.end;
335 ulong image_start = os.image_start;
336 ulong image_len = os.image_len;
337 __maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN;
339 void *load_buf, *image_buf;
340 #if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
342 #endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
344 const char *type_name = genimg_get_type_name(os.type);
346 load_buf = map_sysmem(load, image_len);
347 image_buf = map_sysmem(image_start, image_len);
350 if (load == blob_start || load == image_start) {
351 printf(" XIP %s ... ", type_name);
354 printf(" Loading %s ... ", type_name);
355 memmove_wd(load_buf, image_buf, image_len, CHUNKSZ);
357 *load_end = load + image_len;
362 printf(" Uncompressing %s ... ", type_name);
363 if (gunzip(load_buf, unc_len, image_buf, &image_len) != 0) {
364 puts("GUNZIP: uncompress, out-of-mem or overwrite "
365 "error - must RESET board to recover\n");
367 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
368 return BOOTM_ERR_RESET;
371 *load_end = load + image_len;
373 #endif /* CONFIG_GZIP */
376 printf(" Uncompressing %s ... ", type_name);
378 * If we've got less than 4 MB of malloc() space,
379 * use slower decompression algorithm which requires
380 * at most 2300 KB of memory.
382 int i = BZ2_bzBuffToBuffDecompress(load_buf, &unc_len,
383 image_buf, image_len,
384 CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
386 printf("BUNZIP2: uncompress or overwrite error %d "
387 "- must RESET board to recover\n", i);
389 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
390 return BOOTM_ERR_RESET;
393 *load_end = load + unc_len;
395 #endif /* CONFIG_BZIP2 */
398 SizeT lzma_len = unc_len;
399 printf(" Uncompressing %s ... ", type_name);
401 ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len,
402 image_buf, image_len);
405 printf("LZMA: uncompress or overwrite error %d "
406 "- must RESET board to recover\n", ret);
407 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
408 return BOOTM_ERR_RESET;
410 *load_end = load + unc_len;
413 #endif /* CONFIG_LZMA */
416 printf(" Uncompressing %s ... ", type_name);
418 ret = lzop_decompress(image_buf, image_len, load_buf,
420 if (ret != LZO_E_OK) {
421 printf("LZO: uncompress or overwrite error %d "
422 "- must RESET board to recover\n", ret);
424 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
425 return BOOTM_ERR_RESET;
428 *load_end = load + unc_len;
430 #endif /* CONFIG_LZO */
432 printf("Unimplemented compression type %d\n", comp);
433 return BOOTM_ERR_UNIMPLEMENTED;
436 flush_cache(load, (*load_end - load) * sizeof(ulong));
439 debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
440 bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED);
442 if (!no_overlap && (load < blob_end) && (*load_end > blob_start)) {
443 debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n",
444 blob_start, blob_end);
445 debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load,
448 return BOOTM_ERR_OVERLAP;
454 static int bootm_start_standalone(ulong iflag, int argc, char * const argv[])
457 int (*appl)(int, char * const []);
459 /* Don't start if "autostart" is set to "no" */
460 if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
461 setenv_hex("filesize", images.os.image_len);
464 appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep);
465 (*appl)(argc-1, &argv[1]);
469 /* we overload the cmd field with our state machine info instead of a
470 * function pointer */
471 static cmd_tbl_t cmd_bootm_sub[] = {
472 U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
473 U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
474 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
475 U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
477 #ifdef CONFIG_OF_LIBFDT
478 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
480 U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
481 U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
482 U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
483 U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
486 static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
494 c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
497 state = (long)c->cmd;
499 /* treat start special since it resets the state machine */
500 if (state == BOOTM_STATE_START) {
503 return bootm_start(cmdtp, flag, argc, argv);
506 /* Unrecognized command */
507 return CMD_RET_USAGE;
510 if (images.state < BOOTM_STATE_START ||
511 images.state >= state) {
512 printf("Trying to execute a command out of order\n");
513 return CMD_RET_USAGE;
516 images.state |= state;
517 boot_fn = boot_os[images.os.os];
521 case BOOTM_STATE_START:
522 /* should never occur */
524 case BOOTM_STATE_LOADOS:
525 ret = bootm_load_os(images.os, &load_end, 0);
529 lmb_reserve(&images.lmb, images.os.load,
530 (load_end - images.os.load));
532 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
533 case BOOTM_STATE_RAMDISK:
535 ulong rd_len = images.rd_end - images.rd_start;
537 ret = boot_ramdisk_high(&images.lmb, images.rd_start,
538 rd_len, &images.initrd_start, &images.initrd_end);
542 setenv_hex("initrd_start", images.initrd_start);
543 setenv_hex("initrd_end", images.initrd_end);
547 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_LMB)
548 case BOOTM_STATE_FDT:
550 boot_fdt_add_mem_rsv_regions(&images.lmb,
552 ret = boot_relocate_fdt(&images.lmb,
553 &images.ft_addr, &images.ft_len);
557 case BOOTM_STATE_OS_CMDLINE:
558 ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, &images);
560 printf("cmdline subcommand not supported\n");
562 case BOOTM_STATE_OS_BD_T:
563 ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, &images);
565 printf("bdt subcommand not supported\n");
567 case BOOTM_STATE_OS_PREP:
568 ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, &images);
570 printf("prep subcommand not supported\n");
572 case BOOTM_STATE_OS_GO:
573 disable_interrupts();
574 #ifdef CONFIG_NETCONSOLE
576 * Stop the ethernet stack if NetConsole could have
582 boot_fn(BOOTM_STATE_OS_GO, argc, argv, &images);
589 /*******************************************************************/
590 /* bootm - boot application image from image in memory */
591 /*******************************************************************/
593 int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
599 #ifdef CONFIG_NEEDS_MANUAL_RELOC
600 static int relocated = 0;
605 /* relocate boot function table */
606 for (i = 0; i < ARRAY_SIZE(boot_os); i++)
607 if (boot_os[i] != NULL)
608 boot_os[i] += gd->reloc_off;
610 /* relocate names of sub-command table */
611 for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++)
612 cmd_bootm_sub[i].name += gd->reloc_off;
618 /* determine if we have a sub command */
622 simple_strtoul(argv[1], &endp, 16);
623 /* endp pointing to NULL means that argv[1] was just a
624 * valid number, pass it along to the normal bootm processing
626 * If endp is ':' or '#' assume a FIT identifier so pass
627 * along for normal processing.
629 * Right now we assume the first arg should never be '-'
631 if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
632 return do_bootm_subcommand(cmdtp, flag, argc, argv);
635 if (bootm_start(cmdtp, flag, argc, argv))
639 * We have reached the point of no return: we are going to
640 * overwrite all exception vector code, so we cannot easily
641 * recover from any failures any more...
643 iflag = disable_interrupts();
645 #ifdef CONFIG_NETCONSOLE
646 /* Stop the ethernet stack if NetConsole could have left it up */
650 #if defined(CONFIG_CMD_USB)
652 * turn off USB to prevent the host controller from writing to the
653 * SDRAM while Linux is booting. This could happen (at least for OHCI
654 * controller), because the HCCA (Host Controller Communication Area)
655 * lies within the SDRAM and the host controller writes continously to
656 * this area (as busmaster!). The HccaFrameNumber is for example
657 * updated every 1 ms within the HCCA structure in SDRAM! For more
658 * details see the OpenHCI specification.
663 ret = bootm_load_os(images.os, &load_end, 1);
666 if (ret == BOOTM_ERR_RESET)
667 do_reset(cmdtp, flag, argc, argv);
668 if (ret == BOOTM_ERR_OVERLAP) {
669 if (images.legacy_hdr_valid) {
671 hdr = &images.legacy_hdr_os_copy;
672 if (image_get_type(hdr) == IH_TYPE_MULTI)
673 puts("WARNING: legacy format multi "
677 puts("ERROR: new format image overwritten - "
678 "must RESET the board to recover\n");
679 bootstage_error(BOOTSTAGE_ID_OVERWRITTEN);
680 do_reset(cmdtp, flag, argc, argv);
683 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
686 bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL);
691 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
693 if (images.os.type == IH_TYPE_STANDALONE) {
696 /* This may return when 'autostart' is 'no' */
697 bootm_start_standalone(iflag, argc, argv);
701 bootstage_mark(BOOTSTAGE_ID_CHECK_BOOT_OS);
703 #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
704 if (images.os.os == IH_OS_LINUX)
705 fixup_silent_linux();
708 boot_fn = boot_os[images.os.os];
710 if (boot_fn == NULL) {
713 printf("ERROR: booting os '%s' (%d) is not supported\n",
714 genimg_get_os_name(images.os.os), images.os.os);
715 bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS);
721 boot_fn(0, argc, argv, &images);
723 bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED);
725 puts("\n## Control returned to monitor - resetting...\n");
727 do_reset(cmdtp, flag, argc, argv);
732 int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
734 const char *ep = getenv("autostart");
736 if (ep && !strcmp(ep, "yes")) {
738 local_args[0] = (char *)cmd;
739 local_args[1] = NULL;
740 printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
741 return do_bootm(cmdtp, 0, 1, local_args);
748 * image_get_kernel - verify legacy format kernel image
749 * @img_addr: in RAM address of the legacy format image to be verified
750 * @verify: data CRC verification flag
752 * image_get_kernel() verifies legacy image integrity and returns pointer to
753 * legacy image header if image verification was completed successfully.
756 * pointer to a legacy image header if valid image was found
757 * otherwise return NULL
759 static image_header_t *image_get_kernel(ulong img_addr, int verify)
761 image_header_t *hdr = (image_header_t *)img_addr;
763 if (!image_check_magic(hdr)) {
764 puts("Bad Magic Number\n");
765 bootstage_error(BOOTSTAGE_ID_CHECK_MAGIC);
768 bootstage_mark(BOOTSTAGE_ID_CHECK_HEADER);
770 if (!image_check_hcrc(hdr)) {
771 puts("Bad Header Checksum\n");
772 bootstage_error(BOOTSTAGE_ID_CHECK_HEADER);
776 bootstage_mark(BOOTSTAGE_ID_CHECK_CHECKSUM);
777 image_print_contents(hdr);
780 puts(" Verifying Checksum ... ");
781 if (!image_check_dcrc(hdr)) {
782 printf("Bad Data CRC\n");
783 bootstage_error(BOOTSTAGE_ID_CHECK_CHECKSUM);
788 bootstage_mark(BOOTSTAGE_ID_CHECK_ARCH);
790 if (!image_check_target_arch(hdr)) {
791 printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr));
792 bootstage_error(BOOTSTAGE_ID_CHECK_ARCH);
799 * fit_check_kernel - verify FIT format kernel subimage
800 * @fit_hdr: pointer to the FIT image header
801 * os_noffset: kernel subimage node offset within FIT image
802 * @verify: data CRC verification flag
804 * fit_check_kernel() verifies integrity of the kernel subimage and from
805 * specified FIT image.
811 #if defined(CONFIG_FIT)
812 static int fit_check_kernel(const void *fit, int os_noffset, int verify)
814 fit_image_print(fit, os_noffset, " ");
817 puts(" Verifying Hash Integrity ... ");
818 if (!fit_image_verify(fit, os_noffset)) {
819 puts("Bad Data Hash\n");
820 bootstage_error(BOOTSTAGE_ID_FIT_CHECK_HASH);
825 bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_ARCH);
827 if (!fit_image_check_target_arch(fit, os_noffset)) {
828 puts("Unsupported Architecture\n");
829 bootstage_error(BOOTSTAGE_ID_FIT_CHECK_ARCH);
833 bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_KERNEL);
834 if (!fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL) &&
835 !fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL_NOLOAD)) {
836 puts("Not a kernel image\n");
837 bootstage_error(BOOTSTAGE_ID_FIT_CHECK_KERNEL);
841 bootstage_mark(BOOTSTAGE_ID_FIT_CHECKED);
844 #endif /* CONFIG_FIT */
847 * boot_get_kernel - find kernel image
848 * @os_data: pointer to a ulong variable, will hold os data start address
849 * @os_len: pointer to a ulong variable, will hold os data length
851 * boot_get_kernel() tries to find a kernel image, verifies its integrity
852 * and locates kernel data.
855 * pointer to image header if valid image was found, plus kernel start
856 * address and length, otherwise NULL
858 static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
859 char * const argv[], bootm_headers_t *images, ulong *os_data,
865 #if defined(CONFIG_FIT)
867 const char *fit_uname_config = NULL;
868 const char *fit_uname_kernel = NULL;
875 /* find out kernel image address */
877 img_addr = load_addr;
878 debug("* kernel: default image load address = 0x%08lx\n",
880 #if defined(CONFIG_FIT)
881 } else if (fit_parse_conf(argv[1], load_addr, &img_addr,
882 &fit_uname_config)) {
883 debug("* kernel: config '%s' from image at 0x%08lx\n",
884 fit_uname_config, img_addr);
885 } else if (fit_parse_subimage(argv[1], load_addr, &img_addr,
886 &fit_uname_kernel)) {
887 debug("* kernel: subimage '%s' from image at 0x%08lx\n",
888 fit_uname_kernel, img_addr);
891 img_addr = simple_strtoul(argv[1], NULL, 16);
892 debug("* kernel: cmdline image address = 0x%08lx\n", img_addr);
895 bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC);
897 /* copy from dataflash if needed */
898 img_addr = genimg_get_image(img_addr);
900 /* check image type, for FIT images get FIT kernel node */
901 *os_data = *os_len = 0;
902 buf = map_sysmem(img_addr, 0);
903 switch (genimg_get_format(buf)) {
904 case IMAGE_FORMAT_LEGACY:
905 printf("## Booting kernel from Legacy Image at %08lx ...\n",
907 hdr = image_get_kernel(img_addr, images->verify);
910 bootstage_mark(BOOTSTAGE_ID_CHECK_IMAGETYPE);
912 /* get os_data and os_len */
913 switch (image_get_type(hdr)) {
915 case IH_TYPE_KERNEL_NOLOAD:
916 *os_data = image_get_data(hdr);
917 *os_len = image_get_data_size(hdr);
920 image_multi_getimg(hdr, 0, os_data, os_len);
922 case IH_TYPE_STANDALONE:
923 *os_data = image_get_data(hdr);
924 *os_len = image_get_data_size(hdr);
927 printf("Wrong Image Type for %s command\n",
929 bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE);
934 * copy image header to allow for image overwrites during
935 * kernel decompression.
937 memmove(&images->legacy_hdr_os_copy, hdr,
938 sizeof(image_header_t));
940 /* save pointer to image header */
941 images->legacy_hdr_os = hdr;
943 images->legacy_hdr_valid = 1;
944 bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE);
946 #if defined(CONFIG_FIT)
947 case IMAGE_FORMAT_FIT:
949 printf("## Booting kernel from FIT Image at %08lx ...\n",
952 if (!fit_check_format(fit_hdr)) {
953 puts("Bad FIT kernel image format!\n");
954 bootstage_error(BOOTSTAGE_ID_FIT_FORMAT);
957 bootstage_mark(BOOTSTAGE_ID_FIT_FORMAT);
959 if (!fit_uname_kernel) {
961 * no kernel image node unit name, try to get config
962 * node first. If config unit node name is NULL
963 * fit_conf_get_node() will try to find default config
966 bootstage_mark(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
967 #ifdef CONFIG_FIT_BEST_MATCH
968 if (fit_uname_config)
970 fit_conf_get_node(fit_hdr,
974 fit_conf_find_compat(fit_hdr,
977 cfg_noffset = fit_conf_get_node(fit_hdr,
980 if (cfg_noffset < 0) {
981 bootstage_error(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
984 /* save configuration uname provided in the first
987 images->fit_uname_cfg = fdt_get_name(fit_hdr,
990 printf(" Using '%s' configuration\n",
991 images->fit_uname_cfg);
992 bootstage_mark(BOOTSTAGE_ID_FIT_CONFIG);
994 os_noffset = fit_conf_get_kernel_node(fit_hdr,
996 fit_uname_kernel = fit_get_name(fit_hdr, os_noffset,
999 /* get kernel component image node offset */
1000 bootstage_mark(BOOTSTAGE_ID_FIT_UNIT_NAME);
1001 os_noffset = fit_image_get_node(fit_hdr,
1004 if (os_noffset < 0) {
1005 bootstage_error(BOOTSTAGE_ID_FIT_CONFIG);
1009 printf(" Trying '%s' kernel subimage\n", fit_uname_kernel);
1011 bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_SUBIMAGE);
1012 if (!fit_check_kernel(fit_hdr, os_noffset, images->verify))
1015 /* get kernel image data address and length */
1016 if (fit_image_get_data(fit_hdr, os_noffset, &data, &len)) {
1017 puts("Could not find kernel subimage data!\n");
1018 bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO_ERR);
1021 bootstage_mark(BOOTSTAGE_ID_FIT_KERNEL_INFO);
1024 *os_data = (ulong)data;
1025 images->fit_hdr_os = (void *)fit_hdr;
1026 images->fit_uname_os = fit_uname_kernel;
1027 images->fit_noffset_os = os_noffset;
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 case IMAGE_FORMAT_LEGACY:
1143 puts(" Legacy image found\n");
1144 if (!image_check_magic(hdr)) {
1145 puts(" Bad Magic Number\n");
1149 if (!image_check_hcrc(hdr)) {
1150 puts(" Bad Header Checksum\n");
1154 image_print_contents(hdr);
1156 puts(" Verifying Checksum ... ");
1157 if (!image_check_dcrc(hdr)) {
1158 puts(" Bad Data CRC\n");
1163 #if defined(CONFIG_FIT)
1164 case IMAGE_FORMAT_FIT:
1165 puts(" FIT image found\n");
1167 if (!fit_check_format(hdr)) {
1168 puts("Bad FIT image format!\n");
1172 fit_print_contents(hdr);
1174 if (!fit_all_image_verify(hdr)) {
1175 puts("Bad hash in FIT image!\n");
1182 puts("Unknown image format!\n");
1190 iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
1191 "print header information for application image",
1193 " - print header information for application image starting at\n"
1194 " address 'addr' in memory; this includes verification of the\n"
1195 " image contents (magic number, header and payload checksums)"
1200 /*******************************************************************/
1201 /* imls - list all images found in flash */
1202 /*******************************************************************/
1203 #if defined(CONFIG_CMD_IMLS)
1204 static int do_imls_nor(void)
1210 for (i = 0, info = &flash_info[0];
1211 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
1213 if (info->flash_id == FLASH_UNKNOWN)
1215 for (j = 0; j < info->sector_count; ++j) {
1217 hdr = (void *)info->start[j];
1221 switch (genimg_get_format(hdr)) {
1222 case IMAGE_FORMAT_LEGACY:
1223 if (!image_check_hcrc(hdr))
1226 printf("Legacy Image at %08lX:\n", (ulong)hdr);
1227 image_print_contents(hdr);
1229 puts(" Verifying Checksum ... ");
1230 if (!image_check_dcrc(hdr)) {
1231 puts("Bad Data CRC\n");
1236 #if defined(CONFIG_FIT)
1237 case IMAGE_FORMAT_FIT:
1238 if (!fit_check_format(hdr))
1241 printf("FIT Image at %08lX:\n", (ulong)hdr);
1242 fit_print_contents(hdr);
1257 #if defined(CONFIG_CMD_IMLS_NAND)
1258 static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off,
1264 imgdata = malloc(len);
1266 printf("May be a Legacy Image at NAND device %d offset %08llX:\n",
1268 printf(" Low memory(cannot allocate memory for image)\n");
1272 ret = nand_read_skip_bad(nand, off, &len,
1274 if (ret < 0 && ret != -EUCLEAN) {
1279 if (!image_check_hcrc(imgdata)) {
1284 printf("Legacy Image at NAND device %d offset %08llX:\n",
1286 image_print_contents(imgdata);
1288 puts(" Verifying Checksum ... ");
1289 if (!image_check_dcrc(imgdata))
1290 puts("Bad Data CRC\n");
1299 static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off,
1305 imgdata = malloc(len);
1307 printf("May be a FIT Image at NAND device %d offset %08llX:\n",
1309 printf(" Low memory(cannot allocate memory for image)\n");
1313 ret = nand_read_skip_bad(nand, off, &len,
1315 if (ret < 0 && ret != -EUCLEAN) {
1320 if (!fit_check_format(imgdata)) {
1325 printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off);
1327 fit_print_contents(imgdata);
1333 static int do_imls_nand(void)
1336 int nand_dev = nand_curr_device;
1341 if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) {
1342 puts("\nNo NAND devices available\n");
1348 for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) {
1349 nand = &nand_info[nand_dev];
1350 if (!nand->name || !nand->size)
1353 for (off = 0; off < nand->size; off += nand->erasesize) {
1354 const image_header_t *header;
1357 if (nand_block_isbad(nand, off))
1360 len = sizeof(buffer);
1362 ret = nand_read(nand, off, &len, (u8 *)buffer);
1363 if (ret < 0 && ret != -EUCLEAN) {
1364 printf("NAND read error %d at offset %08llX\n",
1369 switch (genimg_get_format(buffer)) {
1370 case IMAGE_FORMAT_LEGACY:
1371 header = (const image_header_t *)buffer;
1373 len = image_get_image_size(header);
1374 nand_imls_legacyimage(nand, nand_dev, off, len);
1376 #if defined(CONFIG_FIT)
1377 case IMAGE_FORMAT_FIT:
1378 len = fit_get_size(buffer);
1379 nand_imls_fitimage(nand, nand_dev, off, len);
1390 #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
1391 static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1393 int ret_nor = 0, ret_nand = 0;
1395 #if defined(CONFIG_CMD_IMLS)
1396 ret_nor = do_imls_nor();
1399 #if defined(CONFIG_CMD_IMLS_NAND)
1400 ret_nand = do_imls_nand();
1413 imls, 1, 1, do_imls,
1414 "list all images found in flash",
1416 " - Prints information about all images found at sector/block\n"
1417 " boundaries in nor/nand flash."
1421 /*******************************************************************/
1422 /* helper routines */
1423 /*******************************************************************/
1424 #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
1426 #define CONSOLE_ARG "console="
1427 #define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1)
1429 static void fixup_silent_linux(void)
1432 const char *env_val;
1433 char *cmdline = getenv("bootargs");
1435 /* Only fix cmdline when requested */
1436 if (!(gd->flags & GD_FLG_SILENT))
1439 debug("before silent fix-up: %s\n", cmdline);
1440 if (cmdline && (cmdline[0] != '\0')) {
1441 char *start = strstr(cmdline, CONSOLE_ARG);
1443 /* Allocate space for maximum possible new command line */
1444 buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_LEN + 1);
1446 debug("%s: out of memory\n", __func__);
1451 char *end = strchr(start, ' ');
1452 int num_start_bytes = start - cmdline + CONSOLE_ARG_LEN;
1454 strncpy(buf, cmdline, num_start_bytes);
1456 strcpy(buf + num_start_bytes, end);
1458 buf[num_start_bytes] = '\0';
1460 sprintf(buf, "%s %s", cmdline, CONSOLE_ARG);
1465 env_val = CONSOLE_ARG;
1468 setenv("bootargs", env_val);
1469 debug("after silent fix-up: %s\n", env_val);
1472 #endif /* CONFIG_SILENT_CONSOLE */
1475 /*******************************************************************/
1476 /* OS booting routines */
1477 /*******************************************************************/
1479 #ifdef CONFIG_BOOTM_NETBSD
1480 static int do_bootm_netbsd(int flag, int argc, char * const argv[],
1481 bootm_headers_t *images)
1483 void (*loader)(bd_t *, image_header_t *, char *, char *);
1484 image_header_t *os_hdr, *hdr;
1485 ulong kernel_data, kernel_len;
1489 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1492 #if defined(CONFIG_FIT)
1493 if (!images->legacy_hdr_valid) {
1494 fit_unsupported_reset("NetBSD");
1498 hdr = images->legacy_hdr_os;
1501 * Booting a (NetBSD) kernel image
1503 * This process is pretty similar to a standalone application:
1504 * The (first part of an multi-) image must be a stage-2 loader,
1505 * which in turn is responsible for loading & invoking the actual
1506 * kernel. The only differences are the parameters being passed:
1507 * besides the board info strucure, the loader expects a command
1508 * line, the name of the console device, and (optionally) the
1509 * address of the original image header.
1512 if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1513 image_multi_getimg(hdr, 1, &kernel_data, &kernel_len);
1519 #if defined(CONFIG_8xx_CONS_SMC1)
1521 #elif defined(CONFIG_8xx_CONS_SMC2)
1523 #elif defined(CONFIG_8xx_CONS_SCC2)
1525 #elif defined(CONFIG_8xx_CONS_SCC3)
1533 for (i = 2, len = 0; i < argc; i += 1)
1534 len += strlen(argv[i]) + 1;
1535 cmdline = malloc(len);
1537 for (i = 2, len = 0; i < argc; i += 1) {
1539 cmdline[len++] = ' ';
1540 strcpy(&cmdline[len], argv[i]);
1541 len += strlen(argv[i]);
1543 } else if ((cmdline = getenv("bootargs")) == NULL) {
1547 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
1549 printf("## Transferring control to NetBSD stage-2 loader "
1550 "(at address %08lx) ...\n",
1553 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1556 * NetBSD Stage-2 Loader Parameters:
1557 * r3: ptr to board info data
1559 * r5: console device
1560 * r6: boot args string
1562 (*loader)(gd->bd, os_hdr, consdev, cmdline);
1566 #endif /* CONFIG_BOOTM_NETBSD*/
1568 #ifdef CONFIG_LYNXKDI
1569 static int do_bootm_lynxkdi(int flag, int argc, char * const argv[],
1570 bootm_headers_t *images)
1572 image_header_t *hdr = &images->legacy_hdr_os_copy;
1574 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1577 #if defined(CONFIG_FIT)
1578 if (!images->legacy_hdr_valid) {
1579 fit_unsupported_reset("Lynx");
1584 lynxkdi_boot((image_header_t *)hdr);
1588 #endif /* CONFIG_LYNXKDI */
1590 #ifdef CONFIG_BOOTM_RTEMS
1591 static int do_bootm_rtems(int flag, int argc, char * const argv[],
1592 bootm_headers_t *images)
1594 void (*entry_point)(bd_t *);
1596 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1599 #if defined(CONFIG_FIT)
1600 if (!images->legacy_hdr_valid) {
1601 fit_unsupported_reset("RTEMS");
1606 entry_point = (void (*)(bd_t *))images->ep;
1608 printf("## Transferring control to RTEMS (at address %08lx) ...\n",
1609 (ulong)entry_point);
1611 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1615 * r3: ptr to board info data
1617 (*entry_point)(gd->bd);
1621 #endif /* CONFIG_BOOTM_RTEMS */
1623 #if defined(CONFIG_BOOTM_OSE)
1624 static int do_bootm_ose(int flag, int argc, char * const argv[],
1625 bootm_headers_t *images)
1627 void (*entry_point)(void);
1629 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1632 #if defined(CONFIG_FIT)
1633 if (!images->legacy_hdr_valid) {
1634 fit_unsupported_reset("OSE");
1639 entry_point = (void (*)(void))images->ep;
1641 printf("## Transferring control to OSE (at address %08lx) ...\n",
1642 (ulong)entry_point);
1644 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1654 #endif /* CONFIG_BOOTM_OSE */
1656 #if defined(CONFIG_BOOTM_PLAN9)
1657 static int do_bootm_plan9(int flag, int argc, char * const argv[],
1658 bootm_headers_t *images)
1660 void (*entry_point)(void);
1662 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1665 #if defined(CONFIG_FIT)
1666 if (!images->legacy_hdr_valid) {
1667 fit_unsupported_reset("Plan 9");
1672 entry_point = (void (*)(void))images->ep;
1674 printf("## Transferring control to Plan 9 (at address %08lx) ...\n",
1675 (ulong)entry_point);
1677 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1680 * Plan 9 Parameters:
1687 #endif /* CONFIG_BOOTM_PLAN9 */
1689 #if defined(CONFIG_CMD_ELF)
1690 static int do_bootm_vxworks(int flag, int argc, char * const argv[],
1691 bootm_headers_t *images)
1695 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1698 #if defined(CONFIG_FIT)
1699 if (!images->legacy_hdr_valid) {
1700 fit_unsupported_reset("VxWorks");
1705 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1706 setenv("loadaddr", str);
1707 do_bootvx(NULL, 0, 0, NULL);
1712 static int do_bootm_qnxelf(int flag, int argc, char * const argv[],
1713 bootm_headers_t *images)
1715 char *local_args[2];
1718 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1721 #if defined(CONFIG_FIT)
1722 if (!images->legacy_hdr_valid) {
1723 fit_unsupported_reset("QNX");
1728 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1729 local_args[0] = argv[0];
1730 local_args[1] = str; /* and provide it via the arguments */
1731 do_bootelf(NULL, 0, 2, local_args);
1737 #ifdef CONFIG_INTEGRITY
1738 static int do_bootm_integrity(int flag, int argc, char * const argv[],
1739 bootm_headers_t *images)
1741 void (*entry_point)(void);
1743 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1746 #if defined(CONFIG_FIT)
1747 if (!images->legacy_hdr_valid) {
1748 fit_unsupported_reset("INTEGRITY");
1753 entry_point = (void (*)(void))images->ep;
1755 printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
1756 (ulong)entry_point);
1758 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1761 * INTEGRITY Parameters:
1770 #ifdef CONFIG_CMD_BOOTZ
1772 static int __bootz_setup(void *image, void **start, void **end)
1774 /* Please define bootz_setup() for your platform */
1776 puts("Your platform's zImage format isn't supported yet!\n");
1779 int bootz_setup(void *image, void **start, void **end)
1780 __attribute__((weak, alias("__bootz_setup")));
1783 * zImage booting support
1785 static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
1786 char * const argv[], bootm_headers_t *images)
1789 void *zi_start, *zi_end;
1791 memset(images, 0, sizeof(bootm_headers_t));
1793 boot_start_lmb(images);
1795 /* Setup Linux kernel zImage entry point */
1797 images->ep = load_addr;
1798 debug("* kernel: default image load address = 0x%08lx\n",
1801 images->ep = simple_strtoul(argv[1], NULL, 16);
1802 debug("* kernel: cmdline image address = 0x%08lx\n",
1806 ret = bootz_setup((void *)images->ep, &zi_start, &zi_end);
1810 lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
1813 ret = boot_get_ramdisk(argc, argv, images, IH_INITRD_ARCH,
1814 &images->rd_start, &images->rd_end);
1816 puts("Ramdisk image is corrupt or invalid\n");
1820 #if defined(CONFIG_OF_LIBFDT)
1821 /* find flattened device tree */
1822 ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, images,
1823 &images->ft_addr, &images->ft_len);
1825 puts("Could not find a valid device tree\n");
1829 set_working_fdt_addr(images->ft_addr);
1835 static int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1837 bootm_headers_t images;
1839 if (bootz_start(cmdtp, flag, argc, argv, &images))
1843 * We have reached the point of no return: we are going to
1844 * overwrite all exception vector code, so we cannot easily
1845 * recover from any failures any more...
1847 disable_interrupts();
1849 #ifdef CONFIG_NETCONSOLE
1850 /* Stop the ethernet stack if NetConsole could have left it up */
1854 #if defined(CONFIG_CMD_USB)
1856 * turn off USB to prevent the host controller from writing to the
1857 * SDRAM while Linux is booting. This could happen (at least for OHCI
1858 * controller), because the HCCA (Host Controller Communication Area)
1859 * lies within the SDRAM and the host controller writes continously to
1860 * this area (as busmaster!). The HccaFrameNumber is for example
1861 * updated every 1 ms within the HCCA structure in SDRAM! For more
1862 * details see the OpenHCI specification.
1867 #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
1868 fixup_silent_linux();
1872 do_bootm_linux(0, argc, argv, &images);
1874 puts("\n## Control returned to monitor - resetting...\n");
1876 do_reset(cmdtp, flag, argc, argv);
1881 #ifdef CONFIG_SYS_LONGHELP
1882 static char bootz_help_text[] =
1883 "[addr [initrd[:size]] [fdt]]\n"
1884 " - boot Linux zImage stored in memory\n"
1885 "\tThe argument 'initrd' is optional and specifies the address\n"
1886 "\tof the initrd in memory. The optional argument ':size' allows\n"
1887 "\tspecifying the size of RAW initrd.\n"
1888 #if defined(CONFIG_OF_LIBFDT)
1889 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
1890 "\ta third argument is required which is the address of the\n"
1891 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1892 "\tuse a '-' for the second argument. If you do not pass a third\n"
1893 "\ta bd_info struct will be passed instead\n"
1899 bootz, CONFIG_SYS_MAXARGS, 1, do_bootz,
1900 "boot Linux zImage image from memory", bootz_help_text
1902 #endif /* CONFIG_CMD_BOOTZ */