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;
171 memset ((void *)&images, 0, sizeof (images));
172 images.verify = getenv_yesno ("verify");
174 lmb_init(&images.lmb);
176 mem_start = getenv_bootm_low();
177 mem_size = getenv_bootm_size();
179 lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
181 board_lmb_reserve(&images.lmb);
183 /* get kernel image header, start address and length */
184 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
185 &images, &os_data, &os_len);
187 puts ("ERROR: can't get kernel image!\n");
191 /* get image parameters */
192 switch (genimg_get_format (os_hdr)) {
193 case IMAGE_FORMAT_LEGACY:
194 type = image_get_type (os_hdr);
195 comp = image_get_comp (os_hdr);
196 os = image_get_os (os_hdr);
198 image_end = image_get_image_end (os_hdr);
199 load_start = image_get_load (os_hdr);
201 #if defined(CONFIG_FIT)
202 case IMAGE_FORMAT_FIT:
203 if (fit_image_get_type (images.fit_hdr_os,
204 images.fit_noffset_os, &type)) {
205 puts ("Can't get image type!\n");
206 show_boot_progress (-109);
210 if (fit_image_get_comp (images.fit_hdr_os,
211 images.fit_noffset_os, &comp)) {
212 puts ("Can't get image compression!\n");
213 show_boot_progress (-110);
217 if (fit_image_get_os (images.fit_hdr_os,
218 images.fit_noffset_os, &os)) {
219 puts ("Can't get image OS!\n");
220 show_boot_progress (-111);
224 image_end = fit_get_end (images.fit_hdr_os);
226 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
228 puts ("Can't get image load address!\n");
229 show_boot_progress (-112);
235 puts ("ERROR: unknown image format type!\n");
239 /* find kernel entry point */
240 if (images.legacy_hdr_valid) {
241 images.ep = image_get_ep (&images.legacy_hdr_os_copy);
242 #if defined(CONFIG_FIT)
243 } else if (images.fit_uname_os) {
244 ret = fit_image_get_entry (images.fit_hdr_os,
245 images.fit_noffset_os, &images.ep);
247 puts ("Can't get entry point property!\n");
252 puts ("Could not find kernel entry point!\n");
256 if (os == IH_OS_LINUX) {
258 ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
259 &images.rd_start, &images.rd_end);
261 puts ("Ramdisk image is corrupt\n");
265 #if defined(CONFIG_OF_LIBFDT)
266 /* find flattened device tree */
267 ret = boot_get_fdt (flag, argc, argv, &images,
268 &images.ft_addr, &images.ft_len);
270 puts ("Could not find a valid device tree\n");
274 set_working_fdt_addr(images.ft_addr);
278 image_start = (ulong)os_hdr;
280 type_name = genimg_get_type_name (type);
283 * We have reached the point of no return: we are going to
284 * overwrite all exception vector code, so we cannot easily
285 * recover from any failures any more...
287 iflag = disable_interrupts();
289 #if defined(CONFIG_CMD_USB)
291 * turn off USB to prevent the host controller from writing to the
292 * SDRAM while Linux is booting. This could happen (at least for OHCI
293 * controller), because the HCCA (Host Controller Communication Area)
294 * lies within the SDRAM and the host controller writes continously to
295 * this area (as busmaster!). The HccaFrameNumber is for example
296 * updated every 1 ms within the HCCA structure in SDRAM! For more
297 * details see the OpenHCI specification.
303 #ifdef CONFIG_AMIGAONEG3SE
305 * We've possible left the caches enabled during
306 * bios emulation, so turn them off again
314 if (load_start == (ulong)os_hdr) {
315 printf (" XIP %s ... ", type_name);
317 printf (" Loading %s ... ", type_name);
319 memmove_wd ((void *)load_start,
320 (void *)os_data, os_len, CHUNKSZ);
322 load_end = load_start + os_len;
326 printf (" Uncompressing %s ... ", type_name);
327 if (gunzip ((void *)load_start, unc_len,
328 (uchar *)os_data, &os_len) != 0) {
329 puts ("GUNZIP: uncompress or overwrite error "
330 "- must RESET board to recover\n");
331 show_boot_progress (-6);
332 do_reset (cmdtp, flag, argc, argv);
335 load_end = load_start + os_len;
339 printf (" Uncompressing %s ... ", type_name);
341 * If we've got less than 4 MB of malloc() space,
342 * use slower decompression algorithm which requires
343 * at most 2300 KB of memory.
345 int i = BZ2_bzBuffToBuffDecompress ((char*)load_start,
346 &unc_len, (char *)os_data, os_len,
347 CFG_MALLOC_LEN < (4096 * 1024), 0);
349 printf ("BUNZIP2: uncompress or overwrite error %d "
350 "- must RESET board to recover\n", i);
351 show_boot_progress (-6);
352 do_reset (cmdtp, flag, argc, argv);
355 load_end = load_start + unc_len;
357 #endif /* CONFIG_BZIP2 */
361 printf ("Unimplemented compression type %d\n", comp);
362 show_boot_progress (-7);
366 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end);
367 show_boot_progress (7);
369 if ((load_start < image_end) && (load_end > image_start)) {
370 debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end);
371 debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end);
373 if (images.legacy_hdr_valid) {
374 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
375 puts ("WARNING: legacy format multi component "
376 "image overwritten\n");
378 puts ("ERROR: new format image overwritten - "
379 "must RESET the board to recover\n");
380 show_boot_progress (-113);
381 do_reset (cmdtp, flag, argc, argv);
385 show_boot_progress (8);
387 lmb_reserve(&images.lmb, load_start, (load_end - load_start));
390 default: /* handled by (original) Linux case */
392 #ifdef CONFIG_SILENT_CONSOLE
393 fixup_silent_linux();
395 do_bootm_linux (cmdtp, flag, argc, argv, &images);
399 do_bootm_netbsd (cmdtp, flag, argc, argv, &images);
402 #ifdef CONFIG_LYNXKDI
404 do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images);
409 do_bootm_rtems (cmdtp, flag, argc, argv, &images);
412 #if defined(CONFIG_CMD_ELF)
414 do_bootm_vxworks (cmdtp, flag, argc, argv, &images);
418 do_bootm_qnxelf (cmdtp, flag, argc, argv, &images);
424 do_bootm_artos (cmdtp, flag, argc, argv, &images);
429 show_boot_progress (-9);
431 puts ("\n## Control returned to monitor - resetting...\n");
432 do_reset (cmdtp, flag, argc, argv);
441 * image_get_kernel - verify legacy format kernel image
442 * @img_addr: in RAM address of the legacy format image to be verified
443 * @verify: data CRC verification flag
445 * image_get_kernel() verifies legacy image integrity and returns pointer to
446 * legacy image header if image verification was completed successfully.
449 * pointer to a legacy image header if valid image was found
450 * otherwise return NULL
452 static image_header_t *image_get_kernel (ulong img_addr, int verify)
454 image_header_t *hdr = (image_header_t *)img_addr;
456 if (!image_check_magic(hdr)) {
457 puts ("Bad Magic Number\n");
458 show_boot_progress (-1);
461 show_boot_progress (2);
463 if (!image_check_hcrc (hdr)) {
464 puts ("Bad Header Checksum\n");
465 show_boot_progress (-2);
469 show_boot_progress (3);
470 image_print_contents (hdr);
473 puts (" Verifying Checksum ... ");
474 if (!image_check_dcrc (hdr)) {
475 printf ("Bad Data CRC\n");
476 show_boot_progress (-3);
481 show_boot_progress (4);
483 if (!image_check_target_arch (hdr)) {
484 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
485 show_boot_progress (-4);
492 * fit_check_kernel - verify FIT format kernel subimage
493 * @fit_hdr: pointer to the FIT image header
494 * os_noffset: kernel subimage node offset within FIT image
495 * @verify: data CRC verification flag
497 * fit_check_kernel() verifies integrity of the kernel subimage and from
498 * specified FIT image.
504 #if defined (CONFIG_FIT)
505 static int fit_check_kernel (const void *fit, int os_noffset, int verify)
507 fit_image_print (fit, os_noffset, " ");
510 puts (" Verifying Hash Integrity ... ");
511 if (!fit_image_check_hashes (fit, os_noffset)) {
512 puts ("Bad Data Hash\n");
513 show_boot_progress (-104);
518 show_boot_progress (105);
520 if (!fit_image_check_target_arch (fit, os_noffset)) {
521 puts ("Unsupported Architecture\n");
522 show_boot_progress (-105);
526 show_boot_progress (106);
527 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
528 puts ("Not a kernel image\n");
529 show_boot_progress (-106);
533 show_boot_progress (107);
536 #endif /* CONFIG_FIT */
539 * boot_get_kernel - find kernel image
540 * @os_data: pointer to a ulong variable, will hold os data start address
541 * @os_len: pointer to a ulong variable, will hold os data length
543 * boot_get_kernel() tries to find a kernel image, verifies its integrity
544 * and locates kernel data.
547 * pointer to image header if valid image was found, plus kernel start
548 * address and length, otherwise NULL
550 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
551 bootm_headers_t *images, ulong *os_data, ulong *os_len)
555 #if defined(CONFIG_FIT)
557 const char *fit_uname_config = NULL;
558 const char *fit_uname_kernel = NULL;
565 /* find out kernel image address */
567 img_addr = load_addr;
568 debug ("* kernel: default image load address = 0x%08lx\n",
570 #if defined(CONFIG_FIT)
571 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
572 &fit_uname_config)) {
573 debug ("* kernel: config '%s' from image at 0x%08lx\n",
574 fit_uname_config, img_addr);
575 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
576 &fit_uname_kernel)) {
577 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
578 fit_uname_kernel, img_addr);
581 img_addr = simple_strtoul(argv[1], NULL, 16);
582 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
585 show_boot_progress (1);
587 /* copy from dataflash if needed */
588 img_addr = genimg_get_image (img_addr);
590 /* check image type, for FIT images get FIT kernel node */
591 *os_data = *os_len = 0;
592 switch (genimg_get_format ((void *)img_addr)) {
593 case IMAGE_FORMAT_LEGACY:
594 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
596 hdr = image_get_kernel (img_addr, images->verify);
599 show_boot_progress (5);
601 /* get os_data and os_len */
602 switch (image_get_type (hdr)) {
604 *os_data = image_get_data (hdr);
605 *os_len = image_get_data_size (hdr);
608 image_multi_getimg (hdr, 0, os_data, os_len);
611 printf ("Wrong Image Type for %s command\n", cmdtp->name);
612 show_boot_progress (-5);
617 * copy image header to allow for image overwrites during kernel
620 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
622 /* save pointer to image header */
623 images->legacy_hdr_os = hdr;
625 images->legacy_hdr_valid = 1;
626 show_boot_progress (6);
628 #if defined(CONFIG_FIT)
629 case IMAGE_FORMAT_FIT:
630 fit_hdr = (void *)img_addr;
631 printf ("## Booting kernel from FIT Image at %08lx ...\n",
634 if (!fit_check_format (fit_hdr)) {
635 puts ("Bad FIT kernel image format!\n");
636 show_boot_progress (-100);
639 show_boot_progress (100);
641 if (!fit_uname_kernel) {
643 * no kernel image node unit name, try to get config
644 * node first. If config unit node name is NULL
645 * fit_conf_get_node() will try to find default config node
647 show_boot_progress (101);
648 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
649 if (cfg_noffset < 0) {
650 show_boot_progress (-101);
653 /* save configuration uname provided in the first
656 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
657 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
658 show_boot_progress (103);
660 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
661 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
663 /* get kernel component image node offset */
664 show_boot_progress (102);
665 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
667 if (os_noffset < 0) {
668 show_boot_progress (-103);
672 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
674 show_boot_progress (104);
675 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
678 /* get kernel image data address and length */
679 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
680 puts ("Could not find kernel subimage data!\n");
681 show_boot_progress (-107);
684 show_boot_progress (108);
687 *os_data = (ulong)data;
688 images->fit_hdr_os = fit_hdr;
689 images->fit_uname_os = fit_uname_kernel;
690 images->fit_noffset_os = os_noffset;
694 printf ("Wrong Image Format for %s command\n", cmdtp->name);
695 show_boot_progress (-108);
699 debug (" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
700 *os_data, *os_len, *os_len);
702 return (void *)img_addr;
706 bootm, CFG_MAXARGS, 1, do_bootm,
707 "bootm - boot application image from memory\n",
708 "[addr [arg ...]]\n - boot application image stored in memory\n"
709 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
710 "\t'arg' can be the address of an initrd image\n"
711 #if defined(CONFIG_OF_LIBFDT)
712 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
713 "\ta third argument is required which is the address of the\n"
714 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
715 "\tuse a '-' for the second argument. If you do not pass a third\n"
716 "\ta bd_info struct will be passed instead\n"
718 #if defined(CONFIG_FIT)
719 "\t\nFor the new multi component uImage format (FIT) addresses\n"
720 "\tmust be extened to include component or configuration unit name:\n"
721 "\taddr:<subimg_uname> - direct component image specification\n"
722 "\taddr#<conf_uname> - configuration specification\n"
723 "\tUse iminfo command to get the list of existing component\n"
724 "\timages and configurations.\n"
728 /*******************************************************************/
729 /* bootd - boot default image */
730 /*******************************************************************/
731 #if defined(CONFIG_CMD_BOOTD)
732 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
736 #ifndef CFG_HUSH_PARSER
737 if (run_command (getenv ("bootcmd"), flag) < 0)
740 if (parse_string_outer (getenv ("bootcmd"),
741 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
748 boot, 1, 1, do_bootd,
749 "boot - boot default, i.e., run 'bootcmd'\n",
753 /* keep old command name "bootd" for backward compatibility */
755 bootd, 1, 1, do_bootd,
756 "bootd - boot default, i.e., run 'bootcmd'\n",
763 /*******************************************************************/
764 /* iminfo - print header info for a requested image */
765 /*******************************************************************/
766 #if defined(CONFIG_CMD_IMI)
767 int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
774 return image_info (load_addr);
777 for (arg = 1; arg < argc; ++arg) {
778 addr = simple_strtoul (argv[arg], NULL, 16);
779 if (image_info (addr) != 0)
785 static int image_info (ulong addr)
787 void *hdr = (void *)addr;
789 printf ("\n## Checking Image at %08lx ...\n", addr);
791 switch (genimg_get_format (hdr)) {
792 case IMAGE_FORMAT_LEGACY:
793 puts (" Legacy image found\n");
794 if (!image_check_magic (hdr)) {
795 puts (" Bad Magic Number\n");
799 if (!image_check_hcrc (hdr)) {
800 puts (" Bad Header Checksum\n");
804 image_print_contents (hdr);
806 puts (" Verifying Checksum ... ");
807 if (!image_check_dcrc (hdr)) {
808 puts (" Bad Data CRC\n");
813 #if defined(CONFIG_FIT)
814 case IMAGE_FORMAT_FIT:
815 puts (" FIT image found\n");
817 if (!fit_check_format (hdr)) {
818 puts ("Bad FIT image format!\n");
822 fit_print_contents (hdr);
826 puts ("Unknown image format!\n");
834 iminfo, CFG_MAXARGS, 1, do_iminfo,
835 "iminfo - print header information for application image\n",
837 " - print header information for application image starting at\n"
838 " address 'addr' in memory; this includes verification of the\n"
839 " image contents (magic number, header and payload checksums)\n"
844 /*******************************************************************/
845 /* imls - list all images found in flash */
846 /*******************************************************************/
847 #if defined(CONFIG_CMD_IMLS)
848 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
854 for (i = 0, info = &flash_info[0];
855 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
857 if (info->flash_id == FLASH_UNKNOWN)
859 for (j = 0; j < info->sector_count; ++j) {
861 hdr = (void *)info->start[j];
865 switch (genimg_get_format (hdr)) {
866 case IMAGE_FORMAT_LEGACY:
867 if (!image_check_hcrc (hdr))
870 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
871 image_print_contents (hdr);
873 puts (" Verifying Checksum ... ");
874 if (!image_check_dcrc (hdr)) {
875 puts ("Bad Data CRC\n");
880 #if defined(CONFIG_FIT)
881 case IMAGE_FORMAT_FIT:
882 if (!fit_check_format (hdr))
885 printf ("FIT Image at %08lX:\n", (ulong)hdr);
886 fit_print_contents (hdr);
903 "imls - list all images found in flash\n",
905 " - Prints information about all images found at sector\n"
906 " boundaries in flash.\n"
910 /*******************************************************************/
911 /* helper routines */
912 /*******************************************************************/
913 #ifdef CONFIG_SILENT_CONSOLE
914 static void fixup_silent_linux ()
916 char buf[256], *start, *end;
917 char *cmdline = getenv ("bootargs");
919 /* Only fix cmdline when requested */
920 if (!(gd->flags & GD_FLG_SILENT))
923 debug ("before silent fix-up: %s\n", cmdline);
925 if ((start = strstr (cmdline, "console=")) != NULL) {
926 end = strchr (start, ' ');
927 strncpy (buf, cmdline, (start - cmdline + 8));
929 strcpy (buf + (start - cmdline + 8), end);
931 buf[start - cmdline + 8] = '\0';
933 strcpy (buf, cmdline);
934 strcat (buf, " console=");
937 strcpy (buf, "console=");
940 setenv ("bootargs", buf);
941 debug ("after silent fix-up: %s\n", buf);
943 #endif /* CONFIG_SILENT_CONSOLE */
946 /*******************************************************************/
947 /* OS booting routines */
948 /*******************************************************************/
950 static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
951 int argc, char *argv[],
952 bootm_headers_t *images)
954 void (*loader)(bd_t *, image_header_t *, char *, char *);
955 image_header_t *os_hdr, *hdr;
956 ulong kernel_data, kernel_len;
960 #if defined(CONFIG_FIT)
961 if (!images->legacy_hdr_valid) {
962 fit_unsupported_reset ("NetBSD");
963 do_reset (cmdtp, flag, argc, argv);
966 hdr = images->legacy_hdr_os;
969 * Booting a (NetBSD) kernel image
971 * This process is pretty similar to a standalone application:
972 * The (first part of an multi-) image must be a stage-2 loader,
973 * which in turn is responsible for loading & invoking the actual
974 * kernel. The only differences are the parameters being passed:
975 * besides the board info strucure, the loader expects a command
976 * line, the name of the console device, and (optionally) the
977 * address of the original image header.
980 if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
981 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
987 #if defined (CONFIG_8xx_CONS_SMC1)
989 #elif defined (CONFIG_8xx_CONS_SMC2)
991 #elif defined (CONFIG_8xx_CONS_SCC2)
993 #elif defined (CONFIG_8xx_CONS_SCC3)
1001 for (i = 2, len = 0; i < argc; i += 1)
1002 len += strlen (argv[i]) + 1;
1003 cmdline = malloc (len);
1005 for (i = 2, len = 0; i < argc; i += 1) {
1007 cmdline[len++] = ' ';
1008 strcpy (&cmdline[len], argv[i]);
1009 len += strlen (argv[i]);
1011 } else if ((cmdline = getenv ("bootargs")) == NULL) {
1015 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
1017 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
1020 show_boot_progress (15);
1023 * NetBSD Stage-2 Loader Parameters:
1024 * r3: ptr to board info data
1026 * r5: console device
1027 * r6: boot args string
1029 (*loader) (gd->bd, os_hdr, consdev, cmdline);
1032 #ifdef CONFIG_LYNXKDI
1033 static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
1034 int argc, char *argv[],
1035 bootm_headers_t *images)
1037 image_header_t *hdr = &images->legacy_hdr_os_copy;
1039 #if defined(CONFIG_FIT)
1040 if (!images->legacy_hdr_valid) {
1041 fit_unsupported_reset ("Lynx");
1042 do_reset (cmdtp, flag, argc, argv);
1046 lynxkdi_boot ((image_header_t *)hdr);
1048 #endif /* CONFIG_LYNXKDI */
1050 static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
1051 int argc, char *argv[],
1052 bootm_headers_t *images)
1054 void (*entry_point)(bd_t *);
1056 #if defined(CONFIG_FIT)
1057 if (!images->legacy_hdr_valid) {
1058 fit_unsupported_reset ("RTEMS");
1059 do_reset (cmdtp, flag, argc, argv);
1063 entry_point = (void (*)(bd_t *))images->ep;
1065 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1066 (ulong)entry_point);
1068 show_boot_progress (15);
1072 * r3: ptr to board info data
1074 (*entry_point)(gd->bd);
1077 #if defined(CONFIG_CMD_ELF)
1078 static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
1079 int argc, char *argv[],
1080 bootm_headers_t *images)
1084 #if defined(CONFIG_FIT)
1085 if (!images->legacy_hdr_valid) {
1086 fit_unsupported_reset ("VxWorks");
1087 do_reset (cmdtp, flag, argc, argv);
1091 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1092 setenv("loadaddr", str);
1093 do_bootvx(cmdtp, 0, 0, NULL);
1096 static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
1097 int argc, char *argv[],
1098 bootm_headers_t *images)
1100 char *local_args[2];
1103 #if defined(CONFIG_FIT)
1104 if (!images->legacy_hdr_valid) {
1105 fit_unsupported_reset ("QNX");
1106 do_reset (cmdtp, flag, argc, argv);
1110 sprintf(str, "%lx", images->ep); /* write entry-point into string */
1111 local_args[0] = argv[0];
1112 local_args[1] = str; /* and provide it via the arguments */
1113 do_bootelf(cmdtp, 0, 2, local_args);
1117 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
1118 static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
1119 int argc, char *argv[],
1120 bootm_headers_t *images)
1125 int i, j, nxt, len, envno, envsz;
1127 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
1129 #if defined(CONFIG_FIT)
1130 if (!images->legacy_hdr_valid) {
1131 fit_unsupported_reset ("ARTOS");
1132 do_reset (cmdtp, flag, argc, argv);
1137 * Booting an ARTOS kernel image + application
1140 /* this used to be the top of memory, but was wrong... */
1142 /* get stack pointer */
1143 asm volatile ("mr %0,1" : "=r"(top) );
1145 debug ("## Current stack ends at 0x%08lX ", top);
1147 top -= 2048; /* just to be sure */
1148 if (top > CFG_BOOTMAPSZ)
1149 top = CFG_BOOTMAPSZ;
1152 debug ("=> set upper limit to 0x%08lX\n", top);
1154 /* first check the artos specific boot args, then the linux args*/
1155 if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
1158 /* get length of cmdline, and place it */
1160 top = (top - (len + 1)) & ~0xF;
1161 cmdline = (char *)top;
1162 debug ("## cmdline at 0x%08lX ", top);
1163 strcpy (cmdline, s);
1166 top = (top - sizeof (bd_t)) & ~0xF;
1167 debug ("## bd at 0x%08lX ", top);
1169 memcpy (kbd, gd->bd, sizeof (bd_t));
1171 /* first find number of env entries, and their size */
1174 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1175 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
1178 envsz += (nxt - i) + 1; /* plus trailing zero */
1180 envno++; /* plus the terminating zero */
1181 debug ("## %u envvars total size %u ", envno, envsz);
1183 top = (top - sizeof (char **) * envno) & ~0xF;
1184 fwenv = (char **)top;
1185 debug ("## fwenv at 0x%08lX ", top);
1187 top = (top - envsz) & ~0xF;
1192 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1193 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
1196 for (j = i; j < nxt; ++j)
1197 *s++ = env_get_char (j);
1200 *ss++ = NULL; /* terminate */
1202 entry = (void (*)(bd_t *, char *, char **, ulong))images->ep;
1203 (*entry) (kbd, cmdline, fwenv, top);