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