]> git.sur5r.net Git - u-boot/blob - common/cmd_bootm.c
[new uImage] Move image verify flag to bootm_headers structure
[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 void *get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
301                 bootm_headers_t *images, ulong *os_data, ulong *os_len)
302 {
303         image_header_t  *hdr;
304         ulong           img_addr;
305 #if defined(CONFIG_FIT)
306         void            *fit_hdr;
307         const char      *fit_uname_config = NULL;
308         const char      *fit_uname_kernel = NULL;
309 #endif
310
311         /* find out kernel image address */
312         if (argc < 2) {
313                 img_addr = load_addr;
314                 debug ("*  kernel: default image load address = 0x%08lx\n",
315                                 load_addr);
316 #if defined(CONFIG_FIT)
317         } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
318                                                         &fit_uname_config)) {
319                 debug ("*  kernel: config '%s' from image at 0x%08lx\n",
320                                 fit_uname_config, img_addr);
321         } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
322                                                         &fit_uname_kernel)) {
323                 debug ("*  kernel: subimage '%s' from image at 0x%08lx\n",
324                                 fit_uname_kernel, img_addr);
325 #endif
326         } else {
327                 img_addr = simple_strtoul(argv[1], NULL, 16);
328                 debug ("*  kernel: cmdline image address = 0x%08lx\n", img_addr);
329         }
330
331         show_boot_progress (1);
332         printf ("## Booting kernel image at %08lx ...\n", img_addr);
333
334         /* copy from dataflash if needed */
335         img_addr = gen_get_image (img_addr);
336
337         /* check image type, for FIT images get FIT kernel node */
338         switch (gen_image_get_format ((void *)img_addr)) {
339         case IMAGE_FORMAT_LEGACY:
340
341                 debug ("*  kernel: legacy format image\n");
342                 hdr = (image_header_t *)img_addr;
343
344                 if (!image_check_magic(hdr)) {
345                         puts ("Bad Magic Number\n");
346                         show_boot_progress (-1);
347                         return NULL;
348                 }
349                 show_boot_progress (2);
350
351                 if (!image_check_hcrc (hdr)) {
352                         puts ("Bad Header Checksum\n");
353                         show_boot_progress (-2);
354                         return NULL;
355                 }
356
357                 show_boot_progress (3);
358                 image_print_contents (hdr);
359
360                 if (images->verify) {
361                         puts ("   Verifying Checksum ... ");
362                         if (!image_check_dcrc (hdr)) {
363                                 printf ("Bad Data CRC\n");
364                                 show_boot_progress (-3);
365                                 return NULL;
366                         }
367                         puts ("OK\n");
368                 }
369                 show_boot_progress (4);
370
371                 if (!image_check_target_arch (hdr)) {
372                         printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
373                         show_boot_progress (-4);
374                         return NULL;
375                 }
376                 show_boot_progress (5);
377
378                 switch (image_get_type (hdr)) {
379                 case IH_TYPE_KERNEL:
380                         *os_data = image_get_data (hdr);
381                         *os_len = image_get_data_size (hdr);
382                         break;
383                 case IH_TYPE_MULTI:
384                         image_multi_getimg (hdr, 0, os_data, os_len);
385                         break;
386                 default:
387                         printf ("Wrong Image Type for %s command\n", cmdtp->name);
388                         show_boot_progress (-5);
389                         return NULL;
390                 }
391                 images->legacy_hdr_os = hdr;
392                 images->legacy_hdr_valid = 1;
393
394                 break;
395 #if defined(CONFIG_FIT)
396         case IMAGE_FORMAT_FIT:
397                 fit_hdr = (void *)img_addr;
398                 debug ("*  kernel: FIT format image\n");
399                 fit_unsupported ("kernel");
400                 return NULL;
401 #endif
402         default:
403                 printf ("Wrong Image Format for %s command\n", cmdtp->name);
404                 return NULL;
405         }
406
407         debug ("   kernel data at 0x%08lx, end = 0x%08lx\n",
408                         *os_data, *os_data + *os_len);
409
410         return (void *)img_addr;
411 }
412
413 U_BOOT_CMD(
414         bootm,  CFG_MAXARGS,    1,      do_bootm,
415         "bootm   - boot application image from memory\n",
416         "[addr [arg ...]]\n    - boot application image stored in memory\n"
417         "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
418         "\t'arg' can be the address of an initrd image\n"
419 #if defined(CONFIG_OF_LIBFDT)
420         "\tWhen booting a Linux kernel which requires a flat device-tree\n"
421         "\ta third argument is required which is the address of the\n"
422         "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
423         "\tuse a '-' for the second argument. If you do not pass a third\n"
424         "\ta bd_info struct will be passed instead\n"
425 #endif
426 );
427
428 /*******************************************************************/
429 /* bootd - boot default image */
430 /*******************************************************************/
431 #if defined(CONFIG_CMD_BOOTD)
432 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
433 {
434         int rcode = 0;
435
436 #ifndef CFG_HUSH_PARSER
437         if (run_command (getenv ("bootcmd"), flag) < 0)
438                 rcode = 1;
439 #else
440         if (parse_string_outer (getenv ("bootcmd"),
441                         FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
442                 rcode = 1;
443 #endif
444         return rcode;
445 }
446
447 U_BOOT_CMD(
448         boot,   1,      1,      do_bootd,
449         "boot    - boot default, i.e., run 'bootcmd'\n",
450         NULL
451 );
452
453 /* keep old command name "bootd" for backward compatibility */
454 U_BOOT_CMD(
455         bootd, 1,       1,      do_bootd,
456         "bootd   - boot default, i.e., run 'bootcmd'\n",
457         NULL
458 );
459
460 #endif
461
462
463 /*******************************************************************/
464 /* iminfo - print header info for a requested image */
465 /*******************************************************************/
466 #if defined(CONFIG_CMD_IMI)
467 int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
468 {
469         int     arg;
470         ulong   addr;
471         int     rcode = 0;
472
473         if (argc < 2) {
474                 return image_info (load_addr);
475         }
476
477         for (arg = 1; arg < argc; ++arg) {
478                 addr = simple_strtoul (argv[arg], NULL, 16);
479                 if (image_info (addr) != 0)
480                         rcode = 1;
481         }
482         return rcode;
483 }
484
485 static int image_info (ulong addr)
486 {
487         void *hdr = (void *)addr;
488
489         printf ("\n## Checking Image at %08lx ...\n", addr);
490
491         switch (gen_image_get_format (hdr)) {
492         case IMAGE_FORMAT_LEGACY:
493                 puts ("   Legacy image found\n");
494                 if (!image_check_magic (hdr)) {
495                         puts ("   Bad Magic Number\n");
496                         return 1;
497                 }
498
499                 if (!image_check_hcrc (hdr)) {
500                         puts ("   Bad Header Checksum\n");
501                         return 1;
502                 }
503
504                 image_print_contents (hdr);
505
506                 puts ("   Verifying Checksum ... ");
507                 if (!image_check_dcrc (hdr)) {
508                         puts ("   Bad Data CRC\n");
509                         return 1;
510                 }
511                 puts ("OK\n");
512                 return 0;
513 #if defined(CONFIG_FIT)
514         case IMAGE_FORMAT_FIT:
515                 puts ("   FIT image found\n");
516                 fit_unsupported ("iminfo");
517                 return 0;
518 #endif
519         default:
520                 puts ("Unknown image format!\n");
521                 break;
522         }
523
524         return 1;
525 }
526
527 U_BOOT_CMD(
528         iminfo, CFG_MAXARGS,    1,      do_iminfo,
529         "iminfo  - print header information for application image\n",
530         "addr [addr ...]\n"
531         "    - print header information for application image starting at\n"
532         "      address 'addr' in memory; this includes verification of the\n"
533         "      image contents (magic number, header and payload checksums)\n"
534 );
535 #endif
536
537
538 /*******************************************************************/
539 /* imls - list all images found in flash */
540 /*******************************************************************/
541 #if defined(CONFIG_CMD_IMLS)
542 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
543 {
544         flash_info_t *info;
545         int i, j;
546         void *hdr;
547
548         for (i = 0, info = &flash_info[0];
549                 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
550
551                 if (info->flash_id == FLASH_UNKNOWN)
552                         goto next_bank;
553                 for (j = 0; j < info->sector_count; ++j) {
554
555                         hdr = (void *)info->start[j];
556                         if (!hdr)
557                                 goto next_sector;
558
559                         switch (gen_image_get_format (hdr)) {
560                         case IMAGE_FORMAT_LEGACY:
561                                 if (!image_check_magic (hdr))
562                                         goto next_sector;
563
564                                 if (!image_check_hcrc (hdr))
565                                         goto next_sector;
566
567                                 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
568                                 image_print_contents (hdr);
569
570                                 puts ("   Verifying Checksum ... ");
571                                 if (!image_check_dcrc (hdr)) {
572                                         puts ("Bad Data CRC\n");
573                                 } else {
574                                         puts ("OK\n");
575                                 }
576                                 break;
577 #if defined(CONFIG_FIT)
578                         case IMAGE_FORMAT_FIT:
579                                 printf ("FIT Image at %08lX:\n", (ulong)hdr);
580                                 fit_unsupported ("imls");
581                                 break;
582 #endif
583                         default:
584                                 goto next_sector;
585                         }
586
587 next_sector:            ;
588                 }
589 next_bank:      ;
590         }
591
592         return (0);
593 }
594
595 U_BOOT_CMD(
596         imls,   1,              1,      do_imls,
597         "imls    - list all images found in flash\n",
598         "\n"
599         "    - Prints information about all images found at sector\n"
600         "      boundaries in flash.\n"
601 );
602 #endif
603
604 /*******************************************************************/
605 /* helper routines */
606 /*******************************************************************/
607 #ifdef CONFIG_SILENT_CONSOLE
608 static void fixup_silent_linux ()
609 {
610         char buf[256], *start, *end;
611         char *cmdline = getenv ("bootargs");
612
613         /* Only fix cmdline when requested */
614         if (!(gd->flags & GD_FLG_SILENT))
615                 return;
616
617         debug ("before silent fix-up: %s\n", cmdline);
618         if (cmdline) {
619                 if ((start = strstr (cmdline, "console=")) != NULL) {
620                         end = strchr (start, ' ');
621                         strncpy (buf, cmdline, (start - cmdline + 8));
622                         if (end)
623                                 strcpy (buf + (start - cmdline + 8), end);
624                         else
625                                 buf[start - cmdline + 8] = '\0';
626                 } else {
627                         strcpy (buf, cmdline);
628                         strcat (buf, " console=");
629                 }
630         } else {
631                 strcpy (buf, "console=");
632         }
633
634         setenv ("bootargs", buf);
635         debug ("after silent fix-up: %s\n", buf);
636 }
637 #endif /* CONFIG_SILENT_CONSOLE */
638
639
640 /*******************************************************************/
641 /* OS booting routines */
642 /*******************************************************************/
643
644 static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
645                             int argc, char *argv[],
646                             bootm_headers_t *images)
647 {
648         void (*loader)(bd_t *, image_header_t *, char *, char *);
649         image_header_t *os_hdr, *hdr;
650         ulong kernel_data, kernel_len;
651         char *consdev;
652         char *cmdline;
653
654 #if defined(CONFIG_FIT)
655         if (!images->legacy_hdr_valid) {
656                 fit_unsupported_reset ("NetBSD");
657                 do_reset (cmdtp, flag, argc, argv);
658         }
659 #endif
660         hdr = images->legacy_hdr_os;
661
662         /*
663          * Booting a (NetBSD) kernel image
664          *
665          * This process is pretty similar to a standalone application:
666          * The (first part of an multi-) image must be a stage-2 loader,
667          * which in turn is responsible for loading & invoking the actual
668          * kernel.  The only differences are the parameters being passed:
669          * besides the board info strucure, the loader expects a command
670          * line, the name of the console device, and (optionally) the
671          * address of the original image header.
672          */
673         os_hdr = NULL;
674         if (image_check_type (hdr, IH_TYPE_MULTI)) {
675                 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
676                 if (kernel_len)
677                         os_hdr = hdr;
678         }
679
680         consdev = "";
681 #if   defined (CONFIG_8xx_CONS_SMC1)
682         consdev = "smc1";
683 #elif defined (CONFIG_8xx_CONS_SMC2)
684         consdev = "smc2";
685 #elif defined (CONFIG_8xx_CONS_SCC2)
686         consdev = "scc2";
687 #elif defined (CONFIG_8xx_CONS_SCC3)
688         consdev = "scc3";
689 #endif
690
691         if (argc > 2) {
692                 ulong len;
693                 int   i;
694
695                 for (i = 2, len = 0; i < argc; i += 1)
696                         len += strlen (argv[i]) + 1;
697                 cmdline = malloc (len);
698
699                 for (i = 2, len = 0; i < argc; i += 1) {
700                         if (i > 2)
701                                 cmdline[len++] = ' ';
702                         strcpy (&cmdline[len], argv[i]);
703                         len += strlen (argv[i]);
704                 }
705         } else if ((cmdline = getenv ("bootargs")) == NULL) {
706                 cmdline = "";
707         }
708
709         loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
710
711         printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
712                 (ulong)loader);
713
714         show_boot_progress (15);
715
716         /*
717          * NetBSD Stage-2 Loader Parameters:
718          *   r3: ptr to board info data
719          *   r4: image address
720          *   r5: console device
721          *   r6: boot args string
722          */
723         (*loader) (gd->bd, os_hdr, consdev, cmdline);
724 }
725
726 #ifdef CONFIG_LYNXKDI
727 static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
728                              int argc, char *argv[],
729                              bootm_headers_t *images)
730 {
731         image_header_t *hdr = images->legacy_hdr_os;
732
733 #if defined(CONFIG_FIT)
734         if (!images->legacy_hdr_valid) {
735                 fit_unsupported_reset ("Lynx");
736                 do_reset (cmdtp, flag, argc, argv);
737         }
738 #endif
739
740         lynxkdi_boot ((image_header_t *)hdr);
741 }
742 #endif /* CONFIG_LYNXKDI */
743
744 static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
745                            int argc, char *argv[],
746                            bootm_headers_t *images)
747 {
748         image_header_t *hdr = images->legacy_hdr_os;
749         void (*entry_point)(bd_t *);
750
751 #if defined(CONFIG_FIT)
752         if (!images->legacy_hdr_valid) {
753                 fit_unsupported_reset ("RTEMS");
754                 do_reset (cmdtp, flag, argc, argv);
755         }
756 #endif
757
758         entry_point = (void (*)(bd_t *))image_get_ep (hdr);
759
760         printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
761                 (ulong)entry_point);
762
763         show_boot_progress (15);
764
765         /*
766          * RTEMS Parameters:
767          *   r3: ptr to board info data
768          */
769         (*entry_point)(gd->bd);
770 }
771
772 #if defined(CONFIG_CMD_ELF)
773 static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
774                              int argc, char *argv[],
775                              bootm_headers_t *images)
776 {
777         char str[80];
778         image_header_t *hdr = images->legacy_hdr_os;
779
780 #if defined(CONFIG_FIT)
781         if (hdr == NULL) {
782                 fit_unsupported_reset ("VxWorks");
783                 do_reset (cmdtp, flag, argc, argv);
784         }
785 #endif
786
787         sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
788         setenv("loadaddr", str);
789         do_bootvx(cmdtp, 0, 0, NULL);
790 }
791
792 static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
793                             int argc, char *argv[],
794                             bootm_headers_t *images)
795 {
796         char *local_args[2];
797         char str[16];
798         image_header_t *hdr = images->legacy_hdr_os;
799
800 #if defined(CONFIG_FIT)
801         if (!images->legacy_hdr_valid) {
802                 fit_unsupported_reset ("QNX");
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         local_args[0] = argv[0];
809         local_args[1] = str;    /* and provide it via the arguments */
810         do_bootelf(cmdtp, 0, 2, local_args);
811 }
812 #endif
813
814 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
815 static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
816                            int argc, char *argv[],
817                            bootm_headers_t *images)
818 {
819         ulong top;
820         char *s, *cmdline;
821         char **fwenv, **ss;
822         int i, j, nxt, len, envno, envsz;
823         bd_t *kbd;
824         void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
825         image_header_t *hdr = images->legacy_hdr_os;
826
827 #if defined(CONFIG_FIT)
828         if (!images->legacy_hdr_valid) {
829                 fit_unsupported_reset ("ARTOS");
830                 do_reset (cmdtp, flag, argc, argv);
831         }
832 #endif
833
834         /*
835          * Booting an ARTOS kernel image + application
836          */
837
838         /* this used to be the top of memory, but was wrong... */
839 #ifdef CONFIG_PPC
840         /* get stack pointer */
841         asm volatile ("mr %0,1" : "=r"(top) );
842 #endif
843         debug ("## Current stack ends at 0x%08lX ", top);
844
845         top -= 2048;            /* just to be sure */
846         if (top > CFG_BOOTMAPSZ)
847                 top = CFG_BOOTMAPSZ;
848         top &= ~0xF;
849
850         debug ("=> set upper limit to 0x%08lX\n", top);
851
852         /* first check the artos specific boot args, then the linux args*/
853         if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
854                 s = "";
855
856         /* get length of cmdline, and place it */
857         len = strlen (s);
858         top = (top - (len + 1)) & ~0xF;
859         cmdline = (char *)top;
860         debug ("## cmdline at 0x%08lX ", top);
861         strcpy (cmdline, s);
862
863         /* copy bdinfo */
864         top = (top - sizeof (bd_t)) & ~0xF;
865         debug ("## bd at 0x%08lX ", top);
866         kbd = (bd_t *)top;
867         memcpy (kbd, gd->bd, sizeof (bd_t));
868
869         /* first find number of env entries, and their size */
870         envno = 0;
871         envsz = 0;
872         for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
873                 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
874                         ;
875                 envno++;
876                 envsz += (nxt - i) + 1; /* plus trailing zero */
877         }
878         envno++;        /* plus the terminating zero */
879         debug ("## %u envvars total size %u ", envno, envsz);
880
881         top = (top - sizeof (char **) * envno) & ~0xF;
882         fwenv = (char **)top;
883         debug ("## fwenv at 0x%08lX ", top);
884
885         top = (top - envsz) & ~0xF;
886         s = (char *)top;
887         ss = fwenv;
888
889         /* now copy them */
890         for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
891                 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
892                         ;
893                 *ss++ = s;
894                 for (j = i; j < nxt; ++j)
895                         *s++ = env_get_char (j);
896                 *s++ = '\0';
897         }
898         *ss++ = NULL;   /* terminate */
899
900         entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
901         (*entry) (kbd, cmdline, fwenv, top);
902 }
903 #endif