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 DECLARE_GLOBAL_DATA_PTR;
49 extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
51 #define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
55 extern void bz_internal_error(int);
58 #if defined(CONFIG_CMD_IMI)
59 static int image_info (unsigned long addr);
62 #if defined(CONFIG_CMD_IMLS)
64 extern flash_info_t flash_info[]; /* info for FLASH chips */
65 static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
68 #ifdef CONFIG_SILENT_CONSOLE
69 static void fixup_silent_linux (void);
72 static image_header_t *image_get_kernel (ulong img_addr, int verify);
73 #if defined(CONFIG_FIT)
74 static int fit_check_kernel (const void *fit, int os_noffset, int verify);
77 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
78 bootm_headers_t *images, ulong *os_data, ulong *os_len);
79 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
82 * Continue booting an OS image; caller already has:
83 * - copied image header to global variable `header'
84 * - checked header magic number, checksums (both header & image),
85 * - verified image architecture (PPC) and type (KERNEL or MULTI),
86 * - loaded (first part of) image to header load address,
87 * - disabled interrupts.
89 typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag,
90 int argc, char *argv[],
91 bootm_headers_t *images); /* pointers to os/initrd/fdt */
93 extern boot_os_fn do_bootm_linux;
94 static boot_os_fn do_bootm_netbsd;
95 #if defined(CONFIG_LYNXKDI)
96 static boot_os_fn do_bootm_lynxkdi;
97 extern void lynxkdi_boot (image_header_t *);
99 static boot_os_fn do_bootm_rtems;
100 #if defined(CONFIG_CMD_ELF)
101 static boot_os_fn do_bootm_vxworks;
102 static boot_os_fn do_bootm_qnxelf;
103 int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
104 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
106 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
107 static boot_os_fn do_bootm_artos;
110 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
111 static bootm_headers_t images; /* pointers to os/initrd/fdt images */
113 void __board_lmb_reserve(struct lmb *lmb)
115 /* please define platform specific board_lmb_reserve() */
117 void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
120 /*******************************************************************/
121 /* bootm - boot application image from image in memory */
122 /*******************************************************************/
123 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
126 const char *type_name;
127 uint unc_len = CFG_BOOTM_LEN;
128 uint8_t comp, type, os;
131 ulong os_data, os_len;
132 ulong image_start, image_end;
133 ulong load_start, load_end;
135 phys_size_t mem_size;
139 memset ((void *)&images, 0, sizeof (images));
140 images.verify = getenv_yesno ("verify");
145 mem_start = getenv_bootm_low();
146 mem_size = getenv_bootm_size();
148 lmb_add(&lmb, (phys_addr_t)mem_start, mem_size);
150 board_lmb_reserve(&lmb);
152 /* get kernel image header, start address and length */
153 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
154 &images, &os_data, &os_len);
156 puts ("ERROR: can't get kernel image!\n");
160 /* get image parameters */
161 switch (genimg_get_format (os_hdr)) {
162 case IMAGE_FORMAT_LEGACY:
163 type = image_get_type (os_hdr);
164 comp = image_get_comp (os_hdr);
165 os = image_get_os (os_hdr);
167 image_end = image_get_image_end (os_hdr);
168 load_start = image_get_load (os_hdr);
170 #if defined(CONFIG_FIT)
171 case IMAGE_FORMAT_FIT:
172 if (fit_image_get_type (images.fit_hdr_os,
173 images.fit_noffset_os, &type)) {
174 puts ("Can't get image type!\n");
175 show_boot_progress (-109);
179 if (fit_image_get_comp (images.fit_hdr_os,
180 images.fit_noffset_os, &comp)) {
181 puts ("Can't get image compression!\n");
182 show_boot_progress (-110);
186 if (fit_image_get_os (images.fit_hdr_os,
187 images.fit_noffset_os, &os)) {
188 puts ("Can't get image OS!\n");
189 show_boot_progress (-111);
193 image_end = fit_get_end (images.fit_hdr_os);
195 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
197 puts ("Can't get image load address!\n");
198 show_boot_progress (-112);
204 puts ("ERROR: unknown image format type!\n");
208 image_start = (ulong)os_hdr;
210 type_name = genimg_get_type_name (type);
213 * We have reached the point of no return: we are going to
214 * overwrite all exception vector code, so we cannot easily
215 * recover from any failures any more...
217 iflag = disable_interrupts();
219 #if defined(CONFIG_CMD_USB)
221 * turn off USB to prevent the host controller from writing to the
222 * SDRAM while Linux is booting. This could happen (at least for OHCI
223 * controller), because the HCCA (Host Controller Communication Area)
224 * lies within the SDRAM and the host controller writes continously to
225 * this area (as busmaster!). The HccaFrameNumber is for example
226 * updated every 1 ms within the HCCA structure in SDRAM! For more
227 * details see the OpenHCI specification.
233 #ifdef CONFIG_AMIGAONEG3SE
235 * We've possible left the caches enabled during
236 * bios emulation, so turn them off again
244 if (load_start == (ulong)os_hdr) {
245 printf (" XIP %s ... ", type_name);
247 printf (" Loading %s ... ", type_name);
249 memmove_wd ((void *)load_start,
250 (void *)os_data, os_len, CHUNKSZ);
252 load_end = load_start + os_len;
256 printf (" Uncompressing %s ... ", type_name);
257 if (gunzip ((void *)load_start, unc_len,
258 (uchar *)os_data, &os_len) != 0) {
259 puts ("GUNZIP: uncompress or overwrite error "
260 "- must RESET board to recover\n");
261 show_boot_progress (-6);
262 do_reset (cmdtp, flag, argc, argv);
265 load_end = load_start + os_len;
269 printf (" Uncompressing %s ... ", type_name);
271 * If we've got less than 4 MB of malloc() space,
272 * use slower decompression algorithm which requires
273 * at most 2300 KB of memory.
275 int i = BZ2_bzBuffToBuffDecompress ((char*)load_start,
276 &unc_len, (char *)os_data, os_len,
277 CFG_MALLOC_LEN < (4096 * 1024), 0);
279 printf ("BUNZIP2: uncompress or overwrite error %d "
280 "- must RESET board to recover\n", i);
281 show_boot_progress (-6);
282 do_reset (cmdtp, flag, argc, argv);
285 load_end = load_start + unc_len;
287 #endif /* CONFIG_BZIP2 */
291 printf ("Unimplemented compression type %d\n", comp);
292 show_boot_progress (-7);
296 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end);
297 show_boot_progress (7);
299 if ((load_start < image_end) && (load_end > image_start)) {
300 debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end);
301 debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end);
303 if (images.legacy_hdr_valid) {
304 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
305 puts ("WARNING: legacy format multi component "
306 "image overwritten\n");
308 puts ("ERROR: new format image overwritten - "
309 "must RESET the board to recover\n");
310 show_boot_progress (-113);
311 do_reset (cmdtp, flag, argc, argv);
315 show_boot_progress (8);
317 lmb_reserve(&lmb, load_start, (load_end - load_start));
320 default: /* handled by (original) Linux case */
322 #ifdef CONFIG_SILENT_CONSOLE
323 fixup_silent_linux();
325 do_bootm_linux (cmdtp, flag, argc, argv, &images);
329 do_bootm_netbsd (cmdtp, flag, argc, argv, &images);
332 #ifdef CONFIG_LYNXKDI
334 do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images);
339 do_bootm_rtems (cmdtp, flag, argc, argv, &images);
342 #if defined(CONFIG_CMD_ELF)
344 do_bootm_vxworks (cmdtp, flag, argc, argv, &images);
348 do_bootm_qnxelf (cmdtp, flag, argc, argv, &images);
354 do_bootm_artos (cmdtp, flag, argc, argv, &images);
359 show_boot_progress (-9);
361 puts ("\n## Control returned to monitor - resetting...\n");
362 do_reset (cmdtp, flag, argc, argv);
371 * image_get_kernel - verify legacy format kernel image
372 * @img_addr: in RAM address of the legacy format image to be verified
373 * @verify: data CRC verification flag
375 * image_get_kernel() verifies legacy image integrity and returns pointer to
376 * legacy image header if image verification was completed successfully.
379 * pointer to a legacy image header if valid image was found
380 * otherwise return NULL
382 static image_header_t *image_get_kernel (ulong img_addr, int verify)
384 image_header_t *hdr = (image_header_t *)img_addr;
386 if (!image_check_magic(hdr)) {
387 puts ("Bad Magic Number\n");
388 show_boot_progress (-1);
391 show_boot_progress (2);
393 if (!image_check_hcrc (hdr)) {
394 puts ("Bad Header Checksum\n");
395 show_boot_progress (-2);
399 show_boot_progress (3);
400 image_print_contents (hdr);
403 puts (" Verifying Checksum ... ");
404 if (!image_check_dcrc (hdr)) {
405 printf ("Bad Data CRC\n");
406 show_boot_progress (-3);
411 show_boot_progress (4);
413 if (!image_check_target_arch (hdr)) {
414 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
415 show_boot_progress (-4);
422 * fit_check_kernel - verify FIT format kernel subimage
423 * @fit_hdr: pointer to the FIT image header
424 * os_noffset: kernel subimage node offset within FIT image
425 * @verify: data CRC verification flag
427 * fit_check_kernel() verifies integrity of the kernel subimage and from
428 * specified FIT image.
434 #if defined (CONFIG_FIT)
435 static int fit_check_kernel (const void *fit, int os_noffset, int verify)
437 fit_image_print (fit, os_noffset, " ");
440 puts (" Verifying Hash Integrity ... ");
441 if (!fit_image_check_hashes (fit, os_noffset)) {
442 puts ("Bad Data Hash\n");
443 show_boot_progress (-104);
448 show_boot_progress (105);
450 if (!fit_image_check_target_arch (fit, os_noffset)) {
451 puts ("Unsupported Architecture\n");
452 show_boot_progress (-105);
456 show_boot_progress (106);
457 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
458 puts ("Not a kernel image\n");
459 show_boot_progress (-106);
463 show_boot_progress (107);
466 #endif /* CONFIG_FIT */
469 * boot_get_kernel - find kernel image
470 * @os_data: pointer to a ulong variable, will hold os data start address
471 * @os_len: pointer to a ulong variable, will hold os data length
473 * boot_get_kernel() tries to find a kernel image, verifies its integrity
474 * and locates kernel data.
477 * pointer to image header if valid image was found, plus kernel start
478 * address and length, otherwise NULL
480 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
481 bootm_headers_t *images, ulong *os_data, ulong *os_len)
485 #if defined(CONFIG_FIT)
487 const char *fit_uname_config = NULL;
488 const char *fit_uname_kernel = NULL;
495 /* find out kernel image address */
497 img_addr = load_addr;
498 debug ("* kernel: default image load address = 0x%08lx\n",
500 #if defined(CONFIG_FIT)
501 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
502 &fit_uname_config)) {
503 debug ("* kernel: config '%s' from image at 0x%08lx\n",
504 fit_uname_config, img_addr);
505 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
506 &fit_uname_kernel)) {
507 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
508 fit_uname_kernel, img_addr);
511 img_addr = simple_strtoul(argv[1], NULL, 16);
512 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
515 show_boot_progress (1);
517 /* copy from dataflash if needed */
518 img_addr = genimg_get_image (img_addr);
520 /* check image type, for FIT images get FIT kernel node */
521 *os_data = *os_len = 0;
522 switch (genimg_get_format ((void *)img_addr)) {
523 case IMAGE_FORMAT_LEGACY:
524 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
526 hdr = image_get_kernel (img_addr, images->verify);
529 show_boot_progress (5);
531 /* get os_data and os_len */
532 switch (image_get_type (hdr)) {
534 *os_data = image_get_data (hdr);
535 *os_len = image_get_data_size (hdr);
538 image_multi_getimg (hdr, 0, os_data, os_len);
541 printf ("Wrong Image Type for %s command\n", cmdtp->name);
542 show_boot_progress (-5);
547 * copy image header to allow for image overwrites during kernel
550 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
552 /* save pointer to image header */
553 images->legacy_hdr_os = hdr;
555 images->legacy_hdr_valid = 1;
556 show_boot_progress (6);
558 #if defined(CONFIG_FIT)
559 case IMAGE_FORMAT_FIT:
560 fit_hdr = (void *)img_addr;
561 printf ("## Booting kernel from FIT Image at %08lx ...\n",
564 if (!fit_check_format (fit_hdr)) {
565 puts ("Bad FIT kernel image format!\n");
566 show_boot_progress (-100);
569 show_boot_progress (100);
571 if (!fit_uname_kernel) {
573 * no kernel image node unit name, try to get config
574 * node first. If config unit node name is NULL
575 * fit_conf_get_node() will try to find default config node
577 show_boot_progress (101);
578 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
579 if (cfg_noffset < 0) {
580 show_boot_progress (-101);
583 /* save configuration uname provided in the first
586 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
587 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
588 show_boot_progress (103);
590 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
591 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
593 /* get kernel component image node offset */
594 show_boot_progress (102);
595 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
597 if (os_noffset < 0) {
598 show_boot_progress (-103);
602 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
604 show_boot_progress (104);
605 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
608 /* get kernel image data address and length */
609 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
610 puts ("Could not find kernel subimage data!\n");
611 show_boot_progress (-107);
614 show_boot_progress (108);
617 *os_data = (ulong)data;
618 images->fit_hdr_os = fit_hdr;
619 images->fit_uname_os = fit_uname_kernel;
620 images->fit_noffset_os = os_noffset;
624 printf ("Wrong Image Format for %s command\n", cmdtp->name);
625 show_boot_progress (-108);
629 debug (" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
630 *os_data, *os_len, *os_len);
632 return (void *)img_addr;
636 bootm, CFG_MAXARGS, 1, do_bootm,
637 "bootm - boot application image from memory\n",
638 "[addr [arg ...]]\n - boot application image stored in memory\n"
639 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
640 "\t'arg' can be the address of an initrd image\n"
641 #if defined(CONFIG_OF_LIBFDT)
642 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
643 "\ta third argument is required which is the address of the\n"
644 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
645 "\tuse a '-' for the second argument. If you do not pass a third\n"
646 "\ta bd_info struct will be passed instead\n"
648 #if defined(CONFIG_FIT)
649 "\t\nFor the new multi component uImage format (FIT) addresses\n"
650 "\tmust be extened to include component or configuration unit name:\n"
651 "\taddr:<subimg_uname> - direct component image specification\n"
652 "\taddr#<conf_uname> - configuration specification\n"
653 "\tUse iminfo command to get the list of existing component\n"
654 "\timages and configurations.\n"
658 /*******************************************************************/
659 /* bootd - boot default image */
660 /*******************************************************************/
661 #if defined(CONFIG_CMD_BOOTD)
662 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
666 #ifndef CFG_HUSH_PARSER
667 if (run_command (getenv ("bootcmd"), flag) < 0)
670 if (parse_string_outer (getenv ("bootcmd"),
671 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
678 boot, 1, 1, do_bootd,
679 "boot - boot default, i.e., run 'bootcmd'\n",
683 /* keep old command name "bootd" for backward compatibility */
685 bootd, 1, 1, do_bootd,
686 "bootd - boot default, i.e., run 'bootcmd'\n",
693 /*******************************************************************/
694 /* iminfo - print header info for a requested image */
695 /*******************************************************************/
696 #if defined(CONFIG_CMD_IMI)
697 int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
704 return image_info (load_addr);
707 for (arg = 1; arg < argc; ++arg) {
708 addr = simple_strtoul (argv[arg], NULL, 16);
709 if (image_info (addr) != 0)
715 static int image_info (ulong addr)
717 void *hdr = (void *)addr;
719 printf ("\n## Checking Image at %08lx ...\n", addr);
721 switch (genimg_get_format (hdr)) {
722 case IMAGE_FORMAT_LEGACY:
723 puts (" Legacy image found\n");
724 if (!image_check_magic (hdr)) {
725 puts (" Bad Magic Number\n");
729 if (!image_check_hcrc (hdr)) {
730 puts (" Bad Header Checksum\n");
734 image_print_contents (hdr);
736 puts (" Verifying Checksum ... ");
737 if (!image_check_dcrc (hdr)) {
738 puts (" Bad Data CRC\n");
743 #if defined(CONFIG_FIT)
744 case IMAGE_FORMAT_FIT:
745 puts (" FIT image found\n");
747 if (!fit_check_format (hdr)) {
748 puts ("Bad FIT image format!\n");
752 fit_print_contents (hdr);
756 puts ("Unknown image format!\n");
764 iminfo, CFG_MAXARGS, 1, do_iminfo,
765 "iminfo - print header information for application image\n",
767 " - print header information for application image starting at\n"
768 " address 'addr' in memory; this includes verification of the\n"
769 " image contents (magic number, header and payload checksums)\n"
774 /*******************************************************************/
775 /* imls - list all images found in flash */
776 /*******************************************************************/
777 #if defined(CONFIG_CMD_IMLS)
778 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
784 for (i = 0, info = &flash_info[0];
785 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
787 if (info->flash_id == FLASH_UNKNOWN)
789 for (j = 0; j < info->sector_count; ++j) {
791 hdr = (void *)info->start[j];
795 switch (genimg_get_format (hdr)) {
796 case IMAGE_FORMAT_LEGACY:
797 if (!image_check_hcrc (hdr))
800 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
801 image_print_contents (hdr);
803 puts (" Verifying Checksum ... ");
804 if (!image_check_dcrc (hdr)) {
805 puts ("Bad Data CRC\n");
810 #if defined(CONFIG_FIT)
811 case IMAGE_FORMAT_FIT:
812 if (!fit_check_format (hdr))
815 printf ("FIT Image at %08lX:\n", (ulong)hdr);
816 fit_print_contents (hdr);
833 "imls - list all images found in flash\n",
835 " - Prints information about all images found at sector\n"
836 " boundaries in flash.\n"
840 /*******************************************************************/
841 /* helper routines */
842 /*******************************************************************/
843 #ifdef CONFIG_SILENT_CONSOLE
844 static void fixup_silent_linux ()
846 char buf[256], *start, *end;
847 char *cmdline = getenv ("bootargs");
849 /* Only fix cmdline when requested */
850 if (!(gd->flags & GD_FLG_SILENT))
853 debug ("before silent fix-up: %s\n", cmdline);
855 if ((start = strstr (cmdline, "console=")) != NULL) {
856 end = strchr (start, ' ');
857 strncpy (buf, cmdline, (start - cmdline + 8));
859 strcpy (buf + (start - cmdline + 8), end);
861 buf[start - cmdline + 8] = '\0';
863 strcpy (buf, cmdline);
864 strcat (buf, " console=");
867 strcpy (buf, "console=");
870 setenv ("bootargs", buf);
871 debug ("after silent fix-up: %s\n", buf);
873 #endif /* CONFIG_SILENT_CONSOLE */
876 /*******************************************************************/
877 /* OS booting routines */
878 /*******************************************************************/
880 static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
881 int argc, char *argv[],
882 bootm_headers_t *images)
884 void (*loader)(bd_t *, image_header_t *, char *, char *);
885 image_header_t *os_hdr, *hdr;
886 ulong kernel_data, kernel_len;
890 #if defined(CONFIG_FIT)
891 if (!images->legacy_hdr_valid) {
892 fit_unsupported_reset ("NetBSD");
893 do_reset (cmdtp, flag, argc, argv);
896 hdr = images->legacy_hdr_os;
899 * Booting a (NetBSD) kernel image
901 * This process is pretty similar to a standalone application:
902 * The (first part of an multi-) image must be a stage-2 loader,
903 * which in turn is responsible for loading & invoking the actual
904 * kernel. The only differences are the parameters being passed:
905 * besides the board info strucure, the loader expects a command
906 * line, the name of the console device, and (optionally) the
907 * address of the original image header.
910 if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
911 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
917 #if defined (CONFIG_8xx_CONS_SMC1)
919 #elif defined (CONFIG_8xx_CONS_SMC2)
921 #elif defined (CONFIG_8xx_CONS_SCC2)
923 #elif defined (CONFIG_8xx_CONS_SCC3)
931 for (i = 2, len = 0; i < argc; i += 1)
932 len += strlen (argv[i]) + 1;
933 cmdline = malloc (len);
935 for (i = 2, len = 0; i < argc; i += 1) {
937 cmdline[len++] = ' ';
938 strcpy (&cmdline[len], argv[i]);
939 len += strlen (argv[i]);
941 } else if ((cmdline = getenv ("bootargs")) == NULL) {
945 loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
947 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
950 show_boot_progress (15);
953 * NetBSD Stage-2 Loader Parameters:
954 * r3: ptr to board info data
957 * r6: boot args string
959 (*loader) (gd->bd, os_hdr, consdev, cmdline);
962 #ifdef CONFIG_LYNXKDI
963 static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
964 int argc, char *argv[],
965 bootm_headers_t *images)
967 image_header_t *hdr = &images->legacy_hdr_os_copy;
969 #if defined(CONFIG_FIT)
970 if (!images->legacy_hdr_valid) {
971 fit_unsupported_reset ("Lynx");
972 do_reset (cmdtp, flag, argc, argv);
976 lynxkdi_boot ((image_header_t *)hdr);
978 #endif /* CONFIG_LYNXKDI */
980 static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
981 int argc, char *argv[],
982 bootm_headers_t *images)
984 image_header_t *hdr = &images->legacy_hdr_os_copy;
985 void (*entry_point)(bd_t *);
987 #if defined(CONFIG_FIT)
988 if (!images->legacy_hdr_valid) {
989 fit_unsupported_reset ("RTEMS");
990 do_reset (cmdtp, flag, argc, argv);
994 entry_point = (void (*)(bd_t *))image_get_ep (hdr);
996 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
999 show_boot_progress (15);
1003 * r3: ptr to board info data
1005 (*entry_point)(gd->bd);
1008 #if defined(CONFIG_CMD_ELF)
1009 static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
1010 int argc, char *argv[],
1011 bootm_headers_t *images)
1014 image_header_t *hdr = &images->legacy_hdr_os_copy;
1016 #if defined(CONFIG_FIT)
1017 if (!images->legacy_hdr_valid) {
1018 fit_unsupported_reset ("VxWorks");
1019 do_reset (cmdtp, flag, argc, argv);
1023 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
1024 setenv("loadaddr", str);
1025 do_bootvx(cmdtp, 0, 0, NULL);
1028 static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
1029 int argc, char *argv[],
1030 bootm_headers_t *images)
1032 char *local_args[2];
1034 image_header_t *hdr = &images->legacy_hdr_os_copy;
1036 #if defined(CONFIG_FIT)
1037 if (!images->legacy_hdr_valid) {
1038 fit_unsupported_reset ("QNX");
1039 do_reset (cmdtp, flag, argc, argv);
1043 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
1044 local_args[0] = argv[0];
1045 local_args[1] = str; /* and provide it via the arguments */
1046 do_bootelf(cmdtp, 0, 2, local_args);
1050 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
1051 static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
1052 int argc, char *argv[],
1053 bootm_headers_t *images)
1058 int i, j, nxt, len, envno, envsz;
1060 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
1061 image_header_t *hdr = &images->legacy_hdr_os_copy;
1063 #if defined(CONFIG_FIT)
1064 if (!images->legacy_hdr_valid) {
1065 fit_unsupported_reset ("ARTOS");
1066 do_reset (cmdtp, flag, argc, argv);
1071 * Booting an ARTOS kernel image + application
1074 /* this used to be the top of memory, but was wrong... */
1076 /* get stack pointer */
1077 asm volatile ("mr %0,1" : "=r"(top) );
1079 debug ("## Current stack ends at 0x%08lX ", top);
1081 top -= 2048; /* just to be sure */
1082 if (top > CFG_BOOTMAPSZ)
1083 top = CFG_BOOTMAPSZ;
1086 debug ("=> set upper limit to 0x%08lX\n", top);
1088 /* first check the artos specific boot args, then the linux args*/
1089 if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
1092 /* get length of cmdline, and place it */
1094 top = (top - (len + 1)) & ~0xF;
1095 cmdline = (char *)top;
1096 debug ("## cmdline at 0x%08lX ", top);
1097 strcpy (cmdline, s);
1100 top = (top - sizeof (bd_t)) & ~0xF;
1101 debug ("## bd at 0x%08lX ", top);
1103 memcpy (kbd, gd->bd, sizeof (bd_t));
1105 /* first find number of env entries, and their size */
1108 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1109 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
1112 envsz += (nxt - i) + 1; /* plus trailing zero */
1114 envno++; /* plus the terminating zero */
1115 debug ("## %u envvars total size %u ", envno, envsz);
1117 top = (top - sizeof (char **) * envno) & ~0xF;
1118 fwenv = (char **)top;
1119 debug ("## fwenv at 0x%08lX ", top);
1121 top = (top - envsz) & ~0xF;
1126 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1127 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
1130 for (j = i; j < nxt; ++j)
1131 *s++ = env_get_char (j);
1134 *ss++ = NULL; /* terminate */
1136 entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
1137 (*entry) (kbd, cmdline, fwenv, top);