blob: 2705a5d8bafae4e932ff9dc79f29f39bdbea40ed [file] [log] [blame]
wdenk47d1a6e2002-11-03 00:01:44 +00001/*
Stefan Roese15940c92006-03-13 11:16:36 +01002 * (C) Copyright 2000-2006
wdenk47d1a6e2002-11-03 00:01:44 +00003 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
Marian Balakowiczb97a2a02008-01-08 18:14:09 +010024#define DEBUG
25
wdenk47d1a6e2002-11-03 00:01:44 +000026/*
27 * Boot support
28 */
29#include <common.h>
30#include <watchdog.h>
31#include <command.h>
wdenk47d1a6e2002-11-03 00:01:44 +000032#include <image.h>
33#include <malloc.h>
34#include <zlib.h>
wdenkc29fdfc2003-08-29 20:57:53 +000035#include <bzlib.h>
wdenk7f70e852003-05-20 14:25:27 +000036#include <environment.h>
wdenk47d1a6e2002-11-03 00:01:44 +000037#include <asm/byteorder.h>
wdenk8bde7f72003-06-27 21:31:46 +000038
Jon Loeligerbaa26db2007-07-08 17:51:39 -050039#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
wdenk47d1a6e2002-11-03 00:01:44 +000040#include <rtc.h>
41#endif
42
43#ifdef CFG_HUSH_PARSER
44#include <hush.h>
45#endif
46
wdenk2abbe072003-06-16 23:50:08 +000047#ifdef CONFIG_HAS_DATAFLASH
48#include <dataflash.h>
49#endif
50
Marian Balakowicz1ee11802008-01-08 18:17:10 +010051DECLARE_GLOBAL_DATA_PTR;
52
53extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
54#ifndef CFG_BOOTM_LEN
55#define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
56#endif
wdenk47d1a6e2002-11-03 00:01:44 +000057
Marian Balakowicz321359f2008-01-08 18:11:43 +010058#ifdef CONFIG_BZIP2
59extern void bz_internal_error(int);
60#endif
wdenk47d1a6e2002-11-03 00:01:44 +000061
Jon Loeligerbaa26db2007-07-08 17:51:39 -050062#if defined(CONFIG_CMD_IMI)
wdenk47d1a6e2002-11-03 00:01:44 +000063static int image_info (unsigned long addr);
64#endif
wdenk27b207f2003-07-24 23:38:38 +000065
Jon Loeligerbaa26db2007-07-08 17:51:39 -050066#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +000067#include <flash.h>
Marian Balakowicze6f2e902005-10-11 19:09:42 +020068extern flash_info_t flash_info[]; /* info for FLASH chips */
wdenk27b207f2003-07-24 23:38:38 +000069static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
70#endif
71
Marian Balakowicz1ee11802008-01-08 18:17:10 +010072#ifdef CONFIG_SILENT_CONSOLE
73static void fixup_silent_linux (void);
74#endif
75
wdenk47d1a6e2002-11-03 00:01:44 +000076static void print_type (image_header_t *hdr);
Marian Balakowicz1ee11802008-01-08 18:17:10 +010077extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
wdenk47d1a6e2002-11-03 00:01:44 +000078
79/*
80 * Continue booting an OS image; caller already has:
81 * - copied image header to global variable `header'
82 * - checked header magic number, checksums (both header & image),
83 * - verified image architecture (PPC) and type (KERNEL or MULTI),
84 * - loaded (first part of) image to header load address,
85 * - disabled interrupts.
86 */
Marian Balakowicz1ee11802008-01-08 18:17:10 +010087typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010088 int argc, char *argv[],
89 image_header_t *hdr, /* of image to boot */
90 int verify); /* getenv("verify")[0] != 'n' */
wdenk47d1a6e2002-11-03 00:01:44 +000091
Marian Balakowicz1ee11802008-01-08 18:17:10 +010092extern boot_os_fn do_bootm_linux;
93static boot_os_fn do_bootm_netbsd;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +010094#if defined(CONFIG_LYNXKDI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +010095static boot_os_fn do_bootm_lynxkdi;
96extern void lynxkdi_boot (image_header_t *);
wdenkf72da342003-10-10 10:05:42 +000097#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +010098static boot_os_fn do_bootm_rtems;
Jon Loeligerbaa26db2007-07-08 17:51:39 -050099#if defined(CONFIG_CMD_ELF)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100100static boot_os_fn do_bootm_vxworks;
101static boot_os_fn do_bootm_qnxelf;
102int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
103int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
Jon Loeliger90253172007-07-10 11:02:44 -0500104#endif
wdenk7f70e852003-05-20 14:25:27 +0000105#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100106extern uchar (*env_get_char)(int); /* Returns a character from the environment */
107static boot_os_fn do_bootm_artos;
Stefan Roese15940c92006-03-13 11:16:36 +0100108#endif
109
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100110ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
wdenk47d1a6e2002-11-03 00:01:44 +0000111
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100112
113/*******************************************************************/
114/* bootm - boot application image from image in memory */
115/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +0000116int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
117{
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100118 ulong iflag;
Marian Balakowicze99c2662008-01-31 13:20:07 +0100119 char *name;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100120 uint unc_len = CFG_BOOTM_LEN;
121 int verify = getenv_verify();
wdenk47d1a6e2002-11-03 00:01:44 +0000122
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100123 image_header_t *hdr;
124 ulong img_addr;
125 ulong os_data, os_len;
wdenk47d1a6e2002-11-03 00:01:44 +0000126
Marian Balakowicz75824382008-01-31 13:20:06 +0100127 ulong image_start, image_end;
128 ulong load_start, load_end;
129
130
wdenk47d1a6e2002-11-03 00:01:44 +0000131 if (argc < 2) {
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100132 img_addr = load_addr;
wdenk47d1a6e2002-11-03 00:01:44 +0000133 } else {
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100134 img_addr = simple_strtoul(argv[1], NULL, 16);
wdenk47d1a6e2002-11-03 00:01:44 +0000135 }
136
Heiko Schocherfad63402007-07-13 09:54:17 +0200137 show_boot_progress (1);
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100138 printf ("## Booting image at %08lx ...\n", img_addr);
wdenk47d1a6e2002-11-03 00:01:44 +0000139
wdenk2abbe072003-06-16 23:50:08 +0000140#ifdef CONFIG_HAS_DATAFLASH
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100141 if (addr_dataflash (img_addr)){
142 hdr = (image_header_t *)CFG_LOAD_ADDR;
143 read_dataflash (img_addr, image_get_header_size (), (char *)hdr);
wdenk2abbe072003-06-16 23:50:08 +0000144 } else
145#endif
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100146 hdr = (image_header_t *)img_addr;
wdenk47d1a6e2002-11-03 00:01:44 +0000147
Marian Balakowicz261dcf42008-01-08 18:11:44 +0100148 if (!image_check_magic(hdr)) {
wdenk4b9206e2004-03-23 22:14:11 +0000149 puts ("Bad Magic Number\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200150 show_boot_progress (-1);
wdenk47d1a6e2002-11-03 00:01:44 +0000151 return 1;
152 }
Heiko Schocherfad63402007-07-13 09:54:17 +0200153 show_boot_progress (2);
wdenk47d1a6e2002-11-03 00:01:44 +0000154
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100155 if (!image_check_hcrc (hdr)) {
wdenk4b9206e2004-03-23 22:14:11 +0000156 puts ("Bad Header Checksum\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200157 show_boot_progress (-2);
wdenk47d1a6e2002-11-03 00:01:44 +0000158 return 1;
159 }
Heiko Schocherfad63402007-07-13 09:54:17 +0200160 show_boot_progress (3);
wdenk47d1a6e2002-11-03 00:01:44 +0000161
Wolfgang Denkbccae902005-10-06 01:50:50 +0200162#ifdef CONFIG_HAS_DATAFLASH
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100163 if (addr_dataflash (img_addr))
164 read_dataflash (img_addr + image_get_header_size (),
165 image_get_data_size (hdr),
166 (char *)image_get_data (hdr));
Wolfgang Denkbccae902005-10-06 01:50:50 +0200167#endif
168
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100169 /* uImage is in a system RAM, pointed to by hdr */
170 print_image_hdr (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000171
172 if (verify) {
wdenk4b9206e2004-03-23 22:14:11 +0000173 puts (" Verifying Checksum ... ");
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100174 if (!image_check_dcrc (hdr)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000175 printf ("Bad Data CRC\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200176 show_boot_progress (-3);
wdenk47d1a6e2002-11-03 00:01:44 +0000177 return 1;
178 }
wdenk4b9206e2004-03-23 22:14:11 +0000179 puts ("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000180 }
Heiko Schocherfad63402007-07-13 09:54:17 +0200181 show_boot_progress (4);
wdenk47d1a6e2002-11-03 00:01:44 +0000182
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100183 if (!image_check_target_arch (hdr)) {
184 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
Heiko Schocherfad63402007-07-13 09:54:17 +0200185 show_boot_progress (-4);
wdenk47d1a6e2002-11-03 00:01:44 +0000186 return 1;
187 }
Heiko Schocherfad63402007-07-13 09:54:17 +0200188 show_boot_progress (5);
wdenk47d1a6e2002-11-03 00:01:44 +0000189
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100190 switch (image_get_type (hdr)) {
wdenkb13fb012003-10-30 21:49:38 +0000191 case IH_TYPE_KERNEL:
192 name = "Kernel Image";
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100193 os_data = image_get_data (hdr);
194 os_len = image_get_data_size (hdr);
wdenkb13fb012003-10-30 21:49:38 +0000195 break;
wdenkd4ca31c2004-01-02 14:00:00 +0000196 case IH_TYPE_MULTI:
wdenkb13fb012003-10-30 21:49:38 +0000197 name = "Multi-File Image";
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100198 image_multi_getimg (hdr, 0, &os_data, &os_len);
wdenkb13fb012003-10-30 21:49:38 +0000199 break;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100200 default:
201 printf ("Wrong Image Type for %s command\n", cmdtp->name);
Heiko Schocherfad63402007-07-13 09:54:17 +0200202 show_boot_progress (-5);
wdenk47d1a6e2002-11-03 00:01:44 +0000203 return 1;
204 }
Heiko Schocherfad63402007-07-13 09:54:17 +0200205 show_boot_progress (6);
wdenk47d1a6e2002-11-03 00:01:44 +0000206
207 /*
208 * We have reached the point of no return: we are going to
209 * overwrite all exception vector code, so we cannot easily
210 * recover from any failures any more...
211 */
wdenk47d1a6e2002-11-03 00:01:44 +0000212 iflag = disable_interrupts();
213
wdenkc7de8292002-11-19 11:04:11 +0000214#ifdef CONFIG_AMIGAONEG3SE
215 /*
wdenk8bde7f72003-06-27 21:31:46 +0000216 * We've possible left the caches enabled during
wdenkc7de8292002-11-19 11:04:11 +0000217 * bios emulation, so turn them off again
218 */
219 icache_disable();
220 invalidate_l1_instruction_cache();
221 flush_data_cache();
222 dcache_disable();
223#endif
224
Marian Balakowicz75824382008-01-31 13:20:06 +0100225 image_start = (ulong)hdr;
226 image_end = image_get_image_end (hdr);
227 load_start = image_get_load (hdr);
228 load_end = 0;
229
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100230 switch (image_get_comp (hdr)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000231 case IH_COMP_NONE:
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100232 if (image_get_load (hdr) == img_addr) {
wdenk47d1a6e2002-11-03 00:01:44 +0000233 printf (" XIP %s ... ", name);
234 } else {
wdenk47d1a6e2002-11-03 00:01:44 +0000235 printf (" Loading %s ... ", name);
236
Marian Balakowiczaf13cdb2008-01-08 18:11:45 +0100237 memmove_wd ((void *)image_get_load (hdr),
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100238 (void *)os_data, os_len, CHUNKSZ);
Marian Balakowiczaf13cdb2008-01-08 18:11:45 +0100239
Marian Balakowicz75824382008-01-31 13:20:06 +0100240 load_end = load_start + os_len;
Marian Balakowiczaf13cdb2008-01-08 18:11:45 +0100241 puts("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000242 }
243 break;
244 case IH_COMP_GZIP:
245 printf (" Uncompressing %s ... ", name);
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100246 if (gunzip ((void *)image_get_load (hdr), unc_len,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100247 (uchar *)os_data, &os_len) != 0) {
wdenk4b9206e2004-03-23 22:14:11 +0000248 puts ("GUNZIP ERROR - must RESET board to recover\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200249 show_boot_progress (-6);
wdenk47d1a6e2002-11-03 00:01:44 +0000250 do_reset (cmdtp, flag, argc, argv);
251 }
Marian Balakowicz75824382008-01-31 13:20:06 +0100252
253 load_end = load_start + os_len;
wdenk47d1a6e2002-11-03 00:01:44 +0000254 break;
wdenkc29fdfc2003-08-29 20:57:53 +0000255#ifdef CONFIG_BZIP2
256 case IH_COMP_BZIP2:
257 printf (" Uncompressing %s ... ", name);
wdenk5653fc32004-02-08 22:55:38 +0000258 /*
259 * If we've got less than 4 MB of malloc() space,
260 * use slower decompression algorithm which requires
261 * at most 2300 KB of memory.
262 */
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100263 int i = BZ2_bzBuffToBuffDecompress ((char*)image_get_load (hdr),
264 &unc_len, (char *)os_data, os_len,
265 CFG_MALLOC_LEN < (4096 * 1024), 0);
wdenkc29fdfc2003-08-29 20:57:53 +0000266 if (i != BZ_OK) {
267 printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
Heiko Schocherfad63402007-07-13 09:54:17 +0200268 show_boot_progress (-6);
wdenkc29fdfc2003-08-29 20:57:53 +0000269 do_reset (cmdtp, flag, argc, argv);
270 }
Marian Balakowicz75824382008-01-31 13:20:06 +0100271
272 load_end = load_start + unc_len;
wdenkc29fdfc2003-08-29 20:57:53 +0000273 break;
274#endif /* CONFIG_BZIP2 */
wdenk47d1a6e2002-11-03 00:01:44 +0000275 default:
276 if (iflag)
277 enable_interrupts();
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100278 printf ("Unimplemented compression type %d\n", image_get_comp (hdr));
Heiko Schocherfad63402007-07-13 09:54:17 +0200279 show_boot_progress (-7);
wdenk47d1a6e2002-11-03 00:01:44 +0000280 return 1;
281 }
wdenk4b9206e2004-03-23 22:14:11 +0000282 puts ("OK\n");
Heiko Schocherfad63402007-07-13 09:54:17 +0200283 show_boot_progress (7);
wdenk47d1a6e2002-11-03 00:01:44 +0000284
Marian Balakowicz75824382008-01-31 13:20:06 +0100285 if ((load_start < image_end) && (load_end > image_start)) {
286 debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end);
287 debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end);
288
289 puts ("ERROR: image overwritten - must RESET the board to recover.\n");
290 do_reset (cmdtp, flag, argc, argv);
291 }
292
Heiko Schocherfad63402007-07-13 09:54:17 +0200293 show_boot_progress (8);
wdenk47d1a6e2002-11-03 00:01:44 +0000294
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100295 switch (image_get_os (hdr)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000296 default: /* handled by (original) Linux case */
297 case IH_OS_LINUX:
wdenkf72da342003-10-10 10:05:42 +0000298#ifdef CONFIG_SILENT_CONSOLE
299 fixup_silent_linux();
300#endif
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100301 do_bootm_linux (cmdtp, flag, argc, argv, hdr, verify);
wdenk47d1a6e2002-11-03 00:01:44 +0000302 break;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100303
wdenk47d1a6e2002-11-03 00:01:44 +0000304 case IH_OS_NETBSD:
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100305 do_bootm_netbsd (cmdtp, flag, argc, argv, hdr, verify);
wdenk47d1a6e2002-11-03 00:01:44 +0000306 break;
wdenk8bde7f72003-06-27 21:31:46 +0000307
wdenk1f4bb372003-07-27 00:21:01 +0000308#ifdef CONFIG_LYNXKDI
309 case IH_OS_LYNXOS:
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100310 do_bootm_lynxkdi (cmdtp, flag, argc, argv, hdr, verify);
wdenk1f4bb372003-07-27 00:21:01 +0000311 break;
312#endif
313
wdenkd791b1d2003-04-20 14:04:18 +0000314 case IH_OS_RTEMS:
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100315 do_bootm_rtems (cmdtp, flag, argc, argv, hdr, verify);
wdenkd791b1d2003-04-20 14:04:18 +0000316 break;
wdenk8bde7f72003-06-27 21:31:46 +0000317
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500318#if defined(CONFIG_CMD_ELF)
wdenk47d1a6e2002-11-03 00:01:44 +0000319 case IH_OS_VXWORKS:
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100320 do_bootm_vxworks (cmdtp, flag, argc, argv, hdr, verify);
wdenk47d1a6e2002-11-03 00:01:44 +0000321 break;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100322
wdenk47d1a6e2002-11-03 00:01:44 +0000323 case IH_OS_QNX:
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100324 do_bootm_qnxelf (cmdtp, flag, argc, argv, hdr, verify);
wdenk47d1a6e2002-11-03 00:01:44 +0000325 break;
Jon Loeliger90253172007-07-10 11:02:44 -0500326#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100327
wdenk7f70e852003-05-20 14:25:27 +0000328#ifdef CONFIG_ARTOS
329 case IH_OS_ARTOS:
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100330 do_bootm_artos (cmdtp, flag, argc, argv, hdr, verify);
wdenk7f70e852003-05-20 14:25:27 +0000331 break;
332#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000333 }
334
Heiko Schocherfad63402007-07-13 09:54:17 +0200335 show_boot_progress (-9);
wdenk47d1a6e2002-11-03 00:01:44 +0000336#ifdef DEBUG
wdenk4b9206e2004-03-23 22:14:11 +0000337 puts ("\n## Control returned to monitor - resetting...\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000338 do_reset (cmdtp, flag, argc, argv);
339#endif
340 return 1;
341}
342
wdenk0d498392003-07-01 21:06:45 +0000343U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100344 bootm, CFG_MAXARGS, 1, do_bootm,
345 "bootm - boot application image from memory\n",
346 "[addr [arg ...]]\n - boot application image stored in memory\n"
347 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
348 "\t'arg' can be the address of an initrd image\n"
Marian Balakowicz4a2ad5f2008-01-31 13:20:07 +0100349#if defined(CONFIG_OF_LIBFDT)
Matthew McClintock98a9c4d2006-06-28 10:41:37 -0500350 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
Detlev Zundel5441f612007-10-19 16:47:26 +0200351 "\ta third argument is required which is the address of the\n"
Matthew McClintock98a9c4d2006-06-28 10:41:37 -0500352 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
353 "\tuse a '-' for the second argument. If you do not pass a third\n"
354 "\ta bd_info struct will be passed instead\n"
355#endif
wdenk8bde7f72003-06-27 21:31:46 +0000356);
357
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100358/*******************************************************************/
359/* bootd - boot default image */
360/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500361#if defined(CONFIG_CMD_BOOTD)
wdenk47d1a6e2002-11-03 00:01:44 +0000362int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
363{
364 int rcode = 0;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100365
wdenk47d1a6e2002-11-03 00:01:44 +0000366#ifndef CFG_HUSH_PARSER
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100367 if (run_command (getenv ("bootcmd"), flag) < 0)
368 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000369#else
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100370 if (parse_string_outer (getenv ("bootcmd"),
371 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
372 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000373#endif
374 return rcode;
375}
wdenk8bde7f72003-06-27 21:31:46 +0000376
wdenk0d498392003-07-01 21:06:45 +0000377U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100378 boot, 1, 1, do_bootd,
379 "boot - boot default, i.e., run 'bootcmd'\n",
wdenk9d2b18a2003-06-28 23:11:04 +0000380 NULL
381);
382
383/* keep old command name "bootd" for backward compatibility */
wdenk0d498392003-07-01 21:06:45 +0000384U_BOOT_CMD(
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100385 bootd, 1, 1, do_bootd,
386 "bootd - boot default, i.e., run 'bootcmd'\n",
wdenk8bde7f72003-06-27 21:31:46 +0000387 NULL
388);
389
wdenk47d1a6e2002-11-03 00:01:44 +0000390#endif
391
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100392
393/*******************************************************************/
394/* iminfo - print header info for a requested image */
395/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500396#if defined(CONFIG_CMD_IMI)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100397int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000398{
399 int arg;
400 ulong addr;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100401 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000402
403 if (argc < 2) {
404 return image_info (load_addr);
405 }
406
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100407 for (arg = 1; arg < argc; ++arg) {
408 addr = simple_strtoul (argv[arg], NULL, 16);
409 if (image_info (addr) != 0)
410 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000411 }
412 return rcode;
413}
414
415static int image_info (ulong addr)
416{
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100417 image_header_t *hdr = (image_header_t *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +0000418
419 printf ("\n## Checking Image at %08lx ...\n", addr);
420
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100421 if (!image_check_magic (hdr)) {
wdenk4b9206e2004-03-23 22:14:11 +0000422 puts (" Bad Magic Number\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000423 return 1;
424 }
425
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100426 if (!image_check_hcrc (hdr)) {
wdenk4b9206e2004-03-23 22:14:11 +0000427 puts (" Bad Header Checksum\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000428 return 1;
429 }
430
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100431 print_image_hdr (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000432
wdenk4b9206e2004-03-23 22:14:11 +0000433 puts (" Verifying Checksum ... ");
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100434 if (!image_check_dcrc (hdr)) {
wdenk4b9206e2004-03-23 22:14:11 +0000435 puts (" Bad Data CRC\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000436 return 1;
437 }
wdenk4b9206e2004-03-23 22:14:11 +0000438 puts ("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000439 return 0;
440}
wdenk0d498392003-07-01 21:06:45 +0000441
442U_BOOT_CMD(
443 iminfo, CFG_MAXARGS, 1, do_iminfo,
wdenk8bde7f72003-06-27 21:31:46 +0000444 "iminfo - print header information for application image\n",
445 "addr [addr ...]\n"
446 " - print header information for application image starting at\n"
447 " address 'addr' in memory; this includes verification of the\n"
448 " image contents (magic number, header and payload checksums)\n"
449);
Jon Loeliger90253172007-07-10 11:02:44 -0500450#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000451
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100452
453/*******************************************************************/
454/* imls - list all images found in flash */
455/*******************************************************************/
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500456#if defined(CONFIG_CMD_IMLS)
wdenk27b207f2003-07-24 23:38:38 +0000457int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
458{
459 flash_info_t *info;
460 int i, j;
461 image_header_t *hdr;
wdenk27b207f2003-07-24 23:38:38 +0000462
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100463 for (i = 0, info = &flash_info[0];
464 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
465
wdenk27b207f2003-07-24 23:38:38 +0000466 if (info->flash_id == FLASH_UNKNOWN)
467 goto next_bank;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100468 for (j = 0; j < info->sector_count; ++j) {
wdenk27b207f2003-07-24 23:38:38 +0000469
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100470 hdr = (image_header_t *)info->start[j];
471
472 if (!hdr || !image_check_magic (hdr))
wdenk27b207f2003-07-24 23:38:38 +0000473 goto next_sector;
474
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100475 if (!image_check_hcrc (hdr))
wdenk27b207f2003-07-24 23:38:38 +0000476 goto next_sector;
477
478 printf ("Image at %08lX:\n", (ulong)hdr);
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100479 print_image_hdr (hdr);
wdenk5bb226e2003-11-17 21:14:37 +0000480
wdenk4b9206e2004-03-23 22:14:11 +0000481 puts (" Verifying Checksum ... ");
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100482 if (!image_check_dcrc (hdr)) {
483 puts ("Bad Data CRC\n");
484 } else {
485 puts ("OK\n");
wdenk5bb226e2003-11-17 21:14:37 +0000486 }
wdenkbdccc4f2003-08-05 17:43:17 +0000487next_sector: ;
wdenk27b207f2003-07-24 23:38:38 +0000488 }
wdenkbdccc4f2003-08-05 17:43:17 +0000489next_bank: ;
wdenk27b207f2003-07-24 23:38:38 +0000490 }
491
492 return (0);
493}
494
495U_BOOT_CMD(
496 imls, 1, 1, do_imls,
497 "imls - list all images found in flash\n",
498 "\n"
499 " - Prints information about all images found at sector\n"
500 " boundaries in flash.\n"
501);
Jon Loeliger90253172007-07-10 11:02:44 -0500502#endif
wdenk27b207f2003-07-24 23:38:38 +0000503
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100504/*******************************************************************/
505/* */
506/*******************************************************************/
507void print_image_hdr (image_header_t *hdr)
wdenk47d1a6e2002-11-03 00:01:44 +0000508{
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500509#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100510 time_t timestamp = (time_t)image_get_time (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000511 struct rtc_time tm;
512#endif
513
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100514 printf (" Image Name: %.*s\n", IH_NMLEN, image_get_name (hdr));
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100515
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500516#if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
wdenk47d1a6e2002-11-03 00:01:44 +0000517 to_tm (timestamp, &tm);
518 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
519 tm.tm_year, tm.tm_mon, tm.tm_mday,
520 tm.tm_hour, tm.tm_min, tm.tm_sec);
Jon Loeliger90253172007-07-10 11:02:44 -0500521#endif
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100522 puts (" Image Type: ");
523 print_type (hdr);
524
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100525 printf ("\n Data Size: %d Bytes = ", image_get_data_size (hdr));
526 print_size (image_get_data_size (hdr), "\n");
wdenk4b9206e2004-03-23 22:14:11 +0000527 printf (" Load Address: %08x\n"
528 " Entry Point: %08x\n",
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100529 image_get_load (hdr), image_get_ep (hdr));
wdenk47d1a6e2002-11-03 00:01:44 +0000530
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100531 if (image_check_type (hdr, IH_TYPE_MULTI)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000532 int i;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100533 ulong data, len;
534 ulong count = image_multi_count (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000535
wdenk4b9206e2004-03-23 22:14:11 +0000536 puts (" Contents:\n");
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100537 for (i = 0; i < count; i++) {
538 image_multi_getimg (hdr, i, &data, &len);
wdenk47d1a6e2002-11-03 00:01:44 +0000539 printf (" Image %d: %8ld Bytes = ", i, len);
540 print_size (len, "\n");
541 }
542 }
543}
544
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100545static void print_type (image_header_t *hdr)
wdenk47d1a6e2002-11-03 00:01:44 +0000546{
547 char *os, *arch, *type, *comp;
548
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100549 switch (image_get_os (hdr)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000550 case IH_OS_INVALID: os = "Invalid OS"; break;
551 case IH_OS_NETBSD: os = "NetBSD"; break;
552 case IH_OS_LINUX: os = "Linux"; break;
553 case IH_OS_VXWORKS: os = "VxWorks"; break;
554 case IH_OS_QNX: os = "QNX"; break;
555 case IH_OS_U_BOOT: os = "U-Boot"; break;
wdenkd791b1d2003-04-20 14:04:18 +0000556 case IH_OS_RTEMS: os = "RTEMS"; break;
wdenk7f70e852003-05-20 14:25:27 +0000557#ifdef CONFIG_ARTOS
558 case IH_OS_ARTOS: os = "ARTOS"; break;
559#endif
wdenk1f4bb372003-07-27 00:21:01 +0000560#ifdef CONFIG_LYNXKDI
561 case IH_OS_LYNXOS: os = "LynxOS"; break;
562#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000563 default: os = "Unknown OS"; break;
564 }
565
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100566 switch (image_get_arch (hdr)) {
567 case IH_ARCH_INVALID: arch = "Invalid CPU"; break;
568 case IH_ARCH_ALPHA: arch = "Alpha"; break;
569 case IH_ARCH_ARM: arch = "ARM"; break;
570 case IH_ARCH_AVR32: arch = "AVR32"; break;
571 case IH_ARCH_BLACKFIN: arch = "Blackfin"; break;
572 case IH_ARCH_I386: arch = "Intel x86"; break;
573 case IH_ARCH_IA64: arch = "IA64"; break;
574 case IH_ARCH_M68K: arch = "M68K"; break;
575 case IH_ARCH_MICROBLAZE:arch = "Microblaze"; break;
576 case IH_ARCH_MIPS64: arch = "MIPS 64 Bit"; break;
577 case IH_ARCH_MIPS: arch = "MIPS"; break;
578 case IH_ARCH_NIOS2: arch = "Nios-II"; break;
579 case IH_ARCH_NIOS: arch = "Nios"; break;
580 case IH_ARCH_PPC: arch = "PowerPC"; break;
581 case IH_ARCH_S390: arch = "IBM S390"; break;
582 case IH_ARCH_SH: arch = "SuperH"; break;
583 case IH_ARCH_SPARC64: arch = "SPARC 64 Bit"; break;
584 case IH_ARCH_SPARC: arch = "SPARC"; break;
wdenk47d1a6e2002-11-03 00:01:44 +0000585 default: arch = "Unknown Architecture"; break;
586 }
587
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100588 switch (image_get_type (hdr)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000589 case IH_TYPE_INVALID: type = "Invalid Image"; break;
590 case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
591 case IH_TYPE_KERNEL: type = "Kernel Image"; break;
592 case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
593 case IH_TYPE_MULTI: type = "Multi-File Image"; break;
594 case IH_TYPE_FIRMWARE: type = "Firmware"; break;
595 case IH_TYPE_SCRIPT: type = "Script"; break;
Matthew McClintock25c751e2006-08-16 10:54:09 -0500596 case IH_TYPE_FLATDT: type = "Flat Device Tree"; break;
wdenk47d1a6e2002-11-03 00:01:44 +0000597 default: type = "Unknown Image"; break;
598 }
599
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100600 switch (image_get_comp (hdr)) {
wdenk47d1a6e2002-11-03 00:01:44 +0000601 case IH_COMP_NONE: comp = "uncompressed"; break;
602 case IH_COMP_GZIP: comp = "gzip compressed"; break;
603 case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
604 default: comp = "unknown compression"; break;
605 }
606
607 printf ("%s %s %s (%s)", arch, os, type, comp);
608}
609
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100610#ifdef CONFIG_SILENT_CONSOLE
611static void fixup_silent_linux ()
612{
613 char buf[256], *start, *end;
614 char *cmdline = getenv ("bootargs");
615
616 /* Only fix cmdline when requested */
617 if (!(gd->flags & GD_FLG_SILENT))
618 return;
619
620 debug ("before silent fix-up: %s\n", cmdline);
621 if (cmdline) {
622 if ((start = strstr (cmdline, "console=")) != NULL) {
623 end = strchr (start, ' ');
624 strncpy (buf, cmdline, (start - cmdline + 8));
625 if (end)
626 strcpy (buf + (start - cmdline + 8), end);
627 else
628 buf[start - cmdline + 8] = '\0';
629 } else {
630 strcpy (buf, cmdline);
631 strcat (buf, " console=");
632 }
633 } else {
634 strcpy (buf, "console=");
635 }
636
637 setenv ("bootargs", buf);
638 debug ("after silent fix-up: %s\n", buf);
639}
640#endif /* CONFIG_SILENT_CONSOLE */
641
642
643/*******************************************************************/
644/* OS booting routines */
645/*******************************************************************/
646
647static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100648 int argc, char *argv[],
649 image_header_t *hdr, int verify)
wdenkd791b1d2003-04-20 14:04:18 +0000650{
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100651 void (*loader)(bd_t *, image_header_t *, char *, char *);
652 image_header_t *img_addr;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100653 ulong kernel_data, kernel_len;
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100654 char *consdev;
655 char *cmdline;
656
657 /*
658 * Booting a (NetBSD) kernel image
659 *
660 * This process is pretty similar to a standalone application:
661 * The (first part of an multi-) image must be a stage-2 loader,
662 * which in turn is responsible for loading & invoking the actual
663 * kernel. The only differences are the parameters being passed:
664 * besides the board info strucure, the loader expects a command
665 * line, the name of the console device, and (optionally) the
666 * address of the original image header.
667 */
668
669 img_addr = 0;
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100670 if (image_check_type (hdr, IH_TYPE_MULTI)) {
671 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
672 if (kernel_len)
673 img_addr = hdr;
674 }
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100675
676 consdev = "";
677#if defined (CONFIG_8xx_CONS_SMC1)
678 consdev = "smc1";
679#elif defined (CONFIG_8xx_CONS_SMC2)
680 consdev = "smc2";
681#elif defined (CONFIG_8xx_CONS_SCC2)
682 consdev = "scc2";
683#elif defined (CONFIG_8xx_CONS_SCC3)
684 consdev = "scc3";
685#endif
686
687 if (argc > 2) {
688 ulong len;
689 int i;
690
691 for (i = 2, len = 0; i < argc; i += 1)
692 len += strlen (argv[i]) + 1;
693 cmdline = malloc (len);
694
695 for (i = 2, len = 0; i < argc; i += 1) {
696 if (i > 2)
697 cmdline[len++] = ' ';
698 strcpy (&cmdline[len], argv[i]);
699 len += strlen (argv[i]);
700 }
701 } else if ((cmdline = getenv ("bootargs")) == NULL) {
702 cmdline = "";
703 }
704
705 loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
706
707 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
708 (ulong)loader);
709
710 show_boot_progress (15);
711
712 /*
713 * NetBSD Stage-2 Loader Parameters:
714 * r3: ptr to board info data
715 * r4: image address
716 * r5: console device
717 * r6: boot args string
718 */
719 (*loader) (gd->bd, img_addr, consdev, cmdline);
720}
721
722#ifdef CONFIG_LYNXKDI
723static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
724 int argc, char *argv[],
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100725 image_header_t *hdr, int verify)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100726{
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100727 lynxkdi_boot (hdr);
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100728}
729#endif /* CONFIG_LYNXKDI */
730
731static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
732 int argc, char *argv[],
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100733 image_header_t *hdr, int verify)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100734{
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100735 void (*entry_point)(bd_t *);
wdenkd791b1d2003-04-20 14:04:18 +0000736
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100737 entry_point = (void (*)(bd_t *))image_get_ep (hdr);
wdenkd791b1d2003-04-20 14:04:18 +0000738
739 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
740 (ulong)entry_point);
741
Heiko Schocherfad63402007-07-13 09:54:17 +0200742 show_boot_progress (15);
wdenkd791b1d2003-04-20 14:04:18 +0000743
744 /*
745 * RTEMS Parameters:
746 * r3: ptr to board info data
747 */
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100748 (*entry_point)(gd->bd);
wdenkd791b1d2003-04-20 14:04:18 +0000749}
750
Jon Loeligerbaa26db2007-07-08 17:51:39 -0500751#if defined(CONFIG_CMD_ELF)
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100752static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
753 int argc, char *argv[],
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100754 image_header_t *hdr, int verify)
wdenk47d1a6e2002-11-03 00:01:44 +0000755{
wdenk47d1a6e2002-11-03 00:01:44 +0000756 char str[80];
757
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100758 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +0000759 setenv("loadaddr", str);
760 do_bootvx(cmdtp, 0, 0, NULL);
761}
762
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100763static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
764 int argc, char *argv[],
765 image_header_t *hdr, int verify)
wdenk47d1a6e2002-11-03 00:01:44 +0000766{
wdenk47d1a6e2002-11-03 00:01:44 +0000767 char *local_args[2];
768 char str[16];
769
Marian Balakowiczb97a2a02008-01-08 18:14:09 +0100770 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +0000771 local_args[0] = argv[0];
772 local_args[1] = str; /* and provide it via the arguments */
773 do_bootelf(cmdtp, 0, 2, local_args);
774}
Jon Loeliger90253172007-07-10 11:02:44 -0500775#endif
wdenk1f4bb372003-07-27 00:21:01 +0000776
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100777#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
778static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
779 int argc, char *argv[],
Marian Balakowiczf13e7b22008-01-08 18:12:17 +0100780 image_header_t *hdr, int verify)
wdenk1f4bb372003-07-27 00:21:01 +0000781{
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100782 ulong top;
783 char *s, *cmdline;
784 char **fwenv, **ss;
785 int i, j, nxt, len, envno, envsz;
786 bd_t *kbd;
787 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
wdenk1f4bb372003-07-27 00:21:01 +0000788
Marian Balakowicz1ee11802008-01-08 18:17:10 +0100789 /*
790 * Booting an ARTOS kernel image + application
791 */
792
793 /* this used to be the top of memory, but was wrong... */
794#ifdef CONFIG_PPC
795 /* get stack pointer */
796 asm volatile ("mr %0,1" : "=r"(top) );
797#endif
798 debug ("## Current stack ends at 0x%08lX ", top);
799
800 top -= 2048; /* just to be sure */
801 if (top > CFG_BOOTMAPSZ)
802 top = CFG_BOOTMAPSZ;
803 top &= ~0xF;
804
805 debug ("=> set upper limit to 0x%08lX\n", top);
806
807 /* first check the artos specific boot args, then the linux args*/
808 if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
809 s = "";
810
811 /* get length of cmdline, and place it */
812 len = strlen (s);
813 top = (top - (len + 1)) & ~0xF;
814 cmdline = (char *)top;
815 debug ("## cmdline at 0x%08lX ", top);
816 strcpy (cmdline, s);
817
818 /* copy bdinfo */
819 top = (top - sizeof (bd_t)) & ~0xF;
820 debug ("## bd at 0x%08lX ", top);
821 kbd = (bd_t *)top;
822 memcpy (kbd, gd->bd, sizeof (bd_t));
823
824 /* first find number of env entries, and their size */
825 envno = 0;
826 envsz = 0;
827 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
828 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
829 ;
830 envno++;
831 envsz += (nxt - i) + 1; /* plus trailing zero */
832 }
833 envno++; /* plus the terminating zero */
834 debug ("## %u envvars total size %u ", envno, envsz);
835
836 top = (top - sizeof (char **) * envno) & ~0xF;
837 fwenv = (char **)top;
838 debug ("## fwenv at 0x%08lX ", top);
839
840 top = (top - envsz) & ~0xF;
841 s = (char *)top;
842 ss = fwenv;
843
844 /* now copy them */
845 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
846 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
847 ;
848 *ss++ = s;
849 for (j = i; j < nxt; ++j)
850 *s++ = env_get_char (j);
851 *s++ = '\0';
852 }
853 *ss++ = NULL; /* terminate */
854
855 entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
856 (*entry) (kbd, cmdline, fwenv, top);
857}
858#endif