blob: 897e9f6f4040e509233a0cc6dacc2f9c038b031c [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
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +020053#ifdef CONFIG_LZMA
54#define _7ZIP_BYTE_DEFINED /* Byte already defined by zlib */
55#include <lzma/LzmaTypes.h>
56#include <lzma/LzmaDecode.h>
57#include <lzma/LzmaTools.h>
58#endif /* CONFIG_LZMA */
59
Marian Balakowicz2df645e2008-01-08 18:17:10 +010060DECLARE_GLOBAL_DATA_PTR;
wdenk9dfa8d12002-12-08 09:53:23 +000061
Marian Balakowicz2df645e2008-01-08 18:17:10 +010062extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
63#ifndef CFG_BOOTM_LEN
64#define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
wdenk381669a2003-06-16 23:50:08 +000065#endif
66
Marian Balakowiczbe946ba2008-01-08 18:11:43 +010067#ifdef CONFIG_BZIP2
68extern void bz_internal_error(int);
wdenk47d1a6e2002-11-03 00:01:44 +000069#endif
70
Jon Loeliger54324d02007-07-08 17:51:39 -050071#if defined(CONFIG_CMD_IMI)
wdenk47d1a6e2002-11-03 00:01:44 +000072static int image_info (unsigned long addr);
73#endif
wdenk874ac262003-07-24 23:38:38 +000074
Jon Loeliger54324d02007-07-08 17:51:39 -050075#if defined(CONFIG_CMD_IMLS)
wdenk874ac262003-07-24 23:38:38 +000076#include <flash.h>
Marian Balakowicz513b4a12005-10-11 19:09:42 +020077extern flash_info_t flash_info[]; /* info for FLASH chips */
wdenk874ac262003-07-24 23:38:38 +000078static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
79#endif
80
Marian Balakowicz2df645e2008-01-08 18:17:10 +010081#ifdef CONFIG_SILENT_CONSOLE
82static void fixup_silent_linux (void);
83#endif
wdenk47d1a6e2002-11-03 00:01:44 +000084
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +010085static image_header_t *image_get_kernel (ulong img_addr, int verify);
86#if defined(CONFIG_FIT)
87static int fit_check_kernel (const void *fit, int os_noffset, int verify);
wdenk591dda52002-11-18 00:14:45 +000088#endif
89
Marian Balakowiczd7c88a42008-02-29 14:58:34 +010090static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +010091 bootm_headers_t *images, ulong *os_data, ulong *os_len);
Marian Balakowicz2df645e2008-01-08 18:17:10 +010092extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
wdenk47d1a6e2002-11-03 00:01:44 +000093
wdenk47d1a6e2002-11-03 00:01:44 +000094/*
95 * Continue booting an OS image; caller already has:
96 * - copied image header to global variable `header'
97 * - checked header magic number, checksums (both header & image),
98 * - verified image architecture (PPC) and type (KERNEL or MULTI),
99 * - loaded (first part of) image to header load address,
100 * - disabled interrupts.
101 */
Kumar Gala48626aa2008-08-15 08:24:45 -0500102typedef int boot_os_fn (int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100103 bootm_headers_t *images); /* pointers to os/initrd/fdt */
wdenk47d1a6e2002-11-03 00:01:44 +0000104
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100105extern boot_os_fn do_bootm_linux;
106static boot_os_fn do_bootm_netbsd;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100107#if defined(CONFIG_LYNXKDI)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100108static boot_os_fn do_bootm_lynxkdi;
109extern void lynxkdi_boot (image_header_t *);
wdenk47d1a6e2002-11-03 00:01:44 +0000110#endif
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100111static boot_os_fn do_bootm_rtems;
Jon Loeliger54324d02007-07-08 17:51:39 -0500112#if defined(CONFIG_CMD_ELF)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100113static boot_os_fn do_bootm_vxworks;
114static boot_os_fn do_bootm_qnxelf;
115int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
116int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
Jon Loeligerd704d912007-07-10 11:02:44 -0500117#endif
Peter Tyser56b8dd12008-09-08 14:56:49 -0500118#if defined(CONFIG_INTEGRITY)
119static boot_os_fn do_bootm_integrity;
120#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000121
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100122ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100123static bootm_headers_t images; /* pointers to os/initrd/fdt images */
Stefan Roese5d5ce292006-03-13 11:16:36 +0100124
Kumar Galab937bb72008-02-27 21:51:49 -0600125void __board_lmb_reserve(struct lmb *lmb)
126{
127 /* please define platform specific board_lmb_reserve() */
128}
129void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
wdenk47d1a6e2002-11-03 00:01:44 +0000130
Kumar Galafffb1432008-08-15 08:24:37 -0500131#if defined(__ARM__)
132 #define IH_INITRD_ARCH IH_ARCH_ARM
133#elif defined(__avr32__)
134 #define IH_INITRD_ARCH IH_ARCH_AVR32
135#elif defined(__bfin__)
136 #define IH_INITRD_ARCH IH_ARCH_BLACKFIN
137#elif defined(__I386__)
138 #define IH_INITRD_ARCH IH_ARCH_I386
139#elif defined(__M68K__)
140 #define IH_INITRD_ARCH IH_ARCH_M68K
141#elif defined(__microblaze__)
142 #define IH_INITRD_ARCH IH_ARCH_MICROBLAZE
143#elif defined(__mips__)
144 #define IH_INITRD_ARCH IH_ARCH_MIPS
145#elif defined(__nios__)
146 #define IH_INITRD_ARCH IH_ARCH_NIOS
147#elif defined(__nios2__)
148 #define IH_INITRD_ARCH IH_ARCH_NIOS2
149#elif defined(__PPC__)
150 #define IH_INITRD_ARCH IH_ARCH_PPC
151#elif defined(__sh__)
152 #define IH_INITRD_ARCH IH_ARCH_SH
153#elif defined(__sparc__)
154 #define IH_INITRD_ARCH IH_ARCH_SPARC
155#else
156# error Unknown CPU type
157#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000158
Kumar Galabd70bbe2008-08-15 08:24:41 -0500159static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000160{
Becky Bruced26d67c2008-06-09 20:37:18 -0500161 ulong mem_start;
162 phys_size_t mem_size;
Kumar Galabd70bbe2008-08-15 08:24:41 -0500163 void *os_hdr;
Kumar Galafffb1432008-08-15 08:24:37 -0500164 int ret;
wdenk47d1a6e2002-11-03 00:01:44 +0000165
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100166 memset ((void *)&images, 0, sizeof (images));
Bartlomiej Sieka47868592008-04-18 12:39:23 +0200167 images.verify = getenv_yesno ("verify");
wdenk47d1a6e2002-11-03 00:01:44 +0000168
Kumar Galada6d11e2008-08-15 08:24:40 -0500169 lmb_init(&images.lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000170
Kumar Galac5bacfd2008-02-27 21:51:50 -0600171 mem_start = getenv_bootm_low();
172 mem_size = getenv_bootm_size();
wdenk47d1a6e2002-11-03 00:01:44 +0000173
Kumar Galada6d11e2008-08-15 08:24:40 -0500174 lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
wdenk47d1a6e2002-11-03 00:01:44 +0000175
Kumar Galada6d11e2008-08-15 08:24:40 -0500176 board_lmb_reserve(&images.lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000177
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100178 /* get kernel image header, start address and length */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100179 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500180 &images, &images.os.image_start, &images.os.image_len);
181 if (images.os.image_len == 0) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100182 puts ("ERROR: can't get kernel image!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000183 return 1;
184 }
Wolfgang Denk63e44ff2005-10-06 01:50:50 +0200185
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100186 /* get image parameters */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100187 switch (genimg_get_format (os_hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100188 case IMAGE_FORMAT_LEGACY:
Kumar Galabd70bbe2008-08-15 08:24:41 -0500189 images.os.type = image_get_type (os_hdr);
190 images.os.comp = image_get_comp (os_hdr);
191 images.os.os = image_get_os (os_hdr);
Wolfgang Denk63e44ff2005-10-06 01:50:50 +0200192
Kumar Galabd70bbe2008-08-15 08:24:41 -0500193 images.os.end = image_get_image_end (os_hdr);
194 images.os.load = image_get_load (os_hdr);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100195 break;
196#if defined(CONFIG_FIT)
197 case IMAGE_FORMAT_FIT:
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100198 if (fit_image_get_type (images.fit_hdr_os,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500199 images.fit_noffset_os, &images.os.type)) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100200 puts ("Can't get image type!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100201 show_boot_progress (-109);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100202 return 1;
203 }
wdenk47d1a6e2002-11-03 00:01:44 +0000204
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100205 if (fit_image_get_comp (images.fit_hdr_os,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500206 images.fit_noffset_os, &images.os.comp)) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100207 puts ("Can't get image compression!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100208 show_boot_progress (-110);
wdenk47d1a6e2002-11-03 00:01:44 +0000209 return 1;
210 }
wdenk47d1a6e2002-11-03 00:01:44 +0000211
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100212 if (fit_image_get_os (images.fit_hdr_os,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500213 images.fit_noffset_os, &images.os.os)) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100214 puts ("Can't get image OS!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100215 show_boot_progress (-111);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100216 return 1;
217 }
wdenk47d1a6e2002-11-03 00:01:44 +0000218
Kumar Galabd70bbe2008-08-15 08:24:41 -0500219 images.os.end = fit_get_end (images.fit_hdr_os);
wdenk47d1a6e2002-11-03 00:01:44 +0000220
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100221 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500222 &images.os.load)) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100223 puts ("Can't get image load address!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100224 show_boot_progress (-112);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100225 return 1;
wdenk655a0f92003-10-30 21:49:38 +0000226 }
227 break;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100228#endif
229 default:
230 puts ("ERROR: unknown image format type!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000231 return 1;
232 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100233
Kumar Gala93467bc2008-08-15 08:24:36 -0500234 /* find kernel entry point */
235 if (images.legacy_hdr_valid) {
236 images.ep = image_get_ep (&images.legacy_hdr_os_copy);
237#if defined(CONFIG_FIT)
238 } else if (images.fit_uname_os) {
239 ret = fit_image_get_entry (images.fit_hdr_os,
240 images.fit_noffset_os, &images.ep);
241 if (ret) {
242 puts ("Can't get entry point property!\n");
243 return 1;
244 }
245#endif
246 } else {
247 puts ("Could not find kernel entry point!\n");
248 return 1;
249 }
250
Kumar Galabd70bbe2008-08-15 08:24:41 -0500251 if (images.os.os == IH_OS_LINUX) {
Kumar Galafffb1432008-08-15 08:24:37 -0500252 /* find ramdisk */
253 ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
254 &images.rd_start, &images.rd_end);
255 if (ret) {
Kumar Galab8ca7342008-08-29 19:08:29 -0500256 puts ("Ramdisk image is corrupt or invalid\n");
Kumar Galafffb1432008-08-15 08:24:37 -0500257 return 1;
258 }
Kumar Galaa5130ad2008-08-15 08:24:38 -0500259
260#if defined(CONFIG_OF_LIBFDT)
Jean-Christophe PLAGNIOL-VILLARDa936b892008-09-09 22:18:23 +0200261#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
Kumar Galaa5130ad2008-08-15 08:24:38 -0500262 /* find flattened device tree */
263 ret = boot_get_fdt (flag, argc, argv, &images,
264 &images.ft_addr, &images.ft_len);
265 if (ret) {
266 puts ("Could not find a valid device tree\n");
267 return 1;
268 }
Kumar Gala9f4e7e42008-08-15 08:24:39 -0500269
270 set_working_fdt_addr(images.ft_addr);
Kumar Galaa5130ad2008-08-15 08:24:38 -0500271#endif
Jean-Christophe PLAGNIOL-VILLARDa936b892008-09-09 22:18:23 +0200272#endif
Kumar Galafffb1432008-08-15 08:24:37 -0500273 }
274
Kumar Galabd70bbe2008-08-15 08:24:41 -0500275 images.os.start = (ulong)os_hdr;
276 images.valid = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000277
Kumar Galabd70bbe2008-08-15 08:24:41 -0500278 return 0;
279}
Markus Klotzbücher09197cb2008-07-10 14:47:09 +0200280
Kumar Galabd70bbe2008-08-15 08:24:41 -0500281#define BOOTM_ERR_RESET -1
282#define BOOTM_ERR_OVERLAP -2
283#define BOOTM_ERR_UNIMPLEMENTED -3
284static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
285{
286 uint8_t comp = os.comp;
287 ulong load = os.load;
288 ulong blob_start = os.start;
289 ulong blob_end = os.end;
290 ulong image_start = os.image_start;
291 ulong image_len = os.image_len;
292 uint unc_len = CFG_BOOTM_LEN;
Markus Klotzbücher09197cb2008-07-10 14:47:09 +0200293
Kumar Galabd70bbe2008-08-15 08:24:41 -0500294 const char *type_name = genimg_get_type_name (os.type);
wdenk452cfd62002-11-19 11:04:11 +0000295
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100296 switch (comp) {
wdenk47d1a6e2002-11-03 00:01:44 +0000297 case IH_COMP_NONE:
Kumar Galabd70bbe2008-08-15 08:24:41 -0500298 if (load == blob_start) {
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100299 printf (" XIP %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000300 } else {
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100301 printf (" Loading %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000302
Kumar Galabd70bbe2008-08-15 08:24:41 -0500303 memmove_wd ((void *)load,
304 (void *)image_start, image_len, CHUNKSZ);
wdenk47d1a6e2002-11-03 00:01:44 +0000305 }
Kumar Galabd70bbe2008-08-15 08:24:41 -0500306 *load_end = load + image_len;
Guennadi Liakhovetski3110cf82008-07-31 12:35:04 +0200307 puts("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000308 break;
309 case IH_COMP_GZIP:
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100310 printf (" Uncompressing %s ... ", type_name);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500311 if (gunzip ((void *)load, unc_len,
312 (uchar *)image_start, &image_len) != 0) {
Marian Balakowiczb5324a82008-03-12 10:33:01 +0100313 puts ("GUNZIP: uncompress or overwrite error "
314 "- must RESET board to recover\n");
Kumar Galabd70bbe2008-08-15 08:24:41 -0500315 if (boot_progress)
316 show_boot_progress (-6);
317 return BOOTM_ERR_RESET;
wdenk47d1a6e2002-11-03 00:01:44 +0000318 }
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100319
Kumar Galabd70bbe2008-08-15 08:24:41 -0500320 *load_end = load + image_len;
wdenk47d1a6e2002-11-03 00:01:44 +0000321 break;
wdenk710e3502003-08-29 20:57:53 +0000322#ifdef CONFIG_BZIP2
323 case IH_COMP_BZIP2:
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100324 printf (" Uncompressing %s ... ", type_name);
wdenk2cefd152004-02-08 22:55:38 +0000325 /*
326 * If we've got less than 4 MB of malloc() space,
327 * use slower decompression algorithm which requires
328 * at most 2300 KB of memory.
329 */
Kumar Galabd70bbe2008-08-15 08:24:41 -0500330 int i = BZ2_bzBuffToBuffDecompress ((char*)load,
331 &unc_len, (char *)image_start, image_len,
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100332 CFG_MALLOC_LEN < (4096 * 1024), 0);
wdenk710e3502003-08-29 20:57:53 +0000333 if (i != BZ_OK) {
Marian Balakowiczb5324a82008-03-12 10:33:01 +0100334 printf ("BUNZIP2: uncompress or overwrite error %d "
335 "- must RESET board to recover\n", i);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500336 if (boot_progress)
337 show_boot_progress (-6);
338 return BOOTM_ERR_RESET;
wdenk710e3502003-08-29 20:57:53 +0000339 }
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100340
Kumar Galabd70bbe2008-08-15 08:24:41 -0500341 *load_end = load + unc_len;
wdenk710e3502003-08-29 20:57:53 +0000342 break;
343#endif /* CONFIG_BZIP2 */
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200344#ifdef CONFIG_LZMA
345 case IH_COMP_LZMA:
346 printf (" Uncompressing %s ... ", type_name);
347
348 int ret = lzmaBuffToBuffDecompress(
349 (unsigned char *)load, &unc_len,
Luigi 'Comio' Mantellini22834672008-09-13 10:04:32 +0200350 (unsigned char *)image_start, image_len);
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200351 if (ret != LZMA_RESULT_OK) {
352 printf ("LZMA: uncompress or overwrite error %d "
353 "- must RESET board to recover\n", ret);
354 show_boot_progress (-6);
355 return BOOTM_ERR_RESET;
356 }
357 *load_end = load + unc_len;
358 break;
359#endif /* CONFIG_LZMA */
wdenk47d1a6e2002-11-03 00:01:44 +0000360 default:
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100361 printf ("Unimplemented compression type %d\n", comp);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500362 return BOOTM_ERR_UNIMPLEMENTED;
wdenk47d1a6e2002-11-03 00:01:44 +0000363 }
wdenk42c05472004-03-23 22:14:11 +0000364 puts ("OK\n");
Jean-Christophe PLAGNIOL-VILLARDfcd96442008-09-09 22:18:24 +0200365 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500366 if (boot_progress)
367 show_boot_progress (7);
wdenk47d1a6e2002-11-03 00:01:44 +0000368
Kumar Galabd70bbe2008-08-15 08:24:41 -0500369 if ((load < blob_end) && (*load_end > blob_start)) {
370 debug ("images.os.start = 0x%lX, images.os.end = 0x%lx\n", blob_start, blob_end);
Jean-Christophe PLAGNIOL-VILLARDfcd96442008-09-09 22:18:24 +0200371 debug ("images.os.load = 0x%lx, load_end = 0x%lx\n", load, *load_end);
wdenk47d1a6e2002-11-03 00:01:44 +0000372
Kumar Galabd70bbe2008-08-15 08:24:41 -0500373 return BOOTM_ERR_OVERLAP;
374 }
375
376 return 0;
377}
378
379/*******************************************************************/
380/* bootm - boot application image from image in memory */
381/*******************************************************************/
382int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
383{
384
385 ulong iflag;
386 ulong load_end = 0;
387 int ret;
388
Anatolij Gustschin128de002008-08-29 21:04:45 +0200389 if (bootm_start(cmdtp, flag, argc, argv))
390 return 1;
Kumar Galabd70bbe2008-08-15 08:24:41 -0500391
392 /*
393 * We have reached the point of no return: we are going to
394 * overwrite all exception vector code, so we cannot easily
395 * recover from any failures any more...
396 */
397 iflag = disable_interrupts();
398
399#if defined(CONFIG_CMD_USB)
400 /*
401 * turn off USB to prevent the host controller from writing to the
402 * SDRAM while Linux is booting. This could happen (at least for OHCI
403 * controller), because the HCCA (Host Controller Communication Area)
404 * lies within the SDRAM and the host controller writes continously to
405 * this area (as busmaster!). The HccaFrameNumber is for example
406 * updated every 1 ms within the HCCA structure in SDRAM! For more
407 * details see the OpenHCI specification.
408 */
409 usb_stop();
410#endif
411
412#ifdef CONFIG_AMIGAONEG3SE
413 /*
414 * We've possible left the caches enabled during
415 * bios emulation, so turn them off again
416 */
417 icache_disable();
418 dcache_disable();
419#endif
420
421 ret = bootm_load_os(images.os, &load_end, 1);
422
423 if (ret < 0) {
424 if (ret == BOOTM_ERR_RESET)
Marian Balakowiczab00e022008-04-11 11:07:49 +0200425 do_reset (cmdtp, flag, argc, argv);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500426 if (ret == BOOTM_ERR_OVERLAP) {
427 if (images.legacy_hdr_valid) {
428 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
429 puts ("WARNING: legacy format multi component "
430 "image overwritten\n");
431 } else {
432 puts ("ERROR: new format image overwritten - "
433 "must RESET the board to recover\n");
434 show_boot_progress (-113);
435 do_reset (cmdtp, flag, argc, argv);
436 }
437 }
438 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
439 if (iflag)
440 enable_interrupts();
441 show_boot_progress (-7);
442 return 1;
Marian Balakowiczab00e022008-04-11 11:07:49 +0200443 }
wdenk47d1a6e2002-11-03 00:01:44 +0000444 }
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100445
Kumar Galabd70bbe2008-08-15 08:24:41 -0500446 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
wdenk47d1a6e2002-11-03 00:01:44 +0000447
Kumar Galabd70bbe2008-08-15 08:24:41 -0500448 show_boot_progress (8);
Kumar Gala6d7bfa82008-02-27 21:51:47 -0600449
Kumar Galabd70bbe2008-08-15 08:24:41 -0500450 switch (images.os.os) {
wdenk47d1a6e2002-11-03 00:01:44 +0000451 default: /* handled by (original) Linux case */
452 case IH_OS_LINUX:
wdenk808532a2003-10-10 10:05:42 +0000453#ifdef CONFIG_SILENT_CONSOLE
454 fixup_silent_linux();
455#endif
Kumar Gala48626aa2008-08-15 08:24:45 -0500456 do_bootm_linux (0, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000457 break;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100458
wdenk47d1a6e2002-11-03 00:01:44 +0000459 case IH_OS_NETBSD:
Kumar Gala48626aa2008-08-15 08:24:45 -0500460 do_bootm_netbsd (0, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000461 break;
wdenke58b0dc2003-07-27 00:21:01 +0000462
463#ifdef CONFIG_LYNXKDI
464 case IH_OS_LYNXOS:
Kumar Gala48626aa2008-08-15 08:24:45 -0500465 do_bootm_lynxkdi (0, argc, argv, &images);
wdenke58b0dc2003-07-27 00:21:01 +0000466 break;
467#endif
wdenk57b2d802003-06-27 21:31:46 +0000468
wdenk92bbe3f2003-04-20 14:04:18 +0000469 case IH_OS_RTEMS:
Kumar Gala48626aa2008-08-15 08:24:45 -0500470 do_bootm_rtems (0, argc, argv, &images);
wdenk92bbe3f2003-04-20 14:04:18 +0000471 break;
wdenk57b2d802003-06-27 21:31:46 +0000472
Jon Loeliger54324d02007-07-08 17:51:39 -0500473#if defined(CONFIG_CMD_ELF)
wdenk47d1a6e2002-11-03 00:01:44 +0000474 case IH_OS_VXWORKS:
Kumar Gala48626aa2008-08-15 08:24:45 -0500475 do_bootm_vxworks (0, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000476 break;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100477
wdenk47d1a6e2002-11-03 00:01:44 +0000478 case IH_OS_QNX:
Kumar Gala48626aa2008-08-15 08:24:45 -0500479 do_bootm_qnxelf (0, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000480 break;
Jon Loeligerd704d912007-07-10 11:02:44 -0500481#endif
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100482
Peter Tyser56b8dd12008-09-08 14:56:49 -0500483#ifdef CONFIG_INTEGRITY
484 case IH_OS_INTEGRITY:
485 do_bootm_integrity (0, argc, argv, &images);
486 break;
487#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000488 }
489
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200490 show_boot_progress (-9);
wdenk47d1a6e2002-11-03 00:01:44 +0000491#ifdef DEBUG
wdenk42c05472004-03-23 22:14:11 +0000492 puts ("\n## Control returned to monitor - resetting...\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000493#endif
Kumar Gala48626aa2008-08-15 08:24:45 -0500494 do_reset (cmdtp, flag, argc, argv);
Marian Balakowicz9c220262008-03-12 10:14:57 +0100495
wdenk47d1a6e2002-11-03 00:01:44 +0000496 return 1;
497}
498
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100499/**
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100500 * image_get_kernel - verify legacy format kernel image
501 * @img_addr: in RAM address of the legacy format image to be verified
502 * @verify: data CRC verification flag
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100503 *
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100504 * image_get_kernel() verifies legacy image integrity and returns pointer to
505 * legacy image header if image verification was completed successfully.
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100506 *
507 * returns:
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100508 * pointer to a legacy image header if valid image was found
509 * otherwise return NULL
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100510 */
Marian Balakowicz59504f62008-02-27 11:02:07 +0100511static image_header_t *image_get_kernel (ulong img_addr, int verify)
wdenk808532a2003-10-10 10:05:42 +0000512{
Marian Balakowicz59504f62008-02-27 11:02:07 +0100513 image_header_t *hdr = (image_header_t *)img_addr;
wdenk808532a2003-10-10 10:05:42 +0000514
Marian Balakowicz59504f62008-02-27 11:02:07 +0100515 if (!image_check_magic(hdr)) {
516 puts ("Bad Magic Number\n");
517 show_boot_progress (-1);
518 return NULL;
519 }
520 show_boot_progress (2);
wdenk808532a2003-10-10 10:05:42 +0000521
Marian Balakowicz59504f62008-02-27 11:02:07 +0100522 if (!image_check_hcrc (hdr)) {
523 puts ("Bad Header Checksum\n");
524 show_boot_progress (-2);
525 return NULL;
526 }
527
528 show_boot_progress (3);
529 image_print_contents (hdr);
530
531 if (verify) {
532 puts (" Verifying Checksum ... ");
533 if (!image_check_dcrc (hdr)) {
534 printf ("Bad Data CRC\n");
535 show_boot_progress (-3);
536 return NULL;
wdenk808532a2003-10-10 10:05:42 +0000537 }
Marian Balakowicz59504f62008-02-27 11:02:07 +0100538 puts ("OK\n");
wdenk808532a2003-10-10 10:05:42 +0000539 }
Marian Balakowicz59504f62008-02-27 11:02:07 +0100540 show_boot_progress (4);
wdenk808532a2003-10-10 10:05:42 +0000541
Marian Balakowicz59504f62008-02-27 11:02:07 +0100542 if (!image_check_target_arch (hdr)) {
543 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
544 show_boot_progress (-4);
545 return NULL;
546 }
547 return hdr;
wdenk808532a2003-10-10 10:05:42 +0000548}
wdenk808532a2003-10-10 10:05:42 +0000549
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100550/**
551 * fit_check_kernel - verify FIT format kernel subimage
552 * @fit_hdr: pointer to the FIT image header
553 * os_noffset: kernel subimage node offset within FIT image
554 * @verify: data CRC verification flag
555 *
556 * fit_check_kernel() verifies integrity of the kernel subimage and from
557 * specified FIT image.
558 *
559 * returns:
560 * 1, on success
561 * 0, on failure
562 */
563#if defined (CONFIG_FIT)
564static int fit_check_kernel (const void *fit, int os_noffset, int verify)
wdenk47d1a6e2002-11-03 00:01:44 +0000565{
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100566 fit_image_print (fit, os_noffset, " ");
wdenk47d1a6e2002-11-03 00:01:44 +0000567
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100568 if (verify) {
569 puts (" Verifying Hash Integrity ... ");
570 if (!fit_image_check_hashes (fit, os_noffset)) {
571 puts ("Bad Data Hash\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100572 show_boot_progress (-104);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100573 return 0;
574 }
575 puts ("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000576 }
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100577 show_boot_progress (105);
wdenk47d1a6e2002-11-03 00:01:44 +0000578
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100579 if (!fit_image_check_target_arch (fit, os_noffset)) {
580 puts ("Unsupported Architecture\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100581 show_boot_progress (-105);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100582 return 0;
583 }
wdenk47d1a6e2002-11-03 00:01:44 +0000584
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100585 show_boot_progress (106);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100586 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
587 puts ("Not a kernel image\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100588 show_boot_progress (-106);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100589 return 0;
590 }
wdenk47d1a6e2002-11-03 00:01:44 +0000591
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100592 show_boot_progress (107);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100593 return 1;
594}
595#endif /* CONFIG_FIT */
wdenk56f94be2002-11-05 16:35:14 +0000596
Marian Balakowicz59504f62008-02-27 11:02:07 +0100597/**
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100598 * boot_get_kernel - find kernel image
Marian Balakowicz59504f62008-02-27 11:02:07 +0100599 * @os_data: pointer to a ulong variable, will hold os data start address
600 * @os_len: pointer to a ulong variable, will hold os data length
601 *
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100602 * boot_get_kernel() tries to find a kernel image, verifies its integrity
Marian Balakowicz59504f62008-02-27 11:02:07 +0100603 * and locates kernel data.
604 *
605 * returns:
606 * pointer to image header if valid image was found, plus kernel start
607 * address and length, otherwise NULL
608 */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100609static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100610 bootm_headers_t *images, ulong *os_data, ulong *os_len)
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100611{
612 image_header_t *hdr;
613 ulong img_addr;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100614#if defined(CONFIG_FIT)
615 void *fit_hdr;
616 const char *fit_uname_config = NULL;
617 const char *fit_uname_kernel = NULL;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100618 const void *data;
619 size_t len;
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100620 int cfg_noffset;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100621 int os_noffset;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100622#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000623
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100624 /* find out kernel image address */
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100625 if (argc < 2) {
626 img_addr = load_addr;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100627 debug ("* kernel: default image load address = 0x%08lx\n",
628 load_addr);
629#if defined(CONFIG_FIT)
630 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
631 &fit_uname_config)) {
632 debug ("* kernel: config '%s' from image at 0x%08lx\n",
633 fit_uname_config, img_addr);
634 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
635 &fit_uname_kernel)) {
636 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
637 fit_uname_kernel, img_addr);
638#endif
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100639 } else {
640 img_addr = simple_strtoul(argv[1], NULL, 16);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100641 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100642 }
wdenk56f94be2002-11-05 16:35:14 +0000643
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100644 show_boot_progress (1);
wdenk47d1a6e2002-11-03 00:01:44 +0000645
Marian Balakowiczc536d6f2008-02-21 17:20:19 +0100646 /* copy from dataflash if needed */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100647 img_addr = genimg_get_image (img_addr);
wdenk47d1a6e2002-11-03 00:01:44 +0000648
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100649 /* check image type, for FIT images get FIT kernel node */
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100650 *os_data = *os_len = 0;
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100651 switch (genimg_get_format ((void *)img_addr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100652 case IMAGE_FORMAT_LEGACY:
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100653 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
654 img_addr);
Marian Balakowicz59504f62008-02-27 11:02:07 +0100655 hdr = image_get_kernel (img_addr, images->verify);
656 if (!hdr)
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100657 return NULL;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100658 show_boot_progress (5);
wdenk47d1a6e2002-11-03 00:01:44 +0000659
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100660 /* get os_data and os_len */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100661 switch (image_get_type (hdr)) {
662 case IH_TYPE_KERNEL:
663 *os_data = image_get_data (hdr);
664 *os_len = image_get_data_size (hdr);
665 break;
666 case IH_TYPE_MULTI:
667 image_multi_getimg (hdr, 0, os_data, os_len);
668 break;
669 default:
670 printf ("Wrong Image Type for %s command\n", cmdtp->name);
671 show_boot_progress (-5);
672 return NULL;
673 }
Marian Balakowiczab00e022008-04-11 11:07:49 +0200674
675 /*
676 * copy image header to allow for image overwrites during kernel
677 * decompression.
678 */
679 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
680
681 /* save pointer to image header */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100682 images->legacy_hdr_os = hdr;
wdenk47d1a6e2002-11-03 00:01:44 +0000683
Marian Balakowiczab00e022008-04-11 11:07:49 +0200684 images->legacy_hdr_valid = 1;
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100685 show_boot_progress (6);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100686 break;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100687#if defined(CONFIG_FIT)
688 case IMAGE_FORMAT_FIT:
689 fit_hdr = (void *)img_addr;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100690 printf ("## Booting kernel from FIT Image at %08lx ...\n",
691 img_addr);
wdenk47d1a6e2002-11-03 00:01:44 +0000692
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100693 if (!fit_check_format (fit_hdr)) {
694 puts ("Bad FIT kernel image format!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100695 show_boot_progress (-100);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100696 return NULL;
697 }
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100698 show_boot_progress (100);
wdenk47d1a6e2002-11-03 00:01:44 +0000699
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100700 if (!fit_uname_kernel) {
701 /*
702 * no kernel image node unit name, try to get config
703 * node first. If config unit node name is NULL
704 * fit_conf_get_node() will try to find default config node
705 */
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100706 show_boot_progress (101);
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100707 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
708 if (cfg_noffset < 0) {
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100709 show_boot_progress (-101);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100710 return NULL;
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100711 }
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100712 /* save configuration uname provided in the first
713 * bootm argument
714 */
715 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
716 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
717 show_boot_progress (103);
wdenk47d1a6e2002-11-03 00:01:44 +0000718
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100719 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100720 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
721 } else {
722 /* get kernel component image node offset */
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100723 show_boot_progress (102);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100724 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
725 }
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100726 if (os_noffset < 0) {
727 show_boot_progress (-103);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100728 return NULL;
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100729 }
wdenk47d1a6e2002-11-03 00:01:44 +0000730
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100731 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
wdenk47d1a6e2002-11-03 00:01:44 +0000732
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100733 show_boot_progress (104);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100734 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
735 return NULL;
Matthew McClintock6fb7c812006-06-28 10:41:37 -0500736
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100737 /* get kernel image data address and length */
738 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
739 puts ("Could not find kernel subimage data!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100740 show_boot_progress (-107);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100741 return NULL;
Matthew McClintock6fb7c812006-06-28 10:41:37 -0500742 }
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100743 show_boot_progress (108);
wdenk47d1a6e2002-11-03 00:01:44 +0000744
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100745 *os_len = len;
746 *os_data = (ulong)data;
747 images->fit_hdr_os = fit_hdr;
748 images->fit_uname_os = fit_uname_kernel;
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100749 images->fit_noffset_os = os_noffset;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100750 break;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100751#endif
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100752 default:
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100753 printf ("Wrong Image Format for %s command\n", cmdtp->name);
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100754 show_boot_progress (-108);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100755 return NULL;
756 }
wdenk47d1a6e2002-11-03 00:01:44 +0000757
Wolfgang Denk8d541882008-07-10 13:16:09 +0200758 debug (" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100759 *os_data, *os_len, *os_len);
wdenk47d1a6e2002-11-03 00:01:44 +0000760
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100761 return (void *)img_addr;
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100762}
wdenk47d1a6e2002-11-03 00:01:44 +0000763
wdenk47d1a6e2002-11-03 00:01:44 +0000764U_BOOT_CMD(
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100765 bootm, CFG_MAXARGS, 1, do_bootm,
766 "bootm - boot application image from memory\n",
767 "[addr [arg ...]]\n - boot application image stored in memory\n"
768 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
769 "\t'arg' can be the address of an initrd image\n"
Marian Balakowiczd2160852008-01-31 13:20:07 +0100770#if defined(CONFIG_OF_LIBFDT)
wdenk47d1a6e2002-11-03 00:01:44 +0000771 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
772 "\ta third argument is required which is the address of the\n"
773 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
774 "\tuse a '-' for the second argument. If you do not pass a third\n"
775 "\ta bd_info struct will be passed instead\n"
776#endif
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100777#if defined(CONFIG_FIT)
778 "\t\nFor the new multi component uImage format (FIT) addresses\n"
779 "\tmust be extened to include component or configuration unit name:\n"
780 "\taddr:<subimg_uname> - direct component image specification\n"
781 "\taddr#<conf_uname> - configuration specification\n"
782 "\tUse iminfo command to get the list of existing component\n"
783 "\timages and configurations.\n"
784#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000785);
wdenk47d1a6e2002-11-03 00:01:44 +0000786
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100787/*******************************************************************/
788/* bootd - boot default image */
789/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -0500790#if defined(CONFIG_CMD_BOOTD)
wdenk47d1a6e2002-11-03 00:01:44 +0000791int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
792{
793 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000794
wdenk47d1a6e2002-11-03 00:01:44 +0000795#ifndef CFG_HUSH_PARSER
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100796 if (run_command (getenv ("bootcmd"), flag) < 0)
797 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000798#else
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100799 if (parse_string_outer (getenv ("bootcmd"),
800 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
801 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000802#endif
803 return rcode;
804}
wdenk47d1a6e2002-11-03 00:01:44 +0000805
wdenkf287a242003-07-01 21:06:45 +0000806U_BOOT_CMD(
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100807 boot, 1, 1, do_bootd,
808 "boot - boot default, i.e., run 'bootcmd'\n",
wdenk3086a972003-06-28 23:11:04 +0000809 NULL
810);
wdenk47d1a6e2002-11-03 00:01:44 +0000811
wdenk3086a972003-06-28 23:11:04 +0000812/* keep old command name "bootd" for backward compatibility */
wdenkf287a242003-07-01 21:06:45 +0000813U_BOOT_CMD(
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100814 bootd, 1, 1, do_bootd,
815 "bootd - boot default, i.e., run 'bootcmd'\n",
wdenk57b2d802003-06-27 21:31:46 +0000816 NULL
817);
wdenk47d1a6e2002-11-03 00:01:44 +0000818
wdenk47d1a6e2002-11-03 00:01:44 +0000819#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000820
wdenk47d1a6e2002-11-03 00:01:44 +0000821
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100822/*******************************************************************/
823/* iminfo - print header info for a requested image */
824/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -0500825#if defined(CONFIG_CMD_IMI)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100826int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000827{
828 int arg;
829 ulong addr;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100830 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000831
wdenk47d1a6e2002-11-03 00:01:44 +0000832 if (argc < 2) {
833 return image_info (load_addr);
834 }
wdenk47d1a6e2002-11-03 00:01:44 +0000835
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100836 for (arg = 1; arg < argc; ++arg) {
837 addr = simple_strtoul (argv[arg], NULL, 16);
838 if (image_info (addr) != 0)
839 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000840 }
841 return rcode;
842}
wdenk47d1a6e2002-11-03 00:01:44 +0000843
wdenk47d1a6e2002-11-03 00:01:44 +0000844static int image_info (ulong addr)
845{
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100846 void *hdr = (void *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +0000847
wdenk47d1a6e2002-11-03 00:01:44 +0000848 printf ("\n## Checking Image at %08lx ...\n", addr);
wdenk47d1a6e2002-11-03 00:01:44 +0000849
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100850 switch (genimg_get_format (hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100851 case IMAGE_FORMAT_LEGACY:
852 puts (" Legacy image found\n");
853 if (!image_check_magic (hdr)) {
854 puts (" Bad Magic Number\n");
855 return 1;
856 }
wdenk47d1a6e2002-11-03 00:01:44 +0000857
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100858 if (!image_check_hcrc (hdr)) {
859 puts (" Bad Header Checksum\n");
860 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000861 }
862
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100863 image_print_contents (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000864
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100865 puts (" Verifying Checksum ... ");
866 if (!image_check_dcrc (hdr)) {
867 puts (" Bad Data CRC\n");
868 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000869 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100870 puts ("OK\n");
871 return 0;
872#if defined(CONFIG_FIT)
873 case IMAGE_FORMAT_FIT:
874 puts (" FIT image found\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000875
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100876 if (!fit_check_format (hdr)) {
877 puts ("Bad FIT image format!\n");
878 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000879 }
880
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100881 fit_print_contents (hdr);
Bartlomiej Sieka03797f52008-09-09 12:58:16 +0200882
883 if (!fit_all_image_check_hashes (hdr)) {
884 puts ("Bad hash in FIT image!\n");
885 return 1;
886 }
887
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100888 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000889#endif
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100890 default:
891 puts ("Unknown image format!\n");
892 break;
wdenk47d1a6e2002-11-03 00:01:44 +0000893 }
wdenk47d1a6e2002-11-03 00:01:44 +0000894
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100895 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000896}
wdenk47d1a6e2002-11-03 00:01:44 +0000897
wdenkf287a242003-07-01 21:06:45 +0000898U_BOOT_CMD(
899 iminfo, CFG_MAXARGS, 1, do_iminfo,
wdenk57b2d802003-06-27 21:31:46 +0000900 "iminfo - print header information for application image\n",
901 "addr [addr ...]\n"
902 " - print header information for application image starting at\n"
903 " address 'addr' in memory; this includes verification of the\n"
904 " image contents (magic number, header and payload checksums)\n"
905);
wdenk47d1a6e2002-11-03 00:01:44 +0000906#endif
907
908
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100909/*******************************************************************/
910/* imls - list all images found in flash */
911/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -0500912#if defined(CONFIG_CMD_IMLS)
wdenk874ac262003-07-24 23:38:38 +0000913int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
914{
915 flash_info_t *info;
916 int i, j;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100917 void *hdr;
wdenk47d1a6e2002-11-03 00:01:44 +0000918
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100919 for (i = 0, info = &flash_info[0];
920 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
wdenk47d1a6e2002-11-03 00:01:44 +0000921
wdenk874ac262003-07-24 23:38:38 +0000922 if (info->flash_id == FLASH_UNKNOWN)
923 goto next_bank;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100924 for (j = 0; j < info->sector_count; ++j) {
wdenk47d1a6e2002-11-03 00:01:44 +0000925
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100926 hdr = (void *)info->start[j];
927 if (!hdr)
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100928 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +0000929
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100930 switch (genimg_get_format (hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100931 case IMAGE_FORMAT_LEGACY:
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100932 if (!image_check_hcrc (hdr))
933 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +0000934
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100935 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
936 image_print_contents (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000937
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100938 puts (" Verifying Checksum ... ");
939 if (!image_check_dcrc (hdr)) {
940 puts ("Bad Data CRC\n");
941 } else {
942 puts ("OK\n");
943 }
944 break;
945#if defined(CONFIG_FIT)
946 case IMAGE_FORMAT_FIT:
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100947 if (!fit_check_format (hdr))
948 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +0000949
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100950 printf ("FIT Image at %08lX:\n", (ulong)hdr);
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100951 fit_print_contents (hdr);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100952 break;
953#endif
954 default:
955 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +0000956 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100957
wdenk0a658552003-08-05 17:43:17 +0000958next_sector: ;
wdenk47d1a6e2002-11-03 00:01:44 +0000959 }
wdenk0a658552003-08-05 17:43:17 +0000960next_bank: ;
wdenk47d1a6e2002-11-03 00:01:44 +0000961 }
962
wdenk874ac262003-07-24 23:38:38 +0000963 return (0);
964}
wdenk47d1a6e2002-11-03 00:01:44 +0000965
wdenk874ac262003-07-24 23:38:38 +0000966U_BOOT_CMD(
967 imls, 1, 1, do_imls,
968 "imls - list all images found in flash\n",
969 "\n"
970 " - Prints information about all images found at sector\n"
971 " boundaries in flash.\n"
972);
wdenk47d1a6e2002-11-03 00:01:44 +0000973#endif
974
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100975/*******************************************************************/
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100976/* helper routines */
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100977/*******************************************************************/
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100978#ifdef CONFIG_SILENT_CONSOLE
979static void fixup_silent_linux ()
980{
981 char buf[256], *start, *end;
982 char *cmdline = getenv ("bootargs");
wdenk47d1a6e2002-11-03 00:01:44 +0000983
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100984 /* Only fix cmdline when requested */
985 if (!(gd->flags & GD_FLG_SILENT))
986 return;
wdenk47d1a6e2002-11-03 00:01:44 +0000987
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100988 debug ("before silent fix-up: %s\n", cmdline);
989 if (cmdline) {
990 if ((start = strstr (cmdline, "console=")) != NULL) {
991 end = strchr (start, ' ');
992 strncpy (buf, cmdline, (start - cmdline + 8));
993 if (end)
994 strcpy (buf + (start - cmdline + 8), end);
995 else
996 buf[start - cmdline + 8] = '\0';
997 } else {
998 strcpy (buf, cmdline);
999 strcat (buf, " console=");
wdenk47d1a6e2002-11-03 00:01:44 +00001000 }
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001001 } else {
1002 strcpy (buf, "console=");
wdenk47d1a6e2002-11-03 00:01:44 +00001003 }
wdenk47d1a6e2002-11-03 00:01:44 +00001004
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001005 setenv ("bootargs", buf);
1006 debug ("after silent fix-up: %s\n", buf);
1007}
1008#endif /* CONFIG_SILENT_CONSOLE */
wdenk47d1a6e2002-11-03 00:01:44 +00001009
wdenk47d1a6e2002-11-03 00:01:44 +00001010
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001011/*******************************************************************/
1012/* OS booting routines */
1013/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +00001014
Kumar Gala48626aa2008-08-15 08:24:45 -05001015static int do_bootm_netbsd (int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001016 bootm_headers_t *images)
wdenk92bbe3f2003-04-20 14:04:18 +00001017{
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001018 void (*loader)(bd_t *, image_header_t *, char *, char *);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001019 image_header_t *os_hdr, *hdr;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +01001020 ulong kernel_data, kernel_len;
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001021 char *consdev;
1022 char *cmdline;
wdenk47d1a6e2002-11-03 00:01:44 +00001023
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001024#if defined(CONFIG_FIT)
1025 if (!images->legacy_hdr_valid) {
1026 fit_unsupported_reset ("NetBSD");
Kumar Gala48626aa2008-08-15 08:24:45 -05001027 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001028 }
1029#endif
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001030 hdr = images->legacy_hdr_os;
wdenk47d1a6e2002-11-03 00:01:44 +00001031
1032 /*
1033 * Booting a (NetBSD) kernel image
1034 *
1035 * This process is pretty similar to a standalone application:
1036 * The (first part of an multi-) image must be a stage-2 loader,
1037 * which in turn is responsible for loading & invoking the actual
1038 * kernel. The only differences are the parameters being passed:
1039 * besides the board info strucure, the loader expects a command
1040 * line, the name of the console device, and (optionally) the
1041 * address of the original image header.
1042 */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001043 os_hdr = NULL;
Marian Balakowiczab00e022008-04-11 11:07:49 +02001044 if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
Marian Balakowiczb4a12a92008-01-08 18:12:17 +01001045 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
1046 if (kernel_len)
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001047 os_hdr = hdr;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +01001048 }
wdenk47d1a6e2002-11-03 00:01:44 +00001049
1050 consdev = "";
1051#if defined (CONFIG_8xx_CONS_SMC1)
1052 consdev = "smc1";
1053#elif defined (CONFIG_8xx_CONS_SMC2)
1054 consdev = "smc2";
1055#elif defined (CONFIG_8xx_CONS_SCC2)
1056 consdev = "scc2";
1057#elif defined (CONFIG_8xx_CONS_SCC3)
1058 consdev = "scc3";
1059#endif
1060
1061 if (argc > 2) {
1062 ulong len;
1063 int i;
1064
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001065 for (i = 2, len = 0; i < argc; i += 1)
wdenk47d1a6e2002-11-03 00:01:44 +00001066 len += strlen (argv[i]) + 1;
1067 cmdline = malloc (len);
1068
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001069 for (i = 2, len = 0; i < argc; i += 1) {
wdenk47d1a6e2002-11-03 00:01:44 +00001070 if (i > 2)
1071 cmdline[len++] = ' ';
1072 strcpy (&cmdline[len], argv[i]);
1073 len += strlen (argv[i]);
1074 }
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001075 } else if ((cmdline = getenv ("bootargs")) == NULL) {
wdenk47d1a6e2002-11-03 00:01:44 +00001076 cmdline = "";
1077 }
1078
Kumar Gala93467bc2008-08-15 08:24:36 -05001079 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
wdenk47d1a6e2002-11-03 00:01:44 +00001080
1081 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
1082 (ulong)loader);
1083
1084 show_boot_progress (15);
1085
1086 /*
1087 * NetBSD Stage-2 Loader Parameters:
1088 * r3: ptr to board info data
1089 * r4: image address
1090 * r5: console device
1091 * r6: boot args string
1092 */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001093 (*loader) (gd->bd, os_hdr, consdev, cmdline);
Kumar Gala48626aa2008-08-15 08:24:45 -05001094
1095 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001096}
1097
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001098#ifdef CONFIG_LYNXKDI
Kumar Gala48626aa2008-08-15 08:24:45 -05001099static int do_bootm_lynxkdi (int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001100 bootm_headers_t *images)
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001101{
Marian Balakowiczab00e022008-04-11 11:07:49 +02001102 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001103
1104#if defined(CONFIG_FIT)
1105 if (!images->legacy_hdr_valid) {
1106 fit_unsupported_reset ("Lynx");
Kumar Gala48626aa2008-08-15 08:24:45 -05001107 return 1;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001108 }
1109#endif
1110
1111 lynxkdi_boot ((image_header_t *)hdr);
Kumar Gala48626aa2008-08-15 08:24:45 -05001112
1113 return 1;
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001114}
1115#endif /* CONFIG_LYNXKDI */
1116
Kumar Gala48626aa2008-08-15 08:24:45 -05001117static int do_bootm_rtems (int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001118 bootm_headers_t *images)
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001119{
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001120 void (*entry_point)(bd_t *);
wdenk92bbe3f2003-04-20 14:04:18 +00001121
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001122#if defined(CONFIG_FIT)
1123 if (!images->legacy_hdr_valid) {
1124 fit_unsupported_reset ("RTEMS");
Kumar Gala48626aa2008-08-15 08:24:45 -05001125 return 1;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001126 }
1127#endif
1128
Kumar Gala93467bc2008-08-15 08:24:36 -05001129 entry_point = (void (*)(bd_t *))images->ep;
wdenk47d1a6e2002-11-03 00:01:44 +00001130
wdenk92bbe3f2003-04-20 14:04:18 +00001131 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1132 (ulong)entry_point);
wdenk47d1a6e2002-11-03 00:01:44 +00001133
Heiko Schocher8a8ec532007-07-13 09:54:17 +02001134 show_boot_progress (15);
wdenk92bbe3f2003-04-20 14:04:18 +00001135
1136 /*
1137 * RTEMS Parameters:
1138 * r3: ptr to board info data
1139 */
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001140 (*entry_point)(gd->bd);
Kumar Gala48626aa2008-08-15 08:24:45 -05001141
1142 return 1;
wdenk92bbe3f2003-04-20 14:04:18 +00001143}
1144
Jon Loeliger54324d02007-07-08 17:51:39 -05001145#if defined(CONFIG_CMD_ELF)
Kumar Gala48626aa2008-08-15 08:24:45 -05001146static int do_bootm_vxworks (int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001147 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001148{
wdenk47d1a6e2002-11-03 00:01:44 +00001149 char str[80];
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001150
1151#if defined(CONFIG_FIT)
Marian Balakowiczab00e022008-04-11 11:07:49 +02001152 if (!images->legacy_hdr_valid) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001153 fit_unsupported_reset ("VxWorks");
Kumar Gala48626aa2008-08-15 08:24:45 -05001154 return 1;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001155 }
1156#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001157
Kumar Gala93467bc2008-08-15 08:24:36 -05001158 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001159 setenv("loadaddr", str);
Kumar Gala48626aa2008-08-15 08:24:45 -05001160 do_bootvx(NULL, 0, 0, NULL);
1161
1162 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001163}
1164
Kumar Gala48626aa2008-08-15 08:24:45 -05001165static int do_bootm_qnxelf(int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001166 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001167{
wdenk47d1a6e2002-11-03 00:01:44 +00001168 char *local_args[2];
1169 char str[16];
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001170
1171#if defined(CONFIG_FIT)
1172 if (!images->legacy_hdr_valid) {
1173 fit_unsupported_reset ("QNX");
Kumar Gala48626aa2008-08-15 08:24:45 -05001174 return 1;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001175 }
1176#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001177
Kumar Gala93467bc2008-08-15 08:24:36 -05001178 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001179 local_args[0] = argv[0];
1180 local_args[1] = str; /* and provide it via the arguments */
Kumar Gala48626aa2008-08-15 08:24:45 -05001181 do_bootelf(NULL, 0, 2, local_args);
1182
1183 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001184}
Jon Loeligerd704d912007-07-10 11:02:44 -05001185#endif
Peter Tyser56b8dd12008-09-08 14:56:49 -05001186
1187#ifdef CONFIG_INTEGRITY
1188static int do_bootm_integrity (int flag, int argc, char *argv[],
1189 bootm_headers_t *images)
1190{
1191 void (*entry_point)(void);
1192
1193#if defined(CONFIG_FIT)
1194 if (!images->legacy_hdr_valid) {
1195 fit_unsupported_reset ("INTEGRITY");
1196 return 1;
1197 }
1198#endif
1199
1200 entry_point = (void (*)(void))images->ep;
1201
1202 printf ("## Transferring control to INTEGRITY (at address %08lx) ...\n",
1203 (ulong)entry_point);
1204
1205 show_boot_progress (15);
1206
1207 /*
1208 * INTEGRITY Parameters:
1209 * None
1210 */
1211 (*entry_point)();
1212
1213 return 1;
1214}
1215#endif