2 * (C) Copyright 2000-2006
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,
35 #include <environment.h>
37 #include <linux/ctype.h>
38 #include <asm/byteorder.h>
40 #if defined(CONFIG_CMD_USB)
44 #ifdef CONFIG_SYS_HUSH_PARSER
48 #if defined(CONFIG_OF_LIBFDT)
51 #include <fdt_support.h>
55 #define _7ZIP_BYTE_DEFINED /* Byte already defined by zlib */
56 #include <lzma/LzmaTypes.h>
57 #include <lzma/LzmaDecode.h>
58 #include <lzma/LzmaTools.h>
59 #endif /* CONFIG_LZMA */
61 DECLARE_GLOBAL_DATA_PTR;
63 extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
64 #ifndef CONFIG_SYS_BOOTM_LEN
65 #define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
69 extern void bz_internal_error(int);
72 #if defined(CONFIG_CMD_IMI)
73 static int image_info (unsigned long addr);
76 #if defined(CONFIG_CMD_IMLS)
78 extern flash_info_t flash_info[]; /* info for FLASH chips */
79 static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
82 #ifdef CONFIG_SILENT_CONSOLE
83 static void fixup_silent_linux (void);
86 static image_header_t *image_get_kernel (ulong img_addr, int verify);
87 #if defined(CONFIG_FIT)
88 static int fit_check_kernel (const void *fit, int os_noffset, int verify);
91 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
92 bootm_headers_t *images, ulong *os_data, ulong *os_len);
93 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
96 * Continue booting an OS image; caller already has:
97 * - copied image header to global variable `header'
98 * - checked header magic number, checksums (both header & image),
99 * - verified image architecture (PPC) and type (KERNEL or MULTI),
100 * - loaded (first part of) image to header load address,
101 * - disabled interrupts.
103 typedef int boot_os_fn (int flag, int argc, char *argv[],
104 bootm_headers_t *images); /* pointers to os/initrd/fdt */
106 extern boot_os_fn do_bootm_linux;
107 static boot_os_fn do_bootm_netbsd;
108 #if defined(CONFIG_LYNXKDI)
109 static boot_os_fn do_bootm_lynxkdi;
110 extern void lynxkdi_boot (image_header_t *);
112 static boot_os_fn do_bootm_rtems;
113 #if defined(CONFIG_CMD_ELF)
114 static boot_os_fn do_bootm_vxworks;
115 static boot_os_fn do_bootm_qnxelf;
116 int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
117 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
119 #if defined(CONFIG_INTEGRITY)
120 static boot_os_fn do_bootm_integrity;
123 boot_os_fn * boot_os[] = {
124 [IH_OS_LINUX] = do_bootm_linux,
125 [IH_OS_NETBSD] = do_bootm_netbsd,
126 #ifdef CONFIG_LYNXKDI
127 [IH_OS_LYNXOS] = do_bootm_lynxkdi,
129 [IH_OS_RTEMS] = do_bootm_rtems,
130 #if defined(CONFIG_CMD_ELF)
131 [IH_OS_VXWORKS] = do_bootm_vxworks,
132 [IH_OS_QNX] = do_bootm_qnxelf,
134 #ifdef CONFIG_INTEGRITY
135 [IH_OS_INTEGRITY] = do_bootm_integrity,
139 ulong load_addr = CONFIG_SYS_LOAD_ADDR; /* Default Load Address */
140 static bootm_headers_t images; /* pointers to os/initrd/fdt images */
142 void __board_lmb_reserve(struct lmb *lmb)
144 /* please define platform specific board_lmb_reserve() */
146 void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
148 void __arch_lmb_reserve(struct lmb *lmb)
150 /* please define platform specific arch_lmb_reserve() */
152 void arch_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__arch_lmb_reserve")));
155 #define IH_INITRD_ARCH IH_ARCH_ARM
156 #elif defined(__avr32__)
157 #define IH_INITRD_ARCH IH_ARCH_AVR32
158 #elif defined(__bfin__)
159 #define IH_INITRD_ARCH IH_ARCH_BLACKFIN
160 #elif defined(__I386__)
161 #define IH_INITRD_ARCH IH_ARCH_I386
162 #elif defined(__M68K__)
163 #define IH_INITRD_ARCH IH_ARCH_M68K
164 #elif defined(__microblaze__)
165 #define IH_INITRD_ARCH IH_ARCH_MICROBLAZE
166 #elif defined(__mips__)
167 #define IH_INITRD_ARCH IH_ARCH_MIPS
168 #elif defined(__nios__)
169 #define IH_INITRD_ARCH IH_ARCH_NIOS
170 #elif defined(__nios2__)
171 #define IH_INITRD_ARCH IH_ARCH_NIOS2
172 #elif defined(__PPC__)
173 #define IH_INITRD_ARCH IH_ARCH_PPC
174 #elif defined(__sh__)
175 #define IH_INITRD_ARCH IH_ARCH_SH
176 #elif defined(__sparc__)
177 #define IH_INITRD_ARCH IH_ARCH_SPARC
179 # error Unknown CPU type
182 static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
185 phys_size_t mem_size;
189 memset ((void *)&images, 0, sizeof (images));
190 images.verify = getenv_yesno ("verify");
192 lmb_init(&images.lmb);
194 mem_start = getenv_bootm_low();
195 mem_size = getenv_bootm_size();
197 lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
199 arch_lmb_reserve(&images.lmb);
200 board_lmb_reserve(&images.lmb);
202 /* get kernel image header, start address and length */
203 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
204 &images, &images.os.image_start, &images.os.image_len);
205 if (images.os.image_len == 0) {
206 puts ("ERROR: can't get kernel image!\n");
210 /* get image parameters */
211 switch (genimg_get_format (os_hdr)) {
212 case IMAGE_FORMAT_LEGACY:
213 images.os.type = image_get_type (os_hdr);
214 images.os.comp = image_get_comp (os_hdr);
215 images.os.os = image_get_os (os_hdr);
217 images.os.end = image_get_image_end (os_hdr);
218 images.os.load = image_get_load (os_hdr);
220 #if defined(CONFIG_FIT)
221 case IMAGE_FORMAT_FIT:
222 if (fit_image_get_type (images.fit_hdr_os,
223 images.fit_noffset_os, &images.os.type)) {
224 puts ("Can't get image type!\n");
225 show_boot_progress (-109);
229 if (fit_image_get_comp (images.fit_hdr_os,
230 images.fit_noffset_os, &images.os.comp)) {
231 puts ("Can't get image compression!\n");
232 show_boot_progress (-110);
236 if (fit_image_get_os (images.fit_hdr_os,
237 images.fit_noffset_os, &images.os.os)) {
238 puts ("Can't get image OS!\n");
239 show_boot_progress (-111);
243 images.os.end = fit_get_end (images.fit_hdr_os);
245 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
247 puts ("Can't get image load address!\n");
248 show_boot_progress (-112);
254 puts ("ERROR: unknown image format type!\n");
258 /* find kernel entry point */
259 if (images.legacy_hdr_valid) {
260 images.ep = image_get_ep (&images.legacy_hdr_os_copy);
261 #if defined(CONFIG_FIT)
262 } else if (images.fit_uname_os) {
263 ret = fit_image_get_entry (images.fit_hdr_os,
264 images.fit_noffset_os, &images.ep);
266 puts ("Can't get entry point property!\n");
271 puts ("Could not find kernel entry point!\n");
275 if (images.os.os == IH_OS_LINUX) {
277 ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
278 &images.rd_start, &images.rd_end);
280 puts ("Ramdisk image is corrupt or invalid\n");
284 #if defined(CONFIG_OF_LIBFDT)
285 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
286 /* find flattened device tree */
287 ret = boot_get_fdt (flag, argc, argv, &images,
288 &images.ft_addr, &images.ft_len);
290 puts ("Could not find a valid device tree\n");
294 set_working_fdt_addr(images.ft_addr);
299 images.os.start = (ulong)os_hdr;
300 images.state = BOOTM_STATE_START;
305 #define BOOTM_ERR_RESET -1
306 #define BOOTM_ERR_OVERLAP -2
307 #define BOOTM_ERR_UNIMPLEMENTED -3
308 static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
310 uint8_t comp = os.comp;
311 ulong load = os.load;
312 ulong blob_start = os.start;
313 ulong blob_end = os.end;
314 ulong image_start = os.image_start;
315 ulong image_len = os.image_len;
316 uint unc_len = CONFIG_SYS_BOOTM_LEN;
318 const char *type_name = genimg_get_type_name (os.type);
322 if (load == blob_start) {
323 printf (" XIP %s ... ", type_name);
325 printf (" Loading %s ... ", type_name);
327 memmove_wd ((void *)load,
328 (void *)image_start, image_len, CHUNKSZ);
330 *load_end = load + image_len;
334 printf (" Uncompressing %s ... ", type_name);
335 if (gunzip ((void *)load, unc_len,
336 (uchar *)image_start, &image_len) != 0) {
337 puts ("GUNZIP: uncompress or overwrite error "
338 "- must RESET board to recover\n");
340 show_boot_progress (-6);
341 return BOOTM_ERR_RESET;
344 *load_end = load + image_len;
348 printf (" Uncompressing %s ... ", type_name);
350 * If we've got less than 4 MB of malloc() space,
351 * use slower decompression algorithm which requires
352 * at most 2300 KB of memory.
354 int i = BZ2_bzBuffToBuffDecompress ((char*)load,
355 &unc_len, (char *)image_start, image_len,
356 CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
358 printf ("BUNZIP2: uncompress or overwrite error %d "
359 "- must RESET board to recover\n", i);
361 show_boot_progress (-6);
362 return BOOTM_ERR_RESET;
365 *load_end = load + unc_len;
367 #endif /* CONFIG_BZIP2 */
370 printf (" Uncompressing %s ... ", type_name);
372 int ret = lzmaBuffToBuffDecompress(
373 (unsigned char *)load, &unc_len,
374 (unsigned char *)image_start, image_len);
375 if (ret != LZMA_RESULT_OK) {
376 printf ("LZMA: uncompress or overwrite error %d "
377 "- must RESET board to recover\n", ret);
378 show_boot_progress (-6);
379 return BOOTM_ERR_RESET;
381 *load_end = load + unc_len;
383 #endif /* CONFIG_LZMA */
385 printf ("Unimplemented compression type %d\n", comp);
386 return BOOTM_ERR_UNIMPLEMENTED;
389 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
391 show_boot_progress (7);
393 if ((load < blob_end) && (*load_end > blob_start)) {
394 debug ("images.os.start = 0x%lX, images.os.end = 0x%lx\n", blob_start, blob_end);
395 debug ("images.os.load = 0x%lx, load_end = 0x%lx\n", load, *load_end);
397 return BOOTM_ERR_OVERLAP;
403 /* we overload the cmd field with our state machine info instead of a
404 * function pointer */
405 cmd_tbl_t cmd_bootm_sub[] = {
406 U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
407 U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
408 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
409 U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
411 #ifdef CONFIG_OF_LIBFDT
412 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
414 U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
415 U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
416 U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
417 U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
420 int do_bootm_subcommand (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
427 c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
432 /* treat start special since it resets the state machine */
433 if (state == BOOTM_STATE_START) {
436 return bootm_start(cmdtp, flag, argc, argv);
439 /* Unrecognized command */
441 printf ("Usage:\n%s\n", cmdtp->usage);
445 if (images.state >= state) {
446 printf ("Trying to execute a command out of order\n");
447 printf ("Usage:\n%s\n", cmdtp->usage);
451 images.state |= state;
452 boot_fn = boot_os[images.os.os];
456 case BOOTM_STATE_START:
457 /* should never occur */
459 case BOOTM_STATE_LOADOS:
460 ret = bootm_load_os(images.os, &load_end, 0);
464 lmb_reserve(&images.lmb, images.os.load,
465 (load_end - images.os.load));
467 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
468 case BOOTM_STATE_RAMDISK:
470 ulong rd_len = images.rd_end - images.rd_start;
473 ret = boot_ramdisk_high(&images.lmb, images.rd_start,
474 rd_len, &images.initrd_start, &images.initrd_end);
478 sprintf(str, "%lx", images.initrd_start);
479 setenv("initrd_start", str);
480 sprintf(str, "%lx", images.initrd_end);
481 setenv("initrd_end", str);
485 #ifdef CONFIG_OF_LIBFDT
486 case BOOTM_STATE_FDT:
488 ulong bootmap_base = getenv_bootm_low();
489 ret = boot_relocate_fdt(&images.lmb, bootmap_base,
490 &images.ft_addr, &images.ft_len);
494 case BOOTM_STATE_OS_CMDLINE:
495 ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, &images);
497 printf ("cmdline subcommand not supported\n");
499 case BOOTM_STATE_OS_BD_T:
500 ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, &images);
502 printf ("bdt subcommand not supported\n");
504 case BOOTM_STATE_OS_PREP:
505 ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, &images);
507 printf ("prep subcommand not supported\n");
509 case BOOTM_STATE_OS_GO:
510 disable_interrupts();
511 boot_fn(BOOTM_STATE_OS_GO, argc, argv, &images);
518 /*******************************************************************/
519 /* bootm - boot application image from image in memory */
520 /*******************************************************************/
521 static int relocated = 0;
523 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
530 /* relocate boot function table */
533 for (i = 0; i < ARRAY_SIZE(boot_os); i++)
534 boot_os[i] += gd->reloc_off;
538 /* determine if we have a sub command */
542 simple_strtoul(argv[1], &endp, 16);
543 /* endp pointing to NULL means that argv[1] was just a
544 * valid number, pass it along to the normal bootm processing
546 * If endp is ':' or '#' assume a FIT identifier so pass
547 * along for normal processing.
549 * Right now we assume the first arg should never be '-'
551 if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
552 return do_bootm_subcommand(cmdtp, flag, argc, argv);
555 if (bootm_start(cmdtp, flag, argc, argv))
559 * We have reached the point of no return: we are going to
560 * overwrite all exception vector code, so we cannot easily
561 * recover from any failures any more...
563 iflag = disable_interrupts();
565 #if defined(CONFIG_CMD_USB)
567 * turn off USB to prevent the host controller from writing to the
568 * SDRAM while Linux is booting. This could happen (at least for OHCI
569 * controller), because the HCCA (Host Controller Communication Area)
570 * lies within the SDRAM and the host controller writes continously to
571 * this area (as busmaster!). The HccaFrameNumber is for example
572 * updated every 1 ms within the HCCA structure in SDRAM! For more
573 * details see the OpenHCI specification.
578 #ifdef CONFIG_AMIGAONEG3SE
580 * We've possible left the caches enabled during
581 * bios emulation, so turn them off again
587 ret = bootm_load_os(images.os, &load_end, 1);
590 if (ret == BOOTM_ERR_RESET)
591 do_reset (cmdtp, flag, argc, argv);
592 if (ret == BOOTM_ERR_OVERLAP) {
593 if (images.legacy_hdr_valid) {
594 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
595 puts ("WARNING: legacy format multi component "
596 "image overwritten\n");
598 puts ("ERROR: new format image overwritten - "
599 "must RESET the board to recover\n");
600 show_boot_progress (-113);
601 do_reset (cmdtp, flag, argc, argv);
604 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
607 show_boot_progress (-7);
612 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
614 show_boot_progress (8);
616 #ifdef CONFIG_SILENT_CONSOLE
617 if (images.os.os == IH_OS_LINUX)
618 fixup_silent_linux();
621 boot_fn = boot_os[images.os.os];
622 boot_fn(0, argc, argv, &images);
624 show_boot_progress (-9);
626 puts ("\n## Control returned to monitor - resetting...\n");
628 do_reset (cmdtp, flag, argc, argv);
634 * image_get_kernel - verify legacy format kernel image
635 * @img_addr: in RAM address of the legacy format image to be verified
636 * @verify: data CRC verification flag
638 * image_get_kernel() verifies legacy image integrity and returns pointer to
639 * legacy image header if image verification was completed successfully.
642 * pointer to a legacy image header if valid image was found
643 * otherwise return NULL
645 static image_header_t *image_get_kernel (ulong img_addr, int verify)
647 image_header_t *hdr = (image_header_t *)img_addr;
649 if (!image_check_magic(hdr)) {
650 puts ("Bad Magic Number\n");
651 show_boot_progress (-1);
654 show_boot_progress (2);
656 if (!image_check_hcrc (hdr)) {
657 puts ("Bad Header Checksum\n");
658 show_boot_progress (-2);
662 show_boot_progress (3);
663 image_print_contents (hdr);
666 puts (" Verifying Checksum ... ");
667 if (!image_check_dcrc (hdr)) {
668 printf ("Bad Data CRC\n");
669 show_boot_progress (-3);
674 show_boot_progress (4);
676 if (!image_check_target_arch (hdr)) {
677 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
678 show_boot_progress (-4);
685 * fit_check_kernel - verify FIT format kernel subimage
686 * @fit_hdr: pointer to the FIT image header
687 * os_noffset: kernel subimage node offset within FIT image
688 * @verify: data CRC verification flag
690 * fit_check_kernel() verifies integrity of the kernel subimage and from
691 * specified FIT image.
697 #if defined (CONFIG_FIT)
698 static int fit_check_kernel (const void *fit, int os_noffset, int verify)
700 fit_image_print (fit, os_noffset, " ");
703 puts (" Verifying Hash Integrity ... ");
704 if (!fit_image_check_hashes (fit, os_noffset)) {
705 puts ("Bad Data Hash\n");
706 show_boot_progress (-104);
711 show_boot_progress (105);
713 if (!fit_image_check_target_arch (fit, os_noffset)) {
714 puts ("Unsupported Architecture\n");
715 show_boot_progress (-105);
719 show_boot_progress (106);
720 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
721 puts ("Not a kernel image\n");
722 show_boot_progress (-106);
726 show_boot_progress (107);
729 #endif /* CONFIG_FIT */
732 * boot_get_kernel - find kernel image
733 * @os_data: pointer to a ulong variable, will hold os data start address
734 * @os_len: pointer to a ulong variable, will hold os data length
736 * boot_get_kernel() tries to find a kernel image, verifies its integrity
737 * and locates kernel data.
740 * pointer to image header if valid image was found, plus kernel start
741 * address and length, otherwise NULL
743 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
744 bootm_headers_t *images, ulong *os_data, ulong *os_len)
748 #if defined(CONFIG_FIT)
750 const char *fit_uname_config = NULL;
751 const char *fit_uname_kernel = NULL;
758 /* find out kernel image address */
760 img_addr = load_addr;
761 debug ("* kernel: default image load address = 0x%08lx\n",
763 #if defined(CONFIG_FIT)
764 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
765 &fit_uname_config)) {
766 debug ("* kernel: config '%s' from image at 0x%08lx\n",
767 fit_uname_config, img_addr);
768 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
769 &fit_uname_kernel)) {
770 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
771 fit_uname_kernel, img_addr);
774 img_addr = simple_strtoul(argv[1], NULL, 16);
775 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
778 show_boot_progress (1);
780 /* copy from dataflash if needed */
781 img_addr = genimg_get_image (img_addr);
783 /* check image type, for FIT images get FIT kernel node */
784 *os_data = *os_len = 0;
785 switch (genimg_get_format ((void *)img_addr)) {
786 case IMAGE_FORMAT_LEGACY:
787 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
789 hdr = image_get_kernel (img_addr, images->verify);
792 show_boot_progress (5);
794 /* get os_data and os_len */
795 switch (image_get_type (hdr)) {
797 *os_data = image_get_data (hdr);
798 *os_len = image_get_data_size (hdr);
801 image_multi_getimg (hdr, 0, os_data, os_len);
804 printf ("Wrong Image Type for %s command\n", cmdtp->name);
805 show_boot_progress (-5);
810 * copy image header to allow for image overwrites during kernel
813 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
815 /* save pointer to image header */
816 images->legacy_hdr_os = hdr;
818 images->legacy_hdr_valid = 1;
819 show_boot_progress (6);
821 #if defined(CONFIG_FIT)
822 case IMAGE_FORMAT_FIT:
823 fit_hdr = (void *)img_addr;
824 printf ("## Booting kernel from FIT Image at %08lx ...\n",
827 if (!fit_check_format (fit_hdr)) {
828 puts ("Bad FIT kernel image format!\n");
829 show_boot_progress (-100);
832 show_boot_progress (100);
834 if (!fit_uname_kernel) {
836 * no kernel image node unit name, try to get config
837 * node first. If config unit node name is NULL
838 * fit_conf_get_node() will try to find default config node
840 show_boot_progress (101);
841 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
842 if (cfg_noffset < 0) {
843 show_boot_progress (-101);
846 /* save configuration uname provided in the first
849 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
850 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
851 show_boot_progress (103);
853 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
854 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
856 /* get kernel component image node offset */
857 show_boot_progress (102);
858 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
860 if (os_noffset < 0) {
861 show_boot_progress (-103);
865 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
867 show_boot_progress (104);
868 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
871 /* get kernel image data address and length */
872 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
873 puts ("Could not find kernel subimage data!\n");
874 show_boot_progress (-107);
877 show_boot_progress (108);
880 *os_data = (ulong)data;
881 images->fit_hdr_os = fit_hdr;
882 images->fit_uname_os = fit_uname_kernel;
883 images->fit_noffset_os = os_noffset;
887 printf ("Wrong Image Format for %s command\n", cmdtp->name);
888 show_boot_progress (-108);
892 debug (" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
893 *os_data, *os_len, *os_len);
895 return (void *)img_addr;
899 bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
900 "bootm - boot application image from memory\n",
901 "[addr [arg ...]]\n - boot application image stored in memory\n"
902 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
903 "\t'arg' can be the address of an initrd image\n"
904 #if defined(CONFIG_OF_LIBFDT)
905 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
906 "\ta third argument is required which is the address of the\n"
907 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
908 "\tuse a '-' for the second argument. If you do not pass a third\n"
909 "\ta bd_info struct will be passed instead\n"
911 #if defined(CONFIG_FIT)
912 "\t\nFor the new multi component uImage format (FIT) addresses\n"
913 "\tmust be extened to include component or configuration unit name:\n"
914 "\taddr:<subimg_uname> - direct component image specification\n"
915 "\taddr#<conf_uname> - configuration specification\n"
916 "\tUse iminfo command to get the list of existing component\n"
917 "\timages and configurations.\n"
919 "\nSub-commands to do part of the bootm sequence. The sub-commands "
921 "issued in the order below (it's ok to not issue all sub-commands):\n"
922 "\tstart [addr [arg ...]]\n"
923 "\tloados - load OS image\n"
924 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
925 "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
927 #if defined(CONFIG_OF_LIBFDT)
928 "\tfdt - relocate flat device tree\n"
930 "\tbdt - OS specific bd_t processing\n"
931 "\tcmdline - OS specific command line processing/setup\n"
932 "\tprep - OS specific prep before relocation or go\n"
936 /*******************************************************************/
937 /* bootd - boot default image */
938 /*******************************************************************/
939 #if defined(CONFIG_CMD_BOOTD)
940 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
944 #ifndef CONFIG_SYS_HUSH_PARSER
945 if (run_command (getenv ("bootcmd"), flag) < 0)
948 if (parse_string_outer (getenv ("bootcmd"),
949 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
956 boot, 1, 1, do_bootd,
957 "boot - boot default, i.e., run 'bootcmd'\n",
961 /* keep old command name "bootd" for backward compatibility */
963 bootd, 1, 1, do_bootd,
964 "bootd - boot default, i.e., run 'bootcmd'\n",
971 /*******************************************************************/
972 /* iminfo - print header info for a requested image */
973 /*******************************************************************/
974 #if defined(CONFIG_CMD_IMI)
975 int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
982 return image_info (load_addr);
985 for (arg = 1; arg < argc; ++arg) {
986 addr = simple_strtoul (argv[arg], NULL, 16);
987 if (image_info (addr) != 0)
993 static int image_info (ulong addr)
995 void *hdr = (void *)addr;
997 printf ("\n## Checking Image at %08lx ...\n", addr);
999 switch (genimg_get_format (hdr)) {
1000 case IMAGE_FORMAT_LEGACY:
1001 puts (" Legacy image found\n");
1002 if (!image_check_magic (hdr)) {
1003 puts (" Bad Magic Number\n");
1007 if (!image_check_hcrc (hdr)) {
1008 puts (" Bad Header Checksum\n");
1012 image_print_contents (hdr);
1014 puts (" Verifying Checksum ... ");
1015 if (!image_check_dcrc (hdr)) {
1016 puts (" Bad Data CRC\n");
1021 #if defined(CONFIG_FIT)
1022 case IMAGE_FORMAT_FIT:
1023 puts (" FIT image found\n");
1025 if (!fit_check_format (hdr)) {
1026 puts ("Bad FIT image format!\n");
1030 fit_print_contents (hdr);
1032 if (!fit_all_image_check_hashes (hdr)) {
1033 puts ("Bad hash in FIT image!\n");
1040 puts ("Unknown image format!\n");
1048 iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
1049 "iminfo - print header information for application image\n",
1051 " - print header information for application image starting at\n"
1052 " address 'addr' in memory; this includes verification of the\n"
1053 " image contents (magic number, header and payload checksums)\n"
1058 /*******************************************************************/
1059 /* imls - list all images found in flash */
1060 /*******************************************************************/
1061 #if defined(CONFIG_CMD_IMLS)
1062 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1068 for (i = 0, info = &flash_info[0];
1069 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
1071 if (info->flash_id == FLASH_UNKNOWN)
1073 for (j = 0; j < info->sector_count; ++j) {
1075 hdr = (void *)info->start[j];
1079 switch (genimg_get_format (hdr)) {
1080 case IMAGE_FORMAT_LEGACY:
1081 if (!image_check_hcrc (hdr))
1084 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
1085 image_print_contents (hdr);
1087 puts (" Verifying Checksum ... ");
1088 if (!image_check_dcrc (hdr)) {
1089 puts ("Bad Data CRC\n");
1094 #if defined(CONFIG_FIT)
1095 case IMAGE_FORMAT_FIT:
1096 if (!fit_check_format (hdr))
1099 printf ("FIT Image at %08lX:\n", (ulong)hdr);
1100 fit_print_contents (hdr);
1116 imls, 1, 1, do_imls,
1117 "imls - list all images found in flash\n",
1119 " - Prints information about all images found at sector\n"
1120 " boundaries in flash.\n"
1124 /*******************************************************************/
1125 /* helper routines */
1126 /*******************************************************************/
1127 #ifdef CONFIG_SILENT_CONSOLE
1128 static void fixup_silent_linux ()
1130 char buf[256], *start, *end;
1131 char *cmdline = getenv ("bootargs");
1133 /* Only fix cmdline when requested */
1134 if (!(gd->flags & GD_FLG_SILENT))
1137 debug ("before silent fix-up: %s\n", cmdline);
1139 if ((start = strstr (cmdline, "console=")) != NULL) {
1140 end = strchr (start, ' ');
1141 strncpy (buf, cmdline, (start - cmdline + 8));
1143 strcpy (buf + (start - cmdline + 8), end);
1145 buf[start - cmdline + 8] = '\0';
1147 strcpy (buf, cmdline);
1148 strcat (buf, " console=");
1151 strcpy (buf, "console=");
1154 setenv ("bootargs", buf);
1155 debug ("after silent fix-up: %s\n", buf);
1157 #endif /* CONFIG_SILENT_CONSOLE */
1160 /*******************************************************************/
1161 /* OS booting routines */
1162 /*******************************************************************/
1164 static int do_bootm_netbsd (int flag, int argc, char *argv[],
1165 bootm_headers_t *images)
1167 void (*loader)(bd_t *, image_header_t *, char *, char *);
1168 image_header_t *os_hdr, *hdr;
1169 ulong kernel_data, kernel_len;
1173 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1176 #if defined(CONFIG_FIT)
1177 if (!images->legacy_hdr_valid) {
1178 fit_unsupported_reset ("NetBSD");
1182 hdr = images->legacy_hdr_os;
1185 * Booting a (NetBSD) kernel image
1187 * This process is pretty similar to a standalone application:
1188 * The (first part of an multi-) image must be a stage-2 loader,
1189 * which in turn is responsible for loading & invoking the actual
1190 * kernel. The only differences are the parameters being passed:
1191 * besides the board info strucure, the loader expects a command
1192 * line, the name of the console device, and (optionally) the
1193 * address of the original image header.
1196 if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1197 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
1203 #if defined (CONFIG_8xx_CONS_SMC1)
1205 #elif defined (CONFIG_8xx_CONS_SMC2)
1207 #elif defined (CONFIG_8xx_CONS_SCC2)
1209 #elif defined (CONFIG_8xx_CONS_SCC3)
1217 for (i = 2, len = 0; i < argc; i += 1)
1218 len += strlen (argv[i]) + 1;
1219 cmdline = malloc (len);
1221 for (i = 2, len = 0; i < argc; i += 1) {
1223 cmdline[len++] = ' ';
1224 strcpy (&cmdline[len], argv[i]);
1225 len += strlen (argv[i]);
1227 } else if ((cmdline = getenv ("bootargs")) == NULL) {
1231 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
1233 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
1236 show_boot_progress (15);
1239 * NetBSD Stage-2 Loader Parameters:
1240 * r3: ptr to board info data
1242 * r5: console device
1243 * r6: boot args string
1245 (*loader) (gd->bd, os_hdr, consdev, cmdline);
1250 #ifdef CONFIG_LYNXKDI
1251 static int do_bootm_lynxkdi (int flag, int argc, char *argv[],
1252 bootm_headers_t *images)
1254 image_header_t *hdr = &images->legacy_hdr_os_copy;
1256 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1259 #if defined(CONFIG_FIT)
1260 if (!images->legacy_hdr_valid) {
1261 fit_unsupported_reset ("Lynx");
1266 lynxkdi_boot ((image_header_t *)hdr);
1270 #endif /* CONFIG_LYNXKDI */
1272 static int do_bootm_rtems (int flag, int argc, char *argv[],
1273 bootm_headers_t *images)
1275 void (*entry_point)(bd_t *);
1277 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1280 #if defined(CONFIG_FIT)
1281 if (!images->legacy_hdr_valid) {
1282 fit_unsupported_reset ("RTEMS");
1287 entry_point = (void (*)(bd_t *))images->ep;
1289 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1290 (ulong)entry_point);
1292 show_boot_progress (15);
1296 * r3: ptr to board info data
1298 (*entry_point)(gd->bd);
1303 #if defined(CONFIG_CMD_ELF)
1304 static int do_bootm_vxworks (int flag, int argc, char *argv[],
1305 bootm_headers_t *images)
1309 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1312 #if defined(CONFIG_FIT)
1313 if (!images->legacy_hdr_valid) {
1314 fit_unsupported_reset ("VxWorks");
1319 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1320 setenv("loadaddr", str);
1321 do_bootvx(NULL, 0, 0, NULL);
1326 static int do_bootm_qnxelf(int flag, int argc, char *argv[],
1327 bootm_headers_t *images)
1329 char *local_args[2];
1332 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1335 #if defined(CONFIG_FIT)
1336 if (!images->legacy_hdr_valid) {
1337 fit_unsupported_reset ("QNX");
1342 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1343 local_args[0] = argv[0];
1344 local_args[1] = str; /* and provide it via the arguments */
1345 do_bootelf(NULL, 0, 2, local_args);
1351 #ifdef CONFIG_INTEGRITY
1352 static int do_bootm_integrity (int flag, int argc, char *argv[],
1353 bootm_headers_t *images)
1355 void (*entry_point)(void);
1357 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1360 #if defined(CONFIG_FIT)
1361 if (!images->legacy_hdr_valid) {
1362 fit_unsupported_reset ("INTEGRITY");
1367 entry_point = (void (*)(void))images->ep;
1369 printf ("## Transferring control to INTEGRITY (at address %08lx) ...\n",
1370 (ulong)entry_point);
1372 show_boot_progress (15);
1375 * INTEGRITY Parameters: