blob: b09f35bb9f9bbc13ff6655b963c021cedb50d277 [file] [log] [blame]
wdenk47d1a6e2002-11-03 00:01:44 +00001/*
Detlev Zundelca95c9d2009-07-13 16:01:18 +02002 * (C) Copyright 2000-2009
wdenk47d1a6e2002-11-03 00:01:44 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010024
wdenk47d1a6e2002-11-03 00:01:44 +000025/*
26 * Boot support
27 */
28#include <common.h>
29#include <watchdog.h>
30#include <command.h>
wdenk47d1a6e2002-11-03 00:01:44 +000031#include <image.h>
32#include <malloc.h>
Jean-Christophe PLAGNIOL-VILLARDa31e0912009-04-04 12:49:11 +020033#include <u-boot/zlib.h>
wdenkc29fdfc2003-08-29 20:57:53 +000034#include <bzlib.h>
wdenk7f70e852003-05-20 14:25:27 +000035#include <environment.h>
Kumar Gala4ed65522008-02-27 21:51:47 -060036#include <lmb.h>
Kumar Gala49c3a862008-10-21 17:25:45 -050037#include <linux/ctype.h>
wdenk47d1a6e2002-11-03 00:01:44 +000038#include <asm/byteorder.h>
Simon Glass35e7b0f2013-05-07 06:12:03 +000039#include <asm/io.h>
Anatolij Gustschin5bf27662011-11-19 13:12:18 +000040#include <linux/compiler.h>
wdenk8bde7f72003-06-27 21:31:46 +000041
Stefan Roeseebb86c42008-07-30 09:59:51 +020042#if defined(CONFIG_CMD_USB)
Markus Klotzbücher3d71c812008-07-10 14:47:09 +020043#include <usb.h>
44#endif
45
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020046#ifdef CONFIG_SYS_HUSH_PARSER
wdenk47d1a6e2002-11-03 00:01:44 +000047#include <hush.h>
48#endif
49
Kumar Gala54f9c862008-08-15 08:24:39 -050050#if defined(CONFIG_OF_LIBFDT)
Kumar Gala54f9c862008-08-15 08:24:39 -050051#include <libfdt.h>
52#include <fdt_support.h>
53#endif
54
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +020055#ifdef CONFIG_LZMA
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +020056#include <lzma/LzmaTypes.h>
Luigi 'Comio' Mantellinicaf72ff2009-07-21 10:45:49 +020057#include <lzma/LzmaDec.h>
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +020058#include <lzma/LzmaTools.h>
59#endif /* CONFIG_LZMA */
60
Peter Korsgaard20dde482009-11-19 11:37:51 +010061#ifdef CONFIG_LZO
62#include <linux/lzo.h>
63#endif /* CONFIG_LZO */
64
Marian Balakowicz1ee11802008-01-08 18:17:10 +010065DECLARE_GLOBAL_DATA_PTR;
66
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020067#ifndef CONFIG_SYS_BOOTM_LEN
68#define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
wdenk47d1a6e2002-11-03 00:01:44 +000069#endif
70
Marian Balakowicz321359f2008-01-08 18:11:43 +010071#ifdef CONFIG_BZIP2
72extern void bz_internal_error(int);
wdenk228f29a2002-12-08 09:53:23 +000073#endif
74
Jon Loeligerbaa26db2007-07-08 17:51:39 -050075#if defined(CONFIG_CMD_IMI)
Stephen Warren712fbcf2011-10-18 11:11:49 +000076static int image_info(unsigned long addr);
wdenk47d1a6e2002-11-03 00:01:44 +000077#endif
wdenk27b207f2003-07-24 23:38:38 +000078
Jon Loeligerbaa26db2007-07-08 17:51:39 -050079#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +000080#include <flash.h>
Stefan Roeseca5def32010-08-31 10:00:10 +020081#include <mtd/cfi_flash.h>
Marian Balakowicze6f2e902005-10-11 19:09:42 +020082extern flash_info_t flash_info[]; /* info for FLASH chips */
Vipin Kumar8fdf1e02012-12-16 22:32:48 +000083#endif
84
85#if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
Stephen Warren712fbcf2011-10-18 11:11:49 +000086static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
wdenk27b207f2003-07-24 23:38:38 +000087#endif
88
Vipin Kumar8fdf1e02012-12-16 22:32:48 +000089#include <linux/err.h>
90#include <nand.h>
91
Joe Hershbergerbe2e5a02013-02-27 10:20:59 +000092#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
Stephen Warren712fbcf2011-10-18 11:11:49 +000093static void fixup_silent_linux(void);
wdenk2262cfe2002-11-18 00:14:45 +000094#endif
95
Stephen Warren712fbcf2011-10-18 11:11:49 +000096static image_header_t *image_get_kernel(ulong img_addr, int verify);
Marian Balakowicz6986a382008-03-12 10:01:05 +010097#if defined(CONFIG_FIT)
Stephen Warren712fbcf2011-10-18 11:11:49 +000098static int fit_check_kernel(const void *fit, int os_noffset, int verify);
Marian Balakowicz6986a382008-03-12 10:01:05 +010099#endif
100
Simon Glass35e7b0f2013-05-07 06:12:03 +0000101static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
Stephen Warren712fbcf2011-10-18 11:11:49 +0000102 char * const argv[], bootm_headers_t *images,
103 ulong *os_data, ulong *os_len);
wdenk47d1a6e2002-11-03 00:01:44 +0000104
wdenk47d1a6e2002-11-03 00:01:44 +0000105/*
106 * Continue booting an OS image; caller already has:
107 * - copied image header to global variable `header'
108 * - checked header magic number, checksums (both header & image),
109 * - verified image architecture (PPC) and type (KERNEL or MULTI),
110 * - loaded (first part of) image to header load address,
111 * - disabled interrupts.
112 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000113typedef int boot_os_fn(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100114 bootm_headers_t *images); /* pointers to os/initrd/fdt */
wdenk47d1a6e2002-11-03 00:01:44 +0000115
Kumar Galab1d0db12008-10-21 17:25:47 -0500116#ifdef CONFIG_BOOTM_LINUX
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100117extern boot_os_fn do_bootm_linux;
Kumar Galab1d0db12008-10-21 17:25:47 -0500118#endif
119#ifdef CONFIG_BOOTM_NETBSD
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100120static boot_os_fn do_bootm_netbsd;
Kumar Galab1d0db12008-10-21 17:25:47 -0500121#endif
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100122#if defined(CONFIG_LYNXKDI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100123static boot_os_fn do_bootm_lynxkdi;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000124extern void lynxkdi_boot(image_header_t *);
wdenk8bde7f72003-06-27 21:31:46 +0000125#endif
Kumar Galab1d0db12008-10-21 17:25:47 -0500126#ifdef CONFIG_BOOTM_RTEMS
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100127static boot_os_fn do_bootm_rtems;
Kumar Galab1d0db12008-10-21 17:25:47 -0500128#endif
Torkel Lundgren3df61952010-09-28 11:05:36 +0200129#if defined(CONFIG_BOOTM_OSE)
130static boot_os_fn do_bootm_ose;
131#endif
Steven Stallion04d41402013-03-20 06:31:35 +0000132#if defined(CONFIG_BOOTM_PLAN9)
133static boot_os_fn do_bootm_plan9;
134#endif
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500135#if defined(CONFIG_CMD_ELF)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100136static boot_os_fn do_bootm_vxworks;
137static boot_os_fn do_bootm_qnxelf;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000138int do_bootvx(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
139int do_bootelf(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
Jon Loeliger90253172007-07-10 11:02:44 -0500140#endif
Peter Tyserf5ed9e32008-09-08 14:56:49 -0500141#if defined(CONFIG_INTEGRITY)
142static boot_os_fn do_bootm_integrity;
143#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000144
Mike Frysinger00085552009-11-03 11:36:26 -0500145static boot_os_fn *boot_os[] = {
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
Kumar Galabe083152008-10-21 17:25:44 -0500164#if defined(CONFIG_CMD_ELF)
165 [IH_OS_VXWORKS] = do_bootm_vxworks,
166 [IH_OS_QNX] = do_bootm_qnxelf,
167#endif
168#ifdef CONFIG_INTEGRITY
169 [IH_OS_INTEGRITY] = do_bootm_integrity,
170#endif
171};
172
Simon Schwarzdee17762011-09-02 00:50:31 +0000173bootm_headers_t images; /* pointers to os/initrd/fdt images */
Stefan Roese15940c92006-03-13 11:16:36 +0100174
Kumar Gala3dfad402009-08-27 08:23:55 -0500175/* Allow for arch specific config before we boot */
Kim Phillips088f1b12012-10-29 13:34:31 +0000176static void __arch_preboot_os(void)
Kumar Gala3dfad402009-08-27 08:23:55 -0500177{
178 /* please define platform specific arch_preboot_os() */
179}
180void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
181
Mike Frysinger476af292011-10-03 14:50:33 +0000182#define IH_INITRD_ARCH IH_ARCH_DEFAULT
wdenk47d1a6e2002-11-03 00:01:44 +0000183
Mike Frysingera16028d2009-11-03 11:35:59 -0500184#ifdef CONFIG_LMB
Marek Vasut44f074c2012-03-14 21:52:45 +0000185static void boot_start_lmb(bootm_headers_t *images)
186{
Becky Bruce391fd932008-06-09 20:37:18 -0500187 ulong mem_start;
188 phys_size_t mem_size;
wdenk47d1a6e2002-11-03 00:01:44 +0000189
Marek Vasut44f074c2012-03-14 21:52:45 +0000190 lmb_init(&images->lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000191
Kumar Galad3f2fa02008-02-27 21:51:50 -0600192 mem_start = getenv_bootm_low();
193 mem_size = getenv_bootm_size();
wdenk47d1a6e2002-11-03 00:01:44 +0000194
Marek Vasut44f074c2012-03-14 21:52:45 +0000195 lmb_add(&images->lmb, (phys_addr_t)mem_start, mem_size);
wdenk47d1a6e2002-11-03 00:01:44 +0000196
Marek Vasut44f074c2012-03-14 21:52:45 +0000197 arch_lmb_reserve(&images->lmb);
198 board_lmb_reserve(&images->lmb);
Mike Frysingera16028d2009-11-03 11:35:59 -0500199}
Marek Vasut44f074c2012-03-14 21:52:45 +0000200#else
Marek Vasut35cf5fe2012-04-01 03:59:46 +0000201#define lmb_reserve(lmb, base, size)
Marek Vasut44f074c2012-03-14 21:52:45 +0000202static inline void boot_start_lmb(bootm_headers_t *images) { }
203#endif
Mike Frysingera16028d2009-11-03 11:35:59 -0500204
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200205static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Mike Frysingera16028d2009-11-03 11:35:59 -0500206{
Simon Glass35e7b0f2013-05-07 06:12:03 +0000207 const void *os_hdr;
208 int ret;
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");
216
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100217 /* get kernel image header, start address and length */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000218 os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
Kumar Gala396f6352008-08-15 08:24:41 -0500219 &images, &images.os.image_start, &images.os.image_len);
220 if (images.os.image_len == 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000221 puts("ERROR: can't get kernel image!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000222 return 1;
223 }
wdenk47d1a6e2002-11-03 00:01:44 +0000224
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100225 /* get image parameters */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000226 switch (genimg_get_format(os_hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100227 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000228 images.os.type = image_get_type(os_hdr);
229 images.os.comp = image_get_comp(os_hdr);
230 images.os.os = image_get_os(os_hdr);
Wolfgang Denkbccae902005-10-06 01:50:50 +0200231
Stephen Warren712fbcf2011-10-18 11:11:49 +0000232 images.os.end = image_get_image_end(os_hdr);
233 images.os.load = image_get_load(os_hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100234 break;
235#if defined(CONFIG_FIT)
236 case IMAGE_FORMAT_FIT:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000237 if (fit_image_get_type(images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500238 images.fit_noffset_os, &images.os.type)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000239 puts("Can't get image type!\n");
Simon Glass770605e2012-02-13 13:51:18 +0000240 bootstage_error(BOOTSTAGE_ID_FIT_TYPE);
wdenk47d1a6e2002-11-03 00:01:44 +0000241 return 1;
242 }
wdenk47d1a6e2002-11-03 00:01:44 +0000243
Stephen Warren712fbcf2011-10-18 11:11:49 +0000244 if (fit_image_get_comp(images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500245 images.fit_noffset_os, &images.os.comp)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000246 puts("Can't get image compression!\n");
Simon Glass770605e2012-02-13 13:51:18 +0000247 bootstage_error(BOOTSTAGE_ID_FIT_COMPRESSION);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100248 return 1;
249 }
wdenk47d1a6e2002-11-03 00:01:44 +0000250
Stephen Warren712fbcf2011-10-18 11:11:49 +0000251 if (fit_image_get_os(images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500252 images.fit_noffset_os, &images.os.os)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000253 puts("Can't get image OS!\n");
Simon Glass770605e2012-02-13 13:51:18 +0000254 bootstage_error(BOOTSTAGE_ID_FIT_OS);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100255 return 1;
256 }
wdenk47d1a6e2002-11-03 00:01:44 +0000257
Stephen Warren712fbcf2011-10-18 11:11:49 +0000258 images.os.end = fit_get_end(images.fit_hdr_os);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100259
Stephen Warren712fbcf2011-10-18 11:11:49 +0000260 if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500261 &images.os.load)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000262 puts("Can't get image load address!\n");
Simon Glass770605e2012-02-13 13:51:18 +0000263 bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100264 return 1;
wdenkb13fb012003-10-30 21:49:38 +0000265 }
266 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100267#endif
268 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000269 puts("ERROR: unknown image format type!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000270 return 1;
271 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100272
Kumar Galac160a952008-08-15 08:24:36 -0500273 /* find kernel entry point */
274 if (images.legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000275 images.ep = image_get_ep(&images.legacy_hdr_os_copy);
Kumar Galac160a952008-08-15 08:24:36 -0500276#if defined(CONFIG_FIT)
277 } else if (images.fit_uname_os) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000278 ret = fit_image_get_entry(images.fit_hdr_os,
Simon Glassc19d13b2013-05-08 08:06:02 +0000279 images.fit_noffset_os, &images.ep);
Kumar Galac160a952008-08-15 08:24:36 -0500280 if (ret) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000281 puts("Can't get entry point property!\n");
Kumar Galac160a952008-08-15 08:24:36 -0500282 return 1;
283 }
284#endif
285 } else {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000286 puts("Could not find kernel entry point!\n");
Kumar Galac160a952008-08-15 08:24:36 -0500287 return 1;
288 }
289
Stephen Warrenb9b50e82011-11-10 13:17:53 -0700290 if (images.os.type == IH_TYPE_KERNEL_NOLOAD) {
291 images.os.load = images.os.image_start;
292 images.ep += images.os.load;
293 }
294
Heiko Schocher24de2f42010-03-29 13:15:48 +0200295 if (((images.os.type == IH_TYPE_KERNEL) ||
Stephen Warrenb9b50e82011-11-10 13:17:53 -0700296 (images.os.type == IH_TYPE_KERNEL_NOLOAD) ||
Heiko Schocher24de2f42010-03-29 13:15:48 +0200297 (images.os.type == IH_TYPE_MULTI)) &&
Detlev Zundel8b828a82009-12-22 12:43:01 +0100298 (images.os.os == IH_OS_LINUX)) {
Kumar Galac4f94192008-08-15 08:24:37 -0500299 /* find ramdisk */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000300 ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH,
Kumar Galac4f94192008-08-15 08:24:37 -0500301 &images.rd_start, &images.rd_end);
302 if (ret) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000303 puts("Ramdisk image is corrupt or invalid\n");
Kumar Galac4f94192008-08-15 08:24:37 -0500304 return 1;
305 }
Kumar Gala06a09912008-08-15 08:24:38 -0500306
307#if defined(CONFIG_OF_LIBFDT)
308 /* find flattened device tree */
Simon Glass53f375f2013-05-16 13:53:23 +0000309 ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, &images,
Stephen Warren712fbcf2011-10-18 11:11:49 +0000310 &images.ft_addr, &images.ft_len);
Kumar Gala06a09912008-08-15 08:24:38 -0500311 if (ret) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000312 puts("Could not find a valid device tree\n");
Kumar Gala06a09912008-08-15 08:24:38 -0500313 return 1;
314 }
Kumar Gala54f9c862008-08-15 08:24:39 -0500315
316 set_working_fdt_addr(images.ft_addr);
Kumar Gala06a09912008-08-15 08:24:38 -0500317#endif
Kumar Galac4f94192008-08-15 08:24:37 -0500318 }
319
Kumar Gala396f6352008-08-15 08:24:41 -0500320 images.os.start = (ulong)os_hdr;
Kumar Gala49c3a862008-10-21 17:25:45 -0500321 images.state = BOOTM_STATE_START;
Kumar Gala396f6352008-08-15 08:24:41 -0500322
323 return 0;
324}
325
326#define BOOTM_ERR_RESET -1
327#define BOOTM_ERR_OVERLAP -2
328#define BOOTM_ERR_UNIMPLEMENTED -3
329static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
330{
331 uint8_t comp = os.comp;
332 ulong load = os.load;
333 ulong blob_start = os.start;
334 ulong blob_end = os.end;
335 ulong image_start = os.image_start;
336 ulong image_len = os.image_len;
Anatolij Gustschin5bf27662011-11-19 13:12:18 +0000337 __maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN;
Stephen Warrend5108592011-11-10 13:17:54 -0700338 int no_overlap = 0;
Simon Glassaed161e2013-05-16 13:53:24 +0000339 void *load_buf, *image_buf;
Matthias Weisser60fdc5f2010-08-05 13:17:30 +0200340#if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
341 int ret;
342#endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
Kumar Gala396f6352008-08-15 08:24:41 -0500343
Stephen Warren712fbcf2011-10-18 11:11:49 +0000344 const char *type_name = genimg_get_type_name(os.type);
Kumar Gala396f6352008-08-15 08:24:41 -0500345
Simon Glassaed161e2013-05-16 13:53:24 +0000346 load_buf = map_sysmem(load, image_len);
347 image_buf = map_sysmem(image_start, image_len);
Kumar Gala396f6352008-08-15 08:24:41 -0500348 switch (comp) {
349 case IH_COMP_NONE:
Lei Wen02cf3452011-01-10 18:21:15 +0800350 if (load == blob_start || load == image_start) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000351 printf(" XIP %s ... ", type_name);
Stephen Warrend5108592011-11-10 13:17:54 -0700352 no_overlap = 1;
Kumar Gala396f6352008-08-15 08:24:41 -0500353 } else {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000354 printf(" Loading %s ... ", type_name);
Simon Glassaed161e2013-05-16 13:53:24 +0000355 memmove_wd(load_buf, image_buf, image_len, CHUNKSZ);
Kumar Gala396f6352008-08-15 08:24:41 -0500356 }
357 *load_end = load + image_len;
358 puts("OK\n");
359 break;
Mike Frysinger44431ca2010-01-21 19:30:36 -0500360#ifdef CONFIG_GZIP
Kumar Gala396f6352008-08-15 08:24:41 -0500361 case IH_COMP_GZIP:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000362 printf(" Uncompressing %s ... ", type_name);
Simon Glassaed161e2013-05-16 13:53:24 +0000363 if (gunzip(load_buf, unc_len, image_buf, &image_len) != 0) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000364 puts("GUNZIP: uncompress, out-of-mem or overwrite "
365 "error - must RESET board to recover\n");
Kumar Gala396f6352008-08-15 08:24:41 -0500366 if (boot_progress)
Simon Glass770605e2012-02-13 13:51:18 +0000367 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
Kumar Gala396f6352008-08-15 08:24:41 -0500368 return BOOTM_ERR_RESET;
369 }
370
371 *load_end = load + image_len;
372 break;
Mike Frysinger44431ca2010-01-21 19:30:36 -0500373#endif /* CONFIG_GZIP */
Kumar Gala396f6352008-08-15 08:24:41 -0500374#ifdef CONFIG_BZIP2
375 case IH_COMP_BZIP2:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000376 printf(" Uncompressing %s ... ", type_name);
Kumar Gala396f6352008-08-15 08:24:41 -0500377 /*
378 * If we've got less than 4 MB of malloc() space,
379 * use slower decompression algorithm which requires
380 * at most 2300 KB of memory.
381 */
Simon Glassaed161e2013-05-16 13:53:24 +0000382 int i = BZ2_bzBuffToBuffDecompress(load_buf, &unc_len,
383 image_buf, image_len,
384 CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
Kumar Gala396f6352008-08-15 08:24:41 -0500385 if (i != BZ_OK) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000386 printf("BUNZIP2: uncompress or overwrite error %d "
Kumar Gala396f6352008-08-15 08:24:41 -0500387 "- must RESET board to recover\n", i);
388 if (boot_progress)
Simon Glass770605e2012-02-13 13:51:18 +0000389 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
Kumar Gala396f6352008-08-15 08:24:41 -0500390 return BOOTM_ERR_RESET;
391 }
392
393 *load_end = load + unc_len;
394 break;
395#endif /* CONFIG_BZIP2 */
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200396#ifdef CONFIG_LZMA
Mike Frysinger78e1e842010-07-25 15:54:17 -0400397 case IH_COMP_LZMA: {
398 SizeT lzma_len = unc_len;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000399 printf(" Uncompressing %s ... ", type_name);
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200400
Simon Glassaed161e2013-05-16 13:53:24 +0000401 ret = lzmaBuffToBuffDecompress(load_buf, &lzma_len,
402 image_buf, image_len);
Mike Frysinger78e1e842010-07-25 15:54:17 -0400403 unc_len = lzma_len;
Luigi 'Comio' Mantellinicaf72ff2009-07-21 10:45:49 +0200404 if (ret != SZ_OK) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000405 printf("LZMA: uncompress or overwrite error %d "
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200406 "- must RESET board to recover\n", ret);
Simon Glass770605e2012-02-13 13:51:18 +0000407 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200408 return BOOTM_ERR_RESET;
409 }
410 *load_end = load + unc_len;
411 break;
Mike Frysinger78e1e842010-07-25 15:54:17 -0400412 }
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200413#endif /* CONFIG_LZMA */
Peter Korsgaard20dde482009-11-19 11:37:51 +0100414#ifdef CONFIG_LZO
415 case IH_COMP_LZO:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000416 printf(" Uncompressing %s ... ", type_name);
Peter Korsgaard20dde482009-11-19 11:37:51 +0100417
Simon Glassaed161e2013-05-16 13:53:24 +0000418 ret = lzop_decompress(image_buf, image_len, load_buf,
419 &unc_len);
Peter Korsgaard20dde482009-11-19 11:37:51 +0100420 if (ret != LZO_E_OK) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000421 printf("LZO: uncompress or overwrite error %d "
Peter Korsgaard20dde482009-11-19 11:37:51 +0100422 "- must RESET board to recover\n", ret);
423 if (boot_progress)
Simon Glass770605e2012-02-13 13:51:18 +0000424 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
Peter Korsgaard20dde482009-11-19 11:37:51 +0100425 return BOOTM_ERR_RESET;
426 }
427
428 *load_end = load + unc_len;
429 break;
430#endif /* CONFIG_LZO */
Kumar Gala396f6352008-08-15 08:24:41 -0500431 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000432 printf("Unimplemented compression type %d\n", comp);
Kumar Gala396f6352008-08-15 08:24:41 -0500433 return BOOTM_ERR_UNIMPLEMENTED;
434 }
Diana CRACIUN99ffccb2011-08-31 02:45:23 +0000435
436 flush_cache(load, (*load_end - load) * sizeof(ulong));
437
Stephen Warren712fbcf2011-10-18 11:11:49 +0000438 puts("OK\n");
439 debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
Simon Glass770605e2012-02-13 13:51:18 +0000440 bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED);
Kumar Gala396f6352008-08-15 08:24:41 -0500441
Stephen Warrend5108592011-11-10 13:17:54 -0700442 if (!no_overlap && (load < blob_end) && (*load_end > blob_start)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000443 debug("images.os.start = 0x%lX, images.os.end = 0x%lx\n",
444 blob_start, blob_end);
445 debug("images.os.load = 0x%lx, load_end = 0x%lx\n", load,
446 *load_end);
Kumar Gala396f6352008-08-15 08:24:41 -0500447
448 return BOOTM_ERR_OVERLAP;
449 }
450
451 return 0;
452}
453
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200454static int bootm_start_standalone(ulong iflag, int argc, char * const argv[])
Detlev Zundelf97ec302009-07-13 16:01:19 +0200455{
456 char *s;
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200457 int (*appl)(int, char * const []);
Detlev Zundelf97ec302009-07-13 16:01:19 +0200458
459 /* Don't start if "autostart" is set to "no" */
460 if (((s = getenv("autostart")) != NULL) && (strcmp(s, "no") == 0)) {
Simon Glass41ef3722013-02-24 17:33:22 +0000461 setenv_hex("filesize", images.os.image_len);
Detlev Zundelf97ec302009-07-13 16:01:19 +0200462 return 0;
463 }
Simon Glass6d6f1232011-10-07 13:53:40 +0000464 appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep);
Detlev Zundelf97ec302009-07-13 16:01:19 +0200465 (*appl)(argc-1, &argv[1]);
Detlev Zundelf97ec302009-07-13 16:01:19 +0200466 return 0;
467}
468
Kumar Gala49c3a862008-10-21 17:25:45 -0500469/* we overload the cmd field with our state machine info instead of a
470 * function pointer */
Frans Meulenbroeksf74d9bd2010-02-25 10:12:13 +0100471static cmd_tbl_t cmd_bootm_sub[] = {
Kumar Gala49c3a862008-10-21 17:25:45 -0500472 U_BOOT_CMD_MKENT(start, 0, 1, (void *)BOOTM_STATE_START, "", ""),
473 U_BOOT_CMD_MKENT(loados, 0, 1, (void *)BOOTM_STATE_LOADOS, "", ""),
John Rigbyfca43cc2010-10-13 13:57:35 -0600474#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
Kumar Gala49c3a862008-10-21 17:25:45 -0500475 U_BOOT_CMD_MKENT(ramdisk, 0, 1, (void *)BOOTM_STATE_RAMDISK, "", ""),
476#endif
477#ifdef CONFIG_OF_LIBFDT
478 U_BOOT_CMD_MKENT(fdt, 0, 1, (void *)BOOTM_STATE_FDT, "", ""),
479#endif
Kumar Gala49c3a862008-10-21 17:25:45 -0500480 U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
Peter Tyser224c90d2009-11-18 19:08:59 -0600481 U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
Kumar Gala49c3a862008-10-21 17:25:45 -0500482 U_BOOT_CMD_MKENT(prep, 0, 1, (void *)BOOTM_STATE_OS_PREP, "", ""),
483 U_BOOT_CMD_MKENT(go, 0, 1, (void *)BOOTM_STATE_OS_GO, "", ""),
484};
485
Kim Phillips088f1b12012-10-29 13:34:31 +0000486static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
Stephen Warren712fbcf2011-10-18 11:11:49 +0000487 char * const argv[])
Kumar Gala49c3a862008-10-21 17:25:45 -0500488{
489 int ret = 0;
Simon Glass6d6f1232011-10-07 13:53:40 +0000490 long state;
Kumar Gala49c3a862008-10-21 17:25:45 -0500491 cmd_tbl_t *c;
492 boot_os_fn *boot_fn;
493
494 c = find_cmd_tbl(argv[1], &cmd_bootm_sub[0], ARRAY_SIZE(cmd_bootm_sub));
495
496 if (c) {
Simon Glass6d6f1232011-10-07 13:53:40 +0000497 state = (long)c->cmd;
Kumar Gala49c3a862008-10-21 17:25:45 -0500498
499 /* treat start special since it resets the state machine */
500 if (state == BOOTM_STATE_START) {
501 argc--;
502 argv++;
503 return bootm_start(cmdtp, flag, argc, argv);
504 }
Wolfgang Denk47e26b12010-07-17 01:06:04 +0200505 } else {
506 /* Unrecognized command */
Simon Glass4c12eeb2011-12-10 08:44:01 +0000507 return CMD_RET_USAGE;
Kumar Gala49c3a862008-10-21 17:25:45 -0500508 }
509
Gabor Juhos0f307342013-01-06 23:04:25 +0000510 if (images.state < BOOTM_STATE_START ||
511 images.state >= state) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000512 printf("Trying to execute a command out of order\n");
Simon Glass4c12eeb2011-12-10 08:44:01 +0000513 return CMD_RET_USAGE;
Kumar Gala49c3a862008-10-21 17:25:45 -0500514 }
515
516 images.state |= state;
517 boot_fn = boot_os[images.os.os];
518
519 switch (state) {
520 ulong load_end;
521 case BOOTM_STATE_START:
522 /* should never occur */
523 break;
524 case BOOTM_STATE_LOADOS:
525 ret = bootm_load_os(images.os, &load_end, 0);
526 if (ret)
527 return ret;
528
529 lmb_reserve(&images.lmb, images.os.load,
530 (load_end - images.os.load));
531 break;
John Rigbyfca43cc2010-10-13 13:57:35 -0600532#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
Kumar Gala49c3a862008-10-21 17:25:45 -0500533 case BOOTM_STATE_RAMDISK:
534 {
535 ulong rd_len = images.rd_end - images.rd_start;
Kumar Gala49c3a862008-10-21 17:25:45 -0500536
537 ret = boot_ramdisk_high(&images.lmb, images.rd_start,
538 rd_len, &images.initrd_start, &images.initrd_end);
539 if (ret)
540 return ret;
541
Simon Glass41ef3722013-02-24 17:33:22 +0000542 setenv_hex("initrd_start", images.initrd_start);
543 setenv_hex("initrd_end", images.initrd_end);
Kumar Gala49c3a862008-10-21 17:25:45 -0500544 }
545 break;
546#endif
Simon Glass75b3afc2012-12-05 14:46:31 +0000547#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_LMB)
Kumar Gala49c3a862008-10-21 17:25:45 -0500548 case BOOTM_STATE_FDT:
549 {
Grant Likely55b0a392011-03-28 09:59:01 +0000550 boot_fdt_add_mem_rsv_regions(&images.lmb,
551 images.ft_addr);
Grant Likely590d3ca2011-03-28 09:58:34 +0000552 ret = boot_relocate_fdt(&images.lmb,
Kumar Gala49c3a862008-10-21 17:25:45 -0500553 &images.ft_addr, &images.ft_len);
554 break;
555 }
556#endif
557 case BOOTM_STATE_OS_CMDLINE:
558 ret = boot_fn(BOOTM_STATE_OS_CMDLINE, argc, argv, &images);
559 if (ret)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000560 printf("cmdline subcommand not supported\n");
Kumar Gala49c3a862008-10-21 17:25:45 -0500561 break;
562 case BOOTM_STATE_OS_BD_T:
563 ret = boot_fn(BOOTM_STATE_OS_BD_T, argc, argv, &images);
564 if (ret)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000565 printf("bdt subcommand not supported\n");
Kumar Gala49c3a862008-10-21 17:25:45 -0500566 break;
567 case BOOTM_STATE_OS_PREP:
568 ret = boot_fn(BOOTM_STATE_OS_PREP, argc, argv, &images);
569 if (ret)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000570 printf("prep subcommand not supported\n");
Kumar Gala49c3a862008-10-21 17:25:45 -0500571 break;
572 case BOOTM_STATE_OS_GO:
573 disable_interrupts();
Joe Hershbergerf8be7d62012-08-03 10:59:08 +0000574#ifdef CONFIG_NETCONSOLE
575 /*
576 * Stop the ethernet stack if NetConsole could have
577 * left it up
578 */
579 eth_halt();
580#endif
Kumar Gala3dfad402009-08-27 08:23:55 -0500581 arch_preboot_os();
Kumar Gala49c3a862008-10-21 17:25:45 -0500582 boot_fn(BOOTM_STATE_OS_GO, argc, argv, &images);
583 break;
584 }
585
586 return ret;
587}
588
Kumar Gala396f6352008-08-15 08:24:41 -0500589/*******************************************************************/
590/* bootm - boot application image from image in memory */
591/*******************************************************************/
Kumar Galabe083152008-10-21 17:25:44 -0500592
Stephen Warren712fbcf2011-10-18 11:11:49 +0000593int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Kumar Gala396f6352008-08-15 08:24:41 -0500594{
Kumar Gala396f6352008-08-15 08:24:41 -0500595 ulong iflag;
596 ulong load_end = 0;
597 int ret;
Kumar Galabe083152008-10-21 17:25:44 -0500598 boot_os_fn *boot_fn;
Wolfgang Denk2e5167c2010-10-28 20:00:11 +0200599#ifdef CONFIG_NEEDS_MANUAL_RELOC
Peter Tyser521af042009-09-21 11:20:36 -0500600 static int relocated = 0;
Kumar Galabe083152008-10-21 17:25:44 -0500601
Kumar Galabe083152008-10-21 17:25:44 -0500602 if (!relocated) {
603 int i;
Daniel Schwierzeck58bd77d2013-01-07 06:54:52 +0000604
605 /* relocate boot function table */
Kumar Galabe083152008-10-21 17:25:44 -0500606 for (i = 0; i < ARRAY_SIZE(boot_os); i++)
Detlev Zundelca95c9d2009-07-13 16:01:18 +0200607 if (boot_os[i] != NULL)
608 boot_os[i] += gd->reloc_off;
Daniel Schwierzeck58bd77d2013-01-07 06:54:52 +0000609
610 /* relocate names of sub-command table */
611 for (i = 0; i < ARRAY_SIZE(cmd_bootm_sub); i++)
612 cmd_bootm_sub[i].name += gd->reloc_off;
613
Kumar Galabe083152008-10-21 17:25:44 -0500614 relocated = 1;
615 }
Peter Tyser521af042009-09-21 11:20:36 -0500616#endif
Kumar Gala396f6352008-08-15 08:24:41 -0500617
Kumar Gala49c3a862008-10-21 17:25:45 -0500618 /* determine if we have a sub command */
619 if (argc > 1) {
620 char *endp;
621
622 simple_strtoul(argv[1], &endp, 16);
623 /* endp pointing to NULL means that argv[1] was just a
624 * valid number, pass it along to the normal bootm processing
625 *
626 * If endp is ':' or '#' assume a FIT identifier so pass
627 * along for normal processing.
628 *
629 * Right now we assume the first arg should never be '-'
630 */
631 if ((*endp != 0) && (*endp != ':') && (*endp != '#'))
632 return do_bootm_subcommand(cmdtp, flag, argc, argv);
633 }
634
Anatolij Gustschin8e024942008-08-29 21:04:45 +0200635 if (bootm_start(cmdtp, flag, argc, argv))
636 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000637
638 /*
639 * We have reached the point of no return: we are going to
640 * overwrite all exception vector code, so we cannot easily
641 * recover from any failures any more...
642 */
wdenk47d1a6e2002-11-03 00:01:44 +0000643 iflag = disable_interrupts();
644
Joe Hershbergerf8be7d62012-08-03 10:59:08 +0000645#ifdef CONFIG_NETCONSOLE
646 /* Stop the ethernet stack if NetConsole could have left it up */
647 eth_halt();
648#endif
649
Stefan Roeseebb86c42008-07-30 09:59:51 +0200650#if defined(CONFIG_CMD_USB)
Wolfgang Denk699f0512008-07-15 22:22:44 +0200651 /*
652 * turn off USB to prevent the host controller from writing to the
653 * SDRAM while Linux is booting. This could happen (at least for OHCI
654 * controller), because the HCCA (Host Controller Communication Area)
655 * lies within the SDRAM and the host controller writes continously to
656 * this area (as busmaster!). The HccaFrameNumber is for example
657 * updated every 1 ms within the HCCA structure in SDRAM! For more
658 * details see the OpenHCI specification.
659 */
Markus Klotzbücher3d71c812008-07-10 14:47:09 +0200660 usb_stop();
661#endif
662
Kumar Gala396f6352008-08-15 08:24:41 -0500663 ret = bootm_load_os(images.os, &load_end, 1);
wdenk47d1a6e2002-11-03 00:01:44 +0000664
Kumar Gala396f6352008-08-15 08:24:41 -0500665 if (ret < 0) {
666 if (ret == BOOTM_ERR_RESET)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000667 do_reset(cmdtp, flag, argc, argv);
Kumar Gala396f6352008-08-15 08:24:41 -0500668 if (ret == BOOTM_ERR_OVERLAP) {
669 if (images.legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000670 image_header_t *hdr;
671 hdr = &images.legacy_hdr_os_copy;
672 if (image_get_type(hdr) == IH_TYPE_MULTI)
673 puts("WARNING: legacy format multi "
674 "component image "
675 "overwritten\n");
Kumar Gala396f6352008-08-15 08:24:41 -0500676 } else {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000677 puts("ERROR: new format image overwritten - "
Kumar Gala396f6352008-08-15 08:24:41 -0500678 "must RESET the board to recover\n");
Simon Glass770605e2012-02-13 13:51:18 +0000679 bootstage_error(BOOTSTAGE_ID_OVERWRITTEN);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000680 do_reset(cmdtp, flag, argc, argv);
Kumar Gala396f6352008-08-15 08:24:41 -0500681 }
wdenk47d1a6e2002-11-03 00:01:44 +0000682 }
Kumar Gala396f6352008-08-15 08:24:41 -0500683 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
684 if (iflag)
685 enable_interrupts();
Simon Glass770605e2012-02-13 13:51:18 +0000686 bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL);
Kumar Gala396f6352008-08-15 08:24:41 -0500687 return 1;
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200688 }
wdenk47d1a6e2002-11-03 00:01:44 +0000689 }
Marian Balakowicz75824382008-01-31 13:20:06 +0100690
Kumar Gala396f6352008-08-15 08:24:41 -0500691 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
692
Detlev Zundelf97ec302009-07-13 16:01:19 +0200693 if (images.os.type == IH_TYPE_STANDALONE) {
694 if (iflag)
695 enable_interrupts();
696 /* This may return when 'autostart' is 'no' */
697 bootm_start_standalone(iflag, argc, argv);
698 return 0;
699 }
700
Simon Glass770605e2012-02-13 13:51:18 +0000701 bootstage_mark(BOOTSTAGE_ID_CHECK_BOOT_OS);
wdenk47d1a6e2002-11-03 00:01:44 +0000702
Joe Hershbergerbe2e5a02013-02-27 10:20:59 +0000703#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
Kumar Galabe083152008-10-21 17:25:44 -0500704 if (images.os.os == IH_OS_LINUX)
705 fixup_silent_linux();
wdenk1f4bb372003-07-27 00:21:01 +0000706#endif
707
Kumar Galabe083152008-10-21 17:25:44 -0500708 boot_fn = boot_os[images.os.os];
Detlev Zundelca95c9d2009-07-13 16:01:18 +0200709
710 if (boot_fn == NULL) {
711 if (iflag)
712 enable_interrupts();
Stephen Warren712fbcf2011-10-18 11:11:49 +0000713 printf("ERROR: booting os '%s' (%d) is not supported\n",
Detlev Zundelca95c9d2009-07-13 16:01:18 +0200714 genimg_get_os_name(images.os.os), images.os.os);
Simon Glass770605e2012-02-13 13:51:18 +0000715 bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS);
Detlev Zundelca95c9d2009-07-13 16:01:18 +0200716 return 1;
717 }
718
Kumar Gala3dfad402009-08-27 08:23:55 -0500719 arch_preboot_os();
720
Kumar Galabe083152008-10-21 17:25:44 -0500721 boot_fn(0, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000722
Simon Glass770605e2012-02-13 13:51:18 +0000723 bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED);
wdenk47d1a6e2002-11-03 00:01:44 +0000724#ifdef DEBUG
Stephen Warren712fbcf2011-10-18 11:11:49 +0000725 puts("\n## Control returned to monitor - resetting...\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000726#endif
Stephen Warren712fbcf2011-10-18 11:11:49 +0000727 do_reset(cmdtp, flag, argc, argv);
Marian Balakowicza44a2692008-03-12 10:14:57 +0100728
wdenk47d1a6e2002-11-03 00:01:44 +0000729 return 1;
730}
731
Mike Frysinger67d668b2011-06-05 13:43:02 +0000732int bootm_maybe_autostart(cmd_tbl_t *cmdtp, const char *cmd)
733{
734 const char *ep = getenv("autostart");
735
736 if (ep && !strcmp(ep, "yes")) {
737 char *local_args[2];
738 local_args[0] = (char *)cmd;
739 local_args[1] = NULL;
740 printf("Automatic boot of image at addr 0x%08lX ...\n", load_addr);
741 return do_bootm(cmdtp, 0, 1, local_args);
742 }
743
744 return 0;
745}
746
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100747/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100748 * image_get_kernel - verify legacy format kernel image
749 * @img_addr: in RAM address of the legacy format image to be verified
750 * @verify: data CRC verification flag
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100751 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100752 * image_get_kernel() verifies legacy image integrity and returns pointer to
753 * legacy image header if image verification was completed successfully.
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100754 *
755 * returns:
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100756 * pointer to a legacy image header if valid image was found
757 * otherwise return NULL
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100758 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000759static image_header_t *image_get_kernel(ulong img_addr, int verify)
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100760{
761 image_header_t *hdr = (image_header_t *)img_addr;
762
763 if (!image_check_magic(hdr)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000764 puts("Bad Magic Number\n");
Simon Glass770605e2012-02-13 13:51:18 +0000765 bootstage_error(BOOTSTAGE_ID_CHECK_MAGIC);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100766 return NULL;
767 }
Simon Glass770605e2012-02-13 13:51:18 +0000768 bootstage_mark(BOOTSTAGE_ID_CHECK_HEADER);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100769
Stephen Warren712fbcf2011-10-18 11:11:49 +0000770 if (!image_check_hcrc(hdr)) {
771 puts("Bad Header Checksum\n");
Simon Glass770605e2012-02-13 13:51:18 +0000772 bootstage_error(BOOTSTAGE_ID_CHECK_HEADER);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100773 return NULL;
774 }
775
Simon Glass770605e2012-02-13 13:51:18 +0000776 bootstage_mark(BOOTSTAGE_ID_CHECK_CHECKSUM);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000777 image_print_contents(hdr);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100778
779 if (verify) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000780 puts(" Verifying Checksum ... ");
781 if (!image_check_dcrc(hdr)) {
782 printf("Bad Data CRC\n");
Simon Glass770605e2012-02-13 13:51:18 +0000783 bootstage_error(BOOTSTAGE_ID_CHECK_CHECKSUM);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100784 return NULL;
785 }
Stephen Warren712fbcf2011-10-18 11:11:49 +0000786 puts("OK\n");
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100787 }
Simon Glass770605e2012-02-13 13:51:18 +0000788 bootstage_mark(BOOTSTAGE_ID_CHECK_ARCH);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100789
Stephen Warren712fbcf2011-10-18 11:11:49 +0000790 if (!image_check_target_arch(hdr)) {
791 printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr));
Simon Glass770605e2012-02-13 13:51:18 +0000792 bootstage_error(BOOTSTAGE_ID_CHECK_ARCH);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100793 return NULL;
794 }
795 return hdr;
796}
797
798/**
Marian Balakowicz6986a382008-03-12 10:01:05 +0100799 * fit_check_kernel - verify FIT format kernel subimage
800 * @fit_hdr: pointer to the FIT image header
801 * os_noffset: kernel subimage node offset within FIT image
802 * @verify: data CRC verification flag
803 *
804 * fit_check_kernel() verifies integrity of the kernel subimage and from
805 * specified FIT image.
806 *
807 * returns:
808 * 1, on success
809 * 0, on failure
810 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000811#if defined(CONFIG_FIT)
812static int fit_check_kernel(const void *fit, int os_noffset, int verify)
Marian Balakowicz6986a382008-03-12 10:01:05 +0100813{
Stephen Warren712fbcf2011-10-18 11:11:49 +0000814 fit_image_print(fit, os_noffset, " ");
Marian Balakowicz6986a382008-03-12 10:01:05 +0100815
816 if (verify) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000817 puts(" Verifying Hash Integrity ... ");
Simon Glassb8da8362013-05-07 06:11:57 +0000818 if (!fit_image_verify(fit, os_noffset)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000819 puts("Bad Data Hash\n");
Simon Glass770605e2012-02-13 13:51:18 +0000820 bootstage_error(BOOTSTAGE_ID_FIT_CHECK_HASH);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100821 return 0;
822 }
Stephen Warren712fbcf2011-10-18 11:11:49 +0000823 puts("OK\n");
Marian Balakowicz6986a382008-03-12 10:01:05 +0100824 }
Simon Glass770605e2012-02-13 13:51:18 +0000825 bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_ARCH);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100826
Stephen Warren712fbcf2011-10-18 11:11:49 +0000827 if (!fit_image_check_target_arch(fit, os_noffset)) {
828 puts("Unsupported Architecture\n");
Simon Glass770605e2012-02-13 13:51:18 +0000829 bootstage_error(BOOTSTAGE_ID_FIT_CHECK_ARCH);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100830 return 0;
831 }
832
Simon Glass770605e2012-02-13 13:51:18 +0000833 bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_KERNEL);
Stephen Warrenb9b50e82011-11-10 13:17:53 -0700834 if (!fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL) &&
835 !fit_image_check_type(fit, os_noffset, IH_TYPE_KERNEL_NOLOAD)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000836 puts("Not a kernel image\n");
Simon Glass770605e2012-02-13 13:51:18 +0000837 bootstage_error(BOOTSTAGE_ID_FIT_CHECK_KERNEL);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100838 return 0;
839 }
840
Simon Glass770605e2012-02-13 13:51:18 +0000841 bootstage_mark(BOOTSTAGE_ID_FIT_CHECKED);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100842 return 1;
843}
844#endif /* CONFIG_FIT */
845
846/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100847 * boot_get_kernel - find kernel image
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100848 * @os_data: pointer to a ulong variable, will hold os data start address
849 * @os_len: pointer to a ulong variable, will hold os data length
850 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100851 * boot_get_kernel() tries to find a kernel image, verifies its integrity
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100852 * and locates kernel data.
853 *
854 * returns:
855 * pointer to image header if valid image was found, plus kernel start
856 * address and length, otherwise NULL
857 */
Simon Glass35e7b0f2013-05-07 06:12:03 +0000858static const void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
Stephen Warren712fbcf2011-10-18 11:11:49 +0000859 char * const argv[], bootm_headers_t *images, ulong *os_data,
860 ulong *os_len)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100861{
862 image_header_t *hdr;
863 ulong img_addr;
Simon Glass35e7b0f2013-05-07 06:12:03 +0000864 const void *buf;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100865#if defined(CONFIG_FIT)
Simon Glass35e7b0f2013-05-07 06:12:03 +0000866 const void *fit_hdr;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100867 const char *fit_uname_config = NULL;
868 const char *fit_uname_kernel = NULL;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100869 const void *data;
870 size_t len;
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100871 int cfg_noffset;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100872 int os_noffset;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100873#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100874
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100875 /* find out kernel image address */
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100876 if (argc < 2) {
877 img_addr = load_addr;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000878 debug("* kernel: default image load address = 0x%08lx\n",
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100879 load_addr);
880#if defined(CONFIG_FIT)
Stephen Warren712fbcf2011-10-18 11:11:49 +0000881 } else if (fit_parse_conf(argv[1], load_addr, &img_addr,
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100882 &fit_uname_config)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000883 debug("* kernel: config '%s' from image at 0x%08lx\n",
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100884 fit_uname_config, img_addr);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000885 } else if (fit_parse_subimage(argv[1], load_addr, &img_addr,
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100886 &fit_uname_kernel)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +0000887 debug("* kernel: subimage '%s' from image at 0x%08lx\n",
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100888 fit_uname_kernel, img_addr);
889#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100890 } else {
891 img_addr = simple_strtoul(argv[1], NULL, 16);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000892 debug("* kernel: cmdline image address = 0x%08lx\n", img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100893 }
894
Simon Glass770605e2012-02-13 13:51:18 +0000895 bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100896
Marian Balakowiczfff888a12008-02-21 17:20:19 +0100897 /* copy from dataflash if needed */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000898 img_addr = genimg_get_image(img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100899
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100900 /* check image type, for FIT images get FIT kernel node */
Marian Balakowicz6986a382008-03-12 10:01:05 +0100901 *os_data = *os_len = 0;
Simon Glass35e7b0f2013-05-07 06:12:03 +0000902 buf = map_sysmem(img_addr, 0);
903 switch (genimg_get_format(buf)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100904 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000905 printf("## Booting kernel from Legacy Image at %08lx ...\n",
Marian Balakowicz6986a382008-03-12 10:01:05 +0100906 img_addr);
Stephen Warren712fbcf2011-10-18 11:11:49 +0000907 hdr = image_get_kernel(img_addr, images->verify);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100908 if (!hdr)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100909 return NULL;
Simon Glass770605e2012-02-13 13:51:18 +0000910 bootstage_mark(BOOTSTAGE_ID_CHECK_IMAGETYPE);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100911
Marian Balakowicz6986a382008-03-12 10:01:05 +0100912 /* get os_data and os_len */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000913 switch (image_get_type(hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100914 case IH_TYPE_KERNEL:
Stephen Warrenb9b50e82011-11-10 13:17:53 -0700915 case IH_TYPE_KERNEL_NOLOAD:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000916 *os_data = image_get_data(hdr);
917 *os_len = image_get_data_size(hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100918 break;
919 case IH_TYPE_MULTI:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000920 image_multi_getimg(hdr, 0, os_data, os_len);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100921 break;
Detlev Zundelf97ec302009-07-13 16:01:19 +0200922 case IH_TYPE_STANDALONE:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000923 *os_data = image_get_data(hdr);
924 *os_len = image_get_data_size(hdr);
Detlev Zundelf97ec302009-07-13 16:01:19 +0200925 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100926 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +0000927 printf("Wrong Image Type for %s command\n",
928 cmdtp->name);
Simon Glass770605e2012-02-13 13:51:18 +0000929 bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100930 return NULL;
931 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100932
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200933 /*
Stephen Warren712fbcf2011-10-18 11:11:49 +0000934 * copy image header to allow for image overwrites during
935 * kernel decompression.
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200936 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000937 memmove(&images->legacy_hdr_os_copy, hdr,
938 sizeof(image_header_t));
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200939
940 /* save pointer to image header */
941 images->legacy_hdr_os = hdr;
942
943 images->legacy_hdr_valid = 1;
Simon Glass770605e2012-02-13 13:51:18 +0000944 bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100945 break;
946#if defined(CONFIG_FIT)
947 case IMAGE_FORMAT_FIT:
Simon Glass35e7b0f2013-05-07 06:12:03 +0000948 fit_hdr = buf;
Stephen Warren712fbcf2011-10-18 11:11:49 +0000949 printf("## Booting kernel from FIT Image at %08lx ...\n",
Marian Balakowicz6986a382008-03-12 10:01:05 +0100950 img_addr);
951
Stephen Warren712fbcf2011-10-18 11:11:49 +0000952 if (!fit_check_format(fit_hdr)) {
953 puts("Bad FIT kernel image format!\n");
Simon Glass770605e2012-02-13 13:51:18 +0000954 bootstage_error(BOOTSTAGE_ID_FIT_FORMAT);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100955 return NULL;
956 }
Simon Glass770605e2012-02-13 13:51:18 +0000957 bootstage_mark(BOOTSTAGE_ID_FIT_FORMAT);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100958
959 if (!fit_uname_kernel) {
960 /*
961 * no kernel image node unit name, try to get config
962 * node first. If config unit node name is NULL
Stephen Warren712fbcf2011-10-18 11:11:49 +0000963 * fit_conf_get_node() will try to find default config
964 * node
Marian Balakowicz6986a382008-03-12 10:01:05 +0100965 */
Simon Glass770605e2012-02-13 13:51:18 +0000966 bootstage_mark(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
Gabe Blackd95f6ec2012-10-25 16:31:10 +0000967#ifdef CONFIG_FIT_BEST_MATCH
968 if (fit_uname_config)
969 cfg_noffset =
970 fit_conf_get_node(fit_hdr,
971 fit_uname_config);
972 else
973 cfg_noffset =
974 fit_conf_find_compat(fit_hdr,
975 gd->fdt_blob);
976#else
Stephen Warren712fbcf2011-10-18 11:11:49 +0000977 cfg_noffset = fit_conf_get_node(fit_hdr,
978 fit_uname_config);
Gabe Blackd95f6ec2012-10-25 16:31:10 +0000979#endif
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100980 if (cfg_noffset < 0) {
Simon Glass770605e2012-02-13 13:51:18 +0000981 bootstage_error(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100982 return NULL;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100983 }
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100984 /* save configuration uname provided in the first
985 * bootm argument
986 */
Stephen Warren712fbcf2011-10-18 11:11:49 +0000987 images->fit_uname_cfg = fdt_get_name(fit_hdr,
988 cfg_noffset,
989 NULL);
990 printf(" Using '%s' configuration\n",
991 images->fit_uname_cfg);
Simon Glass770605e2012-02-13 13:51:18 +0000992 bootstage_mark(BOOTSTAGE_ID_FIT_CONFIG);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100993
Stephen Warren712fbcf2011-10-18 11:11:49 +0000994 os_noffset = fit_conf_get_kernel_node(fit_hdr,
995 cfg_noffset);
996 fit_uname_kernel = fit_get_name(fit_hdr, os_noffset,
997 NULL);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100998 } else {
999 /* get kernel component image node offset */
Simon Glass770605e2012-02-13 13:51:18 +00001000 bootstage_mark(BOOTSTAGE_ID_FIT_UNIT_NAME);
Stephen Warren712fbcf2011-10-18 11:11:49 +00001001 os_noffset = fit_image_get_node(fit_hdr,
1002 fit_uname_kernel);
Marian Balakowicz6986a382008-03-12 10:01:05 +01001003 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +01001004 if (os_noffset < 0) {
Simon Glass770605e2012-02-13 13:51:18 +00001005 bootstage_error(BOOTSTAGE_ID_FIT_CONFIG);
Marian Balakowicz6986a382008-03-12 10:01:05 +01001006 return NULL;
Marian Balakowicz1372cce2008-03-12 10:33:01 +01001007 }
Marian Balakowicz6986a382008-03-12 10:01:05 +01001008
Stephen Warren712fbcf2011-10-18 11:11:49 +00001009 printf(" Trying '%s' kernel subimage\n", fit_uname_kernel);
Marian Balakowicz6986a382008-03-12 10:01:05 +01001010
Simon Glass770605e2012-02-13 13:51:18 +00001011 bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_SUBIMAGE);
Stephen Warren712fbcf2011-10-18 11:11:49 +00001012 if (!fit_check_kernel(fit_hdr, os_noffset, images->verify))
Marian Balakowicz6986a382008-03-12 10:01:05 +01001013 return NULL;
1014
1015 /* get kernel image data address and length */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001016 if (fit_image_get_data(fit_hdr, os_noffset, &data, &len)) {
1017 puts("Could not find kernel subimage data!\n");
Simon Glass770605e2012-02-13 13:51:18 +00001018 bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO_ERR);
Marian Balakowicz6986a382008-03-12 10:01:05 +01001019 return NULL;
1020 }
Simon Glass770605e2012-02-13 13:51:18 +00001021 bootstage_mark(BOOTSTAGE_ID_FIT_KERNEL_INFO);
Marian Balakowicz6986a382008-03-12 10:01:05 +01001022
1023 *os_len = len;
1024 *os_data = (ulong)data;
Simon Glass35e7b0f2013-05-07 06:12:03 +00001025 images->fit_hdr_os = (void *)fit_hdr;
Marian Balakowicz6986a382008-03-12 10:01:05 +01001026 images->fit_uname_os = fit_uname_kernel;
Marian Balakowicz3dfe1102008-03-12 10:32:59 +01001027 images->fit_noffset_os = os_noffset;
Marian Balakowicz6986a382008-03-12 10:01:05 +01001028 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001029#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{
1090 int rcode = 0;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001091
Simon Glass53071532012-02-14 19:59:21 +00001092 if (run_command(getenv("bootcmd"), flag) < 0)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001093 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001094 return rcode;
1095}
wdenk8bde7f72003-06-27 21:31:46 +00001096
wdenk0d498392003-07-01 21:06:45 +00001097U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001098 boot, 1, 1, do_bootd,
Peter Tyser2fb26042009-01-27 18:03:12 -06001099 "boot default, i.e., run 'bootcmd'",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001100 ""
wdenk9d2b18a2003-06-28 23:11:04 +00001101);
1102
1103/* keep old command name "bootd" for backward compatibility */
wdenk0d498392003-07-01 21:06:45 +00001104U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001105 bootd, 1, 1, do_bootd,
Peter Tyser2fb26042009-01-27 18:03:12 -06001106 "boot default, i.e., run 'bootcmd'",
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001107 ""
wdenk8bde7f72003-06-27 21:31:46 +00001108);
1109
wdenk47d1a6e2002-11-03 00:01:44 +00001110#endif
1111
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001112
1113/*******************************************************************/
1114/* iminfo - print header info for a requested image */
1115/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -05001116#if defined(CONFIG_CMD_IMI)
Kim Phillips088f1b12012-10-29 13:34:31 +00001117static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk47d1a6e2002-11-03 00:01:44 +00001118{
1119 int arg;
1120 ulong addr;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001121 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +00001122
1123 if (argc < 2) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001124 return image_info(load_addr);
wdenk47d1a6e2002-11-03 00:01:44 +00001125 }
1126
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001127 for (arg = 1; arg < argc; ++arg) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001128 addr = simple_strtoul(argv[arg], NULL, 16);
1129 if (image_info(addr) != 0)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001130 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001131 }
1132 return rcode;
1133}
1134
Stephen Warren712fbcf2011-10-18 11:11:49 +00001135static int image_info(ulong addr)
wdenk47d1a6e2002-11-03 00:01:44 +00001136{
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001137 void *hdr = (void *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +00001138
Stephen Warren712fbcf2011-10-18 11:11:49 +00001139 printf("\n## Checking Image at %08lx ...\n", addr);
wdenk47d1a6e2002-11-03 00:01:44 +00001140
Stephen Warren712fbcf2011-10-18 11:11:49 +00001141 switch (genimg_get_format(hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001142 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001143 puts(" Legacy image found\n");
1144 if (!image_check_magic(hdr)) {
1145 puts(" Bad Magic Number\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001146 return 1;
1147 }
1148
Stephen Warren712fbcf2011-10-18 11:11:49 +00001149 if (!image_check_hcrc(hdr)) {
1150 puts(" Bad Header Checksum\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001151 return 1;
1152 }
1153
Stephen Warren712fbcf2011-10-18 11:11:49 +00001154 image_print_contents(hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001155
Stephen Warren712fbcf2011-10-18 11:11:49 +00001156 puts(" Verifying Checksum ... ");
1157 if (!image_check_dcrc(hdr)) {
1158 puts(" Bad Data CRC\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001159 return 1;
1160 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00001161 puts("OK\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001162 return 0;
1163#if defined(CONFIG_FIT)
1164 case IMAGE_FORMAT_FIT:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001165 puts(" FIT image found\n");
Marian Balakowicze32fea62008-03-11 12:35:20 +01001166
Stephen Warren712fbcf2011-10-18 11:11:49 +00001167 if (!fit_check_format(hdr)) {
1168 puts("Bad FIT image format!\n");
Marian Balakowicze32fea62008-03-11 12:35:20 +01001169 return 1;
1170 }
1171
Stephen Warren712fbcf2011-10-18 11:11:49 +00001172 fit_print_contents(hdr);
Bartlomiej Siekaa4f24342008-09-09 12:58:16 +02001173
Simon Glassb8da8362013-05-07 06:11:57 +00001174 if (!fit_all_image_verify(hdr)) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001175 puts("Bad hash in FIT image!\n");
Bartlomiej Siekaa4f24342008-09-09 12:58:16 +02001176 return 1;
1177 }
1178
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001179 return 0;
1180#endif
1181 default:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001182 puts("Unknown image format!\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001183 break;
wdenk47d1a6e2002-11-03 00:01:44 +00001184 }
1185
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001186 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001187}
wdenk0d498392003-07-01 21:06:45 +00001188
1189U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001190 iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
Peter Tyser2fb26042009-01-27 18:03:12 -06001191 "print header information for application image",
wdenk8bde7f72003-06-27 21:31:46 +00001192 "addr [addr ...]\n"
1193 " - print header information for application image starting at\n"
1194 " address 'addr' in memory; this includes verification of the\n"
Wolfgang Denka89c33d2009-05-24 17:06:54 +02001195 " image contents (magic number, header and payload checksums)"
wdenk8bde7f72003-06-27 21:31:46 +00001196);
Jon Loeliger90253172007-07-10 11:02:44 -05001197#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001198
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001199
1200/*******************************************************************/
1201/* imls - list all images found in flash */
1202/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -05001203#if defined(CONFIG_CMD_IMLS)
Vipin Kumar8fdf1e02012-12-16 22:32:48 +00001204static int do_imls_nor(void)
wdenk27b207f2003-07-24 23:38:38 +00001205{
1206 flash_info_t *info;
1207 int i, j;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001208 void *hdr;
wdenk27b207f2003-07-24 23:38:38 +00001209
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001210 for (i = 0, info = &flash_info[0];
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +02001211 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001212
wdenk27b207f2003-07-24 23:38:38 +00001213 if (info->flash_id == FLASH_UNKNOWN)
1214 goto next_bank;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001215 for (j = 0; j < info->sector_count; ++j) {
wdenk27b207f2003-07-24 23:38:38 +00001216
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001217 hdr = (void *)info->start[j];
1218 if (!hdr)
wdenk27b207f2003-07-24 23:38:38 +00001219 goto next_sector;
1220
Stephen Warren712fbcf2011-10-18 11:11:49 +00001221 switch (genimg_get_format(hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001222 case IMAGE_FORMAT_LEGACY:
Stephen Warren712fbcf2011-10-18 11:11:49 +00001223 if (!image_check_hcrc(hdr))
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001224 goto next_sector;
1225
Stephen Warren712fbcf2011-10-18 11:11:49 +00001226 printf("Legacy Image at %08lX:\n", (ulong)hdr);
1227 image_print_contents(hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001228
Stephen Warren712fbcf2011-10-18 11:11:49 +00001229 puts(" Verifying Checksum ... ");
1230 if (!image_check_dcrc(hdr)) {
1231 puts("Bad Data CRC\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001232 } else {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001233 puts("OK\n");
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001234 }
1235 break;
1236#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)) {
1370 case IMAGE_FORMAT_LEGACY:
1371 header = (const image_header_t *)buffer;
1372
1373 len = image_get_image_size(header);
1374 nand_imls_legacyimage(nand, nand_dev, off, len);
1375 break;
1376#if defined(CONFIG_FIT)
1377 case IMAGE_FORMAT_FIT:
1378 len = fit_get_size(buffer);
1379 nand_imls_fitimage(nand, nand_dev, off, len);
1380 break;
1381#endif
1382 }
1383 }
1384 }
1385
1386 return 0;
1387}
1388#endif
1389
1390#if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
1391static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1392{
1393 int ret_nor = 0, ret_nand = 0;
1394
1395#if defined(CONFIG_CMD_IMLS)
1396 ret_nor = do_imls_nor();
1397#endif
1398
1399#if defined(CONFIG_CMD_IMLS_NAND)
1400 ret_nand = do_imls_nand();
1401#endif
1402
1403 if (ret_nor)
1404 return ret_nor;
1405
1406 if (ret_nand)
1407 return ret_nand;
wdenk27b207f2003-07-24 23:38:38 +00001408
1409 return (0);
1410}
1411
1412U_BOOT_CMD(
1413 imls, 1, 1, do_imls,
Peter Tyser2fb26042009-01-27 18:03:12 -06001414 "list all images found in flash",
wdenk27b207f2003-07-24 23:38:38 +00001415 "\n"
Vipin Kumar8fdf1e02012-12-16 22:32:48 +00001416 " - Prints information about all images found at sector/block\n"
1417 " boundaries in nor/nand flash."
wdenk27b207f2003-07-24 23:38:38 +00001418);
Jon Loeliger90253172007-07-10 11:02:44 -05001419#endif
wdenk27b207f2003-07-24 23:38:38 +00001420
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001421/*******************************************************************/
Marian Balakowicz5cf746c2008-01-31 13:59:09 +01001422/* helper routines */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001423/*******************************************************************/
Joe Hershbergerbe2e5a02013-02-27 10:20:59 +00001424#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
Doug Andersona558ad72012-01-17 09:37:41 +00001425
1426#define CONSOLE_ARG "console="
1427#define CONSOLE_ARG_LEN (sizeof(CONSOLE_ARG) - 1)
1428
Doug Anderson3a8653b2011-10-19 12:30:57 +00001429static void fixup_silent_linux(void)
wdenk47d1a6e2002-11-03 00:01:44 +00001430{
Doug Andersona558ad72012-01-17 09:37:41 +00001431 char *buf;
1432 const char *env_val;
Doug Anderson3a8653b2011-10-19 12:30:57 +00001433 char *cmdline = getenv("bootargs");
wdenk47d1a6e2002-11-03 00:01:44 +00001434
1435 /* Only fix cmdline when requested */
1436 if (!(gd->flags & GD_FLG_SILENT))
1437 return;
1438
Doug Anderson3a8653b2011-10-19 12:30:57 +00001439 debug("before silent fix-up: %s\n", cmdline);
Doug Andersona558ad72012-01-17 09:37:41 +00001440 if (cmdline && (cmdline[0] != '\0')) {
1441 char *start = strstr(cmdline, CONSOLE_ARG);
1442
1443 /* Allocate space for maximum possible new command line */
1444 buf = malloc(strlen(cmdline) + 1 + CONSOLE_ARG_LEN + 1);
1445 if (!buf) {
1446 debug("%s: out of memory\n", __func__);
1447 return;
wdenk47d1a6e2002-11-03 00:01:44 +00001448 }
Doug Andersona558ad72012-01-17 09:37:41 +00001449
1450 if (start) {
1451 char *end = strchr(start, ' ');
1452 int num_start_bytes = start - cmdline + CONSOLE_ARG_LEN;
1453
1454 strncpy(buf, cmdline, num_start_bytes);
1455 if (end)
1456 strcpy(buf + num_start_bytes, end);
1457 else
1458 buf[num_start_bytes] = '\0';
1459 } else {
1460 sprintf(buf, "%s %s", cmdline, CONSOLE_ARG);
1461 }
1462 env_val = buf;
wdenk47d1a6e2002-11-03 00:01:44 +00001463 } else {
Doug Andersona558ad72012-01-17 09:37:41 +00001464 buf = NULL;
1465 env_val = CONSOLE_ARG;
wdenk47d1a6e2002-11-03 00:01:44 +00001466 }
1467
Doug Andersona558ad72012-01-17 09:37:41 +00001468 setenv("bootargs", env_val);
1469 debug("after silent fix-up: %s\n", env_val);
1470 free(buf);
wdenk47d1a6e2002-11-03 00:01:44 +00001471}
1472#endif /* CONFIG_SILENT_CONSOLE */
1473
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001474
1475/*******************************************************************/
1476/* OS booting routines */
1477/*******************************************************************/
1478
Kumar Galab1d0db12008-10-21 17:25:47 -05001479#ifdef CONFIG_BOOTM_NETBSD
Stephen Warren712fbcf2011-10-18 11:11:49 +00001480static int do_bootm_netbsd(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001481 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001482{
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001483 void (*loader)(bd_t *, image_header_t *, char *, char *);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001484 image_header_t *os_hdr, *hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001485 ulong kernel_data, kernel_len;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001486 char *consdev;
1487 char *cmdline;
wdenk47d1a6e2002-11-03 00:01:44 +00001488
Kumar Gala49c3a862008-10-21 17:25:45 -05001489 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1490 return 1;
1491
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001492#if defined(CONFIG_FIT)
1493 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001494 fit_unsupported_reset("NetBSD");
Kumar Gala40d7e992008-08-15 08:24:45 -05001495 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001496 }
1497#endif
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001498 hdr = images->legacy_hdr_os;
wdenk47d1a6e2002-11-03 00:01:44 +00001499
1500 /*
1501 * Booting a (NetBSD) kernel image
1502 *
1503 * This process is pretty similar to a standalone application:
1504 * The (first part of an multi-) image must be a stage-2 loader,
1505 * which in turn is responsible for loading & invoking the actual
1506 * kernel. The only differences are the parameters being passed:
1507 * besides the board info strucure, the loader expects a command
1508 * line, the name of the console device, and (optionally) the
1509 * address of the original image header.
1510 */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001511 os_hdr = NULL;
Stephen Warren712fbcf2011-10-18 11:11:49 +00001512 if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1513 image_multi_getimg(hdr, 1, &kernel_data, &kernel_len);
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001514 if (kernel_len)
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001515 os_hdr = hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001516 }
wdenk47d1a6e2002-11-03 00:01:44 +00001517
1518 consdev = "";
Stephen Warren712fbcf2011-10-18 11:11:49 +00001519#if defined(CONFIG_8xx_CONS_SMC1)
wdenk47d1a6e2002-11-03 00:01:44 +00001520 consdev = "smc1";
Stephen Warren712fbcf2011-10-18 11:11:49 +00001521#elif defined(CONFIG_8xx_CONS_SMC2)
wdenk47d1a6e2002-11-03 00:01:44 +00001522 consdev = "smc2";
Stephen Warren712fbcf2011-10-18 11:11:49 +00001523#elif defined(CONFIG_8xx_CONS_SCC2)
wdenk47d1a6e2002-11-03 00:01:44 +00001524 consdev = "scc2";
Stephen Warren712fbcf2011-10-18 11:11:49 +00001525#elif defined(CONFIG_8xx_CONS_SCC3)
wdenk47d1a6e2002-11-03 00:01:44 +00001526 consdev = "scc3";
1527#endif
1528
1529 if (argc > 2) {
1530 ulong len;
1531 int i;
1532
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001533 for (i = 2, len = 0; i < argc; i += 1)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001534 len += strlen(argv[i]) + 1;
1535 cmdline = malloc(len);
wdenk47d1a6e2002-11-03 00:01:44 +00001536
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001537 for (i = 2, len = 0; i < argc; i += 1) {
wdenk47d1a6e2002-11-03 00:01:44 +00001538 if (i > 2)
1539 cmdline[len++] = ' ';
Stephen Warren712fbcf2011-10-18 11:11:49 +00001540 strcpy(&cmdline[len], argv[i]);
1541 len += strlen(argv[i]);
wdenk47d1a6e2002-11-03 00:01:44 +00001542 }
Stephen Warren712fbcf2011-10-18 11:11:49 +00001543 } else if ((cmdline = getenv("bootargs")) == NULL) {
wdenk47d1a6e2002-11-03 00:01:44 +00001544 cmdline = "";
1545 }
1546
Kumar Galac160a952008-08-15 08:24:36 -05001547 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
wdenk47d1a6e2002-11-03 00:01:44 +00001548
Stephen Warren712fbcf2011-10-18 11:11:49 +00001549 printf("## Transferring control to NetBSD stage-2 loader "
1550 "(at address %08lx) ...\n",
wdenk47d1a6e2002-11-03 00:01:44 +00001551 (ulong)loader);
1552
Simon Glass770605e2012-02-13 13:51:18 +00001553 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
wdenk47d1a6e2002-11-03 00:01:44 +00001554
1555 /*
1556 * NetBSD Stage-2 Loader Parameters:
1557 * r3: ptr to board info data
1558 * r4: image address
1559 * r5: console device
1560 * r6: boot args string
1561 */
Stephen Warren712fbcf2011-10-18 11:11:49 +00001562 (*loader)(gd->bd, os_hdr, consdev, cmdline);
Kumar Gala40d7e992008-08-15 08:24:45 -05001563
1564 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001565}
Kumar Galab1d0db12008-10-21 17:25:47 -05001566#endif /* CONFIG_BOOTM_NETBSD*/
wdenk47d1a6e2002-11-03 00:01:44 +00001567
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001568#ifdef CONFIG_LYNXKDI
Stephen Warren712fbcf2011-10-18 11:11:49 +00001569static int do_bootm_lynxkdi(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001570 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001571{
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001572 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001573
Kumar Gala49c3a862008-10-21 17:25:45 -05001574 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1575 return 1;
1576
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001577#if defined(CONFIG_FIT)
1578 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001579 fit_unsupported_reset("Lynx");
Kumar Gala40d7e992008-08-15 08:24:45 -05001580 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001581 }
1582#endif
1583
Stephen Warren712fbcf2011-10-18 11:11:49 +00001584 lynxkdi_boot((image_header_t *)hdr);
Kumar Gala40d7e992008-08-15 08:24:45 -05001585
1586 return 1;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001587}
1588#endif /* CONFIG_LYNXKDI */
1589
Kumar Galab1d0db12008-10-21 17:25:47 -05001590#ifdef CONFIG_BOOTM_RTEMS
Stephen Warren712fbcf2011-10-18 11:11:49 +00001591static int do_bootm_rtems(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001592 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001593{
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001594 void (*entry_point)(bd_t *);
wdenkd791b1d2003-04-20 14:04:18 +00001595
Kumar Gala49c3a862008-10-21 17:25:45 -05001596 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1597 return 1;
1598
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001599#if defined(CONFIG_FIT)
1600 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001601 fit_unsupported_reset("RTEMS");
Kumar Gala40d7e992008-08-15 08:24:45 -05001602 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001603 }
1604#endif
1605
Kumar Galac160a952008-08-15 08:24:36 -05001606 entry_point = (void (*)(bd_t *))images->ep;
wdenkd791b1d2003-04-20 14:04:18 +00001607
Stephen Warren712fbcf2011-10-18 11:11:49 +00001608 printf("## Transferring control to RTEMS (at address %08lx) ...\n",
wdenkd791b1d2003-04-20 14:04:18 +00001609 (ulong)entry_point);
1610
Simon Glass770605e2012-02-13 13:51:18 +00001611 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
wdenkd791b1d2003-04-20 14:04:18 +00001612
1613 /*
1614 * RTEMS Parameters:
1615 * r3: ptr to board info data
1616 */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001617 (*entry_point)(gd->bd);
Kumar Gala40d7e992008-08-15 08:24:45 -05001618
1619 return 1;
wdenkd791b1d2003-04-20 14:04:18 +00001620}
Kumar Galab1d0db12008-10-21 17:25:47 -05001621#endif /* CONFIG_BOOTM_RTEMS */
wdenkd791b1d2003-04-20 14:04:18 +00001622
Torkel Lundgren3df61952010-09-28 11:05:36 +02001623#if defined(CONFIG_BOOTM_OSE)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001624static int do_bootm_ose(int flag, int argc, char * const argv[],
Torkel Lundgren3df61952010-09-28 11:05:36 +02001625 bootm_headers_t *images)
1626{
1627 void (*entry_point)(void);
1628
1629 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1630 return 1;
1631
1632#if defined(CONFIG_FIT)
1633 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001634 fit_unsupported_reset("OSE");
Torkel Lundgren3df61952010-09-28 11:05:36 +02001635 return 1;
1636 }
1637#endif
1638
1639 entry_point = (void (*)(void))images->ep;
1640
Stephen Warren712fbcf2011-10-18 11:11:49 +00001641 printf("## Transferring control to OSE (at address %08lx) ...\n",
Torkel Lundgren3df61952010-09-28 11:05:36 +02001642 (ulong)entry_point);
1643
Simon Glass770605e2012-02-13 13:51:18 +00001644 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
Torkel Lundgren3df61952010-09-28 11:05:36 +02001645
1646 /*
1647 * OSE Parameters:
1648 * None
1649 */
1650 (*entry_point)();
1651
1652 return 1;
1653}
1654#endif /* CONFIG_BOOTM_OSE */
1655
Steven Stallion04d41402013-03-20 06:31:35 +00001656#if defined(CONFIG_BOOTM_PLAN9)
1657static int do_bootm_plan9(int flag, int argc, char * const argv[],
1658 bootm_headers_t *images)
1659{
1660 void (*entry_point)(void);
1661
1662 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1663 return 1;
1664
1665#if defined(CONFIG_FIT)
1666 if (!images->legacy_hdr_valid) {
1667 fit_unsupported_reset("Plan 9");
1668 return 1;
1669 }
1670#endif
1671
1672 entry_point = (void (*)(void))images->ep;
1673
1674 printf("## Transferring control to Plan 9 (at address %08lx) ...\n",
1675 (ulong)entry_point);
1676
1677 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1678
1679 /*
1680 * Plan 9 Parameters:
1681 * None
1682 */
1683 (*entry_point)();
1684
1685 return 1;
1686}
1687#endif /* CONFIG_BOOTM_PLAN9 */
1688
Jon Loeligerbaa26db2007-07-08 17:51:39 -05001689#if defined(CONFIG_CMD_ELF)
Stephen Warren712fbcf2011-10-18 11:11:49 +00001690static int do_bootm_vxworks(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001691 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001692{
wdenk47d1a6e2002-11-03 00:01:44 +00001693 char str[80];
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001694
Kumar Gala49c3a862008-10-21 17:25:45 -05001695 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1696 return 1;
1697
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001698#if defined(CONFIG_FIT)
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001699 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001700 fit_unsupported_reset("VxWorks");
Kumar Gala40d7e992008-08-15 08:24:45 -05001701 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001702 }
1703#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001704
Kumar Galac160a952008-08-15 08:24:36 -05001705 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001706 setenv("loadaddr", str);
Kumar Gala40d7e992008-08-15 08:24:45 -05001707 do_bootvx(NULL, 0, 0, NULL);
1708
1709 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001710}
1711
Wolfgang Denk54841ab2010-06-28 22:00:46 +02001712static int do_bootm_qnxelf(int flag, int argc, char * const argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001713 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001714{
wdenk47d1a6e2002-11-03 00:01:44 +00001715 char *local_args[2];
1716 char str[16];
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001717
Kumar Gala49c3a862008-10-21 17:25:45 -05001718 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1719 return 1;
1720
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001721#if defined(CONFIG_FIT)
1722 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001723 fit_unsupported_reset("QNX");
Kumar Gala40d7e992008-08-15 08:24:45 -05001724 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001725 }
1726#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001727
Kumar Galac160a952008-08-15 08:24:36 -05001728 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001729 local_args[0] = argv[0];
1730 local_args[1] = str; /* and provide it via the arguments */
Kumar Gala40d7e992008-08-15 08:24:45 -05001731 do_bootelf(NULL, 0, 2, local_args);
1732
1733 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001734}
Jon Loeliger90253172007-07-10 11:02:44 -05001735#endif
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001736
1737#ifdef CONFIG_INTEGRITY
Stephen Warren712fbcf2011-10-18 11:11:49 +00001738static int do_bootm_integrity(int flag, int argc, char * const argv[],
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001739 bootm_headers_t *images)
1740{
1741 void (*entry_point)(void);
1742
Kumar Gala49c3a862008-10-21 17:25:45 -05001743 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1744 return 1;
1745
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001746#if defined(CONFIG_FIT)
1747 if (!images->legacy_hdr_valid) {
Stephen Warren712fbcf2011-10-18 11:11:49 +00001748 fit_unsupported_reset("INTEGRITY");
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001749 return 1;
1750 }
1751#endif
1752
1753 entry_point = (void (*)(void))images->ep;
1754
Stephen Warren712fbcf2011-10-18 11:11:49 +00001755 printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001756 (ulong)entry_point);
1757
Simon Glass770605e2012-02-13 13:51:18 +00001758 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001759
1760 /*
1761 * INTEGRITY Parameters:
1762 * None
1763 */
1764 (*entry_point)();
1765
1766 return 1;
1767}
1768#endif
Marek Vasut44f074c2012-03-14 21:52:45 +00001769
1770#ifdef CONFIG_CMD_BOOTZ
1771
1772static int __bootz_setup(void *image, void **start, void **end)
1773{
1774 /* Please define bootz_setup() for your platform */
1775
1776 puts("Your platform's zImage format isn't supported yet!\n");
1777 return -1;
1778}
1779int bootz_setup(void *image, void **start, void **end)
1780 __attribute__((weak, alias("__bootz_setup")));
1781
1782/*
1783 * zImage booting support
1784 */
1785static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
1786 char * const argv[], bootm_headers_t *images)
1787{
1788 int ret;
1789 void *zi_start, *zi_end;
1790
1791 memset(images, 0, sizeof(bootm_headers_t));
1792
1793 boot_start_lmb(images);
1794
1795 /* Setup Linux kernel zImage entry point */
1796 if (argc < 2) {
1797 images->ep = load_addr;
1798 debug("* kernel: default image load address = 0x%08lx\n",
1799 load_addr);
1800 } else {
1801 images->ep = simple_strtoul(argv[1], NULL, 16);
1802 debug("* kernel: cmdline image address = 0x%08lx\n",
1803 images->ep);
1804 }
1805
1806 ret = bootz_setup((void *)images->ep, &zi_start, &zi_end);
1807 if (ret != 0)
1808 return 1;
1809
1810 lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
1811
1812 /* Find ramdisk */
1813 ret = boot_get_ramdisk(argc, argv, images, IH_INITRD_ARCH,
1814 &images->rd_start, &images->rd_end);
1815 if (ret) {
1816 puts("Ramdisk image is corrupt or invalid\n");
1817 return 1;
1818 }
1819
1820#if defined(CONFIG_OF_LIBFDT)
1821 /* find flattened device tree */
Simon Glass53f375f2013-05-16 13:53:23 +00001822 ret = boot_get_fdt(flag, argc, argv, IH_ARCH_DEFAULT, images,
Marek Vasut44f074c2012-03-14 21:52:45 +00001823 &images->ft_addr, &images->ft_len);
1824 if (ret) {
1825 puts("Could not find a valid device tree\n");
1826 return 1;
1827 }
1828
1829 set_working_fdt_addr(images->ft_addr);
1830#endif
1831
1832 return 0;
1833}
1834
1835static int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1836{
Marek Vasut44f074c2012-03-14 21:52:45 +00001837 bootm_headers_t images;
1838
1839 if (bootz_start(cmdtp, flag, argc, argv, &images))
1840 return 1;
1841
1842 /*
1843 * We have reached the point of no return: we are going to
1844 * overwrite all exception vector code, so we cannot easily
1845 * recover from any failures any more...
1846 */
Anatolij Gustschina075a792012-05-19 05:38:19 +00001847 disable_interrupts();
Marek Vasut44f074c2012-03-14 21:52:45 +00001848
Joe Hershbergerf8be7d62012-08-03 10:59:08 +00001849#ifdef CONFIG_NETCONSOLE
1850 /* Stop the ethernet stack if NetConsole could have left it up */
1851 eth_halt();
1852#endif
1853
Marek Vasut44f074c2012-03-14 21:52:45 +00001854#if defined(CONFIG_CMD_USB)
1855 /*
1856 * turn off USB to prevent the host controller from writing to the
1857 * SDRAM while Linux is booting. This could happen (at least for OHCI
1858 * controller), because the HCCA (Host Controller Communication Area)
1859 * lies within the SDRAM and the host controller writes continously to
1860 * this area (as busmaster!). The HccaFrameNumber is for example
1861 * updated every 1 ms within the HCCA structure in SDRAM! For more
1862 * details see the OpenHCI specification.
1863 */
1864 usb_stop();
1865#endif
1866
Joe Hershbergerbe2e5a02013-02-27 10:20:59 +00001867#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
Marek Vasut44f074c2012-03-14 21:52:45 +00001868 fixup_silent_linux();
1869#endif
1870 arch_preboot_os();
1871
1872 do_bootm_linux(0, argc, argv, &images);
1873#ifdef DEBUG
1874 puts("\n## Control returned to monitor - resetting...\n");
1875#endif
1876 do_reset(cmdtp, flag, argc, argv);
1877
1878 return 1;
1879}
1880
Kim Phillips088f1b12012-10-29 13:34:31 +00001881#ifdef CONFIG_SYS_LONGHELP
1882static char bootz_help_text[] =
Marek Vasut017e1f32012-03-18 11:47:58 +00001883 "[addr [initrd[:size]] [fdt]]\n"
1884 " - boot Linux zImage stored in memory\n"
Marek Vasut44f074c2012-03-14 21:52:45 +00001885 "\tThe argument 'initrd' is optional and specifies the address\n"
Marek Vasut017e1f32012-03-18 11:47:58 +00001886 "\tof the initrd in memory. The optional argument ':size' allows\n"
1887 "\tspecifying the size of RAW initrd.\n"
Marek Vasut44f074c2012-03-14 21:52:45 +00001888#if defined(CONFIG_OF_LIBFDT)
1889 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
1890 "\ta third argument is required which is the address of the\n"
1891 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1892 "\tuse a '-' for the second argument. If you do not pass a third\n"
1893 "\ta bd_info struct will be passed instead\n"
1894#endif
Kim Phillips088f1b12012-10-29 13:34:31 +00001895 "";
1896#endif
1897
1898U_BOOT_CMD(
1899 bootz, CONFIG_SYS_MAXARGS, 1, do_bootz,
1900 "boot Linux zImage image from memory", bootz_help_text
Marek Vasut44f074c2012-03-14 21:52:45 +00001901);
1902#endif /* CONFIG_CMD_BOOTZ */