2 * (C) Copyright 2000-2009
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
33 #include <u-boot/zlib.h>
35 #include <environment.h>
37 #include <linux/ctype.h>
38 #include <asm/byteorder.h>
39 #include <linux/compiler.h>
41 #if defined(CONFIG_CMD_USB)
45 #ifdef CONFIG_SYS_HUSH_PARSER
49 #if defined(CONFIG_OF_LIBFDT)
51 #include <fdt_support.h>
55 #include <lzma/LzmaTypes.h>
56 #include <lzma/LzmaDec.h>
57 #include <lzma/LzmaTools.h>
58 #endif /* CONFIG_LZMA */
61 #include <linux/lzo.h>
62 #endif /* CONFIG_LZO */
64 DECLARE_GLOBAL_DATA_PTR;
66 #ifndef CONFIG_SYS_BOOTM_LEN
67 #define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
71 extern void bz_internal_error(int);
74 #if defined(CONFIG_CMD_IMI)
75 static int image_info(unsigned long addr);
78 #if defined(CONFIG_CMD_IMLS)
80 #include <mtd/cfi_flash.h>
81 extern flash_info_t flash_info[]; /* info for FLASH chips */
84 #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
85 static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
88 #include <linux/err.h>
91 #ifdef CONFIG_SILENT_CONSOLE
92 static void fixup_silent_linux(void);
95 static image_header_t *image_get_kernel(ulong img_addr, int verify);
96 #if defined(CONFIG_FIT)
97 static int fit_check_kernel(const void *fit, int os_noffset, int verify);
100 static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
101 char * const argv[], bootm_headers_t *images,
102 ulong *os_data, ulong *os_len);
105 * Continue booting an OS image; caller already has:
106 * - copied image header to global variable `header'
107 * - checked header magic number, checksums (both header & image),
108 * - verified image architecture (PPC) and type (KERNEL or MULTI),
109 * - loaded (first part of) image to header load address,
110 * - disabled interrupts.
112 typedef int boot_os_fn(int flag, int argc, char * const argv[],
113 bootm_headers_t *images); /* pointers to os/initrd/fdt */
115 #ifdef CONFIG_BOOTM_LINUX
116 extern boot_os_fn do_bootm_linux;
118 #ifdef CONFIG_BOOTM_NETBSD
119 static boot_os_fn do_bootm_netbsd;
121 #if defined(CONFIG_LYNXKDI)
122 static boot_os_fn do_bootm_lynxkdi;
123 extern void lynxkdi_boot(image_header_t *);
125 #ifdef CONFIG_BOOTM_RTEMS
126 static boot_os_fn do_bootm_rtems;
128 #if defined(CONFIG_BOOTM_OSE)
129 static boot_os_fn do_bootm_ose;
131 #if defined(CONFIG_CMD_ELF)
132 static boot_os_fn do_bootm_vxworks;
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_CMD_ELF)
158 [IH_OS_VXWORKS] = do_bootm_vxworks,
159 [IH_OS_QNX] = do_bootm_qnxelf,
161 #ifdef CONFIG_INTEGRITY
162 [IH_OS_INTEGRITY] = do_bootm_integrity,
166 bootm_headers_t images; /* pointers to os/initrd/fdt images */
168 /* Allow for arch specific config before we boot */
169 static void __arch_preboot_os(void)
171 /* please define platform specific arch_preboot_os() */
173 void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
175 #define IH_INITRD_ARCH IH_ARCH_DEFAULT
178 static void boot_start_lmb(bootm_headers_t *images)
181 phys_size_t mem_size;
183 lmb_init(&images->lmb);
185 mem_start = getenv_bootm_low();
186 mem_size = getenv_bootm_size();
188 lmb_add(&images->lmb, (phys_addr_t)mem_start, mem_size);
190 arch_lmb_reserve(&images->lmb);
191 board_lmb_reserve(&images->lmb);
194 #define lmb_reserve(lmb, base, size)
195 static inline void boot_start_lmb(bootm_headers_t *images) { }
198 static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
203 memset((void *)&images, 0, sizeof(images));
204 images.verify = getenv_yesno("verify");
206 boot_start_lmb(&images);
208 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_START, "bootm_start");
210 /* get kernel image header, start address and length */
211 os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
212 &images, &images.os.image_start, &images.os.image_len);
213 if (images.os.image_len == 0) {
214 puts("ERROR: can't get kernel image!\n");
218 /* get image parameters */
219 switch (genimg_get_format(os_hdr)) {
220 case IMAGE_FORMAT_LEGACY:
221 images.os.type = image_get_type(os_hdr);
222 images.os.comp = image_get_comp(os_hdr);
223 images.os.os = image_get_os(os_hdr);
225 images.os.end = image_get_image_end(os_hdr);
226 images.os.load = image_get_load(os_hdr);
228 #if defined(CONFIG_FIT)
229 case IMAGE_FORMAT_FIT:
230 if (fit_image_get_type(images.fit_hdr_os,
231 images.fit_noffset_os, &images.os.type)) {
232 puts("Can't get image type!\n");
233 bootstage_error(BOOTSTAGE_ID_FIT_TYPE);
237 if (fit_image_get_comp(images.fit_hdr_os,
238 images.fit_noffset_os, &images.os.comp)) {
239 puts("Can't get image compression!\n");
240 bootstage_error(BOOTSTAGE_ID_FIT_COMPRESSION);
244 if (fit_image_get_os(images.fit_hdr_os,
245 images.fit_noffset_os, &images.os.os)) {
246 puts("Can't get image OS!\n");
247 bootstage_error(BOOTSTAGE_ID_FIT_OS);
251 images.os.end = fit_get_end(images.fit_hdr_os);
253 if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os,
255 puts("Can't get image load address!\n");
256 bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR);
262 puts("ERROR: unknown image format type!\n");
266 /* find kernel entry point */
267 if (images.legacy_hdr_valid) {
268 images.ep = image_get_ep(&images.legacy_hdr_os_copy);
269 #if defined(CONFIG_FIT)
270 } else if (images.fit_uname_os) {
271 ret = fit_image_get_entry(images.fit_hdr_os,
272 images.fit_noffset_os, &images.ep);
274 puts("Can't get entry point property!\n");
279 puts("Could not find kernel entry point!\n");
283 if (images.os.type == IH_TYPE_KERNEL_NOLOAD) {
284 images.os.load = images.os.image_start;
285 images.ep += images.os.load;
288 if (((images.os.type == IH_TYPE_KERNEL) ||
289 (images.os.type == IH_TYPE_KERNEL_NOLOAD) ||
290 (images.os.type == IH_TYPE_MULTI)) &&
291 (images.os.os == IH_OS_LINUX)) {
293 ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH,
294 &images.rd_start, &images.rd_end);
296 puts("Ramdisk image is corrupt or invalid\n");
300 #if defined(CONFIG_OF_LIBFDT)
301 /* find flattened device tree */
302 ret = boot_get_fdt(flag, argc, argv, &images,
303 &images.ft_addr, &images.ft_len);
305 puts("Could not find a valid device tree\n");
309 set_working_fdt_addr(images.ft_addr);
313 images.os.start = (ulong)os_hdr;
314 images.state = BOOTM_STATE_START;
319 #define BOOTM_ERR_RESET -1
320 #define BOOTM_ERR_OVERLAP -2
321 #define BOOTM_ERR_UNIMPLEMENTED -3
322 static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
324 uint8_t comp = os.comp;
325 ulong load = os.load;
326 ulong blob_start = os.start;
327 ulong blob_end = os.end;
328 ulong image_start = os.image_start;
329 ulong image_len = os.image_len;
330 __maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN;
332 #if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
334 #endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
336 const char *type_name = genimg_get_type_name(os.type);
340 if (load == blob_start || load == image_start) {
341 printf(" XIP %s ... ", type_name);
344 printf(" Loading %s ... ", type_name);
345 memmove_wd((void *)load, (void *)image_start,
348 *load_end = load + image_len;
353 printf(" Uncompressing %s ... ", type_name);
354 if (gunzip((void *)load, unc_len,
355 (uchar *)image_start, &image_len) != 0) {
356 puts("GUNZIP: uncompress, out-of-mem or overwrite "
357 "error - must RESET board to recover\n");
359 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
360 return BOOTM_ERR_RESET;
363 *load_end = load + image_len;
365 #endif /* CONFIG_GZIP */
368 printf(" Uncompressing %s ... ", type_name);
370 * If we've got less than 4 MB of malloc() space,
371 * use slower decompression algorithm which requires
372 * at most 2300 KB of memory.
374 int i = BZ2_bzBuffToBuffDecompress((char *)load,
375 &unc_len, (char *)image_start, image_len,
376 CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
378 printf("BUNZIP2: uncompress or overwrite error %d "
379 "- must RESET board to recover\n", i);
381 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
382 return BOOTM_ERR_RESET;
385 *load_end = load + unc_len;
387 #endif /* CONFIG_BZIP2 */
390 SizeT lzma_len = unc_len;
391 printf(" Uncompressing %s ... ", type_name);
393 ret = lzmaBuffToBuffDecompress(
394 (unsigned char *)load, &lzma_len,
395 (unsigned char *)image_start, image_len);
398 printf("LZMA: uncompress or overwrite error %d "
399 "- must RESET board to recover\n", ret);
400 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
401 return BOOTM_ERR_RESET;
403 *load_end = load + unc_len;
406 #endif /* CONFIG_LZMA */
409 printf(" Uncompressing %s ... ", type_name);
411 ret = lzop_decompress((const unsigned char *)image_start,
412 image_len, (unsigned char *)load,
414 if (ret != LZO_E_OK) {
415 printf("LZO: uncompress or overwrite error %d "
416 "- must RESET board to recover\n", ret);
418 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
419 return BOOTM_ERR_RESET;
422 *load_end = load + unc_len;
424 #endif /* CONFIG_LZO */
426 printf("Unimplemented compression type %d\n", comp);
427 return BOOTM_ERR_UNIMPLEMENTED;
430 flush_cache(load, (*load_end - load) * sizeof(ulong));
433 debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
434 bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED);
436 if (!no_overlap && (load < blob_end) && (*load_end > blob_start)) {
437 debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n",
438 blob_start, blob_end);
439 debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load,
442 return BOOTM_ERR_OVERLAP;
448 static int bootm_start_standalone(ulong iflag, int argc, char * const argv[])
451 int (*appl)(int, char * const []);
453 /* Don't start if "autostart" is set to "no" */
454 if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
456 sprintf(buf, "%lX", images.os.image_len);
457 setenv("filesize", buf);
460 appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep);
461 (*appl)(argc-1, &argv[1]);
465 /* we overload the cmd field with our state machine info instead of a
466 * function pointer */
467 static cmd_tbl_t cmd_bootm_sub[] = {
468 U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
469 U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
470 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
471 U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
473 #ifdef CONFIG_OF_LIBFDT
474 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
476 U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
477 U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
478 U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
479 U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
482 static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
490 c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
493 state = (long)c->cmd;
495 /* treat start special since it resets the state machine */
496 if (state == BOOTM_STATE_START) {
499 return bootm_start(cmdtp, flag, argc, argv);
502 /* Unrecognized command */
503 return CMD_RET_USAGE;
506 if (images.state < BOOTM_STATE_START ||
507 images.state >= state) {
508 printf("Trying to execute a command out of order\n");
509 return CMD_RET_USAGE;
512 images.state |= state;
513 boot_fn = boot_os[images.os.os];
517 case BOOTM_STATE_START:
518 /* should never occur */
520 case BOOTM_STATE_LOADOS:
521 ret = bootm_load_os(images.os, &load_end, 0);
525 lmb_reserve(&images.lmb, images.os.load,
526 (load_end - images.os.load));
528 #ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
529 case BOOTM_STATE_RAMDISK:
531 ulong rd_len = images.rd_end - images.rd_start;
534 ret = boot_ramdisk_high(&images.lmb, images.rd_start,
535 rd_len, &images.initrd_start, &images.initrd_end);
539 sprintf(str, "%lx", images.initrd_start);
540 setenv("initrd_start", str);
541 sprintf(str, "%lx", images.initrd_end);
542 setenv("initrd_end", str);
546 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_LMB)
547 case BOOTM_STATE_FDT:
549 boot_fdt_add_mem_rsv_regions(&images.lmb,
551 ret = boot_relocate_fdt(&images.lmb,
552 &images.ft_addr, &images.ft_len);
556 case BOOTM_STATE_OS_CMDLINE:
557 ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, &images);
559 printf("cmdline subcommand not supported\n");
561 case BOOTM_STATE_OS_BD_T:
562 ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, &images);
564 printf("bdt subcommand not supported\n");
566 case BOOTM_STATE_OS_PREP:
567 ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, &images);
569 printf("prep subcommand not supported\n");
571 case BOOTM_STATE_OS_GO:
572 disable_interrupts();
573 #ifdef CONFIG_NETCONSOLE
575 * Stop the ethernet stack if NetConsole could have
581 boot_fn(BOOTM_STATE_OS_GO, argc, argv, &images);
588 /*******************************************************************/
589 /* bootm - boot application image from image in memory */
590 /*******************************************************************/
592 int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
598 #ifdef CONFIG_NEEDS_MANUAL_RELOC
599 static int relocated = 0;
604 /* relocate boot function table */
605 for (i = 0; i < ARRAY_SIZE(boot_os); i++)
606 if (boot_os[i] != NULL)
607 boot_os[i] += gd->reloc_off;
609 /* relocate names of sub-command table */
610 for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++)
611 cmd_bootm_sub[i].name += gd->reloc_off;
617 /* determine if we have a sub command */
621 simple_strtoul(argv[1], &endp, 16);
622 /* endp pointing to NULL means that argv[1] was just a
623 * valid number, pass it along to the normal bootm processing
625 * If endp is ':' or '#' assume a FIT identifier so pass
626 * along for normal processing.
628 * Right now we assume the first arg should never be '-'
630 if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
631 return do_bootm_subcommand(cmdtp, flag, argc, argv);
634 if (bootm_start(cmdtp, flag, argc, argv))
638 * We have reached the point of no return: we are going to
639 * overwrite all exception vector code, so we cannot easily
640 * recover from any failures any more...
642 iflag = disable_interrupts();
644 #ifdef CONFIG_NETCONSOLE
645 /* Stop the ethernet stack if NetConsole could have left it up */
649 #if defined(CONFIG_CMD_USB)
651 * turn off USB to prevent the host controller from writing to the
652 * SDRAM while Linux is booting. This could happen (at least for OHCI
653 * controller), because the HCCA (Host Controller Communication Area)
654 * lies within the SDRAM and the host controller writes continously to
655 * this area (as busmaster!). The HccaFrameNumber is for example
656 * updated every 1 ms within the HCCA structure in SDRAM! For more
657 * details see the OpenHCI specification.
662 ret = bootm_load_os(images.os, &load_end, 1);
665 if (ret == BOOTM_ERR_RESET)
666 do_reset(cmdtp, flag, argc, argv);
667 if (ret == BOOTM_ERR_OVERLAP) {
668 if (images.legacy_hdr_valid) {
670 hdr = &images.legacy_hdr_os_copy;
671 if (image_get_type(hdr) == IH_TYPE_MULTI)
672 puts("WARNING: legacy format multi "
676 puts("ERROR: new format image overwritten - "
677 "must RESET the board to recover\n");
678 bootstage_error(BOOTSTAGE_ID_OVERWRITTEN);
679 do_reset(cmdtp, flag, argc, argv);
682 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
685 bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL);
690 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
692 if (images.os.type == IH_TYPE_STANDALONE) {
695 /* This may return when 'autostart' is 'no' */
696 bootm_start_standalone(iflag, argc, argv);
700 bootstage_mark(BOOTSTAGE_ID_CHECK_BOOT_OS);
702 #ifdef CONFIG_SILENT_CONSOLE
703 if (images.os.os == IH_OS_LINUX)
704 fixup_silent_linux();
707 boot_fn = boot_os[images.os.os];
709 if (boot_fn == NULL) {
712 printf("ERROR: booting os '%s' (%d) is not supported\n",
713 genimg_get_os_name(images.os.os), images.os.os);
714 bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS);
720 boot_fn(0, argc, argv, &images);
722 bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED);
724 puts("\n## Control returned to monitor - resetting...\n");
726 do_reset(cmdtp, flag, argc, argv);
731 int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
733 const char *ep = getenv("autostart");
735 if (ep && !strcmp(ep, "yes")) {
737 local_args[0] = (char *)cmd;
738 local_args[1] = NULL;
739 printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
740 return do_bootm(cmdtp, 0, 1, local_args);
747 * image_get_kernel - verify legacy format kernel image
748 * @img_addr: in RAM address of the legacy format image to be verified
749 * @verify: data CRC verification flag
751 * image_get_kernel() verifies legacy image integrity and returns pointer to
752 * legacy image header if image verification was completed successfully.
755 * pointer to a legacy image header if valid image was found
756 * otherwise return NULL
758 static image_header_t *image_get_kernel(ulong img_addr, int verify)
760 image_header_t *hdr = (image_header_t *)img_addr;
762 if (!image_check_magic(hdr)) {
763 puts("Bad Magic Number\n");
764 bootstage_error(BOOTSTAGE_ID_CHECK_MAGIC);
767 bootstage_mark(BOOTSTAGE_ID_CHECK_HEADER);
769 if (!image_check_hcrc(hdr)) {
770 puts("Bad Header Checksum\n");
771 bootstage_error(BOOTSTAGE_ID_CHECK_HEADER);
775 bootstage_mark(BOOTSTAGE_ID_CHECK_CHECKSUM);
776 image_print_contents(hdr);
779 puts(" Verifying Checksum ... ");
780 if (!image_check_dcrc(hdr)) {
781 printf("Bad Data CRC\n");
782 bootstage_error(BOOTSTAGE_ID_CHECK_CHECKSUM);
787 bootstage_mark(BOOTSTAGE_ID_CHECK_ARCH);
789 if (!image_check_target_arch(hdr)) {
790 printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr));
791 bootstage_error(BOOTSTAGE_ID_CHECK_ARCH);
798 * fit_check_kernel - verify FIT format kernel subimage
799 * @fit_hdr: pointer to the FIT image header
800 * os_noffset: kernel subimage node offset within FIT image
801 * @verify: data CRC verification flag
803 * fit_check_kernel() verifies integrity of the kernel subimage and from
804 * specified FIT image.
810 #if defined(CONFIG_FIT)
811 static int fit_check_kernel(const void *fit, int os_noffset, int verify)
813 fit_image_print(fit, os_noffset, " ");
816 puts(" Verifying Hash Integrity ... ");
817 if (!fit_image_check_hashes(fit, os_noffset)) {
818 puts("Bad Data Hash\n");
819 bootstage_error(BOOTSTAGE_ID_FIT_CHECK_HASH);
824 bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_ARCH);
826 if (!fit_image_check_target_arch(fit, os_noffset)) {
827 puts("Unsupported Architecture\n");
828 bootstage_error(BOOTSTAGE_ID_FIT_CHECK_ARCH);
832 bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_KERNEL);
833 if (!fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL) &&
834 !fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL_NOLOAD)) {
835 puts("Not a kernel image\n");
836 bootstage_error(BOOTSTAGE_ID_FIT_CHECK_KERNEL);
840 bootstage_mark(BOOTSTAGE_ID_FIT_CHECKED);
843 #endif /* CONFIG_FIT */
846 * boot_get_kernel - find kernel image
847 * @os_data: pointer to a ulong variable, will hold os data start address
848 * @os_len: pointer to a ulong variable, will hold os data length
850 * boot_get_kernel() tries to find a kernel image, verifies its integrity
851 * and locates kernel data.
854 * pointer to image header if valid image was found, plus kernel start
855 * address and length, otherwise NULL
857 static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
858 char * const argv[], bootm_headers_t *images, ulong *os_data,
863 #if defined(CONFIG_FIT)
865 const char *fit_uname_config = NULL;
866 const char *fit_uname_kernel = NULL;
873 /* find out kernel image address */
875 img_addr = load_addr;
876 debug("* kernel: default image load address = 0x%08lx\n",
878 #if defined(CONFIG_FIT)
879 } else if (fit_parse_conf(argv[1], load_addr, &img_addr,
880 &fit_uname_config)) {
881 debug("* kernel: config '%s' from image at 0x%08lx\n",
882 fit_uname_config, img_addr);
883 } else if (fit_parse_subimage(argv[1], load_addr, &img_addr,
884 &fit_uname_kernel)) {
885 debug("* kernel: subimage '%s' from image at 0x%08lx\n",
886 fit_uname_kernel, img_addr);
889 img_addr = simple_strtoul(argv[1], NULL, 16);
890 debug("* kernel: cmdline image address = 0x%08lx\n", img_addr);
893 bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC);
895 /* copy from dataflash if needed */
896 img_addr = genimg_get_image(img_addr);
898 /* check image type, for FIT images get FIT kernel node */
899 *os_data = *os_len = 0;
900 switch (genimg_get_format((void *)img_addr)) {
901 case IMAGE_FORMAT_LEGACY:
902 printf("## Booting kernel from Legacy Image at %08lx ...\n",
904 hdr = image_get_kernel(img_addr, images->verify);
907 bootstage_mark(BOOTSTAGE_ID_CHECK_IMAGETYPE);
909 /* get os_data and os_len */
910 switch (image_get_type(hdr)) {
912 case IH_TYPE_KERNEL_NOLOAD:
913 *os_data = image_get_data(hdr);
914 *os_len = image_get_data_size(hdr);
917 image_multi_getimg(hdr, 0, os_data, os_len);
919 case IH_TYPE_STANDALONE:
920 *os_data = image_get_data(hdr);
921 *os_len = image_get_data_size(hdr);
924 printf("Wrong Image Type for %s command\n",
926 bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE);
931 * copy image header to allow for image overwrites during
932 * kernel decompression.
934 memmove(&images->legacy_hdr_os_copy, hdr,
935 sizeof(image_header_t));
937 /* save pointer to image header */
938 images->legacy_hdr_os = hdr;
940 images->legacy_hdr_valid = 1;
941 bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE);
943 #if defined(CONFIG_FIT)
944 case IMAGE_FORMAT_FIT:
945 fit_hdr = (void *)img_addr;
946 printf("## Booting kernel from FIT Image at %08lx ...\n",
949 if (!fit_check_format(fit_hdr)) {
950 puts("Bad FIT kernel image format!\n");
951 bootstage_error(BOOTSTAGE_ID_FIT_FORMAT);
954 bootstage_mark(BOOTSTAGE_ID_FIT_FORMAT);
956 if (!fit_uname_kernel) {
958 * no kernel image node unit name, try to get config
959 * node first. If config unit node name is NULL
960 * fit_conf_get_node() will try to find default config
963 bootstage_mark(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
964 #ifdef CONFIG_FIT_BEST_MATCH
965 if (fit_uname_config)
967 fit_conf_get_node(fit_hdr,
971 fit_conf_find_compat(fit_hdr,
974 cfg_noffset = fit_conf_get_node(fit_hdr,
977 if (cfg_noffset < 0) {
978 bootstage_error(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
981 /* save configuration uname provided in the first
984 images->fit_uname_cfg = fdt_get_name(fit_hdr,
987 printf(" Using '%s' configuration\n",
988 images->fit_uname_cfg);
989 bootstage_mark(BOOTSTAGE_ID_FIT_CONFIG);
991 os_noffset = fit_conf_get_kernel_node(fit_hdr,
993 fit_uname_kernel = fit_get_name(fit_hdr, os_noffset,
996 /* get kernel component image node offset */
997 bootstage_mark(BOOTSTAGE_ID_FIT_UNIT_NAME);
998 os_noffset = fit_image_get_node(fit_hdr,
1001 if (os_noffset < 0) {
1002 bootstage_error(BOOTSTAGE_ID_FIT_CONFIG);
1006 printf(" Trying '%s' kernel subimage\n", fit_uname_kernel);
1008 bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_SUBIMAGE);
1009 if (!fit_check_kernel(fit_hdr, os_noffset, images->verify))
1012 /* get kernel image data address and length */
1013 if (fit_image_get_data(fit_hdr, os_noffset, &data, &len)) {
1014 puts("Could not find kernel subimage data!\n");
1015 bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO_ERR);
1018 bootstage_mark(BOOTSTAGE_ID_FIT_KERNEL_INFO);
1021 *os_data = (ulong)data;
1022 images->fit_hdr_os = fit_hdr;
1023 images->fit_uname_os = fit_uname_kernel;
1024 images->fit_noffset_os = os_noffset;
1028 printf("Wrong Image Format for %s command\n", cmdtp->name);
1029 bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO);
1033 debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
1034 *os_data, *os_len, *os_len);
1036 return (void *)img_addr;
1039 #ifdef CONFIG_SYS_LONGHELP
1040 static char bootm_help_text[] =
1041 "[addr [arg ...]]\n - boot application image stored in memory\n"
1042 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
1043 "\t'arg' can be the address of an initrd image\n"
1044 #if defined(CONFIG_OF_LIBFDT)
1045 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
1046 "\ta third argument is required which is the address of the\n"
1047 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1048 "\tuse a '-' for the second argument. If you do not pass a third\n"
1049 "\ta bd_info struct will be passed instead\n"
1051 #if defined(CONFIG_FIT)
1052 "\t\nFor the new multi component uImage format (FIT) addresses\n"
1053 "\tmust be extened to include component or configuration unit name:\n"
1054 "\taddr:<subimg_uname> - direct component image specification\n"
1055 "\taddr#<conf_uname> - configuration specification\n"
1056 "\tUse iminfo command to get the list of existing component\n"
1057 "\timages and configurations.\n"
1059 "\nSub-commands to do part of the bootm sequence. The sub-commands "
1061 "issued in the order below (it's ok to not issue all sub-commands):\n"
1062 "\tstart [addr [arg ...]]\n"
1063 "\tloados - load OS image\n"
1064 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
1065 "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
1067 #if defined(CONFIG_OF_LIBFDT)
1068 "\tfdt - relocate flat device tree\n"
1070 "\tcmdline - OS specific command line processing/setup\n"
1071 "\tbdt - OS specific bd_t processing\n"
1072 "\tprep - OS specific prep before relocation or go\n"
1077 bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
1078 "boot application image from memory", bootm_help_text
1081 /*******************************************************************/
1082 /* bootd - boot default image */
1083 /*******************************************************************/
1084 #if defined(CONFIG_CMD_BOOTD)
1085 int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1089 if (run_command(getenv("bootcmd"), flag) < 0)
1095 boot, 1, 1, do_bootd,
1096 "boot default, i.e., run 'bootcmd'",
1100 /* keep old command name "bootd" for backward compatibility */
1102 bootd, 1, 1, do_bootd,
1103 "boot default, i.e., run 'bootcmd'",
1110 /*******************************************************************/
1111 /* iminfo - print header info for a requested image */
1112 /*******************************************************************/
1113 #if defined(CONFIG_CMD_IMI)
1114 static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1121 return image_info(load_addr);
1124 for (arg = 1; arg < argc; ++arg) {
1125 addr = simple_strtoul(argv[arg], NULL, 16);
1126 if (image_info(addr) != 0)
1132 static int image_info(ulong addr)
1134 void *hdr = (void *)addr;
1136 printf("\n## Checking Image at %08lx ...\n", addr);
1138 switch (genimg_get_format(hdr)) {
1139 case IMAGE_FORMAT_LEGACY:
1140 puts(" Legacy image found\n");
1141 if (!image_check_magic(hdr)) {
1142 puts(" Bad Magic Number\n");
1146 if (!image_check_hcrc(hdr)) {
1147 puts(" Bad Header Checksum\n");
1151 image_print_contents(hdr);
1153 puts(" Verifying Checksum ... ");
1154 if (!image_check_dcrc(hdr)) {
1155 puts(" Bad Data CRC\n");
1160 #if defined(CONFIG_FIT)
1161 case IMAGE_FORMAT_FIT:
1162 puts(" FIT image found\n");
1164 if (!fit_check_format(hdr)) {
1165 puts("Bad FIT image format!\n");
1169 fit_print_contents(hdr);
1171 if (!fit_all_image_check_hashes(hdr)) {
1172 puts("Bad hash in FIT image!\n");
1179 puts("Unknown image format!\n");
1187 iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
1188 "print header information for application image",
1190 " - print header information for application image starting at\n"
1191 " address 'addr' in memory; this includes verification of the\n"
1192 " image contents (magic number, header and payload checksums)"
1197 /*******************************************************************/
1198 /* imls - list all images found in flash */
1199 /*******************************************************************/
1200 #if defined(CONFIG_CMD_IMLS)
1201 static int do_imls_nor(void)
1207 for (i = 0, info = &flash_info[0];
1208 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
1210 if (info->flash_id == FLASH_UNKNOWN)
1212 for (j = 0; j < info->sector_count; ++j) {
1214 hdr = (void *)info->start[j];
1218 switch (genimg_get_format(hdr)) {
1219 case IMAGE_FORMAT_LEGACY:
1220 if (!image_check_hcrc(hdr))
1223 printf("Legacy Image at %08lX:\n", (ulong)hdr);
1224 image_print_contents(hdr);
1226 puts(" Verifying Checksum ... ");
1227 if (!image_check_dcrc(hdr)) {
1228 puts("Bad Data CRC\n");
1233 #if defined(CONFIG_FIT)
1234 case IMAGE_FORMAT_FIT:
1235 if (!fit_check_format(hdr))
1238 printf("FIT Image at %08lX:\n", (ulong)hdr);
1239 fit_print_contents(hdr);
1254 #if defined(CONFIG_CMD_IMLS_NAND)
1255 static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off,
1261 imgdata = malloc(len);
1263 printf("May be a Legacy Image at NAND device %d offset %08llX:\n",
1265 printf(" Low memory(cannot allocate memory for image)\n");
1269 ret = nand_read_skip_bad(nand, off, &len,
1271 if (ret < 0 && ret != -EUCLEAN) {
1276 if (!image_check_hcrc(imgdata)) {
1281 printf("Legacy Image at NAND device %d offset %08llX:\n",
1283 image_print_contents(imgdata);
1285 puts(" Verifying Checksum ... ");
1286 if (!image_check_dcrc(imgdata))
1287 puts("Bad Data CRC\n");
1296 static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off,
1302 imgdata = malloc(len);
1304 printf("May be a FIT Image at NAND device %d offset %08llX:\n",
1306 printf(" Low memory(cannot allocate memory for image)\n");
1310 ret = nand_read_skip_bad(nand, off, &len,
1312 if (ret < 0 && ret != -EUCLEAN) {
1317 if (!fit_check_format(imgdata)) {
1322 printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off);
1324 fit_print_contents(imgdata);
1330 static int do_imls_nand(void)
1333 int nand_dev = nand_curr_device;
1338 if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) {
1339 puts("\nNo NAND devices available\n");
1345 for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) {
1346 nand = &nand_info[nand_dev];
1347 if (!nand->name || !nand->size)
1350 for (off = 0; off < nand->size; off += nand->erasesize) {
1351 const image_header_t *header;
1354 if (nand_block_isbad(nand, off))
1357 len = sizeof(buffer);
1359 ret = nand_read(nand, off, &len, (u8 *)buffer);
1360 if (ret < 0 && ret != -EUCLEAN) {
1361 printf("NAND read error %d at offset %08llX\n",
1366 switch (genimg_get_format(buffer)) {
1367 case IMAGE_FORMAT_LEGACY:
1368 header = (const image_header_t *)buffer;
1370 len = image_get_image_size(header);
1371 nand_imls_legacyimage(nand, nand_dev, off, len);
1373 #if defined(CONFIG_FIT)
1374 case IMAGE_FORMAT_FIT:
1375 len = fit_get_size(buffer);
1376 nand_imls_fitimage(nand, nand_dev, off, len);
1387 #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
1388 static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1390 int ret_nor = 0, ret_nand = 0;
1392 #if defined(CONFIG_CMD_IMLS)
1393 ret_nor = do_imls_nor();
1396 #if defined(CONFIG_CMD_IMLS_NAND)
1397 ret_nand = do_imls_nand();
1410 imls, 1, 1, do_imls,
1411 "list all images found in flash",
1413 " - Prints information about all images found at sector/block\n"
1414 " boundaries in nor/nand flash."
1418 /*******************************************************************/
1419 /* helper routines */
1420 /*******************************************************************/
1421 #ifdef CONFIG_SILENT_CONSOLE
1422 static void fixup_silent_linux(void)
1424 char buf[256], *start, *end;
1425 char *cmdline = getenv("bootargs");
1427 /* Only fix cmdline when requested */
1428 if (!(gd->flags & GD_FLG_SILENT))
1431 debug("before silent fix-up: %s\n", cmdline);
1433 start = strstr(cmdline, "console=");
1435 end = strchr(start, ' ');
1436 strncpy(buf, cmdline, (start - cmdline + 8));
1438 strcpy(buf + (start - cmdline + 8), end);
1440 buf[start - cmdline + 8] = '\0';
1442 strcpy(buf, cmdline);
1443 strcat(buf, " console=");
1446 strcpy(buf, "console=");
1449 setenv("bootargs", buf);
1450 debug("after silent fix-up: %s\n", buf);
1452 #endif /* CONFIG_SILENT_CONSOLE */
1455 /*******************************************************************/
1456 /* OS booting routines */
1457 /*******************************************************************/
1459 #ifdef CONFIG_BOOTM_NETBSD
1460 static int do_bootm_netbsd(int flag, int argc, char * const argv[],
1461 bootm_headers_t *images)
1463 void (*loader)(bd_t *, image_header_t *, char *, char *);
1464 image_header_t *os_hdr, *hdr;
1465 ulong kernel_data, kernel_len;
1469 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1472 #if defined(CONFIG_FIT)
1473 if (!images->legacy_hdr_valid) {
1474 fit_unsupported_reset("NetBSD");
1478 hdr = images->legacy_hdr_os;
1481 * Booting a (NetBSD) kernel image
1483 * This process is pretty similar to a standalone application:
1484 * The (first part of an multi-) image must be a stage-2 loader,
1485 * which in turn is responsible for loading & invoking the actual
1486 * kernel. The only differences are the parameters being passed:
1487 * besides the board info strucure, the loader expects a command
1488 * line, the name of the console device, and (optionally) the
1489 * address of the original image header.
1492 if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1493 image_multi_getimg(hdr, 1, &kernel_data, &kernel_len);
1499 #if defined(CONFIG_8xx_CONS_SMC1)
1501 #elif defined(CONFIG_8xx_CONS_SMC2)
1503 #elif defined(CONFIG_8xx_CONS_SCC2)
1505 #elif defined(CONFIG_8xx_CONS_SCC3)
1513 for (i = 2, len = 0; i < argc; i += 1)
1514 len += strlen(argv[i]) + 1;
1515 cmdline = malloc(len);
1517 for (i = 2, len = 0; i < argc; i += 1) {
1519 cmdline[len++] = ' ';
1520 strcpy(&cmdline[len], argv[i]);
1521 len += strlen(argv[i]);
1523 } else if ((cmdline = getenv("bootargs")) == NULL) {
1527 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
1529 printf("## Transferring control to NetBSD stage-2 loader "
1530 "(at address %08lx) ...\n",
1533 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1536 * NetBSD Stage-2 Loader Parameters:
1537 * r3: ptr to board info data
1539 * r5: console device
1540 * r6: boot args string
1542 (*loader)(gd->bd, os_hdr, consdev, cmdline);
1546 #endif /* CONFIG_BOOTM_NETBSD*/
1548 #ifdef CONFIG_LYNXKDI
1549 static int do_bootm_lynxkdi(int flag, int argc, char * const argv[],
1550 bootm_headers_t *images)
1552 image_header_t *hdr = &images->legacy_hdr_os_copy;
1554 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1557 #if defined(CONFIG_FIT)
1558 if (!images->legacy_hdr_valid) {
1559 fit_unsupported_reset("Lynx");
1564 lynxkdi_boot((image_header_t *)hdr);
1568 #endif /* CONFIG_LYNXKDI */
1570 #ifdef CONFIG_BOOTM_RTEMS
1571 static int do_bootm_rtems(int flag, int argc, char * const argv[],
1572 bootm_headers_t *images)
1574 void (*entry_point)(bd_t *);
1576 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1579 #if defined(CONFIG_FIT)
1580 if (!images->legacy_hdr_valid) {
1581 fit_unsupported_reset("RTEMS");
1586 entry_point = (void (*)(bd_t *))images->ep;
1588 printf("## Transferring control to RTEMS (at address %08lx) ...\n",
1589 (ulong)entry_point);
1591 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1595 * r3: ptr to board info data
1597 (*entry_point)(gd->bd);
1601 #endif /* CONFIG_BOOTM_RTEMS */
1603 #if defined(CONFIG_BOOTM_OSE)
1604 static int do_bootm_ose(int flag, int argc, char * const argv[],
1605 bootm_headers_t *images)
1607 void (*entry_point)(void);
1609 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1612 #if defined(CONFIG_FIT)
1613 if (!images->legacy_hdr_valid) {
1614 fit_unsupported_reset("OSE");
1619 entry_point = (void (*)(void))images->ep;
1621 printf("## Transferring control to OSE (at address %08lx) ...\n",
1622 (ulong)entry_point);
1624 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1634 #endif /* CONFIG_BOOTM_OSE */
1636 #if defined(CONFIG_CMD_ELF)
1637 static int do_bootm_vxworks(int flag, int argc, char * const argv[],
1638 bootm_headers_t *images)
1642 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1645 #if defined(CONFIG_FIT)
1646 if (!images->legacy_hdr_valid) {
1647 fit_unsupported_reset("VxWorks");
1652 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1653 setenv("loadaddr", str);
1654 do_bootvx(NULL, 0, 0, NULL);
1659 static int do_bootm_qnxelf(int flag, int argc, char * const argv[],
1660 bootm_headers_t *images)
1662 char *local_args[2];
1665 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1668 #if defined(CONFIG_FIT)
1669 if (!images->legacy_hdr_valid) {
1670 fit_unsupported_reset("QNX");
1675 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1676 local_args[0] = argv[0];
1677 local_args[1] = str; /* and provide it via the arguments */
1678 do_bootelf(NULL, 0, 2, local_args);
1684 #ifdef CONFIG_INTEGRITY
1685 static int do_bootm_integrity(int flag, int argc, char * const argv[],
1686 bootm_headers_t *images)
1688 void (*entry_point)(void);
1690 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1693 #if defined(CONFIG_FIT)
1694 if (!images->legacy_hdr_valid) {
1695 fit_unsupported_reset("INTEGRITY");
1700 entry_point = (void (*)(void))images->ep;
1702 printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
1703 (ulong)entry_point);
1705 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1708 * INTEGRITY Parameters:
1717 #ifdef CONFIG_CMD_BOOTZ
1719 static int __bootz_setup(void *image, void **start, void **end)
1721 /* Please define bootz_setup() for your platform */
1723 puts("Your platform's zImage format isn't supported yet!\n");
1726 int bootz_setup(void *image, void **start, void **end)
1727 __attribute__((weak, alias("__bootz_setup")));
1730 * zImage booting support
1732 static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
1733 char * const argv[], bootm_headers_t *images)
1736 void *zi_start, *zi_end;
1738 memset(images, 0, sizeof(bootm_headers_t));
1740 boot_start_lmb(images);
1742 /* Setup Linux kernel zImage entry point */
1744 images->ep = load_addr;
1745 debug("* kernel: default image load address = 0x%08lx\n",
1748 images->ep = simple_strtoul(argv[1], NULL, 16);
1749 debug("* kernel: cmdline image address = 0x%08lx\n",
1753 ret = bootz_setup((void *)images->ep, &zi_start, &zi_end);
1757 lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
1760 ret = boot_get_ramdisk(argc, argv, images, IH_INITRD_ARCH,
1761 &images->rd_start, &images->rd_end);
1763 puts("Ramdisk image is corrupt or invalid\n");
1767 #if defined(CONFIG_OF_LIBFDT)
1768 /* find flattened device tree */
1769 ret = boot_get_fdt(flag, argc, argv, images,
1770 &images->ft_addr, &images->ft_len);
1772 puts("Could not find a valid device tree\n");
1776 set_working_fdt_addr(images->ft_addr);
1782 static int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1784 bootm_headers_t images;
1786 if (bootz_start(cmdtp, flag, argc, argv, &images))
1790 * We have reached the point of no return: we are going to
1791 * overwrite all exception vector code, so we cannot easily
1792 * recover from any failures any more...
1794 disable_interrupts();
1796 #ifdef CONFIG_NETCONSOLE
1797 /* Stop the ethernet stack if NetConsole could have left it up */
1801 #if defined(CONFIG_CMD_USB)
1803 * turn off USB to prevent the host controller from writing to the
1804 * SDRAM while Linux is booting. This could happen (at least for OHCI
1805 * controller), because the HCCA (Host Controller Communication Area)
1806 * lies within the SDRAM and the host controller writes continously to
1807 * this area (as busmaster!). The HccaFrameNumber is for example
1808 * updated every 1 ms within the HCCA structure in SDRAM! For more
1809 * details see the OpenHCI specification.
1814 #ifdef CONFIG_SILENT_CONSOLE
1815 fixup_silent_linux();
1819 do_bootm_linux(0, argc, argv, &images);
1821 puts("\n## Control returned to monitor - resetting...\n");
1823 do_reset(cmdtp, flag, argc, argv);
1828 #ifdef CONFIG_SYS_LONGHELP
1829 static char bootz_help_text[] =
1830 "[addr [initrd[:size]] [fdt]]\n"
1831 " - boot Linux zImage stored in memory\n"
1832 "\tThe argument 'initrd' is optional and specifies the address\n"
1833 "\tof the initrd in memory. The optional argument ':size' allows\n"
1834 "\tspecifying the size of RAW initrd.\n"
1835 #if defined(CONFIG_OF_LIBFDT)
1836 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
1837 "\ta third argument is required which is the address of the\n"
1838 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1839 "\tuse a '-' for the second argument. If you do not pass a third\n"
1840 "\ta bd_info struct will be passed instead\n"
1846 bootz, CONFIG_SYS_MAXARGS, 1, do_bootz,
1847 "boot Linux zImage image from memory", bootz_help_text
1849 #endif /* CONFIG_CMD_BOOTZ */