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