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 extern void udc_disable (void);
65 DECLARE_GLOBAL_DATA_PTR
;
67 extern int gunzip (void *dst
, int dstlen
, unsigned char *src
, unsigned long *lenp
);
69 #define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
73 extern void bz_internal_error(int);
76 #if defined(CONFIG_CMD_IMI)
77 static int image_info (unsigned long addr
);
80 #if defined(CONFIG_CMD_IMLS)
82 extern flash_info_t flash_info
[]; /* info for FLASH chips */
83 static int do_imls (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
86 #ifdef CONFIG_SILENT_CONSOLE
87 static void fixup_silent_linux (void);
90 static image_header_t
*image_get_kernel (ulong img_addr
, int verify
);
91 #if defined(CONFIG_FIT)
92 static int fit_check_kernel (const void *fit
, int os_noffset
, int verify
);
95 static void *boot_get_kernel (cmd_tbl_t
*cmdtp
, int flag
,int argc
, char *argv
[],
96 bootm_headers_t
*images
, ulong
*os_data
, ulong
*os_len
);
97 extern int do_reset (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
100 * Continue booting an OS image; caller already has:
101 * - copied image header to global variable `header'
102 * - checked header magic number, checksums (both header & image),
103 * - verified image architecture (PPC) and type (KERNEL or MULTI),
104 * - loaded (first part of) image to header load address,
105 * - disabled interrupts.
107 typedef void boot_os_fn (cmd_tbl_t
*cmdtp
, int flag
,
108 int argc
, char *argv
[],
109 bootm_headers_t
*images
); /* pointers to os/initrd/fdt */
111 extern boot_os_fn do_bootm_linux
;
112 static boot_os_fn do_bootm_netbsd
;
113 #if defined(CONFIG_LYNXKDI)
114 static boot_os_fn do_bootm_lynxkdi
;
115 extern void lynxkdi_boot (image_header_t
*);
117 static boot_os_fn do_bootm_rtems
;
118 #if defined(CONFIG_CMD_ELF)
119 static boot_os_fn do_bootm_vxworks
;
120 static boot_os_fn do_bootm_qnxelf
;
121 int do_bootvx (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
122 int do_bootelf (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
124 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
125 extern uchar (*env_get_char
)(int); /* Returns a character from the environment */
126 static boot_os_fn do_bootm_artos
;
129 ulong load_addr
= CFG_LOAD_ADDR
; /* Default Load Address */
130 static bootm_headers_t images
; /* pointers to os/initrd/fdt images */
132 void __board_lmb_reserve(struct lmb
*lmb
)
134 /* please define platform specific board_lmb_reserve() */
136 void board_lmb_reserve(struct lmb
*lmb
) __attribute__((weak
, alias("__board_lmb_reserve")));
139 /*******************************************************************/
140 /* bootm - boot application image from image in memory */
141 /*******************************************************************/
142 int do_bootm (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
145 const char *type_name
;
146 uint unc_len
= CFG_BOOTM_LEN
;
147 uint8_t comp
, type
, os
;
150 ulong os_data
, os_len
;
151 ulong image_start
, image_end
;
152 ulong load_start
, load_end
;
153 ulong mem_start
, mem_size
;
157 memset ((void *)&images
, 0, sizeof (images
));
158 images
.verify
= getenv_verify();
159 images
.autostart
= getenv_autostart();
164 mem_start
= getenv_bootm_low();
165 mem_size
= getenv_bootm_size();
167 lmb_add(&lmb
, mem_start
, mem_size
);
169 board_lmb_reserve(&lmb
);
171 /* get kernel image header, start address and length */
172 os_hdr
= boot_get_kernel (cmdtp
, flag
, argc
, argv
,
173 &images
, &os_data
, &os_len
);
175 puts ("ERROR: can't get kernel image!\n");
179 /* get image parameters */
180 switch (genimg_get_format (os_hdr
)) {
181 case IMAGE_FORMAT_LEGACY
:
182 type
= image_get_type (os_hdr
);
183 comp
= image_get_comp (os_hdr
);
184 os
= image_get_os (os_hdr
);
186 image_end
= image_get_image_end (os_hdr
);
187 load_start
= image_get_load (os_hdr
);
189 #if defined(CONFIG_FIT)
190 case IMAGE_FORMAT_FIT
:
191 if (fit_image_get_type (images
.fit_hdr_os
,
192 images
.fit_noffset_os
, &type
)) {
193 puts ("Can't get image type!\n");
194 show_boot_progress (-109);
198 if (fit_image_get_comp (images
.fit_hdr_os
,
199 images
.fit_noffset_os
, &comp
)) {
200 puts ("Can't get image compression!\n");
201 show_boot_progress (-110);
205 if (fit_image_get_os (images
.fit_hdr_os
,
206 images
.fit_noffset_os
, &os
)) {
207 puts ("Can't get image OS!\n");
208 show_boot_progress (-111);
212 image_end
= fit_get_end (images
.fit_hdr_os
);
214 if (fit_image_get_load (images
.fit_hdr_os
, images
.fit_noffset_os
,
216 puts ("Can't get image load address!\n");
217 show_boot_progress (-112);
223 puts ("ERROR: unknown image format type!\n");
227 image_start
= (ulong
)os_hdr
;
229 type_name
= genimg_get_type_name (type
);
231 #ifdef CONFIG_DEPOWER_MMC_ON_BOOT
235 #if (defined(CONFIG_S3C2410) || defined(CONFIG_S3C2440) || \
236 defined(CONFIG_S3C2442) || defined(CONFIG_S3C2443)) && defined(CONFIG_USB_DEVICE)
241 * We have reached the point of no return: we are going to
242 * overwrite all exception vector code, so we cannot easily
243 * recover from any failures any more...
245 iflag
= disable_interrupts();
247 #ifdef CONFIG_AMIGAONEG3SE
249 * We've possible left the caches enabled during
250 * bios emulation, so turn them off again
253 invalidate_l1_instruction_cache();
260 if (load_start
== (ulong
)os_hdr
) {
261 printf (" XIP %s ... ", type_name
);
263 printf (" Loading %s ... ", type_name
);
265 memmove_wd ((void *)load_start
,
266 (void *)os_data
, os_len
, CHUNKSZ
);
268 load_end
= load_start
+ os_len
;
273 printf (" Uncompressing %s ... ", type_name
);
274 if (gunzip ((void *)load_start
, unc_len
,
275 (uchar
*)os_data
, &os_len
) != 0) {
276 puts ("GUNZIP: uncompress or overwrite error "
277 "- must RESET board to recover\n");
278 show_boot_progress (-6);
279 do_reset (cmdtp
, flag
, argc
, argv
);
282 load_end
= load_start
+ os_len
;
286 printf (" Uncompressing %s ... ", type_name
);
288 * If we've got less than 4 MB of malloc() space,
289 * use slower decompression algorithm which requires
290 * at most 2300 KB of memory.
292 int i
= BZ2_bzBuffToBuffDecompress ((char*)load_start
,
293 &unc_len
, (char *)os_data
, os_len
,
294 CFG_MALLOC_LEN
< (4096 * 1024), 0);
296 printf ("BUNZIP2: uncompress or overwrite error %d "
297 "- must RESET board to recover\n", i
);
298 show_boot_progress (-6);
299 do_reset (cmdtp
, flag
, argc
, argv
);
302 load_end
= load_start
+ unc_len
;
304 #endif /* CONFIG_BZIP2 */
308 printf ("Unimplemented compression type %d\n", comp
);
309 show_boot_progress (-7);
313 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start
, load_end
);
314 show_boot_progress (7);
316 if ((load_start
< image_end
) && (load_end
> image_start
)) {
317 debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start
, image_end
);
318 debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start
, load_end
);
320 puts ("ERROR: image overwritten - must RESET the board to recover.\n");
321 show_boot_progress (-113);
322 do_reset (cmdtp
, flag
, argc
, argv
);
325 show_boot_progress (8);
327 lmb_reserve(&lmb
, load_start
, (load_end
- load_start
));
330 default: /* handled by (original) Linux case */
332 #ifdef CONFIG_SILENT_CONSOLE
333 fixup_silent_linux();
335 do_bootm_linux (cmdtp
, flag
, argc
, argv
, &images
);
339 do_bootm_netbsd (cmdtp
, flag
, argc
, argv
, &images
);
342 #ifdef CONFIG_LYNXKDI
344 do_bootm_lynxkdi (cmdtp
, flag
, argc
, argv
, &images
);
349 do_bootm_rtems (cmdtp
, flag
, argc
, argv
, &images
);
352 #if defined(CONFIG_CMD_ELF)
354 do_bootm_vxworks (cmdtp
, flag
, argc
, argv
, &images
);
358 do_bootm_qnxelf (cmdtp
, flag
, argc
, argv
, &images
);
364 do_bootm_artos (cmdtp
, flag
, argc
, argv
, &images
);
369 show_boot_progress (-9);
371 puts ("\n## Control returned to monitor - resetting...\n");
372 if (images
.autostart
)
373 do_reset (cmdtp
, flag
, argc
, argv
);
375 if (!images
.autostart
&& iflag
)
382 * image_get_kernel - verify legacy format kernel image
383 * @img_addr: in RAM address of the legacy format image to be verified
384 * @verify: data CRC verification flag
386 * image_get_kernel() verifies legacy image integrity and returns pointer to
387 * legacy image header if image verification was completed successfully.
390 * pointer to a legacy image header if valid image was found
391 * otherwise return NULL
393 static image_header_t
*image_get_kernel (ulong img_addr
, int verify
)
395 image_header_t
*hdr
= (image_header_t
*)img_addr
;
397 if (!image_check_magic(hdr
)) {
398 puts ("Bad Magic Number\n");
399 show_boot_progress (-1);
402 show_boot_progress (2);
404 if (!image_check_hcrc (hdr
)) {
405 puts ("Bad Header Checksum\n");
406 show_boot_progress (-2);
410 show_boot_progress (3);
411 image_print_contents (hdr
);
414 puts (" Verifying Checksum ... ");
415 if (!image_check_dcrc (hdr
)) {
416 printf ("Bad Data CRC\n");
417 show_boot_progress (-3);
422 show_boot_progress (4);
424 if (!image_check_target_arch (hdr
)) {
425 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr
));
426 show_boot_progress (-4);
433 * fit_check_kernel - verify FIT format kernel subimage
434 * @fit_hdr: pointer to the FIT image header
435 * os_noffset: kernel subimage node offset within FIT image
436 * @verify: data CRC verification flag
438 * fit_check_kernel() verifies integrity of the kernel subimage and from
439 * specified FIT image.
445 #if defined (CONFIG_FIT)
446 static int fit_check_kernel (const void *fit
, int os_noffset
, int verify
)
448 fit_image_print (fit
, os_noffset
, " ");
451 puts (" Verifying Hash Integrity ... ");
452 if (!fit_image_check_hashes (fit
, os_noffset
)) {
453 puts ("Bad Data Hash\n");
454 show_boot_progress (-104);
459 show_boot_progress (105);
461 #ifdef CONFIG_LOGBUFFER
462 #ifndef CONFIG_ALT_LB_ADDR
464 /* Prevent initrd from overwriting logbuffer */
465 if (initrd_high
< (kbd
->bi_memsize
-LOGBUFF_LEN
-LOGBUFF_OVERHEAD
))
466 initrd_high
= kbd
->bi_memsize
-LOGBUFF_LEN
-LOGBUFF_OVERHEAD
;
467 debug ("## Logbuffer at 0x%08lX ", kbd
->bi_memsize
-LOGBUFF_LEN
);
469 debug ("## Logbuffer at 0x%08lX ", CONFIG_ALT_LB_ADDR
);
472 if (!fit_image_check_target_arch (fit
, os_noffset
)) {
473 puts ("Unsupported Architecture\n");
474 show_boot_progress (-105);
478 show_boot_progress (106);
479 if (!fit_image_check_type (fit
, os_noffset
, IH_TYPE_KERNEL
)) {
480 puts ("Not a kernel image\n");
481 show_boot_progress (-106);
485 show_boot_progress (107);
488 #endif /* CONFIG_FIT */
491 * boot_get_kernel - find kernel image
492 * @os_data: pointer to a ulong variable, will hold os data start address
493 * @os_len: pointer to a ulong variable, will hold os data length
495 * boot_get_kernel() tries to find a kernel image, verifies its integrity
496 * and locates kernel data.
499 * pointer to image header if valid image was found, plus kernel start
500 * address and length, otherwise NULL
502 static void *boot_get_kernel (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[],
503 bootm_headers_t
*images
, ulong
*os_data
, ulong
*os_len
)
507 #if defined(CONFIG_FIT)
509 const char *fit_uname_config
= NULL
;
510 const char *fit_uname_kernel
= NULL
;
517 /* find out kernel image address */
519 img_addr
= load_addr
;
520 debug ("* kernel: default image load address = 0x%08lx\n",
522 #if defined(CONFIG_FIT)
523 } else if (fit_parse_conf (argv
[1], load_addr
, &img_addr
,
524 &fit_uname_config
)) {
525 debug ("* kernel: config '%s' from image at 0x%08lx\n",
526 fit_uname_config
, img_addr
);
527 } else if (fit_parse_subimage (argv
[1], load_addr
, &img_addr
,
528 &fit_uname_kernel
)) {
529 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
530 fit_uname_kernel
, img_addr
);
533 img_addr
= simple_strtoul(argv
[1], NULL
, 16);
534 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr
);
537 show_boot_progress (1);
539 /* copy from dataflash if needed */
540 img_addr
= genimg_get_image (img_addr
);
542 /* check image type, for FIT images get FIT kernel node */
543 *os_data
= *os_len
= 0;
544 switch (genimg_get_format ((void *)img_addr
)) {
545 case IMAGE_FORMAT_LEGACY
:
546 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
548 hdr
= image_get_kernel (img_addr
, images
->verify
);
551 show_boot_progress (5);
553 /* get os_data and os_len */
554 switch (image_get_type (hdr
)) {
556 *os_data
= image_get_data (hdr
);
557 *os_len
= image_get_data_size (hdr
);
560 image_multi_getimg (hdr
, 0, os_data
, os_len
);
563 printf ("Wrong Image Type for %s command\n", cmdtp
->name
);
564 show_boot_progress (-5);
567 images
->legacy_hdr_os
= hdr
;
568 images
->legacy_hdr_valid
= 1;
570 show_boot_progress (6);
572 #if defined(CONFIG_FIT)
573 case IMAGE_FORMAT_FIT
:
574 fit_hdr
= (void *)img_addr
;
575 printf ("## Booting kernel from FIT Image at %08lx ...\n",
578 if (!fit_check_format (fit_hdr
)) {
579 puts ("Bad FIT kernel image format!\n");
580 show_boot_progress (-100);
583 show_boot_progress (100);
585 if (!fit_uname_kernel
) {
587 * no kernel image node unit name, try to get config
588 * node first. If config unit node name is NULL
589 * fit_conf_get_node() will try to find default config node
591 show_boot_progress (101);
592 cfg_noffset
= fit_conf_get_node (fit_hdr
, fit_uname_config
);
593 if (cfg_noffset
< 0) {
594 show_boot_progress (-101);
597 /* save configuration uname provided in the first
600 images
->fit_uname_cfg
= fdt_get_name (fit_hdr
, cfg_noffset
, NULL
);
601 printf (" Using '%s' configuration\n", images
->fit_uname_cfg
);
602 show_boot_progress (103);
604 os_noffset
= fit_conf_get_kernel_node (fit_hdr
, cfg_noffset
);
605 fit_uname_kernel
= fit_get_name (fit_hdr
, os_noffset
, NULL
);
607 /* get kernel component image node offset */
608 show_boot_progress (102);
609 os_noffset
= fit_image_get_node (fit_hdr
, fit_uname_kernel
);
611 if (os_noffset
< 0) {
612 show_boot_progress (-103);
616 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel
);
618 show_boot_progress (104);
619 if (!fit_check_kernel (fit_hdr
, os_noffset
, images
->verify
))
622 /* get kernel image data address and length */
623 if (fit_image_get_data (fit_hdr
, os_noffset
, &data
, &len
)) {
624 puts ("Could not find kernel subimage data!\n");
625 show_boot_progress (-107);
628 show_boot_progress (108);
631 *os_data
= (ulong
)data
;
632 images
->fit_hdr_os
= fit_hdr
;
633 images
->fit_uname_os
= fit_uname_kernel
;
634 images
->fit_noffset_os
= os_noffset
;
638 printf ("Wrong Image Format for %s command\n", cmdtp
->name
);
639 show_boot_progress (-108);
643 debug (" kernel data at 0x%08lx, len = 0x%08lx (%d)\n",
644 *os_data
, *os_len
, *os_len
);
646 return (void *)img_addr
;
650 bootm
, CFG_MAXARGS
, 1, do_bootm
,
651 "bootm - boot application image from memory\n",
652 "[addr [arg ...]]\n - boot application image stored in memory\n"
653 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
654 "\t'arg' can be the address of an initrd image\n"
655 #if defined(CONFIG_OF_LIBFDT)
656 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
657 "\ta third argument is required which is the address of the\n"
658 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
659 "\tuse a '-' for the second argument. If you do not pass a third\n"
660 "\ta bd_info struct will be passed instead\n"
662 #if defined(CONFIG_FIT)
663 "\t\nFor the new multi component uImage format (FIT) addresses\n"
664 "\tmust be extened to include component or configuration unit name:\n"
665 "\taddr:<subimg_uname> - direct component image specification\n"
666 "\taddr#<conf_uname> - configuration specification\n"
667 "\tUse iminfo command to get the list of existing component\n"
668 "\timages and configurations.\n"
672 /*******************************************************************/
673 /* bootd - boot default image */
674 /*******************************************************************/
675 #if defined(CONFIG_CMD_BOOTD)
676 int do_bootd (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
680 #ifndef CFG_HUSH_PARSER
681 if (run_command (getenv ("bootcmd"), flag
) < 0)
684 if (parse_string_outer (getenv ("bootcmd"),
685 FLAG_PARSE_SEMICOLON
| FLAG_EXIT_FROM_LOOP
) != 0)
692 boot
, 1, 1, do_bootd
,
693 "boot - boot default, i.e., run 'bootcmd'\n",
697 /* keep old command name "bootd" for backward compatibility */
699 bootd
, 1, 1, do_bootd
,
700 "bootd - boot default, i.e., run 'bootcmd'\n",
707 /*******************************************************************/
708 /* iminfo - print header info for a requested image */
709 /*******************************************************************/
710 #if defined(CONFIG_CMD_IMI)
711 int do_iminfo (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
718 return image_info (load_addr
);
721 for (arg
= 1; arg
< argc
; ++arg
) {
722 addr
= simple_strtoul (argv
[arg
], NULL
, 16);
723 if (image_info (addr
) != 0)
729 static int image_info (ulong addr
)
731 void *hdr
= (void *)addr
;
733 printf ("\n## Checking Image at %08lx ...\n", addr
);
735 switch (genimg_get_format (hdr
)) {
736 case IMAGE_FORMAT_LEGACY
:
737 puts (" Legacy image found\n");
738 if (!image_check_magic (hdr
)) {
739 puts (" Bad Magic Number\n");
743 if (!image_check_hcrc (hdr
)) {
744 puts (" Bad Header Checksum\n");
748 image_print_contents (hdr
);
750 puts (" Verifying Checksum ... ");
751 if (!image_check_dcrc (hdr
)) {
752 puts (" Bad Data CRC\n");
757 #if defined(CONFIG_FIT)
758 case IMAGE_FORMAT_FIT
:
759 puts (" FIT image found\n");
761 if (!fit_check_format (hdr
)) {
762 puts ("Bad FIT image format!\n");
766 fit_print_contents (hdr
);
770 puts ("Unknown image format!\n");
778 iminfo
, CFG_MAXARGS
, 1, do_iminfo
,
779 "iminfo - print header information for application image\n",
781 " - print header information for application image starting at\n"
782 " address 'addr' in memory; this includes verification of the\n"
783 " image contents (magic number, header and payload checksums)\n"
788 /*******************************************************************/
789 /* imls - list all images found in flash */
790 /*******************************************************************/
791 #if defined(CONFIG_CMD_IMLS)
792 int do_imls (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[])
798 for (i
= 0, info
= &flash_info
[0];
799 i
< CFG_MAX_FLASH_BANKS
; ++i
, ++info
) {
801 if (info
->flash_id
== FLASH_UNKNOWN
)
803 for (j
= 0; j
< info
->sector_count
; ++j
) {
805 hdr
= (void *)info
->start
[j
];
809 switch (genimg_get_format (hdr
)) {
810 case IMAGE_FORMAT_LEGACY
:
811 if (!image_check_hcrc (hdr
))
814 printf ("Legacy Image at %08lX:\n", (ulong
)hdr
);
815 image_print_contents (hdr
);
817 puts (" Verifying Checksum ... ");
818 if (!image_check_dcrc (hdr
)) {
819 puts ("Bad Data CRC\n");
824 #if defined(CONFIG_FIT)
825 case IMAGE_FORMAT_FIT
:
826 if (!fit_check_format (hdr
))
829 printf ("FIT Image at %08lX:\n", (ulong
)hdr
);
830 fit_print_contents (hdr
);
847 "imls - list all images found in flash\n",
849 " - Prints information about all images found at sector\n"
850 " boundaries in flash.\n"
854 /*******************************************************************/
855 /* helper routines */
856 /*******************************************************************/
857 #ifdef CONFIG_SILENT_CONSOLE
858 static void fixup_silent_linux ()
860 char buf
[256], *start
, *end
;
861 char *cmdline
= getenv ("bootargs");
863 /* Only fix cmdline when requested */
864 if (!(gd
->flags
& GD_FLG_SILENT
))
867 debug ("before silent fix-up: %s\n", cmdline
);
869 if ((start
= strstr (cmdline
, "console=")) != NULL
) {
870 end
= strchr (start
, ' ');
871 strncpy (buf
, cmdline
, (start
- cmdline
+ 8));
873 strcpy (buf
+ (start
- cmdline
+ 8), end
);
875 buf
[start
- cmdline
+ 8] = '\0';
877 strcpy (buf
, cmdline
);
878 strcat (buf
, " console=");
881 strcpy (buf
, "console=");
884 setenv ("bootargs", buf
);
885 debug ("after silent fix-up: %s\n", buf
);
887 #endif /* CONFIG_SILENT_CONSOLE */
890 /*******************************************************************/
891 /* OS booting routines */
892 /*******************************************************************/
894 static void do_bootm_netbsd (cmd_tbl_t
*cmdtp
, int flag
,
895 int argc
, char *argv
[],
896 bootm_headers_t
*images
)
898 void (*loader
)(bd_t
*, image_header_t
*, char *, char *);
899 image_header_t
*os_hdr
, *hdr
;
900 ulong kernel_data
, kernel_len
;
904 #if defined(CONFIG_FIT)
905 if (!images
->legacy_hdr_valid
) {
906 fit_unsupported_reset ("NetBSD");
907 do_reset (cmdtp
, flag
, argc
, argv
);
910 hdr
= images
->legacy_hdr_os
;
913 * Booting a (NetBSD) kernel image
915 * This process is pretty similar to a standalone application:
916 * The (first part of an multi-) image must be a stage-2 loader,
917 * which in turn is responsible for loading & invoking the actual
918 * kernel. The only differences are the parameters being passed:
919 * besides the board info strucure, the loader expects a command
920 * line, the name of the console device, and (optionally) the
921 * address of the original image header.
924 if (image_check_type (hdr
, IH_TYPE_MULTI
)) {
925 image_multi_getimg (hdr
, 1, &kernel_data
, &kernel_len
);
931 #if defined (CONFIG_8xx_CONS_SMC1)
933 #elif defined (CONFIG_8xx_CONS_SMC2)
935 #elif defined (CONFIG_8xx_CONS_SCC2)
937 #elif defined (CONFIG_8xx_CONS_SCC3)
945 for (i
= 2, len
= 0; i
< argc
; i
+= 1)
946 len
+= strlen (argv
[i
]) + 1;
947 cmdline
= malloc (len
);
949 for (i
= 2, len
= 0; i
< argc
; i
+= 1) {
951 cmdline
[len
++] = ' ';
952 strcpy (&cmdline
[len
], argv
[i
]);
953 len
+= strlen (argv
[i
]);
955 } else if ((cmdline
= getenv ("bootargs")) == NULL
) {
959 loader
= (void (*)(bd_t
*, image_header_t
*, char *, char *))image_get_ep (hdr
);
961 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
964 show_boot_progress (15);
967 * NetBSD Stage-2 Loader Parameters:
968 * r3: ptr to board info data
971 * r6: boot args string
973 (*loader
) (gd
->bd
, os_hdr
, consdev
, cmdline
);
976 #ifdef CONFIG_LYNXKDI
977 static void do_bootm_lynxkdi (cmd_tbl_t
*cmdtp
, int flag
,
978 int argc
, char *argv
[],
979 bootm_headers_t
*images
)
981 image_header_t
*hdr
= images
->legacy_hdr_os
;
983 #if defined(CONFIG_FIT)
984 if (!images
->legacy_hdr_valid
) {
985 fit_unsupported_reset ("Lynx");
986 do_reset (cmdtp
, flag
, argc
, argv
);
990 lynxkdi_boot ((image_header_t
*)hdr
);
992 #endif /* CONFIG_LYNXKDI */
994 static void do_bootm_rtems (cmd_tbl_t
*cmdtp
, int flag
,
995 int argc
, char *argv
[],
996 bootm_headers_t
*images
)
998 image_header_t
*hdr
= images
->legacy_hdr_os
;
999 void (*entry_point
)(bd_t
*);
1001 #if defined(CONFIG_FIT)
1002 if (!images
->legacy_hdr_valid
) {
1003 fit_unsupported_reset ("RTEMS");
1004 do_reset (cmdtp
, flag
, argc
, argv
);
1008 entry_point
= (void (*)(bd_t
*))image_get_ep (hdr
);
1010 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1011 (ulong
)entry_point
);
1013 show_boot_progress (15);
1017 * r3: ptr to board info data
1019 (*entry_point
)(gd
->bd
);
1022 #if defined(CONFIG_CMD_ELF)
1023 static void do_bootm_vxworks (cmd_tbl_t
*cmdtp
, int flag
,
1024 int argc
, char *argv
[],
1025 bootm_headers_t
*images
)
1028 image_header_t
*hdr
= images
->legacy_hdr_os
;
1030 #if defined(CONFIG_FIT)
1032 fit_unsupported_reset ("VxWorks");
1033 do_reset (cmdtp
, flag
, argc
, argv
);
1037 sprintf(str
, "%x", image_get_ep (hdr
)); /* write entry-point into string */
1038 setenv("loadaddr", str
);
1039 do_bootvx(cmdtp
, 0, 0, NULL
);
1042 static void do_bootm_qnxelf(cmd_tbl_t
*cmdtp
, int flag
,
1043 int argc
, char *argv
[],
1044 bootm_headers_t
*images
)
1046 char *local_args
[2];
1048 image_header_t
*hdr
= images
->legacy_hdr_os
;
1050 #if defined(CONFIG_FIT)
1051 if (!images
->legacy_hdr_valid
) {
1052 fit_unsupported_reset ("QNX");
1053 do_reset (cmdtp
, flag
, argc
, argv
);
1057 sprintf(str
, "%x", image_get_ep (hdr
)); /* write entry-point into string */
1058 local_args
[0] = argv
[0];
1059 local_args
[1] = str
; /* and provide it via the arguments */
1060 do_bootelf(cmdtp
, 0, 2, local_args
);
1064 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
1065 static void do_bootm_artos (cmd_tbl_t
*cmdtp
, int flag
,
1066 int argc
, char *argv
[],
1067 bootm_headers_t
*images
)
1072 int i
, j
, nxt
, len
, envno
, envsz
;
1074 void (*entry
)(bd_t
*bd
, char *cmdline
, char **fwenv
, ulong top
);
1075 image_header_t
*hdr
= images
->legacy_hdr_os
;
1077 #if defined(CONFIG_FIT)
1078 if (!images
->legacy_hdr_valid
) {
1079 fit_unsupported_reset ("ARTOS");
1080 do_reset (cmdtp
, flag
, argc
, argv
);
1085 * Booting an ARTOS kernel image + application
1088 /* this used to be the top of memory, but was wrong... */
1090 /* get stack pointer */
1091 asm volatile ("mr %0,1" : "=r"(top
) );
1093 debug ("## Current stack ends at 0x%08lX ", top
);
1095 top
-= 2048; /* just to be sure */
1096 if (top
> CFG_BOOTMAPSZ
)
1097 top
= CFG_BOOTMAPSZ
;
1100 debug ("=> set upper limit to 0x%08lX\n", top
);
1102 /* first check the artos specific boot args, then the linux args*/
1103 if ((s
= getenv( "abootargs")) == NULL
&& (s
= getenv ("bootargs")) == NULL
)
1106 /* get length of cmdline, and place it */
1108 top
= (top
- (len
+ 1)) & ~0xF;
1109 cmdline
= (char *)top
;
1110 debug ("## cmdline at 0x%08lX ", top
);
1111 strcpy (cmdline
, s
);
1114 top
= (top
- sizeof (bd_t
)) & ~0xF;
1115 debug ("## bd at 0x%08lX ", top
);
1117 memcpy (kbd
, gd
->bd
, sizeof (bd_t
));
1119 /* first find number of env entries, and their size */
1122 for (i
= 0; env_get_char (i
) != '\0'; i
= nxt
+ 1) {
1123 for (nxt
= i
; env_get_char (nxt
) != '\0'; ++nxt
)
1126 envsz
+= (nxt
- i
) + 1; /* plus trailing zero */
1128 envno
++; /* plus the terminating zero */
1129 debug ("## %u envvars total size %u ", envno
, envsz
);
1131 top
= (top
- sizeof (char **) * envno
) & ~0xF;
1132 fwenv
= (char **)top
;
1133 debug ("## fwenv at 0x%08lX ", top
);
1135 top
= (top
- envsz
) & ~0xF;
1140 for (i
= 0; env_get_char (i
) != '\0'; i
= nxt
+ 1) {
1141 for (nxt
= i
; env_get_char (nxt
) != '\0'; ++nxt
)
1144 for (j
= i
; j
< nxt
; ++j
)
1145 *s
++ = env_get_char (j
);
1148 *ss
++ = NULL
; /* terminate */
1150 entry
= (void (*)(bd_t
*, char *, char **, ulong
))image_get_ep (hdr
);
1151 (*entry
) (kbd
, cmdline
, fwenv
, top
);