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_OF_LIBFDT)
42 #include <fdt_support.h>
44 #if defined(CONFIG_OF_FLAT_TREE)
48 void mmc_depower(void);
50 DECLARE_GLOBAL_DATA_PTR
;
53 extern int do_reset (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
55 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
59 #ifdef CFG_HUSH_PARSER
63 DECLARE_GLOBAL_DATA_PTR
;
65 extern int gunzip (void *dst
, int dstlen
, unsigned char *src
, unsigned long *lenp
);
67 #define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
71 extern void bz_internal_error(int);
74 #if defined(CONFIG_CMD_IMI)
75 static int image_info (unsigned long addr
);
78 #if defined(CONFIG_CMD_IMLS)
80 extern flash_info_t flash_info
[]; /* info for FLASH chips */
81 static int do_imls (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
84 #ifdef CONFIG_SILENT_CONSOLE
85 static void fixup_silent_linux (void);
88 static image_header_t
*image_get_kernel (ulong img_addr
, int verify
);
89 #if defined(CONFIG_FIT)
90 static int fit_check_kernel (const void *fit
, int os_noffset
, int verify
);
93 static void *boot_get_kernel (cmd_tbl_t
*cmdtp
, int flag
,int argc
, char *argv
[],
94 bootm_headers_t
*images
, ulong
*os_data
, ulong
*os_len
);
95 extern int do_reset (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
98 * Continue booting an OS image; caller already has:
99 * - copied image header to global variable `header'
100 * - checked header magic number, checksums (both header & image),
101 * - verified image architecture (PPC) and type (KERNEL or MULTI),
102 * - loaded (first part of) image to header load address,
103 * - disabled interrupts.
105 typedef void boot_os_fn (cmd_tbl_t
*cmdtp
, int flag
,
106 int argc
, char *argv
[],
107 bootm_headers_t
*images
); /* pointers to os/initrd/fdt */
109 extern boot_os_fn do_bootm_linux
;
110 static boot_os_fn do_bootm_netbsd
;
111 #if defined(CONFIG_LYNXKDI)
112 static boot_os_fn do_bootm_lynxkdi
;
113 extern void lynxkdi_boot (image_header_t
*);
115 static boot_os_fn do_bootm_rtems
;
116 #if defined(CONFIG_CMD_ELF)
117 static boot_os_fn do_bootm_vxworks
;
118 static boot_os_fn do_bootm_qnxelf
;
119 int do_bootvx (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
120 int do_bootelf (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
122 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
123 extern uchar (*env_get_char
)(int); /* Returns a character from the environment */
124 static boot_os_fn do_bootm_artos
;
127 ulong load_addr
= CFG_LOAD_ADDR
; /* Default Load Address */
128 static bootm_headers_t images
; /* pointers to os/initrd/fdt images */
130 void __board_lmb_reserve(struct lmb
*lmb
)
132 /* please define platform specific board_lmb_reserve() */
134 void board_lmb_reserve(struct lmb
*lmb
) __attribute__((weak
, alias("__board_lmb_reserve")));
137 /*******************************************************************/
138 /* bootm - boot application image from image in memory */
139 /*******************************************************************/
140 int do_bootm (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
143 const char *type_name
;
144 uint unc_len
= CFG_BOOTM_LEN
;
145 uint8_t comp
, type
, os
;
148 ulong os_data
, os_len
;
149 ulong image_start
, image_end
;
150 ulong load_start
, load_end
;
151 ulong mem_start
, mem_size
;
155 memset ((void *)&images
, 0, sizeof (images
));
156 images
.verify
= getenv_verify();
157 images
.autostart
= getenv_autostart();
162 mem_start
= getenv_bootm_low();
163 mem_size
= getenv_bootm_size();
165 lmb_add(&lmb
, mem_start
, mem_size
);
167 board_lmb_reserve(&lmb
);
169 /* get kernel image header, start address and length */
170 os_hdr
= boot_get_kernel (cmdtp
, flag
, argc
, argv
,
171 &images
, &os_data
, &os_len
);
173 puts ("ERROR: can't get kernel image!\n");
177 /* get image parameters */
178 switch (genimg_get_format (os_hdr
)) {
179 case IMAGE_FORMAT_LEGACY
:
180 type
= image_get_type (os_hdr
);
181 comp
= image_get_comp (os_hdr
);
182 os
= image_get_os (os_hdr
);
184 image_end
= image_get_image_end (os_hdr
);
185 load_start
= image_get_load (os_hdr
);
187 #if defined(CONFIG_FIT)
188 case IMAGE_FORMAT_FIT
:
189 if (fit_image_get_type (images
.fit_hdr_os
,
190 images
.fit_noffset_os
, &type
)) {
191 puts ("Can't get image type!\n");
192 show_boot_progress (-109);
196 if (fit_image_get_comp (images
.fit_hdr_os
,
197 images
.fit_noffset_os
, &comp
)) {
198 puts ("Can't get image compression!\n");
199 show_boot_progress (-110);
203 if (fit_image_get_os (images
.fit_hdr_os
,
204 images
.fit_noffset_os
, &os
)) {
205 puts ("Can't get image OS!\n");
206 show_boot_progress (-111);
210 image_end
= fit_get_end (images
.fit_hdr_os
);
212 if (fit_image_get_load (images
.fit_hdr_os
, images
.fit_noffset_os
,
214 puts ("Can't get image load address!\n");
215 show_boot_progress (-112);
221 puts ("ERROR: unknown image format type!\n");
225 image_start
= (ulong
)os_hdr
;
227 type_name
= genimg_get_type_name (type
);
229 #ifdef CONFIG_DEPOWER_MMC_ON_BOOT
234 * We have reached the point of no return: we are going to
235 * overwrite all exception vector code, so we cannot easily
236 * recover from any failures any more...
238 iflag
= disable_interrupts();
240 #ifdef CONFIG_AMIGAONEG3SE
242 * We've possible left the caches enabled during
243 * bios emulation, so turn them off again
246 invalidate_l1_instruction_cache();
253 if (load_start
== (ulong
)os_hdr
) {
254 printf (" XIP %s ... ", type_name
);
256 printf (" Loading %s ... ", type_name
);
258 memmove_wd ((void *)load_start
,
259 (void *)os_data
, os_len
, CHUNKSZ
);
261 load_end
= load_start
+ os_len
;
266 printf (" Uncompressing %s ... ", type_name
);
267 if (gunzip ((void *)load_start
, unc_len
,
268 (uchar
*)os_data
, &os_len
) != 0) {
269 puts ("GUNZIP: uncompress or overwrite error "
270 "- must RESET board to recover\n");
271 show_boot_progress (-6);
272 do_reset (cmdtp
, flag
, argc
, argv
);
275 load_end
= load_start
+ os_len
;
279 printf (" Uncompressing %s ... ", type_name
);
281 * If we've got less than 4 MB of malloc() space,
282 * use slower decompression algorithm which requires
283 * at most 2300 KB of memory.
285 int i
= BZ2_bzBuffToBuffDecompress ((char*)load_start
,
286 &unc_len
, (char *)os_data
, os_len
,
287 CFG_MALLOC_LEN
< (4096 * 1024), 0);
289 printf ("BUNZIP2: uncompress or overwrite error %d "
290 "- must RESET board to recover\n", i
);
291 show_boot_progress (-6);
292 do_reset (cmdtp
, flag
, argc
, argv
);
295 load_end
= load_start
+ unc_len
;
297 #endif /* CONFIG_BZIP2 */
301 printf ("Unimplemented compression type %d\n", comp
);
302 show_boot_progress (-7);
306 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start
, load_end
);
307 show_boot_progress (7);
309 if ((load_start
< image_end
) && (load_end
> image_start
)) {
310 debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start
, image_end
);
311 debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start
, load_end
);
313 puts ("ERROR: image overwritten - must RESET the board to recover.\n");
314 show_boot_progress (-113);
315 do_reset (cmdtp
, flag
, argc
, argv
);
318 show_boot_progress (8);
320 lmb_reserve(&lmb
, load_start
, (load_end
- load_start
));
323 default: /* handled by (original) Linux case */
325 #ifdef CONFIG_SILENT_CONSOLE
326 fixup_silent_linux();
328 do_bootm_linux (cmdtp
, flag
, argc
, argv
, &images
);
332 do_bootm_netbsd (cmdtp
, flag
, argc
, argv
, &images
);
335 #ifdef CONFIG_LYNXKDI
337 do_bootm_lynxkdi (cmdtp
, flag
, argc
, argv
, &images
);
342 do_bootm_rtems (cmdtp
, flag
, argc
, argv
, &images
);
345 #if defined(CONFIG_CMD_ELF)
347 do_bootm_vxworks (cmdtp
, flag
, argc
, argv
, &images
);
351 do_bootm_qnxelf (cmdtp
, flag
, argc
, argv
, &images
);
357 do_bootm_artos (cmdtp
, flag
, argc
, argv
, &images
);
362 show_boot_progress (-9);
364 puts ("\n## Control returned to monitor - resetting...\n");
365 if (images
.autostart
)
366 do_reset (cmdtp
, flag
, argc
, argv
);
368 if (!images
.autostart
&& iflag
)
375 * image_get_kernel - verify legacy format kernel image
376 * @img_addr: in RAM address of the legacy format image to be verified
377 * @verify: data CRC verification flag
379 * image_get_kernel() verifies legacy image integrity and returns pointer to
380 * legacy image header if image verification was completed successfully.
383 * pointer to a legacy image header if valid image was found
384 * otherwise return NULL
386 static image_header_t
*image_get_kernel (ulong img_addr
, int verify
)
388 image_header_t
*hdr
= (image_header_t
*)img_addr
;
390 if (!image_check_magic(hdr
)) {
391 puts ("Bad Magic Number\n");
392 show_boot_progress (-1);
395 show_boot_progress (2);
397 if (!image_check_hcrc (hdr
)) {
398 puts ("Bad Header Checksum\n");
399 show_boot_progress (-2);
403 show_boot_progress (3);
404 image_print_contents (hdr
);
407 puts (" Verifying Checksum ... ");
408 if (!image_check_dcrc (hdr
)) {
409 printf ("Bad Data CRC\n");
410 show_boot_progress (-3);
415 show_boot_progress (4);
417 if (!image_check_target_arch (hdr
)) {
418 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr
));
419 show_boot_progress (-4);
426 * fit_check_kernel - verify FIT format kernel subimage
427 * @fit_hdr: pointer to the FIT image header
428 * os_noffset: kernel subimage node offset within FIT image
429 * @verify: data CRC verification flag
431 * fit_check_kernel() verifies integrity of the kernel subimage and from
432 * specified FIT image.
438 #if defined (CONFIG_FIT)
439 static int fit_check_kernel (const void *fit
, int os_noffset
, int verify
)
441 fit_image_print (fit
, os_noffset
, " ");
444 puts (" Verifying Hash Integrity ... ");
445 if (!fit_image_check_hashes (fit
, os_noffset
)) {
446 puts ("Bad Data Hash\n");
447 show_boot_progress (-104);
452 show_boot_progress (105);
454 #ifdef CONFIG_LOGBUFFER
455 #ifndef CONFIG_ALT_LB_ADDR
457 /* Prevent initrd from overwriting logbuffer */
458 if (initrd_high
< (kbd
->bi_memsize
-LOGBUFF_LEN
-LOGBUFF_OVERHEAD
))
459 initrd_high
= kbd
->bi_memsize
-LOGBUFF_LEN
-LOGBUFF_OVERHEAD
;
460 debug ("## Logbuffer at 0x%08lX ", kbd
->bi_memsize
-LOGBUFF_LEN
);
462 debug ("## Logbuffer at 0x%08lX ", CONFIG_ALT_LB_ADDR
);
465 if (!fit_image_check_target_arch (fit
, os_noffset
)) {
466 puts ("Unsupported Architecture\n");
467 show_boot_progress (-105);
471 show_boot_progress (106);
472 if (!fit_image_check_type (fit
, os_noffset
, IH_TYPE_KERNEL
)) {
473 puts ("Not a kernel image\n");
474 show_boot_progress (-106);
478 show_boot_progress (107);
481 #endif /* CONFIG_FIT */
484 * boot_get_kernel - find kernel image
485 * @os_data: pointer to a ulong variable, will hold os data start address
486 * @os_len: pointer to a ulong variable, will hold os data length
488 * boot_get_kernel() tries to find a kernel image, verifies its integrity
489 * and locates kernel data.
492 * pointer to image header if valid image was found, plus kernel start
493 * address and length, otherwise NULL
495 static void *boot_get_kernel (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[],
496 bootm_headers_t
*images
, ulong
*os_data
, ulong
*os_len
)
500 #if defined(CONFIG_FIT)
502 const char *fit_uname_config
= NULL
;
503 const char *fit_uname_kernel
= NULL
;
510 /* find out kernel image address */
512 img_addr
= load_addr
;
513 debug ("* kernel: default image load address = 0x%08lx\n",
515 #if defined(CONFIG_FIT)
516 } else if (fit_parse_conf (argv
[1], load_addr
, &img_addr
,
517 &fit_uname_config
)) {
518 debug ("* kernel: config '%s' from image at 0x%08lx\n",
519 fit_uname_config
, img_addr
);
520 } else if (fit_parse_subimage (argv
[1], load_addr
, &img_addr
,
521 &fit_uname_kernel
)) {
522 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
523 fit_uname_kernel
, img_addr
);
526 img_addr
= simple_strtoul(argv
[1], NULL
, 16);
527 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr
);
530 show_boot_progress (1);
532 /* copy from dataflash if needed */
533 img_addr
= genimg_get_image (img_addr
);
535 /* check image type, for FIT images get FIT kernel node */
536 *os_data
= *os_len
= 0;
537 switch (genimg_get_format ((void *)img_addr
)) {
538 case IMAGE_FORMAT_LEGACY
:
539 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
541 hdr
= image_get_kernel (img_addr
, images
->verify
);
544 show_boot_progress (5);
546 /* get os_data and os_len */
547 switch (image_get_type (hdr
)) {
549 *os_data
= image_get_data (hdr
);
550 *os_len
= image_get_data_size (hdr
);
553 image_multi_getimg (hdr
, 0, os_data
, os_len
);
556 printf ("Wrong Image Type for %s command\n", cmdtp
->name
);
557 show_boot_progress (-5);
560 images
->legacy_hdr_os
= hdr
;
561 images
->legacy_hdr_valid
= 1;
563 show_boot_progress (6);
565 #if defined(CONFIG_FIT)
566 case IMAGE_FORMAT_FIT
:
567 fit_hdr
= (void *)img_addr
;
568 printf ("## Booting kernel from FIT Image at %08lx ...\n",
571 if (!fit_check_format (fit_hdr
)) {
572 puts ("Bad FIT kernel image format!\n");
573 show_boot_progress (-100);
576 show_boot_progress (100);
578 if (!fit_uname_kernel
) {
580 * no kernel image node unit name, try to get config
581 * node first. If config unit node name is NULL
582 * fit_conf_get_node() will try to find default config node
584 show_boot_progress (101);
585 cfg_noffset
= fit_conf_get_node (fit_hdr
, fit_uname_config
);
586 if (cfg_noffset
< 0) {
587 show_boot_progress (-101);
590 /* save configuration uname provided in the first
593 images
->fit_uname_cfg
= fdt_get_name (fit_hdr
, cfg_noffset
, NULL
);
594 printf (" Using '%s' configuration\n", images
->fit_uname_cfg
);
595 show_boot_progress (103);
597 os_noffset
= fit_conf_get_kernel_node (fit_hdr
, cfg_noffset
);
598 fit_uname_kernel
= fit_get_name (fit_hdr
, os_noffset
, NULL
);
600 /* get kernel component image node offset */
601 show_boot_progress (102);
602 os_noffset
= fit_image_get_node (fit_hdr
, fit_uname_kernel
);
604 if (os_noffset
< 0) {
605 show_boot_progress (-103);
609 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel
);
611 show_boot_progress (104);
612 if (!fit_check_kernel (fit_hdr
, os_noffset
, images
->verify
))
615 /* get kernel image data address and length */
616 if (fit_image_get_data (fit_hdr
, os_noffset
, &data
, &len
)) {
617 puts ("Could not find kernel subimage data!\n");
618 show_boot_progress (-107);
621 show_boot_progress (108);
624 *os_data
= (ulong
)data
;
625 images
->fit_hdr_os
= fit_hdr
;
626 images
->fit_uname_os
= fit_uname_kernel
;
627 images
->fit_noffset_os
= os_noffset
;
631 printf ("Wrong Image Format for %s command\n", cmdtp
->name
);
632 show_boot_progress (-108);
636 debug (" kernel data at 0x%08lx, len = 0x%08lx (%d)\n",
637 *os_data
, *os_len
, *os_len
);
639 return (void *)img_addr
;
643 bootm
, CFG_MAXARGS
, 1, do_bootm
,
644 "bootm - boot application image from memory\n",
645 "[addr [arg ...]]\n - boot application image stored in memory\n"
646 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
647 "\t'arg' can be the address of an initrd image\n"
648 #if defined(CONFIG_OF_LIBFDT)
649 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
650 "\ta third argument is required which is the address of the\n"
651 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
652 "\tuse a '-' for the second argument. If you do not pass a third\n"
653 "\ta bd_info struct will be passed instead\n"
655 #if defined(CONFIG_FIT)
656 "\t\nFor the new multi component uImage format (FIT) addresses\n"
657 "\tmust be extened to include component or configuration unit name:\n"
658 "\taddr:<subimg_uname> - direct component image specification\n"
659 "\taddr#<conf_uname> - configuration specification\n"
660 "\tUse iminfo command to get the list of existing component\n"
661 "\timages and configurations.\n"
665 /*******************************************************************/
666 /* bootd - boot default image */
667 /*******************************************************************/
668 #if defined(CONFIG_CMD_BOOTD)
669 int do_bootd (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
673 #ifndef CFG_HUSH_PARSER
674 if (run_command (getenv ("bootcmd"), flag
) < 0)
677 if (parse_string_outer (getenv ("bootcmd"),
678 FLAG_PARSE_SEMICOLON
| FLAG_EXIT_FROM_LOOP
) != 0)
685 boot
, 1, 1, do_bootd
,
686 "boot - boot default, i.e., run 'bootcmd'\n",
690 /* keep old command name "bootd" for backward compatibility */
692 bootd
, 1, 1, do_bootd
,
693 "bootd - boot default, i.e., run 'bootcmd'\n",
700 /*******************************************************************/
701 /* iminfo - print header info for a requested image */
702 /*******************************************************************/
703 #if defined(CONFIG_CMD_IMI)
704 int do_iminfo (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
711 return image_info (load_addr
);
714 for (arg
= 1; arg
< argc
; ++arg
) {
715 addr
= simple_strtoul (argv
[arg
], NULL
, 16);
716 if (image_info (addr
) != 0)
722 static int image_info (ulong addr
)
724 void *hdr
= (void *)addr
;
726 printf ("\n## Checking Image at %08lx ...\n", addr
);
728 switch (genimg_get_format (hdr
)) {
729 case IMAGE_FORMAT_LEGACY
:
730 puts (" Legacy image found\n");
731 if (!image_check_magic (hdr
)) {
732 puts (" Bad Magic Number\n");
736 if (!image_check_hcrc (hdr
)) {
737 puts (" Bad Header Checksum\n");
741 image_print_contents (hdr
);
743 puts (" Verifying Checksum ... ");
744 if (!image_check_dcrc (hdr
)) {
745 puts (" Bad Data CRC\n");
750 #if defined(CONFIG_FIT)
751 case IMAGE_FORMAT_FIT
:
752 puts (" FIT image found\n");
754 if (!fit_check_format (hdr
)) {
755 puts ("Bad FIT image format!\n");
759 fit_print_contents (hdr
);
763 puts ("Unknown image format!\n");
771 iminfo
, CFG_MAXARGS
, 1, do_iminfo
,
772 "iminfo - print header information for application image\n",
774 " - print header information for application image starting at\n"
775 " address 'addr' in memory; this includes verification of the\n"
776 " image contents (magic number, header and payload checksums)\n"
781 /*******************************************************************/
782 /* imls - list all images found in flash */
783 /*******************************************************************/
784 #if defined(CONFIG_CMD_IMLS)
785 int do_imls (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
791 for (i
= 0, info
= &flash_info
[0];
792 i
< CFG_MAX_FLASH_BANKS
; ++i
, ++info
) {
794 if (info
->flash_id
== FLASH_UNKNOWN
)
796 for (j
= 0; j
< info
->sector_count
; ++j
) {
798 hdr
= (void *)info
->start
[j
];
802 switch (genimg_get_format (hdr
)) {
803 case IMAGE_FORMAT_LEGACY
:
804 if (!image_check_hcrc (hdr
))
807 printf ("Legacy Image at %08lX:\n", (ulong
)hdr
);
808 image_print_contents (hdr
);
810 puts (" Verifying Checksum ... ");
811 if (!image_check_dcrc (hdr
)) {
812 puts ("Bad Data CRC\n");
817 #if defined(CONFIG_FIT)
818 case IMAGE_FORMAT_FIT
:
819 if (!fit_check_format (hdr
))
822 printf ("FIT Image at %08lX:\n", (ulong
)hdr
);
823 fit_print_contents (hdr
);
840 "imls - list all images found in flash\n",
842 " - Prints information about all images found at sector\n"
843 " boundaries in flash.\n"
847 /*******************************************************************/
848 /* helper routines */
849 /*******************************************************************/
850 #ifdef CONFIG_SILENT_CONSOLE
851 static void fixup_silent_linux ()
853 char buf
[256], *start
, *end
;
854 char *cmdline
= getenv ("bootargs");
856 /* Only fix cmdline when requested */
857 if (!(gd
->flags
& GD_FLG_SILENT
))
860 debug ("before silent fix-up: %s\n", cmdline
);
862 if ((start
= strstr (cmdline
, "console=")) != NULL
) {
863 end
= strchr (start
, ' ');
864 strncpy (buf
, cmdline
, (start
- cmdline
+ 8));
866 strcpy (buf
+ (start
- cmdline
+ 8), end
);
868 buf
[start
- cmdline
+ 8] = '\0';
870 strcpy (buf
, cmdline
);
871 strcat (buf
, " console=");
874 strcpy (buf
, "console=");
877 setenv ("bootargs", buf
);
878 debug ("after silent fix-up: %s\n", buf
);
880 #endif /* CONFIG_SILENT_CONSOLE */
883 /*******************************************************************/
884 /* OS booting routines */
885 /*******************************************************************/
887 static void do_bootm_netbsd (cmd_tbl_t
*cmdtp
, int flag
,
888 int argc
, char *argv
[],
889 bootm_headers_t
*images
)
891 void (*loader
)(bd_t
*, image_header_t
*, char *, char *);
892 image_header_t
*os_hdr
, *hdr
;
893 ulong kernel_data
, kernel_len
;
897 #if defined(CONFIG_FIT)
898 if (!images
->legacy_hdr_valid
) {
899 fit_unsupported_reset ("NetBSD");
900 do_reset (cmdtp
, flag
, argc
, argv
);
903 hdr
= images
->legacy_hdr_os
;
906 * Booting a (NetBSD) kernel image
908 * This process is pretty similar to a standalone application:
909 * The (first part of an multi-) image must be a stage-2 loader,
910 * which in turn is responsible for loading & invoking the actual
911 * kernel. The only differences are the parameters being passed:
912 * besides the board info strucure, the loader expects a command
913 * line, the name of the console device, and (optionally) the
914 * address of the original image header.
917 if (image_check_type (hdr
, IH_TYPE_MULTI
)) {
918 image_multi_getimg (hdr
, 1, &kernel_data
, &kernel_len
);
924 #if defined (CONFIG_8xx_CONS_SMC1)
926 #elif defined (CONFIG_8xx_CONS_SMC2)
928 #elif defined (CONFIG_8xx_CONS_SCC2)
930 #elif defined (CONFIG_8xx_CONS_SCC3)
938 for (i
= 2, len
= 0; i
< argc
; i
+= 1)
939 len
+= strlen (argv
[i
]) + 1;
940 cmdline
= malloc (len
);
942 for (i
= 2, len
= 0; i
< argc
; i
+= 1) {
944 cmdline
[len
++] = ' ';
945 strcpy (&cmdline
[len
], argv
[i
]);
946 len
+= strlen (argv
[i
]);
948 } else if ((cmdline
= getenv ("bootargs")) == NULL
) {
952 loader
= (void (*)(bd_t
*, image_header_t
*, char *, char *))image_get_ep (hdr
);
954 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
957 show_boot_progress (15);
960 * NetBSD Stage-2 Loader Parameters:
961 * r3: ptr to board info data
964 * r6: boot args string
966 (*loader
) (gd
->bd
, os_hdr
, consdev
, cmdline
);
969 #ifdef CONFIG_LYNXKDI
970 static void do_bootm_lynxkdi (cmd_tbl_t
*cmdtp
, int flag
,
971 int argc
, char *argv
[],
972 bootm_headers_t
*images
)
974 image_header_t
*hdr
= images
->legacy_hdr_os
;
976 #if defined(CONFIG_FIT)
977 if (!images
->legacy_hdr_valid
) {
978 fit_unsupported_reset ("Lynx");
979 do_reset (cmdtp
, flag
, argc
, argv
);
983 lynxkdi_boot ((image_header_t
*)hdr
);
985 #endif /* CONFIG_LYNXKDI */
987 static void do_bootm_rtems (cmd_tbl_t
*cmdtp
, int flag
,
988 int argc
, char *argv
[],
989 bootm_headers_t
*images
)
991 image_header_t
*hdr
= images
->legacy_hdr_os
;
992 void (*entry_point
)(bd_t
*);
994 #if defined(CONFIG_FIT)
995 if (!images
->legacy_hdr_valid
) {
996 fit_unsupported_reset ("RTEMS");
997 do_reset (cmdtp
, flag
, argc
, argv
);
1001 entry_point
= (void (*)(bd_t
*))image_get_ep (hdr
);
1003 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1004 (ulong
)entry_point
);
1006 show_boot_progress (15);
1010 * r3: ptr to board info data
1012 (*entry_point
)(gd
->bd
);
1015 #if defined(CONFIG_CMD_ELF)
1016 static void do_bootm_vxworks (cmd_tbl_t
*cmdtp
, int flag
,
1017 int argc
, char *argv
[],
1018 bootm_headers_t
*images
)
1021 image_header_t
*hdr
= images
->legacy_hdr_os
;
1023 #if defined(CONFIG_FIT)
1025 fit_unsupported_reset ("VxWorks");
1026 do_reset (cmdtp
, flag
, argc
, argv
);
1030 sprintf(str
, "%x", image_get_ep (hdr
)); /* write entry-point into string */
1031 setenv("loadaddr", str
);
1032 do_bootvx(cmdtp
, 0, 0, NULL
);
1035 static void do_bootm_qnxelf(cmd_tbl_t
*cmdtp
, int flag
,
1036 int argc
, char *argv
[],
1037 bootm_headers_t
*images
)
1039 char *local_args
[2];
1041 image_header_t
*hdr
= images
->legacy_hdr_os
;
1043 #if defined(CONFIG_FIT)
1044 if (!images
->legacy_hdr_valid
) {
1045 fit_unsupported_reset ("QNX");
1046 do_reset (cmdtp
, flag
, argc
, argv
);
1050 sprintf(str
, "%x", image_get_ep (hdr
)); /* write entry-point into string */
1051 local_args
[0] = argv
[0];
1052 local_args
[1] = str
; /* and provide it via the arguments */
1053 do_bootelf(cmdtp
, 0, 2, local_args
);
1057 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
1058 static void do_bootm_artos (cmd_tbl_t
*cmdtp
, int flag
,
1059 int argc
, char *argv
[],
1060 bootm_headers_t
*images
)
1065 int i
, j
, nxt
, len
, envno
, envsz
;
1067 void (*entry
)(bd_t
*bd
, char *cmdline
, char **fwenv
, ulong top
);
1068 image_header_t
*hdr
= images
->legacy_hdr_os
;
1070 #if defined(CONFIG_FIT)
1071 if (!images
->legacy_hdr_valid
) {
1072 fit_unsupported_reset ("ARTOS");
1073 do_reset (cmdtp
, flag
, argc
, argv
);
1078 * Booting an ARTOS kernel image + application
1081 /* this used to be the top of memory, but was wrong... */
1083 /* get stack pointer */
1084 asm volatile ("mr %0,1" : "=r"(top
) );
1086 debug ("## Current stack ends at 0x%08lX ", top
);
1088 top
-= 2048; /* just to be sure */
1089 if (top
> CFG_BOOTMAPSZ
)
1090 top
= CFG_BOOTMAPSZ
;
1093 debug ("=> set upper limit to 0x%08lX\n", top
);
1095 /* first check the artos specific boot args, then the linux args*/
1096 if ((s
= getenv( "abootargs")) == NULL
&& (s
= getenv ("bootargs")) == NULL
)
1099 /* get length of cmdline, and place it */
1101 top
= (top
- (len
+ 1)) & ~0xF;
1102 cmdline
= (char *)top
;
1103 debug ("## cmdline at 0x%08lX ", top
);
1104 strcpy (cmdline
, s
);
1107 top
= (top
- sizeof (bd_t
)) & ~0xF;
1108 debug ("## bd at 0x%08lX ", top
);
1110 memcpy (kbd
, gd
->bd
, sizeof (bd_t
));
1112 /* first find number of env entries, and their size */
1115 for (i
= 0; env_get_char (i
) != '\0'; i
= nxt
+ 1) {
1116 for (nxt
= i
; env_get_char (nxt
) != '\0'; ++nxt
)
1119 envsz
+= (nxt
- i
) + 1; /* plus trailing zero */
1121 envno
++; /* plus the terminating zero */
1122 debug ("## %u envvars total size %u ", envno
, envsz
);
1124 top
= (top
- sizeof (char **) * envno
) & ~0xF;
1125 fwenv
= (char **)top
;
1126 debug ("## fwenv at 0x%08lX ", top
);
1128 top
= (top
- envsz
) & ~0xF;
1133 for (i
= 0; env_get_char (i
) != '\0'; i
= nxt
+ 1) {
1134 for (nxt
= i
; env_get_char (nxt
) != '\0'; ++nxt
)
1137 for (j
= i
; j
< nxt
; ++j
)
1138 *s
++ = env_get_char (j
);
1141 *ss
++ = NULL
; /* terminate */
1143 entry
= (void (*)(bd_t
*, char *, char **, ulong
))image_get_ep (hdr
);
1144 (*entry
) (kbd
, cmdline
, fwenv
, top
);