blob: 861712b78bcec63aa1302351df9d51c559fd6be5 [file] [log] [blame]
wdenk47d1a6e2002-11-03 00:01:44 +00001/*
Stefan Roese5d5ce292006-03-13 11:16:36 +01002 * (C) Copyright 2000-2006
wdenk47d1a6e2002-11-03 00:01:44 +00003 * 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
Marian Balakowicz41d71ed2008-01-08 18:14:09 +010024
wdenk47d1a6e2002-11-03 00:01:44 +000025/*
26 * Boot support
27 */
28#include <common.h>
29#include <watchdog.h>
30#include <command.h>
wdenk47d1a6e2002-11-03 00:01:44 +000031#include <image.h>
32#include <malloc.h>
33#include <zlib.h>
wdenk710e3502003-08-29 20:57:53 +000034#include <bzlib.h>
wdenk0893c472003-05-20 14:25:27 +000035#include <environment.h>
Kumar Gala6d7bfa82008-02-27 21:51:47 -060036#include <lmb.h>
wdenk47d1a6e2002-11-03 00:01:44 +000037#include <asm/byteorder.h>
wdenk57b2d802003-06-27 21:31:46 +000038
Stefan Roesea629a722008-07-30 09:59:51 +020039#if defined(CONFIG_CMD_USB)
Markus Klotzbücher09197cb2008-07-10 14:47:09 +020040#include <usb.h>
41#endif
42
wdenk47d1a6e2002-11-03 00:01:44 +000043#ifdef CFG_HUSH_PARSER
44#include <hush.h>
45#endif
46
Kumar Gala9f4e7e42008-08-15 08:24:39 -050047#if defined(CONFIG_OF_LIBFDT)
48#include <fdt.h>
49#include <libfdt.h>
50#include <fdt_support.h>
51#endif
52
Marian Balakowicz2df645e2008-01-08 18:17:10 +010053DECLARE_GLOBAL_DATA_PTR;
wdenk9dfa8d12002-12-08 09:53:23 +000054
Marian Balakowicz2df645e2008-01-08 18:17:10 +010055extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
56#ifndef CFG_BOOTM_LEN
57#define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
wdenk381669a2003-06-16 23:50:08 +000058#endif
59
Marian Balakowiczbe946ba2008-01-08 18:11:43 +010060#ifdef CONFIG_BZIP2
61extern void bz_internal_error(int);
wdenk47d1a6e2002-11-03 00:01:44 +000062#endif
63
Jon Loeliger54324d02007-07-08 17:51:39 -050064#if defined(CONFIG_CMD_IMI)
wdenk47d1a6e2002-11-03 00:01:44 +000065static int image_info (unsigned long addr);
66#endif
wdenk874ac262003-07-24 23:38:38 +000067
Jon Loeliger54324d02007-07-08 17:51:39 -050068#if defined(CONFIG_CMD_IMLS)
wdenk874ac262003-07-24 23:38:38 +000069#include <flash.h>
Marian Balakowicz513b4a12005-10-11 19:09:42 +020070extern flash_info_t flash_info[]; /* info for FLASH chips */
wdenk874ac262003-07-24 23:38:38 +000071static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
72#endif
73
Marian Balakowicz2df645e2008-01-08 18:17:10 +010074#ifdef CONFIG_SILENT_CONSOLE
75static void fixup_silent_linux (void);
76#endif
wdenk47d1a6e2002-11-03 00:01:44 +000077
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +010078static image_header_t *image_get_kernel (ulong img_addr, int verify);
79#if defined(CONFIG_FIT)
80static int fit_check_kernel (const void *fit, int os_noffset, int verify);
wdenk591dda52002-11-18 00:14:45 +000081#endif
82
Marian Balakowiczd7c88a42008-02-29 14:58:34 +010083static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +010084 bootm_headers_t *images, ulong *os_data, ulong *os_len);
Marian Balakowicz2df645e2008-01-08 18:17:10 +010085extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
wdenk47d1a6e2002-11-03 00:01:44 +000086
wdenk47d1a6e2002-11-03 00:01:44 +000087/*
88 * Continue booting an OS image; caller already has:
89 * - copied image header to global variable `header'
90 * - checked header magic number, checksums (both header & image),
91 * - verified image architecture (PPC) and type (KERNEL or MULTI),
92 * - loaded (first part of) image to header load address,
93 * - disabled interrupts.
94 */
Kumar Gala48626aa2008-08-15 08:24:45 -050095typedef int boot_os_fn (int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +010096 bootm_headers_t *images); /* pointers to os/initrd/fdt */
wdenk47d1a6e2002-11-03 00:01:44 +000097
Marian Balakowicz2df645e2008-01-08 18:17:10 +010098extern boot_os_fn do_bootm_linux;
99static boot_os_fn do_bootm_netbsd;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100100#if defined(CONFIG_LYNXKDI)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100101static boot_os_fn do_bootm_lynxkdi;
102extern void lynxkdi_boot (image_header_t *);
wdenk47d1a6e2002-11-03 00:01:44 +0000103#endif
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100104static boot_os_fn do_bootm_rtems;
Jon Loeliger54324d02007-07-08 17:51:39 -0500105#if defined(CONFIG_CMD_ELF)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100106static boot_os_fn do_bootm_vxworks;
107static boot_os_fn do_bootm_qnxelf;
108int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
109int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
Jon Loeligerd704d912007-07-10 11:02:44 -0500110#endif
Peter Tyser56b8dd12008-09-08 14:56:49 -0500111#if defined(CONFIG_INTEGRITY)
112static boot_os_fn do_bootm_integrity;
113#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000114
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100115ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100116static bootm_headers_t images; /* pointers to os/initrd/fdt images */
Stefan Roese5d5ce292006-03-13 11:16:36 +0100117
Kumar Galab937bb72008-02-27 21:51:49 -0600118void __board_lmb_reserve(struct lmb *lmb)
119{
120 /* please define platform specific board_lmb_reserve() */
121}
122void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
wdenk47d1a6e2002-11-03 00:01:44 +0000123
Kumar Galafffb1432008-08-15 08:24:37 -0500124#if defined(__ARM__)
125 #define IH_INITRD_ARCH IH_ARCH_ARM
126#elif defined(__avr32__)
127 #define IH_INITRD_ARCH IH_ARCH_AVR32
128#elif defined(__bfin__)
129 #define IH_INITRD_ARCH IH_ARCH_BLACKFIN
130#elif defined(__I386__)
131 #define IH_INITRD_ARCH IH_ARCH_I386
132#elif defined(__M68K__)
133 #define IH_INITRD_ARCH IH_ARCH_M68K
134#elif defined(__microblaze__)
135 #define IH_INITRD_ARCH IH_ARCH_MICROBLAZE
136#elif defined(__mips__)
137 #define IH_INITRD_ARCH IH_ARCH_MIPS
138#elif defined(__nios__)
139 #define IH_INITRD_ARCH IH_ARCH_NIOS
140#elif defined(__nios2__)
141 #define IH_INITRD_ARCH IH_ARCH_NIOS2
142#elif defined(__PPC__)
143 #define IH_INITRD_ARCH IH_ARCH_PPC
144#elif defined(__sh__)
145 #define IH_INITRD_ARCH IH_ARCH_SH
146#elif defined(__sparc__)
147 #define IH_INITRD_ARCH IH_ARCH_SPARC
148#else
149# error Unknown CPU type
150#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000151
Kumar Galabd70bbe2008-08-15 08:24:41 -0500152static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000153{
Becky Bruced26d67c2008-06-09 20:37:18 -0500154 ulong mem_start;
155 phys_size_t mem_size;
Kumar Galabd70bbe2008-08-15 08:24:41 -0500156 void *os_hdr;
Kumar Galafffb1432008-08-15 08:24:37 -0500157 int ret;
wdenk47d1a6e2002-11-03 00:01:44 +0000158
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100159 memset ((void *)&images, 0, sizeof (images));
Bartlomiej Sieka47868592008-04-18 12:39:23 +0200160 images.verify = getenv_yesno ("verify");
wdenk47d1a6e2002-11-03 00:01:44 +0000161
Kumar Galada6d11e2008-08-15 08:24:40 -0500162 lmb_init(&images.lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000163
Kumar Galac5bacfd2008-02-27 21:51:50 -0600164 mem_start = getenv_bootm_low();
165 mem_size = getenv_bootm_size();
wdenk47d1a6e2002-11-03 00:01:44 +0000166
Kumar Galada6d11e2008-08-15 08:24:40 -0500167 lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
wdenk47d1a6e2002-11-03 00:01:44 +0000168
Kumar Galada6d11e2008-08-15 08:24:40 -0500169 board_lmb_reserve(&images.lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000170
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100171 /* get kernel image header, start address and length */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100172 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500173 &images, &images.os.image_start, &images.os.image_len);
174 if (images.os.image_len == 0) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100175 puts ("ERROR: can't get kernel image!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000176 return 1;
177 }
Wolfgang Denk63e44ff2005-10-06 01:50:50 +0200178
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100179 /* get image parameters */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100180 switch (genimg_get_format (os_hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100181 case IMAGE_FORMAT_LEGACY:
Kumar Galabd70bbe2008-08-15 08:24:41 -0500182 images.os.type = image_get_type (os_hdr);
183 images.os.comp = image_get_comp (os_hdr);
184 images.os.os = image_get_os (os_hdr);
Wolfgang Denk63e44ff2005-10-06 01:50:50 +0200185
Kumar Galabd70bbe2008-08-15 08:24:41 -0500186 images.os.end = image_get_image_end (os_hdr);
187 images.os.load = image_get_load (os_hdr);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100188 break;
189#if defined(CONFIG_FIT)
190 case IMAGE_FORMAT_FIT:
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100191 if (fit_image_get_type (images.fit_hdr_os,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500192 images.fit_noffset_os, &images.os.type)) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100193 puts ("Can't get image type!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100194 show_boot_progress (-109);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100195 return 1;
196 }
wdenk47d1a6e2002-11-03 00:01:44 +0000197
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100198 if (fit_image_get_comp (images.fit_hdr_os,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500199 images.fit_noffset_os, &images.os.comp)) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100200 puts ("Can't get image compression!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100201 show_boot_progress (-110);
wdenk47d1a6e2002-11-03 00:01:44 +0000202 return 1;
203 }
wdenk47d1a6e2002-11-03 00:01:44 +0000204
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100205 if (fit_image_get_os (images.fit_hdr_os,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500206 images.fit_noffset_os, &images.os.os)) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100207 puts ("Can't get image OS!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100208 show_boot_progress (-111);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100209 return 1;
210 }
wdenk47d1a6e2002-11-03 00:01:44 +0000211
Kumar Galabd70bbe2008-08-15 08:24:41 -0500212 images.os.end = fit_get_end (images.fit_hdr_os);
wdenk47d1a6e2002-11-03 00:01:44 +0000213
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100214 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500215 &images.os.load)) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100216 puts ("Can't get image load address!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100217 show_boot_progress (-112);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100218 return 1;
wdenk655a0f92003-10-30 21:49:38 +0000219 }
220 break;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100221#endif
222 default:
223 puts ("ERROR: unknown image format type!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000224 return 1;
225 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100226
Kumar Gala93467bc2008-08-15 08:24:36 -0500227 /* find kernel entry point */
228 if (images.legacy_hdr_valid) {
229 images.ep = image_get_ep (&images.legacy_hdr_os_copy);
230#if defined(CONFIG_FIT)
231 } else if (images.fit_uname_os) {
232 ret = fit_image_get_entry (images.fit_hdr_os,
233 images.fit_noffset_os, &images.ep);
234 if (ret) {
235 puts ("Can't get entry point property!\n");
236 return 1;
237 }
238#endif
239 } else {
240 puts ("Could not find kernel entry point!\n");
241 return 1;
242 }
243
Kumar Galabd70bbe2008-08-15 08:24:41 -0500244 if (images.os.os == IH_OS_LINUX) {
Kumar Galafffb1432008-08-15 08:24:37 -0500245 /* find ramdisk */
246 ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
247 &images.rd_start, &images.rd_end);
248 if (ret) {
Kumar Galab8ca7342008-08-29 19:08:29 -0500249 puts ("Ramdisk image is corrupt or invalid\n");
Kumar Galafffb1432008-08-15 08:24:37 -0500250 return 1;
251 }
Kumar Galaa5130ad2008-08-15 08:24:38 -0500252
253#if defined(CONFIG_OF_LIBFDT)
254 /* find flattened device tree */
255 ret = boot_get_fdt (flag, argc, argv, &images,
256 &images.ft_addr, &images.ft_len);
257 if (ret) {
258 puts ("Could not find a valid device tree\n");
259 return 1;
260 }
Kumar Gala9f4e7e42008-08-15 08:24:39 -0500261
262 set_working_fdt_addr(images.ft_addr);
Kumar Galaa5130ad2008-08-15 08:24:38 -0500263#endif
Kumar Galafffb1432008-08-15 08:24:37 -0500264 }
265
Kumar Galabd70bbe2008-08-15 08:24:41 -0500266 images.os.start = (ulong)os_hdr;
267 images.valid = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000268
Kumar Galabd70bbe2008-08-15 08:24:41 -0500269 return 0;
270}
Markus Klotzbücher09197cb2008-07-10 14:47:09 +0200271
Kumar Galabd70bbe2008-08-15 08:24:41 -0500272#define BOOTM_ERR_RESET -1
273#define BOOTM_ERR_OVERLAP -2
274#define BOOTM_ERR_UNIMPLEMENTED -3
275static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
276{
277 uint8_t comp = os.comp;
278 ulong load = os.load;
279 ulong blob_start = os.start;
280 ulong blob_end = os.end;
281 ulong image_start = os.image_start;
282 ulong image_len = os.image_len;
283 uint unc_len = CFG_BOOTM_LEN;
Markus Klotzbücher09197cb2008-07-10 14:47:09 +0200284
Kumar Galabd70bbe2008-08-15 08:24:41 -0500285 const char *type_name = genimg_get_type_name (os.type);
wdenk452cfd62002-11-19 11:04:11 +0000286
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100287 switch (comp) {
wdenk47d1a6e2002-11-03 00:01:44 +0000288 case IH_COMP_NONE:
Kumar Galabd70bbe2008-08-15 08:24:41 -0500289 if (load == blob_start) {
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100290 printf (" XIP %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000291 } else {
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100292 printf (" Loading %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000293
Kumar Galabd70bbe2008-08-15 08:24:41 -0500294 memmove_wd ((void *)load,
295 (void *)image_start, image_len, CHUNKSZ);
wdenk47d1a6e2002-11-03 00:01:44 +0000296 }
Kumar Galabd70bbe2008-08-15 08:24:41 -0500297 *load_end = load + image_len;
Guennadi Liakhovetski3110cf82008-07-31 12:35:04 +0200298 puts("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000299 break;
300 case IH_COMP_GZIP:
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100301 printf (" Uncompressing %s ... ", type_name);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500302 if (gunzip ((void *)load, unc_len,
303 (uchar *)image_start, &image_len) != 0) {
Marian Balakowiczb5324a82008-03-12 10:33:01 +0100304 puts ("GUNZIP: uncompress or overwrite error "
305 "- must RESET board to recover\n");
Kumar Galabd70bbe2008-08-15 08:24:41 -0500306 if (boot_progress)
307 show_boot_progress (-6);
308 return BOOTM_ERR_RESET;
wdenk47d1a6e2002-11-03 00:01:44 +0000309 }
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100310
Kumar Galabd70bbe2008-08-15 08:24:41 -0500311 *load_end = load + image_len;
wdenk47d1a6e2002-11-03 00:01:44 +0000312 break;
wdenk710e3502003-08-29 20:57:53 +0000313#ifdef CONFIG_BZIP2
314 case IH_COMP_BZIP2:
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100315 printf (" Uncompressing %s ... ", type_name);
wdenk2cefd152004-02-08 22:55:38 +0000316 /*
317 * If we've got less than 4 MB of malloc() space,
318 * use slower decompression algorithm which requires
319 * at most 2300 KB of memory.
320 */
Kumar Galabd70bbe2008-08-15 08:24:41 -0500321 int i = BZ2_bzBuffToBuffDecompress ((char*)load,
322 &unc_len, (char *)image_start, image_len,
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100323 CFG_MALLOC_LEN < (4096 * 1024), 0);
wdenk710e3502003-08-29 20:57:53 +0000324 if (i != BZ_OK) {
Marian Balakowiczb5324a82008-03-12 10:33:01 +0100325 printf ("BUNZIP2: uncompress or overwrite error %d "
326 "- must RESET board to recover\n", i);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500327 if (boot_progress)
328 show_boot_progress (-6);
329 return BOOTM_ERR_RESET;
wdenk710e3502003-08-29 20:57:53 +0000330 }
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100331
Kumar Galabd70bbe2008-08-15 08:24:41 -0500332 *load_end = load + unc_len;
wdenk710e3502003-08-29 20:57:53 +0000333 break;
334#endif /* CONFIG_BZIP2 */
wdenk47d1a6e2002-11-03 00:01:44 +0000335 default:
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100336 printf ("Unimplemented compression type %d\n", comp);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500337 return BOOTM_ERR_UNIMPLEMENTED;
wdenk47d1a6e2002-11-03 00:01:44 +0000338 }
wdenk42c05472004-03-23 22:14:11 +0000339 puts ("OK\n");
Wolfgang Denk7d956352008-09-08 22:10:28 +0200340 debug (" kernel loaded at 0x%08lx, end = 0x%8p\n", load, load_end);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500341 if (boot_progress)
342 show_boot_progress (7);
wdenk47d1a6e2002-11-03 00:01:44 +0000343
Kumar Galabd70bbe2008-08-15 08:24:41 -0500344 if ((load < blob_end) && (*load_end > blob_start)) {
345 debug ("images.os.start = 0x%lX, images.os.end = 0x%lx\n", blob_start, blob_end);
Wolfgang Denk7d956352008-09-08 22:10:28 +0200346 debug ("images.os.load = 0x%lx, load_end = 0x%p\n", load, load_end);
wdenk47d1a6e2002-11-03 00:01:44 +0000347
Kumar Galabd70bbe2008-08-15 08:24:41 -0500348 return BOOTM_ERR_OVERLAP;
349 }
350
351 return 0;
352}
353
354/*******************************************************************/
355/* bootm - boot application image from image in memory */
356/*******************************************************************/
357int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
358{
359
360 ulong iflag;
361 ulong load_end = 0;
362 int ret;
363
Anatolij Gustschin128de002008-08-29 21:04:45 +0200364 if (bootm_start(cmdtp, flag, argc, argv))
365 return 1;
Kumar Galabd70bbe2008-08-15 08:24:41 -0500366
367 /*
368 * We have reached the point of no return: we are going to
369 * overwrite all exception vector code, so we cannot easily
370 * recover from any failures any more...
371 */
372 iflag = disable_interrupts();
373
374#if defined(CONFIG_CMD_USB)
375 /*
376 * turn off USB to prevent the host controller from writing to the
377 * SDRAM while Linux is booting. This could happen (at least for OHCI
378 * controller), because the HCCA (Host Controller Communication Area)
379 * lies within the SDRAM and the host controller writes continously to
380 * this area (as busmaster!). The HccaFrameNumber is for example
381 * updated every 1 ms within the HCCA structure in SDRAM! For more
382 * details see the OpenHCI specification.
383 */
384 usb_stop();
385#endif
386
387#ifdef CONFIG_AMIGAONEG3SE
388 /*
389 * We've possible left the caches enabled during
390 * bios emulation, so turn them off again
391 */
392 icache_disable();
393 dcache_disable();
394#endif
395
396 ret = bootm_load_os(images.os, &load_end, 1);
397
398 if (ret < 0) {
399 if (ret == BOOTM_ERR_RESET)
Marian Balakowiczab00e022008-04-11 11:07:49 +0200400 do_reset (cmdtp, flag, argc, argv);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500401 if (ret == BOOTM_ERR_OVERLAP) {
402 if (images.legacy_hdr_valid) {
403 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
404 puts ("WARNING: legacy format multi component "
405 "image overwritten\n");
406 } else {
407 puts ("ERROR: new format image overwritten - "
408 "must RESET the board to recover\n");
409 show_boot_progress (-113);
410 do_reset (cmdtp, flag, argc, argv);
411 }
412 }
413 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
414 if (iflag)
415 enable_interrupts();
416 show_boot_progress (-7);
417 return 1;
Marian Balakowiczab00e022008-04-11 11:07:49 +0200418 }
wdenk47d1a6e2002-11-03 00:01:44 +0000419 }
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100420
Kumar Galabd70bbe2008-08-15 08:24:41 -0500421 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
wdenk47d1a6e2002-11-03 00:01:44 +0000422
Kumar Galabd70bbe2008-08-15 08:24:41 -0500423 show_boot_progress (8);
Kumar Gala6d7bfa82008-02-27 21:51:47 -0600424
Kumar Galabd70bbe2008-08-15 08:24:41 -0500425 switch (images.os.os) {
wdenk47d1a6e2002-11-03 00:01:44 +0000426 default: /* handled by (original) Linux case */
427 case IH_OS_LINUX:
wdenk808532a2003-10-10 10:05:42 +0000428#ifdef CONFIG_SILENT_CONSOLE
429 fixup_silent_linux();
430#endif
Kumar Gala48626aa2008-08-15 08:24:45 -0500431 do_bootm_linux (0, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000432 break;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100433
wdenk47d1a6e2002-11-03 00:01:44 +0000434 case IH_OS_NETBSD:
Kumar Gala48626aa2008-08-15 08:24:45 -0500435 do_bootm_netbsd (0, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000436 break;
wdenke58b0dc2003-07-27 00:21:01 +0000437
438#ifdef CONFIG_LYNXKDI
439 case IH_OS_LYNXOS:
Kumar Gala48626aa2008-08-15 08:24:45 -0500440 do_bootm_lynxkdi (0, argc, argv, &images);
wdenke58b0dc2003-07-27 00:21:01 +0000441 break;
442#endif
wdenk57b2d802003-06-27 21:31:46 +0000443
wdenk92bbe3f2003-04-20 14:04:18 +0000444 case IH_OS_RTEMS:
Kumar Gala48626aa2008-08-15 08:24:45 -0500445 do_bootm_rtems (0, argc, argv, &images);
wdenk92bbe3f2003-04-20 14:04:18 +0000446 break;
wdenk57b2d802003-06-27 21:31:46 +0000447
Jon Loeliger54324d02007-07-08 17:51:39 -0500448#if defined(CONFIG_CMD_ELF)
wdenk47d1a6e2002-11-03 00:01:44 +0000449 case IH_OS_VXWORKS:
Kumar Gala48626aa2008-08-15 08:24:45 -0500450 do_bootm_vxworks (0, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000451 break;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100452
wdenk47d1a6e2002-11-03 00:01:44 +0000453 case IH_OS_QNX:
Kumar Gala48626aa2008-08-15 08:24:45 -0500454 do_bootm_qnxelf (0, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000455 break;
Jon Loeligerd704d912007-07-10 11:02:44 -0500456#endif
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100457
Peter Tyser56b8dd12008-09-08 14:56:49 -0500458#ifdef CONFIG_INTEGRITY
459 case IH_OS_INTEGRITY:
460 do_bootm_integrity (0, argc, argv, &images);
461 break;
462#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000463 }
464
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200465 show_boot_progress (-9);
wdenk47d1a6e2002-11-03 00:01:44 +0000466#ifdef DEBUG
wdenk42c05472004-03-23 22:14:11 +0000467 puts ("\n## Control returned to monitor - resetting...\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000468#endif
Kumar Gala48626aa2008-08-15 08:24:45 -0500469 do_reset (cmdtp, flag, argc, argv);
Marian Balakowicz9c220262008-03-12 10:14:57 +0100470
wdenk47d1a6e2002-11-03 00:01:44 +0000471 return 1;
472}
473
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100474/**
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100475 * image_get_kernel - verify legacy format kernel image
476 * @img_addr: in RAM address of the legacy format image to be verified
477 * @verify: data CRC verification flag
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100478 *
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100479 * image_get_kernel() verifies legacy image integrity and returns pointer to
480 * legacy image header if image verification was completed successfully.
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100481 *
482 * returns:
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100483 * pointer to a legacy image header if valid image was found
484 * otherwise return NULL
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100485 */
Marian Balakowicz59504f62008-02-27 11:02:07 +0100486static image_header_t *image_get_kernel (ulong img_addr, int verify)
wdenk808532a2003-10-10 10:05:42 +0000487{
Marian Balakowicz59504f62008-02-27 11:02:07 +0100488 image_header_t *hdr = (image_header_t *)img_addr;
wdenk808532a2003-10-10 10:05:42 +0000489
Marian Balakowicz59504f62008-02-27 11:02:07 +0100490 if (!image_check_magic(hdr)) {
491 puts ("Bad Magic Number\n");
492 show_boot_progress (-1);
493 return NULL;
494 }
495 show_boot_progress (2);
wdenk808532a2003-10-10 10:05:42 +0000496
Marian Balakowicz59504f62008-02-27 11:02:07 +0100497 if (!image_check_hcrc (hdr)) {
498 puts ("Bad Header Checksum\n");
499 show_boot_progress (-2);
500 return NULL;
501 }
502
503 show_boot_progress (3);
504 image_print_contents (hdr);
505
506 if (verify) {
507 puts (" Verifying Checksum ... ");
508 if (!image_check_dcrc (hdr)) {
509 printf ("Bad Data CRC\n");
510 show_boot_progress (-3);
511 return NULL;
wdenk808532a2003-10-10 10:05:42 +0000512 }
Marian Balakowicz59504f62008-02-27 11:02:07 +0100513 puts ("OK\n");
wdenk808532a2003-10-10 10:05:42 +0000514 }
Marian Balakowicz59504f62008-02-27 11:02:07 +0100515 show_boot_progress (4);
wdenk808532a2003-10-10 10:05:42 +0000516
Marian Balakowicz59504f62008-02-27 11:02:07 +0100517 if (!image_check_target_arch (hdr)) {
518 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
519 show_boot_progress (-4);
520 return NULL;
521 }
522 return hdr;
wdenk808532a2003-10-10 10:05:42 +0000523}
wdenk808532a2003-10-10 10:05:42 +0000524
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100525/**
526 * fit_check_kernel - verify FIT format kernel subimage
527 * @fit_hdr: pointer to the FIT image header
528 * os_noffset: kernel subimage node offset within FIT image
529 * @verify: data CRC verification flag
530 *
531 * fit_check_kernel() verifies integrity of the kernel subimage and from
532 * specified FIT image.
533 *
534 * returns:
535 * 1, on success
536 * 0, on failure
537 */
538#if defined (CONFIG_FIT)
539static int fit_check_kernel (const void *fit, int os_noffset, int verify)
wdenk47d1a6e2002-11-03 00:01:44 +0000540{
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100541 fit_image_print (fit, os_noffset, " ");
wdenk47d1a6e2002-11-03 00:01:44 +0000542
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100543 if (verify) {
544 puts (" Verifying Hash Integrity ... ");
545 if (!fit_image_check_hashes (fit, os_noffset)) {
546 puts ("Bad Data Hash\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100547 show_boot_progress (-104);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100548 return 0;
549 }
550 puts ("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000551 }
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100552 show_boot_progress (105);
wdenk47d1a6e2002-11-03 00:01:44 +0000553
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100554 if (!fit_image_check_target_arch (fit, os_noffset)) {
555 puts ("Unsupported Architecture\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100556 show_boot_progress (-105);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100557 return 0;
558 }
wdenk47d1a6e2002-11-03 00:01:44 +0000559
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100560 show_boot_progress (106);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100561 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
562 puts ("Not a kernel image\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100563 show_boot_progress (-106);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100564 return 0;
565 }
wdenk47d1a6e2002-11-03 00:01:44 +0000566
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100567 show_boot_progress (107);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100568 return 1;
569}
570#endif /* CONFIG_FIT */
wdenk56f94be2002-11-05 16:35:14 +0000571
Marian Balakowicz59504f62008-02-27 11:02:07 +0100572/**
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100573 * boot_get_kernel - find kernel image
Marian Balakowicz59504f62008-02-27 11:02:07 +0100574 * @os_data: pointer to a ulong variable, will hold os data start address
575 * @os_len: pointer to a ulong variable, will hold os data length
576 *
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100577 * boot_get_kernel() tries to find a kernel image, verifies its integrity
Marian Balakowicz59504f62008-02-27 11:02:07 +0100578 * and locates kernel data.
579 *
580 * returns:
581 * pointer to image header if valid image was found, plus kernel start
582 * address and length, otherwise NULL
583 */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100584static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100585 bootm_headers_t *images, ulong *os_data, ulong *os_len)
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100586{
587 image_header_t *hdr;
588 ulong img_addr;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100589#if defined(CONFIG_FIT)
590 void *fit_hdr;
591 const char *fit_uname_config = NULL;
592 const char *fit_uname_kernel = NULL;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100593 const void *data;
594 size_t len;
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100595 int cfg_noffset;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100596 int os_noffset;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100597#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000598
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100599 /* find out kernel image address */
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100600 if (argc < 2) {
601 img_addr = load_addr;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100602 debug ("* kernel: default image load address = 0x%08lx\n",
603 load_addr);
604#if defined(CONFIG_FIT)
605 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
606 &fit_uname_config)) {
607 debug ("* kernel: config '%s' from image at 0x%08lx\n",
608 fit_uname_config, img_addr);
609 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
610 &fit_uname_kernel)) {
611 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
612 fit_uname_kernel, img_addr);
613#endif
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100614 } else {
615 img_addr = simple_strtoul(argv[1], NULL, 16);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100616 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100617 }
wdenk56f94be2002-11-05 16:35:14 +0000618
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100619 show_boot_progress (1);
wdenk47d1a6e2002-11-03 00:01:44 +0000620
Marian Balakowiczc536d6f2008-02-21 17:20:19 +0100621 /* copy from dataflash if needed */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100622 img_addr = genimg_get_image (img_addr);
wdenk47d1a6e2002-11-03 00:01:44 +0000623
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100624 /* check image type, for FIT images get FIT kernel node */
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100625 *os_data = *os_len = 0;
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100626 switch (genimg_get_format ((void *)img_addr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100627 case IMAGE_FORMAT_LEGACY:
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100628 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
629 img_addr);
Marian Balakowicz59504f62008-02-27 11:02:07 +0100630 hdr = image_get_kernel (img_addr, images->verify);
631 if (!hdr)
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100632 return NULL;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100633 show_boot_progress (5);
wdenk47d1a6e2002-11-03 00:01:44 +0000634
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100635 /* get os_data and os_len */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100636 switch (image_get_type (hdr)) {
637 case IH_TYPE_KERNEL:
638 *os_data = image_get_data (hdr);
639 *os_len = image_get_data_size (hdr);
640 break;
641 case IH_TYPE_MULTI:
642 image_multi_getimg (hdr, 0, os_data, os_len);
643 break;
644 default:
645 printf ("Wrong Image Type for %s command\n", cmdtp->name);
646 show_boot_progress (-5);
647 return NULL;
648 }
Marian Balakowiczab00e022008-04-11 11:07:49 +0200649
650 /*
651 * copy image header to allow for image overwrites during kernel
652 * decompression.
653 */
654 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
655
656 /* save pointer to image header */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100657 images->legacy_hdr_os = hdr;
wdenk47d1a6e2002-11-03 00:01:44 +0000658
Marian Balakowiczab00e022008-04-11 11:07:49 +0200659 images->legacy_hdr_valid = 1;
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100660 show_boot_progress (6);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100661 break;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100662#if defined(CONFIG_FIT)
663 case IMAGE_FORMAT_FIT:
664 fit_hdr = (void *)img_addr;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100665 printf ("## Booting kernel from FIT Image at %08lx ...\n",
666 img_addr);
wdenk47d1a6e2002-11-03 00:01:44 +0000667
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100668 if (!fit_check_format (fit_hdr)) {
669 puts ("Bad FIT kernel image format!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100670 show_boot_progress (-100);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100671 return NULL;
672 }
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100673 show_boot_progress (100);
wdenk47d1a6e2002-11-03 00:01:44 +0000674
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100675 if (!fit_uname_kernel) {
676 /*
677 * no kernel image node unit name, try to get config
678 * node first. If config unit node name is NULL
679 * fit_conf_get_node() will try to find default config node
680 */
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100681 show_boot_progress (101);
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100682 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
683 if (cfg_noffset < 0) {
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100684 show_boot_progress (-101);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100685 return NULL;
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100686 }
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100687 /* save configuration uname provided in the first
688 * bootm argument
689 */
690 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
691 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
692 show_boot_progress (103);
wdenk47d1a6e2002-11-03 00:01:44 +0000693
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100694 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100695 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
696 } else {
697 /* get kernel component image node offset */
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100698 show_boot_progress (102);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100699 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
700 }
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100701 if (os_noffset < 0) {
702 show_boot_progress (-103);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100703 return NULL;
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100704 }
wdenk47d1a6e2002-11-03 00:01:44 +0000705
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100706 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
wdenk47d1a6e2002-11-03 00:01:44 +0000707
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100708 show_boot_progress (104);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100709 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
710 return NULL;
Matthew McClintock6fb7c812006-06-28 10:41:37 -0500711
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100712 /* get kernel image data address and length */
713 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
714 puts ("Could not find kernel subimage data!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100715 show_boot_progress (-107);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100716 return NULL;
Matthew McClintock6fb7c812006-06-28 10:41:37 -0500717 }
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100718 show_boot_progress (108);
wdenk47d1a6e2002-11-03 00:01:44 +0000719
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100720 *os_len = len;
721 *os_data = (ulong)data;
722 images->fit_hdr_os = fit_hdr;
723 images->fit_uname_os = fit_uname_kernel;
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100724 images->fit_noffset_os = os_noffset;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100725 break;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100726#endif
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100727 default:
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100728 printf ("Wrong Image Format for %s command\n", cmdtp->name);
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100729 show_boot_progress (-108);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100730 return NULL;
731 }
wdenk47d1a6e2002-11-03 00:01:44 +0000732
Wolfgang Denk8d541882008-07-10 13:16:09 +0200733 debug (" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100734 *os_data, *os_len, *os_len);
wdenk47d1a6e2002-11-03 00:01:44 +0000735
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100736 return (void *)img_addr;
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100737}
wdenk47d1a6e2002-11-03 00:01:44 +0000738
wdenk47d1a6e2002-11-03 00:01:44 +0000739U_BOOT_CMD(
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100740 bootm, CFG_MAXARGS, 1, do_bootm,
741 "bootm - boot application image from memory\n",
742 "[addr [arg ...]]\n - boot application image stored in memory\n"
743 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
744 "\t'arg' can be the address of an initrd image\n"
Marian Balakowiczd2160852008-01-31 13:20:07 +0100745#if defined(CONFIG_OF_LIBFDT)
wdenk47d1a6e2002-11-03 00:01:44 +0000746 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
747 "\ta third argument is required which is the address of the\n"
748 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
749 "\tuse a '-' for the second argument. If you do not pass a third\n"
750 "\ta bd_info struct will be passed instead\n"
751#endif
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100752#if defined(CONFIG_FIT)
753 "\t\nFor the new multi component uImage format (FIT) addresses\n"
754 "\tmust be extened to include component or configuration unit name:\n"
755 "\taddr:<subimg_uname> - direct component image specification\n"
756 "\taddr#<conf_uname> - configuration specification\n"
757 "\tUse iminfo command to get the list of existing component\n"
758 "\timages and configurations.\n"
759#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000760);
wdenk47d1a6e2002-11-03 00:01:44 +0000761
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100762/*******************************************************************/
763/* bootd - boot default image */
764/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -0500765#if defined(CONFIG_CMD_BOOTD)
wdenk47d1a6e2002-11-03 00:01:44 +0000766int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
767{
768 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000769
wdenk47d1a6e2002-11-03 00:01:44 +0000770#ifndef CFG_HUSH_PARSER
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100771 if (run_command (getenv ("bootcmd"), flag) < 0)
772 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000773#else
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100774 if (parse_string_outer (getenv ("bootcmd"),
775 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
776 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000777#endif
778 return rcode;
779}
wdenk47d1a6e2002-11-03 00:01:44 +0000780
wdenkf287a242003-07-01 21:06:45 +0000781U_BOOT_CMD(
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100782 boot, 1, 1, do_bootd,
783 "boot - boot default, i.e., run 'bootcmd'\n",
wdenk3086a972003-06-28 23:11:04 +0000784 NULL
785);
wdenk47d1a6e2002-11-03 00:01:44 +0000786
wdenk3086a972003-06-28 23:11:04 +0000787/* keep old command name "bootd" for backward compatibility */
wdenkf287a242003-07-01 21:06:45 +0000788U_BOOT_CMD(
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100789 bootd, 1, 1, do_bootd,
790 "bootd - boot default, i.e., run 'bootcmd'\n",
wdenk57b2d802003-06-27 21:31:46 +0000791 NULL
792);
wdenk47d1a6e2002-11-03 00:01:44 +0000793
wdenk47d1a6e2002-11-03 00:01:44 +0000794#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000795
wdenk47d1a6e2002-11-03 00:01:44 +0000796
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100797/*******************************************************************/
798/* iminfo - print header info for a requested image */
799/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -0500800#if defined(CONFIG_CMD_IMI)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100801int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000802{
803 int arg;
804 ulong addr;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100805 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000806
wdenk47d1a6e2002-11-03 00:01:44 +0000807 if (argc < 2) {
808 return image_info (load_addr);
809 }
wdenk47d1a6e2002-11-03 00:01:44 +0000810
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100811 for (arg = 1; arg < argc; ++arg) {
812 addr = simple_strtoul (argv[arg], NULL, 16);
813 if (image_info (addr) != 0)
814 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000815 }
816 return rcode;
817}
wdenk47d1a6e2002-11-03 00:01:44 +0000818
wdenk47d1a6e2002-11-03 00:01:44 +0000819static int image_info (ulong addr)
820{
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100821 void *hdr = (void *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +0000822
wdenk47d1a6e2002-11-03 00:01:44 +0000823 printf ("\n## Checking Image at %08lx ...\n", addr);
wdenk47d1a6e2002-11-03 00:01:44 +0000824
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100825 switch (genimg_get_format (hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100826 case IMAGE_FORMAT_LEGACY:
827 puts (" Legacy image found\n");
828 if (!image_check_magic (hdr)) {
829 puts (" Bad Magic Number\n");
830 return 1;
831 }
wdenk47d1a6e2002-11-03 00:01:44 +0000832
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100833 if (!image_check_hcrc (hdr)) {
834 puts (" Bad Header Checksum\n");
835 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000836 }
837
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100838 image_print_contents (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000839
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100840 puts (" Verifying Checksum ... ");
841 if (!image_check_dcrc (hdr)) {
842 puts (" Bad Data CRC\n");
843 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000844 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100845 puts ("OK\n");
846 return 0;
847#if defined(CONFIG_FIT)
848 case IMAGE_FORMAT_FIT:
849 puts (" FIT image found\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000850
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100851 if (!fit_check_format (hdr)) {
852 puts ("Bad FIT image format!\n");
853 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000854 }
855
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100856 fit_print_contents (hdr);
Bartlomiej Sieka03797f52008-09-09 12:58:16 +0200857
858 if (!fit_all_image_check_hashes (hdr)) {
859 puts ("Bad hash in FIT image!\n");
860 return 1;
861 }
862
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100863 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000864#endif
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100865 default:
866 puts ("Unknown image format!\n");
867 break;
wdenk47d1a6e2002-11-03 00:01:44 +0000868 }
wdenk47d1a6e2002-11-03 00:01:44 +0000869
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100870 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000871}
wdenk47d1a6e2002-11-03 00:01:44 +0000872
wdenkf287a242003-07-01 21:06:45 +0000873U_BOOT_CMD(
874 iminfo, CFG_MAXARGS, 1, do_iminfo,
wdenk57b2d802003-06-27 21:31:46 +0000875 "iminfo - print header information for application image\n",
876 "addr [addr ...]\n"
877 " - print header information for application image starting at\n"
878 " address 'addr' in memory; this includes verification of the\n"
879 " image contents (magic number, header and payload checksums)\n"
880);
wdenk47d1a6e2002-11-03 00:01:44 +0000881#endif
882
883
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100884/*******************************************************************/
885/* imls - list all images found in flash */
886/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -0500887#if defined(CONFIG_CMD_IMLS)
wdenk874ac262003-07-24 23:38:38 +0000888int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
889{
890 flash_info_t *info;
891 int i, j;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100892 void *hdr;
wdenk47d1a6e2002-11-03 00:01:44 +0000893
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100894 for (i = 0, info = &flash_info[0];
895 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
wdenk47d1a6e2002-11-03 00:01:44 +0000896
wdenk874ac262003-07-24 23:38:38 +0000897 if (info->flash_id == FLASH_UNKNOWN)
898 goto next_bank;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100899 for (j = 0; j < info->sector_count; ++j) {
wdenk47d1a6e2002-11-03 00:01:44 +0000900
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100901 hdr = (void *)info->start[j];
902 if (!hdr)
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100903 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +0000904
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100905 switch (genimg_get_format (hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100906 case IMAGE_FORMAT_LEGACY:
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100907 if (!image_check_hcrc (hdr))
908 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +0000909
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100910 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
911 image_print_contents (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000912
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100913 puts (" Verifying Checksum ... ");
914 if (!image_check_dcrc (hdr)) {
915 puts ("Bad Data CRC\n");
916 } else {
917 puts ("OK\n");
918 }
919 break;
920#if defined(CONFIG_FIT)
921 case IMAGE_FORMAT_FIT:
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100922 if (!fit_check_format (hdr))
923 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +0000924
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100925 printf ("FIT Image at %08lX:\n", (ulong)hdr);
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100926 fit_print_contents (hdr);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100927 break;
928#endif
929 default:
930 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +0000931 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100932
wdenk0a658552003-08-05 17:43:17 +0000933next_sector: ;
wdenk47d1a6e2002-11-03 00:01:44 +0000934 }
wdenk0a658552003-08-05 17:43:17 +0000935next_bank: ;
wdenk47d1a6e2002-11-03 00:01:44 +0000936 }
937
wdenk874ac262003-07-24 23:38:38 +0000938 return (0);
939}
wdenk47d1a6e2002-11-03 00:01:44 +0000940
wdenk874ac262003-07-24 23:38:38 +0000941U_BOOT_CMD(
942 imls, 1, 1, do_imls,
943 "imls - list all images found in flash\n",
944 "\n"
945 " - Prints information about all images found at sector\n"
946 " boundaries in flash.\n"
947);
wdenk47d1a6e2002-11-03 00:01:44 +0000948#endif
949
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100950/*******************************************************************/
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100951/* helper routines */
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100952/*******************************************************************/
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100953#ifdef CONFIG_SILENT_CONSOLE
954static void fixup_silent_linux ()
955{
956 char buf[256], *start, *end;
957 char *cmdline = getenv ("bootargs");
wdenk47d1a6e2002-11-03 00:01:44 +0000958
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100959 /* Only fix cmdline when requested */
960 if (!(gd->flags & GD_FLG_SILENT))
961 return;
wdenk47d1a6e2002-11-03 00:01:44 +0000962
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100963 debug ("before silent fix-up: %s\n", cmdline);
964 if (cmdline) {
965 if ((start = strstr (cmdline, "console=")) != NULL) {
966 end = strchr (start, ' ');
967 strncpy (buf, cmdline, (start - cmdline + 8));
968 if (end)
969 strcpy (buf + (start - cmdline + 8), end);
970 else
971 buf[start - cmdline + 8] = '\0';
972 } else {
973 strcpy (buf, cmdline);
974 strcat (buf, " console=");
wdenk47d1a6e2002-11-03 00:01:44 +0000975 }
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100976 } else {
977 strcpy (buf, "console=");
wdenk47d1a6e2002-11-03 00:01:44 +0000978 }
wdenk47d1a6e2002-11-03 00:01:44 +0000979
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100980 setenv ("bootargs", buf);
981 debug ("after silent fix-up: %s\n", buf);
982}
983#endif /* CONFIG_SILENT_CONSOLE */
wdenk47d1a6e2002-11-03 00:01:44 +0000984
wdenk47d1a6e2002-11-03 00:01:44 +0000985
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100986/*******************************************************************/
987/* OS booting routines */
988/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +0000989
Kumar Gala48626aa2008-08-15 08:24:45 -0500990static int do_bootm_netbsd (int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100991 bootm_headers_t *images)
wdenk92bbe3f2003-04-20 14:04:18 +0000992{
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100993 void (*loader)(bd_t *, image_header_t *, char *, char *);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100994 image_header_t *os_hdr, *hdr;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100995 ulong kernel_data, kernel_len;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100996 char *consdev;
997 char *cmdline;
wdenk47d1a6e2002-11-03 00:01:44 +0000998
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100999#if defined(CONFIG_FIT)
1000 if (!images->legacy_hdr_valid) {
1001 fit_unsupported_reset ("NetBSD");
Kumar Gala48626aa2008-08-15 08:24:45 -05001002 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001003 }
1004#endif
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001005 hdr = images->legacy_hdr_os;
wdenk47d1a6e2002-11-03 00:01:44 +00001006
1007 /*
1008 * Booting a (NetBSD) kernel image
1009 *
1010 * This process is pretty similar to a standalone application:
1011 * The (first part of an multi-) image must be a stage-2 loader,
1012 * which in turn is responsible for loading & invoking the actual
1013 * kernel. The only differences are the parameters being passed:
1014 * besides the board info strucure, the loader expects a command
1015 * line, the name of the console device, and (optionally) the
1016 * address of the original image header.
1017 */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001018 os_hdr = NULL;
Marian Balakowiczab00e022008-04-11 11:07:49 +02001019 if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
Marian Balakowiczb4a12a92008-01-08 18:12:17 +01001020 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
1021 if (kernel_len)
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001022 os_hdr = hdr;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +01001023 }
wdenk47d1a6e2002-11-03 00:01:44 +00001024
1025 consdev = "";
1026#if defined (CONFIG_8xx_CONS_SMC1)
1027 consdev = "smc1";
1028#elif defined (CONFIG_8xx_CONS_SMC2)
1029 consdev = "smc2";
1030#elif defined (CONFIG_8xx_CONS_SCC2)
1031 consdev = "scc2";
1032#elif defined (CONFIG_8xx_CONS_SCC3)
1033 consdev = "scc3";
1034#endif
1035
1036 if (argc > 2) {
1037 ulong len;
1038 int i;
1039
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001040 for (i = 2, len = 0; i < argc; i += 1)
wdenk47d1a6e2002-11-03 00:01:44 +00001041 len += strlen (argv[i]) + 1;
1042 cmdline = malloc (len);
1043
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001044 for (i = 2, len = 0; i < argc; i += 1) {
wdenk47d1a6e2002-11-03 00:01:44 +00001045 if (i > 2)
1046 cmdline[len++] = ' ';
1047 strcpy (&cmdline[len], argv[i]);
1048 len += strlen (argv[i]);
1049 }
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001050 } else if ((cmdline = getenv ("bootargs")) == NULL) {
wdenk47d1a6e2002-11-03 00:01:44 +00001051 cmdline = "";
1052 }
1053
Kumar Gala93467bc2008-08-15 08:24:36 -05001054 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
wdenk47d1a6e2002-11-03 00:01:44 +00001055
1056 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
1057 (ulong)loader);
1058
1059 show_boot_progress (15);
1060
1061 /*
1062 * NetBSD Stage-2 Loader Parameters:
1063 * r3: ptr to board info data
1064 * r4: image address
1065 * r5: console device
1066 * r6: boot args string
1067 */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001068 (*loader) (gd->bd, os_hdr, consdev, cmdline);
Kumar Gala48626aa2008-08-15 08:24:45 -05001069
1070 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001071}
1072
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001073#ifdef CONFIG_LYNXKDI
Kumar Gala48626aa2008-08-15 08:24:45 -05001074static int do_bootm_lynxkdi (int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001075 bootm_headers_t *images)
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001076{
Marian Balakowiczab00e022008-04-11 11:07:49 +02001077 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001078
1079#if defined(CONFIG_FIT)
1080 if (!images->legacy_hdr_valid) {
1081 fit_unsupported_reset ("Lynx");
Kumar Gala48626aa2008-08-15 08:24:45 -05001082 return 1;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001083 }
1084#endif
1085
1086 lynxkdi_boot ((image_header_t *)hdr);
Kumar Gala48626aa2008-08-15 08:24:45 -05001087
1088 return 1;
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001089}
1090#endif /* CONFIG_LYNXKDI */
1091
Kumar Gala48626aa2008-08-15 08:24:45 -05001092static int do_bootm_rtems (int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001093 bootm_headers_t *images)
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001094{
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001095 void (*entry_point)(bd_t *);
wdenk92bbe3f2003-04-20 14:04:18 +00001096
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001097#if defined(CONFIG_FIT)
1098 if (!images->legacy_hdr_valid) {
1099 fit_unsupported_reset ("RTEMS");
Kumar Gala48626aa2008-08-15 08:24:45 -05001100 return 1;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001101 }
1102#endif
1103
Kumar Gala93467bc2008-08-15 08:24:36 -05001104 entry_point = (void (*)(bd_t *))images->ep;
wdenk47d1a6e2002-11-03 00:01:44 +00001105
wdenk92bbe3f2003-04-20 14:04:18 +00001106 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1107 (ulong)entry_point);
wdenk47d1a6e2002-11-03 00:01:44 +00001108
Heiko Schocher8a8ec532007-07-13 09:54:17 +02001109 show_boot_progress (15);
wdenk92bbe3f2003-04-20 14:04:18 +00001110
1111 /*
1112 * RTEMS Parameters:
1113 * r3: ptr to board info data
1114 */
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001115 (*entry_point)(gd->bd);
Kumar Gala48626aa2008-08-15 08:24:45 -05001116
1117 return 1;
wdenk92bbe3f2003-04-20 14:04:18 +00001118}
1119
Jon Loeliger54324d02007-07-08 17:51:39 -05001120#if defined(CONFIG_CMD_ELF)
Kumar Gala48626aa2008-08-15 08:24:45 -05001121static int do_bootm_vxworks (int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001122 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001123{
wdenk47d1a6e2002-11-03 00:01:44 +00001124 char str[80];
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001125
1126#if defined(CONFIG_FIT)
Marian Balakowiczab00e022008-04-11 11:07:49 +02001127 if (!images->legacy_hdr_valid) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001128 fit_unsupported_reset ("VxWorks");
Kumar Gala48626aa2008-08-15 08:24:45 -05001129 return 1;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001130 }
1131#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001132
Kumar Gala93467bc2008-08-15 08:24:36 -05001133 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001134 setenv("loadaddr", str);
Kumar Gala48626aa2008-08-15 08:24:45 -05001135 do_bootvx(NULL, 0, 0, NULL);
1136
1137 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001138}
1139
Kumar Gala48626aa2008-08-15 08:24:45 -05001140static int do_bootm_qnxelf(int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001141 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001142{
wdenk47d1a6e2002-11-03 00:01:44 +00001143 char *local_args[2];
1144 char str[16];
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001145
1146#if defined(CONFIG_FIT)
1147 if (!images->legacy_hdr_valid) {
1148 fit_unsupported_reset ("QNX");
Kumar Gala48626aa2008-08-15 08:24:45 -05001149 return 1;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001150 }
1151#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001152
Kumar Gala93467bc2008-08-15 08:24:36 -05001153 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001154 local_args[0] = argv[0];
1155 local_args[1] = str; /* and provide it via the arguments */
Kumar Gala48626aa2008-08-15 08:24:45 -05001156 do_bootelf(NULL, 0, 2, local_args);
1157
1158 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001159}
Jon Loeligerd704d912007-07-10 11:02:44 -05001160#endif
Peter Tyser56b8dd12008-09-08 14:56:49 -05001161
1162#ifdef CONFIG_INTEGRITY
1163static int do_bootm_integrity (int flag, int argc, char *argv[],
1164 bootm_headers_t *images)
1165{
1166 void (*entry_point)(void);
1167
1168#if defined(CONFIG_FIT)
1169 if (!images->legacy_hdr_valid) {
1170 fit_unsupported_reset ("INTEGRITY");
1171 return 1;
1172 }
1173#endif
1174
1175 entry_point = (void (*)(void))images->ep;
1176
1177 printf ("## Transferring control to INTEGRITY (at address %08lx) ...\n",
1178 (ulong)entry_point);
1179
1180 show_boot_progress (15);
1181
1182 /*
1183 * INTEGRITY Parameters:
1184 * None
1185 */
1186 (*entry_point)();
1187
1188 return 1;
1189}
1190#endif