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 #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
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_BOOTM_PLAN9)
132 static boot_os_fn do_bootm_plan9;
134 #if defined(CONFIG_CMD_ELF)
135 static boot_os_fn do_bootm_vxworks;
136 static boot_os_fn do_bootm_qnxelf;
137 int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
138 int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
140 #if defined(CONFIG_INTEGRITY)
141 static boot_os_fn do_bootm_integrity;
144 static boot_os_fn *boot_os[] = {
145 #ifdef CONFIG_BOOTM_LINUX
146 [IH_OS_LINUX] = do_bootm_linux,
148 #ifdef CONFIG_BOOTM_NETBSD
149 [IH_OS_NETBSD] = do_bootm_netbsd,
151 #ifdef CONFIG_LYNXKDI
152 [IH_OS_LYNXOS] = do_bootm_lynxkdi,
154 #ifdef CONFIG_BOOTM_RTEMS
155 [IH_OS_RTEMS] = do_bootm_rtems,
157 #if defined(CONFIG_BOOTM_OSE)
158 [IH_OS_OSE] = do_bootm_ose,
160 #if defined(CONFIG_BOOTM_PLAN9)
161 [IH_OS_PLAN9] = do_bootm_plan9,
163 #if defined(CONFIG_CMD_ELF)
164 [IH_OS_VXWORKS] = do_bootm_vxworks,
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[])
209 memset((void *)&images, 0, sizeof(images));
210 images.verify = getenv_yesno("verify");
212 boot_start_lmb(&images);
214 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_START, "bootm_start");
216 /* get kernel image header, start address and length */
217 os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
218 &images, &images.os.image_start, &images.os.image_len);
219 if (images.os.image_len == 0) {
220 puts("ERROR: can't get kernel image!\n");
224 /* get image parameters */
225 switch (genimg_get_format(os_hdr)) {
226 case IMAGE_FORMAT_LEGACY:
227 images.os.type = image_get_type(os_hdr);
228 images.os.comp = image_get_comp(os_hdr);
229 images.os.os = image_get_os(os_hdr);
231 images.os.end = image_get_image_end(os_hdr);
232 images.os.load = image_get_load(os_hdr);
234 #if defined(CONFIG_FIT)
235 case IMAGE_FORMAT_FIT:
236 if (fit_image_get_type(images.fit_hdr_os,
237 images.fit_noffset_os, &images.os.type)) {
238 puts("Can't get image type!\n");
239 bootstage_error(BOOTSTAGE_ID_FIT_TYPE);
243 if (fit_image_get_comp(images.fit_hdr_os,
244 images.fit_noffset_os, &images.os.comp)) {
245 puts("Can't get image compression!\n");
246 bootstage_error(BOOTSTAGE_ID_FIT_COMPRESSION);
250 if (fit_image_get_os(images.fit_hdr_os,
251 images.fit_noffset_os, &images.os.os)) {
252 puts("Can't get image OS!\n");
253 bootstage_error(BOOTSTAGE_ID_FIT_OS);
257 images.os.end = fit_get_end(images.fit_hdr_os);
259 if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os,
261 puts("Can't get image load address!\n");
262 bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR);
268 puts("ERROR: unknown image format type!\n");
272 /* find kernel entry point */
273 if (images.legacy_hdr_valid) {
274 images.ep = image_get_ep(&images.legacy_hdr_os_copy);
275 #if defined(CONFIG_FIT)
276 } else if (images.fit_uname_os) {
277 ret = fit_image_get_entry(images.fit_hdr_os,
278 images.fit_noffset_os, &images.ep);
280 puts("Can't get entry point property!\n");
285 puts("Could not find kernel entry point!\n");
289 if (images.os.type == IH_TYPE_KERNEL_NOLOAD) {
290 images.os.load = images.os.image_start;
291 images.ep += images.os.load;
294 if (((images.os.type == IH_TYPE_KERNEL) ||
295 (images.os.type == IH_TYPE_KERNEL_NOLOAD) ||
296 (images.os.type == IH_TYPE_MULTI)) &&
297 (images.os.os == IH_OS_LINUX)) {
299 ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH,
300 &images.rd_start, &images.rd_end);
302 puts("Ramdisk image is corrupt or invalid\n");
306 #if defined(CONFIG_OF_LIBFDT)
307 /* find flattened device tree */
308 ret = boot_get_fdt(flag, argc, argv, &images,
309 &images.ft_addr, &images.ft_len);
311 puts("Could not find a valid device tree\n");
315 set_working_fdt_addr(images.ft_addr);
319 images.os.start = (ulong)os_hdr;
320 images.state = BOOTM_STATE_START;
325 #define BOOTM_ERR_RESET -1
326 #define BOOTM_ERR_OVERLAP -2
327 #define BOOTM_ERR_UNIMPLEMENTED -3
328 static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
330 uint8_t comp = os.comp;
331 ulong load = os.load;
332 ulong blob_start = os.start;
333 ulong blob_end = os.end;
334 ulong image_start = os.image_start;
335 ulong image_len = os.image_len;
336 __maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN;
338 #if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
340 #endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
342 const char *type_name = genimg_get_type_name(os.type);
346 if (load == blob_start || load == image_start) {
347 printf(" XIP %s ... ", type_name);
350 printf(" Loading %s ... ", type_name);
351 memmove_wd((void *)load, (void *)image_start,
354 *load_end = load + image_len;
359 printf(" Uncompressing %s ... ", type_name);
360 if (gunzip((void *)load, unc_len,
361 (uchar *)image_start, &image_len) != 0) {
362 puts("GUNZIP: uncompress, out-of-mem or overwrite "
363 "error - must RESET board to recover\n");
365 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
366 return BOOTM_ERR_RESET;
369 *load_end = load + image_len;
371 #endif /* CONFIG_GZIP */
374 printf(" Uncompressing %s ... ", type_name);
376 * If we've got less than 4 MB of malloc() space,
377 * use slower decompression algorithm which requires
378 * at most 2300 KB of memory.
380 int i = BZ2_bzBuffToBuffDecompress((char *)load,
381 &unc_len, (char *)image_start, image_len,
382 CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
384 printf("BUNZIP2: uncompress or overwrite error %d "
385 "- must RESET board to recover\n", i);
387 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
388 return BOOTM_ERR_RESET;
391 *load_end = load + unc_len;
393 #endif /* CONFIG_BZIP2 */
396 SizeT lzma_len = unc_len;
397 printf(" Uncompressing %s ... ", type_name);
399 ret = lzmaBuffToBuffDecompress(
400 (unsigned char *)load, &lzma_len,
401 (unsigned char *)image_start, image_len);
404 printf("LZMA: uncompress or overwrite error %d "
405 "- must RESET board to recover\n", ret);
406 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
407 return BOOTM_ERR_RESET;
409 *load_end = load + unc_len;
412 #endif /* CONFIG_LZMA */
415 printf(" Uncompressing %s ... ", type_name);
417 ret = lzop_decompress((const unsigned char *)image_start,
418 image_len, (unsigned char *)load,
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_check_hashes(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 void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
859 char * const argv[], bootm_headers_t *images, ulong *os_data,
864 #if defined(CONFIG_FIT)
866 const char *fit_uname_config = NULL;
867 const char *fit_uname_kernel = NULL;
874 /* find out kernel image address */
876 img_addr = load_addr;
877 debug("* kernel: default image load address = 0x%08lx\n",
879 #if defined(CONFIG_FIT)
880 } else if (fit_parse_conf(argv[1], load_addr, &img_addr,
881 &fit_uname_config)) {
882 debug("* kernel: config '%s' from image at 0x%08lx\n",
883 fit_uname_config, img_addr);
884 } else if (fit_parse_subimage(argv[1], load_addr, &img_addr,
885 &fit_uname_kernel)) {
886 debug("* kernel: subimage '%s' from image at 0x%08lx\n",
887 fit_uname_kernel, img_addr);
890 img_addr = simple_strtoul(argv[1], NULL, 16);
891 debug("* kernel: cmdline image address = 0x%08lx\n", img_addr);
894 bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC);
896 /* copy from dataflash if needed */
897 img_addr = genimg_get_image(img_addr);
899 /* check image type, for FIT images get FIT kernel node */
900 *os_data = *os_len = 0;
901 switch (genimg_get_format((void *)img_addr)) {
902 case IMAGE_FORMAT_LEGACY:
903 printf("## Booting kernel from Legacy Image at %08lx ...\n",
905 hdr = image_get_kernel(img_addr, images->verify);
908 bootstage_mark(BOOTSTAGE_ID_CHECK_IMAGETYPE);
910 /* get os_data and os_len */
911 switch (image_get_type(hdr)) {
913 case IH_TYPE_KERNEL_NOLOAD:
914 *os_data = image_get_data(hdr);
915 *os_len = image_get_data_size(hdr);
918 image_multi_getimg(hdr, 0, os_data, os_len);
920 case IH_TYPE_STANDALONE:
921 *os_data = image_get_data(hdr);
922 *os_len = image_get_data_size(hdr);
925 printf("Wrong Image Type for %s command\n",
927 bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE);
932 * copy image header to allow for image overwrites during
933 * kernel decompression.
935 memmove(&images->legacy_hdr_os_copy, hdr,
936 sizeof(image_header_t));
938 /* save pointer to image header */
939 images->legacy_hdr_os = hdr;
941 images->legacy_hdr_valid = 1;
942 bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE);
944 #if defined(CONFIG_FIT)
945 case IMAGE_FORMAT_FIT:
946 fit_hdr = (void *)img_addr;
947 printf("## Booting kernel from FIT Image at %08lx ...\n",
950 if (!fit_check_format(fit_hdr)) {
951 puts("Bad FIT kernel image format!\n");
952 bootstage_error(BOOTSTAGE_ID_FIT_FORMAT);
955 bootstage_mark(BOOTSTAGE_ID_FIT_FORMAT);
957 if (!fit_uname_kernel) {
959 * no kernel image node unit name, try to get config
960 * node first. If config unit node name is NULL
961 * fit_conf_get_node() will try to find default config
964 bootstage_mark(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
965 #ifdef CONFIG_FIT_BEST_MATCH
966 if (fit_uname_config)
968 fit_conf_get_node(fit_hdr,
972 fit_conf_find_compat(fit_hdr,
975 cfg_noffset = fit_conf_get_node(fit_hdr,
978 if (cfg_noffset < 0) {
979 bootstage_error(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
982 /* save configuration uname provided in the first
985 images->fit_uname_cfg = fdt_get_name(fit_hdr,
988 printf(" Using '%s' configuration\n",
989 images->fit_uname_cfg);
990 bootstage_mark(BOOTSTAGE_ID_FIT_CONFIG);
992 os_noffset = fit_conf_get_kernel_node(fit_hdr,
994 fit_uname_kernel = fit_get_name(fit_hdr, os_noffset,
997 /* get kernel component image node offset */
998 bootstage_mark(BOOTSTAGE_ID_FIT_UNIT_NAME);
999 os_noffset = fit_image_get_node(fit_hdr,
1002 if (os_noffset < 0) {
1003 bootstage_error(BOOTSTAGE_ID_FIT_CONFIG);
1007 printf(" Trying '%s' kernel subimage\n", fit_uname_kernel);
1009 bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_SUBIMAGE);
1010 if (!fit_check_kernel(fit_hdr, os_noffset, images->verify))
1013 /* get kernel image data address and length */
1014 if (fit_image_get_data(fit_hdr, os_noffset, &data, &len)) {
1015 puts("Could not find kernel subimage data!\n");
1016 bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO_ERR);
1019 bootstage_mark(BOOTSTAGE_ID_FIT_KERNEL_INFO);
1022 *os_data = (ulong)data;
1023 images->fit_hdr_os = fit_hdr;
1024 images->fit_uname_os = fit_uname_kernel;
1025 images->fit_noffset_os = os_noffset;
1029 printf("Wrong Image Format for %s command\n", cmdtp->name);
1030 bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO);
1034 debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
1035 *os_data, *os_len, *os_len);
1037 return (void *)img_addr;
1040 #ifdef CONFIG_SYS_LONGHELP
1041 static char bootm_help_text[] =
1042 "[addr [arg ...]]\n - boot application image stored in memory\n"
1043 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
1044 "\t'arg' can be the address of an initrd image\n"
1045 #if defined(CONFIG_OF_LIBFDT)
1046 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
1047 "\ta third argument is required which is the address of the\n"
1048 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1049 "\tuse a '-' for the second argument. If you do not pass a third\n"
1050 "\ta bd_info struct will be passed instead\n"
1052 #if defined(CONFIG_FIT)
1053 "\t\nFor the new multi component uImage format (FIT) addresses\n"
1054 "\tmust be extened to include component or configuration unit name:\n"
1055 "\taddr:<subimg_uname> - direct component image specification\n"
1056 "\taddr#<conf_uname> - configuration specification\n"
1057 "\tUse iminfo command to get the list of existing component\n"
1058 "\timages and configurations.\n"
1060 "\nSub-commands to do part of the bootm sequence. The sub-commands "
1062 "issued in the order below (it's ok to not issue all sub-commands):\n"
1063 "\tstart [addr [arg ...]]\n"
1064 "\tloados - load OS image\n"
1065 #if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH)
1066 "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
1068 #if defined(CONFIG_OF_LIBFDT)
1069 "\tfdt - relocate flat device tree\n"
1071 "\tcmdline - OS specific command line processing/setup\n"
1072 "\tbdt - OS specific bd_t processing\n"
1073 "\tprep - OS specific prep before relocation or go\n"
1078 bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
1079 "boot application image from memory", bootm_help_text
1082 /*******************************************************************/
1083 /* bootd - boot default image */
1084 /*******************************************************************/
1085 #if defined(CONFIG_CMD_BOOTD)
1086 int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1090 if (run_command(getenv("bootcmd"), flag) < 0)
1096 boot, 1, 1, do_bootd,
1097 "boot default, i.e., run 'bootcmd'",
1101 /* keep old command name "bootd" for backward compatibility */
1103 bootd, 1, 1, do_bootd,
1104 "boot default, i.e., run 'bootcmd'",
1111 /*******************************************************************/
1112 /* iminfo - print header info for a requested image */
1113 /*******************************************************************/
1114 #if defined(CONFIG_CMD_IMI)
1115 static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1122 return image_info(load_addr);
1125 for (arg = 1; arg < argc; ++arg) {
1126 addr = simple_strtoul(argv[arg], NULL, 16);
1127 if (image_info(addr) != 0)
1133 static int image_info(ulong addr)
1135 void *hdr = (void *)addr;
1137 printf("\n## Checking Image at %08lx ...\n", addr);
1139 switch (genimg_get_format(hdr)) {
1140 case IMAGE_FORMAT_LEGACY:
1141 puts(" Legacy image found\n");
1142 if (!image_check_magic(hdr)) {
1143 puts(" Bad Magic Number\n");
1147 if (!image_check_hcrc(hdr)) {
1148 puts(" Bad Header Checksum\n");
1152 image_print_contents(hdr);
1154 puts(" Verifying Checksum ... ");
1155 if (!image_check_dcrc(hdr)) {
1156 puts(" Bad Data CRC\n");
1161 #if defined(CONFIG_FIT)
1162 case IMAGE_FORMAT_FIT:
1163 puts(" FIT image found\n");
1165 if (!fit_check_format(hdr)) {
1166 puts("Bad FIT image format!\n");
1170 fit_print_contents(hdr);
1172 if (!fit_all_image_check_hashes(hdr)) {
1173 puts("Bad hash in FIT image!\n");
1180 puts("Unknown image format!\n");
1188 iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
1189 "print header information for application image",
1191 " - print header information for application image starting at\n"
1192 " address 'addr' in memory; this includes verification of the\n"
1193 " image contents (magic number, header and payload checksums)"
1198 /*******************************************************************/
1199 /* imls - list all images found in flash */
1200 /*******************************************************************/
1201 #if defined(CONFIG_CMD_IMLS)
1202 static int do_imls_nor(void)
1208 for (i = 0, info = &flash_info[0];
1209 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
1211 if (info->flash_id == FLASH_UNKNOWN)
1213 for (j = 0; j < info->sector_count; ++j) {
1215 hdr = (void *)info->start[j];
1219 switch (genimg_get_format(hdr)) {
1220 case IMAGE_FORMAT_LEGACY:
1221 if (!image_check_hcrc(hdr))
1224 printf("Legacy Image at %08lX:\n", (ulong)hdr);
1225 image_print_contents(hdr);
1227 puts(" Verifying Checksum ... ");
1228 if (!image_check_dcrc(hdr)) {
1229 puts("Bad Data CRC\n");
1234 #if defined(CONFIG_FIT)
1235 case IMAGE_FORMAT_FIT:
1236 if (!fit_check_format(hdr))
1239 printf("FIT Image at %08lX:\n", (ulong)hdr);
1240 fit_print_contents(hdr);
1255 #if defined(CONFIG_CMD_IMLS_NAND)
1256 static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off,
1262 imgdata = malloc(len);
1264 printf("May be a Legacy Image at NAND device %d offset %08llX:\n",
1266 printf(" Low memory(cannot allocate memory for image)\n");
1270 ret = nand_read_skip_bad(nand, off, &len,
1272 if (ret < 0 && ret != -EUCLEAN) {
1277 if (!image_check_hcrc(imgdata)) {
1282 printf("Legacy Image at NAND device %d offset %08llX:\n",
1284 image_print_contents(imgdata);
1286 puts(" Verifying Checksum ... ");
1287 if (!image_check_dcrc(imgdata))
1288 puts("Bad Data CRC\n");
1297 static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off,
1303 imgdata = malloc(len);
1305 printf("May be a FIT Image at NAND device %d offset %08llX:\n",
1307 printf(" Low memory(cannot allocate memory for image)\n");
1311 ret = nand_read_skip_bad(nand, off, &len,
1313 if (ret < 0 && ret != -EUCLEAN) {
1318 if (!fit_check_format(imgdata)) {
1323 printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off);
1325 fit_print_contents(imgdata);
1331 static int do_imls_nand(void)
1334 int nand_dev = nand_curr_device;
1339 if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) {
1340 puts("\nNo NAND devices available\n");
1346 for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) {
1347 nand = &nand_info[nand_dev];
1348 if (!nand->name || !nand->size)
1351 for (off = 0; off < nand->size; off += nand->erasesize) {
1352 const image_header_t *header;
1355 if (nand_block_isbad(nand, off))
1358 len = sizeof(buffer);
1360 ret = nand_read(nand, off, &len, (u8 *)buffer);
1361 if (ret < 0 && ret != -EUCLEAN) {
1362 printf("NAND read error %d at offset %08llX\n",
1367 switch (genimg_get_format(buffer)) {
1368 case IMAGE_FORMAT_LEGACY:
1369 header = (const image_header_t *)buffer;
1371 len = image_get_image_size(header);
1372 nand_imls_legacyimage(nand, nand_dev, off, len);
1374 #if defined(CONFIG_FIT)
1375 case IMAGE_FORMAT_FIT:
1376 len = fit_get_size(buffer);
1377 nand_imls_fitimage(nand, nand_dev, off, len);
1388 #if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
1389 static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1391 int ret_nor = 0, ret_nand = 0;
1393 #if defined(CONFIG_CMD_IMLS)
1394 ret_nor = do_imls_nor();
1397 #if defined(CONFIG_CMD_IMLS_NAND)
1398 ret_nand = do_imls_nand();
1411 imls, 1, 1, do_imls,
1412 "list all images found in flash",
1414 " - Prints information about all images found at sector/block\n"
1415 " boundaries in nor/nand flash."
1419 /*******************************************************************/
1420 /* helper routines */
1421 /*******************************************************************/
1422 #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
1423 static void fixup_silent_linux(void)
1425 char buf[256], *start, *end;
1426 char *cmdline = getenv("bootargs");
1428 /* Only fix cmdline when requested */
1429 if (!(gd->flags & GD_FLG_SILENT))
1432 debug("before silent fix-up: %s\n", cmdline);
1434 start = strstr(cmdline, "console=");
1436 end = strchr(start, ' ');
1437 strncpy(buf, cmdline, (start - cmdline + 8));
1439 strcpy(buf + (start - cmdline + 8), end);
1441 buf[start - cmdline + 8] = '\0';
1443 strcpy(buf, cmdline);
1444 strcat(buf, " console=");
1447 strcpy(buf, "console=");
1450 setenv("bootargs", buf);
1451 debug("after silent fix-up: %s\n", buf);
1453 #endif /* CONFIG_SILENT_CONSOLE */
1456 /*******************************************************************/
1457 /* OS booting routines */
1458 /*******************************************************************/
1460 #ifdef CONFIG_BOOTM_NETBSD
1461 static int do_bootm_netbsd(int flag, int argc, char * const argv[],
1462 bootm_headers_t *images)
1464 void (*loader)(bd_t *, image_header_t *, char *, char *);
1465 image_header_t *os_hdr, *hdr;
1466 ulong kernel_data, kernel_len;
1470 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1473 #if defined(CONFIG_FIT)
1474 if (!images->legacy_hdr_valid) {
1475 fit_unsupported_reset("NetBSD");
1479 hdr = images->legacy_hdr_os;
1482 * Booting a (NetBSD) kernel image
1484 * This process is pretty similar to a standalone application:
1485 * The (first part of an multi-) image must be a stage-2 loader,
1486 * which in turn is responsible for loading & invoking the actual
1487 * kernel. The only differences are the parameters being passed:
1488 * besides the board info strucure, the loader expects a command
1489 * line, the name of the console device, and (optionally) the
1490 * address of the original image header.
1493 if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1494 image_multi_getimg(hdr, 1, &kernel_data, &kernel_len);
1500 #if defined(CONFIG_8xx_CONS_SMC1)
1502 #elif defined(CONFIG_8xx_CONS_SMC2)
1504 #elif defined(CONFIG_8xx_CONS_SCC2)
1506 #elif defined(CONFIG_8xx_CONS_SCC3)
1514 for (i = 2, len = 0; i < argc; i += 1)
1515 len += strlen(argv[i]) + 1;
1516 cmdline = malloc(len);
1518 for (i = 2, len = 0; i < argc; i += 1) {
1520 cmdline[len++] = ' ';
1521 strcpy(&cmdline[len], argv[i]);
1522 len += strlen(argv[i]);
1524 } else if ((cmdline = getenv("bootargs")) == NULL) {
1528 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
1530 printf("## Transferring control to NetBSD stage-2 loader "
1531 "(at address %08lx) ...\n",
1534 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1537 * NetBSD Stage-2 Loader Parameters:
1538 * r3: ptr to board info data
1540 * r5: console device
1541 * r6: boot args string
1543 (*loader)(gd->bd, os_hdr, consdev, cmdline);
1547 #endif /* CONFIG_BOOTM_NETBSD*/
1549 #ifdef CONFIG_LYNXKDI
1550 static int do_bootm_lynxkdi(int flag, int argc, char * const argv[],
1551 bootm_headers_t *images)
1553 image_header_t *hdr = &images->legacy_hdr_os_copy;
1555 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1558 #if defined(CONFIG_FIT)
1559 if (!images->legacy_hdr_valid) {
1560 fit_unsupported_reset("Lynx");
1565 lynxkdi_boot((image_header_t *)hdr);
1569 #endif /* CONFIG_LYNXKDI */
1571 #ifdef CONFIG_BOOTM_RTEMS
1572 static int do_bootm_rtems(int flag, int argc, char * const argv[],
1573 bootm_headers_t *images)
1575 void (*entry_point)(bd_t *);
1577 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1580 #if defined(CONFIG_FIT)
1581 if (!images->legacy_hdr_valid) {
1582 fit_unsupported_reset("RTEMS");
1587 entry_point = (void (*)(bd_t *))images->ep;
1589 printf("## Transferring control to RTEMS (at address %08lx) ...\n",
1590 (ulong)entry_point);
1592 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1596 * r3: ptr to board info data
1598 (*entry_point)(gd->bd);
1602 #endif /* CONFIG_BOOTM_RTEMS */
1604 #if defined(CONFIG_BOOTM_OSE)
1605 static int do_bootm_ose(int flag, int argc, char * const argv[],
1606 bootm_headers_t *images)
1608 void (*entry_point)(void);
1610 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1613 #if defined(CONFIG_FIT)
1614 if (!images->legacy_hdr_valid) {
1615 fit_unsupported_reset("OSE");
1620 entry_point = (void (*)(void))images->ep;
1622 printf("## Transferring control to OSE (at address %08lx) ...\n",
1623 (ulong)entry_point);
1625 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1635 #endif /* CONFIG_BOOTM_OSE */
1637 #if defined(CONFIG_BOOTM_PLAN9)
1638 static int do_bootm_plan9(int flag, int argc, char * const argv[],
1639 bootm_headers_t *images)
1641 void (*entry_point)(void);
1643 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1646 #if defined(CONFIG_FIT)
1647 if (!images->legacy_hdr_valid) {
1648 fit_unsupported_reset("Plan 9");
1653 entry_point = (void (*)(void))images->ep;
1655 printf("## Transferring control to Plan 9 (at address %08lx) ...\n",
1656 (ulong)entry_point);
1658 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1661 * Plan 9 Parameters:
1668 #endif /* CONFIG_BOOTM_PLAN9 */
1670 #if defined(CONFIG_CMD_ELF)
1671 static int do_bootm_vxworks(int flag, int argc, char * const argv[],
1672 bootm_headers_t *images)
1676 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1679 #if defined(CONFIG_FIT)
1680 if (!images->legacy_hdr_valid) {
1681 fit_unsupported_reset("VxWorks");
1686 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1687 setenv("loadaddr", str);
1688 do_bootvx(NULL, 0, 0, NULL);
1693 static int do_bootm_qnxelf(int flag, int argc, char * const argv[],
1694 bootm_headers_t *images)
1696 char *local_args[2];
1699 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1702 #if defined(CONFIG_FIT)
1703 if (!images->legacy_hdr_valid) {
1704 fit_unsupported_reset("QNX");
1709 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1710 local_args[0] = argv[0];
1711 local_args[1] = str; /* and provide it via the arguments */
1712 do_bootelf(NULL, 0, 2, local_args);
1718 #ifdef CONFIG_INTEGRITY
1719 static int do_bootm_integrity(int flag, int argc, char * const argv[],
1720 bootm_headers_t *images)
1722 void (*entry_point)(void);
1724 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1727 #if defined(CONFIG_FIT)
1728 if (!images->legacy_hdr_valid) {
1729 fit_unsupported_reset("INTEGRITY");
1734 entry_point = (void (*)(void))images->ep;
1736 printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
1737 (ulong)entry_point);
1739 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1742 * INTEGRITY Parameters:
1751 #ifdef CONFIG_CMD_BOOTZ
1753 static int __bootz_setup(void *image, void **start, void **end)
1755 /* Please define bootz_setup() for your platform */
1757 puts("Your platform's zImage format isn't supported yet!\n");
1760 int bootz_setup(void *image, void **start, void **end)
1761 __attribute__((weak, alias("__bootz_setup")));
1764 * zImage booting support
1766 static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
1767 char * const argv[], bootm_headers_t *images)
1770 void *zi_start, *zi_end;
1772 memset(images, 0, sizeof(bootm_headers_t));
1774 boot_start_lmb(images);
1776 /* Setup Linux kernel zImage entry point */
1778 images->ep = load_addr;
1779 debug("* kernel: default image load address = 0x%08lx\n",
1782 images->ep = simple_strtoul(argv[1], NULL, 16);
1783 debug("* kernel: cmdline image address = 0x%08lx\n",
1787 ret = bootz_setup((void *)images->ep, &zi_start, &zi_end);
1791 lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
1794 ret = boot_get_ramdisk(argc, argv, images, IH_INITRD_ARCH,
1795 &images->rd_start, &images->rd_end);
1797 puts("Ramdisk image is corrupt or invalid\n");
1801 #if defined(CONFIG_OF_LIBFDT)
1802 /* find flattened device tree */
1803 ret = boot_get_fdt(flag, argc, argv, images,
1804 &images->ft_addr, &images->ft_len);
1806 puts("Could not find a valid device tree\n");
1810 set_working_fdt_addr(images->ft_addr);
1816 static int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1818 bootm_headers_t images;
1820 if (bootz_start(cmdtp, flag, argc, argv, &images))
1824 * We have reached the point of no return: we are going to
1825 * overwrite all exception vector code, so we cannot easily
1826 * recover from any failures any more...
1828 disable_interrupts();
1830 #ifdef CONFIG_NETCONSOLE
1831 /* Stop the ethernet stack if NetConsole could have left it up */
1835 #if defined(CONFIG_CMD_USB)
1837 * turn off USB to prevent the host controller from writing to the
1838 * SDRAM while Linux is booting. This could happen (at least for OHCI
1839 * controller), because the HCCA (Host Controller Communication Area)
1840 * lies within the SDRAM and the host controller writes continously to
1841 * this area (as busmaster!). The HccaFrameNumber is for example
1842 * updated every 1 ms within the HCCA structure in SDRAM! For more
1843 * details see the OpenHCI specification.
1848 #if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
1849 fixup_silent_linux();
1853 do_bootm_linux(0, argc, argv, &images);
1855 puts("\n## Control returned to monitor - resetting...\n");
1857 do_reset(cmdtp, flag, argc, argv);
1862 #ifdef CONFIG_SYS_LONGHELP
1863 static char bootz_help_text[] =
1864 "[addr [initrd[:size]] [fdt]]\n"
1865 " - boot Linux zImage stored in memory\n"
1866 "\tThe argument 'initrd' is optional and specifies the address\n"
1867 "\tof the initrd in memory. The optional argument ':size' allows\n"
1868 "\tspecifying the size of RAW initrd.\n"
1869 #if defined(CONFIG_OF_LIBFDT)
1870 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
1871 "\ta third argument is required which is the address of the\n"
1872 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1873 "\tuse a '-' for the second argument. If you do not pass a third\n"
1874 "\ta bd_info struct will be passed instead\n"
1880 bootz, CONFIG_SYS_MAXARGS, 1, do_bootz,
1881 "boot Linux zImage image from memory", bootz_help_text
1883 #endif /* CONFIG_CMD_BOOTZ */