blob: b073f095ba00610f978d0b4d22b6e69ee24861ae [file] [log] [blame]
wdenk47d1a6e2002-11-03 00:01:44 +00001/*
Detlev Zundelca95c9d2009-07-13 16:01:18 +02002 * (C) Copyright 2000-2009
wdenk47d1a6e2002-11-03 00:01:44 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010024
wdenk47d1a6e2002-11-03 00:01:44 +000025/*
26 * Boot support
27 */
28#include <common.h>
29#include <watchdog.h>
30#include <command.h>
wdenk47d1a6e2002-11-03 00:01:44 +000031#include <image.h>
32#include <malloc.h>
Jean-Christophe PLAGNIOL-VILLARDa31e0912009-04-04 12:49:11 +020033#include <u-boot/zlib.h>
wdenkc29fdfc2003-08-29 20:57:53 +000034#include <bzlib.h>
wdenk7f70e852003-05-20 14:25:27 +000035#include <environment.h>
Kumar Gala4ed65522008-02-27 21:51:47 -060036#include <lmb.h>
Kumar Gala49c3a862008-10-21 17:25:45 -050037#include <linux/ctype.h>
wdenk47d1a6e2002-11-03 00:01:44 +000038#include <asm/byteorder.h>
Anatolij Gustschin5bf27662011-11-19 13:12:18 +000039#include <linux/compiler.h>
wdenk8bde7f72003-06-27 21:31:46 +000040
Stefan Roeseebb86c42008-07-30 09:59:51 +020041#if defined(CONFIG_CMD_USB)
Markus Klotzbücher3d71c812008-07-10 14:47:09 +020042#include <usb.h>
43#endif
44
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020045#ifdef CONFIG_SYS_HUSH_PARSER
wdenk47d1a6e2002-11-03 00:01:44 +000046#include <hush.h>
47#endif
48
Kumar Gala54f9c862008-08-15 08:24:39 -050049#if defined(CONFIG_OF_LIBFDT)
50#include <fdt.h>
51#include <libfdt.h>
52#include <fdt_support.h>
53#endif
54
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +020055#ifdef CONFIG_LZMA
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +020056#include <lzma/LzmaTypes.h>
Luigi 'Comio' Mantellinicaf72ff2009-07-21 10:45:49 +020057#include <lzma/LzmaDec.h>
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +020058#include <lzma/LzmaTools.h>
59#endif /* CONFIG_LZMA */
60
Peter Korsgaard20dde482009-11-19 11:37:51 +010061#ifdef CONFIG_LZO
62#include <linux/lzo.h>
63#endif /* CONFIG_LZO */
64
Marian Balakowicz1ee11802008-01-08 18:17:10 +010065DECLARE_GLOBAL_DATA_PTR;
66
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020067#ifndef CONFIG_SYS_BOOTM_LEN
68#define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
wdenk47d1a6e2002-11-03 00:01:44 +000069#endif
70
Marian Balakowicz321359f2008-01-08 18:11:43 +010071#ifdef CONFIG_BZIP2
72extern void bz_internal_error(int);
wdenk228f29a2002-12-08 09:53:23 +000073#endif
74
Jon Loeligerbaa26db2007-07-08 17:51:39 -050075#if defined(CONFIG_CMD_IMI)
Stephen Warren712fbcf2011-10-18 11:11:49 +000076static int image_info(unsigned long addr);
wdenk47d1a6e2002-11-03 00:01:44 +000077#endif
wdenk27b207f2003-07-24 23:38:38 +000078
Jon Loeligerbaa26db2007-07-08 17:51:39 -050079#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +000080#include <flash.h>
Stefan Roeseca5def32010-08-31 10:00:10 +020081#include <mtd/cfi_flash.h>
Marian Balakowicze6f2e902005-10-11 19:09:42 +020082extern flash_info_t flash_info[]; /* info for FLASH chips */
Stephen Warren712fbcf2011-10-18 11:11:49 +000083static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
wdenk27b207f2003-07-24 23:38:38 +000084#endif
85
Marian Balakowicz1ee11802008-01-08 18:17:10 +010086#ifdef CONFIG_SILENT_CONSOLE
Stephen Warren712fbcf2011-10-18 11:11:49 +000087static void fixup_silent_linux(void);
wdenk2262cfe2002-11-18 00:14:45 +000088#endif
89
Stephen Warren712fbcf2011-10-18 11:11:49 +000090static image_header_t *image_get_kernel(ulong img_addr, int verify);
Marian Balakowicz6986a382008-03-12 10:01:05 +010091#if defined(CONFIG_FIT)
Stephen Warren712fbcf2011-10-18 11:11:49 +000092static int fit_check_kernel(const void *fit, int os_noffset, int verify);
Marian Balakowicz6986a382008-03-12 10:01:05 +010093#endif
94
Stephen Warren712fbcf2011-10-18 11:11:49 +000095static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
96 char * const argv[], bootm_headers_t *images,
97 ulong *os_data, ulong *os_len);
wdenk47d1a6e2002-11-03 00:01:44 +000098
wdenk47d1a6e2002-11-03 00:01:44 +000099/*
100 * Continue booting an OS image; caller already has:
101 * - copied image header to global variable `header'
102 * - checked header magic number, checksums (both header & image),
103 * - verified image architecture (PPC) and type (KERNEL or MULTI),
104 * - loaded (first part of) image to header load address,
105 * - disabled interrupts.
106 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000107typedef int boot_os_fn(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100108 bootm_headers_t *images); /* pointers to os/initrd/fdt */
wdenk47d1a6e2002-11-03 00:01:44 +0000109
Kumar Galab1d0db12008-10-21 17:25:47 -0500110#ifdef CONFIG_BOOTM_LINUX
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100111extern boot_os_fn do_bootm_linux;
Kumar Galab1d0db12008-10-21 17:25:47 -0500112#endif
113#ifdef CONFIG_BOOTM_NETBSD
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100114static boot_os_fn do_bootm_netbsd;
Kumar Galab1d0db12008-10-21 17:25:47 -0500115#endif
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100116#if defined(CONFIG_LYNXKDI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100117static boot_os_fn do_bootm_lynxkdi;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000118extern void lynxkdi_boot(image_header_t *);
wdenk8bde7f72003-06-27 21:31:46 +0000119#endif
Kumar Galab1d0db12008-10-21 17:25:47 -0500120#ifdef CONFIG_BOOTM_RTEMS
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100121static boot_os_fn do_bootm_rtems;
Kumar Galab1d0db12008-10-21 17:25:47 -0500122#endif
Torkel Lundgren3df61952010-09-28 11:05:36 +0200123#if defined(CONFIG_BOOTM_OSE)
124static boot_os_fn do_bootm_ose;
125#endif
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500126#if defined(CONFIG_CMD_ELF)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100127static boot_os_fn do_bootm_vxworks;
128static boot_os_fn do_bootm_qnxelf;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000129int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
130int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
Jon Loeliger90253172007-07-10 11:02:44 -0500131#endif
Peter Tyserf5ed9e32008-09-08 14:56:49 -0500132#if defined(CONFIG_INTEGRITY)
133static boot_os_fn do_bootm_integrity;
134#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000135
Mike Frysinger00085552009-11-03 11:36:26 -0500136static boot_os_fn *boot_os[] = {
Kumar Galab1d0db12008-10-21 17:25:47 -0500137#ifdef CONFIG_BOOTM_LINUX
Kumar Galabe083152008-10-21 17:25:44 -0500138 [IH_OS_LINUX] = do_bootm_linux,
Kumar Galab1d0db12008-10-21 17:25:47 -0500139#endif
140#ifdef CONFIG_BOOTM_NETBSD
Kumar Galabe083152008-10-21 17:25:44 -0500141 [IH_OS_NETBSD] = do_bootm_netbsd,
Kumar Galab1d0db12008-10-21 17:25:47 -0500142#endif
Kumar Galabe083152008-10-21 17:25:44 -0500143#ifdef CONFIG_LYNXKDI
144 [IH_OS_LYNXOS] = do_bootm_lynxkdi,
145#endif
Kumar Galab1d0db12008-10-21 17:25:47 -0500146#ifdef CONFIG_BOOTM_RTEMS
Kumar Galabe083152008-10-21 17:25:44 -0500147 [IH_OS_RTEMS] = do_bootm_rtems,
Kumar Galab1d0db12008-10-21 17:25:47 -0500148#endif
Torkel Lundgren3df61952010-09-28 11:05:36 +0200149#if defined(CONFIG_BOOTM_OSE)
150 [IH_OS_OSE] = do_bootm_ose,
151#endif
Kumar Galabe083152008-10-21 17:25:44 -0500152#if defined(CONFIG_CMD_ELF)
153 [IH_OS_VXWORKS] = do_bootm_vxworks,
154 [IH_OS_QNX] = do_bootm_qnxelf,
155#endif
156#ifdef CONFIG_INTEGRITY
157 [IH_OS_INTEGRITY] = do_bootm_integrity,
158#endif
159};
160
Simon Schwarzdee17762011-09-02 00:50:31 +0000161bootm_headers_t images; /* pointers to os/initrd/fdt images */
Stefan Roese15940c92006-03-13 11:16:36 +0100162
Kumar Gala3dfad402009-08-27 08:23:55 -0500163/* Allow for arch specific config before we boot */
164void __arch_preboot_os(void)
165{
166 /* please define platform specific arch_preboot_os() */
167}
168void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
169
Mike Frysinger476af292011-10-03 14:50:33 +0000170#define IH_INITRD_ARCH IH_ARCH_DEFAULT
wdenk47d1a6e2002-11-03 00:01:44 +0000171
Mike Frysingera16028d2009-11-03 11:35:59 -0500172static void bootm_start_lmb(void)
wdenk47d1a6e2002-11-03 00:01:44 +0000173{
Mike Frysingera16028d2009-11-03 11:35:59 -0500174#ifdef CONFIG_LMB
Becky Bruce391fd932008-06-09 20:37:18 -0500175 ulong mem_start;
176 phys_size_t mem_size;
wdenk47d1a6e2002-11-03 00:01:44 +0000177
Kumar Galae906cfa2008-08-15 08:24:40 -0500178 lmb_init(&images.lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000179
Kumar Galad3f2fa02008-02-27 21:51:50 -0600180 mem_start = getenv_bootm_low();
181 mem_size = getenv_bootm_size();
wdenk47d1a6e2002-11-03 00:01:44 +0000182
Kumar Galae906cfa2008-08-15 08:24:40 -0500183 lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
wdenk47d1a6e2002-11-03 00:01:44 +0000184
Kumar Gala76da19d2008-10-16 21:52:08 -0500185 arch_lmb_reserve(&images.lmb);
Kumar Galae906cfa2008-08-15 08:24:40 -0500186 board_lmb_reserve(&images.lmb);
Mike Frysingera16028d2009-11-03 11:35:59 -0500187#else
188# define lmb_reserve(lmb, base, size)
189#endif
190}
191
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200192static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Mike Frysingera16028d2009-11-03 11:35:59 -0500193{
194 void *os_hdr;
195 int ret;
196
Stephen Warren712fbcf2011-10-18 11:11:49 +0000197 memset((void *)&images, 0, sizeof(images));
198 images.verify = getenv_yesno("verify");
Mike Frysingera16028d2009-11-03 11:35:59 -0500199
200 bootm_start_lmb();
wdenk47d1a6e2002-11-03 00:01:44 +0000201
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100202 /* get kernel image header, start address and length */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000203 os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
Kumar Gala396f6352008-08-15 08:24:41 -0500204 &images, &images.os.image_start, &images.os.image_len);
205 if (images.os.image_len == 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000206 puts("ERROR: can't get kernel image!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000207 return 1;
208 }
wdenk47d1a6e2002-11-03 00:01:44 +0000209
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100210 /* get image parameters */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000211 switch (genimg_get_format(os_hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100212 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000213 images.os.type = image_get_type(os_hdr);
214 images.os.comp = image_get_comp(os_hdr);
215 images.os.os = image_get_os(os_hdr);
Wolfgang Denkbccae902005-10-06 01:50:50 +0200216
Stephen Warren712fbcf2011-10-18 11:11:49 +0000217 images.os.end = image_get_image_end(os_hdr);
218 images.os.load = image_get_load(os_hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100219 break;
220#if defined(CONFIG_FIT)
221 case IMAGE_FORMAT_FIT:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000222 if (fit_image_get_type(images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500223 images.fit_noffset_os, &images.os.type)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000224 puts("Can't get image type!\n");
225 show_boot_progress(-109);
wdenk47d1a6e2002-11-03 00:01:44 +0000226 return 1;
227 }
wdenk47d1a6e2002-11-03 00:01:44 +0000228
Stephen Warren712fbcf2011-10-18 11:11:49 +0000229 if (fit_image_get_comp(images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500230 images.fit_noffset_os, &images.os.comp)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000231 puts("Can't get image compression!\n");
232 show_boot_progress(-110);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100233 return 1;
234 }
wdenk47d1a6e2002-11-03 00:01:44 +0000235
Stephen Warren712fbcf2011-10-18 11:11:49 +0000236 if (fit_image_get_os(images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500237 images.fit_noffset_os, &images.os.os)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000238 puts("Can't get image OS!\n");
239 show_boot_progress(-111);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100240 return 1;
241 }
wdenk47d1a6e2002-11-03 00:01:44 +0000242
Stephen Warren712fbcf2011-10-18 11:11:49 +0000243 images.os.end = fit_get_end(images.fit_hdr_os);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100244
Stephen Warren712fbcf2011-10-18 11:11:49 +0000245 if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500246 &images.os.load)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000247 puts("Can't get image load address!\n");
248 show_boot_progress(-112);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100249 return 1;
wdenkb13fb012003-10-30 21:49:38 +0000250 }
251 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100252#endif
253 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000254 puts("ERROR: unknown image format type!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000255 return 1;
256 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100257
Kumar Galac160a952008-08-15 08:24:36 -0500258 /* find kernel entry point */
259 if (images.legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000260 images.ep = image_get_ep(&images.legacy_hdr_os_copy);
Kumar Galac160a952008-08-15 08:24:36 -0500261#if defined(CONFIG_FIT)
262 } else if (images.fit_uname_os) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000263 ret = fit_image_get_entry(images.fit_hdr_os,
Kumar Galac160a952008-08-15 08:24:36 -0500264 images.fit_noffset_os, &images.ep);
265 if (ret) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000266 puts("Can't get entry point property!\n");
Kumar Galac160a952008-08-15 08:24:36 -0500267 return 1;
268 }
269#endif
270 } else {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000271 puts("Could not find kernel entry point!\n");
Kumar Galac160a952008-08-15 08:24:36 -0500272 return 1;
273 }
274
Heiko Schocher24de2f42010-03-29 13:15:48 +0200275 if (((images.os.type == IH_TYPE_KERNEL) ||
276 (images.os.type == IH_TYPE_MULTI)) &&
Detlev Zundel8b828a82009-12-22 12:43:01 +0100277 (images.os.os == IH_OS_LINUX)) {
Kumar Galac4f94192008-08-15 08:24:37 -0500278 /* find ramdisk */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000279 ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH,
Kumar Galac4f94192008-08-15 08:24:37 -0500280 &images.rd_start, &images.rd_end);
281 if (ret) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000282 puts("Ramdisk image is corrupt or invalid\n");
Kumar Galac4f94192008-08-15 08:24:37 -0500283 return 1;
284 }
Kumar Gala06a09912008-08-15 08:24:38 -0500285
286#if defined(CONFIG_OF_LIBFDT)
287 /* find flattened device tree */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000288 ret = boot_get_fdt(flag, argc, argv, &images,
289 &images.ft_addr, &images.ft_len);
Kumar Gala06a09912008-08-15 08:24:38 -0500290 if (ret) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000291 puts("Could not find a valid device tree\n");
Kumar Gala06a09912008-08-15 08:24:38 -0500292 return 1;
293 }
Kumar Gala54f9c862008-08-15 08:24:39 -0500294
295 set_working_fdt_addr(images.ft_addr);
Kumar Gala06a09912008-08-15 08:24:38 -0500296#endif
Kumar Galac4f94192008-08-15 08:24:37 -0500297 }
298
Kumar Gala396f6352008-08-15 08:24:41 -0500299 images.os.start = (ulong)os_hdr;
Kumar Gala49c3a862008-10-21 17:25:45 -0500300 images.state = BOOTM_STATE_START;
Kumar Gala396f6352008-08-15 08:24:41 -0500301
302 return 0;
303}
304
305#define BOOTM_ERR_RESET -1
306#define BOOTM_ERR_OVERLAP -2
307#define BOOTM_ERR_UNIMPLEMENTED -3
308static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
309{
310 uint8_t comp = os.comp;
311 ulong load = os.load;
312 ulong blob_start = os.start;
313 ulong blob_end = os.end;
314 ulong image_start = os.image_start;
315 ulong image_len = os.image_len;
Anatolij Gustschin5bf27662011-11-19 13:12:18 +0000316 __maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN;
Matthias Weisser60fdc5f2010-08-05 13:17:30 +0200317#if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
318 int ret;
319#endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
Kumar Gala396f6352008-08-15 08:24:41 -0500320
Stephen Warren712fbcf2011-10-18 11:11:49 +0000321 const char *type_name = genimg_get_type_name(os.type);
Kumar Gala396f6352008-08-15 08:24:41 -0500322
323 switch (comp) {
324 case IH_COMP_NONE:
Lei Wen02cf3452011-01-10 18:21:15 +0800325 if (load == blob_start || load == image_start) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000326 printf(" XIP %s ... ", type_name);
Kumar Gala396f6352008-08-15 08:24:41 -0500327 } else {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000328 printf(" Loading %s ... ", type_name);
329 memmove_wd((void *)load, (void *)image_start,
Larry Johnson54fa2c52010-04-20 08:09:43 -0400330 image_len, CHUNKSZ);
Kumar Gala396f6352008-08-15 08:24:41 -0500331 }
332 *load_end = load + image_len;
333 puts("OK\n");
334 break;
Mike Frysinger44431ca2010-01-21 19:30:36 -0500335#ifdef CONFIG_GZIP
Kumar Gala396f6352008-08-15 08:24:41 -0500336 case IH_COMP_GZIP:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000337 printf(" Uncompressing %s ... ", type_name);
338 if (gunzip((void *)load, unc_len,
339 (uchar *)image_start, &image_len) != 0) {
340 puts("GUNZIP: uncompress, out-of-mem or overwrite "
341 "error - must RESET board to recover\n");
Kumar Gala396f6352008-08-15 08:24:41 -0500342 if (boot_progress)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000343 show_boot_progress(-6);
Kumar Gala396f6352008-08-15 08:24:41 -0500344 return BOOTM_ERR_RESET;
345 }
346
347 *load_end = load + image_len;
348 break;
Mike Frysinger44431ca2010-01-21 19:30:36 -0500349#endif /* CONFIG_GZIP */
Kumar Gala396f6352008-08-15 08:24:41 -0500350#ifdef CONFIG_BZIP2
351 case IH_COMP_BZIP2:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000352 printf(" Uncompressing %s ... ", type_name);
Kumar Gala396f6352008-08-15 08:24:41 -0500353 /*
354 * If we've got less than 4 MB of malloc() space,
355 * use slower decompression algorithm which requires
356 * at most 2300 KB of memory.
357 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000358 int i = BZ2_bzBuffToBuffDecompress((char *)load,
Kumar Gala396f6352008-08-15 08:24:41 -0500359 &unc_len, (char *)image_start, image_len,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200360 CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
Kumar Gala396f6352008-08-15 08:24:41 -0500361 if (i != BZ_OK) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000362 printf("BUNZIP2: uncompress or overwrite error %d "
Kumar Gala396f6352008-08-15 08:24:41 -0500363 "- must RESET board to recover\n", i);
364 if (boot_progress)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000365 show_boot_progress(-6);
Kumar Gala396f6352008-08-15 08:24:41 -0500366 return BOOTM_ERR_RESET;
367 }
368
369 *load_end = load + unc_len;
370 break;
371#endif /* CONFIG_BZIP2 */
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200372#ifdef CONFIG_LZMA
Mike Frysinger78e1e842010-07-25 15:54:17 -0400373 case IH_COMP_LZMA: {
374 SizeT lzma_len = unc_len;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000375 printf(" Uncompressing %s ... ", type_name);
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200376
Matthias Weisser60fdc5f2010-08-05 13:17:30 +0200377 ret = lzmaBuffToBuffDecompress(
Mike Frysinger78e1e842010-07-25 15:54:17 -0400378 (unsigned char *)load, &lzma_len,
Luigi 'Comio' Mantellinid977a572008-09-13 10:04:32 +0200379 (unsigned char *)image_start, image_len);
Mike Frysinger78e1e842010-07-25 15:54:17 -0400380 unc_len = lzma_len;
Luigi 'Comio' Mantellinicaf72ff2009-07-21 10:45:49 +0200381 if (ret != SZ_OK) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000382 printf("LZMA: uncompress or overwrite error %d "
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200383 "- must RESET board to recover\n", ret);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000384 show_boot_progress(-6);
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200385 return BOOTM_ERR_RESET;
386 }
387 *load_end = load + unc_len;
388 break;
Mike Frysinger78e1e842010-07-25 15:54:17 -0400389 }
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200390#endif /* CONFIG_LZMA */
Peter Korsgaard20dde482009-11-19 11:37:51 +0100391#ifdef CONFIG_LZO
392 case IH_COMP_LZO:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000393 printf(" Uncompressing %s ... ", type_name);
Peter Korsgaard20dde482009-11-19 11:37:51 +0100394
Matthias Weisser60fdc5f2010-08-05 13:17:30 +0200395 ret = lzop_decompress((const unsigned char *)image_start,
Peter Korsgaard20dde482009-11-19 11:37:51 +0100396 image_len, (unsigned char *)load,
397 &unc_len);
398 if (ret != LZO_E_OK) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000399 printf("LZO: uncompress or overwrite error %d "
Peter Korsgaard20dde482009-11-19 11:37:51 +0100400 "- must RESET board to recover\n", ret);
401 if (boot_progress)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000402 show_boot_progress(-6);
Peter Korsgaard20dde482009-11-19 11:37:51 +0100403 return BOOTM_ERR_RESET;
404 }
405
406 *load_end = load + unc_len;
407 break;
408#endif /* CONFIG_LZO */
Kumar Gala396f6352008-08-15 08:24:41 -0500409 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000410 printf("Unimplemented compression type %d\n", comp);
Kumar Gala396f6352008-08-15 08:24:41 -0500411 return BOOTM_ERR_UNIMPLEMENTED;
412 }
Diana CRACIUN99ffccb2011-08-31 02:45:23 +0000413
414 flush_cache(load, (*load_end - load) * sizeof(ulong));
415
Stephen Warren712fbcf2011-10-18 11:11:49 +0000416 puts("OK\n");
417 debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
Kumar Gala396f6352008-08-15 08:24:41 -0500418 if (boot_progress)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000419 show_boot_progress(7);
Kumar Gala396f6352008-08-15 08:24:41 -0500420
421 if ((load < blob_end) && (*load_end > blob_start)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000422 debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n",
423 blob_start, blob_end);
424 debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load,
425 *load_end);
Kumar Gala396f6352008-08-15 08:24:41 -0500426
427 return BOOTM_ERR_OVERLAP;
428 }
429
430 return 0;
431}
432
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200433static int bootm_start_standalone(ulong iflag, int argc, char * const argv[])
Detlev Zundelf97ec302009-07-13 16:01:19 +0200434{
435 char *s;
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200436 int (*appl)(int, char * const []);
Detlev Zundelf97ec302009-07-13 16:01:19 +0200437
438 /* Don't start if "autostart" is set to "no" */
439 if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
440 char buf[32];
441 sprintf(buf, "%lX", images.os.image_len);
442 setenv("filesize", buf);
443 return 0;
444 }
Simon Glass6d6f1232011-10-07 13:53:40 +0000445 appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep);
Detlev Zundelf97ec302009-07-13 16:01:19 +0200446 (*appl)(argc-1, &argv[1]);
Detlev Zundelf97ec302009-07-13 16:01:19 +0200447 return 0;
448}
449
Kumar Gala49c3a862008-10-21 17:25:45 -0500450/* we overload the cmd field with our state machine info instead of a
451 * function pointer */
Frans Meulenbroeksf74d9bd2010-02-25 10:12:13 +0100452static cmd_tbl_t cmd_bootm_sub[] = {
Kumar Gala49c3a862008-10-21 17:25:45 -0500453 U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
454 U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
John Rigbyfca43cc2010-10-13 13:57:35 -0600455#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
Kumar Gala49c3a862008-10-21 17:25:45 -0500456 U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
457#endif
458#ifdef CONFIG_OF_LIBFDT
459 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
460#endif
Kumar Gala49c3a862008-10-21 17:25:45 -0500461 U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
Peter Tyser224c90d2009-11-18 19:08:59 -0600462 U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
Kumar Gala49c3a862008-10-21 17:25:45 -0500463 U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
464 U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
465};
466
Stephen Warren712fbcf2011-10-18 11:11:49 +0000467int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
468 char * const argv[])
Kumar Gala49c3a862008-10-21 17:25:45 -0500469{
470 int ret = 0;
Simon Glass6d6f1232011-10-07 13:53:40 +0000471 long state;
Kumar Gala49c3a862008-10-21 17:25:45 -0500472 cmd_tbl_t *c;
473 boot_os_fn *boot_fn;
474
475 c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
476
477 if (c) {
Simon Glass6d6f1232011-10-07 13:53:40 +0000478 state = (long)c->cmd;
Kumar Gala49c3a862008-10-21 17:25:45 -0500479
480 /* treat start special since it resets the state machine */
481 if (state == BOOTM_STATE_START) {
482 argc--;
483 argv++;
484 return bootm_start(cmdtp, flag, argc, argv);
485 }
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200486 } else {
487 /* Unrecognized command */
488 return cmd_usage(cmdtp);
Kumar Gala49c3a862008-10-21 17:25:45 -0500489 }
490
491 if (images.state >= state) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000492 printf("Trying to execute a command out of order\n");
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200493 return cmd_usage(cmdtp);
Kumar Gala49c3a862008-10-21 17:25:45 -0500494 }
495
496 images.state |= state;
497 boot_fn = boot_os[images.os.os];
498
499 switch (state) {
500 ulong load_end;
501 case BOOTM_STATE_START:
502 /* should never occur */
503 break;
504 case BOOTM_STATE_LOADOS:
505 ret = bootm_load_os(images.os, &load_end, 0);
506 if (ret)
507 return ret;
508
509 lmb_reserve(&images.lmb, images.os.load,
510 (load_end - images.os.load));
511 break;
John Rigbyfca43cc2010-10-13 13:57:35 -0600512#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
Kumar Gala49c3a862008-10-21 17:25:45 -0500513 case BOOTM_STATE_RAMDISK:
514 {
515 ulong rd_len = images.rd_end - images.rd_start;
516 char str[17];
517
518 ret = boot_ramdisk_high(&images.lmb, images.rd_start,
519 rd_len, &images.initrd_start, &images.initrd_end);
520 if (ret)
521 return ret;
522
523 sprintf(str, "%lx", images.initrd_start);
524 setenv("initrd_start", str);
525 sprintf(str, "%lx", images.initrd_end);
526 setenv("initrd_end", str);
527 }
528 break;
529#endif
Grant Likelyed59e582011-03-28 09:58:49 +0000530#if defined(CONFIG_OF_LIBFDT)
Kumar Gala49c3a862008-10-21 17:25:45 -0500531 case BOOTM_STATE_FDT:
532 {
Grant Likely55b0a392011-03-28 09:59:01 +0000533 boot_fdt_add_mem_rsv_regions(&images.lmb,
534 images.ft_addr);
Grant Likely590d3ca2011-03-28 09:58:34 +0000535 ret = boot_relocate_fdt(&images.lmb,
Kumar Gala49c3a862008-10-21 17:25:45 -0500536 &images.ft_addr, &images.ft_len);
537 break;
538 }
539#endif
540 case BOOTM_STATE_OS_CMDLINE:
541 ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, &images);
542 if (ret)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000543 printf("cmdline subcommand not supported\n");
Kumar Gala49c3a862008-10-21 17:25:45 -0500544 break;
545 case BOOTM_STATE_OS_BD_T:
546 ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, &images);
547 if (ret)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000548 printf("bdt subcommand not supported\n");
Kumar Gala49c3a862008-10-21 17:25:45 -0500549 break;
550 case BOOTM_STATE_OS_PREP:
551 ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, &images);
552 if (ret)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000553 printf("prep subcommand not supported\n");
Kumar Gala49c3a862008-10-21 17:25:45 -0500554 break;
555 case BOOTM_STATE_OS_GO:
556 disable_interrupts();
Kumar Gala3dfad402009-08-27 08:23:55 -0500557 arch_preboot_os();
Kumar Gala49c3a862008-10-21 17:25:45 -0500558 boot_fn(BOOTM_STATE_OS_GO, argc, argv, &images);
559 break;
560 }
561
562 return ret;
563}
564
Kumar Gala396f6352008-08-15 08:24:41 -0500565/*******************************************************************/
566/* bootm - boot application image from image in memory */
567/*******************************************************************/
Kumar Galabe083152008-10-21 17:25:44 -0500568
Stephen Warren712fbcf2011-10-18 11:11:49 +0000569int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Kumar Gala396f6352008-08-15 08:24:41 -0500570{
Kumar Gala396f6352008-08-15 08:24:41 -0500571 ulong iflag;
572 ulong load_end = 0;
573 int ret;
Kumar Galabe083152008-10-21 17:25:44 -0500574 boot_os_fn *boot_fn;
Wolfgang Denk2e5167c2010-10-28 20:00:11 +0200575#ifdef CONFIG_NEEDS_MANUAL_RELOC
Peter Tyser521af042009-09-21 11:20:36 -0500576 static int relocated = 0;
Kumar Galabe083152008-10-21 17:25:44 -0500577
578 /* relocate boot function table */
579 if (!relocated) {
580 int i;
581 for (i = 0; i < ARRAY_SIZE(boot_os); i++)
Detlev Zundelca95c9d2009-07-13 16:01:18 +0200582 if (boot_os[i] != NULL)
583 boot_os[i] += gd->reloc_off;
Kumar Galabe083152008-10-21 17:25:44 -0500584 relocated = 1;
585 }
Peter Tyser521af042009-09-21 11:20:36 -0500586#endif
Kumar Gala396f6352008-08-15 08:24:41 -0500587
Kumar Gala49c3a862008-10-21 17:25:45 -0500588 /* determine if we have a sub command */
589 if (argc > 1) {
590 char *endp;
591
592 simple_strtoul(argv[1], &endp, 16);
593 /* endp pointing to NULL means that argv[1] was just a
594 * valid number, pass it along to the normal bootm processing
595 *
596 * If endp is ':' or '#' assume a FIT identifier so pass
597 * along for normal processing.
598 *
599 * Right now we assume the first arg should never be '-'
600 */
601 if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
602 return do_bootm_subcommand(cmdtp, flag, argc, argv);
603 }
604
Anatolij Gustschin8e024942008-08-29 21:04:45 +0200605 if (bootm_start(cmdtp, flag, argc, argv))
606 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000607
608 /*
609 * We have reached the point of no return: we are going to
610 * overwrite all exception vector code, so we cannot easily
611 * recover from any failures any more...
612 */
wdenk47d1a6e2002-11-03 00:01:44 +0000613 iflag = disable_interrupts();
614
Stefan Roeseebb86c42008-07-30 09:59:51 +0200615#if defined(CONFIG_CMD_USB)
Wolfgang Denk699f0512008-07-15 22:22:44 +0200616 /*
617 * turn off USB to prevent the host controller from writing to the
618 * SDRAM while Linux is booting. This could happen (at least for OHCI
619 * controller), because the HCCA (Host Controller Communication Area)
620 * lies within the SDRAM and the host controller writes continously to
621 * this area (as busmaster!). The HccaFrameNumber is for example
622 * updated every 1 ms within the HCCA structure in SDRAM! For more
623 * details see the OpenHCI specification.
624 */
Markus Klotzbücher3d71c812008-07-10 14:47:09 +0200625 usb_stop();
626#endif
627
Kumar Gala396f6352008-08-15 08:24:41 -0500628 ret = bootm_load_os(images.os, &load_end, 1);
wdenk47d1a6e2002-11-03 00:01:44 +0000629
Kumar Gala396f6352008-08-15 08:24:41 -0500630 if (ret < 0) {
631 if (ret == BOOTM_ERR_RESET)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000632 do_reset(cmdtp, flag, argc, argv);
Kumar Gala396f6352008-08-15 08:24:41 -0500633 if (ret == BOOTM_ERR_OVERLAP) {
634 if (images.legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000635 image_header_t *hdr;
636 hdr = &images.legacy_hdr_os_copy;
637 if (image_get_type(hdr) == IH_TYPE_MULTI)
638 puts("WARNING: legacy format multi "
639 "component image "
640 "overwritten\n");
Kumar Gala396f6352008-08-15 08:24:41 -0500641 } else {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000642 puts("ERROR: new format image overwritten - "
Kumar Gala396f6352008-08-15 08:24:41 -0500643 "must RESET the board to recover\n");
Stephen Warren712fbcf2011-10-18 11:11:49 +0000644 show_boot_progress(-113);
645 do_reset(cmdtp, flag, argc, argv);
Kumar Gala396f6352008-08-15 08:24:41 -0500646 }
wdenk47d1a6e2002-11-03 00:01:44 +0000647 }
Kumar Gala396f6352008-08-15 08:24:41 -0500648 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
649 if (iflag)
650 enable_interrupts();
Stephen Warren712fbcf2011-10-18 11:11:49 +0000651 show_boot_progress(-7);
Kumar Gala396f6352008-08-15 08:24:41 -0500652 return 1;
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200653 }
wdenk47d1a6e2002-11-03 00:01:44 +0000654 }
Marian Balakowicz75824382008-01-31 13:20:06 +0100655
Kumar Gala396f6352008-08-15 08:24:41 -0500656 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
657
Detlev Zundelf97ec302009-07-13 16:01:19 +0200658 if (images.os.type == IH_TYPE_STANDALONE) {
659 if (iflag)
660 enable_interrupts();
661 /* This may return when 'autostart' is 'no' */
662 bootm_start_standalone(iflag, argc, argv);
663 return 0;
664 }
665
Stephen Warren712fbcf2011-10-18 11:11:49 +0000666 show_boot_progress(8);
wdenk47d1a6e2002-11-03 00:01:44 +0000667
wdenkf72da342003-10-10 10:05:42 +0000668#ifdef CONFIG_SILENT_CONSOLE
Kumar Galabe083152008-10-21 17:25:44 -0500669 if (images.os.os == IH_OS_LINUX)
670 fixup_silent_linux();
wdenk1f4bb372003-07-27 00:21:01 +0000671#endif
672
Kumar Galabe083152008-10-21 17:25:44 -0500673 boot_fn = boot_os[images.os.os];
Detlev Zundelca95c9d2009-07-13 16:01:18 +0200674
675 if (boot_fn == NULL) {
676 if (iflag)
677 enable_interrupts();
Stephen Warren712fbcf2011-10-18 11:11:49 +0000678 printf("ERROR: booting os '%s' (%d) is not supported\n",
Detlev Zundelca95c9d2009-07-13 16:01:18 +0200679 genimg_get_os_name(images.os.os), images.os.os);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000680 show_boot_progress(-8);
Detlev Zundelca95c9d2009-07-13 16:01:18 +0200681 return 1;
682 }
683
Kumar Gala3dfad402009-08-27 08:23:55 -0500684 arch_preboot_os();
685
Kumar Galabe083152008-10-21 17:25:44 -0500686 boot_fn(0, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000687
Stephen Warren712fbcf2011-10-18 11:11:49 +0000688 show_boot_progress(-9);
wdenk47d1a6e2002-11-03 00:01:44 +0000689#ifdef DEBUG
Stephen Warren712fbcf2011-10-18 11:11:49 +0000690 puts("\n## Control returned to monitor - resetting...\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000691#endif
Stephen Warren712fbcf2011-10-18 11:11:49 +0000692 do_reset(cmdtp, flag, argc, argv);
Marian Balakowicza44a2692008-03-12 10:14:57 +0100693
wdenk47d1a6e2002-11-03 00:01:44 +0000694 return 1;
695}
696
Mike Frysinger67d668b2011-06-05 13:43:02 +0000697int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
698{
699 const char *ep = getenv("autostart");
700
701 if (ep && !strcmp(ep, "yes")) {
702 char *local_args[2];
703 local_args[0] = (char *)cmd;
704 local_args[1] = NULL;
705 printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
706 return do_bootm(cmdtp, 0, 1, local_args);
707 }
708
709 return 0;
710}
711
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100712/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100713 * image_get_kernel - verify legacy format kernel image
714 * @img_addr: in RAM address of the legacy format image to be verified
715 * @verify: data CRC verification flag
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100716 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100717 * image_get_kernel() verifies legacy image integrity and returns pointer to
718 * legacy image header if image verification was completed successfully.
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100719 *
720 * returns:
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100721 * pointer to a legacy image header if valid image was found
722 * otherwise return NULL
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100723 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000724static image_header_t *image_get_kernel(ulong img_addr, int verify)
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100725{
726 image_header_t *hdr = (image_header_t *)img_addr;
727
728 if (!image_check_magic(hdr)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000729 puts("Bad Magic Number\n");
730 show_boot_progress(-1);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100731 return NULL;
732 }
Stephen Warren712fbcf2011-10-18 11:11:49 +0000733 show_boot_progress(2);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100734
Stephen Warren712fbcf2011-10-18 11:11:49 +0000735 if (!image_check_hcrc(hdr)) {
736 puts("Bad Header Checksum\n");
737 show_boot_progress(-2);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100738 return NULL;
739 }
740
Stephen Warren712fbcf2011-10-18 11:11:49 +0000741 show_boot_progress(3);
742 image_print_contents(hdr);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100743
744 if (verify) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000745 puts(" Verifying Checksum ... ");
746 if (!image_check_dcrc(hdr)) {
747 printf("Bad Data CRC\n");
748 show_boot_progress(-3);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100749 return NULL;
750 }
Stephen Warren712fbcf2011-10-18 11:11:49 +0000751 puts("OK\n");
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100752 }
Stephen Warren712fbcf2011-10-18 11:11:49 +0000753 show_boot_progress(4);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100754
Stephen Warren712fbcf2011-10-18 11:11:49 +0000755 if (!image_check_target_arch(hdr)) {
756 printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr));
757 show_boot_progress(-4);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100758 return NULL;
759 }
760 return hdr;
761}
762
763/**
Marian Balakowicz6986a382008-03-12 10:01:05 +0100764 * fit_check_kernel - verify FIT format kernel subimage
765 * @fit_hdr: pointer to the FIT image header
766 * os_noffset: kernel subimage node offset within FIT image
767 * @verify: data CRC verification flag
768 *
769 * fit_check_kernel() verifies integrity of the kernel subimage and from
770 * specified FIT image.
771 *
772 * returns:
773 * 1, on success
774 * 0, on failure
775 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000776#if defined(CONFIG_FIT)
777static int fit_check_kernel(const void *fit, int os_noffset, int verify)
Marian Balakowicz6986a382008-03-12 10:01:05 +0100778{
Stephen Warren712fbcf2011-10-18 11:11:49 +0000779 fit_image_print(fit, os_noffset, " ");
Marian Balakowicz6986a382008-03-12 10:01:05 +0100780
781 if (verify) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000782 puts(" Verifying Hash Integrity ... ");
783 if (!fit_image_check_hashes(fit, os_noffset)) {
784 puts("Bad Data Hash\n");
785 show_boot_progress(-104);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100786 return 0;
787 }
Stephen Warren712fbcf2011-10-18 11:11:49 +0000788 puts("OK\n");
Marian Balakowicz6986a382008-03-12 10:01:05 +0100789 }
Stephen Warren712fbcf2011-10-18 11:11:49 +0000790 show_boot_progress(105);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100791
Stephen Warren712fbcf2011-10-18 11:11:49 +0000792 if (!fit_image_check_target_arch(fit, os_noffset)) {
793 puts("Unsupported Architecture\n");
794 show_boot_progress(-105);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100795 return 0;
796 }
797
Stephen Warren712fbcf2011-10-18 11:11:49 +0000798 show_boot_progress(106);
799 if (!fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL)) {
800 puts("Not a kernel image\n");
801 show_boot_progress(-106);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100802 return 0;
803 }
804
Stephen Warren712fbcf2011-10-18 11:11:49 +0000805 show_boot_progress(107);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100806 return 1;
807}
808#endif /* CONFIG_FIT */
809
810/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100811 * boot_get_kernel - find kernel image
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100812 * @os_data: pointer to a ulong variable, will hold os data start address
813 * @os_len: pointer to a ulong variable, will hold os data length
814 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100815 * boot_get_kernel() tries to find a kernel image, verifies its integrity
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100816 * and locates kernel data.
817 *
818 * returns:
819 * pointer to image header if valid image was found, plus kernel start
820 * address and length, otherwise NULL
821 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000822static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
823 char * const argv[], bootm_headers_t *images, ulong *os_data,
824 ulong *os_len)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100825{
826 image_header_t *hdr;
827 ulong img_addr;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100828#if defined(CONFIG_FIT)
829 void *fit_hdr;
830 const char *fit_uname_config = NULL;
831 const char *fit_uname_kernel = NULL;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100832 const void *data;
833 size_t len;
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100834 int cfg_noffset;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100835 int os_noffset;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100836#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100837
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100838 /* find out kernel image address */
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100839 if (argc < 2) {
840 img_addr = load_addr;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000841 debug("* kernel: default image load address = 0x%08lx\n",
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100842 load_addr);
843#if defined(CONFIG_FIT)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000844 } else if (fit_parse_conf(argv[1], load_addr, &img_addr,
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100845 &fit_uname_config)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000846 debug("* kernel: config '%s' from image at 0x%08lx\n",
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100847 fit_uname_config, img_addr);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000848 } else if (fit_parse_subimage(argv[1], load_addr, &img_addr,
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100849 &fit_uname_kernel)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000850 debug("* kernel: subimage '%s' from image at 0x%08lx\n",
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100851 fit_uname_kernel, img_addr);
852#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100853 } else {
854 img_addr = simple_strtoul(argv[1], NULL, 16);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000855 debug("* kernel: cmdline image address = 0x%08lx\n", img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100856 }
857
Stephen Warren712fbcf2011-10-18 11:11:49 +0000858 show_boot_progress(1);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100859
Marian Balakowiczfff888a12008-02-21 17:20:19 +0100860 /* copy from dataflash if needed */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000861 img_addr = genimg_get_image(img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100862
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100863 /* check image type, for FIT images get FIT kernel node */
Marian Balakowicz6986a382008-03-12 10:01:05 +0100864 *os_data = *os_len = 0;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000865 switch (genimg_get_format((void *)img_addr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100866 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000867 printf("## Booting kernel from Legacy Image at %08lx ...\n",
Marian Balakowicz6986a382008-03-12 10:01:05 +0100868 img_addr);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000869 hdr = image_get_kernel(img_addr, images->verify);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100870 if (!hdr)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100871 return NULL;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000872 show_boot_progress(5);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100873
Marian Balakowicz6986a382008-03-12 10:01:05 +0100874 /* get os_data and os_len */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000875 switch (image_get_type(hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100876 case IH_TYPE_KERNEL:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000877 *os_data = image_get_data(hdr);
878 *os_len = image_get_data_size(hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100879 break;
880 case IH_TYPE_MULTI:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000881 image_multi_getimg(hdr, 0, os_data, os_len);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100882 break;
Detlev Zundelf97ec302009-07-13 16:01:19 +0200883 case IH_TYPE_STANDALONE:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000884 *os_data = image_get_data(hdr);
885 *os_len = image_get_data_size(hdr);
Detlev Zundelf97ec302009-07-13 16:01:19 +0200886 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100887 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000888 printf("Wrong Image Type for %s command\n",
889 cmdtp->name);
890 show_boot_progress(-5);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100891 return NULL;
892 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100893
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200894 /*
Stephen Warren712fbcf2011-10-18 11:11:49 +0000895 * copy image header to allow for image overwrites during
896 * kernel decompression.
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200897 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000898 memmove(&images->legacy_hdr_os_copy, hdr,
899 sizeof(image_header_t));
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200900
901 /* save pointer to image header */
902 images->legacy_hdr_os = hdr;
903
904 images->legacy_hdr_valid = 1;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000905 show_boot_progress(6);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100906 break;
907#if defined(CONFIG_FIT)
908 case IMAGE_FORMAT_FIT:
909 fit_hdr = (void *)img_addr;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000910 printf("## Booting kernel from FIT Image at %08lx ...\n",
Marian Balakowicz6986a382008-03-12 10:01:05 +0100911 img_addr);
912
Stephen Warren712fbcf2011-10-18 11:11:49 +0000913 if (!fit_check_format(fit_hdr)) {
914 puts("Bad FIT kernel image format!\n");
915 show_boot_progress(-100);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100916 return NULL;
917 }
Stephen Warren712fbcf2011-10-18 11:11:49 +0000918 show_boot_progress(100);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100919
920 if (!fit_uname_kernel) {
921 /*
922 * no kernel image node unit name, try to get config
923 * node first. If config unit node name is NULL
Stephen Warren712fbcf2011-10-18 11:11:49 +0000924 * fit_conf_get_node() will try to find default config
925 * node
Marian Balakowicz6986a382008-03-12 10:01:05 +0100926 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000927 show_boot_progress(101);
928 cfg_noffset = fit_conf_get_node(fit_hdr,
929 fit_uname_config);
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100930 if (cfg_noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000931 show_boot_progress(-101);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100932 return NULL;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100933 }
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100934 /* save configuration uname provided in the first
935 * bootm argument
936 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000937 images->fit_uname_cfg = fdt_get_name(fit_hdr,
938 cfg_noffset,
939 NULL);
940 printf(" Using '%s' configuration\n",
941 images->fit_uname_cfg);
942 show_boot_progress(103);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100943
Stephen Warren712fbcf2011-10-18 11:11:49 +0000944 os_noffset = fit_conf_get_kernel_node(fit_hdr,
945 cfg_noffset);
946 fit_uname_kernel = fit_get_name(fit_hdr, os_noffset,
947 NULL);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100948 } else {
949 /* get kernel component image node offset */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000950 show_boot_progress(102);
951 os_noffset = fit_image_get_node(fit_hdr,
952 fit_uname_kernel);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100953 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100954 if (os_noffset < 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000955 show_boot_progress(-103);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100956 return NULL;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100957 }
Marian Balakowicz6986a382008-03-12 10:01:05 +0100958
Stephen Warren712fbcf2011-10-18 11:11:49 +0000959 printf(" Trying '%s' kernel subimage\n", fit_uname_kernel);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100960
Stephen Warren712fbcf2011-10-18 11:11:49 +0000961 show_boot_progress(104);
962 if (!fit_check_kernel(fit_hdr, os_noffset, images->verify))
Marian Balakowicz6986a382008-03-12 10:01:05 +0100963 return NULL;
964
965 /* get kernel image data address and length */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000966 if (fit_image_get_data(fit_hdr, os_noffset, &data, &len)) {
967 puts("Could not find kernel subimage data!\n");
968 show_boot_progress(-107);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100969 return NULL;
970 }
Stephen Warren712fbcf2011-10-18 11:11:49 +0000971 show_boot_progress(108);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100972
973 *os_len = len;
974 *os_data = (ulong)data;
975 images->fit_hdr_os = fit_hdr;
976 images->fit_uname_os = fit_uname_kernel;
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100977 images->fit_noffset_os = os_noffset;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100978 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100979#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100980 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000981 printf("Wrong Image Format for %s command\n", cmdtp->name);
982 show_boot_progress(-108);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100983 return NULL;
984 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100985
Stephen Warren712fbcf2011-10-18 11:11:49 +0000986 debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
Marian Balakowicz6986a382008-03-12 10:01:05 +0100987 *os_data, *os_len, *os_len);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100988
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100989 return (void *)img_addr;
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100990}
991
wdenk0d498392003-07-01 21:06:45 +0000992U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200993 bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
Peter Tyser2fb26042009-01-27 18:03:12 -0600994 "boot application image from memory",
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100995 "[addr [arg ...]]\n - boot application image stored in memory\n"
996 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
997 "\t'arg' can be the address of an initrd image\n"
Marian Balakowicz4a2ad5f2008-01-31 13:20:07 +0100998#if defined(CONFIG_OF_LIBFDT)
Matthew McClintock98a9c4d2006-06-28 10:41:37 -0500999 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
Detlev Zundel5441f612007-10-19 16:47:26 +02001000 "\ta third argument is required which is the address of the\n"
Matthew McClintock98a9c4d2006-06-28 10:41:37 -05001001 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1002 "\tuse a '-' for the second argument. If you do not pass a third\n"
1003 "\ta bd_info struct will be passed instead\n"
1004#endif
Marian Balakowicz6986a382008-03-12 10:01:05 +01001005#if defined(CONFIG_FIT)
1006 "\t\nFor the new multi component uImage format (FIT) addresses\n"
1007 "\tmust be extened to include component or configuration unit name:\n"
1008 "\taddr:<subimg_uname> - direct component image specification\n"
1009 "\taddr#<conf_uname> - configuration specification\n"
1010 "\tUse iminfo command to get the list of existing component\n"
1011 "\timages and configurations.\n"
1012#endif
Kumar Gala49c3a862008-10-21 17:25:45 -05001013 "\nSub-commands to do part of the bootm sequence. The sub-commands "
1014 "must be\n"
1015 "issued in the order below (it's ok to not issue all sub-commands):\n"
1016 "\tstart [addr [arg ...]]\n"
1017 "\tloados - load OS image\n"
1018#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
1019 "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
1020#endif
1021#if defined(CONFIG_OF_LIBFDT)
1022 "\tfdt - relocate flat device tree\n"
1023#endif
Kumar Gala49c3a862008-10-21 17:25:45 -05001024 "\tcmdline - OS specific command line processing/setup\n"
Peter Tyser224c90d2009-11-18 19:08:59 -06001025 "\tbdt - OS specific bd_t processing\n"
Kumar Gala49c3a862008-10-21 17:25:45 -05001026 "\tprep - OS specific prep before relocation or go\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001027 "\tgo - start OS"
wdenk8bde7f72003-06-27 21:31:46 +00001028);
1029
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001030/*******************************************************************/
1031/* bootd - boot default image */
1032/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -05001033#if defined(CONFIG_CMD_BOOTD)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001034int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk47d1a6e2002-11-03 00:01:44 +00001035{
1036 int rcode = 0;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001037
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001038#ifndef CONFIG_SYS_HUSH_PARSER
Stephen Warren712fbcf2011-10-18 11:11:49 +00001039 if (run_command(getenv("bootcmd"), flag) < 0)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001040 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001041#else
Stephen Warren712fbcf2011-10-18 11:11:49 +00001042 if (parse_string_outer(getenv("bootcmd"),
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001043 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
1044 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001045#endif
1046 return rcode;
1047}
wdenk8bde7f72003-06-27 21:31:46 +00001048
wdenk0d498392003-07-01 21:06:45 +00001049U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001050 boot, 1, 1, do_bootd,
Peter Tyser2fb26042009-01-27 18:03:12 -06001051 "boot default, i.e., run 'bootcmd'",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001052 ""
wdenk9d2b18a2003-06-28 23:11:04 +00001053);
1054
1055/* keep old command name "bootd" for backward compatibility */
wdenk0d498392003-07-01 21:06:45 +00001056U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001057 bootd, 1, 1, do_bootd,
Peter Tyser2fb26042009-01-27 18:03:12 -06001058 "boot default, i.e., run 'bootcmd'",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001059 ""
wdenk8bde7f72003-06-27 21:31:46 +00001060);
1061
wdenk47d1a6e2002-11-03 00:01:44 +00001062#endif
1063
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001064
1065/*******************************************************************/
1066/* iminfo - print header info for a requested image */
1067/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -05001068#if defined(CONFIG_CMD_IMI)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001069int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk47d1a6e2002-11-03 00:01:44 +00001070{
1071 int arg;
1072 ulong addr;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001073 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +00001074
1075 if (argc < 2) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001076 return image_info(load_addr);
wdenk47d1a6e2002-11-03 00:01:44 +00001077 }
1078
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001079 for (arg = 1; arg < argc; ++arg) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001080 addr = simple_strtoul(argv[arg], NULL, 16);
1081 if (image_info(addr) != 0)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001082 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001083 }
1084 return rcode;
1085}
1086
Stephen Warren712fbcf2011-10-18 11:11:49 +00001087static int image_info(ulong addr)
wdenk47d1a6e2002-11-03 00:01:44 +00001088{
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001089 void *hdr = (void *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +00001090
Stephen Warren712fbcf2011-10-18 11:11:49 +00001091 printf("\n## Checking Image at %08lx ...\n", addr);
wdenk47d1a6e2002-11-03 00:01:44 +00001092
Stephen Warren712fbcf2011-10-18 11:11:49 +00001093 switch (genimg_get_format(hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001094 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001095 puts(" Legacy image found\n");
1096 if (!image_check_magic(hdr)) {
1097 puts(" Bad Magic Number\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001098 return 1;
1099 }
1100
Stephen Warren712fbcf2011-10-18 11:11:49 +00001101 if (!image_check_hcrc(hdr)) {
1102 puts(" Bad Header Checksum\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001103 return 1;
1104 }
1105
Stephen Warren712fbcf2011-10-18 11:11:49 +00001106 image_print_contents(hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001107
Stephen Warren712fbcf2011-10-18 11:11:49 +00001108 puts(" Verifying Checksum ... ");
1109 if (!image_check_dcrc(hdr)) {
1110 puts(" Bad Data CRC\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001111 return 1;
1112 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00001113 puts("OK\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001114 return 0;
1115#if defined(CONFIG_FIT)
1116 case IMAGE_FORMAT_FIT:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001117 puts(" FIT image found\n");
Marian Balakowicze32fea62008-03-11 12:35:20 +01001118
Stephen Warren712fbcf2011-10-18 11:11:49 +00001119 if (!fit_check_format(hdr)) {
1120 puts("Bad FIT image format!\n");
Marian Balakowicze32fea62008-03-11 12:35:20 +01001121 return 1;
1122 }
1123
Stephen Warren712fbcf2011-10-18 11:11:49 +00001124 fit_print_contents(hdr);
Bartlomiej Siekaa4f24342008-09-09 12:58:16 +02001125
Stephen Warren712fbcf2011-10-18 11:11:49 +00001126 if (!fit_all_image_check_hashes(hdr)) {
1127 puts("Bad hash in FIT image!\n");
Bartlomiej Siekaa4f24342008-09-09 12:58:16 +02001128 return 1;
1129 }
1130
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001131 return 0;
1132#endif
1133 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001134 puts("Unknown image format!\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001135 break;
wdenk47d1a6e2002-11-03 00:01:44 +00001136 }
1137
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001138 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001139}
wdenk0d498392003-07-01 21:06:45 +00001140
1141U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001142 iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
Peter Tyser2fb26042009-01-27 18:03:12 -06001143 "print header information for application image",
wdenk8bde7f72003-06-27 21:31:46 +00001144 "addr [addr ...]\n"
1145 " - print header information for application image starting at\n"
1146 " address 'addr' in memory; this includes verification of the\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001147 " image contents (magic number, header and payload checksums)"
wdenk8bde7f72003-06-27 21:31:46 +00001148);
Jon Loeliger90253172007-07-10 11:02:44 -05001149#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001150
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001151
1152/*******************************************************************/
1153/* imls - list all images found in flash */
1154/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -05001155#if defined(CONFIG_CMD_IMLS)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001156int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk27b207f2003-07-24 23:38:38 +00001157{
1158 flash_info_t *info;
1159 int i, j;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001160 void *hdr;
wdenk27b207f2003-07-24 23:38:38 +00001161
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001162 for (i = 0, info = &flash_info[0];
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001163 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001164
wdenk27b207f2003-07-24 23:38:38 +00001165 if (info->flash_id == FLASH_UNKNOWN)
1166 goto next_bank;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001167 for (j = 0; j < info->sector_count; ++j) {
wdenk27b207f2003-07-24 23:38:38 +00001168
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001169 hdr = (void *)info->start[j];
1170 if (!hdr)
wdenk27b207f2003-07-24 23:38:38 +00001171 goto next_sector;
1172
Stephen Warren712fbcf2011-10-18 11:11:49 +00001173 switch (genimg_get_format(hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001174 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001175 if (!image_check_hcrc(hdr))
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001176 goto next_sector;
1177
Stephen Warren712fbcf2011-10-18 11:11:49 +00001178 printf("Legacy Image at %08lX:\n", (ulong)hdr);
1179 image_print_contents(hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001180
Stephen Warren712fbcf2011-10-18 11:11:49 +00001181 puts(" Verifying Checksum ... ");
1182 if (!image_check_dcrc(hdr)) {
1183 puts("Bad Data CRC\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001184 } else {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001185 puts("OK\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001186 }
1187 break;
1188#if defined(CONFIG_FIT)
1189 case IMAGE_FORMAT_FIT:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001190 if (!fit_check_format(hdr))
Marian Balakowicze32fea62008-03-11 12:35:20 +01001191 goto next_sector;
1192
Stephen Warren712fbcf2011-10-18 11:11:49 +00001193 printf("FIT Image at %08lX:\n", (ulong)hdr);
1194 fit_print_contents(hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001195 break;
1196#endif
1197 default:
wdenk27b207f2003-07-24 23:38:38 +00001198 goto next_sector;
wdenk5bb226e2003-11-17 21:14:37 +00001199 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001200
wdenkbdccc4f2003-08-05 17:43:17 +00001201next_sector: ;
wdenk27b207f2003-07-24 23:38:38 +00001202 }
wdenkbdccc4f2003-08-05 17:43:17 +00001203next_bank: ;
wdenk27b207f2003-07-24 23:38:38 +00001204 }
1205
1206 return (0);
1207}
1208
1209U_BOOT_CMD(
1210 imls, 1, 1, do_imls,
Peter Tyser2fb26042009-01-27 18:03:12 -06001211 "list all images found in flash",
wdenk27b207f2003-07-24 23:38:38 +00001212 "\n"
1213 " - Prints information about all images found at sector\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001214 " boundaries in flash."
wdenk27b207f2003-07-24 23:38:38 +00001215);
Jon Loeliger90253172007-07-10 11:02:44 -05001216#endif
wdenk27b207f2003-07-24 23:38:38 +00001217
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001218/*******************************************************************/
Marian Balakowicz5cf746c2008-01-31 13:59:09 +01001219/* helper routines */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001220/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +00001221#ifdef CONFIG_SILENT_CONSOLE
Doug Anderson3a8653b2011-10-19 12:30:57 +00001222static void fixup_silent_linux(void)
wdenk47d1a6e2002-11-03 00:01:44 +00001223{
1224 char buf[256], *start, *end;
Doug Anderson3a8653b2011-10-19 12:30:57 +00001225 char *cmdline = getenv("bootargs");
wdenk47d1a6e2002-11-03 00:01:44 +00001226
1227 /* Only fix cmdline when requested */
1228 if (!(gd->flags & GD_FLG_SILENT))
1229 return;
1230
Doug Anderson3a8653b2011-10-19 12:30:57 +00001231 debug("before silent fix-up: %s\n", cmdline);
wdenk47d1a6e2002-11-03 00:01:44 +00001232 if (cmdline) {
Doug Anderson3a8653b2011-10-19 12:30:57 +00001233 start = strstr(cmdline, "console=");
1234 if (start) {
1235 end = strchr(start, ' ');
1236 strncpy(buf, cmdline, (start - cmdline + 8));
wdenk47d1a6e2002-11-03 00:01:44 +00001237 if (end)
Doug Anderson3a8653b2011-10-19 12:30:57 +00001238 strcpy(buf + (start - cmdline + 8), end);
wdenk47d1a6e2002-11-03 00:01:44 +00001239 else
1240 buf[start - cmdline + 8] = '\0';
1241 } else {
Doug Anderson3a8653b2011-10-19 12:30:57 +00001242 strcpy(buf, cmdline);
1243 strcat(buf, " console=");
wdenk47d1a6e2002-11-03 00:01:44 +00001244 }
1245 } else {
Doug Anderson3a8653b2011-10-19 12:30:57 +00001246 strcpy(buf, "console=");
wdenk47d1a6e2002-11-03 00:01:44 +00001247 }
1248
Doug Anderson3a8653b2011-10-19 12:30:57 +00001249 setenv("bootargs", buf);
1250 debug("after silent fix-up: %s\n", buf);
wdenk47d1a6e2002-11-03 00:01:44 +00001251}
1252#endif /* CONFIG_SILENT_CONSOLE */
1253
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001254
1255/*******************************************************************/
1256/* OS booting routines */
1257/*******************************************************************/
1258
Kumar Galab1d0db12008-10-21 17:25:47 -05001259#ifdef CONFIG_BOOTM_NETBSD
Stephen Warren712fbcf2011-10-18 11:11:49 +00001260static int do_bootm_netbsd(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001261 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001262{
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001263 void (*loader)(bd_t *, image_header_t *, char *, char *);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001264 image_header_t *os_hdr, *hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001265 ulong kernel_data, kernel_len;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001266 char *consdev;
1267 char *cmdline;
wdenk47d1a6e2002-11-03 00:01:44 +00001268
Kumar Gala49c3a862008-10-21 17:25:45 -05001269 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1270 return 1;
1271
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001272#if defined(CONFIG_FIT)
1273 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001274 fit_unsupported_reset("NetBSD");
Kumar Gala40d7e992008-08-15 08:24:45 -05001275 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001276 }
1277#endif
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001278 hdr = images->legacy_hdr_os;
wdenk47d1a6e2002-11-03 00:01:44 +00001279
1280 /*
1281 * Booting a (NetBSD) kernel image
1282 *
1283 * This process is pretty similar to a standalone application:
1284 * The (first part of an multi-) image must be a stage-2 loader,
1285 * which in turn is responsible for loading & invoking the actual
1286 * kernel. The only differences are the parameters being passed:
1287 * besides the board info strucure, the loader expects a command
1288 * line, the name of the console device, and (optionally) the
1289 * address of the original image header.
1290 */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001291 os_hdr = NULL;
Stephen Warren712fbcf2011-10-18 11:11:49 +00001292 if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1293 image_multi_getimg(hdr, 1, &kernel_data, &kernel_len);
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001294 if (kernel_len)
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001295 os_hdr = hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001296 }
wdenk47d1a6e2002-11-03 00:01:44 +00001297
1298 consdev = "";
Stephen Warren712fbcf2011-10-18 11:11:49 +00001299#if defined(CONFIG_8xx_CONS_SMC1)
wdenk47d1a6e2002-11-03 00:01:44 +00001300 consdev = "smc1";
Stephen Warren712fbcf2011-10-18 11:11:49 +00001301#elif defined(CONFIG_8xx_CONS_SMC2)
wdenk47d1a6e2002-11-03 00:01:44 +00001302 consdev = "smc2";
Stephen Warren712fbcf2011-10-18 11:11:49 +00001303#elif defined(CONFIG_8xx_CONS_SCC2)
wdenk47d1a6e2002-11-03 00:01:44 +00001304 consdev = "scc2";
Stephen Warren712fbcf2011-10-18 11:11:49 +00001305#elif defined(CONFIG_8xx_CONS_SCC3)
wdenk47d1a6e2002-11-03 00:01:44 +00001306 consdev = "scc3";
1307#endif
1308
1309 if (argc > 2) {
1310 ulong len;
1311 int i;
1312
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001313 for (i = 2, len = 0; i < argc; i += 1)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001314 len += strlen(argv[i]) + 1;
1315 cmdline = malloc(len);
wdenk47d1a6e2002-11-03 00:01:44 +00001316
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001317 for (i = 2, len = 0; i < argc; i += 1) {
wdenk47d1a6e2002-11-03 00:01:44 +00001318 if (i > 2)
1319 cmdline[len++] = ' ';
Stephen Warren712fbcf2011-10-18 11:11:49 +00001320 strcpy(&cmdline[len], argv[i]);
1321 len += strlen(argv[i]);
wdenk47d1a6e2002-11-03 00:01:44 +00001322 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00001323 } else if ((cmdline = getenv("bootargs")) == NULL) {
wdenk47d1a6e2002-11-03 00:01:44 +00001324 cmdline = "";
1325 }
1326
Kumar Galac160a952008-08-15 08:24:36 -05001327 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
wdenk47d1a6e2002-11-03 00:01:44 +00001328
Stephen Warren712fbcf2011-10-18 11:11:49 +00001329 printf("## Transferring control to NetBSD stage-2 loader "
1330 "(at address %08lx) ...\n",
wdenk47d1a6e2002-11-03 00:01:44 +00001331 (ulong)loader);
1332
Stephen Warren712fbcf2011-10-18 11:11:49 +00001333 show_boot_progress(15);
wdenk47d1a6e2002-11-03 00:01:44 +00001334
1335 /*
1336 * NetBSD Stage-2 Loader Parameters:
1337 * r3: ptr to board info data
1338 * r4: image address
1339 * r5: console device
1340 * r6: boot args string
1341 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001342 (*loader)(gd->bd, os_hdr, consdev, cmdline);
Kumar Gala40d7e992008-08-15 08:24:45 -05001343
1344 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001345}
Kumar Galab1d0db12008-10-21 17:25:47 -05001346#endif /* CONFIG_BOOTM_NETBSD*/
wdenk47d1a6e2002-11-03 00:01:44 +00001347
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001348#ifdef CONFIG_LYNXKDI
Stephen Warren712fbcf2011-10-18 11:11:49 +00001349static int do_bootm_lynxkdi(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001350 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001351{
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001352 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001353
Kumar Gala49c3a862008-10-21 17:25:45 -05001354 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1355 return 1;
1356
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001357#if defined(CONFIG_FIT)
1358 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001359 fit_unsupported_reset("Lynx");
Kumar Gala40d7e992008-08-15 08:24:45 -05001360 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001361 }
1362#endif
1363
Stephen Warren712fbcf2011-10-18 11:11:49 +00001364 lynxkdi_boot((image_header_t *)hdr);
Kumar Gala40d7e992008-08-15 08:24:45 -05001365
1366 return 1;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001367}
1368#endif /* CONFIG_LYNXKDI */
1369
Kumar Galab1d0db12008-10-21 17:25:47 -05001370#ifdef CONFIG_BOOTM_RTEMS
Stephen Warren712fbcf2011-10-18 11:11:49 +00001371static int do_bootm_rtems(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001372 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001373{
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001374 void (*entry_point)(bd_t *);
wdenkd791b1d2003-04-20 14:04:18 +00001375
Kumar Gala49c3a862008-10-21 17:25:45 -05001376 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1377 return 1;
1378
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001379#if defined(CONFIG_FIT)
1380 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001381 fit_unsupported_reset("RTEMS");
Kumar Gala40d7e992008-08-15 08:24:45 -05001382 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001383 }
1384#endif
1385
Kumar Galac160a952008-08-15 08:24:36 -05001386 entry_point = (void (*)(bd_t *))images->ep;
wdenkd791b1d2003-04-20 14:04:18 +00001387
Stephen Warren712fbcf2011-10-18 11:11:49 +00001388 printf("## Transferring control to RTEMS (at address %08lx) ...\n",
wdenkd791b1d2003-04-20 14:04:18 +00001389 (ulong)entry_point);
1390
Stephen Warren712fbcf2011-10-18 11:11:49 +00001391 show_boot_progress(15);
wdenkd791b1d2003-04-20 14:04:18 +00001392
1393 /*
1394 * RTEMS Parameters:
1395 * r3: ptr to board info data
1396 */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001397 (*entry_point)(gd->bd);
Kumar Gala40d7e992008-08-15 08:24:45 -05001398
1399 return 1;
wdenkd791b1d2003-04-20 14:04:18 +00001400}
Kumar Galab1d0db12008-10-21 17:25:47 -05001401#endif /* CONFIG_BOOTM_RTEMS */
wdenkd791b1d2003-04-20 14:04:18 +00001402
Torkel Lundgren3df61952010-09-28 11:05:36 +02001403#if defined(CONFIG_BOOTM_OSE)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001404static int do_bootm_ose(int flag, int argc, char * const argv[],
Torkel Lundgren3df61952010-09-28 11:05:36 +02001405 bootm_headers_t *images)
1406{
1407 void (*entry_point)(void);
1408
1409 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1410 return 1;
1411
1412#if defined(CONFIG_FIT)
1413 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001414 fit_unsupported_reset("OSE");
Torkel Lundgren3df61952010-09-28 11:05:36 +02001415 return 1;
1416 }
1417#endif
1418
1419 entry_point = (void (*)(void))images->ep;
1420
Stephen Warren712fbcf2011-10-18 11:11:49 +00001421 printf("## Transferring control to OSE (at address %08lx) ...\n",
Torkel Lundgren3df61952010-09-28 11:05:36 +02001422 (ulong)entry_point);
1423
Stephen Warren712fbcf2011-10-18 11:11:49 +00001424 show_boot_progress(15);
Torkel Lundgren3df61952010-09-28 11:05:36 +02001425
1426 /*
1427 * OSE Parameters:
1428 * None
1429 */
1430 (*entry_point)();
1431
1432 return 1;
1433}
1434#endif /* CONFIG_BOOTM_OSE */
1435
Jon Loeligerbaa26db2007-07-08 17:51:39 -05001436#if defined(CONFIG_CMD_ELF)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001437static int do_bootm_vxworks(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001438 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001439{
wdenk47d1a6e2002-11-03 00:01:44 +00001440 char str[80];
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001441
Kumar Gala49c3a862008-10-21 17:25:45 -05001442 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1443 return 1;
1444
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001445#if defined(CONFIG_FIT)
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001446 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001447 fit_unsupported_reset("VxWorks");
Kumar Gala40d7e992008-08-15 08:24:45 -05001448 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001449 }
1450#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001451
Kumar Galac160a952008-08-15 08:24:36 -05001452 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001453 setenv("loadaddr", str);
Kumar Gala40d7e992008-08-15 08:24:45 -05001454 do_bootvx(NULL, 0, 0, NULL);
1455
1456 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001457}
1458
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001459static int do_bootm_qnxelf(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001460 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001461{
wdenk47d1a6e2002-11-03 00:01:44 +00001462 char *local_args[2];
1463 char str[16];
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001464
Kumar Gala49c3a862008-10-21 17:25:45 -05001465 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1466 return 1;
1467
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001468#if defined(CONFIG_FIT)
1469 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001470 fit_unsupported_reset("QNX");
Kumar Gala40d7e992008-08-15 08:24:45 -05001471 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001472 }
1473#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001474
Kumar Galac160a952008-08-15 08:24:36 -05001475 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001476 local_args[0] = argv[0];
1477 local_args[1] = str; /* and provide it via the arguments */
Kumar Gala40d7e992008-08-15 08:24:45 -05001478 do_bootelf(NULL, 0, 2, local_args);
1479
1480 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001481}
Jon Loeliger90253172007-07-10 11:02:44 -05001482#endif
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001483
1484#ifdef CONFIG_INTEGRITY
Stephen Warren712fbcf2011-10-18 11:11:49 +00001485static int do_bootm_integrity(int flag, int argc, char * const argv[],
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001486 bootm_headers_t *images)
1487{
1488 void (*entry_point)(void);
1489
Kumar Gala49c3a862008-10-21 17:25:45 -05001490 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1491 return 1;
1492
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001493#if defined(CONFIG_FIT)
1494 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001495 fit_unsupported_reset("INTEGRITY");
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001496 return 1;
1497 }
1498#endif
1499
1500 entry_point = (void (*)(void))images->ep;
1501
Stephen Warren712fbcf2011-10-18 11:11:49 +00001502 printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001503 (ulong)entry_point);
1504
Stephen Warren712fbcf2011-10-18 11:11:49 +00001505 show_boot_progress(15);
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001506
1507 /*
1508 * INTEGRITY Parameters:
1509 * None
1510 */
1511 (*entry_point)();
1512
1513 return 1;
1514}
1515#endif