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