blob: b87ac49e520b6ec829bd80db32a387d71362e645 [file] [log] [blame]
wdenk47d1a6e2002-11-03 00:01:44 +00001/*
Stefan Roese15940c92006-03-13 11:16:36 +01002 * (C) Copyright 2000-2006
wdenk47d1a6e2002-11-03 00:01:44 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010024
wdenk47d1a6e2002-11-03 00:01:44 +000025/*
26 * Boot support
27 */
28#include <common.h>
29#include <watchdog.h>
30#include <command.h>
wdenk47d1a6e2002-11-03 00:01:44 +000031#include <image.h>
32#include <malloc.h>
33#include <zlib.h>
wdenkc29fdfc2003-08-29 20:57:53 +000034#include <bzlib.h>
wdenk7f70e852003-05-20 14:25:27 +000035#include <environment.h>
Kumar Gala4ed65522008-02-27 21:51:47 -060036#include <lmb.h>
wdenk47d1a6e2002-11-03 00:01:44 +000037#include <asm/byteorder.h>
wdenk8bde7f72003-06-27 21:31:46 +000038
Stefan Roeseebb86c42008-07-30 09:59:51 +020039#if defined(CONFIG_CMD_USB)
Markus Klotzbücher3d71c812008-07-10 14:47:09 +020040#include <usb.h>
41#endif
42
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020043#ifdef CONFIG_SYS_HUSH_PARSER
wdenk47d1a6e2002-11-03 00:01:44 +000044#include <hush.h>
45#endif
46
Kumar Gala54f9c862008-08-15 08:24:39 -050047#if defined(CONFIG_OF_LIBFDT)
48#include <fdt.h>
49#include <libfdt.h>
50#include <fdt_support.h>
51#endif
52
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +020053#ifdef CONFIG_LZMA
54#define _7ZIP_BYTE_DEFINED /* Byte already defined by zlib */
55#include <lzma/LzmaTypes.h>
56#include <lzma/LzmaDecode.h>
57#include <lzma/LzmaTools.h>
58#endif /* CONFIG_LZMA */
59
Marian Balakowicz1ee11802008-01-08 18:17:10 +010060DECLARE_GLOBAL_DATA_PTR;
61
62extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020063#ifndef CONFIG_SYS_BOOTM_LEN
64#define CONFIG_SYS_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
wdenk47d1a6e2002-11-03 00:01:44 +000065#endif
66
Marian Balakowicz321359f2008-01-08 18:11:43 +010067#ifdef CONFIG_BZIP2
68extern void bz_internal_error(int);
wdenk228f29a2002-12-08 09:53:23 +000069#endif
70
Jon Loeligerbaa26db2007-07-08 17:51:39 -050071#if defined(CONFIG_CMD_IMI)
wdenk47d1a6e2002-11-03 00:01:44 +000072static int image_info (unsigned long addr);
73#endif
wdenk27b207f2003-07-24 23:38:38 +000074
Jon Loeligerbaa26db2007-07-08 17:51:39 -050075#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +000076#include <flash.h>
Marian Balakowicze6f2e902005-10-11 19:09:42 +020077extern flash_info_t flash_info[]; /* info for FLASH chips */
wdenk27b207f2003-07-24 23:38:38 +000078static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
79#endif
80
Marian Balakowicz1ee11802008-01-08 18:17:10 +010081#ifdef CONFIG_SILENT_CONSOLE
82static void fixup_silent_linux (void);
wdenk2262cfe2002-11-18 00:14:45 +000083#endif
84
Marian Balakowicz6986a382008-03-12 10:01:05 +010085static image_header_t *image_get_kernel (ulong img_addr, int verify);
86#if defined(CONFIG_FIT)
87static int fit_check_kernel (const void *fit, int os_noffset, int verify);
88#endif
89
Marian Balakowicz9a4daad2008-02-29 14:58:34 +010090static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +010091 bootm_headers_t *images, ulong *os_data, ulong *os_len);
Marian Balakowicz1ee11802008-01-08 18:17:10 +010092extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
wdenk47d1a6e2002-11-03 00:01:44 +000093
wdenk47d1a6e2002-11-03 00:01:44 +000094/*
95 * Continue booting an OS image; caller already has:
96 * - copied image header to global variable `header'
97 * - checked header magic number, checksums (both header & image),
98 * - verified image architecture (PPC) and type (KERNEL or MULTI),
99 * - loaded (first part of) image to header load address,
100 * - disabled interrupts.
101 */
Kumar Gala40d7e992008-08-15 08:24:45 -0500102typedef int boot_os_fn (int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100103 bootm_headers_t *images); /* pointers to os/initrd/fdt */
wdenk47d1a6e2002-11-03 00:01:44 +0000104
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100105extern boot_os_fn do_bootm_linux;
106static boot_os_fn do_bootm_netbsd;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100107#if defined(CONFIG_LYNXKDI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100108static boot_os_fn do_bootm_lynxkdi;
109extern void lynxkdi_boot (image_header_t *);
wdenk8bde7f72003-06-27 21:31:46 +0000110#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100111static boot_os_fn do_bootm_rtems;
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500112#if defined(CONFIG_CMD_ELF)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100113static boot_os_fn do_bootm_vxworks;
114static boot_os_fn do_bootm_qnxelf;
115int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
116int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
Jon Loeliger90253172007-07-10 11:02:44 -0500117#endif
Peter Tyserf5ed9e32008-09-08 14:56:49 -0500118#if defined(CONFIG_INTEGRITY)
119static boot_os_fn do_bootm_integrity;
120#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000121
Kumar Galabe083152008-10-21 17:25:44 -0500122boot_os_fn * boot_os[] = {
123 [IH_OS_LINUX] = do_bootm_linux,
124 [IH_OS_NETBSD] = do_bootm_netbsd,
125#ifdef CONFIG_LYNXKDI
126 [IH_OS_LYNXOS] = do_bootm_lynxkdi,
127#endif
128 [IH_OS_RTEMS] = do_bootm_rtems,
129#if defined(CONFIG_CMD_ELF)
130 [IH_OS_VXWORKS] = do_bootm_vxworks,
131 [IH_OS_QNX] = do_bootm_qnxelf,
132#endif
133#ifdef CONFIG_INTEGRITY
134 [IH_OS_INTEGRITY] = do_bootm_integrity,
135#endif
136};
137
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200138ulong load_addr = CONFIG_SYS_LOAD_ADDR; /* Default Load Address */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100139static bootm_headers_t images; /* pointers to os/initrd/fdt images */
Stefan Roese15940c92006-03-13 11:16:36 +0100140
Kumar Galae822d7f2008-02-27 21:51:49 -0600141void __board_lmb_reserve(struct lmb *lmb)
142{
143 /* please define platform specific board_lmb_reserve() */
144}
145void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
wdenk47d1a6e2002-11-03 00:01:44 +0000146
Kumar Gala76da19d2008-10-16 21:52:08 -0500147void __arch_lmb_reserve(struct lmb *lmb)
148{
149 /* please define platform specific arch_lmb_reserve() */
150}
151void arch_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__arch_lmb_reserve")));
152
Kumar Galac4f94192008-08-15 08:24:37 -0500153#if defined(__ARM__)
154 #define IH_INITRD_ARCH IH_ARCH_ARM
155#elif defined(__avr32__)
156 #define IH_INITRD_ARCH IH_ARCH_AVR32
157#elif defined(__bfin__)
158 #define IH_INITRD_ARCH IH_ARCH_BLACKFIN
159#elif defined(__I386__)
160 #define IH_INITRD_ARCH IH_ARCH_I386
161#elif defined(__M68K__)
162 #define IH_INITRD_ARCH IH_ARCH_M68K
163#elif defined(__microblaze__)
164 #define IH_INITRD_ARCH IH_ARCH_MICROBLAZE
165#elif defined(__mips__)
166 #define IH_INITRD_ARCH IH_ARCH_MIPS
167#elif defined(__nios__)
168 #define IH_INITRD_ARCH IH_ARCH_NIOS
169#elif defined(__nios2__)
170 #define IH_INITRD_ARCH IH_ARCH_NIOS2
171#elif defined(__PPC__)
172 #define IH_INITRD_ARCH IH_ARCH_PPC
173#elif defined(__sh__)
174 #define IH_INITRD_ARCH IH_ARCH_SH
175#elif defined(__sparc__)
176 #define IH_INITRD_ARCH IH_ARCH_SPARC
177#else
178# error Unknown CPU type
179#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000180
Kumar Gala396f6352008-08-15 08:24:41 -0500181static int bootm_start(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000182{
Becky Bruce391fd932008-06-09 20:37:18 -0500183 ulong mem_start;
184 phys_size_t mem_size;
Kumar Gala396f6352008-08-15 08:24:41 -0500185 void *os_hdr;
Kumar Galac4f94192008-08-15 08:24:37 -0500186 int ret;
wdenk47d1a6e2002-11-03 00:01:44 +0000187
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100188 memset ((void *)&images, 0, sizeof (images));
Bartlomiej Siekaedbed242008-04-18 12:39:23 +0200189 images.verify = getenv_yesno ("verify");
wdenk47d1a6e2002-11-03 00:01:44 +0000190
Kumar Galae906cfa2008-08-15 08:24:40 -0500191 lmb_init(&images.lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000192
Kumar Galad3f2fa02008-02-27 21:51:50 -0600193 mem_start = getenv_bootm_low();
194 mem_size = getenv_bootm_size();
wdenk47d1a6e2002-11-03 00:01:44 +0000195
Kumar Galae906cfa2008-08-15 08:24:40 -0500196 lmb_add(&images.lmb, (phys_addr_t)mem_start, mem_size);
wdenk47d1a6e2002-11-03 00:01:44 +0000197
Kumar Gala76da19d2008-10-16 21:52:08 -0500198 arch_lmb_reserve(&images.lmb);
Kumar Galae906cfa2008-08-15 08:24:40 -0500199 board_lmb_reserve(&images.lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000200
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100201 /* get kernel image header, start address and length */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100202 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
Kumar Gala396f6352008-08-15 08:24:41 -0500203 &images, &images.os.image_start, &images.os.image_len);
204 if (images.os.image_len == 0) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100205 puts ("ERROR: can't get kernel image!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000206 return 1;
207 }
wdenk47d1a6e2002-11-03 00:01:44 +0000208
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100209 /* get image parameters */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100210 switch (genimg_get_format (os_hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100211 case IMAGE_FORMAT_LEGACY:
Kumar Gala396f6352008-08-15 08:24:41 -0500212 images.os.type = image_get_type (os_hdr);
213 images.os.comp = image_get_comp (os_hdr);
214 images.os.os = image_get_os (os_hdr);
Wolfgang Denkbccae902005-10-06 01:50:50 +0200215
Kumar Gala396f6352008-08-15 08:24:41 -0500216 images.os.end = image_get_image_end (os_hdr);
217 images.os.load = image_get_load (os_hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100218 break;
219#if defined(CONFIG_FIT)
220 case IMAGE_FORMAT_FIT:
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100221 if (fit_image_get_type (images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500222 images.fit_noffset_os, &images.os.type)) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100223 puts ("Can't get image type!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100224 show_boot_progress (-109);
wdenk47d1a6e2002-11-03 00:01:44 +0000225 return 1;
226 }
wdenk47d1a6e2002-11-03 00:01:44 +0000227
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100228 if (fit_image_get_comp (images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500229 images.fit_noffset_os, &images.os.comp)) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100230 puts ("Can't get image compression!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100231 show_boot_progress (-110);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100232 return 1;
233 }
wdenk47d1a6e2002-11-03 00:01:44 +0000234
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100235 if (fit_image_get_os (images.fit_hdr_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500236 images.fit_noffset_os, &images.os.os)) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100237 puts ("Can't get image OS!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100238 show_boot_progress (-111);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100239 return 1;
240 }
wdenk47d1a6e2002-11-03 00:01:44 +0000241
Kumar Gala396f6352008-08-15 08:24:41 -0500242 images.os.end = fit_get_end (images.fit_hdr_os);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100243
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100244 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
Kumar Gala396f6352008-08-15 08:24:41 -0500245 &images.os.load)) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100246 puts ("Can't get image load address!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100247 show_boot_progress (-112);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100248 return 1;
wdenkb13fb012003-10-30 21:49:38 +0000249 }
250 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100251#endif
252 default:
253 puts ("ERROR: unknown image format type!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000254 return 1;
255 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100256
Kumar Galac160a952008-08-15 08:24:36 -0500257 /* find kernel entry point */
258 if (images.legacy_hdr_valid) {
259 images.ep = image_get_ep (&images.legacy_hdr_os_copy);
260#if defined(CONFIG_FIT)
261 } else if (images.fit_uname_os) {
262 ret = fit_image_get_entry (images.fit_hdr_os,
263 images.fit_noffset_os, &images.ep);
264 if (ret) {
265 puts ("Can't get entry point property!\n");
266 return 1;
267 }
268#endif
269 } else {
270 puts ("Could not find kernel entry point!\n");
271 return 1;
272 }
273
Kumar Gala396f6352008-08-15 08:24:41 -0500274 if (images.os.os == IH_OS_LINUX) {
Kumar Galac4f94192008-08-15 08:24:37 -0500275 /* find ramdisk */
276 ret = boot_get_ramdisk (argc, argv, &images, IH_INITRD_ARCH,
277 &images.rd_start, &images.rd_end);
278 if (ret) {
Kumar Galaea86b9e2008-08-29 19:08:29 -0500279 puts ("Ramdisk image is corrupt or invalid\n");
Kumar Galac4f94192008-08-15 08:24:37 -0500280 return 1;
281 }
Kumar Gala06a09912008-08-15 08:24:38 -0500282
283#if defined(CONFIG_OF_LIBFDT)
Jean-Christophe PLAGNIOL-VILLARD1d9af0b2008-09-09 22:18:23 +0200284#if defined(CONFIG_PPC) || defined(CONFIG_M68K) || defined(CONFIG_SPARC)
Kumar Gala06a09912008-08-15 08:24:38 -0500285 /* find flattened device tree */
286 ret = boot_get_fdt (flag, argc, argv, &images,
287 &images.ft_addr, &images.ft_len);
288 if (ret) {
289 puts ("Could not find a valid device tree\n");
290 return 1;
291 }
Kumar Gala54f9c862008-08-15 08:24:39 -0500292
293 set_working_fdt_addr(images.ft_addr);
Kumar Gala06a09912008-08-15 08:24:38 -0500294#endif
Jean-Christophe PLAGNIOL-VILLARD1d9af0b2008-09-09 22:18:23 +0200295#endif
Kumar Galac4f94192008-08-15 08:24:37 -0500296 }
297
Kumar Gala396f6352008-08-15 08:24:41 -0500298 images.os.start = (ulong)os_hdr;
299 images.valid = 1;
300
301 return 0;
302}
303
304#define BOOTM_ERR_RESET -1
305#define BOOTM_ERR_OVERLAP -2
306#define BOOTM_ERR_UNIMPLEMENTED -3
307static int bootm_load_os(image_info_t os, ulong *load_end, int boot_progress)
308{
309 uint8_t comp = os.comp;
310 ulong load = os.load;
311 ulong blob_start = os.start;
312 ulong blob_end = os.end;
313 ulong image_start = os.image_start;
314 ulong image_len = os.image_len;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200315 uint unc_len = CONFIG_SYS_BOOTM_LEN;
Kumar Gala396f6352008-08-15 08:24:41 -0500316
317 const char *type_name = genimg_get_type_name (os.type);
318
319 switch (comp) {
320 case IH_COMP_NONE:
321 if (load == blob_start) {
322 printf (" XIP %s ... ", type_name);
323 } else {
324 printf (" Loading %s ... ", type_name);
325
326 memmove_wd ((void *)load,
327 (void *)image_start, image_len, CHUNKSZ);
328 }
329 *load_end = load + image_len;
330 puts("OK\n");
331 break;
332 case IH_COMP_GZIP:
333 printf (" Uncompressing %s ... ", type_name);
334 if (gunzip ((void *)load, unc_len,
335 (uchar *)image_start, &image_len) != 0) {
336 puts ("GUNZIP: uncompress or overwrite error "
337 "- must RESET board to recover\n");
338 if (boot_progress)
339 show_boot_progress (-6);
340 return BOOTM_ERR_RESET;
341 }
342
343 *load_end = load + image_len;
344 break;
345#ifdef CONFIG_BZIP2
346 case IH_COMP_BZIP2:
347 printf (" Uncompressing %s ... ", type_name);
348 /*
349 * If we've got less than 4 MB of malloc() space,
350 * use slower decompression algorithm which requires
351 * at most 2300 KB of memory.
352 */
353 int i = BZ2_bzBuffToBuffDecompress ((char*)load,
354 &unc_len, (char *)image_start, image_len,
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200355 CONFIG_SYS_MALLOC_LEN < (4096 * 1024), 0);
Kumar Gala396f6352008-08-15 08:24:41 -0500356 if (i != BZ_OK) {
357 printf ("BUNZIP2: uncompress or overwrite error %d "
358 "- must RESET board to recover\n", i);
359 if (boot_progress)
360 show_boot_progress (-6);
361 return BOOTM_ERR_RESET;
362 }
363
364 *load_end = load + unc_len;
365 break;
366#endif /* CONFIG_BZIP2 */
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200367#ifdef CONFIG_LZMA
368 case IH_COMP_LZMA:
369 printf (" Uncompressing %s ... ", type_name);
370
371 int ret = lzmaBuffToBuffDecompress(
372 (unsigned char *)load, &unc_len,
Luigi 'Comio' Mantellinid977a572008-09-13 10:04:32 +0200373 (unsigned char *)image_start, image_len);
Luigi 'Comio' Mantellinifc9c1722008-09-08 02:46:13 +0200374 if (ret != LZMA_RESULT_OK) {
375 printf ("LZMA: uncompress or overwrite error %d "
376 "- must RESET board to recover\n", ret);
377 show_boot_progress (-6);
378 return BOOTM_ERR_RESET;
379 }
380 *load_end = load + unc_len;
381 break;
382#endif /* CONFIG_LZMA */
Kumar Gala396f6352008-08-15 08:24:41 -0500383 default:
384 printf ("Unimplemented compression type %d\n", comp);
385 return BOOTM_ERR_UNIMPLEMENTED;
386 }
387 puts ("OK\n");
Jean-Christophe PLAGNIOL-VILLARD54b4ab32008-09-09 22:18:24 +0200388 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load, *load_end);
Kumar Gala396f6352008-08-15 08:24:41 -0500389 if (boot_progress)
390 show_boot_progress (7);
391
392 if ((load < blob_end) && (*load_end > blob_start)) {
393 debug ("images.os.start = 0x%lX, images.os.end = 0x%lx\n", blob_start, blob_end);
Jean-Christophe PLAGNIOL-VILLARD54b4ab32008-09-09 22:18:24 +0200394 debug ("images.os.load = 0x%lx, load_end = 0x%lx\n", load, *load_end);
Kumar Gala396f6352008-08-15 08:24:41 -0500395
396 return BOOTM_ERR_OVERLAP;
397 }
398
399 return 0;
400}
401
402/*******************************************************************/
403/* bootm - boot application image from image in memory */
404/*******************************************************************/
Kumar Galabe083152008-10-21 17:25:44 -0500405static int relocated = 0;
406
Kumar Gala396f6352008-08-15 08:24:41 -0500407int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
408{
Kumar Gala396f6352008-08-15 08:24:41 -0500409 ulong iflag;
410 ulong load_end = 0;
411 int ret;
Kumar Galabe083152008-10-21 17:25:44 -0500412 boot_os_fn *boot_fn;
413
414 /* relocate boot function table */
415 if (!relocated) {
416 int i;
417 for (i = 0; i < ARRAY_SIZE(boot_os); i++)
418 boot_os[i] += gd->reloc_off;
419 relocated = 1;
420 }
Kumar Gala396f6352008-08-15 08:24:41 -0500421
Anatolij Gustschin8e024942008-08-29 21:04:45 +0200422 if (bootm_start(cmdtp, flag, argc, argv))
423 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000424
425 /*
426 * We have reached the point of no return: we are going to
427 * overwrite all exception vector code, so we cannot easily
428 * recover from any failures any more...
429 */
wdenk47d1a6e2002-11-03 00:01:44 +0000430 iflag = disable_interrupts();
431
Stefan Roeseebb86c42008-07-30 09:59:51 +0200432#if defined(CONFIG_CMD_USB)
Wolfgang Denk699f0512008-07-15 22:22:44 +0200433 /*
434 * turn off USB to prevent the host controller from writing to the
435 * SDRAM while Linux is booting. This could happen (at least for OHCI
436 * controller), because the HCCA (Host Controller Communication Area)
437 * lies within the SDRAM and the host controller writes continously to
438 * this area (as busmaster!). The HccaFrameNumber is for example
439 * updated every 1 ms within the HCCA structure in SDRAM! For more
440 * details see the OpenHCI specification.
441 */
Markus Klotzbücher3d71c812008-07-10 14:47:09 +0200442 usb_stop();
443#endif
444
wdenkc7de8292002-11-19 11:04:11 +0000445#ifdef CONFIG_AMIGAONEG3SE
446 /*
wdenk8bde7f72003-06-27 21:31:46 +0000447 * We've possible left the caches enabled during
wdenkc7de8292002-11-19 11:04:11 +0000448 * bios emulation, so turn them off again
449 */
450 icache_disable();
wdenkc7de8292002-11-19 11:04:11 +0000451 dcache_disable();
452#endif
453
Kumar Gala396f6352008-08-15 08:24:41 -0500454 ret = bootm_load_os(images.os, &load_end, 1);
wdenk47d1a6e2002-11-03 00:01:44 +0000455
Kumar Gala396f6352008-08-15 08:24:41 -0500456 if (ret < 0) {
457 if (ret == BOOTM_ERR_RESET)
wdenk47d1a6e2002-11-03 00:01:44 +0000458 do_reset (cmdtp, flag, argc, argv);
Kumar Gala396f6352008-08-15 08:24:41 -0500459 if (ret == BOOTM_ERR_OVERLAP) {
460 if (images.legacy_hdr_valid) {
461 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
462 puts ("WARNING: legacy format multi component "
463 "image overwritten\n");
464 } else {
465 puts ("ERROR: new format image overwritten - "
466 "must RESET the board to recover\n");
467 show_boot_progress (-113);
468 do_reset (cmdtp, flag, argc, argv);
469 }
wdenk47d1a6e2002-11-03 00:01:44 +0000470 }
Kumar Gala396f6352008-08-15 08:24:41 -0500471 if (ret == BOOTM_ERR_UNIMPLEMENTED) {
472 if (iflag)
473 enable_interrupts();
474 show_boot_progress (-7);
475 return 1;
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200476 }
wdenk47d1a6e2002-11-03 00:01:44 +0000477 }
Marian Balakowicz75824382008-01-31 13:20:06 +0100478
Kumar Gala396f6352008-08-15 08:24:41 -0500479 lmb_reserve(&images.lmb, images.os.load, (load_end - images.os.load));
480
Heiko Schocherfad63402007-07-13 09:54:17 +0200481 show_boot_progress (8);
wdenk47d1a6e2002-11-03 00:01:44 +0000482
wdenkf72da342003-10-10 10:05:42 +0000483#ifdef CONFIG_SILENT_CONSOLE
Kumar Galabe083152008-10-21 17:25:44 -0500484 if (images.os.os == IH_OS_LINUX)
485 fixup_silent_linux();
wdenk1f4bb372003-07-27 00:21:01 +0000486#endif
487
Kumar Galabe083152008-10-21 17:25:44 -0500488 boot_fn = boot_os[images.os.os];
489 boot_fn(0, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000490
Heiko Schocherfad63402007-07-13 09:54:17 +0200491 show_boot_progress (-9);
wdenk47d1a6e2002-11-03 00:01:44 +0000492#ifdef DEBUG
wdenk4b9206e2004-03-23 22:14:11 +0000493 puts ("\n## Control returned to monitor - resetting...\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000494#endif
Kumar Gala40d7e992008-08-15 08:24:45 -0500495 do_reset (cmdtp, flag, argc, argv);
Marian Balakowicza44a2692008-03-12 10:14:57 +0100496
wdenk47d1a6e2002-11-03 00:01:44 +0000497 return 1;
498}
499
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100500/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100501 * image_get_kernel - verify legacy format kernel image
502 * @img_addr: in RAM address of the legacy format image to be verified
503 * @verify: data CRC verification flag
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100504 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100505 * image_get_kernel() verifies legacy image integrity and returns pointer to
506 * legacy image header if image verification was completed successfully.
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100507 *
508 * returns:
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100509 * pointer to a legacy image header if valid image was found
510 * otherwise return NULL
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100511 */
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100512static image_header_t *image_get_kernel (ulong img_addr, int verify)
513{
514 image_header_t *hdr = (image_header_t *)img_addr;
515
516 if (!image_check_magic(hdr)) {
517 puts ("Bad Magic Number\n");
518 show_boot_progress (-1);
519 return NULL;
520 }
521 show_boot_progress (2);
522
523 if (!image_check_hcrc (hdr)) {
524 puts ("Bad Header Checksum\n");
525 show_boot_progress (-2);
526 return NULL;
527 }
528
529 show_boot_progress (3);
530 image_print_contents (hdr);
531
532 if (verify) {
533 puts (" Verifying Checksum ... ");
534 if (!image_check_dcrc (hdr)) {
535 printf ("Bad Data CRC\n");
536 show_boot_progress (-3);
537 return NULL;
538 }
539 puts ("OK\n");
540 }
541 show_boot_progress (4);
542
543 if (!image_check_target_arch (hdr)) {
544 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
545 show_boot_progress (-4);
546 return NULL;
547 }
548 return hdr;
549}
550
551/**
Marian Balakowicz6986a382008-03-12 10:01:05 +0100552 * fit_check_kernel - verify FIT format kernel subimage
553 * @fit_hdr: pointer to the FIT image header
554 * os_noffset: kernel subimage node offset within FIT image
555 * @verify: data CRC verification flag
556 *
557 * fit_check_kernel() verifies integrity of the kernel subimage and from
558 * specified FIT image.
559 *
560 * returns:
561 * 1, on success
562 * 0, on failure
563 */
564#if defined (CONFIG_FIT)
565static int fit_check_kernel (const void *fit, int os_noffset, int verify)
566{
567 fit_image_print (fit, os_noffset, " ");
568
569 if (verify) {
570 puts (" Verifying Hash Integrity ... ");
571 if (!fit_image_check_hashes (fit, os_noffset)) {
572 puts ("Bad Data Hash\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100573 show_boot_progress (-104);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100574 return 0;
575 }
576 puts ("OK\n");
577 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100578 show_boot_progress (105);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100579
580 if (!fit_image_check_target_arch (fit, os_noffset)) {
581 puts ("Unsupported Architecture\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100582 show_boot_progress (-105);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100583 return 0;
584 }
585
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100586 show_boot_progress (106);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100587 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
588 puts ("Not a kernel image\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100589 show_boot_progress (-106);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100590 return 0;
591 }
592
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100593 show_boot_progress (107);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100594 return 1;
595}
596#endif /* CONFIG_FIT */
597
598/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100599 * boot_get_kernel - find kernel image
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100600 * @os_data: pointer to a ulong variable, will hold os data start address
601 * @os_len: pointer to a ulong variable, will hold os data length
602 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100603 * boot_get_kernel() tries to find a kernel image, verifies its integrity
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100604 * and locates kernel data.
605 *
606 * returns:
607 * pointer to image header if valid image was found, plus kernel start
608 * address and length, otherwise NULL
609 */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100610static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100611 bootm_headers_t *images, ulong *os_data, ulong *os_len)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100612{
613 image_header_t *hdr;
614 ulong img_addr;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100615#if defined(CONFIG_FIT)
616 void *fit_hdr;
617 const char *fit_uname_config = NULL;
618 const char *fit_uname_kernel = NULL;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100619 const void *data;
620 size_t len;
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100621 int cfg_noffset;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100622 int os_noffset;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100623#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100624
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100625 /* find out kernel image address */
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100626 if (argc < 2) {
627 img_addr = load_addr;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100628 debug ("* kernel: default image load address = 0x%08lx\n",
629 load_addr);
630#if defined(CONFIG_FIT)
631 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
632 &fit_uname_config)) {
633 debug ("* kernel: config '%s' from image at 0x%08lx\n",
634 fit_uname_config, img_addr);
635 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
636 &fit_uname_kernel)) {
637 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
638 fit_uname_kernel, img_addr);
639#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100640 } else {
641 img_addr = simple_strtoul(argv[1], NULL, 16);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100642 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100643 }
644
645 show_boot_progress (1);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100646
Marian Balakowiczfff888a12008-02-21 17:20:19 +0100647 /* copy from dataflash if needed */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100648 img_addr = genimg_get_image (img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100649
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100650 /* check image type, for FIT images get FIT kernel node */
Marian Balakowicz6986a382008-03-12 10:01:05 +0100651 *os_data = *os_len = 0;
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100652 switch (genimg_get_format ((void *)img_addr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100653 case IMAGE_FORMAT_LEGACY:
Marian Balakowicz6986a382008-03-12 10:01:05 +0100654 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
655 img_addr);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100656 hdr = image_get_kernel (img_addr, images->verify);
657 if (!hdr)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100658 return NULL;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100659 show_boot_progress (5);
660
Marian Balakowicz6986a382008-03-12 10:01:05 +0100661 /* get os_data and os_len */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100662 switch (image_get_type (hdr)) {
663 case IH_TYPE_KERNEL:
664 *os_data = image_get_data (hdr);
665 *os_len = image_get_data_size (hdr);
666 break;
667 case IH_TYPE_MULTI:
668 image_multi_getimg (hdr, 0, os_data, os_len);
669 break;
670 default:
671 printf ("Wrong Image Type for %s command\n", cmdtp->name);
672 show_boot_progress (-5);
673 return NULL;
674 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100675
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200676 /*
677 * copy image header to allow for image overwrites during kernel
678 * decompression.
679 */
680 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
681
682 /* save pointer to image header */
683 images->legacy_hdr_os = hdr;
684
685 images->legacy_hdr_valid = 1;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100686 show_boot_progress (6);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100687 break;
688#if defined(CONFIG_FIT)
689 case IMAGE_FORMAT_FIT:
690 fit_hdr = (void *)img_addr;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100691 printf ("## Booting kernel from FIT Image at %08lx ...\n",
692 img_addr);
693
694 if (!fit_check_format (fit_hdr)) {
695 puts ("Bad FIT kernel image format!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100696 show_boot_progress (-100);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100697 return NULL;
698 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100699 show_boot_progress (100);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100700
701 if (!fit_uname_kernel) {
702 /*
703 * no kernel image node unit name, try to get config
704 * node first. If config unit node name is NULL
705 * fit_conf_get_node() will try to find default config node
706 */
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100707 show_boot_progress (101);
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100708 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
709 if (cfg_noffset < 0) {
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100710 show_boot_progress (-101);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100711 return NULL;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100712 }
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100713 /* save configuration uname provided in the first
714 * bootm argument
715 */
716 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
717 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
718 show_boot_progress (103);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100719
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100720 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100721 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
722 } else {
723 /* get kernel component image node offset */
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100724 show_boot_progress (102);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100725 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
726 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100727 if (os_noffset < 0) {
728 show_boot_progress (-103);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100729 return NULL;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100730 }
Marian Balakowicz6986a382008-03-12 10:01:05 +0100731
732 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
733
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100734 show_boot_progress (104);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100735 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
736 return NULL;
737
738 /* get kernel image data address and length */
739 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
740 puts ("Could not find kernel subimage data!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100741 show_boot_progress (-107);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100742 return NULL;
743 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100744 show_boot_progress (108);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100745
746 *os_len = len;
747 *os_data = (ulong)data;
748 images->fit_hdr_os = fit_hdr;
749 images->fit_uname_os = fit_uname_kernel;
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100750 images->fit_noffset_os = os_noffset;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100751 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100752#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100753 default:
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100754 printf ("Wrong Image Format for %s command\n", cmdtp->name);
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100755 show_boot_progress (-108);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100756 return NULL;
757 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100758
Wolfgang Denk06c53be2008-07-10 13:16:09 +0200759 debug (" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
Marian Balakowicz6986a382008-03-12 10:01:05 +0100760 *os_data, *os_len, *os_len);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100761
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100762 return (void *)img_addr;
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100763}
764
wdenk0d498392003-07-01 21:06:45 +0000765U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200766 bootm, CONFIG_SYS_MAXARGS, 1, do_bootm,
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100767 "bootm - boot application image from memory\n",
768 "[addr [arg ...]]\n - boot application image stored in memory\n"
769 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
770 "\t'arg' can be the address of an initrd image\n"
Marian Balakowicz4a2ad5f2008-01-31 13:20:07 +0100771#if defined(CONFIG_OF_LIBFDT)
Matthew McClintock98a9c4d2006-06-28 10:41:37 -0500772 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
Detlev Zundel5441f612007-10-19 16:47:26 +0200773 "\ta third argument is required which is the address of the\n"
Matthew McClintock98a9c4d2006-06-28 10:41:37 -0500774 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
775 "\tuse a '-' for the second argument. If you do not pass a third\n"
776 "\ta bd_info struct will be passed instead\n"
777#endif
Marian Balakowicz6986a382008-03-12 10:01:05 +0100778#if defined(CONFIG_FIT)
779 "\t\nFor the new multi component uImage format (FIT) addresses\n"
780 "\tmust be extened to include component or configuration unit name:\n"
781 "\taddr:<subimg_uname> - direct component image specification\n"
782 "\taddr#<conf_uname> - configuration specification\n"
783 "\tUse iminfo command to get the list of existing component\n"
784 "\timages and configurations.\n"
785#endif
wdenk8bde7f72003-06-27 21:31:46 +0000786);
787
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100788/*******************************************************************/
789/* bootd - boot default image */
790/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500791#if defined(CONFIG_CMD_BOOTD)
wdenk47d1a6e2002-11-03 00:01:44 +0000792int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
793{
794 int rcode = 0;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100795
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200796#ifndef CONFIG_SYS_HUSH_PARSER
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100797 if (run_command (getenv ("bootcmd"), flag) < 0)
798 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000799#else
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100800 if (parse_string_outer (getenv ("bootcmd"),
801 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
802 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000803#endif
804 return rcode;
805}
wdenk8bde7f72003-06-27 21:31:46 +0000806
wdenk0d498392003-07-01 21:06:45 +0000807U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100808 boot, 1, 1, do_bootd,
809 "boot - boot default, i.e., run 'bootcmd'\n",
wdenk9d2b18a2003-06-28 23:11:04 +0000810 NULL
811);
812
813/* keep old command name "bootd" for backward compatibility */
wdenk0d498392003-07-01 21:06:45 +0000814U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100815 bootd, 1, 1, do_bootd,
816 "bootd - boot default, i.e., run 'bootcmd'\n",
wdenk8bde7f72003-06-27 21:31:46 +0000817 NULL
818);
819
wdenk47d1a6e2002-11-03 00:01:44 +0000820#endif
821
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100822
823/*******************************************************************/
824/* iminfo - print header info for a requested image */
825/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500826#if defined(CONFIG_CMD_IMI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100827int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000828{
829 int arg;
830 ulong addr;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100831 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000832
833 if (argc < 2) {
834 return image_info (load_addr);
835 }
836
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100837 for (arg = 1; arg < argc; ++arg) {
838 addr = simple_strtoul (argv[arg], NULL, 16);
839 if (image_info (addr) != 0)
840 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000841 }
842 return rcode;
843}
844
845static int image_info (ulong addr)
846{
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100847 void *hdr = (void *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +0000848
849 printf ("\n## Checking Image at %08lx ...\n", addr);
850
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100851 switch (genimg_get_format (hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100852 case IMAGE_FORMAT_LEGACY:
853 puts (" Legacy image found\n");
854 if (!image_check_magic (hdr)) {
855 puts (" Bad Magic Number\n");
856 return 1;
857 }
858
859 if (!image_check_hcrc (hdr)) {
860 puts (" Bad Header Checksum\n");
861 return 1;
862 }
863
864 image_print_contents (hdr);
865
866 puts (" Verifying Checksum ... ");
867 if (!image_check_dcrc (hdr)) {
868 puts (" Bad Data CRC\n");
869 return 1;
870 }
871 puts ("OK\n");
872 return 0;
873#if defined(CONFIG_FIT)
874 case IMAGE_FORMAT_FIT:
875 puts (" FIT image found\n");
Marian Balakowicze32fea62008-03-11 12:35:20 +0100876
877 if (!fit_check_format (hdr)) {
878 puts ("Bad FIT image format!\n");
879 return 1;
880 }
881
882 fit_print_contents (hdr);
Bartlomiej Siekaa4f24342008-09-09 12:58:16 +0200883
884 if (!fit_all_image_check_hashes (hdr)) {
885 puts ("Bad hash in FIT image!\n");
886 return 1;
887 }
888
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100889 return 0;
890#endif
891 default:
892 puts ("Unknown image format!\n");
893 break;
wdenk47d1a6e2002-11-03 00:01:44 +0000894 }
895
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100896 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000897}
wdenk0d498392003-07-01 21:06:45 +0000898
899U_BOOT_CMD(
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200900 iminfo, CONFIG_SYS_MAXARGS, 1, do_iminfo,
wdenk8bde7f72003-06-27 21:31:46 +0000901 "iminfo - print header information for application image\n",
902 "addr [addr ...]\n"
903 " - print header information for application image starting at\n"
904 " address 'addr' in memory; this includes verification of the\n"
905 " image contents (magic number, header and payload checksums)\n"
906);
Jon Loeliger90253172007-07-10 11:02:44 -0500907#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000908
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100909
910/*******************************************************************/
911/* imls - list all images found in flash */
912/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500913#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +0000914int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
915{
916 flash_info_t *info;
917 int i, j;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100918 void *hdr;
wdenk27b207f2003-07-24 23:38:38 +0000919
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100920 for (i = 0, info = &flash_info[0];
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200921 i < CONFIG_SYS_MAX_FLASH_BANKS; ++i, ++info) {
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100922
wdenk27b207f2003-07-24 23:38:38 +0000923 if (info->flash_id == FLASH_UNKNOWN)
924 goto next_bank;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100925 for (j = 0; j < info->sector_count; ++j) {
wdenk27b207f2003-07-24 23:38:38 +0000926
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100927 hdr = (void *)info->start[j];
928 if (!hdr)
wdenk27b207f2003-07-24 23:38:38 +0000929 goto next_sector;
930
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100931 switch (genimg_get_format (hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100932 case IMAGE_FORMAT_LEGACY:
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100933 if (!image_check_hcrc (hdr))
934 goto next_sector;
935
936 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
937 image_print_contents (hdr);
938
939 puts (" Verifying Checksum ... ");
940 if (!image_check_dcrc (hdr)) {
941 puts ("Bad Data CRC\n");
942 } else {
943 puts ("OK\n");
944 }
945 break;
946#if defined(CONFIG_FIT)
947 case IMAGE_FORMAT_FIT:
Marian Balakowicze32fea62008-03-11 12:35:20 +0100948 if (!fit_check_format (hdr))
949 goto next_sector;
950
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100951 printf ("FIT Image at %08lX:\n", (ulong)hdr);
Marian Balakowicze32fea62008-03-11 12:35:20 +0100952 fit_print_contents (hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100953 break;
954#endif
955 default:
wdenk27b207f2003-07-24 23:38:38 +0000956 goto next_sector;
wdenk5bb226e2003-11-17 21:14:37 +0000957 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100958
wdenkbdccc4f2003-08-05 17:43:17 +0000959next_sector: ;
wdenk27b207f2003-07-24 23:38:38 +0000960 }
wdenkbdccc4f2003-08-05 17:43:17 +0000961next_bank: ;
wdenk27b207f2003-07-24 23:38:38 +0000962 }
963
964 return (0);
965}
966
967U_BOOT_CMD(
968 imls, 1, 1, do_imls,
969 "imls - list all images found in flash\n",
970 "\n"
971 " - Prints information about all images found at sector\n"
972 " boundaries in flash.\n"
973);
Jon Loeliger90253172007-07-10 11:02:44 -0500974#endif
wdenk27b207f2003-07-24 23:38:38 +0000975
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100976/*******************************************************************/
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100977/* helper routines */
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100978/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +0000979#ifdef CONFIG_SILENT_CONSOLE
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100980static void fixup_silent_linux ()
wdenk47d1a6e2002-11-03 00:01:44 +0000981{
982 char buf[256], *start, *end;
983 char *cmdline = getenv ("bootargs");
984
985 /* Only fix cmdline when requested */
986 if (!(gd->flags & GD_FLG_SILENT))
987 return;
988
989 debug ("before silent fix-up: %s\n", cmdline);
990 if (cmdline) {
991 if ((start = strstr (cmdline, "console=")) != NULL) {
992 end = strchr (start, ' ');
993 strncpy (buf, cmdline, (start - cmdline + 8));
994 if (end)
995 strcpy (buf + (start - cmdline + 8), end);
996 else
997 buf[start - cmdline + 8] = '\0';
998 } else {
999 strcpy (buf, cmdline);
1000 strcat (buf, " console=");
1001 }
1002 } else {
1003 strcpy (buf, "console=");
1004 }
1005
1006 setenv ("bootargs", buf);
1007 debug ("after silent fix-up: %s\n", buf);
1008}
1009#endif /* CONFIG_SILENT_CONSOLE */
1010
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001011
1012/*******************************************************************/
1013/* OS booting routines */
1014/*******************************************************************/
1015
Kumar Gala40d7e992008-08-15 08:24:45 -05001016static int do_bootm_netbsd (int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001017 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001018{
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001019 void (*loader)(bd_t *, image_header_t *, char *, char *);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001020 image_header_t *os_hdr, *hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001021 ulong kernel_data, kernel_len;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001022 char *consdev;
1023 char *cmdline;
wdenk47d1a6e2002-11-03 00:01:44 +00001024
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001025#if defined(CONFIG_FIT)
1026 if (!images->legacy_hdr_valid) {
1027 fit_unsupported_reset ("NetBSD");
Kumar Gala40d7e992008-08-15 08:24:45 -05001028 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001029 }
1030#endif
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001031 hdr = images->legacy_hdr_os;
wdenk47d1a6e2002-11-03 00:01:44 +00001032
1033 /*
1034 * Booting a (NetBSD) kernel image
1035 *
1036 * This process is pretty similar to a standalone application:
1037 * The (first part of an multi-) image must be a stage-2 loader,
1038 * which in turn is responsible for loading & invoking the actual
1039 * kernel. The only differences are the parameters being passed:
1040 * besides the board info strucure, the loader expects a command
1041 * line, the name of the console device, and (optionally) the
1042 * address of the original image header.
1043 */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001044 os_hdr = NULL;
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001045 if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001046 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
1047 if (kernel_len)
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001048 os_hdr = hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001049 }
wdenk47d1a6e2002-11-03 00:01:44 +00001050
1051 consdev = "";
1052#if defined (CONFIG_8xx_CONS_SMC1)
1053 consdev = "smc1";
1054#elif defined (CONFIG_8xx_CONS_SMC2)
1055 consdev = "smc2";
1056#elif defined (CONFIG_8xx_CONS_SCC2)
1057 consdev = "scc2";
1058#elif defined (CONFIG_8xx_CONS_SCC3)
1059 consdev = "scc3";
1060#endif
1061
1062 if (argc > 2) {
1063 ulong len;
1064 int i;
1065
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001066 for (i = 2, len = 0; i < argc; i += 1)
wdenk47d1a6e2002-11-03 00:01:44 +00001067 len += strlen (argv[i]) + 1;
1068 cmdline = malloc (len);
1069
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001070 for (i = 2, len = 0; i < argc; i += 1) {
wdenk47d1a6e2002-11-03 00:01:44 +00001071 if (i > 2)
1072 cmdline[len++] = ' ';
1073 strcpy (&cmdline[len], argv[i]);
1074 len += strlen (argv[i]);
1075 }
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001076 } else if ((cmdline = getenv ("bootargs")) == NULL) {
wdenk47d1a6e2002-11-03 00:01:44 +00001077 cmdline = "";
1078 }
1079
Kumar Galac160a952008-08-15 08:24:36 -05001080 loader = (void (*)(bd_t *, image_header_t *, char *, char *))images->ep;
wdenk47d1a6e2002-11-03 00:01:44 +00001081
1082 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
1083 (ulong)loader);
1084
1085 show_boot_progress (15);
1086
1087 /*
1088 * NetBSD Stage-2 Loader Parameters:
1089 * r3: ptr to board info data
1090 * r4: image address
1091 * r5: console device
1092 * r6: boot args string
1093 */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001094 (*loader) (gd->bd, os_hdr, consdev, cmdline);
Kumar Gala40d7e992008-08-15 08:24:45 -05001095
1096 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001097}
1098
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001099#ifdef CONFIG_LYNXKDI
Kumar Gala40d7e992008-08-15 08:24:45 -05001100static int do_bootm_lynxkdi (int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001101 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001102{
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001103 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001104
1105#if defined(CONFIG_FIT)
1106 if (!images->legacy_hdr_valid) {
1107 fit_unsupported_reset ("Lynx");
Kumar Gala40d7e992008-08-15 08:24:45 -05001108 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001109 }
1110#endif
1111
1112 lynxkdi_boot ((image_header_t *)hdr);
Kumar Gala40d7e992008-08-15 08:24:45 -05001113
1114 return 1;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001115}
1116#endif /* CONFIG_LYNXKDI */
1117
Kumar Gala40d7e992008-08-15 08:24:45 -05001118static int do_bootm_rtems (int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001119 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001120{
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001121 void (*entry_point)(bd_t *);
wdenkd791b1d2003-04-20 14:04:18 +00001122
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001123#if defined(CONFIG_FIT)
1124 if (!images->legacy_hdr_valid) {
1125 fit_unsupported_reset ("RTEMS");
Kumar Gala40d7e992008-08-15 08:24:45 -05001126 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001127 }
1128#endif
1129
Kumar Galac160a952008-08-15 08:24:36 -05001130 entry_point = (void (*)(bd_t *))images->ep;
wdenkd791b1d2003-04-20 14:04:18 +00001131
1132 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1133 (ulong)entry_point);
1134
Heiko Schocherfad63402007-07-13 09:54:17 +02001135 show_boot_progress (15);
wdenkd791b1d2003-04-20 14:04:18 +00001136
1137 /*
1138 * RTEMS Parameters:
1139 * r3: ptr to board info data
1140 */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001141 (*entry_point)(gd->bd);
Kumar Gala40d7e992008-08-15 08:24:45 -05001142
1143 return 1;
wdenkd791b1d2003-04-20 14:04:18 +00001144}
1145
Jon Loeligerbaa26db2007-07-08 17:51:39 -05001146#if defined(CONFIG_CMD_ELF)
Kumar Gala40d7e992008-08-15 08:24:45 -05001147static int do_bootm_vxworks (int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001148 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001149{
wdenk47d1a6e2002-11-03 00:01:44 +00001150 char str[80];
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001151
1152#if defined(CONFIG_FIT)
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001153 if (!images->legacy_hdr_valid) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001154 fit_unsupported_reset ("VxWorks");
Kumar Gala40d7e992008-08-15 08:24:45 -05001155 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001156 }
1157#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001158
Kumar Galac160a952008-08-15 08:24:36 -05001159 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001160 setenv("loadaddr", str);
Kumar Gala40d7e992008-08-15 08:24:45 -05001161 do_bootvx(NULL, 0, 0, NULL);
1162
1163 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001164}
1165
Kumar Gala40d7e992008-08-15 08:24:45 -05001166static int do_bootm_qnxelf(int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001167 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001168{
wdenk47d1a6e2002-11-03 00:01:44 +00001169 char *local_args[2];
1170 char str[16];
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001171
1172#if defined(CONFIG_FIT)
1173 if (!images->legacy_hdr_valid) {
1174 fit_unsupported_reset ("QNX");
Kumar Gala40d7e992008-08-15 08:24:45 -05001175 return 1;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001176 }
1177#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001178
Kumar Galac160a952008-08-15 08:24:36 -05001179 sprintf(str, "%lx", images->ep); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001180 local_args[0] = argv[0];
1181 local_args[1] = str; /* and provide it via the arguments */
Kumar Gala40d7e992008-08-15 08:24:45 -05001182 do_bootelf(NULL, 0, 2, local_args);
1183
1184 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +00001185}
Jon Loeliger90253172007-07-10 11:02:44 -05001186#endif
Peter Tyserf5ed9e32008-09-08 14:56:49 -05001187
1188#ifdef CONFIG_INTEGRITY
1189static int do_bootm_integrity (int flag, int argc, char *argv[],
1190 bootm_headers_t *images)
1191{
1192 void (*entry_point)(void);
1193
1194#if defined(CONFIG_FIT)
1195 if (!images->legacy_hdr_valid) {
1196 fit_unsupported_reset ("INTEGRITY");
1197 return 1;
1198 }
1199#endif
1200
1201 entry_point = (void (*)(void))images->ep;
1202
1203 printf ("## Transferring control to INTEGRITY (at address %08lx) ...\n",
1204 (ulong)entry_point);
1205
1206 show_boot_progress (15);
1207
1208 /*
1209 * INTEGRITY Parameters:
1210 * None
1211 */
1212 (*entry_point)();
1213
1214 return 1;
1215}
1216#endif