blob: 5f7458b80a3e80615cad943f8a30fa1bbfe2ded3 [file] [log] [blame]
wdenk47d1a6e2002-11-03 00:01:44 +00001/*
Stefan Roese5d5ce292006-03-13 11:16:36 +01002 * (C) Copyright 2000-2006
wdenk47d1a6e2002-11-03 00:01:44 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
Marian Balakowicz41d71ed2008-01-08 18:14:09 +010024
wdenk47d1a6e2002-11-03 00:01:44 +000025/*
26 * Boot support
27 */
28#include <common.h>
29#include <watchdog.h>
30#include <command.h>
wdenk47d1a6e2002-11-03 00:01:44 +000031#include <image.h>
32#include <malloc.h>
33#include <zlib.h>
wdenk710e3502003-08-29 20:57:53 +000034#include <bzlib.h>
wdenk0893c472003-05-20 14:25:27 +000035#include <environment.h>
Kumar Gala6d7bfa82008-02-27 21:51:47 -060036#include <lmb.h>
wdenk47d1a6e2002-11-03 00:01:44 +000037#include <asm/byteorder.h>
wdenk57b2d802003-06-27 21:31:46 +000038
Stefan Roesea629a722008-07-30 09:59:51 +020039#if defined(CONFIG_CMD_USB)
Markus Klotzbücher09197cb2008-07-10 14:47:09 +020040#include <usb.h>
41#endif
42
wdenk47d1a6e2002-11-03 00:01:44 +000043#ifdef CFG_HUSH_PARSER
44#include <hush.h>
45#endif
46
Kumar Gala9f4e7e42008-08-15 08:24:39 -050047#if defined(CONFIG_OF_LIBFDT)
48#include <fdt.h>
49#include <libfdt.h>
50#include <fdt_support.h>
51#endif
52
Marian Balakowicz2df645e2008-01-08 18:17:10 +010053DECLARE_GLOBAL_DATA_PTR;
wdenk9dfa8d12002-12-08 09:53:23 +000054
Marian Balakowicz2df645e2008-01-08 18:17:10 +010055extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
56#ifndef CFG_BOOTM_LEN
57#define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
wdenk381669a2003-06-16 23:50:08 +000058#endif
59
Marian Balakowiczbe946ba2008-01-08 18:11:43 +010060#ifdef CONFIG_BZIP2
61extern void bz_internal_error(int);
wdenk47d1a6e2002-11-03 00:01:44 +000062#endif
63
Jon Loeliger54324d02007-07-08 17:51:39 -050064#if defined(CONFIG_CMD_IMI)
wdenk47d1a6e2002-11-03 00:01:44 +000065static int image_info (unsigned long addr);
66#endif
wdenk874ac262003-07-24 23:38:38 +000067
Jon Loeliger54324d02007-07-08 17:51:39 -050068#if defined(CONFIG_CMD_IMLS)
wdenk874ac262003-07-24 23:38:38 +000069#include <flash.h>
Marian Balakowicz513b4a12005-10-11 19:09:42 +020070extern flash_info_t flash_info[]; /* info for FLASH chips */
wdenk874ac262003-07-24 23:38:38 +000071static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
72#endif
73
Marian Balakowicz2df645e2008-01-08 18:17:10 +010074#ifdef CONFIG_SILENT_CONSOLE
75static void fixup_silent_linux (void);
76#endif
wdenk47d1a6e2002-11-03 00:01:44 +000077
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +010078static image_header_t *image_get_kernel (ulong img_addr, int verify);
79#if defined(CONFIG_FIT)
80static int fit_check_kernel (const void *fit, int os_noffset, int verify);
wdenk591dda52002-11-18 00:14:45 +000081#endif
82
Marian Balakowiczd7c88a42008-02-29 14:58:34 +010083static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +010084 bootm_headers_t *images, ulong *os_data, ulong *os_len);
Marian Balakowicz2df645e2008-01-08 18:17:10 +010085extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
wdenk47d1a6e2002-11-03 00:01:44 +000086
wdenk47d1a6e2002-11-03 00:01:44 +000087/*
88 * Continue booting an OS image; caller already has:
89 * - copied image header to global variable `header'
90 * - checked header magic number, checksums (both header & image),
91 * - verified image architecture (PPC) and type (KERNEL or MULTI),
92 * - loaded (first part of) image to header load address,
93 * - disabled interrupts.
94 */
Marian Balakowicz2df645e2008-01-08 18:17:10 +010095typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag,
Marian Balakowiczb4a12a92008-01-08 18:12:17 +010096 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +010097 bootm_headers_t *images); /* pointers to os/initrd/fdt */
wdenk47d1a6e2002-11-03 00:01:44 +000098
Marian Balakowicz2df645e2008-01-08 18:17:10 +010099extern boot_os_fn do_bootm_linux;
100static boot_os_fn do_bootm_netbsd;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100101#if defined(CONFIG_LYNXKDI)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100102static boot_os_fn do_bootm_lynxkdi;
103extern void lynxkdi_boot (image_header_t *);
wdenk47d1a6e2002-11-03 00:01:44 +0000104#endif
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100105static boot_os_fn do_bootm_rtems;
Jon Loeliger54324d02007-07-08 17:51:39 -0500106#if defined(CONFIG_CMD_ELF)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100107static boot_os_fn do_bootm_vxworks;
108static boot_os_fn do_bootm_qnxelf;
109int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
110int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
Jon Loeligerd704d912007-07-10 11:02:44 -0500111#endif
wdenk0893c472003-05-20 14:25:27 +0000112#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100113static boot_os_fn do_bootm_artos;
wdenke58b0dc2003-07-27 00:21:01 +0000114#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000115
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100116ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100117static bootm_headers_t images; /* pointers to os/initrd/fdt images */
Stefan Roese5d5ce292006-03-13 11:16:36 +0100118
Kumar Galab937bb72008-02-27 21:51:49 -0600119void __board_lmb_reserve(struct lmb *lmb)
120{
121 /* please define platform specific board_lmb_reserve() */
122}
123void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
wdenk47d1a6e2002-11-03 00:01:44 +0000124
Kumar Galafffb1432008-08-15 08:24:37 -0500125#if defined(__ARM__)
126 #define IH_INITRD_ARCH IH_ARCH_ARM
127#elif defined(__avr32__)
128 #define IH_INITRD_ARCH IH_ARCH_AVR32
129#elif defined(__bfin__)
130 #define IH_INITRD_ARCH IH_ARCH_BLACKFIN
131#elif defined(__I386__)
132 #define IH_INITRD_ARCH IH_ARCH_I386
133#elif defined(__M68K__)
134 #define IH_INITRD_ARCH IH_ARCH_M68K
135#elif defined(__microblaze__)
136 #define IH_INITRD_ARCH IH_ARCH_MICROBLAZE
137#elif defined(__mips__)
138 #define IH_INITRD_ARCH IH_ARCH_MIPS
139#elif defined(__nios__)
140 #define IH_INITRD_ARCH IH_ARCH_NIOS
141#elif defined(__nios2__)
142 #define IH_INITRD_ARCH IH_ARCH_NIOS2
143#elif defined(__PPC__)
144 #define IH_INITRD_ARCH IH_ARCH_PPC
145#elif defined(__sh__)
146 #define IH_INITRD_ARCH IH_ARCH_SH
147#elif defined(__sparc__)
148 #define IH_INITRD_ARCH IH_ARCH_SPARC
149#else
150# error Unknown CPU type
151#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000152
Kumar Galabd70bbe2008-08-15 08:24:41 -0500153static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000154{
Becky Bruced26d67c2008-06-09 20:37:18 -0500155 ulong mem_start;
156 phys_size_t mem_size;
Kumar Galabd70bbe2008-08-15 08:24:41 -0500157 void *os_hdr;
Kumar Galafffb1432008-08-15 08:24:37 -0500158 int ret;
wdenk47d1a6e2002-11-03 00:01:44 +0000159
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100160 memset ((void *)&images, 0, sizeof (images));
Bartlomiej Sieka47868592008-04-18 12:39:23 +0200161 images.verify = getenv_yesno ("verify");
wdenk47d1a6e2002-11-03 00:01:44 +0000162
Kumar Galada6d11e2008-08-15 08:24:40 -0500163 lmb_init(&images.lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000164
Kumar Galac5bacfd2008-02-27 21:51:50 -0600165 mem_start = getenv_bootm_low();
166 mem_size = getenv_bootm_size();
wdenk47d1a6e2002-11-03 00:01:44 +0000167
Kumar Galada6d11e2008-08-15 08:24:40 -0500168 lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
wdenk47d1a6e2002-11-03 00:01:44 +0000169
Kumar Galada6d11e2008-08-15 08:24:40 -0500170 board_lmb_reserve(&images.lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000171
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100172 /* get kernel image header, start address and length */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100173 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500174 &images, &images.os.image_start, &images.os.image_len);
175 if (images.os.image_len == 0) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100176 puts ("ERROR: can't get kernel image!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000177 return 1;
178 }
Wolfgang Denk63e44ff2005-10-06 01:50:50 +0200179
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100180 /* get image parameters */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100181 switch (genimg_get_format (os_hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100182 case IMAGE_FORMAT_LEGACY:
Kumar Galabd70bbe2008-08-15 08:24:41 -0500183 images.os.type = image_get_type (os_hdr);
184 images.os.comp = image_get_comp (os_hdr);
185 images.os.os = image_get_os (os_hdr);
Wolfgang Denk63e44ff2005-10-06 01:50:50 +0200186
Kumar Galabd70bbe2008-08-15 08:24:41 -0500187 images.os.end = image_get_image_end (os_hdr);
188 images.os.load = image_get_load (os_hdr);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100189 break;
190#if defined(CONFIG_FIT)
191 case IMAGE_FORMAT_FIT:
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100192 if (fit_image_get_type (images.fit_hdr_os,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500193 images.fit_noffset_os, &images.os.type)) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100194 puts ("Can't get image type!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100195 show_boot_progress (-109);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100196 return 1;
197 }
wdenk47d1a6e2002-11-03 00:01:44 +0000198
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100199 if (fit_image_get_comp (images.fit_hdr_os,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500200 images.fit_noffset_os, &images.os.comp)) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100201 puts ("Can't get image compression!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100202 show_boot_progress (-110);
wdenk47d1a6e2002-11-03 00:01:44 +0000203 return 1;
204 }
wdenk47d1a6e2002-11-03 00:01:44 +0000205
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100206 if (fit_image_get_os (images.fit_hdr_os,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500207 images.fit_noffset_os, &images.os.os)) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100208 puts ("Can't get image OS!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100209 show_boot_progress (-111);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100210 return 1;
211 }
wdenk47d1a6e2002-11-03 00:01:44 +0000212
Kumar Galabd70bbe2008-08-15 08:24:41 -0500213 images.os.end = fit_get_end (images.fit_hdr_os);
wdenk47d1a6e2002-11-03 00:01:44 +0000214
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100215 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500216 &images.os.load)) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100217 puts ("Can't get image load address!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100218 show_boot_progress (-112);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100219 return 1;
wdenk655a0f92003-10-30 21:49:38 +0000220 }
221 break;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100222#endif
223 default:
224 puts ("ERROR: unknown image format type!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000225 return 1;
226 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100227
Kumar Gala93467bc2008-08-15 08:24:36 -0500228 /* find kernel entry point */
229 if (images.legacy_hdr_valid) {
230 images.ep = image_get_ep (&images.legacy_hdr_os_copy);
231#if defined(CONFIG_FIT)
232 } else if (images.fit_uname_os) {
233 ret = fit_image_get_entry (images.fit_hdr_os,
234 images.fit_noffset_os, &images.ep);
235 if (ret) {
236 puts ("Can't get entry point property!\n");
237 return 1;
238 }
239#endif
240 } else {
241 puts ("Could not find kernel entry point!\n");
242 return 1;
243 }
244
Kumar Galabd70bbe2008-08-15 08:24:41 -0500245 if (images.os.os == IH_OS_LINUX) {
Kumar Galafffb1432008-08-15 08:24:37 -0500246 /* find ramdisk */
247 ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
248 &images.rd_start, &images.rd_end);
249 if (ret) {
250 puts ("Ramdisk image is corrupt\n");
251 return 1;
252 }
Kumar Galaa5130ad2008-08-15 08:24:38 -0500253
254#if defined(CONFIG_OF_LIBFDT)
255 /* find flattened device tree */
256 ret = boot_get_fdt (flag, argc, argv, &images,
257 &images.ft_addr, &images.ft_len);
258 if (ret) {
259 puts ("Could not find a valid device tree\n");
260 return 1;
261 }
Kumar Gala9f4e7e42008-08-15 08:24:39 -0500262
263 set_working_fdt_addr(images.ft_addr);
Kumar Galaa5130ad2008-08-15 08:24:38 -0500264#endif
Kumar Galafffb1432008-08-15 08:24:37 -0500265 }
266
Kumar Galabd70bbe2008-08-15 08:24:41 -0500267 images.os.start = (ulong)os_hdr;
268 images.valid = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000269
Kumar Galabd70bbe2008-08-15 08:24:41 -0500270 return 0;
271}
Markus Klotzbücher09197cb2008-07-10 14:47:09 +0200272
Kumar Galabd70bbe2008-08-15 08:24:41 -0500273#define BOOTM_ERR_RESET -1
274#define BOOTM_ERR_OVERLAP -2
275#define BOOTM_ERR_UNIMPLEMENTED -3
276static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
277{
278 uint8_t comp = os.comp;
279 ulong load = os.load;
280 ulong blob_start = os.start;
281 ulong blob_end = os.end;
282 ulong image_start = os.image_start;
283 ulong image_len = os.image_len;
284 uint unc_len = CFG_BOOTM_LEN;
Markus Klotzbücher09197cb2008-07-10 14:47:09 +0200285
Kumar Galabd70bbe2008-08-15 08:24:41 -0500286 const char *type_name = genimg_get_type_name (os.type);
wdenk452cfd62002-11-19 11:04:11 +0000287
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100288 switch (comp) {
wdenk47d1a6e2002-11-03 00:01:44 +0000289 case IH_COMP_NONE:
Kumar Galabd70bbe2008-08-15 08:24:41 -0500290 if (load == blob_start) {
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100291 printf (" XIP %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000292 } else {
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100293 printf (" Loading %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000294
Kumar Galabd70bbe2008-08-15 08:24:41 -0500295 memmove_wd ((void *)load,
296 (void *)image_start, image_len, CHUNKSZ);
wdenk47d1a6e2002-11-03 00:01:44 +0000297 }
Kumar Galabd70bbe2008-08-15 08:24:41 -0500298 *load_end = load + image_len;
Guennadi Liakhovetski3110cf82008-07-31 12:35:04 +0200299 puts("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000300 break;
301 case IH_COMP_GZIP:
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100302 printf (" Uncompressing %s ... ", type_name);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500303 if (gunzip ((void *)load, unc_len,
304 (uchar *)image_start, &image_len) != 0) {
Marian Balakowiczb5324a82008-03-12 10:33:01 +0100305 puts ("GUNZIP: uncompress or overwrite error "
306 "- must RESET board to recover\n");
Kumar Galabd70bbe2008-08-15 08:24:41 -0500307 if (boot_progress)
308 show_boot_progress (-6);
309 return BOOTM_ERR_RESET;
wdenk47d1a6e2002-11-03 00:01:44 +0000310 }
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100311
Kumar Galabd70bbe2008-08-15 08:24:41 -0500312 *load_end = load + image_len;
wdenk47d1a6e2002-11-03 00:01:44 +0000313 break;
wdenk710e3502003-08-29 20:57:53 +0000314#ifdef CONFIG_BZIP2
315 case IH_COMP_BZIP2:
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100316 printf (" Uncompressing %s ... ", type_name);
wdenk2cefd152004-02-08 22:55:38 +0000317 /*
318 * If we've got less than 4 MB of malloc() space,
319 * use slower decompression algorithm which requires
320 * at most 2300 KB of memory.
321 */
Kumar Galabd70bbe2008-08-15 08:24:41 -0500322 int i = BZ2_bzBuffToBuffDecompress ((char*)load,
323 &unc_len, (char *)image_start, image_len,
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100324 CFG_MALLOC_LEN < (4096 * 1024), 0);
wdenk710e3502003-08-29 20:57:53 +0000325 if (i != BZ_OK) {
Marian Balakowiczb5324a82008-03-12 10:33:01 +0100326 printf ("BUNZIP2: uncompress or overwrite error %d "
327 "- must RESET board to recover\n", i);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500328 if (boot_progress)
329 show_boot_progress (-6);
330 return BOOTM_ERR_RESET;
wdenk710e3502003-08-29 20:57:53 +0000331 }
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100332
Kumar Galabd70bbe2008-08-15 08:24:41 -0500333 *load_end = load + unc_len;
wdenk710e3502003-08-29 20:57:53 +0000334 break;
335#endif /* CONFIG_BZIP2 */
wdenk47d1a6e2002-11-03 00:01:44 +0000336 default:
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100337 printf ("Unimplemented compression type %d\n", comp);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500338 return BOOTM_ERR_UNIMPLEMENTED;
wdenk47d1a6e2002-11-03 00:01:44 +0000339 }
wdenk42c05472004-03-23 22:14:11 +0000340 puts ("OK\n");
Kumar Galabd70bbe2008-08-15 08:24:41 -0500341 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, load_end);
342 if (boot_progress)
343 show_boot_progress (7);
wdenk47d1a6e2002-11-03 00:01:44 +0000344
Kumar Galabd70bbe2008-08-15 08:24:41 -0500345 if ((load < blob_end) && (*load_end > blob_start)) {
346 debug ("images.os.start = 0x%lX, images.os.end = 0x%lx\n", blob_start, blob_end);
347 debug ("images.os.load = 0x%lx, load_end = 0x%lx\n", load, load_end);
wdenk47d1a6e2002-11-03 00:01:44 +0000348
Kumar Galabd70bbe2008-08-15 08:24:41 -0500349 return BOOTM_ERR_OVERLAP;
350 }
351
352 return 0;
353}
354
355/*******************************************************************/
356/* bootm - boot application image from image in memory */
357/*******************************************************************/
358int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
359{
360
361 ulong iflag;
362 ulong load_end = 0;
363 int ret;
364
365 bootm_start(cmdtp, flag, argc, argv);
366
367 /*
368 * We have reached the point of no return: we are going to
369 * overwrite all exception vector code, so we cannot easily
370 * recover from any failures any more...
371 */
372 iflag = disable_interrupts();
373
374#if defined(CONFIG_CMD_USB)
375 /*
376 * turn off USB to prevent the host controller from writing to the
377 * SDRAM while Linux is booting. This could happen (at least for OHCI
378 * controller), because the HCCA (Host Controller Communication Area)
379 * lies within the SDRAM and the host controller writes continously to
380 * this area (as busmaster!). The HccaFrameNumber is for example
381 * updated every 1 ms within the HCCA structure in SDRAM! For more
382 * details see the OpenHCI specification.
383 */
384 usb_stop();
385#endif
386
387#ifdef CONFIG_AMIGAONEG3SE
388 /*
389 * We've possible left the caches enabled during
390 * bios emulation, so turn them off again
391 */
392 icache_disable();
393 dcache_disable();
394#endif
395
396 ret = bootm_load_os(images.os, &load_end, 1);
397
398 if (ret < 0) {
399 if (ret == BOOTM_ERR_RESET)
Marian Balakowiczab00e022008-04-11 11:07:49 +0200400 do_reset (cmdtp, flag, argc, argv);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500401 if (ret == BOOTM_ERR_OVERLAP) {
402 if (images.legacy_hdr_valid) {
403 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
404 puts ("WARNING: legacy format multi component "
405 "image overwritten\n");
406 } else {
407 puts ("ERROR: new format image overwritten - "
408 "must RESET the board to recover\n");
409 show_boot_progress (-113);
410 do_reset (cmdtp, flag, argc, argv);
411 }
412 }
413 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
414 if (iflag)
415 enable_interrupts();
416 show_boot_progress (-7);
417 return 1;
Marian Balakowiczab00e022008-04-11 11:07:49 +0200418 }
wdenk47d1a6e2002-11-03 00:01:44 +0000419 }
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100420
Kumar Galabd70bbe2008-08-15 08:24:41 -0500421 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
wdenk47d1a6e2002-11-03 00:01:44 +0000422
Kumar Galabd70bbe2008-08-15 08:24:41 -0500423 show_boot_progress (8);
Kumar Gala6d7bfa82008-02-27 21:51:47 -0600424
Kumar Galabd70bbe2008-08-15 08:24:41 -0500425 switch (images.os.os) {
wdenk47d1a6e2002-11-03 00:01:44 +0000426 default: /* handled by (original) Linux case */
427 case IH_OS_LINUX:
wdenk808532a2003-10-10 10:05:42 +0000428#ifdef CONFIG_SILENT_CONSOLE
429 fixup_silent_linux();
430#endif
Marian Balakowicz61fde552008-02-27 11:01:04 +0100431 do_bootm_linux (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000432 break;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100433
wdenk47d1a6e2002-11-03 00:01:44 +0000434 case IH_OS_NETBSD:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100435 do_bootm_netbsd (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000436 break;
wdenke58b0dc2003-07-27 00:21:01 +0000437
438#ifdef CONFIG_LYNXKDI
439 case IH_OS_LYNXOS:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100440 do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images);
wdenke58b0dc2003-07-27 00:21:01 +0000441 break;
442#endif
wdenk57b2d802003-06-27 21:31:46 +0000443
wdenk92bbe3f2003-04-20 14:04:18 +0000444 case IH_OS_RTEMS:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100445 do_bootm_rtems (cmdtp, flag, argc, argv, &images);
wdenk92bbe3f2003-04-20 14:04:18 +0000446 break;
wdenk57b2d802003-06-27 21:31:46 +0000447
Jon Loeliger54324d02007-07-08 17:51:39 -0500448#if defined(CONFIG_CMD_ELF)
wdenk47d1a6e2002-11-03 00:01:44 +0000449 case IH_OS_VXWORKS:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100450 do_bootm_vxworks (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000451 break;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100452
wdenk47d1a6e2002-11-03 00:01:44 +0000453 case IH_OS_QNX:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100454 do_bootm_qnxelf (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000455 break;
Jon Loeligerd704d912007-07-10 11:02:44 -0500456#endif
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100457
wdenk0893c472003-05-20 14:25:27 +0000458#ifdef CONFIG_ARTOS
459 case IH_OS_ARTOS:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100460 do_bootm_artos (cmdtp, flag, argc, argv, &images);
wdenk0893c472003-05-20 14:25:27 +0000461 break;
462#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000463 }
464
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200465 show_boot_progress (-9);
wdenk47d1a6e2002-11-03 00:01:44 +0000466#ifdef DEBUG
wdenk42c05472004-03-23 22:14:11 +0000467 puts ("\n## Control returned to monitor - resetting...\n");
Kumar Gala026e4ac2008-08-11 09:20:53 -0500468 do_reset (cmdtp, flag, argc, argv);
wdenk47d1a6e2002-11-03 00:01:44 +0000469#endif
Kumar Gala026e4ac2008-08-11 09:20:53 -0500470 if (iflag)
Marian Balakowicz9c220262008-03-12 10:14:57 +0100471 enable_interrupts();
472
wdenk47d1a6e2002-11-03 00:01:44 +0000473 return 1;
474}
475
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100476/**
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100477 * image_get_kernel - verify legacy format kernel image
478 * @img_addr: in RAM address of the legacy format image to be verified
479 * @verify: data CRC verification flag
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100480 *
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100481 * image_get_kernel() verifies legacy image integrity and returns pointer to
482 * legacy image header if image verification was completed successfully.
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100483 *
484 * returns:
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100485 * pointer to a legacy image header if valid image was found
486 * otherwise return NULL
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100487 */
Marian Balakowicz59504f62008-02-27 11:02:07 +0100488static image_header_t *image_get_kernel (ulong img_addr, int verify)
wdenk808532a2003-10-10 10:05:42 +0000489{
Marian Balakowicz59504f62008-02-27 11:02:07 +0100490 image_header_t *hdr = (image_header_t *)img_addr;
wdenk808532a2003-10-10 10:05:42 +0000491
Marian Balakowicz59504f62008-02-27 11:02:07 +0100492 if (!image_check_magic(hdr)) {
493 puts ("Bad Magic Number\n");
494 show_boot_progress (-1);
495 return NULL;
496 }
497 show_boot_progress (2);
wdenk808532a2003-10-10 10:05:42 +0000498
Marian Balakowicz59504f62008-02-27 11:02:07 +0100499 if (!image_check_hcrc (hdr)) {
500 puts ("Bad Header Checksum\n");
501 show_boot_progress (-2);
502 return NULL;
503 }
504
505 show_boot_progress (3);
506 image_print_contents (hdr);
507
508 if (verify) {
509 puts (" Verifying Checksum ... ");
510 if (!image_check_dcrc (hdr)) {
511 printf ("Bad Data CRC\n");
512 show_boot_progress (-3);
513 return NULL;
wdenk808532a2003-10-10 10:05:42 +0000514 }
Marian Balakowicz59504f62008-02-27 11:02:07 +0100515 puts ("OK\n");
wdenk808532a2003-10-10 10:05:42 +0000516 }
Marian Balakowicz59504f62008-02-27 11:02:07 +0100517 show_boot_progress (4);
wdenk808532a2003-10-10 10:05:42 +0000518
Marian Balakowicz59504f62008-02-27 11:02:07 +0100519 if (!image_check_target_arch (hdr)) {
520 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
521 show_boot_progress (-4);
522 return NULL;
523 }
524 return hdr;
wdenk808532a2003-10-10 10:05:42 +0000525}
wdenk808532a2003-10-10 10:05:42 +0000526
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100527/**
528 * fit_check_kernel - verify FIT format kernel subimage
529 * @fit_hdr: pointer to the FIT image header
530 * os_noffset: kernel subimage node offset within FIT image
531 * @verify: data CRC verification flag
532 *
533 * fit_check_kernel() verifies integrity of the kernel subimage and from
534 * specified FIT image.
535 *
536 * returns:
537 * 1, on success
538 * 0, on failure
539 */
540#if defined (CONFIG_FIT)
541static int fit_check_kernel (const void *fit, int os_noffset, int verify)
wdenk47d1a6e2002-11-03 00:01:44 +0000542{
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100543 fit_image_print (fit, os_noffset, " ");
wdenk47d1a6e2002-11-03 00:01:44 +0000544
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100545 if (verify) {
546 puts (" Verifying Hash Integrity ... ");
547 if (!fit_image_check_hashes (fit, os_noffset)) {
548 puts ("Bad Data Hash\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100549 show_boot_progress (-104);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100550 return 0;
551 }
552 puts ("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000553 }
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100554 show_boot_progress (105);
wdenk47d1a6e2002-11-03 00:01:44 +0000555
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100556 if (!fit_image_check_target_arch (fit, os_noffset)) {
557 puts ("Unsupported Architecture\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100558 show_boot_progress (-105);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100559 return 0;
560 }
wdenk47d1a6e2002-11-03 00:01:44 +0000561
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100562 show_boot_progress (106);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100563 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
564 puts ("Not a kernel image\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100565 show_boot_progress (-106);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100566 return 0;
567 }
wdenk47d1a6e2002-11-03 00:01:44 +0000568
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100569 show_boot_progress (107);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100570 return 1;
571}
572#endif /* CONFIG_FIT */
wdenk56f94be2002-11-05 16:35:14 +0000573
Marian Balakowicz59504f62008-02-27 11:02:07 +0100574/**
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100575 * boot_get_kernel - find kernel image
Marian Balakowicz59504f62008-02-27 11:02:07 +0100576 * @os_data: pointer to a ulong variable, will hold os data start address
577 * @os_len: pointer to a ulong variable, will hold os data length
578 *
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100579 * boot_get_kernel() tries to find a kernel image, verifies its integrity
Marian Balakowicz59504f62008-02-27 11:02:07 +0100580 * and locates kernel data.
581 *
582 * returns:
583 * pointer to image header if valid image was found, plus kernel start
584 * address and length, otherwise NULL
585 */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100586static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100587 bootm_headers_t *images, ulong *os_data, ulong *os_len)
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100588{
589 image_header_t *hdr;
590 ulong img_addr;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100591#if defined(CONFIG_FIT)
592 void *fit_hdr;
593 const char *fit_uname_config = NULL;
594 const char *fit_uname_kernel = NULL;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100595 const void *data;
596 size_t len;
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100597 int cfg_noffset;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100598 int os_noffset;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100599#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000600
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100601 /* find out kernel image address */
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100602 if (argc < 2) {
603 img_addr = load_addr;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100604 debug ("* kernel: default image load address = 0x%08lx\n",
605 load_addr);
606#if defined(CONFIG_FIT)
607 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
608 &fit_uname_config)) {
609 debug ("* kernel: config '%s' from image at 0x%08lx\n",
610 fit_uname_config, img_addr);
611 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
612 &fit_uname_kernel)) {
613 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
614 fit_uname_kernel, img_addr);
615#endif
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100616 } else {
617 img_addr = simple_strtoul(argv[1], NULL, 16);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100618 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100619 }
wdenk56f94be2002-11-05 16:35:14 +0000620
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100621 show_boot_progress (1);
wdenk47d1a6e2002-11-03 00:01:44 +0000622
Marian Balakowiczc536d6f2008-02-21 17:20:19 +0100623 /* copy from dataflash if needed */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100624 img_addr = genimg_get_image (img_addr);
wdenk47d1a6e2002-11-03 00:01:44 +0000625
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100626 /* check image type, for FIT images get FIT kernel node */
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100627 *os_data = *os_len = 0;
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100628 switch (genimg_get_format ((void *)img_addr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100629 case IMAGE_FORMAT_LEGACY:
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100630 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
631 img_addr);
Marian Balakowicz59504f62008-02-27 11:02:07 +0100632 hdr = image_get_kernel (img_addr, images->verify);
633 if (!hdr)
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100634 return NULL;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100635 show_boot_progress (5);
wdenk47d1a6e2002-11-03 00:01:44 +0000636
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100637 /* get os_data and os_len */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100638 switch (image_get_type (hdr)) {
639 case IH_TYPE_KERNEL:
640 *os_data = image_get_data (hdr);
641 *os_len = image_get_data_size (hdr);
642 break;
643 case IH_TYPE_MULTI:
644 image_multi_getimg (hdr, 0, os_data, os_len);
645 break;
646 default:
647 printf ("Wrong Image Type for %s command\n", cmdtp->name);
648 show_boot_progress (-5);
649 return NULL;
650 }
Marian Balakowiczab00e022008-04-11 11:07:49 +0200651
652 /*
653 * copy image header to allow for image overwrites during kernel
654 * decompression.
655 */
656 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
657
658 /* save pointer to image header */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100659 images->legacy_hdr_os = hdr;
wdenk47d1a6e2002-11-03 00:01:44 +0000660
Marian Balakowiczab00e022008-04-11 11:07:49 +0200661 images->legacy_hdr_valid = 1;
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100662 show_boot_progress (6);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100663 break;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100664#if defined(CONFIG_FIT)
665 case IMAGE_FORMAT_FIT:
666 fit_hdr = (void *)img_addr;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100667 printf ("## Booting kernel from FIT Image at %08lx ...\n",
668 img_addr);
wdenk47d1a6e2002-11-03 00:01:44 +0000669
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100670 if (!fit_check_format (fit_hdr)) {
671 puts ("Bad FIT kernel image format!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100672 show_boot_progress (-100);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100673 return NULL;
674 }
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100675 show_boot_progress (100);
wdenk47d1a6e2002-11-03 00:01:44 +0000676
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100677 if (!fit_uname_kernel) {
678 /*
679 * no kernel image node unit name, try to get config
680 * node first. If config unit node name is NULL
681 * fit_conf_get_node() will try to find default config node
682 */
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100683 show_boot_progress (101);
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100684 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
685 if (cfg_noffset < 0) {
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100686 show_boot_progress (-101);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100687 return NULL;
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100688 }
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100689 /* save configuration uname provided in the first
690 * bootm argument
691 */
692 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
693 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
694 show_boot_progress (103);
wdenk47d1a6e2002-11-03 00:01:44 +0000695
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100696 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100697 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
698 } else {
699 /* get kernel component image node offset */
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100700 show_boot_progress (102);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100701 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
702 }
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100703 if (os_noffset < 0) {
704 show_boot_progress (-103);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100705 return NULL;
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100706 }
wdenk47d1a6e2002-11-03 00:01:44 +0000707
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100708 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
wdenk47d1a6e2002-11-03 00:01:44 +0000709
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100710 show_boot_progress (104);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100711 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
712 return NULL;
Matthew McClintock6fb7c812006-06-28 10:41:37 -0500713
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100714 /* get kernel image data address and length */
715 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
716 puts ("Could not find kernel subimage data!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100717 show_boot_progress (-107);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100718 return NULL;
Matthew McClintock6fb7c812006-06-28 10:41:37 -0500719 }
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100720 show_boot_progress (108);
wdenk47d1a6e2002-11-03 00:01:44 +0000721
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100722 *os_len = len;
723 *os_data = (ulong)data;
724 images->fit_hdr_os = fit_hdr;
725 images->fit_uname_os = fit_uname_kernel;
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100726 images->fit_noffset_os = os_noffset;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100727 break;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100728#endif
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100729 default:
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100730 printf ("Wrong Image Format for %s command\n", cmdtp->name);
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100731 show_boot_progress (-108);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100732 return NULL;
733 }
wdenk47d1a6e2002-11-03 00:01:44 +0000734
Wolfgang Denk8d541882008-07-10 13:16:09 +0200735 debug (" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100736 *os_data, *os_len, *os_len);
wdenk47d1a6e2002-11-03 00:01:44 +0000737
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100738 return (void *)img_addr;
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100739}
wdenk47d1a6e2002-11-03 00:01:44 +0000740
wdenk47d1a6e2002-11-03 00:01:44 +0000741U_BOOT_CMD(
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100742 bootm, CFG_MAXARGS, 1, do_bootm,
743 "bootm - boot application image from memory\n",
744 "[addr [arg ...]]\n - boot application image stored in memory\n"
745 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
746 "\t'arg' can be the address of an initrd image\n"
Marian Balakowiczd2160852008-01-31 13:20:07 +0100747#if defined(CONFIG_OF_LIBFDT)
wdenk47d1a6e2002-11-03 00:01:44 +0000748 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
749 "\ta third argument is required which is the address of the\n"
750 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
751 "\tuse a '-' for the second argument. If you do not pass a third\n"
752 "\ta bd_info struct will be passed instead\n"
753#endif
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100754#if defined(CONFIG_FIT)
755 "\t\nFor the new multi component uImage format (FIT) addresses\n"
756 "\tmust be extened to include component or configuration unit name:\n"
757 "\taddr:<subimg_uname> - direct component image specification\n"
758 "\taddr#<conf_uname> - configuration specification\n"
759 "\tUse iminfo command to get the list of existing component\n"
760 "\timages and configurations.\n"
761#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000762);
wdenk47d1a6e2002-11-03 00:01:44 +0000763
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100764/*******************************************************************/
765/* bootd - boot default image */
766/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -0500767#if defined(CONFIG_CMD_BOOTD)
wdenk47d1a6e2002-11-03 00:01:44 +0000768int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
769{
770 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000771
wdenk47d1a6e2002-11-03 00:01:44 +0000772#ifndef CFG_HUSH_PARSER
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100773 if (run_command (getenv ("bootcmd"), flag) < 0)
774 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000775#else
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100776 if (parse_string_outer (getenv ("bootcmd"),
777 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
778 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000779#endif
780 return rcode;
781}
wdenk47d1a6e2002-11-03 00:01:44 +0000782
wdenkf287a242003-07-01 21:06:45 +0000783U_BOOT_CMD(
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100784 boot, 1, 1, do_bootd,
785 "boot - boot default, i.e., run 'bootcmd'\n",
wdenk3086a972003-06-28 23:11:04 +0000786 NULL
787);
wdenk47d1a6e2002-11-03 00:01:44 +0000788
wdenk3086a972003-06-28 23:11:04 +0000789/* keep old command name "bootd" for backward compatibility */
wdenkf287a242003-07-01 21:06:45 +0000790U_BOOT_CMD(
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100791 bootd, 1, 1, do_bootd,
792 "bootd - boot default, i.e., run 'bootcmd'\n",
wdenk57b2d802003-06-27 21:31:46 +0000793 NULL
794);
wdenk47d1a6e2002-11-03 00:01:44 +0000795
wdenk47d1a6e2002-11-03 00:01:44 +0000796#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000797
wdenk47d1a6e2002-11-03 00:01:44 +0000798
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100799/*******************************************************************/
800/* iminfo - print header info for a requested image */
801/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -0500802#if defined(CONFIG_CMD_IMI)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100803int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000804{
805 int arg;
806 ulong addr;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100807 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000808
wdenk47d1a6e2002-11-03 00:01:44 +0000809 if (argc < 2) {
810 return image_info (load_addr);
811 }
wdenk47d1a6e2002-11-03 00:01:44 +0000812
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100813 for (arg = 1; arg < argc; ++arg) {
814 addr = simple_strtoul (argv[arg], NULL, 16);
815 if (image_info (addr) != 0)
816 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000817 }
818 return rcode;
819}
wdenk47d1a6e2002-11-03 00:01:44 +0000820
wdenk47d1a6e2002-11-03 00:01:44 +0000821static int image_info (ulong addr)
822{
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100823 void *hdr = (void *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +0000824
wdenk47d1a6e2002-11-03 00:01:44 +0000825 printf ("\n## Checking Image at %08lx ...\n", addr);
wdenk47d1a6e2002-11-03 00:01:44 +0000826
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100827 switch (genimg_get_format (hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100828 case IMAGE_FORMAT_LEGACY:
829 puts (" Legacy image found\n");
830 if (!image_check_magic (hdr)) {
831 puts (" Bad Magic Number\n");
832 return 1;
833 }
wdenk47d1a6e2002-11-03 00:01:44 +0000834
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100835 if (!image_check_hcrc (hdr)) {
836 puts (" Bad Header Checksum\n");
837 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000838 }
839
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100840 image_print_contents (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000841
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100842 puts (" Verifying Checksum ... ");
843 if (!image_check_dcrc (hdr)) {
844 puts (" Bad Data CRC\n");
845 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000846 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100847 puts ("OK\n");
848 return 0;
849#if defined(CONFIG_FIT)
850 case IMAGE_FORMAT_FIT:
851 puts (" FIT image found\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000852
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100853 if (!fit_check_format (hdr)) {
854 puts ("Bad FIT image format!\n");
855 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000856 }
857
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100858 fit_print_contents (hdr);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100859 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000860#endif
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100861 default:
862 puts ("Unknown image format!\n");
863 break;
wdenk47d1a6e2002-11-03 00:01:44 +0000864 }
wdenk47d1a6e2002-11-03 00:01:44 +0000865
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100866 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000867}
wdenk47d1a6e2002-11-03 00:01:44 +0000868
wdenkf287a242003-07-01 21:06:45 +0000869U_BOOT_CMD(
870 iminfo, CFG_MAXARGS, 1, do_iminfo,
wdenk57b2d802003-06-27 21:31:46 +0000871 "iminfo - print header information for application image\n",
872 "addr [addr ...]\n"
873 " - print header information for application image starting at\n"
874 " address 'addr' in memory; this includes verification of the\n"
875 " image contents (magic number, header and payload checksums)\n"
876);
wdenk47d1a6e2002-11-03 00:01:44 +0000877#endif
878
879
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100880/*******************************************************************/
881/* imls - list all images found in flash */
882/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -0500883#if defined(CONFIG_CMD_IMLS)
wdenk874ac262003-07-24 23:38:38 +0000884int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
885{
886 flash_info_t *info;
887 int i, j;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100888 void *hdr;
wdenk47d1a6e2002-11-03 00:01:44 +0000889
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100890 for (i = 0, info = &flash_info[0];
891 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
wdenk47d1a6e2002-11-03 00:01:44 +0000892
wdenk874ac262003-07-24 23:38:38 +0000893 if (info->flash_id == FLASH_UNKNOWN)
894 goto next_bank;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100895 for (j = 0; j < info->sector_count; ++j) {
wdenk47d1a6e2002-11-03 00:01:44 +0000896
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100897 hdr = (void *)info->start[j];
898 if (!hdr)
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100899 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +0000900
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100901 switch (genimg_get_format (hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100902 case IMAGE_FORMAT_LEGACY:
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100903 if (!image_check_hcrc (hdr))
904 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +0000905
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100906 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
907 image_print_contents (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000908
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100909 puts (" Verifying Checksum ... ");
910 if (!image_check_dcrc (hdr)) {
911 puts ("Bad Data CRC\n");
912 } else {
913 puts ("OK\n");
914 }
915 break;
916#if defined(CONFIG_FIT)
917 case IMAGE_FORMAT_FIT:
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100918 if (!fit_check_format (hdr))
919 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +0000920
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100921 printf ("FIT Image at %08lX:\n", (ulong)hdr);
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100922 fit_print_contents (hdr);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100923 break;
924#endif
925 default:
926 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +0000927 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100928
wdenk0a658552003-08-05 17:43:17 +0000929next_sector: ;
wdenk47d1a6e2002-11-03 00:01:44 +0000930 }
wdenk0a658552003-08-05 17:43:17 +0000931next_bank: ;
wdenk47d1a6e2002-11-03 00:01:44 +0000932 }
933
wdenk874ac262003-07-24 23:38:38 +0000934 return (0);
935}
wdenk47d1a6e2002-11-03 00:01:44 +0000936
wdenk874ac262003-07-24 23:38:38 +0000937U_BOOT_CMD(
938 imls, 1, 1, do_imls,
939 "imls - list all images found in flash\n",
940 "\n"
941 " - Prints information about all images found at sector\n"
942 " boundaries in flash.\n"
943);
wdenk47d1a6e2002-11-03 00:01:44 +0000944#endif
945
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100946/*******************************************************************/
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100947/* helper routines */
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100948/*******************************************************************/
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100949#ifdef CONFIG_SILENT_CONSOLE
950static void fixup_silent_linux ()
951{
952 char buf[256], *start, *end;
953 char *cmdline = getenv ("bootargs");
wdenk47d1a6e2002-11-03 00:01:44 +0000954
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100955 /* Only fix cmdline when requested */
956 if (!(gd->flags & GD_FLG_SILENT))
957 return;
wdenk47d1a6e2002-11-03 00:01:44 +0000958
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100959 debug ("before silent fix-up: %s\n", cmdline);
960 if (cmdline) {
961 if ((start = strstr (cmdline, "console=")) != NULL) {
962 end = strchr (start, ' ');
963 strncpy (buf, cmdline, (start - cmdline + 8));
964 if (end)
965 strcpy (buf + (start - cmdline + 8), end);
966 else
967 buf[start - cmdline + 8] = '\0';
968 } else {
969 strcpy (buf, cmdline);
970 strcat (buf, " console=");
wdenk47d1a6e2002-11-03 00:01:44 +0000971 }
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100972 } else {
973 strcpy (buf, "console=");
wdenk47d1a6e2002-11-03 00:01:44 +0000974 }
wdenk47d1a6e2002-11-03 00:01:44 +0000975
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100976 setenv ("bootargs", buf);
977 debug ("after silent fix-up: %s\n", buf);
978}
979#endif /* CONFIG_SILENT_CONSOLE */
wdenk47d1a6e2002-11-03 00:01:44 +0000980
wdenk47d1a6e2002-11-03 00:01:44 +0000981
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100982/*******************************************************************/
983/* OS booting routines */
984/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +0000985
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100986static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100987 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100988 bootm_headers_t *images)
wdenk92bbe3f2003-04-20 14:04:18 +0000989{
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100990 void (*loader)(bd_t *, image_header_t *, char *, char *);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100991 image_header_t *os_hdr, *hdr;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100992 ulong kernel_data, kernel_len;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100993 char *consdev;
994 char *cmdline;
wdenk47d1a6e2002-11-03 00:01:44 +0000995
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100996#if defined(CONFIG_FIT)
997 if (!images->legacy_hdr_valid) {
998 fit_unsupported_reset ("NetBSD");
999 do_reset (cmdtp, flag, argc, argv);
wdenk47d1a6e2002-11-03 00:01:44 +00001000 }
1001#endif
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001002 hdr = images->legacy_hdr_os;
wdenk47d1a6e2002-11-03 00:01:44 +00001003
1004 /*
1005 * Booting a (NetBSD) kernel image
1006 *
1007 * This process is pretty similar to a standalone application:
1008 * The (first part of an multi-) image must be a stage-2 loader,
1009 * which in turn is responsible for loading & invoking the actual
1010 * kernel. The only differences are the parameters being passed:
1011 * besides the board info strucure, the loader expects a command
1012 * line, the name of the console device, and (optionally) the
1013 * address of the original image header.
1014 */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001015 os_hdr = NULL;
Marian Balakowiczab00e022008-04-11 11:07:49 +02001016 if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
Marian Balakowiczb4a12a92008-01-08 18:12:17 +01001017 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
1018 if (kernel_len)
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001019 os_hdr = hdr;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +01001020 }
wdenk47d1a6e2002-11-03 00:01:44 +00001021
1022 consdev = "";
1023#if defined (CONFIG_8xx_CONS_SMC1)
1024 consdev = "smc1";
1025#elif defined (CONFIG_8xx_CONS_SMC2)
1026 consdev = "smc2";
1027#elif defined (CONFIG_8xx_CONS_SCC2)
1028 consdev = "scc2";
1029#elif defined (CONFIG_8xx_CONS_SCC3)
1030 consdev = "scc3";
1031#endif
1032
1033 if (argc > 2) {
1034 ulong len;
1035 int i;
1036
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001037 for (i = 2, len = 0; i < argc; i += 1)
wdenk47d1a6e2002-11-03 00:01:44 +00001038 len += strlen (argv[i]) + 1;
1039 cmdline = malloc (len);
1040
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001041 for (i = 2, len = 0; i < argc; i += 1) {
wdenk47d1a6e2002-11-03 00:01:44 +00001042 if (i > 2)
1043 cmdline[len++] = ' ';
1044 strcpy (&cmdline[len], argv[i]);
1045 len += strlen (argv[i]);
1046 }
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001047 } else if ((cmdline = getenv ("bootargs")) == NULL) {
wdenk47d1a6e2002-11-03 00:01:44 +00001048 cmdline = "";
1049 }
1050
Kumar Gala93467bc2008-08-15 08:24:36 -05001051 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
wdenk47d1a6e2002-11-03 00:01:44 +00001052
1053 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
1054 (ulong)loader);
1055
1056 show_boot_progress (15);
1057
1058 /*
1059 * NetBSD Stage-2 Loader Parameters:
1060 * r3: ptr to board info data
1061 * r4: image address
1062 * r5: console device
1063 * r6: boot args string
1064 */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001065 (*loader) (gd->bd, os_hdr, consdev, cmdline);
wdenk47d1a6e2002-11-03 00:01:44 +00001066}
1067
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001068#ifdef CONFIG_LYNXKDI
1069static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
1070 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001071 bootm_headers_t *images)
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001072{
Marian Balakowiczab00e022008-04-11 11:07:49 +02001073 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001074
1075#if defined(CONFIG_FIT)
1076 if (!images->legacy_hdr_valid) {
1077 fit_unsupported_reset ("Lynx");
1078 do_reset (cmdtp, flag, argc, argv);
1079 }
1080#endif
1081
1082 lynxkdi_boot ((image_header_t *)hdr);
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001083}
1084#endif /* CONFIG_LYNXKDI */
1085
1086static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
1087 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001088 bootm_headers_t *images)
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001089{
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001090 void (*entry_point)(bd_t *);
wdenk92bbe3f2003-04-20 14:04:18 +00001091
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001092#if defined(CONFIG_FIT)
1093 if (!images->legacy_hdr_valid) {
1094 fit_unsupported_reset ("RTEMS");
1095 do_reset (cmdtp, flag, argc, argv);
1096 }
1097#endif
1098
Kumar Gala93467bc2008-08-15 08:24:36 -05001099 entry_point = (void (*)(bd_t *))images->ep;
wdenk47d1a6e2002-11-03 00:01:44 +00001100
wdenk92bbe3f2003-04-20 14:04:18 +00001101 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1102 (ulong)entry_point);
wdenk47d1a6e2002-11-03 00:01:44 +00001103
Heiko Schocher8a8ec532007-07-13 09:54:17 +02001104 show_boot_progress (15);
wdenk92bbe3f2003-04-20 14:04:18 +00001105
1106 /*
1107 * RTEMS Parameters:
1108 * r3: ptr to board info data
1109 */
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001110 (*entry_point)(gd->bd);
wdenk92bbe3f2003-04-20 14:04:18 +00001111}
1112
Jon Loeliger54324d02007-07-08 17:51:39 -05001113#if defined(CONFIG_CMD_ELF)
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001114static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
1115 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001116 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001117{
wdenk47d1a6e2002-11-03 00:01:44 +00001118 char str[80];
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001119
1120#if defined(CONFIG_FIT)
Marian Balakowiczab00e022008-04-11 11:07:49 +02001121 if (!images->legacy_hdr_valid) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001122 fit_unsupported_reset ("VxWorks");
1123 do_reset (cmdtp, flag, argc, argv);
1124 }
1125#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001126
Kumar Gala93467bc2008-08-15 08:24:36 -05001127 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001128 setenv("loadaddr", str);
1129 do_bootvx(cmdtp, 0, 0, NULL);
1130}
1131
Marian Balakowiczb4a12a92008-01-08 18:12:17 +01001132static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
1133 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001134 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001135{
wdenk47d1a6e2002-11-03 00:01:44 +00001136 char *local_args[2];
1137 char str[16];
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001138
1139#if defined(CONFIG_FIT)
1140 if (!images->legacy_hdr_valid) {
1141 fit_unsupported_reset ("QNX");
1142 do_reset (cmdtp, flag, argc, argv);
1143 }
1144#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001145
Kumar Gala93467bc2008-08-15 08:24:36 -05001146 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001147 local_args[0] = argv[0];
1148 local_args[1] = str; /* and provide it via the arguments */
1149 do_bootelf(cmdtp, 0, 2, local_args);
1150}
Jon Loeligerd704d912007-07-10 11:02:44 -05001151#endif
wdenke58b0dc2003-07-27 00:21:01 +00001152
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001153#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
1154static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
1155 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001156 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001157{
1158 ulong top;
1159 char *s, *cmdline;
1160 char **fwenv, **ss;
1161 int i, j, nxt, len, envno, envsz;
1162 bd_t *kbd;
1163 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001164
1165#if defined(CONFIG_FIT)
1166 if (!images->legacy_hdr_valid) {
1167 fit_unsupported_reset ("ARTOS");
1168 do_reset (cmdtp, flag, argc, argv);
1169 }
1170#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001171
1172 /*
1173 * Booting an ARTOS kernel image + application
1174 */
1175
1176 /* this used to be the top of memory, but was wrong... */
1177#ifdef CONFIG_PPC
1178 /* get stack pointer */
1179 asm volatile ("mr %0,1" : "=r"(top) );
1180#endif
1181 debug ("## Current stack ends at 0x%08lX ", top);
1182
1183 top -= 2048; /* just to be sure */
1184 if (top > CFG_BOOTMAPSZ)
1185 top = CFG_BOOTMAPSZ;
1186 top &= ~0xF;
1187
1188 debug ("=> set upper limit to 0x%08lX\n", top);
1189
1190 /* first check the artos specific boot args, then the linux args*/
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001191 if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
wdenk47d1a6e2002-11-03 00:01:44 +00001192 s = "";
1193
1194 /* get length of cmdline, and place it */
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001195 len = strlen (s);
wdenk47d1a6e2002-11-03 00:01:44 +00001196 top = (top - (len + 1)) & ~0xF;
1197 cmdline = (char *)top;
1198 debug ("## cmdline at 0x%08lX ", top);
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001199 strcpy (cmdline, s);
wdenk47d1a6e2002-11-03 00:01:44 +00001200
1201 /* copy bdinfo */
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001202 top = (top - sizeof (bd_t)) & ~0xF;
wdenk47d1a6e2002-11-03 00:01:44 +00001203 debug ("## bd at 0x%08lX ", top);
1204 kbd = (bd_t *)top;
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001205 memcpy (kbd, gd->bd, sizeof (bd_t));
wdenk47d1a6e2002-11-03 00:01:44 +00001206
1207 /* first find number of env entries, and their size */
1208 envno = 0;
1209 envsz = 0;
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001210 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1211 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
wdenk47d1a6e2002-11-03 00:01:44 +00001212 ;
1213 envno++;
1214 envsz += (nxt - i) + 1; /* plus trailing zero */
1215 }
1216 envno++; /* plus the terminating zero */
1217 debug ("## %u envvars total size %u ", envno, envsz);
1218
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001219 top = (top - sizeof (char **) * envno) & ~0xF;
wdenk47d1a6e2002-11-03 00:01:44 +00001220 fwenv = (char **)top;
1221 debug ("## fwenv at 0x%08lX ", top);
1222
1223 top = (top - envsz) & ~0xF;
1224 s = (char *)top;
1225 ss = fwenv;
1226
1227 /* now copy them */
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001228 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1229 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
wdenk47d1a6e2002-11-03 00:01:44 +00001230 ;
1231 *ss++ = s;
1232 for (j = i; j < nxt; ++j)
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001233 *s++ = env_get_char (j);
wdenk47d1a6e2002-11-03 00:01:44 +00001234 *s++ = '\0';
1235 }
1236 *ss++ = NULL; /* terminate */
1237
Kumar Gala93467bc2008-08-15 08:24:36 -05001238 entry = (void (*)(bd_t *, char *, char **, ulong))images->ep;
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001239 (*entry) (kbd, cmdline, fwenv, top);
wdenk47d1a6e2002-11-03 00:01:44 +00001240}
wdenk47d1a6e2002-11-03 00:01:44 +00001241#endif