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 #ifdef CFG_HUSH_PARSER
43 DECLARE_GLOBAL_DATA_PTR;
45 extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
47 #define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
51 extern void bz_internal_error(int);
54 #if defined(CONFIG_CMD_IMI)
55 static int image_info (unsigned long addr);
58 #if defined(CONFIG_CMD_IMLS)
60 extern flash_info_t flash_info[]; /* info for FLASH chips */
61 static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
64 #ifdef CONFIG_SILENT_CONSOLE
65 static void fixup_silent_linux (void);
68 static image_header_t *image_get_kernel (ulong img_addr, int verify);
69 #if defined(CONFIG_FIT)
70 static int fit_check_kernel (const void *fit, int os_noffset, int verify);
73 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
74 bootm_headers_t *images, ulong *os_data, ulong *os_len);
75 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
78 * Continue booting an OS image; caller already has:
79 * - copied image header to global variable `header'
80 * - checked header magic number, checksums (both header & image),
81 * - verified image architecture (PPC) and type (KERNEL or MULTI),
82 * - loaded (first part of) image to header load address,
83 * - disabled interrupts.
85 typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag,
86 int argc, char *argv[],
87 bootm_headers_t *images); /* pointers to os/initrd/fdt */
89 extern boot_os_fn do_bootm_linux;
90 static boot_os_fn do_bootm_netbsd;
91 #if defined(CONFIG_LYNXKDI)
92 static boot_os_fn do_bootm_lynxkdi;
93 extern void lynxkdi_boot (image_header_t *);
95 static boot_os_fn do_bootm_rtems;
96 #if defined(CONFIG_CMD_ELF)
97 static boot_os_fn do_bootm_vxworks;
98 static boot_os_fn do_bootm_qnxelf;
99 int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
100 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
102 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
103 extern uchar (*env_get_char)(int); /* Returns a character from the environment */
104 static boot_os_fn do_bootm_artos;
107 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
108 static bootm_headers_t images; /* pointers to os/initrd/fdt images */
110 void __board_lmb_reserve(struct lmb *lmb)
112 /* please define platform specific board_lmb_reserve() */
114 void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
117 /*******************************************************************/
118 /* bootm - boot application image from image in memory */
119 /*******************************************************************/
120 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
123 const char *type_name;
124 uint unc_len = CFG_BOOTM_LEN;
125 uint8_t comp, type, os;
128 ulong os_data, os_len;
129 ulong image_start, image_end;
130 ulong load_start, load_end;
131 ulong mem_start, mem_size;
135 memset ((void *)&images, 0, sizeof (images));
136 images.verify = getenv_verify();
137 images.autostart = getenv_autostart();
142 mem_start = getenv_bootm_low();
143 mem_size = getenv_bootm_size();
145 lmb_add(&lmb, mem_start, mem_size);
147 board_lmb_reserve(&lmb);
149 /* get kernel image header, start address and length */
150 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
151 &images, &os_data, &os_len);
153 puts ("ERROR: can't get kernel image!\n");
157 /* get image parameters */
158 switch (genimg_get_format (os_hdr)) {
159 case IMAGE_FORMAT_LEGACY:
160 type = image_get_type (os_hdr);
161 comp = image_get_comp (os_hdr);
162 os = image_get_os (os_hdr);
164 image_end = image_get_image_end (os_hdr);
165 load_start = image_get_load (os_hdr);
167 #if defined(CONFIG_FIT)
168 case IMAGE_FORMAT_FIT:
169 if (fit_image_get_type (images.fit_hdr_os,
170 images.fit_noffset_os, &type)) {
171 puts ("Can't get image type!\n");
172 show_boot_progress (-109);
176 if (fit_image_get_comp (images.fit_hdr_os,
177 images.fit_noffset_os, &comp)) {
178 puts ("Can't get image compression!\n");
179 show_boot_progress (-110);
183 if (fit_image_get_os (images.fit_hdr_os,
184 images.fit_noffset_os, &os)) {
185 puts ("Can't get image OS!\n");
186 show_boot_progress (-111);
190 image_end = fit_get_end (images.fit_hdr_os);
192 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
194 puts ("Can't get image load address!\n");
195 show_boot_progress (-112);
201 puts ("ERROR: unknown image format type!\n");
205 image_start = (ulong)os_hdr;
207 type_name = genimg_get_type_name (type);
210 * We have reached the point of no return: we are going to
211 * overwrite all exception vector code, so we cannot easily
212 * recover from any failures any more...
214 iflag = disable_interrupts();
216 #ifdef CONFIG_AMIGAONEG3SE
218 * We've possible left the caches enabled during
219 * bios emulation, so turn them off again
222 invalidate_l1_instruction_cache();
229 if (load_start == (ulong)os_hdr) {
230 printf (" XIP %s ... ", type_name);
232 printf (" Loading %s ... ", type_name);
234 memmove_wd ((void *)load_start,
235 (void *)os_data, os_len, CHUNKSZ);
237 load_end = load_start + os_len;
242 printf (" Uncompressing %s ... ", type_name);
243 if (gunzip ((void *)load_start, unc_len,
244 (uchar *)os_data, &os_len) != 0) {
245 puts ("GUNZIP: uncompress or overwrite error "
246 "- must RESET board to recover\n");
247 show_boot_progress (-6);
248 do_reset (cmdtp, flag, argc, argv);
251 load_end = load_start + os_len;
255 printf (" Uncompressing %s ... ", type_name);
257 * If we've got less than 4 MB of malloc() space,
258 * use slower decompression algorithm which requires
259 * at most 2300 KB of memory.
261 int i = BZ2_bzBuffToBuffDecompress ((char*)load_start,
262 &unc_len, (char *)os_data, os_len,
263 CFG_MALLOC_LEN < (4096 * 1024), 0);
265 printf ("BUNZIP2: uncompress or overwrite error %d "
266 "- must RESET board to recover\n", i);
267 show_boot_progress (-6);
268 do_reset (cmdtp, flag, argc, argv);
271 load_end = load_start + unc_len;
273 #endif /* CONFIG_BZIP2 */
277 printf ("Unimplemented compression type %d\n", comp);
278 show_boot_progress (-7);
282 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end);
283 show_boot_progress (7);
285 if ((load_start < image_end) && (load_end > image_start)) {
286 debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end);
287 debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end);
289 puts ("ERROR: image overwritten - must RESET the board to recover.\n");
290 show_boot_progress (-113);
291 do_reset (cmdtp, flag, argc, argv);
294 show_boot_progress (8);
296 lmb_reserve(&lmb, load_start, (load_end - load_start));
299 default: /* handled by (original) Linux case */
301 #ifdef CONFIG_SILENT_CONSOLE
302 fixup_silent_linux();
304 do_bootm_linux (cmdtp, flag, argc, argv, &images);
308 do_bootm_netbsd (cmdtp, flag, argc, argv, &images);
311 #ifdef CONFIG_LYNXKDI
313 do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images);
318 do_bootm_rtems (cmdtp, flag, argc, argv, &images);
321 #if defined(CONFIG_CMD_ELF)
323 do_bootm_vxworks (cmdtp, flag, argc, argv, &images);
327 do_bootm_qnxelf (cmdtp, flag, argc, argv, &images);
333 do_bootm_artos (cmdtp, flag, argc, argv, &images);
338 show_boot_progress (-9);
340 puts ("\n## Control returned to monitor - resetting...\n");
341 if (images.autostart)
342 do_reset (cmdtp, flag, argc, argv);
344 if (!images.autostart && iflag)
351 * image_get_kernel - verify legacy format kernel image
352 * @img_addr: in RAM address of the legacy format image to be verified
353 * @verify: data CRC verification flag
355 * image_get_kernel() verifies legacy image integrity and returns pointer to
356 * legacy image header if image verification was completed successfully.
359 * pointer to a legacy image header if valid image was found
360 * otherwise return NULL
362 static image_header_t *image_get_kernel (ulong img_addr, int verify)
364 image_header_t *hdr = (image_header_t *)img_addr;
366 if (!image_check_magic(hdr)) {
367 puts ("Bad Magic Number\n");
368 show_boot_progress (-1);
371 show_boot_progress (2);
373 if (!image_check_hcrc (hdr)) {
374 puts ("Bad Header Checksum\n");
375 show_boot_progress (-2);
379 show_boot_progress (3);
380 image_print_contents (hdr);
383 puts (" Verifying Checksum ... ");
384 if (!image_check_dcrc (hdr)) {
385 printf ("Bad Data CRC\n");
386 show_boot_progress (-3);
391 show_boot_progress (4);
393 if (!image_check_target_arch (hdr)) {
394 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
395 show_boot_progress (-4);
402 * fit_check_kernel - verify FIT format kernel subimage
403 * @fit_hdr: pointer to the FIT image header
404 * os_noffset: kernel subimage node offset within FIT image
405 * @verify: data CRC verification flag
407 * fit_check_kernel() verifies integrity of the kernel subimage and from
408 * specified FIT image.
414 #if defined (CONFIG_FIT)
415 static int fit_check_kernel (const void *fit, int os_noffset, int verify)
417 fit_image_print (fit, os_noffset, " ");
420 puts (" Verifying Hash Integrity ... ");
421 if (!fit_image_check_hashes (fit, os_noffset)) {
422 puts ("Bad Data Hash\n");
423 show_boot_progress (-104);
428 show_boot_progress (105);
430 #ifdef CONFIG_LOGBUFFER
431 #ifndef CONFIG_ALT_LB_ADDR
433 /* Prevent initrd from overwriting logbuffer */
434 if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
435 initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
436 debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
438 debug ("## Logbuffer at 0x%08lX ", CONFIG_ALT_LB_ADDR);
441 if (!fit_image_check_target_arch (fit, os_noffset)) {
442 puts ("Unsupported Architecture\n");
443 show_boot_progress (-105);
447 show_boot_progress (106);
448 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
449 puts ("Not a kernel image\n");
450 show_boot_progress (-106);
454 show_boot_progress (107);
457 #endif /* CONFIG_FIT */
460 * boot_get_kernel - find kernel image
461 * @os_data: pointer to a ulong variable, will hold os data start address
462 * @os_len: pointer to a ulong variable, will hold os data length
464 * boot_get_kernel() tries to find a kernel image, verifies its integrity
465 * and locates kernel data.
468 * pointer to image header if valid image was found, plus kernel start
469 * address and length, otherwise NULL
471 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
472 bootm_headers_t *images, ulong *os_data, ulong *os_len)
476 #if defined(CONFIG_FIT)
478 const char *fit_uname_config = NULL;
479 const char *fit_uname_kernel = NULL;
486 /* find out kernel image address */
488 img_addr = load_addr;
489 debug ("* kernel: default image load address = 0x%08lx\n",
491 #if defined(CONFIG_FIT)
492 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
493 &fit_uname_config)) {
494 debug ("* kernel: config '%s' from image at 0x%08lx\n",
495 fit_uname_config, img_addr);
496 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
497 &fit_uname_kernel)) {
498 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
499 fit_uname_kernel, img_addr);
502 img_addr = simple_strtoul(argv[1], NULL, 16);
503 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
506 show_boot_progress (1);
508 /* copy from dataflash if needed */
509 img_addr = genimg_get_image (img_addr);
511 /* check image type, for FIT images get FIT kernel node */
512 *os_data = *os_len = 0;
513 switch (genimg_get_format ((void *)img_addr)) {
514 case IMAGE_FORMAT_LEGACY:
515 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
517 hdr = image_get_kernel (img_addr, images->verify);
520 show_boot_progress (5);
522 /* get os_data and os_len */
523 switch (image_get_type (hdr)) {
525 *os_data = image_get_data (hdr);
526 *os_len = image_get_data_size (hdr);
529 image_multi_getimg (hdr, 0, os_data, os_len);
532 printf ("Wrong Image Type for %s command\n", cmdtp->name);
533 show_boot_progress (-5);
536 images->legacy_hdr_os = hdr;
537 images->legacy_hdr_valid = 1;
539 show_boot_progress (6);
541 #if defined(CONFIG_FIT)
542 case IMAGE_FORMAT_FIT:
543 fit_hdr = (void *)img_addr;
544 printf ("## Booting kernel from FIT Image at %08lx ...\n",
547 if (!fit_check_format (fit_hdr)) {
548 puts ("Bad FIT kernel image format!\n");
549 show_boot_progress (-100);
552 show_boot_progress (100);
554 if (!fit_uname_kernel) {
556 * no kernel image node unit name, try to get config
557 * node first. If config unit node name is NULL
558 * fit_conf_get_node() will try to find default config node
560 show_boot_progress (101);
561 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
562 if (cfg_noffset < 0) {
563 show_boot_progress (-101);
566 /* save configuration uname provided in the first
569 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
570 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
571 show_boot_progress (103);
573 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
574 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
576 /* get kernel component image node offset */
577 show_boot_progress (102);
578 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
580 if (os_noffset < 0) {
581 show_boot_progress (-103);
585 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
587 show_boot_progress (104);
588 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
591 /* get kernel image data address and length */
592 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
593 puts ("Could not find kernel subimage data!\n");
594 show_boot_progress (-107);
597 show_boot_progress (108);
600 *os_data = (ulong)data;
601 images->fit_hdr_os = fit_hdr;
602 images->fit_uname_os = fit_uname_kernel;
603 images->fit_noffset_os = os_noffset;
607 printf ("Wrong Image Format for %s command\n", cmdtp->name);
608 show_boot_progress (-108);
612 debug (" kernel data at 0x%08lx, len = 0x%08lx (%d)\n",
613 *os_data, *os_len, *os_len);
615 return (void *)img_addr;
619 bootm, CFG_MAXARGS, 1, do_bootm,
620 "bootm - boot application image from memory\n",
621 "[addr [arg ...]]\n - boot application image stored in memory\n"
622 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
623 "\t'arg' can be the address of an initrd image\n"
624 #if defined(CONFIG_OF_LIBFDT)
625 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
626 "\ta third argument is required which is the address of the\n"
627 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
628 "\tuse a '-' for the second argument. If you do not pass a third\n"
629 "\ta bd_info struct will be passed instead\n"
631 #if defined(CONFIG_FIT)
632 "\t\nFor the new multi component uImage format (FIT) addresses\n"
633 "\tmust be extened to include component or configuration unit name:\n"
634 "\taddr:<subimg_uname> - direct component image specification\n"
635 "\taddr#<conf_uname> - configuration specification\n"
636 "\tUse iminfo command to get the list of existing component\n"
637 "\timages and configurations.\n"
641 /*******************************************************************/
642 /* bootd - boot default image */
643 /*******************************************************************/
644 #if defined(CONFIG_CMD_BOOTD)
645 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
649 #ifndef CFG_HUSH_PARSER
650 if (run_command (getenv ("bootcmd"), flag) < 0)
653 if (parse_string_outer (getenv ("bootcmd"),
654 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
661 boot, 1, 1, do_bootd,
662 "boot - boot default, i.e., run 'bootcmd'\n",
666 /* keep old command name "bootd" for backward compatibility */
668 bootd, 1, 1, do_bootd,
669 "bootd - boot default, i.e., run 'bootcmd'\n",
676 /*******************************************************************/
677 /* iminfo - print header info for a requested image */
678 /*******************************************************************/
679 #if defined(CONFIG_CMD_IMI)
680 int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
687 return image_info (load_addr);
690 for (arg = 1; arg < argc; ++arg) {
691 addr = simple_strtoul (argv[arg], NULL, 16);
692 if (image_info (addr) != 0)
698 static int image_info (ulong addr)
700 void *hdr = (void *)addr;
702 printf ("\n## Checking Image at %08lx ...\n", addr);
704 switch (genimg_get_format (hdr)) {
705 case IMAGE_FORMAT_LEGACY:
706 puts (" Legacy image found\n");
707 if (!image_check_magic (hdr)) {
708 puts (" Bad Magic Number\n");
712 if (!image_check_hcrc (hdr)) {
713 puts (" Bad Header Checksum\n");
717 image_print_contents (hdr);
719 puts (" Verifying Checksum ... ");
720 if (!image_check_dcrc (hdr)) {
721 puts (" Bad Data CRC\n");
726 #if defined(CONFIG_FIT)
727 case IMAGE_FORMAT_FIT:
728 puts (" FIT image found\n");
730 if (!fit_check_format (hdr)) {
731 puts ("Bad FIT image format!\n");
735 fit_print_contents (hdr);
739 puts ("Unknown image format!\n");
747 iminfo, CFG_MAXARGS, 1, do_iminfo,
748 "iminfo - print header information for application image\n",
750 " - print header information for application image starting at\n"
751 " address 'addr' in memory; this includes verification of the\n"
752 " image contents (magic number, header and payload checksums)\n"
757 /*******************************************************************/
758 /* imls - list all images found in flash */
759 /*******************************************************************/
760 #if defined(CONFIG_CMD_IMLS)
761 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
767 for (i = 0, info = &flash_info[0];
768 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
770 if (info->flash_id == FLASH_UNKNOWN)
772 for (j = 0; j < info->sector_count; ++j) {
774 hdr = (void *)info->start[j];
778 switch (genimg_get_format (hdr)) {
779 case IMAGE_FORMAT_LEGACY:
780 if (!image_check_hcrc (hdr))
783 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
784 image_print_contents (hdr);
786 puts (" Verifying Checksum ... ");
787 if (!image_check_dcrc (hdr)) {
788 puts ("Bad Data CRC\n");
793 #if defined(CONFIG_FIT)
794 case IMAGE_FORMAT_FIT:
795 if (!fit_check_format (hdr))
798 printf ("FIT Image at %08lX:\n", (ulong)hdr);
799 fit_print_contents (hdr);
816 "imls - list all images found in flash\n",
818 " - Prints information about all images found at sector\n"
819 " boundaries in flash.\n"
823 /*******************************************************************/
824 /* helper routines */
825 /*******************************************************************/
826 #ifdef CONFIG_SILENT_CONSOLE
827 static void fixup_silent_linux ()
829 char buf[256], *start, *end;
830 char *cmdline = getenv ("bootargs");
832 /* Only fix cmdline when requested */
833 if (!(gd->flags & GD_FLG_SILENT))
836 debug ("before silent fix-up: %s\n", cmdline);
838 if ((start = strstr (cmdline, "console=")) != NULL) {
839 end = strchr (start, ' ');
840 strncpy (buf, cmdline, (start - cmdline + 8));
842 strcpy (buf + (start - cmdline + 8), end);
844 buf[start - cmdline + 8] = '\0';
846 strcpy (buf, cmdline);
847 strcat (buf, " console=");
850 strcpy (buf, "console=");
853 setenv ("bootargs", buf);
854 debug ("after silent fix-up: %s\n", buf);
856 #endif /* CONFIG_SILENT_CONSOLE */
859 /*******************************************************************/
860 /* OS booting routines */
861 /*******************************************************************/
863 static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
864 int argc, char *argv[],
865 bootm_headers_t *images)
867 void (*loader)(bd_t *, image_header_t *, char *, char *);
868 image_header_t *os_hdr, *hdr;
869 ulong kernel_data, kernel_len;
873 #if defined(CONFIG_FIT)
874 if (!images->legacy_hdr_valid) {
875 fit_unsupported_reset ("NetBSD");
876 do_reset (cmdtp, flag, argc, argv);
879 hdr = images->legacy_hdr_os;
882 * Booting a (NetBSD) kernel image
884 * This process is pretty similar to a standalone application:
885 * The (first part of an multi-) image must be a stage-2 loader,
886 * which in turn is responsible for loading & invoking the actual
887 * kernel. The only differences are the parameters being passed:
888 * besides the board info strucure, the loader expects a command
889 * line, the name of the console device, and (optionally) the
890 * address of the original image header.
893 if (image_check_type (hdr, IH_TYPE_MULTI)) {
894 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
900 #if defined (CONFIG_8xx_CONS_SMC1)
902 #elif defined (CONFIG_8xx_CONS_SMC2)
904 #elif defined (CONFIG_8xx_CONS_SCC2)
906 #elif defined (CONFIG_8xx_CONS_SCC3)
914 for (i = 2, len = 0; i < argc; i += 1)
915 len += strlen (argv[i]) + 1;
916 cmdline = malloc (len);
918 for (i = 2, len = 0; i < argc; i += 1) {
920 cmdline[len++] = ' ';
921 strcpy (&cmdline[len], argv[i]);
922 len += strlen (argv[i]);
924 } else if ((cmdline = getenv ("bootargs")) == NULL) {
928 loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
930 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
933 show_boot_progress (15);
936 * NetBSD Stage-2 Loader Parameters:
937 * r3: ptr to board info data
940 * r6: boot args string
942 (*loader) (gd->bd, os_hdr, consdev, cmdline);
945 #ifdef CONFIG_LYNXKDI
946 static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
947 int argc, char *argv[],
948 bootm_headers_t *images)
950 image_header_t *hdr = images->legacy_hdr_os;
952 #if defined(CONFIG_FIT)
953 if (!images->legacy_hdr_valid) {
954 fit_unsupported_reset ("Lynx");
955 do_reset (cmdtp, flag, argc, argv);
959 lynxkdi_boot ((image_header_t *)hdr);
961 #endif /* CONFIG_LYNXKDI */
963 static void do_bootm_rtems (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;
968 void (*entry_point)(bd_t *);
970 #if defined(CONFIG_FIT)
971 if (!images->legacy_hdr_valid) {
972 fit_unsupported_reset ("RTEMS");
973 do_reset (cmdtp, flag, argc, argv);
977 entry_point = (void (*)(bd_t *))image_get_ep (hdr);
979 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
982 show_boot_progress (15);
986 * r3: ptr to board info data
988 (*entry_point)(gd->bd);
991 #if defined(CONFIG_CMD_ELF)
992 static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
993 int argc, char *argv[],
994 bootm_headers_t *images)
997 image_header_t *hdr = images->legacy_hdr_os;
999 #if defined(CONFIG_FIT)
1001 fit_unsupported_reset ("VxWorks");
1002 do_reset (cmdtp, flag, argc, argv);
1006 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
1007 setenv("loadaddr", str);
1008 do_bootvx(cmdtp, 0, 0, NULL);
1011 static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
1012 int argc, char *argv[],
1013 bootm_headers_t *images)
1015 char *local_args[2];
1017 image_header_t *hdr = images->legacy_hdr_os;
1019 #if defined(CONFIG_FIT)
1020 if (!images->legacy_hdr_valid) {
1021 fit_unsupported_reset ("QNX");
1022 do_reset (cmdtp, flag, argc, argv);
1026 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
1027 local_args[0] = argv[0];
1028 local_args[1] = str; /* and provide it via the arguments */
1029 do_bootelf(cmdtp, 0, 2, local_args);
1033 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
1034 static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
1035 int argc, char *argv[],
1036 bootm_headers_t *images)
1041 int i, j, nxt, len, envno, envsz;
1043 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
1044 image_header_t *hdr = images->legacy_hdr_os;
1046 #if defined(CONFIG_FIT)
1047 if (!images->legacy_hdr_valid) {
1048 fit_unsupported_reset ("ARTOS");
1049 do_reset (cmdtp, flag, argc, argv);
1054 * Booting an ARTOS kernel image + application
1057 /* this used to be the top of memory, but was wrong... */
1059 /* get stack pointer */
1060 asm volatile ("mr %0,1" : "=r"(top) );
1062 debug ("## Current stack ends at 0x%08lX ", top);
1064 top -= 2048; /* just to be sure */
1065 if (top > CFG_BOOTMAPSZ)
1066 top = CFG_BOOTMAPSZ;
1069 debug ("=> set upper limit to 0x%08lX\n", top);
1071 /* first check the artos specific boot args, then the linux args*/
1072 if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
1075 /* get length of cmdline, and place it */
1077 top = (top - (len + 1)) & ~0xF;
1078 cmdline = (char *)top;
1079 debug ("## cmdline at 0x%08lX ", top);
1080 strcpy (cmdline, s);
1083 top = (top - sizeof (bd_t)) & ~0xF;
1084 debug ("## bd at 0x%08lX ", top);
1086 memcpy (kbd, gd->bd, sizeof (bd_t));
1088 /* first find number of env entries, and their size */
1091 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1092 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
1095 envsz += (nxt - i) + 1; /* plus trailing zero */
1097 envno++; /* plus the terminating zero */
1098 debug ("## %u envvars total size %u ", envno, envsz);
1100 top = (top - sizeof (char **) * envno) & ~0xF;
1101 fwenv = (char **)top;
1102 debug ("## fwenv at 0x%08lX ", top);
1104 top = (top - envsz) & ~0xF;
1109 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1110 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
1113 for (j = i; j < nxt; ++j)
1114 *s++ = env_get_char (j);
1117 *ss++ = NULL; /* terminate */
1119 entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
1120 (*entry) (kbd, cmdline, fwenv, top);