blob: 529596926001730d491e23eb35a8593e6d9d1e30 [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
wdenk47d1a6e2002-11-03 00:01:44 +000043#ifdef CFG_HUSH_PARSER
44#include <hush.h>
45#endif
46
Marian Balakowicz1ee11802008-01-08 18:17:10 +010047DECLARE_GLOBAL_DATA_PTR;
48
49extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
50#ifndef CFG_BOOTM_LEN
51#define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
wdenk47d1a6e2002-11-03 00:01:44 +000052#endif
53
Marian Balakowicz321359f2008-01-08 18:11:43 +010054#ifdef CONFIG_BZIP2
55extern void bz_internal_error(int);
wdenk228f29a2002-12-08 09:53:23 +000056#endif
57
Jon Loeligerbaa26db2007-07-08 17:51:39 -050058#if defined(CONFIG_CMD_IMI)
wdenk47d1a6e2002-11-03 00:01:44 +000059static int image_info (unsigned long addr);
60#endif
wdenk27b207f2003-07-24 23:38:38 +000061
Jon Loeligerbaa26db2007-07-08 17:51:39 -050062#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +000063#include <flash.h>
Marian Balakowicze6f2e902005-10-11 19:09:42 +020064extern flash_info_t flash_info[]; /* info for FLASH chips */
wdenk27b207f2003-07-24 23:38:38 +000065static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
66#endif
67
Marian Balakowicz1ee11802008-01-08 18:17:10 +010068#ifdef CONFIG_SILENT_CONSOLE
69static void fixup_silent_linux (void);
wdenk2262cfe2002-11-18 00:14:45 +000070#endif
71
Marian Balakowicz6986a382008-03-12 10:01:05 +010072static image_header_t *image_get_kernel (ulong img_addr, int verify);
73#if defined(CONFIG_FIT)
74static int fit_check_kernel (const void *fit, int os_noffset, int verify);
75#endif
76
Marian Balakowicz9a4daad2008-02-29 14:58:34 +010077static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +010078 bootm_headers_t *images, ulong *os_data, ulong *os_len);
Marian Balakowicz1ee11802008-01-08 18:17:10 +010079extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
wdenk47d1a6e2002-11-03 00:01:44 +000080
wdenk47d1a6e2002-11-03 00:01:44 +000081/*
82 * Continue booting an OS image; caller already has:
83 * - copied image header to global variable `header'
84 * - checked header magic number, checksums (both header & image),
85 * - verified image architecture (PPC) and type (KERNEL or MULTI),
86 * - loaded (first part of) image to header load address,
87 * - disabled interrupts.
88 */
Marian Balakowicz1ee11802008-01-08 18:17:10 +010089typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010090 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +010091 bootm_headers_t *images); /* pointers to os/initrd/fdt */
wdenk47d1a6e2002-11-03 00:01:44 +000092
Marian Balakowicz1ee11802008-01-08 18:17:10 +010093extern boot_os_fn do_bootm_linux;
94static boot_os_fn do_bootm_netbsd;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010095#if defined(CONFIG_LYNXKDI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +010096static boot_os_fn do_bootm_lynxkdi;
97extern void lynxkdi_boot (image_header_t *);
wdenk8bde7f72003-06-27 21:31:46 +000098#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +010099static boot_os_fn do_bootm_rtems;
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500100#if defined(CONFIG_CMD_ELF)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100101static boot_os_fn do_bootm_vxworks;
102static boot_os_fn do_bootm_qnxelf;
103int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
104int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
Jon Loeliger90253172007-07-10 11:02:44 -0500105#endif
wdenk7f70e852003-05-20 14:25:27 +0000106#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100107static boot_os_fn do_bootm_artos;
wdenk1f4bb372003-07-27 00:21:01 +0000108#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000109
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100110ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100111static bootm_headers_t images; /* pointers to os/initrd/fdt images */
Stefan Roese15940c92006-03-13 11:16:36 +0100112
Kumar Galae822d7f2008-02-27 21:51:49 -0600113void __board_lmb_reserve(struct lmb *lmb)
114{
115 /* please define platform specific board_lmb_reserve() */
116}
117void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
wdenk47d1a6e2002-11-03 00:01:44 +0000118
wdenk47d1a6e2002-11-03 00:01:44 +0000119
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100120/*******************************************************************/
121/* bootm - boot application image from image in memory */
122/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +0000123int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
124{
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100125 ulong iflag;
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100126 const char *type_name;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100127 uint unc_len = CFG_BOOTM_LEN;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100128 uint8_t comp, type, os;
wdenk47d1a6e2002-11-03 00:01:44 +0000129
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100130 void *os_hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100131 ulong os_data, os_len;
Marian Balakowicz75824382008-01-31 13:20:06 +0100132 ulong image_start, image_end;
133 ulong load_start, load_end;
Becky Bruce391fd932008-06-09 20:37:18 -0500134 ulong mem_start;
135 phys_size_t mem_size;
wdenk47d1a6e2002-11-03 00:01:44 +0000136
Kumar Gala4ed65522008-02-27 21:51:47 -0600137 struct lmb lmb;
wdenk47d1a6e2002-11-03 00:01:44 +0000138
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100139 memset ((void *)&images, 0, sizeof (images));
Bartlomiej Siekaedbed242008-04-18 12:39:23 +0200140 images.verify = getenv_yesno ("verify");
Kumar Gala4ed65522008-02-27 21:51:47 -0600141 images.lmb = &lmb;
wdenk47d1a6e2002-11-03 00:01:44 +0000142
Kumar Gala4ed65522008-02-27 21:51:47 -0600143 lmb_init(&lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000144
Kumar Galad3f2fa02008-02-27 21:51:50 -0600145 mem_start = getenv_bootm_low();
146 mem_size = getenv_bootm_size();
wdenk47d1a6e2002-11-03 00:01:44 +0000147
Becky Bruce391fd932008-06-09 20:37:18 -0500148 lmb_add(&lmb, (phys_addr_t)mem_start, mem_size);
wdenk47d1a6e2002-11-03 00:01:44 +0000149
Kumar Galae822d7f2008-02-27 21:51:49 -0600150 board_lmb_reserve(&lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000151
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100152 /* get kernel image header, start address and length */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100153 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100154 &images, &os_data, &os_len);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100155 if (os_len == 0) {
156 puts ("ERROR: can't get kernel image!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000157 return 1;
158 }
wdenk47d1a6e2002-11-03 00:01:44 +0000159
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100160 /* get image parameters */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100161 switch (genimg_get_format (os_hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100162 case IMAGE_FORMAT_LEGACY:
163 type = image_get_type (os_hdr);
164 comp = image_get_comp (os_hdr);
165 os = image_get_os (os_hdr);
Wolfgang Denkbccae902005-10-06 01:50:50 +0200166
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100167 image_end = image_get_image_end (os_hdr);
168 load_start = image_get_load (os_hdr);
169 break;
170#if defined(CONFIG_FIT)
171 case IMAGE_FORMAT_FIT:
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100172 if (fit_image_get_type (images.fit_hdr_os,
173 images.fit_noffset_os, &type)) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100174 puts ("Can't get image type!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100175 show_boot_progress (-109);
wdenk47d1a6e2002-11-03 00:01:44 +0000176 return 1;
177 }
wdenk47d1a6e2002-11-03 00:01:44 +0000178
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100179 if (fit_image_get_comp (images.fit_hdr_os,
180 images.fit_noffset_os, &comp)) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100181 puts ("Can't get image compression!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100182 show_boot_progress (-110);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100183 return 1;
184 }
wdenk47d1a6e2002-11-03 00:01:44 +0000185
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100186 if (fit_image_get_os (images.fit_hdr_os,
187 images.fit_noffset_os, &os)) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100188 puts ("Can't get image OS!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100189 show_boot_progress (-111);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100190 return 1;
191 }
wdenk47d1a6e2002-11-03 00:01:44 +0000192
Marian Balakowicz6986a382008-03-12 10:01:05 +0100193 image_end = fit_get_end (images.fit_hdr_os);
194
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100195 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
Marian Balakowicz6986a382008-03-12 10:01:05 +0100196 &load_start)) {
197 puts ("Can't get image load address!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100198 show_boot_progress (-112);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100199 return 1;
wdenkb13fb012003-10-30 21:49:38 +0000200 }
201 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100202#endif
203 default:
204 puts ("ERROR: unknown image format type!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000205 return 1;
206 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100207
208 image_start = (ulong)os_hdr;
209 load_end = 0;
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100210 type_name = genimg_get_type_name (type);
wdenk47d1a6e2002-11-03 00:01:44 +0000211
212 /*
213 * We have reached the point of no return: we are going to
214 * overwrite all exception vector code, so we cannot easily
215 * recover from any failures any more...
216 */
wdenk47d1a6e2002-11-03 00:01:44 +0000217 iflag = disable_interrupts();
218
Stefan Roeseebb86c42008-07-30 09:59:51 +0200219#if defined(CONFIG_CMD_USB)
Wolfgang Denk699f0512008-07-15 22:22:44 +0200220 /*
221 * turn off USB to prevent the host controller from writing to the
222 * SDRAM while Linux is booting. This could happen (at least for OHCI
223 * controller), because the HCCA (Host Controller Communication Area)
224 * lies within the SDRAM and the host controller writes continously to
225 * this area (as busmaster!). The HccaFrameNumber is for example
226 * updated every 1 ms within the HCCA structure in SDRAM! For more
227 * details see the OpenHCI specification.
228 */
Markus Klotzbücher3d71c812008-07-10 14:47:09 +0200229 usb_stop();
230#endif
231
232
wdenkc7de8292002-11-19 11:04:11 +0000233#ifdef CONFIG_AMIGAONEG3SE
234 /*
wdenk8bde7f72003-06-27 21:31:46 +0000235 * We've possible left the caches enabled during
wdenkc7de8292002-11-19 11:04:11 +0000236 * bios emulation, so turn them off again
237 */
238 icache_disable();
239 invalidate_l1_instruction_cache();
240 flush_data_cache();
241 dcache_disable();
242#endif
243
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100244 switch (comp) {
wdenk47d1a6e2002-11-03 00:01:44 +0000245 case IH_COMP_NONE:
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100246 if (load_start == (ulong)os_hdr) {
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100247 printf (" XIP %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000248 } else {
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100249 printf (" Loading %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000250
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100251 memmove_wd ((void *)load_start,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100252 (void *)os_data, os_len, CHUNKSZ);
wdenk47d1a6e2002-11-03 00:01:44 +0000253 }
Guennadi Liakhovetski2e752be2008-07-31 12:35:04 +0200254 load_end = load_start + os_len;
255 puts("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000256 break;
257 case IH_COMP_GZIP:
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100258 printf (" Uncompressing %s ... ", type_name);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100259 if (gunzip ((void *)load_start, unc_len,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100260 (uchar *)os_data, &os_len) != 0) {
Marian Balakowicz2682ce82008-03-12 10:33:01 +0100261 puts ("GUNZIP: uncompress or overwrite error "
262 "- must RESET board to recover\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200263 show_boot_progress (-6);
wdenk47d1a6e2002-11-03 00:01:44 +0000264 do_reset (cmdtp, flag, argc, argv);
265 }
Marian Balakowicz75824382008-01-31 13:20:06 +0100266
267 load_end = load_start + os_len;
wdenk47d1a6e2002-11-03 00:01:44 +0000268 break;
wdenkc29fdfc2003-08-29 20:57:53 +0000269#ifdef CONFIG_BZIP2
270 case IH_COMP_BZIP2:
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100271 printf (" Uncompressing %s ... ", type_name);
wdenk5653fc32004-02-08 22:55:38 +0000272 /*
273 * If we've got less than 4 MB of malloc() space,
274 * use slower decompression algorithm which requires
275 * at most 2300 KB of memory.
276 */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100277 int i = BZ2_bzBuffToBuffDecompress ((char*)load_start,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100278 &unc_len, (char *)os_data, os_len,
279 CFG_MALLOC_LEN < (4096 * 1024), 0);
wdenkc29fdfc2003-08-29 20:57:53 +0000280 if (i != BZ_OK) {
Marian Balakowicz2682ce82008-03-12 10:33:01 +0100281 printf ("BUNZIP2: uncompress or overwrite error %d "
282 "- must RESET board to recover\n", i);
Heiko Schocherfad63402007-07-13 09:54:17 +0200283 show_boot_progress (-6);
wdenkc29fdfc2003-08-29 20:57:53 +0000284 do_reset (cmdtp, flag, argc, argv);
285 }
Marian Balakowicz75824382008-01-31 13:20:06 +0100286
287 load_end = load_start + unc_len;
wdenkc29fdfc2003-08-29 20:57:53 +0000288 break;
289#endif /* CONFIG_BZIP2 */
wdenk47d1a6e2002-11-03 00:01:44 +0000290 default:
291 if (iflag)
292 enable_interrupts();
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100293 printf ("Unimplemented compression type %d\n", comp);
Heiko Schocherfad63402007-07-13 09:54:17 +0200294 show_boot_progress (-7);
wdenk47d1a6e2002-11-03 00:01:44 +0000295 return 1;
296 }
wdenk4b9206e2004-03-23 22:14:11 +0000297 puts ("OK\n");
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100298 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end);
Heiko Schocherfad63402007-07-13 09:54:17 +0200299 show_boot_progress (7);
wdenk47d1a6e2002-11-03 00:01:44 +0000300
Marian Balakowicz75824382008-01-31 13:20:06 +0100301 if ((load_start < image_end) && (load_end > image_start)) {
302 debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end);
303 debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end);
wdenk47d1a6e2002-11-03 00:01:44 +0000304
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200305 if (images.legacy_hdr_valid) {
306 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
307 puts ("WARNING: legacy format multi component "
308 "image overwritten\n");
309 } else {
310 puts ("ERROR: new format image overwritten - "
311 "must RESET the board to recover\n");
312 show_boot_progress (-113);
313 do_reset (cmdtp, flag, argc, argv);
314 }
wdenk47d1a6e2002-11-03 00:01:44 +0000315 }
Marian Balakowicz75824382008-01-31 13:20:06 +0100316
Heiko Schocherfad63402007-07-13 09:54:17 +0200317 show_boot_progress (8);
wdenk47d1a6e2002-11-03 00:01:44 +0000318
Kumar Gala4ed65522008-02-27 21:51:47 -0600319 lmb_reserve(&lmb, load_start, (load_end - load_start));
320
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100321 switch (os) {
wdenk47d1a6e2002-11-03 00:01:44 +0000322 default: /* handled by (original) Linux case */
323 case IH_OS_LINUX:
wdenkf72da342003-10-10 10:05:42 +0000324#ifdef CONFIG_SILENT_CONSOLE
325 fixup_silent_linux();
326#endif
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100327 do_bootm_linux (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000328 break;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100329
wdenk47d1a6e2002-11-03 00:01:44 +0000330 case IH_OS_NETBSD:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100331 do_bootm_netbsd (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000332 break;
wdenk8bde7f72003-06-27 21:31:46 +0000333
wdenk1f4bb372003-07-27 00:21:01 +0000334#ifdef CONFIG_LYNXKDI
335 case IH_OS_LYNXOS:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100336 do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images);
wdenk1f4bb372003-07-27 00:21:01 +0000337 break;
338#endif
339
wdenkd791b1d2003-04-20 14:04:18 +0000340 case IH_OS_RTEMS:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100341 do_bootm_rtems (cmdtp, flag, argc, argv, &images);
wdenkd791b1d2003-04-20 14:04:18 +0000342 break;
wdenk8bde7f72003-06-27 21:31:46 +0000343
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500344#if defined(CONFIG_CMD_ELF)
wdenk47d1a6e2002-11-03 00:01:44 +0000345 case IH_OS_VXWORKS:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100346 do_bootm_vxworks (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000347 break;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100348
wdenk47d1a6e2002-11-03 00:01:44 +0000349 case IH_OS_QNX:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100350 do_bootm_qnxelf (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000351 break;
Jon Loeliger90253172007-07-10 11:02:44 -0500352#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100353
wdenk7f70e852003-05-20 14:25:27 +0000354#ifdef CONFIG_ARTOS
355 case IH_OS_ARTOS:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100356 do_bootm_artos (cmdtp, flag, argc, argv, &images);
wdenk7f70e852003-05-20 14:25:27 +0000357 break;
358#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000359 }
360
Heiko Schocherfad63402007-07-13 09:54:17 +0200361 show_boot_progress (-9);
wdenk47d1a6e2002-11-03 00:01:44 +0000362#ifdef DEBUG
wdenk4b9206e2004-03-23 22:14:11 +0000363 puts ("\n## Control returned to monitor - resetting...\n");
Kumar Gala3216ca92008-08-11 09:20:53 -0500364 do_reset (cmdtp, flag, argc, argv);
wdenk47d1a6e2002-11-03 00:01:44 +0000365#endif
Kumar Gala3216ca92008-08-11 09:20:53 -0500366 if (iflag)
Marian Balakowicza44a2692008-03-12 10:14:57 +0100367 enable_interrupts();
368
wdenk47d1a6e2002-11-03 00:01:44 +0000369 return 1;
370}
371
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100372/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100373 * image_get_kernel - verify legacy format kernel image
374 * @img_addr: in RAM address of the legacy format image to be verified
375 * @verify: data CRC verification flag
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100376 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100377 * image_get_kernel() verifies legacy image integrity and returns pointer to
378 * legacy image header if image verification was completed successfully.
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100379 *
380 * returns:
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100381 * pointer to a legacy image header if valid image was found
382 * otherwise return NULL
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100383 */
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100384static image_header_t *image_get_kernel (ulong img_addr, int verify)
385{
386 image_header_t *hdr = (image_header_t *)img_addr;
387
388 if (!image_check_magic(hdr)) {
389 puts ("Bad Magic Number\n");
390 show_boot_progress (-1);
391 return NULL;
392 }
393 show_boot_progress (2);
394
395 if (!image_check_hcrc (hdr)) {
396 puts ("Bad Header Checksum\n");
397 show_boot_progress (-2);
398 return NULL;
399 }
400
401 show_boot_progress (3);
402 image_print_contents (hdr);
403
404 if (verify) {
405 puts (" Verifying Checksum ... ");
406 if (!image_check_dcrc (hdr)) {
407 printf ("Bad Data CRC\n");
408 show_boot_progress (-3);
409 return NULL;
410 }
411 puts ("OK\n");
412 }
413 show_boot_progress (4);
414
415 if (!image_check_target_arch (hdr)) {
416 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
417 show_boot_progress (-4);
418 return NULL;
419 }
420 return hdr;
421}
422
423/**
Marian Balakowicz6986a382008-03-12 10:01:05 +0100424 * fit_check_kernel - verify FIT format kernel subimage
425 * @fit_hdr: pointer to the FIT image header
426 * os_noffset: kernel subimage node offset within FIT image
427 * @verify: data CRC verification flag
428 *
429 * fit_check_kernel() verifies integrity of the kernel subimage and from
430 * specified FIT image.
431 *
432 * returns:
433 * 1, on success
434 * 0, on failure
435 */
436#if defined (CONFIG_FIT)
437static int fit_check_kernel (const void *fit, int os_noffset, int verify)
438{
439 fit_image_print (fit, os_noffset, " ");
440
441 if (verify) {
442 puts (" Verifying Hash Integrity ... ");
443 if (!fit_image_check_hashes (fit, os_noffset)) {
444 puts ("Bad Data Hash\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100445 show_boot_progress (-104);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100446 return 0;
447 }
448 puts ("OK\n");
449 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100450 show_boot_progress (105);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100451
452 if (!fit_image_check_target_arch (fit, os_noffset)) {
453 puts ("Unsupported Architecture\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100454 show_boot_progress (-105);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100455 return 0;
456 }
457
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100458 show_boot_progress (106);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100459 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
460 puts ("Not a kernel image\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100461 show_boot_progress (-106);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100462 return 0;
463 }
464
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100465 show_boot_progress (107);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100466 return 1;
467}
468#endif /* CONFIG_FIT */
469
470/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100471 * boot_get_kernel - find kernel image
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100472 * @os_data: pointer to a ulong variable, will hold os data start address
473 * @os_len: pointer to a ulong variable, will hold os data length
474 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100475 * boot_get_kernel() tries to find a kernel image, verifies its integrity
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100476 * and locates kernel data.
477 *
478 * returns:
479 * pointer to image header if valid image was found, plus kernel start
480 * address and length, otherwise NULL
481 */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100482static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100483 bootm_headers_t *images, ulong *os_data, ulong *os_len)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100484{
485 image_header_t *hdr;
486 ulong img_addr;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100487#if defined(CONFIG_FIT)
488 void *fit_hdr;
489 const char *fit_uname_config = NULL;
490 const char *fit_uname_kernel = NULL;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100491 const void *data;
492 size_t len;
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100493 int cfg_noffset;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100494 int os_noffset;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100495#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100496
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100497 /* find out kernel image address */
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100498 if (argc < 2) {
499 img_addr = load_addr;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100500 debug ("* kernel: default image load address = 0x%08lx\n",
501 load_addr);
502#if defined(CONFIG_FIT)
503 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
504 &fit_uname_config)) {
505 debug ("* kernel: config '%s' from image at 0x%08lx\n",
506 fit_uname_config, img_addr);
507 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
508 &fit_uname_kernel)) {
509 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
510 fit_uname_kernel, img_addr);
511#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100512 } else {
513 img_addr = simple_strtoul(argv[1], NULL, 16);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100514 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100515 }
516
517 show_boot_progress (1);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100518
Marian Balakowiczfff888a12008-02-21 17:20:19 +0100519 /* copy from dataflash if needed */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100520 img_addr = genimg_get_image (img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100521
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100522 /* check image type, for FIT images get FIT kernel node */
Marian Balakowicz6986a382008-03-12 10:01:05 +0100523 *os_data = *os_len = 0;
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100524 switch (genimg_get_format ((void *)img_addr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100525 case IMAGE_FORMAT_LEGACY:
Marian Balakowicz6986a382008-03-12 10:01:05 +0100526 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
527 img_addr);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100528 hdr = image_get_kernel (img_addr, images->verify);
529 if (!hdr)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100530 return NULL;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100531 show_boot_progress (5);
532
Marian Balakowicz6986a382008-03-12 10:01:05 +0100533 /* get os_data and os_len */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100534 switch (image_get_type (hdr)) {
535 case IH_TYPE_KERNEL:
536 *os_data = image_get_data (hdr);
537 *os_len = image_get_data_size (hdr);
538 break;
539 case IH_TYPE_MULTI:
540 image_multi_getimg (hdr, 0, os_data, os_len);
541 break;
542 default:
543 printf ("Wrong Image Type for %s command\n", cmdtp->name);
544 show_boot_progress (-5);
545 return NULL;
546 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100547
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200548 /*
549 * copy image header to allow for image overwrites during kernel
550 * decompression.
551 */
552 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
553
554 /* save pointer to image header */
555 images->legacy_hdr_os = hdr;
556
557 images->legacy_hdr_valid = 1;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100558 show_boot_progress (6);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100559 break;
560#if defined(CONFIG_FIT)
561 case IMAGE_FORMAT_FIT:
562 fit_hdr = (void *)img_addr;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100563 printf ("## Booting kernel from FIT Image at %08lx ...\n",
564 img_addr);
565
566 if (!fit_check_format (fit_hdr)) {
567 puts ("Bad FIT kernel image format!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100568 show_boot_progress (-100);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100569 return NULL;
570 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100571 show_boot_progress (100);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100572
573 if (!fit_uname_kernel) {
574 /*
575 * no kernel image node unit name, try to get config
576 * node first. If config unit node name is NULL
577 * fit_conf_get_node() will try to find default config node
578 */
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100579 show_boot_progress (101);
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100580 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
581 if (cfg_noffset < 0) {
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100582 show_boot_progress (-101);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100583 return NULL;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100584 }
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100585 /* save configuration uname provided in the first
586 * bootm argument
587 */
588 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
589 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
590 show_boot_progress (103);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100591
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100592 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100593 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
594 } else {
595 /* get kernel component image node offset */
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100596 show_boot_progress (102);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100597 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
598 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100599 if (os_noffset < 0) {
600 show_boot_progress (-103);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100601 return NULL;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100602 }
Marian Balakowicz6986a382008-03-12 10:01:05 +0100603
604 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
605
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100606 show_boot_progress (104);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100607 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
608 return NULL;
609
610 /* get kernel image data address and length */
611 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
612 puts ("Could not find kernel subimage data!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100613 show_boot_progress (-107);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100614 return NULL;
615 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100616 show_boot_progress (108);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100617
618 *os_len = len;
619 *os_data = (ulong)data;
620 images->fit_hdr_os = fit_hdr;
621 images->fit_uname_os = fit_uname_kernel;
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100622 images->fit_noffset_os = os_noffset;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100623 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100624#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100625 default:
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100626 printf ("Wrong Image Format for %s command\n", cmdtp->name);
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100627 show_boot_progress (-108);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100628 return NULL;
629 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100630
Wolfgang Denk06c53be2008-07-10 13:16:09 +0200631 debug (" kernel data at 0x%08lx, len = 0x%08lx (%ld)\n",
Marian Balakowicz6986a382008-03-12 10:01:05 +0100632 *os_data, *os_len, *os_len);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100633
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100634 return (void *)img_addr;
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100635}
636
wdenk0d498392003-07-01 21:06:45 +0000637U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100638 bootm, CFG_MAXARGS, 1, do_bootm,
639 "bootm - boot application image from memory\n",
640 "[addr [arg ...]]\n - boot application image stored in memory\n"
641 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
642 "\t'arg' can be the address of an initrd image\n"
Marian Balakowicz4a2ad5f2008-01-31 13:20:07 +0100643#if defined(CONFIG_OF_LIBFDT)
Matthew McClintock98a9c4d2006-06-28 10:41:37 -0500644 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
Detlev Zundel5441f612007-10-19 16:47:26 +0200645 "\ta third argument is required which is the address of the\n"
Matthew McClintock98a9c4d2006-06-28 10:41:37 -0500646 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
647 "\tuse a '-' for the second argument. If you do not pass a third\n"
648 "\ta bd_info struct will be passed instead\n"
649#endif
Marian Balakowicz6986a382008-03-12 10:01:05 +0100650#if defined(CONFIG_FIT)
651 "\t\nFor the new multi component uImage format (FIT) addresses\n"
652 "\tmust be extened to include component or configuration unit name:\n"
653 "\taddr:<subimg_uname> - direct component image specification\n"
654 "\taddr#<conf_uname> - configuration specification\n"
655 "\tUse iminfo command to get the list of existing component\n"
656 "\timages and configurations.\n"
657#endif
wdenk8bde7f72003-06-27 21:31:46 +0000658);
659
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100660/*******************************************************************/
661/* bootd - boot default image */
662/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500663#if defined(CONFIG_CMD_BOOTD)
wdenk47d1a6e2002-11-03 00:01:44 +0000664int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
665{
666 int rcode = 0;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100667
wdenk47d1a6e2002-11-03 00:01:44 +0000668#ifndef CFG_HUSH_PARSER
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100669 if (run_command (getenv ("bootcmd"), flag) < 0)
670 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000671#else
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100672 if (parse_string_outer (getenv ("bootcmd"),
673 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
674 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000675#endif
676 return rcode;
677}
wdenk8bde7f72003-06-27 21:31:46 +0000678
wdenk0d498392003-07-01 21:06:45 +0000679U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100680 boot, 1, 1, do_bootd,
681 "boot - boot default, i.e., run 'bootcmd'\n",
wdenk9d2b18a2003-06-28 23:11:04 +0000682 NULL
683);
684
685/* keep old command name "bootd" for backward compatibility */
wdenk0d498392003-07-01 21:06:45 +0000686U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100687 bootd, 1, 1, do_bootd,
688 "bootd - boot default, i.e., run 'bootcmd'\n",
wdenk8bde7f72003-06-27 21:31:46 +0000689 NULL
690);
691
wdenk47d1a6e2002-11-03 00:01:44 +0000692#endif
693
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100694
695/*******************************************************************/
696/* iminfo - print header info for a requested image */
697/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500698#if defined(CONFIG_CMD_IMI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100699int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000700{
701 int arg;
702 ulong addr;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100703 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000704
705 if (argc < 2) {
706 return image_info (load_addr);
707 }
708
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100709 for (arg = 1; arg < argc; ++arg) {
710 addr = simple_strtoul (argv[arg], NULL, 16);
711 if (image_info (addr) != 0)
712 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000713 }
714 return rcode;
715}
716
717static int image_info (ulong addr)
718{
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100719 void *hdr = (void *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +0000720
721 printf ("\n## Checking Image at %08lx ...\n", addr);
722
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100723 switch (genimg_get_format (hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100724 case IMAGE_FORMAT_LEGACY:
725 puts (" Legacy image found\n");
726 if (!image_check_magic (hdr)) {
727 puts (" Bad Magic Number\n");
728 return 1;
729 }
730
731 if (!image_check_hcrc (hdr)) {
732 puts (" Bad Header Checksum\n");
733 return 1;
734 }
735
736 image_print_contents (hdr);
737
738 puts (" Verifying Checksum ... ");
739 if (!image_check_dcrc (hdr)) {
740 puts (" Bad Data CRC\n");
741 return 1;
742 }
743 puts ("OK\n");
744 return 0;
745#if defined(CONFIG_FIT)
746 case IMAGE_FORMAT_FIT:
747 puts (" FIT image found\n");
Marian Balakowicze32fea62008-03-11 12:35:20 +0100748
749 if (!fit_check_format (hdr)) {
750 puts ("Bad FIT image format!\n");
751 return 1;
752 }
753
754 fit_print_contents (hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100755 return 0;
756#endif
757 default:
758 puts ("Unknown image format!\n");
759 break;
wdenk47d1a6e2002-11-03 00:01:44 +0000760 }
761
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100762 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000763}
wdenk0d498392003-07-01 21:06:45 +0000764
765U_BOOT_CMD(
766 iminfo, CFG_MAXARGS, 1, do_iminfo,
wdenk8bde7f72003-06-27 21:31:46 +0000767 "iminfo - print header information for application image\n",
768 "addr [addr ...]\n"
769 " - print header information for application image starting at\n"
770 " address 'addr' in memory; this includes verification of the\n"
771 " image contents (magic number, header and payload checksums)\n"
772);
Jon Loeliger90253172007-07-10 11:02:44 -0500773#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000774
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100775
776/*******************************************************************/
777/* imls - list all images found in flash */
778/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500779#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +0000780int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
781{
782 flash_info_t *info;
783 int i, j;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100784 void *hdr;
wdenk27b207f2003-07-24 23:38:38 +0000785
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100786 for (i = 0, info = &flash_info[0];
787 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
788
wdenk27b207f2003-07-24 23:38:38 +0000789 if (info->flash_id == FLASH_UNKNOWN)
790 goto next_bank;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100791 for (j = 0; j < info->sector_count; ++j) {
wdenk27b207f2003-07-24 23:38:38 +0000792
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100793 hdr = (void *)info->start[j];
794 if (!hdr)
wdenk27b207f2003-07-24 23:38:38 +0000795 goto next_sector;
796
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100797 switch (genimg_get_format (hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100798 case IMAGE_FORMAT_LEGACY:
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100799 if (!image_check_hcrc (hdr))
800 goto next_sector;
801
802 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
803 image_print_contents (hdr);
804
805 puts (" Verifying Checksum ... ");
806 if (!image_check_dcrc (hdr)) {
807 puts ("Bad Data CRC\n");
808 } else {
809 puts ("OK\n");
810 }
811 break;
812#if defined(CONFIG_FIT)
813 case IMAGE_FORMAT_FIT:
Marian Balakowicze32fea62008-03-11 12:35:20 +0100814 if (!fit_check_format (hdr))
815 goto next_sector;
816
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100817 printf ("FIT Image at %08lX:\n", (ulong)hdr);
Marian Balakowicze32fea62008-03-11 12:35:20 +0100818 fit_print_contents (hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100819 break;
820#endif
821 default:
wdenk27b207f2003-07-24 23:38:38 +0000822 goto next_sector;
wdenk5bb226e2003-11-17 21:14:37 +0000823 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100824
wdenkbdccc4f2003-08-05 17:43:17 +0000825next_sector: ;
wdenk27b207f2003-07-24 23:38:38 +0000826 }
wdenkbdccc4f2003-08-05 17:43:17 +0000827next_bank: ;
wdenk27b207f2003-07-24 23:38:38 +0000828 }
829
830 return (0);
831}
832
833U_BOOT_CMD(
834 imls, 1, 1, do_imls,
835 "imls - list all images found in flash\n",
836 "\n"
837 " - Prints information about all images found at sector\n"
838 " boundaries in flash.\n"
839);
Jon Loeliger90253172007-07-10 11:02:44 -0500840#endif
wdenk27b207f2003-07-24 23:38:38 +0000841
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100842/*******************************************************************/
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100843/* helper routines */
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100844/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +0000845#ifdef CONFIG_SILENT_CONSOLE
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100846static void fixup_silent_linux ()
wdenk47d1a6e2002-11-03 00:01:44 +0000847{
848 char buf[256], *start, *end;
849 char *cmdline = getenv ("bootargs");
850
851 /* Only fix cmdline when requested */
852 if (!(gd->flags & GD_FLG_SILENT))
853 return;
854
855 debug ("before silent fix-up: %s\n", cmdline);
856 if (cmdline) {
857 if ((start = strstr (cmdline, "console=")) != NULL) {
858 end = strchr (start, ' ');
859 strncpy (buf, cmdline, (start - cmdline + 8));
860 if (end)
861 strcpy (buf + (start - cmdline + 8), end);
862 else
863 buf[start - cmdline + 8] = '\0';
864 } else {
865 strcpy (buf, cmdline);
866 strcat (buf, " console=");
867 }
868 } else {
869 strcpy (buf, "console=");
870 }
871
872 setenv ("bootargs", buf);
873 debug ("after silent fix-up: %s\n", buf);
874}
875#endif /* CONFIG_SILENT_CONSOLE */
876
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100877
878/*******************************************************************/
879/* OS booting routines */
880/*******************************************************************/
881
882static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100883 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100884 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +0000885{
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100886 void (*loader)(bd_t *, image_header_t *, char *, char *);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100887 image_header_t *os_hdr, *hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100888 ulong kernel_data, kernel_len;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100889 char *consdev;
890 char *cmdline;
wdenk47d1a6e2002-11-03 00:01:44 +0000891
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100892#if defined(CONFIG_FIT)
893 if (!images->legacy_hdr_valid) {
894 fit_unsupported_reset ("NetBSD");
895 do_reset (cmdtp, flag, argc, argv);
wdenk47d1a6e2002-11-03 00:01:44 +0000896 }
897#endif
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100898 hdr = images->legacy_hdr_os;
wdenk47d1a6e2002-11-03 00:01:44 +0000899
900 /*
901 * Booting a (NetBSD) kernel image
902 *
903 * This process is pretty similar to a standalone application:
904 * The (first part of an multi-) image must be a stage-2 loader,
905 * which in turn is responsible for loading & invoking the actual
906 * kernel. The only differences are the parameters being passed:
907 * besides the board info strucure, the loader expects a command
908 * line, the name of the console device, and (optionally) the
909 * address of the original image header.
910 */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100911 os_hdr = NULL;
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200912 if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100913 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
914 if (kernel_len)
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100915 os_hdr = hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100916 }
wdenk47d1a6e2002-11-03 00:01:44 +0000917
918 consdev = "";
919#if defined (CONFIG_8xx_CONS_SMC1)
920 consdev = "smc1";
921#elif defined (CONFIG_8xx_CONS_SMC2)
922 consdev = "smc2";
923#elif defined (CONFIG_8xx_CONS_SCC2)
924 consdev = "scc2";
925#elif defined (CONFIG_8xx_CONS_SCC3)
926 consdev = "scc3";
927#endif
928
929 if (argc > 2) {
930 ulong len;
931 int i;
932
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100933 for (i = 2, len = 0; i < argc; i += 1)
wdenk47d1a6e2002-11-03 00:01:44 +0000934 len += strlen (argv[i]) + 1;
935 cmdline = malloc (len);
936
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100937 for (i = 2, len = 0; i < argc; i += 1) {
wdenk47d1a6e2002-11-03 00:01:44 +0000938 if (i > 2)
939 cmdline[len++] = ' ';
940 strcpy (&cmdline[len], argv[i]);
941 len += strlen (argv[i]);
942 }
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100943 } else if ((cmdline = getenv ("bootargs")) == NULL) {
wdenk47d1a6e2002-11-03 00:01:44 +0000944 cmdline = "";
945 }
946
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100947 loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000948
949 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
950 (ulong)loader);
951
952 show_boot_progress (15);
953
954 /*
955 * NetBSD Stage-2 Loader Parameters:
956 * r3: ptr to board info data
957 * r4: image address
958 * r5: console device
959 * r6: boot args string
960 */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100961 (*loader) (gd->bd, os_hdr, consdev, cmdline);
wdenk47d1a6e2002-11-03 00:01:44 +0000962}
963
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100964#ifdef CONFIG_LYNXKDI
965static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
966 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100967 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100968{
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200969 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100970
971#if defined(CONFIG_FIT)
972 if (!images->legacy_hdr_valid) {
973 fit_unsupported_reset ("Lynx");
974 do_reset (cmdtp, flag, argc, argv);
975 }
976#endif
977
978 lynxkdi_boot ((image_header_t *)hdr);
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100979}
980#endif /* CONFIG_LYNXKDI */
981
982static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
983 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100984 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100985{
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200986 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100987 void (*entry_point)(bd_t *);
wdenkd791b1d2003-04-20 14:04:18 +0000988
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100989#if defined(CONFIG_FIT)
990 if (!images->legacy_hdr_valid) {
991 fit_unsupported_reset ("RTEMS");
992 do_reset (cmdtp, flag, argc, argv);
993 }
994#endif
995
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100996 entry_point = (void (*)(bd_t *))image_get_ep (hdr);
wdenkd791b1d2003-04-20 14:04:18 +0000997
998 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
999 (ulong)entry_point);
1000
Heiko Schocherfad63402007-07-13 09:54:17 +02001001 show_boot_progress (15);
wdenkd791b1d2003-04-20 14:04:18 +00001002
1003 /*
1004 * RTEMS Parameters:
1005 * r3: ptr to board info data
1006 */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001007 (*entry_point)(gd->bd);
wdenkd791b1d2003-04-20 14:04:18 +00001008}
1009
Jon Loeligerbaa26db2007-07-08 17:51:39 -05001010#if defined(CONFIG_CMD_ELF)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001011static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
1012 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001013 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001014{
wdenk47d1a6e2002-11-03 00:01:44 +00001015 char str[80];
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001016 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001017
1018#if defined(CONFIG_FIT)
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001019 if (!images->legacy_hdr_valid) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001020 fit_unsupported_reset ("VxWorks");
1021 do_reset (cmdtp, flag, argc, argv);
1022 }
1023#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001024
Marian Balakowiczb97a2a02008-01-08 18:14:09 +01001025 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001026 setenv("loadaddr", str);
1027 do_bootvx(cmdtp, 0, 0, NULL);
1028}
1029
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001030static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
1031 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001032 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001033{
wdenk47d1a6e2002-11-03 00:01:44 +00001034 char *local_args[2];
1035 char str[16];
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001036 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001037
1038#if defined(CONFIG_FIT)
1039 if (!images->legacy_hdr_valid) {
1040 fit_unsupported_reset ("QNX");
1041 do_reset (cmdtp, flag, argc, argv);
1042 }
1043#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001044
Marian Balakowiczb97a2a02008-01-08 18:14:09 +01001045 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001046 local_args[0] = argv[0];
1047 local_args[1] = str; /* and provide it via the arguments */
1048 do_bootelf(cmdtp, 0, 2, local_args);
1049}
Jon Loeliger90253172007-07-10 11:02:44 -05001050#endif
wdenk1f4bb372003-07-27 00:21:01 +00001051
wdenk47d1a6e2002-11-03 00:01:44 +00001052#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001053static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
1054 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001055 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001056{
1057 ulong top;
1058 char *s, *cmdline;
1059 char **fwenv, **ss;
1060 int i, j, nxt, len, envno, envsz;
1061 bd_t *kbd;
1062 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001063 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001064
1065#if defined(CONFIG_FIT)
1066 if (!images->legacy_hdr_valid) {
1067 fit_unsupported_reset ("ARTOS");
1068 do_reset (cmdtp, flag, argc, argv);
1069 }
1070#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001071
1072 /*
1073 * Booting an ARTOS kernel image + application
1074 */
1075
1076 /* this used to be the top of memory, but was wrong... */
1077#ifdef CONFIG_PPC
1078 /* get stack pointer */
1079 asm volatile ("mr %0,1" : "=r"(top) );
1080#endif
1081 debug ("## Current stack ends at 0x%08lX ", top);
1082
1083 top -= 2048; /* just to be sure */
1084 if (top > CFG_BOOTMAPSZ)
1085 top = CFG_BOOTMAPSZ;
1086 top &= ~0xF;
1087
1088 debug ("=> set upper limit to 0x%08lX\n", top);
1089
1090 /* first check the artos specific boot args, then the linux args*/
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001091 if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
wdenk47d1a6e2002-11-03 00:01:44 +00001092 s = "";
1093
1094 /* get length of cmdline, and place it */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001095 len = strlen (s);
wdenk47d1a6e2002-11-03 00:01:44 +00001096 top = (top - (len + 1)) & ~0xF;
1097 cmdline = (char *)top;
1098 debug ("## cmdline at 0x%08lX ", top);
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001099 strcpy (cmdline, s);
wdenk47d1a6e2002-11-03 00:01:44 +00001100
1101 /* copy bdinfo */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001102 top = (top - sizeof (bd_t)) & ~0xF;
wdenk47d1a6e2002-11-03 00:01:44 +00001103 debug ("## bd at 0x%08lX ", top);
1104 kbd = (bd_t *)top;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001105 memcpy (kbd, gd->bd, sizeof (bd_t));
wdenk47d1a6e2002-11-03 00:01:44 +00001106
1107 /* first find number of env entries, and their size */
1108 envno = 0;
1109 envsz = 0;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001110 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1111 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
wdenk47d1a6e2002-11-03 00:01:44 +00001112 ;
1113 envno++;
1114 envsz += (nxt - i) + 1; /* plus trailing zero */
1115 }
1116 envno++; /* plus the terminating zero */
1117 debug ("## %u envvars total size %u ", envno, envsz);
1118
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001119 top = (top - sizeof (char **) * envno) & ~0xF;
wdenk47d1a6e2002-11-03 00:01:44 +00001120 fwenv = (char **)top;
1121 debug ("## fwenv at 0x%08lX ", top);
1122
1123 top = (top - envsz) & ~0xF;
1124 s = (char *)top;
1125 ss = fwenv;
1126
1127 /* now copy them */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001128 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1129 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
wdenk47d1a6e2002-11-03 00:01:44 +00001130 ;
1131 *ss++ = s;
1132 for (j = i; j < nxt; ++j)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001133 *s++ = env_get_char (j);
wdenk47d1a6e2002-11-03 00:01:44 +00001134 *s++ = '\0';
1135 }
1136 *ss++ = NULL; /* terminate */
1137
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001138 entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
1139 (*entry) (kbd, cmdline, fwenv, top);
wdenk47d1a6e2002-11-03 00:01:44 +00001140}
1141#endif