blob: 08a014f4484d3035835b937fd7200aa9e1e14140 [file] [log] [blame]
wdenk47d1a6e2002-11-03 00:01:44 +00001/*
Stefan Roese15940c92006-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 Balakowiczb97a2a02008-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>
wdenkc29fdfc2003-08-29 20:57:53 +000034#include <bzlib.h>
wdenk7f70e852003-05-20 14:25:27 +000035#include <environment.h>
Kumar Gala4ed65522008-02-27 21:51:47 -060036#include <lmb.h>
wdenk47d1a6e2002-11-03 00:01:44 +000037#include <asm/byteorder.h>
wdenk8bde7f72003-06-27 21:31:46 +000038
Stefan Roeseebb86c42008-07-30 09:59:51 +020039#if defined(CONFIG_CMD_USB)
Markus Klotzbücher3d71c812008-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 Gala54f9c862008-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 Balakowicz1ee11802008-01-08 18:17:10 +010053DECLARE_GLOBAL_DATA_PTR;
54
55extern 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 */
wdenk47d1a6e2002-11-03 00:01:44 +000058#endif
59
Marian Balakowicz321359f2008-01-08 18:11:43 +010060#ifdef CONFIG_BZIP2
61extern void bz_internal_error(int);
wdenk228f29a2002-12-08 09:53:23 +000062#endif
63
Jon Loeligerbaa26db2007-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
wdenk27b207f2003-07-24 23:38:38 +000067
Jon Loeligerbaa26db2007-07-08 17:51:39 -050068#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +000069#include <flash.h>
Marian Balakowicze6f2e902005-10-11 19:09:42 +020070extern flash_info_t flash_info[]; /* info for FLASH chips */
wdenk27b207f2003-07-24 23:38:38 +000071static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
72#endif
73
Marian Balakowicz1ee11802008-01-08 18:17:10 +010074#ifdef CONFIG_SILENT_CONSOLE
75static void fixup_silent_linux (void);
wdenk2262cfe2002-11-18 00:14:45 +000076#endif
77
Marian Balakowicz6986a382008-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);
81#endif
82
Marian Balakowicz9a4daad2008-02-29 14:58:34 +010083static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +010084 bootm_headers_t *images, ulong *os_data, ulong *os_len);
Marian Balakowicz1ee11802008-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 Gala40d7e992008-08-15 08:24:45 -050095typedef int boot_os_fn (int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +010096 bootm_headers_t *images); /* pointers to os/initrd/fdt */
wdenk47d1a6e2002-11-03 00:01:44 +000097
Marian Balakowicz1ee11802008-01-08 18:17:10 +010098extern boot_os_fn do_bootm_linux;
99static boot_os_fn do_bootm_netbsd;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100100#if defined(CONFIG_LYNXKDI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100101static boot_os_fn do_bootm_lynxkdi;
102extern void lynxkdi_boot (image_header_t *);
wdenk8bde7f72003-06-27 21:31:46 +0000103#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100104static boot_os_fn do_bootm_rtems;
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500105#if defined(CONFIG_CMD_ELF)
Marian Balakowicz1ee11802008-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 Loeliger90253172007-07-10 11:02:44 -0500110#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000111
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100112ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100113static bootm_headers_t images; /* pointers to os/initrd/fdt images */
Stefan Roese15940c92006-03-13 11:16:36 +0100114
Kumar Galae822d7f2008-02-27 21:51:49 -0600115void __board_lmb_reserve(struct lmb *lmb)
116{
117 /* please define platform specific board_lmb_reserve() */
118}
119void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
wdenk47d1a6e2002-11-03 00:01:44 +0000120
Kumar Galac4f94192008-08-15 08:24:37 -0500121#if defined(__ARM__)
122 #define IH_INITRD_ARCH IH_ARCH_ARM
123#elif defined(__avr32__)
124 #define IH_INITRD_ARCH IH_ARCH_AVR32
125#elif defined(__bfin__)
126 #define IH_INITRD_ARCH IH_ARCH_BLACKFIN
127#elif defined(__I386__)
128 #define IH_INITRD_ARCH IH_ARCH_I386
129#elif defined(__M68K__)
130 #define IH_INITRD_ARCH IH_ARCH_M68K
131#elif defined(__microblaze__)
132 #define IH_INITRD_ARCH IH_ARCH_MICROBLAZE
133#elif defined(__mips__)
134 #define IH_INITRD_ARCH IH_ARCH_MIPS
135#elif defined(__nios__)
136 #define IH_INITRD_ARCH IH_ARCH_NIOS
137#elif defined(__nios2__)
138 #define IH_INITRD_ARCH IH_ARCH_NIOS2
139#elif defined(__PPC__)
140 #define IH_INITRD_ARCH IH_ARCH_PPC
141#elif defined(__sh__)
142 #define IH_INITRD_ARCH IH_ARCH_SH
143#elif defined(__sparc__)
144 #define IH_INITRD_ARCH IH_ARCH_SPARC
145#else
146# error Unknown CPU type
147#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000148
Kumar Gala396f6352008-08-15 08:24:41 -0500149static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000150{
Becky Bruce391fd932008-06-09 20:37:18 -0500151 ulong mem_start;
152 phys_size_t mem_size;
Kumar Gala396f6352008-08-15 08:24:41 -0500153 void *os_hdr;
Kumar Galac4f94192008-08-15 08:24:37 -0500154 int ret;
wdenk47d1a6e2002-11-03 00:01:44 +0000155
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100156 memset ((void *)&images, 0, sizeof (images));
Bartlomiej Siekaedbed242008-04-18 12:39:23 +0200157 images.verify = getenv_yesno ("verify");
wdenk47d1a6e2002-11-03 00:01:44 +0000158
Kumar Galae906cfa2008-08-15 08:24:40 -0500159 lmb_init(&images.lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000160
Kumar Galad3f2fa02008-02-27 21:51:50 -0600161 mem_start = getenv_bootm_low();
162 mem_size = getenv_bootm_size();
wdenk47d1a6e2002-11-03 00:01:44 +0000163
Kumar Galae906cfa2008-08-15 08:24:40 -0500164 lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
wdenk47d1a6e2002-11-03 00:01:44 +0000165
Kumar Galae906cfa2008-08-15 08:24:40 -0500166 board_lmb_reserve(&images.lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000167
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100168 /* get kernel image header, start address and length */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100169 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
Kumar Gala396f6352008-08-15 08:24:41 -0500170 &images, &images.os.image_start, &images.os.image_len);
171 if (images.os.image_len == 0) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100172 puts ("ERROR: can't get kernel image!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000173 return 1;
174 }
wdenk47d1a6e2002-11-03 00:01:44 +0000175
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100176 /* get image parameters */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100177 switch (genimg_get_format (os_hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100178 case IMAGE_FORMAT_LEGACY:
Kumar Gala396f6352008-08-15 08:24:41 -0500179 images.os.type = image_get_type (os_hdr);
180 images.os.comp = image_get_comp (os_hdr);
181 images.os.os = image_get_os (os_hdr);
Wolfgang Denkbccae902005-10-06 01:50:50 +0200182
Kumar Gala396f6352008-08-15 08:24:41 -0500183 images.os.end = image_get_image_end (os_hdr);
184 images.os.load = image_get_load (os_hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100185 break;
186#if defined(CONFIG_FIT)
187 case IMAGE_FORMAT_FIT:
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100188 if (fit_image_get_type (images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500189 images.fit_noffset_os, &images.os.type)) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100190 puts ("Can't get image type!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100191 show_boot_progress (-109);
wdenk47d1a6e2002-11-03 00:01:44 +0000192 return 1;
193 }
wdenk47d1a6e2002-11-03 00:01:44 +0000194
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100195 if (fit_image_get_comp (images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500196 images.fit_noffset_os, &images.os.comp)) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100197 puts ("Can't get image compression!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100198 show_boot_progress (-110);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100199 return 1;
200 }
wdenk47d1a6e2002-11-03 00:01:44 +0000201
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100202 if (fit_image_get_os (images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500203 images.fit_noffset_os, &images.os.os)) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100204 puts ("Can't get image OS!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100205 show_boot_progress (-111);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100206 return 1;
207 }
wdenk47d1a6e2002-11-03 00:01:44 +0000208
Kumar Gala396f6352008-08-15 08:24:41 -0500209 images.os.end = fit_get_end (images.fit_hdr_os);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100210
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100211 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500212 &images.os.load)) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100213 puts ("Can't get image load address!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100214 show_boot_progress (-112);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100215 return 1;
wdenkb13fb012003-10-30 21:49:38 +0000216 }
217 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100218#endif
219 default:
220 puts ("ERROR: unknown image format type!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000221 return 1;
222 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100223
Kumar Galac160a952008-08-15 08:24:36 -0500224 /* find kernel entry point */
225 if (images.legacy_hdr_valid) {
226 images.ep = image_get_ep (&images.legacy_hdr_os_copy);
227#if defined(CONFIG_FIT)
228 } else if (images.fit_uname_os) {
229 ret = fit_image_get_entry (images.fit_hdr_os,
230 images.fit_noffset_os, &images.ep);
231 if (ret) {
232 puts ("Can't get entry point property!\n");
233 return 1;
234 }
235#endif
236 } else {
237 puts ("Could not find kernel entry point!\n");
238 return 1;
239 }
240
Kumar Gala396f6352008-08-15 08:24:41 -0500241 if (images.os.os == IH_OS_LINUX) {
Kumar Galac4f94192008-08-15 08:24:37 -0500242 /* find ramdisk */
243 ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
244 &images.rd_start, &images.rd_end);
245 if (ret) {
Kumar Galaea86b9e2008-08-29 19:08:29 -0500246 puts ("Ramdisk image is corrupt or invalid\n");
Kumar Galac4f94192008-08-15 08:24:37 -0500247 return 1;
248 }
Kumar Gala06a09912008-08-15 08:24:38 -0500249
250#if defined(CONFIG_OF_LIBFDT)
251 /* find flattened device tree */
252 ret = boot_get_fdt (flag, argc, argv, &images,
253 &images.ft_addr, &images.ft_len);
254 if (ret) {
255 puts ("Could not find a valid device tree\n");
256 return 1;
257 }
Kumar Gala54f9c862008-08-15 08:24:39 -0500258
259 set_working_fdt_addr(images.ft_addr);
Kumar Gala06a09912008-08-15 08:24:38 -0500260#endif
Kumar Galac4f94192008-08-15 08:24:37 -0500261 }
262
Kumar Gala396f6352008-08-15 08:24:41 -0500263 images.os.start = (ulong)os_hdr;
264 images.valid = 1;
265
266 return 0;
267}
268
269#define BOOTM_ERR_RESET -1
270#define BOOTM_ERR_OVERLAP -2
271#define BOOTM_ERR_UNIMPLEMENTED -3
272static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
273{
274 uint8_t comp = os.comp;
275 ulong load = os.load;
276 ulong blob_start = os.start;
277 ulong blob_end = os.end;
278 ulong image_start = os.image_start;
279 ulong image_len = os.image_len;
280 uint unc_len = CFG_BOOTM_LEN;
281
282 const char *type_name = genimg_get_type_name (os.type);
283
284 switch (comp) {
285 case IH_COMP_NONE:
286 if (load == blob_start) {
287 printf (" XIP %s ... ", type_name);
288 } else {
289 printf (" Loading %s ... ", type_name);
290
291 memmove_wd ((void *)load,
292 (void *)image_start, image_len, CHUNKSZ);
293 }
294 *load_end = load + image_len;
295 puts("OK\n");
296 break;
297 case IH_COMP_GZIP:
298 printf (" Uncompressing %s ... ", type_name);
299 if (gunzip ((void *)load, unc_len,
300 (uchar *)image_start, &image_len) != 0) {
301 puts ("GUNZIP: uncompress or overwrite error "
302 "- must RESET board to recover\n");
303 if (boot_progress)
304 show_boot_progress (-6);
305 return BOOTM_ERR_RESET;
306 }
307
308 *load_end = load + image_len;
309 break;
310#ifdef CONFIG_BZIP2
311 case IH_COMP_BZIP2:
312 printf (" Uncompressing %s ... ", type_name);
313 /*
314 * If we've got less than 4 MB of malloc() space,
315 * use slower decompression algorithm which requires
316 * at most 2300 KB of memory.
317 */
318 int i = BZ2_bzBuffToBuffDecompress ((char*)load,
319 &unc_len, (char *)image_start, image_len,
320 CFG_MALLOC_LEN < (4096 * 1024), 0);
321 if (i != BZ_OK) {
322 printf ("BUNZIP2: uncompress or overwrite error %d "
323 "- must RESET board to recover\n", i);
324 if (boot_progress)
325 show_boot_progress (-6);
326 return BOOTM_ERR_RESET;
327 }
328
329 *load_end = load + unc_len;
330 break;
331#endif /* CONFIG_BZIP2 */
332 default:
333 printf ("Unimplemented compression type %d\n", comp);
334 return BOOTM_ERR_UNIMPLEMENTED;
335 }
336 puts ("OK\n");
Wolfgang Denk9863a152008-09-08 22:10:28 +0200337 debug (" kernel loaded at 0x%08lx, end = 0x%8p\n", load, load_end);
Kumar Gala396f6352008-08-15 08:24:41 -0500338 if (boot_progress)
339 show_boot_progress (7);
340
341 if ((load < blob_end) && (*load_end > blob_start)) {
342 debug ("images.os.start = 0x%lX, images.os.end = 0x%lx\n", blob_start, blob_end);
Wolfgang Denk9863a152008-09-08 22:10:28 +0200343 debug ("images.os.load = 0x%lx, load_end = 0x%p\n", load, load_end);
Kumar Gala396f6352008-08-15 08:24:41 -0500344
345 return BOOTM_ERR_OVERLAP;
346 }
347
348 return 0;
349}
350
351/*******************************************************************/
352/* bootm - boot application image from image in memory */
353/*******************************************************************/
354int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
355{
356
357 ulong iflag;
358 ulong load_end = 0;
359 int ret;
360
Anatolij Gustschin8e024942008-08-29 21:04:45 +0200361 if (bootm_start(cmdtp, flag, argc, argv))
362 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000363
364 /*
365 * We have reached the point of no return: we are going to
366 * overwrite all exception vector code, so we cannot easily
367 * recover from any failures any more...
368 */
wdenk47d1a6e2002-11-03 00:01:44 +0000369 iflag = disable_interrupts();
370
Stefan Roeseebb86c42008-07-30 09:59:51 +0200371#if defined(CONFIG_CMD_USB)
Wolfgang Denk699f0512008-07-15 22:22:44 +0200372 /*
373 * turn off USB to prevent the host controller from writing to the
374 * SDRAM while Linux is booting. This could happen (at least for OHCI
375 * controller), because the HCCA (Host Controller Communication Area)
376 * lies within the SDRAM and the host controller writes continously to
377 * this area (as busmaster!). The HccaFrameNumber is for example
378 * updated every 1 ms within the HCCA structure in SDRAM! For more
379 * details see the OpenHCI specification.
380 */
Markus Klotzbücher3d71c812008-07-10 14:47:09 +0200381 usb_stop();
382#endif
383
wdenkc7de8292002-11-19 11:04:11 +0000384#ifdef CONFIG_AMIGAONEG3SE
385 /*
wdenk8bde7f72003-06-27 21:31:46 +0000386 * We've possible left the caches enabled during
wdenkc7de8292002-11-19 11:04:11 +0000387 * bios emulation, so turn them off again
388 */
389 icache_disable();
wdenkc7de8292002-11-19 11:04:11 +0000390 dcache_disable();
391#endif
392
Kumar Gala396f6352008-08-15 08:24:41 -0500393 ret = bootm_load_os(images.os, &load_end, 1);
wdenk47d1a6e2002-11-03 00:01:44 +0000394
Kumar Gala396f6352008-08-15 08:24:41 -0500395 if (ret < 0) {
396 if (ret == BOOTM_ERR_RESET)
wdenk47d1a6e2002-11-03 00:01:44 +0000397 do_reset (cmdtp, flag, argc, argv);
Kumar Gala396f6352008-08-15 08:24:41 -0500398 if (ret == BOOTM_ERR_OVERLAP) {
399 if (images.legacy_hdr_valid) {
400 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
401 puts ("WARNING: legacy format multi component "
402 "image overwritten\n");
403 } else {
404 puts ("ERROR: new format image overwritten - "
405 "must RESET the board to recover\n");
406 show_boot_progress (-113);
407 do_reset (cmdtp, flag, argc, argv);
408 }
wdenk47d1a6e2002-11-03 00:01:44 +0000409 }
Kumar Gala396f6352008-08-15 08:24:41 -0500410 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
411 if (iflag)
412 enable_interrupts();
413 show_boot_progress (-7);
414 return 1;
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200415 }
wdenk47d1a6e2002-11-03 00:01:44 +0000416 }
Marian Balakowicz75824382008-01-31 13:20:06 +0100417
Kumar Gala396f6352008-08-15 08:24:41 -0500418 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
419
Heiko Schocherfad63402007-07-13 09:54:17 +0200420 show_boot_progress (8);
wdenk47d1a6e2002-11-03 00:01:44 +0000421
Kumar Gala396f6352008-08-15 08:24:41 -0500422 switch (images.os.os) {
wdenk47d1a6e2002-11-03 00:01:44 +0000423 default: /* handled by (original) Linux case */
424 case IH_OS_LINUX:
wdenkf72da342003-10-10 10:05:42 +0000425#ifdef CONFIG_SILENT_CONSOLE
426 fixup_silent_linux();
427#endif
Kumar Gala40d7e992008-08-15 08:24:45 -0500428 do_bootm_linux (0, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000429 break;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100430
wdenk47d1a6e2002-11-03 00:01:44 +0000431 case IH_OS_NETBSD:
Kumar Gala40d7e992008-08-15 08:24:45 -0500432 do_bootm_netbsd (0, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000433 break;
wdenk8bde7f72003-06-27 21:31:46 +0000434
wdenk1f4bb372003-07-27 00:21:01 +0000435#ifdef CONFIG_LYNXKDI
436 case IH_OS_LYNXOS:
Kumar Gala40d7e992008-08-15 08:24:45 -0500437 do_bootm_lynxkdi (0, argc, argv, &images);
wdenk1f4bb372003-07-27 00:21:01 +0000438 break;
439#endif
440
wdenkd791b1d2003-04-20 14:04:18 +0000441 case IH_OS_RTEMS:
Kumar Gala40d7e992008-08-15 08:24:45 -0500442 do_bootm_rtems (0, argc, argv, &images);
wdenkd791b1d2003-04-20 14:04:18 +0000443 break;
wdenk8bde7f72003-06-27 21:31:46 +0000444
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500445#if defined(CONFIG_CMD_ELF)
wdenk47d1a6e2002-11-03 00:01:44 +0000446 case IH_OS_VXWORKS:
Kumar Gala40d7e992008-08-15 08:24:45 -0500447 do_bootm_vxworks (0, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000448 break;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100449
wdenk47d1a6e2002-11-03 00:01:44 +0000450 case IH_OS_QNX:
Kumar Gala40d7e992008-08-15 08:24:45 -0500451 do_bootm_qnxelf (0, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000452 break;
Jon Loeliger90253172007-07-10 11:02:44 -0500453#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100454
wdenk47d1a6e2002-11-03 00:01:44 +0000455 }
456
Heiko Schocherfad63402007-07-13 09:54:17 +0200457 show_boot_progress (-9);
wdenk47d1a6e2002-11-03 00:01:44 +0000458#ifdef DEBUG
wdenk4b9206e2004-03-23 22:14:11 +0000459 puts ("\n## Control returned to monitor - resetting...\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000460#endif
Kumar Gala40d7e992008-08-15 08:24:45 -0500461 do_reset (cmdtp, flag, argc, argv);
Marian Balakowicza44a2692008-03-12 10:14:57 +0100462
wdenk47d1a6e2002-11-03 00:01:44 +0000463 return 1;
464}
465
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100466/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100467 * image_get_kernel - verify legacy format kernel image
468 * @img_addr: in RAM address of the legacy format image to be verified
469 * @verify: data CRC verification flag
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100470 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100471 * image_get_kernel() verifies legacy image integrity and returns pointer to
472 * legacy image header if image verification was completed successfully.
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100473 *
474 * returns:
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100475 * pointer to a legacy image header if valid image was found
476 * otherwise return NULL
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100477 */
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100478static image_header_t *image_get_kernel (ulong img_addr, int verify)
479{
480 image_header_t *hdr = (image_header_t *)img_addr;
481
482 if (!image_check_magic(hdr)) {
483 puts ("Bad Magic Number\n");
484 show_boot_progress (-1);
485 return NULL;
486 }
487 show_boot_progress (2);
488
489 if (!image_check_hcrc (hdr)) {
490 puts ("Bad Header Checksum\n");
491 show_boot_progress (-2);
492 return NULL;
493 }
494
495 show_boot_progress (3);
496 image_print_contents (hdr);
497
498 if (verify) {
499 puts (" Verifying Checksum ... ");
500 if (!image_check_dcrc (hdr)) {
501 printf ("Bad Data CRC\n");
502 show_boot_progress (-3);
503 return NULL;
504 }
505 puts ("OK\n");
506 }
507 show_boot_progress (4);
508
509 if (!image_check_target_arch (hdr)) {
510 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
511 show_boot_progress (-4);
512 return NULL;
513 }
514 return hdr;
515}
516
517/**
Marian Balakowicz6986a382008-03-12 10:01:05 +0100518 * fit_check_kernel - verify FIT format kernel subimage
519 * @fit_hdr: pointer to the FIT image header
520 * os_noffset: kernel subimage node offset within FIT image
521 * @verify: data CRC verification flag
522 *
523 * fit_check_kernel() verifies integrity of the kernel subimage and from
524 * specified FIT image.
525 *
526 * returns:
527 * 1, on success
528 * 0, on failure
529 */
530#if defined (CONFIG_FIT)
531static int fit_check_kernel (const void *fit, int os_noffset, int verify)
532{
533 fit_image_print (fit, os_noffset, " ");
534
535 if (verify) {
536 puts (" Verifying Hash Integrity ... ");
537 if (!fit_image_check_hashes (fit, os_noffset)) {
538 puts ("Bad Data Hash\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100539 show_boot_progress (-104);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100540 return 0;
541 }
542 puts ("OK\n");
543 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100544 show_boot_progress (105);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100545
546 if (!fit_image_check_target_arch (fit, os_noffset)) {
547 puts ("Unsupported Architecture\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100548 show_boot_progress (-105);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100549 return 0;
550 }
551
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100552 show_boot_progress (106);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100553 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
554 puts ("Not a kernel image\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100555 show_boot_progress (-106);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100556 return 0;
557 }
558
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100559 show_boot_progress (107);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100560 return 1;
561}
562#endif /* CONFIG_FIT */
563
564/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100565 * boot_get_kernel - find kernel image
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100566 * @os_data: pointer to a ulong variable, will hold os data start address
567 * @os_len: pointer to a ulong variable, will hold os data length
568 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100569 * boot_get_kernel() tries to find a kernel image, verifies its integrity
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100570 * and locates kernel data.
571 *
572 * returns:
573 * pointer to image header if valid image was found, plus kernel start
574 * address and length, otherwise NULL
575 */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100576static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100577 bootm_headers_t *images, ulong *os_data, ulong *os_len)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100578{
579 image_header_t *hdr;
580 ulong img_addr;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100581#if defined(CONFIG_FIT)
582 void *fit_hdr;
583 const char *fit_uname_config = NULL;
584 const char *fit_uname_kernel = NULL;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100585 const void *data;
586 size_t len;
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100587 int cfg_noffset;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100588 int os_noffset;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100589#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100590
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100591 /* find out kernel image address */
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100592 if (argc < 2) {
593 img_addr = load_addr;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100594 debug ("* kernel: default image load address = 0x%08lx\n",
595 load_addr);
596#if defined(CONFIG_FIT)
597 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
598 &fit_uname_config)) {
599 debug ("* kernel: config '%s' from image at 0x%08lx\n",
600 fit_uname_config, img_addr);
601 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
602 &fit_uname_kernel)) {
603 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
604 fit_uname_kernel, img_addr);
605#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100606 } else {
607 img_addr = simple_strtoul(argv[1], NULL, 16);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100608 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100609 }
610
611 show_boot_progress (1);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100612
Marian Balakowiczfff888a12008-02-21 17:20:19 +0100613 /* copy from dataflash if needed */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100614 img_addr = genimg_get_image (img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100615
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100616 /* check image type, for FIT images get FIT kernel node */
Marian Balakowicz6986a382008-03-12 10:01:05 +0100617 *os_data = *os_len = 0;
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100618 switch (genimg_get_format ((void *)img_addr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100619 case IMAGE_FORMAT_LEGACY:
Marian Balakowicz6986a382008-03-12 10:01:05 +0100620 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
621 img_addr);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100622 hdr = image_get_kernel (img_addr, images->verify);
623 if (!hdr)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100624 return NULL;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100625 show_boot_progress (5);
626
Marian Balakowicz6986a382008-03-12 10:01:05 +0100627 /* get os_data and os_len */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100628 switch (image_get_type (hdr)) {
629 case IH_TYPE_KERNEL:
630 *os_data = image_get_data (hdr);
631 *os_len = image_get_data_size (hdr);
632 break;
633 case IH_TYPE_MULTI:
634 image_multi_getimg (hdr, 0, os_data, os_len);
635 break;
636 default:
637 printf ("Wrong Image Type for %s command\n", cmdtp->name);
638 show_boot_progress (-5);
639 return NULL;
640 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100641
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200642 /*
643 * copy image header to allow for image overwrites during kernel
644 * decompression.
645 */
646 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
647
648 /* save pointer to image header */
649 images->legacy_hdr_os = hdr;
650
651 images->legacy_hdr_valid = 1;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100652 show_boot_progress (6);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100653 break;
654#if defined(CONFIG_FIT)
655 case IMAGE_FORMAT_FIT:
656 fit_hdr = (void *)img_addr;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100657 printf ("## Booting kernel from FIT Image at %08lx ...\n",
658 img_addr);
659
660 if (!fit_check_format (fit_hdr)) {
661 puts ("Bad FIT kernel image format!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100662 show_boot_progress (-100);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100663 return NULL;
664 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100665 show_boot_progress (100);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100666
667 if (!fit_uname_kernel) {
668 /*
669 * no kernel image node unit name, try to get config
670 * node first. If config unit node name is NULL
671 * fit_conf_get_node() will try to find default config node
672 */
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100673 show_boot_progress (101);
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100674 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
675 if (cfg_noffset < 0) {
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100676 show_boot_progress (-101);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100677 return NULL;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100678 }
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100679 /* save configuration uname provided in the first
680 * bootm argument
681 */
682 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
683 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
684 show_boot_progress (103);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100685
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100686 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100687 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
688 } else {
689 /* get kernel component image node offset */
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100690 show_boot_progress (102);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100691 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
692 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100693 if (os_noffset < 0) {
694 show_boot_progress (-103);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100695 return NULL;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100696 }
Marian Balakowicz6986a382008-03-12 10:01:05 +0100697
698 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
699
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100700 show_boot_progress (104);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100701 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
702 return NULL;
703
704 /* get kernel image data address and length */
705 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
706 puts ("Could not find kernel subimage data!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100707 show_boot_progress (-107);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100708 return NULL;
709 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100710 show_boot_progress (108);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100711
712 *os_len = len;
713 *os_data = (ulong)data;
714 images->fit_hdr_os = fit_hdr;
715 images->fit_uname_os = fit_uname_kernel;
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100716 images->fit_noffset_os = os_noffset;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100717 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100718#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100719 default:
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100720 printf ("Wrong Image Format for %s command\n", cmdtp->name);
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100721 show_boot_progress (-108);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100722 return NULL;
723 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100724
Wolfgang Denk06c53be2008-07-10 13:16:09 +0200725 debug (" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
Marian Balakowicz6986a382008-03-12 10:01:05 +0100726 *os_data, *os_len, *os_len);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100727
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100728 return (void *)img_addr;
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100729}
730
wdenk0d498392003-07-01 21:06:45 +0000731U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100732 bootm, CFG_MAXARGS, 1, do_bootm,
733 "bootm - boot application image from memory\n",
734 "[addr [arg ...]]\n - boot application image stored in memory\n"
735 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
736 "\t'arg' can be the address of an initrd image\n"
Marian Balakowicz4a2ad5f2008-01-31 13:20:07 +0100737#if defined(CONFIG_OF_LIBFDT)
Matthew McClintock98a9c4d2006-06-28 10:41:37 -0500738 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
Detlev Zundel5441f612007-10-19 16:47:26 +0200739 "\ta third argument is required which is the address of the\n"
Matthew McClintock98a9c4d2006-06-28 10:41:37 -0500740 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
741 "\tuse a '-' for the second argument. If you do not pass a third\n"
742 "\ta bd_info struct will be passed instead\n"
743#endif
Marian Balakowicz6986a382008-03-12 10:01:05 +0100744#if defined(CONFIG_FIT)
745 "\t\nFor the new multi component uImage format (FIT) addresses\n"
746 "\tmust be extened to include component or configuration unit name:\n"
747 "\taddr:<subimg_uname> - direct component image specification\n"
748 "\taddr#<conf_uname> - configuration specification\n"
749 "\tUse iminfo command to get the list of existing component\n"
750 "\timages and configurations.\n"
751#endif
wdenk8bde7f72003-06-27 21:31:46 +0000752);
753
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100754/*******************************************************************/
755/* bootd - boot default image */
756/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500757#if defined(CONFIG_CMD_BOOTD)
wdenk47d1a6e2002-11-03 00:01:44 +0000758int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
759{
760 int rcode = 0;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100761
wdenk47d1a6e2002-11-03 00:01:44 +0000762#ifndef CFG_HUSH_PARSER
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100763 if (run_command (getenv ("bootcmd"), flag) < 0)
764 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000765#else
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100766 if (parse_string_outer (getenv ("bootcmd"),
767 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
768 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000769#endif
770 return rcode;
771}
wdenk8bde7f72003-06-27 21:31:46 +0000772
wdenk0d498392003-07-01 21:06:45 +0000773U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100774 boot, 1, 1, do_bootd,
775 "boot - boot default, i.e., run 'bootcmd'\n",
wdenk9d2b18a2003-06-28 23:11:04 +0000776 NULL
777);
778
779/* keep old command name "bootd" for backward compatibility */
wdenk0d498392003-07-01 21:06:45 +0000780U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100781 bootd, 1, 1, do_bootd,
782 "bootd - boot default, i.e., run 'bootcmd'\n",
wdenk8bde7f72003-06-27 21:31:46 +0000783 NULL
784);
785
wdenk47d1a6e2002-11-03 00:01:44 +0000786#endif
787
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100788
789/*******************************************************************/
790/* iminfo - print header info for a requested image */
791/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500792#if defined(CONFIG_CMD_IMI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100793int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000794{
795 int arg;
796 ulong addr;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100797 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000798
799 if (argc < 2) {
800 return image_info (load_addr);
801 }
802
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100803 for (arg = 1; arg < argc; ++arg) {
804 addr = simple_strtoul (argv[arg], NULL, 16);
805 if (image_info (addr) != 0)
806 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000807 }
808 return rcode;
809}
810
811static int image_info (ulong addr)
812{
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100813 void *hdr = (void *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +0000814
815 printf ("\n## Checking Image at %08lx ...\n", addr);
816
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100817 switch (genimg_get_format (hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100818 case IMAGE_FORMAT_LEGACY:
819 puts (" Legacy image found\n");
820 if (!image_check_magic (hdr)) {
821 puts (" Bad Magic Number\n");
822 return 1;
823 }
824
825 if (!image_check_hcrc (hdr)) {
826 puts (" Bad Header Checksum\n");
827 return 1;
828 }
829
830 image_print_contents (hdr);
831
832 puts (" Verifying Checksum ... ");
833 if (!image_check_dcrc (hdr)) {
834 puts (" Bad Data CRC\n");
835 return 1;
836 }
837 puts ("OK\n");
838 return 0;
839#if defined(CONFIG_FIT)
840 case IMAGE_FORMAT_FIT:
841 puts (" FIT image found\n");
Marian Balakowicze32fea62008-03-11 12:35:20 +0100842
843 if (!fit_check_format (hdr)) {
844 puts ("Bad FIT image format!\n");
845 return 1;
846 }
847
848 fit_print_contents (hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100849 return 0;
850#endif
851 default:
852 puts ("Unknown image format!\n");
853 break;
wdenk47d1a6e2002-11-03 00:01:44 +0000854 }
855
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100856 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000857}
wdenk0d498392003-07-01 21:06:45 +0000858
859U_BOOT_CMD(
860 iminfo, CFG_MAXARGS, 1, do_iminfo,
wdenk8bde7f72003-06-27 21:31:46 +0000861 "iminfo - print header information for application image\n",
862 "addr [addr ...]\n"
863 " - print header information for application image starting at\n"
864 " address 'addr' in memory; this includes verification of the\n"
865 " image contents (magic number, header and payload checksums)\n"
866);
Jon Loeliger90253172007-07-10 11:02:44 -0500867#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000868
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100869
870/*******************************************************************/
871/* imls - list all images found in flash */
872/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500873#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +0000874int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
875{
876 flash_info_t *info;
877 int i, j;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100878 void *hdr;
wdenk27b207f2003-07-24 23:38:38 +0000879
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100880 for (i = 0, info = &flash_info[0];
881 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
882
wdenk27b207f2003-07-24 23:38:38 +0000883 if (info->flash_id == FLASH_UNKNOWN)
884 goto next_bank;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100885 for (j = 0; j < info->sector_count; ++j) {
wdenk27b207f2003-07-24 23:38:38 +0000886
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100887 hdr = (void *)info->start[j];
888 if (!hdr)
wdenk27b207f2003-07-24 23:38:38 +0000889 goto next_sector;
890
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100891 switch (genimg_get_format (hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100892 case IMAGE_FORMAT_LEGACY:
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100893 if (!image_check_hcrc (hdr))
894 goto next_sector;
895
896 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
897 image_print_contents (hdr);
898
899 puts (" Verifying Checksum ... ");
900 if (!image_check_dcrc (hdr)) {
901 puts ("Bad Data CRC\n");
902 } else {
903 puts ("OK\n");
904 }
905 break;
906#if defined(CONFIG_FIT)
907 case IMAGE_FORMAT_FIT:
Marian Balakowicze32fea62008-03-11 12:35:20 +0100908 if (!fit_check_format (hdr))
909 goto next_sector;
910
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100911 printf ("FIT Image at %08lX:\n", (ulong)hdr);
Marian Balakowicze32fea62008-03-11 12:35:20 +0100912 fit_print_contents (hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100913 break;
914#endif
915 default:
wdenk27b207f2003-07-24 23:38:38 +0000916 goto next_sector;
wdenk5bb226e2003-11-17 21:14:37 +0000917 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100918
wdenkbdccc4f2003-08-05 17:43:17 +0000919next_sector: ;
wdenk27b207f2003-07-24 23:38:38 +0000920 }
wdenkbdccc4f2003-08-05 17:43:17 +0000921next_bank: ;
wdenk27b207f2003-07-24 23:38:38 +0000922 }
923
924 return (0);
925}
926
927U_BOOT_CMD(
928 imls, 1, 1, do_imls,
929 "imls - list all images found in flash\n",
930 "\n"
931 " - Prints information about all images found at sector\n"
932 " boundaries in flash.\n"
933);
Jon Loeliger90253172007-07-10 11:02:44 -0500934#endif
wdenk27b207f2003-07-24 23:38:38 +0000935
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100936/*******************************************************************/
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100937/* helper routines */
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100938/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +0000939#ifdef CONFIG_SILENT_CONSOLE
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100940static void fixup_silent_linux ()
wdenk47d1a6e2002-11-03 00:01:44 +0000941{
942 char buf[256], *start, *end;
943 char *cmdline = getenv ("bootargs");
944
945 /* Only fix cmdline when requested */
946 if (!(gd->flags & GD_FLG_SILENT))
947 return;
948
949 debug ("before silent fix-up: %s\n", cmdline);
950 if (cmdline) {
951 if ((start = strstr (cmdline, "console=")) != NULL) {
952 end = strchr (start, ' ');
953 strncpy (buf, cmdline, (start - cmdline + 8));
954 if (end)
955 strcpy (buf + (start - cmdline + 8), end);
956 else
957 buf[start - cmdline + 8] = '\0';
958 } else {
959 strcpy (buf, cmdline);
960 strcat (buf, " console=");
961 }
962 } else {
963 strcpy (buf, "console=");
964 }
965
966 setenv ("bootargs", buf);
967 debug ("after silent fix-up: %s\n", buf);
968}
969#endif /* CONFIG_SILENT_CONSOLE */
970
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100971
972/*******************************************************************/
973/* OS booting routines */
974/*******************************************************************/
975
Kumar Gala40d7e992008-08-15 08:24:45 -0500976static int do_bootm_netbsd (int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100977 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +0000978{
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100979 void (*loader)(bd_t *, image_header_t *, char *, char *);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100980 image_header_t *os_hdr, *hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100981 ulong kernel_data, kernel_len;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100982 char *consdev;
983 char *cmdline;
wdenk47d1a6e2002-11-03 00:01:44 +0000984
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100985#if defined(CONFIG_FIT)
986 if (!images->legacy_hdr_valid) {
987 fit_unsupported_reset ("NetBSD");
Kumar Gala40d7e992008-08-15 08:24:45 -0500988 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000989 }
990#endif
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100991 hdr = images->legacy_hdr_os;
wdenk47d1a6e2002-11-03 00:01:44 +0000992
993 /*
994 * Booting a (NetBSD) kernel image
995 *
996 * This process is pretty similar to a standalone application:
997 * The (first part of an multi-) image must be a stage-2 loader,
998 * which in turn is responsible for loading & invoking the actual
999 * kernel. The only differences are the parameters being passed:
1000 * besides the board info strucure, the loader expects a command
1001 * line, the name of the console device, and (optionally) the
1002 * address of the original image header.
1003 */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001004 os_hdr = NULL;
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001005 if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001006 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
1007 if (kernel_len)
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001008 os_hdr = hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001009 }
wdenk47d1a6e2002-11-03 00:01:44 +00001010
1011 consdev = "";
1012#if defined (CONFIG_8xx_CONS_SMC1)
1013 consdev = "smc1";
1014#elif defined (CONFIG_8xx_CONS_SMC2)
1015 consdev = "smc2";
1016#elif defined (CONFIG_8xx_CONS_SCC2)
1017 consdev = "scc2";
1018#elif defined (CONFIG_8xx_CONS_SCC3)
1019 consdev = "scc3";
1020#endif
1021
1022 if (argc > 2) {
1023 ulong len;
1024 int i;
1025
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001026 for (i = 2, len = 0; i < argc; i += 1)
wdenk47d1a6e2002-11-03 00:01:44 +00001027 len += strlen (argv[i]) + 1;
1028 cmdline = malloc (len);
1029
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001030 for (i = 2, len = 0; i < argc; i += 1) {
wdenk47d1a6e2002-11-03 00:01:44 +00001031 if (i > 2)
1032 cmdline[len++] = ' ';
1033 strcpy (&cmdline[len], argv[i]);
1034 len += strlen (argv[i]);
1035 }
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001036 } else if ((cmdline = getenv ("bootargs")) == NULL) {
wdenk47d1a6e2002-11-03 00:01:44 +00001037 cmdline = "";
1038 }
1039
Kumar Galac160a952008-08-15 08:24:36 -05001040 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
wdenk47d1a6e2002-11-03 00:01:44 +00001041
1042 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
1043 (ulong)loader);
1044
1045 show_boot_progress (15);
1046
1047 /*
1048 * NetBSD Stage-2 Loader Parameters:
1049 * r3: ptr to board info data
1050 * r4: image address
1051 * r5: console device
1052 * r6: boot args string
1053 */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001054 (*loader) (gd->bd, os_hdr, consdev, cmdline);
Kumar Gala40d7e992008-08-15 08:24:45 -05001055
1056 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001057}
1058
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001059#ifdef CONFIG_LYNXKDI
Kumar Gala40d7e992008-08-15 08:24:45 -05001060static int do_bootm_lynxkdi (int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001061 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001062{
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001063 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001064
1065#if defined(CONFIG_FIT)
1066 if (!images->legacy_hdr_valid) {
1067 fit_unsupported_reset ("Lynx");
Kumar Gala40d7e992008-08-15 08:24:45 -05001068 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001069 }
1070#endif
1071
1072 lynxkdi_boot ((image_header_t *)hdr);
Kumar Gala40d7e992008-08-15 08:24:45 -05001073
1074 return 1;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001075}
1076#endif /* CONFIG_LYNXKDI */
1077
Kumar Gala40d7e992008-08-15 08:24:45 -05001078static int do_bootm_rtems (int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001079 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001080{
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001081 void (*entry_point)(bd_t *);
wdenkd791b1d2003-04-20 14:04:18 +00001082
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001083#if defined(CONFIG_FIT)
1084 if (!images->legacy_hdr_valid) {
1085 fit_unsupported_reset ("RTEMS");
Kumar Gala40d7e992008-08-15 08:24:45 -05001086 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001087 }
1088#endif
1089
Kumar Galac160a952008-08-15 08:24:36 -05001090 entry_point = (void (*)(bd_t *))images->ep;
wdenkd791b1d2003-04-20 14:04:18 +00001091
1092 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1093 (ulong)entry_point);
1094
Heiko Schocherfad63402007-07-13 09:54:17 +02001095 show_boot_progress (15);
wdenkd791b1d2003-04-20 14:04:18 +00001096
1097 /*
1098 * RTEMS Parameters:
1099 * r3: ptr to board info data
1100 */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001101 (*entry_point)(gd->bd);
Kumar Gala40d7e992008-08-15 08:24:45 -05001102
1103 return 1;
wdenkd791b1d2003-04-20 14:04:18 +00001104}
1105
Jon Loeligerbaa26db2007-07-08 17:51:39 -05001106#if defined(CONFIG_CMD_ELF)
Kumar Gala40d7e992008-08-15 08:24:45 -05001107static int do_bootm_vxworks (int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001108 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001109{
wdenk47d1a6e2002-11-03 00:01:44 +00001110 char str[80];
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001111
1112#if defined(CONFIG_FIT)
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001113 if (!images->legacy_hdr_valid) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001114 fit_unsupported_reset ("VxWorks");
Kumar Gala40d7e992008-08-15 08:24:45 -05001115 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001116 }
1117#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001118
Kumar Galac160a952008-08-15 08:24:36 -05001119 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001120 setenv("loadaddr", str);
Kumar Gala40d7e992008-08-15 08:24:45 -05001121 do_bootvx(NULL, 0, 0, NULL);
1122
1123 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001124}
1125
Kumar Gala40d7e992008-08-15 08:24:45 -05001126static int do_bootm_qnxelf(int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001127 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001128{
wdenk47d1a6e2002-11-03 00:01:44 +00001129 char *local_args[2];
1130 char str[16];
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001131
1132#if defined(CONFIG_FIT)
1133 if (!images->legacy_hdr_valid) {
1134 fit_unsupported_reset ("QNX");
Kumar Gala40d7e992008-08-15 08:24:45 -05001135 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001136 }
1137#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001138
Kumar Galac160a952008-08-15 08:24:36 -05001139 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001140 local_args[0] = argv[0];
1141 local_args[1] = str; /* and provide it via the arguments */
Kumar Gala40d7e992008-08-15 08:24:45 -05001142 do_bootelf(NULL, 0, 2, local_args);
1143
1144 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001145}
Jon Loeliger90253172007-07-10 11:02:44 -05001146#endif