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 CFG_HUSH_PARSER
47 #if defined(CONFIG_OF_LIBFDT)
50 #include <fdt_support.h>
53 DECLARE_GLOBAL_DATA_PTR;
55 extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
57 #define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
61 extern void bz_internal_error(int);
64 #if defined(CONFIG_CMD_IMI)
65 static int image_info (unsigned long addr);
68 #if defined(CONFIG_CMD_IMLS)
70 extern flash_info_t flash_info[]; /* info for FLASH chips */
71 static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
74 #ifdef CONFIG_SILENT_CONSOLE
75 static void fixup_silent_linux (void);
78 static image_header_t *image_get_kernel (ulong img_addr, int verify);
79 #if defined(CONFIG_FIT)
80 static int fit_check_kernel (const void *fit, int os_noffset, int verify);
83 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
84 bootm_headers_t *images, ulong *os_data, ulong *os_len);
85 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
88 * Continue booting an OS image; caller already has:
89 * - copied image header to global variable `header'
90 * - checked header magic number, checksums (both header & image),
91 * - verified image architecture (PPC) and type (KERNEL or MULTI),
92 * - loaded (first part of) image to header load address,
93 * - disabled interrupts.
95 typedef int boot_os_fn (int flag, int argc, char *argv[],
96 bootm_headers_t *images); /* pointers to os/initrd/fdt */
98 extern boot_os_fn do_bootm_linux;
99 static boot_os_fn do_bootm_netbsd;
100 #if defined(CONFIG_LYNXKDI)
101 static boot_os_fn do_bootm_lynxkdi;
102 extern void lynxkdi_boot (image_header_t *);
104 static boot_os_fn do_bootm_rtems;
105 #if defined(CONFIG_CMD_ELF)
106 static boot_os_fn do_bootm_vxworks;
107 static boot_os_fn do_bootm_qnxelf;
108 int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
109 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
111 #if defined(CONFIG_INTEGRITY)
112 static boot_os_fn do_bootm_integrity;
115 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
116 static bootm_headers_t images; /* pointers to os/initrd/fdt images */
118 void __board_lmb_reserve(struct lmb *lmb)
120 /* please define platform specific board_lmb_reserve() */
122 void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
125 #define IH_INITRD_ARCH IH_ARCH_ARM
126 #elif defined(__avr32__)
127 #define IH_INITRD_ARCH IH_ARCH_AVR32
128 #elif defined(__bfin__)
129 #define IH_INITRD_ARCH IH_ARCH_BLACKFIN
130 #elif defined(__I386__)
131 #define IH_INITRD_ARCH IH_ARCH_I386
132 #elif defined(__M68K__)
133 #define IH_INITRD_ARCH IH_ARCH_M68K
134 #elif defined(__microblaze__)
135 #define IH_INITRD_ARCH IH_ARCH_MICROBLAZE
136 #elif defined(__mips__)
137 #define IH_INITRD_ARCH IH_ARCH_MIPS
138 #elif defined(__nios__)
139 #define IH_INITRD_ARCH IH_ARCH_NIOS
140 #elif defined(__nios2__)
141 #define IH_INITRD_ARCH IH_ARCH_NIOS2
142 #elif defined(__PPC__)
143 #define IH_INITRD_ARCH IH_ARCH_PPC
144 #elif defined(__sh__)
145 #define IH_INITRD_ARCH IH_ARCH_SH
146 #elif defined(__sparc__)
147 #define IH_INITRD_ARCH IH_ARCH_SPARC
149 # error Unknown CPU type
152 static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
155 phys_size_t mem_size;
159 memset ((void *)&images, 0, sizeof (images));
160 images.verify = getenv_yesno ("verify");
162 lmb_init(&images.lmb);
164 mem_start = getenv_bootm_low();
165 mem_size = getenv_bootm_size();
167 lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
169 board_lmb_reserve(&images.lmb);
171 /* get kernel image header, start address and length */
172 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
173 &images, &images.os.image_start, &images.os.image_len);
174 if (images.os.image_len == 0) {
175 puts ("ERROR: can't get kernel image!\n");
179 /* get image parameters */
180 switch (genimg_get_format (os_hdr)) {
181 case IMAGE_FORMAT_LEGACY:
182 images.os.type = image_get_type (os_hdr);
183 images.os.comp = image_get_comp (os_hdr);
184 images.os.os = image_get_os (os_hdr);
186 images.os.end = image_get_image_end (os_hdr);
187 images.os.load = image_get_load (os_hdr);
189 #if defined(CONFIG_FIT)
190 case IMAGE_FORMAT_FIT:
191 if (fit_image_get_type (images.fit_hdr_os,
192 images.fit_noffset_os, &images.os.type)) {
193 puts ("Can't get image type!\n");
194 show_boot_progress (-109);
198 if (fit_image_get_comp (images.fit_hdr_os,
199 images.fit_noffset_os, &images.os.comp)) {
200 puts ("Can't get image compression!\n");
201 show_boot_progress (-110);
205 if (fit_image_get_os (images.fit_hdr_os,
206 images.fit_noffset_os, &images.os.os)) {
207 puts ("Can't get image OS!\n");
208 show_boot_progress (-111);
212 images.os.end = fit_get_end (images.fit_hdr_os);
214 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
216 puts ("Can't get image load address!\n");
217 show_boot_progress (-112);
223 puts ("ERROR: unknown image format type!\n");
227 /* find kernel entry point */
228 if (images.legacy_hdr_valid) {
229 images.ep = image_get_ep (&images.legacy_hdr_os_copy);
230 #if defined(CONFIG_FIT)
231 } else if (images.fit_uname_os) {
232 ret = fit_image_get_entry (images.fit_hdr_os,
233 images.fit_noffset_os, &images.ep);
235 puts ("Can't get entry point property!\n");
240 puts ("Could not find kernel entry point!\n");
244 if (images.os.os == IH_OS_LINUX) {
246 ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
247 &images.rd_start, &images.rd_end);
249 puts ("Ramdisk image is corrupt or invalid\n");
253 #if defined(CONFIG_OF_LIBFDT)
254 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
255 /* find flattened device tree */
256 ret = boot_get_fdt (flag, argc, argv, &images,
257 &images.ft_addr, &images.ft_len);
259 puts ("Could not find a valid device tree\n");
263 set_working_fdt_addr(images.ft_addr);
268 images.os.start = (ulong)os_hdr;
274 #define BOOTM_ERR_RESET -1
275 #define BOOTM_ERR_OVERLAP -2
276 #define BOOTM_ERR_UNIMPLEMENTED -3
277 static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
279 uint8_t comp = os.comp;
280 ulong load = os.load;
281 ulong blob_start = os.start;
282 ulong blob_end = os.end;
283 ulong image_start = os.image_start;
284 ulong image_len = os.image_len;
285 uint unc_len = CFG_BOOTM_LEN;
287 const char *type_name = genimg_get_type_name (os.type);
291 if (load == blob_start) {
292 printf (" XIP %s ... ", type_name);
294 printf (" Loading %s ... ", type_name);
296 memmove_wd ((void *)load,
297 (void *)image_start, image_len, CHUNKSZ);
299 *load_end = load + image_len;
303 printf (" Uncompressing %s ... ", type_name);
304 if (gunzip ((void *)load, unc_len,
305 (uchar *)image_start, &image_len) != 0) {
306 puts ("GUNZIP: uncompress or overwrite error "
307 "- must RESET board to recover\n");
309 show_boot_progress (-6);
310 return BOOTM_ERR_RESET;
313 *load_end = load + image_len;
317 printf (" Uncompressing %s ... ", type_name);
319 * If we've got less than 4 MB of malloc() space,
320 * use slower decompression algorithm which requires
321 * at most 2300 KB of memory.
323 int i = BZ2_bzBuffToBuffDecompress ((char*)load,
324 &unc_len, (char *)image_start, image_len,
325 CFG_MALLOC_LEN < (4096 * 1024), 0);
327 printf ("BUNZIP2: uncompress or overwrite error %d "
328 "- must RESET board to recover\n", i);
330 show_boot_progress (-6);
331 return BOOTM_ERR_RESET;
334 *load_end = load + unc_len;
336 #endif /* CONFIG_BZIP2 */
338 printf ("Unimplemented compression type %d\n", comp);
339 return BOOTM_ERR_UNIMPLEMENTED;
342 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
344 show_boot_progress (7);
346 if ((load < blob_end) && (*load_end > blob_start)) {
347 debug ("images.os.start = 0x%lX, images.os.end = 0x%lx\n", blob_start, blob_end);
348 debug ("images.os.load = 0x%lx, load_end = 0x%lx\n", load, *load_end);
350 return BOOTM_ERR_OVERLAP;
356 /*******************************************************************/
357 /* bootm - boot application image from image in memory */
358 /*******************************************************************/
359 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
366 if (bootm_start(cmdtp, flag, argc, argv))
370 * We have reached the point of no return: we are going to
371 * overwrite all exception vector code, so we cannot easily
372 * recover from any failures any more...
374 iflag = disable_interrupts();
376 #if defined(CONFIG_CMD_USB)
378 * turn off USB to prevent the host controller from writing to the
379 * SDRAM while Linux is booting. This could happen (at least for OHCI
380 * controller), because the HCCA (Host Controller Communication Area)
381 * lies within the SDRAM and the host controller writes continously to
382 * this area (as busmaster!). The HccaFrameNumber is for example
383 * updated every 1 ms within the HCCA structure in SDRAM! For more
384 * details see the OpenHCI specification.
389 #ifdef CONFIG_AMIGAONEG3SE
391 * We've possible left the caches enabled during
392 * bios emulation, so turn them off again
398 ret = bootm_load_os(images.os, &load_end, 1);
401 if (ret == BOOTM_ERR_RESET)
402 do_reset (cmdtp, flag, argc, argv);
403 if (ret == BOOTM_ERR_OVERLAP) {
404 if (images.legacy_hdr_valid) {
405 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
406 puts ("WARNING: legacy format multi component "
407 "image overwritten\n");
409 puts ("ERROR: new format image overwritten - "
410 "must RESET the board to recover\n");
411 show_boot_progress (-113);
412 do_reset (cmdtp, flag, argc, argv);
415 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
418 show_boot_progress (-7);
423 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
425 show_boot_progress (8);
427 switch (images.os.os) {
428 default: /* handled by (original) Linux case */
430 #ifdef CONFIG_SILENT_CONSOLE
431 fixup_silent_linux();
433 do_bootm_linux (0, argc, argv, &images);
437 do_bootm_netbsd (0, argc, argv, &images);
440 #ifdef CONFIG_LYNXKDI
442 do_bootm_lynxkdi (0, argc, argv, &images);
447 do_bootm_rtems (0, argc, argv, &images);
450 #if defined(CONFIG_CMD_ELF)
452 do_bootm_vxworks (0, argc, argv, &images);
456 do_bootm_qnxelf (0, argc, argv, &images);
460 #ifdef CONFIG_INTEGRITY
461 case IH_OS_INTEGRITY:
462 do_bootm_integrity (0, argc, argv, &images);
467 show_boot_progress (-9);
469 puts ("\n## Control returned to monitor - resetting...\n");
471 do_reset (cmdtp, flag, argc, argv);
477 * image_get_kernel - verify legacy format kernel image
478 * @img_addr: in RAM address of the legacy format image to be verified
479 * @verify: data CRC verification flag
481 * image_get_kernel() verifies legacy image integrity and returns pointer to
482 * legacy image header if image verification was completed successfully.
485 * pointer to a legacy image header if valid image was found
486 * otherwise return NULL
488 static image_header_t *image_get_kernel (ulong img_addr, int verify)
490 image_header_t *hdr = (image_header_t *)img_addr;
492 if (!image_check_magic(hdr)) {
493 puts ("Bad Magic Number\n");
494 show_boot_progress (-1);
497 show_boot_progress (2);
499 if (!image_check_hcrc (hdr)) {
500 puts ("Bad Header Checksum\n");
501 show_boot_progress (-2);
505 show_boot_progress (3);
506 image_print_contents (hdr);
509 puts (" Verifying Checksum ... ");
510 if (!image_check_dcrc (hdr)) {
511 printf ("Bad Data CRC\n");
512 show_boot_progress (-3);
517 show_boot_progress (4);
519 if (!image_check_target_arch (hdr)) {
520 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
521 show_boot_progress (-4);
528 * fit_check_kernel - verify FIT format kernel subimage
529 * @fit_hdr: pointer to the FIT image header
530 * os_noffset: kernel subimage node offset within FIT image
531 * @verify: data CRC verification flag
533 * fit_check_kernel() verifies integrity of the kernel subimage and from
534 * specified FIT image.
540 #if defined (CONFIG_FIT)
541 static int fit_check_kernel (const void *fit, int os_noffset, int verify)
543 fit_image_print (fit, os_noffset, " ");
546 puts (" Verifying Hash Integrity ... ");
547 if (!fit_image_check_hashes (fit, os_noffset)) {
548 puts ("Bad Data Hash\n");
549 show_boot_progress (-104);
554 show_boot_progress (105);
556 if (!fit_image_check_target_arch (fit, os_noffset)) {
557 puts ("Unsupported Architecture\n");
558 show_boot_progress (-105);
562 show_boot_progress (106);
563 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
564 puts ("Not a kernel image\n");
565 show_boot_progress (-106);
569 show_boot_progress (107);
572 #endif /* CONFIG_FIT */
575 * boot_get_kernel - find kernel image
576 * @os_data: pointer to a ulong variable, will hold os data start address
577 * @os_len: pointer to a ulong variable, will hold os data length
579 * boot_get_kernel() tries to find a kernel image, verifies its integrity
580 * and locates kernel data.
583 * pointer to image header if valid image was found, plus kernel start
584 * address and length, otherwise NULL
586 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
587 bootm_headers_t *images, ulong *os_data, ulong *os_len)
591 #if defined(CONFIG_FIT)
593 const char *fit_uname_config = NULL;
594 const char *fit_uname_kernel = NULL;
601 /* find out kernel image address */
603 img_addr = load_addr;
604 debug ("* kernel: default image load address = 0x%08lx\n",
606 #if defined(CONFIG_FIT)
607 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
608 &fit_uname_config)) {
609 debug ("* kernel: config '%s' from image at 0x%08lx\n",
610 fit_uname_config, img_addr);
611 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
612 &fit_uname_kernel)) {
613 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
614 fit_uname_kernel, img_addr);
617 img_addr = simple_strtoul(argv[1], NULL, 16);
618 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
621 show_boot_progress (1);
623 /* copy from dataflash if needed */
624 img_addr = genimg_get_image (img_addr);
626 /* check image type, for FIT images get FIT kernel node */
627 *os_data = *os_len = 0;
628 switch (genimg_get_format ((void *)img_addr)) {
629 case IMAGE_FORMAT_LEGACY:
630 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
632 hdr = image_get_kernel (img_addr, images->verify);
635 show_boot_progress (5);
637 /* get os_data and os_len */
638 switch (image_get_type (hdr)) {
640 *os_data = image_get_data (hdr);
641 *os_len = image_get_data_size (hdr);
644 image_multi_getimg (hdr, 0, os_data, os_len);
647 printf ("Wrong Image Type for %s command\n", cmdtp->name);
648 show_boot_progress (-5);
653 * copy image header to allow for image overwrites during kernel
656 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
658 /* save pointer to image header */
659 images->legacy_hdr_os = hdr;
661 images->legacy_hdr_valid = 1;
662 show_boot_progress (6);
664 #if defined(CONFIG_FIT)
665 case IMAGE_FORMAT_FIT:
666 fit_hdr = (void *)img_addr;
667 printf ("## Booting kernel from FIT Image at %08lx ...\n",
670 if (!fit_check_format (fit_hdr)) {
671 puts ("Bad FIT kernel image format!\n");
672 show_boot_progress (-100);
675 show_boot_progress (100);
677 if (!fit_uname_kernel) {
679 * no kernel image node unit name, try to get config
680 * node first. If config unit node name is NULL
681 * fit_conf_get_node() will try to find default config node
683 show_boot_progress (101);
684 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
685 if (cfg_noffset < 0) {
686 show_boot_progress (-101);
689 /* save configuration uname provided in the first
692 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
693 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
694 show_boot_progress (103);
696 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
697 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
699 /* get kernel component image node offset */
700 show_boot_progress (102);
701 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
703 if (os_noffset < 0) {
704 show_boot_progress (-103);
708 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
710 show_boot_progress (104);
711 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
714 /* get kernel image data address and length */
715 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
716 puts ("Could not find kernel subimage data!\n");
717 show_boot_progress (-107);
720 show_boot_progress (108);
723 *os_data = (ulong)data;
724 images->fit_hdr_os = fit_hdr;
725 images->fit_uname_os = fit_uname_kernel;
726 images->fit_noffset_os = os_noffset;
730 printf ("Wrong Image Format for %s command\n", cmdtp->name);
731 show_boot_progress (-108);
735 debug (" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
736 *os_data, *os_len, *os_len);
738 return (void *)img_addr;
742 bootm, CFG_MAXARGS, 1, do_bootm,
743 "bootm - boot application image from memory\n",
744 "[addr [arg ...]]\n - boot application image stored in memory\n"
745 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
746 "\t'arg' can be the address of an initrd image\n"
747 #if defined(CONFIG_OF_LIBFDT)
748 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
749 "\ta third argument is required which is the address of the\n"
750 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
751 "\tuse a '-' for the second argument. If you do not pass a third\n"
752 "\ta bd_info struct will be passed instead\n"
754 #if defined(CONFIG_FIT)
755 "\t\nFor the new multi component uImage format (FIT) addresses\n"
756 "\tmust be extened to include component or configuration unit name:\n"
757 "\taddr:<subimg_uname> - direct component image specification\n"
758 "\taddr#<conf_uname> - configuration specification\n"
759 "\tUse iminfo command to get the list of existing component\n"
760 "\timages and configurations.\n"
764 /*******************************************************************/
765 /* bootd - boot default image */
766 /*******************************************************************/
767 #if defined(CONFIG_CMD_BOOTD)
768 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
772 #ifndef CFG_HUSH_PARSER
773 if (run_command (getenv ("bootcmd"), flag) < 0)
776 if (parse_string_outer (getenv ("bootcmd"),
777 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
784 boot, 1, 1, do_bootd,
785 "boot - boot default, i.e., run 'bootcmd'\n",
789 /* keep old command name "bootd" for backward compatibility */
791 bootd, 1, 1, do_bootd,
792 "bootd - boot default, i.e., run 'bootcmd'\n",
799 /*******************************************************************/
800 /* iminfo - print header info for a requested image */
801 /*******************************************************************/
802 #if defined(CONFIG_CMD_IMI)
803 int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
810 return image_info (load_addr);
813 for (arg = 1; arg < argc; ++arg) {
814 addr = simple_strtoul (argv[arg], NULL, 16);
815 if (image_info (addr) != 0)
821 static int image_info (ulong addr)
823 void *hdr = (void *)addr;
825 printf ("\n## Checking Image at %08lx ...\n", addr);
827 switch (genimg_get_format (hdr)) {
828 case IMAGE_FORMAT_LEGACY:
829 puts (" Legacy image found\n");
830 if (!image_check_magic (hdr)) {
831 puts (" Bad Magic Number\n");
835 if (!image_check_hcrc (hdr)) {
836 puts (" Bad Header Checksum\n");
840 image_print_contents (hdr);
842 puts (" Verifying Checksum ... ");
843 if (!image_check_dcrc (hdr)) {
844 puts (" Bad Data CRC\n");
849 #if defined(CONFIG_FIT)
850 case IMAGE_FORMAT_FIT:
851 puts (" FIT image found\n");
853 if (!fit_check_format (hdr)) {
854 puts ("Bad FIT image format!\n");
858 fit_print_contents (hdr);
860 if (!fit_all_image_check_hashes (hdr)) {
861 puts ("Bad hash in FIT image!\n");
868 puts ("Unknown image format!\n");
876 iminfo, CFG_MAXARGS, 1, do_iminfo,
877 "iminfo - print header information for application image\n",
879 " - print header information for application image starting at\n"
880 " address 'addr' in memory; this includes verification of the\n"
881 " image contents (magic number, header and payload checksums)\n"
886 /*******************************************************************/
887 /* imls - list all images found in flash */
888 /*******************************************************************/
889 #if defined(CONFIG_CMD_IMLS)
890 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
896 for (i = 0, info = &flash_info[0];
897 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
899 if (info->flash_id == FLASH_UNKNOWN)
901 for (j = 0; j < info->sector_count; ++j) {
903 hdr = (void *)info->start[j];
907 switch (genimg_get_format (hdr)) {
908 case IMAGE_FORMAT_LEGACY:
909 if (!image_check_hcrc (hdr))
912 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
913 image_print_contents (hdr);
915 puts (" Verifying Checksum ... ");
916 if (!image_check_dcrc (hdr)) {
917 puts ("Bad Data CRC\n");
922 #if defined(CONFIG_FIT)
923 case IMAGE_FORMAT_FIT:
924 if (!fit_check_format (hdr))
927 printf ("FIT Image at %08lX:\n", (ulong)hdr);
928 fit_print_contents (hdr);
945 "imls - list all images found in flash\n",
947 " - Prints information about all images found at sector\n"
948 " boundaries in flash.\n"
952 /*******************************************************************/
953 /* helper routines */
954 /*******************************************************************/
955 #ifdef CONFIG_SILENT_CONSOLE
956 static void fixup_silent_linux ()
958 char buf[256], *start, *end;
959 char *cmdline = getenv ("bootargs");
961 /* Only fix cmdline when requested */
962 if (!(gd->flags & GD_FLG_SILENT))
965 debug ("before silent fix-up: %s\n", cmdline);
967 if ((start = strstr (cmdline, "console=")) != NULL) {
968 end = strchr (start, ' ');
969 strncpy (buf, cmdline, (start - cmdline + 8));
971 strcpy (buf + (start - cmdline + 8), end);
973 buf[start - cmdline + 8] = '\0';
975 strcpy (buf, cmdline);
976 strcat (buf, " console=");
979 strcpy (buf, "console=");
982 setenv ("bootargs", buf);
983 debug ("after silent fix-up: %s\n", buf);
985 #endif /* CONFIG_SILENT_CONSOLE */
988 /*******************************************************************/
989 /* OS booting routines */
990 /*******************************************************************/
992 static int do_bootm_netbsd (int flag, int argc, char *argv[],
993 bootm_headers_t *images)
995 void (*loader)(bd_t *, image_header_t *, char *, char *);
996 image_header_t *os_hdr, *hdr;
997 ulong kernel_data, kernel_len;
1001 #if defined(CONFIG_FIT)
1002 if (!images->legacy_hdr_valid) {
1003 fit_unsupported_reset ("NetBSD");
1007 hdr = images->legacy_hdr_os;
1010 * Booting a (NetBSD) kernel image
1012 * This process is pretty similar to a standalone application:
1013 * The (first part of an multi-) image must be a stage-2 loader,
1014 * which in turn is responsible for loading & invoking the actual
1015 * kernel. The only differences are the parameters being passed:
1016 * besides the board info strucure, the loader expects a command
1017 * line, the name of the console device, and (optionally) the
1018 * address of the original image header.
1021 if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1022 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
1028 #if defined (CONFIG_8xx_CONS_SMC1)
1030 #elif defined (CONFIG_8xx_CONS_SMC2)
1032 #elif defined (CONFIG_8xx_CONS_SCC2)
1034 #elif defined (CONFIG_8xx_CONS_SCC3)
1042 for (i = 2, len = 0; i < argc; i += 1)
1043 len += strlen (argv[i]) + 1;
1044 cmdline = malloc (len);
1046 for (i = 2, len = 0; i < argc; i += 1) {
1048 cmdline[len++] = ' ';
1049 strcpy (&cmdline[len], argv[i]);
1050 len += strlen (argv[i]);
1052 } else if ((cmdline = getenv ("bootargs")) == NULL) {
1056 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
1058 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
1061 show_boot_progress (15);
1064 * NetBSD Stage-2 Loader Parameters:
1065 * r3: ptr to board info data
1067 * r5: console device
1068 * r6: boot args string
1070 (*loader) (gd->bd, os_hdr, consdev, cmdline);
1075 #ifdef CONFIG_LYNXKDI
1076 static int do_bootm_lynxkdi (int flag, int argc, char *argv[],
1077 bootm_headers_t *images)
1079 image_header_t *hdr = &images->legacy_hdr_os_copy;
1081 #if defined(CONFIG_FIT)
1082 if (!images->legacy_hdr_valid) {
1083 fit_unsupported_reset ("Lynx");
1088 lynxkdi_boot ((image_header_t *)hdr);
1092 #endif /* CONFIG_LYNXKDI */
1094 static int do_bootm_rtems (int flag, int argc, char *argv[],
1095 bootm_headers_t *images)
1097 void (*entry_point)(bd_t *);
1099 #if defined(CONFIG_FIT)
1100 if (!images->legacy_hdr_valid) {
1101 fit_unsupported_reset ("RTEMS");
1106 entry_point = (void (*)(bd_t *))images->ep;
1108 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1109 (ulong)entry_point);
1111 show_boot_progress (15);
1115 * r3: ptr to board info data
1117 (*entry_point)(gd->bd);
1122 #if defined(CONFIG_CMD_ELF)
1123 static int do_bootm_vxworks (int flag, int argc, char *argv[],
1124 bootm_headers_t *images)
1128 #if defined(CONFIG_FIT)
1129 if (!images->legacy_hdr_valid) {
1130 fit_unsupported_reset ("VxWorks");
1135 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1136 setenv("loadaddr", str);
1137 do_bootvx(NULL, 0, 0, NULL);
1142 static int do_bootm_qnxelf(int flag, int argc, char *argv[],
1143 bootm_headers_t *images)
1145 char *local_args[2];
1148 #if defined(CONFIG_FIT)
1149 if (!images->legacy_hdr_valid) {
1150 fit_unsupported_reset ("QNX");
1155 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1156 local_args[0] = argv[0];
1157 local_args[1] = str; /* and provide it via the arguments */
1158 do_bootelf(NULL, 0, 2, local_args);
1164 #ifdef CONFIG_INTEGRITY
1165 static int do_bootm_integrity (int flag, int argc, char *argv[],
1166 bootm_headers_t *images)
1168 void (*entry_point)(void);
1170 #if defined(CONFIG_FIT)
1171 if (!images->legacy_hdr_valid) {
1172 fit_unsupported_reset ("INTEGRITY");
1177 entry_point = (void (*)(void))images->ep;
1179 printf ("## Transferring control to INTEGRITY (at address %08lx) ...\n",
1180 (ulong)entry_point);
1182 show_boot_progress (15);
1185 * INTEGRITY Parameters: