blob: 9e5ce4b38fc96228a942e968c020679e15c53aeb [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
wdenk47d1a6e2002-11-03 00:01:44 +000039#ifdef CFG_HUSH_PARSER
40#include <hush.h>
41#endif
42
Marian Balakowicz1ee11802008-01-08 18:17:10 +010043DECLARE_GLOBAL_DATA_PTR;
44
45extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
46#ifndef CFG_BOOTM_LEN
47#define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
wdenk47d1a6e2002-11-03 00:01:44 +000048#endif
49
Marian Balakowicz321359f2008-01-08 18:11:43 +010050#ifdef CONFIG_BZIP2
51extern void bz_internal_error(int);
wdenk228f29a2002-12-08 09:53:23 +000052#endif
53
Jon Loeligerbaa26db2007-07-08 17:51:39 -050054#if defined(CONFIG_CMD_IMI)
wdenk47d1a6e2002-11-03 00:01:44 +000055static int image_info (unsigned long addr);
56#endif
wdenk27b207f2003-07-24 23:38:38 +000057
Jon Loeligerbaa26db2007-07-08 17:51:39 -050058#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +000059#include <flash.h>
Marian Balakowicze6f2e902005-10-11 19:09:42 +020060extern flash_info_t flash_info[]; /* info for FLASH chips */
wdenk27b207f2003-07-24 23:38:38 +000061static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
62#endif
63
Marian Balakowicz1ee11802008-01-08 18:17:10 +010064#ifdef CONFIG_SILENT_CONSOLE
65static void fixup_silent_linux (void);
wdenk2262cfe2002-11-18 00:14:45 +000066#endif
67
Marian Balakowicz6986a382008-03-12 10:01:05 +010068static image_header_t *image_get_kernel (ulong img_addr, int verify);
69#if defined(CONFIG_FIT)
70static int fit_check_kernel (const void *fit, int os_noffset, int verify);
71#endif
72
Marian Balakowicz9a4daad2008-02-29 14:58:34 +010073static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +010074 bootm_headers_t *images, ulong *os_data, ulong *os_len);
Marian Balakowicz1ee11802008-01-08 18:17:10 +010075extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
wdenk47d1a6e2002-11-03 00:01:44 +000076
wdenk47d1a6e2002-11-03 00:01:44 +000077/*
78 * Continue booting an OS image; caller already has:
79 * - copied image header to global variable `header'
80 * - checked header magic number, checksums (both header & image),
81 * - verified image architecture (PPC) and type (KERNEL or MULTI),
82 * - loaded (first part of) image to header load address,
83 * - disabled interrupts.
84 */
Marian Balakowicz1ee11802008-01-08 18:17:10 +010085typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010086 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +010087 bootm_headers_t *images); /* pointers to os/initrd/fdt */
wdenk47d1a6e2002-11-03 00:01:44 +000088
Marian Balakowicz1ee11802008-01-08 18:17:10 +010089extern boot_os_fn do_bootm_linux;
90static boot_os_fn do_bootm_netbsd;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010091#if defined(CONFIG_LYNXKDI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +010092static boot_os_fn do_bootm_lynxkdi;
93extern void lynxkdi_boot (image_header_t *);
wdenk8bde7f72003-06-27 21:31:46 +000094#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +010095static boot_os_fn do_bootm_rtems;
Jon Loeligerbaa26db2007-07-08 17:51:39 -050096#if defined(CONFIG_CMD_ELF)
Marian Balakowicz1ee11802008-01-08 18:17:10 +010097static boot_os_fn do_bootm_vxworks;
98static boot_os_fn do_bootm_qnxelf;
99int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
100int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
Jon Loeliger90253172007-07-10 11:02:44 -0500101#endif
wdenk7f70e852003-05-20 14:25:27 +0000102#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100103extern uchar (*env_get_char)(int); /* Returns a character from the environment */
104static boot_os_fn do_bootm_artos;
wdenk1f4bb372003-07-27 00:21:01 +0000105#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000106
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100107ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100108static bootm_headers_t images; /* pointers to os/initrd/fdt images */
Stefan Roese15940c92006-03-13 11:16:36 +0100109
Kumar Galae822d7f2008-02-27 21:51:49 -0600110void __board_lmb_reserve(struct lmb *lmb)
111{
112 /* please define platform specific board_lmb_reserve() */
113}
114void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
wdenk47d1a6e2002-11-03 00:01:44 +0000115
wdenk47d1a6e2002-11-03 00:01:44 +0000116
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100117/*******************************************************************/
118/* bootm - boot application image from image in memory */
119/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +0000120int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
121{
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100122 ulong iflag;
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100123 const char *type_name;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100124 uint unc_len = CFG_BOOTM_LEN;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100125 uint8_t comp, type, os;
wdenk47d1a6e2002-11-03 00:01:44 +0000126
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100127 void *os_hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100128 ulong os_data, os_len;
Marian Balakowicz75824382008-01-31 13:20:06 +0100129 ulong image_start, image_end;
130 ulong load_start, load_end;
Kumar Galad3f2fa02008-02-27 21:51:50 -0600131 ulong mem_start, mem_size;
wdenk47d1a6e2002-11-03 00:01:44 +0000132
Kumar Gala4ed65522008-02-27 21:51:47 -0600133 struct lmb lmb;
wdenk47d1a6e2002-11-03 00:01:44 +0000134
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100135 memset ((void *)&images, 0, sizeof (images));
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100136 images.verify = getenv_verify();
Kumar Galaf5614e72008-02-27 21:51:48 -0600137 images.autostart = getenv_autostart();
Kumar Gala4ed65522008-02-27 21:51:47 -0600138 images.lmb = &lmb;
wdenk47d1a6e2002-11-03 00:01:44 +0000139
Kumar Gala4ed65522008-02-27 21:51:47 -0600140 lmb_init(&lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000141
Kumar Galad3f2fa02008-02-27 21:51:50 -0600142 mem_start = getenv_bootm_low();
143 mem_size = getenv_bootm_size();
wdenk47d1a6e2002-11-03 00:01:44 +0000144
Kumar Galad3f2fa02008-02-27 21:51:50 -0600145 lmb_add(&lmb, mem_start, mem_size);
wdenk47d1a6e2002-11-03 00:01:44 +0000146
Kumar Galae822d7f2008-02-27 21:51:49 -0600147 board_lmb_reserve(&lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000148
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100149 /* get kernel image header, start address and length */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100150 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100151 &images, &os_data, &os_len);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100152 if (os_len == 0) {
153 puts ("ERROR: can't get kernel image!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000154 return 1;
155 }
wdenk47d1a6e2002-11-03 00:01:44 +0000156
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100157 /* get image parameters */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100158 switch (genimg_get_format (os_hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100159 case IMAGE_FORMAT_LEGACY:
160 type = image_get_type (os_hdr);
161 comp = image_get_comp (os_hdr);
162 os = image_get_os (os_hdr);
Wolfgang Denkbccae902005-10-06 01:50:50 +0200163
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100164 image_end = image_get_image_end (os_hdr);
165 load_start = image_get_load (os_hdr);
166 break;
167#if defined(CONFIG_FIT)
168 case IMAGE_FORMAT_FIT:
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100169 if (fit_image_get_type (images.fit_hdr_os,
170 images.fit_noffset_os, &type)) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100171 puts ("Can't get image type!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100172 show_boot_progress (-109);
wdenk47d1a6e2002-11-03 00:01:44 +0000173 return 1;
174 }
wdenk47d1a6e2002-11-03 00:01:44 +0000175
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100176 if (fit_image_get_comp (images.fit_hdr_os,
177 images.fit_noffset_os, &comp)) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100178 puts ("Can't get image compression!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100179 show_boot_progress (-110);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100180 return 1;
181 }
wdenk47d1a6e2002-11-03 00:01:44 +0000182
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100183 if (fit_image_get_os (images.fit_hdr_os,
184 images.fit_noffset_os, &os)) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100185 puts ("Can't get image OS!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100186 show_boot_progress (-111);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100187 return 1;
188 }
wdenk47d1a6e2002-11-03 00:01:44 +0000189
Marian Balakowicz6986a382008-03-12 10:01:05 +0100190 image_end = fit_get_end (images.fit_hdr_os);
191
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100192 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
Marian Balakowicz6986a382008-03-12 10:01:05 +0100193 &load_start)) {
194 puts ("Can't get image load address!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100195 show_boot_progress (-112);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100196 return 1;
wdenkb13fb012003-10-30 21:49:38 +0000197 }
198 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100199#endif
200 default:
201 puts ("ERROR: unknown image format type!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000202 return 1;
203 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100204
205 image_start = (ulong)os_hdr;
206 load_end = 0;
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100207 type_name = genimg_get_type_name (type);
wdenk47d1a6e2002-11-03 00:01:44 +0000208
209 /*
210 * We have reached the point of no return: we are going to
211 * overwrite all exception vector code, so we cannot easily
212 * recover from any failures any more...
213 */
wdenk47d1a6e2002-11-03 00:01:44 +0000214 iflag = disable_interrupts();
215
wdenkc7de8292002-11-19 11:04:11 +0000216#ifdef CONFIG_AMIGAONEG3SE
217 /*
wdenk8bde7f72003-06-27 21:31:46 +0000218 * We've possible left the caches enabled during
wdenkc7de8292002-11-19 11:04:11 +0000219 * bios emulation, so turn them off again
220 */
221 icache_disable();
222 invalidate_l1_instruction_cache();
223 flush_data_cache();
224 dcache_disable();
225#endif
226
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100227 switch (comp) {
wdenk47d1a6e2002-11-03 00:01:44 +0000228 case IH_COMP_NONE:
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100229 if (load_start == (ulong)os_hdr) {
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100230 printf (" XIP %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000231 } else {
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100232 printf (" Loading %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000233
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100234 memmove_wd ((void *)load_start,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100235 (void *)os_data, os_len, CHUNKSZ);
wdenk47d1a6e2002-11-03 00:01:44 +0000236
Marian Balakowicz75824382008-01-31 13:20:06 +0100237 load_end = load_start + os_len;
Marian Balakowiczaf13cdb2008-01-08 18:11:45 +0100238 puts("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000239 }
240 break;
241 case IH_COMP_GZIP:
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100242 printf (" Uncompressing %s ... ", type_name);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100243 if (gunzip ((void *)load_start, unc_len,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100244 (uchar *)os_data, &os_len) != 0) {
Marian Balakowicz2682ce82008-03-12 10:33:01 +0100245 puts ("GUNZIP: uncompress or overwrite error "
246 "- must RESET board to recover\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200247 show_boot_progress (-6);
wdenk47d1a6e2002-11-03 00:01:44 +0000248 do_reset (cmdtp, flag, argc, argv);
249 }
Marian Balakowicz75824382008-01-31 13:20:06 +0100250
251 load_end = load_start + os_len;
wdenk47d1a6e2002-11-03 00:01:44 +0000252 break;
wdenkc29fdfc2003-08-29 20:57:53 +0000253#ifdef CONFIG_BZIP2
254 case IH_COMP_BZIP2:
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100255 printf (" Uncompressing %s ... ", type_name);
wdenk5653fc32004-02-08 22:55:38 +0000256 /*
257 * If we've got less than 4 MB of malloc() space,
258 * use slower decompression algorithm which requires
259 * at most 2300 KB of memory.
260 */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100261 int i = BZ2_bzBuffToBuffDecompress ((char*)load_start,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100262 &unc_len, (char *)os_data, os_len,
263 CFG_MALLOC_LEN < (4096 * 1024), 0);
wdenkc29fdfc2003-08-29 20:57:53 +0000264 if (i != BZ_OK) {
Marian Balakowicz2682ce82008-03-12 10:33:01 +0100265 printf ("BUNZIP2: uncompress or overwrite error %d "
266 "- must RESET board to recover\n", i);
Heiko Schocherfad63402007-07-13 09:54:17 +0200267 show_boot_progress (-6);
wdenkc29fdfc2003-08-29 20:57:53 +0000268 do_reset (cmdtp, flag, argc, argv);
269 }
Marian Balakowicz75824382008-01-31 13:20:06 +0100270
271 load_end = load_start + unc_len;
wdenkc29fdfc2003-08-29 20:57:53 +0000272 break;
273#endif /* CONFIG_BZIP2 */
wdenk47d1a6e2002-11-03 00:01:44 +0000274 default:
275 if (iflag)
276 enable_interrupts();
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100277 printf ("Unimplemented compression type %d\n", comp);
Heiko Schocherfad63402007-07-13 09:54:17 +0200278 show_boot_progress (-7);
wdenk47d1a6e2002-11-03 00:01:44 +0000279 return 1;
280 }
wdenk4b9206e2004-03-23 22:14:11 +0000281 puts ("OK\n");
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100282 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end);
Heiko Schocherfad63402007-07-13 09:54:17 +0200283 show_boot_progress (7);
wdenk47d1a6e2002-11-03 00:01:44 +0000284
Marian Balakowicz75824382008-01-31 13:20:06 +0100285 if ((load_start < image_end) && (load_end > image_start)) {
286 debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end);
287 debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end);
wdenk47d1a6e2002-11-03 00:01:44 +0000288
Marian Balakowicz75824382008-01-31 13:20:06 +0100289 puts ("ERROR: image overwritten - must RESET the board to recover.\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100290 show_boot_progress (-113);
Marian Balakowicz75824382008-01-31 13:20:06 +0100291 do_reset (cmdtp, flag, argc, argv);
wdenk47d1a6e2002-11-03 00:01:44 +0000292 }
Marian Balakowicz75824382008-01-31 13:20:06 +0100293
Heiko Schocherfad63402007-07-13 09:54:17 +0200294 show_boot_progress (8);
wdenk47d1a6e2002-11-03 00:01:44 +0000295
Kumar Gala4ed65522008-02-27 21:51:47 -0600296 lmb_reserve(&lmb, load_start, (load_end - load_start));
297
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100298 switch (os) {
wdenk47d1a6e2002-11-03 00:01:44 +0000299 default: /* handled by (original) Linux case */
300 case IH_OS_LINUX:
wdenkf72da342003-10-10 10:05:42 +0000301#ifdef CONFIG_SILENT_CONSOLE
302 fixup_silent_linux();
303#endif
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100304 do_bootm_linux (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000305 break;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100306
wdenk47d1a6e2002-11-03 00:01:44 +0000307 case IH_OS_NETBSD:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100308 do_bootm_netbsd (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000309 break;
wdenk8bde7f72003-06-27 21:31:46 +0000310
wdenk1f4bb372003-07-27 00:21:01 +0000311#ifdef CONFIG_LYNXKDI
312 case IH_OS_LYNXOS:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100313 do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images);
wdenk1f4bb372003-07-27 00:21:01 +0000314 break;
315#endif
316
wdenkd791b1d2003-04-20 14:04:18 +0000317 case IH_OS_RTEMS:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100318 do_bootm_rtems (cmdtp, flag, argc, argv, &images);
wdenkd791b1d2003-04-20 14:04:18 +0000319 break;
wdenk8bde7f72003-06-27 21:31:46 +0000320
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500321#if defined(CONFIG_CMD_ELF)
wdenk47d1a6e2002-11-03 00:01:44 +0000322 case IH_OS_VXWORKS:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100323 do_bootm_vxworks (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000324 break;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100325
wdenk47d1a6e2002-11-03 00:01:44 +0000326 case IH_OS_QNX:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100327 do_bootm_qnxelf (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000328 break;
Jon Loeliger90253172007-07-10 11:02:44 -0500329#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100330
wdenk7f70e852003-05-20 14:25:27 +0000331#ifdef CONFIG_ARTOS
332 case IH_OS_ARTOS:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100333 do_bootm_artos (cmdtp, flag, argc, argv, &images);
wdenk7f70e852003-05-20 14:25:27 +0000334 break;
335#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000336 }
337
Heiko Schocherfad63402007-07-13 09:54:17 +0200338 show_boot_progress (-9);
wdenk47d1a6e2002-11-03 00:01:44 +0000339#ifdef DEBUG
wdenk4b9206e2004-03-23 22:14:11 +0000340 puts ("\n## Control returned to monitor - resetting...\n");
Marian Balakowicza44a2692008-03-12 10:14:57 +0100341 if (images.autostart)
342 do_reset (cmdtp, flag, argc, argv);
wdenk47d1a6e2002-11-03 00:01:44 +0000343#endif
Marian Balakowicza44a2692008-03-12 10:14:57 +0100344 if (!images.autostart && iflag)
345 enable_interrupts();
346
wdenk47d1a6e2002-11-03 00:01:44 +0000347 return 1;
348}
349
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100350/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100351 * image_get_kernel - verify legacy format kernel image
352 * @img_addr: in RAM address of the legacy format image to be verified
353 * @verify: data CRC verification flag
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100354 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100355 * image_get_kernel() verifies legacy image integrity and returns pointer to
356 * legacy image header if image verification was completed successfully.
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100357 *
358 * returns:
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100359 * pointer to a legacy image header if valid image was found
360 * otherwise return NULL
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100361 */
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100362static image_header_t *image_get_kernel (ulong img_addr, int verify)
363{
364 image_header_t *hdr = (image_header_t *)img_addr;
365
366 if (!image_check_magic(hdr)) {
367 puts ("Bad Magic Number\n");
368 show_boot_progress (-1);
369 return NULL;
370 }
371 show_boot_progress (2);
372
373 if (!image_check_hcrc (hdr)) {
374 puts ("Bad Header Checksum\n");
375 show_boot_progress (-2);
376 return NULL;
377 }
378
379 show_boot_progress (3);
380 image_print_contents (hdr);
381
382 if (verify) {
383 puts (" Verifying Checksum ... ");
384 if (!image_check_dcrc (hdr)) {
385 printf ("Bad Data CRC\n");
386 show_boot_progress (-3);
387 return NULL;
388 }
389 puts ("OK\n");
390 }
391 show_boot_progress (4);
392
393 if (!image_check_target_arch (hdr)) {
394 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
395 show_boot_progress (-4);
396 return NULL;
397 }
398 return hdr;
399}
400
401/**
Marian Balakowicz6986a382008-03-12 10:01:05 +0100402 * fit_check_kernel - verify FIT format kernel subimage
403 * @fit_hdr: pointer to the FIT image header
404 * os_noffset: kernel subimage node offset within FIT image
405 * @verify: data CRC verification flag
406 *
407 * fit_check_kernel() verifies integrity of the kernel subimage and from
408 * specified FIT image.
409 *
410 * returns:
411 * 1, on success
412 * 0, on failure
413 */
414#if defined (CONFIG_FIT)
415static int fit_check_kernel (const void *fit, int os_noffset, int verify)
416{
417 fit_image_print (fit, os_noffset, " ");
418
419 if (verify) {
420 puts (" Verifying Hash Integrity ... ");
421 if (!fit_image_check_hashes (fit, os_noffset)) {
422 puts ("Bad Data Hash\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100423 show_boot_progress (-104);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100424 return 0;
425 }
426 puts ("OK\n");
427 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100428 show_boot_progress (105);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100429
Bartlomiej Sieka27f33e92008-03-26 09:38:06 +0100430#ifdef CONFIG_LOGBUFFER
431#ifndef CONFIG_ALT_LB_ADDR
432 kbd=gd->bd;
433 /* Prevent initrd from overwriting logbuffer */
434 if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
435 initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
436 debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
437#else
438 debug ("## Logbuffer at 0x%08lX ", CONFIG_ALT_LB_ADDR);
439#endif
440#endif
Marian Balakowicz6986a382008-03-12 10:01:05 +0100441 if (!fit_image_check_target_arch (fit, os_noffset)) {
442 puts ("Unsupported Architecture\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100443 show_boot_progress (-105);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100444 return 0;
445 }
446
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100447 show_boot_progress (106);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100448 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
449 puts ("Not a kernel image\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100450 show_boot_progress (-106);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100451 return 0;
452 }
453
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100454 show_boot_progress (107);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100455 return 1;
456}
457#endif /* CONFIG_FIT */
458
459/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100460 * boot_get_kernel - find kernel image
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100461 * @os_data: pointer to a ulong variable, will hold os data start address
462 * @os_len: pointer to a ulong variable, will hold os data length
463 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100464 * boot_get_kernel() tries to find a kernel image, verifies its integrity
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100465 * and locates kernel data.
466 *
467 * returns:
468 * pointer to image header if valid image was found, plus kernel start
469 * address and length, otherwise NULL
470 */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100471static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100472 bootm_headers_t *images, ulong *os_data, ulong *os_len)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100473{
474 image_header_t *hdr;
475 ulong img_addr;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100476#if defined(CONFIG_FIT)
477 void *fit_hdr;
478 const char *fit_uname_config = NULL;
479 const char *fit_uname_kernel = NULL;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100480 const void *data;
481 size_t len;
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100482 int cfg_noffset;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100483 int os_noffset;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100484#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100485
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100486 /* find out kernel image address */
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100487 if (argc < 2) {
488 img_addr = load_addr;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100489 debug ("* kernel: default image load address = 0x%08lx\n",
490 load_addr);
491#if defined(CONFIG_FIT)
492 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
493 &fit_uname_config)) {
494 debug ("* kernel: config '%s' from image at 0x%08lx\n",
495 fit_uname_config, img_addr);
496 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
497 &fit_uname_kernel)) {
498 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
499 fit_uname_kernel, img_addr);
500#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100501 } else {
502 img_addr = simple_strtoul(argv[1], NULL, 16);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100503 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100504 }
505
506 show_boot_progress (1);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100507
Marian Balakowiczfff888a12008-02-21 17:20:19 +0100508 /* copy from dataflash if needed */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100509 img_addr = genimg_get_image (img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100510
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100511 /* check image type, for FIT images get FIT kernel node */
Marian Balakowicz6986a382008-03-12 10:01:05 +0100512 *os_data = *os_len = 0;
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100513 switch (genimg_get_format ((void *)img_addr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100514 case IMAGE_FORMAT_LEGACY:
Marian Balakowicz6986a382008-03-12 10:01:05 +0100515 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
516 img_addr);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100517 hdr = image_get_kernel (img_addr, images->verify);
518 if (!hdr)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100519 return NULL;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100520 show_boot_progress (5);
521
Marian Balakowicz6986a382008-03-12 10:01:05 +0100522 /* get os_data and os_len */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100523 switch (image_get_type (hdr)) {
524 case IH_TYPE_KERNEL:
525 *os_data = image_get_data (hdr);
526 *os_len = image_get_data_size (hdr);
527 break;
528 case IH_TYPE_MULTI:
529 image_multi_getimg (hdr, 0, os_data, os_len);
530 break;
531 default:
532 printf ("Wrong Image Type for %s command\n", cmdtp->name);
533 show_boot_progress (-5);
534 return NULL;
535 }
536 images->legacy_hdr_os = hdr;
537 images->legacy_hdr_valid = 1;
538
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100539 show_boot_progress (6);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100540 break;
541#if defined(CONFIG_FIT)
542 case IMAGE_FORMAT_FIT:
543 fit_hdr = (void *)img_addr;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100544 printf ("## Booting kernel from FIT Image at %08lx ...\n",
545 img_addr);
546
547 if (!fit_check_format (fit_hdr)) {
548 puts ("Bad FIT kernel image format!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100549 show_boot_progress (-100);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100550 return NULL;
551 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100552 show_boot_progress (100);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100553
554 if (!fit_uname_kernel) {
555 /*
556 * no kernel image node unit name, try to get config
557 * node first. If config unit node name is NULL
558 * fit_conf_get_node() will try to find default config node
559 */
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100560 show_boot_progress (101);
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100561 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
562 if (cfg_noffset < 0) {
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100563 show_boot_progress (-101);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100564 return NULL;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100565 }
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100566 /* save configuration uname provided in the first
567 * bootm argument
568 */
569 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
570 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
571 show_boot_progress (103);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100572
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100573 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100574 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
575 } else {
576 /* get kernel component image node offset */
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100577 show_boot_progress (102);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100578 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
579 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100580 if (os_noffset < 0) {
581 show_boot_progress (-103);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100582 return NULL;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100583 }
Marian Balakowicz6986a382008-03-12 10:01:05 +0100584
585 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
586
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100587 show_boot_progress (104);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100588 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
589 return NULL;
590
591 /* get kernel image data address and length */
592 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
593 puts ("Could not find kernel subimage data!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100594 show_boot_progress (-107);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100595 return NULL;
596 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100597 show_boot_progress (108);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100598
599 *os_len = len;
600 *os_data = (ulong)data;
601 images->fit_hdr_os = fit_hdr;
602 images->fit_uname_os = fit_uname_kernel;
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100603 images->fit_noffset_os = os_noffset;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100604 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100605#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100606 default:
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100607 printf ("Wrong Image Format for %s command\n", cmdtp->name);
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100608 show_boot_progress (-108);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100609 return NULL;
610 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100611
Marian Balakowicz6986a382008-03-12 10:01:05 +0100612 debug (" kernel data at 0x%08lx, len = 0x%08lx (%d)\n",
613 *os_data, *os_len, *os_len);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100614
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100615 return (void *)img_addr;
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100616}
617
wdenk0d498392003-07-01 21:06:45 +0000618U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100619 bootm, CFG_MAXARGS, 1, do_bootm,
620 "bootm - boot application image from memory\n",
621 "[addr [arg ...]]\n - boot application image stored in memory\n"
622 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
623 "\t'arg' can be the address of an initrd image\n"
Marian Balakowicz4a2ad5f2008-01-31 13:20:07 +0100624#if defined(CONFIG_OF_LIBFDT)
Matthew McClintock98a9c4d2006-06-28 10:41:37 -0500625 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
Detlev Zundel5441f612007-10-19 16:47:26 +0200626 "\ta third argument is required which is the address of the\n"
Matthew McClintock98a9c4d2006-06-28 10:41:37 -0500627 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
628 "\tuse a '-' for the second argument. If you do not pass a third\n"
629 "\ta bd_info struct will be passed instead\n"
630#endif
Marian Balakowicz6986a382008-03-12 10:01:05 +0100631#if defined(CONFIG_FIT)
632 "\t\nFor the new multi component uImage format (FIT) addresses\n"
633 "\tmust be extened to include component or configuration unit name:\n"
634 "\taddr:<subimg_uname> - direct component image specification\n"
635 "\taddr#<conf_uname> - configuration specification\n"
636 "\tUse iminfo command to get the list of existing component\n"
637 "\timages and configurations.\n"
638#endif
wdenk8bde7f72003-06-27 21:31:46 +0000639);
640
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100641/*******************************************************************/
642/* bootd - boot default image */
643/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500644#if defined(CONFIG_CMD_BOOTD)
wdenk47d1a6e2002-11-03 00:01:44 +0000645int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
646{
647 int rcode = 0;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100648
wdenk47d1a6e2002-11-03 00:01:44 +0000649#ifndef CFG_HUSH_PARSER
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100650 if (run_command (getenv ("bootcmd"), flag) < 0)
651 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000652#else
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100653 if (parse_string_outer (getenv ("bootcmd"),
654 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
655 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000656#endif
657 return rcode;
658}
wdenk8bde7f72003-06-27 21:31:46 +0000659
wdenk0d498392003-07-01 21:06:45 +0000660U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100661 boot, 1, 1, do_bootd,
662 "boot - boot default, i.e., run 'bootcmd'\n",
wdenk9d2b18a2003-06-28 23:11:04 +0000663 NULL
664);
665
666/* keep old command name "bootd" for backward compatibility */
wdenk0d498392003-07-01 21:06:45 +0000667U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100668 bootd, 1, 1, do_bootd,
669 "bootd - boot default, i.e., run 'bootcmd'\n",
wdenk8bde7f72003-06-27 21:31:46 +0000670 NULL
671);
672
wdenk47d1a6e2002-11-03 00:01:44 +0000673#endif
674
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100675
676/*******************************************************************/
677/* iminfo - print header info for a requested image */
678/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500679#if defined(CONFIG_CMD_IMI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100680int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000681{
682 int arg;
683 ulong addr;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100684 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000685
686 if (argc < 2) {
687 return image_info (load_addr);
688 }
689
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100690 for (arg = 1; arg < argc; ++arg) {
691 addr = simple_strtoul (argv[arg], NULL, 16);
692 if (image_info (addr) != 0)
693 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000694 }
695 return rcode;
696}
697
698static int image_info (ulong addr)
699{
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100700 void *hdr = (void *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +0000701
702 printf ("\n## Checking Image at %08lx ...\n", addr);
703
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100704 switch (genimg_get_format (hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100705 case IMAGE_FORMAT_LEGACY:
706 puts (" Legacy image found\n");
707 if (!image_check_magic (hdr)) {
708 puts (" Bad Magic Number\n");
709 return 1;
710 }
711
712 if (!image_check_hcrc (hdr)) {
713 puts (" Bad Header Checksum\n");
714 return 1;
715 }
716
717 image_print_contents (hdr);
718
719 puts (" Verifying Checksum ... ");
720 if (!image_check_dcrc (hdr)) {
721 puts (" Bad Data CRC\n");
722 return 1;
723 }
724 puts ("OK\n");
725 return 0;
726#if defined(CONFIG_FIT)
727 case IMAGE_FORMAT_FIT:
728 puts (" FIT image found\n");
Marian Balakowicze32fea62008-03-11 12:35:20 +0100729
730 if (!fit_check_format (hdr)) {
731 puts ("Bad FIT image format!\n");
732 return 1;
733 }
734
735 fit_print_contents (hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100736 return 0;
737#endif
738 default:
739 puts ("Unknown image format!\n");
740 break;
wdenk47d1a6e2002-11-03 00:01:44 +0000741 }
742
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100743 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000744}
wdenk0d498392003-07-01 21:06:45 +0000745
746U_BOOT_CMD(
747 iminfo, CFG_MAXARGS, 1, do_iminfo,
wdenk8bde7f72003-06-27 21:31:46 +0000748 "iminfo - print header information for application image\n",
749 "addr [addr ...]\n"
750 " - print header information for application image starting at\n"
751 " address 'addr' in memory; this includes verification of the\n"
752 " image contents (magic number, header and payload checksums)\n"
753);
Jon Loeliger90253172007-07-10 11:02:44 -0500754#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000755
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100756
757/*******************************************************************/
758/* imls - list all images found in flash */
759/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500760#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +0000761int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
762{
763 flash_info_t *info;
764 int i, j;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100765 void *hdr;
wdenk27b207f2003-07-24 23:38:38 +0000766
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100767 for (i = 0, info = &flash_info[0];
768 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
769
wdenk27b207f2003-07-24 23:38:38 +0000770 if (info->flash_id == FLASH_UNKNOWN)
771 goto next_bank;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100772 for (j = 0; j < info->sector_count; ++j) {
wdenk27b207f2003-07-24 23:38:38 +0000773
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100774 hdr = (void *)info->start[j];
775 if (!hdr)
wdenk27b207f2003-07-24 23:38:38 +0000776 goto next_sector;
777
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100778 switch (genimg_get_format (hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100779 case IMAGE_FORMAT_LEGACY:
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100780 if (!image_check_hcrc (hdr))
781 goto next_sector;
782
783 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
784 image_print_contents (hdr);
785
786 puts (" Verifying Checksum ... ");
787 if (!image_check_dcrc (hdr)) {
788 puts ("Bad Data CRC\n");
789 } else {
790 puts ("OK\n");
791 }
792 break;
793#if defined(CONFIG_FIT)
794 case IMAGE_FORMAT_FIT:
Marian Balakowicze32fea62008-03-11 12:35:20 +0100795 if (!fit_check_format (hdr))
796 goto next_sector;
797
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100798 printf ("FIT Image at %08lX:\n", (ulong)hdr);
Marian Balakowicze32fea62008-03-11 12:35:20 +0100799 fit_print_contents (hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100800 break;
801#endif
802 default:
wdenk27b207f2003-07-24 23:38:38 +0000803 goto next_sector;
wdenk5bb226e2003-11-17 21:14:37 +0000804 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100805
wdenkbdccc4f2003-08-05 17:43:17 +0000806next_sector: ;
wdenk27b207f2003-07-24 23:38:38 +0000807 }
wdenkbdccc4f2003-08-05 17:43:17 +0000808next_bank: ;
wdenk27b207f2003-07-24 23:38:38 +0000809 }
810
811 return (0);
812}
813
814U_BOOT_CMD(
815 imls, 1, 1, do_imls,
816 "imls - list all images found in flash\n",
817 "\n"
818 " - Prints information about all images found at sector\n"
819 " boundaries in flash.\n"
820);
Jon Loeliger90253172007-07-10 11:02:44 -0500821#endif
wdenk27b207f2003-07-24 23:38:38 +0000822
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100823/*******************************************************************/
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100824/* helper routines */
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100825/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +0000826#ifdef CONFIG_SILENT_CONSOLE
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100827static void fixup_silent_linux ()
wdenk47d1a6e2002-11-03 00:01:44 +0000828{
829 char buf[256], *start, *end;
830 char *cmdline = getenv ("bootargs");
831
832 /* Only fix cmdline when requested */
833 if (!(gd->flags & GD_FLG_SILENT))
834 return;
835
836 debug ("before silent fix-up: %s\n", cmdline);
837 if (cmdline) {
838 if ((start = strstr (cmdline, "console=")) != NULL) {
839 end = strchr (start, ' ');
840 strncpy (buf, cmdline, (start - cmdline + 8));
841 if (end)
842 strcpy (buf + (start - cmdline + 8), end);
843 else
844 buf[start - cmdline + 8] = '\0';
845 } else {
846 strcpy (buf, cmdline);
847 strcat (buf, " console=");
848 }
849 } else {
850 strcpy (buf, "console=");
851 }
852
853 setenv ("bootargs", buf);
854 debug ("after silent fix-up: %s\n", buf);
855}
856#endif /* CONFIG_SILENT_CONSOLE */
857
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100858
859/*******************************************************************/
860/* OS booting routines */
861/*******************************************************************/
862
863static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100864 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100865 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +0000866{
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100867 void (*loader)(bd_t *, image_header_t *, char *, char *);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100868 image_header_t *os_hdr, *hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100869 ulong kernel_data, kernel_len;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100870 char *consdev;
871 char *cmdline;
wdenk47d1a6e2002-11-03 00:01:44 +0000872
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100873#if defined(CONFIG_FIT)
874 if (!images->legacy_hdr_valid) {
875 fit_unsupported_reset ("NetBSD");
876 do_reset (cmdtp, flag, argc, argv);
wdenk47d1a6e2002-11-03 00:01:44 +0000877 }
878#endif
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100879 hdr = images->legacy_hdr_os;
wdenk47d1a6e2002-11-03 00:01:44 +0000880
881 /*
882 * Booting a (NetBSD) kernel image
883 *
884 * This process is pretty similar to a standalone application:
885 * The (first part of an multi-) image must be a stage-2 loader,
886 * which in turn is responsible for loading & invoking the actual
887 * kernel. The only differences are the parameters being passed:
888 * besides the board info strucure, the loader expects a command
889 * line, the name of the console device, and (optionally) the
890 * address of the original image header.
891 */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100892 os_hdr = NULL;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100893 if (image_check_type (hdr, IH_TYPE_MULTI)) {
894 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
895 if (kernel_len)
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100896 os_hdr = hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100897 }
wdenk47d1a6e2002-11-03 00:01:44 +0000898
899 consdev = "";
900#if defined (CONFIG_8xx_CONS_SMC1)
901 consdev = "smc1";
902#elif defined (CONFIG_8xx_CONS_SMC2)
903 consdev = "smc2";
904#elif defined (CONFIG_8xx_CONS_SCC2)
905 consdev = "scc2";
906#elif defined (CONFIG_8xx_CONS_SCC3)
907 consdev = "scc3";
908#endif
909
910 if (argc > 2) {
911 ulong len;
912 int i;
913
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100914 for (i = 2, len = 0; i < argc; i += 1)
wdenk47d1a6e2002-11-03 00:01:44 +0000915 len += strlen (argv[i]) + 1;
916 cmdline = malloc (len);
917
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100918 for (i = 2, len = 0; i < argc; i += 1) {
wdenk47d1a6e2002-11-03 00:01:44 +0000919 if (i > 2)
920 cmdline[len++] = ' ';
921 strcpy (&cmdline[len], argv[i]);
922 len += strlen (argv[i]);
923 }
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100924 } else if ((cmdline = getenv ("bootargs")) == NULL) {
wdenk47d1a6e2002-11-03 00:01:44 +0000925 cmdline = "";
926 }
927
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100928 loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000929
930 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
931 (ulong)loader);
932
933 show_boot_progress (15);
934
935 /*
936 * NetBSD Stage-2 Loader Parameters:
937 * r3: ptr to board info data
938 * r4: image address
939 * r5: console device
940 * r6: boot args string
941 */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100942 (*loader) (gd->bd, os_hdr, consdev, cmdline);
wdenk47d1a6e2002-11-03 00:01:44 +0000943}
944
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100945#ifdef CONFIG_LYNXKDI
946static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
947 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100948 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100949{
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100950 image_header_t *hdr = images->legacy_hdr_os;
951
952#if defined(CONFIG_FIT)
953 if (!images->legacy_hdr_valid) {
954 fit_unsupported_reset ("Lynx");
955 do_reset (cmdtp, flag, argc, argv);
956 }
957#endif
958
959 lynxkdi_boot ((image_header_t *)hdr);
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100960}
961#endif /* CONFIG_LYNXKDI */
962
963static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
964 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100965 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100966{
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100967 image_header_t *hdr = images->legacy_hdr_os;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100968 void (*entry_point)(bd_t *);
wdenkd791b1d2003-04-20 14:04:18 +0000969
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100970#if defined(CONFIG_FIT)
971 if (!images->legacy_hdr_valid) {
972 fit_unsupported_reset ("RTEMS");
973 do_reset (cmdtp, flag, argc, argv);
974 }
975#endif
976
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100977 entry_point = (void (*)(bd_t *))image_get_ep (hdr);
wdenkd791b1d2003-04-20 14:04:18 +0000978
979 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
980 (ulong)entry_point);
981
Heiko Schocherfad63402007-07-13 09:54:17 +0200982 show_boot_progress (15);
wdenkd791b1d2003-04-20 14:04:18 +0000983
984 /*
985 * RTEMS Parameters:
986 * r3: ptr to board info data
987 */
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100988 (*entry_point)(gd->bd);
wdenkd791b1d2003-04-20 14:04:18 +0000989}
990
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500991#if defined(CONFIG_CMD_ELF)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100992static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
993 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100994 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +0000995{
wdenk47d1a6e2002-11-03 00:01:44 +0000996 char str[80];
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100997 image_header_t *hdr = images->legacy_hdr_os;
998
999#if defined(CONFIG_FIT)
1000 if (hdr == NULL) {
1001 fit_unsupported_reset ("VxWorks");
1002 do_reset (cmdtp, flag, argc, argv);
1003 }
1004#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001005
Marian Balakowiczb97a2a02008-01-08 18:14:09 +01001006 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001007 setenv("loadaddr", str);
1008 do_bootvx(cmdtp, 0, 0, NULL);
1009}
1010
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001011static void do_bootm_qnxelf(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 *local_args[2];
1016 char str[16];
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001017 image_header_t *hdr = images->legacy_hdr_os;
1018
1019#if defined(CONFIG_FIT)
1020 if (!images->legacy_hdr_valid) {
1021 fit_unsupported_reset ("QNX");
1022 do_reset (cmdtp, flag, argc, argv);
1023 }
1024#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001025
Marian Balakowiczb97a2a02008-01-08 18:14:09 +01001026 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001027 local_args[0] = argv[0];
1028 local_args[1] = str; /* and provide it via the arguments */
1029 do_bootelf(cmdtp, 0, 2, local_args);
1030}
Jon Loeliger90253172007-07-10 11:02:44 -05001031#endif
wdenk1f4bb372003-07-27 00:21:01 +00001032
wdenk47d1a6e2002-11-03 00:01:44 +00001033#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001034static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
1035 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001036 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001037{
1038 ulong top;
1039 char *s, *cmdline;
1040 char **fwenv, **ss;
1041 int i, j, nxt, len, envno, envsz;
1042 bd_t *kbd;
1043 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001044 image_header_t *hdr = images->legacy_hdr_os;
1045
1046#if defined(CONFIG_FIT)
1047 if (!images->legacy_hdr_valid) {
1048 fit_unsupported_reset ("ARTOS");
1049 do_reset (cmdtp, flag, argc, argv);
1050 }
1051#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001052
1053 /*
1054 * Booting an ARTOS kernel image + application
1055 */
1056
1057 /* this used to be the top of memory, but was wrong... */
1058#ifdef CONFIG_PPC
1059 /* get stack pointer */
1060 asm volatile ("mr %0,1" : "=r"(top) );
1061#endif
1062 debug ("## Current stack ends at 0x%08lX ", top);
1063
1064 top -= 2048; /* just to be sure */
1065 if (top > CFG_BOOTMAPSZ)
1066 top = CFG_BOOTMAPSZ;
1067 top &= ~0xF;
1068
1069 debug ("=> set upper limit to 0x%08lX\n", top);
1070
1071 /* first check the artos specific boot args, then the linux args*/
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001072 if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
wdenk47d1a6e2002-11-03 00:01:44 +00001073 s = "";
1074
1075 /* get length of cmdline, and place it */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001076 len = strlen (s);
wdenk47d1a6e2002-11-03 00:01:44 +00001077 top = (top - (len + 1)) & ~0xF;
1078 cmdline = (char *)top;
1079 debug ("## cmdline at 0x%08lX ", top);
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001080 strcpy (cmdline, s);
wdenk47d1a6e2002-11-03 00:01:44 +00001081
1082 /* copy bdinfo */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001083 top = (top - sizeof (bd_t)) & ~0xF;
wdenk47d1a6e2002-11-03 00:01:44 +00001084 debug ("## bd at 0x%08lX ", top);
1085 kbd = (bd_t *)top;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001086 memcpy (kbd, gd->bd, sizeof (bd_t));
wdenk47d1a6e2002-11-03 00:01:44 +00001087
1088 /* first find number of env entries, and their size */
1089 envno = 0;
1090 envsz = 0;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001091 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1092 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
wdenk47d1a6e2002-11-03 00:01:44 +00001093 ;
1094 envno++;
1095 envsz += (nxt - i) + 1; /* plus trailing zero */
1096 }
1097 envno++; /* plus the terminating zero */
1098 debug ("## %u envvars total size %u ", envno, envsz);
1099
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001100 top = (top - sizeof (char **) * envno) & ~0xF;
wdenk47d1a6e2002-11-03 00:01:44 +00001101 fwenv = (char **)top;
1102 debug ("## fwenv at 0x%08lX ", top);
1103
1104 top = (top - envsz) & ~0xF;
1105 s = (char *)top;
1106 ss = fwenv;
1107
1108 /* now copy them */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001109 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1110 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
wdenk47d1a6e2002-11-03 00:01:44 +00001111 ;
1112 *ss++ = s;
1113 for (j = i; j < nxt; ++j)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001114 *s++ = env_get_char (j);
wdenk47d1a6e2002-11-03 00:01:44 +00001115 *s++ = '\0';
1116 }
1117 *ss++ = NULL; /* terminate */
1118
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001119 entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
1120 (*entry) (kbd, cmdline, fwenv, top);
wdenk47d1a6e2002-11-03 00:01:44 +00001121}
1122#endif