blob: daee7bf22ad75c69965b82a7f234b352c1a317ae [file] [log] [blame]
wdenk47d1a6e2002-11-03 00:01:44 +00001/*
Stefan Roese5d5ce292006-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 Balakowicz41d71ed2008-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>
wdenk710e3502003-08-29 20:57:53 +000035#include <bzlib.h>
wdenk0893c472003-05-20 14:25:27 +000036#include <environment.h>
Kumar Gala6d7bfa82008-02-27 21:51:47 -060037#include <lmb.h>
wdenk47d1a6e2002-11-03 00:01:44 +000038#include <asm/byteorder.h>
wdenk57b2d802003-06-27 21:31:46 +000039
wdenk47d1a6e2002-11-03 00:01:44 +000040#ifdef CFG_HUSH_PARSER
41#include <hush.h>
42#endif
43
Marian Balakowicz2df645e2008-01-08 18:17:10 +010044DECLARE_GLOBAL_DATA_PTR;
45
46extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
47#ifndef CFG_BOOTM_LEN
48#define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
49#endif
wdenk47d1a6e2002-11-03 00:01:44 +000050
Marian Balakowiczbe946ba2008-01-08 18:11:43 +010051#ifdef CONFIG_BZIP2
52extern void bz_internal_error(int);
53#endif
wdenk47d1a6e2002-11-03 00:01:44 +000054
Jon Loeliger54324d02007-07-08 17:51:39 -050055#if defined(CONFIG_CMD_IMI)
wdenk47d1a6e2002-11-03 00:01:44 +000056static int image_info (unsigned long addr);
57#endif
wdenk874ac262003-07-24 23:38:38 +000058
Jon Loeliger54324d02007-07-08 17:51:39 -050059#if defined(CONFIG_CMD_IMLS)
wdenk874ac262003-07-24 23:38:38 +000060#include <flash.h>
Marian Balakowicz513b4a12005-10-11 19:09:42 +020061extern flash_info_t flash_info[]; /* info for FLASH chips */
wdenk874ac262003-07-24 23:38:38 +000062static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
63#endif
64
Marian Balakowicz2df645e2008-01-08 18:17:10 +010065#ifdef CONFIG_SILENT_CONSOLE
66static void fixup_silent_linux (void);
67#endif
68
Marian Balakowiczd7c88a42008-02-29 14:58:34 +010069static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +010070 bootm_headers_t *images, ulong *os_data, ulong *os_len);
Marian Balakowicz2df645e2008-01-08 18:17:10 +010071extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
wdenk47d1a6e2002-11-03 00:01:44 +000072
73/*
74 * Continue booting an OS image; caller already has:
75 * - copied image header to global variable `header'
76 * - checked header magic number, checksums (both header & image),
77 * - verified image architecture (PPC) and type (KERNEL or MULTI),
78 * - loaded (first part of) image to header load address,
79 * - disabled interrupts.
80 */
Marian Balakowicz2df645e2008-01-08 18:17:10 +010081typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag,
Marian Balakowiczb4a12a92008-01-08 18:12:17 +010082 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +010083 bootm_headers_t *images); /* pointers to os/initrd/fdt */
Marian Balakowicz2437cf22008-01-08 18:11:43 +010084
Marian Balakowicz2df645e2008-01-08 18:17:10 +010085extern boot_os_fn do_bootm_linux;
86static boot_os_fn do_bootm_netbsd;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +010087#if defined(CONFIG_LYNXKDI)
Marian Balakowicz2df645e2008-01-08 18:17:10 +010088static boot_os_fn do_bootm_lynxkdi;
89extern void lynxkdi_boot (image_header_t *);
wdenk808532a2003-10-10 10:05:42 +000090#endif
Marian Balakowicz2df645e2008-01-08 18:17:10 +010091static boot_os_fn do_bootm_rtems;
Jon Loeliger54324d02007-07-08 17:51:39 -050092#if defined(CONFIG_CMD_ELF)
Marian Balakowicz2df645e2008-01-08 18:17:10 +010093static boot_os_fn do_bootm_vxworks;
94static boot_os_fn do_bootm_qnxelf;
95int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
96int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
Jon Loeligerd704d912007-07-10 11:02:44 -050097#endif
wdenk0893c472003-05-20 14:25:27 +000098#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
Marian Balakowicz2df645e2008-01-08 18:17:10 +010099extern uchar (*env_get_char)(int); /* Returns a character from the environment */
100static boot_os_fn do_bootm_artos;
Stefan Roese5d5ce292006-03-13 11:16:36 +0100101#endif
102
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100103ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100104static bootm_headers_t images; /* pointers to os/initrd/fdt images */
wdenk47d1a6e2002-11-03 00:01:44 +0000105
Kumar Galab937bb72008-02-27 21:51:49 -0600106void __board_lmb_reserve(struct lmb *lmb)
107{
108 /* please define platform specific board_lmb_reserve() */
109}
110void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
111
Marian Balakowicz2df645e2008-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 Balakowiczb4a12a92008-01-08 18:12:17 +0100118 ulong iflag;
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100119 const char *type_name;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100120 uint unc_len = CFG_BOOTM_LEN;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100121 uint8_t comp, type, os;
wdenk47d1a6e2002-11-03 00:01:44 +0000122
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100123 void *os_hdr;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100124 ulong os_data, os_len;
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100125 ulong image_start, image_end;
126 ulong load_start, load_end;
Kumar Galac5bacfd2008-02-27 21:51:50 -0600127 ulong mem_start, mem_size;
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100128
Kumar Gala6d7bfa82008-02-27 21:51:47 -0600129 struct lmb lmb;
130
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100131 memset ((void *)&images, 0, sizeof (images));
Marian Balakowicz61fde552008-02-27 11:01:04 +0100132 images.verify = getenv_verify();
Kumar Galafb71ccf2008-02-27 21:51:48 -0600133 images.autostart = getenv_autostart();
Kumar Gala6d7bfa82008-02-27 21:51:47 -0600134 images.lmb = &lmb;
135
136 lmb_init(&lmb);
137
Kumar Galac5bacfd2008-02-27 21:51:50 -0600138 mem_start = getenv_bootm_low();
139 mem_size = getenv_bootm_size();
140
141 lmb_add(&lmb, mem_start, mem_size);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100142
Kumar Galab937bb72008-02-27 21:51:49 -0600143 board_lmb_reserve(&lmb);
144
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100145 /* get kernel image header, start address and length */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100146 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100147 &images, &os_data, &os_len);
148 if (os_len == 0)
wdenk47d1a6e2002-11-03 00:01:44 +0000149 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000150
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200151 show_boot_progress (6);
wdenk47d1a6e2002-11-03 00:01:44 +0000152
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100153 /* get image parameters */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100154 switch (genimg_get_format (os_hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100155 case IMAGE_FORMAT_LEGACY:
156 type = image_get_type (os_hdr);
157 comp = image_get_comp (os_hdr);
158 os = image_get_os (os_hdr);
159
160 image_end = image_get_image_end (os_hdr);
161 load_start = image_get_load (os_hdr);
162 break;
163#if defined(CONFIG_FIT)
164 case IMAGE_FORMAT_FIT:
165 fit_unsupported ("bootm");
166 return 1;
167#endif
168 default:
169 puts ("ERROR: unknown image format type!\n");
170 return 1;
171 }
172
173 image_start = (ulong)os_hdr;
174 load_end = 0;
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100175 type_name = genimg_get_type_name (type);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100176
wdenk47d1a6e2002-11-03 00:01:44 +0000177 /*
178 * We have reached the point of no return: we are going to
179 * overwrite all exception vector code, so we cannot easily
180 * recover from any failures any more...
181 */
wdenk47d1a6e2002-11-03 00:01:44 +0000182 iflag = disable_interrupts();
183
wdenk452cfd62002-11-19 11:04:11 +0000184#ifdef CONFIG_AMIGAONEG3SE
185 /*
wdenk57b2d802003-06-27 21:31:46 +0000186 * We've possible left the caches enabled during
wdenk452cfd62002-11-19 11:04:11 +0000187 * bios emulation, so turn them off again
188 */
189 icache_disable();
190 invalidate_l1_instruction_cache();
191 flush_data_cache();
192 dcache_disable();
193#endif
194
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100195 switch (comp) {
wdenk47d1a6e2002-11-03 00:01:44 +0000196 case IH_COMP_NONE:
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100197 if (load_start == (ulong)os_hdr) {
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100198 printf (" XIP %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000199 } else {
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100200 printf (" Loading %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000201
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100202 memmove_wd ((void *)load_start,
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100203 (void *)os_data, os_len, CHUNKSZ);
Marian Balakowiczf9a67bd2008-01-08 18:11:45 +0100204
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100205 load_end = load_start + os_len;
Marian Balakowiczf9a67bd2008-01-08 18:11:45 +0100206 puts("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000207 }
208 break;
209 case IH_COMP_GZIP:
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100210 printf (" Uncompressing %s ... ", type_name);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100211 if (gunzip ((void *)load_start, unc_len,
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100212 (uchar *)os_data, &os_len) != 0) {
wdenk42c05472004-03-23 22:14:11 +0000213 puts ("GUNZIP ERROR - must RESET board to recover\n");
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200214 show_boot_progress (-6);
wdenk47d1a6e2002-11-03 00:01:44 +0000215 do_reset (cmdtp, flag, argc, argv);
216 }
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100217
218 load_end = load_start + os_len;
wdenk47d1a6e2002-11-03 00:01:44 +0000219 break;
wdenk710e3502003-08-29 20:57:53 +0000220#ifdef CONFIG_BZIP2
221 case IH_COMP_BZIP2:
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100222 printf (" Uncompressing %s ... ", type_name);
wdenk2cefd152004-02-08 22:55:38 +0000223 /*
224 * If we've got less than 4 MB of malloc() space,
225 * use slower decompression algorithm which requires
226 * at most 2300 KB of memory.
227 */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100228 int i = BZ2_bzBuffToBuffDecompress ((char*)load_start,
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100229 &unc_len, (char *)os_data, os_len,
230 CFG_MALLOC_LEN < (4096 * 1024), 0);
wdenk710e3502003-08-29 20:57:53 +0000231 if (i != BZ_OK) {
232 printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200233 show_boot_progress (-6);
wdenk710e3502003-08-29 20:57:53 +0000234 do_reset (cmdtp, flag, argc, argv);
235 }
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100236
237 load_end = load_start + unc_len;
wdenk710e3502003-08-29 20:57:53 +0000238 break;
239#endif /* CONFIG_BZIP2 */
wdenk47d1a6e2002-11-03 00:01:44 +0000240 default:
241 if (iflag)
242 enable_interrupts();
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100243 printf ("Unimplemented compression type %d\n", comp);
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200244 show_boot_progress (-7);
wdenk47d1a6e2002-11-03 00:01:44 +0000245 return 1;
246 }
wdenk42c05472004-03-23 22:14:11 +0000247 puts ("OK\n");
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100248 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end);
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200249 show_boot_progress (7);
wdenk47d1a6e2002-11-03 00:01:44 +0000250
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100251 if ((load_start < image_end) && (load_end > image_start)) {
252 debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end);
253 debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end);
254
255 puts ("ERROR: image overwritten - must RESET the board to recover.\n");
256 do_reset (cmdtp, flag, argc, argv);
257 }
258
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200259 show_boot_progress (8);
wdenk47d1a6e2002-11-03 00:01:44 +0000260
Kumar Gala6d7bfa82008-02-27 21:51:47 -0600261 lmb_reserve(&lmb, load_start, (load_end - load_start));
262
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100263 switch (os) {
wdenk47d1a6e2002-11-03 00:01:44 +0000264 default: /* handled by (original) Linux case */
265 case IH_OS_LINUX:
wdenk808532a2003-10-10 10:05:42 +0000266#ifdef CONFIG_SILENT_CONSOLE
267 fixup_silent_linux();
268#endif
Marian Balakowicz61fde552008-02-27 11:01:04 +0100269 do_bootm_linux (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000270 break;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100271
wdenk47d1a6e2002-11-03 00:01:44 +0000272 case IH_OS_NETBSD:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100273 do_bootm_netbsd (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000274 break;
wdenke58b0dc2003-07-27 00:21:01 +0000275
276#ifdef CONFIG_LYNXKDI
277 case IH_OS_LYNXOS:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100278 do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images);
wdenke58b0dc2003-07-27 00:21:01 +0000279 break;
280#endif
wdenk57b2d802003-06-27 21:31:46 +0000281
wdenk92bbe3f2003-04-20 14:04:18 +0000282 case IH_OS_RTEMS:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100283 do_bootm_rtems (cmdtp, flag, argc, argv, &images);
wdenk92bbe3f2003-04-20 14:04:18 +0000284 break;
wdenk57b2d802003-06-27 21:31:46 +0000285
Jon Loeliger54324d02007-07-08 17:51:39 -0500286#if defined(CONFIG_CMD_ELF)
wdenk47d1a6e2002-11-03 00:01:44 +0000287 case IH_OS_VXWORKS:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100288 do_bootm_vxworks (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000289 break;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100290
wdenk47d1a6e2002-11-03 00:01:44 +0000291 case IH_OS_QNX:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100292 do_bootm_qnxelf (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000293 break;
Jon Loeligerd704d912007-07-10 11:02:44 -0500294#endif
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100295
wdenk0893c472003-05-20 14:25:27 +0000296#ifdef CONFIG_ARTOS
297 case IH_OS_ARTOS:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100298 do_bootm_artos (cmdtp, flag, argc, argv, &images);
wdenk0893c472003-05-20 14:25:27 +0000299 break;
300#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000301 }
302
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200303 show_boot_progress (-9);
wdenk47d1a6e2002-11-03 00:01:44 +0000304#ifdef DEBUG
wdenk42c05472004-03-23 22:14:11 +0000305 puts ("\n## Control returned to monitor - resetting...\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000306 do_reset (cmdtp, flag, argc, argv);
307#endif
308 return 1;
309}
310
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100311/**
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100312 * image_get_kernel - verify legacy format kernel image
313 * @img_addr: in RAM address of the legacy format image to be verified
314 * @verify: data CRC verification flag
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100315 *
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100316 * image_get_kernel() verifies legacy image integrity and returns pointer to
317 * legacy image header if image verification was completed successfully.
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100318 *
319 * returns:
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100320 * pointer to a legacy image header if valid image was found
321 * otherwise return NULL
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100322 */
Marian Balakowicz59504f62008-02-27 11:02:07 +0100323static image_header_t *image_get_kernel (ulong img_addr, int verify)
324{
325 image_header_t *hdr = (image_header_t *)img_addr;
326
327 if (!image_check_magic(hdr)) {
328 puts ("Bad Magic Number\n");
329 show_boot_progress (-1);
330 return NULL;
331 }
332 show_boot_progress (2);
333
334 if (!image_check_hcrc (hdr)) {
335 puts ("Bad Header Checksum\n");
336 show_boot_progress (-2);
337 return NULL;
338 }
339
340 show_boot_progress (3);
341 image_print_contents (hdr);
342
343 if (verify) {
344 puts (" Verifying Checksum ... ");
345 if (!image_check_dcrc (hdr)) {
346 printf ("Bad Data CRC\n");
347 show_boot_progress (-3);
348 return NULL;
349 }
350 puts ("OK\n");
351 }
352 show_boot_progress (4);
353
354 if (!image_check_target_arch (hdr)) {
355 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
356 show_boot_progress (-4);
357 return NULL;
358 }
359 return hdr;
360}
361
362/**
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100363 * boot_get_kernel - find kernel image
Marian Balakowicz59504f62008-02-27 11:02:07 +0100364 * @os_data: pointer to a ulong variable, will hold os data start address
365 * @os_len: pointer to a ulong variable, will hold os data length
366 *
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100367 * boot_get_kernel() tries to find a kernel image, verifies its integrity
Marian Balakowicz59504f62008-02-27 11:02:07 +0100368 * and locates kernel data.
369 *
370 * returns:
371 * pointer to image header if valid image was found, plus kernel start
372 * address and length, otherwise NULL
373 */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100374static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100375 bootm_headers_t *images, ulong *os_data, ulong *os_len)
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100376{
377 image_header_t *hdr;
378 ulong img_addr;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100379#if defined(CONFIG_FIT)
380 void *fit_hdr;
381 const char *fit_uname_config = NULL;
382 const char *fit_uname_kernel = NULL;
383#endif
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100384
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100385 /* find out kernel image address */
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100386 if (argc < 2) {
387 img_addr = load_addr;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100388 debug ("* kernel: default image load address = 0x%08lx\n",
389 load_addr);
390#if defined(CONFIG_FIT)
391 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
392 &fit_uname_config)) {
393 debug ("* kernel: config '%s' from image at 0x%08lx\n",
394 fit_uname_config, img_addr);
395 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
396 &fit_uname_kernel)) {
397 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
398 fit_uname_kernel, img_addr);
399#endif
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100400 } else {
401 img_addr = simple_strtoul(argv[1], NULL, 16);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100402 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100403 }
404
405 show_boot_progress (1);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100406 printf ("## Booting kernel image at %08lx ...\n", img_addr);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100407
Marian Balakowiczc536d6f2008-02-21 17:20:19 +0100408 /* copy from dataflash if needed */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100409 img_addr = genimg_get_image (img_addr);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100410
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100411 /* check image type, for FIT images get FIT kernel node */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100412 switch (genimg_get_format ((void *)img_addr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100413 case IMAGE_FORMAT_LEGACY:
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100414
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100415 debug ("* kernel: legacy format image\n");
Marian Balakowicz59504f62008-02-27 11:02:07 +0100416 hdr = image_get_kernel (img_addr, images->verify);
417 if (!hdr)
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100418 return NULL;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100419 show_boot_progress (5);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100420
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100421 switch (image_get_type (hdr)) {
422 case IH_TYPE_KERNEL:
423 *os_data = image_get_data (hdr);
424 *os_len = image_get_data_size (hdr);
425 break;
426 case IH_TYPE_MULTI:
427 image_multi_getimg (hdr, 0, os_data, os_len);
428 break;
429 default:
430 printf ("Wrong Image Type for %s command\n", cmdtp->name);
431 show_boot_progress (-5);
432 return NULL;
433 }
434 images->legacy_hdr_os = hdr;
435 images->legacy_hdr_valid = 1;
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100436
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100437 break;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100438#if defined(CONFIG_FIT)
439 case IMAGE_FORMAT_FIT:
440 fit_hdr = (void *)img_addr;
441 debug ("* kernel: FIT format image\n");
442 fit_unsupported ("kernel");
443 return NULL;
444#endif
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100445 default:
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100446 printf ("Wrong Image Format for %s command\n", cmdtp->name);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100447 return NULL;
448 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100449
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100450 debug (" kernel data at 0x%08lx, end = 0x%08lx\n",
451 *os_data, *os_data + *os_len);
452
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100453 return (void *)img_addr;
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100454}
455
wdenkf287a242003-07-01 21:06:45 +0000456U_BOOT_CMD(
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100457 bootm, CFG_MAXARGS, 1, do_bootm,
458 "bootm - boot application image from memory\n",
459 "[addr [arg ...]]\n - boot application image stored in memory\n"
460 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
461 "\t'arg' can be the address of an initrd image\n"
Marian Balakowiczd2160852008-01-31 13:20:07 +0100462#if defined(CONFIG_OF_LIBFDT)
Matthew McClintock6fb7c812006-06-28 10:41:37 -0500463 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
Detlev Zundele6099162007-10-19 16:47:26 +0200464 "\ta third argument is required which is the address of the\n"
Matthew McClintock6fb7c812006-06-28 10:41:37 -0500465 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
466 "\tuse a '-' for the second argument. If you do not pass a third\n"
467 "\ta bd_info struct will be passed instead\n"
468#endif
wdenk57b2d802003-06-27 21:31:46 +0000469);
470
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100471/*******************************************************************/
472/* bootd - boot default image */
473/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -0500474#if defined(CONFIG_CMD_BOOTD)
wdenk47d1a6e2002-11-03 00:01:44 +0000475int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
476{
477 int rcode = 0;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100478
wdenk47d1a6e2002-11-03 00:01:44 +0000479#ifndef CFG_HUSH_PARSER
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100480 if (run_command (getenv ("bootcmd"), flag) < 0)
481 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000482#else
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100483 if (parse_string_outer (getenv ("bootcmd"),
484 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
485 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000486#endif
487 return rcode;
488}
wdenk57b2d802003-06-27 21:31:46 +0000489
wdenkf287a242003-07-01 21:06:45 +0000490U_BOOT_CMD(
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100491 boot, 1, 1, do_bootd,
492 "boot - boot default, i.e., run 'bootcmd'\n",
wdenk3086a972003-06-28 23:11:04 +0000493 NULL
494);
495
496/* keep old command name "bootd" for backward compatibility */
wdenkf287a242003-07-01 21:06:45 +0000497U_BOOT_CMD(
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100498 bootd, 1, 1, do_bootd,
499 "bootd - boot default, i.e., run 'bootcmd'\n",
wdenk57b2d802003-06-27 21:31:46 +0000500 NULL
501);
502
wdenk47d1a6e2002-11-03 00:01:44 +0000503#endif
504
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100505
506/*******************************************************************/
507/* iminfo - print header info for a requested image */
508/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -0500509#if defined(CONFIG_CMD_IMI)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100510int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000511{
512 int arg;
513 ulong addr;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100514 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000515
516 if (argc < 2) {
517 return image_info (load_addr);
518 }
519
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100520 for (arg = 1; arg < argc; ++arg) {
521 addr = simple_strtoul (argv[arg], NULL, 16);
522 if (image_info (addr) != 0)
523 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000524 }
525 return rcode;
526}
527
528static int image_info (ulong addr)
529{
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100530 void *hdr = (void *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +0000531
532 printf ("\n## Checking Image at %08lx ...\n", addr);
533
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100534 switch (genimg_get_format (hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100535 case IMAGE_FORMAT_LEGACY:
536 puts (" Legacy image found\n");
537 if (!image_check_magic (hdr)) {
538 puts (" Bad Magic Number\n");
539 return 1;
540 }
wdenk47d1a6e2002-11-03 00:01:44 +0000541
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100542 if (!image_check_hcrc (hdr)) {
543 puts (" Bad Header Checksum\n");
544 return 1;
545 }
wdenk47d1a6e2002-11-03 00:01:44 +0000546
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100547 image_print_contents (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000548
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100549 puts (" Verifying Checksum ... ");
550 if (!image_check_dcrc (hdr)) {
551 puts (" Bad Data CRC\n");
552 return 1;
553 }
554 puts ("OK\n");
555 return 0;
556#if defined(CONFIG_FIT)
557 case IMAGE_FORMAT_FIT:
558 puts (" FIT image found\n");
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100559
560 if (!fit_check_format (hdr)) {
561 puts ("Bad FIT image format!\n");
562 return 1;
563 }
564
565 fit_print_contents (hdr);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100566 return 0;
567#endif
568 default:
569 puts ("Unknown image format!\n");
570 break;
wdenk47d1a6e2002-11-03 00:01:44 +0000571 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100572
573 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000574}
wdenkf287a242003-07-01 21:06:45 +0000575
576U_BOOT_CMD(
577 iminfo, CFG_MAXARGS, 1, do_iminfo,
wdenk57b2d802003-06-27 21:31:46 +0000578 "iminfo - print header information for application image\n",
579 "addr [addr ...]\n"
580 " - print header information for application image starting at\n"
581 " address 'addr' in memory; this includes verification of the\n"
582 " image contents (magic number, header and payload checksums)\n"
583);
Jon Loeligerd704d912007-07-10 11:02:44 -0500584#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000585
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100586
587/*******************************************************************/
588/* imls - list all images found in flash */
589/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -0500590#if defined(CONFIG_CMD_IMLS)
wdenk874ac262003-07-24 23:38:38 +0000591int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
592{
593 flash_info_t *info;
594 int i, j;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100595 void *hdr;
wdenk874ac262003-07-24 23:38:38 +0000596
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100597 for (i = 0, info = &flash_info[0];
598 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
599
wdenk874ac262003-07-24 23:38:38 +0000600 if (info->flash_id == FLASH_UNKNOWN)
601 goto next_bank;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100602 for (j = 0; j < info->sector_count; ++j) {
wdenk874ac262003-07-24 23:38:38 +0000603
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100604 hdr = (void *)info->start[j];
605 if (!hdr)
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100606 goto next_sector;
wdenk874ac262003-07-24 23:38:38 +0000607
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100608 switch (genimg_get_format (hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100609 case IMAGE_FORMAT_LEGACY:
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100610 if (!image_check_hcrc (hdr))
611 goto next_sector;
wdenkc6abb7e2003-11-17 21:14:37 +0000612
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100613 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
614 image_print_contents (hdr);
615
616 puts (" Verifying Checksum ... ");
617 if (!image_check_dcrc (hdr)) {
618 puts ("Bad Data CRC\n");
619 } else {
620 puts ("OK\n");
621 }
622 break;
623#if defined(CONFIG_FIT)
624 case IMAGE_FORMAT_FIT:
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100625 if (!fit_check_format (hdr))
626 goto next_sector;
627
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100628 printf ("FIT Image at %08lX:\n", (ulong)hdr);
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100629 fit_print_contents (hdr);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100630 break;
631#endif
632 default:
633 goto next_sector;
wdenkc6abb7e2003-11-17 21:14:37 +0000634 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100635
wdenk0a658552003-08-05 17:43:17 +0000636next_sector: ;
wdenk874ac262003-07-24 23:38:38 +0000637 }
wdenk0a658552003-08-05 17:43:17 +0000638next_bank: ;
wdenk874ac262003-07-24 23:38:38 +0000639 }
640
641 return (0);
642}
643
644U_BOOT_CMD(
645 imls, 1, 1, do_imls,
646 "imls - list all images found in flash\n",
647 "\n"
648 " - Prints information about all images found at sector\n"
649 " boundaries in flash.\n"
650);
Jon Loeligerd704d912007-07-10 11:02:44 -0500651#endif
wdenk874ac262003-07-24 23:38:38 +0000652
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100653/*******************************************************************/
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100654/* helper routines */
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100655/*******************************************************************/
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100656#ifdef CONFIG_SILENT_CONSOLE
657static void fixup_silent_linux ()
658{
659 char buf[256], *start, *end;
660 char *cmdline = getenv ("bootargs");
661
662 /* Only fix cmdline when requested */
663 if (!(gd->flags & GD_FLG_SILENT))
664 return;
665
666 debug ("before silent fix-up: %s\n", cmdline);
667 if (cmdline) {
668 if ((start = strstr (cmdline, "console=")) != NULL) {
669 end = strchr (start, ' ');
670 strncpy (buf, cmdline, (start - cmdline + 8));
671 if (end)
672 strcpy (buf + (start - cmdline + 8), end);
673 else
674 buf[start - cmdline + 8] = '\0';
675 } else {
676 strcpy (buf, cmdline);
677 strcat (buf, " console=");
678 }
679 } else {
680 strcpy (buf, "console=");
681 }
682
683 setenv ("bootargs", buf);
684 debug ("after silent fix-up: %s\n", buf);
685}
686#endif /* CONFIG_SILENT_CONSOLE */
687
688
689/*******************************************************************/
690/* OS booting routines */
691/*******************************************************************/
692
693static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100694 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100695 bootm_headers_t *images)
wdenk92bbe3f2003-04-20 14:04:18 +0000696{
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100697 void (*loader)(bd_t *, image_header_t *, char *, char *);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100698 image_header_t *os_hdr, *hdr;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100699 ulong kernel_data, kernel_len;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100700 char *consdev;
701 char *cmdline;
702
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100703#if defined(CONFIG_FIT)
704 if (!images->legacy_hdr_valid) {
705 fit_unsupported_reset ("NetBSD");
706 do_reset (cmdtp, flag, argc, argv);
707 }
708#endif
709 hdr = images->legacy_hdr_os;
710
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100711 /*
712 * Booting a (NetBSD) kernel image
713 *
714 * This process is pretty similar to a standalone application:
715 * The (first part of an multi-) image must be a stage-2 loader,
716 * which in turn is responsible for loading & invoking the actual
717 * kernel. The only differences are the parameters being passed:
718 * besides the board info strucure, the loader expects a command
719 * line, the name of the console device, and (optionally) the
720 * address of the original image header.
721 */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100722 os_hdr = NULL;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100723 if (image_check_type (hdr, IH_TYPE_MULTI)) {
724 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
725 if (kernel_len)
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100726 os_hdr = hdr;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100727 }
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100728
729 consdev = "";
730#if defined (CONFIG_8xx_CONS_SMC1)
731 consdev = "smc1";
732#elif defined (CONFIG_8xx_CONS_SMC2)
733 consdev = "smc2";
734#elif defined (CONFIG_8xx_CONS_SCC2)
735 consdev = "scc2";
736#elif defined (CONFIG_8xx_CONS_SCC3)
737 consdev = "scc3";
738#endif
739
740 if (argc > 2) {
741 ulong len;
742 int i;
743
744 for (i = 2, len = 0; i < argc; i += 1)
745 len += strlen (argv[i]) + 1;
746 cmdline = malloc (len);
747
748 for (i = 2, len = 0; i < argc; i += 1) {
749 if (i > 2)
750 cmdline[len++] = ' ';
751 strcpy (&cmdline[len], argv[i]);
752 len += strlen (argv[i]);
753 }
754 } else if ((cmdline = getenv ("bootargs")) == NULL) {
755 cmdline = "";
756 }
757
758 loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
759
760 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
761 (ulong)loader);
762
763 show_boot_progress (15);
764
765 /*
766 * NetBSD Stage-2 Loader Parameters:
767 * r3: ptr to board info data
768 * r4: image address
769 * r5: console device
770 * r6: boot args string
771 */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100772 (*loader) (gd->bd, os_hdr, consdev, cmdline);
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100773}
774
775#ifdef CONFIG_LYNXKDI
776static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
777 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100778 bootm_headers_t *images)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100779{
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100780 image_header_t *hdr = images->legacy_hdr_os;
781
782#if defined(CONFIG_FIT)
783 if (!images->legacy_hdr_valid) {
784 fit_unsupported_reset ("Lynx");
785 do_reset (cmdtp, flag, argc, argv);
786 }
787#endif
788
789 lynxkdi_boot ((image_header_t *)hdr);
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100790}
791#endif /* CONFIG_LYNXKDI */
792
793static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
794 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100795 bootm_headers_t *images)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100796{
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100797 image_header_t *hdr = images->legacy_hdr_os;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100798 void (*entry_point)(bd_t *);
wdenk92bbe3f2003-04-20 14:04:18 +0000799
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100800#if defined(CONFIG_FIT)
801 if (!images->legacy_hdr_valid) {
802 fit_unsupported_reset ("RTEMS");
803 do_reset (cmdtp, flag, argc, argv);
804 }
805#endif
806
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100807 entry_point = (void (*)(bd_t *))image_get_ep (hdr);
wdenk92bbe3f2003-04-20 14:04:18 +0000808
809 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
810 (ulong)entry_point);
811
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200812 show_boot_progress (15);
wdenk92bbe3f2003-04-20 14:04:18 +0000813
814 /*
815 * RTEMS Parameters:
816 * r3: ptr to board info data
817 */
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100818 (*entry_point)(gd->bd);
wdenk92bbe3f2003-04-20 14:04:18 +0000819}
820
Jon Loeliger54324d02007-07-08 17:51:39 -0500821#if defined(CONFIG_CMD_ELF)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100822static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
823 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100824 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +0000825{
wdenk47d1a6e2002-11-03 00:01:44 +0000826 char str[80];
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100827 image_header_t *hdr = images->legacy_hdr_os;
828
829#if defined(CONFIG_FIT)
830 if (hdr == NULL) {
831 fit_unsupported_reset ("VxWorks");
832 do_reset (cmdtp, flag, argc, argv);
833 }
834#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000835
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100836 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +0000837 setenv("loadaddr", str);
838 do_bootvx(cmdtp, 0, 0, NULL);
839}
840
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100841static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
842 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100843 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +0000844{
wdenk47d1a6e2002-11-03 00:01:44 +0000845 char *local_args[2];
846 char str[16];
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100847 image_header_t *hdr = images->legacy_hdr_os;
848
849#if defined(CONFIG_FIT)
850 if (!images->legacy_hdr_valid) {
851 fit_unsupported_reset ("QNX");
852 do_reset (cmdtp, flag, argc, argv);
853 }
854#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000855
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100856 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +0000857 local_args[0] = argv[0];
858 local_args[1] = str; /* and provide it via the arguments */
859 do_bootelf(cmdtp, 0, 2, local_args);
860}
Jon Loeligerd704d912007-07-10 11:02:44 -0500861#endif
wdenke58b0dc2003-07-27 00:21:01 +0000862
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100863#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
864static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
865 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100866 bootm_headers_t *images)
wdenke58b0dc2003-07-27 00:21:01 +0000867{
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100868 ulong top;
869 char *s, *cmdline;
870 char **fwenv, **ss;
871 int i, j, nxt, len, envno, envsz;
872 bd_t *kbd;
873 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100874 image_header_t *hdr = images->legacy_hdr_os;
875
876#if defined(CONFIG_FIT)
877 if (!images->legacy_hdr_valid) {
878 fit_unsupported_reset ("ARTOS");
879 do_reset (cmdtp, flag, argc, argv);
880 }
881#endif
wdenke58b0dc2003-07-27 00:21:01 +0000882
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100883 /*
884 * Booting an ARTOS kernel image + application
885 */
886
887 /* this used to be the top of memory, but was wrong... */
888#ifdef CONFIG_PPC
889 /* get stack pointer */
890 asm volatile ("mr %0,1" : "=r"(top) );
891#endif
892 debug ("## Current stack ends at 0x%08lX ", top);
893
894 top -= 2048; /* just to be sure */
895 if (top > CFG_BOOTMAPSZ)
896 top = CFG_BOOTMAPSZ;
897 top &= ~0xF;
898
899 debug ("=> set upper limit to 0x%08lX\n", top);
900
901 /* first check the artos specific boot args, then the linux args*/
902 if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
903 s = "";
904
905 /* get length of cmdline, and place it */
906 len = strlen (s);
907 top = (top - (len + 1)) & ~0xF;
908 cmdline = (char *)top;
909 debug ("## cmdline at 0x%08lX ", top);
910 strcpy (cmdline, s);
911
912 /* copy bdinfo */
913 top = (top - sizeof (bd_t)) & ~0xF;
914 debug ("## bd at 0x%08lX ", top);
915 kbd = (bd_t *)top;
916 memcpy (kbd, gd->bd, sizeof (bd_t));
917
918 /* first find number of env entries, and their size */
919 envno = 0;
920 envsz = 0;
921 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
922 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
923 ;
924 envno++;
925 envsz += (nxt - i) + 1; /* plus trailing zero */
926 }
927 envno++; /* plus the terminating zero */
928 debug ("## %u envvars total size %u ", envno, envsz);
929
930 top = (top - sizeof (char **) * envno) & ~0xF;
931 fwenv = (char **)top;
932 debug ("## fwenv at 0x%08lX ", top);
933
934 top = (top - envsz) & ~0xF;
935 s = (char *)top;
936 ss = fwenv;
937
938 /* now copy them */
939 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
940 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
941 ;
942 *ss++ = s;
943 for (j = i; j < nxt; ++j)
944 *s++ = env_get_char (j);
945 *s++ = '\0';
946 }
947 *ss++ = NULL; /* terminate */
948
949 entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
950 (*entry) (kbd, cmdline, fwenv, top);
951}
952#endif