Merge branch 'master' into next
[platform/kernel/u-boot.git] / common / cmd_bootm.c
1 /*
2  * (C) Copyright 2000-2009
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
25 /*
26  * Boot support
27  */
28 #include <common.h>
29 #include <watchdog.h>
30 #include <command.h>
31 #include <image.h>
32 #include <malloc.h>
33 #include <u-boot/zlib.h>
34 #include <bzlib.h>
35 #include <environment.h>
36 #include <lmb.h>
37 #include <linux/ctype.h>
38 #include <asm/byteorder.h>
39
40 #if defined(CONFIG_CMD_USB)
41 #include <usb.h>
42 #endif
43
44 #ifdef CONFIG_SYS_HUSH_PARSER
45 #include <hush.h>
46 #endif
47
48 #if defined(CONFIG_OF_LIBFDT)
49 #include <fdt.h>
50 #include <libfdt.h>
51 #include <fdt_support.h>
52 #endif
53
54 #ifdef CONFIG_LZMA
55 #include <lzma/LzmaTypes.h>
56 #include <lzma/LzmaDec.h>
57 #include <lzma/LzmaTools.h>
58 #endif /* CONFIG_LZMA */
59
60 #ifdef CONFIG_LZO
61 #include <linux/lzo.h>
62 #endif /* CONFIG_LZO */
63
64 DECLARE_GLOBAL_DATA_PTR;
65
66 extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
67 #ifndef CONFIG_SYS_BOOTM_LEN
68 #define CONFIG_SYS_BOOTM_LEN    0x800000        /* use 8MByte as default max gunzip size */
69 #endif
70
71 #ifdef CONFIG_BZIP2
72 extern void bz_internal_error(int);
73 #endif
74
75 #if defined(CONFIG_CMD_IMI)
76 static int image_info (unsigned long addr);
77 #endif
78
79 #if defined(CONFIG_CMD_IMLS)
80 #include <flash.h>
81 extern flash_info_t flash_info[]; /* info for FLASH chips */
82 static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
83 #endif
84
85 #ifdef CONFIG_SILENT_CONSOLE
86 static void fixup_silent_linux (void);
87 #endif
88
89 static image_header_t *image_get_kernel (ulong img_addr, int verify);
90 #if defined(CONFIG_FIT)
91 static int fit_check_kernel (const void *fit, int os_noffset, int verify);
92 #endif
93
94 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
95                 bootm_headers_t *images, ulong *os_data, ulong *os_len);
96 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
97
98 /*
99  *  Continue booting an OS image; caller already has:
100  *  - copied image header to global variable `header'
101  *  - checked header magic number, checksums (both header & image),
102  *  - verified image architecture (PPC) and type (KERNEL or MULTI),
103  *  - loaded (first part of) image to header load address,
104  *  - disabled interrupts.
105  */
106 typedef int boot_os_fn (int flag, int argc, char *argv[],
107                         bootm_headers_t *images); /* pointers to os/initrd/fdt */
108
109 #define CONFIG_BOOTM_LINUX 1
110 #define CONFIG_BOOTM_NETBSD 1
111 #define CONFIG_BOOTM_RTEMS 1
112
113 #ifdef CONFIG_BOOTM_LINUX
114 extern boot_os_fn do_bootm_linux;
115 #endif
116 #ifdef CONFIG_BOOTM_NETBSD
117 static boot_os_fn do_bootm_netbsd;
118 #endif
119 #if defined(CONFIG_LYNXKDI)
120 static boot_os_fn do_bootm_lynxkdi;
121 extern void lynxkdi_boot (image_header_t *);
122 #endif
123 #ifdef CONFIG_BOOTM_RTEMS
124 static boot_os_fn do_bootm_rtems;
125 #endif
126 #if defined(CONFIG_CMD_ELF)
127 static boot_os_fn do_bootm_vxworks;
128 static boot_os_fn do_bootm_qnxelf;
129 int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
130 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
131 #endif
132 #if defined(CONFIG_INTEGRITY)
133 static boot_os_fn do_bootm_integrity;
134 #endif
135
136 static boot_os_fn *boot_os[] = {
137 #ifdef CONFIG_BOOTM_LINUX
138         [IH_OS_LINUX] = do_bootm_linux,
139 #endif
140 #ifdef CONFIG_BOOTM_NETBSD
141         [IH_OS_NETBSD] = do_bootm_netbsd,
142 #endif
143 #ifdef CONFIG_LYNXKDI
144         [IH_OS_LYNXOS] = do_bootm_lynxkdi,
145 #endif
146 #ifdef CONFIG_BOOTM_RTEMS
147         [IH_OS_RTEMS] = do_bootm_rtems,
148 #endif
149 #if defined(CONFIG_CMD_ELF)
150         [IH_OS_VXWORKS] = do_bootm_vxworks,
151         [IH_OS_QNX] = do_bootm_qnxelf,
152 #endif
153 #ifdef CONFIG_INTEGRITY
154         [IH_OS_INTEGRITY] = do_bootm_integrity,
155 #endif
156 };
157
158 ulong load_addr = CONFIG_SYS_LOAD_ADDR; /* Default Load Address */
159 static bootm_headers_t images;          /* pointers to os/initrd/fdt images */
160
161 void __board_lmb_reserve(struct lmb *lmb)
162 {
163         /* please define platform specific board_lmb_reserve() */
164 }
165 void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
166
167 void __arch_lmb_reserve(struct lmb *lmb)
168 {
169         /* please define platform specific arch_lmb_reserve() */
170 }
171 void arch_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__arch_lmb_reserve")));
172
173 /* Allow for arch specific config before we boot */
174 void __arch_preboot_os(void)
175 {
176         /* please define platform specific arch_preboot_os() */
177 }
178 void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
179
180 #if defined(__ARM__)
181   #define IH_INITRD_ARCH IH_ARCH_ARM
182 #elif defined(__avr32__)
183   #define IH_INITRD_ARCH IH_ARCH_AVR32
184 #elif defined(__bfin__)
185   #define IH_INITRD_ARCH IH_ARCH_BLACKFIN
186 #elif defined(__I386__)
187   #define IH_INITRD_ARCH IH_ARCH_I386
188 #elif defined(__M68K__)
189   #define IH_INITRD_ARCH IH_ARCH_M68K
190 #elif defined(__microblaze__)
191   #define IH_INITRD_ARCH IH_ARCH_MICROBLAZE
192 #elif defined(__mips__)
193   #define IH_INITRD_ARCH IH_ARCH_MIPS
194 #elif defined(__nios__)
195   #define IH_INITRD_ARCH IH_ARCH_NIOS
196 #elif defined(__nios2__)
197   #define IH_INITRD_ARCH IH_ARCH_NIOS2
198 #elif defined(__PPC__)
199   #define IH_INITRD_ARCH IH_ARCH_PPC
200 #elif defined(__sh__)
201   #define IH_INITRD_ARCH IH_ARCH_SH
202 #elif defined(__sparc__)
203   #define IH_INITRD_ARCH IH_ARCH_SPARC
204 #else
205 # error Unknown CPU type
206 #endif
207
208 static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
209 {
210         ulong           mem_start;
211         phys_size_t     mem_size;
212         void            *os_hdr;
213         int             ret;
214
215         memset ((void *)&images, 0, sizeof (images));
216         images.verify = getenv_yesno ("verify");
217
218         lmb_init(&images.lmb);
219
220         mem_start = getenv_bootm_low();
221         mem_size = getenv_bootm_size();
222
223         lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
224
225         arch_lmb_reserve(&images.lmb);
226         board_lmb_reserve(&images.lmb);
227
228         /* get kernel image header, start address and length */
229         os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
230                         &images, &images.os.image_start, &images.os.image_len);
231         if (images.os.image_len == 0) {
232                 puts ("ERROR: can't get kernel image!\n");
233                 return 1;
234         }
235
236         /* get image parameters */
237         switch (genimg_get_format (os_hdr)) {
238         case IMAGE_FORMAT_LEGACY:
239                 images.os.type = image_get_type (os_hdr);
240                 images.os.comp = image_get_comp (os_hdr);
241                 images.os.os = image_get_os (os_hdr);
242
243                 images.os.end = image_get_image_end (os_hdr);
244                 images.os.load = image_get_load (os_hdr);
245                 break;
246 #if defined(CONFIG_FIT)
247         case IMAGE_FORMAT_FIT:
248                 if (fit_image_get_type (images.fit_hdr_os,
249                                         images.fit_noffset_os, &images.os.type)) {
250                         puts ("Can't get image type!\n");
251                         show_boot_progress (-109);
252                         return 1;
253                 }
254
255                 if (fit_image_get_comp (images.fit_hdr_os,
256                                         images.fit_noffset_os, &images.os.comp)) {
257                         puts ("Can't get image compression!\n");
258                         show_boot_progress (-110);
259                         return 1;
260                 }
261
262                 if (fit_image_get_os (images.fit_hdr_os,
263                                         images.fit_noffset_os, &images.os.os)) {
264                         puts ("Can't get image OS!\n");
265                         show_boot_progress (-111);
266                         return 1;
267                 }
268
269                 images.os.end = fit_get_end (images.fit_hdr_os);
270
271                 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
272                                         &images.os.load)) {
273                         puts ("Can't get image load address!\n");
274                         show_boot_progress (-112);
275                         return 1;
276                 }
277                 break;
278 #endif
279         default:
280                 puts ("ERROR: unknown image format type!\n");
281                 return 1;
282         }
283
284         /* find kernel entry point */
285         if (images.legacy_hdr_valid) {
286                 images.ep = image_get_ep (&images.legacy_hdr_os_copy);
287 #if defined(CONFIG_FIT)
288         } else if (images.fit_uname_os) {
289                 ret = fit_image_get_entry (images.fit_hdr_os,
290                                 images.fit_noffset_os, &images.ep);
291                 if (ret) {
292                         puts ("Can't get entry point property!\n");
293                         return 1;
294                 }
295 #endif
296         } else {
297                 puts ("Could not find kernel entry point!\n");
298                 return 1;
299         }
300
301         if (images.os.os == IH_OS_LINUX) {
302                 /* find ramdisk */
303                 ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
304                                 &images.rd_start, &images.rd_end);
305                 if (ret) {
306                         puts ("Ramdisk image is corrupt or invalid\n");
307                         return 1;
308                 }
309
310 #if defined(CONFIG_OF_LIBFDT)
311 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
312                 /* find flattened device tree */
313                 ret = boot_get_fdt (flag, argc, argv, &images,
314                                     &images.ft_addr, &images.ft_len);
315                 if (ret) {
316                         puts ("Could not find a valid device tree\n");
317                         return 1;
318                 }
319
320                 set_working_fdt_addr(images.ft_addr);
321 #endif
322 #endif
323         }
324
325         images.os.start = (ulong)os_hdr;
326         images.state = BOOTM_STATE_START;
327
328         return 0;
329 }
330
331 #define BOOTM_ERR_RESET         -1
332 #define BOOTM_ERR_OVERLAP       -2
333 #define BOOTM_ERR_UNIMPLEMENTED -3
334 static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
335 {
336         uint8_t comp = os.comp;
337         ulong load = os.load;
338         ulong blob_start = os.start;
339         ulong blob_end = os.end;
340         ulong image_start = os.image_start;
341         ulong image_len = os.image_len;
342         uint unc_len = CONFIG_SYS_BOOTM_LEN;
343
344         const char *type_name = genimg_get_type_name (os.type);
345
346         switch (comp) {
347         case IH_COMP_NONE:
348                 if (load == blob_start) {
349                         printf ("   XIP %s ... ", type_name);
350                 } else {
351                         printf ("   Loading %s ... ", type_name);
352
353                         if (load != image_start) {
354                                 memmove_wd ((void *)load,
355                                                 (void *)image_start, image_len, CHUNKSZ);
356                         }
357                 }
358                 *load_end = load + image_len;
359                 puts("OK\n");
360                 break;
361         case IH_COMP_GZIP:
362                 printf ("   Uncompressing %s ... ", type_name);
363                 if (gunzip ((void *)load, unc_len,
364                                         (uchar *)image_start, &image_len) != 0) {
365                         puts ("GUNZIP: uncompress, out-of-mem or overwrite error "
366                                 "- must RESET board to recover\n");
367                         if (boot_progress)
368                                 show_boot_progress (-6);
369                         return BOOTM_ERR_RESET;
370                 }
371
372                 *load_end = load + image_len;
373                 break;
374 #ifdef CONFIG_BZIP2
375         case IH_COMP_BZIP2:
376                 printf ("   Uncompressing %s ... ", type_name);
377                 /*
378                  * If we've got less than 4 MB of malloc() space,
379                  * use slower decompression algorithm which requires
380                  * at most 2300 KB of memory.
381                  */
382                 int i = BZ2_bzBuffToBuffDecompress ((char*)load,
383                                         &unc_len, (char *)image_start, image_len,
384                                         CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
385                 if (i != BZ_OK) {
386                         printf ("BUNZIP2: uncompress or overwrite error %d "
387                                 "- must RESET board to recover\n", i);
388                         if (boot_progress)
389                                 show_boot_progress (-6);
390                         return BOOTM_ERR_RESET;
391                 }
392
393                 *load_end = load + unc_len;
394                 break;
395 #endif /* CONFIG_BZIP2 */
396 #ifdef CONFIG_LZMA
397         case IH_COMP_LZMA:
398                 printf ("   Uncompressing %s ... ", type_name);
399
400                 int ret = lzmaBuffToBuffDecompress(
401                         (unsigned char *)load, &unc_len,
402                         (unsigned char *)image_start, image_len);
403                 if (ret != SZ_OK) {
404                         printf ("LZMA: uncompress or overwrite error %d "
405                                 "- must RESET board to recover\n", ret);
406                         show_boot_progress (-6);
407                         return BOOTM_ERR_RESET;
408                 }
409                 *load_end = load + unc_len;
410                 break;
411 #endif /* CONFIG_LZMA */
412 #ifdef CONFIG_LZO
413         case IH_COMP_LZO:
414                 printf ("   Uncompressing %s ... ", type_name);
415
416                 int ret = lzop_decompress((const unsigned char *)image_start,
417                                           image_len, (unsigned char *)load,
418                                           &unc_len);
419                 if (ret != LZO_E_OK) {
420                         printf ("LZO: uncompress or overwrite error %d "
421                               "- must RESET board to recover\n", ret);
422                         if (boot_progress)
423                                 show_boot_progress (-6);
424                         return BOOTM_ERR_RESET;
425                 }
426
427                 *load_end = load + unc_len;
428                 break;
429 #endif /* CONFIG_LZO */
430         default:
431                 printf ("Unimplemented compression type %d\n", comp);
432                 return BOOTM_ERR_UNIMPLEMENTED;
433         }
434         puts ("OK\n");
435         debug ("   kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
436         if (boot_progress)
437                 show_boot_progress (7);
438
439         if ((load < blob_end) && (*load_end > blob_start)) {
440                 debug ("images.os.start = 0x%lX, images.os.end = 0x%lx\n", blob_start, blob_end);
441                 debug ("images.os.load = 0x%lx, load_end = 0x%lx\n", load, *load_end);
442
443                 return BOOTM_ERR_OVERLAP;
444         }
445
446         return 0;
447 }
448
449 static int bootm_start_standalone(ulong iflag, int argc, char *argv[])
450 {
451         char  *s;
452         int   (*appl)(int, char *[]);
453
454         /* Don't start if "autostart" is set to "no" */
455         if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
456                 char buf[32];
457                 sprintf(buf, "%lX", images.os.image_len);
458                 setenv("filesize", buf);
459                 return 0;
460         }
461         appl = (int (*)(int, char *[]))ntohl(images.ep);
462         (*appl)(argc-1, &argv[1]);
463
464         return 0;
465 }
466
467 /* we overload the cmd field with our state machine info instead of a
468  * function pointer */
469 cmd_tbl_t cmd_bootm_sub[] = {
470         U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
471         U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
472 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
473         U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
474 #endif
475 #ifdef CONFIG_OF_LIBFDT
476         U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
477 #endif
478         U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
479         U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
480         U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
481         U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
482 };
483
484 int do_bootm_subcommand (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
485 {
486         int ret = 0;
487         int state;
488         cmd_tbl_t *c;
489         boot_os_fn *boot_fn;
490
491         c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
492
493         if (c) {
494                 state = (int)c->cmd;
495
496                 /* treat start special since it resets the state machine */
497                 if (state == BOOTM_STATE_START) {
498                         argc--;
499                         argv++;
500                         return bootm_start(cmdtp, flag, argc, argv);
501                 }
502         }
503         /* Unrecognized command */
504         else {
505                 cmd_usage(cmdtp);
506                 return 1;
507         }
508
509         if (images.state >= state) {
510                 printf ("Trying to execute a command out of order\n");
511                 cmd_usage(cmdtp);
512                 return 1;
513         }
514
515         images.state |= state;
516         boot_fn = boot_os[images.os.os];
517
518         switch (state) {
519                 ulong load_end;
520                 case BOOTM_STATE_START:
521                         /* should never occur */
522                         break;
523                 case BOOTM_STATE_LOADOS:
524                         ret = bootm_load_os(images.os, &load_end, 0);
525                         if (ret)
526                                 return ret;
527
528                         lmb_reserve(&images.lmb, images.os.load,
529                                         (load_end - images.os.load));
530                         break;
531 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
532                 case BOOTM_STATE_RAMDISK:
533                 {
534                         ulong rd_len = images.rd_end - images.rd_start;
535                         char str[17];
536
537                         ret = boot_ramdisk_high(&images.lmb, images.rd_start,
538                                 rd_len, &images.initrd_start, &images.initrd_end);
539                         if (ret)
540                                 return ret;
541
542                         sprintf(str, "%lx", images.initrd_start);
543                         setenv("initrd_start", str);
544                         sprintf(str, "%lx", images.initrd_end);
545                         setenv("initrd_end", str);
546                 }
547                         break;
548 #endif
549 #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_SYS_BOOTMAPSZ)
550                 case BOOTM_STATE_FDT:
551                 {
552                         ulong bootmap_base = getenv_bootm_low();
553                         ret = boot_relocate_fdt(&images.lmb, bootmap_base,
554                                 &images.ft_addr, &images.ft_len);
555                         break;
556                 }
557 #endif
558                 case BOOTM_STATE_OS_CMDLINE:
559                         ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, &images);
560                         if (ret)
561                                 printf ("cmdline subcommand not supported\n");
562                         break;
563                 case BOOTM_STATE_OS_BD_T:
564                         ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, &images);
565                         if (ret)
566                                 printf ("bdt subcommand not supported\n");
567                         break;
568                 case BOOTM_STATE_OS_PREP:
569                         ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, &images);
570                         if (ret)
571                                 printf ("prep subcommand not supported\n");
572                         break;
573                 case BOOTM_STATE_OS_GO:
574                         disable_interrupts();
575                         arch_preboot_os();
576                         boot_fn(BOOTM_STATE_OS_GO, argc, argv, &images);
577                         break;
578         }
579
580         return ret;
581 }
582
583 /*******************************************************************/
584 /* bootm - boot application image from image in memory */
585 /*******************************************************************/
586
587 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
588 {
589         ulong           iflag;
590         ulong           load_end = 0;
591         int             ret;
592         boot_os_fn      *boot_fn;
593 #ifndef CONFIG_RELOC_FIXUP_WORKS
594         static int relocated = 0;
595
596         /* relocate boot function table */
597         if (!relocated) {
598                 int i;
599                 for (i = 0; i < ARRAY_SIZE(boot_os); i++)
600                         if (boot_os[i] != NULL)
601                                 boot_os[i] += gd->reloc_off;
602                 relocated = 1;
603         }
604 #endif
605
606         /* determine if we have a sub command */
607         if (argc > 1) {
608                 char *endp;
609
610                 simple_strtoul(argv[1], &endp, 16);
611                 /* endp pointing to NULL means that argv[1] was just a
612                  * valid number, pass it along to the normal bootm processing
613                  *
614                  * If endp is ':' or '#' assume a FIT identifier so pass
615                  * along for normal processing.
616                  *
617                  * Right now we assume the first arg should never be '-'
618                  */
619                 if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
620                         return do_bootm_subcommand(cmdtp, flag, argc, argv);
621         }
622
623         if (bootm_start(cmdtp, flag, argc, argv))
624                 return 1;
625
626         /*
627          * We have reached the point of no return: we are going to
628          * overwrite all exception vector code, so we cannot easily
629          * recover from any failures any more...
630          */
631         iflag = disable_interrupts();
632
633 #if defined(CONFIG_CMD_USB)
634         /*
635          * turn off USB to prevent the host controller from writing to the
636          * SDRAM while Linux is booting. This could happen (at least for OHCI
637          * controller), because the HCCA (Host Controller Communication Area)
638          * lies within the SDRAM and the host controller writes continously to
639          * this area (as busmaster!). The HccaFrameNumber is for example
640          * updated every 1 ms within the HCCA structure in SDRAM! For more
641          * details see the OpenHCI specification.
642          */
643         usb_stop();
644 #endif
645
646 #ifdef CONFIG_AMIGAONEG3SE
647         /*
648          * We've possible left the caches enabled during
649          * bios emulation, so turn them off again
650          */
651         icache_disable();
652         dcache_disable();
653 #endif
654
655         ret = bootm_load_os(images.os, &load_end, 1);
656
657         if (ret < 0) {
658                 if (ret == BOOTM_ERR_RESET)
659                         do_reset (cmdtp, flag, argc, argv);
660                 if (ret == BOOTM_ERR_OVERLAP) {
661                         if (images.legacy_hdr_valid) {
662                                 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
663                                         puts ("WARNING: legacy format multi component "
664                                                 "image overwritten\n");
665                         } else {
666                                 puts ("ERROR: new format image overwritten - "
667                                         "must RESET the board to recover\n");
668                                 show_boot_progress (-113);
669                                 do_reset (cmdtp, flag, argc, argv);
670                         }
671                 }
672                 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
673                         if (iflag)
674                                 enable_interrupts();
675                         show_boot_progress (-7);
676                         return 1;
677                 }
678         }
679
680         lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
681
682         if (images.os.type == IH_TYPE_STANDALONE) {
683                 if (iflag)
684                         enable_interrupts();
685                 /* This may return when 'autostart' is 'no' */
686                 bootm_start_standalone(iflag, argc, argv);
687                 return 0;
688         }
689
690         show_boot_progress (8);
691
692 #ifdef CONFIG_SILENT_CONSOLE
693         if (images.os.os == IH_OS_LINUX)
694                 fixup_silent_linux();
695 #endif
696
697         boot_fn = boot_os[images.os.os];
698
699         if (boot_fn == NULL) {
700                 if (iflag)
701                         enable_interrupts();
702                 printf ("ERROR: booting os '%s' (%d) is not supported\n",
703                         genimg_get_os_name(images.os.os), images.os.os);
704                 show_boot_progress (-8);
705                 return 1;
706         }
707
708         arch_preboot_os();
709
710         boot_fn(0, argc, argv, &images);
711
712         show_boot_progress (-9);
713 #ifdef DEBUG
714         puts ("\n## Control returned to monitor - resetting...\n");
715 #endif
716         do_reset (cmdtp, flag, argc, argv);
717
718         return 1;
719 }
720
721 /**
722  * image_get_kernel - verify legacy format kernel image
723  * @img_addr: in RAM address of the legacy format image to be verified
724  * @verify: data CRC verification flag
725  *
726  * image_get_kernel() verifies legacy image integrity and returns pointer to
727  * legacy image header if image verification was completed successfully.
728  *
729  * returns:
730  *     pointer to a legacy image header if valid image was found
731  *     otherwise return NULL
732  */
733 static image_header_t *image_get_kernel (ulong img_addr, int verify)
734 {
735         image_header_t *hdr = (image_header_t *)img_addr;
736
737         if (!image_check_magic(hdr)) {
738                 puts ("Bad Magic Number\n");
739                 show_boot_progress (-1);
740                 return NULL;
741         }
742         show_boot_progress (2);
743
744         if (!image_check_hcrc (hdr)) {
745                 puts ("Bad Header Checksum\n");
746                 show_boot_progress (-2);
747                 return NULL;
748         }
749
750         show_boot_progress (3);
751         image_print_contents (hdr);
752
753         if (verify) {
754                 puts ("   Verifying Checksum ... ");
755                 if (!image_check_dcrc (hdr)) {
756                         printf ("Bad Data CRC\n");
757                         show_boot_progress (-3);
758                         return NULL;
759                 }
760                 puts ("OK\n");
761         }
762         show_boot_progress (4);
763
764         if (!image_check_target_arch (hdr)) {
765                 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
766                 show_boot_progress (-4);
767                 return NULL;
768         }
769         return hdr;
770 }
771
772 /**
773  * fit_check_kernel - verify FIT format kernel subimage
774  * @fit_hdr: pointer to the FIT image header
775  * os_noffset: kernel subimage node offset within FIT image
776  * @verify: data CRC verification flag
777  *
778  * fit_check_kernel() verifies integrity of the kernel subimage and from
779  * specified FIT image.
780  *
781  * returns:
782  *     1, on success
783  *     0, on failure
784  */
785 #if defined (CONFIG_FIT)
786 static int fit_check_kernel (const void *fit, int os_noffset, int verify)
787 {
788         fit_image_print (fit, os_noffset, "   ");
789
790         if (verify) {
791                 puts ("   Verifying Hash Integrity ... ");
792                 if (!fit_image_check_hashes (fit, os_noffset)) {
793                         puts ("Bad Data Hash\n");
794                         show_boot_progress (-104);
795                         return 0;
796                 }
797                 puts ("OK\n");
798         }
799         show_boot_progress (105);
800
801         if (!fit_image_check_target_arch (fit, os_noffset)) {
802                 puts ("Unsupported Architecture\n");
803                 show_boot_progress (-105);
804                 return 0;
805         }
806
807         show_boot_progress (106);
808         if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
809                 puts ("Not a kernel image\n");
810                 show_boot_progress (-106);
811                 return 0;
812         }
813
814         show_boot_progress (107);
815         return 1;
816 }
817 #endif /* CONFIG_FIT */
818
819 /**
820  * boot_get_kernel - find kernel image
821  * @os_data: pointer to a ulong variable, will hold os data start address
822  * @os_len: pointer to a ulong variable, will hold os data length
823  *
824  * boot_get_kernel() tries to find a kernel image, verifies its integrity
825  * and locates kernel data.
826  *
827  * returns:
828  *     pointer to image header if valid image was found, plus kernel start
829  *     address and length, otherwise NULL
830  */
831 static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
832                 bootm_headers_t *images, ulong *os_data, ulong *os_len)
833 {
834         image_header_t  *hdr;
835         ulong           img_addr;
836 #if defined(CONFIG_FIT)
837         void            *fit_hdr;
838         const char      *fit_uname_config = NULL;
839         const char      *fit_uname_kernel = NULL;
840         const void      *data;
841         size_t          len;
842         int             cfg_noffset;
843         int             os_noffset;
844 #endif
845
846         /* find out kernel image address */
847         if (argc < 2) {
848                 img_addr = load_addr;
849                 debug ("*  kernel: default image load address = 0x%08lx\n",
850                                 load_addr);
851 #if defined(CONFIG_FIT)
852         } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
853                                                         &fit_uname_config)) {
854                 debug ("*  kernel: config '%s' from image at 0x%08lx\n",
855                                 fit_uname_config, img_addr);
856         } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
857                                                         &fit_uname_kernel)) {
858                 debug ("*  kernel: subimage '%s' from image at 0x%08lx\n",
859                                 fit_uname_kernel, img_addr);
860 #endif
861         } else {
862                 img_addr = simple_strtoul(argv[1], NULL, 16);
863                 debug ("*  kernel: cmdline image address = 0x%08lx\n", img_addr);
864         }
865
866         show_boot_progress (1);
867
868         /* copy from dataflash if needed */
869         img_addr = genimg_get_image (img_addr);
870
871         /* check image type, for FIT images get FIT kernel node */
872         *os_data = *os_len = 0;
873         switch (genimg_get_format ((void *)img_addr)) {
874         case IMAGE_FORMAT_LEGACY:
875                 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
876                                 img_addr);
877                 hdr = image_get_kernel (img_addr, images->verify);
878                 if (!hdr)
879                         return NULL;
880                 show_boot_progress (5);
881
882                 /* get os_data and os_len */
883                 switch (image_get_type (hdr)) {
884                 case IH_TYPE_KERNEL:
885                         *os_data = image_get_data (hdr);
886                         *os_len = image_get_data_size (hdr);
887                         break;
888                 case IH_TYPE_MULTI:
889                         image_multi_getimg (hdr, 0, os_data, os_len);
890                         break;
891                 case IH_TYPE_STANDALONE:
892                         if (argc >2) {
893                                 hdr->ih_load = htonl(simple_strtoul(argv[2], NULL, 16));
894                         }
895                         *os_data = image_get_data (hdr);
896                         *os_len = image_get_data_size (hdr);
897                         break;
898                 default:
899                         printf ("Wrong Image Type for %s command\n", cmdtp->name);
900                         show_boot_progress (-5);
901                         return NULL;
902                 }
903
904                 /*
905                  * copy image header to allow for image overwrites during kernel
906                  * decompression.
907                  */
908                 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
909
910                 /* save pointer to image header */
911                 images->legacy_hdr_os = hdr;
912
913                 images->legacy_hdr_valid = 1;
914                 show_boot_progress (6);
915                 break;
916 #if defined(CONFIG_FIT)
917         case IMAGE_FORMAT_FIT:
918                 fit_hdr = (void *)img_addr;
919                 printf ("## Booting kernel from FIT Image at %08lx ...\n",
920                                 img_addr);
921
922                 if (!fit_check_format (fit_hdr)) {
923                         puts ("Bad FIT kernel image format!\n");
924                         show_boot_progress (-100);
925                         return NULL;
926                 }
927                 show_boot_progress (100);
928
929                 if (!fit_uname_kernel) {
930                         /*
931                          * no kernel image node unit name, try to get config
932                          * node first. If config unit node name is NULL
933                          * fit_conf_get_node() will try to find default config node
934                          */
935                         show_boot_progress (101);
936                         cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
937                         if (cfg_noffset < 0) {
938                                 show_boot_progress (-101);
939                                 return NULL;
940                         }
941                         /* save configuration uname provided in the first
942                          * bootm argument
943                          */
944                         images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
945                         printf ("   Using '%s' configuration\n", images->fit_uname_cfg);
946                         show_boot_progress (103);
947
948                         os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
949                         fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
950                 } else {
951                         /* get kernel component image node offset */
952                         show_boot_progress (102);
953                         os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
954                 }
955                 if (os_noffset < 0) {
956                         show_boot_progress (-103);
957                         return NULL;
958                 }
959
960                 printf ("   Trying '%s' kernel subimage\n", fit_uname_kernel);
961
962                 show_boot_progress (104);
963                 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
964                         return NULL;
965
966                 /* get kernel image data address and length */
967                 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
968                         puts ("Could not find kernel subimage data!\n");
969                         show_boot_progress (-107);
970                         return NULL;
971                 }
972                 show_boot_progress (108);
973
974                 *os_len = len;
975                 *os_data = (ulong)data;
976                 images->fit_hdr_os = fit_hdr;
977                 images->fit_uname_os = fit_uname_kernel;
978                 images->fit_noffset_os = os_noffset;
979                 break;
980 #endif
981         default:
982                 printf ("Wrong Image Format for %s command\n", cmdtp->name);
983                 show_boot_progress (-108);
984                 return NULL;
985         }
986
987         debug ("   kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
988                         *os_data, *os_len, *os_len);
989
990         return (void *)img_addr;
991 }
992
993 U_BOOT_CMD(
994         bootm,  CONFIG_SYS_MAXARGS,     1,      do_bootm,
995         "boot application image from memory",
996         "[addr [arg ...]]\n    - boot application image stored in memory\n"
997         "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
998         "\t'arg' can be the address of an initrd image\n"
999 #if defined(CONFIG_OF_LIBFDT)
1000         "\tWhen booting a Linux kernel which requires a flat device-tree\n"
1001         "\ta third argument is required which is the address of the\n"
1002         "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1003         "\tuse a '-' for the second argument. If you do not pass a third\n"
1004         "\ta bd_info struct will be passed instead\n"
1005 #endif
1006 #if defined(CONFIG_FIT)
1007         "\t\nFor the new multi component uImage format (FIT) addresses\n"
1008         "\tmust be extened to include component or configuration unit name:\n"
1009         "\taddr:<subimg_uname> - direct component image specification\n"
1010         "\taddr#<conf_uname>   - configuration specification\n"
1011         "\tUse iminfo command to get the list of existing component\n"
1012         "\timages and configurations.\n"
1013 #endif
1014         "\nSub-commands to do part of the bootm sequence.  The sub-commands "
1015         "must be\n"
1016         "issued in the order below (it's ok to not issue all sub-commands):\n"
1017         "\tstart [addr [arg ...]]\n"
1018         "\tloados  - load OS image\n"
1019 #if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
1020         "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
1021 #endif
1022 #if defined(CONFIG_OF_LIBFDT)
1023         "\tfdt     - relocate flat device tree\n"
1024 #endif
1025         "\tbdt     - OS specific bd_t processing\n"
1026         "\tcmdline - OS specific command line processing/setup\n"
1027         "\tprep    - OS specific prep before relocation or go\n"
1028         "\tgo      - start OS"
1029 );
1030
1031 /*******************************************************************/
1032 /* bootd - boot default image */
1033 /*******************************************************************/
1034 #if defined(CONFIG_CMD_BOOTD)
1035 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1036 {
1037         int rcode = 0;
1038
1039 #ifndef CONFIG_SYS_HUSH_PARSER
1040         if (run_command (getenv ("bootcmd"), flag) < 0)
1041                 rcode = 1;
1042 #else
1043         if (parse_string_outer (getenv ("bootcmd"),
1044                         FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
1045                 rcode = 1;
1046 #endif
1047         return rcode;
1048 }
1049
1050 U_BOOT_CMD(
1051         boot,   1,      1,      do_bootd,
1052         "boot default, i.e., run 'bootcmd'",
1053         ""
1054 );
1055
1056 /* keep old command name "bootd" for backward compatibility */
1057 U_BOOT_CMD(
1058         bootd, 1,       1,      do_bootd,
1059         "boot default, i.e., run 'bootcmd'",
1060         ""
1061 );
1062
1063 #endif
1064
1065
1066 /*******************************************************************/
1067 /* iminfo - print header info for a requested image */
1068 /*******************************************************************/
1069 #if defined(CONFIG_CMD_IMI)
1070 int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1071 {
1072         int     arg;
1073         ulong   addr;
1074         int     rcode = 0;
1075
1076         if (argc < 2) {
1077                 return image_info (load_addr);
1078         }
1079
1080         for (arg = 1; arg < argc; ++arg) {
1081                 addr = simple_strtoul (argv[arg], NULL, 16);
1082                 if (image_info (addr) != 0)
1083                         rcode = 1;
1084         }
1085         return rcode;
1086 }
1087
1088 static int image_info (ulong addr)
1089 {
1090         void *hdr = (void *)addr;
1091
1092         printf ("\n## Checking Image at %08lx ...\n", addr);
1093
1094         switch (genimg_get_format (hdr)) {
1095         case IMAGE_FORMAT_LEGACY:
1096                 puts ("   Legacy image found\n");
1097                 if (!image_check_magic (hdr)) {
1098                         puts ("   Bad Magic Number\n");
1099                         return 1;
1100                 }
1101
1102                 if (!image_check_hcrc (hdr)) {
1103                         puts ("   Bad Header Checksum\n");
1104                         return 1;
1105                 }
1106
1107                 image_print_contents (hdr);
1108
1109                 puts ("   Verifying Checksum ... ");
1110                 if (!image_check_dcrc (hdr)) {
1111                         puts ("   Bad Data CRC\n");
1112                         return 1;
1113                 }
1114                 puts ("OK\n");
1115                 return 0;
1116 #if defined(CONFIG_FIT)
1117         case IMAGE_FORMAT_FIT:
1118                 puts ("   FIT image found\n");
1119
1120                 if (!fit_check_format (hdr)) {
1121                         puts ("Bad FIT image format!\n");
1122                         return 1;
1123                 }
1124
1125                 fit_print_contents (hdr);
1126
1127                 if (!fit_all_image_check_hashes (hdr)) {
1128                         puts ("Bad hash in FIT image!\n");
1129                         return 1;
1130                 }
1131
1132                 return 0;
1133 #endif
1134         default:
1135                 puts ("Unknown image format!\n");
1136                 break;
1137         }
1138
1139         return 1;
1140 }
1141
1142 U_BOOT_CMD(
1143         iminfo, CONFIG_SYS_MAXARGS,     1,      do_iminfo,
1144         "print header information for application image",
1145         "addr [addr ...]\n"
1146         "    - print header information for application image starting at\n"
1147         "      address 'addr' in memory; this includes verification of the\n"
1148         "      image contents (magic number, header and payload checksums)"
1149 );
1150 #endif
1151
1152
1153 /*******************************************************************/
1154 /* imls - list all images found in flash */
1155 /*******************************************************************/
1156 #if defined(CONFIG_CMD_IMLS)
1157 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1158 {
1159         flash_info_t *info;
1160         int i, j;
1161         void *hdr;
1162
1163         for (i = 0, info = &flash_info[0];
1164                 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
1165
1166                 if (info->flash_id == FLASH_UNKNOWN)
1167                         goto next_bank;
1168                 for (j = 0; j < info->sector_count; ++j) {
1169
1170                         hdr = (void *)info->start[j];
1171                         if (!hdr)
1172                                 goto next_sector;
1173
1174                         switch (genimg_get_format (hdr)) {
1175                         case IMAGE_FORMAT_LEGACY:
1176                                 if (!image_check_hcrc (hdr))
1177                                         goto next_sector;
1178
1179                                 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
1180                                 image_print_contents (hdr);
1181
1182                                 puts ("   Verifying Checksum ... ");
1183                                 if (!image_check_dcrc (hdr)) {
1184                                         puts ("Bad Data CRC\n");
1185                                 } else {
1186                                         puts ("OK\n");
1187                                 }
1188                                 break;
1189 #if defined(CONFIG_FIT)
1190                         case IMAGE_FORMAT_FIT:
1191                                 if (!fit_check_format (hdr))
1192                                         goto next_sector;
1193
1194                                 printf ("FIT Image at %08lX:\n", (ulong)hdr);
1195                                 fit_print_contents (hdr);
1196                                 break;
1197 #endif
1198                         default:
1199                                 goto next_sector;
1200                         }
1201
1202 next_sector:            ;
1203                 }
1204 next_bank:      ;
1205         }
1206
1207         return (0);
1208 }
1209
1210 U_BOOT_CMD(
1211         imls,   1,              1,      do_imls,
1212         "list all images found in flash",
1213         "\n"
1214         "    - Prints information about all images found at sector\n"
1215         "      boundaries in flash."
1216 );
1217 #endif
1218
1219 /*******************************************************************/
1220 /* helper routines */
1221 /*******************************************************************/
1222 #ifdef CONFIG_SILENT_CONSOLE
1223 static void fixup_silent_linux ()
1224 {
1225         char buf[256], *start, *end;
1226         char *cmdline = getenv ("bootargs");
1227
1228         /* Only fix cmdline when requested */
1229         if (!(gd->flags & GD_FLG_SILENT))
1230                 return;
1231
1232         debug ("before silent fix-up: %s\n", cmdline);
1233         if (cmdline) {
1234                 if ((start = strstr (cmdline, "console=")) != NULL) {
1235                         end = strchr (start, ' ');
1236                         strncpy (buf, cmdline, (start - cmdline + 8));
1237                         if (end)
1238                                 strcpy (buf + (start - cmdline + 8), end);
1239                         else
1240                                 buf[start - cmdline + 8] = '\0';
1241                 } else {
1242                         strcpy (buf, cmdline);
1243                         strcat (buf, " console=");
1244                 }
1245         } else {
1246                 strcpy (buf, "console=");
1247         }
1248
1249         setenv ("bootargs", buf);
1250         debug ("after silent fix-up: %s\n", buf);
1251 }
1252 #endif /* CONFIG_SILENT_CONSOLE */
1253
1254
1255 /*******************************************************************/
1256 /* OS booting routines */
1257 /*******************************************************************/
1258
1259 #ifdef CONFIG_BOOTM_NETBSD
1260 static int do_bootm_netbsd (int flag, int argc, char *argv[],
1261                             bootm_headers_t *images)
1262 {
1263         void (*loader)(bd_t *, image_header_t *, char *, char *);
1264         image_header_t *os_hdr, *hdr;
1265         ulong kernel_data, kernel_len;
1266         char *consdev;
1267         char *cmdline;
1268
1269         if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1270                 return 1;
1271
1272 #if defined(CONFIG_FIT)
1273         if (!images->legacy_hdr_valid) {
1274                 fit_unsupported_reset ("NetBSD");
1275                 return 1;
1276         }
1277 #endif
1278         hdr = images->legacy_hdr_os;
1279
1280         /*
1281          * Booting a (NetBSD) kernel image
1282          *
1283          * This process is pretty similar to a standalone application:
1284          * The (first part of an multi-) image must be a stage-2 loader,
1285          * which in turn is responsible for loading & invoking the actual
1286          * kernel.  The only differences are the parameters being passed:
1287          * besides the board info strucure, the loader expects a command
1288          * line, the name of the console device, and (optionally) the
1289          * address of the original image header.
1290          */
1291         os_hdr = NULL;
1292         if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1293                 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
1294                 if (kernel_len)
1295                         os_hdr = hdr;
1296         }
1297
1298         consdev = "";
1299 #if   defined (CONFIG_8xx_CONS_SMC1)
1300         consdev = "smc1";
1301 #elif defined (CONFIG_8xx_CONS_SMC2)
1302         consdev = "smc2";
1303 #elif defined (CONFIG_8xx_CONS_SCC2)
1304         consdev = "scc2";
1305 #elif defined (CONFIG_8xx_CONS_SCC3)
1306         consdev = "scc3";
1307 #endif
1308
1309         if (argc > 2) {
1310                 ulong len;
1311                 int   i;
1312
1313                 for (i = 2, len = 0; i < argc; i += 1)
1314                         len += strlen (argv[i]) + 1;
1315                 cmdline = malloc (len);
1316
1317                 for (i = 2, len = 0; i < argc; i += 1) {
1318                         if (i > 2)
1319                                 cmdline[len++] = ' ';
1320                         strcpy (&cmdline[len], argv[i]);
1321                         len += strlen (argv[i]);
1322                 }
1323         } else if ((cmdline = getenv ("bootargs")) == NULL) {
1324                 cmdline = "";
1325         }
1326
1327         loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
1328
1329         printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
1330                 (ulong)loader);
1331
1332         show_boot_progress (15);
1333
1334         /*
1335          * NetBSD Stage-2 Loader Parameters:
1336          *   r3: ptr to board info data
1337          *   r4: image address
1338          *   r5: console device
1339          *   r6: boot args string
1340          */
1341         (*loader) (gd->bd, os_hdr, consdev, cmdline);
1342
1343         return 1;
1344 }
1345 #endif /* CONFIG_BOOTM_NETBSD*/
1346
1347 #ifdef CONFIG_LYNXKDI
1348 static int do_bootm_lynxkdi (int flag, int argc, char *argv[],
1349                              bootm_headers_t *images)
1350 {
1351         image_header_t *hdr = &images->legacy_hdr_os_copy;
1352
1353         if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1354                 return 1;
1355
1356 #if defined(CONFIG_FIT)
1357         if (!images->legacy_hdr_valid) {
1358                 fit_unsupported_reset ("Lynx");
1359                 return 1;
1360         }
1361 #endif
1362
1363         lynxkdi_boot ((image_header_t *)hdr);
1364
1365         return 1;
1366 }
1367 #endif /* CONFIG_LYNXKDI */
1368
1369 #ifdef CONFIG_BOOTM_RTEMS
1370 static int do_bootm_rtems (int flag, int argc, char *argv[],
1371                            bootm_headers_t *images)
1372 {
1373         void (*entry_point)(bd_t *);
1374
1375         if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1376                 return 1;
1377
1378 #if defined(CONFIG_FIT)
1379         if (!images->legacy_hdr_valid) {
1380                 fit_unsupported_reset ("RTEMS");
1381                 return 1;
1382         }
1383 #endif
1384
1385         entry_point = (void (*)(bd_t *))images->ep;
1386
1387         printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1388                 (ulong)entry_point);
1389
1390         show_boot_progress (15);
1391
1392         /*
1393          * RTEMS Parameters:
1394          *   r3: ptr to board info data
1395          */
1396         (*entry_point)(gd->bd);
1397
1398         return 1;
1399 }
1400 #endif /* CONFIG_BOOTM_RTEMS */
1401
1402 #if defined(CONFIG_CMD_ELF)
1403 static int do_bootm_vxworks (int flag, int argc, char *argv[],
1404                              bootm_headers_t *images)
1405 {
1406         char str[80];
1407
1408         if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1409                 return 1;
1410
1411 #if defined(CONFIG_FIT)
1412         if (!images->legacy_hdr_valid) {
1413                 fit_unsupported_reset ("VxWorks");
1414                 return 1;
1415         }
1416 #endif
1417
1418         sprintf(str, "%lx", images->ep); /* write entry-point into string */
1419         setenv("loadaddr", str);
1420         do_bootvx(NULL, 0, 0, NULL);
1421
1422         return 1;
1423 }
1424
1425 static int do_bootm_qnxelf(int flag, int argc, char *argv[],
1426                             bootm_headers_t *images)
1427 {
1428         char *local_args[2];
1429         char str[16];
1430
1431         if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1432                 return 1;
1433
1434 #if defined(CONFIG_FIT)
1435         if (!images->legacy_hdr_valid) {
1436                 fit_unsupported_reset ("QNX");
1437                 return 1;
1438         }
1439 #endif
1440
1441         sprintf(str, "%lx", images->ep); /* write entry-point into string */
1442         local_args[0] = argv[0];
1443         local_args[1] = str;    /* and provide it via the arguments */
1444         do_bootelf(NULL, 0, 2, local_args);
1445
1446         return 1;
1447 }
1448 #endif
1449
1450 #ifdef CONFIG_INTEGRITY
1451 static int do_bootm_integrity (int flag, int argc, char *argv[],
1452                            bootm_headers_t *images)
1453 {
1454         void (*entry_point)(void);
1455
1456         if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1457                 return 1;
1458
1459 #if defined(CONFIG_FIT)
1460         if (!images->legacy_hdr_valid) {
1461                 fit_unsupported_reset ("INTEGRITY");
1462                 return 1;
1463         }
1464 #endif
1465
1466         entry_point = (void (*)(void))images->ep;
1467
1468         printf ("## Transferring control to INTEGRITY (at address %08lx) ...\n",
1469                 (ulong)entry_point);
1470
1471         show_boot_progress (15);
1472
1473         /*
1474          * INTEGRITY Parameters:
1475          *   None
1476          */
1477         (*entry_point)();
1478
1479         return 1;
1480 }
1481 #endif