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,
33 #include <u-boot/zlib.h>
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 #define CONFIG_BOOTM_LINUX 1
107 #define CONFIG_BOOTM_NETBSD 1
108 #define CONFIG_BOOTM_RTEMS 1
110 #ifdef CONFIG_BOOTM_LINUX
111 extern boot_os_fn do_bootm_linux;
113 #ifdef CONFIG_BOOTM_NETBSD
114 static boot_os_fn do_bootm_netbsd;
116 #if defined(CONFIG_LYNXKDI)
117 static boot_os_fn do_bootm_lynxkdi;
118 extern void lynxkdi_boot (image_header_t *);
120 #ifdef CONFIG_BOOTM_RTEMS
121 static boot_os_fn do_bootm_rtems;
123 #if defined(CONFIG_CMD_ELF)
124 static boot_os_fn do_bootm_vxworks;
125 static boot_os_fn do_bootm_qnxelf;
126 int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
127 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
129 #if defined(CONFIG_INTEGRITY)
130 static boot_os_fn do_bootm_integrity;
133 boot_os_fn * boot_os[] = {
134 #ifdef CONFIG_BOOTM_LINUX
135 [IH_OS_LINUX] = do_bootm_linux,
137 #ifdef CONFIG_BOOTM_NETBSD
138 [IH_OS_NETBSD] = do_bootm_netbsd,
140 #ifdef CONFIG_LYNXKDI
141 [IH_OS_LYNXOS] = do_bootm_lynxkdi,
143 #ifdef CONFIG_BOOTM_RTEMS
144 [IH_OS_RTEMS] = do_bootm_rtems,
146 #if defined(CONFIG_CMD_ELF)
147 [IH_OS_VXWORKS] = do_bootm_vxworks,
148 [IH_OS_QNX] = do_bootm_qnxelf,
150 #ifdef CONFIG_INTEGRITY
151 [IH_OS_INTEGRITY] = do_bootm_integrity,
155 ulong load_addr = CONFIG_SYS_LOAD_ADDR; /* Default Load Address */
156 static bootm_headers_t images; /* pointers to os/initrd/fdt images */
158 void __board_lmb_reserve(struct lmb *lmb)
160 /* please define platform specific board_lmb_reserve() */
162 void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
164 void __arch_lmb_reserve(struct lmb *lmb)
166 /* please define platform specific arch_lmb_reserve() */
168 void arch_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__arch_lmb_reserve")));
171 #define IH_INITRD_ARCH IH_ARCH_ARM
172 #elif defined(__avr32__)
173 #define IH_INITRD_ARCH IH_ARCH_AVR32
174 #elif defined(__bfin__)
175 #define IH_INITRD_ARCH IH_ARCH_BLACKFIN
176 #elif defined(__I386__)
177 #define IH_INITRD_ARCH IH_ARCH_I386
178 #elif defined(__M68K__)
179 #define IH_INITRD_ARCH IH_ARCH_M68K
180 #elif defined(__microblaze__)
181 #define IH_INITRD_ARCH IH_ARCH_MICROBLAZE
182 #elif defined(__mips__)
183 #define IH_INITRD_ARCH IH_ARCH_MIPS
184 #elif defined(__nios__)
185 #define IH_INITRD_ARCH IH_ARCH_NIOS
186 #elif defined(__nios2__)
187 #define IH_INITRD_ARCH IH_ARCH_NIOS2
188 #elif defined(__PPC__)
189 #define IH_INITRD_ARCH IH_ARCH_PPC
190 #elif defined(__sh__)
191 #define IH_INITRD_ARCH IH_ARCH_SH
192 #elif defined(__sparc__)
193 #define IH_INITRD_ARCH IH_ARCH_SPARC
195 # error Unknown CPU type
198 static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
201 phys_size_t mem_size;
205 memset ((void *)&images, 0, sizeof (images));
206 images.verify = getenv_yesno ("verify");
208 lmb_init(&images.lmb);
210 mem_start = getenv_bootm_low();
211 mem_size = getenv_bootm_size();
213 lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
215 arch_lmb_reserve(&images.lmb);
216 board_lmb_reserve(&images.lmb);
218 /* get kernel image header, start address and length */
219 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
220 &images, &images.os.image_start, &images.os.image_len);
221 if (images.os.image_len == 0) {
222 puts ("ERROR: can't get kernel image!\n");
226 /* get image parameters */
227 switch (genimg_get_format (os_hdr)) {
228 case IMAGE_FORMAT_LEGACY:
229 images.os.type = image_get_type (os_hdr);
230 images.os.comp = image_get_comp (os_hdr);
231 images.os.os = image_get_os (os_hdr);
233 images.os.end = image_get_image_end (os_hdr);
234 images.os.load = image_get_load (os_hdr);
236 #if defined(CONFIG_FIT)
237 case IMAGE_FORMAT_FIT:
238 if (fit_image_get_type (images.fit_hdr_os,
239 images.fit_noffset_os, &images.os.type)) {
240 puts ("Can't get image type!\n");
241 show_boot_progress (-109);
245 if (fit_image_get_comp (images.fit_hdr_os,
246 images.fit_noffset_os, &images.os.comp)) {
247 puts ("Can't get image compression!\n");
248 show_boot_progress (-110);
252 if (fit_image_get_os (images.fit_hdr_os,
253 images.fit_noffset_os, &images.os.os)) {
254 puts ("Can't get image OS!\n");
255 show_boot_progress (-111);
259 images.os.end = fit_get_end (images.fit_hdr_os);
261 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
263 puts ("Can't get image load address!\n");
264 show_boot_progress (-112);
270 puts ("ERROR: unknown image format type!\n");
274 /* find kernel entry point */
275 if (images.legacy_hdr_valid) {
276 images.ep = image_get_ep (&images.legacy_hdr_os_copy);
277 #if defined(CONFIG_FIT)
278 } else if (images.fit_uname_os) {
279 ret = fit_image_get_entry (images.fit_hdr_os,
280 images.fit_noffset_os, &images.ep);
282 puts ("Can't get entry point property!\n");
287 puts ("Could not find kernel entry point!\n");
291 if (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 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
302 /* find flattened device tree */
303 ret = boot_get_fdt (flag, argc, argv, &images,
304 &images.ft_addr, &images.ft_len);
306 puts ("Could not find a valid device tree\n");
310 set_working_fdt_addr(images.ft_addr);
315 images.os.start = (ulong)os_hdr;
316 images.state = BOOTM_STATE_START;
321 #define BOOTM_ERR_RESET -1
322 #define BOOTM_ERR_OVERLAP -2
323 #define BOOTM_ERR_UNIMPLEMENTED -3
324 static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
326 uint8_t comp = os.comp;
327 ulong load = os.load;
328 ulong blob_start = os.start;
329 ulong blob_end = os.end;
330 ulong image_start = os.image_start;
331 ulong image_len = os.image_len;
332 uint unc_len = CONFIG_SYS_BOOTM_LEN;
334 const char *type_name = genimg_get_type_name (os.type);
338 if (load == blob_start) {
339 printf (" XIP %s ... ", type_name);
341 printf (" Loading %s ... ", type_name);
343 if (load != image_start) {
344 memmove_wd ((void *)load,
345 (void *)image_start, image_len, CHUNKSZ);
348 *load_end = load + image_len;
352 printf (" Uncompressing %s ... ", type_name);
353 if (gunzip ((void *)load, unc_len,
354 (uchar *)image_start, &image_len) != 0) {
355 puts ("GUNZIP: uncompress, out-of-mem or overwrite error "
356 "- must RESET board to recover\n");
358 show_boot_progress (-6);
359 return BOOTM_ERR_RESET;
362 *load_end = load + image_len;
366 printf (" Uncompressing %s ... ", type_name);
368 * If we've got less than 4 MB of malloc() space,
369 * use slower decompression algorithm which requires
370 * at most 2300 KB of memory.
372 int i = BZ2_bzBuffToBuffDecompress ((char*)load,
373 &unc_len, (char *)image_start, image_len,
374 CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
376 printf ("BUNZIP2: uncompress or overwrite error %d "
377 "- must RESET board to recover\n", i);
379 show_boot_progress (-6);
380 return BOOTM_ERR_RESET;
383 *load_end = load + unc_len;
385 #endif /* CONFIG_BZIP2 */
388 printf (" Uncompressing %s ... ", type_name);
390 int ret = lzmaBuffToBuffDecompress(
391 (unsigned char *)load, &unc_len,
392 (unsigned char *)image_start, image_len);
393 if (ret != LZMA_RESULT_OK) {
394 printf ("LZMA: uncompress or overwrite error %d "
395 "- must RESET board to recover\n", ret);
396 show_boot_progress (-6);
397 return BOOTM_ERR_RESET;
399 *load_end = load + unc_len;
401 #endif /* CONFIG_LZMA */
403 printf ("Unimplemented compression type %d\n", comp);
404 return BOOTM_ERR_UNIMPLEMENTED;
407 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
409 show_boot_progress (7);
411 if ((load < blob_end) && (*load_end > blob_start)) {
412 debug ("images.os.start = 0x%lX, images.os.end = 0x%lx\n", blob_start, blob_end);
413 debug ("images.os.load = 0x%lx, load_end = 0x%lx\n", load, *load_end);
415 return BOOTM_ERR_OVERLAP;
421 /* we overload the cmd field with our state machine info instead of a
422 * function pointer */
423 cmd_tbl_t cmd_bootm_sub[] = {
424 U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
425 U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
426 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
427 U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
429 #ifdef CONFIG_OF_LIBFDT
430 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
432 U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
433 U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
434 U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
435 U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
438 int do_bootm_subcommand (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
445 c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
450 /* treat start special since it resets the state machine */
451 if (state == BOOTM_STATE_START) {
454 return bootm_start(cmdtp, flag, argc, argv);
457 /* Unrecognized command */
463 if (images.state >= state) {
464 printf ("Trying to execute a command out of order\n");
469 images.state |= state;
470 boot_fn = boot_os[images.os.os];
474 case BOOTM_STATE_START:
475 /* should never occur */
477 case BOOTM_STATE_LOADOS:
478 ret = bootm_load_os(images.os, &load_end, 0);
482 lmb_reserve(&images.lmb, images.os.load,
483 (load_end - images.os.load));
485 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
486 case BOOTM_STATE_RAMDISK:
488 ulong rd_len = images.rd_end - images.rd_start;
491 ret = boot_ramdisk_high(&images.lmb, images.rd_start,
492 rd_len, &images.initrd_start, &images.initrd_end);
496 sprintf(str, "%lx", images.initrd_start);
497 setenv("initrd_start", str);
498 sprintf(str, "%lx", images.initrd_end);
499 setenv("initrd_end", str);
503 #ifdef CONFIG_OF_LIBFDT
504 case BOOTM_STATE_FDT:
506 ulong bootmap_base = getenv_bootm_low();
507 ret = boot_relocate_fdt(&images.lmb, bootmap_base,
508 &images.ft_addr, &images.ft_len);
512 case BOOTM_STATE_OS_CMDLINE:
513 ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, &images);
515 printf ("cmdline subcommand not supported\n");
517 case BOOTM_STATE_OS_BD_T:
518 ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, &images);
520 printf ("bdt subcommand not supported\n");
522 case BOOTM_STATE_OS_PREP:
523 ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, &images);
525 printf ("prep subcommand not supported\n");
527 case BOOTM_STATE_OS_GO:
528 disable_interrupts();
529 boot_fn(BOOTM_STATE_OS_GO, argc, argv, &images);
536 /*******************************************************************/
537 /* bootm - boot application image from image in memory */
538 /*******************************************************************/
539 static int relocated = 0;
541 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
548 /* relocate boot function table */
551 for (i = 0; i < ARRAY_SIZE(boot_os); i++)
552 boot_os[i] += gd->reloc_off;
556 /* determine if we have a sub command */
560 simple_strtoul(argv[1], &endp, 16);
561 /* endp pointing to NULL means that argv[1] was just a
562 * valid number, pass it along to the normal bootm processing
564 * If endp is ':' or '#' assume a FIT identifier so pass
565 * along for normal processing.
567 * Right now we assume the first arg should never be '-'
569 if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
570 return do_bootm_subcommand(cmdtp, flag, argc, argv);
573 if (bootm_start(cmdtp, flag, argc, argv))
577 * We have reached the point of no return: we are going to
578 * overwrite all exception vector code, so we cannot easily
579 * recover from any failures any more...
581 iflag = disable_interrupts();
583 #if defined(CONFIG_CMD_USB)
585 * turn off USB to prevent the host controller from writing to the
586 * SDRAM while Linux is booting. This could happen (at least for OHCI
587 * controller), because the HCCA (Host Controller Communication Area)
588 * lies within the SDRAM and the host controller writes continously to
589 * this area (as busmaster!). The HccaFrameNumber is for example
590 * updated every 1 ms within the HCCA structure in SDRAM! For more
591 * details see the OpenHCI specification.
596 #ifdef CONFIG_AMIGAONEG3SE
598 * We've possible left the caches enabled during
599 * bios emulation, so turn them off again
605 ret = bootm_load_os(images.os, &load_end, 1);
608 if (ret == BOOTM_ERR_RESET)
609 do_reset (cmdtp, flag, argc, argv);
610 if (ret == BOOTM_ERR_OVERLAP) {
611 if (images.legacy_hdr_valid) {
612 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
613 puts ("WARNING: legacy format multi component "
614 "image overwritten\n");
616 puts ("ERROR: new format image overwritten - "
617 "must RESET the board to recover\n");
618 show_boot_progress (-113);
619 do_reset (cmdtp, flag, argc, argv);
622 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
625 show_boot_progress (-7);
630 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
632 show_boot_progress (8);
634 #ifdef CONFIG_SILENT_CONSOLE
635 if (images.os.os == IH_OS_LINUX)
636 fixup_silent_linux();
639 boot_fn = boot_os[images.os.os];
640 boot_fn(0, argc, argv, &images);
642 show_boot_progress (-9);
644 puts ("\n## Control returned to monitor - resetting...\n");
646 do_reset (cmdtp, flag, argc, argv);
652 * image_get_kernel - verify legacy format kernel image
653 * @img_addr: in RAM address of the legacy format image to be verified
654 * @verify: data CRC verification flag
656 * image_get_kernel() verifies legacy image integrity and returns pointer to
657 * legacy image header if image verification was completed successfully.
660 * pointer to a legacy image header if valid image was found
661 * otherwise return NULL
663 static image_header_t *image_get_kernel (ulong img_addr, int verify)
665 image_header_t *hdr = (image_header_t *)img_addr;
667 if (!image_check_magic(hdr)) {
668 puts ("Bad Magic Number\n");
669 show_boot_progress (-1);
672 show_boot_progress (2);
674 if (!image_check_hcrc (hdr)) {
675 puts ("Bad Header Checksum\n");
676 show_boot_progress (-2);
680 show_boot_progress (3);
681 image_print_contents (hdr);
684 puts (" Verifying Checksum ... ");
685 if (!image_check_dcrc (hdr)) {
686 printf ("Bad Data CRC\n");
687 show_boot_progress (-3);
692 show_boot_progress (4);
694 if (!image_check_target_arch (hdr)) {
695 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
696 show_boot_progress (-4);
703 * fit_check_kernel - verify FIT format kernel subimage
704 * @fit_hdr: pointer to the FIT image header
705 * os_noffset: kernel subimage node offset within FIT image
706 * @verify: data CRC verification flag
708 * fit_check_kernel() verifies integrity of the kernel subimage and from
709 * specified FIT image.
715 #if defined (CONFIG_FIT)
716 static int fit_check_kernel (const void *fit, int os_noffset, int verify)
718 fit_image_print (fit, os_noffset, " ");
721 puts (" Verifying Hash Integrity ... ");
722 if (!fit_image_check_hashes (fit, os_noffset)) {
723 puts ("Bad Data Hash\n");
724 show_boot_progress (-104);
729 show_boot_progress (105);
731 if (!fit_image_check_target_arch (fit, os_noffset)) {
732 puts ("Unsupported Architecture\n");
733 show_boot_progress (-105);
737 show_boot_progress (106);
738 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
739 puts ("Not a kernel image\n");
740 show_boot_progress (-106);
744 show_boot_progress (107);
747 #endif /* CONFIG_FIT */
750 * boot_get_kernel - find kernel image
751 * @os_data: pointer to a ulong variable, will hold os data start address
752 * @os_len: pointer to a ulong variable, will hold os data length
754 * boot_get_kernel() tries to find a kernel image, verifies its integrity
755 * and locates kernel data.
758 * pointer to image header if valid image was found, plus kernel start
759 * address and length, otherwise NULL
761 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
762 bootm_headers_t *images, ulong *os_data, ulong *os_len)
766 #if defined(CONFIG_FIT)
768 const char *fit_uname_config = NULL;
769 const char *fit_uname_kernel = NULL;
776 /* find out kernel image address */
778 img_addr = load_addr;
779 debug ("* kernel: default image load address = 0x%08lx\n",
781 #if defined(CONFIG_FIT)
782 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
783 &fit_uname_config)) {
784 debug ("* kernel: config '%s' from image at 0x%08lx\n",
785 fit_uname_config, img_addr);
786 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
787 &fit_uname_kernel)) {
788 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
789 fit_uname_kernel, img_addr);
792 img_addr = simple_strtoul(argv[1], NULL, 16);
793 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
796 show_boot_progress (1);
798 /* copy from dataflash if needed */
799 img_addr = genimg_get_image (img_addr);
801 /* check image type, for FIT images get FIT kernel node */
802 *os_data = *os_len = 0;
803 switch (genimg_get_format ((void *)img_addr)) {
804 case IMAGE_FORMAT_LEGACY:
805 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
807 hdr = image_get_kernel (img_addr, images->verify);
810 show_boot_progress (5);
812 /* get os_data and os_len */
813 switch (image_get_type (hdr)) {
815 *os_data = image_get_data (hdr);
816 *os_len = image_get_data_size (hdr);
819 image_multi_getimg (hdr, 0, os_data, os_len);
822 printf ("Wrong Image Type for %s command\n", cmdtp->name);
823 show_boot_progress (-5);
828 * copy image header to allow for image overwrites during kernel
831 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
833 /* save pointer to image header */
834 images->legacy_hdr_os = hdr;
836 images->legacy_hdr_valid = 1;
837 show_boot_progress (6);
839 #if defined(CONFIG_FIT)
840 case IMAGE_FORMAT_FIT:
841 fit_hdr = (void *)img_addr;
842 printf ("## Booting kernel from FIT Image at %08lx ...\n",
845 if (!fit_check_format (fit_hdr)) {
846 puts ("Bad FIT kernel image format!\n");
847 show_boot_progress (-100);
850 show_boot_progress (100);
852 if (!fit_uname_kernel) {
854 * no kernel image node unit name, try to get config
855 * node first. If config unit node name is NULL
856 * fit_conf_get_node() will try to find default config node
858 show_boot_progress (101);
859 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
860 if (cfg_noffset < 0) {
861 show_boot_progress (-101);
864 /* save configuration uname provided in the first
867 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
868 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
869 show_boot_progress (103);
871 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
872 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
874 /* get kernel component image node offset */
875 show_boot_progress (102);
876 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
878 if (os_noffset < 0) {
879 show_boot_progress (-103);
883 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
885 show_boot_progress (104);
886 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
889 /* get kernel image data address and length */
890 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
891 puts ("Could not find kernel subimage data!\n");
892 show_boot_progress (-107);
895 show_boot_progress (108);
898 *os_data = (ulong)data;
899 images->fit_hdr_os = fit_hdr;
900 images->fit_uname_os = fit_uname_kernel;
901 images->fit_noffset_os = os_noffset;
905 printf ("Wrong Image Format for %s command\n", cmdtp->name);
906 show_boot_progress (-108);
910 debug (" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
911 *os_data, *os_len, *os_len);
913 return (void *)img_addr;
917 bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
918 "boot application image from memory",
919 "[addr [arg ...]]\n - boot application image stored in memory\n"
920 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
921 "\t'arg' can be the address of an initrd image\n"
922 #if defined(CONFIG_OF_LIBFDT)
923 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
924 "\ta third argument is required which is the address of the\n"
925 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
926 "\tuse a '-' for the second argument. If you do not pass a third\n"
927 "\ta bd_info struct will be passed instead\n"
929 #if defined(CONFIG_FIT)
930 "\t\nFor the new multi component uImage format (FIT) addresses\n"
931 "\tmust be extened to include component or configuration unit name:\n"
932 "\taddr:<subimg_uname> - direct component image specification\n"
933 "\taddr#<conf_uname> - configuration specification\n"
934 "\tUse iminfo command to get the list of existing component\n"
935 "\timages and configurations.\n"
937 "\nSub-commands to do part of the bootm sequence. The sub-commands "
939 "issued in the order below (it's ok to not issue all sub-commands):\n"
940 "\tstart [addr [arg ...]]\n"
941 "\tloados - load OS image\n"
942 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
943 "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
945 #if defined(CONFIG_OF_LIBFDT)
946 "\tfdt - relocate flat device tree\n"
948 "\tbdt - OS specific bd_t processing\n"
949 "\tcmdline - OS specific command line processing/setup\n"
950 "\tprep - OS specific prep before relocation or go\n"
954 /*******************************************************************/
955 /* bootd - boot default image */
956 /*******************************************************************/
957 #if defined(CONFIG_CMD_BOOTD)
958 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
962 #ifndef CONFIG_SYS_HUSH_PARSER
963 if (run_command (getenv ("bootcmd"), flag) < 0)
966 if (parse_string_outer (getenv ("bootcmd"),
967 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
974 boot, 1, 1, do_bootd,
975 "boot default, i.e., run 'bootcmd'",
979 /* keep old command name "bootd" for backward compatibility */
981 bootd, 1, 1, do_bootd,
982 "boot default, i.e., run 'bootcmd'",
989 /*******************************************************************/
990 /* iminfo - print header info for a requested image */
991 /*******************************************************************/
992 #if defined(CONFIG_CMD_IMI)
993 int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1000 return image_info (load_addr);
1003 for (arg = 1; arg < argc; ++arg) {
1004 addr = simple_strtoul (argv[arg], NULL, 16);
1005 if (image_info (addr) != 0)
1011 static int image_info (ulong addr)
1013 void *hdr = (void *)addr;
1015 printf ("\n## Checking Image at %08lx ...\n", addr);
1017 switch (genimg_get_format (hdr)) {
1018 case IMAGE_FORMAT_LEGACY:
1019 puts (" Legacy image found\n");
1020 if (!image_check_magic (hdr)) {
1021 puts (" Bad Magic Number\n");
1025 if (!image_check_hcrc (hdr)) {
1026 puts (" Bad Header Checksum\n");
1030 image_print_contents (hdr);
1032 puts (" Verifying Checksum ... ");
1033 if (!image_check_dcrc (hdr)) {
1034 puts (" Bad Data CRC\n");
1039 #if defined(CONFIG_FIT)
1040 case IMAGE_FORMAT_FIT:
1041 puts (" FIT image found\n");
1043 if (!fit_check_format (hdr)) {
1044 puts ("Bad FIT image format!\n");
1048 fit_print_contents (hdr);
1050 if (!fit_all_image_check_hashes (hdr)) {
1051 puts ("Bad hash in FIT image!\n");
1058 puts ("Unknown image format!\n");
1066 iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
1067 "print header information for application image",
1069 " - print header information for application image starting at\n"
1070 " address 'addr' in memory; this includes verification of the\n"
1071 " image contents (magic number, header and payload checksums)\n"
1076 /*******************************************************************/
1077 /* imls - list all images found in flash */
1078 /*******************************************************************/
1079 #if defined(CONFIG_CMD_IMLS)
1080 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1086 for (i = 0, info = &flash_info[0];
1087 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
1089 if (info->flash_id == FLASH_UNKNOWN)
1091 for (j = 0; j < info->sector_count; ++j) {
1093 hdr = (void *)info->start[j];
1097 switch (genimg_get_format (hdr)) {
1098 case IMAGE_FORMAT_LEGACY:
1099 if (!image_check_hcrc (hdr))
1102 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
1103 image_print_contents (hdr);
1105 puts (" Verifying Checksum ... ");
1106 if (!image_check_dcrc (hdr)) {
1107 puts ("Bad Data CRC\n");
1112 #if defined(CONFIG_FIT)
1113 case IMAGE_FORMAT_FIT:
1114 if (!fit_check_format (hdr))
1117 printf ("FIT Image at %08lX:\n", (ulong)hdr);
1118 fit_print_contents (hdr);
1134 imls, 1, 1, do_imls,
1135 "list all images found in flash",
1137 " - Prints information about all images found at sector\n"
1138 " boundaries in flash.\n"
1142 /*******************************************************************/
1143 /* helper routines */
1144 /*******************************************************************/
1145 #ifdef CONFIG_SILENT_CONSOLE
1146 static void fixup_silent_linux ()
1148 char buf[256], *start, *end;
1149 char *cmdline = getenv ("bootargs");
1151 /* Only fix cmdline when requested */
1152 if (!(gd->flags & GD_FLG_SILENT))
1155 debug ("before silent fix-up: %s\n", cmdline);
1157 if ((start = strstr (cmdline, "console=")) != NULL) {
1158 end = strchr (start, ' ');
1159 strncpy (buf, cmdline, (start - cmdline + 8));
1161 strcpy (buf + (start - cmdline + 8), end);
1163 buf[start - cmdline + 8] = '\0';
1165 strcpy (buf, cmdline);
1166 strcat (buf, " console=");
1169 strcpy (buf, "console=");
1172 setenv ("bootargs", buf);
1173 debug ("after silent fix-up: %s\n", buf);
1175 #endif /* CONFIG_SILENT_CONSOLE */
1178 /*******************************************************************/
1179 /* OS booting routines */
1180 /*******************************************************************/
1182 #ifdef CONFIG_BOOTM_NETBSD
1183 static int do_bootm_netbsd (int flag, int argc, char *argv[],
1184 bootm_headers_t *images)
1186 void (*loader)(bd_t *, image_header_t *, char *, char *);
1187 image_header_t *os_hdr, *hdr;
1188 ulong kernel_data, kernel_len;
1192 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1195 #if defined(CONFIG_FIT)
1196 if (!images->legacy_hdr_valid) {
1197 fit_unsupported_reset ("NetBSD");
1201 hdr = images->legacy_hdr_os;
1204 * Booting a (NetBSD) kernel image
1206 * This process is pretty similar to a standalone application:
1207 * The (first part of an multi-) image must be a stage-2 loader,
1208 * which in turn is responsible for loading & invoking the actual
1209 * kernel. The only differences are the parameters being passed:
1210 * besides the board info strucure, the loader expects a command
1211 * line, the name of the console device, and (optionally) the
1212 * address of the original image header.
1215 if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1216 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
1222 #if defined (CONFIG_8xx_CONS_SMC1)
1224 #elif defined (CONFIG_8xx_CONS_SMC2)
1226 #elif defined (CONFIG_8xx_CONS_SCC2)
1228 #elif defined (CONFIG_8xx_CONS_SCC3)
1236 for (i = 2, len = 0; i < argc; i += 1)
1237 len += strlen (argv[i]) + 1;
1238 cmdline = malloc (len);
1240 for (i = 2, len = 0; i < argc; i += 1) {
1242 cmdline[len++] = ' ';
1243 strcpy (&cmdline[len], argv[i]);
1244 len += strlen (argv[i]);
1246 } else if ((cmdline = getenv ("bootargs")) == NULL) {
1250 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
1252 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
1255 show_boot_progress (15);
1258 * NetBSD Stage-2 Loader Parameters:
1259 * r3: ptr to board info data
1261 * r5: console device
1262 * r6: boot args string
1264 (*loader) (gd->bd, os_hdr, consdev, cmdline);
1268 #endif /* CONFIG_BOOTM_NETBSD*/
1270 #ifdef CONFIG_LYNXKDI
1271 static int do_bootm_lynxkdi (int flag, int argc, char *argv[],
1272 bootm_headers_t *images)
1274 image_header_t *hdr = &images->legacy_hdr_os_copy;
1276 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1279 #if defined(CONFIG_FIT)
1280 if (!images->legacy_hdr_valid) {
1281 fit_unsupported_reset ("Lynx");
1286 lynxkdi_boot ((image_header_t *)hdr);
1290 #endif /* CONFIG_LYNXKDI */
1292 #ifdef CONFIG_BOOTM_RTEMS
1293 static int do_bootm_rtems (int flag, int argc, char *argv[],
1294 bootm_headers_t *images)
1296 void (*entry_point)(bd_t *);
1298 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1301 #if defined(CONFIG_FIT)
1302 if (!images->legacy_hdr_valid) {
1303 fit_unsupported_reset ("RTEMS");
1308 entry_point = (void (*)(bd_t *))images->ep;
1310 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1311 (ulong)entry_point);
1313 show_boot_progress (15);
1317 * r3: ptr to board info data
1319 (*entry_point)(gd->bd);
1323 #endif /* CONFIG_BOOTM_RTEMS */
1325 #if defined(CONFIG_CMD_ELF)
1326 static int do_bootm_vxworks (int flag, int argc, char *argv[],
1327 bootm_headers_t *images)
1331 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1334 #if defined(CONFIG_FIT)
1335 if (!images->legacy_hdr_valid) {
1336 fit_unsupported_reset ("VxWorks");
1341 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1342 setenv("loadaddr", str);
1343 do_bootvx(NULL, 0, 0, NULL);
1348 static int do_bootm_qnxelf(int flag, int argc, char *argv[],
1349 bootm_headers_t *images)
1351 char *local_args[2];
1354 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1357 #if defined(CONFIG_FIT)
1358 if (!images->legacy_hdr_valid) {
1359 fit_unsupported_reset ("QNX");
1364 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1365 local_args[0] = argv[0];
1366 local_args[1] = str; /* and provide it via the arguments */
1367 do_bootelf(NULL, 0, 2, local_args);
1373 #ifdef CONFIG_INTEGRITY
1374 static int do_bootm_integrity (int flag, int argc, char *argv[],
1375 bootm_headers_t *images)
1377 void (*entry_point)(void);
1379 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1382 #if defined(CONFIG_FIT)
1383 if (!images->legacy_hdr_valid) {
1384 fit_unsupported_reset ("INTEGRITY");
1389 entry_point = (void (*)(void))images->ep;
1391 printf ("## Transferring control to INTEGRITY (at address %08lx) ...\n",
1392 (ulong)entry_point);
1394 show_boot_progress (15);
1397 * INTEGRITY Parameters: