blob: 0d67132363cffd3b4f3345d92da55149e36fb283 [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 +0100103static boot_os_fn do_bootm_artos;
wdenk1f4bb372003-07-27 00:21:01 +0000104#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000105
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100106ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100107static bootm_headers_t images; /* pointers to os/initrd/fdt images */
Stefan Roese15940c92006-03-13 11:16:36 +0100108
Kumar Galae822d7f2008-02-27 21:51:49 -0600109void __board_lmb_reserve(struct lmb *lmb)
110{
111 /* please define platform specific board_lmb_reserve() */
112}
113void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
wdenk47d1a6e2002-11-03 00:01:44 +0000114
wdenk47d1a6e2002-11-03 00:01:44 +0000115
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100116/*******************************************************************/
117/* bootm - boot application image from image in memory */
118/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +0000119int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
120{
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100121 ulong iflag;
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100122 const char *type_name;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100123 uint unc_len = CFG_BOOTM_LEN;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100124 uint8_t comp, type, os;
wdenk47d1a6e2002-11-03 00:01:44 +0000125
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100126 void *os_hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100127 ulong os_data, os_len;
Marian Balakowicz75824382008-01-31 13:20:06 +0100128 ulong image_start, image_end;
129 ulong load_start, load_end;
Kumar Galad3f2fa02008-02-27 21:51:50 -0600130 ulong mem_start, mem_size;
wdenk47d1a6e2002-11-03 00:01:44 +0000131
Kumar Gala4ed65522008-02-27 21:51:47 -0600132 struct lmb lmb;
wdenk47d1a6e2002-11-03 00:01:44 +0000133
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100134 memset ((void *)&images, 0, sizeof (images));
Bartlomiej Siekaedbed242008-04-18 12:39:23 +0200135 images.verify = getenv_yesno ("verify");
136 images.autostart = getenv_yesno ("autostart");
Kumar Gala4ed65522008-02-27 21:51:47 -0600137 images.lmb = &lmb;
wdenk47d1a6e2002-11-03 00:01:44 +0000138
Kumar Gala4ed65522008-02-27 21:51:47 -0600139 lmb_init(&lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000140
Kumar Galad3f2fa02008-02-27 21:51:50 -0600141 mem_start = getenv_bootm_low();
142 mem_size = getenv_bootm_size();
wdenk47d1a6e2002-11-03 00:01:44 +0000143
Kumar Galad3f2fa02008-02-27 21:51:50 -0600144 lmb_add(&lmb, mem_start, mem_size);
wdenk47d1a6e2002-11-03 00:01:44 +0000145
Kumar Galae822d7f2008-02-27 21:51:49 -0600146 board_lmb_reserve(&lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000147
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100148 /* get kernel image header, start address and length */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100149 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100150 &images, &os_data, &os_len);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100151 if (os_len == 0) {
152 puts ("ERROR: can't get kernel image!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000153 return 1;
154 }
wdenk47d1a6e2002-11-03 00:01:44 +0000155
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100156 /* get image parameters */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100157 switch (genimg_get_format (os_hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100158 case IMAGE_FORMAT_LEGACY:
159 type = image_get_type (os_hdr);
160 comp = image_get_comp (os_hdr);
161 os = image_get_os (os_hdr);
Wolfgang Denkbccae902005-10-06 01:50:50 +0200162
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100163 image_end = image_get_image_end (os_hdr);
164 load_start = image_get_load (os_hdr);
165 break;
166#if defined(CONFIG_FIT)
167 case IMAGE_FORMAT_FIT:
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100168 if (fit_image_get_type (images.fit_hdr_os,
169 images.fit_noffset_os, &type)) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100170 puts ("Can't get image type!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100171 show_boot_progress (-109);
wdenk47d1a6e2002-11-03 00:01:44 +0000172 return 1;
173 }
wdenk47d1a6e2002-11-03 00:01:44 +0000174
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100175 if (fit_image_get_comp (images.fit_hdr_os,
176 images.fit_noffset_os, &comp)) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100177 puts ("Can't get image compression!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100178 show_boot_progress (-110);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100179 return 1;
180 }
wdenk47d1a6e2002-11-03 00:01:44 +0000181
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100182 if (fit_image_get_os (images.fit_hdr_os,
183 images.fit_noffset_os, &os)) {
Marian Balakowicz6986a382008-03-12 10:01:05 +0100184 puts ("Can't get image OS!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100185 show_boot_progress (-111);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100186 return 1;
187 }
wdenk47d1a6e2002-11-03 00:01:44 +0000188
Marian Balakowicz6986a382008-03-12 10:01:05 +0100189 image_end = fit_get_end (images.fit_hdr_os);
190
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100191 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
Marian Balakowicz6986a382008-03-12 10:01:05 +0100192 &load_start)) {
193 puts ("Can't get image load address!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100194 show_boot_progress (-112);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100195 return 1;
wdenkb13fb012003-10-30 21:49:38 +0000196 }
197 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100198#endif
199 default:
200 puts ("ERROR: unknown image format type!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000201 return 1;
202 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100203
204 image_start = (ulong)os_hdr;
205 load_end = 0;
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100206 type_name = genimg_get_type_name (type);
wdenk47d1a6e2002-11-03 00:01:44 +0000207
208 /*
209 * We have reached the point of no return: we are going to
210 * overwrite all exception vector code, so we cannot easily
211 * recover from any failures any more...
212 */
wdenk47d1a6e2002-11-03 00:01:44 +0000213 iflag = disable_interrupts();
214
wdenkc7de8292002-11-19 11:04:11 +0000215#ifdef CONFIG_AMIGAONEG3SE
216 /*
wdenk8bde7f72003-06-27 21:31:46 +0000217 * We've possible left the caches enabled during
wdenkc7de8292002-11-19 11:04:11 +0000218 * bios emulation, so turn them off again
219 */
220 icache_disable();
221 invalidate_l1_instruction_cache();
222 flush_data_cache();
223 dcache_disable();
224#endif
225
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100226 switch (comp) {
wdenk47d1a6e2002-11-03 00:01:44 +0000227 case IH_COMP_NONE:
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100228 if (load_start == (ulong)os_hdr) {
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100229 printf (" XIP %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000230 } else {
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100231 printf (" Loading %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000232
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100233 memmove_wd ((void *)load_start,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100234 (void *)os_data, os_len, CHUNKSZ);
wdenk47d1a6e2002-11-03 00:01:44 +0000235
Marian Balakowicz75824382008-01-31 13:20:06 +0100236 load_end = load_start + os_len;
Marian Balakowiczaf13cdb2008-01-08 18:11:45 +0100237 puts("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000238 }
239 break;
240 case IH_COMP_GZIP:
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100241 printf (" Uncompressing %s ... ", type_name);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100242 if (gunzip ((void *)load_start, unc_len,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100243 (uchar *)os_data, &os_len) != 0) {
Marian Balakowicz2682ce82008-03-12 10:33:01 +0100244 puts ("GUNZIP: uncompress or overwrite error "
245 "- must RESET board to recover\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200246 show_boot_progress (-6);
wdenk47d1a6e2002-11-03 00:01:44 +0000247 do_reset (cmdtp, flag, argc, argv);
248 }
Marian Balakowicz75824382008-01-31 13:20:06 +0100249
250 load_end = load_start + os_len;
wdenk47d1a6e2002-11-03 00:01:44 +0000251 break;
wdenkc29fdfc2003-08-29 20:57:53 +0000252#ifdef CONFIG_BZIP2
253 case IH_COMP_BZIP2:
Marian Balakowicz42b73e82008-01-31 13:20:07 +0100254 printf (" Uncompressing %s ... ", type_name);
wdenk5653fc32004-02-08 22:55:38 +0000255 /*
256 * If we've got less than 4 MB of malloc() space,
257 * use slower decompression algorithm which requires
258 * at most 2300 KB of memory.
259 */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100260 int i = BZ2_bzBuffToBuffDecompress ((char*)load_start,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100261 &unc_len, (char *)os_data, os_len,
262 CFG_MALLOC_LEN < (4096 * 1024), 0);
wdenkc29fdfc2003-08-29 20:57:53 +0000263 if (i != BZ_OK) {
Marian Balakowicz2682ce82008-03-12 10:33:01 +0100264 printf ("BUNZIP2: uncompress or overwrite error %d "
265 "- must RESET board to recover\n", i);
Heiko Schocherfad63402007-07-13 09:54:17 +0200266 show_boot_progress (-6);
wdenkc29fdfc2003-08-29 20:57:53 +0000267 do_reset (cmdtp, flag, argc, argv);
268 }
Marian Balakowicz75824382008-01-31 13:20:06 +0100269
270 load_end = load_start + unc_len;
wdenkc29fdfc2003-08-29 20:57:53 +0000271 break;
272#endif /* CONFIG_BZIP2 */
wdenk47d1a6e2002-11-03 00:01:44 +0000273 default:
274 if (iflag)
275 enable_interrupts();
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100276 printf ("Unimplemented compression type %d\n", comp);
Heiko Schocherfad63402007-07-13 09:54:17 +0200277 show_boot_progress (-7);
wdenk47d1a6e2002-11-03 00:01:44 +0000278 return 1;
279 }
wdenk4b9206e2004-03-23 22:14:11 +0000280 puts ("OK\n");
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100281 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end);
Heiko Schocherfad63402007-07-13 09:54:17 +0200282 show_boot_progress (7);
wdenk47d1a6e2002-11-03 00:01:44 +0000283
Marian Balakowicz75824382008-01-31 13:20:06 +0100284 if ((load_start < image_end) && (load_end > image_start)) {
285 debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end);
286 debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end);
wdenk47d1a6e2002-11-03 00:01:44 +0000287
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200288 if (images.legacy_hdr_valid) {
289 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
290 puts ("WARNING: legacy format multi component "
291 "image overwritten\n");
292 } else {
293 puts ("ERROR: new format image overwritten - "
294 "must RESET the board to recover\n");
295 show_boot_progress (-113);
296 do_reset (cmdtp, flag, argc, argv);
297 }
wdenk47d1a6e2002-11-03 00:01:44 +0000298 }
Marian Balakowicz75824382008-01-31 13:20:06 +0100299
Heiko Schocherfad63402007-07-13 09:54:17 +0200300 show_boot_progress (8);
wdenk47d1a6e2002-11-03 00:01:44 +0000301
Kumar Gala4ed65522008-02-27 21:51:47 -0600302 lmb_reserve(&lmb, load_start, (load_end - load_start));
303
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100304 switch (os) {
wdenk47d1a6e2002-11-03 00:01:44 +0000305 default: /* handled by (original) Linux case */
306 case IH_OS_LINUX:
wdenkf72da342003-10-10 10:05:42 +0000307#ifdef CONFIG_SILENT_CONSOLE
308 fixup_silent_linux();
309#endif
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100310 do_bootm_linux (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000311 break;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100312
wdenk47d1a6e2002-11-03 00:01:44 +0000313 case IH_OS_NETBSD:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100314 do_bootm_netbsd (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000315 break;
wdenk8bde7f72003-06-27 21:31:46 +0000316
wdenk1f4bb372003-07-27 00:21:01 +0000317#ifdef CONFIG_LYNXKDI
318 case IH_OS_LYNXOS:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100319 do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images);
wdenk1f4bb372003-07-27 00:21:01 +0000320 break;
321#endif
322
wdenkd791b1d2003-04-20 14:04:18 +0000323 case IH_OS_RTEMS:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100324 do_bootm_rtems (cmdtp, flag, argc, argv, &images);
wdenkd791b1d2003-04-20 14:04:18 +0000325 break;
wdenk8bde7f72003-06-27 21:31:46 +0000326
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500327#if defined(CONFIG_CMD_ELF)
wdenk47d1a6e2002-11-03 00:01:44 +0000328 case IH_OS_VXWORKS:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100329 do_bootm_vxworks (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000330 break;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100331
wdenk47d1a6e2002-11-03 00:01:44 +0000332 case IH_OS_QNX:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100333 do_bootm_qnxelf (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000334 break;
Jon Loeliger90253172007-07-10 11:02:44 -0500335#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100336
wdenk7f70e852003-05-20 14:25:27 +0000337#ifdef CONFIG_ARTOS
338 case IH_OS_ARTOS:
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100339 do_bootm_artos (cmdtp, flag, argc, argv, &images);
wdenk7f70e852003-05-20 14:25:27 +0000340 break;
341#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000342 }
343
Heiko Schocherfad63402007-07-13 09:54:17 +0200344 show_boot_progress (-9);
wdenk47d1a6e2002-11-03 00:01:44 +0000345#ifdef DEBUG
wdenk4b9206e2004-03-23 22:14:11 +0000346 puts ("\n## Control returned to monitor - resetting...\n");
Marian Balakowicza44a2692008-03-12 10:14:57 +0100347 if (images.autostart)
348 do_reset (cmdtp, flag, argc, argv);
wdenk47d1a6e2002-11-03 00:01:44 +0000349#endif
Marian Balakowicza44a2692008-03-12 10:14:57 +0100350 if (!images.autostart && iflag)
351 enable_interrupts();
352
wdenk47d1a6e2002-11-03 00:01:44 +0000353 return 1;
354}
355
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100356/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100357 * image_get_kernel - verify legacy format kernel image
358 * @img_addr: in RAM address of the legacy format image to be verified
359 * @verify: data CRC verification flag
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100360 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100361 * image_get_kernel() verifies legacy image integrity and returns pointer to
362 * legacy image header if image verification was completed successfully.
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100363 *
364 * returns:
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100365 * pointer to a legacy image header if valid image was found
366 * otherwise return NULL
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100367 */
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100368static image_header_t *image_get_kernel (ulong img_addr, int verify)
369{
370 image_header_t *hdr = (image_header_t *)img_addr;
371
372 if (!image_check_magic(hdr)) {
373 puts ("Bad Magic Number\n");
374 show_boot_progress (-1);
375 return NULL;
376 }
377 show_boot_progress (2);
378
379 if (!image_check_hcrc (hdr)) {
380 puts ("Bad Header Checksum\n");
381 show_boot_progress (-2);
382 return NULL;
383 }
384
385 show_boot_progress (3);
386 image_print_contents (hdr);
387
388 if (verify) {
389 puts (" Verifying Checksum ... ");
390 if (!image_check_dcrc (hdr)) {
391 printf ("Bad Data CRC\n");
392 show_boot_progress (-3);
393 return NULL;
394 }
395 puts ("OK\n");
396 }
397 show_boot_progress (4);
398
399 if (!image_check_target_arch (hdr)) {
400 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
401 show_boot_progress (-4);
402 return NULL;
403 }
404 return hdr;
405}
406
407/**
Marian Balakowicz6986a382008-03-12 10:01:05 +0100408 * fit_check_kernel - verify FIT format kernel subimage
409 * @fit_hdr: pointer to the FIT image header
410 * os_noffset: kernel subimage node offset within FIT image
411 * @verify: data CRC verification flag
412 *
413 * fit_check_kernel() verifies integrity of the kernel subimage and from
414 * specified FIT image.
415 *
416 * returns:
417 * 1, on success
418 * 0, on failure
419 */
420#if defined (CONFIG_FIT)
421static int fit_check_kernel (const void *fit, int os_noffset, int verify)
422{
423 fit_image_print (fit, os_noffset, " ");
424
425 if (verify) {
426 puts (" Verifying Hash Integrity ... ");
427 if (!fit_image_check_hashes (fit, os_noffset)) {
428 puts ("Bad Data Hash\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100429 show_boot_progress (-104);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100430 return 0;
431 }
432 puts ("OK\n");
433 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100434 show_boot_progress (105);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100435
436 if (!fit_image_check_target_arch (fit, os_noffset)) {
437 puts ("Unsupported Architecture\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100438 show_boot_progress (-105);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100439 return 0;
440 }
441
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100442 show_boot_progress (106);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100443 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
444 puts ("Not a kernel image\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100445 show_boot_progress (-106);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100446 return 0;
447 }
448
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100449 show_boot_progress (107);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100450 return 1;
451}
452#endif /* CONFIG_FIT */
453
454/**
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100455 * boot_get_kernel - find kernel image
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100456 * @os_data: pointer to a ulong variable, will hold os data start address
457 * @os_len: pointer to a ulong variable, will hold os data length
458 *
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100459 * boot_get_kernel() tries to find a kernel image, verifies its integrity
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100460 * and locates kernel data.
461 *
462 * returns:
463 * pointer to image header if valid image was found, plus kernel start
464 * address and length, otherwise NULL
465 */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100466static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100467 bootm_headers_t *images, ulong *os_data, ulong *os_len)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100468{
469 image_header_t *hdr;
470 ulong img_addr;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100471#if defined(CONFIG_FIT)
472 void *fit_hdr;
473 const char *fit_uname_config = NULL;
474 const char *fit_uname_kernel = NULL;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100475 const void *data;
476 size_t len;
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100477 int cfg_noffset;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100478 int os_noffset;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100479#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100480
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100481 /* find out kernel image address */
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100482 if (argc < 2) {
483 img_addr = load_addr;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100484 debug ("* kernel: default image load address = 0x%08lx\n",
485 load_addr);
486#if defined(CONFIG_FIT)
487 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
488 &fit_uname_config)) {
489 debug ("* kernel: config '%s' from image at 0x%08lx\n",
490 fit_uname_config, img_addr);
491 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
492 &fit_uname_kernel)) {
493 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
494 fit_uname_kernel, img_addr);
495#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100496 } else {
497 img_addr = simple_strtoul(argv[1], NULL, 16);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100498 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100499 }
500
501 show_boot_progress (1);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100502
Marian Balakowiczfff888a12008-02-21 17:20:19 +0100503 /* copy from dataflash if needed */
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100504 img_addr = genimg_get_image (img_addr);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100505
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100506 /* check image type, for FIT images get FIT kernel node */
Marian Balakowicz6986a382008-03-12 10:01:05 +0100507 *os_data = *os_len = 0;
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100508 switch (genimg_get_format ((void *)img_addr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100509 case IMAGE_FORMAT_LEGACY:
Marian Balakowicz6986a382008-03-12 10:01:05 +0100510 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
511 img_addr);
Marian Balakowicz1efd4362008-02-27 11:02:07 +0100512 hdr = image_get_kernel (img_addr, images->verify);
513 if (!hdr)
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100514 return NULL;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100515 show_boot_progress (5);
516
Marian Balakowicz6986a382008-03-12 10:01:05 +0100517 /* get os_data and os_len */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100518 switch (image_get_type (hdr)) {
519 case IH_TYPE_KERNEL:
520 *os_data = image_get_data (hdr);
521 *os_len = image_get_data_size (hdr);
522 break;
523 case IH_TYPE_MULTI:
524 image_multi_getimg (hdr, 0, os_data, os_len);
525 break;
526 default:
527 printf ("Wrong Image Type for %s command\n", cmdtp->name);
528 show_boot_progress (-5);
529 return NULL;
530 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100531
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200532 /*
533 * copy image header to allow for image overwrites during kernel
534 * decompression.
535 */
536 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
537
538 /* save pointer to image header */
539 images->legacy_hdr_os = hdr;
540
541 images->legacy_hdr_valid = 1;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100542 show_boot_progress (6);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100543 break;
544#if defined(CONFIG_FIT)
545 case IMAGE_FORMAT_FIT:
546 fit_hdr = (void *)img_addr;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100547 printf ("## Booting kernel from FIT Image at %08lx ...\n",
548 img_addr);
549
550 if (!fit_check_format (fit_hdr)) {
551 puts ("Bad FIT kernel image format!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100552 show_boot_progress (-100);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100553 return NULL;
554 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100555 show_boot_progress (100);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100556
557 if (!fit_uname_kernel) {
558 /*
559 * no kernel image node unit name, try to get config
560 * node first. If config unit node name is NULL
561 * fit_conf_get_node() will try to find default config node
562 */
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100563 show_boot_progress (101);
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100564 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
565 if (cfg_noffset < 0) {
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100566 show_boot_progress (-101);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100567 return NULL;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100568 }
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100569 /* save configuration uname provided in the first
570 * bootm argument
571 */
572 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
573 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
574 show_boot_progress (103);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100575
Marian Balakowiczf773bea2008-03-12 10:35:46 +0100576 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100577 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
578 } else {
579 /* get kernel component image node offset */
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100580 show_boot_progress (102);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100581 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
582 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100583 if (os_noffset < 0) {
584 show_boot_progress (-103);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100585 return NULL;
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100586 }
Marian Balakowicz6986a382008-03-12 10:01:05 +0100587
588 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
589
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100590 show_boot_progress (104);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100591 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
592 return NULL;
593
594 /* get kernel image data address and length */
595 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
596 puts ("Could not find kernel subimage data!\n");
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100597 show_boot_progress (-107);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100598 return NULL;
599 }
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100600 show_boot_progress (108);
Marian Balakowicz6986a382008-03-12 10:01:05 +0100601
602 *os_len = len;
603 *os_data = (ulong)data;
604 images->fit_hdr_os = fit_hdr;
605 images->fit_uname_os = fit_uname_kernel;
Marian Balakowicz3dfe1102008-03-12 10:32:59 +0100606 images->fit_noffset_os = os_noffset;
Marian Balakowicz6986a382008-03-12 10:01:05 +0100607 break;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100608#endif
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100609 default:
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100610 printf ("Wrong Image Format for %s command\n", cmdtp->name);
Marian Balakowicz1372cce2008-03-12 10:33:01 +0100611 show_boot_progress (-108);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100612 return NULL;
613 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100614
Marian Balakowicz6986a382008-03-12 10:01:05 +0100615 debug (" kernel data at 0x%08lx, len = 0x%08lx (%d)\n",
616 *os_data, *os_len, *os_len);
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100617
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100618 return (void *)img_addr;
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100619}
620
wdenk0d498392003-07-01 21:06:45 +0000621U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100622 bootm, CFG_MAXARGS, 1, do_bootm,
623 "bootm - boot application image from memory\n",
624 "[addr [arg ...]]\n - boot application image stored in memory\n"
625 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
626 "\t'arg' can be the address of an initrd image\n"
Marian Balakowicz4a2ad5f2008-01-31 13:20:07 +0100627#if defined(CONFIG_OF_LIBFDT)
Matthew McClintock98a9c4d2006-06-28 10:41:37 -0500628 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
Detlev Zundel5441f612007-10-19 16:47:26 +0200629 "\ta third argument is required which is the address of the\n"
Matthew McClintock98a9c4d2006-06-28 10:41:37 -0500630 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
631 "\tuse a '-' for the second argument. If you do not pass a third\n"
632 "\ta bd_info struct will be passed instead\n"
633#endif
Marian Balakowicz6986a382008-03-12 10:01:05 +0100634#if defined(CONFIG_FIT)
635 "\t\nFor the new multi component uImage format (FIT) addresses\n"
636 "\tmust be extened to include component or configuration unit name:\n"
637 "\taddr:<subimg_uname> - direct component image specification\n"
638 "\taddr#<conf_uname> - configuration specification\n"
639 "\tUse iminfo command to get the list of existing component\n"
640 "\timages and configurations.\n"
641#endif
wdenk8bde7f72003-06-27 21:31:46 +0000642);
643
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100644/*******************************************************************/
645/* bootd - boot default image */
646/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500647#if defined(CONFIG_CMD_BOOTD)
wdenk47d1a6e2002-11-03 00:01:44 +0000648int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
649{
650 int rcode = 0;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100651
wdenk47d1a6e2002-11-03 00:01:44 +0000652#ifndef CFG_HUSH_PARSER
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100653 if (run_command (getenv ("bootcmd"), flag) < 0)
654 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000655#else
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100656 if (parse_string_outer (getenv ("bootcmd"),
657 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
658 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000659#endif
660 return rcode;
661}
wdenk8bde7f72003-06-27 21:31:46 +0000662
wdenk0d498392003-07-01 21:06:45 +0000663U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100664 boot, 1, 1, do_bootd,
665 "boot - boot default, i.e., run 'bootcmd'\n",
wdenk9d2b18a2003-06-28 23:11:04 +0000666 NULL
667);
668
669/* keep old command name "bootd" for backward compatibility */
wdenk0d498392003-07-01 21:06:45 +0000670U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100671 bootd, 1, 1, do_bootd,
672 "bootd - boot default, i.e., run 'bootcmd'\n",
wdenk8bde7f72003-06-27 21:31:46 +0000673 NULL
674);
675
wdenk47d1a6e2002-11-03 00:01:44 +0000676#endif
677
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100678
679/*******************************************************************/
680/* iminfo - print header info for a requested image */
681/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500682#if defined(CONFIG_CMD_IMI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100683int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000684{
685 int arg;
686 ulong addr;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100687 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000688
689 if (argc < 2) {
690 return image_info (load_addr);
691 }
692
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100693 for (arg = 1; arg < argc; ++arg) {
694 addr = simple_strtoul (argv[arg], NULL, 16);
695 if (image_info (addr) != 0)
696 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000697 }
698 return rcode;
699}
700
701static int image_info (ulong addr)
702{
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100703 void *hdr = (void *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +0000704
705 printf ("\n## Checking Image at %08lx ...\n", addr);
706
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100707 switch (genimg_get_format (hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100708 case IMAGE_FORMAT_LEGACY:
709 puts (" Legacy image found\n");
710 if (!image_check_magic (hdr)) {
711 puts (" Bad Magic Number\n");
712 return 1;
713 }
714
715 if (!image_check_hcrc (hdr)) {
716 puts (" Bad Header Checksum\n");
717 return 1;
718 }
719
720 image_print_contents (hdr);
721
722 puts (" Verifying Checksum ... ");
723 if (!image_check_dcrc (hdr)) {
724 puts (" Bad Data CRC\n");
725 return 1;
726 }
727 puts ("OK\n");
728 return 0;
729#if defined(CONFIG_FIT)
730 case IMAGE_FORMAT_FIT:
731 puts (" FIT image found\n");
Marian Balakowicze32fea62008-03-11 12:35:20 +0100732
733 if (!fit_check_format (hdr)) {
734 puts ("Bad FIT image format!\n");
735 return 1;
736 }
737
738 fit_print_contents (hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100739 return 0;
740#endif
741 default:
742 puts ("Unknown image format!\n");
743 break;
wdenk47d1a6e2002-11-03 00:01:44 +0000744 }
745
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100746 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000747}
wdenk0d498392003-07-01 21:06:45 +0000748
749U_BOOT_CMD(
750 iminfo, CFG_MAXARGS, 1, do_iminfo,
wdenk8bde7f72003-06-27 21:31:46 +0000751 "iminfo - print header information for application image\n",
752 "addr [addr ...]\n"
753 " - print header information for application image starting at\n"
754 " address 'addr' in memory; this includes verification of the\n"
755 " image contents (magic number, header and payload checksums)\n"
756);
Jon Loeliger90253172007-07-10 11:02:44 -0500757#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000758
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100759
760/*******************************************************************/
761/* imls - list all images found in flash */
762/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500763#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +0000764int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
765{
766 flash_info_t *info;
767 int i, j;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100768 void *hdr;
wdenk27b207f2003-07-24 23:38:38 +0000769
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100770 for (i = 0, info = &flash_info[0];
771 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
772
wdenk27b207f2003-07-24 23:38:38 +0000773 if (info->flash_id == FLASH_UNKNOWN)
774 goto next_bank;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100775 for (j = 0; j < info->sector_count; ++j) {
wdenk27b207f2003-07-24 23:38:38 +0000776
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100777 hdr = (void *)info->start[j];
778 if (!hdr)
wdenk27b207f2003-07-24 23:38:38 +0000779 goto next_sector;
780
Marian Balakowicz9a4daad2008-02-29 14:58:34 +0100781 switch (genimg_get_format (hdr)) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100782 case IMAGE_FORMAT_LEGACY:
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100783 if (!image_check_hcrc (hdr))
784 goto next_sector;
785
786 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
787 image_print_contents (hdr);
788
789 puts (" Verifying Checksum ... ");
790 if (!image_check_dcrc (hdr)) {
791 puts ("Bad Data CRC\n");
792 } else {
793 puts ("OK\n");
794 }
795 break;
796#if defined(CONFIG_FIT)
797 case IMAGE_FORMAT_FIT:
Marian Balakowicze32fea62008-03-11 12:35:20 +0100798 if (!fit_check_format (hdr))
799 goto next_sector;
800
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100801 printf ("FIT Image at %08lX:\n", (ulong)hdr);
Marian Balakowicze32fea62008-03-11 12:35:20 +0100802 fit_print_contents (hdr);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100803 break;
804#endif
805 default:
wdenk27b207f2003-07-24 23:38:38 +0000806 goto next_sector;
wdenk5bb226e2003-11-17 21:14:37 +0000807 }
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100808
wdenkbdccc4f2003-08-05 17:43:17 +0000809next_sector: ;
wdenk27b207f2003-07-24 23:38:38 +0000810 }
wdenkbdccc4f2003-08-05 17:43:17 +0000811next_bank: ;
wdenk27b207f2003-07-24 23:38:38 +0000812 }
813
814 return (0);
815}
816
817U_BOOT_CMD(
818 imls, 1, 1, do_imls,
819 "imls - list all images found in flash\n",
820 "\n"
821 " - Prints information about all images found at sector\n"
822 " boundaries in flash.\n"
823);
Jon Loeliger90253172007-07-10 11:02:44 -0500824#endif
wdenk27b207f2003-07-24 23:38:38 +0000825
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100826/*******************************************************************/
Marian Balakowicz5cf746c2008-01-31 13:59:09 +0100827/* helper routines */
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100828/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +0000829#ifdef CONFIG_SILENT_CONSOLE
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100830static void fixup_silent_linux ()
wdenk47d1a6e2002-11-03 00:01:44 +0000831{
832 char buf[256], *start, *end;
833 char *cmdline = getenv ("bootargs");
834
835 /* Only fix cmdline when requested */
836 if (!(gd->flags & GD_FLG_SILENT))
837 return;
838
839 debug ("before silent fix-up: %s\n", cmdline);
840 if (cmdline) {
841 if ((start = strstr (cmdline, "console=")) != NULL) {
842 end = strchr (start, ' ');
843 strncpy (buf, cmdline, (start - cmdline + 8));
844 if (end)
845 strcpy (buf + (start - cmdline + 8), end);
846 else
847 buf[start - cmdline + 8] = '\0';
848 } else {
849 strcpy (buf, cmdline);
850 strcat (buf, " console=");
851 }
852 } else {
853 strcpy (buf, "console=");
854 }
855
856 setenv ("bootargs", buf);
857 debug ("after silent fix-up: %s\n", buf);
858}
859#endif /* CONFIG_SILENT_CONSOLE */
860
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100861
862/*******************************************************************/
863/* OS booting routines */
864/*******************************************************************/
865
866static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100867 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100868 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +0000869{
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100870 void (*loader)(bd_t *, image_header_t *, char *, char *);
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100871 image_header_t *os_hdr, *hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100872 ulong kernel_data, kernel_len;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100873 char *consdev;
874 char *cmdline;
wdenk47d1a6e2002-11-03 00:01:44 +0000875
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100876#if defined(CONFIG_FIT)
877 if (!images->legacy_hdr_valid) {
878 fit_unsupported_reset ("NetBSD");
879 do_reset (cmdtp, flag, argc, argv);
wdenk47d1a6e2002-11-03 00:01:44 +0000880 }
881#endif
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100882 hdr = images->legacy_hdr_os;
wdenk47d1a6e2002-11-03 00:01:44 +0000883
884 /*
885 * Booting a (NetBSD) kernel image
886 *
887 * This process is pretty similar to a standalone application:
888 * The (first part of an multi-) image must be a stage-2 loader,
889 * which in turn is responsible for loading & invoking the actual
890 * kernel. The only differences are the parameters being passed:
891 * besides the board info strucure, the loader expects a command
892 * line, the name of the console device, and (optionally) the
893 * address of the original image header.
894 */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100895 os_hdr = NULL;
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200896 if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100897 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
898 if (kernel_len)
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100899 os_hdr = hdr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100900 }
wdenk47d1a6e2002-11-03 00:01:44 +0000901
902 consdev = "";
903#if defined (CONFIG_8xx_CONS_SMC1)
904 consdev = "smc1";
905#elif defined (CONFIG_8xx_CONS_SMC2)
906 consdev = "smc2";
907#elif defined (CONFIG_8xx_CONS_SCC2)
908 consdev = "scc2";
909#elif defined (CONFIG_8xx_CONS_SCC3)
910 consdev = "scc3";
911#endif
912
913 if (argc > 2) {
914 ulong len;
915 int i;
916
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100917 for (i = 2, len = 0; i < argc; i += 1)
wdenk47d1a6e2002-11-03 00:01:44 +0000918 len += strlen (argv[i]) + 1;
919 cmdline = malloc (len);
920
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100921 for (i = 2, len = 0; i < argc; i += 1) {
wdenk47d1a6e2002-11-03 00:01:44 +0000922 if (i > 2)
923 cmdline[len++] = ' ';
924 strcpy (&cmdline[len], argv[i]);
925 len += strlen (argv[i]);
926 }
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100927 } else if ((cmdline = getenv ("bootargs")) == NULL) {
wdenk47d1a6e2002-11-03 00:01:44 +0000928 cmdline = "";
929 }
930
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100931 loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000932
933 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
934 (ulong)loader);
935
936 show_boot_progress (15);
937
938 /*
939 * NetBSD Stage-2 Loader Parameters:
940 * r3: ptr to board info data
941 * r4: image address
942 * r5: console device
943 * r6: boot args string
944 */
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100945 (*loader) (gd->bd, os_hdr, consdev, cmdline);
wdenk47d1a6e2002-11-03 00:01:44 +0000946}
947
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100948#ifdef CONFIG_LYNXKDI
949static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
950 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100951 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100952{
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200953 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100954
955#if defined(CONFIG_FIT)
956 if (!images->legacy_hdr_valid) {
957 fit_unsupported_reset ("Lynx");
958 do_reset (cmdtp, flag, argc, argv);
959 }
960#endif
961
962 lynxkdi_boot ((image_header_t *)hdr);
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100963}
964#endif /* CONFIG_LYNXKDI */
965
966static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
967 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100968 bootm_headers_t *images)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100969{
Marian Balakowiczcb1c4892008-04-11 11:07:49 +0200970 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100971 void (*entry_point)(bd_t *);
wdenkd791b1d2003-04-20 14:04:18 +0000972
Marian Balakowiczd5934ad2008-02-04 08:28:09 +0100973#if defined(CONFIG_FIT)
974 if (!images->legacy_hdr_valid) {
975 fit_unsupported_reset ("RTEMS");
976 do_reset (cmdtp, flag, argc, argv);
977 }
978#endif
979
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100980 entry_point = (void (*)(bd_t *))image_get_ep (hdr);
wdenkd791b1d2003-04-20 14:04:18 +0000981
982 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
983 (ulong)entry_point);
984
Heiko Schocherfad63402007-07-13 09:54:17 +0200985 show_boot_progress (15);
wdenkd791b1d2003-04-20 14:04:18 +0000986
987 /*
988 * RTEMS Parameters:
989 * r3: ptr to board info data
990 */
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100991 (*entry_point)(gd->bd);
wdenkd791b1d2003-04-20 14:04:18 +0000992}
993
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500994#if defined(CONFIG_CMD_ELF)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100995static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
996 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +0100997 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +0000998{
wdenk47d1a6e2002-11-03 00:01:44 +0000999 char str[80];
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001000 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001001
1002#if defined(CONFIG_FIT)
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001003 if (!images->legacy_hdr_valid) {
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001004 fit_unsupported_reset ("VxWorks");
1005 do_reset (cmdtp, flag, argc, argv);
1006 }
1007#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001008
Marian Balakowiczb97a2a02008-01-08 18:14:09 +01001009 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001010 setenv("loadaddr", str);
1011 do_bootvx(cmdtp, 0, 0, NULL);
1012}
1013
Marian Balakowiczf13e7b22008-01-08 18:12:17 +01001014static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
1015 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001016 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001017{
wdenk47d1a6e2002-11-03 00:01:44 +00001018 char *local_args[2];
1019 char str[16];
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001020 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001021
1022#if defined(CONFIG_FIT)
1023 if (!images->legacy_hdr_valid) {
1024 fit_unsupported_reset ("QNX");
1025 do_reset (cmdtp, flag, argc, argv);
1026 }
1027#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001028
Marian Balakowiczb97a2a02008-01-08 18:14:09 +01001029 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001030 local_args[0] = argv[0];
1031 local_args[1] = str; /* and provide it via the arguments */
1032 do_bootelf(cmdtp, 0, 2, local_args);
1033}
Jon Loeliger90253172007-07-10 11:02:44 -05001034#endif
wdenk1f4bb372003-07-27 00:21:01 +00001035
wdenk47d1a6e2002-11-03 00:01:44 +00001036#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001037static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
1038 int argc, char *argv[],
Marian Balakowicz8a5ea3e2008-02-27 11:01:04 +01001039 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001040{
1041 ulong top;
1042 char *s, *cmdline;
1043 char **fwenv, **ss;
1044 int i, j, nxt, len, envno, envsz;
1045 bd_t *kbd;
1046 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
Marian Balakowiczcb1c4892008-04-11 11:07:49 +02001047 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczd5934ad2008-02-04 08:28:09 +01001048
1049#if defined(CONFIG_FIT)
1050 if (!images->legacy_hdr_valid) {
1051 fit_unsupported_reset ("ARTOS");
1052 do_reset (cmdtp, flag, argc, argv);
1053 }
1054#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001055
1056 /*
1057 * Booting an ARTOS kernel image + application
1058 */
1059
1060 /* this used to be the top of memory, but was wrong... */
1061#ifdef CONFIG_PPC
1062 /* get stack pointer */
1063 asm volatile ("mr %0,1" : "=r"(top) );
1064#endif
1065 debug ("## Current stack ends at 0x%08lX ", top);
1066
1067 top -= 2048; /* just to be sure */
1068 if (top > CFG_BOOTMAPSZ)
1069 top = CFG_BOOTMAPSZ;
1070 top &= ~0xF;
1071
1072 debug ("=> set upper limit to 0x%08lX\n", top);
1073
1074 /* first check the artos specific boot args, then the linux args*/
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001075 if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
wdenk47d1a6e2002-11-03 00:01:44 +00001076 s = "";
1077
1078 /* get length of cmdline, and place it */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001079 len = strlen (s);
wdenk47d1a6e2002-11-03 00:01:44 +00001080 top = (top - (len + 1)) & ~0xF;
1081 cmdline = (char *)top;
1082 debug ("## cmdline at 0x%08lX ", top);
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001083 strcpy (cmdline, s);
wdenk47d1a6e2002-11-03 00:01:44 +00001084
1085 /* copy bdinfo */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001086 top = (top - sizeof (bd_t)) & ~0xF;
wdenk47d1a6e2002-11-03 00:01:44 +00001087 debug ("## bd at 0x%08lX ", top);
1088 kbd = (bd_t *)top;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001089 memcpy (kbd, gd->bd, sizeof (bd_t));
wdenk47d1a6e2002-11-03 00:01:44 +00001090
1091 /* first find number of env entries, and their size */
1092 envno = 0;
1093 envsz = 0;
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001094 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1095 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
wdenk47d1a6e2002-11-03 00:01:44 +00001096 ;
1097 envno++;
1098 envsz += (nxt - i) + 1; /* plus trailing zero */
1099 }
1100 envno++; /* plus the terminating zero */
1101 debug ("## %u envvars total size %u ", envno, envsz);
1102
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001103 top = (top - sizeof (char **) * envno) & ~0xF;
wdenk47d1a6e2002-11-03 00:01:44 +00001104 fwenv = (char **)top;
1105 debug ("## fwenv at 0x%08lX ", top);
1106
1107 top = (top - envsz) & ~0xF;
1108 s = (char *)top;
1109 ss = fwenv;
1110
1111 /* now copy them */
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001112 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1113 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
wdenk47d1a6e2002-11-03 00:01:44 +00001114 ;
1115 *ss++ = s;
1116 for (j = i; j < nxt; ++j)
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001117 *s++ = env_get_char (j);
wdenk47d1a6e2002-11-03 00:01:44 +00001118 *s++ = '\0';
1119 }
1120 *ss++ = NULL; /* terminate */
1121
Marian Balakowicz1ee11802008-01-08 18:17:10 +01001122 entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
1123 (*entry) (kbd, cmdline, fwenv, top);
wdenk47d1a6e2002-11-03 00:01:44 +00001124}
1125#endif