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 void boot_os_fn (cmd_tbl_t *cmdtp, int flag,
96 int argc, char *argv[],
97 bootm_headers_t *images); /* pointers to os/initrd/fdt */
99 extern boot_os_fn do_bootm_linux;
100 static boot_os_fn do_bootm_netbsd;
101 #if defined(CONFIG_LYNXKDI)
102 static boot_os_fn do_bootm_lynxkdi;
103 extern void lynxkdi_boot (image_header_t *);
105 static boot_os_fn do_bootm_rtems;
106 #if defined(CONFIG_CMD_ELF)
107 static boot_os_fn do_bootm_vxworks;
108 static boot_os_fn do_bootm_qnxelf;
109 int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
110 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
112 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
113 static boot_os_fn do_bootm_artos;
116 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
117 static bootm_headers_t images; /* pointers to os/initrd/fdt images */
119 void __board_lmb_reserve(struct lmb *lmb)
121 /* please define platform specific board_lmb_reserve() */
123 void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
126 #define IH_INITRD_ARCH IH_ARCH_ARM
127 #elif defined(__avr32__)
128 #define IH_INITRD_ARCH IH_ARCH_AVR32
129 #elif defined(__bfin__)
130 #define IH_INITRD_ARCH IH_ARCH_BLACKFIN
131 #elif defined(__I386__)
132 #define IH_INITRD_ARCH IH_ARCH_I386
133 #elif defined(__M68K__)
134 #define IH_INITRD_ARCH IH_ARCH_M68K
135 #elif defined(__microblaze__)
136 #define IH_INITRD_ARCH IH_ARCH_MICROBLAZE
137 #elif defined(__mips__)
138 #define IH_INITRD_ARCH IH_ARCH_MIPS
139 #elif defined(__nios__)
140 #define IH_INITRD_ARCH IH_ARCH_NIOS
141 #elif defined(__nios2__)
142 #define IH_INITRD_ARCH IH_ARCH_NIOS2
143 #elif defined(__PPC__)
144 #define IH_INITRD_ARCH IH_ARCH_PPC
145 #elif defined(__sh__)
146 #define IH_INITRD_ARCH IH_ARCH_SH
147 #elif defined(__sparc__)
148 #define IH_INITRD_ARCH IH_ARCH_SPARC
150 # error Unknown CPU type
153 /*******************************************************************/
154 /* bootm - boot application image from image in memory */
155 /*******************************************************************/
156 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
159 const char *type_name;
160 uint unc_len = CFG_BOOTM_LEN;
161 uint8_t comp, type, os;
164 ulong os_data, os_len;
165 ulong image_start, image_end;
166 ulong load_start, load_end;
168 phys_size_t mem_size;
173 memset ((void *)&images, 0, sizeof (images));
174 images.verify = getenv_yesno ("verify");
179 mem_start = getenv_bootm_low();
180 mem_size = getenv_bootm_size();
182 lmb_add(&lmb, (phys_addr_t)mem_start, mem_size);
184 board_lmb_reserve(&lmb);
186 /* get kernel image header, start address and length */
187 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
188 &images, &os_data, &os_len);
190 puts ("ERROR: can't get kernel image!\n");
194 /* get image parameters */
195 switch (genimg_get_format (os_hdr)) {
196 case IMAGE_FORMAT_LEGACY:
197 type = image_get_type (os_hdr);
198 comp = image_get_comp (os_hdr);
199 os = image_get_os (os_hdr);
201 image_end = image_get_image_end (os_hdr);
202 load_start = image_get_load (os_hdr);
204 #if defined(CONFIG_FIT)
205 case IMAGE_FORMAT_FIT:
206 if (fit_image_get_type (images.fit_hdr_os,
207 images.fit_noffset_os, &type)) {
208 puts ("Can't get image type!\n");
209 show_boot_progress (-109);
213 if (fit_image_get_comp (images.fit_hdr_os,
214 images.fit_noffset_os, &comp)) {
215 puts ("Can't get image compression!\n");
216 show_boot_progress (-110);
220 if (fit_image_get_os (images.fit_hdr_os,
221 images.fit_noffset_os, &os)) {
222 puts ("Can't get image OS!\n");
223 show_boot_progress (-111);
227 image_end = fit_get_end (images.fit_hdr_os);
229 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
231 puts ("Can't get image load address!\n");
232 show_boot_progress (-112);
238 puts ("ERROR: unknown image format type!\n");
242 /* find kernel entry point */
243 if (images.legacy_hdr_valid) {
244 images.ep = image_get_ep (&images.legacy_hdr_os_copy);
245 #if defined(CONFIG_FIT)
246 } else if (images.fit_uname_os) {
247 ret = fit_image_get_entry (images.fit_hdr_os,
248 images.fit_noffset_os, &images.ep);
250 puts ("Can't get entry point property!\n");
255 puts ("Could not find kernel entry point!\n");
259 if (os == IH_OS_LINUX) {
261 ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
262 &images.rd_start, &images.rd_end);
264 puts ("Ramdisk image is corrupt\n");
268 #if defined(CONFIG_OF_LIBFDT)
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);
281 image_start = (ulong)os_hdr;
283 type_name = genimg_get_type_name (type);
286 * We have reached the point of no return: we are going to
287 * overwrite all exception vector code, so we cannot easily
288 * recover from any failures any more...
290 iflag = disable_interrupts();
292 #if defined(CONFIG_CMD_USB)
294 * turn off USB to prevent the host controller from writing to the
295 * SDRAM while Linux is booting. This could happen (at least for OHCI
296 * controller), because the HCCA (Host Controller Communication Area)
297 * lies within the SDRAM and the host controller writes continously to
298 * this area (as busmaster!). The HccaFrameNumber is for example
299 * updated every 1 ms within the HCCA structure in SDRAM! For more
300 * details see the OpenHCI specification.
306 #ifdef CONFIG_AMIGAONEG3SE
308 * We've possible left the caches enabled during
309 * bios emulation, so turn them off again
317 if (load_start == (ulong)os_hdr) {
318 printf (" XIP %s ... ", type_name);
320 printf (" Loading %s ... ", type_name);
322 memmove_wd ((void *)load_start,
323 (void *)os_data, os_len, CHUNKSZ);
325 load_end = load_start + os_len;
329 printf (" Uncompressing %s ... ", type_name);
330 if (gunzip ((void *)load_start, unc_len,
331 (uchar *)os_data, &os_len) != 0) {
332 puts ("GUNZIP: uncompress or overwrite error "
333 "- must RESET board to recover\n");
334 show_boot_progress (-6);
335 do_reset (cmdtp, flag, argc, argv);
338 load_end = load_start + os_len;
342 printf (" Uncompressing %s ... ", type_name);
344 * If we've got less than 4 MB of malloc() space,
345 * use slower decompression algorithm which requires
346 * at most 2300 KB of memory.
348 int i = BZ2_bzBuffToBuffDecompress ((char*)load_start,
349 &unc_len, (char *)os_data, os_len,
350 CFG_MALLOC_LEN < (4096 * 1024), 0);
352 printf ("BUNZIP2: uncompress or overwrite error %d "
353 "- must RESET board to recover\n", i);
354 show_boot_progress (-6);
355 do_reset (cmdtp, flag, argc, argv);
358 load_end = load_start + unc_len;
360 #endif /* CONFIG_BZIP2 */
364 printf ("Unimplemented compression type %d\n", comp);
365 show_boot_progress (-7);
369 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end);
370 show_boot_progress (7);
372 if ((load_start < image_end) && (load_end > image_start)) {
373 debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end);
374 debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end);
376 if (images.legacy_hdr_valid) {
377 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
378 puts ("WARNING: legacy format multi component "
379 "image overwritten\n");
381 puts ("ERROR: new format image overwritten - "
382 "must RESET the board to recover\n");
383 show_boot_progress (-113);
384 do_reset (cmdtp, flag, argc, argv);
388 show_boot_progress (8);
390 lmb_reserve(&lmb, load_start, (load_end - load_start));
393 default: /* handled by (original) Linux case */
395 #ifdef CONFIG_SILENT_CONSOLE
396 fixup_silent_linux();
398 do_bootm_linux (cmdtp, flag, argc, argv, &images);
402 do_bootm_netbsd (cmdtp, flag, argc, argv, &images);
405 #ifdef CONFIG_LYNXKDI
407 do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images);
412 do_bootm_rtems (cmdtp, flag, argc, argv, &images);
415 #if defined(CONFIG_CMD_ELF)
417 do_bootm_vxworks (cmdtp, flag, argc, argv, &images);
421 do_bootm_qnxelf (cmdtp, flag, argc, argv, &images);
427 do_bootm_artos (cmdtp, flag, argc, argv, &images);
432 show_boot_progress (-9);
434 puts ("\n## Control returned to monitor - resetting...\n");
435 do_reset (cmdtp, flag, argc, argv);
444 * image_get_kernel - verify legacy format kernel image
445 * @img_addr: in RAM address of the legacy format image to be verified
446 * @verify: data CRC verification flag
448 * image_get_kernel() verifies legacy image integrity and returns pointer to
449 * legacy image header if image verification was completed successfully.
452 * pointer to a legacy image header if valid image was found
453 * otherwise return NULL
455 static image_header_t *image_get_kernel (ulong img_addr, int verify)
457 image_header_t *hdr = (image_header_t *)img_addr;
459 if (!image_check_magic(hdr)) {
460 puts ("Bad Magic Number\n");
461 show_boot_progress (-1);
464 show_boot_progress (2);
466 if (!image_check_hcrc (hdr)) {
467 puts ("Bad Header Checksum\n");
468 show_boot_progress (-2);
472 show_boot_progress (3);
473 image_print_contents (hdr);
476 puts (" Verifying Checksum ... ");
477 if (!image_check_dcrc (hdr)) {
478 printf ("Bad Data CRC\n");
479 show_boot_progress (-3);
484 show_boot_progress (4);
486 if (!image_check_target_arch (hdr)) {
487 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
488 show_boot_progress (-4);
495 * fit_check_kernel - verify FIT format kernel subimage
496 * @fit_hdr: pointer to the FIT image header
497 * os_noffset: kernel subimage node offset within FIT image
498 * @verify: data CRC verification flag
500 * fit_check_kernel() verifies integrity of the kernel subimage and from
501 * specified FIT image.
507 #if defined (CONFIG_FIT)
508 static int fit_check_kernel (const void *fit, int os_noffset, int verify)
510 fit_image_print (fit, os_noffset, " ");
513 puts (" Verifying Hash Integrity ... ");
514 if (!fit_image_check_hashes (fit, os_noffset)) {
515 puts ("Bad Data Hash\n");
516 show_boot_progress (-104);
521 show_boot_progress (105);
523 if (!fit_image_check_target_arch (fit, os_noffset)) {
524 puts ("Unsupported Architecture\n");
525 show_boot_progress (-105);
529 show_boot_progress (106);
530 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
531 puts ("Not a kernel image\n");
532 show_boot_progress (-106);
536 show_boot_progress (107);
539 #endif /* CONFIG_FIT */
542 * boot_get_kernel - find kernel image
543 * @os_data: pointer to a ulong variable, will hold os data start address
544 * @os_len: pointer to a ulong variable, will hold os data length
546 * boot_get_kernel() tries to find a kernel image, verifies its integrity
547 * and locates kernel data.
550 * pointer to image header if valid image was found, plus kernel start
551 * address and length, otherwise NULL
553 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
554 bootm_headers_t *images, ulong *os_data, ulong *os_len)
558 #if defined(CONFIG_FIT)
560 const char *fit_uname_config = NULL;
561 const char *fit_uname_kernel = NULL;
568 /* find out kernel image address */
570 img_addr = load_addr;
571 debug ("* kernel: default image load address = 0x%08lx\n",
573 #if defined(CONFIG_FIT)
574 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
575 &fit_uname_config)) {
576 debug ("* kernel: config '%s' from image at 0x%08lx\n",
577 fit_uname_config, img_addr);
578 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
579 &fit_uname_kernel)) {
580 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
581 fit_uname_kernel, img_addr);
584 img_addr = simple_strtoul(argv[1], NULL, 16);
585 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
588 show_boot_progress (1);
590 /* copy from dataflash if needed */
591 img_addr = genimg_get_image (img_addr);
593 /* check image type, for FIT images get FIT kernel node */
594 *os_data = *os_len = 0;
595 switch (genimg_get_format ((void *)img_addr)) {
596 case IMAGE_FORMAT_LEGACY:
597 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
599 hdr = image_get_kernel (img_addr, images->verify);
602 show_boot_progress (5);
604 /* get os_data and os_len */
605 switch (image_get_type (hdr)) {
607 *os_data = image_get_data (hdr);
608 *os_len = image_get_data_size (hdr);
611 image_multi_getimg (hdr, 0, os_data, os_len);
614 printf ("Wrong Image Type for %s command\n", cmdtp->name);
615 show_boot_progress (-5);
620 * copy image header to allow for image overwrites during kernel
623 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
625 /* save pointer to image header */
626 images->legacy_hdr_os = hdr;
628 images->legacy_hdr_valid = 1;
629 show_boot_progress (6);
631 #if defined(CONFIG_FIT)
632 case IMAGE_FORMAT_FIT:
633 fit_hdr = (void *)img_addr;
634 printf ("## Booting kernel from FIT Image at %08lx ...\n",
637 if (!fit_check_format (fit_hdr)) {
638 puts ("Bad FIT kernel image format!\n");
639 show_boot_progress (-100);
642 show_boot_progress (100);
644 if (!fit_uname_kernel) {
646 * no kernel image node unit name, try to get config
647 * node first. If config unit node name is NULL
648 * fit_conf_get_node() will try to find default config node
650 show_boot_progress (101);
651 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
652 if (cfg_noffset < 0) {
653 show_boot_progress (-101);
656 /* save configuration uname provided in the first
659 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
660 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
661 show_boot_progress (103);
663 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
664 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
666 /* get kernel component image node offset */
667 show_boot_progress (102);
668 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
670 if (os_noffset < 0) {
671 show_boot_progress (-103);
675 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
677 show_boot_progress (104);
678 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
681 /* get kernel image data address and length */
682 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
683 puts ("Could not find kernel subimage data!\n");
684 show_boot_progress (-107);
687 show_boot_progress (108);
690 *os_data = (ulong)data;
691 images->fit_hdr_os = fit_hdr;
692 images->fit_uname_os = fit_uname_kernel;
693 images->fit_noffset_os = os_noffset;
697 printf ("Wrong Image Format for %s command\n", cmdtp->name);
698 show_boot_progress (-108);
702 debug (" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
703 *os_data, *os_len, *os_len);
705 return (void *)img_addr;
709 bootm, CFG_MAXARGS, 1, do_bootm,
710 "bootm - boot application image from memory\n",
711 "[addr [arg ...]]\n - boot application image stored in memory\n"
712 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
713 "\t'arg' can be the address of an initrd image\n"
714 #if defined(CONFIG_OF_LIBFDT)
715 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
716 "\ta third argument is required which is the address of the\n"
717 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
718 "\tuse a '-' for the second argument. If you do not pass a third\n"
719 "\ta bd_info struct will be passed instead\n"
721 #if defined(CONFIG_FIT)
722 "\t\nFor the new multi component uImage format (FIT) addresses\n"
723 "\tmust be extened to include component or configuration unit name:\n"
724 "\taddr:<subimg_uname> - direct component image specification\n"
725 "\taddr#<conf_uname> - configuration specification\n"
726 "\tUse iminfo command to get the list of existing component\n"
727 "\timages and configurations.\n"
731 /*******************************************************************/
732 /* bootd - boot default image */
733 /*******************************************************************/
734 #if defined(CONFIG_CMD_BOOTD)
735 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
739 #ifndef CFG_HUSH_PARSER
740 if (run_command (getenv ("bootcmd"), flag) < 0)
743 if (parse_string_outer (getenv ("bootcmd"),
744 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
751 boot, 1, 1, do_bootd,
752 "boot - boot default, i.e., run 'bootcmd'\n",
756 /* keep old command name "bootd" for backward compatibility */
758 bootd, 1, 1, do_bootd,
759 "bootd - boot default, i.e., run 'bootcmd'\n",
766 /*******************************************************************/
767 /* iminfo - print header info for a requested image */
768 /*******************************************************************/
769 #if defined(CONFIG_CMD_IMI)
770 int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
777 return image_info (load_addr);
780 for (arg = 1; arg < argc; ++arg) {
781 addr = simple_strtoul (argv[arg], NULL, 16);
782 if (image_info (addr) != 0)
788 static int image_info (ulong addr)
790 void *hdr = (void *)addr;
792 printf ("\n## Checking Image at %08lx ...\n", addr);
794 switch (genimg_get_format (hdr)) {
795 case IMAGE_FORMAT_LEGACY:
796 puts (" Legacy image found\n");
797 if (!image_check_magic (hdr)) {
798 puts (" Bad Magic Number\n");
802 if (!image_check_hcrc (hdr)) {
803 puts (" Bad Header Checksum\n");
807 image_print_contents (hdr);
809 puts (" Verifying Checksum ... ");
810 if (!image_check_dcrc (hdr)) {
811 puts (" Bad Data CRC\n");
816 #if defined(CONFIG_FIT)
817 case IMAGE_FORMAT_FIT:
818 puts (" FIT image found\n");
820 if (!fit_check_format (hdr)) {
821 puts ("Bad FIT image format!\n");
825 fit_print_contents (hdr);
829 puts ("Unknown image format!\n");
837 iminfo, CFG_MAXARGS, 1, do_iminfo,
838 "iminfo - print header information for application image\n",
840 " - print header information for application image starting at\n"
841 " address 'addr' in memory; this includes verification of the\n"
842 " image contents (magic number, header and payload checksums)\n"
847 /*******************************************************************/
848 /* imls - list all images found in flash */
849 /*******************************************************************/
850 #if defined(CONFIG_CMD_IMLS)
851 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
857 for (i = 0, info = &flash_info[0];
858 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
860 if (info->flash_id == FLASH_UNKNOWN)
862 for (j = 0; j < info->sector_count; ++j) {
864 hdr = (void *)info->start[j];
868 switch (genimg_get_format (hdr)) {
869 case IMAGE_FORMAT_LEGACY:
870 if (!image_check_hcrc (hdr))
873 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
874 image_print_contents (hdr);
876 puts (" Verifying Checksum ... ");
877 if (!image_check_dcrc (hdr)) {
878 puts ("Bad Data CRC\n");
883 #if defined(CONFIG_FIT)
884 case IMAGE_FORMAT_FIT:
885 if (!fit_check_format (hdr))
888 printf ("FIT Image at %08lX:\n", (ulong)hdr);
889 fit_print_contents (hdr);
906 "imls - list all images found in flash\n",
908 " - Prints information about all images found at sector\n"
909 " boundaries in flash.\n"
913 /*******************************************************************/
914 /* helper routines */
915 /*******************************************************************/
916 #ifdef CONFIG_SILENT_CONSOLE
917 static void fixup_silent_linux ()
919 char buf[256], *start, *end;
920 char *cmdline = getenv ("bootargs");
922 /* Only fix cmdline when requested */
923 if (!(gd->flags & GD_FLG_SILENT))
926 debug ("before silent fix-up: %s\n", cmdline);
928 if ((start = strstr (cmdline, "console=")) != NULL) {
929 end = strchr (start, ' ');
930 strncpy (buf, cmdline, (start - cmdline + 8));
932 strcpy (buf + (start - cmdline + 8), end);
934 buf[start - cmdline + 8] = '\0';
936 strcpy (buf, cmdline);
937 strcat (buf, " console=");
940 strcpy (buf, "console=");
943 setenv ("bootargs", buf);
944 debug ("after silent fix-up: %s\n", buf);
946 #endif /* CONFIG_SILENT_CONSOLE */
949 /*******************************************************************/
950 /* OS booting routines */
951 /*******************************************************************/
953 static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
954 int argc, char *argv[],
955 bootm_headers_t *images)
957 void (*loader)(bd_t *, image_header_t *, char *, char *);
958 image_header_t *os_hdr, *hdr;
959 ulong kernel_data, kernel_len;
963 #if defined(CONFIG_FIT)
964 if (!images->legacy_hdr_valid) {
965 fit_unsupported_reset ("NetBSD");
966 do_reset (cmdtp, flag, argc, argv);
969 hdr = images->legacy_hdr_os;
972 * Booting a (NetBSD) kernel image
974 * This process is pretty similar to a standalone application:
975 * The (first part of an multi-) image must be a stage-2 loader,
976 * which in turn is responsible for loading & invoking the actual
977 * kernel. The only differences are the parameters being passed:
978 * besides the board info strucure, the loader expects a command
979 * line, the name of the console device, and (optionally) the
980 * address of the original image header.
983 if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
984 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
990 #if defined (CONFIG_8xx_CONS_SMC1)
992 #elif defined (CONFIG_8xx_CONS_SMC2)
994 #elif defined (CONFIG_8xx_CONS_SCC2)
996 #elif defined (CONFIG_8xx_CONS_SCC3)
1004 for (i = 2, len = 0; i < argc; i += 1)
1005 len += strlen (argv[i]) + 1;
1006 cmdline = malloc (len);
1008 for (i = 2, len = 0; i < argc; i += 1) {
1010 cmdline[len++] = ' ';
1011 strcpy (&cmdline[len], argv[i]);
1012 len += strlen (argv[i]);
1014 } else if ((cmdline = getenv ("bootargs")) == NULL) {
1018 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
1020 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
1023 show_boot_progress (15);
1026 * NetBSD Stage-2 Loader Parameters:
1027 * r3: ptr to board info data
1029 * r5: console device
1030 * r6: boot args string
1032 (*loader) (gd->bd, os_hdr, consdev, cmdline);
1035 #ifdef CONFIG_LYNXKDI
1036 static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
1037 int argc, char *argv[],
1038 bootm_headers_t *images)
1040 image_header_t *hdr = &images->legacy_hdr_os_copy;
1042 #if defined(CONFIG_FIT)
1043 if (!images->legacy_hdr_valid) {
1044 fit_unsupported_reset ("Lynx");
1045 do_reset (cmdtp, flag, argc, argv);
1049 lynxkdi_boot ((image_header_t *)hdr);
1051 #endif /* CONFIG_LYNXKDI */
1053 static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
1054 int argc, char *argv[],
1055 bootm_headers_t *images)
1057 void (*entry_point)(bd_t *);
1059 #if defined(CONFIG_FIT)
1060 if (!images->legacy_hdr_valid) {
1061 fit_unsupported_reset ("RTEMS");
1062 do_reset (cmdtp, flag, argc, argv);
1066 entry_point = (void (*)(bd_t *))images->ep;
1068 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1069 (ulong)entry_point);
1071 show_boot_progress (15);
1075 * r3: ptr to board info data
1077 (*entry_point)(gd->bd);
1080 #if defined(CONFIG_CMD_ELF)
1081 static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
1082 int argc, char *argv[],
1083 bootm_headers_t *images)
1087 #if defined(CONFIG_FIT)
1088 if (!images->legacy_hdr_valid) {
1089 fit_unsupported_reset ("VxWorks");
1090 do_reset (cmdtp, flag, argc, argv);
1094 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1095 setenv("loadaddr", str);
1096 do_bootvx(cmdtp, 0, 0, NULL);
1099 static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
1100 int argc, char *argv[],
1101 bootm_headers_t *images)
1103 char *local_args[2];
1106 #if defined(CONFIG_FIT)
1107 if (!images->legacy_hdr_valid) {
1108 fit_unsupported_reset ("QNX");
1109 do_reset (cmdtp, flag, argc, argv);
1113 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1114 local_args[0] = argv[0];
1115 local_args[1] = str; /* and provide it via the arguments */
1116 do_bootelf(cmdtp, 0, 2, local_args);
1120 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
1121 static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
1122 int argc, char *argv[],
1123 bootm_headers_t *images)
1128 int i, j, nxt, len, envno, envsz;
1130 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
1132 #if defined(CONFIG_FIT)
1133 if (!images->legacy_hdr_valid) {
1134 fit_unsupported_reset ("ARTOS");
1135 do_reset (cmdtp, flag, argc, argv);
1140 * Booting an ARTOS kernel image + application
1143 /* this used to be the top of memory, but was wrong... */
1145 /* get stack pointer */
1146 asm volatile ("mr %0,1" : "=r"(top) );
1148 debug ("## Current stack ends at 0x%08lX ", top);
1150 top -= 2048; /* just to be sure */
1151 if (top > CFG_BOOTMAPSZ)
1152 top = CFG_BOOTMAPSZ;
1155 debug ("=> set upper limit to 0x%08lX\n", top);
1157 /* first check the artos specific boot args, then the linux args*/
1158 if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
1161 /* get length of cmdline, and place it */
1163 top = (top - (len + 1)) & ~0xF;
1164 cmdline = (char *)top;
1165 debug ("## cmdline at 0x%08lX ", top);
1166 strcpy (cmdline, s);
1169 top = (top - sizeof (bd_t)) & ~0xF;
1170 debug ("## bd at 0x%08lX ", top);
1172 memcpy (kbd, gd->bd, sizeof (bd_t));
1174 /* first find number of env entries, and their size */
1177 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1178 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
1181 envsz += (nxt - i) + 1; /* plus trailing zero */
1183 envno++; /* plus the terminating zero */
1184 debug ("## %u envvars total size %u ", envno, envsz);
1186 top = (top - sizeof (char **) * envno) & ~0xF;
1187 fwenv = (char **)top;
1188 debug ("## fwenv at 0x%08lX ", top);
1190 top = (top - envsz) & ~0xF;
1195 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1196 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
1199 for (j = i; j < nxt; ++j)
1200 *s++ = env_get_char (j);
1203 *ss++ = NULL; /* terminate */
1205 entry = (void (*)(bd_t *, char *, char **, ulong))images->ep;
1206 (*entry) (kbd, cmdline, fwenv, top);