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 <asm/byteorder.h>
39 #if defined(CONFIG_CMD_USB)
43 #ifdef CONFIG_SYS_HUSH_PARSER
47 #if defined(CONFIG_OF_LIBFDT)
50 #include <fdt_support.h>
54 #define _7ZIP_BYTE_DEFINED /* Byte already defined by zlib */
55 #include <lzma/LzmaTypes.h>
56 #include <lzma/LzmaDecode.h>
57 #include <lzma/LzmaTools.h>
58 #endif /* CONFIG_LZMA */
60 DECLARE_GLOBAL_DATA_PTR;
62 extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
63 #ifndef CONFIG_SYS_BOOTM_LEN
64 #define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
68 extern void bz_internal_error(int);
71 #if defined(CONFIG_CMD_IMI)
72 static int image_info (unsigned long addr);
75 #if defined(CONFIG_CMD_IMLS)
77 extern flash_info_t flash_info[]; /* info for FLASH chips */
78 static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
81 #ifdef CONFIG_SILENT_CONSOLE
82 static void fixup_silent_linux (void);
85 static image_header_t *image_get_kernel (ulong img_addr, int verify);
86 #if defined(CONFIG_FIT)
87 static int fit_check_kernel (const void *fit, int os_noffset, int verify);
90 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
91 bootm_headers_t *images, ulong *os_data, ulong *os_len);
92 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
95 * Continue booting an OS image; caller already has:
96 * - copied image header to global variable `header'
97 * - checked header magic number, checksums (both header & image),
98 * - verified image architecture (PPC) and type (KERNEL or MULTI),
99 * - loaded (first part of) image to header load address,
100 * - disabled interrupts.
102 typedef int boot_os_fn (int flag, int argc, char *argv[],
103 bootm_headers_t *images); /* pointers to os/initrd/fdt */
105 extern boot_os_fn do_bootm_linux;
106 static boot_os_fn do_bootm_netbsd;
107 #if defined(CONFIG_LYNXKDI)
108 static boot_os_fn do_bootm_lynxkdi;
109 extern void lynxkdi_boot (image_header_t *);
111 static boot_os_fn do_bootm_rtems;
112 #if defined(CONFIG_CMD_ELF)
113 static boot_os_fn do_bootm_vxworks;
114 static boot_os_fn do_bootm_qnxelf;
115 int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
116 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
118 #if defined(CONFIG_INTEGRITY)
119 static boot_os_fn do_bootm_integrity;
122 boot_os_fn * boot_os[] = {
123 [IH_OS_LINUX] = do_bootm_linux,
124 [IH_OS_NETBSD] = do_bootm_netbsd,
125 #ifdef CONFIG_LYNXKDI
126 [IH_OS_LYNXOS] = do_bootm_lynxkdi,
128 [IH_OS_RTEMS] = do_bootm_rtems,
129 #if defined(CONFIG_CMD_ELF)
130 [IH_OS_VXWORKS] = do_bootm_vxworks,
131 [IH_OS_QNX] = do_bootm_qnxelf,
133 #ifdef CONFIG_INTEGRITY
134 [IH_OS_INTEGRITY] = do_bootm_integrity,
138 ulong load_addr = CONFIG_SYS_LOAD_ADDR; /* Default Load Address */
139 static bootm_headers_t images; /* pointers to os/initrd/fdt images */
141 void __board_lmb_reserve(struct lmb *lmb)
143 /* please define platform specific board_lmb_reserve() */
145 void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
147 void __arch_lmb_reserve(struct lmb *lmb)
149 /* please define platform specific arch_lmb_reserve() */
151 void arch_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__arch_lmb_reserve")));
154 #define IH_INITRD_ARCH IH_ARCH_ARM
155 #elif defined(__avr32__)
156 #define IH_INITRD_ARCH IH_ARCH_AVR32
157 #elif defined(__bfin__)
158 #define IH_INITRD_ARCH IH_ARCH_BLACKFIN
159 #elif defined(__I386__)
160 #define IH_INITRD_ARCH IH_ARCH_I386
161 #elif defined(__M68K__)
162 #define IH_INITRD_ARCH IH_ARCH_M68K
163 #elif defined(__microblaze__)
164 #define IH_INITRD_ARCH IH_ARCH_MICROBLAZE
165 #elif defined(__mips__)
166 #define IH_INITRD_ARCH IH_ARCH_MIPS
167 #elif defined(__nios__)
168 #define IH_INITRD_ARCH IH_ARCH_NIOS
169 #elif defined(__nios2__)
170 #define IH_INITRD_ARCH IH_ARCH_NIOS2
171 #elif defined(__PPC__)
172 #define IH_INITRD_ARCH IH_ARCH_PPC
173 #elif defined(__sh__)
174 #define IH_INITRD_ARCH IH_ARCH_SH
175 #elif defined(__sparc__)
176 #define IH_INITRD_ARCH IH_ARCH_SPARC
178 # error Unknown CPU type
181 static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
184 phys_size_t mem_size;
188 memset ((void *)&images, 0, sizeof (images));
189 images.verify = getenv_yesno ("verify");
191 lmb_init(&images.lmb);
193 mem_start = getenv_bootm_low();
194 mem_size = getenv_bootm_size();
196 lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
198 arch_lmb_reserve(&images.lmb);
199 board_lmb_reserve(&images.lmb);
201 /* get kernel image header, start address and length */
202 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
203 &images, &images.os.image_start, &images.os.image_len);
204 if (images.os.image_len == 0) {
205 puts ("ERROR: can't get kernel image!\n");
209 /* get image parameters */
210 switch (genimg_get_format (os_hdr)) {
211 case IMAGE_FORMAT_LEGACY:
212 images.os.type = image_get_type (os_hdr);
213 images.os.comp = image_get_comp (os_hdr);
214 images.os.os = image_get_os (os_hdr);
216 images.os.end = image_get_image_end (os_hdr);
217 images.os.load = image_get_load (os_hdr);
219 #if defined(CONFIG_FIT)
220 case IMAGE_FORMAT_FIT:
221 if (fit_image_get_type (images.fit_hdr_os,
222 images.fit_noffset_os, &images.os.type)) {
223 puts ("Can't get image type!\n");
224 show_boot_progress (-109);
228 if (fit_image_get_comp (images.fit_hdr_os,
229 images.fit_noffset_os, &images.os.comp)) {
230 puts ("Can't get image compression!\n");
231 show_boot_progress (-110);
235 if (fit_image_get_os (images.fit_hdr_os,
236 images.fit_noffset_os, &images.os.os)) {
237 puts ("Can't get image OS!\n");
238 show_boot_progress (-111);
242 images.os.end = fit_get_end (images.fit_hdr_os);
244 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
246 puts ("Can't get image load address!\n");
247 show_boot_progress (-112);
253 puts ("ERROR: unknown image format type!\n");
257 /* find kernel entry point */
258 if (images.legacy_hdr_valid) {
259 images.ep = image_get_ep (&images.legacy_hdr_os_copy);
260 #if defined(CONFIG_FIT)
261 } else if (images.fit_uname_os) {
262 ret = fit_image_get_entry (images.fit_hdr_os,
263 images.fit_noffset_os, &images.ep);
265 puts ("Can't get entry point property!\n");
270 puts ("Could not find kernel entry point!\n");
274 if (images.os.os == IH_OS_LINUX) {
276 ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
277 &images.rd_start, &images.rd_end);
279 puts ("Ramdisk image is corrupt or invalid\n");
283 #if defined(CONFIG_OF_LIBFDT)
284 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
285 /* find flattened device tree */
286 ret = boot_get_fdt (flag, argc, argv, &images,
287 &images.ft_addr, &images.ft_len);
289 puts ("Could not find a valid device tree\n");
293 set_working_fdt_addr(images.ft_addr);
298 images.os.start = (ulong)os_hdr;
304 #define BOOTM_ERR_RESET -1
305 #define BOOTM_ERR_OVERLAP -2
306 #define BOOTM_ERR_UNIMPLEMENTED -3
307 static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
309 uint8_t comp = os.comp;
310 ulong load = os.load;
311 ulong blob_start = os.start;
312 ulong blob_end = os.end;
313 ulong image_start = os.image_start;
314 ulong image_len = os.image_len;
315 uint unc_len = CONFIG_SYS_BOOTM_LEN;
317 const char *type_name = genimg_get_type_name (os.type);
321 if (load == blob_start) {
322 printf (" XIP %s ... ", type_name);
324 printf (" Loading %s ... ", type_name);
326 memmove_wd ((void *)load,
327 (void *)image_start, image_len, CHUNKSZ);
329 *load_end = load + image_len;
333 printf (" Uncompressing %s ... ", type_name);
334 if (gunzip ((void *)load, unc_len,
335 (uchar *)image_start, &image_len) != 0) {
336 puts ("GUNZIP: uncompress or overwrite error "
337 "- must RESET board to recover\n");
339 show_boot_progress (-6);
340 return BOOTM_ERR_RESET;
343 *load_end = load + image_len;
347 printf (" Uncompressing %s ... ", type_name);
349 * If we've got less than 4 MB of malloc() space,
350 * use slower decompression algorithm which requires
351 * at most 2300 KB of memory.
353 int i = BZ2_bzBuffToBuffDecompress ((char*)load,
354 &unc_len, (char *)image_start, image_len,
355 CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
357 printf ("BUNZIP2: uncompress or overwrite error %d "
358 "- must RESET board to recover\n", i);
360 show_boot_progress (-6);
361 return BOOTM_ERR_RESET;
364 *load_end = load + unc_len;
366 #endif /* CONFIG_BZIP2 */
369 printf (" Uncompressing %s ... ", type_name);
371 int ret = lzmaBuffToBuffDecompress(
372 (unsigned char *)load, &unc_len,
373 (unsigned char *)image_start, image_len);
374 if (ret != LZMA_RESULT_OK) {
375 printf ("LZMA: uncompress or overwrite error %d "
376 "- must RESET board to recover\n", ret);
377 show_boot_progress (-6);
378 return BOOTM_ERR_RESET;
380 *load_end = load + unc_len;
382 #endif /* CONFIG_LZMA */
384 printf ("Unimplemented compression type %d\n", comp);
385 return BOOTM_ERR_UNIMPLEMENTED;
388 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
390 show_boot_progress (7);
392 if ((load < blob_end) && (*load_end > blob_start)) {
393 debug ("images.os.start = 0x%lX, images.os.end = 0x%lx\n", blob_start, blob_end);
394 debug ("images.os.load = 0x%lx, load_end = 0x%lx\n", load, *load_end);
396 return BOOTM_ERR_OVERLAP;
402 /*******************************************************************/
403 /* bootm - boot application image from image in memory */
404 /*******************************************************************/
405 static int relocated = 0;
407 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
414 /* relocate boot function table */
417 for (i = 0; i < ARRAY_SIZE(boot_os); i++)
418 boot_os[i] += gd->reloc_off;
422 if (bootm_start(cmdtp, flag, argc, argv))
426 * We have reached the point of no return: we are going to
427 * overwrite all exception vector code, so we cannot easily
428 * recover from any failures any more...
430 iflag = disable_interrupts();
432 #if defined(CONFIG_CMD_USB)
434 * turn off USB to prevent the host controller from writing to the
435 * SDRAM while Linux is booting. This could happen (at least for OHCI
436 * controller), because the HCCA (Host Controller Communication Area)
437 * lies within the SDRAM and the host controller writes continously to
438 * this area (as busmaster!). The HccaFrameNumber is for example
439 * updated every 1 ms within the HCCA structure in SDRAM! For more
440 * details see the OpenHCI specification.
445 #ifdef CONFIG_AMIGAONEG3SE
447 * We've possible left the caches enabled during
448 * bios emulation, so turn them off again
454 ret = bootm_load_os(images.os, &load_end, 1);
457 if (ret == BOOTM_ERR_RESET)
458 do_reset (cmdtp, flag, argc, argv);
459 if (ret == BOOTM_ERR_OVERLAP) {
460 if (images.legacy_hdr_valid) {
461 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
462 puts ("WARNING: legacy format multi component "
463 "image overwritten\n");
465 puts ("ERROR: new format image overwritten - "
466 "must RESET the board to recover\n");
467 show_boot_progress (-113);
468 do_reset (cmdtp, flag, argc, argv);
471 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
474 show_boot_progress (-7);
479 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
481 show_boot_progress (8);
483 #ifdef CONFIG_SILENT_CONSOLE
484 if (images.os.os == IH_OS_LINUX)
485 fixup_silent_linux();
488 boot_fn = boot_os[images.os.os];
489 boot_fn(0, argc, argv, &images);
491 show_boot_progress (-9);
493 puts ("\n## Control returned to monitor - resetting...\n");
495 do_reset (cmdtp, flag, argc, argv);
501 * image_get_kernel - verify legacy format kernel image
502 * @img_addr: in RAM address of the legacy format image to be verified
503 * @verify: data CRC verification flag
505 * image_get_kernel() verifies legacy image integrity and returns pointer to
506 * legacy image header if image verification was completed successfully.
509 * pointer to a legacy image header if valid image was found
510 * otherwise return NULL
512 static image_header_t *image_get_kernel (ulong img_addr, int verify)
514 image_header_t *hdr = (image_header_t *)img_addr;
516 if (!image_check_magic(hdr)) {
517 puts ("Bad Magic Number\n");
518 show_boot_progress (-1);
521 show_boot_progress (2);
523 if (!image_check_hcrc (hdr)) {
524 puts ("Bad Header Checksum\n");
525 show_boot_progress (-2);
529 show_boot_progress (3);
530 image_print_contents (hdr);
533 puts (" Verifying Checksum ... ");
534 if (!image_check_dcrc (hdr)) {
535 printf ("Bad Data CRC\n");
536 show_boot_progress (-3);
541 show_boot_progress (4);
543 if (!image_check_target_arch (hdr)) {
544 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
545 show_boot_progress (-4);
552 * fit_check_kernel - verify FIT format kernel subimage
553 * @fit_hdr: pointer to the FIT image header
554 * os_noffset: kernel subimage node offset within FIT image
555 * @verify: data CRC verification flag
557 * fit_check_kernel() verifies integrity of the kernel subimage and from
558 * specified FIT image.
564 #if defined (CONFIG_FIT)
565 static int fit_check_kernel (const void *fit, int os_noffset, int verify)
567 fit_image_print (fit, os_noffset, " ");
570 puts (" Verifying Hash Integrity ... ");
571 if (!fit_image_check_hashes (fit, os_noffset)) {
572 puts ("Bad Data Hash\n");
573 show_boot_progress (-104);
578 show_boot_progress (105);
580 if (!fit_image_check_target_arch (fit, os_noffset)) {
581 puts ("Unsupported Architecture\n");
582 show_boot_progress (-105);
586 show_boot_progress (106);
587 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
588 puts ("Not a kernel image\n");
589 show_boot_progress (-106);
593 show_boot_progress (107);
596 #endif /* CONFIG_FIT */
599 * boot_get_kernel - find kernel image
600 * @os_data: pointer to a ulong variable, will hold os data start address
601 * @os_len: pointer to a ulong variable, will hold os data length
603 * boot_get_kernel() tries to find a kernel image, verifies its integrity
604 * and locates kernel data.
607 * pointer to image header if valid image was found, plus kernel start
608 * address and length, otherwise NULL
610 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
611 bootm_headers_t *images, ulong *os_data, ulong *os_len)
615 #if defined(CONFIG_FIT)
617 const char *fit_uname_config = NULL;
618 const char *fit_uname_kernel = NULL;
625 /* find out kernel image address */
627 img_addr = load_addr;
628 debug ("* kernel: default image load address = 0x%08lx\n",
630 #if defined(CONFIG_FIT)
631 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
632 &fit_uname_config)) {
633 debug ("* kernel: config '%s' from image at 0x%08lx\n",
634 fit_uname_config, img_addr);
635 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
636 &fit_uname_kernel)) {
637 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
638 fit_uname_kernel, img_addr);
641 img_addr = simple_strtoul(argv[1], NULL, 16);
642 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
645 show_boot_progress (1);
647 /* copy from dataflash if needed */
648 img_addr = genimg_get_image (img_addr);
650 /* check image type, for FIT images get FIT kernel node */
651 *os_data = *os_len = 0;
652 switch (genimg_get_format ((void *)img_addr)) {
653 case IMAGE_FORMAT_LEGACY:
654 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
656 hdr = image_get_kernel (img_addr, images->verify);
659 show_boot_progress (5);
661 /* get os_data and os_len */
662 switch (image_get_type (hdr)) {
664 *os_data = image_get_data (hdr);
665 *os_len = image_get_data_size (hdr);
668 image_multi_getimg (hdr, 0, os_data, os_len);
671 printf ("Wrong Image Type for %s command\n", cmdtp->name);
672 show_boot_progress (-5);
677 * copy image header to allow for image overwrites during kernel
680 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
682 /* save pointer to image header */
683 images->legacy_hdr_os = hdr;
685 images->legacy_hdr_valid = 1;
686 show_boot_progress (6);
688 #if defined(CONFIG_FIT)
689 case IMAGE_FORMAT_FIT:
690 fit_hdr = (void *)img_addr;
691 printf ("## Booting kernel from FIT Image at %08lx ...\n",
694 if (!fit_check_format (fit_hdr)) {
695 puts ("Bad FIT kernel image format!\n");
696 show_boot_progress (-100);
699 show_boot_progress (100);
701 if (!fit_uname_kernel) {
703 * no kernel image node unit name, try to get config
704 * node first. If config unit node name is NULL
705 * fit_conf_get_node() will try to find default config node
707 show_boot_progress (101);
708 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
709 if (cfg_noffset < 0) {
710 show_boot_progress (-101);
713 /* save configuration uname provided in the first
716 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
717 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
718 show_boot_progress (103);
720 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
721 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
723 /* get kernel component image node offset */
724 show_boot_progress (102);
725 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
727 if (os_noffset < 0) {
728 show_boot_progress (-103);
732 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
734 show_boot_progress (104);
735 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
738 /* get kernel image data address and length */
739 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
740 puts ("Could not find kernel subimage data!\n");
741 show_boot_progress (-107);
744 show_boot_progress (108);
747 *os_data = (ulong)data;
748 images->fit_hdr_os = fit_hdr;
749 images->fit_uname_os = fit_uname_kernel;
750 images->fit_noffset_os = os_noffset;
754 printf ("Wrong Image Format for %s command\n", cmdtp->name);
755 show_boot_progress (-108);
759 debug (" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
760 *os_data, *os_len, *os_len);
762 return (void *)img_addr;
766 bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
767 "bootm - boot application image from memory\n",
768 "[addr [arg ...]]\n - boot application image stored in memory\n"
769 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
770 "\t'arg' can be the address of an initrd image\n"
771 #if defined(CONFIG_OF_LIBFDT)
772 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
773 "\ta third argument is required which is the address of the\n"
774 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
775 "\tuse a '-' for the second argument. If you do not pass a third\n"
776 "\ta bd_info struct will be passed instead\n"
778 #if defined(CONFIG_FIT)
779 "\t\nFor the new multi component uImage format (FIT) addresses\n"
780 "\tmust be extened to include component or configuration unit name:\n"
781 "\taddr:<subimg_uname> - direct component image specification\n"
782 "\taddr#<conf_uname> - configuration specification\n"
783 "\tUse iminfo command to get the list of existing component\n"
784 "\timages and configurations.\n"
788 /*******************************************************************/
789 /* bootd - boot default image */
790 /*******************************************************************/
791 #if defined(CONFIG_CMD_BOOTD)
792 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
796 #ifndef CONFIG_SYS_HUSH_PARSER
797 if (run_command (getenv ("bootcmd"), flag) < 0)
800 if (parse_string_outer (getenv ("bootcmd"),
801 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
808 boot, 1, 1, do_bootd,
809 "boot - boot default, i.e., run 'bootcmd'\n",
813 /* keep old command name "bootd" for backward compatibility */
815 bootd, 1, 1, do_bootd,
816 "bootd - boot default, i.e., run 'bootcmd'\n",
823 /*******************************************************************/
824 /* iminfo - print header info for a requested image */
825 /*******************************************************************/
826 #if defined(CONFIG_CMD_IMI)
827 int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
834 return image_info (load_addr);
837 for (arg = 1; arg < argc; ++arg) {
838 addr = simple_strtoul (argv[arg], NULL, 16);
839 if (image_info (addr) != 0)
845 static int image_info (ulong addr)
847 void *hdr = (void *)addr;
849 printf ("\n## Checking Image at %08lx ...\n", addr);
851 switch (genimg_get_format (hdr)) {
852 case IMAGE_FORMAT_LEGACY:
853 puts (" Legacy image found\n");
854 if (!image_check_magic (hdr)) {
855 puts (" Bad Magic Number\n");
859 if (!image_check_hcrc (hdr)) {
860 puts (" Bad Header Checksum\n");
864 image_print_contents (hdr);
866 puts (" Verifying Checksum ... ");
867 if (!image_check_dcrc (hdr)) {
868 puts (" Bad Data CRC\n");
873 #if defined(CONFIG_FIT)
874 case IMAGE_FORMAT_FIT:
875 puts (" FIT image found\n");
877 if (!fit_check_format (hdr)) {
878 puts ("Bad FIT image format!\n");
882 fit_print_contents (hdr);
884 if (!fit_all_image_check_hashes (hdr)) {
885 puts ("Bad hash in FIT image!\n");
892 puts ("Unknown image format!\n");
900 iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
901 "iminfo - print header information for application image\n",
903 " - print header information for application image starting at\n"
904 " address 'addr' in memory; this includes verification of the\n"
905 " image contents (magic number, header and payload checksums)\n"
910 /*******************************************************************/
911 /* imls - list all images found in flash */
912 /*******************************************************************/
913 #if defined(CONFIG_CMD_IMLS)
914 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
920 for (i = 0, info = &flash_info[0];
921 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
923 if (info->flash_id == FLASH_UNKNOWN)
925 for (j = 0; j < info->sector_count; ++j) {
927 hdr = (void *)info->start[j];
931 switch (genimg_get_format (hdr)) {
932 case IMAGE_FORMAT_LEGACY:
933 if (!image_check_hcrc (hdr))
936 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
937 image_print_contents (hdr);
939 puts (" Verifying Checksum ... ");
940 if (!image_check_dcrc (hdr)) {
941 puts ("Bad Data CRC\n");
946 #if defined(CONFIG_FIT)
947 case IMAGE_FORMAT_FIT:
948 if (!fit_check_format (hdr))
951 printf ("FIT Image at %08lX:\n", (ulong)hdr);
952 fit_print_contents (hdr);
969 "imls - list all images found in flash\n",
971 " - Prints information about all images found at sector\n"
972 " boundaries in flash.\n"
976 /*******************************************************************/
977 /* helper routines */
978 /*******************************************************************/
979 #ifdef CONFIG_SILENT_CONSOLE
980 static void fixup_silent_linux ()
982 char buf[256], *start, *end;
983 char *cmdline = getenv ("bootargs");
985 /* Only fix cmdline when requested */
986 if (!(gd->flags & GD_FLG_SILENT))
989 debug ("before silent fix-up: %s\n", cmdline);
991 if ((start = strstr (cmdline, "console=")) != NULL) {
992 end = strchr (start, ' ');
993 strncpy (buf, cmdline, (start - cmdline + 8));
995 strcpy (buf + (start - cmdline + 8), end);
997 buf[start - cmdline + 8] = '\0';
999 strcpy (buf, cmdline);
1000 strcat (buf, " console=");
1003 strcpy (buf, "console=");
1006 setenv ("bootargs", buf);
1007 debug ("after silent fix-up: %s\n", buf);
1009 #endif /* CONFIG_SILENT_CONSOLE */
1012 /*******************************************************************/
1013 /* OS booting routines */
1014 /*******************************************************************/
1016 static int do_bootm_netbsd (int flag, int argc, char *argv[],
1017 bootm_headers_t *images)
1019 void (*loader)(bd_t *, image_header_t *, char *, char *);
1020 image_header_t *os_hdr, *hdr;
1021 ulong kernel_data, kernel_len;
1025 #if defined(CONFIG_FIT)
1026 if (!images->legacy_hdr_valid) {
1027 fit_unsupported_reset ("NetBSD");
1031 hdr = images->legacy_hdr_os;
1034 * Booting a (NetBSD) kernel image
1036 * This process is pretty similar to a standalone application:
1037 * The (first part of an multi-) image must be a stage-2 loader,
1038 * which in turn is responsible for loading & invoking the actual
1039 * kernel. The only differences are the parameters being passed:
1040 * besides the board info strucure, the loader expects a command
1041 * line, the name of the console device, and (optionally) the
1042 * address of the original image header.
1045 if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1046 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
1052 #if defined (CONFIG_8xx_CONS_SMC1)
1054 #elif defined (CONFIG_8xx_CONS_SMC2)
1056 #elif defined (CONFIG_8xx_CONS_SCC2)
1058 #elif defined (CONFIG_8xx_CONS_SCC3)
1066 for (i = 2, len = 0; i < argc; i += 1)
1067 len += strlen (argv[i]) + 1;
1068 cmdline = malloc (len);
1070 for (i = 2, len = 0; i < argc; i += 1) {
1072 cmdline[len++] = ' ';
1073 strcpy (&cmdline[len], argv[i]);
1074 len += strlen (argv[i]);
1076 } else if ((cmdline = getenv ("bootargs")) == NULL) {
1080 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
1082 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
1085 show_boot_progress (15);
1088 * NetBSD Stage-2 Loader Parameters:
1089 * r3: ptr to board info data
1091 * r5: console device
1092 * r6: boot args string
1094 (*loader) (gd->bd, os_hdr, consdev, cmdline);
1099 #ifdef CONFIG_LYNXKDI
1100 static int do_bootm_lynxkdi (int flag, int argc, char *argv[],
1101 bootm_headers_t *images)
1103 image_header_t *hdr = &images->legacy_hdr_os_copy;
1105 #if defined(CONFIG_FIT)
1106 if (!images->legacy_hdr_valid) {
1107 fit_unsupported_reset ("Lynx");
1112 lynxkdi_boot ((image_header_t *)hdr);
1116 #endif /* CONFIG_LYNXKDI */
1118 static int do_bootm_rtems (int flag, int argc, char *argv[],
1119 bootm_headers_t *images)
1121 void (*entry_point)(bd_t *);
1123 #if defined(CONFIG_FIT)
1124 if (!images->legacy_hdr_valid) {
1125 fit_unsupported_reset ("RTEMS");
1130 entry_point = (void (*)(bd_t *))images->ep;
1132 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1133 (ulong)entry_point);
1135 show_boot_progress (15);
1139 * r3: ptr to board info data
1141 (*entry_point)(gd->bd);
1146 #if defined(CONFIG_CMD_ELF)
1147 static int do_bootm_vxworks (int flag, int argc, char *argv[],
1148 bootm_headers_t *images)
1152 #if defined(CONFIG_FIT)
1153 if (!images->legacy_hdr_valid) {
1154 fit_unsupported_reset ("VxWorks");
1159 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1160 setenv("loadaddr", str);
1161 do_bootvx(NULL, 0, 0, NULL);
1166 static int do_bootm_qnxelf(int flag, int argc, char *argv[],
1167 bootm_headers_t *images)
1169 char *local_args[2];
1172 #if defined(CONFIG_FIT)
1173 if (!images->legacy_hdr_valid) {
1174 fit_unsupported_reset ("QNX");
1179 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1180 local_args[0] = argv[0];
1181 local_args[1] = str; /* and provide it via the arguments */
1182 do_bootelf(NULL, 0, 2, local_args);
1188 #ifdef CONFIG_INTEGRITY
1189 static int do_bootm_integrity (int flag, int argc, char *argv[],
1190 bootm_headers_t *images)
1192 void (*entry_point)(void);
1194 #if defined(CONFIG_FIT)
1195 if (!images->legacy_hdr_valid) {
1196 fit_unsupported_reset ("INTEGRITY");
1201 entry_point = (void (*)(void))images->ep;
1203 printf ("## Transferring control to INTEGRITY (at address %08lx) ...\n",
1204 (ulong)entry_point);
1206 show_boot_progress (15);
1209 * INTEGRITY Parameters: