blob: c06f4b730f363e64826531dc2d3fd8b0b85a51cf [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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk47d1a6e2002-11-03 00:01:44 +00006 */
7
Marian Balakowiczb97a2a02008-01-08 18:14:09 +01008
wdenk47d1a6e2002-11-03 00:01:44 +00009/*
10 * Boot support
11 */
12#include <common.h>
13#include <watchdog.h>
14#include <command.h>
wdenk47d1a6e2002-11-03 00:01:44 +000015#include <image.h>
16#include <malloc.h>
Jean-Christophe PLAGNIOL-VILLARDa31e0912009-04-04 12:49:11 +020017#include <u-boot/zlib.h>
wdenkc29fdfc2003-08-29 20:57:53 +000018#include <bzlib.h>
wdenk7f70e852003-05-20 14:25:27 +000019#include <environment.h>
Kumar Gala4ed65522008-02-27 21:51:47 -060020#include <lmb.h>
Kumar Gala49c3a862008-10-21 17:25:45 -050021#include <linux/ctype.h>
wdenk47d1a6e2002-11-03 00:01:44 +000022#include <asm/byteorder.h>
Simon Glass35e7b0f2013-05-07 06:12:03 +000023#include <asm/io.h>
Anatolij Gustschin5bf27662011-11-19 13:12:18 +000024#include <linux/compiler.h>
wdenk8bde7f72003-06-27 21:31:46 +000025
Miao Yan871a57b2013-11-28 17:51:38 +080026#if defined(CONFIG_BOOTM_VXWORKS) && \
27 (defined(CONFIG_PPC) || defined(CONFIG_ARM))
28#include <vxworks.h>
29#endif
30
Stefan Roeseebb86c42008-07-30 09:59:51 +020031#if defined(CONFIG_CMD_USB)
Markus Klotzbücher3d71c812008-07-10 14:47:09 +020032#include <usb.h>
33#endif
34
Kumar Gala54f9c862008-08-15 08:24:39 -050035#if defined(CONFIG_OF_LIBFDT)
Kumar Gala54f9c862008-08-15 08:24:39 -050036#include <libfdt.h>
37#include <fdt_support.h>
38#endif
39
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +020040#ifdef CONFIG_LZMA
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +020041#include <lzma/LzmaTypes.h>
Luigi 'Comio' Mantellinicaf72ff2009-07-21 10:45:49 +020042#include <lzma/LzmaDec.h>
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +020043#include <lzma/LzmaTools.h>
44#endif /* CONFIG_LZMA */
45
Peter Korsgaard20dde482009-11-19 11:37:51 +010046#ifdef CONFIG_LZO
47#include <linux/lzo.h>
48#endif /* CONFIG_LZO */
49
Marian Balakowicz1ee11802008-01-08 18:17:10 +010050DECLARE_GLOBAL_DATA_PTR;
51
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020052#ifndef CONFIG_SYS_BOOTM_LEN
53#define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
wdenk47d1a6e2002-11-03 00:01:44 +000054#endif
55
Marian Balakowicz321359f2008-01-08 18:11:43 +010056#ifdef CONFIG_BZIP2
57extern void bz_internal_error(int);
wdenk228f29a2002-12-08 09:53:23 +000058#endif
59
Jon Loeligerbaa26db2007-07-08 17:51:39 -050060#if defined(CONFIG_CMD_IMI)
Stephen Warren712fbcf2011-10-18 11:11:49 +000061static int image_info(unsigned long addr);
wdenk47d1a6e2002-11-03 00:01:44 +000062#endif
wdenk27b207f2003-07-24 23:38:38 +000063
Jon Loeligerbaa26db2007-07-08 17:51:39 -050064#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +000065#include <flash.h>
Stefan Roeseca5def32010-08-31 10:00:10 +020066#include <mtd/cfi_flash.h>
Marian Balakowicze6f2e902005-10-11 19:09:42 +020067extern flash_info_t flash_info[]; /* info for FLASH chips */
Vipin Kumar8fdf1e02012-12-16 22:32:48 +000068#endif
69
70#if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
Stephen Warren712fbcf2011-10-18 11:11:49 +000071static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
wdenk27b207f2003-07-24 23:38:38 +000072#endif
73
Vipin Kumar8fdf1e02012-12-16 22:32:48 +000074#include <linux/err.h>
75#include <nand.h>
76
Joe Hershbergerbe2e5a02013-02-27 10:20:59 +000077#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
Stephen Warren712fbcf2011-10-18 11:11:49 +000078static void fixup_silent_linux(void);
wdenk2262cfe2002-11-18 00:14:45 +000079#endif
80
Simon Glassc5cbe1e2013-12-26 16:26:24 -070081static int do_bootm_standalone(int flag, int argc, char * const argv[],
82 bootm_headers_t *images);
83
Simon Glass35e7b0f2013-05-07 06:12:03 +000084static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
Stephen Warren712fbcf2011-10-18 11:11:49 +000085 char * const argv[], bootm_headers_t *images,
86 ulong *os_data, ulong *os_len);
wdenk47d1a6e2002-11-03 00:01:44 +000087
wdenk47d1a6e2002-11-03 00:01:44 +000088/*
89 * Continue booting an OS image; caller already has:
90 * - copied image header to global variable `header'
91 * - checked header magic number, checksums (both header & image),
92 * - verified image architecture (PPC) and type (KERNEL or MULTI),
93 * - loaded (first part of) image to header load address,
94 * - disabled interrupts.
Simon Glass983c72f2013-06-11 11:14:46 -070095 *
Simon Glass35fc84f2013-06-11 11:14:47 -070096 * @flag: Flags indicating what to do (BOOTM_STATE_...)
Simon Glass983c72f2013-06-11 11:14:46 -070097 * @argc: Number of arguments. Note that the arguments are shifted down
98 * so that 0 is the first argument not processed by U-Boot, and
99 * argc is adjusted accordingly. This avoids confusion as to how
100 * many arguments are available for the OS.
101 * @images: Pointers to os/initrd/fdt
102 * @return 1 on error. On success the OS boots so this function does
103 * not return.
wdenk47d1a6e2002-11-03 00:01:44 +0000104 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000105typedef int boot_os_fn(int flag, int argc, char * const argv[],
Simon Glass983c72f2013-06-11 11:14:46 -0700106 bootm_headers_t *images);
wdenk47d1a6e2002-11-03 00:01:44 +0000107
Kumar Galab1d0db12008-10-21 17:25:47 -0500108#ifdef CONFIG_BOOTM_LINUX
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100109extern boot_os_fn do_bootm_linux;
Kumar Galab1d0db12008-10-21 17:25:47 -0500110#endif
111#ifdef CONFIG_BOOTM_NETBSD
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100112static boot_os_fn do_bootm_netbsd;
Kumar Galab1d0db12008-10-21 17:25:47 -0500113#endif
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100114#if defined(CONFIG_LYNXKDI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100115static boot_os_fn do_bootm_lynxkdi;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000116extern void lynxkdi_boot(image_header_t *);
wdenk8bde7f72003-06-27 21:31:46 +0000117#endif
Kumar Galab1d0db12008-10-21 17:25:47 -0500118#ifdef CONFIG_BOOTM_RTEMS
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100119static boot_os_fn do_bootm_rtems;
Kumar Galab1d0db12008-10-21 17:25:47 -0500120#endif
Torkel Lundgren3df61952010-09-28 11:05:36 +0200121#if defined(CONFIG_BOOTM_OSE)
122static boot_os_fn do_bootm_ose;
123#endif
Steven Stallion04d41402013-03-20 06:31:35 +0000124#if defined(CONFIG_BOOTM_PLAN9)
125static boot_os_fn do_bootm_plan9;
126#endif
Miao Yan871a57b2013-11-28 17:51:38 +0800127#if defined(CONFIG_BOOTM_VXWORKS) && \
128 (defined(CONFIG_PPC) || defined(CONFIG_ARM))
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100129static boot_os_fn do_bootm_vxworks;
Miao Yan17ab52f2013-11-28 17:51:36 +0800130#endif
131#if defined(CONFIG_CMD_ELF)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100132static boot_os_fn do_bootm_qnxelf;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000133int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
134int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
Jon Loeliger90253172007-07-10 11:02:44 -0500135#endif
Peter Tyserf5ed9e32008-09-08 14:56:49 -0500136#if defined(CONFIG_INTEGRITY)
137static boot_os_fn do_bootm_integrity;
138#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000139
Mike Frysinger00085552009-11-03 11:36:26 -0500140static boot_os_fn *boot_os[] = {
Simon Glassc5cbe1e2013-12-26 16:26:24 -0700141 [IH_OS_U_BOOT] = do_bootm_standalone,
Kumar Galab1d0db12008-10-21 17:25:47 -0500142#ifdef CONFIG_BOOTM_LINUX
Kumar Galabe083152008-10-21 17:25:44 -0500143 [IH_OS_LINUX] = do_bootm_linux,
Kumar Galab1d0db12008-10-21 17:25:47 -0500144#endif
145#ifdef CONFIG_BOOTM_NETBSD
Kumar Galabe083152008-10-21 17:25:44 -0500146 [IH_OS_NETBSD] = do_bootm_netbsd,
Kumar Galab1d0db12008-10-21 17:25:47 -0500147#endif
Kumar Galabe083152008-10-21 17:25:44 -0500148#ifdef CONFIG_LYNXKDI
149 [IH_OS_LYNXOS] = do_bootm_lynxkdi,
150#endif
Kumar Galab1d0db12008-10-21 17:25:47 -0500151#ifdef CONFIG_BOOTM_RTEMS
Kumar Galabe083152008-10-21 17:25:44 -0500152 [IH_OS_RTEMS] = do_bootm_rtems,
Kumar Galab1d0db12008-10-21 17:25:47 -0500153#endif
Torkel Lundgren3df61952010-09-28 11:05:36 +0200154#if defined(CONFIG_BOOTM_OSE)
155 [IH_OS_OSE] = do_bootm_ose,
156#endif
Steven Stallion04d41402013-03-20 06:31:35 +0000157#if defined(CONFIG_BOOTM_PLAN9)
158 [IH_OS_PLAN9] = do_bootm_plan9,
159#endif
Miao Yan871a57b2013-11-28 17:51:38 +0800160#if defined(CONFIG_BOOTM_VXWORKS) && \
161 (defined(CONFIG_PPC) || defined(CONFIG_ARM))
Kumar Galabe083152008-10-21 17:25:44 -0500162 [IH_OS_VXWORKS] = do_bootm_vxworks,
Miao Yan17ab52f2013-11-28 17:51:36 +0800163#endif
164#if defined(CONFIG_CMD_ELF)
Kumar Galabe083152008-10-21 17:25:44 -0500165 [IH_OS_QNX] = do_bootm_qnxelf,
166#endif
167#ifdef CONFIG_INTEGRITY
168 [IH_OS_INTEGRITY] = do_bootm_integrity,
169#endif
170};
171
Simon Schwarzdee17762011-09-02 00:50:31 +0000172bootm_headers_t images; /* pointers to os/initrd/fdt images */
Stefan Roese15940c92006-03-13 11:16:36 +0100173
Kumar Gala3dfad402009-08-27 08:23:55 -0500174/* Allow for arch specific config before we boot */
Kim Phillips088f1b12012-10-29 13:34:31 +0000175static void __arch_preboot_os(void)
Kumar Gala3dfad402009-08-27 08:23:55 -0500176{
177 /* please define platform specific arch_preboot_os() */
178}
179void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
180
Mike Frysinger476af292011-10-03 14:50:33 +0000181#define IH_INITRD_ARCH IH_ARCH_DEFAULT
wdenk47d1a6e2002-11-03 00:01:44 +0000182
Mike Frysingera16028d2009-11-03 11:35:59 -0500183#ifdef CONFIG_LMB
Marek Vasut44f074c2012-03-14 21:52:45 +0000184static void boot_start_lmb(bootm_headers_t *images)
185{
Becky Bruce391fd932008-06-09 20:37:18 -0500186 ulong mem_start;
187 phys_size_t mem_size;
wdenk47d1a6e2002-11-03 00:01:44 +0000188
Marek Vasut44f074c2012-03-14 21:52:45 +0000189 lmb_init(&images->lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000190
Kumar Galad3f2fa02008-02-27 21:51:50 -0600191 mem_start = getenv_bootm_low();
192 mem_size = getenv_bootm_size();
wdenk47d1a6e2002-11-03 00:01:44 +0000193
Marek Vasut44f074c2012-03-14 21:52:45 +0000194 lmb_add(&images->lmb, (phys_addr_t)mem_start, mem_size);
wdenk47d1a6e2002-11-03 00:01:44 +0000195
Marek Vasut44f074c2012-03-14 21:52:45 +0000196 arch_lmb_reserve(&images->lmb);
197 board_lmb_reserve(&images->lmb);
Mike Frysingera16028d2009-11-03 11:35:59 -0500198}
Marek Vasut44f074c2012-03-14 21:52:45 +0000199#else
Marek Vasut35cf5fe2012-04-01 03:59:46 +0000200#define lmb_reserve(lmb, base, size)
Marek Vasut44f074c2012-03-14 21:52:45 +0000201static inline void boot_start_lmb(bootm_headers_t *images) { }
202#endif
Mike Frysingera16028d2009-11-03 11:35:59 -0500203
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200204static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Mike Frysingera16028d2009-11-03 11:35:59 -0500205{
Stephen Warren712fbcf2011-10-18 11:11:49 +0000206 memset((void *)&images, 0, sizeof(images));
207 images.verify = getenv_yesno("verify");
Mike Frysingera16028d2009-11-03 11:35:59 -0500208
Marek Vasut44f074c2012-03-14 21:52:45 +0000209 boot_start_lmb(&images);
wdenk47d1a6e2002-11-03 00:01:44 +0000210
Simon Glass573f14f2011-12-10 11:08:06 +0000211 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_START, "bootm_start");
Simon Glass35fc84f2013-06-11 11:14:47 -0700212 images.state = BOOTM_STATE_START;
213
214 return 0;
215}
216
217static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,
218 char * const argv[])
219{
220 const void *os_hdr;
Sebastian Siewior9ace3fc2014-05-05 15:08:09 -0500221 bool ep_found = false;
Simon Glass573f14f2011-12-10 11:08:06 +0000222
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100223 /* get kernel image header, start address and length */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000224 os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
Kumar Gala396f6352008-08-15 08:24:41 -0500225 &images, &images.os.image_start, &images.os.image_len);
226 if (images.os.image_len == 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000227 puts("ERROR: can't get kernel image!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000228 return 1;
229 }
wdenk47d1a6e2002-11-03 00:01:44 +0000230
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100231 /* get image parameters */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000232 switch (genimg_get_format(os_hdr)) {
Heiko Schocher21d29f72014-05-28 11:33:33 +0200233#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100234 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000235 images.os.type = image_get_type(os_hdr);
236 images.os.comp = image_get_comp(os_hdr);
237 images.os.os = image_get_os(os_hdr);
Wolfgang Denkbccae902005-10-06 01:50:50 +0200238
Stephen Warren712fbcf2011-10-18 11:11:49 +0000239 images.os.end = image_get_image_end(os_hdr);
240 images.os.load = image_get_load(os_hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100241 break;
Heiko Schocher21d29f72014-05-28 11:33:33 +0200242#endif
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100243#if defined(CONFIG_FIT)
244 case IMAGE_FORMAT_FIT:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000245 if (fit_image_get_type(images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500246 images.fit_noffset_os, &images.os.type)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000247 puts("Can't get image type!\n");
Simon Glass770605e2012-02-13 13:51:18 +0000248 bootstage_error(BOOTSTAGE_ID_FIT_TYPE);
wdenk47d1a6e2002-11-03 00:01:44 +0000249 return 1;
250 }
wdenk47d1a6e2002-11-03 00:01:44 +0000251
Stephen Warren712fbcf2011-10-18 11:11:49 +0000252 if (fit_image_get_comp(images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500253 images.fit_noffset_os, &images.os.comp)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000254 puts("Can't get image compression!\n");
Simon Glass770605e2012-02-13 13:51:18 +0000255 bootstage_error(BOOTSTAGE_ID_FIT_COMPRESSION);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100256 return 1;
257 }
wdenk47d1a6e2002-11-03 00:01:44 +0000258
Stephen Warren712fbcf2011-10-18 11:11:49 +0000259 if (fit_image_get_os(images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500260 images.fit_noffset_os, &images.os.os)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000261 puts("Can't get image OS!\n");
Simon Glass770605e2012-02-13 13:51:18 +0000262 bootstage_error(BOOTSTAGE_ID_FIT_OS);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100263 return 1;
264 }
wdenk47d1a6e2002-11-03 00:01:44 +0000265
Stephen Warren712fbcf2011-10-18 11:11:49 +0000266 images.os.end = fit_get_end(images.fit_hdr_os);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100267
Stephen Warren712fbcf2011-10-18 11:11:49 +0000268 if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500269 &images.os.load)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000270 puts("Can't get image load address!\n");
Simon Glass770605e2012-02-13 13:51:18 +0000271 bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100272 return 1;
wdenkb13fb012003-10-30 21:49:38 +0000273 }
274 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100275#endif
Sebastian Siewior9ace3fc2014-05-05 15:08:09 -0500276#ifdef CONFIG_ANDROID_BOOT_IMAGE
277 case IMAGE_FORMAT_ANDROID:
278 images.os.type = IH_TYPE_KERNEL;
279 images.os.comp = IH_COMP_NONE;
280 images.os.os = IH_OS_LINUX;
281 images.ep = images.os.load;
282 ep_found = true;
283
284 images.os.end = android_image_get_end(os_hdr);
285 images.os.load = android_image_get_kload(os_hdr);
286 break;
287#endif
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100288 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000289 puts("ERROR: unknown image format type!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000290 return 1;
291 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100292
Kumar Galac160a952008-08-15 08:24:36 -0500293 /* find kernel entry point */
294 if (images.legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000295 images.ep = image_get_ep(&images.legacy_hdr_os_copy);
Kumar Galac160a952008-08-15 08:24:36 -0500296#if defined(CONFIG_FIT)
297 } else if (images.fit_uname_os) {
Simon Glass35fc84f2013-06-11 11:14:47 -0700298 int ret;
299
Stephen Warren712fbcf2011-10-18 11:11:49 +0000300 ret = fit_image_get_entry(images.fit_hdr_os,
Simon Glassc19d13b2013-05-08 08:06:02 +0000301 images.fit_noffset_os, &images.ep);
Kumar Galac160a952008-08-15 08:24:36 -0500302 if (ret) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000303 puts("Can't get entry point property!\n");
Kumar Galac160a952008-08-15 08:24:36 -0500304 return 1;
305 }
306#endif
Sebastian Siewior9ace3fc2014-05-05 15:08:09 -0500307 } else if (!ep_found) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000308 puts("Could not find kernel entry point!\n");
Kumar Galac160a952008-08-15 08:24:36 -0500309 return 1;
310 }
311
Stephen Warrenb9b50e892011-11-10 13:17:53 -0700312 if (images.os.type == IH_TYPE_KERNEL_NOLOAD) {
313 images.os.load = images.os.image_start;
314 images.ep += images.os.load;
315 }
316
Simon Glass35fc84f2013-06-11 11:14:47 -0700317 images.os.start = (ulong)os_hdr;
318
319 return 0;
320}
321
Tom Rini225fd8c2013-07-09 15:33:25 -0400322static int bootm_find_ramdisk(int flag, int argc, char * const argv[])
Simon Glass35fc84f2013-06-11 11:14:47 -0700323{
324 int ret;
325
Tom Rini225fd8c2013-07-09 15:33:25 -0400326 /* find ramdisk */
327 ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH,
328 &images.rd_start, &images.rd_end);
329 if (ret) {
330 puts("Ramdisk image is corrupt or invalid\n");
331 return 1;
332 }
333
334 return 0;
335}
336
337#if defined(CONFIG_OF_LIBFDT)
338static int bootm_find_fdt(int flag, int argc, char * const argv[])
339{
340 int ret;
341
342 /* find flattened device tree */
343 ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, &images,
344 &images.ft_addr, &images.ft_len);
345 if (ret) {
346 puts("Could not find a valid device tree\n");
347 return 1;
348 }
349
350 set_working_fdt_addr(images.ft_addr);
351
352 return 0;
353}
354#endif
355
356static int bootm_find_other(cmd_tbl_t *cmdtp, int flag, int argc,
357 char * const argv[])
358{
Heiko Schocher24de2f42010-03-29 13:15:48 +0200359 if (((images.os.type == IH_TYPE_KERNEL) ||
Stephen Warrenb9b50e892011-11-10 13:17:53 -0700360 (images.os.type == IH_TYPE_KERNEL_NOLOAD) ||
Heiko Schocher24de2f42010-03-29 13:15:48 +0200361 (images.os.type == IH_TYPE_MULTI)) &&
Miao Yan871a57b2013-11-28 17:51:38 +0800362 (images.os.os == IH_OS_LINUX ||
363 images.os.os == IH_OS_VXWORKS)) {
Tom Rini225fd8c2013-07-09 15:33:25 -0400364 if (bootm_find_ramdisk(flag, argc, argv))
Kumar Galac4f94192008-08-15 08:24:37 -0500365 return 1;
Kumar Gala06a09912008-08-15 08:24:38 -0500366
367#if defined(CONFIG_OF_LIBFDT)
Tom Rini225fd8c2013-07-09 15:33:25 -0400368 if (bootm_find_fdt(flag, argc, argv))
Kumar Gala06a09912008-08-15 08:24:38 -0500369 return 1;
Kumar Gala06a09912008-08-15 08:24:38 -0500370#endif
Kumar Galac4f94192008-08-15 08:24:37 -0500371 }
372
Kumar Gala396f6352008-08-15 08:24:41 -0500373 return 0;
374}
375
376#define BOOTM_ERR_RESET -1
377#define BOOTM_ERR_OVERLAP -2
378#define BOOTM_ERR_UNIMPLEMENTED -3
Tom Rinid3664382013-06-28 11:38:02 -0400379static int bootm_load_os(bootm_headers_t *images, unsigned long *load_end,
380 int boot_progress)
Kumar Gala396f6352008-08-15 08:24:41 -0500381{
Tom Rinid3664382013-06-28 11:38:02 -0400382 image_info_t os = images->os;
Kumar Gala396f6352008-08-15 08:24:41 -0500383 uint8_t comp = os.comp;
384 ulong load = os.load;
385 ulong blob_start = os.start;
386 ulong blob_end = os.end;
387 ulong image_start = os.image_start;
388 ulong image_len = os.image_len;
Anatolij Gustschin5bf27662011-11-19 13:12:18 +0000389 __maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN;
Stephen Warrend5108592011-11-10 13:17:54 -0700390 int no_overlap = 0;
Simon Glassaed161e2013-05-16 13:53:24 +0000391 void *load_buf, *image_buf;
Matthias Weisser60fdc5f2010-08-05 13:17:30 +0200392#if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
393 int ret;
394#endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
Kumar Gala396f6352008-08-15 08:24:41 -0500395
Stephen Warren712fbcf2011-10-18 11:11:49 +0000396 const char *type_name = genimg_get_type_name(os.type);
Kumar Gala396f6352008-08-15 08:24:41 -0500397
Kees Cook315c0ac2013-08-16 07:59:16 -0700398 load_buf = map_sysmem(load, unc_len);
Simon Glassaed161e2013-05-16 13:53:24 +0000399 image_buf = map_sysmem(image_start, image_len);
Kumar Gala396f6352008-08-15 08:24:41 -0500400 switch (comp) {
401 case IH_COMP_NONE:
Tom Rini717ccc12014-05-01 10:01:08 -0400402 if (load == image_start) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000403 printf(" XIP %s ... ", type_name);
Stephen Warrend5108592011-11-10 13:17:54 -0700404 no_overlap = 1;
Kumar Gala396f6352008-08-15 08:24:41 -0500405 } else {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000406 printf(" Loading %s ... ", type_name);
Simon Glassaed161e2013-05-16 13:53:24 +0000407 memmove_wd(load_buf, image_buf, image_len, CHUNKSZ);
Kumar Gala396f6352008-08-15 08:24:41 -0500408 }
409 *load_end = load + image_len;
Kumar Gala396f6352008-08-15 08:24:41 -0500410 break;
Mike Frysinger44431ca2010-01-21 19:30:36 -0500411#ifdef CONFIG_GZIP
Kumar Gala396f6352008-08-15 08:24:41 -0500412 case IH_COMP_GZIP:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000413 printf(" Uncompressing %s ... ", type_name);
Simon Glassaed161e2013-05-16 13:53:24 +0000414 if (gunzip(load_buf, unc_len, image_buf, &image_len) != 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000415 puts("GUNZIP: uncompress, out-of-mem or overwrite "
416 "error - must RESET board to recover\n");
Kumar Gala396f6352008-08-15 08:24:41 -0500417 if (boot_progress)
Simon Glass770605e2012-02-13 13:51:18 +0000418 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
Kumar Gala396f6352008-08-15 08:24:41 -0500419 return BOOTM_ERR_RESET;
420 }
421
422 *load_end = load + image_len;
423 break;
Mike Frysinger44431ca2010-01-21 19:30:36 -0500424#endif /* CONFIG_GZIP */
Kumar Gala396f6352008-08-15 08:24:41 -0500425#ifdef CONFIG_BZIP2
426 case IH_COMP_BZIP2:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000427 printf(" Uncompressing %s ... ", type_name);
Kumar Gala396f6352008-08-15 08:24:41 -0500428 /*
429 * If we've got less than 4 MB of malloc() space,
430 * use slower decompression algorithm which requires
431 * at most 2300 KB of memory.
432 */
Simon Glassaed161e2013-05-16 13:53:24 +0000433 int i = BZ2_bzBuffToBuffDecompress(load_buf, &unc_len,
434 image_buf, image_len,
435 CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
Kumar Gala396f6352008-08-15 08:24:41 -0500436 if (i != BZ_OK) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000437 printf("BUNZIP2: uncompress or overwrite error %d "
Kumar Gala396f6352008-08-15 08:24:41 -0500438 "- must RESET board to recover\n", i);
439 if (boot_progress)
Simon Glass770605e2012-02-13 13:51:18 +0000440 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
Kumar Gala396f6352008-08-15 08:24:41 -0500441 return BOOTM_ERR_RESET;
442 }
443
444 *load_end = load + unc_len;
445 break;
446#endif /* CONFIG_BZIP2 */
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200447#ifdef CONFIG_LZMA
Mike Frysinger78e1e842010-07-25 15:54:17 -0400448 case IH_COMP_LZMA: {
449 SizeT lzma_len = unc_len;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000450 printf(" Uncompressing %s ... ", type_name);
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200451
Simon Glassaed161e2013-05-16 13:53:24 +0000452 ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len,
453 image_buf, image_len);
Mike Frysinger78e1e842010-07-25 15:54:17 -0400454 unc_len = lzma_len;
Luigi 'Comio' Mantellinicaf72ff2009-07-21 10:45:49 +0200455 if (ret != SZ_OK) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000456 printf("LZMA: uncompress or overwrite error %d "
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200457 "- must RESET board to recover\n", ret);
Simon Glass770605e2012-02-13 13:51:18 +0000458 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200459 return BOOTM_ERR_RESET;
460 }
461 *load_end = load + unc_len;
462 break;
Mike Frysinger78e1e842010-07-25 15:54:17 -0400463 }
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200464#endif /* CONFIG_LZMA */
Peter Korsgaard20dde482009-11-19 11:37:51 +0100465#ifdef CONFIG_LZO
Simon Glass628af172013-08-30 11:00:09 -0600466 case IH_COMP_LZO: {
Kees Cook77cc8902014-04-15 10:28:12 -0700467 size_t size = unc_len;
Simon Glass628af172013-08-30 11:00:09 -0600468
Stephen Warren712fbcf2011-10-18 11:11:49 +0000469 printf(" Uncompressing %s ... ", type_name);
Peter Korsgaard20dde482009-11-19 11:37:51 +0100470
Simon Glass628af172013-08-30 11:00:09 -0600471 ret = lzop_decompress(image_buf, image_len, load_buf, &size);
Peter Korsgaard20dde482009-11-19 11:37:51 +0100472 if (ret != LZO_E_OK) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000473 printf("LZO: uncompress or overwrite error %d "
Peter Korsgaard20dde482009-11-19 11:37:51 +0100474 "- must RESET board to recover\n", ret);
475 if (boot_progress)
Simon Glass770605e2012-02-13 13:51:18 +0000476 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
Peter Korsgaard20dde482009-11-19 11:37:51 +0100477 return BOOTM_ERR_RESET;
478 }
479
Simon Glass628af172013-08-30 11:00:09 -0600480 *load_end = load + size;
Peter Korsgaard20dde482009-11-19 11:37:51 +0100481 break;
Simon Glass628af172013-08-30 11:00:09 -0600482 }
Peter Korsgaard20dde482009-11-19 11:37:51 +0100483#endif /* CONFIG_LZO */
Kumar Gala396f6352008-08-15 08:24:41 -0500484 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000485 printf("Unimplemented compression type %d\n", comp);
Kumar Gala396f6352008-08-15 08:24:41 -0500486 return BOOTM_ERR_UNIMPLEMENTED;
487 }
Diana CRACIUN99ffccb2011-08-31 02:45:23 +0000488
489 flush_cache(load, (*load_end - load) * sizeof(ulong));
490
Stephen Warren712fbcf2011-10-18 11:11:49 +0000491 puts("OK\n");
492 debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
Simon Glass770605e2012-02-13 13:51:18 +0000493 bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED);
Kumar Gala396f6352008-08-15 08:24:41 -0500494
Stephen Warrend5108592011-11-10 13:17:54 -0700495 if (!no_overlap && (load < blob_end) && (*load_end > blob_start)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000496 debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n",
497 blob_start, blob_end);
498 debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load,
499 *load_end);
Kumar Gala396f6352008-08-15 08:24:41 -0500500
Tom Rinid3664382013-06-28 11:38:02 -0400501 /* Check what type of image this is. */
502 if (images->legacy_hdr_valid) {
503 if (image_get_type(&images->legacy_hdr_os_copy)
504 == IH_TYPE_MULTI)
505 puts("WARNING: legacy format multi component image overwritten\n");
506 return BOOTM_ERR_OVERLAP;
507 } else {
508 puts("ERROR: new format image overwritten - must RESET the board to recover\n");
509 bootstage_error(BOOTSTAGE_ID_OVERWRITTEN);
510 return BOOTM_ERR_RESET;
511 }
Kumar Gala396f6352008-08-15 08:24:41 -0500512 }
513
514 return 0;
515}
516
Simon Glassc5cbe1e2013-12-26 16:26:24 -0700517static int do_bootm_standalone(int flag, int argc, char * const argv[],
518 bootm_headers_t *images)
Detlev Zundelf97ec302009-07-13 16:01:19 +0200519{
520 char *s;
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200521 int (*appl)(int, char * const []);
Detlev Zundelf97ec302009-07-13 16:01:19 +0200522
523 /* Don't start if "autostart" is set to "no" */
524 if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
Simon Glassc5cbe1e2013-12-26 16:26:24 -0700525 setenv_hex("filesize", images->os.image_len);
Detlev Zundelf97ec302009-07-13 16:01:19 +0200526 return 0;
527 }
Christian Eggers9c896142014-02-08 19:27:45 +0100528 appl = (int (*)(int, char * const []))images->ep;
529 appl(argc, argv);
Detlev Zundelf97ec302009-07-13 16:01:19 +0200530 return 0;
531}
532
Kumar Gala49c3a862008-10-21 17:25:45 -0500533/* we overload the cmd field with our state machine info instead of a
534 * function pointer */
Frans Meulenbroeksf74d9bd2010-02-25 10:12:13 +0100535static cmd_tbl_t cmd_bootm_sub[] = {
Kumar Gala49c3a862008-10-21 17:25:45 -0500536 U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
537 U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
John Rigbyfca43cc2010-10-13 13:57:35 -0600538#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
Kumar Gala49c3a862008-10-21 17:25:45 -0500539 U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
540#endif
541#ifdef CONFIG_OF_LIBFDT
542 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
543#endif
Kumar Gala49c3a862008-10-21 17:25:45 -0500544 U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
Peter Tyser224c90d2009-11-18 19:08:59 -0600545 U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
Kumar Gala49c3a862008-10-21 17:25:45 -0500546 U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
Simon Glassd0ae31e2013-06-11 11:14:48 -0700547 U_BOOT_CMD_MKENT(fake, 0, 1, (void *)BOOTM_STATE_OS_FAKE_GO, "", ""),
Kumar Gala49c3a862008-10-21 17:25:45 -0500548 U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
549};
550
Simon Glass35fc84f2013-06-11 11:14:47 -0700551static int boot_selected_os(int argc, char * const argv[], int state,
Simon Glass5ff0d082013-06-28 00:46:12 -0700552 bootm_headers_t *images, boot_os_fn *boot_fn)
Simon Glass35fc84f2013-06-11 11:14:47 -0700553{
Simon Glass35fc84f2013-06-11 11:14:47 -0700554 arch_preboot_os();
555 boot_fn(state, argc, argv, images);
Simon Glassc5cbe1e2013-12-26 16:26:24 -0700556
557 /* Stand-alone may return when 'autostart' is 'no' */
558 if (images->os.type == IH_TYPE_STANDALONE ||
559 state == BOOTM_STATE_OS_FAKE_GO) /* We expect to return */
Simon Glassd0ae31e2013-06-11 11:14:48 -0700560 return 0;
Simon Glass35fc84f2013-06-11 11:14:47 -0700561 bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED);
562#ifdef DEBUG
563 puts("\n## Control returned to monitor - resetting...\n");
564#endif
565 return BOOTM_ERR_RESET;
566}
567
568/**
Simon Glass385501d2013-07-04 13:26:08 -0700569 * bootm_disable_interrupts() - Disable interrupts in preparation for load/boot
570 *
571 * @return interrupt flag (0 if interrupts were disabled, non-zero if they were
572 * enabled)
573 */
574static ulong bootm_disable_interrupts(void)
575{
576 ulong iflag;
577
578 /*
579 * We have reached the point of no return: we are going to
580 * overwrite all exception vector code, so we cannot easily
581 * recover from any failures any more...
582 */
583 iflag = disable_interrupts();
584#ifdef CONFIG_NETCONSOLE
585 /* Stop the ethernet stack if NetConsole could have left it up */
586 eth_halt();
Frederic Leroy80949722013-09-10 12:02:31 +0200587 eth_unregister(eth_get_dev());
Simon Glass385501d2013-07-04 13:26:08 -0700588#endif
589
590#if defined(CONFIG_CMD_USB)
591 /*
592 * turn off USB to prevent the host controller from writing to the
593 * SDRAM while Linux is booting. This could happen (at least for OHCI
594 * controller), because the HCCA (Host Controller Communication Area)
595 * lies within the SDRAM and the host controller writes continously to
596 * this area (as busmaster!). The HccaFrameNumber is for example
597 * updated every 1 ms within the HCCA structure in SDRAM! For more
598 * details see the OpenHCI specification.
599 */
600 usb_stop();
601#endif
602 return iflag;
603}
604
605/**
Simon Glass35fc84f2013-06-11 11:14:47 -0700606 * Execute selected states of the bootm command.
607 *
608 * Note the arguments to this state must be the first argument, Any 'bootm'
609 * or sub-command arguments must have already been taken.
610 *
611 * Note that if states contains more than one flag it MUST contain
612 * BOOTM_STATE_START, since this handles and consumes the command line args.
613 *
Tom Rinid3664382013-06-28 11:38:02 -0400614 * Also note that aside from boot_os_fn functions and bootm_load_os no other
615 * functions we store the return value of in 'ret' may use a negative return
616 * value, without special handling.
617 *
Simon Glass35fc84f2013-06-11 11:14:47 -0700618 * @param cmdtp Pointer to bootm command table entry
619 * @param flag Command flags (CMD_FLAG_...)
620 * @param argc Number of subcommand arguments (0 = no arguments)
621 * @param argv Arguments
622 * @param states Mask containing states to run (BOOTM_STATE_...)
623 * @param images Image header information
624 * @param boot_progress 1 to show boot progress, 0 to not do this
625 * @return 0 if ok, something else on error. Some errors will cause this
626 * function to perform a reboot! If states contains BOOTM_STATE_OS_GO
627 * then the intent is to boot an OS, so this function will not return
628 * unless the image type is standalone.
629 */
630static int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc,
631 char * const argv[], int states, bootm_headers_t *images,
632 int boot_progress)
633{
634 boot_os_fn *boot_fn;
635 ulong iflag = 0;
Simon Glassa26913f2013-07-04 13:26:09 -0700636 int ret = 0, need_boot_fn;
Simon Glass35fc84f2013-06-11 11:14:47 -0700637
638 images->state |= states;
639
640 /*
641 * Work through the states and see how far we get. We stop on
642 * any error.
643 */
644 if (states & BOOTM_STATE_START)
645 ret = bootm_start(cmdtp, flag, argc, argv);
646
647 if (!ret && (states & BOOTM_STATE_FINDOS))
648 ret = bootm_find_os(cmdtp, flag, argc, argv);
649
650 if (!ret && (states & BOOTM_STATE_FINDOTHER)) {
651 ret = bootm_find_other(cmdtp, flag, argc, argv);
652 argc = 0; /* consume the args */
653 }
654
655 /* Load the OS */
656 if (!ret && (states & BOOTM_STATE_LOADOS)) {
657 ulong load_end;
658
Simon Glass385501d2013-07-04 13:26:08 -0700659 iflag = bootm_disable_interrupts();
Tom Rinid3664382013-06-28 11:38:02 -0400660 ret = bootm_load_os(images, &load_end, 0);
Tom Rinid3664382013-06-28 11:38:02 -0400661 if (ret == 0)
Simon Glass35fc84f2013-06-11 11:14:47 -0700662 lmb_reserve(&images->lmb, images->os.load,
663 (load_end - images->os.load));
Tom Rini970150a2013-07-11 09:35:23 -0400664 else if (ret && ret != BOOTM_ERR_OVERLAP)
665 goto err;
Tom Rinid3664382013-06-28 11:38:02 -0400666 else if (ret == BOOTM_ERR_OVERLAP)
667 ret = 0;
Paul B. Hensonbd4a3992013-08-03 21:29:09 -0700668#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
Simon Glass576aacd2013-07-16 20:09:59 -0700669 if (images->os.os == IH_OS_LINUX)
670 fixup_silent_linux();
671#endif
Simon Glass35fc84f2013-06-11 11:14:47 -0700672 }
673
674 /* Relocate the ramdisk */
675#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
676 if (!ret && (states & BOOTM_STATE_RAMDISK)) {
677 ulong rd_len = images->rd_end - images->rd_start;
678
679 ret = boot_ramdisk_high(&images->lmb, images->rd_start,
680 rd_len, &images->initrd_start, &images->initrd_end);
681 if (!ret) {
682 setenv_hex("initrd_start", images->initrd_start);
683 setenv_hex("initrd_end", images->initrd_end);
684 }
685 }
686#endif
687#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_LMB)
688 if (!ret && (states & BOOTM_STATE_FDT)) {
689 boot_fdt_add_mem_rsv_regions(&images->lmb, images->ft_addr);
690 ret = boot_relocate_fdt(&images->lmb, &images->ft_addr,
691 &images->ft_len);
692 }
693#endif
694
695 /* From now on, we need the OS boot function */
696 if (ret)
697 return ret;
698 boot_fn = boot_os[images->os.os];
Simon Glassa26913f2013-07-04 13:26:09 -0700699 need_boot_fn = states & (BOOTM_STATE_OS_CMDLINE |
700 BOOTM_STATE_OS_BD_T | BOOTM_STATE_OS_PREP |
701 BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO);
702 if (boot_fn == NULL && need_boot_fn) {
Simon Glass35fc84f2013-06-11 11:14:47 -0700703 if (iflag)
704 enable_interrupts();
705 printf("ERROR: booting os '%s' (%d) is not supported\n",
706 genimg_get_os_name(images->os.os), images->os.os);
707 bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS);
708 return 1;
709 }
710
711 /* Call various other states that are not generally used */
712 if (!ret && (states & BOOTM_STATE_OS_CMDLINE))
713 ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, images);
714 if (!ret && (states & BOOTM_STATE_OS_BD_T))
715 ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images);
716 if (!ret && (states & BOOTM_STATE_OS_PREP))
717 ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, images);
718
Simon Glassd0ae31e2013-06-11 11:14:48 -0700719#ifdef CONFIG_TRACE
720 /* Pretend to run the OS, then run a user command */
721 if (!ret && (states & BOOTM_STATE_OS_FAKE_GO)) {
722 char *cmd_list = getenv("fakegocmd");
723
724 ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_FAKE_GO,
Simon Glass5ff0d082013-06-28 00:46:12 -0700725 images, boot_fn);
Simon Glassd0ae31e2013-06-11 11:14:48 -0700726 if (!ret && cmd_list)
727 ret = run_command_list(cmd_list, -1, flag);
728 }
729#endif
Simon Glassb7a1d132013-07-10 09:25:33 -0400730
731 /* Check for unsupported subcommand. */
732 if (ret) {
733 puts("subcommand not supported\n");
734 return ret;
Tom Rinid3664382013-06-28 11:38:02 -0400735 }
736
Simon Glassb7a1d132013-07-10 09:25:33 -0400737 /* Now run the OS! We hope this doesn't return */
738 if (!ret && (states & BOOTM_STATE_OS_GO))
739 ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_GO,
740 images, boot_fn);
Simon Glass35fc84f2013-06-11 11:14:47 -0700741
742 /* Deal with any fallout */
Tom Rinid3664382013-06-28 11:38:02 -0400743err:
Simon Glass35fc84f2013-06-11 11:14:47 -0700744 if (iflag)
745 enable_interrupts();
Tom Rinid3664382013-06-28 11:38:02 -0400746
747 if (ret == BOOTM_ERR_UNIMPLEMENTED)
748 bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL);
749 else if (ret == BOOTM_ERR_RESET)
750 do_reset(cmdtp, flag, argc, argv);
Simon Glass35fc84f2013-06-11 11:14:47 -0700751
752 return ret;
753}
754
Kim Phillips088f1b12012-10-29 13:34:31 +0000755static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
Stephen Warren712fbcf2011-10-18 11:11:49 +0000756 char * const argv[])
Kumar Gala49c3a862008-10-21 17:25:45 -0500757{
758 int ret = 0;
Simon Glass6d6f1232011-10-07 13:53:40 +0000759 long state;
Kumar Gala49c3a862008-10-21 17:25:45 -0500760 cmd_tbl_t *c;
Kumar Gala49c3a862008-10-21 17:25:45 -0500761
Simon Glass983c72f2013-06-11 11:14:46 -0700762 c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
763 argc--; argv++;
Kumar Gala49c3a862008-10-21 17:25:45 -0500764
765 if (c) {
Simon Glass6d6f1232011-10-07 13:53:40 +0000766 state = (long)c->cmd;
Simon Glass983c72f2013-06-11 11:14:46 -0700767 if (state == BOOTM_STATE_START)
Simon Glass35fc84f2013-06-11 11:14:47 -0700768 state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER;
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200769 } else {
770 /* Unrecognized command */
Simon Glass4c12eeb2011-12-10 08:44:01 +0000771 return CMD_RET_USAGE;
Kumar Gala49c3a862008-10-21 17:25:45 -0500772 }
773
Simon Glass35fc84f2013-06-11 11:14:47 -0700774 if (state != BOOTM_STATE_START && images.state >= state) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000775 printf("Trying to execute a command out of order\n");
Simon Glass4c12eeb2011-12-10 08:44:01 +0000776 return CMD_RET_USAGE;
Kumar Gala49c3a862008-10-21 17:25:45 -0500777 }
778
Simon Glass35fc84f2013-06-11 11:14:47 -0700779 ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0);
Kumar Gala49c3a862008-10-21 17:25:45 -0500780
781 return ret;
782}
783
Kumar Gala396f6352008-08-15 08:24:41 -0500784/*******************************************************************/
785/* bootm - boot application image from image in memory */
786/*******************************************************************/
Kumar Galabe083152008-10-21 17:25:44 -0500787
Stephen Warren712fbcf2011-10-18 11:11:49 +0000788int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Kumar Gala396f6352008-08-15 08:24:41 -0500789{
Wolfgang Denk2e5167c2010-10-28 20:00:11 +0200790#ifdef CONFIG_NEEDS_MANUAL_RELOC
Peter Tyser521af042009-09-21 11:20:36 -0500791 static int relocated = 0;
Kumar Galabe083152008-10-21 17:25:44 -0500792
Kumar Galabe083152008-10-21 17:25:44 -0500793 if (!relocated) {
794 int i;
Daniel Schwierzeck58bd77d2013-01-07 06:54:52 +0000795
796 /* relocate boot function table */
Kumar Galabe083152008-10-21 17:25:44 -0500797 for (i = 0; i < ARRAY_SIZE(boot_os); i++)
Detlev Zundelca95c9d2009-07-13 16:01:18 +0200798 if (boot_os[i] != NULL)
799 boot_os[i] += gd->reloc_off;
Daniel Schwierzeck58bd77d2013-01-07 06:54:52 +0000800
801 /* relocate names of sub-command table */
802 for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++)
803 cmd_bootm_sub[i].name += gd->reloc_off;
804
Kumar Galabe083152008-10-21 17:25:44 -0500805 relocated = 1;
806 }
Peter Tyser521af042009-09-21 11:20:36 -0500807#endif
Kumar Gala396f6352008-08-15 08:24:41 -0500808
Kumar Gala49c3a862008-10-21 17:25:45 -0500809 /* determine if we have a sub command */
Simon Glass983c72f2013-06-11 11:14:46 -0700810 argc--; argv++;
811 if (argc > 0) {
Kumar Gala49c3a862008-10-21 17:25:45 -0500812 char *endp;
813
Simon Glass983c72f2013-06-11 11:14:46 -0700814 simple_strtoul(argv[0], &endp, 16);
815 /* endp pointing to NULL means that argv[0] was just a
Kumar Gala49c3a862008-10-21 17:25:45 -0500816 * valid number, pass it along to the normal bootm processing
817 *
818 * If endp is ':' or '#' assume a FIT identifier so pass
819 * along for normal processing.
820 *
821 * Right now we assume the first arg should never be '-'
822 */
823 if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
824 return do_bootm_subcommand(cmdtp, flag, argc, argv);
825 }
826
Simon Glass35fc84f2013-06-11 11:14:47 -0700827 return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START |
828 BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER |
Tom Rini3d187b32013-09-23 14:20:37 -0400829 BOOTM_STATE_LOADOS |
830#if defined(CONFIG_PPC) || defined(CONFIG_MIPS)
831 BOOTM_STATE_OS_CMDLINE |
832#endif
Paul Burton5c427e42013-09-06 11:23:55 +0100833 BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
834 BOOTM_STATE_OS_GO, &images, 1);
wdenk47d1a6e2002-11-03 00:01:44 +0000835}
836
Mike Frysinger67d668b2011-06-05 13:43:02 +0000837int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
838{
839 const char *ep = getenv("autostart");
840
841 if (ep && !strcmp(ep, "yes")) {
842 char *local_args[2];
843 local_args[0] = (char *)cmd;
844 local_args[1] = NULL;
845 printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
846 return do_bootm(cmdtp, 0, 1, local_args);
847 }
848
849 return 0;
850}
851
Heiko Schocher21d29f72014-05-28 11:33:33 +0200852#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100853/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100854 * image_get_kernel - verify legacy format kernel image
855 * @img_addr: in RAM address of the legacy format image to be verified
856 * @verify: data CRC verification flag
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100857 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100858 * image_get_kernel() verifies legacy image integrity and returns pointer to
859 * legacy image header if image verification was completed successfully.
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100860 *
861 * returns:
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100862 * pointer to a legacy image header if valid image was found
863 * otherwise return NULL
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100864 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000865static image_header_t *image_get_kernel(ulong img_addr, int verify)
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100866{
867 image_header_t *hdr = (image_header_t *)img_addr;
868
869 if (!image_check_magic(hdr)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000870 puts("Bad Magic Number\n");
Simon Glass770605e2012-02-13 13:51:18 +0000871 bootstage_error(BOOTSTAGE_ID_CHECK_MAGIC);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100872 return NULL;
873 }
Simon Glass770605e2012-02-13 13:51:18 +0000874 bootstage_mark(BOOTSTAGE_ID_CHECK_HEADER);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100875
Stephen Warren712fbcf2011-10-18 11:11:49 +0000876 if (!image_check_hcrc(hdr)) {
877 puts("Bad Header Checksum\n");
Simon Glass770605e2012-02-13 13:51:18 +0000878 bootstage_error(BOOTSTAGE_ID_CHECK_HEADER);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100879 return NULL;
880 }
881
Simon Glass770605e2012-02-13 13:51:18 +0000882 bootstage_mark(BOOTSTAGE_ID_CHECK_CHECKSUM);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000883 image_print_contents(hdr);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100884
885 if (verify) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000886 puts(" Verifying Checksum ... ");
887 if (!image_check_dcrc(hdr)) {
888 printf("Bad Data CRC\n");
Simon Glass770605e2012-02-13 13:51:18 +0000889 bootstage_error(BOOTSTAGE_ID_CHECK_CHECKSUM);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100890 return NULL;
891 }
Stephen Warren712fbcf2011-10-18 11:11:49 +0000892 puts("OK\n");
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100893 }
Simon Glass770605e2012-02-13 13:51:18 +0000894 bootstage_mark(BOOTSTAGE_ID_CHECK_ARCH);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100895
Stephen Warren712fbcf2011-10-18 11:11:49 +0000896 if (!image_check_target_arch(hdr)) {
897 printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr));
Simon Glass770605e2012-02-13 13:51:18 +0000898 bootstage_error(BOOTSTAGE_ID_CHECK_ARCH);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100899 return NULL;
900 }
901 return hdr;
902}
Heiko Schocher21d29f72014-05-28 11:33:33 +0200903#endif
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100904
905/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100906 * boot_get_kernel - find kernel image
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100907 * @os_data: pointer to a ulong variable, will hold os data start address
908 * @os_len: pointer to a ulong variable, will hold os data length
909 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100910 * boot_get_kernel() tries to find a kernel image, verifies its integrity
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100911 * and locates kernel data.
912 *
913 * returns:
914 * pointer to image header if valid image was found, plus kernel start
915 * address and length, otherwise NULL
916 */
Simon Glass35e7b0f2013-05-07 06:12:03 +0000917static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
Stephen Warren712fbcf2011-10-18 11:11:49 +0000918 char * const argv[], bootm_headers_t *images, ulong *os_data,
919 ulong *os_len)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100920{
Heiko Schocher21d29f72014-05-28 11:33:33 +0200921#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100922 image_header_t *hdr;
Heiko Schocher21d29f72014-05-28 11:33:33 +0200923#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100924 ulong img_addr;
Simon Glass35e7b0f2013-05-07 06:12:03 +0000925 const void *buf;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100926#if defined(CONFIG_FIT)
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100927 const char *fit_uname_config = NULL;
928 const char *fit_uname_kernel = NULL;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100929 int os_noffset;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100930#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100931
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100932 /* find out kernel image address */
Simon Glass983c72f2013-06-11 11:14:46 -0700933 if (argc < 1) {
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100934 img_addr = load_addr;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000935 debug("* kernel: default image load address = 0x%08lx\n",
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100936 load_addr);
937#if defined(CONFIG_FIT)
Simon Glass983c72f2013-06-11 11:14:46 -0700938 } else if (fit_parse_conf(argv[0], load_addr, &img_addr,
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100939 &fit_uname_config)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000940 debug("* kernel: config '%s' from image at 0x%08lx\n",
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100941 fit_uname_config, img_addr);
Simon Glass983c72f2013-06-11 11:14:46 -0700942 } else if (fit_parse_subimage(argv[0], load_addr, &img_addr,
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100943 &fit_uname_kernel)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000944 debug("* kernel: subimage '%s' from image at 0x%08lx\n",
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100945 fit_uname_kernel, img_addr);
946#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100947 } else {
Simon Glass983c72f2013-06-11 11:14:46 -0700948 img_addr = simple_strtoul(argv[0], NULL, 16);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000949 debug("* kernel: cmdline image address = 0x%08lx\n", img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100950 }
951
Simon Glass770605e2012-02-13 13:51:18 +0000952 bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100953
Marian Balakowiczfff888a12008-02-21 17:20:19 +0100954 /* copy from dataflash if needed */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000955 img_addr = genimg_get_image(img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100956
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100957 /* check image type, for FIT images get FIT kernel node */
Marian Balakowicz6986a382008-03-12 10:01:05 +0100958 *os_data = *os_len = 0;
Simon Glass35e7b0f2013-05-07 06:12:03 +0000959 buf = map_sysmem(img_addr, 0);
960 switch (genimg_get_format(buf)) {
Heiko Schocher21d29f72014-05-28 11:33:33 +0200961#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100962 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000963 printf("## Booting kernel from Legacy Image at %08lx ...\n",
Marian Balakowicz6986a382008-03-12 10:01:05 +0100964 img_addr);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000965 hdr = image_get_kernel(img_addr, images->verify);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100966 if (!hdr)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100967 return NULL;
Simon Glass770605e2012-02-13 13:51:18 +0000968 bootstage_mark(BOOTSTAGE_ID_CHECK_IMAGETYPE);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100969
Marian Balakowicz6986a382008-03-12 10:01:05 +0100970 /* get os_data and os_len */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000971 switch (image_get_type(hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100972 case IH_TYPE_KERNEL:
Stephen Warrenb9b50e892011-11-10 13:17:53 -0700973 case IH_TYPE_KERNEL_NOLOAD:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000974 *os_data = image_get_data(hdr);
975 *os_len = image_get_data_size(hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100976 break;
977 case IH_TYPE_MULTI:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000978 image_multi_getimg(hdr, 0, os_data, os_len);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100979 break;
Detlev Zundelf97ec302009-07-13 16:01:19 +0200980 case IH_TYPE_STANDALONE:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000981 *os_data = image_get_data(hdr);
982 *os_len = image_get_data_size(hdr);
Detlev Zundelf97ec302009-07-13 16:01:19 +0200983 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100984 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000985 printf("Wrong Image Type for %s command\n",
986 cmdtp->name);
Simon Glass770605e2012-02-13 13:51:18 +0000987 bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100988 return NULL;
989 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100990
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200991 /*
Stephen Warren712fbcf2011-10-18 11:11:49 +0000992 * copy image header to allow for image overwrites during
993 * kernel decompression.
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200994 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000995 memmove(&images->legacy_hdr_os_copy, hdr,
996 sizeof(image_header_t));
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200997
998 /* save pointer to image header */
999 images->legacy_hdr_os = hdr;
1000
1001 images->legacy_hdr_valid = 1;
Simon Glass770605e2012-02-13 13:51:18 +00001002 bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001003 break;
Heiko Schocher21d29f72014-05-28 11:33:33 +02001004#endif
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001005#if defined(CONFIG_FIT)
1006 case IMAGE_FORMAT_FIT:
Simon Glass46518002013-05-16 13:53:25 +00001007 os_noffset = fit_image_load(images, FIT_KERNEL_PROP,
1008 img_addr,
Simon Glassf320a4d2013-07-10 23:08:10 -07001009 &fit_uname_kernel, &fit_uname_config,
Simon Glass46518002013-05-16 13:53:25 +00001010 IH_ARCH_DEFAULT, IH_TYPE_KERNEL,
1011 BOOTSTAGE_ID_FIT_KERNEL_START,
1012 FIT_LOAD_IGNORED, os_data, os_len);
1013 if (os_noffset < 0)
Marian Balakowicz6986a382008-03-12 10:01:05 +01001014 return NULL;
1015
Simon Glass46518002013-05-16 13:53:25 +00001016 images->fit_hdr_os = map_sysmem(img_addr, 0);
Marian Balakowicz6986a382008-03-12 10:01:05 +01001017 images->fit_uname_os = fit_uname_kernel;
Simon Glassf320a4d2013-07-10 23:08:10 -07001018 images->fit_uname_cfg = fit_uname_config;
Marian Balakowicz3dfe1102008-03-12 10:32:59 +01001019 images->fit_noffset_os = os_noffset;
Marian Balakowicz6986a382008-03-12 10:01:05 +01001020 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001021#endif
Sebastian Siewior9ace3fc2014-05-05 15:08:09 -05001022#ifdef CONFIG_ANDROID_BOOT_IMAGE
1023 case IMAGE_FORMAT_ANDROID:
1024 printf("## Booting Android Image at 0x%08lx ...\n", img_addr);
1025 if (android_image_get_kernel((void *)img_addr, images->verify,
1026 os_data, os_len))
1027 return NULL;
1028 break;
1029#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +01001030 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001031 printf("Wrong Image Format for %s command\n", cmdtp->name);
Simon Glass770605e2012-02-13 13:51:18 +00001032 bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +01001033 return NULL;
1034 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001035
Stephen Warren712fbcf2011-10-18 11:11:49 +00001036 debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
Marian Balakowicz6986a382008-03-12 10:01:05 +01001037 *os_data, *os_len, *os_len);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +01001038
Simon Glass35e7b0f2013-05-07 06:12:03 +00001039 return buf;
Marian Balakowicz5cf746c2008-01-31 13:59:09 +01001040}
1041
Kim Phillips088f1b12012-10-29 13:34:31 +00001042#ifdef CONFIG_SYS_LONGHELP
1043static char bootm_help_text[] =
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001044 "[addr [arg ...]]\n - boot application image stored in memory\n"
1045 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
1046 "\t'arg' can be the address of an initrd image\n"
Marian Balakowicz4a2ad5f2008-01-31 13:20:07 +01001047#if defined(CONFIG_OF_LIBFDT)
Matthew McClintock98a9c4d2006-06-28 10:41:37 -05001048 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
Detlev Zundel5441f612007-10-19 16:47:26 +02001049 "\ta third argument is required which is the address of the\n"
Matthew McClintock98a9c4d2006-06-28 10:41:37 -05001050 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1051 "\tuse a '-' for the second argument. If you do not pass a third\n"
1052 "\ta bd_info struct will be passed instead\n"
1053#endif
Marian Balakowicz6986a382008-03-12 10:01:05 +01001054#if defined(CONFIG_FIT)
1055 "\t\nFor the new multi component uImage format (FIT) addresses\n"
1056 "\tmust be extened to include component or configuration unit name:\n"
1057 "\taddr:<subimg_uname> - direct component image specification\n"
1058 "\taddr#<conf_uname> - configuration specification\n"
1059 "\tUse iminfo command to get the list of existing component\n"
1060 "\timages and configurations.\n"
1061#endif
Kumar Gala49c3a862008-10-21 17:25:45 -05001062 "\nSub-commands to do part of the bootm sequence. The sub-commands "
1063 "must be\n"
1064 "issued in the order below (it's ok to not issue all sub-commands):\n"
1065 "\tstart [addr [arg ...]]\n"
1066 "\tloados - load OS image\n"
Daniel Schwierzeck59af76d2013-02-26 04:54:19 +00001067#if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH)
Kumar Gala49c3a862008-10-21 17:25:45 -05001068 "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
1069#endif
1070#if defined(CONFIG_OF_LIBFDT)
1071 "\tfdt - relocate flat device tree\n"
1072#endif
Kumar Gala49c3a862008-10-21 17:25:45 -05001073 "\tcmdline - OS specific command line processing/setup\n"
Peter Tyser224c90d2009-11-18 19:08:59 -06001074 "\tbdt - OS specific bd_t processing\n"
Kumar Gala49c3a862008-10-21 17:25:45 -05001075 "\tprep - OS specific prep before relocation or go\n"
Kim Phillips088f1b12012-10-29 13:34:31 +00001076 "\tgo - start OS";
1077#endif
1078
1079U_BOOT_CMD(
1080 bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
1081 "boot application image from memory", bootm_help_text
wdenk8bde7f72003-06-27 21:31:46 +00001082);
1083
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001084/*******************************************************************/
1085/* bootd - boot default image */
1086/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -05001087#if defined(CONFIG_CMD_BOOTD)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001088int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk47d1a6e2002-11-03 00:01:44 +00001089{
Thomas Betker73671da2014-06-05 20:07:56 +02001090 return run_command(getenv("bootcmd"), flag);
wdenk47d1a6e2002-11-03 00:01:44 +00001091}
wdenk8bde7f72003-06-27 21:31:46 +00001092
wdenk0d498392003-07-01 21:06:45 +00001093U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001094 boot, 1, 1, do_bootd,
Peter Tyser2fb26042009-01-27 18:03:12 -06001095 "boot default, i.e., run 'bootcmd'",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001096 ""
wdenk9d2b18a2003-06-28 23:11:04 +00001097);
1098
1099/* keep old command name "bootd" for backward compatibility */
wdenk0d498392003-07-01 21:06:45 +00001100U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001101 bootd, 1, 1, do_bootd,
Peter Tyser2fb26042009-01-27 18:03:12 -06001102 "boot default, i.e., run 'bootcmd'",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001103 ""
wdenk8bde7f72003-06-27 21:31:46 +00001104);
1105
wdenk47d1a6e2002-11-03 00:01:44 +00001106#endif
1107
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001108
1109/*******************************************************************/
1110/* iminfo - print header info for a requested image */
1111/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -05001112#if defined(CONFIG_CMD_IMI)
Kim Phillips088f1b12012-10-29 13:34:31 +00001113static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk47d1a6e2002-11-03 00:01:44 +00001114{
1115 int arg;
1116 ulong addr;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001117 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +00001118
1119 if (argc < 2) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001120 return image_info(load_addr);
wdenk47d1a6e2002-11-03 00:01:44 +00001121 }
1122
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001123 for (arg = 1; arg < argc; ++arg) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001124 addr = simple_strtoul(argv[arg], NULL, 16);
1125 if (image_info(addr) != 0)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001126 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001127 }
1128 return rcode;
1129}
1130
Stephen Warren712fbcf2011-10-18 11:11:49 +00001131static int image_info(ulong addr)
wdenk47d1a6e2002-11-03 00:01:44 +00001132{
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001133 void *hdr = (void *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +00001134
Stephen Warren712fbcf2011-10-18 11:11:49 +00001135 printf("\n## Checking Image at %08lx ...\n", addr);
wdenk47d1a6e2002-11-03 00:01:44 +00001136
Stephen Warren712fbcf2011-10-18 11:11:49 +00001137 switch (genimg_get_format(hdr)) {
Heiko Schocher21d29f72014-05-28 11:33:33 +02001138#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001139 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001140 puts(" Legacy image found\n");
1141 if (!image_check_magic(hdr)) {
1142 puts(" Bad Magic Number\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001143 return 1;
1144 }
1145
Stephen Warren712fbcf2011-10-18 11:11:49 +00001146 if (!image_check_hcrc(hdr)) {
1147 puts(" Bad Header Checksum\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001148 return 1;
1149 }
1150
Stephen Warren712fbcf2011-10-18 11:11:49 +00001151 image_print_contents(hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001152
Stephen Warren712fbcf2011-10-18 11:11:49 +00001153 puts(" Verifying Checksum ... ");
1154 if (!image_check_dcrc(hdr)) {
1155 puts(" Bad Data CRC\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001156 return 1;
1157 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00001158 puts("OK\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001159 return 0;
Heiko Schocher21d29f72014-05-28 11:33:33 +02001160#endif
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001161#if defined(CONFIG_FIT)
1162 case IMAGE_FORMAT_FIT:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001163 puts(" FIT image found\n");
Marian Balakowicze32fea62008-03-11 12:35:20 +01001164
Stephen Warren712fbcf2011-10-18 11:11:49 +00001165 if (!fit_check_format(hdr)) {
1166 puts("Bad FIT image format!\n");
Marian Balakowicze32fea62008-03-11 12:35:20 +01001167 return 1;
1168 }
1169
Stephen Warren712fbcf2011-10-18 11:11:49 +00001170 fit_print_contents(hdr);
Bartlomiej Siekaa4f24342008-09-09 12:58:16 +02001171
Simon Glassb8da8362013-05-07 06:11:57 +00001172 if (!fit_all_image_verify(hdr)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001173 puts("Bad hash in FIT image!\n");
Bartlomiej Siekaa4f24342008-09-09 12:58:16 +02001174 return 1;
1175 }
1176
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001177 return 0;
1178#endif
1179 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001180 puts("Unknown image format!\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001181 break;
wdenk47d1a6e2002-11-03 00:01:44 +00001182 }
1183
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001184 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001185}
wdenk0d498392003-07-01 21:06:45 +00001186
1187U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001188 iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
Peter Tyser2fb26042009-01-27 18:03:12 -06001189 "print header information for application image",
wdenk8bde7f72003-06-27 21:31:46 +00001190 "addr [addr ...]\n"
1191 " - print header information for application image starting at\n"
1192 " address 'addr' in memory; this includes verification of the\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001193 " image contents (magic number, header and payload checksums)"
wdenk8bde7f72003-06-27 21:31:46 +00001194);
Jon Loeliger90253172007-07-10 11:02:44 -05001195#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001196
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001197
1198/*******************************************************************/
1199/* imls - list all images found in flash */
1200/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -05001201#if defined(CONFIG_CMD_IMLS)
Vipin Kumar8fdf1e02012-12-16 22:32:48 +00001202static int do_imls_nor(void)
wdenk27b207f2003-07-24 23:38:38 +00001203{
1204 flash_info_t *info;
1205 int i, j;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001206 void *hdr;
wdenk27b207f2003-07-24 23:38:38 +00001207
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001208 for (i = 0, info = &flash_info[0];
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001209 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001210
wdenk27b207f2003-07-24 23:38:38 +00001211 if (info->flash_id == FLASH_UNKNOWN)
1212 goto next_bank;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001213 for (j = 0; j < info->sector_count; ++j) {
wdenk27b207f2003-07-24 23:38:38 +00001214
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001215 hdr = (void *)info->start[j];
1216 if (!hdr)
wdenk27b207f2003-07-24 23:38:38 +00001217 goto next_sector;
1218
Stephen Warren712fbcf2011-10-18 11:11:49 +00001219 switch (genimg_get_format(hdr)) {
Heiko Schocher21d29f72014-05-28 11:33:33 +02001220#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001221 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001222 if (!image_check_hcrc(hdr))
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001223 goto next_sector;
1224
Stephen Warren712fbcf2011-10-18 11:11:49 +00001225 printf("Legacy Image at %08lX:\n", (ulong)hdr);
1226 image_print_contents(hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001227
Stephen Warren712fbcf2011-10-18 11:11:49 +00001228 puts(" Verifying Checksum ... ");
1229 if (!image_check_dcrc(hdr)) {
1230 puts("Bad Data CRC\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001231 } else {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001232 puts("OK\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001233 }
1234 break;
Heiko Schocher21d29f72014-05-28 11:33:33 +02001235#endif
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001236#if defined(CONFIG_FIT)
1237 case IMAGE_FORMAT_FIT:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001238 if (!fit_check_format(hdr))
Marian Balakowicze32fea62008-03-11 12:35:20 +01001239 goto next_sector;
1240
Stephen Warren712fbcf2011-10-18 11:11:49 +00001241 printf("FIT Image at %08lX:\n", (ulong)hdr);
1242 fit_print_contents(hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001243 break;
1244#endif
1245 default:
wdenk27b207f2003-07-24 23:38:38 +00001246 goto next_sector;
wdenk5bb226e2003-11-17 21:14:37 +00001247 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001248
wdenkbdccc4f2003-08-05 17:43:17 +00001249next_sector: ;
wdenk27b207f2003-07-24 23:38:38 +00001250 }
wdenkbdccc4f2003-08-05 17:43:17 +00001251next_bank: ;
wdenk27b207f2003-07-24 23:38:38 +00001252 }
Vipin Kumar8fdf1e02012-12-16 22:32:48 +00001253 return 0;
1254}
1255#endif
1256
1257#if defined(CONFIG_CMD_IMLS_NAND)
1258static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off,
1259 size_t len)
1260{
1261 void *imgdata;
1262 int ret;
1263
1264 imgdata = malloc(len);
1265 if (!imgdata) {
1266 printf("May be a Legacy Image at NAND device %d offset %08llX:\n",
1267 nand_dev, off);
1268 printf(" Low memory(cannot allocate memory for image)\n");
1269 return -ENOMEM;
1270 }
1271
1272 ret = nand_read_skip_bad(nand, off, &len,
1273 imgdata);
1274 if (ret < 0 && ret != -EUCLEAN) {
1275 free(imgdata);
1276 return ret;
1277 }
1278
1279 if (!image_check_hcrc(imgdata)) {
1280 free(imgdata);
1281 return 0;
1282 }
1283
1284 printf("Legacy Image at NAND device %d offset %08llX:\n",
1285 nand_dev, off);
1286 image_print_contents(imgdata);
1287
1288 puts(" Verifying Checksum ... ");
1289 if (!image_check_dcrc(imgdata))
1290 puts("Bad Data CRC\n");
1291 else
1292 puts("OK\n");
1293
1294 free(imgdata);
1295
1296 return 0;
1297}
1298
1299static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off,
1300 size_t len)
1301{
1302 void *imgdata;
1303 int ret;
1304
1305 imgdata = malloc(len);
1306 if (!imgdata) {
1307 printf("May be a FIT Image at NAND device %d offset %08llX:\n",
1308 nand_dev, off);
1309 printf(" Low memory(cannot allocate memory for image)\n");
1310 return -ENOMEM;
1311 }
1312
1313 ret = nand_read_skip_bad(nand, off, &len,
1314 imgdata);
1315 if (ret < 0 && ret != -EUCLEAN) {
1316 free(imgdata);
1317 return ret;
1318 }
1319
1320 if (!fit_check_format(imgdata)) {
1321 free(imgdata);
1322 return 0;
1323 }
1324
1325 printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off);
1326
1327 fit_print_contents(imgdata);
1328 free(imgdata);
1329
1330 return 0;
1331}
1332
1333static int do_imls_nand(void)
1334{
1335 nand_info_t *nand;
1336 int nand_dev = nand_curr_device;
1337 size_t len;
1338 loff_t off;
1339 u32 buffer[16];
1340
1341 if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) {
1342 puts("\nNo NAND devices available\n");
1343 return -ENODEV;
1344 }
1345
1346 printf("\n");
1347
1348 for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) {
1349 nand = &nand_info[nand_dev];
1350 if (!nand->name || !nand->size)
1351 continue;
1352
1353 for (off = 0; off < nand->size; off += nand->erasesize) {
1354 const image_header_t *header;
1355 int ret;
1356
1357 if (nand_block_isbad(nand, off))
1358 continue;
1359
1360 len = sizeof(buffer);
1361
1362 ret = nand_read(nand, off, &len, (u8 *)buffer);
1363 if (ret < 0 && ret != -EUCLEAN) {
1364 printf("NAND read error %d at offset %08llX\n",
1365 ret, off);
1366 continue;
1367 }
1368
1369 switch (genimg_get_format(buffer)) {
Heiko Schocher21d29f72014-05-28 11:33:33 +02001370#if defined(CONFIG_IMAGE_FORMAT_LEGACY)
Vipin Kumar8fdf1e02012-12-16 22:32:48 +00001371 case IMAGE_FORMAT_LEGACY:
1372 header = (const image_header_t *)buffer;
1373
1374 len = image_get_image_size(header);
1375 nand_imls_legacyimage(nand, nand_dev, off, len);
1376 break;
Heiko Schocher21d29f72014-05-28 11:33:33 +02001377#endif
Vipin Kumar8fdf1e02012-12-16 22:32:48 +00001378#if defined(CONFIG_FIT)
1379 case IMAGE_FORMAT_FIT:
1380 len = fit_get_size(buffer);
1381 nand_imls_fitimage(nand, nand_dev, off, len);
1382 break;
1383#endif
1384 }
1385 }
1386 }
1387
1388 return 0;
1389}
1390#endif
1391
1392#if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
1393static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1394{
1395 int ret_nor = 0, ret_nand = 0;
1396
1397#if defined(CONFIG_CMD_IMLS)
1398 ret_nor = do_imls_nor();
1399#endif
1400
1401#if defined(CONFIG_CMD_IMLS_NAND)
1402 ret_nand = do_imls_nand();
1403#endif
1404
1405 if (ret_nor)
1406 return ret_nor;
1407
1408 if (ret_nand)
1409 return ret_nand;
wdenk27b207f2003-07-24 23:38:38 +00001410
1411 return (0);
1412}
1413
1414U_BOOT_CMD(
1415 imls, 1, 1, do_imls,
Peter Tyser2fb26042009-01-27 18:03:12 -06001416 "list all images found in flash",
wdenk27b207f2003-07-24 23:38:38 +00001417 "\n"
Vipin Kumar8fdf1e02012-12-16 22:32:48 +00001418 " - Prints information about all images found at sector/block\n"
1419 " boundaries in nor/nand flash."
wdenk27b207f2003-07-24 23:38:38 +00001420);
Jon Loeliger90253172007-07-10 11:02:44 -05001421#endif
wdenk27b207f2003-07-24 23:38:38 +00001422
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001423/*******************************************************************/
Marian Balakowicz5cf746c2008-01-31 13:59:09 +01001424/* helper routines */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001425/*******************************************************************/
Joe Hershbergerbe2e5a02013-02-27 10:20:59 +00001426#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
Doug Andersona558ad72012-01-17 09:37:41 +00001427
1428#define CONSOLE_ARG "console="
1429#define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1)
1430
Doug Anderson3a8653b2011-10-19 12:30:57 +00001431static void fixup_silent_linux(void)
wdenk47d1a6e2002-11-03 00:01:44 +00001432{
Doug Andersona558ad72012-01-17 09:37:41 +00001433 char *buf;
1434 const char *env_val;
Doug Anderson3a8653b2011-10-19 12:30:57 +00001435 char *cmdline = getenv("bootargs");
Simon Glass8d51aac2013-07-16 20:10:00 -07001436 int want_silent;
wdenk47d1a6e2002-11-03 00:01:44 +00001437
Simon Glass8d51aac2013-07-16 20:10:00 -07001438 /*
1439 * Only fix cmdline when requested. The environment variable can be:
1440 *
1441 * no - we never fixup
1442 * yes - we always fixup
1443 * unset - we rely on the console silent flag
1444 */
1445 want_silent = getenv_yesno("silent_linux");
1446 if (want_silent == 0)
1447 return;
1448 else if (want_silent == -1 && !(gd->flags & GD_FLG_SILENT))
wdenk47d1a6e2002-11-03 00:01:44 +00001449 return;
1450
Doug Anderson3a8653b2011-10-19 12:30:57 +00001451 debug("before silent fix-up: %s\n", cmdline);
Doug Andersona558ad72012-01-17 09:37:41 +00001452 if (cmdline && (cmdline[0] != '\0')) {
1453 char *start = strstr(cmdline, CONSOLE_ARG);
1454
1455 /* Allocate space for maximum possible new command line */
1456 buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_LEN + 1);
1457 if (!buf) {
1458 debug("%s: out of memory\n", __func__);
1459 return;
wdenk47d1a6e2002-11-03 00:01:44 +00001460 }
Doug Andersona558ad72012-01-17 09:37:41 +00001461
1462 if (start) {
1463 char *end = strchr(start, ' ');
1464 int num_start_bytes = start - cmdline + CONSOLE_ARG_LEN;
1465
1466 strncpy(buf, cmdline, num_start_bytes);
1467 if (end)
1468 strcpy(buf + num_start_bytes, end);
1469 else
1470 buf[num_start_bytes] = '\0';
1471 } else {
1472 sprintf(buf, "%s %s", cmdline, CONSOLE_ARG);
1473 }
1474 env_val = buf;
wdenk47d1a6e2002-11-03 00:01:44 +00001475 } else {
Doug Andersona558ad72012-01-17 09:37:41 +00001476 buf = NULL;
1477 env_val = CONSOLE_ARG;
wdenk47d1a6e2002-11-03 00:01:44 +00001478 }
1479
Doug Andersona558ad72012-01-17 09:37:41 +00001480 setenv("bootargs", env_val);
1481 debug("after silent fix-up: %s\n", env_val);
1482 free(buf);
wdenk47d1a6e2002-11-03 00:01:44 +00001483}
1484#endif /* CONFIG_SILENT_CONSOLE */
1485
Steven Stallioneeaef5e2013-06-10 01:00:09 -07001486#if defined(CONFIG_BOOTM_NETBSD) || defined(CONFIG_BOOTM_PLAN9)
1487static void copy_args(char *dest, int argc, char * const argv[], char delim)
1488{
1489 int i;
1490
1491 for (i = 0; i < argc; i++) {
1492 if (i > 0)
1493 *dest++ = delim;
1494 strcpy(dest, argv[i]);
1495 dest += strlen(argv[i]);
1496 }
1497}
1498#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001499
1500/*******************************************************************/
1501/* OS booting routines */
1502/*******************************************************************/
1503
Kumar Galab1d0db12008-10-21 17:25:47 -05001504#ifdef CONFIG_BOOTM_NETBSD
Stephen Warren712fbcf2011-10-18 11:11:49 +00001505static int do_bootm_netbsd(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001506 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001507{
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001508 void (*loader)(bd_t *, image_header_t *, char *, char *);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001509 image_header_t *os_hdr, *hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001510 ulong kernel_data, kernel_len;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001511 char *consdev;
1512 char *cmdline;
wdenk47d1a6e2002-11-03 00:01:44 +00001513
Miao Yan5b629312013-11-04 11:18:14 +08001514 if (flag != BOOTM_STATE_OS_GO)
Simon Glass7af26b12013-07-10 23:08:09 -07001515 return 0;
Kumar Gala49c3a862008-10-21 17:25:45 -05001516
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001517#if defined(CONFIG_FIT)
1518 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001519 fit_unsupported_reset("NetBSD");
Kumar Gala40d7e992008-08-15 08:24:45 -05001520 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001521 }
1522#endif
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001523 hdr = images->legacy_hdr_os;
wdenk47d1a6e2002-11-03 00:01:44 +00001524
1525 /*
1526 * Booting a (NetBSD) kernel image
1527 *
1528 * This process is pretty similar to a standalone application:
1529 * The (first part of an multi-) image must be a stage-2 loader,
1530 * which in turn is responsible for loading & invoking the actual
1531 * kernel. The only differences are the parameters being passed:
1532 * besides the board info strucure, the loader expects a command
1533 * line, the name of the console device, and (optionally) the
1534 * address of the original image header.
1535 */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001536 os_hdr = NULL;
Stephen Warren712fbcf2011-10-18 11:11:49 +00001537 if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1538 image_multi_getimg(hdr, 1, &kernel_data, &kernel_len);
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001539 if (kernel_len)
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001540 os_hdr = hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001541 }
wdenk47d1a6e2002-11-03 00:01:44 +00001542
1543 consdev = "";
Stephen Warren712fbcf2011-10-18 11:11:49 +00001544#if defined(CONFIG_8xx_CONS_SMC1)
wdenk47d1a6e2002-11-03 00:01:44 +00001545 consdev = "smc1";
Stephen Warren712fbcf2011-10-18 11:11:49 +00001546#elif defined(CONFIG_8xx_CONS_SMC2)
wdenk47d1a6e2002-11-03 00:01:44 +00001547 consdev = "smc2";
Stephen Warren712fbcf2011-10-18 11:11:49 +00001548#elif defined(CONFIG_8xx_CONS_SCC2)
wdenk47d1a6e2002-11-03 00:01:44 +00001549 consdev = "scc2";
Stephen Warren712fbcf2011-10-18 11:11:49 +00001550#elif defined(CONFIG_8xx_CONS_SCC3)
wdenk47d1a6e2002-11-03 00:01:44 +00001551 consdev = "scc3";
1552#endif
1553
Simon Glass983c72f2013-06-11 11:14:46 -07001554 if (argc > 0) {
wdenk47d1a6e2002-11-03 00:01:44 +00001555 ulong len;
1556 int i;
1557
Simon Glass983c72f2013-06-11 11:14:46 -07001558 for (i = 0, len = 0; i < argc; i += 1)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001559 len += strlen(argv[i]) + 1;
1560 cmdline = malloc(len);
Steven Stallioneeaef5e2013-06-10 01:00:09 -07001561 copy_args(cmdline, argc, argv, ' ');
Stephen Warren712fbcf2011-10-18 11:11:49 +00001562 } else if ((cmdline = getenv("bootargs")) == NULL) {
wdenk47d1a6e2002-11-03 00:01:44 +00001563 cmdline = "";
1564 }
1565
Kumar Galac160a952008-08-15 08:24:36 -05001566 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
wdenk47d1a6e2002-11-03 00:01:44 +00001567
Stephen Warren712fbcf2011-10-18 11:11:49 +00001568 printf("## Transferring control to NetBSD stage-2 loader "
1569 "(at address %08lx) ...\n",
wdenk47d1a6e2002-11-03 00:01:44 +00001570 (ulong)loader);
1571
Simon Glass770605e2012-02-13 13:51:18 +00001572 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
wdenk47d1a6e2002-11-03 00:01:44 +00001573
1574 /*
1575 * NetBSD Stage-2 Loader Parameters:
Kees Jongenburgere2ce8162013-12-12 16:18:35 +01001576 * arg[0]: pointer to board info data
1577 * arg[1]: image load address
1578 * arg[2]: char pointer to the console device to use
1579 * arg[3]: char pointer to the boot arguments
wdenk47d1a6e2002-11-03 00:01:44 +00001580 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001581 (*loader)(gd->bd, os_hdr, consdev, cmdline);
Kumar Gala40d7e992008-08-15 08:24:45 -05001582
1583 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001584}
Kumar Galab1d0db12008-10-21 17:25:47 -05001585#endif /* CONFIG_BOOTM_NETBSD*/
wdenk47d1a6e2002-11-03 00:01:44 +00001586
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001587#ifdef CONFIG_LYNXKDI
Stephen Warren712fbcf2011-10-18 11:11:49 +00001588static int do_bootm_lynxkdi(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001589 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001590{
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001591 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001592
Miao Yan5b629312013-11-04 11:18:14 +08001593 if (flag != BOOTM_STATE_OS_GO)
Simon Glass7af26b12013-07-10 23:08:09 -07001594 return 0;
Kumar Gala49c3a862008-10-21 17:25:45 -05001595
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001596#if defined(CONFIG_FIT)
1597 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001598 fit_unsupported_reset("Lynx");
Kumar Gala40d7e992008-08-15 08:24:45 -05001599 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001600 }
1601#endif
1602
Stephen Warren712fbcf2011-10-18 11:11:49 +00001603 lynxkdi_boot((image_header_t *)hdr);
Kumar Gala40d7e992008-08-15 08:24:45 -05001604
1605 return 1;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001606}
1607#endif /* CONFIG_LYNXKDI */
1608
Kumar Galab1d0db12008-10-21 17:25:47 -05001609#ifdef CONFIG_BOOTM_RTEMS
Stephen Warren712fbcf2011-10-18 11:11:49 +00001610static int do_bootm_rtems(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001611 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001612{
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001613 void (*entry_point)(bd_t *);
wdenkd791b1d2003-04-20 14:04:18 +00001614
Miao Yan5b629312013-11-04 11:18:14 +08001615 if (flag != BOOTM_STATE_OS_GO)
Simon Glass7af26b12013-07-10 23:08:09 -07001616 return 0;
Kumar Gala49c3a862008-10-21 17:25:45 -05001617
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001618#if defined(CONFIG_FIT)
1619 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001620 fit_unsupported_reset("RTEMS");
Kumar Gala40d7e992008-08-15 08:24:45 -05001621 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001622 }
1623#endif
1624
Kumar Galac160a952008-08-15 08:24:36 -05001625 entry_point = (void (*)(bd_t *))images->ep;
wdenkd791b1d2003-04-20 14:04:18 +00001626
Stephen Warren712fbcf2011-10-18 11:11:49 +00001627 printf("## Transferring control to RTEMS (at address %08lx) ...\n",
wdenkd791b1d2003-04-20 14:04:18 +00001628 (ulong)entry_point);
1629
Simon Glass770605e2012-02-13 13:51:18 +00001630 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
wdenkd791b1d2003-04-20 14:04:18 +00001631
1632 /*
1633 * RTEMS Parameters:
1634 * r3: ptr to board info data
1635 */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001636 (*entry_point)(gd->bd);
Kumar Gala40d7e992008-08-15 08:24:45 -05001637
1638 return 1;
wdenkd791b1d2003-04-20 14:04:18 +00001639}
Kumar Galab1d0db12008-10-21 17:25:47 -05001640#endif /* CONFIG_BOOTM_RTEMS */
wdenkd791b1d2003-04-20 14:04:18 +00001641
Torkel Lundgren3df61952010-09-28 11:05:36 +02001642#if defined(CONFIG_BOOTM_OSE)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001643static int do_bootm_ose(int flag, int argc, char * const argv[],
Torkel Lundgren3df61952010-09-28 11:05:36 +02001644 bootm_headers_t *images)
1645{
1646 void (*entry_point)(void);
1647
Miao Yan5b629312013-11-04 11:18:14 +08001648 if (flag != BOOTM_STATE_OS_GO)
Simon Glass7af26b12013-07-10 23:08:09 -07001649 return 0;
Torkel Lundgren3df61952010-09-28 11:05:36 +02001650
1651#if defined(CONFIG_FIT)
1652 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001653 fit_unsupported_reset("OSE");
Torkel Lundgren3df61952010-09-28 11:05:36 +02001654 return 1;
1655 }
1656#endif
1657
1658 entry_point = (void (*)(void))images->ep;
1659
Stephen Warren712fbcf2011-10-18 11:11:49 +00001660 printf("## Transferring control to OSE (at address %08lx) ...\n",
Torkel Lundgren3df61952010-09-28 11:05:36 +02001661 (ulong)entry_point);
1662
Simon Glass770605e2012-02-13 13:51:18 +00001663 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
Torkel Lundgren3df61952010-09-28 11:05:36 +02001664
1665 /*
1666 * OSE Parameters:
1667 * None
1668 */
1669 (*entry_point)();
1670
1671 return 1;
1672}
1673#endif /* CONFIG_BOOTM_OSE */
1674
Steven Stallion04d41402013-03-20 06:31:35 +00001675#if defined(CONFIG_BOOTM_PLAN9)
1676static int do_bootm_plan9(int flag, int argc, char * const argv[],
1677 bootm_headers_t *images)
1678{
1679 void (*entry_point)(void);
Steven Stallioneeaef5e2013-06-10 01:00:09 -07001680 char *s;
Steven Stallion04d41402013-03-20 06:31:35 +00001681
Miao Yan5b629312013-11-04 11:18:14 +08001682 if (flag != BOOTM_STATE_OS_GO)
Simon Glass7af26b12013-07-10 23:08:09 -07001683 return 0;
Steven Stallion04d41402013-03-20 06:31:35 +00001684
1685#if defined(CONFIG_FIT)
1686 if (!images->legacy_hdr_valid) {
1687 fit_unsupported_reset("Plan 9");
1688 return 1;
1689 }
1690#endif
1691
Steven Stallioneeaef5e2013-06-10 01:00:09 -07001692 /* See README.plan9 */
1693 s = getenv("confaddr");
1694 if (s != NULL) {
1695 char *confaddr = (char *)simple_strtoul(s, NULL, 16);
1696
1697 if (argc > 0) {
1698 copy_args(confaddr, argc, argv, '\n');
1699 } else {
1700 s = getenv("bootargs");
1701 if (s != NULL)
1702 strcpy(confaddr, s);
1703 }
1704 }
1705
Steven Stallion04d41402013-03-20 06:31:35 +00001706 entry_point = (void (*)(void))images->ep;
1707
1708 printf("## Transferring control to Plan 9 (at address %08lx) ...\n",
1709 (ulong)entry_point);
1710
1711 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1712
1713 /*
1714 * Plan 9 Parameters:
1715 * None
1716 */
1717 (*entry_point)();
1718
1719 return 1;
1720}
1721#endif /* CONFIG_BOOTM_PLAN9 */
1722
Miao Yan871a57b2013-11-28 17:51:38 +08001723#if defined(CONFIG_BOOTM_VXWORKS) && \
1724 (defined(CONFIG_PPC) || defined(CONFIG_ARM))
1725
1726void do_bootvx_fdt(bootm_headers_t *images)
1727{
1728#if defined(CONFIG_OF_LIBFDT)
1729 int ret;
1730 char *bootline;
1731 ulong of_size = images->ft_len;
1732 char **of_flat_tree = &images->ft_addr;
1733 struct lmb *lmb = &images->lmb;
1734
1735 if (*of_flat_tree) {
1736 boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree);
1737
1738 ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size);
1739 if (ret)
1740 return;
1741
1742 ret = fdt_add_subnode(*of_flat_tree, 0, "chosen");
1743 if ((ret >= 0 || ret == -FDT_ERR_EXISTS)) {
1744 bootline = getenv("bootargs");
1745 if (bootline) {
1746 ret = fdt_find_and_setprop(*of_flat_tree,
1747 "/chosen", "bootargs",
1748 bootline,
1749 strlen(bootline) + 1, 1);
1750 if (ret < 0) {
1751 printf("## ERROR: %s : %s\n", __func__,
1752 fdt_strerror(ret));
1753 return;
1754 }
1755 }
1756 } else {
1757 printf("## ERROR: %s : %s\n", __func__,
1758 fdt_strerror(ret));
1759 return;
1760 }
1761 }
1762#endif
1763
1764 boot_prep_vxworks(images);
1765
1766 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1767
1768#if defined(CONFIG_OF_LIBFDT)
1769 printf("## Starting vxWorks at 0x%08lx, device tree at 0x%08lx ...\n",
1770 (ulong)images->ep, (ulong)*of_flat_tree);
1771#else
1772 printf("## Starting vxWorks at 0x%08lx\n", (ulong)images->ep);
1773#endif
1774
1775 boot_jump_vxworks(images);
1776
1777 puts("## vxWorks terminated\n");
1778}
1779
Stephen Warren712fbcf2011-10-18 11:11:49 +00001780static int do_bootm_vxworks(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001781 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001782{
Miao Yan5b629312013-11-04 11:18:14 +08001783 if (flag != BOOTM_STATE_OS_GO)
Simon Glass7af26b12013-07-10 23:08:09 -07001784 return 0;
Kumar Gala49c3a862008-10-21 17:25:45 -05001785
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001786#if defined(CONFIG_FIT)
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001787 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001788 fit_unsupported_reset("VxWorks");
Kumar Gala40d7e992008-08-15 08:24:45 -05001789 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001790 }
1791#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001792
Miao Yan871a57b2013-11-28 17:51:38 +08001793 do_bootvx_fdt(images);
Kumar Gala40d7e992008-08-15 08:24:45 -05001794
1795 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001796}
Miao Yan17ab52f2013-11-28 17:51:36 +08001797#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001798
Miao Yan17ab52f2013-11-28 17:51:36 +08001799#if defined(CONFIG_CMD_ELF)
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001800static int do_bootm_qnxelf(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001801 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001802{
wdenk47d1a6e2002-11-03 00:01:44 +00001803 char *local_args[2];
1804 char str[16];
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001805
Miao Yan5b629312013-11-04 11:18:14 +08001806 if (flag != BOOTM_STATE_OS_GO)
Simon Glass7af26b12013-07-10 23:08:09 -07001807 return 0;
Kumar Gala49c3a862008-10-21 17:25:45 -05001808
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001809#if defined(CONFIG_FIT)
1810 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001811 fit_unsupported_reset("QNX");
Kumar Gala40d7e992008-08-15 08:24:45 -05001812 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001813 }
1814#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001815
Kumar Galac160a952008-08-15 08:24:36 -05001816 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001817 local_args[0] = argv[0];
1818 local_args[1] = str; /* and provide it via the arguments */
Kumar Gala40d7e992008-08-15 08:24:45 -05001819 do_bootelf(NULL, 0, 2, local_args);
1820
1821 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001822}
Jon Loeliger90253172007-07-10 11:02:44 -05001823#endif
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001824
1825#ifdef CONFIG_INTEGRITY
Stephen Warren712fbcf2011-10-18 11:11:49 +00001826static int do_bootm_integrity(int flag, int argc, char * const argv[],
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001827 bootm_headers_t *images)
1828{
1829 void (*entry_point)(void);
1830
Miao Yan5b629312013-11-04 11:18:14 +08001831 if (flag != BOOTM_STATE_OS_GO)
Simon Glass7af26b12013-07-10 23:08:09 -07001832 return 0;
Kumar Gala49c3a862008-10-21 17:25:45 -05001833
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001834#if defined(CONFIG_FIT)
1835 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001836 fit_unsupported_reset("INTEGRITY");
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001837 return 1;
1838 }
1839#endif
1840
1841 entry_point = (void (*)(void))images->ep;
1842
Stephen Warren712fbcf2011-10-18 11:11:49 +00001843 printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001844 (ulong)entry_point);
1845
Simon Glass770605e2012-02-13 13:51:18 +00001846 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001847
1848 /*
1849 * INTEGRITY Parameters:
1850 * None
1851 */
1852 (*entry_point)();
1853
1854 return 1;
1855}
1856#endif
Marek Vasut44f074c2012-03-14 21:52:45 +00001857
1858#ifdef CONFIG_CMD_BOOTZ
1859
Simon Glassa5266d62013-07-04 13:26:10 -07001860int __weak bootz_setup(ulong image, ulong *start, ulong *end)
Marek Vasut44f074c2012-03-14 21:52:45 +00001861{
1862 /* Please define bootz_setup() for your platform */
1863
1864 puts("Your platform's zImage format isn't supported yet!\n");
1865 return -1;
1866}
Marek Vasut44f074c2012-03-14 21:52:45 +00001867
1868/*
1869 * zImage booting support
1870 */
1871static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
1872 char * const argv[], bootm_headers_t *images)
1873{
1874 int ret;
Simon Glassa5266d62013-07-04 13:26:10 -07001875 ulong zi_start, zi_end;
Marek Vasut44f074c2012-03-14 21:52:45 +00001876
Simon Glass35fc84f2013-06-11 11:14:47 -07001877 ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
1878 images, 1);
Marek Vasut44f074c2012-03-14 21:52:45 +00001879
1880 /* Setup Linux kernel zImage entry point */
Tom Rini2b9599e2013-07-09 15:32:34 -04001881 if (!argc) {
Marek Vasut44f074c2012-03-14 21:52:45 +00001882 images->ep = load_addr;
1883 debug("* kernel: default image load address = 0x%08lx\n",
1884 load_addr);
1885 } else {
Tom Rini2b9599e2013-07-09 15:32:34 -04001886 images->ep = simple_strtoul(argv[0], NULL, 16);
Marek Vasut44f074c2012-03-14 21:52:45 +00001887 debug("* kernel: cmdline image address = 0x%08lx\n",
1888 images->ep);
1889 }
1890
Simon Glassa5266d62013-07-04 13:26:10 -07001891 ret = bootz_setup(images->ep, &zi_start, &zi_end);
Marek Vasut44f074c2012-03-14 21:52:45 +00001892 if (ret != 0)
1893 return 1;
1894
1895 lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
1896
Tom Rini225fd8c2013-07-09 15:33:25 -04001897 /*
1898 * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
1899 * have a header that provide this informaiton.
1900 */
Tom Rini2b9599e2013-07-09 15:32:34 -04001901 if (bootm_find_ramdisk(flag, argc, argv))
1902 return 1;
Marek Vasut44f074c2012-03-14 21:52:45 +00001903
Tom Rini2b9599e2013-07-09 15:32:34 -04001904#if defined(CONFIG_OF_LIBFDT)
1905 if (bootm_find_fdt(flag, argc, argv))
1906 return 1;
1907#endif
1908
1909 return 0;
Marek Vasut44f074c2012-03-14 21:52:45 +00001910}
1911
Rob Herringda620222012-12-02 21:00:23 -06001912int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Marek Vasut44f074c2012-03-14 21:52:45 +00001913{
Simon Glass35fc84f2013-06-11 11:14:47 -07001914 int ret;
Marek Vasut44f074c2012-03-14 21:52:45 +00001915
Tom Rini2b9599e2013-07-09 15:32:34 -04001916 /* Consume 'bootz' */
1917 argc--; argv++;
1918
Marek Vasut44f074c2012-03-14 21:52:45 +00001919 if (bootz_start(cmdtp, flag, argc, argv, &images))
1920 return 1;
1921
Simon Glass385501d2013-07-04 13:26:08 -07001922 /*
1923 * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
1924 * disable interrupts ourselves
1925 */
1926 bootm_disable_interrupts();
1927
Simon Glassfb1b1392013-07-04 13:26:11 -07001928 images.os.os = IH_OS_LINUX;
Simon Glass35fc84f2013-06-11 11:14:47 -07001929 ret = do_bootm_states(cmdtp, flag, argc, argv,
Simon Glassfb1b1392013-07-04 13:26:11 -07001930 BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
1931 BOOTM_STATE_OS_GO,
Simon Glassd0ae31e2013-06-11 11:14:48 -07001932 &images, 1);
Marek Vasut44f074c2012-03-14 21:52:45 +00001933
Simon Glass35fc84f2013-06-11 11:14:47 -07001934 return ret;
Marek Vasut44f074c2012-03-14 21:52:45 +00001935}
1936
Kim Phillips088f1b12012-10-29 13:34:31 +00001937#ifdef CONFIG_SYS_LONGHELP
1938static char bootz_help_text[] =
Marek Vasut017e1f32012-03-18 11:47:58 +00001939 "[addr [initrd[:size]] [fdt]]\n"
1940 " - boot Linux zImage stored in memory\n"
Marek Vasut44f074c2012-03-14 21:52:45 +00001941 "\tThe argument 'initrd' is optional and specifies the address\n"
Marek Vasut017e1f32012-03-18 11:47:58 +00001942 "\tof the initrd in memory. The optional argument ':size' allows\n"
1943 "\tspecifying the size of RAW initrd.\n"
Marek Vasut44f074c2012-03-14 21:52:45 +00001944#if defined(CONFIG_OF_LIBFDT)
1945 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
1946 "\ta third argument is required which is the address of the\n"
1947 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1948 "\tuse a '-' for the second argument. If you do not pass a third\n"
1949 "\ta bd_info struct will be passed instead\n"
1950#endif
Kim Phillips088f1b12012-10-29 13:34:31 +00001951 "";
1952#endif
1953
1954U_BOOT_CMD(
1955 bootz, CONFIG_SYS_MAXARGS, 1, do_bootz,
1956 "boot Linux zImage image from memory", bootz_help_text
Marek Vasut44f074c2012-03-14 21:52:45 +00001957);
1958#endif /* CONFIG_CMD_BOOTZ */