blob: 9751edc9076121db4680fa91cc606c3ae4369804 [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
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020035#ifdef CONFIG_SYS_HUSH_PARSER
wdenk47d1a6e2002-11-03 00:01:44 +000036#include <hush.h>
37#endif
38
Kumar Gala54f9c862008-08-15 08:24:39 -050039#if defined(CONFIG_OF_LIBFDT)
Kumar Gala54f9c862008-08-15 08:24:39 -050040#include <libfdt.h>
41#include <fdt_support.h>
42#endif
43
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +020044#ifdef CONFIG_LZMA
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +020045#include <lzma/LzmaTypes.h>
Luigi 'Comio' Mantellinicaf72ff2009-07-21 10:45:49 +020046#include <lzma/LzmaDec.h>
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +020047#include <lzma/LzmaTools.h>
48#endif /* CONFIG_LZMA */
49
Peter Korsgaard20dde482009-11-19 11:37:51 +010050#ifdef CONFIG_LZO
51#include <linux/lzo.h>
52#endif /* CONFIG_LZO */
53
Marian Balakowicz1ee11802008-01-08 18:17:10 +010054DECLARE_GLOBAL_DATA_PTR;
55
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020056#ifndef CONFIG_SYS_BOOTM_LEN
57#define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
wdenk47d1a6e2002-11-03 00:01:44 +000058#endif
59
Marian Balakowicz321359f2008-01-08 18:11:43 +010060#ifdef CONFIG_BZIP2
61extern void bz_internal_error(int);
wdenk228f29a2002-12-08 09:53:23 +000062#endif
63
Jon Loeligerbaa26db2007-07-08 17:51:39 -050064#if defined(CONFIG_CMD_IMI)
Stephen Warren712fbcf2011-10-18 11:11:49 +000065static int image_info(unsigned long addr);
wdenk47d1a6e2002-11-03 00:01:44 +000066#endif
wdenk27b207f2003-07-24 23:38:38 +000067
Jon Loeligerbaa26db2007-07-08 17:51:39 -050068#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +000069#include <flash.h>
Stefan Roeseca5def32010-08-31 10:00:10 +020070#include <mtd/cfi_flash.h>
Marian Balakowicze6f2e902005-10-11 19:09:42 +020071extern flash_info_t flash_info[]; /* info for FLASH chips */
Vipin Kumar8fdf1e02012-12-16 22:32:48 +000072#endif
73
74#if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
Stephen Warren712fbcf2011-10-18 11:11:49 +000075static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
wdenk27b207f2003-07-24 23:38:38 +000076#endif
77
Vipin Kumar8fdf1e02012-12-16 22:32:48 +000078#include <linux/err.h>
79#include <nand.h>
80
Joe Hershbergerbe2e5a02013-02-27 10:20:59 +000081#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
Stephen Warren712fbcf2011-10-18 11:11:49 +000082static void fixup_silent_linux(void);
wdenk2262cfe2002-11-18 00:14:45 +000083#endif
84
Simon Glassc5cbe1e2013-12-26 16:26:24 -070085static int do_bootm_standalone(int flag, int argc, char * const argv[],
86 bootm_headers_t *images);
87
Simon Glass35e7b0f2013-05-07 06:12:03 +000088static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
Stephen Warren712fbcf2011-10-18 11:11:49 +000089 char * const argv[], bootm_headers_t *images,
90 ulong *os_data, ulong *os_len);
wdenk47d1a6e2002-11-03 00:01:44 +000091
wdenk47d1a6e2002-11-03 00:01:44 +000092/*
93 * Continue booting an OS image; caller already has:
94 * - copied image header to global variable `header'
95 * - checked header magic number, checksums (both header & image),
96 * - verified image architecture (PPC) and type (KERNEL or MULTI),
97 * - loaded (first part of) image to header load address,
98 * - disabled interrupts.
Simon Glass983c72f2013-06-11 11:14:46 -070099 *
Simon Glass35fc84f2013-06-11 11:14:47 -0700100 * @flag: Flags indicating what to do (BOOTM_STATE_...)
Simon Glass983c72f2013-06-11 11:14:46 -0700101 * @argc: Number of arguments. Note that the arguments are shifted down
102 * so that 0 is the first argument not processed by U-Boot, and
103 * argc is adjusted accordingly. This avoids confusion as to how
104 * many arguments are available for the OS.
105 * @images: Pointers to os/initrd/fdt
106 * @return 1 on error. On success the OS boots so this function does
107 * not return.
wdenk47d1a6e2002-11-03 00:01:44 +0000108 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000109typedef int boot_os_fn(int flag, int argc, char * const argv[],
Simon Glass983c72f2013-06-11 11:14:46 -0700110 bootm_headers_t *images);
wdenk47d1a6e2002-11-03 00:01:44 +0000111
Kumar Galab1d0db12008-10-21 17:25:47 -0500112#ifdef CONFIG_BOOTM_LINUX
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100113extern boot_os_fn do_bootm_linux;
Kumar Galab1d0db12008-10-21 17:25:47 -0500114#endif
115#ifdef CONFIG_BOOTM_NETBSD
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100116static boot_os_fn do_bootm_netbsd;
Kumar Galab1d0db12008-10-21 17:25:47 -0500117#endif
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100118#if defined(CONFIG_LYNXKDI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100119static boot_os_fn do_bootm_lynxkdi;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000120extern void lynxkdi_boot(image_header_t *);
wdenk8bde7f72003-06-27 21:31:46 +0000121#endif
Kumar Galab1d0db12008-10-21 17:25:47 -0500122#ifdef CONFIG_BOOTM_RTEMS
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100123static boot_os_fn do_bootm_rtems;
Kumar Galab1d0db12008-10-21 17:25:47 -0500124#endif
Torkel Lundgren3df61952010-09-28 11:05:36 +0200125#if defined(CONFIG_BOOTM_OSE)
126static boot_os_fn do_bootm_ose;
127#endif
Steven Stallion04d41402013-03-20 06:31:35 +0000128#if defined(CONFIG_BOOTM_PLAN9)
129static boot_os_fn do_bootm_plan9;
130#endif
Miao Yan871a57b2013-11-28 17:51:38 +0800131#if defined(CONFIG_BOOTM_VXWORKS) && \
132 (defined(CONFIG_PPC) || defined(CONFIG_ARM))
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100133static boot_os_fn do_bootm_vxworks;
Miao Yan17ab52f2013-11-28 17:51:36 +0800134#endif
135#if defined(CONFIG_CMD_ELF)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100136static boot_os_fn do_bootm_qnxelf;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000137int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
138int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
Jon Loeliger90253172007-07-10 11:02:44 -0500139#endif
Peter Tyserf5ed9e32008-09-08 14:56:49 -0500140#if defined(CONFIG_INTEGRITY)
141static boot_os_fn do_bootm_integrity;
142#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000143
Mike Frysinger00085552009-11-03 11:36:26 -0500144static boot_os_fn *boot_os[] = {
Simon Glassc5cbe1e2013-12-26 16:26:24 -0700145 [IH_OS_U_BOOT] = do_bootm_standalone,
Kumar Galab1d0db12008-10-21 17:25:47 -0500146#ifdef CONFIG_BOOTM_LINUX
Kumar Galabe083152008-10-21 17:25:44 -0500147 [IH_OS_LINUX] = do_bootm_linux,
Kumar Galab1d0db12008-10-21 17:25:47 -0500148#endif
149#ifdef CONFIG_BOOTM_NETBSD
Kumar Galabe083152008-10-21 17:25:44 -0500150 [IH_OS_NETBSD] = do_bootm_netbsd,
Kumar Galab1d0db12008-10-21 17:25:47 -0500151#endif
Kumar Galabe083152008-10-21 17:25:44 -0500152#ifdef CONFIG_LYNXKDI
153 [IH_OS_LYNXOS] = do_bootm_lynxkdi,
154#endif
Kumar Galab1d0db12008-10-21 17:25:47 -0500155#ifdef CONFIG_BOOTM_RTEMS
Kumar Galabe083152008-10-21 17:25:44 -0500156 [IH_OS_RTEMS] = do_bootm_rtems,
Kumar Galab1d0db12008-10-21 17:25:47 -0500157#endif
Torkel Lundgren3df61952010-09-28 11:05:36 +0200158#if defined(CONFIG_BOOTM_OSE)
159 [IH_OS_OSE] = do_bootm_ose,
160#endif
Steven Stallion04d41402013-03-20 06:31:35 +0000161#if defined(CONFIG_BOOTM_PLAN9)
162 [IH_OS_PLAN9] = do_bootm_plan9,
163#endif
Miao Yan871a57b2013-11-28 17:51:38 +0800164#if defined(CONFIG_BOOTM_VXWORKS) && \
165 (defined(CONFIG_PPC) || defined(CONFIG_ARM))
Kumar Galabe083152008-10-21 17:25:44 -0500166 [IH_OS_VXWORKS] = do_bootm_vxworks,
Miao Yan17ab52f2013-11-28 17:51:36 +0800167#endif
168#if defined(CONFIG_CMD_ELF)
Kumar Galabe083152008-10-21 17:25:44 -0500169 [IH_OS_QNX] = do_bootm_qnxelf,
170#endif
171#ifdef CONFIG_INTEGRITY
172 [IH_OS_INTEGRITY] = do_bootm_integrity,
173#endif
174};
175
Simon Schwarzdee17762011-09-02 00:50:31 +0000176bootm_headers_t images; /* pointers to os/initrd/fdt images */
Stefan Roese15940c92006-03-13 11:16:36 +0100177
Kumar Gala3dfad402009-08-27 08:23:55 -0500178/* Allow for arch specific config before we boot */
Kim Phillips088f1b12012-10-29 13:34:31 +0000179static void __arch_preboot_os(void)
Kumar Gala3dfad402009-08-27 08:23:55 -0500180{
181 /* please define platform specific arch_preboot_os() */
182}
183void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
184
Mike Frysinger476af292011-10-03 14:50:33 +0000185#define IH_INITRD_ARCH IH_ARCH_DEFAULT
wdenk47d1a6e2002-11-03 00:01:44 +0000186
Mike Frysingera16028d2009-11-03 11:35:59 -0500187#ifdef CONFIG_LMB
Marek Vasut44f074c2012-03-14 21:52:45 +0000188static void boot_start_lmb(bootm_headers_t *images)
189{
Becky Bruce391fd932008-06-09 20:37:18 -0500190 ulong mem_start;
191 phys_size_t mem_size;
wdenk47d1a6e2002-11-03 00:01:44 +0000192
Marek Vasut44f074c2012-03-14 21:52:45 +0000193 lmb_init(&images->lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000194
Kumar Galad3f2fa02008-02-27 21:51:50 -0600195 mem_start = getenv_bootm_low();
196 mem_size = getenv_bootm_size();
wdenk47d1a6e2002-11-03 00:01:44 +0000197
Marek Vasut44f074c2012-03-14 21:52:45 +0000198 lmb_add(&images->lmb, (phys_addr_t)mem_start, mem_size);
wdenk47d1a6e2002-11-03 00:01:44 +0000199
Marek Vasut44f074c2012-03-14 21:52:45 +0000200 arch_lmb_reserve(&images->lmb);
201 board_lmb_reserve(&images->lmb);
Mike Frysingera16028d2009-11-03 11:35:59 -0500202}
Marek Vasut44f074c2012-03-14 21:52:45 +0000203#else
Marek Vasut35cf5fe2012-04-01 03:59:46 +0000204#define lmb_reserve(lmb, base, size)
Marek Vasut44f074c2012-03-14 21:52:45 +0000205static inline void boot_start_lmb(bootm_headers_t *images) { }
206#endif
Mike Frysingera16028d2009-11-03 11:35:59 -0500207
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200208static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Mike Frysingera16028d2009-11-03 11:35:59 -0500209{
Stephen Warren712fbcf2011-10-18 11:11:49 +0000210 memset((void *)&images, 0, sizeof(images));
211 images.verify = getenv_yesno("verify");
Mike Frysingera16028d2009-11-03 11:35:59 -0500212
Marek Vasut44f074c2012-03-14 21:52:45 +0000213 boot_start_lmb(&images);
wdenk47d1a6e2002-11-03 00:01:44 +0000214
Simon Glass573f14f2011-12-10 11:08:06 +0000215 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_START, "bootm_start");
Simon Glass35fc84f2013-06-11 11:14:47 -0700216 images.state = BOOTM_STATE_START;
217
218 return 0;
219}
220
221static int bootm_find_os(cmd_tbl_t *cmdtp, int flag, int argc,
222 char * const argv[])
223{
224 const void *os_hdr;
Simon Glass573f14f2011-12-10 11:08:06 +0000225
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100226 /* get kernel image header, start address and length */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000227 os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
Kumar Gala396f6352008-08-15 08:24:41 -0500228 &images, &images.os.image_start, &images.os.image_len);
229 if (images.os.image_len == 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000230 puts("ERROR: can't get kernel image!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000231 return 1;
232 }
wdenk47d1a6e2002-11-03 00:01:44 +0000233
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100234 /* get image parameters */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000235 switch (genimg_get_format(os_hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100236 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000237 images.os.type = image_get_type(os_hdr);
238 images.os.comp = image_get_comp(os_hdr);
239 images.os.os = image_get_os(os_hdr);
Wolfgang Denkbccae902005-10-06 01:50:50 +0200240
Stephen Warren712fbcf2011-10-18 11:11:49 +0000241 images.os.end = image_get_image_end(os_hdr);
242 images.os.load = image_get_load(os_hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100243 break;
244#if defined(CONFIG_FIT)
245 case IMAGE_FORMAT_FIT:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000246 if (fit_image_get_type(images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500247 images.fit_noffset_os, &images.os.type)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000248 puts("Can't get image type!\n");
Simon Glass770605e2012-02-13 13:51:18 +0000249 bootstage_error(BOOTSTAGE_ID_FIT_TYPE);
wdenk47d1a6e2002-11-03 00:01:44 +0000250 return 1;
251 }
wdenk47d1a6e2002-11-03 00:01:44 +0000252
Stephen Warren712fbcf2011-10-18 11:11:49 +0000253 if (fit_image_get_comp(images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500254 images.fit_noffset_os, &images.os.comp)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000255 puts("Can't get image compression!\n");
Simon Glass770605e2012-02-13 13:51:18 +0000256 bootstage_error(BOOTSTAGE_ID_FIT_COMPRESSION);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100257 return 1;
258 }
wdenk47d1a6e2002-11-03 00:01:44 +0000259
Stephen Warren712fbcf2011-10-18 11:11:49 +0000260 if (fit_image_get_os(images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500261 images.fit_noffset_os, &images.os.os)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000262 puts("Can't get image OS!\n");
Simon Glass770605e2012-02-13 13:51:18 +0000263 bootstage_error(BOOTSTAGE_ID_FIT_OS);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100264 return 1;
265 }
wdenk47d1a6e2002-11-03 00:01:44 +0000266
Stephen Warren712fbcf2011-10-18 11:11:49 +0000267 images.os.end = fit_get_end(images.fit_hdr_os);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100268
Stephen Warren712fbcf2011-10-18 11:11:49 +0000269 if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500270 &images.os.load)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000271 puts("Can't get image load address!\n");
Simon Glass770605e2012-02-13 13:51:18 +0000272 bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100273 return 1;
wdenkb13fb012003-10-30 21:49:38 +0000274 }
275 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100276#endif
277 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000278 puts("ERROR: unknown image format type!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000279 return 1;
280 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100281
Kumar Galac160a952008-08-15 08:24:36 -0500282 /* find kernel entry point */
283 if (images.legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000284 images.ep = image_get_ep(&images.legacy_hdr_os_copy);
Kumar Galac160a952008-08-15 08:24:36 -0500285#if defined(CONFIG_FIT)
286 } else if (images.fit_uname_os) {
Simon Glass35fc84f2013-06-11 11:14:47 -0700287 int ret;
288
Stephen Warren712fbcf2011-10-18 11:11:49 +0000289 ret = fit_image_get_entry(images.fit_hdr_os,
Simon Glassc19d13b2013-05-08 08:06:02 +0000290 images.fit_noffset_os, &images.ep);
Kumar Galac160a952008-08-15 08:24:36 -0500291 if (ret) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000292 puts("Can't get entry point property!\n");
Kumar Galac160a952008-08-15 08:24:36 -0500293 return 1;
294 }
295#endif
296 } else {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000297 puts("Could not find kernel entry point!\n");
Kumar Galac160a952008-08-15 08:24:36 -0500298 return 1;
299 }
300
Stephen Warrenb9b50e892011-11-10 13:17:53 -0700301 if (images.os.type == IH_TYPE_KERNEL_NOLOAD) {
302 images.os.load = images.os.image_start;
303 images.ep += images.os.load;
304 }
305
Simon Glass35fc84f2013-06-11 11:14:47 -0700306 images.os.start = (ulong)os_hdr;
307
308 return 0;
309}
310
Tom Rini225fd8c2013-07-09 15:33:25 -0400311static int bootm_find_ramdisk(int flag, int argc, char * const argv[])
Simon Glass35fc84f2013-06-11 11:14:47 -0700312{
313 int ret;
314
Tom Rini225fd8c2013-07-09 15:33:25 -0400315 /* find ramdisk */
316 ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH,
317 &images.rd_start, &images.rd_end);
318 if (ret) {
319 puts("Ramdisk image is corrupt or invalid\n");
320 return 1;
321 }
322
323 return 0;
324}
325
326#if defined(CONFIG_OF_LIBFDT)
327static int bootm_find_fdt(int flag, int argc, char * const argv[])
328{
329 int ret;
330
331 /* find flattened device tree */
332 ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, &images,
333 &images.ft_addr, &images.ft_len);
334 if (ret) {
335 puts("Could not find a valid device tree\n");
336 return 1;
337 }
338
339 set_working_fdt_addr(images.ft_addr);
340
341 return 0;
342}
343#endif
344
345static int bootm_find_other(cmd_tbl_t *cmdtp, int flag, int argc,
346 char * const argv[])
347{
Heiko Schocher24de2f42010-03-29 13:15:48 +0200348 if (((images.os.type == IH_TYPE_KERNEL) ||
Stephen Warrenb9b50e892011-11-10 13:17:53 -0700349 (images.os.type == IH_TYPE_KERNEL_NOLOAD) ||
Heiko Schocher24de2f42010-03-29 13:15:48 +0200350 (images.os.type == IH_TYPE_MULTI)) &&
Miao Yan871a57b2013-11-28 17:51:38 +0800351 (images.os.os == IH_OS_LINUX ||
352 images.os.os == IH_OS_VXWORKS)) {
Tom Rini225fd8c2013-07-09 15:33:25 -0400353 if (bootm_find_ramdisk(flag, argc, argv))
Kumar Galac4f94192008-08-15 08:24:37 -0500354 return 1;
Kumar Gala06a09912008-08-15 08:24:38 -0500355
356#if defined(CONFIG_OF_LIBFDT)
Tom Rini225fd8c2013-07-09 15:33:25 -0400357 if (bootm_find_fdt(flag, argc, argv))
Kumar Gala06a09912008-08-15 08:24:38 -0500358 return 1;
Kumar Gala06a09912008-08-15 08:24:38 -0500359#endif
Kumar Galac4f94192008-08-15 08:24:37 -0500360 }
361
Kumar Gala396f6352008-08-15 08:24:41 -0500362 return 0;
363}
364
365#define BOOTM_ERR_RESET -1
366#define BOOTM_ERR_OVERLAP -2
367#define BOOTM_ERR_UNIMPLEMENTED -3
Tom Rinid3664382013-06-28 11:38:02 -0400368static int bootm_load_os(bootm_headers_t *images, unsigned long *load_end,
369 int boot_progress)
Kumar Gala396f6352008-08-15 08:24:41 -0500370{
Tom Rinid3664382013-06-28 11:38:02 -0400371 image_info_t os = images->os;
Kumar Gala396f6352008-08-15 08:24:41 -0500372 uint8_t comp = os.comp;
373 ulong load = os.load;
374 ulong blob_start = os.start;
375 ulong blob_end = os.end;
376 ulong image_start = os.image_start;
377 ulong image_len = os.image_len;
Anatolij Gustschin5bf27662011-11-19 13:12:18 +0000378 __maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN;
Stephen Warrend5108592011-11-10 13:17:54 -0700379 int no_overlap = 0;
Simon Glassaed161e2013-05-16 13:53:24 +0000380 void *load_buf, *image_buf;
Matthias Weisser60fdc5f2010-08-05 13:17:30 +0200381#if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
382 int ret;
383#endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
Kumar Gala396f6352008-08-15 08:24:41 -0500384
Stephen Warren712fbcf2011-10-18 11:11:49 +0000385 const char *type_name = genimg_get_type_name(os.type);
Kumar Gala396f6352008-08-15 08:24:41 -0500386
Kees Cook315c0ac2013-08-16 07:59:16 -0700387 load_buf = map_sysmem(load, unc_len);
Simon Glassaed161e2013-05-16 13:53:24 +0000388 image_buf = map_sysmem(image_start, image_len);
Kumar Gala396f6352008-08-15 08:24:41 -0500389 switch (comp) {
390 case IH_COMP_NONE:
Lei Wen02cf3452011-01-10 18:21:15 +0800391 if (load == blob_start || load == image_start) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000392 printf(" XIP %s ... ", type_name);
Stephen Warrend5108592011-11-10 13:17:54 -0700393 no_overlap = 1;
Kumar Gala396f6352008-08-15 08:24:41 -0500394 } else {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000395 printf(" Loading %s ... ", type_name);
Simon Glassaed161e2013-05-16 13:53:24 +0000396 memmove_wd(load_buf, image_buf, image_len, CHUNKSZ);
Kumar Gala396f6352008-08-15 08:24:41 -0500397 }
398 *load_end = load + image_len;
Kumar Gala396f6352008-08-15 08:24:41 -0500399 break;
Mike Frysinger44431ca2010-01-21 19:30:36 -0500400#ifdef CONFIG_GZIP
Kumar Gala396f6352008-08-15 08:24:41 -0500401 case IH_COMP_GZIP:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000402 printf(" Uncompressing %s ... ", type_name);
Simon Glassaed161e2013-05-16 13:53:24 +0000403 if (gunzip(load_buf, unc_len, image_buf, &image_len) != 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000404 puts("GUNZIP: uncompress, out-of-mem or overwrite "
405 "error - must RESET board to recover\n");
Kumar Gala396f6352008-08-15 08:24:41 -0500406 if (boot_progress)
Simon Glass770605e2012-02-13 13:51:18 +0000407 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
Kumar Gala396f6352008-08-15 08:24:41 -0500408 return BOOTM_ERR_RESET;
409 }
410
411 *load_end = load + image_len;
412 break;
Mike Frysinger44431ca2010-01-21 19:30:36 -0500413#endif /* CONFIG_GZIP */
Kumar Gala396f6352008-08-15 08:24:41 -0500414#ifdef CONFIG_BZIP2
415 case IH_COMP_BZIP2:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000416 printf(" Uncompressing %s ... ", type_name);
Kumar Gala396f6352008-08-15 08:24:41 -0500417 /*
418 * If we've got less than 4 MB of malloc() space,
419 * use slower decompression algorithm which requires
420 * at most 2300 KB of memory.
421 */
Simon Glassaed161e2013-05-16 13:53:24 +0000422 int i = BZ2_bzBuffToBuffDecompress(load_buf, &unc_len,
423 image_buf, image_len,
424 CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
Kumar Gala396f6352008-08-15 08:24:41 -0500425 if (i != BZ_OK) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000426 printf("BUNZIP2: uncompress or overwrite error %d "
Kumar Gala396f6352008-08-15 08:24:41 -0500427 "- must RESET board to recover\n", i);
428 if (boot_progress)
Simon Glass770605e2012-02-13 13:51:18 +0000429 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
Kumar Gala396f6352008-08-15 08:24:41 -0500430 return BOOTM_ERR_RESET;
431 }
432
433 *load_end = load + unc_len;
434 break;
435#endif /* CONFIG_BZIP2 */
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200436#ifdef CONFIG_LZMA
Mike Frysinger78e1e842010-07-25 15:54:17 -0400437 case IH_COMP_LZMA: {
438 SizeT lzma_len = unc_len;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000439 printf(" Uncompressing %s ... ", type_name);
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200440
Simon Glassaed161e2013-05-16 13:53:24 +0000441 ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len,
442 image_buf, image_len);
Mike Frysinger78e1e842010-07-25 15:54:17 -0400443 unc_len = lzma_len;
Luigi 'Comio' Mantellinicaf72ff2009-07-21 10:45:49 +0200444 if (ret != SZ_OK) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000445 printf("LZMA: uncompress or overwrite error %d "
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200446 "- must RESET board to recover\n", ret);
Simon Glass770605e2012-02-13 13:51:18 +0000447 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200448 return BOOTM_ERR_RESET;
449 }
450 *load_end = load + unc_len;
451 break;
Mike Frysinger78e1e842010-07-25 15:54:17 -0400452 }
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200453#endif /* CONFIG_LZMA */
Peter Korsgaard20dde482009-11-19 11:37:51 +0100454#ifdef CONFIG_LZO
Simon Glass628af172013-08-30 11:00:09 -0600455 case IH_COMP_LZO: {
456 size_t size;
457
Stephen Warren712fbcf2011-10-18 11:11:49 +0000458 printf(" Uncompressing %s ... ", type_name);
Peter Korsgaard20dde482009-11-19 11:37:51 +0100459
Simon Glass628af172013-08-30 11:00:09 -0600460 ret = lzop_decompress(image_buf, image_len, load_buf, &size);
Peter Korsgaard20dde482009-11-19 11:37:51 +0100461 if (ret != LZO_E_OK) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000462 printf("LZO: uncompress or overwrite error %d "
Peter Korsgaard20dde482009-11-19 11:37:51 +0100463 "- must RESET board to recover\n", ret);
464 if (boot_progress)
Simon Glass770605e2012-02-13 13:51:18 +0000465 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
Peter Korsgaard20dde482009-11-19 11:37:51 +0100466 return BOOTM_ERR_RESET;
467 }
468
Simon Glass628af172013-08-30 11:00:09 -0600469 *load_end = load + size;
Peter Korsgaard20dde482009-11-19 11:37:51 +0100470 break;
Simon Glass628af172013-08-30 11:00:09 -0600471 }
Peter Korsgaard20dde482009-11-19 11:37:51 +0100472#endif /* CONFIG_LZO */
Kumar Gala396f6352008-08-15 08:24:41 -0500473 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000474 printf("Unimplemented compression type %d\n", comp);
Kumar Gala396f6352008-08-15 08:24:41 -0500475 return BOOTM_ERR_UNIMPLEMENTED;
476 }
Diana CRACIUN99ffccb2011-08-31 02:45:23 +0000477
478 flush_cache(load, (*load_end - load) * sizeof(ulong));
479
Stephen Warren712fbcf2011-10-18 11:11:49 +0000480 puts("OK\n");
481 debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
Simon Glass770605e2012-02-13 13:51:18 +0000482 bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED);
Kumar Gala396f6352008-08-15 08:24:41 -0500483
Stephen Warrend5108592011-11-10 13:17:54 -0700484 if (!no_overlap && (load < blob_end) && (*load_end > blob_start)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000485 debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n",
486 blob_start, blob_end);
487 debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load,
488 *load_end);
Kumar Gala396f6352008-08-15 08:24:41 -0500489
Tom Rinid3664382013-06-28 11:38:02 -0400490 /* Check what type of image this is. */
491 if (images->legacy_hdr_valid) {
492 if (image_get_type(&images->legacy_hdr_os_copy)
493 == IH_TYPE_MULTI)
494 puts("WARNING: legacy format multi component image overwritten\n");
495 return BOOTM_ERR_OVERLAP;
496 } else {
497 puts("ERROR: new format image overwritten - must RESET the board to recover\n");
498 bootstage_error(BOOTSTAGE_ID_OVERWRITTEN);
499 return BOOTM_ERR_RESET;
500 }
Kumar Gala396f6352008-08-15 08:24:41 -0500501 }
502
503 return 0;
504}
505
Simon Glassc5cbe1e2013-12-26 16:26:24 -0700506static int do_bootm_standalone(int flag, int argc, char * const argv[],
507 bootm_headers_t *images)
Detlev Zundelf97ec302009-07-13 16:01:19 +0200508{
509 char *s;
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200510 int (*appl)(int, char * const []);
Detlev Zundelf97ec302009-07-13 16:01:19 +0200511
512 /* Don't start if "autostart" is set to "no" */
513 if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
Simon Glassc5cbe1e2013-12-26 16:26:24 -0700514 setenv_hex("filesize", images->os.image_len);
Detlev Zundelf97ec302009-07-13 16:01:19 +0200515 return 0;
516 }
Christian Eggers9c896142014-02-08 19:27:45 +0100517 appl = (int (*)(int, char * const []))images->ep;
518 appl(argc, argv);
Detlev Zundelf97ec302009-07-13 16:01:19 +0200519 return 0;
520}
521
Kumar Gala49c3a862008-10-21 17:25:45 -0500522/* we overload the cmd field with our state machine info instead of a
523 * function pointer */
Frans Meulenbroeksf74d9bd2010-02-25 10:12:13 +0100524static cmd_tbl_t cmd_bootm_sub[] = {
Kumar Gala49c3a862008-10-21 17:25:45 -0500525 U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
526 U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
John Rigbyfca43cc2010-10-13 13:57:35 -0600527#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
Kumar Gala49c3a862008-10-21 17:25:45 -0500528 U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
529#endif
530#ifdef CONFIG_OF_LIBFDT
531 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
532#endif
Kumar Gala49c3a862008-10-21 17:25:45 -0500533 U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
Peter Tyser224c90d2009-11-18 19:08:59 -0600534 U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
Kumar Gala49c3a862008-10-21 17:25:45 -0500535 U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
Simon Glassd0ae31e2013-06-11 11:14:48 -0700536 U_BOOT_CMD_MKENT(fake, 0, 1, (void *)BOOTM_STATE_OS_FAKE_GO, "", ""),
Kumar Gala49c3a862008-10-21 17:25:45 -0500537 U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
538};
539
Simon Glass35fc84f2013-06-11 11:14:47 -0700540static int boot_selected_os(int argc, char * const argv[], int state,
Simon Glass5ff0d082013-06-28 00:46:12 -0700541 bootm_headers_t *images, boot_os_fn *boot_fn)
Simon Glass35fc84f2013-06-11 11:14:47 -0700542{
Simon Glass35fc84f2013-06-11 11:14:47 -0700543 arch_preboot_os();
544 boot_fn(state, argc, argv, images);
Simon Glassc5cbe1e2013-12-26 16:26:24 -0700545
546 /* Stand-alone may return when 'autostart' is 'no' */
547 if (images->os.type == IH_TYPE_STANDALONE ||
548 state == BOOTM_STATE_OS_FAKE_GO) /* We expect to return */
Simon Glassd0ae31e2013-06-11 11:14:48 -0700549 return 0;
Simon Glass35fc84f2013-06-11 11:14:47 -0700550 bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED);
551#ifdef DEBUG
552 puts("\n## Control returned to monitor - resetting...\n");
553#endif
554 return BOOTM_ERR_RESET;
555}
556
557/**
Simon Glass385501d2013-07-04 13:26:08 -0700558 * bootm_disable_interrupts() - Disable interrupts in preparation for load/boot
559 *
560 * @return interrupt flag (0 if interrupts were disabled, non-zero if they were
561 * enabled)
562 */
563static ulong bootm_disable_interrupts(void)
564{
565 ulong iflag;
566
567 /*
568 * We have reached the point of no return: we are going to
569 * overwrite all exception vector code, so we cannot easily
570 * recover from any failures any more...
571 */
572 iflag = disable_interrupts();
573#ifdef CONFIG_NETCONSOLE
574 /* Stop the ethernet stack if NetConsole could have left it up */
575 eth_halt();
Frederic Leroy80949722013-09-10 12:02:31 +0200576 eth_unregister(eth_get_dev());
Simon Glass385501d2013-07-04 13:26:08 -0700577#endif
578
579#if defined(CONFIG_CMD_USB)
580 /*
581 * turn off USB to prevent the host controller from writing to the
582 * SDRAM while Linux is booting. This could happen (at least for OHCI
583 * controller), because the HCCA (Host Controller Communication Area)
584 * lies within the SDRAM and the host controller writes continously to
585 * this area (as busmaster!). The HccaFrameNumber is for example
586 * updated every 1 ms within the HCCA structure in SDRAM! For more
587 * details see the OpenHCI specification.
588 */
589 usb_stop();
590#endif
591 return iflag;
592}
593
594/**
Simon Glass35fc84f2013-06-11 11:14:47 -0700595 * Execute selected states of the bootm command.
596 *
597 * Note the arguments to this state must be the first argument, Any 'bootm'
598 * or sub-command arguments must have already been taken.
599 *
600 * Note that if states contains more than one flag it MUST contain
601 * BOOTM_STATE_START, since this handles and consumes the command line args.
602 *
Tom Rinid3664382013-06-28 11:38:02 -0400603 * Also note that aside from boot_os_fn functions and bootm_load_os no other
604 * functions we store the return value of in 'ret' may use a negative return
605 * value, without special handling.
606 *
Simon Glass35fc84f2013-06-11 11:14:47 -0700607 * @param cmdtp Pointer to bootm command table entry
608 * @param flag Command flags (CMD_FLAG_...)
609 * @param argc Number of subcommand arguments (0 = no arguments)
610 * @param argv Arguments
611 * @param states Mask containing states to run (BOOTM_STATE_...)
612 * @param images Image header information
613 * @param boot_progress 1 to show boot progress, 0 to not do this
614 * @return 0 if ok, something else on error. Some errors will cause this
615 * function to perform a reboot! If states contains BOOTM_STATE_OS_GO
616 * then the intent is to boot an OS, so this function will not return
617 * unless the image type is standalone.
618 */
619static int do_bootm_states(cmd_tbl_t *cmdtp, int flag, int argc,
620 char * const argv[], int states, bootm_headers_t *images,
621 int boot_progress)
622{
623 boot_os_fn *boot_fn;
624 ulong iflag = 0;
Simon Glassa26913f2013-07-04 13:26:09 -0700625 int ret = 0, need_boot_fn;
Simon Glass35fc84f2013-06-11 11:14:47 -0700626
627 images->state |= states;
628
629 /*
630 * Work through the states and see how far we get. We stop on
631 * any error.
632 */
633 if (states & BOOTM_STATE_START)
634 ret = bootm_start(cmdtp, flag, argc, argv);
635
636 if (!ret && (states & BOOTM_STATE_FINDOS))
637 ret = bootm_find_os(cmdtp, flag, argc, argv);
638
639 if (!ret && (states & BOOTM_STATE_FINDOTHER)) {
640 ret = bootm_find_other(cmdtp, flag, argc, argv);
641 argc = 0; /* consume the args */
642 }
643
644 /* Load the OS */
645 if (!ret && (states & BOOTM_STATE_LOADOS)) {
646 ulong load_end;
647
Simon Glass385501d2013-07-04 13:26:08 -0700648 iflag = bootm_disable_interrupts();
Tom Rinid3664382013-06-28 11:38:02 -0400649 ret = bootm_load_os(images, &load_end, 0);
Tom Rinid3664382013-06-28 11:38:02 -0400650 if (ret == 0)
Simon Glass35fc84f2013-06-11 11:14:47 -0700651 lmb_reserve(&images->lmb, images->os.load,
652 (load_end - images->os.load));
Tom Rini970150a2013-07-11 09:35:23 -0400653 else if (ret && ret != BOOTM_ERR_OVERLAP)
654 goto err;
Tom Rinid3664382013-06-28 11:38:02 -0400655 else if (ret == BOOTM_ERR_OVERLAP)
656 ret = 0;
Paul B. Hensonbd4a3992013-08-03 21:29:09 -0700657#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
Simon Glass576aacd2013-07-16 20:09:59 -0700658 if (images->os.os == IH_OS_LINUX)
659 fixup_silent_linux();
660#endif
Simon Glass35fc84f2013-06-11 11:14:47 -0700661 }
662
663 /* Relocate the ramdisk */
664#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
665 if (!ret && (states & BOOTM_STATE_RAMDISK)) {
666 ulong rd_len = images->rd_end - images->rd_start;
667
668 ret = boot_ramdisk_high(&images->lmb, images->rd_start,
669 rd_len, &images->initrd_start, &images->initrd_end);
670 if (!ret) {
671 setenv_hex("initrd_start", images->initrd_start);
672 setenv_hex("initrd_end", images->initrd_end);
673 }
674 }
675#endif
676#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_LMB)
677 if (!ret && (states & BOOTM_STATE_FDT)) {
678 boot_fdt_add_mem_rsv_regions(&images->lmb, images->ft_addr);
679 ret = boot_relocate_fdt(&images->lmb, &images->ft_addr,
680 &images->ft_len);
681 }
682#endif
683
684 /* From now on, we need the OS boot function */
685 if (ret)
686 return ret;
687 boot_fn = boot_os[images->os.os];
Simon Glassa26913f2013-07-04 13:26:09 -0700688 need_boot_fn = states & (BOOTM_STATE_OS_CMDLINE |
689 BOOTM_STATE_OS_BD_T | BOOTM_STATE_OS_PREP |
690 BOOTM_STATE_OS_FAKE_GO | BOOTM_STATE_OS_GO);
691 if (boot_fn == NULL && need_boot_fn) {
Simon Glass35fc84f2013-06-11 11:14:47 -0700692 if (iflag)
693 enable_interrupts();
694 printf("ERROR: booting os '%s' (%d) is not supported\n",
695 genimg_get_os_name(images->os.os), images->os.os);
696 bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS);
697 return 1;
698 }
699
700 /* Call various other states that are not generally used */
701 if (!ret && (states & BOOTM_STATE_OS_CMDLINE))
702 ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, images);
703 if (!ret && (states & BOOTM_STATE_OS_BD_T))
704 ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, images);
705 if (!ret && (states & BOOTM_STATE_OS_PREP))
706 ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, images);
707
Simon Glassd0ae31e2013-06-11 11:14:48 -0700708#ifdef CONFIG_TRACE
709 /* Pretend to run the OS, then run a user command */
710 if (!ret && (states & BOOTM_STATE_OS_FAKE_GO)) {
711 char *cmd_list = getenv("fakegocmd");
712
713 ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_FAKE_GO,
Simon Glass5ff0d082013-06-28 00:46:12 -0700714 images, boot_fn);
Simon Glassd0ae31e2013-06-11 11:14:48 -0700715 if (!ret && cmd_list)
716 ret = run_command_list(cmd_list, -1, flag);
717 }
718#endif
Simon Glassb7a1d132013-07-10 09:25:33 -0400719
720 /* Check for unsupported subcommand. */
721 if (ret) {
722 puts("subcommand not supported\n");
723 return ret;
Tom Rinid3664382013-06-28 11:38:02 -0400724 }
725
Simon Glassb7a1d132013-07-10 09:25:33 -0400726 /* Now run the OS! We hope this doesn't return */
727 if (!ret && (states & BOOTM_STATE_OS_GO))
728 ret = boot_selected_os(argc, argv, BOOTM_STATE_OS_GO,
729 images, boot_fn);
Simon Glass35fc84f2013-06-11 11:14:47 -0700730
731 /* Deal with any fallout */
Tom Rinid3664382013-06-28 11:38:02 -0400732err:
Simon Glass35fc84f2013-06-11 11:14:47 -0700733 if (iflag)
734 enable_interrupts();
Tom Rinid3664382013-06-28 11:38:02 -0400735
736 if (ret == BOOTM_ERR_UNIMPLEMENTED)
737 bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL);
738 else if (ret == BOOTM_ERR_RESET)
739 do_reset(cmdtp, flag, argc, argv);
Simon Glass35fc84f2013-06-11 11:14:47 -0700740
741 return ret;
742}
743
Kim Phillips088f1b12012-10-29 13:34:31 +0000744static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
Stephen Warren712fbcf2011-10-18 11:11:49 +0000745 char * const argv[])
Kumar Gala49c3a862008-10-21 17:25:45 -0500746{
747 int ret = 0;
Simon Glass6d6f1232011-10-07 13:53:40 +0000748 long state;
Kumar Gala49c3a862008-10-21 17:25:45 -0500749 cmd_tbl_t *c;
Kumar Gala49c3a862008-10-21 17:25:45 -0500750
Simon Glass983c72f2013-06-11 11:14:46 -0700751 c = find_cmd_tbl(argv[0], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
752 argc--; argv++;
Kumar Gala49c3a862008-10-21 17:25:45 -0500753
754 if (c) {
Simon Glass6d6f1232011-10-07 13:53:40 +0000755 state = (long)c->cmd;
Simon Glass983c72f2013-06-11 11:14:46 -0700756 if (state == BOOTM_STATE_START)
Simon Glass35fc84f2013-06-11 11:14:47 -0700757 state |= BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER;
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200758 } else {
759 /* Unrecognized command */
Simon Glass4c12eeb2011-12-10 08:44:01 +0000760 return CMD_RET_USAGE;
Kumar Gala49c3a862008-10-21 17:25:45 -0500761 }
762
Simon Glass35fc84f2013-06-11 11:14:47 -0700763 if (state != BOOTM_STATE_START && images.state >= state) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000764 printf("Trying to execute a command out of order\n");
Simon Glass4c12eeb2011-12-10 08:44:01 +0000765 return CMD_RET_USAGE;
Kumar Gala49c3a862008-10-21 17:25:45 -0500766 }
767
Simon Glass35fc84f2013-06-11 11:14:47 -0700768 ret = do_bootm_states(cmdtp, flag, argc, argv, state, &images, 0);
Kumar Gala49c3a862008-10-21 17:25:45 -0500769
770 return ret;
771}
772
Kumar Gala396f6352008-08-15 08:24:41 -0500773/*******************************************************************/
774/* bootm - boot application image from image in memory */
775/*******************************************************************/
Kumar Galabe083152008-10-21 17:25:44 -0500776
Stephen Warren712fbcf2011-10-18 11:11:49 +0000777int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Kumar Gala396f6352008-08-15 08:24:41 -0500778{
Wolfgang Denk2e5167c2010-10-28 20:00:11 +0200779#ifdef CONFIG_NEEDS_MANUAL_RELOC
Peter Tyser521af042009-09-21 11:20:36 -0500780 static int relocated = 0;
Kumar Galabe083152008-10-21 17:25:44 -0500781
Kumar Galabe083152008-10-21 17:25:44 -0500782 if (!relocated) {
783 int i;
Daniel Schwierzeck58bd77d2013-01-07 06:54:52 +0000784
785 /* relocate boot function table */
Kumar Galabe083152008-10-21 17:25:44 -0500786 for (i = 0; i < ARRAY_SIZE(boot_os); i++)
Detlev Zundelca95c9d2009-07-13 16:01:18 +0200787 if (boot_os[i] != NULL)
788 boot_os[i] += gd->reloc_off;
Daniel Schwierzeck58bd77d2013-01-07 06:54:52 +0000789
790 /* relocate names of sub-command table */
791 for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++)
792 cmd_bootm_sub[i].name += gd->reloc_off;
793
Kumar Galabe083152008-10-21 17:25:44 -0500794 relocated = 1;
795 }
Peter Tyser521af042009-09-21 11:20:36 -0500796#endif
Kumar Gala396f6352008-08-15 08:24:41 -0500797
Kumar Gala49c3a862008-10-21 17:25:45 -0500798 /* determine if we have a sub command */
Simon Glass983c72f2013-06-11 11:14:46 -0700799 argc--; argv++;
800 if (argc > 0) {
Kumar Gala49c3a862008-10-21 17:25:45 -0500801 char *endp;
802
Simon Glass983c72f2013-06-11 11:14:46 -0700803 simple_strtoul(argv[0], &endp, 16);
804 /* endp pointing to NULL means that argv[0] was just a
Kumar Gala49c3a862008-10-21 17:25:45 -0500805 * valid number, pass it along to the normal bootm processing
806 *
807 * If endp is ':' or '#' assume a FIT identifier so pass
808 * along for normal processing.
809 *
810 * Right now we assume the first arg should never be '-'
811 */
812 if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
813 return do_bootm_subcommand(cmdtp, flag, argc, argv);
814 }
815
Simon Glass35fc84f2013-06-11 11:14:47 -0700816 return do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START |
817 BOOTM_STATE_FINDOS | BOOTM_STATE_FINDOTHER |
Tom Rini3d187b32013-09-23 14:20:37 -0400818 BOOTM_STATE_LOADOS |
819#if defined(CONFIG_PPC) || defined(CONFIG_MIPS)
820 BOOTM_STATE_OS_CMDLINE |
821#endif
Paul Burton5c427e42013-09-06 11:23:55 +0100822 BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
823 BOOTM_STATE_OS_GO, &images, 1);
wdenk47d1a6e2002-11-03 00:01:44 +0000824}
825
Mike Frysinger67d668b2011-06-05 13:43:02 +0000826int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
827{
828 const char *ep = getenv("autostart");
829
830 if (ep && !strcmp(ep, "yes")) {
831 char *local_args[2];
832 local_args[0] = (char *)cmd;
833 local_args[1] = NULL;
834 printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
835 return do_bootm(cmdtp, 0, 1, local_args);
836 }
837
838 return 0;
839}
840
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100841/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100842 * image_get_kernel - verify legacy format kernel image
843 * @img_addr: in RAM address of the legacy format image to be verified
844 * @verify: data CRC verification flag
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100845 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100846 * image_get_kernel() verifies legacy image integrity and returns pointer to
847 * legacy image header if image verification was completed successfully.
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100848 *
849 * returns:
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100850 * pointer to a legacy image header if valid image was found
851 * otherwise return NULL
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100852 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000853static image_header_t *image_get_kernel(ulong img_addr, int verify)
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100854{
855 image_header_t *hdr = (image_header_t *)img_addr;
856
857 if (!image_check_magic(hdr)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000858 puts("Bad Magic Number\n");
Simon Glass770605e2012-02-13 13:51:18 +0000859 bootstage_error(BOOTSTAGE_ID_CHECK_MAGIC);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100860 return NULL;
861 }
Simon Glass770605e2012-02-13 13:51:18 +0000862 bootstage_mark(BOOTSTAGE_ID_CHECK_HEADER);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100863
Stephen Warren712fbcf2011-10-18 11:11:49 +0000864 if (!image_check_hcrc(hdr)) {
865 puts("Bad Header Checksum\n");
Simon Glass770605e2012-02-13 13:51:18 +0000866 bootstage_error(BOOTSTAGE_ID_CHECK_HEADER);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100867 return NULL;
868 }
869
Simon Glass770605e2012-02-13 13:51:18 +0000870 bootstage_mark(BOOTSTAGE_ID_CHECK_CHECKSUM);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000871 image_print_contents(hdr);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100872
873 if (verify) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000874 puts(" Verifying Checksum ... ");
875 if (!image_check_dcrc(hdr)) {
876 printf("Bad Data CRC\n");
Simon Glass770605e2012-02-13 13:51:18 +0000877 bootstage_error(BOOTSTAGE_ID_CHECK_CHECKSUM);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100878 return NULL;
879 }
Stephen Warren712fbcf2011-10-18 11:11:49 +0000880 puts("OK\n");
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100881 }
Simon Glass770605e2012-02-13 13:51:18 +0000882 bootstage_mark(BOOTSTAGE_ID_CHECK_ARCH);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100883
Stephen Warren712fbcf2011-10-18 11:11:49 +0000884 if (!image_check_target_arch(hdr)) {
885 printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr));
Simon Glass770605e2012-02-13 13:51:18 +0000886 bootstage_error(BOOTSTAGE_ID_CHECK_ARCH);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100887 return NULL;
888 }
889 return hdr;
890}
891
892/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100893 * boot_get_kernel - find kernel image
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100894 * @os_data: pointer to a ulong variable, will hold os data start address
895 * @os_len: pointer to a ulong variable, will hold os data length
896 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100897 * boot_get_kernel() tries to find a kernel image, verifies its integrity
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100898 * and locates kernel data.
899 *
900 * returns:
901 * pointer to image header if valid image was found, plus kernel start
902 * address and length, otherwise NULL
903 */
Simon Glass35e7b0f2013-05-07 06:12:03 +0000904static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
Stephen Warren712fbcf2011-10-18 11:11:49 +0000905 char * const argv[], bootm_headers_t *images, ulong *os_data,
906 ulong *os_len)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100907{
908 image_header_t *hdr;
909 ulong img_addr;
Simon Glass35e7b0f2013-05-07 06:12:03 +0000910 const void *buf;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100911#if defined(CONFIG_FIT)
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100912 const char *fit_uname_config = NULL;
913 const char *fit_uname_kernel = NULL;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100914 int os_noffset;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100915#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100916
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100917 /* find out kernel image address */
Simon Glass983c72f2013-06-11 11:14:46 -0700918 if (argc < 1) {
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100919 img_addr = load_addr;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000920 debug("* kernel: default image load address = 0x%08lx\n",
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100921 load_addr);
922#if defined(CONFIG_FIT)
Simon Glass983c72f2013-06-11 11:14:46 -0700923 } else if (fit_parse_conf(argv[0], load_addr, &img_addr,
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100924 &fit_uname_config)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000925 debug("* kernel: config '%s' from image at 0x%08lx\n",
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100926 fit_uname_config, img_addr);
Simon Glass983c72f2013-06-11 11:14:46 -0700927 } else if (fit_parse_subimage(argv[0], load_addr, &img_addr,
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100928 &fit_uname_kernel)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000929 debug("* kernel: subimage '%s' from image at 0x%08lx\n",
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100930 fit_uname_kernel, img_addr);
931#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100932 } else {
Simon Glass983c72f2013-06-11 11:14:46 -0700933 img_addr = simple_strtoul(argv[0], NULL, 16);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000934 debug("* kernel: cmdline image address = 0x%08lx\n", img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100935 }
936
Simon Glass770605e2012-02-13 13:51:18 +0000937 bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100938
Marian Balakowiczfff888a12008-02-21 17:20:19 +0100939 /* copy from dataflash if needed */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000940 img_addr = genimg_get_image(img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100941
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100942 /* check image type, for FIT images get FIT kernel node */
Marian Balakowicz6986a382008-03-12 10:01:05 +0100943 *os_data = *os_len = 0;
Simon Glass35e7b0f2013-05-07 06:12:03 +0000944 buf = map_sysmem(img_addr, 0);
945 switch (genimg_get_format(buf)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100946 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000947 printf("## Booting kernel from Legacy Image at %08lx ...\n",
Marian Balakowicz6986a382008-03-12 10:01:05 +0100948 img_addr);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000949 hdr = image_get_kernel(img_addr, images->verify);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100950 if (!hdr)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100951 return NULL;
Simon Glass770605e2012-02-13 13:51:18 +0000952 bootstage_mark(BOOTSTAGE_ID_CHECK_IMAGETYPE);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100953
Marian Balakowicz6986a382008-03-12 10:01:05 +0100954 /* get os_data and os_len */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000955 switch (image_get_type(hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100956 case IH_TYPE_KERNEL:
Stephen Warrenb9b50e892011-11-10 13:17:53 -0700957 case IH_TYPE_KERNEL_NOLOAD:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000958 *os_data = image_get_data(hdr);
959 *os_len = image_get_data_size(hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100960 break;
961 case IH_TYPE_MULTI:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000962 image_multi_getimg(hdr, 0, os_data, os_len);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100963 break;
Detlev Zundelf97ec302009-07-13 16:01:19 +0200964 case IH_TYPE_STANDALONE:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000965 *os_data = image_get_data(hdr);
966 *os_len = image_get_data_size(hdr);
Detlev Zundelf97ec302009-07-13 16:01:19 +0200967 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100968 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000969 printf("Wrong Image Type for %s command\n",
970 cmdtp->name);
Simon Glass770605e2012-02-13 13:51:18 +0000971 bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100972 return NULL;
973 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100974
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200975 /*
Stephen Warren712fbcf2011-10-18 11:11:49 +0000976 * copy image header to allow for image overwrites during
977 * kernel decompression.
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200978 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000979 memmove(&images->legacy_hdr_os_copy, hdr,
980 sizeof(image_header_t));
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200981
982 /* save pointer to image header */
983 images->legacy_hdr_os = hdr;
984
985 images->legacy_hdr_valid = 1;
Simon Glass770605e2012-02-13 13:51:18 +0000986 bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100987 break;
988#if defined(CONFIG_FIT)
989 case IMAGE_FORMAT_FIT:
Simon Glass46518002013-05-16 13:53:25 +0000990 os_noffset = fit_image_load(images, FIT_KERNEL_PROP,
991 img_addr,
Simon Glassf320a4d2013-07-10 23:08:10 -0700992 &fit_uname_kernel, &fit_uname_config,
Simon Glass46518002013-05-16 13:53:25 +0000993 IH_ARCH_DEFAULT, IH_TYPE_KERNEL,
994 BOOTSTAGE_ID_FIT_KERNEL_START,
995 FIT_LOAD_IGNORED, os_data, os_len);
996 if (os_noffset < 0)
Marian Balakowicz6986a382008-03-12 10:01:05 +0100997 return NULL;
998
Simon Glass46518002013-05-16 13:53:25 +0000999 images->fit_hdr_os = map_sysmem(img_addr, 0);
Marian Balakowicz6986a382008-03-12 10:01:05 +01001000 images->fit_uname_os = fit_uname_kernel;
Simon Glassf320a4d2013-07-10 23:08:10 -07001001 images->fit_uname_cfg = fit_uname_config;
Marian Balakowicz3dfe1102008-03-12 10:32:59 +01001002 images->fit_noffset_os = os_noffset;
Marian Balakowicz6986a382008-03-12 10:01:05 +01001003 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001004#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +01001005 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001006 printf("Wrong Image Format for %s command\n", cmdtp->name);
Simon Glass770605e2012-02-13 13:51:18 +00001007 bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +01001008 return NULL;
1009 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001010
Stephen Warren712fbcf2011-10-18 11:11:49 +00001011 debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
Marian Balakowicz6986a382008-03-12 10:01:05 +01001012 *os_data, *os_len, *os_len);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +01001013
Simon Glass35e7b0f2013-05-07 06:12:03 +00001014 return buf;
Marian Balakowicz5cf746c2008-01-31 13:59:09 +01001015}
1016
Kim Phillips088f1b12012-10-29 13:34:31 +00001017#ifdef CONFIG_SYS_LONGHELP
1018static char bootm_help_text[] =
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001019 "[addr [arg ...]]\n - boot application image stored in memory\n"
1020 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
1021 "\t'arg' can be the address of an initrd image\n"
Marian Balakowicz4a2ad5f2008-01-31 13:20:07 +01001022#if defined(CONFIG_OF_LIBFDT)
Matthew McClintock98a9c4d2006-06-28 10:41:37 -05001023 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
Detlev Zundel5441f612007-10-19 16:47:26 +02001024 "\ta third argument is required which is the address of the\n"
Matthew McClintock98a9c4d2006-06-28 10:41:37 -05001025 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1026 "\tuse a '-' for the second argument. If you do not pass a third\n"
1027 "\ta bd_info struct will be passed instead\n"
1028#endif
Marian Balakowicz6986a382008-03-12 10:01:05 +01001029#if defined(CONFIG_FIT)
1030 "\t\nFor the new multi component uImage format (FIT) addresses\n"
1031 "\tmust be extened to include component or configuration unit name:\n"
1032 "\taddr:<subimg_uname> - direct component image specification\n"
1033 "\taddr#<conf_uname> - configuration specification\n"
1034 "\tUse iminfo command to get the list of existing component\n"
1035 "\timages and configurations.\n"
1036#endif
Kumar Gala49c3a862008-10-21 17:25:45 -05001037 "\nSub-commands to do part of the bootm sequence. The sub-commands "
1038 "must be\n"
1039 "issued in the order below (it's ok to not issue all sub-commands):\n"
1040 "\tstart [addr [arg ...]]\n"
1041 "\tloados - load OS image\n"
Daniel Schwierzeck59af76d2013-02-26 04:54:19 +00001042#if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH)
Kumar Gala49c3a862008-10-21 17:25:45 -05001043 "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
1044#endif
1045#if defined(CONFIG_OF_LIBFDT)
1046 "\tfdt - relocate flat device tree\n"
1047#endif
Kumar Gala49c3a862008-10-21 17:25:45 -05001048 "\tcmdline - OS specific command line processing/setup\n"
Peter Tyser224c90d2009-11-18 19:08:59 -06001049 "\tbdt - OS specific bd_t processing\n"
Kumar Gala49c3a862008-10-21 17:25:45 -05001050 "\tprep - OS specific prep before relocation or go\n"
Kim Phillips088f1b12012-10-29 13:34:31 +00001051 "\tgo - start OS";
1052#endif
1053
1054U_BOOT_CMD(
1055 bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
1056 "boot application image from memory", bootm_help_text
wdenk8bde7f72003-06-27 21:31:46 +00001057);
1058
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001059/*******************************************************************/
1060/* bootd - boot default image */
1061/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -05001062#if defined(CONFIG_CMD_BOOTD)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001063int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk47d1a6e2002-11-03 00:01:44 +00001064{
1065 int rcode = 0;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001066
Simon Glass53071532012-02-14 19:59:21 +00001067 if (run_command(getenv("bootcmd"), flag) < 0)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001068 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001069 return rcode;
1070}
wdenk8bde7f72003-06-27 21:31:46 +00001071
wdenk0d498392003-07-01 21:06:45 +00001072U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001073 boot, 1, 1, do_bootd,
Peter Tyser2fb26042009-01-27 18:03:12 -06001074 "boot default, i.e., run 'bootcmd'",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001075 ""
wdenk9d2b18a2003-06-28 23:11:04 +00001076);
1077
1078/* keep old command name "bootd" for backward compatibility */
wdenk0d498392003-07-01 21:06:45 +00001079U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001080 bootd, 1, 1, do_bootd,
Peter Tyser2fb26042009-01-27 18:03:12 -06001081 "boot default, i.e., run 'bootcmd'",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001082 ""
wdenk8bde7f72003-06-27 21:31:46 +00001083);
1084
wdenk47d1a6e2002-11-03 00:01:44 +00001085#endif
1086
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001087
1088/*******************************************************************/
1089/* iminfo - print header info for a requested image */
1090/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -05001091#if defined(CONFIG_CMD_IMI)
Kim Phillips088f1b12012-10-29 13:34:31 +00001092static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk47d1a6e2002-11-03 00:01:44 +00001093{
1094 int arg;
1095 ulong addr;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001096 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +00001097
1098 if (argc < 2) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001099 return image_info(load_addr);
wdenk47d1a6e2002-11-03 00:01:44 +00001100 }
1101
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001102 for (arg = 1; arg < argc; ++arg) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001103 addr = simple_strtoul(argv[arg], NULL, 16);
1104 if (image_info(addr) != 0)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001105 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001106 }
1107 return rcode;
1108}
1109
Stephen Warren712fbcf2011-10-18 11:11:49 +00001110static int image_info(ulong addr)
wdenk47d1a6e2002-11-03 00:01:44 +00001111{
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001112 void *hdr = (void *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +00001113
Stephen Warren712fbcf2011-10-18 11:11:49 +00001114 printf("\n## Checking Image at %08lx ...\n", addr);
wdenk47d1a6e2002-11-03 00:01:44 +00001115
Stephen Warren712fbcf2011-10-18 11:11:49 +00001116 switch (genimg_get_format(hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001117 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001118 puts(" Legacy image found\n");
1119 if (!image_check_magic(hdr)) {
1120 puts(" Bad Magic Number\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001121 return 1;
1122 }
1123
Stephen Warren712fbcf2011-10-18 11:11:49 +00001124 if (!image_check_hcrc(hdr)) {
1125 puts(" Bad Header Checksum\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001126 return 1;
1127 }
1128
Stephen Warren712fbcf2011-10-18 11:11:49 +00001129 image_print_contents(hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001130
Stephen Warren712fbcf2011-10-18 11:11:49 +00001131 puts(" Verifying Checksum ... ");
1132 if (!image_check_dcrc(hdr)) {
1133 puts(" Bad Data CRC\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001134 return 1;
1135 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00001136 puts("OK\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001137 return 0;
1138#if defined(CONFIG_FIT)
1139 case IMAGE_FORMAT_FIT:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001140 puts(" FIT image found\n");
Marian Balakowicze32fea62008-03-11 12:35:20 +01001141
Stephen Warren712fbcf2011-10-18 11:11:49 +00001142 if (!fit_check_format(hdr)) {
1143 puts("Bad FIT image format!\n");
Marian Balakowicze32fea62008-03-11 12:35:20 +01001144 return 1;
1145 }
1146
Stephen Warren712fbcf2011-10-18 11:11:49 +00001147 fit_print_contents(hdr);
Bartlomiej Siekaa4f24342008-09-09 12:58:16 +02001148
Simon Glassb8da8362013-05-07 06:11:57 +00001149 if (!fit_all_image_verify(hdr)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001150 puts("Bad hash in FIT image!\n");
Bartlomiej Siekaa4f24342008-09-09 12:58:16 +02001151 return 1;
1152 }
1153
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001154 return 0;
1155#endif
1156 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001157 puts("Unknown image format!\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001158 break;
wdenk47d1a6e2002-11-03 00:01:44 +00001159 }
1160
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001161 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001162}
wdenk0d498392003-07-01 21:06:45 +00001163
1164U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001165 iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
Peter Tyser2fb26042009-01-27 18:03:12 -06001166 "print header information for application image",
wdenk8bde7f72003-06-27 21:31:46 +00001167 "addr [addr ...]\n"
1168 " - print header information for application image starting at\n"
1169 " address 'addr' in memory; this includes verification of the\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001170 " image contents (magic number, header and payload checksums)"
wdenk8bde7f72003-06-27 21:31:46 +00001171);
Jon Loeliger90253172007-07-10 11:02:44 -05001172#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001173
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001174
1175/*******************************************************************/
1176/* imls - list all images found in flash */
1177/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -05001178#if defined(CONFIG_CMD_IMLS)
Vipin Kumar8fdf1e02012-12-16 22:32:48 +00001179static int do_imls_nor(void)
wdenk27b207f2003-07-24 23:38:38 +00001180{
1181 flash_info_t *info;
1182 int i, j;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001183 void *hdr;
wdenk27b207f2003-07-24 23:38:38 +00001184
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001185 for (i = 0, info = &flash_info[0];
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001186 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001187
wdenk27b207f2003-07-24 23:38:38 +00001188 if (info->flash_id == FLASH_UNKNOWN)
1189 goto next_bank;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001190 for (j = 0; j < info->sector_count; ++j) {
wdenk27b207f2003-07-24 23:38:38 +00001191
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001192 hdr = (void *)info->start[j];
1193 if (!hdr)
wdenk27b207f2003-07-24 23:38:38 +00001194 goto next_sector;
1195
Stephen Warren712fbcf2011-10-18 11:11:49 +00001196 switch (genimg_get_format(hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001197 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001198 if (!image_check_hcrc(hdr))
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001199 goto next_sector;
1200
Stephen Warren712fbcf2011-10-18 11:11:49 +00001201 printf("Legacy Image at %08lX:\n", (ulong)hdr);
1202 image_print_contents(hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001203
Stephen Warren712fbcf2011-10-18 11:11:49 +00001204 puts(" Verifying Checksum ... ");
1205 if (!image_check_dcrc(hdr)) {
1206 puts("Bad Data CRC\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001207 } else {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001208 puts("OK\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001209 }
1210 break;
1211#if defined(CONFIG_FIT)
1212 case IMAGE_FORMAT_FIT:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001213 if (!fit_check_format(hdr))
Marian Balakowicze32fea62008-03-11 12:35:20 +01001214 goto next_sector;
1215
Stephen Warren712fbcf2011-10-18 11:11:49 +00001216 printf("FIT Image at %08lX:\n", (ulong)hdr);
1217 fit_print_contents(hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001218 break;
1219#endif
1220 default:
wdenk27b207f2003-07-24 23:38:38 +00001221 goto next_sector;
wdenk5bb226e2003-11-17 21:14:37 +00001222 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001223
wdenkbdccc4f2003-08-05 17:43:17 +00001224next_sector: ;
wdenk27b207f2003-07-24 23:38:38 +00001225 }
wdenkbdccc4f2003-08-05 17:43:17 +00001226next_bank: ;
wdenk27b207f2003-07-24 23:38:38 +00001227 }
Vipin Kumar8fdf1e02012-12-16 22:32:48 +00001228 return 0;
1229}
1230#endif
1231
1232#if defined(CONFIG_CMD_IMLS_NAND)
1233static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off,
1234 size_t len)
1235{
1236 void *imgdata;
1237 int ret;
1238
1239 imgdata = malloc(len);
1240 if (!imgdata) {
1241 printf("May be a Legacy Image at NAND device %d offset %08llX:\n",
1242 nand_dev, off);
1243 printf(" Low memory(cannot allocate memory for image)\n");
1244 return -ENOMEM;
1245 }
1246
1247 ret = nand_read_skip_bad(nand, off, &len,
1248 imgdata);
1249 if (ret < 0 && ret != -EUCLEAN) {
1250 free(imgdata);
1251 return ret;
1252 }
1253
1254 if (!image_check_hcrc(imgdata)) {
1255 free(imgdata);
1256 return 0;
1257 }
1258
1259 printf("Legacy Image at NAND device %d offset %08llX:\n",
1260 nand_dev, off);
1261 image_print_contents(imgdata);
1262
1263 puts(" Verifying Checksum ... ");
1264 if (!image_check_dcrc(imgdata))
1265 puts("Bad Data CRC\n");
1266 else
1267 puts("OK\n");
1268
1269 free(imgdata);
1270
1271 return 0;
1272}
1273
1274static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off,
1275 size_t len)
1276{
1277 void *imgdata;
1278 int ret;
1279
1280 imgdata = malloc(len);
1281 if (!imgdata) {
1282 printf("May be a FIT Image at NAND device %d offset %08llX:\n",
1283 nand_dev, off);
1284 printf(" Low memory(cannot allocate memory for image)\n");
1285 return -ENOMEM;
1286 }
1287
1288 ret = nand_read_skip_bad(nand, off, &len,
1289 imgdata);
1290 if (ret < 0 && ret != -EUCLEAN) {
1291 free(imgdata);
1292 return ret;
1293 }
1294
1295 if (!fit_check_format(imgdata)) {
1296 free(imgdata);
1297 return 0;
1298 }
1299
1300 printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off);
1301
1302 fit_print_contents(imgdata);
1303 free(imgdata);
1304
1305 return 0;
1306}
1307
1308static int do_imls_nand(void)
1309{
1310 nand_info_t *nand;
1311 int nand_dev = nand_curr_device;
1312 size_t len;
1313 loff_t off;
1314 u32 buffer[16];
1315
1316 if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) {
1317 puts("\nNo NAND devices available\n");
1318 return -ENODEV;
1319 }
1320
1321 printf("\n");
1322
1323 for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) {
1324 nand = &nand_info[nand_dev];
1325 if (!nand->name || !nand->size)
1326 continue;
1327
1328 for (off = 0; off < nand->size; off += nand->erasesize) {
1329 const image_header_t *header;
1330 int ret;
1331
1332 if (nand_block_isbad(nand, off))
1333 continue;
1334
1335 len = sizeof(buffer);
1336
1337 ret = nand_read(nand, off, &len, (u8 *)buffer);
1338 if (ret < 0 && ret != -EUCLEAN) {
1339 printf("NAND read error %d at offset %08llX\n",
1340 ret, off);
1341 continue;
1342 }
1343
1344 switch (genimg_get_format(buffer)) {
1345 case IMAGE_FORMAT_LEGACY:
1346 header = (const image_header_t *)buffer;
1347
1348 len = image_get_image_size(header);
1349 nand_imls_legacyimage(nand, nand_dev, off, len);
1350 break;
1351#if defined(CONFIG_FIT)
1352 case IMAGE_FORMAT_FIT:
1353 len = fit_get_size(buffer);
1354 nand_imls_fitimage(nand, nand_dev, off, len);
1355 break;
1356#endif
1357 }
1358 }
1359 }
1360
1361 return 0;
1362}
1363#endif
1364
1365#if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
1366static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1367{
1368 int ret_nor = 0, ret_nand = 0;
1369
1370#if defined(CONFIG_CMD_IMLS)
1371 ret_nor = do_imls_nor();
1372#endif
1373
1374#if defined(CONFIG_CMD_IMLS_NAND)
1375 ret_nand = do_imls_nand();
1376#endif
1377
1378 if (ret_nor)
1379 return ret_nor;
1380
1381 if (ret_nand)
1382 return ret_nand;
wdenk27b207f2003-07-24 23:38:38 +00001383
1384 return (0);
1385}
1386
1387U_BOOT_CMD(
1388 imls, 1, 1, do_imls,
Peter Tyser2fb26042009-01-27 18:03:12 -06001389 "list all images found in flash",
wdenk27b207f2003-07-24 23:38:38 +00001390 "\n"
Vipin Kumar8fdf1e02012-12-16 22:32:48 +00001391 " - Prints information about all images found at sector/block\n"
1392 " boundaries in nor/nand flash."
wdenk27b207f2003-07-24 23:38:38 +00001393);
Jon Loeliger90253172007-07-10 11:02:44 -05001394#endif
wdenk27b207f2003-07-24 23:38:38 +00001395
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001396/*******************************************************************/
Marian Balakowicz5cf746c2008-01-31 13:59:09 +01001397/* helper routines */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001398/*******************************************************************/
Joe Hershbergerbe2e5a02013-02-27 10:20:59 +00001399#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
Doug Andersona558ad72012-01-17 09:37:41 +00001400
1401#define CONSOLE_ARG "console="
1402#define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1)
1403
Doug Anderson3a8653b2011-10-19 12:30:57 +00001404static void fixup_silent_linux(void)
wdenk47d1a6e2002-11-03 00:01:44 +00001405{
Doug Andersona558ad72012-01-17 09:37:41 +00001406 char *buf;
1407 const char *env_val;
Doug Anderson3a8653b2011-10-19 12:30:57 +00001408 char *cmdline = getenv("bootargs");
Simon Glass8d51aac2013-07-16 20:10:00 -07001409 int want_silent;
wdenk47d1a6e2002-11-03 00:01:44 +00001410
Simon Glass8d51aac2013-07-16 20:10:00 -07001411 /*
1412 * Only fix cmdline when requested. The environment variable can be:
1413 *
1414 * no - we never fixup
1415 * yes - we always fixup
1416 * unset - we rely on the console silent flag
1417 */
1418 want_silent = getenv_yesno("silent_linux");
1419 if (want_silent == 0)
1420 return;
1421 else if (want_silent == -1 && !(gd->flags & GD_FLG_SILENT))
wdenk47d1a6e2002-11-03 00:01:44 +00001422 return;
1423
Doug Anderson3a8653b2011-10-19 12:30:57 +00001424 debug("before silent fix-up: %s\n", cmdline);
Doug Andersona558ad72012-01-17 09:37:41 +00001425 if (cmdline && (cmdline[0] != '\0')) {
1426 char *start = strstr(cmdline, CONSOLE_ARG);
1427
1428 /* Allocate space for maximum possible new command line */
1429 buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_LEN + 1);
1430 if (!buf) {
1431 debug("%s: out of memory\n", __func__);
1432 return;
wdenk47d1a6e2002-11-03 00:01:44 +00001433 }
Doug Andersona558ad72012-01-17 09:37:41 +00001434
1435 if (start) {
1436 char *end = strchr(start, ' ');
1437 int num_start_bytes = start - cmdline + CONSOLE_ARG_LEN;
1438
1439 strncpy(buf, cmdline, num_start_bytes);
1440 if (end)
1441 strcpy(buf + num_start_bytes, end);
1442 else
1443 buf[num_start_bytes] = '\0';
1444 } else {
1445 sprintf(buf, "%s %s", cmdline, CONSOLE_ARG);
1446 }
1447 env_val = buf;
wdenk47d1a6e2002-11-03 00:01:44 +00001448 } else {
Doug Andersona558ad72012-01-17 09:37:41 +00001449 buf = NULL;
1450 env_val = CONSOLE_ARG;
wdenk47d1a6e2002-11-03 00:01:44 +00001451 }
1452
Doug Andersona558ad72012-01-17 09:37:41 +00001453 setenv("bootargs", env_val);
1454 debug("after silent fix-up: %s\n", env_val);
1455 free(buf);
wdenk47d1a6e2002-11-03 00:01:44 +00001456}
1457#endif /* CONFIG_SILENT_CONSOLE */
1458
Steven Stallioneeaef5e2013-06-10 01:00:09 -07001459#if defined(CONFIG_BOOTM_NETBSD) || defined(CONFIG_BOOTM_PLAN9)
1460static void copy_args(char *dest, int argc, char * const argv[], char delim)
1461{
1462 int i;
1463
1464 for (i = 0; i < argc; i++) {
1465 if (i > 0)
1466 *dest++ = delim;
1467 strcpy(dest, argv[i]);
1468 dest += strlen(argv[i]);
1469 }
1470}
1471#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001472
1473/*******************************************************************/
1474/* OS booting routines */
1475/*******************************************************************/
1476
Kumar Galab1d0db12008-10-21 17:25:47 -05001477#ifdef CONFIG_BOOTM_NETBSD
Stephen Warren712fbcf2011-10-18 11:11:49 +00001478static int do_bootm_netbsd(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001479 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001480{
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001481 void (*loader)(bd_t *, image_header_t *, char *, char *);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001482 image_header_t *os_hdr, *hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001483 ulong kernel_data, kernel_len;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001484 char *consdev;
1485 char *cmdline;
wdenk47d1a6e2002-11-03 00:01:44 +00001486
Miao Yan5b629312013-11-04 11:18:14 +08001487 if (flag != BOOTM_STATE_OS_GO)
Simon Glass7af26b12013-07-10 23:08:09 -07001488 return 0;
Kumar Gala49c3a862008-10-21 17:25:45 -05001489
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001490#if defined(CONFIG_FIT)
1491 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001492 fit_unsupported_reset("NetBSD");
Kumar Gala40d7e992008-08-15 08:24:45 -05001493 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001494 }
1495#endif
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001496 hdr = images->legacy_hdr_os;
wdenk47d1a6e2002-11-03 00:01:44 +00001497
1498 /*
1499 * Booting a (NetBSD) kernel image
1500 *
1501 * This process is pretty similar to a standalone application:
1502 * The (first part of an multi-) image must be a stage-2 loader,
1503 * which in turn is responsible for loading & invoking the actual
1504 * kernel. The only differences are the parameters being passed:
1505 * besides the board info strucure, the loader expects a command
1506 * line, the name of the console device, and (optionally) the
1507 * address of the original image header.
1508 */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001509 os_hdr = NULL;
Stephen Warren712fbcf2011-10-18 11:11:49 +00001510 if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1511 image_multi_getimg(hdr, 1, &kernel_data, &kernel_len);
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001512 if (kernel_len)
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001513 os_hdr = hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001514 }
wdenk47d1a6e2002-11-03 00:01:44 +00001515
1516 consdev = "";
Stephen Warren712fbcf2011-10-18 11:11:49 +00001517#if defined(CONFIG_8xx_CONS_SMC1)
wdenk47d1a6e2002-11-03 00:01:44 +00001518 consdev = "smc1";
Stephen Warren712fbcf2011-10-18 11:11:49 +00001519#elif defined(CONFIG_8xx_CONS_SMC2)
wdenk47d1a6e2002-11-03 00:01:44 +00001520 consdev = "smc2";
Stephen Warren712fbcf2011-10-18 11:11:49 +00001521#elif defined(CONFIG_8xx_CONS_SCC2)
wdenk47d1a6e2002-11-03 00:01:44 +00001522 consdev = "scc2";
Stephen Warren712fbcf2011-10-18 11:11:49 +00001523#elif defined(CONFIG_8xx_CONS_SCC3)
wdenk47d1a6e2002-11-03 00:01:44 +00001524 consdev = "scc3";
1525#endif
1526
Simon Glass983c72f2013-06-11 11:14:46 -07001527 if (argc > 0) {
wdenk47d1a6e2002-11-03 00:01:44 +00001528 ulong len;
1529 int i;
1530
Simon Glass983c72f2013-06-11 11:14:46 -07001531 for (i = 0, len = 0; i < argc; i += 1)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001532 len += strlen(argv[i]) + 1;
1533 cmdline = malloc(len);
Steven Stallioneeaef5e2013-06-10 01:00:09 -07001534 copy_args(cmdline, argc, argv, ' ');
Stephen Warren712fbcf2011-10-18 11:11:49 +00001535 } else if ((cmdline = getenv("bootargs")) == NULL) {
wdenk47d1a6e2002-11-03 00:01:44 +00001536 cmdline = "";
1537 }
1538
Kumar Galac160a952008-08-15 08:24:36 -05001539 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
wdenk47d1a6e2002-11-03 00:01:44 +00001540
Stephen Warren712fbcf2011-10-18 11:11:49 +00001541 printf("## Transferring control to NetBSD stage-2 loader "
1542 "(at address %08lx) ...\n",
wdenk47d1a6e2002-11-03 00:01:44 +00001543 (ulong)loader);
1544
Simon Glass770605e2012-02-13 13:51:18 +00001545 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
wdenk47d1a6e2002-11-03 00:01:44 +00001546
1547 /*
1548 * NetBSD Stage-2 Loader Parameters:
Kees Jongenburgere2ce8162013-12-12 16:18:35 +01001549 * arg[0]: pointer to board info data
1550 * arg[1]: image load address
1551 * arg[2]: char pointer to the console device to use
1552 * arg[3]: char pointer to the boot arguments
wdenk47d1a6e2002-11-03 00:01:44 +00001553 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001554 (*loader)(gd->bd, os_hdr, consdev, cmdline);
Kumar Gala40d7e992008-08-15 08:24:45 -05001555
1556 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001557}
Kumar Galab1d0db12008-10-21 17:25:47 -05001558#endif /* CONFIG_BOOTM_NETBSD*/
wdenk47d1a6e2002-11-03 00:01:44 +00001559
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001560#ifdef CONFIG_LYNXKDI
Stephen Warren712fbcf2011-10-18 11:11:49 +00001561static int do_bootm_lynxkdi(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001562 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001563{
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001564 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001565
Miao Yan5b629312013-11-04 11:18:14 +08001566 if (flag != BOOTM_STATE_OS_GO)
Simon Glass7af26b12013-07-10 23:08:09 -07001567 return 0;
Kumar Gala49c3a862008-10-21 17:25:45 -05001568
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001569#if defined(CONFIG_FIT)
1570 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001571 fit_unsupported_reset("Lynx");
Kumar Gala40d7e992008-08-15 08:24:45 -05001572 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001573 }
1574#endif
1575
Stephen Warren712fbcf2011-10-18 11:11:49 +00001576 lynxkdi_boot((image_header_t *)hdr);
Kumar Gala40d7e992008-08-15 08:24:45 -05001577
1578 return 1;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001579}
1580#endif /* CONFIG_LYNXKDI */
1581
Kumar Galab1d0db12008-10-21 17:25:47 -05001582#ifdef CONFIG_BOOTM_RTEMS
Stephen Warren712fbcf2011-10-18 11:11:49 +00001583static int do_bootm_rtems(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001584 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001585{
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001586 void (*entry_point)(bd_t *);
wdenkd791b1d2003-04-20 14:04:18 +00001587
Miao Yan5b629312013-11-04 11:18:14 +08001588 if (flag != BOOTM_STATE_OS_GO)
Simon Glass7af26b12013-07-10 23:08:09 -07001589 return 0;
Kumar Gala49c3a862008-10-21 17:25:45 -05001590
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001591#if defined(CONFIG_FIT)
1592 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001593 fit_unsupported_reset("RTEMS");
Kumar Gala40d7e992008-08-15 08:24:45 -05001594 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001595 }
1596#endif
1597
Kumar Galac160a952008-08-15 08:24:36 -05001598 entry_point = (void (*)(bd_t *))images->ep;
wdenkd791b1d2003-04-20 14:04:18 +00001599
Stephen Warren712fbcf2011-10-18 11:11:49 +00001600 printf("## Transferring control to RTEMS (at address %08lx) ...\n",
wdenkd791b1d2003-04-20 14:04:18 +00001601 (ulong)entry_point);
1602
Simon Glass770605e2012-02-13 13:51:18 +00001603 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
wdenkd791b1d2003-04-20 14:04:18 +00001604
1605 /*
1606 * RTEMS Parameters:
1607 * r3: ptr to board info data
1608 */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001609 (*entry_point)(gd->bd);
Kumar Gala40d7e992008-08-15 08:24:45 -05001610
1611 return 1;
wdenkd791b1d2003-04-20 14:04:18 +00001612}
Kumar Galab1d0db12008-10-21 17:25:47 -05001613#endif /* CONFIG_BOOTM_RTEMS */
wdenkd791b1d2003-04-20 14:04:18 +00001614
Torkel Lundgren3df61952010-09-28 11:05:36 +02001615#if defined(CONFIG_BOOTM_OSE)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001616static int do_bootm_ose(int flag, int argc, char * const argv[],
Torkel Lundgren3df61952010-09-28 11:05:36 +02001617 bootm_headers_t *images)
1618{
1619 void (*entry_point)(void);
1620
Miao Yan5b629312013-11-04 11:18:14 +08001621 if (flag != BOOTM_STATE_OS_GO)
Simon Glass7af26b12013-07-10 23:08:09 -07001622 return 0;
Torkel Lundgren3df61952010-09-28 11:05:36 +02001623
1624#if defined(CONFIG_FIT)
1625 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001626 fit_unsupported_reset("OSE");
Torkel Lundgren3df61952010-09-28 11:05:36 +02001627 return 1;
1628 }
1629#endif
1630
1631 entry_point = (void (*)(void))images->ep;
1632
Stephen Warren712fbcf2011-10-18 11:11:49 +00001633 printf("## Transferring control to OSE (at address %08lx) ...\n",
Torkel Lundgren3df61952010-09-28 11:05:36 +02001634 (ulong)entry_point);
1635
Simon Glass770605e2012-02-13 13:51:18 +00001636 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
Torkel Lundgren3df61952010-09-28 11:05:36 +02001637
1638 /*
1639 * OSE Parameters:
1640 * None
1641 */
1642 (*entry_point)();
1643
1644 return 1;
1645}
1646#endif /* CONFIG_BOOTM_OSE */
1647
Steven Stallion04d41402013-03-20 06:31:35 +00001648#if defined(CONFIG_BOOTM_PLAN9)
1649static int do_bootm_plan9(int flag, int argc, char * const argv[],
1650 bootm_headers_t *images)
1651{
1652 void (*entry_point)(void);
Steven Stallioneeaef5e2013-06-10 01:00:09 -07001653 char *s;
Steven Stallion04d41402013-03-20 06:31:35 +00001654
Miao Yan5b629312013-11-04 11:18:14 +08001655 if (flag != BOOTM_STATE_OS_GO)
Simon Glass7af26b12013-07-10 23:08:09 -07001656 return 0;
Steven Stallion04d41402013-03-20 06:31:35 +00001657
1658#if defined(CONFIG_FIT)
1659 if (!images->legacy_hdr_valid) {
1660 fit_unsupported_reset("Plan 9");
1661 return 1;
1662 }
1663#endif
1664
Steven Stallioneeaef5e2013-06-10 01:00:09 -07001665 /* See README.plan9 */
1666 s = getenv("confaddr");
1667 if (s != NULL) {
1668 char *confaddr = (char *)simple_strtoul(s, NULL, 16);
1669
1670 if (argc > 0) {
1671 copy_args(confaddr, argc, argv, '\n');
1672 } else {
1673 s = getenv("bootargs");
1674 if (s != NULL)
1675 strcpy(confaddr, s);
1676 }
1677 }
1678
Steven Stallion04d41402013-03-20 06:31:35 +00001679 entry_point = (void (*)(void))images->ep;
1680
1681 printf("## Transferring control to Plan 9 (at address %08lx) ...\n",
1682 (ulong)entry_point);
1683
1684 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1685
1686 /*
1687 * Plan 9 Parameters:
1688 * None
1689 */
1690 (*entry_point)();
1691
1692 return 1;
1693}
1694#endif /* CONFIG_BOOTM_PLAN9 */
1695
Miao Yan871a57b2013-11-28 17:51:38 +08001696#if defined(CONFIG_BOOTM_VXWORKS) && \
1697 (defined(CONFIG_PPC) || defined(CONFIG_ARM))
1698
1699void do_bootvx_fdt(bootm_headers_t *images)
1700{
1701#if defined(CONFIG_OF_LIBFDT)
1702 int ret;
1703 char *bootline;
1704 ulong of_size = images->ft_len;
1705 char **of_flat_tree = &images->ft_addr;
1706 struct lmb *lmb = &images->lmb;
1707
1708 if (*of_flat_tree) {
1709 boot_fdt_add_mem_rsv_regions(lmb, *of_flat_tree);
1710
1711 ret = boot_relocate_fdt(lmb, of_flat_tree, &of_size);
1712 if (ret)
1713 return;
1714
1715 ret = fdt_add_subnode(*of_flat_tree, 0, "chosen");
1716 if ((ret >= 0 || ret == -FDT_ERR_EXISTS)) {
1717 bootline = getenv("bootargs");
1718 if (bootline) {
1719 ret = fdt_find_and_setprop(*of_flat_tree,
1720 "/chosen", "bootargs",
1721 bootline,
1722 strlen(bootline) + 1, 1);
1723 if (ret < 0) {
1724 printf("## ERROR: %s : %s\n", __func__,
1725 fdt_strerror(ret));
1726 return;
1727 }
1728 }
1729 } else {
1730 printf("## ERROR: %s : %s\n", __func__,
1731 fdt_strerror(ret));
1732 return;
1733 }
1734 }
1735#endif
1736
1737 boot_prep_vxworks(images);
1738
1739 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1740
1741#if defined(CONFIG_OF_LIBFDT)
1742 printf("## Starting vxWorks at 0x%08lx, device tree at 0x%08lx ...\n",
1743 (ulong)images->ep, (ulong)*of_flat_tree);
1744#else
1745 printf("## Starting vxWorks at 0x%08lx\n", (ulong)images->ep);
1746#endif
1747
1748 boot_jump_vxworks(images);
1749
1750 puts("## vxWorks terminated\n");
1751}
1752
Stephen Warren712fbcf2011-10-18 11:11:49 +00001753static int do_bootm_vxworks(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001754 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001755{
Miao Yan5b629312013-11-04 11:18:14 +08001756 if (flag != BOOTM_STATE_OS_GO)
Simon Glass7af26b12013-07-10 23:08:09 -07001757 return 0;
Kumar Gala49c3a862008-10-21 17:25:45 -05001758
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001759#if defined(CONFIG_FIT)
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001760 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001761 fit_unsupported_reset("VxWorks");
Kumar Gala40d7e992008-08-15 08:24:45 -05001762 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001763 }
1764#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001765
Miao Yan871a57b2013-11-28 17:51:38 +08001766 do_bootvx_fdt(images);
Kumar Gala40d7e992008-08-15 08:24:45 -05001767
1768 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001769}
Miao Yan17ab52f2013-11-28 17:51:36 +08001770#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001771
Miao Yan17ab52f2013-11-28 17:51:36 +08001772#if defined(CONFIG_CMD_ELF)
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001773static int do_bootm_qnxelf(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001774 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001775{
wdenk47d1a6e2002-11-03 00:01:44 +00001776 char *local_args[2];
1777 char str[16];
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001778
Miao Yan5b629312013-11-04 11:18:14 +08001779 if (flag != BOOTM_STATE_OS_GO)
Simon Glass7af26b12013-07-10 23:08:09 -07001780 return 0;
Kumar Gala49c3a862008-10-21 17:25:45 -05001781
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001782#if defined(CONFIG_FIT)
1783 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001784 fit_unsupported_reset("QNX");
Kumar Gala40d7e992008-08-15 08:24:45 -05001785 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001786 }
1787#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001788
Kumar Galac160a952008-08-15 08:24:36 -05001789 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001790 local_args[0] = argv[0];
1791 local_args[1] = str; /* and provide it via the arguments */
Kumar Gala40d7e992008-08-15 08:24:45 -05001792 do_bootelf(NULL, 0, 2, local_args);
1793
1794 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001795}
Jon Loeliger90253172007-07-10 11:02:44 -05001796#endif
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001797
1798#ifdef CONFIG_INTEGRITY
Stephen Warren712fbcf2011-10-18 11:11:49 +00001799static int do_bootm_integrity(int flag, int argc, char * const argv[],
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001800 bootm_headers_t *images)
1801{
1802 void (*entry_point)(void);
1803
Miao Yan5b629312013-11-04 11:18:14 +08001804 if (flag != BOOTM_STATE_OS_GO)
Simon Glass7af26b12013-07-10 23:08:09 -07001805 return 0;
Kumar Gala49c3a862008-10-21 17:25:45 -05001806
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001807#if defined(CONFIG_FIT)
1808 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001809 fit_unsupported_reset("INTEGRITY");
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001810 return 1;
1811 }
1812#endif
1813
1814 entry_point = (void (*)(void))images->ep;
1815
Stephen Warren712fbcf2011-10-18 11:11:49 +00001816 printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001817 (ulong)entry_point);
1818
Simon Glass770605e2012-02-13 13:51:18 +00001819 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001820
1821 /*
1822 * INTEGRITY Parameters:
1823 * None
1824 */
1825 (*entry_point)();
1826
1827 return 1;
1828}
1829#endif
Marek Vasut44f074c2012-03-14 21:52:45 +00001830
1831#ifdef CONFIG_CMD_BOOTZ
1832
Simon Glassa5266d62013-07-04 13:26:10 -07001833int __weak bootz_setup(ulong image, ulong *start, ulong *end)
Marek Vasut44f074c2012-03-14 21:52:45 +00001834{
1835 /* Please define bootz_setup() for your platform */
1836
1837 puts("Your platform's zImage format isn't supported yet!\n");
1838 return -1;
1839}
Marek Vasut44f074c2012-03-14 21:52:45 +00001840
1841/*
1842 * zImage booting support
1843 */
1844static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
1845 char * const argv[], bootm_headers_t *images)
1846{
1847 int ret;
Simon Glassa5266d62013-07-04 13:26:10 -07001848 ulong zi_start, zi_end;
Marek Vasut44f074c2012-03-14 21:52:45 +00001849
Simon Glass35fc84f2013-06-11 11:14:47 -07001850 ret = do_bootm_states(cmdtp, flag, argc, argv, BOOTM_STATE_START,
1851 images, 1);
Marek Vasut44f074c2012-03-14 21:52:45 +00001852
1853 /* Setup Linux kernel zImage entry point */
Tom Rini2b9599e2013-07-09 15:32:34 -04001854 if (!argc) {
Marek Vasut44f074c2012-03-14 21:52:45 +00001855 images->ep = load_addr;
1856 debug("* kernel: default image load address = 0x%08lx\n",
1857 load_addr);
1858 } else {
Tom Rini2b9599e2013-07-09 15:32:34 -04001859 images->ep = simple_strtoul(argv[0], NULL, 16);
Marek Vasut44f074c2012-03-14 21:52:45 +00001860 debug("* kernel: cmdline image address = 0x%08lx\n",
1861 images->ep);
1862 }
1863
Simon Glassa5266d62013-07-04 13:26:10 -07001864 ret = bootz_setup(images->ep, &zi_start, &zi_end);
Marek Vasut44f074c2012-03-14 21:52:45 +00001865 if (ret != 0)
1866 return 1;
1867
1868 lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
1869
Tom Rini225fd8c2013-07-09 15:33:25 -04001870 /*
1871 * Handle the BOOTM_STATE_FINDOTHER state ourselves as we do not
1872 * have a header that provide this informaiton.
1873 */
Tom Rini2b9599e2013-07-09 15:32:34 -04001874 if (bootm_find_ramdisk(flag, argc, argv))
1875 return 1;
Marek Vasut44f074c2012-03-14 21:52:45 +00001876
Tom Rini2b9599e2013-07-09 15:32:34 -04001877#if defined(CONFIG_OF_LIBFDT)
1878 if (bootm_find_fdt(flag, argc, argv))
1879 return 1;
1880#endif
1881
1882 return 0;
Marek Vasut44f074c2012-03-14 21:52:45 +00001883}
1884
Rob Herringda620222012-12-02 21:00:23 -06001885int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Marek Vasut44f074c2012-03-14 21:52:45 +00001886{
Simon Glass35fc84f2013-06-11 11:14:47 -07001887 int ret;
Marek Vasut44f074c2012-03-14 21:52:45 +00001888
Tom Rini2b9599e2013-07-09 15:32:34 -04001889 /* Consume 'bootz' */
1890 argc--; argv++;
1891
Marek Vasut44f074c2012-03-14 21:52:45 +00001892 if (bootz_start(cmdtp, flag, argc, argv, &images))
1893 return 1;
1894
Simon Glass385501d2013-07-04 13:26:08 -07001895 /*
1896 * We are doing the BOOTM_STATE_LOADOS state ourselves, so must
1897 * disable interrupts ourselves
1898 */
1899 bootm_disable_interrupts();
1900
Simon Glassfb1b1392013-07-04 13:26:11 -07001901 images.os.os = IH_OS_LINUX;
Simon Glass35fc84f2013-06-11 11:14:47 -07001902 ret = do_bootm_states(cmdtp, flag, argc, argv,
Simon Glassfb1b1392013-07-04 13:26:11 -07001903 BOOTM_STATE_OS_PREP | BOOTM_STATE_OS_FAKE_GO |
1904 BOOTM_STATE_OS_GO,
Simon Glassd0ae31e2013-06-11 11:14:48 -07001905 &images, 1);
Marek Vasut44f074c2012-03-14 21:52:45 +00001906
Simon Glass35fc84f2013-06-11 11:14:47 -07001907 return ret;
Marek Vasut44f074c2012-03-14 21:52:45 +00001908}
1909
Kim Phillips088f1b12012-10-29 13:34:31 +00001910#ifdef CONFIG_SYS_LONGHELP
1911static char bootz_help_text[] =
Marek Vasut017e1f32012-03-18 11:47:58 +00001912 "[addr [initrd[:size]] [fdt]]\n"
1913 " - boot Linux zImage stored in memory\n"
Marek Vasut44f074c2012-03-14 21:52:45 +00001914 "\tThe argument 'initrd' is optional and specifies the address\n"
Marek Vasut017e1f32012-03-18 11:47:58 +00001915 "\tof the initrd in memory. The optional argument ':size' allows\n"
1916 "\tspecifying the size of RAW initrd.\n"
Marek Vasut44f074c2012-03-14 21:52:45 +00001917#if defined(CONFIG_OF_LIBFDT)
1918 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
1919 "\ta third argument is required which is the address of the\n"
1920 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1921 "\tuse a '-' for the second argument. If you do not pass a third\n"
1922 "\ta bd_info struct will be passed instead\n"
1923#endif
Kim Phillips088f1b12012-10-29 13:34:31 +00001924 "";
1925#endif
1926
1927U_BOOT_CMD(
1928 bootz, CONFIG_SYS_MAXARGS, 1, do_bootz,
1929 "boot Linux zImage image from memory", bootz_help_text
Marek Vasut44f074c2012-03-14 21:52:45 +00001930);
1931#endif /* CONFIG_CMD_BOOTZ */