blob: 7438469d091721a6dcba15ec2263ef7b086dc743 [file] [log] [blame]
wdenk47d1a6e2002-11-03 00:01:44 +00001/*
Detlev Zundel77094472009-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 Balakowicz41d71ed2008-01-08 18:14:09 +010024
wdenk47d1a6e2002-11-03 00:01:44 +000025/*
26 * Boot support
27 */
28#include <common.h>
29#include <watchdog.h>
30#include <command.h>
wdenk47d1a6e2002-11-03 00:01:44 +000031#include <image.h>
32#include <malloc.h>
Jean-Christophe PLAGNIOL-VILLARD6bb94492009-04-04 12:49:11 +020033#include <u-boot/zlib.h>
wdenk710e3502003-08-29 20:57:53 +000034#include <bzlib.h>
wdenk0893c472003-05-20 14:25:27 +000035#include <environment.h>
Kumar Gala6d7bfa82008-02-27 21:51:47 -060036#include <lmb.h>
Kumar Gala18178bc2008-10-21 17:25:45 -050037#include <linux/ctype.h>
wdenk47d1a6e2002-11-03 00:01:44 +000038#include <asm/byteorder.h>
Anatolij Gustschin18e73d92011-11-19 13:12:18 +000039#include <linux/compiler.h>
wdenk57b2d802003-06-27 21:31:46 +000040
Stefan Roesea629a722008-07-30 09:59:51 +020041#if defined(CONFIG_CMD_USB)
Markus Klotzbücher09197cb2008-07-10 14:47:09 +020042#include <usb.h>
43#endif
44
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020045#ifdef CONFIG_SYS_HUSH_PARSER
wdenk47d1a6e2002-11-03 00:01:44 +000046#include <hush.h>
47#endif
48
Kumar Gala9f4e7e42008-08-15 08:24:39 -050049#if defined(CONFIG_OF_LIBFDT)
Kumar Gala9f4e7e42008-08-15 08:24:39 -050050#include <libfdt.h>
51#include <fdt_support.h>
52#endif
53
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +020054#ifdef CONFIG_LZMA
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +020055#include <lzma/LzmaTypes.h>
Luigi 'Comio' Mantellinid02bd742009-07-21 10:45:49 +020056#include <lzma/LzmaDec.h>
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +020057#include <lzma/LzmaTools.h>
58#endif /* CONFIG_LZMA */
59
Peter Korsgaardf7440cd2009-11-19 11:37:51 +010060#ifdef CONFIG_LZO
61#include <linux/lzo.h>
62#endif /* CONFIG_LZO */
63
Marian Balakowicz2df645e2008-01-08 18:17:10 +010064DECLARE_GLOBAL_DATA_PTR;
wdenk9dfa8d12002-12-08 09:53:23 +000065
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020066#ifndef CONFIG_SYS_BOOTM_LEN
67#define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
wdenk381669a2003-06-16 23:50:08 +000068#endif
69
Marian Balakowiczbe946ba2008-01-08 18:11:43 +010070#ifdef CONFIG_BZIP2
71extern void bz_internal_error(int);
wdenk47d1a6e2002-11-03 00:01:44 +000072#endif
73
Jon Loeliger54324d02007-07-08 17:51:39 -050074#if defined(CONFIG_CMD_IMI)
Stephen Warren6904b6e2011-10-18 11:11:49 +000075static int image_info(unsigned long addr);
wdenk47d1a6e2002-11-03 00:01:44 +000076#endif
wdenk874ac262003-07-24 23:38:38 +000077
Jon Loeliger54324d02007-07-08 17:51:39 -050078#if defined(CONFIG_CMD_IMLS)
wdenk874ac262003-07-24 23:38:38 +000079#include <flash.h>
Stefan Roesefb9a7302010-08-31 10:00:10 +020080#include <mtd/cfi_flash.h>
Marian Balakowicz513b4a12005-10-11 19:09:42 +020081extern flash_info_t flash_info[]; /* info for FLASH chips */
Vipin Kumar3df41b12012-12-16 22:32:48 +000082#endif
83
84#if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
Stephen Warren6904b6e2011-10-18 11:11:49 +000085static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
wdenk874ac262003-07-24 23:38:38 +000086#endif
87
Vipin Kumar3df41b12012-12-16 22:32:48 +000088#include <linux/err.h>
89#include <nand.h>
90
Joe Hershberger01c2d982013-02-27 10:20:59 +000091#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
Stephen Warren6904b6e2011-10-18 11:11:49 +000092static void fixup_silent_linux(void);
Marian Balakowicz2df645e2008-01-08 18:17:10 +010093#endif
wdenk47d1a6e2002-11-03 00:01:44 +000094
Stephen Warren6904b6e2011-10-18 11:11:49 +000095static image_header_t *image_get_kernel(ulong img_addr, int verify);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +010096#if defined(CONFIG_FIT)
Stephen Warren6904b6e2011-10-18 11:11:49 +000097static int fit_check_kernel(const void *fit, int os_noffset, int verify);
wdenk591dda52002-11-18 00:14:45 +000098#endif
99
Stephen Warren6904b6e2011-10-18 11:11:49 +0000100static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
101 char * const argv[], bootm_headers_t *images,
102 ulong *os_data, ulong *os_len);
wdenk47d1a6e2002-11-03 00:01:44 +0000103
wdenk47d1a6e2002-11-03 00:01:44 +0000104/*
105 * Continue booting an OS image; caller already has:
106 * - copied image header to global variable `header'
107 * - checked header magic number, checksums (both header & image),
108 * - verified image architecture (PPC) and type (KERNEL or MULTI),
109 * - loaded (first part of) image to header load address,
110 * - disabled interrupts.
111 */
Stephen Warren6904b6e2011-10-18 11:11:49 +0000112typedef int boot_os_fn(int flag, int argc, char * const argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100113 bootm_headers_t *images); /* pointers to os/initrd/fdt */
wdenk47d1a6e2002-11-03 00:01:44 +0000114
Kumar Gala697675e2008-10-21 17:25:47 -0500115#ifdef CONFIG_BOOTM_LINUX
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100116extern boot_os_fn do_bootm_linux;
Kumar Gala697675e2008-10-21 17:25:47 -0500117#endif
118#ifdef CONFIG_BOOTM_NETBSD
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100119static boot_os_fn do_bootm_netbsd;
Kumar Gala697675e2008-10-21 17:25:47 -0500120#endif
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100121#if defined(CONFIG_LYNXKDI)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100122static boot_os_fn do_bootm_lynxkdi;
Stephen Warren6904b6e2011-10-18 11:11:49 +0000123extern void lynxkdi_boot(image_header_t *);
wdenk47d1a6e2002-11-03 00:01:44 +0000124#endif
Kumar Gala697675e2008-10-21 17:25:47 -0500125#ifdef CONFIG_BOOTM_RTEMS
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100126static boot_os_fn do_bootm_rtems;
Kumar Gala697675e2008-10-21 17:25:47 -0500127#endif
Torkel Lundgren29a58662010-09-28 11:05:36 +0200128#if defined(CONFIG_BOOTM_OSE)
129static boot_os_fn do_bootm_ose;
130#endif
Steven Stallion36ec8ac2013-03-20 06:31:35 +0000131#if defined(CONFIG_BOOTM_PLAN9)
132static boot_os_fn do_bootm_plan9;
133#endif
Jon Loeliger54324d02007-07-08 17:51:39 -0500134#if defined(CONFIG_CMD_ELF)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100135static boot_os_fn do_bootm_vxworks;
136static boot_os_fn do_bootm_qnxelf;
Stephen Warren6904b6e2011-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 Loeligerd704d912007-07-10 11:02:44 -0500139#endif
Peter Tyser56b8dd12008-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 Frysinger6c1616a2009-11-03 11:36:26 -0500144static boot_os_fn *boot_os[] = {
Kumar Gala697675e2008-10-21 17:25:47 -0500145#ifdef CONFIG_BOOTM_LINUX
Kumar Galabf3954f2008-10-21 17:25:44 -0500146 [IH_OS_LINUX] = do_bootm_linux,
Kumar Gala697675e2008-10-21 17:25:47 -0500147#endif
148#ifdef CONFIG_BOOTM_NETBSD
Kumar Galabf3954f2008-10-21 17:25:44 -0500149 [IH_OS_NETBSD] = do_bootm_netbsd,
Kumar Gala697675e2008-10-21 17:25:47 -0500150#endif
Kumar Galabf3954f2008-10-21 17:25:44 -0500151#ifdef CONFIG_LYNXKDI
152 [IH_OS_LYNXOS] = do_bootm_lynxkdi,
153#endif
Kumar Gala697675e2008-10-21 17:25:47 -0500154#ifdef CONFIG_BOOTM_RTEMS
Kumar Galabf3954f2008-10-21 17:25:44 -0500155 [IH_OS_RTEMS] = do_bootm_rtems,
Kumar Gala697675e2008-10-21 17:25:47 -0500156#endif
Torkel Lundgren29a58662010-09-28 11:05:36 +0200157#if defined(CONFIG_BOOTM_OSE)
158 [IH_OS_OSE] = do_bootm_ose,
159#endif
Steven Stallion36ec8ac2013-03-20 06:31:35 +0000160#if defined(CONFIG_BOOTM_PLAN9)
161 [IH_OS_PLAN9] = do_bootm_plan9,
162#endif
Kumar Galabf3954f2008-10-21 17:25:44 -0500163#if defined(CONFIG_CMD_ELF)
164 [IH_OS_VXWORKS] = do_bootm_vxworks,
165 [IH_OS_QNX] = do_bootm_qnxelf,
166#endif
167#ifdef CONFIG_INTEGRITY
168 [IH_OS_INTEGRITY] = do_bootm_integrity,
169#endif
170};
171
Simon Schwarz6519bbf2011-09-02 00:50:31 +0000172bootm_headers_t images; /* pointers to os/initrd/fdt images */
Stefan Roese5d5ce292006-03-13 11:16:36 +0100173
Kumar Gala5e726692009-08-27 08:23:55 -0500174/* Allow for arch specific config before we boot */
Kim Phillipsdc00a682012-10-29 13:34:31 +0000175static void __arch_preboot_os(void)
Kumar Gala5e726692009-08-27 08:23:55 -0500176{
177 /* please define platform specific arch_preboot_os() */
178}
179void arch_preboot_os(void) __attribute__((weak, alias("__arch_preboot_os")));
180
Mike Frysinger5da0bed2011-10-03 14:50:33 +0000181#define IH_INITRD_ARCH IH_ARCH_DEFAULT
wdenk47d1a6e2002-11-03 00:01:44 +0000182
Mike Frysingera0dadf82009-11-03 11:35:59 -0500183#ifdef CONFIG_LMB
Marek Vasutcf41a9b2012-03-14 21:52:45 +0000184static void boot_start_lmb(bootm_headers_t *images)
185{
Becky Bruced26d67c2008-06-09 20:37:18 -0500186 ulong mem_start;
187 phys_size_t mem_size;
wdenk47d1a6e2002-11-03 00:01:44 +0000188
Marek Vasutcf41a9b2012-03-14 21:52:45 +0000189 lmb_init(&images->lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000190
Kumar Galac5bacfd2008-02-27 21:51:50 -0600191 mem_start = getenv_bootm_low();
192 mem_size = getenv_bootm_size();
wdenk47d1a6e2002-11-03 00:01:44 +0000193
Marek Vasutcf41a9b2012-03-14 21:52:45 +0000194 lmb_add(&images->lmb, (phys_addr_t)mem_start, mem_size);
wdenk47d1a6e2002-11-03 00:01:44 +0000195
Marek Vasutcf41a9b2012-03-14 21:52:45 +0000196 arch_lmb_reserve(&images->lmb);
197 board_lmb_reserve(&images->lmb);
198}
Mike Frysingera0dadf82009-11-03 11:35:59 -0500199#else
Marek Vasutac15cad2012-04-01 03:59:46 +0000200#define lmb_reserve(lmb, base, size)
Marek Vasutcf41a9b2012-03-14 21:52:45 +0000201static inline void boot_start_lmb(bootm_headers_t *images) { }
Mike Frysingera0dadf82009-11-03 11:35:59 -0500202#endif
Mike Frysingera0dadf82009-11-03 11:35:59 -0500203
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200204static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Mike Frysingera0dadf82009-11-03 11:35:59 -0500205{
206 void *os_hdr;
207 int ret;
208
Stephen Warren6904b6e2011-10-18 11:11:49 +0000209 memset((void *)&images, 0, sizeof(images));
210 images.verify = getenv_yesno("verify");
Mike Frysingera0dadf82009-11-03 11:35:59 -0500211
Marek Vasutcf41a9b2012-03-14 21:52:45 +0000212 boot_start_lmb(&images);
wdenk47d1a6e2002-11-03 00:01:44 +0000213
Simon Glass768cbf02011-12-10 11:08:06 +0000214 bootstage_mark_name(BOOTSTAGE_ID_BOOTM_START, "bootm_start");
215
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100216 /* get kernel image header, start address and length */
Stephen Warren6904b6e2011-10-18 11:11:49 +0000217 os_hdr = boot_get_kernel(cmdtp, flag, argc, argv,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500218 &images, &images.os.image_start, &images.os.image_len);
219 if (images.os.image_len == 0) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000220 puts("ERROR: can't get kernel image!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000221 return 1;
222 }
Wolfgang Denk63e44ff2005-10-06 01:50:50 +0200223
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100224 /* get image parameters */
Stephen Warren6904b6e2011-10-18 11:11:49 +0000225 switch (genimg_get_format(os_hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100226 case IMAGE_FORMAT_LEGACY:
Stephen Warren6904b6e2011-10-18 11:11:49 +0000227 images.os.type = image_get_type(os_hdr);
228 images.os.comp = image_get_comp(os_hdr);
229 images.os.os = image_get_os(os_hdr);
Wolfgang Denk63e44ff2005-10-06 01:50:50 +0200230
Stephen Warren6904b6e2011-10-18 11:11:49 +0000231 images.os.end = image_get_image_end(os_hdr);
232 images.os.load = image_get_load(os_hdr);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100233 break;
234#if defined(CONFIG_FIT)
235 case IMAGE_FORMAT_FIT:
Stephen Warren6904b6e2011-10-18 11:11:49 +0000236 if (fit_image_get_type(images.fit_hdr_os,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500237 images.fit_noffset_os, &images.os.type)) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000238 puts("Can't get image type!\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000239 bootstage_error(BOOTSTAGE_ID_FIT_TYPE);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100240 return 1;
241 }
wdenk47d1a6e2002-11-03 00:01:44 +0000242
Stephen Warren6904b6e2011-10-18 11:11:49 +0000243 if (fit_image_get_comp(images.fit_hdr_os,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500244 images.fit_noffset_os, &images.os.comp)) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000245 puts("Can't get image compression!\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000246 bootstage_error(BOOTSTAGE_ID_FIT_COMPRESSION);
wdenk47d1a6e2002-11-03 00:01:44 +0000247 return 1;
248 }
wdenk47d1a6e2002-11-03 00:01:44 +0000249
Stephen Warren6904b6e2011-10-18 11:11:49 +0000250 if (fit_image_get_os(images.fit_hdr_os,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500251 images.fit_noffset_os, &images.os.os)) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000252 puts("Can't get image OS!\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000253 bootstage_error(BOOTSTAGE_ID_FIT_OS);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100254 return 1;
255 }
wdenk47d1a6e2002-11-03 00:01:44 +0000256
Stephen Warren6904b6e2011-10-18 11:11:49 +0000257 images.os.end = fit_get_end(images.fit_hdr_os);
wdenk47d1a6e2002-11-03 00:01:44 +0000258
Stephen Warren6904b6e2011-10-18 11:11:49 +0000259 if (fit_image_get_load(images.fit_hdr_os, images.fit_noffset_os,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500260 &images.os.load)) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000261 puts("Can't get image load address!\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000262 bootstage_error(BOOTSTAGE_ID_FIT_LOADADDR);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100263 return 1;
wdenk655a0f92003-10-30 21:49:38 +0000264 }
265 break;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100266#endif
267 default:
Stephen Warren6904b6e2011-10-18 11:11:49 +0000268 puts("ERROR: unknown image format type!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000269 return 1;
270 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100271
Kumar Gala93467bc2008-08-15 08:24:36 -0500272 /* find kernel entry point */
273 if (images.legacy_hdr_valid) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000274 images.ep = image_get_ep(&images.legacy_hdr_os_copy);
Kumar Gala93467bc2008-08-15 08:24:36 -0500275#if defined(CONFIG_FIT)
276 } else if (images.fit_uname_os) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000277 ret = fit_image_get_entry(images.fit_hdr_os,
Kumar Gala93467bc2008-08-15 08:24:36 -0500278 images.fit_noffset_os, &images.ep);
279 if (ret) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000280 puts("Can't get entry point property!\n");
Kumar Gala93467bc2008-08-15 08:24:36 -0500281 return 1;
282 }
283#endif
284 } else {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000285 puts("Could not find kernel entry point!\n");
Kumar Gala93467bc2008-08-15 08:24:36 -0500286 return 1;
287 }
288
Stephen Warren8c87eba2011-11-10 13:17:53 -0700289 if (images.os.type == IH_TYPE_KERNEL_NOLOAD) {
290 images.os.load = images.os.image_start;
291 images.ep += images.os.load;
292 }
293
Heiko Schocher64ccc832010-03-29 13:15:48 +0200294 if (((images.os.type == IH_TYPE_KERNEL) ||
Stephen Warren8c87eba2011-11-10 13:17:53 -0700295 (images.os.type == IH_TYPE_KERNEL_NOLOAD) ||
Heiko Schocher64ccc832010-03-29 13:15:48 +0200296 (images.os.type == IH_TYPE_MULTI)) &&
Detlev Zundel4e46ab32009-12-22 12:43:01 +0100297 (images.os.os == IH_OS_LINUX)) {
Kumar Galafffb1432008-08-15 08:24:37 -0500298 /* find ramdisk */
Stephen Warren6904b6e2011-10-18 11:11:49 +0000299 ret = boot_get_ramdisk(argc, argv, &images, IH_INITRD_ARCH,
Kumar Galafffb1432008-08-15 08:24:37 -0500300 &images.rd_start, &images.rd_end);
301 if (ret) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000302 puts("Ramdisk image is corrupt or invalid\n");
Kumar Galafffb1432008-08-15 08:24:37 -0500303 return 1;
304 }
Kumar Galaa5130ad2008-08-15 08:24:38 -0500305
306#if defined(CONFIG_OF_LIBFDT)
307 /* find flattened device tree */
Stephen Warren6904b6e2011-10-18 11:11:49 +0000308 ret = boot_get_fdt(flag, argc, argv, &images,
309 &images.ft_addr, &images.ft_len);
Kumar Galaa5130ad2008-08-15 08:24:38 -0500310 if (ret) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000311 puts("Could not find a valid device tree\n");
Kumar Galaa5130ad2008-08-15 08:24:38 -0500312 return 1;
313 }
Kumar Gala9f4e7e42008-08-15 08:24:39 -0500314
315 set_working_fdt_addr(images.ft_addr);
Kumar Galaa5130ad2008-08-15 08:24:38 -0500316#endif
Kumar Galafffb1432008-08-15 08:24:37 -0500317 }
318
Kumar Galabd70bbe2008-08-15 08:24:41 -0500319 images.os.start = (ulong)os_hdr;
Kumar Gala18178bc2008-10-21 17:25:45 -0500320 images.state = BOOTM_STATE_START;
wdenk47d1a6e2002-11-03 00:01:44 +0000321
Kumar Galabd70bbe2008-08-15 08:24:41 -0500322 return 0;
323}
Markus Klotzbücher09197cb2008-07-10 14:47:09 +0200324
Kumar Galabd70bbe2008-08-15 08:24:41 -0500325#define BOOTM_ERR_RESET -1
326#define BOOTM_ERR_OVERLAP -2
327#define BOOTM_ERR_UNIMPLEMENTED -3
328static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
329{
330 uint8_t comp = os.comp;
331 ulong load = os.load;
332 ulong blob_start = os.start;
333 ulong blob_end = os.end;
334 ulong image_start = os.image_start;
335 ulong image_len = os.image_len;
Anatolij Gustschin18e73d92011-11-19 13:12:18 +0000336 __maybe_unused uint unc_len = CONFIG_SYS_BOOTM_LEN;
Stephen Warrenf66131d2011-11-10 13:17:54 -0700337 int no_overlap = 0;
Matthias Weisserc8bb9632010-08-05 13:17:30 +0200338#if defined(CONFIG_LZMA) || defined(CONFIG_LZO)
339 int ret;
340#endif /* defined(CONFIG_LZMA) || defined(CONFIG_LZO) */
Markus Klotzbücher09197cb2008-07-10 14:47:09 +0200341
Stephen Warren6904b6e2011-10-18 11:11:49 +0000342 const char *type_name = genimg_get_type_name(os.type);
wdenk452cfd62002-11-19 11:04:11 +0000343
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100344 switch (comp) {
wdenk47d1a6e2002-11-03 00:01:44 +0000345 case IH_COMP_NONE:
Lei Wen8790b9e2011-01-10 18:21:15 +0800346 if (load == blob_start || load == image_start) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000347 printf(" XIP %s ... ", type_name);
Stephen Warrenf66131d2011-11-10 13:17:54 -0700348 no_overlap = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000349 } else {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000350 printf(" Loading %s ... ", type_name);
351 memmove_wd((void *)load, (void *)image_start,
Larry Johnsone4551002010-04-20 08:09:43 -0400352 image_len, CHUNKSZ);
wdenk47d1a6e2002-11-03 00:01:44 +0000353 }
Kumar Galabd70bbe2008-08-15 08:24:41 -0500354 *load_end = load + image_len;
Guennadi Liakhovetski3110cf82008-07-31 12:35:04 +0200355 puts("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000356 break;
Mike Frysingerab427ae2010-01-21 19:30:36 -0500357#ifdef CONFIG_GZIP
wdenk47d1a6e2002-11-03 00:01:44 +0000358 case IH_COMP_GZIP:
Stephen Warren6904b6e2011-10-18 11:11:49 +0000359 printf(" Uncompressing %s ... ", type_name);
360 if (gunzip((void *)load, unc_len,
361 (uchar *)image_start, &image_len) != 0) {
362 puts("GUNZIP: uncompress, out-of-mem or overwrite "
363 "error - must RESET board to recover\n");
Kumar Galabd70bbe2008-08-15 08:24:41 -0500364 if (boot_progress)
Simon Glass0169e6b2012-02-13 13:51:18 +0000365 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500366 return BOOTM_ERR_RESET;
wdenk47d1a6e2002-11-03 00:01:44 +0000367 }
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100368
Kumar Galabd70bbe2008-08-15 08:24:41 -0500369 *load_end = load + image_len;
wdenk47d1a6e2002-11-03 00:01:44 +0000370 break;
Mike Frysingerab427ae2010-01-21 19:30:36 -0500371#endif /* CONFIG_GZIP */
wdenk710e3502003-08-29 20:57:53 +0000372#ifdef CONFIG_BZIP2
373 case IH_COMP_BZIP2:
Stephen Warren6904b6e2011-10-18 11:11:49 +0000374 printf(" Uncompressing %s ... ", type_name);
wdenk2cefd152004-02-08 22:55:38 +0000375 /*
376 * If we've got less than 4 MB of malloc() space,
377 * use slower decompression algorithm which requires
378 * at most 2300 KB of memory.
379 */
Stephen Warren6904b6e2011-10-18 11:11:49 +0000380 int i = BZ2_bzBuffToBuffDecompress((char *)load,
Kumar Galabd70bbe2008-08-15 08:24:41 -0500381 &unc_len, (char *)image_start, image_len,
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200382 CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
wdenk710e3502003-08-29 20:57:53 +0000383 if (i != BZ_OK) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000384 printf("BUNZIP2: uncompress or overwrite error %d "
Marian Balakowiczb5324a82008-03-12 10:33:01 +0100385 "- must RESET board to recover\n", i);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500386 if (boot_progress)
Simon Glass0169e6b2012-02-13 13:51:18 +0000387 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500388 return BOOTM_ERR_RESET;
wdenk710e3502003-08-29 20:57:53 +0000389 }
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100390
Kumar Galabd70bbe2008-08-15 08:24:41 -0500391 *load_end = load + unc_len;
wdenk710e3502003-08-29 20:57:53 +0000392 break;
393#endif /* CONFIG_BZIP2 */
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200394#ifdef CONFIG_LZMA
Mike Frysingerb41ad242010-07-25 15:54:17 -0400395 case IH_COMP_LZMA: {
396 SizeT lzma_len = unc_len;
Stephen Warren6904b6e2011-10-18 11:11:49 +0000397 printf(" Uncompressing %s ... ", type_name);
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200398
Matthias Weisserc8bb9632010-08-05 13:17:30 +0200399 ret = lzmaBuffToBuffDecompress(
Mike Frysingerb41ad242010-07-25 15:54:17 -0400400 (unsigned char *)load, &lzma_len,
Luigi 'Comio' Mantellini22834672008-09-13 10:04:32 +0200401 (unsigned char *)image_start, image_len);
Mike Frysingerb41ad242010-07-25 15:54:17 -0400402 unc_len = lzma_len;
Luigi 'Comio' Mantellinid02bd742009-07-21 10:45:49 +0200403 if (ret != SZ_OK) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000404 printf("LZMA: uncompress or overwrite error %d "
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200405 "- must RESET board to recover\n", ret);
Simon Glass0169e6b2012-02-13 13:51:18 +0000406 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200407 return BOOTM_ERR_RESET;
408 }
409 *load_end = load + unc_len;
410 break;
Mike Frysingerb41ad242010-07-25 15:54:17 -0400411 }
Luigi 'Comio' Mantellini35afc062008-09-08 02:46:13 +0200412#endif /* CONFIG_LZMA */
Peter Korsgaardf7440cd2009-11-19 11:37:51 +0100413#ifdef CONFIG_LZO
414 case IH_COMP_LZO:
Stephen Warren6904b6e2011-10-18 11:11:49 +0000415 printf(" Uncompressing %s ... ", type_name);
Peter Korsgaardf7440cd2009-11-19 11:37:51 +0100416
Matthias Weisserc8bb9632010-08-05 13:17:30 +0200417 ret = lzop_decompress((const unsigned char *)image_start,
Peter Korsgaardf7440cd2009-11-19 11:37:51 +0100418 image_len, (unsigned char *)load,
419 &unc_len);
420 if (ret != LZO_E_OK) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000421 printf("LZO: uncompress or overwrite error %d "
Peter Korsgaardf7440cd2009-11-19 11:37:51 +0100422 "- must RESET board to recover\n", ret);
423 if (boot_progress)
Simon Glass0169e6b2012-02-13 13:51:18 +0000424 bootstage_error(BOOTSTAGE_ID_DECOMP_IMAGE);
Peter Korsgaardf7440cd2009-11-19 11:37:51 +0100425 return BOOTM_ERR_RESET;
426 }
427
428 *load_end = load + unc_len;
429 break;
430#endif /* CONFIG_LZO */
wdenk47d1a6e2002-11-03 00:01:44 +0000431 default:
Stephen Warren6904b6e2011-10-18 11:11:49 +0000432 printf("Unimplemented compression type %d\n", comp);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500433 return BOOTM_ERR_UNIMPLEMENTED;
wdenk47d1a6e2002-11-03 00:01:44 +0000434 }
Diana CRACIUN4b2fbe42011-08-31 02:45:23 +0000435
436 flush_cache(load, (*load_end - load) * sizeof(ulong));
437
Stephen Warren6904b6e2011-10-18 11:11:49 +0000438 puts("OK\n");
439 debug(" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
Simon Glass0169e6b2012-02-13 13:51:18 +0000440 bootstage_mark(BOOTSTAGE_ID_KERNEL_LOADED);
wdenk47d1a6e2002-11-03 00:01:44 +0000441
Stephen Warrenf66131d2011-11-10 13:17:54 -0700442 if (!no_overlap && (load < blob_end) && (*load_end > blob_start)) {
Stephen Warren6904b6e2011-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);
wdenk47d1a6e2002-11-03 00:01:44 +0000447
Kumar Galabd70bbe2008-08-15 08:24:41 -0500448 return BOOTM_ERR_OVERLAP;
449 }
450
451 return 0;
452}
453
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200454static int bootm_start_standalone(ulong iflag, int argc, char * const argv[])
Detlev Zundelea32b5e2009-07-13 16:01:19 +0200455{
456 char *s;
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200457 int (*appl)(int, char * const []);
Detlev Zundelea32b5e2009-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 Glass103789d2013-02-24 17:33:22 +0000461 setenv_hex("filesize", images.os.image_len);
Detlev Zundelea32b5e2009-07-13 16:01:19 +0200462 return 0;
463 }
Simon Glass81afc3d2011-10-07 13:53:40 +0000464 appl = (int (*)(int, char * const []))(ulong)ntohl(images.ep);
Detlev Zundelea32b5e2009-07-13 16:01:19 +0200465 (*appl)(argc-1, &argv[1]);
Detlev Zundelea32b5e2009-07-13 16:01:19 +0200466 return 0;
467}
468
Kumar Gala18178bc2008-10-21 17:25:45 -0500469/* we overload the cmd field with our state machine info instead of a
470 * function pointer */
Frans Meulenbroeks6b419fb2010-02-25 10:12:13 +0100471static cmd_tbl_t cmd_bootm_sub[] = {
Kumar Gala18178bc2008-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 Rigbyeea8e692010-10-13 13:57:35 -0600474#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
Kumar Gala18178bc2008-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 Gala18178bc2008-10-21 17:25:45 -0500480 U_BOOT_CMD_MKENT(cmdline, 0, 1, (void *)BOOTM_STATE_OS_CMDLINE, "", ""),
Peter Tyser694a3932009-11-18 19:08:59 -0600481 U_BOOT_CMD_MKENT(bdt, 0, 1, (void *)BOOTM_STATE_OS_BD_T, "", ""),
Kumar Gala18178bc2008-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 Phillipsdc00a682012-10-29 13:34:31 +0000486static int do_bootm_subcommand(cmd_tbl_t *cmdtp, int flag, int argc,
Stephen Warren6904b6e2011-10-18 11:11:49 +0000487 char * const argv[])
Kumar Gala18178bc2008-10-21 17:25:45 -0500488{
489 int ret = 0;
Simon Glass81afc3d2011-10-07 13:53:40 +0000490 long state;
Kumar Gala18178bc2008-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 Glass81afc3d2011-10-07 13:53:40 +0000497 state = (long)c->cmd;
Kumar Gala18178bc2008-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 Denk3b683112010-07-17 01:06:04 +0200505 } else {
506 /* Unrecognized command */
Simon Glassa06dfc72011-12-10 08:44:01 +0000507 return CMD_RET_USAGE;
Kumar Gala18178bc2008-10-21 17:25:45 -0500508 }
509
Gabor Juhos6f732bc2013-01-06 23:04:25 +0000510 if (images.state < BOOTM_STATE_START ||
511 images.state >= state) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000512 printf("Trying to execute a command out of order\n");
Simon Glassa06dfc72011-12-10 08:44:01 +0000513 return CMD_RET_USAGE;
Kumar Gala18178bc2008-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 Rigbyeea8e692010-10-13 13:57:35 -0600532#ifdef CONFIG_SYS_BOOT_RAMDISK_HIGH
Kumar Gala18178bc2008-10-21 17:25:45 -0500533 case BOOTM_STATE_RAMDISK:
534 {
535 ulong rd_len = images.rd_end - images.rd_start;
Kumar Gala18178bc2008-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 Glass103789d2013-02-24 17:33:22 +0000542 setenv_hex("initrd_start", images.initrd_start);
543 setenv_hex("initrd_end", images.initrd_end);
Kumar Gala18178bc2008-10-21 17:25:45 -0500544 }
545 break;
546#endif
Simon Glass8ee5d6c2012-12-05 14:46:31 +0000547#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_LMB)
Kumar Gala18178bc2008-10-21 17:25:45 -0500548 case BOOTM_STATE_FDT:
549 {
Grant Likely20f54922011-03-28 09:59:01 +0000550 boot_fdt_add_mem_rsv_regions(&images.lmb,
551 images.ft_addr);
Grant Likelydfff7a22011-03-28 09:58:34 +0000552 ret = boot_relocate_fdt(&images.lmb,
Kumar Gala18178bc2008-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 Warren6904b6e2011-10-18 11:11:49 +0000560 printf("cmdline subcommand not supported\n");
Kumar Gala18178bc2008-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 Warren6904b6e2011-10-18 11:11:49 +0000565 printf("bdt subcommand not supported\n");
Kumar Gala18178bc2008-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 Warren6904b6e2011-10-18 11:11:49 +0000570 printf("prep subcommand not supported\n");
Kumar Gala18178bc2008-10-21 17:25:45 -0500571 break;
572 case BOOTM_STATE_OS_GO:
573 disable_interrupts();
Joe Hershberger9f374062012-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 Gala5e726692009-08-27 08:23:55 -0500581 arch_preboot_os();
Kumar Gala18178bc2008-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 Galabd70bbe2008-08-15 08:24:41 -0500589/*******************************************************************/
590/* bootm - boot application image from image in memory */
591/*******************************************************************/
Kumar Galabf3954f2008-10-21 17:25:44 -0500592
Stephen Warren6904b6e2011-10-18 11:11:49 +0000593int do_bootm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Kumar Galabd70bbe2008-08-15 08:24:41 -0500594{
Kumar Galabd70bbe2008-08-15 08:24:41 -0500595 ulong iflag;
596 ulong load_end = 0;
597 int ret;
Kumar Galabf3954f2008-10-21 17:25:44 -0500598 boot_os_fn *boot_fn;
Wolfgang Denkd0813e52010-10-28 20:00:11 +0200599#ifdef CONFIG_NEEDS_MANUAL_RELOC
Peter Tyser9057cbf2009-09-21 11:20:36 -0500600 static int relocated = 0;
Kumar Galabf3954f2008-10-21 17:25:44 -0500601
Kumar Galabf3954f2008-10-21 17:25:44 -0500602 if (!relocated) {
603 int i;
Daniel Schwierzecka2187092013-01-07 06:54:52 +0000604
605 /* relocate boot function table */
Kumar Galabf3954f2008-10-21 17:25:44 -0500606 for (i = 0; i < ARRAY_SIZE(boot_os); i++)
Detlev Zundel77094472009-07-13 16:01:18 +0200607 if (boot_os[i] != NULL)
608 boot_os[i] += gd->reloc_off;
Daniel Schwierzecka2187092013-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 Galabf3954f2008-10-21 17:25:44 -0500614 relocated = 1;
615 }
Peter Tyser9057cbf2009-09-21 11:20:36 -0500616#endif
Kumar Galabd70bbe2008-08-15 08:24:41 -0500617
Kumar Gala18178bc2008-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 Gustschin128de002008-08-29 21:04:45 +0200635 if (bootm_start(cmdtp, flag, argc, argv))
636 return 1;
Kumar Galabd70bbe2008-08-15 08:24:41 -0500637
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 */
643 iflag = disable_interrupts();
644
Joe Hershberger9f374062012-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
Kumar Galabd70bbe2008-08-15 08:24:41 -0500650#if defined(CONFIG_CMD_USB)
651 /*
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 */
660 usb_stop();
661#endif
662
Kumar Galabd70bbe2008-08-15 08:24:41 -0500663 ret = bootm_load_os(images.os, &load_end, 1);
664
665 if (ret < 0) {
666 if (ret == BOOTM_ERR_RESET)
Stephen Warren6904b6e2011-10-18 11:11:49 +0000667 do_reset(cmdtp, flag, argc, argv);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500668 if (ret == BOOTM_ERR_OVERLAP) {
669 if (images.legacy_hdr_valid) {
Stephen Warren6904b6e2011-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 Galabd70bbe2008-08-15 08:24:41 -0500676 } else {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000677 puts("ERROR: new format image overwritten - "
Kumar Galabd70bbe2008-08-15 08:24:41 -0500678 "must RESET the board to recover\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000679 bootstage_error(BOOTSTAGE_ID_OVERWRITTEN);
Stephen Warren6904b6e2011-10-18 11:11:49 +0000680 do_reset(cmdtp, flag, argc, argv);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500681 }
682 }
683 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
684 if (iflag)
685 enable_interrupts();
Simon Glass0169e6b2012-02-13 13:51:18 +0000686 bootstage_error(BOOTSTAGE_ID_DECOMP_UNIMPL);
Kumar Galabd70bbe2008-08-15 08:24:41 -0500687 return 1;
Marian Balakowiczab00e022008-04-11 11:07:49 +0200688 }
wdenk47d1a6e2002-11-03 00:01:44 +0000689 }
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100690
Kumar Galabd70bbe2008-08-15 08:24:41 -0500691 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
wdenk47d1a6e2002-11-03 00:01:44 +0000692
Detlev Zundelea32b5e2009-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 Glass0169e6b2012-02-13 13:51:18 +0000701 bootstage_mark(BOOTSTAGE_ID_CHECK_BOOT_OS);
Kumar Gala6d7bfa82008-02-27 21:51:47 -0600702
Joe Hershberger01c2d982013-02-27 10:20:59 +0000703#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
Kumar Galabf3954f2008-10-21 17:25:44 -0500704 if (images.os.os == IH_OS_LINUX)
705 fixup_silent_linux();
wdenk808532a2003-10-10 10:05:42 +0000706#endif
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100707
Kumar Galabf3954f2008-10-21 17:25:44 -0500708 boot_fn = boot_os[images.os.os];
Detlev Zundel77094472009-07-13 16:01:18 +0200709
710 if (boot_fn == NULL) {
711 if (iflag)
712 enable_interrupts();
Stephen Warren6904b6e2011-10-18 11:11:49 +0000713 printf("ERROR: booting os '%s' (%d) is not supported\n",
Detlev Zundel77094472009-07-13 16:01:18 +0200714 genimg_get_os_name(images.os.os), images.os.os);
Simon Glass0169e6b2012-02-13 13:51:18 +0000715 bootstage_error(BOOTSTAGE_ID_CHECK_BOOT_OS);
Detlev Zundel77094472009-07-13 16:01:18 +0200716 return 1;
717 }
718
Kumar Gala5e726692009-08-27 08:23:55 -0500719 arch_preboot_os();
720
Kumar Galabf3954f2008-10-21 17:25:44 -0500721 boot_fn(0, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000722
Simon Glass0169e6b2012-02-13 13:51:18 +0000723 bootstage_error(BOOTSTAGE_ID_BOOT_OS_RETURNED);
wdenk47d1a6e2002-11-03 00:01:44 +0000724#ifdef DEBUG
Stephen Warren6904b6e2011-10-18 11:11:49 +0000725 puts("\n## Control returned to monitor - resetting...\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000726#endif
Stephen Warren6904b6e2011-10-18 11:11:49 +0000727 do_reset(cmdtp, flag, argc, argv);
Marian Balakowicz9c220262008-03-12 10:14:57 +0100728
wdenk47d1a6e2002-11-03 00:01:44 +0000729 return 1;
730}
731
Mike Frysinger194c2e82011-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 Balakowiczc40032c2008-01-31 13:59:09 +0100747/**
Marian Balakowiczd7c88a42008-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 Balakowiczc40032c2008-01-31 13:59:09 +0100751 *
Marian Balakowiczd7c88a42008-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 Balakowiczc40032c2008-01-31 13:59:09 +0100754 *
755 * returns:
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100756 * pointer to a legacy image header if valid image was found
757 * otherwise return NULL
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100758 */
Stephen Warren6904b6e2011-10-18 11:11:49 +0000759static image_header_t *image_get_kernel(ulong img_addr, int verify)
wdenk808532a2003-10-10 10:05:42 +0000760{
Marian Balakowicz59504f62008-02-27 11:02:07 +0100761 image_header_t *hdr = (image_header_t *)img_addr;
wdenk808532a2003-10-10 10:05:42 +0000762
Marian Balakowicz59504f62008-02-27 11:02:07 +0100763 if (!image_check_magic(hdr)) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000764 puts("Bad Magic Number\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000765 bootstage_error(BOOTSTAGE_ID_CHECK_MAGIC);
Marian Balakowicz59504f62008-02-27 11:02:07 +0100766 return NULL;
767 }
Simon Glass0169e6b2012-02-13 13:51:18 +0000768 bootstage_mark(BOOTSTAGE_ID_CHECK_HEADER);
wdenk808532a2003-10-10 10:05:42 +0000769
Stephen Warren6904b6e2011-10-18 11:11:49 +0000770 if (!image_check_hcrc(hdr)) {
771 puts("Bad Header Checksum\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000772 bootstage_error(BOOTSTAGE_ID_CHECK_HEADER);
Marian Balakowicz59504f62008-02-27 11:02:07 +0100773 return NULL;
774 }
775
Simon Glass0169e6b2012-02-13 13:51:18 +0000776 bootstage_mark(BOOTSTAGE_ID_CHECK_CHECKSUM);
Stephen Warren6904b6e2011-10-18 11:11:49 +0000777 image_print_contents(hdr);
Marian Balakowicz59504f62008-02-27 11:02:07 +0100778
779 if (verify) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000780 puts(" Verifying Checksum ... ");
781 if (!image_check_dcrc(hdr)) {
782 printf("Bad Data CRC\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000783 bootstage_error(BOOTSTAGE_ID_CHECK_CHECKSUM);
Marian Balakowicz59504f62008-02-27 11:02:07 +0100784 return NULL;
wdenk808532a2003-10-10 10:05:42 +0000785 }
Stephen Warren6904b6e2011-10-18 11:11:49 +0000786 puts("OK\n");
wdenk808532a2003-10-10 10:05:42 +0000787 }
Simon Glass0169e6b2012-02-13 13:51:18 +0000788 bootstage_mark(BOOTSTAGE_ID_CHECK_ARCH);
wdenk808532a2003-10-10 10:05:42 +0000789
Stephen Warren6904b6e2011-10-18 11:11:49 +0000790 if (!image_check_target_arch(hdr)) {
791 printf("Unsupported Architecture 0x%x\n", image_get_arch(hdr));
Simon Glass0169e6b2012-02-13 13:51:18 +0000792 bootstage_error(BOOTSTAGE_ID_CHECK_ARCH);
Marian Balakowicz59504f62008-02-27 11:02:07 +0100793 return NULL;
794 }
795 return hdr;
wdenk808532a2003-10-10 10:05:42 +0000796}
wdenk808532a2003-10-10 10:05:42 +0000797
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100798/**
799 * 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 Warren6904b6e2011-10-18 11:11:49 +0000811#if defined(CONFIG_FIT)
812static int fit_check_kernel(const void *fit, int os_noffset, int verify)
wdenk47d1a6e2002-11-03 00:01:44 +0000813{
Stephen Warren6904b6e2011-10-18 11:11:49 +0000814 fit_image_print(fit, os_noffset, " ");
wdenk47d1a6e2002-11-03 00:01:44 +0000815
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100816 if (verify) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000817 puts(" Verifying Hash Integrity ... ");
818 if (!fit_image_check_hashes(fit, os_noffset)) {
819 puts("Bad Data Hash\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000820 bootstage_error(BOOTSTAGE_ID_FIT_CHECK_HASH);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100821 return 0;
822 }
Stephen Warren6904b6e2011-10-18 11:11:49 +0000823 puts("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000824 }
Simon Glass0169e6b2012-02-13 13:51:18 +0000825 bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_ARCH);
wdenk47d1a6e2002-11-03 00:01:44 +0000826
Stephen Warren6904b6e2011-10-18 11:11:49 +0000827 if (!fit_image_check_target_arch(fit, os_noffset)) {
828 puts("Unsupported Architecture\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000829 bootstage_error(BOOTSTAGE_ID_FIT_CHECK_ARCH);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100830 return 0;
831 }
wdenk47d1a6e2002-11-03 00:01:44 +0000832
Simon Glass0169e6b2012-02-13 13:51:18 +0000833 bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_KERNEL);
Stephen Warren8c87eba2011-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 Warren6904b6e2011-10-18 11:11:49 +0000836 puts("Not a kernel image\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000837 bootstage_error(BOOTSTAGE_ID_FIT_CHECK_KERNEL);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100838 return 0;
839 }
wdenk47d1a6e2002-11-03 00:01:44 +0000840
Simon Glass0169e6b2012-02-13 13:51:18 +0000841 bootstage_mark(BOOTSTAGE_ID_FIT_CHECKED);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100842 return 1;
843}
844#endif /* CONFIG_FIT */
wdenk56f94be2002-11-05 16:35:14 +0000845
Marian Balakowicz59504f62008-02-27 11:02:07 +0100846/**
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100847 * boot_get_kernel - find kernel image
Marian Balakowicz59504f62008-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 Balakowiczd7c88a42008-02-29 14:58:34 +0100851 * boot_get_kernel() tries to find a kernel image, verifies its integrity
Marian Balakowicz59504f62008-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 */
Stephen Warren6904b6e2011-10-18 11:11:49 +0000858static void *boot_get_kernel(cmd_tbl_t *cmdtp, int flag, int argc,
859 char * const argv[], bootm_headers_t *images, ulong *os_data,
860 ulong *os_len)
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100861{
862 image_header_t *hdr;
863 ulong img_addr;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100864#if defined(CONFIG_FIT)
865 void *fit_hdr;
866 const char *fit_uname_config = NULL;
867 const char *fit_uname_kernel = NULL;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100868 const void *data;
869 size_t len;
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100870 int cfg_noffset;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100871 int os_noffset;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100872#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000873
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100874 /* find out kernel image address */
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100875 if (argc < 2) {
876 img_addr = load_addr;
Stephen Warren6904b6e2011-10-18 11:11:49 +0000877 debug("* kernel: default image load address = 0x%08lx\n",
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100878 load_addr);
879#if defined(CONFIG_FIT)
Stephen Warren6904b6e2011-10-18 11:11:49 +0000880 } else if (fit_parse_conf(argv[1], load_addr, &img_addr,
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100881 &fit_uname_config)) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000882 debug("* kernel: config '%s' from image at 0x%08lx\n",
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100883 fit_uname_config, img_addr);
Stephen Warren6904b6e2011-10-18 11:11:49 +0000884 } else if (fit_parse_subimage(argv[1], load_addr, &img_addr,
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100885 &fit_uname_kernel)) {
Stephen Warren6904b6e2011-10-18 11:11:49 +0000886 debug("* kernel: subimage '%s' from image at 0x%08lx\n",
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100887 fit_uname_kernel, img_addr);
888#endif
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100889 } else {
890 img_addr = simple_strtoul(argv[1], NULL, 16);
Stephen Warren6904b6e2011-10-18 11:11:49 +0000891 debug("* kernel: cmdline image address = 0x%08lx\n", img_addr);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100892 }
wdenk56f94be2002-11-05 16:35:14 +0000893
Simon Glass0169e6b2012-02-13 13:51:18 +0000894 bootstage_mark(BOOTSTAGE_ID_CHECK_MAGIC);
wdenk47d1a6e2002-11-03 00:01:44 +0000895
Marian Balakowiczc536d6f2008-02-21 17:20:19 +0100896 /* copy from dataflash if needed */
Stephen Warren6904b6e2011-10-18 11:11:49 +0000897 img_addr = genimg_get_image(img_addr);
wdenk47d1a6e2002-11-03 00:01:44 +0000898
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100899 /* check image type, for FIT images get FIT kernel node */
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100900 *os_data = *os_len = 0;
Stephen Warren6904b6e2011-10-18 11:11:49 +0000901 switch (genimg_get_format((void *)img_addr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100902 case IMAGE_FORMAT_LEGACY:
Stephen Warren6904b6e2011-10-18 11:11:49 +0000903 printf("## Booting kernel from Legacy Image at %08lx ...\n",
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100904 img_addr);
Stephen Warren6904b6e2011-10-18 11:11:49 +0000905 hdr = image_get_kernel(img_addr, images->verify);
Marian Balakowicz59504f62008-02-27 11:02:07 +0100906 if (!hdr)
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100907 return NULL;
Simon Glass0169e6b2012-02-13 13:51:18 +0000908 bootstage_mark(BOOTSTAGE_ID_CHECK_IMAGETYPE);
wdenk47d1a6e2002-11-03 00:01:44 +0000909
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100910 /* get os_data and os_len */
Stephen Warren6904b6e2011-10-18 11:11:49 +0000911 switch (image_get_type(hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100912 case IH_TYPE_KERNEL:
Stephen Warren8c87eba2011-11-10 13:17:53 -0700913 case IH_TYPE_KERNEL_NOLOAD:
Stephen Warren6904b6e2011-10-18 11:11:49 +0000914 *os_data = image_get_data(hdr);
915 *os_len = image_get_data_size(hdr);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100916 break;
917 case IH_TYPE_MULTI:
Stephen Warren6904b6e2011-10-18 11:11:49 +0000918 image_multi_getimg(hdr, 0, os_data, os_len);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100919 break;
Detlev Zundelea32b5e2009-07-13 16:01:19 +0200920 case IH_TYPE_STANDALONE:
Stephen Warren6904b6e2011-10-18 11:11:49 +0000921 *os_data = image_get_data(hdr);
922 *os_len = image_get_data_size(hdr);
Detlev Zundelea32b5e2009-07-13 16:01:19 +0200923 break;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100924 default:
Stephen Warren6904b6e2011-10-18 11:11:49 +0000925 printf("Wrong Image Type for %s command\n",
926 cmdtp->name);
Simon Glass0169e6b2012-02-13 13:51:18 +0000927 bootstage_error(BOOTSTAGE_ID_CHECK_IMAGETYPE);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100928 return NULL;
929 }
Marian Balakowiczab00e022008-04-11 11:07:49 +0200930
931 /*
Stephen Warren6904b6e2011-10-18 11:11:49 +0000932 * copy image header to allow for image overwrites during
933 * kernel decompression.
Marian Balakowiczab00e022008-04-11 11:07:49 +0200934 */
Stephen Warren6904b6e2011-10-18 11:11:49 +0000935 memmove(&images->legacy_hdr_os_copy, hdr,
936 sizeof(image_header_t));
Marian Balakowiczab00e022008-04-11 11:07:49 +0200937
938 /* save pointer to image header */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100939 images->legacy_hdr_os = hdr;
wdenk47d1a6e2002-11-03 00:01:44 +0000940
Marian Balakowiczab00e022008-04-11 11:07:49 +0200941 images->legacy_hdr_valid = 1;
Simon Glass0169e6b2012-02-13 13:51:18 +0000942 bootstage_mark(BOOTSTAGE_ID_DECOMP_IMAGE);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100943 break;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100944#if defined(CONFIG_FIT)
945 case IMAGE_FORMAT_FIT:
946 fit_hdr = (void *)img_addr;
Stephen Warren6904b6e2011-10-18 11:11:49 +0000947 printf("## Booting kernel from FIT Image at %08lx ...\n",
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100948 img_addr);
wdenk47d1a6e2002-11-03 00:01:44 +0000949
Stephen Warren6904b6e2011-10-18 11:11:49 +0000950 if (!fit_check_format(fit_hdr)) {
951 puts("Bad FIT kernel image format!\n");
Simon Glass0169e6b2012-02-13 13:51:18 +0000952 bootstage_error(BOOTSTAGE_ID_FIT_FORMAT);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100953 return NULL;
954 }
Simon Glass0169e6b2012-02-13 13:51:18 +0000955 bootstage_mark(BOOTSTAGE_ID_FIT_FORMAT);
wdenk47d1a6e2002-11-03 00:01:44 +0000956
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100957 if (!fit_uname_kernel) {
958 /*
959 * no kernel image node unit name, try to get config
960 * node first. If config unit node name is NULL
Stephen Warren6904b6e2011-10-18 11:11:49 +0000961 * fit_conf_get_node() will try to find default config
962 * node
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100963 */
Simon Glass0169e6b2012-02-13 13:51:18 +0000964 bootstage_mark(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
Gabe Blackd572e162012-10-25 16:31:10 +0000965#ifdef CONFIG_FIT_BEST_MATCH
966 if (fit_uname_config)
967 cfg_noffset =
968 fit_conf_get_node(fit_hdr,
969 fit_uname_config);
970 else
971 cfg_noffset =
972 fit_conf_find_compat(fit_hdr,
973 gd->fdt_blob);
974#else
Stephen Warren6904b6e2011-10-18 11:11:49 +0000975 cfg_noffset = fit_conf_get_node(fit_hdr,
976 fit_uname_config);
Gabe Blackd572e162012-10-25 16:31:10 +0000977#endif
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100978 if (cfg_noffset < 0) {
Simon Glass0169e6b2012-02-13 13:51:18 +0000979 bootstage_error(BOOTSTAGE_ID_FIT_NO_UNIT_NAME);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100980 return NULL;
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100981 }
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100982 /* save configuration uname provided in the first
983 * bootm argument
984 */
Stephen Warren6904b6e2011-10-18 11:11:49 +0000985 images->fit_uname_cfg = fdt_get_name(fit_hdr,
986 cfg_noffset,
987 NULL);
988 printf(" Using '%s' configuration\n",
989 images->fit_uname_cfg);
Simon Glass0169e6b2012-02-13 13:51:18 +0000990 bootstage_mark(BOOTSTAGE_ID_FIT_CONFIG);
wdenk47d1a6e2002-11-03 00:01:44 +0000991
Stephen Warren6904b6e2011-10-18 11:11:49 +0000992 os_noffset = fit_conf_get_kernel_node(fit_hdr,
993 cfg_noffset);
994 fit_uname_kernel = fit_get_name(fit_hdr, os_noffset,
995 NULL);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100996 } else {
997 /* get kernel component image node offset */
Simon Glass0169e6b2012-02-13 13:51:18 +0000998 bootstage_mark(BOOTSTAGE_ID_FIT_UNIT_NAME);
Stephen Warren6904b6e2011-10-18 11:11:49 +0000999 os_noffset = fit_image_get_node(fit_hdr,
1000 fit_uname_kernel);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +01001001 }
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +01001002 if (os_noffset < 0) {
Simon Glass0169e6b2012-02-13 13:51:18 +00001003 bootstage_error(BOOTSTAGE_ID_FIT_CONFIG);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +01001004 return NULL;
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +01001005 }
wdenk47d1a6e2002-11-03 00:01:44 +00001006
Stephen Warren6904b6e2011-10-18 11:11:49 +00001007 printf(" Trying '%s' kernel subimage\n", fit_uname_kernel);
wdenk47d1a6e2002-11-03 00:01:44 +00001008
Simon Glass0169e6b2012-02-13 13:51:18 +00001009 bootstage_mark(BOOTSTAGE_ID_FIT_CHECK_SUBIMAGE);
Stephen Warren6904b6e2011-10-18 11:11:49 +00001010 if (!fit_check_kernel(fit_hdr, os_noffset, images->verify))
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +01001011 return NULL;
Matthew McClintock6fb7c812006-06-28 10:41:37 -05001012
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +01001013 /* get kernel image data address and length */
Stephen Warren6904b6e2011-10-18 11:11:49 +00001014 if (fit_image_get_data(fit_hdr, os_noffset, &data, &len)) {
1015 puts("Could not find kernel subimage data!\n");
Simon Glass0169e6b2012-02-13 13:51:18 +00001016 bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO_ERR);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +01001017 return NULL;
Matthew McClintock6fb7c812006-06-28 10:41:37 -05001018 }
Simon Glass0169e6b2012-02-13 13:51:18 +00001019 bootstage_mark(BOOTSTAGE_ID_FIT_KERNEL_INFO);
wdenk47d1a6e2002-11-03 00:01:44 +00001020
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +01001021 *os_len = len;
1022 *os_data = (ulong)data;
1023 images->fit_hdr_os = fit_hdr;
1024 images->fit_uname_os = fit_uname_kernel;
Marian Balakowicz61c1ad52008-03-12 10:32:59 +01001025 images->fit_noffset_os = os_noffset;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +01001026 break;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001027#endif
Marian Balakowiczc40032c2008-01-31 13:59:09 +01001028 default:
Stephen Warren6904b6e2011-10-18 11:11:49 +00001029 printf("Wrong Image Format for %s command\n", cmdtp->name);
Simon Glass0169e6b2012-02-13 13:51:18 +00001030 bootstage_error(BOOTSTAGE_ID_FIT_KERNEL_INFO);
Marian Balakowiczc40032c2008-01-31 13:59:09 +01001031 return NULL;
1032 }
wdenk47d1a6e2002-11-03 00:01:44 +00001033
Stephen Warren6904b6e2011-10-18 11:11:49 +00001034 debug(" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +01001035 *os_data, *os_len, *os_len);
wdenk47d1a6e2002-11-03 00:01:44 +00001036
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001037 return (void *)img_addr;
Marian Balakowiczc40032c2008-01-31 13:59:09 +01001038}
wdenk47d1a6e2002-11-03 00:01:44 +00001039
Kim Phillipsdc00a682012-10-29 13:34:31 +00001040#ifdef CONFIG_SYS_LONGHELP
1041static char bootm_help_text[] =
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001042 "[addr [arg ...]]\n - boot application image stored in memory\n"
1043 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
1044 "\t'arg' can be the address of an initrd image\n"
Marian Balakowiczd2160852008-01-31 13:20:07 +01001045#if defined(CONFIG_OF_LIBFDT)
wdenk47d1a6e2002-11-03 00:01:44 +00001046 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
1047 "\ta third argument is required which is the address of the\n"
1048 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1049 "\tuse a '-' for the second argument. If you do not pass a third\n"
1050 "\ta bd_info struct will be passed instead\n"
1051#endif
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +01001052#if defined(CONFIG_FIT)
1053 "\t\nFor the new multi component uImage format (FIT) addresses\n"
1054 "\tmust be extened to include component or configuration unit name:\n"
1055 "\taddr:<subimg_uname> - direct component image specification\n"
1056 "\taddr#<conf_uname> - configuration specification\n"
1057 "\tUse iminfo command to get the list of existing component\n"
1058 "\timages and configurations.\n"
1059#endif
Kumar Gala18178bc2008-10-21 17:25:45 -05001060 "\nSub-commands to do part of the bootm sequence. The sub-commands "
1061 "must be\n"
1062 "issued in the order below (it's ok to not issue all sub-commands):\n"
1063 "\tstart [addr [arg ...]]\n"
1064 "\tloados - load OS image\n"
Daniel Schwierzeckf2f2ec92013-02-26 04:54:19 +00001065#if defined(CONFIG_SYS_BOOT_RAMDISK_HIGH)
Kumar Gala18178bc2008-10-21 17:25:45 -05001066 "\tramdisk - relocate initrd, set env initrd_start/initrd_end\n"
1067#endif
1068#if defined(CONFIG_OF_LIBFDT)
1069 "\tfdt - relocate flat device tree\n"
1070#endif
Kumar Gala18178bc2008-10-21 17:25:45 -05001071 "\tcmdline - OS specific command line processing/setup\n"
Peter Tyser694a3932009-11-18 19:08:59 -06001072 "\tbdt - OS specific bd_t processing\n"
Kumar Gala18178bc2008-10-21 17:25:45 -05001073 "\tprep - OS specific prep before relocation or go\n"
Kim Phillipsdc00a682012-10-29 13:34:31 +00001074 "\tgo - start OS";
1075#endif
1076
1077U_BOOT_CMD(
1078 bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
1079 "boot application image from memory", bootm_help_text
wdenk47d1a6e2002-11-03 00:01:44 +00001080);
wdenk47d1a6e2002-11-03 00:01:44 +00001081
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001082/*******************************************************************/
1083/* bootd - boot default image */
1084/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -05001085#if defined(CONFIG_CMD_BOOTD)
Stephen Warren6904b6e2011-10-18 11:11:49 +00001086int do_bootd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk47d1a6e2002-11-03 00:01:44 +00001087{
1088 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +00001089
Simon Glassbf8c5b02012-02-14 19:59:21 +00001090 if (run_command(getenv("bootcmd"), flag) < 0)
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001091 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001092 return rcode;
1093}
wdenk47d1a6e2002-11-03 00:01:44 +00001094
wdenkf287a242003-07-01 21:06:45 +00001095U_BOOT_CMD(
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001096 boot, 1, 1, do_bootd,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001097 "boot default, i.e., run 'bootcmd'",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001098 ""
wdenk3086a972003-06-28 23:11:04 +00001099);
wdenk47d1a6e2002-11-03 00:01:44 +00001100
wdenk3086a972003-06-28 23:11:04 +00001101/* keep old command name "bootd" for backward compatibility */
wdenkf287a242003-07-01 21:06:45 +00001102U_BOOT_CMD(
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001103 bootd, 1, 1, do_bootd,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001104 "boot default, i.e., run 'bootcmd'",
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001105 ""
wdenk57b2d802003-06-27 21:31:46 +00001106);
wdenk47d1a6e2002-11-03 00:01:44 +00001107
wdenk47d1a6e2002-11-03 00:01:44 +00001108#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001109
wdenk47d1a6e2002-11-03 00:01:44 +00001110
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001111/*******************************************************************/
1112/* iminfo - print header info for a requested image */
1113/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -05001114#if defined(CONFIG_CMD_IMI)
Kim Phillipsdc00a682012-10-29 13:34:31 +00001115static int do_iminfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
wdenk47d1a6e2002-11-03 00:01:44 +00001116{
1117 int arg;
1118 ulong addr;
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001119 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +00001120
wdenk47d1a6e2002-11-03 00:01:44 +00001121 if (argc < 2) {
Stephen Warren6904b6e2011-10-18 11:11:49 +00001122 return image_info(load_addr);
wdenk47d1a6e2002-11-03 00:01:44 +00001123 }
wdenk47d1a6e2002-11-03 00:01:44 +00001124
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001125 for (arg = 1; arg < argc; ++arg) {
Stephen Warren6904b6e2011-10-18 11:11:49 +00001126 addr = simple_strtoul(argv[arg], NULL, 16);
1127 if (image_info(addr) != 0)
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001128 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001129 }
1130 return rcode;
1131}
wdenk47d1a6e2002-11-03 00:01:44 +00001132
Stephen Warren6904b6e2011-10-18 11:11:49 +00001133static int image_info(ulong addr)
wdenk47d1a6e2002-11-03 00:01:44 +00001134{
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001135 void *hdr = (void *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +00001136
Stephen Warren6904b6e2011-10-18 11:11:49 +00001137 printf("\n## Checking Image at %08lx ...\n", addr);
wdenk47d1a6e2002-11-03 00:01:44 +00001138
Stephen Warren6904b6e2011-10-18 11:11:49 +00001139 switch (genimg_get_format(hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001140 case IMAGE_FORMAT_LEGACY:
Stephen Warren6904b6e2011-10-18 11:11:49 +00001141 puts(" Legacy image found\n");
1142 if (!image_check_magic(hdr)) {
1143 puts(" Bad Magic Number\n");
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001144 return 1;
1145 }
wdenk47d1a6e2002-11-03 00:01:44 +00001146
Stephen Warren6904b6e2011-10-18 11:11:49 +00001147 if (!image_check_hcrc(hdr)) {
1148 puts(" Bad Header Checksum\n");
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001149 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001150 }
1151
Stephen Warren6904b6e2011-10-18 11:11:49 +00001152 image_print_contents(hdr);
wdenk47d1a6e2002-11-03 00:01:44 +00001153
Stephen Warren6904b6e2011-10-18 11:11:49 +00001154 puts(" Verifying Checksum ... ");
1155 if (!image_check_dcrc(hdr)) {
1156 puts(" Bad Data CRC\n");
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001157 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001158 }
Stephen Warren6904b6e2011-10-18 11:11:49 +00001159 puts("OK\n");
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001160 return 0;
1161#if defined(CONFIG_FIT)
1162 case IMAGE_FORMAT_FIT:
Stephen Warren6904b6e2011-10-18 11:11:49 +00001163 puts(" FIT image found\n");
wdenk47d1a6e2002-11-03 00:01:44 +00001164
Stephen Warren6904b6e2011-10-18 11:11:49 +00001165 if (!fit_check_format(hdr)) {
1166 puts("Bad FIT image format!\n");
Marian Balakowiczcc1fd912008-03-11 12:35:20 +01001167 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001168 }
1169
Stephen Warren6904b6e2011-10-18 11:11:49 +00001170 fit_print_contents(hdr);
Bartlomiej Sieka03797f52008-09-09 12:58:16 +02001171
Stephen Warren6904b6e2011-10-18 11:11:49 +00001172 if (!fit_all_image_check_hashes(hdr)) {
1173 puts("Bad hash in FIT image!\n");
Bartlomiej Sieka03797f52008-09-09 12:58:16 +02001174 return 1;
1175 }
1176
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001177 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +00001178#endif
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001179 default:
Stephen Warren6904b6e2011-10-18 11:11:49 +00001180 puts("Unknown image format!\n");
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001181 break;
wdenk47d1a6e2002-11-03 00:01:44 +00001182 }
wdenk47d1a6e2002-11-03 00:01:44 +00001183
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001184 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001185}
wdenk47d1a6e2002-11-03 00:01:44 +00001186
wdenkf287a242003-07-01 21:06:45 +00001187U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001188 iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001189 "print header information for application image",
wdenk57b2d802003-06-27 21:31:46 +00001190 "addr [addr ...]\n"
1191 " - print header information for application image starting at\n"
1192 " address 'addr' in memory; this includes verification of the\n"
Wolfgang Denkc54781c2009-05-24 17:06:54 +02001193 " image contents (magic number, header and payload checksums)"
wdenk57b2d802003-06-27 21:31:46 +00001194);
wdenk47d1a6e2002-11-03 00:01:44 +00001195#endif
1196
1197
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001198/*******************************************************************/
1199/* imls - list all images found in flash */
1200/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -05001201#if defined(CONFIG_CMD_IMLS)
Vipin Kumar3df41b12012-12-16 22:32:48 +00001202static int do_imls_nor(void)
wdenk874ac262003-07-24 23:38:38 +00001203{
1204 flash_info_t *info;
1205 int i, j;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001206 void *hdr;
wdenk47d1a6e2002-11-03 00:01:44 +00001207
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001208 for (i = 0, info = &flash_info[0];
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +02001209 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
wdenk47d1a6e2002-11-03 00:01:44 +00001210
wdenk874ac262003-07-24 23:38:38 +00001211 if (info->flash_id == FLASH_UNKNOWN)
1212 goto next_bank;
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001213 for (j = 0; j < info->sector_count; ++j) {
wdenk47d1a6e2002-11-03 00:01:44 +00001214
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001215 hdr = (void *)info->start[j];
1216 if (!hdr)
Marian Balakowicz41d71ed2008-01-08 18:14:09 +01001217 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +00001218
Stephen Warren6904b6e2011-10-18 11:11:49 +00001219 switch (genimg_get_format(hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001220 case IMAGE_FORMAT_LEGACY:
Stephen Warren6904b6e2011-10-18 11:11:49 +00001221 if (!image_check_hcrc(hdr))
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001222 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +00001223
Stephen Warren6904b6e2011-10-18 11:11:49 +00001224 printf("Legacy Image at %08lX:\n", (ulong)hdr);
1225 image_print_contents(hdr);
wdenk47d1a6e2002-11-03 00:01:44 +00001226
Stephen Warren6904b6e2011-10-18 11:11:49 +00001227 puts(" Verifying Checksum ... ");
1228 if (!image_check_dcrc(hdr)) {
1229 puts("Bad Data CRC\n");
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001230 } else {
Stephen Warren6904b6e2011-10-18 11:11:49 +00001231 puts("OK\n");
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001232 }
1233 break;
1234#if defined(CONFIG_FIT)
1235 case IMAGE_FORMAT_FIT:
Stephen Warren6904b6e2011-10-18 11:11:49 +00001236 if (!fit_check_format(hdr))
Marian Balakowiczcc1fd912008-03-11 12:35:20 +01001237 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +00001238
Stephen Warren6904b6e2011-10-18 11:11:49 +00001239 printf("FIT Image at %08lX:\n", (ulong)hdr);
1240 fit_print_contents(hdr);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001241 break;
1242#endif
1243 default:
1244 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +00001245 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001246
wdenk0a658552003-08-05 17:43:17 +00001247next_sector: ;
wdenk47d1a6e2002-11-03 00:01:44 +00001248 }
wdenk0a658552003-08-05 17:43:17 +00001249next_bank: ;
wdenk47d1a6e2002-11-03 00:01:44 +00001250 }
Vipin Kumar3df41b12012-12-16 22:32:48 +00001251 return 0;
1252}
1253#endif
1254
1255#if defined(CONFIG_CMD_IMLS_NAND)
1256static int nand_imls_legacyimage(nand_info_t *nand, int nand_dev, loff_t off,
1257 size_t len)
1258{
1259 void *imgdata;
1260 int ret;
1261
1262 imgdata = malloc(len);
1263 if (!imgdata) {
1264 printf("May be a Legacy Image at NAND device %d offset %08llX:\n",
1265 nand_dev, off);
1266 printf(" Low memory(cannot allocate memory for image)\n");
1267 return -ENOMEM;
1268 }
1269
1270 ret = nand_read_skip_bad(nand, off, &len,
1271 imgdata);
1272 if (ret < 0 && ret != -EUCLEAN) {
1273 free(imgdata);
1274 return ret;
1275 }
1276
1277 if (!image_check_hcrc(imgdata)) {
1278 free(imgdata);
1279 return 0;
1280 }
1281
1282 printf("Legacy Image at NAND device %d offset %08llX:\n",
1283 nand_dev, off);
1284 image_print_contents(imgdata);
1285
1286 puts(" Verifying Checksum ... ");
1287 if (!image_check_dcrc(imgdata))
1288 puts("Bad Data CRC\n");
1289 else
1290 puts("OK\n");
1291
1292 free(imgdata);
1293
1294 return 0;
1295}
1296
1297static int nand_imls_fitimage(nand_info_t *nand, int nand_dev, loff_t off,
1298 size_t len)
1299{
1300 void *imgdata;
1301 int ret;
1302
1303 imgdata = malloc(len);
1304 if (!imgdata) {
1305 printf("May be a FIT Image at NAND device %d offset %08llX:\n",
1306 nand_dev, off);
1307 printf(" Low memory(cannot allocate memory for image)\n");
1308 return -ENOMEM;
1309 }
wdenk47d1a6e2002-11-03 00:01:44 +00001310
Vipin Kumar3df41b12012-12-16 22:32:48 +00001311 ret = nand_read_skip_bad(nand, off, &len,
1312 imgdata);
1313 if (ret < 0 && ret != -EUCLEAN) {
1314 free(imgdata);
1315 return ret;
1316 }
1317
1318 if (!fit_check_format(imgdata)) {
1319 free(imgdata);
1320 return 0;
1321 }
1322
1323 printf("FIT Image at NAND device %d offset %08llX:\n", nand_dev, off);
1324
1325 fit_print_contents(imgdata);
1326 free(imgdata);
1327
1328 return 0;
1329}
1330
1331static int do_imls_nand(void)
1332{
1333 nand_info_t *nand;
1334 int nand_dev = nand_curr_device;
1335 size_t len;
1336 loff_t off;
1337 u32 buffer[16];
1338
1339 if (nand_dev < 0 || nand_dev >= CONFIG_SYS_MAX_NAND_DEVICE) {
1340 puts("\nNo NAND devices available\n");
1341 return -ENODEV;
1342 }
1343
1344 printf("\n");
1345
1346 for (nand_dev = 0; nand_dev < CONFIG_SYS_MAX_NAND_DEVICE; nand_dev++) {
1347 nand = &nand_info[nand_dev];
1348 if (!nand->name || !nand->size)
1349 continue;
1350
1351 for (off = 0; off < nand->size; off += nand->erasesize) {
1352 const image_header_t *header;
1353 int ret;
1354
1355 if (nand_block_isbad(nand, off))
1356 continue;
1357
1358 len = sizeof(buffer);
1359
1360 ret = nand_read(nand, off, &len, (u8 *)buffer);
1361 if (ret < 0 && ret != -EUCLEAN) {
1362 printf("NAND read error %d at offset %08llX\n",
1363 ret, off);
1364 continue;
1365 }
1366
1367 switch (genimg_get_format(buffer)) {
1368 case IMAGE_FORMAT_LEGACY:
1369 header = (const image_header_t *)buffer;
1370
1371 len = image_get_image_size(header);
1372 nand_imls_legacyimage(nand, nand_dev, off, len);
1373 break;
1374#if defined(CONFIG_FIT)
1375 case IMAGE_FORMAT_FIT:
1376 len = fit_get_size(buffer);
1377 nand_imls_fitimage(nand, nand_dev, off, len);
1378 break;
1379#endif
1380 }
1381 }
1382 }
1383
1384 return 0;
1385}
1386#endif
1387
1388#if defined(CONFIG_CMD_IMLS) || defined(CONFIG_CMD_IMLS_NAND)
1389static int do_imls(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1390{
1391 int ret_nor = 0, ret_nand = 0;
1392
1393#if defined(CONFIG_CMD_IMLS)
1394 ret_nor = do_imls_nor();
1395#endif
1396
1397#if defined(CONFIG_CMD_IMLS_NAND)
1398 ret_nand = do_imls_nand();
1399#endif
1400
1401 if (ret_nor)
1402 return ret_nor;
1403
1404 if (ret_nand)
1405 return ret_nand;
1406
wdenk874ac262003-07-24 23:38:38 +00001407 return (0);
1408}
wdenk47d1a6e2002-11-03 00:01:44 +00001409
wdenk874ac262003-07-24 23:38:38 +00001410U_BOOT_CMD(
1411 imls, 1, 1, do_imls,
Peter Tyserdfb72b82009-01-27 18:03:12 -06001412 "list all images found in flash",
wdenk874ac262003-07-24 23:38:38 +00001413 "\n"
Vipin Kumar3df41b12012-12-16 22:32:48 +00001414 " - Prints information about all images found at sector/block\n"
1415 " boundaries in nor/nand flash."
wdenk874ac262003-07-24 23:38:38 +00001416);
wdenk47d1a6e2002-11-03 00:01:44 +00001417#endif
1418
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001419/*******************************************************************/
Marian Balakowiczc40032c2008-01-31 13:59:09 +01001420/* helper routines */
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001421/*******************************************************************/
Joe Hershberger01c2d982013-02-27 10:20:59 +00001422#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
Doug Andersonc76b8342011-10-19 12:30:57 +00001423static void fixup_silent_linux(void)
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001424{
1425 char buf[256], *start, *end;
Doug Andersonc76b8342011-10-19 12:30:57 +00001426 char *cmdline = getenv("bootargs");
wdenk47d1a6e2002-11-03 00:01:44 +00001427
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001428 /* Only fix cmdline when requested */
1429 if (!(gd->flags & GD_FLG_SILENT))
1430 return;
wdenk47d1a6e2002-11-03 00:01:44 +00001431
Doug Andersonc76b8342011-10-19 12:30:57 +00001432 debug("before silent fix-up: %s\n", cmdline);
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001433 if (cmdline) {
Doug Andersonc76b8342011-10-19 12:30:57 +00001434 start = strstr(cmdline, "console=");
1435 if (start) {
1436 end = strchr(start, ' ');
1437 strncpy(buf, cmdline, (start - cmdline + 8));
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001438 if (end)
Doug Andersonc76b8342011-10-19 12:30:57 +00001439 strcpy(buf + (start - cmdline + 8), end);
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001440 else
1441 buf[start - cmdline + 8] = '\0';
1442 } else {
Doug Andersonc76b8342011-10-19 12:30:57 +00001443 strcpy(buf, cmdline);
1444 strcat(buf, " console=");
wdenk47d1a6e2002-11-03 00:01:44 +00001445 }
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001446 } else {
Doug Andersonc76b8342011-10-19 12:30:57 +00001447 strcpy(buf, "console=");
wdenk47d1a6e2002-11-03 00:01:44 +00001448 }
wdenk47d1a6e2002-11-03 00:01:44 +00001449
Doug Andersonc76b8342011-10-19 12:30:57 +00001450 setenv("bootargs", buf);
1451 debug("after silent fix-up: %s\n", buf);
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001452}
1453#endif /* CONFIG_SILENT_CONSOLE */
wdenk47d1a6e2002-11-03 00:01:44 +00001454
wdenk47d1a6e2002-11-03 00:01:44 +00001455
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001456/*******************************************************************/
1457/* OS booting routines */
1458/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +00001459
Kumar Gala697675e2008-10-21 17:25:47 -05001460#ifdef CONFIG_BOOTM_NETBSD
Stephen Warren6904b6e2011-10-18 11:11:49 +00001461static int do_bootm_netbsd(int flag, int argc, char * const argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001462 bootm_headers_t *images)
wdenk92bbe3f2003-04-20 14:04:18 +00001463{
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001464 void (*loader)(bd_t *, image_header_t *, char *, char *);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001465 image_header_t *os_hdr, *hdr;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +01001466 ulong kernel_data, kernel_len;
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001467 char *consdev;
1468 char *cmdline;
wdenk47d1a6e2002-11-03 00:01:44 +00001469
Kumar Gala18178bc2008-10-21 17:25:45 -05001470 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1471 return 1;
1472
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001473#if defined(CONFIG_FIT)
1474 if (!images->legacy_hdr_valid) {
Stephen Warren6904b6e2011-10-18 11:11:49 +00001475 fit_unsupported_reset("NetBSD");
Kumar Gala48626aa2008-08-15 08:24:45 -05001476 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001477 }
1478#endif
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001479 hdr = images->legacy_hdr_os;
wdenk47d1a6e2002-11-03 00:01:44 +00001480
1481 /*
1482 * Booting a (NetBSD) kernel image
1483 *
1484 * This process is pretty similar to a standalone application:
1485 * The (first part of an multi-) image must be a stage-2 loader,
1486 * which in turn is responsible for loading & invoking the actual
1487 * kernel. The only differences are the parameters being passed:
1488 * besides the board info strucure, the loader expects a command
1489 * line, the name of the console device, and (optionally) the
1490 * address of the original image header.
1491 */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001492 os_hdr = NULL;
Stephen Warren6904b6e2011-10-18 11:11:49 +00001493 if (image_check_type(&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
1494 image_multi_getimg(hdr, 1, &kernel_data, &kernel_len);
Marian Balakowiczb4a12a92008-01-08 18:12:17 +01001495 if (kernel_len)
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001496 os_hdr = hdr;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +01001497 }
wdenk47d1a6e2002-11-03 00:01:44 +00001498
1499 consdev = "";
Stephen Warren6904b6e2011-10-18 11:11:49 +00001500#if defined(CONFIG_8xx_CONS_SMC1)
wdenk47d1a6e2002-11-03 00:01:44 +00001501 consdev = "smc1";
Stephen Warren6904b6e2011-10-18 11:11:49 +00001502#elif defined(CONFIG_8xx_CONS_SMC2)
wdenk47d1a6e2002-11-03 00:01:44 +00001503 consdev = "smc2";
Stephen Warren6904b6e2011-10-18 11:11:49 +00001504#elif defined(CONFIG_8xx_CONS_SCC2)
wdenk47d1a6e2002-11-03 00:01:44 +00001505 consdev = "scc2";
Stephen Warren6904b6e2011-10-18 11:11:49 +00001506#elif defined(CONFIG_8xx_CONS_SCC3)
wdenk47d1a6e2002-11-03 00:01:44 +00001507 consdev = "scc3";
1508#endif
1509
1510 if (argc > 2) {
1511 ulong len;
1512 int i;
1513
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001514 for (i = 2, len = 0; i < argc; i += 1)
Stephen Warren6904b6e2011-10-18 11:11:49 +00001515 len += strlen(argv[i]) + 1;
1516 cmdline = malloc(len);
wdenk47d1a6e2002-11-03 00:01:44 +00001517
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001518 for (i = 2, len = 0; i < argc; i += 1) {
wdenk47d1a6e2002-11-03 00:01:44 +00001519 if (i > 2)
1520 cmdline[len++] = ' ';
Stephen Warren6904b6e2011-10-18 11:11:49 +00001521 strcpy(&cmdline[len], argv[i]);
1522 len += strlen(argv[i]);
wdenk47d1a6e2002-11-03 00:01:44 +00001523 }
Stephen Warren6904b6e2011-10-18 11:11:49 +00001524 } else if ((cmdline = getenv("bootargs")) == NULL) {
wdenk47d1a6e2002-11-03 00:01:44 +00001525 cmdline = "";
1526 }
1527
Kumar Gala93467bc2008-08-15 08:24:36 -05001528 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
wdenk47d1a6e2002-11-03 00:01:44 +00001529
Stephen Warren6904b6e2011-10-18 11:11:49 +00001530 printf("## Transferring control to NetBSD stage-2 loader "
1531 "(at address %08lx) ...\n",
wdenk47d1a6e2002-11-03 00:01:44 +00001532 (ulong)loader);
1533
Simon Glass0169e6b2012-02-13 13:51:18 +00001534 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
wdenk47d1a6e2002-11-03 00:01:44 +00001535
1536 /*
1537 * NetBSD Stage-2 Loader Parameters:
1538 * r3: ptr to board info data
1539 * r4: image address
1540 * r5: console device
1541 * r6: boot args string
1542 */
Stephen Warren6904b6e2011-10-18 11:11:49 +00001543 (*loader)(gd->bd, os_hdr, consdev, cmdline);
Kumar Gala48626aa2008-08-15 08:24:45 -05001544
1545 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001546}
Kumar Gala697675e2008-10-21 17:25:47 -05001547#endif /* CONFIG_BOOTM_NETBSD*/
wdenk47d1a6e2002-11-03 00:01:44 +00001548
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001549#ifdef CONFIG_LYNXKDI
Stephen Warren6904b6e2011-10-18 11:11:49 +00001550static int do_bootm_lynxkdi(int flag, int argc, char * const argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001551 bootm_headers_t *images)
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001552{
Marian Balakowiczab00e022008-04-11 11:07:49 +02001553 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001554
Kumar Gala18178bc2008-10-21 17:25:45 -05001555 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1556 return 1;
1557
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001558#if defined(CONFIG_FIT)
1559 if (!images->legacy_hdr_valid) {
Stephen Warren6904b6e2011-10-18 11:11:49 +00001560 fit_unsupported_reset("Lynx");
Kumar Gala48626aa2008-08-15 08:24:45 -05001561 return 1;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001562 }
1563#endif
1564
Stephen Warren6904b6e2011-10-18 11:11:49 +00001565 lynxkdi_boot((image_header_t *)hdr);
Kumar Gala48626aa2008-08-15 08:24:45 -05001566
1567 return 1;
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001568}
1569#endif /* CONFIG_LYNXKDI */
1570
Kumar Gala697675e2008-10-21 17:25:47 -05001571#ifdef CONFIG_BOOTM_RTEMS
Stephen Warren6904b6e2011-10-18 11:11:49 +00001572static int do_bootm_rtems(int flag, int argc, char * const argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001573 bootm_headers_t *images)
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001574{
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001575 void (*entry_point)(bd_t *);
wdenk92bbe3f2003-04-20 14:04:18 +00001576
Kumar Gala18178bc2008-10-21 17:25:45 -05001577 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1578 return 1;
1579
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001580#if defined(CONFIG_FIT)
1581 if (!images->legacy_hdr_valid) {
Stephen Warren6904b6e2011-10-18 11:11:49 +00001582 fit_unsupported_reset("RTEMS");
Kumar Gala48626aa2008-08-15 08:24:45 -05001583 return 1;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001584 }
1585#endif
1586
Kumar Gala93467bc2008-08-15 08:24:36 -05001587 entry_point = (void (*)(bd_t *))images->ep;
wdenk47d1a6e2002-11-03 00:01:44 +00001588
Stephen Warren6904b6e2011-10-18 11:11:49 +00001589 printf("## Transferring control to RTEMS (at address %08lx) ...\n",
wdenk92bbe3f2003-04-20 14:04:18 +00001590 (ulong)entry_point);
wdenk47d1a6e2002-11-03 00:01:44 +00001591
Simon Glass0169e6b2012-02-13 13:51:18 +00001592 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
wdenk92bbe3f2003-04-20 14:04:18 +00001593
1594 /*
1595 * RTEMS Parameters:
1596 * r3: ptr to board info data
1597 */
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001598 (*entry_point)(gd->bd);
Kumar Gala48626aa2008-08-15 08:24:45 -05001599
1600 return 1;
wdenk92bbe3f2003-04-20 14:04:18 +00001601}
Kumar Gala697675e2008-10-21 17:25:47 -05001602#endif /* CONFIG_BOOTM_RTEMS */
wdenk92bbe3f2003-04-20 14:04:18 +00001603
Torkel Lundgren29a58662010-09-28 11:05:36 +02001604#if defined(CONFIG_BOOTM_OSE)
Stephen Warren6904b6e2011-10-18 11:11:49 +00001605static int do_bootm_ose(int flag, int argc, char * const argv[],
Torkel Lundgren29a58662010-09-28 11:05:36 +02001606 bootm_headers_t *images)
1607{
1608 void (*entry_point)(void);
1609
1610 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1611 return 1;
1612
1613#if defined(CONFIG_FIT)
1614 if (!images->legacy_hdr_valid) {
Stephen Warren6904b6e2011-10-18 11:11:49 +00001615 fit_unsupported_reset("OSE");
Torkel Lundgren29a58662010-09-28 11:05:36 +02001616 return 1;
1617 }
1618#endif
1619
1620 entry_point = (void (*)(void))images->ep;
1621
Stephen Warren6904b6e2011-10-18 11:11:49 +00001622 printf("## Transferring control to OSE (at address %08lx) ...\n",
Torkel Lundgren29a58662010-09-28 11:05:36 +02001623 (ulong)entry_point);
1624
Simon Glass0169e6b2012-02-13 13:51:18 +00001625 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
Torkel Lundgren29a58662010-09-28 11:05:36 +02001626
1627 /*
1628 * OSE Parameters:
1629 * None
1630 */
1631 (*entry_point)();
1632
1633 return 1;
1634}
1635#endif /* CONFIG_BOOTM_OSE */
1636
Steven Stallion36ec8ac2013-03-20 06:31:35 +00001637#if defined(CONFIG_BOOTM_PLAN9)
1638static int do_bootm_plan9(int flag, int argc, char * const argv[],
1639 bootm_headers_t *images)
1640{
1641 void (*entry_point)(void);
1642
1643 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1644 return 1;
1645
1646#if defined(CONFIG_FIT)
1647 if (!images->legacy_hdr_valid) {
1648 fit_unsupported_reset("Plan 9");
1649 return 1;
1650 }
1651#endif
1652
1653 entry_point = (void (*)(void))images->ep;
1654
1655 printf("## Transferring control to Plan 9 (at address %08lx) ...\n",
1656 (ulong)entry_point);
1657
1658 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
1659
1660 /*
1661 * Plan 9 Parameters:
1662 * None
1663 */
1664 (*entry_point)();
1665
1666 return 1;
1667}
1668#endif /* CONFIG_BOOTM_PLAN9 */
1669
Jon Loeliger54324d02007-07-08 17:51:39 -05001670#if defined(CONFIG_CMD_ELF)
Stephen Warren6904b6e2011-10-18 11:11:49 +00001671static int do_bootm_vxworks(int flag, int argc, char * const argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001672 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001673{
wdenk47d1a6e2002-11-03 00:01:44 +00001674 char str[80];
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001675
Kumar Gala18178bc2008-10-21 17:25:45 -05001676 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1677 return 1;
1678
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001679#if defined(CONFIG_FIT)
Marian Balakowiczab00e022008-04-11 11:07:49 +02001680 if (!images->legacy_hdr_valid) {
Stephen Warren6904b6e2011-10-18 11:11:49 +00001681 fit_unsupported_reset("VxWorks");
Kumar Gala48626aa2008-08-15 08:24:45 -05001682 return 1;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001683 }
1684#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001685
Kumar Gala93467bc2008-08-15 08:24:36 -05001686 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001687 setenv("loadaddr", str);
Kumar Gala48626aa2008-08-15 08:24:45 -05001688 do_bootvx(NULL, 0, 0, NULL);
1689
1690 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001691}
1692
Wolfgang Denk6262d0212010-06-28 22:00:46 +02001693static int do_bootm_qnxelf(int flag, int argc, char * const argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001694 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001695{
wdenk47d1a6e2002-11-03 00:01:44 +00001696 char *local_args[2];
1697 char str[16];
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001698
Kumar Gala18178bc2008-10-21 17:25:45 -05001699 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1700 return 1;
1701
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001702#if defined(CONFIG_FIT)
1703 if (!images->legacy_hdr_valid) {
Stephen Warren6904b6e2011-10-18 11:11:49 +00001704 fit_unsupported_reset("QNX");
Kumar Gala48626aa2008-08-15 08:24:45 -05001705 return 1;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001706 }
1707#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001708
Kumar Gala93467bc2008-08-15 08:24:36 -05001709 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001710 local_args[0] = argv[0];
1711 local_args[1] = str; /* and provide it via the arguments */
Kumar Gala48626aa2008-08-15 08:24:45 -05001712 do_bootelf(NULL, 0, 2, local_args);
1713
1714 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001715}
Jon Loeligerd704d912007-07-10 11:02:44 -05001716#endif
Peter Tyser56b8dd12008-09-08 14:56:49 -05001717
1718#ifdef CONFIG_INTEGRITY
Stephen Warren6904b6e2011-10-18 11:11:49 +00001719static int do_bootm_integrity(int flag, int argc, char * const argv[],
Peter Tyser56b8dd12008-09-08 14:56:49 -05001720 bootm_headers_t *images)
1721{
1722 void (*entry_point)(void);
1723
Kumar Gala18178bc2008-10-21 17:25:45 -05001724 if ((flag != 0) && (flag != BOOTM_STATE_OS_GO))
1725 return 1;
1726
Peter Tyser56b8dd12008-09-08 14:56:49 -05001727#if defined(CONFIG_FIT)
1728 if (!images->legacy_hdr_valid) {
Stephen Warren6904b6e2011-10-18 11:11:49 +00001729 fit_unsupported_reset("INTEGRITY");
Peter Tyser56b8dd12008-09-08 14:56:49 -05001730 return 1;
1731 }
1732#endif
1733
1734 entry_point = (void (*)(void))images->ep;
1735
Stephen Warren6904b6e2011-10-18 11:11:49 +00001736 printf("## Transferring control to INTEGRITY (at address %08lx) ...\n",
Peter Tyser56b8dd12008-09-08 14:56:49 -05001737 (ulong)entry_point);
1738
Simon Glass0169e6b2012-02-13 13:51:18 +00001739 bootstage_mark(BOOTSTAGE_ID_RUN_OS);
Peter Tyser56b8dd12008-09-08 14:56:49 -05001740
1741 /*
1742 * INTEGRITY Parameters:
1743 * None
1744 */
1745 (*entry_point)();
1746
1747 return 1;
1748}
1749#endif
Marek Vasutcf41a9b2012-03-14 21:52:45 +00001750
1751#ifdef CONFIG_CMD_BOOTZ
1752
1753static int __bootz_setup(void *image, void **start, void **end)
1754{
1755 /* Please define bootz_setup() for your platform */
1756
1757 puts("Your platform's zImage format isn't supported yet!\n");
1758 return -1;
1759}
1760int bootz_setup(void *image, void **start, void **end)
1761 __attribute__((weak, alias("__bootz_setup")));
1762
1763/*
1764 * zImage booting support
1765 */
1766static int bootz_start(cmd_tbl_t *cmdtp, int flag, int argc,
1767 char * const argv[], bootm_headers_t *images)
1768{
1769 int ret;
1770 void *zi_start, *zi_end;
1771
1772 memset(images, 0, sizeof(bootm_headers_t));
1773
1774 boot_start_lmb(images);
1775
1776 /* Setup Linux kernel zImage entry point */
1777 if (argc < 2) {
1778 images->ep = load_addr;
1779 debug("* kernel: default image load address = 0x%08lx\n",
1780 load_addr);
1781 } else {
1782 images->ep = simple_strtoul(argv[1], NULL, 16);
1783 debug("* kernel: cmdline image address = 0x%08lx\n",
1784 images->ep);
1785 }
1786
1787 ret = bootz_setup((void *)images->ep, &zi_start, &zi_end);
1788 if (ret != 0)
1789 return 1;
1790
1791 lmb_reserve(&images->lmb, images->ep, zi_end - zi_start);
1792
1793 /* Find ramdisk */
1794 ret = boot_get_ramdisk(argc, argv, images, IH_INITRD_ARCH,
1795 &images->rd_start, &images->rd_end);
1796 if (ret) {
1797 puts("Ramdisk image is corrupt or invalid\n");
1798 return 1;
1799 }
1800
1801#if defined(CONFIG_OF_LIBFDT)
1802 /* find flattened device tree */
1803 ret = boot_get_fdt(flag, argc, argv, images,
1804 &images->ft_addr, &images->ft_len);
1805 if (ret) {
1806 puts("Could not find a valid device tree\n");
1807 return 1;
1808 }
1809
1810 set_working_fdt_addr(images->ft_addr);
1811#endif
1812
1813 return 0;
1814}
1815
1816static int do_bootz(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
1817{
Marek Vasutcf41a9b2012-03-14 21:52:45 +00001818 bootm_headers_t images;
1819
1820 if (bootz_start(cmdtp, flag, argc, argv, &images))
1821 return 1;
1822
1823 /*
1824 * We have reached the point of no return: we are going to
1825 * overwrite all exception vector code, so we cannot easily
1826 * recover from any failures any more...
1827 */
Anatolij Gustschinc1f87ad2012-05-19 05:38:19 +00001828 disable_interrupts();
Marek Vasutcf41a9b2012-03-14 21:52:45 +00001829
Joe Hershberger9f374062012-08-03 10:59:08 +00001830#ifdef CONFIG_NETCONSOLE
1831 /* Stop the ethernet stack if NetConsole could have left it up */
1832 eth_halt();
1833#endif
1834
Marek Vasutcf41a9b2012-03-14 21:52:45 +00001835#if defined(CONFIG_CMD_USB)
1836 /*
1837 * turn off USB to prevent the host controller from writing to the
1838 * SDRAM while Linux is booting. This could happen (at least for OHCI
1839 * controller), because the HCCA (Host Controller Communication Area)
1840 * lies within the SDRAM and the host controller writes continously to
1841 * this area (as busmaster!). The HccaFrameNumber is for example
1842 * updated every 1 ms within the HCCA structure in SDRAM! For more
1843 * details see the OpenHCI specification.
1844 */
1845 usb_stop();
1846#endif
1847
Joe Hershberger01c2d982013-02-27 10:20:59 +00001848#if defined(CONFIG_SILENT_CONSOLE) && !defined(CONFIG_SILENT_U_BOOT_ONLY)
Marek Vasutcf41a9b2012-03-14 21:52:45 +00001849 fixup_silent_linux();
1850#endif
1851 arch_preboot_os();
1852
1853 do_bootm_linux(0, argc, argv, &images);
1854#ifdef DEBUG
1855 puts("\n## Control returned to monitor - resetting...\n");
1856#endif
1857 do_reset(cmdtp, flag, argc, argv);
1858
1859 return 1;
1860}
1861
Kim Phillipsdc00a682012-10-29 13:34:31 +00001862#ifdef CONFIG_SYS_LONGHELP
1863static char bootz_help_text[] =
Marek Vasut28850d02012-03-18 11:47:58 +00001864 "[addr [initrd[:size]] [fdt]]\n"
1865 " - boot Linux zImage stored in memory\n"
Marek Vasutcf41a9b2012-03-14 21:52:45 +00001866 "\tThe argument 'initrd' is optional and specifies the address\n"
Marek Vasut28850d02012-03-18 11:47:58 +00001867 "\tof the initrd in memory. The optional argument ':size' allows\n"
1868 "\tspecifying the size of RAW initrd.\n"
Marek Vasutcf41a9b2012-03-14 21:52:45 +00001869#if defined(CONFIG_OF_LIBFDT)
1870 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
1871 "\ta third argument is required which is the address of the\n"
1872 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
1873 "\tuse a '-' for the second argument. If you do not pass a third\n"
1874 "\ta bd_info struct will be passed instead\n"
1875#endif
Kim Phillipsdc00a682012-10-29 13:34:31 +00001876 "";
1877#endif
1878
1879U_BOOT_CMD(
1880 bootz, CONFIG_SYS_MAXARGS, 1, do_bootz,
1881 "boot Linux zImage image from memory", bootz_help_text
Marek Vasutcf41a9b2012-03-14 21:52:45 +00001882);
1883#endif /* CONFIG_CMD_BOOTZ */