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