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 ulong load_addr = CONFIG_SYS_LOAD_ADDR; /* Default Load Address */
123 static bootm_headers_t images; /* pointers to os/initrd/fdt images */
125 void __board_lmb_reserve(struct lmb *lmb)
127 /* please define platform specific board_lmb_reserve() */
129 void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
131 void __arch_lmb_reserve(struct lmb *lmb)
133 /* please define platform specific arch_lmb_reserve() */
135 void arch_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__arch_lmb_reserve")));
138 #define IH_INITRD_ARCH IH_ARCH_ARM
139 #elif defined(__avr32__)
140 #define IH_INITRD_ARCH IH_ARCH_AVR32
141 #elif defined(__bfin__)
142 #define IH_INITRD_ARCH IH_ARCH_BLACKFIN
143 #elif defined(__I386__)
144 #define IH_INITRD_ARCH IH_ARCH_I386
145 #elif defined(__M68K__)
146 #define IH_INITRD_ARCH IH_ARCH_M68K
147 #elif defined(__microblaze__)
148 #define IH_INITRD_ARCH IH_ARCH_MICROBLAZE
149 #elif defined(__mips__)
150 #define IH_INITRD_ARCH IH_ARCH_MIPS
151 #elif defined(__nios__)
152 #define IH_INITRD_ARCH IH_ARCH_NIOS
153 #elif defined(__nios2__)
154 #define IH_INITRD_ARCH IH_ARCH_NIOS2
155 #elif defined(__PPC__)
156 #define IH_INITRD_ARCH IH_ARCH_PPC
157 #elif defined(__sh__)
158 #define IH_INITRD_ARCH IH_ARCH_SH
159 #elif defined(__sparc__)
160 #define IH_INITRD_ARCH IH_ARCH_SPARC
162 # error Unknown CPU type
165 static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
168 phys_size_t mem_size;
172 memset ((void *)&images, 0, sizeof (images));
173 images.verify = getenv_yesno ("verify");
175 lmb_init(&images.lmb);
177 mem_start = getenv_bootm_low();
178 mem_size = getenv_bootm_size();
180 lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
182 arch_lmb_reserve(&images.lmb);
183 board_lmb_reserve(&images.lmb);
185 /* get kernel image header, start address and length */
186 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
187 &images, &images.os.image_start, &images.os.image_len);
188 if (images.os.image_len == 0) {
189 puts ("ERROR: can't get kernel image!\n");
193 /* get image parameters */
194 switch (genimg_get_format (os_hdr)) {
195 case IMAGE_FORMAT_LEGACY:
196 images.os.type = image_get_type (os_hdr);
197 images.os.comp = image_get_comp (os_hdr);
198 images.os.os = image_get_os (os_hdr);
200 images.os.end = image_get_image_end (os_hdr);
201 images.os.load = image_get_load (os_hdr);
203 #if defined(CONFIG_FIT)
204 case IMAGE_FORMAT_FIT:
205 if (fit_image_get_type (images.fit_hdr_os,
206 images.fit_noffset_os, &images.os.type)) {
207 puts ("Can't get image type!\n");
208 show_boot_progress (-109);
212 if (fit_image_get_comp (images.fit_hdr_os,
213 images.fit_noffset_os, &images.os.comp)) {
214 puts ("Can't get image compression!\n");
215 show_boot_progress (-110);
219 if (fit_image_get_os (images.fit_hdr_os,
220 images.fit_noffset_os, &images.os.os)) {
221 puts ("Can't get image OS!\n");
222 show_boot_progress (-111);
226 images.os.end = fit_get_end (images.fit_hdr_os);
228 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
230 puts ("Can't get image load address!\n");
231 show_boot_progress (-112);
237 puts ("ERROR: unknown image format type!\n");
241 /* find kernel entry point */
242 if (images.legacy_hdr_valid) {
243 images.ep = image_get_ep (&images.legacy_hdr_os_copy);
244 #if defined(CONFIG_FIT)
245 } else if (images.fit_uname_os) {
246 ret = fit_image_get_entry (images.fit_hdr_os,
247 images.fit_noffset_os, &images.ep);
249 puts ("Can't get entry point property!\n");
254 puts ("Could not find kernel entry point!\n");
258 if (images.os.os == IH_OS_LINUX) {
260 ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
261 &images.rd_start, &images.rd_end);
263 puts ("Ramdisk image is corrupt or invalid\n");
267 #if defined(CONFIG_OF_LIBFDT)
268 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
269 /* find flattened device tree */
270 ret = boot_get_fdt (flag, argc, argv, &images,
271 &images.ft_addr, &images.ft_len);
273 puts ("Could not find a valid device tree\n");
277 set_working_fdt_addr(images.ft_addr);
282 images.os.start = (ulong)os_hdr;
288 #define BOOTM_ERR_RESET -1
289 #define BOOTM_ERR_OVERLAP -2
290 #define BOOTM_ERR_UNIMPLEMENTED -3
291 static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
293 uint8_t comp = os.comp;
294 ulong load = os.load;
295 ulong blob_start = os.start;
296 ulong blob_end = os.end;
297 ulong image_start = os.image_start;
298 ulong image_len = os.image_len;
299 uint unc_len = CONFIG_SYS_BOOTM_LEN;
301 const char *type_name = genimg_get_type_name (os.type);
305 if (load == blob_start) {
306 printf (" XIP %s ... ", type_name);
308 printf (" Loading %s ... ", type_name);
310 memmove_wd ((void *)load,
311 (void *)image_start, image_len, CHUNKSZ);
313 *load_end = load + image_len;
317 printf (" Uncompressing %s ... ", type_name);
318 if (gunzip ((void *)load, unc_len,
319 (uchar *)image_start, &image_len) != 0) {
320 puts ("GUNZIP: uncompress or overwrite error "
321 "- must RESET board to recover\n");
323 show_boot_progress (-6);
324 return BOOTM_ERR_RESET;
327 *load_end = load + image_len;
331 printf (" Uncompressing %s ... ", type_name);
333 * If we've got less than 4 MB of malloc() space,
334 * use slower decompression algorithm which requires
335 * at most 2300 KB of memory.
337 int i = BZ2_bzBuffToBuffDecompress ((char*)load,
338 &unc_len, (char *)image_start, image_len,
339 CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
341 printf ("BUNZIP2: uncompress or overwrite error %d "
342 "- must RESET board to recover\n", i);
344 show_boot_progress (-6);
345 return BOOTM_ERR_RESET;
348 *load_end = load + unc_len;
350 #endif /* CONFIG_BZIP2 */
353 printf (" Uncompressing %s ... ", type_name);
355 int ret = lzmaBuffToBuffDecompress(
356 (unsigned char *)load, &unc_len,
357 (unsigned char *)image_start, image_len);
358 if (ret != LZMA_RESULT_OK) {
359 printf ("LZMA: uncompress or overwrite error %d "
360 "- must RESET board to recover\n", ret);
361 show_boot_progress (-6);
362 return BOOTM_ERR_RESET;
364 *load_end = load + unc_len;
366 #endif /* CONFIG_LZMA */
368 printf ("Unimplemented compression type %d\n", comp);
369 return BOOTM_ERR_UNIMPLEMENTED;
372 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
374 show_boot_progress (7);
376 if ((load < blob_end) && (*load_end > blob_start)) {
377 debug ("images.os.start = 0x%lX, images.os.end = 0x%lx\n", blob_start, blob_end);
378 debug ("images.os.load = 0x%lx, load_end = 0x%lx\n", load, *load_end);
380 return BOOTM_ERR_OVERLAP;
386 /*******************************************************************/
387 /* bootm - boot application image from image in memory */
388 /*******************************************************************/
389 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
396 if (bootm_start(cmdtp, flag, argc, argv))
400 * We have reached the point of no return: we are going to
401 * overwrite all exception vector code, so we cannot easily
402 * recover from any failures any more...
404 iflag = disable_interrupts();
406 #if defined(CONFIG_CMD_USB)
408 * turn off USB to prevent the host controller from writing to the
409 * SDRAM while Linux is booting. This could happen (at least for OHCI
410 * controller), because the HCCA (Host Controller Communication Area)
411 * lies within the SDRAM and the host controller writes continously to
412 * this area (as busmaster!). The HccaFrameNumber is for example
413 * updated every 1 ms within the HCCA structure in SDRAM! For more
414 * details see the OpenHCI specification.
419 #ifdef CONFIG_AMIGAONEG3SE
421 * We've possible left the caches enabled during
422 * bios emulation, so turn them off again
428 ret = bootm_load_os(images.os, &load_end, 1);
431 if (ret == BOOTM_ERR_RESET)
432 do_reset (cmdtp, flag, argc, argv);
433 if (ret == BOOTM_ERR_OVERLAP) {
434 if (images.legacy_hdr_valid) {
435 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
436 puts ("WARNING: legacy format multi component "
437 "image overwritten\n");
439 puts ("ERROR: new format image overwritten - "
440 "must RESET the board to recover\n");
441 show_boot_progress (-113);
442 do_reset (cmdtp, flag, argc, argv);
445 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
448 show_boot_progress (-7);
453 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
455 show_boot_progress (8);
457 switch (images.os.os) {
458 default: /* handled by (original) Linux case */
460 #ifdef CONFIG_SILENT_CONSOLE
461 fixup_silent_linux();
463 do_bootm_linux (0, argc, argv, &images);
467 do_bootm_netbsd (0, argc, argv, &images);
470 #ifdef CONFIG_LYNXKDI
472 do_bootm_lynxkdi (0, argc, argv, &images);
477 do_bootm_rtems (0, argc, argv, &images);
480 #if defined(CONFIG_CMD_ELF)
482 do_bootm_vxworks (0, argc, argv, &images);
486 do_bootm_qnxelf (0, argc, argv, &images);
490 #ifdef CONFIG_INTEGRITY
491 case IH_OS_INTEGRITY:
492 do_bootm_integrity (0, argc, argv, &images);
497 show_boot_progress (-9);
499 puts ("\n## Control returned to monitor - resetting...\n");
501 do_reset (cmdtp, flag, argc, argv);
507 * image_get_kernel - verify legacy format kernel image
508 * @img_addr: in RAM address of the legacy format image to be verified
509 * @verify: data CRC verification flag
511 * image_get_kernel() verifies legacy image integrity and returns pointer to
512 * legacy image header if image verification was completed successfully.
515 * pointer to a legacy image header if valid image was found
516 * otherwise return NULL
518 static image_header_t *image_get_kernel (ulong img_addr, int verify)
520 image_header_t *hdr = (image_header_t *)img_addr;
522 if (!image_check_magic(hdr)) {
523 puts ("Bad Magic Number\n");
524 show_boot_progress (-1);
527 show_boot_progress (2);
529 if (!image_check_hcrc (hdr)) {
530 puts ("Bad Header Checksum\n");
531 show_boot_progress (-2);
535 show_boot_progress (3);
536 image_print_contents (hdr);
539 puts (" Verifying Checksum ... ");
540 if (!image_check_dcrc (hdr)) {
541 printf ("Bad Data CRC\n");
542 show_boot_progress (-3);
547 show_boot_progress (4);
549 if (!image_check_target_arch (hdr)) {
550 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
551 show_boot_progress (-4);
558 * fit_check_kernel - verify FIT format kernel subimage
559 * @fit_hdr: pointer to the FIT image header
560 * os_noffset: kernel subimage node offset within FIT image
561 * @verify: data CRC verification flag
563 * fit_check_kernel() verifies integrity of the kernel subimage and from
564 * specified FIT image.
570 #if defined (CONFIG_FIT)
571 static int fit_check_kernel (const void *fit, int os_noffset, int verify)
573 fit_image_print (fit, os_noffset, " ");
576 puts (" Verifying Hash Integrity ... ");
577 if (!fit_image_check_hashes (fit, os_noffset)) {
578 puts ("Bad Data Hash\n");
579 show_boot_progress (-104);
584 show_boot_progress (105);
586 if (!fit_image_check_target_arch (fit, os_noffset)) {
587 puts ("Unsupported Architecture\n");
588 show_boot_progress (-105);
592 show_boot_progress (106);
593 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
594 puts ("Not a kernel image\n");
595 show_boot_progress (-106);
599 show_boot_progress (107);
602 #endif /* CONFIG_FIT */
605 * boot_get_kernel - find kernel image
606 * @os_data: pointer to a ulong variable, will hold os data start address
607 * @os_len: pointer to a ulong variable, will hold os data length
609 * boot_get_kernel() tries to find a kernel image, verifies its integrity
610 * and locates kernel data.
613 * pointer to image header if valid image was found, plus kernel start
614 * address and length, otherwise NULL
616 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
617 bootm_headers_t *images, ulong *os_data, ulong *os_len)
621 #if defined(CONFIG_FIT)
623 const char *fit_uname_config = NULL;
624 const char *fit_uname_kernel = NULL;
631 /* find out kernel image address */
633 img_addr = load_addr;
634 debug ("* kernel: default image load address = 0x%08lx\n",
636 #if defined(CONFIG_FIT)
637 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
638 &fit_uname_config)) {
639 debug ("* kernel: config '%s' from image at 0x%08lx\n",
640 fit_uname_config, img_addr);
641 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
642 &fit_uname_kernel)) {
643 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
644 fit_uname_kernel, img_addr);
647 img_addr = simple_strtoul(argv[1], NULL, 16);
648 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
651 show_boot_progress (1);
653 /* copy from dataflash if needed */
654 img_addr = genimg_get_image (img_addr);
656 /* check image type, for FIT images get FIT kernel node */
657 *os_data = *os_len = 0;
658 switch (genimg_get_format ((void *)img_addr)) {
659 case IMAGE_FORMAT_LEGACY:
660 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
662 hdr = image_get_kernel (img_addr, images->verify);
665 show_boot_progress (5);
667 /* get os_data and os_len */
668 switch (image_get_type (hdr)) {
670 *os_data = image_get_data (hdr);
671 *os_len = image_get_data_size (hdr);
674 image_multi_getimg (hdr, 0, os_data, os_len);
677 printf ("Wrong Image Type for %s command\n", cmdtp->name);
678 show_boot_progress (-5);
683 * copy image header to allow for image overwrites during kernel
686 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
688 /* save pointer to image header */
689 images->legacy_hdr_os = hdr;
691 images->legacy_hdr_valid = 1;
692 show_boot_progress (6);
694 #if defined(CONFIG_FIT)
695 case IMAGE_FORMAT_FIT:
696 fit_hdr = (void *)img_addr;
697 printf ("## Booting kernel from FIT Image at %08lx ...\n",
700 if (!fit_check_format (fit_hdr)) {
701 puts ("Bad FIT kernel image format!\n");
702 show_boot_progress (-100);
705 show_boot_progress (100);
707 if (!fit_uname_kernel) {
709 * no kernel image node unit name, try to get config
710 * node first. If config unit node name is NULL
711 * fit_conf_get_node() will try to find default config node
713 show_boot_progress (101);
714 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
715 if (cfg_noffset < 0) {
716 show_boot_progress (-101);
719 /* save configuration uname provided in the first
722 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
723 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
724 show_boot_progress (103);
726 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
727 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
729 /* get kernel component image node offset */
730 show_boot_progress (102);
731 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
733 if (os_noffset < 0) {
734 show_boot_progress (-103);
738 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
740 show_boot_progress (104);
741 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
744 /* get kernel image data address and length */
745 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
746 puts ("Could not find kernel subimage data!\n");
747 show_boot_progress (-107);
750 show_boot_progress (108);
753 *os_data = (ulong)data;
754 images->fit_hdr_os = fit_hdr;
755 images->fit_uname_os = fit_uname_kernel;
756 images->fit_noffset_os = os_noffset;
760 printf ("Wrong Image Format for %s command\n", cmdtp->name);
761 show_boot_progress (-108);
765 debug (" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
766 *os_data, *os_len, *os_len);
768 return (void *)img_addr;
772 bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
773 "bootm - boot application image from memory\n",
774 "[addr [arg ...]]\n - boot application image stored in memory\n"
775 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
776 "\t'arg' can be the address of an initrd image\n"
777 #if defined(CONFIG_OF_LIBFDT)
778 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
779 "\ta third argument is required which is the address of the\n"
780 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
781 "\tuse a '-' for the second argument. If you do not pass a third\n"
782 "\ta bd_info struct will be passed instead\n"
784 #if defined(CONFIG_FIT)
785 "\t\nFor the new multi component uImage format (FIT) addresses\n"
786 "\tmust be extened to include component or configuration unit name:\n"
787 "\taddr:<subimg_uname> - direct component image specification\n"
788 "\taddr#<conf_uname> - configuration specification\n"
789 "\tUse iminfo command to get the list of existing component\n"
790 "\timages and configurations.\n"
794 /*******************************************************************/
795 /* bootd - boot default image */
796 /*******************************************************************/
797 #if defined(CONFIG_CMD_BOOTD)
798 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
802 #ifndef CONFIG_SYS_HUSH_PARSER
803 if (run_command (getenv ("bootcmd"), flag) < 0)
806 if (parse_string_outer (getenv ("bootcmd"),
807 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
814 boot, 1, 1, do_bootd,
815 "boot - boot default, i.e., run 'bootcmd'\n",
819 /* keep old command name "bootd" for backward compatibility */
821 bootd, 1, 1, do_bootd,
822 "bootd - boot default, i.e., run 'bootcmd'\n",
829 /*******************************************************************/
830 /* iminfo - print header info for a requested image */
831 /*******************************************************************/
832 #if defined(CONFIG_CMD_IMI)
833 int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
840 return image_info (load_addr);
843 for (arg = 1; arg < argc; ++arg) {
844 addr = simple_strtoul (argv[arg], NULL, 16);
845 if (image_info (addr) != 0)
851 static int image_info (ulong addr)
853 void *hdr = (void *)addr;
855 printf ("\n## Checking Image at %08lx ...\n", addr);
857 switch (genimg_get_format (hdr)) {
858 case IMAGE_FORMAT_LEGACY:
859 puts (" Legacy image found\n");
860 if (!image_check_magic (hdr)) {
861 puts (" Bad Magic Number\n");
865 if (!image_check_hcrc (hdr)) {
866 puts (" Bad Header Checksum\n");
870 image_print_contents (hdr);
872 puts (" Verifying Checksum ... ");
873 if (!image_check_dcrc (hdr)) {
874 puts (" Bad Data CRC\n");
879 #if defined(CONFIG_FIT)
880 case IMAGE_FORMAT_FIT:
881 puts (" FIT image found\n");
883 if (!fit_check_format (hdr)) {
884 puts ("Bad FIT image format!\n");
888 fit_print_contents (hdr);
890 if (!fit_all_image_check_hashes (hdr)) {
891 puts ("Bad hash in FIT image!\n");
898 puts ("Unknown image format!\n");
906 iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
907 "iminfo - print header information for application image\n",
909 " - print header information for application image starting at\n"
910 " address 'addr' in memory; this includes verification of the\n"
911 " image contents (magic number, header and payload checksums)\n"
916 /*******************************************************************/
917 /* imls - list all images found in flash */
918 /*******************************************************************/
919 #if defined(CONFIG_CMD_IMLS)
920 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
926 for (i = 0, info = &flash_info[0];
927 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
929 if (info->flash_id == FLASH_UNKNOWN)
931 for (j = 0; j < info->sector_count; ++j) {
933 hdr = (void *)info->start[j];
937 switch (genimg_get_format (hdr)) {
938 case IMAGE_FORMAT_LEGACY:
939 if (!image_check_hcrc (hdr))
942 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
943 image_print_contents (hdr);
945 puts (" Verifying Checksum ... ");
946 if (!image_check_dcrc (hdr)) {
947 puts ("Bad Data CRC\n");
952 #if defined(CONFIG_FIT)
953 case IMAGE_FORMAT_FIT:
954 if (!fit_check_format (hdr))
957 printf ("FIT Image at %08lX:\n", (ulong)hdr);
958 fit_print_contents (hdr);
975 "imls - list all images found in flash\n",
977 " - Prints information about all images found at sector\n"
978 " boundaries in flash.\n"
982 /*******************************************************************/
983 /* helper routines */
984 /*******************************************************************/
985 #ifdef CONFIG_SILENT_CONSOLE
986 static void fixup_silent_linux ()
988 char buf[256], *start, *end;
989 char *cmdline = getenv ("bootargs");
991 /* Only fix cmdline when requested */
992 if (!(gd->flags & GD_FLG_SILENT))
995 debug ("before silent fix-up: %s\n", cmdline);
997 if ((start = strstr (cmdline, "console=")) != NULL) {
998 end = strchr (start, ' ');
999 strncpy (buf, cmdline, (start - cmdline + 8));
1001 strcpy (buf + (start - cmdline + 8), end);
1003 buf[start - cmdline + 8] = '\0';
1005 strcpy (buf, cmdline);
1006 strcat (buf, " console=");
1009 strcpy (buf, "console=");
1012 setenv ("bootargs", buf);
1013 debug ("after silent fix-up: %s\n", buf);
1015 #endif /* CONFIG_SILENT_CONSOLE */
1018 /*******************************************************************/
1019 /* OS booting routines */
1020 /*******************************************************************/
1022 static int do_bootm_netbsd (int flag, int argc, char *argv[],
1023 bootm_headers_t *images)
1025 void (*loader)(bd_t *, image_header_t *, char *, char *);
1026 image_header_t *os_hdr, *hdr;
1027 ulong kernel_data, kernel_len;
1031 #if defined(CONFIG_FIT)
1032 if (!images->legacy_hdr_valid) {
1033 fit_unsupported_reset ("NetBSD");
1037 hdr = images->legacy_hdr_os;
1040 * Booting a (NetBSD) kernel image
1042 * This process is pretty similar to a standalone application:
1043 * The (first part of an multi-) image must be a stage-2 loader,
1044 * which in turn is responsible for loading & invoking the actual
1045 * kernel. The only differences are the parameters being passed:
1046 * besides the board info strucure, the loader expects a command
1047 * line, the name of the console device, and (optionally) the
1048 * address of the original image header.
1051 if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1052 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
1058 #if defined (CONFIG_8xx_CONS_SMC1)
1060 #elif defined (CONFIG_8xx_CONS_SMC2)
1062 #elif defined (CONFIG_8xx_CONS_SCC2)
1064 #elif defined (CONFIG_8xx_CONS_SCC3)
1072 for (i = 2, len = 0; i < argc; i += 1)
1073 len += strlen (argv[i]) + 1;
1074 cmdline = malloc (len);
1076 for (i = 2, len = 0; i < argc; i += 1) {
1078 cmdline[len++] = ' ';
1079 strcpy (&cmdline[len], argv[i]);
1080 len += strlen (argv[i]);
1082 } else if ((cmdline = getenv ("bootargs")) == NULL) {
1086 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
1088 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
1091 show_boot_progress (15);
1094 * NetBSD Stage-2 Loader Parameters:
1095 * r3: ptr to board info data
1097 * r5: console device
1098 * r6: boot args string
1100 (*loader) (gd->bd, os_hdr, consdev, cmdline);
1105 #ifdef CONFIG_LYNXKDI
1106 static int do_bootm_lynxkdi (int flag, int argc, char *argv[],
1107 bootm_headers_t *images)
1109 image_header_t *hdr = &images->legacy_hdr_os_copy;
1111 #if defined(CONFIG_FIT)
1112 if (!images->legacy_hdr_valid) {
1113 fit_unsupported_reset ("Lynx");
1118 lynxkdi_boot ((image_header_t *)hdr);
1122 #endif /* CONFIG_LYNXKDI */
1124 static int do_bootm_rtems (int flag, int argc, char *argv[],
1125 bootm_headers_t *images)
1127 void (*entry_point)(bd_t *);
1129 #if defined(CONFIG_FIT)
1130 if (!images->legacy_hdr_valid) {
1131 fit_unsupported_reset ("RTEMS");
1136 entry_point = (void (*)(bd_t *))images->ep;
1138 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1139 (ulong)entry_point);
1141 show_boot_progress (15);
1145 * r3: ptr to board info data
1147 (*entry_point)(gd->bd);
1152 #if defined(CONFIG_CMD_ELF)
1153 static int do_bootm_vxworks (int flag, int argc, char *argv[],
1154 bootm_headers_t *images)
1158 #if defined(CONFIG_FIT)
1159 if (!images->legacy_hdr_valid) {
1160 fit_unsupported_reset ("VxWorks");
1165 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1166 setenv("loadaddr", str);
1167 do_bootvx(NULL, 0, 0, NULL);
1172 static int do_bootm_qnxelf(int flag, int argc, char *argv[],
1173 bootm_headers_t *images)
1175 char *local_args[2];
1178 #if defined(CONFIG_FIT)
1179 if (!images->legacy_hdr_valid) {
1180 fit_unsupported_reset ("QNX");
1185 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1186 local_args[0] = argv[0];
1187 local_args[1] = str; /* and provide it via the arguments */
1188 do_bootelf(NULL, 0, 2, local_args);
1194 #ifdef CONFIG_INTEGRITY
1195 static int do_bootm_integrity (int flag, int argc, char *argv[],
1196 bootm_headers_t *images)
1198 void (*entry_point)(void);
1200 #if defined(CONFIG_FIT)
1201 if (!images->legacy_hdr_valid) {
1202 fit_unsupported_reset ("INTEGRITY");
1207 entry_point = (void (*)(void))images->ep;
1209 printf ("## Transferring control to INTEGRITY (at address %08lx) ...\n",
1210 (ulong)entry_point);
1212 show_boot_progress (15);
1215 * INTEGRITY Parameters: