]> git.sur5r.net Git - u-boot/blob - common/cmd_bootm.c
[new uImage] Add image_get_kernel() routine
[u-boot] / common / cmd_bootm.c
1 /*
2  * (C) Copyright 2000-2006
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
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.
12  *
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.
17  *
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,
21  * MA 02111-1307 USA
22  */
23
24 #define DEBUG
25
26 /*
27  * Boot support
28  */
29 #include <common.h>
30 #include <watchdog.h>
31 #include <command.h>
32 #include <image.h>
33 #include <malloc.h>
34 #include <zlib.h>
35 #include <bzlib.h>
36 #include <environment.h>
37 #include <asm/byteorder.h>
38
39 #ifdef CFG_HUSH_PARSER
40 #include <hush.h>
41 #endif
42
43 DECLARE_GLOBAL_DATA_PTR;
44
45 extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
46 #ifndef CFG_BOOTM_LEN
47 #define CFG_BOOTM_LEN   0x800000        /* use 8MByte as default max gunzip size */
48 #endif
49
50 #ifdef CONFIG_BZIP2
51 extern void bz_internal_error(int);
52 #endif
53
54 #if defined(CONFIG_CMD_IMI)
55 static int image_info (unsigned long addr);
56 #endif
57
58 #if defined(CONFIG_CMD_IMLS)
59 #include <flash.h>
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[]);
62 #endif
63
64 #ifdef CONFIG_SILENT_CONSOLE
65 static void fixup_silent_linux (void);
66 #endif
67
68 static void *get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
69                 bootm_headers_t *images, ulong *os_data, ulong *os_len);
70 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
71
72 /*
73  *  Continue booting an OS image; caller already has:
74  *  - copied image header to global variable `header'
75  *  - checked header magic number, checksums (both header & image),
76  *  - verified image architecture (PPC) and type (KERNEL or MULTI),
77  *  - loaded (first part of) image to header load address,
78  *  - disabled interrupts.
79  */
80 typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag,
81                         int argc, char *argv[],
82                         bootm_headers_t *images); /* pointers to os/initrd/fdt */
83
84 extern boot_os_fn do_bootm_linux;
85 static boot_os_fn do_bootm_netbsd;
86 #if defined(CONFIG_LYNXKDI)
87 static boot_os_fn do_bootm_lynxkdi;
88 extern void lynxkdi_boot (image_header_t *);
89 #endif
90 static boot_os_fn do_bootm_rtems;
91 #if defined(CONFIG_CMD_ELF)
92 static boot_os_fn do_bootm_vxworks;
93 static boot_os_fn do_bootm_qnxelf;
94 int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
95 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
96 #endif
97 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
98 extern uchar (*env_get_char)(int); /* Returns a character from the environment */
99 static boot_os_fn do_bootm_artos;
100 #endif
101
102 ulong load_addr = CFG_LOAD_ADDR;        /* Default Load Address */
103 static bootm_headers_t images;          /* pointers to os/initrd/fdt images */
104
105
106 /*******************************************************************/
107 /* bootm - boot application image from image in memory */
108 /*******************************************************************/
109 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
110 {
111         ulong           iflag;
112         const char      *type_name;
113         uint            unc_len = CFG_BOOTM_LEN;
114         uint8_t         comp, type, os;
115
116         void            *os_hdr;
117         ulong           os_data, os_len;
118         ulong           image_start, image_end;
119         ulong           load_start, load_end;
120
121         memset ((void *)&images, 0, sizeof (images));
122         images.verify = getenv_verify();
123
124         /* get kernel image header, start address and length */
125         os_hdr = get_kernel (cmdtp, flag, argc, argv,
126                         &images, &os_data, &os_len);
127         if (os_len == 0)
128                 return 1;
129
130         show_boot_progress (6);
131
132         /* get image parameters */
133         switch (gen_image_get_format (os_hdr)) {
134         case IMAGE_FORMAT_LEGACY:
135                 type = image_get_type (os_hdr);
136                 comp = image_get_comp (os_hdr);
137                 os = image_get_os (os_hdr);
138
139                 image_end = image_get_image_end (os_hdr);
140                 load_start = image_get_load (os_hdr);
141                 break;
142 #if defined(CONFIG_FIT)
143         case IMAGE_FORMAT_FIT:
144                 fit_unsupported ("bootm");
145                 return 1;
146 #endif
147         default:
148                 puts ("ERROR: unknown image format type!\n");
149                 return 1;
150         }
151
152         image_start = (ulong)os_hdr;
153         load_end = 0;
154         type_name = image_get_type_name (type);
155
156         /*
157          * We have reached the point of no return: we are going to
158          * overwrite all exception vector code, so we cannot easily
159          * recover from any failures any more...
160          */
161         iflag = disable_interrupts();
162
163 #ifdef CONFIG_AMIGAONEG3SE
164         /*
165          * We've possible left the caches enabled during
166          * bios emulation, so turn them off again
167          */
168         icache_disable();
169         invalidate_l1_instruction_cache();
170         flush_data_cache();
171         dcache_disable();
172 #endif
173
174         switch (comp) {
175         case IH_COMP_NONE:
176                 if (load_start == (ulong)os_hdr) {
177                         printf ("   XIP %s ... ", type_name);
178                 } else {
179                         printf ("   Loading %s ... ", type_name);
180
181                         memmove_wd ((void *)load_start,
182                                    (void *)os_data, os_len, CHUNKSZ);
183
184                         load_end = load_start + os_len;
185                         puts("OK\n");
186                 }
187                 break;
188         case IH_COMP_GZIP:
189                 printf ("   Uncompressing %s ... ", type_name);
190                 if (gunzip ((void *)load_start, unc_len,
191                                         (uchar *)os_data, &os_len) != 0) {
192                         puts ("GUNZIP ERROR - must RESET board to recover\n");
193                         show_boot_progress (-6);
194                         do_reset (cmdtp, flag, argc, argv);
195                 }
196
197                 load_end = load_start + os_len;
198                 break;
199 #ifdef CONFIG_BZIP2
200         case IH_COMP_BZIP2:
201                 printf ("   Uncompressing %s ... ", type_name);
202                 /*
203                  * If we've got less than 4 MB of malloc() space,
204                  * use slower decompression algorithm which requires
205                  * at most 2300 KB of memory.
206                  */
207                 int i = BZ2_bzBuffToBuffDecompress ((char*)load_start,
208                                         &unc_len, (char *)os_data, os_len,
209                                         CFG_MALLOC_LEN < (4096 * 1024), 0);
210                 if (i != BZ_OK) {
211                         printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
212                         show_boot_progress (-6);
213                         do_reset (cmdtp, flag, argc, argv);
214                 }
215
216                 load_end = load_start + unc_len;
217                 break;
218 #endif /* CONFIG_BZIP2 */
219         default:
220                 if (iflag)
221                         enable_interrupts();
222                 printf ("Unimplemented compression type %d\n", comp);
223                 show_boot_progress (-7);
224                 return 1;
225         }
226         puts ("OK\n");
227         debug ("   kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end);
228         show_boot_progress (7);
229
230         if ((load_start < image_end) && (load_end > image_start)) {
231                 debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end);
232                 debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end);
233
234                 puts ("ERROR: image overwritten - must RESET the board to recover.\n");
235                 do_reset (cmdtp, flag, argc, argv);
236         }
237
238         show_boot_progress (8);
239
240         switch (os) {
241         default:                        /* handled by (original) Linux case */
242         case IH_OS_LINUX:
243 #ifdef CONFIG_SILENT_CONSOLE
244             fixup_silent_linux();
245 #endif
246             do_bootm_linux (cmdtp, flag, argc, argv, &images);
247             break;
248
249         case IH_OS_NETBSD:
250             do_bootm_netbsd (cmdtp, flag, argc, argv, &images);
251             break;
252
253 #ifdef CONFIG_LYNXKDI
254         case IH_OS_LYNXOS:
255             do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images);
256             break;
257 #endif
258
259         case IH_OS_RTEMS:
260             do_bootm_rtems (cmdtp, flag, argc, argv, &images);
261             break;
262
263 #if defined(CONFIG_CMD_ELF)
264         case IH_OS_VXWORKS:
265             do_bootm_vxworks (cmdtp, flag, argc, argv, &images);
266             break;
267
268         case IH_OS_QNX:
269             do_bootm_qnxelf (cmdtp, flag, argc, argv, &images);
270             break;
271 #endif
272
273 #ifdef CONFIG_ARTOS
274         case IH_OS_ARTOS:
275             do_bootm_artos (cmdtp, flag, argc, argv, &images);
276             break;
277 #endif
278         }
279
280         show_boot_progress (-9);
281 #ifdef DEBUG
282         puts ("\n## Control returned to monitor - resetting...\n");
283         do_reset (cmdtp, flag, argc, argv);
284 #endif
285         return 1;
286 }
287
288 /**
289  * get_kernel - find kernel image
290  * @os_data: pointer to a ulong variable, will hold os data start address
291  * @os_len: pointer to a ulong variable, will hold os data length
292  *
293  * get_kernel() tries to find a kernel image, verifies its integrity
294  * and locates kernel data.
295  *
296  * returns:
297  *     pointer to image header if valid image was found, plus kernel start
298  *     address and length, otherwise NULL
299  */
300 static image_header_t *image_get_kernel (ulong img_addr, int verify)
301 {
302         image_header_t *hdr = (image_header_t *)img_addr;
303
304         if (!image_check_magic(hdr)) {
305                 puts ("Bad Magic Number\n");
306                 show_boot_progress (-1);
307                 return NULL;
308         }
309         show_boot_progress (2);
310
311         if (!image_check_hcrc (hdr)) {
312                 puts ("Bad Header Checksum\n");
313                 show_boot_progress (-2);
314                 return NULL;
315         }
316
317         show_boot_progress (3);
318         image_print_contents (hdr);
319
320         if (verify) {
321                 puts ("   Verifying Checksum ... ");
322                 if (!image_check_dcrc (hdr)) {
323                         printf ("Bad Data CRC\n");
324                         show_boot_progress (-3);
325                         return NULL;
326                 }
327                 puts ("OK\n");
328         }
329         show_boot_progress (4);
330
331         if (!image_check_target_arch (hdr)) {
332                 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
333                 show_boot_progress (-4);
334                 return NULL;
335         }
336         return hdr;
337 }
338
339 /**
340  * get_kernel - find kernel image
341  * @os_data: pointer to a ulong variable, will hold os data start address
342  * @os_len: pointer to a ulong variable, will hold os data length
343  *
344  * get_kernel() tries to find a kernel image, verifies its integrity
345  * and locates kernel data.
346  *
347  * returns:
348  *     pointer to image header if valid image was found, plus kernel start
349  *     address and length, otherwise NULL
350  */
351 static void *get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
352                 bootm_headers_t *images, ulong *os_data, ulong *os_len)
353 {
354         image_header_t  *hdr;
355         ulong           img_addr;
356 #if defined(CONFIG_FIT)
357         void            *fit_hdr;
358         const char      *fit_uname_config = NULL;
359         const char      *fit_uname_kernel = NULL;
360 #endif
361
362         /* find out kernel image address */
363         if (argc < 2) {
364                 img_addr = load_addr;
365                 debug ("*  kernel: default image load address = 0x%08lx\n",
366                                 load_addr);
367 #if defined(CONFIG_FIT)
368         } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
369                                                         &fit_uname_config)) {
370                 debug ("*  kernel: config '%s' from image at 0x%08lx\n",
371                                 fit_uname_config, img_addr);
372         } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
373                                                         &fit_uname_kernel)) {
374                 debug ("*  kernel: subimage '%s' from image at 0x%08lx\n",
375                                 fit_uname_kernel, img_addr);
376 #endif
377         } else {
378                 img_addr = simple_strtoul(argv[1], NULL, 16);
379                 debug ("*  kernel: cmdline image address = 0x%08lx\n", img_addr);
380         }
381
382         show_boot_progress (1);
383         printf ("## Booting kernel image at %08lx ...\n", img_addr);
384
385         /* copy from dataflash if needed */
386         img_addr = gen_get_image (img_addr);
387
388         /* check image type, for FIT images get FIT kernel node */
389         switch (gen_image_get_format ((void *)img_addr)) {
390         case IMAGE_FORMAT_LEGACY:
391
392                 debug ("*  kernel: legacy format image\n");
393                 hdr = image_get_kernel (img_addr, images->verify);
394                 if (!hdr)
395                         return NULL;
396                 show_boot_progress (5);
397
398                 switch (image_get_type (hdr)) {
399                 case IH_TYPE_KERNEL:
400                         *os_data = image_get_data (hdr);
401                         *os_len = image_get_data_size (hdr);
402                         break;
403                 case IH_TYPE_MULTI:
404                         image_multi_getimg (hdr, 0, os_data, os_len);
405                         break;
406                 default:
407                         printf ("Wrong Image Type for %s command\n", cmdtp->name);
408                         show_boot_progress (-5);
409                         return NULL;
410                 }
411                 images->legacy_hdr_os = hdr;
412                 images->legacy_hdr_valid = 1;
413
414                 break;
415 #if defined(CONFIG_FIT)
416         case IMAGE_FORMAT_FIT:
417                 fit_hdr = (void *)img_addr;
418                 debug ("*  kernel: FIT format image\n");
419                 fit_unsupported ("kernel");
420                 return NULL;
421 #endif
422         default:
423                 printf ("Wrong Image Format for %s command\n", cmdtp->name);
424                 return NULL;
425         }
426
427         debug ("   kernel data at 0x%08lx, end = 0x%08lx\n",
428                         *os_data, *os_data + *os_len);
429
430         return (void *)img_addr;
431 }
432
433 U_BOOT_CMD(
434         bootm,  CFG_MAXARGS,    1,      do_bootm,
435         "bootm   - boot application image from memory\n",
436         "[addr [arg ...]]\n    - boot application image stored in memory\n"
437         "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
438         "\t'arg' can be the address of an initrd image\n"
439 #if defined(CONFIG_OF_LIBFDT)
440         "\tWhen booting a Linux kernel which requires a flat device-tree\n"
441         "\ta third argument is required which is the address of the\n"
442         "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
443         "\tuse a '-' for the second argument. If you do not pass a third\n"
444         "\ta bd_info struct will be passed instead\n"
445 #endif
446 );
447
448 /*******************************************************************/
449 /* bootd - boot default image */
450 /*******************************************************************/
451 #if defined(CONFIG_CMD_BOOTD)
452 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
453 {
454         int rcode = 0;
455
456 #ifndef CFG_HUSH_PARSER
457         if (run_command (getenv ("bootcmd"), flag) < 0)
458                 rcode = 1;
459 #else
460         if (parse_string_outer (getenv ("bootcmd"),
461                         FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
462                 rcode = 1;
463 #endif
464         return rcode;
465 }
466
467 U_BOOT_CMD(
468         boot,   1,      1,      do_bootd,
469         "boot    - boot default, i.e., run 'bootcmd'\n",
470         NULL
471 );
472
473 /* keep old command name "bootd" for backward compatibility */
474 U_BOOT_CMD(
475         bootd, 1,       1,      do_bootd,
476         "bootd   - boot default, i.e., run 'bootcmd'\n",
477         NULL
478 );
479
480 #endif
481
482
483 /*******************************************************************/
484 /* iminfo - print header info for a requested image */
485 /*******************************************************************/
486 #if defined(CONFIG_CMD_IMI)
487 int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
488 {
489         int     arg;
490         ulong   addr;
491         int     rcode = 0;
492
493         if (argc < 2) {
494                 return image_info (load_addr);
495         }
496
497         for (arg = 1; arg < argc; ++arg) {
498                 addr = simple_strtoul (argv[arg], NULL, 16);
499                 if (image_info (addr) != 0)
500                         rcode = 1;
501         }
502         return rcode;
503 }
504
505 static int image_info (ulong addr)
506 {
507         void *hdr = (void *)addr;
508
509         printf ("\n## Checking Image at %08lx ...\n", addr);
510
511         switch (gen_image_get_format (hdr)) {
512         case IMAGE_FORMAT_LEGACY:
513                 puts ("   Legacy image found\n");
514                 if (!image_check_magic (hdr)) {
515                         puts ("   Bad Magic Number\n");
516                         return 1;
517                 }
518
519                 if (!image_check_hcrc (hdr)) {
520                         puts ("   Bad Header Checksum\n");
521                         return 1;
522                 }
523
524                 image_print_contents (hdr);
525
526                 puts ("   Verifying Checksum ... ");
527                 if (!image_check_dcrc (hdr)) {
528                         puts ("   Bad Data CRC\n");
529                         return 1;
530                 }
531                 puts ("OK\n");
532                 return 0;
533 #if defined(CONFIG_FIT)
534         case IMAGE_FORMAT_FIT:
535                 puts ("   FIT image found\n");
536                 fit_unsupported ("iminfo");
537                 return 0;
538 #endif
539         default:
540                 puts ("Unknown image format!\n");
541                 break;
542         }
543
544         return 1;
545 }
546
547 U_BOOT_CMD(
548         iminfo, CFG_MAXARGS,    1,      do_iminfo,
549         "iminfo  - print header information for application image\n",
550         "addr [addr ...]\n"
551         "    - print header information for application image starting at\n"
552         "      address 'addr' in memory; this includes verification of the\n"
553         "      image contents (magic number, header and payload checksums)\n"
554 );
555 #endif
556
557
558 /*******************************************************************/
559 /* imls - list all images found in flash */
560 /*******************************************************************/
561 #if defined(CONFIG_CMD_IMLS)
562 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
563 {
564         flash_info_t *info;
565         int i, j;
566         void *hdr;
567
568         for (i = 0, info = &flash_info[0];
569                 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
570
571                 if (info->flash_id == FLASH_UNKNOWN)
572                         goto next_bank;
573                 for (j = 0; j < info->sector_count; ++j) {
574
575                         hdr = (void *)info->start[j];
576                         if (!hdr)
577                                 goto next_sector;
578
579                         switch (gen_image_get_format (hdr)) {
580                         case IMAGE_FORMAT_LEGACY:
581                                 if (!image_check_magic (hdr))
582                                         goto next_sector;
583
584                                 if (!image_check_hcrc (hdr))
585                                         goto next_sector;
586
587                                 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
588                                 image_print_contents (hdr);
589
590                                 puts ("   Verifying Checksum ... ");
591                                 if (!image_check_dcrc (hdr)) {
592                                         puts ("Bad Data CRC\n");
593                                 } else {
594                                         puts ("OK\n");
595                                 }
596                                 break;
597 #if defined(CONFIG_FIT)
598                         case IMAGE_FORMAT_FIT:
599                                 printf ("FIT Image at %08lX:\n", (ulong)hdr);
600                                 fit_unsupported ("imls");
601                                 break;
602 #endif
603                         default:
604                                 goto next_sector;
605                         }
606
607 next_sector:            ;
608                 }
609 next_bank:      ;
610         }
611
612         return (0);
613 }
614
615 U_BOOT_CMD(
616         imls,   1,              1,      do_imls,
617         "imls    - list all images found in flash\n",
618         "\n"
619         "    - Prints information about all images found at sector\n"
620         "      boundaries in flash.\n"
621 );
622 #endif
623
624 /*******************************************************************/
625 /* helper routines */
626 /*******************************************************************/
627 #ifdef CONFIG_SILENT_CONSOLE
628 static void fixup_silent_linux ()
629 {
630         char buf[256], *start, *end;
631         char *cmdline = getenv ("bootargs");
632
633         /* Only fix cmdline when requested */
634         if (!(gd->flags & GD_FLG_SILENT))
635                 return;
636
637         debug ("before silent fix-up: %s\n", cmdline);
638         if (cmdline) {
639                 if ((start = strstr (cmdline, "console=")) != NULL) {
640                         end = strchr (start, ' ');
641                         strncpy (buf, cmdline, (start - cmdline + 8));
642                         if (end)
643                                 strcpy (buf + (start - cmdline + 8), end);
644                         else
645                                 buf[start - cmdline + 8] = '\0';
646                 } else {
647                         strcpy (buf, cmdline);
648                         strcat (buf, " console=");
649                 }
650         } else {
651                 strcpy (buf, "console=");
652         }
653
654         setenv ("bootargs", buf);
655         debug ("after silent fix-up: %s\n", buf);
656 }
657 #endif /* CONFIG_SILENT_CONSOLE */
658
659
660 /*******************************************************************/
661 /* OS booting routines */
662 /*******************************************************************/
663
664 static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
665                             int argc, char *argv[],
666                             bootm_headers_t *images)
667 {
668         void (*loader)(bd_t *, image_header_t *, char *, char *);
669         image_header_t *os_hdr, *hdr;
670         ulong kernel_data, kernel_len;
671         char *consdev;
672         char *cmdline;
673
674 #if defined(CONFIG_FIT)
675         if (!images->legacy_hdr_valid) {
676                 fit_unsupported_reset ("NetBSD");
677                 do_reset (cmdtp, flag, argc, argv);
678         }
679 #endif
680         hdr = images->legacy_hdr_os;
681
682         /*
683          * Booting a (NetBSD) kernel image
684          *
685          * This process is pretty similar to a standalone application:
686          * The (first part of an multi-) image must be a stage-2 loader,
687          * which in turn is responsible for loading & invoking the actual
688          * kernel.  The only differences are the parameters being passed:
689          * besides the board info strucure, the loader expects a command
690          * line, the name of the console device, and (optionally) the
691          * address of the original image header.
692          */
693         os_hdr = NULL;
694         if (image_check_type (hdr, IH_TYPE_MULTI)) {
695                 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
696                 if (kernel_len)
697                         os_hdr = hdr;
698         }
699
700         consdev = "";
701 #if   defined (CONFIG_8xx_CONS_SMC1)
702         consdev = "smc1";
703 #elif defined (CONFIG_8xx_CONS_SMC2)
704         consdev = "smc2";
705 #elif defined (CONFIG_8xx_CONS_SCC2)
706         consdev = "scc2";
707 #elif defined (CONFIG_8xx_CONS_SCC3)
708         consdev = "scc3";
709 #endif
710
711         if (argc > 2) {
712                 ulong len;
713                 int   i;
714
715                 for (i = 2, len = 0; i < argc; i += 1)
716                         len += strlen (argv[i]) + 1;
717                 cmdline = malloc (len);
718
719                 for (i = 2, len = 0; i < argc; i += 1) {
720                         if (i > 2)
721                                 cmdline[len++] = ' ';
722                         strcpy (&cmdline[len], argv[i]);
723                         len += strlen (argv[i]);
724                 }
725         } else if ((cmdline = getenv ("bootargs")) == NULL) {
726                 cmdline = "";
727         }
728
729         loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
730
731         printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
732                 (ulong)loader);
733
734         show_boot_progress (15);
735
736         /*
737          * NetBSD Stage-2 Loader Parameters:
738          *   r3: ptr to board info data
739          *   r4: image address
740          *   r5: console device
741          *   r6: boot args string
742          */
743         (*loader) (gd->bd, os_hdr, consdev, cmdline);
744 }
745
746 #ifdef CONFIG_LYNXKDI
747 static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
748                              int argc, char *argv[],
749                              bootm_headers_t *images)
750 {
751         image_header_t *hdr = images->legacy_hdr_os;
752
753 #if defined(CONFIG_FIT)
754         if (!images->legacy_hdr_valid) {
755                 fit_unsupported_reset ("Lynx");
756                 do_reset (cmdtp, flag, argc, argv);
757         }
758 #endif
759
760         lynxkdi_boot ((image_header_t *)hdr);
761 }
762 #endif /* CONFIG_LYNXKDI */
763
764 static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
765                            int argc, char *argv[],
766                            bootm_headers_t *images)
767 {
768         image_header_t *hdr = images->legacy_hdr_os;
769         void (*entry_point)(bd_t *);
770
771 #if defined(CONFIG_FIT)
772         if (!images->legacy_hdr_valid) {
773                 fit_unsupported_reset ("RTEMS");
774                 do_reset (cmdtp, flag, argc, argv);
775         }
776 #endif
777
778         entry_point = (void (*)(bd_t *))image_get_ep (hdr);
779
780         printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
781                 (ulong)entry_point);
782
783         show_boot_progress (15);
784
785         /*
786          * RTEMS Parameters:
787          *   r3: ptr to board info data
788          */
789         (*entry_point)(gd->bd);
790 }
791
792 #if defined(CONFIG_CMD_ELF)
793 static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
794                              int argc, char *argv[],
795                              bootm_headers_t *images)
796 {
797         char str[80];
798         image_header_t *hdr = images->legacy_hdr_os;
799
800 #if defined(CONFIG_FIT)
801         if (hdr == NULL) {
802                 fit_unsupported_reset ("VxWorks");
803                 do_reset (cmdtp, flag, argc, argv);
804         }
805 #endif
806
807         sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
808         setenv("loadaddr", str);
809         do_bootvx(cmdtp, 0, 0, NULL);
810 }
811
812 static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
813                             int argc, char *argv[],
814                             bootm_headers_t *images)
815 {
816         char *local_args[2];
817         char str[16];
818         image_header_t *hdr = images->legacy_hdr_os;
819
820 #if defined(CONFIG_FIT)
821         if (!images->legacy_hdr_valid) {
822                 fit_unsupported_reset ("QNX");
823                 do_reset (cmdtp, flag, argc, argv);
824         }
825 #endif
826
827         sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
828         local_args[0] = argv[0];
829         local_args[1] = str;    /* and provide it via the arguments */
830         do_bootelf(cmdtp, 0, 2, local_args);
831 }
832 #endif
833
834 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
835 static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
836                            int argc, char *argv[],
837                            bootm_headers_t *images)
838 {
839         ulong top;
840         char *s, *cmdline;
841         char **fwenv, **ss;
842         int i, j, nxt, len, envno, envsz;
843         bd_t *kbd;
844         void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
845         image_header_t *hdr = images->legacy_hdr_os;
846
847 #if defined(CONFIG_FIT)
848         if (!images->legacy_hdr_valid) {
849                 fit_unsupported_reset ("ARTOS");
850                 do_reset (cmdtp, flag, argc, argv);
851         }
852 #endif
853
854         /*
855          * Booting an ARTOS kernel image + application
856          */
857
858         /* this used to be the top of memory, but was wrong... */
859 #ifdef CONFIG_PPC
860         /* get stack pointer */
861         asm volatile ("mr %0,1" : "=r"(top) );
862 #endif
863         debug ("## Current stack ends at 0x%08lX ", top);
864
865         top -= 2048;            /* just to be sure */
866         if (top > CFG_BOOTMAPSZ)
867                 top = CFG_BOOTMAPSZ;
868         top &= ~0xF;
869
870         debug ("=> set upper limit to 0x%08lX\n", top);
871
872         /* first check the artos specific boot args, then the linux args*/
873         if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
874                 s = "";
875
876         /* get length of cmdline, and place it */
877         len = strlen (s);
878         top = (top - (len + 1)) & ~0xF;
879         cmdline = (char *)top;
880         debug ("## cmdline at 0x%08lX ", top);
881         strcpy (cmdline, s);
882
883         /* copy bdinfo */
884         top = (top - sizeof (bd_t)) & ~0xF;
885         debug ("## bd at 0x%08lX ", top);
886         kbd = (bd_t *)top;
887         memcpy (kbd, gd->bd, sizeof (bd_t));
888
889         /* first find number of env entries, and their size */
890         envno = 0;
891         envsz = 0;
892         for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
893                 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
894                         ;
895                 envno++;
896                 envsz += (nxt - i) + 1; /* plus trailing zero */
897         }
898         envno++;        /* plus the terminating zero */
899         debug ("## %u envvars total size %u ", envno, envsz);
900
901         top = (top - sizeof (char **) * envno) & ~0xF;
902         fwenv = (char **)top;
903         debug ("## fwenv at 0x%08lX ", top);
904
905         top = (top - envsz) & ~0xF;
906         s = (char *)top;
907         ss = fwenv;
908
909         /* now copy them */
910         for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
911                 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
912                         ;
913                 *ss++ = s;
914                 for (j = i; j < nxt; ++j)
915                         *s++ = env_get_char (j);
916                 *s++ = '\0';
917         }
918         *ss++ = NULL;   /* terminate */
919
920         entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
921         (*entry) (kbd, cmdline, fwenv, top);
922 }
923 #endif