blob: ebb6b69f4d11c84e8af56959eeacd80a55addb78 [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#define DEBUG
25
wdenk47d1a6e2002-11-03 00:01:44 +000026/*
27 * Boot support
28 */
29#include <common.h>
30#include <watchdog.h>
31#include <command.h>
wdenk47d1a6e2002-11-03 00:01:44 +000032#include <image.h>
33#include <malloc.h>
34#include <zlib.h>
wdenkc29fdfc2003-08-29 20:57:53 +000035#include <bzlib.h>
wdenk7f70e852003-05-20 14:25:27 +000036#include <environment.h>
wdenk47d1a6e2002-11-03 00:01:44 +000037#include <asm/byteorder.h>
wdenk8bde7f72003-06-27 21:31:46 +000038
Jon Loeligerbaa26db2007-07-08 17:51:39 -050039#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
wdenk47d1a6e2002-11-03 00:01:44 +000040#include <rtc.h>
41#endif
42
43#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 */
52#endif
wdenk47d1a6e2002-11-03 00:01:44 +000053
Marian Balakowicz321359f2008-01-08 18:11:43 +010054#ifdef CONFIG_BZIP2
55extern void bz_internal_error(int);
56#endif
wdenk47d1a6e2002-11-03 00:01:44 +000057
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);
70#endif
71
wdenk47d1a6e2002-11-03 00:01:44 +000072static void print_type (image_header_t *hdr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +010073static image_header_t *get_kernel (cmd_tbl_t *cmdtp, int flag,
74 int argc, char *argv[], int verify,
75 ulong *os_data, ulong *os_len);
Marian Balakowicz1ee11802008-01-08 18:17:10 +010076extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
wdenk47d1a6e2002-11-03 00:01:44 +000077
78/*
79 * Continue booting an OS image; caller already has:
80 * - copied image header to global variable `header'
81 * - checked header magic number, checksums (both header & image),
82 * - verified image architecture (PPC) and type (KERNEL or MULTI),
83 * - loaded (first part of) image to header load address,
84 * - disabled interrupts.
85 */
Marian Balakowicz1ee11802008-01-08 18:17:10 +010086typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010087 int argc, char *argv[],
88 image_header_t *hdr, /* of image to boot */
89 int verify); /* getenv("verify")[0] != 'n' */
wdenk47d1a6e2002-11-03 00:01:44 +000090
Marian Balakowicz1ee11802008-01-08 18:17:10 +010091extern boot_os_fn do_bootm_linux;
92static boot_os_fn do_bootm_netbsd;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010093#if defined(CONFIG_LYNXKDI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +010094static boot_os_fn do_bootm_lynxkdi;
95extern void lynxkdi_boot (image_header_t *);
wdenkf72da342003-10-10 10:05:42 +000096#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +010097static boot_os_fn do_bootm_rtems;
Jon Loeligerbaa26db2007-07-08 17:51:39 -050098#if defined(CONFIG_CMD_ELF)
Marian Balakowicz1ee11802008-01-08 18:17:10 +010099static boot_os_fn do_bootm_vxworks;
100static boot_os_fn do_bootm_qnxelf;
101int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
102int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
Jon Loeliger90253172007-07-10 11:02:44 -0500103#endif
wdenk7f70e852003-05-20 14:25:27 +0000104#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100105extern uchar (*env_get_char)(int); /* Returns a character from the environment */
106static boot_os_fn do_bootm_artos;
Stefan Roese15940c92006-03-13 11:16:36 +0100107#endif
108
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100109ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
wdenk47d1a6e2002-11-03 00:01:44 +0000110
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100111
112/*******************************************************************/
113/* bootm - boot application image from image in memory */
114/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +0000115int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
116{
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100117 ulong iflag;
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100118 const char *type_name;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100119 uint unc_len = CFG_BOOTM_LEN;
120 int verify = getenv_verify();
wdenk47d1a6e2002-11-03 00:01:44 +0000121
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100122 image_header_t *hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100123 ulong os_data, os_len;
wdenk47d1a6e2002-11-03 00:01:44 +0000124
Marian Balakowicz75824382008-01-31 13:20:06 +0100125 ulong image_start, image_end;
126 ulong load_start, load_end;
127
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100128 /* get kernel image header, start address and length */
129 hdr = get_kernel (cmdtp, flag, argc, argv, verify,
130 &os_data, &os_len);
131 if (hdr == NULL)
wdenk47d1a6e2002-11-03 00:01:44 +0000132 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000133
Heiko Schocherfad63402007-07-13 09:54:17 +0200134 show_boot_progress (6);
wdenk47d1a6e2002-11-03 00:01:44 +0000135
136 /*
137 * We have reached the point of no return: we are going to
138 * overwrite all exception vector code, so we cannot easily
139 * recover from any failures any more...
140 */
wdenk47d1a6e2002-11-03 00:01:44 +0000141 iflag = disable_interrupts();
142
wdenkc7de8292002-11-19 11:04:11 +0000143#ifdef CONFIG_AMIGAONEG3SE
144 /*
wdenk8bde7f72003-06-27 21:31:46 +0000145 * We've possible left the caches enabled during
wdenkc7de8292002-11-19 11:04:11 +0000146 * bios emulation, so turn them off again
147 */
148 icache_disable();
149 invalidate_l1_instruction_cache();
150 flush_data_cache();
151 dcache_disable();
152#endif
153
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100154 type_name = image_get_type_name (image_get_type (hdr));
155
Marian Balakowicz75824382008-01-31 13:20:06 +0100156 image_start = (ulong)hdr;
157 image_end = image_get_image_end (hdr);
158 load_start = image_get_load (hdr);
159 load_end = 0;
160
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100161 switch (image_get_comp (hdr)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000162 case IH_COMP_NONE:
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100163 if (image_get_load (hdr) == (ulong)hdr) {
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100164 printf (" XIP %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000165 } else {
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100166 printf (" Loading %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000167
Marian Balakowiczaf13cdb2008-01-08 18:11:45 +0100168 memmove_wd ((void *)image_get_load (hdr),
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100169 (void *)os_data, os_len, CHUNKSZ);
Marian Balakowiczaf13cdb2008-01-08 18:11:45 +0100170
Marian Balakowicz75824382008-01-31 13:20:06 +0100171 load_end = load_start + os_len;
Marian Balakowiczaf13cdb2008-01-08 18:11:45 +0100172 puts("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000173 }
174 break;
175 case IH_COMP_GZIP:
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100176 printf (" Uncompressing %s ... ", type_name);
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100177 if (gunzip ((void *)image_get_load (hdr), unc_len,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100178 (uchar *)os_data, &os_len) != 0) {
wdenk4b9206e2004-03-23 22:14:11 +0000179 puts ("GUNZIP ERROR - must RESET board to recover\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200180 show_boot_progress (-6);
wdenk47d1a6e2002-11-03 00:01:44 +0000181 do_reset (cmdtp, flag, argc, argv);
182 }
Marian Balakowicz75824382008-01-31 13:20:06 +0100183
184 load_end = load_start + os_len;
wdenk47d1a6e2002-11-03 00:01:44 +0000185 break;
wdenkc29fdfc2003-08-29 20:57:53 +0000186#ifdef CONFIG_BZIP2
187 case IH_COMP_BZIP2:
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100188 printf (" Uncompressing %s ... ", type_name);
wdenk5653fc32004-02-08 22:55:38 +0000189 /*
190 * If we've got less than 4 MB of malloc() space,
191 * use slower decompression algorithm which requires
192 * at most 2300 KB of memory.
193 */
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100194 int i = BZ2_bzBuffToBuffDecompress ((char*)image_get_load (hdr),
195 &unc_len, (char *)os_data, os_len,
196 CFG_MALLOC_LEN < (4096 * 1024), 0);
wdenkc29fdfc2003-08-29 20:57:53 +0000197 if (i != BZ_OK) {
198 printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
Heiko Schocherfad63402007-07-13 09:54:17 +0200199 show_boot_progress (-6);
wdenkc29fdfc2003-08-29 20:57:53 +0000200 do_reset (cmdtp, flag, argc, argv);
201 }
Marian Balakowicz75824382008-01-31 13:20:06 +0100202
203 load_end = load_start + unc_len;
wdenkc29fdfc2003-08-29 20:57:53 +0000204 break;
205#endif /* CONFIG_BZIP2 */
wdenk47d1a6e2002-11-03 00:01:44 +0000206 default:
207 if (iflag)
208 enable_interrupts();
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100209 printf ("Unimplemented compression type %d\n", image_get_comp (hdr));
Heiko Schocherfad63402007-07-13 09:54:17 +0200210 show_boot_progress (-7);
wdenk47d1a6e2002-11-03 00:01:44 +0000211 return 1;
212 }
wdenk4b9206e2004-03-23 22:14:11 +0000213 puts ("OK\n");
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100214 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end);
Heiko Schocherfad63402007-07-13 09:54:17 +0200215 show_boot_progress (7);
wdenk47d1a6e2002-11-03 00:01:44 +0000216
Marian Balakowicz75824382008-01-31 13:20:06 +0100217 if ((load_start < image_end) && (load_end > image_start)) {
218 debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end);
219 debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end);
220
221 puts ("ERROR: image overwritten - must RESET the board to recover.\n");
222 do_reset (cmdtp, flag, argc, argv);
223 }
224
Heiko Schocherfad63402007-07-13 09:54:17 +0200225 show_boot_progress (8);
wdenk47d1a6e2002-11-03 00:01:44 +0000226
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100227 switch (image_get_os (hdr)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000228 default: /* handled by (original) Linux case */
229 case IH_OS_LINUX:
wdenkf72da342003-10-10 10:05:42 +0000230#ifdef CONFIG_SILENT_CONSOLE
231 fixup_silent_linux();
232#endif
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100233 do_bootm_linux (cmdtp, flag, argc, argv, hdr, verify);
wdenk47d1a6e2002-11-03 00:01:44 +0000234 break;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100235
wdenk47d1a6e2002-11-03 00:01:44 +0000236 case IH_OS_NETBSD:
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100237 do_bootm_netbsd (cmdtp, flag, argc, argv, hdr, verify);
wdenk47d1a6e2002-11-03 00:01:44 +0000238 break;
wdenk8bde7f72003-06-27 21:31:46 +0000239
wdenk1f4bb372003-07-27 00:21:01 +0000240#ifdef CONFIG_LYNXKDI
241 case IH_OS_LYNXOS:
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100242 do_bootm_lynxkdi (cmdtp, flag, argc, argv, hdr, verify);
wdenk1f4bb372003-07-27 00:21:01 +0000243 break;
244#endif
245
wdenkd791b1d2003-04-20 14:04:18 +0000246 case IH_OS_RTEMS:
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100247 do_bootm_rtems (cmdtp, flag, argc, argv, hdr, verify);
wdenkd791b1d2003-04-20 14:04:18 +0000248 break;
wdenk8bde7f72003-06-27 21:31:46 +0000249
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500250#if defined(CONFIG_CMD_ELF)
wdenk47d1a6e2002-11-03 00:01:44 +0000251 case IH_OS_VXWORKS:
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100252 do_bootm_vxworks (cmdtp, flag, argc, argv, hdr, verify);
wdenk47d1a6e2002-11-03 00:01:44 +0000253 break;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100254
wdenk47d1a6e2002-11-03 00:01:44 +0000255 case IH_OS_QNX:
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100256 do_bootm_qnxelf (cmdtp, flag, argc, argv, hdr, verify);
wdenk47d1a6e2002-11-03 00:01:44 +0000257 break;
Jon Loeliger90253172007-07-10 11:02:44 -0500258#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100259
wdenk7f70e852003-05-20 14:25:27 +0000260#ifdef CONFIG_ARTOS
261 case IH_OS_ARTOS:
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100262 do_bootm_artos (cmdtp, flag, argc, argv, hdr, verify);
wdenk7f70e852003-05-20 14:25:27 +0000263 break;
264#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000265 }
266
Heiko Schocherfad63402007-07-13 09:54:17 +0200267 show_boot_progress (-9);
wdenk47d1a6e2002-11-03 00:01:44 +0000268#ifdef DEBUG
wdenk4b9206e2004-03-23 22:14:11 +0000269 puts ("\n## Control returned to monitor - resetting...\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000270 do_reset (cmdtp, flag, argc, argv);
271#endif
272 return 1;
273}
274
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100275/**
276 * get_kernel - find kernel image
277 * @os_data: pointer to a ulong variable, will hold os data start address
278 * @os_len: pointer to a ulong variable, will hold os data length
279 *
280 * get_kernel() tries to find a kernel image, verifies its integrity
281 * and locates kernel data.
282 *
283 * returns:
284 * pointer to image header if valid image was found, plus kernel start
285 * address and length, otherwise NULL
286 */
287static image_header_t *get_kernel (cmd_tbl_t *cmdtp, int flag,
288 int argc, char *argv[], int verify,
289 ulong *os_data, ulong *os_len)
290{
291 image_header_t *hdr;
292 ulong img_addr;
293
294 if (argc < 2) {
295 img_addr = load_addr;
296 } else {
297 img_addr = simple_strtoul(argv[1], NULL, 16);
298 }
299
300 show_boot_progress (1);
301 printf ("## Booting image at %08lx ...\n", img_addr);
302
Marian Balakowiczfff888a12008-02-21 17:20:19 +0100303 /* copy from dataflash if needed */
304 img_addr = gen_get_image (img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100305 hdr = (image_header_t *)img_addr;
306
307 if (!image_check_magic(hdr)) {
308 puts ("Bad Magic Number\n");
309 show_boot_progress (-1);
310 return NULL;
311 }
312 show_boot_progress (2);
313
314 if (!image_check_hcrc (hdr)) {
315 puts ("Bad Header Checksum\n");
316 show_boot_progress (-2);
317 return NULL;
318 }
Marian Balakowiczfff888a12008-02-21 17:20:19 +0100319
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100320 show_boot_progress (3);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100321 print_image_hdr (hdr);
322
323 if (verify) {
324 puts (" Verifying Checksum ... ");
325 if (!image_check_dcrc (hdr)) {
326 printf ("Bad Data CRC\n");
327 show_boot_progress (-3);
328 return NULL;
329 }
330 puts ("OK\n");
331 }
332 show_boot_progress (4);
333
334 if (!image_check_target_arch (hdr)) {
335 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
336 show_boot_progress (-4);
337 return NULL;
338 }
339 show_boot_progress (5);
340
341 switch (image_get_type (hdr)) {
342 case IH_TYPE_KERNEL:
343 *os_data = image_get_data (hdr);
344 *os_len = image_get_data_size (hdr);
345 break;
346 case IH_TYPE_MULTI:
347 image_multi_getimg (hdr, 0, os_data, os_len);
348 break;
349 default:
350 printf ("Wrong Image Type for %s command\n", cmdtp->name);
351 show_boot_progress (-5);
352 return NULL;
353 }
354 debug (" kernel data at 0x%08lx, end = 0x%08lx\n",
355 *os_data, *os_data + *os_len);
356
357 return hdr;
358}
359
wdenk0d498392003-07-01 21:06:45 +0000360U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100361 bootm, CFG_MAXARGS, 1, do_bootm,
362 "bootm - boot application image from memory\n",
363 "[addr [arg ...]]\n - boot application image stored in memory\n"
364 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
365 "\t'arg' can be the address of an initrd image\n"
Marian Balakowicz4a2ad5f2008-01-31 13:20:07 +0100366#if defined(CONFIG_OF_LIBFDT)
Matthew McClintock98a9c4d2006-06-28 10:41:37 -0500367 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
Detlev Zundel5441f612007-10-19 16:47:26 +0200368 "\ta third argument is required which is the address of the\n"
Matthew McClintock98a9c4d2006-06-28 10:41:37 -0500369 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
370 "\tuse a '-' for the second argument. If you do not pass a third\n"
371 "\ta bd_info struct will be passed instead\n"
372#endif
wdenk8bde7f72003-06-27 21:31:46 +0000373);
374
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100375/*******************************************************************/
376/* bootd - boot default image */
377/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500378#if defined(CONFIG_CMD_BOOTD)
wdenk47d1a6e2002-11-03 00:01:44 +0000379int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
380{
381 int rcode = 0;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100382
wdenk47d1a6e2002-11-03 00:01:44 +0000383#ifndef CFG_HUSH_PARSER
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100384 if (run_command (getenv ("bootcmd"), flag) < 0)
385 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000386#else
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100387 if (parse_string_outer (getenv ("bootcmd"),
388 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
389 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000390#endif
391 return rcode;
392}
wdenk8bde7f72003-06-27 21:31:46 +0000393
wdenk0d498392003-07-01 21:06:45 +0000394U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100395 boot, 1, 1, do_bootd,
396 "boot - boot default, i.e., run 'bootcmd'\n",
wdenk9d2b18a2003-06-28 23:11:04 +0000397 NULL
398);
399
400/* keep old command name "bootd" for backward compatibility */
wdenk0d498392003-07-01 21:06:45 +0000401U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100402 bootd, 1, 1, do_bootd,
403 "bootd - boot default, i.e., run 'bootcmd'\n",
wdenk8bde7f72003-06-27 21:31:46 +0000404 NULL
405);
406
wdenk47d1a6e2002-11-03 00:01:44 +0000407#endif
408
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100409
410/*******************************************************************/
411/* iminfo - print header info for a requested image */
412/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500413#if defined(CONFIG_CMD_IMI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100414int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000415{
416 int arg;
417 ulong addr;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100418 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000419
420 if (argc < 2) {
421 return image_info (load_addr);
422 }
423
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100424 for (arg = 1; arg < argc; ++arg) {
425 addr = simple_strtoul (argv[arg], NULL, 16);
426 if (image_info (addr) != 0)
427 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000428 }
429 return rcode;
430}
431
432static int image_info (ulong addr)
433{
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100434 image_header_t *hdr = (image_header_t *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +0000435
436 printf ("\n## Checking Image at %08lx ...\n", addr);
437
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100438 if (!image_check_magic (hdr)) {
wdenk4b9206e2004-03-23 22:14:11 +0000439 puts (" Bad Magic Number\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000440 return 1;
441 }
442
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100443 if (!image_check_hcrc (hdr)) {
wdenk4b9206e2004-03-23 22:14:11 +0000444 puts (" Bad Header Checksum\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000445 return 1;
446 }
447
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100448 print_image_hdr (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000449
wdenk4b9206e2004-03-23 22:14:11 +0000450 puts (" Verifying Checksum ... ");
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100451 if (!image_check_dcrc (hdr)) {
wdenk4b9206e2004-03-23 22:14:11 +0000452 puts (" Bad Data CRC\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000453 return 1;
454 }
wdenk4b9206e2004-03-23 22:14:11 +0000455 puts ("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000456 return 0;
457}
wdenk0d498392003-07-01 21:06:45 +0000458
459U_BOOT_CMD(
460 iminfo, CFG_MAXARGS, 1, do_iminfo,
wdenk8bde7f72003-06-27 21:31:46 +0000461 "iminfo - print header information for application image\n",
462 "addr [addr ...]\n"
463 " - print header information for application image starting at\n"
464 " address 'addr' in memory; this includes verification of the\n"
465 " image contents (magic number, header and payload checksums)\n"
466);
Jon Loeliger90253172007-07-10 11:02:44 -0500467#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000468
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100469
470/*******************************************************************/
471/* imls - list all images found in flash */
472/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500473#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +0000474int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
475{
476 flash_info_t *info;
477 int i, j;
478 image_header_t *hdr;
wdenk27b207f2003-07-24 23:38:38 +0000479
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100480 for (i = 0, info = &flash_info[0];
481 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
482
wdenk27b207f2003-07-24 23:38:38 +0000483 if (info->flash_id == FLASH_UNKNOWN)
484 goto next_bank;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100485 for (j = 0; j < info->sector_count; ++j) {
wdenk27b207f2003-07-24 23:38:38 +0000486
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100487 hdr = (image_header_t *)info->start[j];
488
489 if (!hdr || !image_check_magic (hdr))
wdenk27b207f2003-07-24 23:38:38 +0000490 goto next_sector;
491
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100492 if (!image_check_hcrc (hdr))
wdenk27b207f2003-07-24 23:38:38 +0000493 goto next_sector;
494
495 printf ("Image at %08lX:\n", (ulong)hdr);
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100496 print_image_hdr (hdr);
wdenk5bb226e2003-11-17 21:14:37 +0000497
wdenk4b9206e2004-03-23 22:14:11 +0000498 puts (" Verifying Checksum ... ");
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100499 if (!image_check_dcrc (hdr)) {
500 puts ("Bad Data CRC\n");
501 } else {
502 puts ("OK\n");
wdenk5bb226e2003-11-17 21:14:37 +0000503 }
wdenkbdccc4f2003-08-05 17:43:17 +0000504next_sector: ;
wdenk27b207f2003-07-24 23:38:38 +0000505 }
wdenkbdccc4f2003-08-05 17:43:17 +0000506next_bank: ;
wdenk27b207f2003-07-24 23:38:38 +0000507 }
508
509 return (0);
510}
511
512U_BOOT_CMD(
513 imls, 1, 1, do_imls,
514 "imls - list all images found in flash\n",
515 "\n"
516 " - Prints information about all images found at sector\n"
517 " boundaries in flash.\n"
518);
Jon Loeliger90253172007-07-10 11:02:44 -0500519#endif
wdenk27b207f2003-07-24 23:38:38 +0000520
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100521/*******************************************************************/
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100522/* helper routines */
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100523/*******************************************************************/
524void print_image_hdr (image_header_t *hdr)
wdenk47d1a6e2002-11-03 00:01:44 +0000525{
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500526#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100527 time_t timestamp = (time_t)image_get_time (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000528 struct rtc_time tm;
529#endif
530
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100531 printf (" Image Name: %.*s\n", IH_NMLEN, image_get_name (hdr));
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100532
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500533#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
wdenk47d1a6e2002-11-03 00:01:44 +0000534 to_tm (timestamp, &tm);
535 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
536 tm.tm_year, tm.tm_mon, tm.tm_mday,
537 tm.tm_hour, tm.tm_min, tm.tm_sec);
Jon Loeliger90253172007-07-10 11:02:44 -0500538#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100539 puts (" Image Type: ");
540 print_type (hdr);
541
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100542 printf ("\n Data Size: %d Bytes = ", image_get_data_size (hdr));
543 print_size (image_get_data_size (hdr), "\n");
wdenk4b9206e2004-03-23 22:14:11 +0000544 printf (" Load Address: %08x\n"
545 " Entry Point: %08x\n",
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100546 image_get_load (hdr), image_get_ep (hdr));
wdenk47d1a6e2002-11-03 00:01:44 +0000547
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100548 if (image_check_type (hdr, IH_TYPE_MULTI)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000549 int i;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100550 ulong data, len;
551 ulong count = image_multi_count (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000552
wdenk4b9206e2004-03-23 22:14:11 +0000553 puts (" Contents:\n");
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100554 for (i = 0; i < count; i++) {
555 image_multi_getimg (hdr, i, &data, &len);
wdenk47d1a6e2002-11-03 00:01:44 +0000556 printf (" Image %d: %8ld Bytes = ", i, len);
557 print_size (len, "\n");
558 }
559 }
560}
561
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100562static void print_type (image_header_t *hdr)
wdenk47d1a6e2002-11-03 00:01:44 +0000563{
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100564 const char *os, *arch, *type, *comp;
wdenk47d1a6e2002-11-03 00:01:44 +0000565
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100566 os = image_get_os_name (image_get_os (hdr));
567 arch = image_get_arch_name (image_get_arch (hdr));
568 type = image_get_type_name (image_get_type (hdr));
569 comp = image_get_comp_name (image_get_comp (hdr));
wdenk47d1a6e2002-11-03 00:01:44 +0000570
571 printf ("%s %s %s (%s)", arch, os, type, comp);
572}
573
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100574#ifdef CONFIG_SILENT_CONSOLE
575static void fixup_silent_linux ()
576{
577 char buf[256], *start, *end;
578 char *cmdline = getenv ("bootargs");
579
580 /* Only fix cmdline when requested */
581 if (!(gd->flags & GD_FLG_SILENT))
582 return;
583
584 debug ("before silent fix-up: %s\n", cmdline);
585 if (cmdline) {
586 if ((start = strstr (cmdline, "console=")) != NULL) {
587 end = strchr (start, ' ');
588 strncpy (buf, cmdline, (start - cmdline + 8));
589 if (end)
590 strcpy (buf + (start - cmdline + 8), end);
591 else
592 buf[start - cmdline + 8] = '\0';
593 } else {
594 strcpy (buf, cmdline);
595 strcat (buf, " console=");
596 }
597 } else {
598 strcpy (buf, "console=");
599 }
600
601 setenv ("bootargs", buf);
602 debug ("after silent fix-up: %s\n", buf);
603}
604#endif /* CONFIG_SILENT_CONSOLE */
605
606
607/*******************************************************************/
608/* OS booting routines */
609/*******************************************************************/
610
611static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100612 int argc, char *argv[],
613 image_header_t *hdr, int verify)
wdenkd791b1d2003-04-20 14:04:18 +0000614{
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100615 void (*loader)(bd_t *, image_header_t *, char *, char *);
616 image_header_t *img_addr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100617 ulong kernel_data, kernel_len;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100618 char *consdev;
619 char *cmdline;
620
621 /*
622 * Booting a (NetBSD) kernel image
623 *
624 * This process is pretty similar to a standalone application:
625 * The (first part of an multi-) image must be a stage-2 loader,
626 * which in turn is responsible for loading & invoking the actual
627 * kernel. The only differences are the parameters being passed:
628 * besides the board info strucure, the loader expects a command
629 * line, the name of the console device, and (optionally) the
630 * address of the original image header.
631 */
632
633 img_addr = 0;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100634 if (image_check_type (hdr, IH_TYPE_MULTI)) {
635 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
636 if (kernel_len)
637 img_addr = hdr;
638 }
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100639
640 consdev = "";
641#if defined (CONFIG_8xx_CONS_SMC1)
642 consdev = "smc1";
643#elif defined (CONFIG_8xx_CONS_SMC2)
644 consdev = "smc2";
645#elif defined (CONFIG_8xx_CONS_SCC2)
646 consdev = "scc2";
647#elif defined (CONFIG_8xx_CONS_SCC3)
648 consdev = "scc3";
649#endif
650
651 if (argc > 2) {
652 ulong len;
653 int i;
654
655 for (i = 2, len = 0; i < argc; i += 1)
656 len += strlen (argv[i]) + 1;
657 cmdline = malloc (len);
658
659 for (i = 2, len = 0; i < argc; i += 1) {
660 if (i > 2)
661 cmdline[len++] = ' ';
662 strcpy (&cmdline[len], argv[i]);
663 len += strlen (argv[i]);
664 }
665 } else if ((cmdline = getenv ("bootargs")) == NULL) {
666 cmdline = "";
667 }
668
669 loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
670
671 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
672 (ulong)loader);
673
674 show_boot_progress (15);
675
676 /*
677 * NetBSD Stage-2 Loader Parameters:
678 * r3: ptr to board info data
679 * r4: image address
680 * r5: console device
681 * r6: boot args string
682 */
683 (*loader) (gd->bd, img_addr, consdev, cmdline);
684}
685
686#ifdef CONFIG_LYNXKDI
687static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
688 int argc, char *argv[],
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100689 image_header_t *hdr, int verify)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100690{
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100691 lynxkdi_boot (hdr);
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100692}
693#endif /* CONFIG_LYNXKDI */
694
695static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
696 int argc, char *argv[],
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100697 image_header_t *hdr, int verify)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100698{
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100699 void (*entry_point)(bd_t *);
wdenkd791b1d2003-04-20 14:04:18 +0000700
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100701 entry_point = (void (*)(bd_t *))image_get_ep (hdr);
wdenkd791b1d2003-04-20 14:04:18 +0000702
703 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
704 (ulong)entry_point);
705
Heiko Schocherfad63402007-07-13 09:54:17 +0200706 show_boot_progress (15);
wdenkd791b1d2003-04-20 14:04:18 +0000707
708 /*
709 * RTEMS Parameters:
710 * r3: ptr to board info data
711 */
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100712 (*entry_point)(gd->bd);
wdenkd791b1d2003-04-20 14:04:18 +0000713}
714
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500715#if defined(CONFIG_CMD_ELF)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100716static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
717 int argc, char *argv[],
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100718 image_header_t *hdr, int verify)
wdenk47d1a6e2002-11-03 00:01:44 +0000719{
wdenk47d1a6e2002-11-03 00:01:44 +0000720 char str[80];
721
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100722 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +0000723 setenv("loadaddr", str);
724 do_bootvx(cmdtp, 0, 0, NULL);
725}
726
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100727static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
728 int argc, char *argv[],
729 image_header_t *hdr, int verify)
wdenk47d1a6e2002-11-03 00:01:44 +0000730{
wdenk47d1a6e2002-11-03 00:01:44 +0000731 char *local_args[2];
732 char str[16];
733
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100734 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +0000735 local_args[0] = argv[0];
736 local_args[1] = str; /* and provide it via the arguments */
737 do_bootelf(cmdtp, 0, 2, local_args);
738}
Jon Loeliger90253172007-07-10 11:02:44 -0500739#endif
wdenk1f4bb372003-07-27 00:21:01 +0000740
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100741#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
742static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
743 int argc, char *argv[],
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100744 image_header_t *hdr, int verify)
wdenk1f4bb372003-07-27 00:21:01 +0000745{
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100746 ulong top;
747 char *s, *cmdline;
748 char **fwenv, **ss;
749 int i, j, nxt, len, envno, envsz;
750 bd_t *kbd;
751 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
wdenk1f4bb372003-07-27 00:21:01 +0000752
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100753 /*
754 * Booting an ARTOS kernel image + application
755 */
756
757 /* this used to be the top of memory, but was wrong... */
758#ifdef CONFIG_PPC
759 /* get stack pointer */
760 asm volatile ("mr %0,1" : "=r"(top) );
761#endif
762 debug ("## Current stack ends at 0x%08lX ", top);
763
764 top -= 2048; /* just to be sure */
765 if (top > CFG_BOOTMAPSZ)
766 top = CFG_BOOTMAPSZ;
767 top &= ~0xF;
768
769 debug ("=> set upper limit to 0x%08lX\n", top);
770
771 /* first check the artos specific boot args, then the linux args*/
772 if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
773 s = "";
774
775 /* get length of cmdline, and place it */
776 len = strlen (s);
777 top = (top - (len + 1)) & ~0xF;
778 cmdline = (char *)top;
779 debug ("## cmdline at 0x%08lX ", top);
780 strcpy (cmdline, s);
781
782 /* copy bdinfo */
783 top = (top - sizeof (bd_t)) & ~0xF;
784 debug ("## bd at 0x%08lX ", top);
785 kbd = (bd_t *)top;
786 memcpy (kbd, gd->bd, sizeof (bd_t));
787
788 /* first find number of env entries, and their size */
789 envno = 0;
790 envsz = 0;
791 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
792 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
793 ;
794 envno++;
795 envsz += (nxt - i) + 1; /* plus trailing zero */
796 }
797 envno++; /* plus the terminating zero */
798 debug ("## %u envvars total size %u ", envno, envsz);
799
800 top = (top - sizeof (char **) * envno) & ~0xF;
801 fwenv = (char **)top;
802 debug ("## fwenv at 0x%08lX ", top);
803
804 top = (top - envsz) & ~0xF;
805 s = (char *)top;
806 ss = fwenv;
807
808 /* now copy them */
809 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
810 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
811 ;
812 *ss++ = s;
813 for (j = i; j < nxt; ++j)
814 *s++ = env_get_char (j);
815 *s++ = '\0';
816 }
817 *ss++ = NULL; /* terminate */
818
819 entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
820 (*entry) (kbd, cmdline, fwenv, top);
821}
822#endif