blob: 2de132961a01a3aa8a7ae0cceff27a923e18028a [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
Gerald Van Baren213bf8c2007-03-31 12:23:51 -040039#if defined(CONFIG_OF_LIBFDT)
40#include <fdt.h>
41#include <libfdt.h>
Gerald Van Barenc28abb92007-04-14 22:51:24 -040042#include <fdt_support.h>
Marian Balakowiczd45d5a12008-01-08 18:11:43 +010043#elif defined(CONFIG_OF_FLAT_TREE)
Wolfgang Denkf57f70a2005-10-13 01:45:54 +020044#include <ft_build.h>
45#endif
46
Jon Loeligerbaa26db2007-07-08 17:51:39 -050047#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
wdenk47d1a6e2002-11-03 00:01:44 +000048#include <rtc.h>
49#endif
50
51#ifdef CFG_HUSH_PARSER
52#include <hush.h>
53#endif
54
wdenk2abbe072003-06-16 23:50:08 +000055#ifdef CONFIG_HAS_DATAFLASH
56#include <dataflash.h>
57#endif
58
Marian Balakowicz1ee11802008-01-08 18:17:10 +010059DECLARE_GLOBAL_DATA_PTR;
60
61extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
62#ifndef CFG_BOOTM_LEN
63#define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
64#endif
wdenk47d1a6e2002-11-03 00:01:44 +000065
Marian Balakowicz321359f2008-01-08 18:11:43 +010066#ifdef CONFIG_BZIP2
67extern void bz_internal_error(int);
68#endif
wdenk47d1a6e2002-11-03 00:01:44 +000069
Jon Loeligerbaa26db2007-07-08 17:51:39 -050070#if defined(CONFIG_CMD_IMI)
wdenk47d1a6e2002-11-03 00:01:44 +000071static int image_info (unsigned long addr);
72#endif
wdenk27b207f2003-07-24 23:38:38 +000073
Jon Loeligerbaa26db2007-07-08 17:51:39 -050074#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +000075#include <flash.h>
Marian Balakowicze6f2e902005-10-11 19:09:42 +020076extern flash_info_t flash_info[]; /* info for FLASH chips */
wdenk27b207f2003-07-24 23:38:38 +000077static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
78#endif
79
Marian Balakowicz1ee11802008-01-08 18:17:10 +010080#ifdef CONFIG_SILENT_CONSOLE
81static void fixup_silent_linux (void);
82#endif
83
wdenk47d1a6e2002-11-03 00:01:44 +000084static void print_type (image_header_t *hdr);
Marian Balakowicz1ee11802008-01-08 18:17:10 +010085extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
wdenk47d1a6e2002-11-03 00:01:44 +000086
87/*
88 * Continue booting an OS image; caller already has:
89 * - copied image header to global variable `header'
90 * - checked header magic number, checksums (both header & image),
91 * - verified image architecture (PPC) and type (KERNEL or MULTI),
92 * - loaded (first part of) image to header load address,
93 * - disabled interrupts.
94 */
Marian Balakowicz1ee11802008-01-08 18:17:10 +010095typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag,
96 int argc, char *argv[],
97 ulong addr, /* of image to boot */
98 ulong *len_ptr, /* multi-file image length table */
99 int verify); /* getenv("verify")[0] != 'n' */
wdenk47d1a6e2002-11-03 00:01:44 +0000100
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100101extern boot_os_fn do_bootm_linux;
102static boot_os_fn do_bootm_netbsd;
103#ifdef CONFIG_LYNXKDI
104static boot_os_fn do_bootm_lynxkdi;
105extern void lynxkdi_boot (image_header_t *);
wdenkf72da342003-10-10 10:05:42 +0000106#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100107static boot_os_fn do_bootm_rtems;
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500108#if defined(CONFIG_CMD_ELF)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100109static boot_os_fn do_bootm_vxworks;
110static boot_os_fn do_bootm_qnxelf;
111int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
112int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
Jon Loeliger90253172007-07-10 11:02:44 -0500113#endif
wdenk7f70e852003-05-20 14:25:27 +0000114#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100115extern uchar (*env_get_char)(int); /* Returns a character from the environment */
116static boot_os_fn do_bootm_artos;
Stefan Roese15940c92006-03-13 11:16:36 +0100117#endif
118
wdenk47d1a6e2002-11-03 00:01:44 +0000119image_header_t header;
120
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100121ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
wdenk47d1a6e2002-11-03 00:01:44 +0000122
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100123
124/*******************************************************************/
125/* bootm - boot application image from image in memory */
126/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +0000127int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
128{
129 ulong iflag;
130 ulong addr;
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100131 ulong data, len;
wdenk47d1a6e2002-11-03 00:01:44 +0000132 ulong *len_ptr;
Stefan Roese15940c92006-03-13 11:16:36 +0100133 uint unc_len = CFG_BOOTM_LEN;
wdenk47d1a6e2002-11-03 00:01:44 +0000134 int i, verify;
135 char *name, *s;
wdenkb13fb012003-10-30 21:49:38 +0000136 int (*appl)(int, char *[]);
wdenk47d1a6e2002-11-03 00:01:44 +0000137 image_header_t *hdr = &header;
138
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100139 verify = getenv_verify ();
wdenk47d1a6e2002-11-03 00:01:44 +0000140
141 if (argc < 2) {
142 addr = load_addr;
143 } else {
144 addr = simple_strtoul(argv[1], NULL, 16);
145 }
146
Heiko Schocherfad63402007-07-13 09:54:17 +0200147 show_boot_progress (1);
wdenk47d1a6e2002-11-03 00:01:44 +0000148 printf ("## Booting image at %08lx ...\n", addr);
149
150 /* Copy header so we can blank CRC field for re-calculation */
wdenk2abbe072003-06-16 23:50:08 +0000151#ifdef CONFIG_HAS_DATAFLASH
152 if (addr_dataflash(addr)){
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100153 read_dataflash (addr, image_get_header_size (), (char *)&header);
wdenk2abbe072003-06-16 23:50:08 +0000154 } else
155#endif
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100156 memmove (&header, (char *)addr, image_get_header_size ());
wdenk47d1a6e2002-11-03 00:01:44 +0000157
Marian Balakowicz261dcf42008-01-08 18:11:44 +0100158 if (!image_check_magic(hdr)) {
wdenk4b9206e2004-03-23 22:14:11 +0000159 puts ("Bad Magic Number\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200160 show_boot_progress (-1);
wdenk47d1a6e2002-11-03 00:01:44 +0000161 return 1;
162 }
Heiko Schocherfad63402007-07-13 09:54:17 +0200163 show_boot_progress (2);
wdenk47d1a6e2002-11-03 00:01:44 +0000164
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100165 if (!image_check_hcrc (hdr)) {
wdenk4b9206e2004-03-23 22:14:11 +0000166 puts ("Bad Header Checksum\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200167 show_boot_progress (-2);
wdenk47d1a6e2002-11-03 00:01:44 +0000168 return 1;
169 }
Heiko Schocherfad63402007-07-13 09:54:17 +0200170 show_boot_progress (3);
wdenk47d1a6e2002-11-03 00:01:44 +0000171
Wolfgang Denkbccae902005-10-06 01:50:50 +0200172#ifdef CONFIG_HAS_DATAFLASH
173 if (addr_dataflash(addr)){
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100174 len = image_get_image_size (hdr);
Wolfgang Denkbccae902005-10-06 01:50:50 +0200175 read_dataflash(addr, len, (char *)CFG_LOAD_ADDR);
176 addr = CFG_LOAD_ADDR;
177 }
178#endif
179
wdenk47d1a6e2002-11-03 00:01:44 +0000180 /* for multi-file images we need the data part, too */
wdenka57a4962003-10-26 22:52:58 +0000181 print_image_hdr ((image_header_t *)addr);
wdenk47d1a6e2002-11-03 00:01:44 +0000182
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100183 len = image_get_data_size (hdr);
184 data = addr + image_get_header_size ();
185 len_ptr = (ulong *)data;
wdenk47d1a6e2002-11-03 00:01:44 +0000186
187 if (verify) {
wdenk4b9206e2004-03-23 22:14:11 +0000188 puts (" Verifying Checksum ... ");
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100189 if (!image_check_dcrc ((image_header_t *)addr)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000190 printf ("Bad Data CRC\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200191 show_boot_progress (-3);
wdenk47d1a6e2002-11-03 00:01:44 +0000192 return 1;
193 }
wdenk4b9206e2004-03-23 22:14:11 +0000194 puts ("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000195 }
Heiko Schocherfad63402007-07-13 09:54:17 +0200196 show_boot_progress (4);
wdenk47d1a6e2002-11-03 00:01:44 +0000197
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100198 if (!image_check_target_arch (hdr)) {
199 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
Heiko Schocherfad63402007-07-13 09:54:17 +0200200 show_boot_progress (-4);
wdenk47d1a6e2002-11-03 00:01:44 +0000201 return 1;
202 }
Heiko Schocherfad63402007-07-13 09:54:17 +0200203 show_boot_progress (5);
wdenk47d1a6e2002-11-03 00:01:44 +0000204
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100205 switch (image_get_type (hdr)) {
wdenkb13fb012003-10-30 21:49:38 +0000206 case IH_TYPE_STANDALONE:
207 name = "Standalone Application";
208 /* A second argument overwrites the load address */
209 if (argc > 2) {
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100210 image_set_load (hdr, simple_strtoul (argv[2], NULL, 16));
wdenkb13fb012003-10-30 21:49:38 +0000211 }
212 break;
213 case IH_TYPE_KERNEL:
214 name = "Kernel Image";
215 break;
wdenkd4ca31c2004-01-02 14:00:00 +0000216 case IH_TYPE_MULTI:
wdenkb13fb012003-10-30 21:49:38 +0000217 name = "Multi-File Image";
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100218 len = image_to_cpu (len_ptr[0]);
wdenkb13fb012003-10-30 21:49:38 +0000219 /* OS kernel is always the first image */
220 data += 8; /* kernel_len + terminator */
221 for (i=1; len_ptr[i]; ++i)
222 data += 4;
223 break;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100224 default:
225 printf ("Wrong Image Type for %s command\n", cmdtp->name);
Heiko Schocherfad63402007-07-13 09:54:17 +0200226 show_boot_progress (-5);
wdenk47d1a6e2002-11-03 00:01:44 +0000227 return 1;
228 }
Heiko Schocherfad63402007-07-13 09:54:17 +0200229 show_boot_progress (6);
wdenk47d1a6e2002-11-03 00:01:44 +0000230
231 /*
232 * We have reached the point of no return: we are going to
233 * overwrite all exception vector code, so we cannot easily
234 * recover from any failures any more...
235 */
wdenk47d1a6e2002-11-03 00:01:44 +0000236 iflag = disable_interrupts();
237
wdenkc7de8292002-11-19 11:04:11 +0000238#ifdef CONFIG_AMIGAONEG3SE
239 /*
wdenk8bde7f72003-06-27 21:31:46 +0000240 * We've possible left the caches enabled during
wdenkc7de8292002-11-19 11:04:11 +0000241 * bios emulation, so turn them off again
242 */
243 icache_disable();
244 invalidate_l1_instruction_cache();
245 flush_data_cache();
246 dcache_disable();
247#endif
248
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100249 switch (image_get_comp (hdr)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000250 case IH_COMP_NONE:
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100251 if (image_get_load (hdr) == addr) {
wdenk47d1a6e2002-11-03 00:01:44 +0000252 printf (" XIP %s ... ", name);
253 } else {
wdenk47d1a6e2002-11-03 00:01:44 +0000254 printf (" Loading %s ... ", name);
255
Marian Balakowiczaf13cdb2008-01-08 18:11:45 +0100256 memmove_wd ((void *)image_get_load (hdr),
257 (void *)data, len, CHUNKSZ);
258
259 puts("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000260 }
261 break;
262 case IH_COMP_GZIP:
263 printf (" Uncompressing %s ... ", name);
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100264 if (gunzip ((void *)image_get_load (hdr), unc_len,
wdenkeedcd072004-09-08 22:03:11 +0000265 (uchar *)data, &len) != 0) {
wdenk4b9206e2004-03-23 22:14:11 +0000266 puts ("GUNZIP ERROR - must RESET board to recover\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200267 show_boot_progress (-6);
wdenk47d1a6e2002-11-03 00:01:44 +0000268 do_reset (cmdtp, flag, argc, argv);
269 }
270 break;
wdenkc29fdfc2003-08-29 20:57:53 +0000271#ifdef CONFIG_BZIP2
272 case IH_COMP_BZIP2:
273 printf (" Uncompressing %s ... ", name);
wdenk5653fc32004-02-08 22:55:38 +0000274 /*
275 * If we've got less than 4 MB of malloc() space,
276 * use slower decompression algorithm which requires
277 * at most 2300 KB of memory.
278 */
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100279 i = BZ2_bzBuffToBuffDecompress ((char*)image_get_load (hdr),
wdenk5653fc32004-02-08 22:55:38 +0000280 &unc_len, (char *)data, len,
281 CFG_MALLOC_LEN < (4096 * 1024), 0);
wdenkc29fdfc2003-08-29 20:57:53 +0000282 if (i != BZ_OK) {
283 printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
Heiko Schocherfad63402007-07-13 09:54:17 +0200284 show_boot_progress (-6);
wdenkc29fdfc2003-08-29 20:57:53 +0000285 do_reset (cmdtp, flag, argc, argv);
286 }
287 break;
288#endif /* CONFIG_BZIP2 */
wdenk47d1a6e2002-11-03 00:01:44 +0000289 default:
290 if (iflag)
291 enable_interrupts();
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100292 printf ("Unimplemented compression type %d\n", image_get_comp (hdr));
Heiko Schocherfad63402007-07-13 09:54:17 +0200293 show_boot_progress (-7);
wdenk47d1a6e2002-11-03 00:01:44 +0000294 return 1;
295 }
wdenk4b9206e2004-03-23 22:14:11 +0000296 puts ("OK\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200297 show_boot_progress (7);
wdenk47d1a6e2002-11-03 00:01:44 +0000298
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100299 switch (image_get_type (hdr)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000300 case IH_TYPE_STANDALONE:
wdenk47d1a6e2002-11-03 00:01:44 +0000301 if (iflag)
302 enable_interrupts();
303
wdenk4a6fd342003-04-12 23:38:12 +0000304 /* load (and uncompress), but don't start if "autostart"
305 * is set to "no"
306 */
wdenk4a551702003-10-08 23:26:14 +0000307 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0)) {
308 char buf[32];
309 sprintf(buf, "%lX", len);
310 setenv("filesize", buf);
wdenk4a6fd342003-04-12 23:38:12 +0000311 return 0;
wdenk4a551702003-10-08 23:26:14 +0000312 }
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100313 appl = (int (*)(int, char *[]))image_get_ep (hdr);
wdenkb13fb012003-10-30 21:49:38 +0000314 (*appl)(argc-1, &argv[1]);
wdenk4a6fd342003-04-12 23:38:12 +0000315 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000316 case IH_TYPE_KERNEL:
317 case IH_TYPE_MULTI:
318 /* handled below */
319 break;
320 default:
321 if (iflag)
322 enable_interrupts();
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100323 printf ("Can't boot image type %d\n", image_get_type (hdr));
Heiko Schocherfad63402007-07-13 09:54:17 +0200324 show_boot_progress (-8);
wdenk47d1a6e2002-11-03 00:01:44 +0000325 return 1;
326 }
Heiko Schocherfad63402007-07-13 09:54:17 +0200327 show_boot_progress (8);
wdenk47d1a6e2002-11-03 00:01:44 +0000328
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100329 switch (image_get_os (hdr)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000330 default: /* handled by (original) Linux case */
331 case IH_OS_LINUX:
wdenkf72da342003-10-10 10:05:42 +0000332#ifdef CONFIG_SILENT_CONSOLE
333 fixup_silent_linux();
334#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000335 do_bootm_linux (cmdtp, flag, argc, argv,
336 addr, len_ptr, verify);
337 break;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100338
wdenk47d1a6e2002-11-03 00:01:44 +0000339 case IH_OS_NETBSD:
340 do_bootm_netbsd (cmdtp, flag, argc, argv,
341 addr, len_ptr, verify);
342 break;
wdenk8bde7f72003-06-27 21:31:46 +0000343
wdenk1f4bb372003-07-27 00:21:01 +0000344#ifdef CONFIG_LYNXKDI
345 case IH_OS_LYNXOS:
346 do_bootm_lynxkdi (cmdtp, flag, argc, argv,
347 addr, len_ptr, verify);
348 break;
349#endif
350
wdenkd791b1d2003-04-20 14:04:18 +0000351 case IH_OS_RTEMS:
352 do_bootm_rtems (cmdtp, flag, argc, argv,
353 addr, len_ptr, verify);
354 break;
wdenk8bde7f72003-06-27 21:31:46 +0000355
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500356#if defined(CONFIG_CMD_ELF)
wdenk47d1a6e2002-11-03 00:01:44 +0000357 case IH_OS_VXWORKS:
358 do_bootm_vxworks (cmdtp, flag, argc, argv,
359 addr, len_ptr, verify);
360 break;
361 case IH_OS_QNX:
362 do_bootm_qnxelf (cmdtp, flag, argc, argv,
363 addr, len_ptr, verify);
364 break;
Jon Loeliger90253172007-07-10 11:02:44 -0500365#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100366
wdenk7f70e852003-05-20 14:25:27 +0000367#ifdef CONFIG_ARTOS
368 case IH_OS_ARTOS:
369 do_bootm_artos (cmdtp, flag, argc, argv,
370 addr, len_ptr, verify);
371 break;
372#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000373 }
374
Heiko Schocherfad63402007-07-13 09:54:17 +0200375 show_boot_progress (-9);
wdenk47d1a6e2002-11-03 00:01:44 +0000376#ifdef DEBUG
wdenk4b9206e2004-03-23 22:14:11 +0000377 puts ("\n## Control returned to monitor - resetting...\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000378 do_reset (cmdtp, flag, argc, argv);
379#endif
380 return 1;
381}
382
wdenk0d498392003-07-01 21:06:45 +0000383U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100384 bootm, CFG_MAXARGS, 1, do_bootm,
385 "bootm - boot application image from memory\n",
386 "[addr [arg ...]]\n - boot application image stored in memory\n"
387 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
388 "\t'arg' can be the address of an initrd image\n"
Gerald Van Baren213bf8c2007-03-31 12:23:51 -0400389#if defined(CONFIG_OF_FLAT_TREE) || defined(CONFIG_OF_LIBFDT)
Matthew McClintock98a9c4d2006-06-28 10:41:37 -0500390 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
Detlev Zundel5441f612007-10-19 16:47:26 +0200391 "\ta third argument is required which is the address of the\n"
Matthew McClintock98a9c4d2006-06-28 10:41:37 -0500392 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
393 "\tuse a '-' for the second argument. If you do not pass a third\n"
394 "\ta bd_info struct will be passed instead\n"
395#endif
wdenk8bde7f72003-06-27 21:31:46 +0000396);
397
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100398/*******************************************************************/
399/* bootd - boot default image */
400/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500401#if defined(CONFIG_CMD_BOOTD)
wdenk47d1a6e2002-11-03 00:01:44 +0000402int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
403{
404 int rcode = 0;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100405
wdenk47d1a6e2002-11-03 00:01:44 +0000406#ifndef CFG_HUSH_PARSER
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100407 if (run_command (getenv ("bootcmd"), flag) < 0)
408 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000409#else
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100410 if (parse_string_outer (getenv ("bootcmd"),
411 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
412 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000413#endif
414 return rcode;
415}
wdenk8bde7f72003-06-27 21:31:46 +0000416
wdenk0d498392003-07-01 21:06:45 +0000417U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100418 boot, 1, 1, do_bootd,
419 "boot - boot default, i.e., run 'bootcmd'\n",
wdenk9d2b18a2003-06-28 23:11:04 +0000420 NULL
421);
422
423/* keep old command name "bootd" for backward compatibility */
wdenk0d498392003-07-01 21:06:45 +0000424U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100425 bootd, 1, 1, do_bootd,
426 "bootd - boot default, i.e., run 'bootcmd'\n",
wdenk8bde7f72003-06-27 21:31:46 +0000427 NULL
428);
429
wdenk47d1a6e2002-11-03 00:01:44 +0000430#endif
431
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100432
433/*******************************************************************/
434/* iminfo - print header info for a requested image */
435/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500436#if defined(CONFIG_CMD_IMI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100437int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000438{
439 int arg;
440 ulong addr;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100441 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000442
443 if (argc < 2) {
444 return image_info (load_addr);
445 }
446
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100447 for (arg = 1; arg < argc; ++arg) {
448 addr = simple_strtoul (argv[arg], NULL, 16);
449 if (image_info (addr) != 0)
450 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000451 }
452 return rcode;
453}
454
455static int image_info (ulong addr)
456{
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100457 image_header_t *hdr = (image_header_t *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +0000458
459 printf ("\n## Checking Image at %08lx ...\n", addr);
460
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100461 if (!image_check_magic (hdr)) {
wdenk4b9206e2004-03-23 22:14:11 +0000462 puts (" Bad Magic Number\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000463 return 1;
464 }
465
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100466 if (!image_check_hcrc (hdr)) {
wdenk4b9206e2004-03-23 22:14:11 +0000467 puts (" Bad Header Checksum\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000468 return 1;
469 }
470
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100471 print_image_hdr (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000472
wdenk4b9206e2004-03-23 22:14:11 +0000473 puts (" Verifying Checksum ... ");
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100474 if (!image_check_dcrc (hdr)) {
wdenk4b9206e2004-03-23 22:14:11 +0000475 puts (" Bad Data CRC\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000476 return 1;
477 }
wdenk4b9206e2004-03-23 22:14:11 +0000478 puts ("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000479 return 0;
480}
wdenk0d498392003-07-01 21:06:45 +0000481
482U_BOOT_CMD(
483 iminfo, CFG_MAXARGS, 1, do_iminfo,
wdenk8bde7f72003-06-27 21:31:46 +0000484 "iminfo - print header information for application image\n",
485 "addr [addr ...]\n"
486 " - print header information for application image starting at\n"
487 " address 'addr' in memory; this includes verification of the\n"
488 " image contents (magic number, header and payload checksums)\n"
489);
Jon Loeliger90253172007-07-10 11:02:44 -0500490#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000491
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100492
493/*******************************************************************/
494/* imls - list all images found in flash */
495/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500496#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +0000497int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
498{
499 flash_info_t *info;
500 int i, j;
501 image_header_t *hdr;
wdenk27b207f2003-07-24 23:38:38 +0000502
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100503 for (i = 0, info = &flash_info[0];
504 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
505
wdenk27b207f2003-07-24 23:38:38 +0000506 if (info->flash_id == FLASH_UNKNOWN)
507 goto next_bank;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100508 for (j = 0; j < info->sector_count; ++j) {
wdenk27b207f2003-07-24 23:38:38 +0000509
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100510 hdr = (image_header_t *)info->start[j];
511
512 if (!hdr || !image_check_magic (hdr))
wdenk27b207f2003-07-24 23:38:38 +0000513 goto next_sector;
514
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100515 if (!image_check_hcrc (hdr))
wdenk27b207f2003-07-24 23:38:38 +0000516 goto next_sector;
517
518 printf ("Image at %08lX:\n", (ulong)hdr);
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100519 print_image_hdr (hdr);
wdenk5bb226e2003-11-17 21:14:37 +0000520
wdenk4b9206e2004-03-23 22:14:11 +0000521 puts (" Verifying Checksum ... ");
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100522 if (!image_check_dcrc (hdr)) {
523 puts ("Bad Data CRC\n");
524 } else {
525 puts ("OK\n");
wdenk5bb226e2003-11-17 21:14:37 +0000526 }
wdenkbdccc4f2003-08-05 17:43:17 +0000527next_sector: ;
wdenk27b207f2003-07-24 23:38:38 +0000528 }
wdenkbdccc4f2003-08-05 17:43:17 +0000529next_bank: ;
wdenk27b207f2003-07-24 23:38:38 +0000530 }
531
532 return (0);
533}
534
535U_BOOT_CMD(
536 imls, 1, 1, do_imls,
537 "imls - list all images found in flash\n",
538 "\n"
539 " - Prints information about all images found at sector\n"
540 " boundaries in flash.\n"
541);
Jon Loeliger90253172007-07-10 11:02:44 -0500542#endif
wdenk27b207f2003-07-24 23:38:38 +0000543
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100544/*******************************************************************/
545/* */
546/*******************************************************************/
547void print_image_hdr (image_header_t *hdr)
wdenk47d1a6e2002-11-03 00:01:44 +0000548{
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500549#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100550 time_t timestamp = (time_t)image_get_time (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000551 struct rtc_time tm;
552#endif
553
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100554 printf (" Image Name: %.*s\n", IH_NMLEN, image_get_name (hdr));
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100555
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500556#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
wdenk47d1a6e2002-11-03 00:01:44 +0000557 to_tm (timestamp, &tm);
558 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
559 tm.tm_year, tm.tm_mon, tm.tm_mday,
560 tm.tm_hour, tm.tm_min, tm.tm_sec);
Jon Loeliger90253172007-07-10 11:02:44 -0500561#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100562 puts (" Image Type: ");
563 print_type (hdr);
564
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100565 printf ("\n Data Size: %d Bytes = ", image_get_data_size (hdr));
566 print_size (image_get_data_size (hdr), "\n");
wdenk4b9206e2004-03-23 22:14:11 +0000567 printf (" Load Address: %08x\n"
568 " Entry Point: %08x\n",
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100569 image_get_load (hdr), image_get_ep (hdr));
wdenk47d1a6e2002-11-03 00:01:44 +0000570
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100571 if (image_check_type (hdr, IH_TYPE_MULTI)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000572 int i;
573 ulong len;
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100574 ulong *len_ptr = (ulong *)((ulong)hdr + image_get_header_size ());
wdenk47d1a6e2002-11-03 00:01:44 +0000575
wdenk4b9206e2004-03-23 22:14:11 +0000576 puts (" Contents:\n");
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100577 for (i = 0; (len = image_to_cpu (*len_ptr)); ++i, ++len_ptr) {
wdenk47d1a6e2002-11-03 00:01:44 +0000578 printf (" Image %d: %8ld Bytes = ", i, len);
579 print_size (len, "\n");
580 }
581 }
582}
583
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100584static void print_type (image_header_t *hdr)
wdenk47d1a6e2002-11-03 00:01:44 +0000585{
586 char *os, *arch, *type, *comp;
587
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100588 switch (image_get_os (hdr)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000589 case IH_OS_INVALID: os = "Invalid OS"; break;
590 case IH_OS_NETBSD: os = "NetBSD"; break;
591 case IH_OS_LINUX: os = "Linux"; break;
592 case IH_OS_VXWORKS: os = "VxWorks"; break;
593 case IH_OS_QNX: os = "QNX"; break;
594 case IH_OS_U_BOOT: os = "U-Boot"; break;
wdenkd791b1d2003-04-20 14:04:18 +0000595 case IH_OS_RTEMS: os = "RTEMS"; break;
wdenk7f70e852003-05-20 14:25:27 +0000596#ifdef CONFIG_ARTOS
597 case IH_OS_ARTOS: os = "ARTOS"; break;
598#endif
wdenk1f4bb372003-07-27 00:21:01 +0000599#ifdef CONFIG_LYNXKDI
600 case IH_OS_LYNXOS: os = "LynxOS"; break;
601#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000602 default: os = "Unknown OS"; break;
603 }
604
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100605 switch (image_get_arch (hdr)) {
606 case IH_ARCH_INVALID: arch = "Invalid CPU"; break;
607 case IH_ARCH_ALPHA: arch = "Alpha"; break;
608 case IH_ARCH_ARM: arch = "ARM"; break;
609 case IH_ARCH_AVR32: arch = "AVR32"; break;
610 case IH_ARCH_BLACKFIN: arch = "Blackfin"; break;
611 case IH_ARCH_I386: arch = "Intel x86"; break;
612 case IH_ARCH_IA64: arch = "IA64"; break;
613 case IH_ARCH_M68K: arch = "M68K"; break;
614 case IH_ARCH_MICROBLAZE:arch = "Microblaze"; break;
615 case IH_ARCH_MIPS64: arch = "MIPS 64 Bit"; break;
616 case IH_ARCH_MIPS: arch = "MIPS"; break;
617 case IH_ARCH_NIOS2: arch = "Nios-II"; break;
618 case IH_ARCH_NIOS: arch = "Nios"; break;
619 case IH_ARCH_PPC: arch = "PowerPC"; break;
620 case IH_ARCH_S390: arch = "IBM S390"; break;
621 case IH_ARCH_SH: arch = "SuperH"; break;
622 case IH_ARCH_SPARC64: arch = "SPARC 64 Bit"; break;
623 case IH_ARCH_SPARC: arch = "SPARC"; break;
wdenk47d1a6e2002-11-03 00:01:44 +0000624 default: arch = "Unknown Architecture"; break;
625 }
626
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100627 switch (image_get_type (hdr)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000628 case IH_TYPE_INVALID: type = "Invalid Image"; break;
629 case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
630 case IH_TYPE_KERNEL: type = "Kernel Image"; break;
631 case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
632 case IH_TYPE_MULTI: type = "Multi-File Image"; break;
633 case IH_TYPE_FIRMWARE: type = "Firmware"; break;
634 case IH_TYPE_SCRIPT: type = "Script"; break;
Matthew McClintock25c751e2006-08-16 10:54:09 -0500635 case IH_TYPE_FLATDT: type = "Flat Device Tree"; break;
wdenk47d1a6e2002-11-03 00:01:44 +0000636 default: type = "Unknown Image"; break;
637 }
638
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100639 switch (image_get_comp (hdr)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000640 case IH_COMP_NONE: comp = "uncompressed"; break;
641 case IH_COMP_GZIP: comp = "gzip compressed"; break;
642 case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
643 default: comp = "unknown compression"; break;
644 }
645
646 printf ("%s %s %s (%s)", arch, os, type, comp);
647}
648
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100649#ifdef CONFIG_SILENT_CONSOLE
650static void fixup_silent_linux ()
651{
652 char buf[256], *start, *end;
653 char *cmdline = getenv ("bootargs");
654
655 /* Only fix cmdline when requested */
656 if (!(gd->flags & GD_FLG_SILENT))
657 return;
658
659 debug ("before silent fix-up: %s\n", cmdline);
660 if (cmdline) {
661 if ((start = strstr (cmdline, "console=")) != NULL) {
662 end = strchr (start, ' ');
663 strncpy (buf, cmdline, (start - cmdline + 8));
664 if (end)
665 strcpy (buf + (start - cmdline + 8), end);
666 else
667 buf[start - cmdline + 8] = '\0';
668 } else {
669 strcpy (buf, cmdline);
670 strcat (buf, " console=");
671 }
672 } else {
673 strcpy (buf, "console=");
674 }
675
676 setenv ("bootargs", buf);
677 debug ("after silent fix-up: %s\n", buf);
678}
679#endif /* CONFIG_SILENT_CONSOLE */
680
681
682/*******************************************************************/
683/* OS booting routines */
684/*******************************************************************/
685
686static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
687 int argc, char *argv[],
688 ulong addr, ulong *len_ptr,
689 int verify)
wdenkd791b1d2003-04-20 14:04:18 +0000690{
wdenkd791b1d2003-04-20 14:04:18 +0000691 image_header_t *hdr = &header;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100692
693 void (*loader)(bd_t *, image_header_t *, char *, char *);
694 image_header_t *img_addr;
695 char *consdev;
696 char *cmdline;
697
698 /*
699 * Booting a (NetBSD) kernel image
700 *
701 * This process is pretty similar to a standalone application:
702 * The (first part of an multi-) image must be a stage-2 loader,
703 * which in turn is responsible for loading & invoking the actual
704 * kernel. The only differences are the parameters being passed:
705 * besides the board info strucure, the loader expects a command
706 * line, the name of the console device, and (optionally) the
707 * address of the original image header.
708 */
709
710 img_addr = 0;
711 if ((image_check_type (hdr, IH_TYPE_MULTI)) && (len_ptr[1]))
712 img_addr = (image_header_t *)addr;
713
714 consdev = "";
715#if defined (CONFIG_8xx_CONS_SMC1)
716 consdev = "smc1";
717#elif defined (CONFIG_8xx_CONS_SMC2)
718 consdev = "smc2";
719#elif defined (CONFIG_8xx_CONS_SCC2)
720 consdev = "scc2";
721#elif defined (CONFIG_8xx_CONS_SCC3)
722 consdev = "scc3";
723#endif
724
725 if (argc > 2) {
726 ulong len;
727 int i;
728
729 for (i = 2, len = 0; i < argc; i += 1)
730 len += strlen (argv[i]) + 1;
731 cmdline = malloc (len);
732
733 for (i = 2, len = 0; i < argc; i += 1) {
734 if (i > 2)
735 cmdline[len++] = ' ';
736 strcpy (&cmdline[len], argv[i]);
737 len += strlen (argv[i]);
738 }
739 } else if ((cmdline = getenv ("bootargs")) == NULL) {
740 cmdline = "";
741 }
742
743 loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
744
745 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
746 (ulong)loader);
747
748 show_boot_progress (15);
749
750 /*
751 * NetBSD Stage-2 Loader Parameters:
752 * r3: ptr to board info data
753 * r4: image address
754 * r5: console device
755 * r6: boot args string
756 */
757 (*loader) (gd->bd, img_addr, consdev, cmdline);
758}
759
760#ifdef CONFIG_LYNXKDI
761static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
762 int argc, char *argv[],
763 ulong addr, ulong *len_ptr,
764 int verify)
765{
766 lynxkdi_boot (&header);
767}
768#endif /* CONFIG_LYNXKDI */
769
770static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
771 int argc, char *argv[],
772 ulong addr, ulong *len_ptr,
773 int verify)
774{
775 image_header_t *hdr = &header;
776 void (*entry_point)(bd_t *);
wdenkd791b1d2003-04-20 14:04:18 +0000777
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100778 entry_point = (void (*)(bd_t *))image_get_ep (hdr);
wdenkd791b1d2003-04-20 14:04:18 +0000779
780 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
781 (ulong)entry_point);
782
Heiko Schocherfad63402007-07-13 09:54:17 +0200783 show_boot_progress (15);
wdenkd791b1d2003-04-20 14:04:18 +0000784
785 /*
786 * RTEMS Parameters:
787 * r3: ptr to board info data
788 */
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100789 (*entry_point)(gd->bd);
wdenkd791b1d2003-04-20 14:04:18 +0000790}
791
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500792#if defined(CONFIG_CMD_ELF)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100793static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
794 int argc, char *argv[],
795 ulong addr, ulong *len_ptr,
796 int verify)
wdenk47d1a6e2002-11-03 00:01:44 +0000797{
798 image_header_t *hdr = &header;
799 char str[80];
800
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100801 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +0000802 setenv("loadaddr", str);
803 do_bootvx(cmdtp, 0, 0, NULL);
804}
805
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100806static void do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag,
807 int argc, char *argv[],
808 ulong addr, ulong *len_ptr,
809 int verify)
wdenk47d1a6e2002-11-03 00:01:44 +0000810{
811 image_header_t *hdr = &header;
812 char *local_args[2];
813 char str[16];
814
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100815 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +0000816 local_args[0] = argv[0];
817 local_args[1] = str; /* and provide it via the arguments */
818 do_bootelf(cmdtp, 0, 2, local_args);
819}
Jon Loeliger90253172007-07-10 11:02:44 -0500820#endif
wdenk1f4bb372003-07-27 00:21:01 +0000821
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100822#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
823static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
824 int argc, char *argv[],
825 ulong addr, ulong *len_ptr,
826 int verify)
wdenk1f4bb372003-07-27 00:21:01 +0000827{
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100828 ulong top;
829 char *s, *cmdline;
830 char **fwenv, **ss;
831 int i, j, nxt, len, envno, envsz;
832 bd_t *kbd;
833 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
834 image_header_t *hdr = &header;
wdenk1f4bb372003-07-27 00:21:01 +0000835
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100836 /*
837 * Booting an ARTOS kernel image + application
838 */
839
840 /* this used to be the top of memory, but was wrong... */
841#ifdef CONFIG_PPC
842 /* get stack pointer */
843 asm volatile ("mr %0,1" : "=r"(top) );
844#endif
845 debug ("## Current stack ends at 0x%08lX ", top);
846
847 top -= 2048; /* just to be sure */
848 if (top > CFG_BOOTMAPSZ)
849 top = CFG_BOOTMAPSZ;
850 top &= ~0xF;
851
852 debug ("=> set upper limit to 0x%08lX\n", top);
853
854 /* first check the artos specific boot args, then the linux args*/
855 if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
856 s = "";
857
858 /* get length of cmdline, and place it */
859 len = strlen (s);
860 top = (top - (len + 1)) & ~0xF;
861 cmdline = (char *)top;
862 debug ("## cmdline at 0x%08lX ", top);
863 strcpy (cmdline, s);
864
865 /* copy bdinfo */
866 top = (top - sizeof (bd_t)) & ~0xF;
867 debug ("## bd at 0x%08lX ", top);
868 kbd = (bd_t *)top;
869 memcpy (kbd, gd->bd, sizeof (bd_t));
870
871 /* first find number of env entries, and their size */
872 envno = 0;
873 envsz = 0;
874 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
875 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
876 ;
877 envno++;
878 envsz += (nxt - i) + 1; /* plus trailing zero */
879 }
880 envno++; /* plus the terminating zero */
881 debug ("## %u envvars total size %u ", envno, envsz);
882
883 top = (top - sizeof (char **) * envno) & ~0xF;
884 fwenv = (char **)top;
885 debug ("## fwenv at 0x%08lX ", top);
886
887 top = (top - envsz) & ~0xF;
888 s = (char *)top;
889 ss = fwenv;
890
891 /* now copy them */
892 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
893 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
894 ;
895 *ss++ = s;
896 for (j = i; j < nxt; ++j)
897 *s++ = env_get_char (j);
898 *s++ = '\0';
899 }
900 *ss++ = NULL; /* terminate */
901
902 entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
903 (*entry) (kbd, cmdline, fwenv, top);
904}
905#endif