blob: 959689ea7a8e824e434d69c885ec6b8194f8b56d [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
wdenk47d1a6e2002-11-03 00:01:44 +000025/*
26 * Boot support
27 */
28#include <common.h>
29#include <watchdog.h>
30#include <command.h>
wdenk47d1a6e2002-11-03 00:01:44 +000031#include <image.h>
32#include <malloc.h>
33#include <zlib.h>
wdenk710e3502003-08-29 20:57:53 +000034#include <bzlib.h>
wdenk0893c472003-05-20 14:25:27 +000035#include <environment.h>
Kumar Gala6d7bfa82008-02-27 21:51:47 -060036#include <lmb.h>
wdenk47d1a6e2002-11-03 00:01:44 +000037#include <asm/byteorder.h>
wdenk57b2d802003-06-27 21:31:46 +000038
wdenk47d1a6e2002-11-03 00:01:44 +000039#ifdef CFG_HUSH_PARSER
40#include <hush.h>
41#endif
42
Marian Balakowicz2df645e2008-01-08 18:17:10 +010043DECLARE_GLOBAL_DATA_PTR;
wdenk9dfa8d12002-12-08 09:53:23 +000044
Marian Balakowicz2df645e2008-01-08 18:17:10 +010045extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
46#ifndef CFG_BOOTM_LEN
47#define CFG_BOOTM_LEN 0x800000 /* use 8MByte as default max gunzip size */
wdenk381669a2003-06-16 23:50:08 +000048#endif
49
Marian Balakowiczbe946ba2008-01-08 18:11:43 +010050#ifdef CONFIG_BZIP2
51extern void bz_internal_error(int);
wdenk47d1a6e2002-11-03 00:01:44 +000052#endif
53
Jon Loeliger54324d02007-07-08 17:51:39 -050054#if defined(CONFIG_CMD_IMI)
wdenk47d1a6e2002-11-03 00:01:44 +000055static int image_info (unsigned long addr);
56#endif
wdenk874ac262003-07-24 23:38:38 +000057
Jon Loeliger54324d02007-07-08 17:51:39 -050058#if defined(CONFIG_CMD_IMLS)
wdenk874ac262003-07-24 23:38:38 +000059#include <flash.h>
Marian Balakowicz513b4a12005-10-11 19:09:42 +020060extern flash_info_t flash_info[]; /* info for FLASH chips */
wdenk874ac262003-07-24 23:38:38 +000061static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
62#endif
63
Marian Balakowicz2df645e2008-01-08 18:17:10 +010064#ifdef CONFIG_SILENT_CONSOLE
65static void fixup_silent_linux (void);
66#endif
wdenk47d1a6e2002-11-03 00:01:44 +000067
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +010068static image_header_t *image_get_kernel (ulong img_addr, int verify);
69#if defined(CONFIG_FIT)
70static int fit_check_kernel (const void *fit, int os_noffset, int verify);
wdenk591dda52002-11-18 00:14:45 +000071#endif
72
Marian Balakowiczd7c88a42008-02-29 14:58:34 +010073static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag,int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +010074 bootm_headers_t *images, ulong *os_data, ulong *os_len);
Marian Balakowicz2df645e2008-01-08 18:17:10 +010075extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
wdenk47d1a6e2002-11-03 00:01:44 +000076
wdenk47d1a6e2002-11-03 00:01:44 +000077/*
78 * Continue booting an OS image; caller already has:
79 * - copied image header to global variable `header'
80 * - checked header magic number, checksums (both header & image),
81 * - verified image architecture (PPC) and type (KERNEL or MULTI),
82 * - loaded (first part of) image to header load address,
83 * - disabled interrupts.
84 */
Marian Balakowicz2df645e2008-01-08 18:17:10 +010085typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag,
Marian Balakowiczb4a12a92008-01-08 18:12:17 +010086 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +010087 bootm_headers_t *images); /* pointers to os/initrd/fdt */
wdenk47d1a6e2002-11-03 00:01:44 +000088
Marian Balakowicz2df645e2008-01-08 18:17:10 +010089extern boot_os_fn do_bootm_linux;
90static boot_os_fn do_bootm_netbsd;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +010091#if defined(CONFIG_LYNXKDI)
Marian Balakowicz2df645e2008-01-08 18:17:10 +010092static boot_os_fn do_bootm_lynxkdi;
93extern void lynxkdi_boot (image_header_t *);
wdenk47d1a6e2002-11-03 00:01:44 +000094#endif
Marian Balakowicz2df645e2008-01-08 18:17:10 +010095static boot_os_fn do_bootm_rtems;
Jon Loeliger54324d02007-07-08 17:51:39 -050096#if defined(CONFIG_CMD_ELF)
Marian Balakowicz2df645e2008-01-08 18:17:10 +010097static boot_os_fn do_bootm_vxworks;
98static boot_os_fn do_bootm_qnxelf;
99int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
100int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
Jon Loeligerd704d912007-07-10 11:02:44 -0500101#endif
wdenk0893c472003-05-20 14:25:27 +0000102#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100103static boot_os_fn do_bootm_artos;
wdenke58b0dc2003-07-27 00:21:01 +0000104#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000105
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100106ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100107static bootm_headers_t images; /* pointers to os/initrd/fdt images */
Stefan Roese5d5ce292006-03-13 11:16:36 +0100108
Kumar Galab937bb72008-02-27 21:51:49 -0600109void __board_lmb_reserve(struct lmb *lmb)
110{
111 /* please define platform specific board_lmb_reserve() */
112}
113void board_lmb_reserve(struct lmb *lmb) __attribute__((weak, alias("__board_lmb_reserve")));
wdenk47d1a6e2002-11-03 00:01:44 +0000114
wdenk47d1a6e2002-11-03 00:01:44 +0000115
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100116/*******************************************************************/
117/* bootm - boot application image from image in memory */
118/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +0000119int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
120{
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100121 ulong iflag;
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100122 const char *type_name;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100123 uint unc_len = CFG_BOOTM_LEN;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100124 uint8_t comp, type, os;
wdenk47d1a6e2002-11-03 00:01:44 +0000125
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100126 void *os_hdr;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100127 ulong os_data, os_len;
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100128 ulong image_start, image_end;
129 ulong load_start, load_end;
Becky Bruced26d67c2008-06-09 20:37:18 -0500130 ulong mem_start;
131 phys_size_t mem_size;
wdenk47d1a6e2002-11-03 00:01:44 +0000132
Kumar Gala6d7bfa82008-02-27 21:51:47 -0600133 struct lmb lmb;
wdenk47d1a6e2002-11-03 00:01:44 +0000134
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100135 memset ((void *)&images, 0, sizeof (images));
Bartlomiej Sieka47868592008-04-18 12:39:23 +0200136 images.verify = getenv_yesno ("verify");
137 images.autostart = getenv_yesno ("autostart");
Kumar Gala6d7bfa82008-02-27 21:51:47 -0600138 images.lmb = &lmb;
wdenk47d1a6e2002-11-03 00:01:44 +0000139
Kumar Gala6d7bfa82008-02-27 21:51:47 -0600140 lmb_init(&lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000141
Kumar Galac5bacfd2008-02-27 21:51:50 -0600142 mem_start = getenv_bootm_low();
143 mem_size = getenv_bootm_size();
wdenk47d1a6e2002-11-03 00:01:44 +0000144
Becky Bruced26d67c2008-06-09 20:37:18 -0500145 lmb_add(&lmb, (phys_addr_t)mem_start, mem_size);
wdenk47d1a6e2002-11-03 00:01:44 +0000146
Kumar Galab937bb72008-02-27 21:51:49 -0600147 board_lmb_reserve(&lmb);
wdenk47d1a6e2002-11-03 00:01:44 +0000148
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100149 /* get kernel image header, start address and length */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100150 os_hdr = boot_get_kernel (cmdtp, flag, argc, argv,
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100151 &images, &os_data, &os_len);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100152 if (os_len == 0) {
153 puts ("ERROR: can't get kernel image!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000154 return 1;
155 }
Wolfgang Denk63e44ff2005-10-06 01:50:50 +0200156
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100157 /* get image parameters */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100158 switch (genimg_get_format (os_hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100159 case IMAGE_FORMAT_LEGACY:
160 type = image_get_type (os_hdr);
161 comp = image_get_comp (os_hdr);
162 os = image_get_os (os_hdr);
Wolfgang Denk63e44ff2005-10-06 01:50:50 +0200163
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100164 image_end = image_get_image_end (os_hdr);
165 load_start = image_get_load (os_hdr);
166 break;
167#if defined(CONFIG_FIT)
168 case IMAGE_FORMAT_FIT:
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100169 if (fit_image_get_type (images.fit_hdr_os,
170 images.fit_noffset_os, &type)) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100171 puts ("Can't get image type!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100172 show_boot_progress (-109);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100173 return 1;
174 }
wdenk47d1a6e2002-11-03 00:01:44 +0000175
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100176 if (fit_image_get_comp (images.fit_hdr_os,
177 images.fit_noffset_os, &comp)) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100178 puts ("Can't get image compression!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100179 show_boot_progress (-110);
wdenk47d1a6e2002-11-03 00:01:44 +0000180 return 1;
181 }
wdenk47d1a6e2002-11-03 00:01:44 +0000182
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100183 if (fit_image_get_os (images.fit_hdr_os,
184 images.fit_noffset_os, &os)) {
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100185 puts ("Can't get image OS!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100186 show_boot_progress (-111);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100187 return 1;
188 }
wdenk47d1a6e2002-11-03 00:01:44 +0000189
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100190 image_end = fit_get_end (images.fit_hdr_os);
wdenk47d1a6e2002-11-03 00:01:44 +0000191
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100192 if (fit_image_get_load (images.fit_hdr_os, images.fit_noffset_os,
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100193 &load_start)) {
194 puts ("Can't get image load address!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100195 show_boot_progress (-112);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100196 return 1;
wdenk655a0f92003-10-30 21:49:38 +0000197 }
198 break;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100199#endif
200 default:
201 puts ("ERROR: unknown image format type!\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000202 return 1;
203 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100204
205 image_start = (ulong)os_hdr;
206 load_end = 0;
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100207 type_name = genimg_get_type_name (type);
wdenk47d1a6e2002-11-03 00:01:44 +0000208
209 /*
210 * We have reached the point of no return: we are going to
211 * overwrite all exception vector code, so we cannot easily
212 * recover from any failures any more...
213 */
wdenk47d1a6e2002-11-03 00:01:44 +0000214 iflag = disable_interrupts();
215
wdenk452cfd62002-11-19 11:04:11 +0000216#ifdef CONFIG_AMIGAONEG3SE
217 /*
wdenk57b2d802003-06-27 21:31:46 +0000218 * We've possible left the caches enabled during
wdenk452cfd62002-11-19 11:04:11 +0000219 * bios emulation, so turn them off again
220 */
221 icache_disable();
222 invalidate_l1_instruction_cache();
223 flush_data_cache();
224 dcache_disable();
225#endif
226
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100227 switch (comp) {
wdenk47d1a6e2002-11-03 00:01:44 +0000228 case IH_COMP_NONE:
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100229 if (load_start == (ulong)os_hdr) {
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100230 printf (" XIP %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000231 } else {
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100232 printf (" Loading %s ... ", type_name);
wdenk47d1a6e2002-11-03 00:01:44 +0000233
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100234 memmove_wd ((void *)load_start,
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100235 (void *)os_data, os_len, CHUNKSZ);
wdenk47d1a6e2002-11-03 00:01:44 +0000236
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100237 load_end = load_start + os_len;
Marian Balakowiczf9a67bd2008-01-08 18:11:45 +0100238 puts("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000239 }
240 break;
241 case IH_COMP_GZIP:
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100242 printf (" Uncompressing %s ... ", type_name);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100243 if (gunzip ((void *)load_start, unc_len,
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100244 (uchar *)os_data, &os_len) != 0) {
Marian Balakowiczb5324a82008-03-12 10:33:01 +0100245 puts ("GUNZIP: uncompress or overwrite error "
246 "- must RESET board to recover\n");
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200247 show_boot_progress (-6);
wdenk47d1a6e2002-11-03 00:01:44 +0000248 do_reset (cmdtp, flag, argc, argv);
249 }
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100250
251 load_end = load_start + os_len;
wdenk47d1a6e2002-11-03 00:01:44 +0000252 break;
wdenk710e3502003-08-29 20:57:53 +0000253#ifdef CONFIG_BZIP2
254 case IH_COMP_BZIP2:
Marian Balakowicz05c1d3f2008-01-31 13:20:07 +0100255 printf (" Uncompressing %s ... ", type_name);
wdenk2cefd152004-02-08 22:55:38 +0000256 /*
257 * If we've got less than 4 MB of malloc() space,
258 * use slower decompression algorithm which requires
259 * at most 2300 KB of memory.
260 */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100261 int i = BZ2_bzBuffToBuffDecompress ((char*)load_start,
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100262 &unc_len, (char *)os_data, os_len,
263 CFG_MALLOC_LEN < (4096 * 1024), 0);
wdenk710e3502003-08-29 20:57:53 +0000264 if (i != BZ_OK) {
Marian Balakowiczb5324a82008-03-12 10:33:01 +0100265 printf ("BUNZIP2: uncompress or overwrite error %d "
266 "- must RESET board to recover\n", i);
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200267 show_boot_progress (-6);
wdenk710e3502003-08-29 20:57:53 +0000268 do_reset (cmdtp, flag, argc, argv);
269 }
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100270
271 load_end = load_start + unc_len;
wdenk710e3502003-08-29 20:57:53 +0000272 break;
273#endif /* CONFIG_BZIP2 */
wdenk47d1a6e2002-11-03 00:01:44 +0000274 default:
275 if (iflag)
276 enable_interrupts();
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100277 printf ("Unimplemented compression type %d\n", comp);
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200278 show_boot_progress (-7);
wdenk47d1a6e2002-11-03 00:01:44 +0000279 return 1;
280 }
wdenk42c05472004-03-23 22:14:11 +0000281 puts ("OK\n");
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100282 debug (" kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end);
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200283 show_boot_progress (7);
wdenk47d1a6e2002-11-03 00:01:44 +0000284
Marian Balakowiczf92332b2008-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);
wdenk47d1a6e2002-11-03 00:01:44 +0000288
Marian Balakowiczab00e022008-04-11 11:07:49 +0200289 if (images.legacy_hdr_valid) {
290 if (image_get_type (&images.legacy_hdr_os_copy) == IH_TYPE_MULTI)
291 puts ("WARNING: legacy format multi component "
292 "image overwritten\n");
293 } else {
294 puts ("ERROR: new format image overwritten - "
295 "must RESET the board to recover\n");
296 show_boot_progress (-113);
297 do_reset (cmdtp, flag, argc, argv);
298 }
wdenk47d1a6e2002-11-03 00:01:44 +0000299 }
Marian Balakowiczf92332b2008-01-31 13:20:06 +0100300
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200301 show_boot_progress (8);
wdenk47d1a6e2002-11-03 00:01:44 +0000302
Kumar Gala6d7bfa82008-02-27 21:51:47 -0600303 lmb_reserve(&lmb, load_start, (load_end - load_start));
304
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100305 switch (os) {
wdenk47d1a6e2002-11-03 00:01:44 +0000306 default: /* handled by (original) Linux case */
307 case IH_OS_LINUX:
wdenk808532a2003-10-10 10:05:42 +0000308#ifdef CONFIG_SILENT_CONSOLE
309 fixup_silent_linux();
310#endif
Marian Balakowicz61fde552008-02-27 11:01:04 +0100311 do_bootm_linux (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000312 break;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100313
wdenk47d1a6e2002-11-03 00:01:44 +0000314 case IH_OS_NETBSD:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100315 do_bootm_netbsd (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000316 break;
wdenke58b0dc2003-07-27 00:21:01 +0000317
318#ifdef CONFIG_LYNXKDI
319 case IH_OS_LYNXOS:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100320 do_bootm_lynxkdi (cmdtp, flag, argc, argv, &images);
wdenke58b0dc2003-07-27 00:21:01 +0000321 break;
322#endif
wdenk57b2d802003-06-27 21:31:46 +0000323
wdenk92bbe3f2003-04-20 14:04:18 +0000324 case IH_OS_RTEMS:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100325 do_bootm_rtems (cmdtp, flag, argc, argv, &images);
wdenk92bbe3f2003-04-20 14:04:18 +0000326 break;
wdenk57b2d802003-06-27 21:31:46 +0000327
Jon Loeliger54324d02007-07-08 17:51:39 -0500328#if defined(CONFIG_CMD_ELF)
wdenk47d1a6e2002-11-03 00:01:44 +0000329 case IH_OS_VXWORKS:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100330 do_bootm_vxworks (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000331 break;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100332
wdenk47d1a6e2002-11-03 00:01:44 +0000333 case IH_OS_QNX:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100334 do_bootm_qnxelf (cmdtp, flag, argc, argv, &images);
wdenk47d1a6e2002-11-03 00:01:44 +0000335 break;
Jon Loeligerd704d912007-07-10 11:02:44 -0500336#endif
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100337
wdenk0893c472003-05-20 14:25:27 +0000338#ifdef CONFIG_ARTOS
339 case IH_OS_ARTOS:
Marian Balakowicz61fde552008-02-27 11:01:04 +0100340 do_bootm_artos (cmdtp, flag, argc, argv, &images);
wdenk0893c472003-05-20 14:25:27 +0000341 break;
342#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000343 }
344
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200345 show_boot_progress (-9);
wdenk47d1a6e2002-11-03 00:01:44 +0000346#ifdef DEBUG
wdenk42c05472004-03-23 22:14:11 +0000347 puts ("\n## Control returned to monitor - resetting...\n");
Marian Balakowicz9c220262008-03-12 10:14:57 +0100348 if (images.autostart)
349 do_reset (cmdtp, flag, argc, argv);
wdenk47d1a6e2002-11-03 00:01:44 +0000350#endif
Marian Balakowicz9c220262008-03-12 10:14:57 +0100351 if (!images.autostart && iflag)
352 enable_interrupts();
353
wdenk47d1a6e2002-11-03 00:01:44 +0000354 return 1;
355}
356
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100357/**
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100358 * image_get_kernel - verify legacy format kernel image
359 * @img_addr: in RAM address of the legacy format image to be verified
360 * @verify: data CRC verification flag
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100361 *
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100362 * image_get_kernel() verifies legacy image integrity and returns pointer to
363 * legacy image header if image verification was completed successfully.
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100364 *
365 * returns:
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100366 * pointer to a legacy image header if valid image was found
367 * otherwise return NULL
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100368 */
Marian Balakowicz59504f62008-02-27 11:02:07 +0100369static image_header_t *image_get_kernel (ulong img_addr, int verify)
wdenk808532a2003-10-10 10:05:42 +0000370{
Marian Balakowicz59504f62008-02-27 11:02:07 +0100371 image_header_t *hdr = (image_header_t *)img_addr;
wdenk808532a2003-10-10 10:05:42 +0000372
Marian Balakowicz59504f62008-02-27 11:02:07 +0100373 if (!image_check_magic(hdr)) {
374 puts ("Bad Magic Number\n");
375 show_boot_progress (-1);
376 return NULL;
377 }
378 show_boot_progress (2);
wdenk808532a2003-10-10 10:05:42 +0000379
Marian Balakowicz59504f62008-02-27 11:02:07 +0100380 if (!image_check_hcrc (hdr)) {
381 puts ("Bad Header Checksum\n");
382 show_boot_progress (-2);
383 return NULL;
384 }
385
386 show_boot_progress (3);
387 image_print_contents (hdr);
388
389 if (verify) {
390 puts (" Verifying Checksum ... ");
391 if (!image_check_dcrc (hdr)) {
392 printf ("Bad Data CRC\n");
393 show_boot_progress (-3);
394 return NULL;
wdenk808532a2003-10-10 10:05:42 +0000395 }
Marian Balakowicz59504f62008-02-27 11:02:07 +0100396 puts ("OK\n");
wdenk808532a2003-10-10 10:05:42 +0000397 }
Marian Balakowicz59504f62008-02-27 11:02:07 +0100398 show_boot_progress (4);
wdenk808532a2003-10-10 10:05:42 +0000399
Marian Balakowicz59504f62008-02-27 11:02:07 +0100400 if (!image_check_target_arch (hdr)) {
401 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
402 show_boot_progress (-4);
403 return NULL;
404 }
405 return hdr;
wdenk808532a2003-10-10 10:05:42 +0000406}
wdenk808532a2003-10-10 10:05:42 +0000407
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100408/**
409 * fit_check_kernel - verify FIT format kernel subimage
410 * @fit_hdr: pointer to the FIT image header
411 * os_noffset: kernel subimage node offset within FIT image
412 * @verify: data CRC verification flag
413 *
414 * fit_check_kernel() verifies integrity of the kernel subimage and from
415 * specified FIT image.
416 *
417 * returns:
418 * 1, on success
419 * 0, on failure
420 */
421#if defined (CONFIG_FIT)
422static int fit_check_kernel (const void *fit, int os_noffset, int verify)
wdenk47d1a6e2002-11-03 00:01:44 +0000423{
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100424 fit_image_print (fit, os_noffset, " ");
wdenk47d1a6e2002-11-03 00:01:44 +0000425
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100426 if (verify) {
427 puts (" Verifying Hash Integrity ... ");
428 if (!fit_image_check_hashes (fit, os_noffset)) {
429 puts ("Bad Data Hash\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100430 show_boot_progress (-104);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100431 return 0;
432 }
433 puts ("OK\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000434 }
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100435 show_boot_progress (105);
wdenk47d1a6e2002-11-03 00:01:44 +0000436
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100437 if (!fit_image_check_target_arch (fit, os_noffset)) {
438 puts ("Unsupported Architecture\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100439 show_boot_progress (-105);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100440 return 0;
441 }
wdenk47d1a6e2002-11-03 00:01:44 +0000442
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100443 show_boot_progress (106);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100444 if (!fit_image_check_type (fit, os_noffset, IH_TYPE_KERNEL)) {
445 puts ("Not a kernel image\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100446 show_boot_progress (-106);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100447 return 0;
448 }
wdenk47d1a6e2002-11-03 00:01:44 +0000449
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100450 show_boot_progress (107);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100451 return 1;
452}
453#endif /* CONFIG_FIT */
wdenk56f94be2002-11-05 16:35:14 +0000454
Marian Balakowicz59504f62008-02-27 11:02:07 +0100455/**
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100456 * boot_get_kernel - find kernel image
Marian Balakowicz59504f62008-02-27 11:02:07 +0100457 * @os_data: pointer to a ulong variable, will hold os data start address
458 * @os_len: pointer to a ulong variable, will hold os data length
459 *
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100460 * boot_get_kernel() tries to find a kernel image, verifies its integrity
Marian Balakowicz59504f62008-02-27 11:02:07 +0100461 * and locates kernel data.
462 *
463 * returns:
464 * pointer to image header if valid image was found, plus kernel start
465 * address and length, otherwise NULL
466 */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100467static void *boot_get_kernel (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100468 bootm_headers_t *images, ulong *os_data, ulong *os_len)
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100469{
470 image_header_t *hdr;
471 ulong img_addr;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100472#if defined(CONFIG_FIT)
473 void *fit_hdr;
474 const char *fit_uname_config = NULL;
475 const char *fit_uname_kernel = NULL;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100476 const void *data;
477 size_t len;
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100478 int cfg_noffset;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100479 int os_noffset;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100480#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000481
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100482 /* find out kernel image address */
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100483 if (argc < 2) {
484 img_addr = load_addr;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100485 debug ("* kernel: default image load address = 0x%08lx\n",
486 load_addr);
487#if defined(CONFIG_FIT)
488 } else if (fit_parse_conf (argv[1], load_addr, &img_addr,
489 &fit_uname_config)) {
490 debug ("* kernel: config '%s' from image at 0x%08lx\n",
491 fit_uname_config, img_addr);
492 } else if (fit_parse_subimage (argv[1], load_addr, &img_addr,
493 &fit_uname_kernel)) {
494 debug ("* kernel: subimage '%s' from image at 0x%08lx\n",
495 fit_uname_kernel, img_addr);
496#endif
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100497 } else {
498 img_addr = simple_strtoul(argv[1], NULL, 16);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100499 debug ("* kernel: cmdline image address = 0x%08lx\n", img_addr);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100500 }
wdenk56f94be2002-11-05 16:35:14 +0000501
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100502 show_boot_progress (1);
wdenk47d1a6e2002-11-03 00:01:44 +0000503
Marian Balakowiczc536d6f2008-02-21 17:20:19 +0100504 /* copy from dataflash if needed */
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100505 img_addr = genimg_get_image (img_addr);
wdenk47d1a6e2002-11-03 00:01:44 +0000506
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100507 /* check image type, for FIT images get FIT kernel node */
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100508 *os_data = *os_len = 0;
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100509 switch (genimg_get_format ((void *)img_addr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100510 case IMAGE_FORMAT_LEGACY:
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100511 printf ("## Booting kernel from Legacy Image at %08lx ...\n",
512 img_addr);
Marian Balakowicz59504f62008-02-27 11:02:07 +0100513 hdr = image_get_kernel (img_addr, images->verify);
514 if (!hdr)
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100515 return NULL;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100516 show_boot_progress (5);
wdenk47d1a6e2002-11-03 00:01:44 +0000517
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100518 /* get os_data and os_len */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100519 switch (image_get_type (hdr)) {
520 case IH_TYPE_KERNEL:
521 *os_data = image_get_data (hdr);
522 *os_len = image_get_data_size (hdr);
523 break;
524 case IH_TYPE_MULTI:
525 image_multi_getimg (hdr, 0, os_data, os_len);
526 break;
527 default:
528 printf ("Wrong Image Type for %s command\n", cmdtp->name);
529 show_boot_progress (-5);
530 return NULL;
531 }
Marian Balakowiczab00e022008-04-11 11:07:49 +0200532
533 /*
534 * copy image header to allow for image overwrites during kernel
535 * decompression.
536 */
537 memmove (&images->legacy_hdr_os_copy, hdr, sizeof(image_header_t));
538
539 /* save pointer to image header */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100540 images->legacy_hdr_os = hdr;
wdenk47d1a6e2002-11-03 00:01:44 +0000541
Marian Balakowiczab00e022008-04-11 11:07:49 +0200542 images->legacy_hdr_valid = 1;
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100543 show_boot_progress (6);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100544 break;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100545#if defined(CONFIG_FIT)
546 case IMAGE_FORMAT_FIT:
547 fit_hdr = (void *)img_addr;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100548 printf ("## Booting kernel from FIT Image at %08lx ...\n",
549 img_addr);
wdenk47d1a6e2002-11-03 00:01:44 +0000550
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100551 if (!fit_check_format (fit_hdr)) {
552 puts ("Bad FIT kernel image format!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100553 show_boot_progress (-100);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100554 return NULL;
555 }
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100556 show_boot_progress (100);
wdenk47d1a6e2002-11-03 00:01:44 +0000557
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100558 if (!fit_uname_kernel) {
559 /*
560 * no kernel image node unit name, try to get config
561 * node first. If config unit node name is NULL
562 * fit_conf_get_node() will try to find default config node
563 */
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100564 show_boot_progress (101);
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100565 cfg_noffset = fit_conf_get_node (fit_hdr, fit_uname_config);
566 if (cfg_noffset < 0) {
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100567 show_boot_progress (-101);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100568 return NULL;
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100569 }
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100570 /* save configuration uname provided in the first
571 * bootm argument
572 */
573 images->fit_uname_cfg = fdt_get_name (fit_hdr, cfg_noffset, NULL);
574 printf (" Using '%s' configuration\n", images->fit_uname_cfg);
575 show_boot_progress (103);
wdenk47d1a6e2002-11-03 00:01:44 +0000576
Marian Balakowicz0cd4f3d2008-03-12 10:35:46 +0100577 os_noffset = fit_conf_get_kernel_node (fit_hdr, cfg_noffset);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100578 fit_uname_kernel = fit_get_name (fit_hdr, os_noffset, NULL);
579 } else {
580 /* get kernel component image node offset */
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100581 show_boot_progress (102);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100582 os_noffset = fit_image_get_node (fit_hdr, fit_uname_kernel);
583 }
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100584 if (os_noffset < 0) {
585 show_boot_progress (-103);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100586 return NULL;
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100587 }
wdenk47d1a6e2002-11-03 00:01:44 +0000588
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100589 printf (" Trying '%s' kernel subimage\n", fit_uname_kernel);
wdenk47d1a6e2002-11-03 00:01:44 +0000590
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100591 show_boot_progress (104);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100592 if (!fit_check_kernel (fit_hdr, os_noffset, images->verify))
593 return NULL;
Matthew McClintock6fb7c812006-06-28 10:41:37 -0500594
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100595 /* get kernel image data address and length */
596 if (fit_image_get_data (fit_hdr, os_noffset, &data, &len)) {
597 puts ("Could not find kernel subimage data!\n");
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100598 show_boot_progress (-107);
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100599 return NULL;
Matthew McClintock6fb7c812006-06-28 10:41:37 -0500600 }
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100601 show_boot_progress (108);
wdenk47d1a6e2002-11-03 00:01:44 +0000602
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100603 *os_len = len;
604 *os_data = (ulong)data;
605 images->fit_hdr_os = fit_hdr;
606 images->fit_uname_os = fit_uname_kernel;
Marian Balakowicz61c1ad52008-03-12 10:32:59 +0100607 images->fit_noffset_os = os_noffset;
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100608 break;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100609#endif
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100610 default:
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100611 printf ("Wrong Image Format for %s command\n", cmdtp->name);
Marian Balakowicz74eb4ae2008-03-12 10:33:01 +0100612 show_boot_progress (-108);
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100613 return NULL;
614 }
wdenk47d1a6e2002-11-03 00:01:44 +0000615
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100616 debug (" kernel data at 0x%08lx, len = 0x%08lx (%d)\n",
617 *os_data, *os_len, *os_len);
wdenk47d1a6e2002-11-03 00:01:44 +0000618
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100619 return (void *)img_addr;
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100620}
wdenk47d1a6e2002-11-03 00:01:44 +0000621
wdenk47d1a6e2002-11-03 00:01:44 +0000622U_BOOT_CMD(
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100623 bootm, CFG_MAXARGS, 1, do_bootm,
624 "bootm - boot application image from memory\n",
625 "[addr [arg ...]]\n - boot application image stored in memory\n"
626 "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
627 "\t'arg' can be the address of an initrd image\n"
Marian Balakowiczd2160852008-01-31 13:20:07 +0100628#if defined(CONFIG_OF_LIBFDT)
wdenk47d1a6e2002-11-03 00:01:44 +0000629 "\tWhen booting a Linux kernel which requires a flat device-tree\n"
630 "\ta third argument is required which is the address of the\n"
631 "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
632 "\tuse a '-' for the second argument. If you do not pass a third\n"
633 "\ta bd_info struct will be passed instead\n"
634#endif
Marian Balakowicz9f8e4aa2008-03-12 10:01:05 +0100635#if defined(CONFIG_FIT)
636 "\t\nFor the new multi component uImage format (FIT) addresses\n"
637 "\tmust be extened to include component or configuration unit name:\n"
638 "\taddr:<subimg_uname> - direct component image specification\n"
639 "\taddr#<conf_uname> - configuration specification\n"
640 "\tUse iminfo command to get the list of existing component\n"
641 "\timages and configurations.\n"
642#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000643);
wdenk47d1a6e2002-11-03 00:01:44 +0000644
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100645/*******************************************************************/
646/* bootd - boot default image */
647/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -0500648#if defined(CONFIG_CMD_BOOTD)
wdenk47d1a6e2002-11-03 00:01:44 +0000649int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
650{
651 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000652
wdenk47d1a6e2002-11-03 00:01:44 +0000653#ifndef CFG_HUSH_PARSER
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100654 if (run_command (getenv ("bootcmd"), flag) < 0)
655 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000656#else
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100657 if (parse_string_outer (getenv ("bootcmd"),
658 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
659 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000660#endif
661 return rcode;
662}
wdenk47d1a6e2002-11-03 00:01:44 +0000663
wdenkf287a242003-07-01 21:06:45 +0000664U_BOOT_CMD(
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100665 boot, 1, 1, do_bootd,
666 "boot - boot default, i.e., run 'bootcmd'\n",
wdenk3086a972003-06-28 23:11:04 +0000667 NULL
668);
wdenk47d1a6e2002-11-03 00:01:44 +0000669
wdenk3086a972003-06-28 23:11:04 +0000670/* keep old command name "bootd" for backward compatibility */
wdenkf287a242003-07-01 21:06:45 +0000671U_BOOT_CMD(
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100672 bootd, 1, 1, do_bootd,
673 "bootd - boot default, i.e., run 'bootcmd'\n",
wdenk57b2d802003-06-27 21:31:46 +0000674 NULL
675);
wdenk47d1a6e2002-11-03 00:01:44 +0000676
wdenk47d1a6e2002-11-03 00:01:44 +0000677#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000678
wdenk47d1a6e2002-11-03 00:01:44 +0000679
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100680/*******************************************************************/
681/* iminfo - print header info for a requested image */
682/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -0500683#if defined(CONFIG_CMD_IMI)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100684int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
wdenk47d1a6e2002-11-03 00:01:44 +0000685{
686 int arg;
687 ulong addr;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100688 int rcode = 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000689
wdenk47d1a6e2002-11-03 00:01:44 +0000690 if (argc < 2) {
691 return image_info (load_addr);
692 }
wdenk47d1a6e2002-11-03 00:01:44 +0000693
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100694 for (arg = 1; arg < argc; ++arg) {
695 addr = simple_strtoul (argv[arg], NULL, 16);
696 if (image_info (addr) != 0)
697 rcode = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000698 }
699 return rcode;
700}
wdenk47d1a6e2002-11-03 00:01:44 +0000701
wdenk47d1a6e2002-11-03 00:01:44 +0000702static int image_info (ulong addr)
703{
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100704 void *hdr = (void *)addr;
wdenk47d1a6e2002-11-03 00:01:44 +0000705
wdenk47d1a6e2002-11-03 00:01:44 +0000706 printf ("\n## Checking Image at %08lx ...\n", addr);
wdenk47d1a6e2002-11-03 00:01:44 +0000707
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100708 switch (genimg_get_format (hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100709 case IMAGE_FORMAT_LEGACY:
710 puts (" Legacy image found\n");
711 if (!image_check_magic (hdr)) {
712 puts (" Bad Magic Number\n");
713 return 1;
714 }
wdenk47d1a6e2002-11-03 00:01:44 +0000715
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100716 if (!image_check_hcrc (hdr)) {
717 puts (" Bad Header Checksum\n");
718 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000719 }
720
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100721 image_print_contents (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000722
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100723 puts (" Verifying Checksum ... ");
724 if (!image_check_dcrc (hdr)) {
725 puts (" Bad Data CRC\n");
726 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000727 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100728 puts ("OK\n");
729 return 0;
730#if defined(CONFIG_FIT)
731 case IMAGE_FORMAT_FIT:
732 puts (" FIT image found\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000733
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100734 if (!fit_check_format (hdr)) {
735 puts ("Bad FIT image format!\n");
736 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000737 }
738
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100739 fit_print_contents (hdr);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100740 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000741#endif
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100742 default:
743 puts ("Unknown image format!\n");
744 break;
wdenk47d1a6e2002-11-03 00:01:44 +0000745 }
wdenk47d1a6e2002-11-03 00:01:44 +0000746
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100747 return 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000748}
wdenk47d1a6e2002-11-03 00:01:44 +0000749
wdenkf287a242003-07-01 21:06:45 +0000750U_BOOT_CMD(
751 iminfo, CFG_MAXARGS, 1, do_iminfo,
wdenk57b2d802003-06-27 21:31:46 +0000752 "iminfo - print header information for application image\n",
753 "addr [addr ...]\n"
754 " - print header information for application image starting at\n"
755 " address 'addr' in memory; this includes verification of the\n"
756 " image contents (magic number, header and payload checksums)\n"
757);
wdenk47d1a6e2002-11-03 00:01:44 +0000758#endif
759
760
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100761/*******************************************************************/
762/* imls - list all images found in flash */
763/*******************************************************************/
Jon Loeliger54324d02007-07-08 17:51:39 -0500764#if defined(CONFIG_CMD_IMLS)
wdenk874ac262003-07-24 23:38:38 +0000765int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
766{
767 flash_info_t *info;
768 int i, j;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100769 void *hdr;
wdenk47d1a6e2002-11-03 00:01:44 +0000770
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100771 for (i = 0, info = &flash_info[0];
772 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
wdenk47d1a6e2002-11-03 00:01:44 +0000773
wdenk874ac262003-07-24 23:38:38 +0000774 if (info->flash_id == FLASH_UNKNOWN)
775 goto next_bank;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100776 for (j = 0; j < info->sector_count; ++j) {
wdenk47d1a6e2002-11-03 00:01:44 +0000777
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100778 hdr = (void *)info->start[j];
779 if (!hdr)
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100780 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +0000781
Marian Balakowiczd7c88a42008-02-29 14:58:34 +0100782 switch (genimg_get_format (hdr)) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100783 case IMAGE_FORMAT_LEGACY:
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100784 if (!image_check_hcrc (hdr))
785 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +0000786
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100787 printf ("Legacy Image at %08lX:\n", (ulong)hdr);
788 image_print_contents (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000789
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100790 puts (" Verifying Checksum ... ");
791 if (!image_check_dcrc (hdr)) {
792 puts ("Bad Data CRC\n");
793 } else {
794 puts ("OK\n");
795 }
796 break;
797#if defined(CONFIG_FIT)
798 case IMAGE_FORMAT_FIT:
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100799 if (!fit_check_format (hdr))
800 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +0000801
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100802 printf ("FIT Image at %08lX:\n", (ulong)hdr);
Marian Balakowiczcc1fd912008-03-11 12:35:20 +0100803 fit_print_contents (hdr);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100804 break;
805#endif
806 default:
807 goto next_sector;
wdenk47d1a6e2002-11-03 00:01:44 +0000808 }
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100809
wdenk0a658552003-08-05 17:43:17 +0000810next_sector: ;
wdenk47d1a6e2002-11-03 00:01:44 +0000811 }
wdenk0a658552003-08-05 17:43:17 +0000812next_bank: ;
wdenk47d1a6e2002-11-03 00:01:44 +0000813 }
814
wdenk874ac262003-07-24 23:38:38 +0000815 return (0);
816}
wdenk47d1a6e2002-11-03 00:01:44 +0000817
wdenk874ac262003-07-24 23:38:38 +0000818U_BOOT_CMD(
819 imls, 1, 1, do_imls,
820 "imls - list all images found in flash\n",
821 "\n"
822 " - Prints information about all images found at sector\n"
823 " boundaries in flash.\n"
824);
wdenk47d1a6e2002-11-03 00:01:44 +0000825#endif
826
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100827/*******************************************************************/
Marian Balakowiczc40032c2008-01-31 13:59:09 +0100828/* helper routines */
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100829/*******************************************************************/
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100830#ifdef CONFIG_SILENT_CONSOLE
831static void fixup_silent_linux ()
832{
833 char buf[256], *start, *end;
834 char *cmdline = getenv ("bootargs");
wdenk47d1a6e2002-11-03 00:01:44 +0000835
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100836 /* Only fix cmdline when requested */
837 if (!(gd->flags & GD_FLG_SILENT))
838 return;
wdenk47d1a6e2002-11-03 00:01:44 +0000839
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100840 debug ("before silent fix-up: %s\n", cmdline);
841 if (cmdline) {
842 if ((start = strstr (cmdline, "console=")) != NULL) {
843 end = strchr (start, ' ');
844 strncpy (buf, cmdline, (start - cmdline + 8));
845 if (end)
846 strcpy (buf + (start - cmdline + 8), end);
847 else
848 buf[start - cmdline + 8] = '\0';
849 } else {
850 strcpy (buf, cmdline);
851 strcat (buf, " console=");
wdenk47d1a6e2002-11-03 00:01:44 +0000852 }
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100853 } else {
854 strcpy (buf, "console=");
wdenk47d1a6e2002-11-03 00:01:44 +0000855 }
wdenk47d1a6e2002-11-03 00:01:44 +0000856
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100857 setenv ("bootargs", buf);
858 debug ("after silent fix-up: %s\n", buf);
859}
860#endif /* CONFIG_SILENT_CONSOLE */
wdenk47d1a6e2002-11-03 00:01:44 +0000861
wdenk47d1a6e2002-11-03 00:01:44 +0000862
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100863/*******************************************************************/
864/* OS booting routines */
865/*******************************************************************/
wdenk47d1a6e2002-11-03 00:01:44 +0000866
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100867static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100868 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100869 bootm_headers_t *images)
wdenk92bbe3f2003-04-20 14:04:18 +0000870{
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100871 void (*loader)(bd_t *, image_header_t *, char *, char *);
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100872 image_header_t *os_hdr, *hdr;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100873 ulong kernel_data, kernel_len;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100874 char *consdev;
875 char *cmdline;
wdenk47d1a6e2002-11-03 00:01:44 +0000876
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100877#if defined(CONFIG_FIT)
878 if (!images->legacy_hdr_valid) {
879 fit_unsupported_reset ("NetBSD");
880 do_reset (cmdtp, flag, argc, argv);
wdenk47d1a6e2002-11-03 00:01:44 +0000881 }
882#endif
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100883 hdr = images->legacy_hdr_os;
wdenk47d1a6e2002-11-03 00:01:44 +0000884
885 /*
886 * Booting a (NetBSD) kernel image
887 *
888 * This process is pretty similar to a standalone application:
889 * The (first part of an multi-) image must be a stage-2 loader,
890 * which in turn is responsible for loading & invoking the actual
891 * kernel. The only differences are the parameters being passed:
892 * besides the board info strucure, the loader expects a command
893 * line, the name of the console device, and (optionally) the
894 * address of the original image header.
895 */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100896 os_hdr = NULL;
Marian Balakowiczab00e022008-04-11 11:07:49 +0200897 if (image_check_type (&images->legacy_hdr_os_copy, IH_TYPE_MULTI)) {
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100898 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
899 if (kernel_len)
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100900 os_hdr = hdr;
Marian Balakowiczb4a12a92008-01-08 18:12:17 +0100901 }
wdenk47d1a6e2002-11-03 00:01:44 +0000902
903 consdev = "";
904#if defined (CONFIG_8xx_CONS_SMC1)
905 consdev = "smc1";
906#elif defined (CONFIG_8xx_CONS_SMC2)
907 consdev = "smc2";
908#elif defined (CONFIG_8xx_CONS_SCC2)
909 consdev = "scc2";
910#elif defined (CONFIG_8xx_CONS_SCC3)
911 consdev = "scc3";
912#endif
913
914 if (argc > 2) {
915 ulong len;
916 int i;
917
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100918 for (i = 2, len = 0; i < argc; i += 1)
wdenk47d1a6e2002-11-03 00:01:44 +0000919 len += strlen (argv[i]) + 1;
920 cmdline = malloc (len);
921
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100922 for (i = 2, len = 0; i < argc; i += 1) {
wdenk47d1a6e2002-11-03 00:01:44 +0000923 if (i > 2)
924 cmdline[len++] = ' ';
925 strcpy (&cmdline[len], argv[i]);
926 len += strlen (argv[i]);
927 }
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100928 } else if ((cmdline = getenv ("bootargs")) == NULL) {
wdenk47d1a6e2002-11-03 00:01:44 +0000929 cmdline = "";
930 }
931
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100932 loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000933
934 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
935 (ulong)loader);
936
937 show_boot_progress (15);
938
939 /*
940 * NetBSD Stage-2 Loader Parameters:
941 * r3: ptr to board info data
942 * r4: image address
943 * r5: console device
944 * r6: boot args string
945 */
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100946 (*loader) (gd->bd, os_hdr, consdev, cmdline);
wdenk47d1a6e2002-11-03 00:01:44 +0000947}
948
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100949#ifdef CONFIG_LYNXKDI
950static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
951 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100952 bootm_headers_t *images)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100953{
Marian Balakowiczab00e022008-04-11 11:07:49 +0200954 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100955
956#if defined(CONFIG_FIT)
957 if (!images->legacy_hdr_valid) {
958 fit_unsupported_reset ("Lynx");
959 do_reset (cmdtp, flag, argc, argv);
960 }
961#endif
962
963 lynxkdi_boot ((image_header_t *)hdr);
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100964}
965#endif /* CONFIG_LYNXKDI */
966
967static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
968 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100969 bootm_headers_t *images)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100970{
Marian Balakowiczab00e022008-04-11 11:07:49 +0200971 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100972 void (*entry_point)(bd_t *);
wdenk92bbe3f2003-04-20 14:04:18 +0000973
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +0100974#if defined(CONFIG_FIT)
975 if (!images->legacy_hdr_valid) {
976 fit_unsupported_reset ("RTEMS");
977 do_reset (cmdtp, flag, argc, argv);
978 }
979#endif
980
Marian Balakowicz41d71ed2008-01-08 18:14:09 +0100981 entry_point = (void (*)(bd_t *))image_get_ep (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000982
wdenk92bbe3f2003-04-20 14:04:18 +0000983 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
984 (ulong)entry_point);
wdenk47d1a6e2002-11-03 00:01:44 +0000985
Heiko Schocher8a8ec532007-07-13 09:54:17 +0200986 show_boot_progress (15);
wdenk92bbe3f2003-04-20 14:04:18 +0000987
988 /*
989 * RTEMS Parameters:
990 * r3: ptr to board info data
991 */
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100992 (*entry_point)(gd->bd);
wdenk92bbe3f2003-04-20 14:04:18 +0000993}
994
Jon Loeliger54324d02007-07-08 17:51:39 -0500995#if defined(CONFIG_CMD_ELF)
Marian Balakowicz2df645e2008-01-08 18:17:10 +0100996static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
997 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +0100998 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +0000999{
wdenk47d1a6e2002-11-03 00:01:44 +00001000 char str[80];
Marian Balakowiczab00e022008-04-11 11:07:49 +02001001 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001002
1003#if defined(CONFIG_FIT)
Marian Balakowiczab00e022008-04-11 11:07:49 +02001004 if (!images->legacy_hdr_valid) {
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001005 fit_unsupported_reset ("VxWorks");
1006 do_reset (cmdtp, flag, argc, argv);
1007 }
1008#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001009
Marian Balakowicz41d71ed2008-01-08 18:14:09 +01001010 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001011 setenv("loadaddr", str);
1012 do_bootvx(cmdtp, 0, 0, NULL);
1013}
1014
Marian Balakowiczb4a12a92008-01-08 18:12:17 +01001015static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
1016 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001017 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001018{
wdenk47d1a6e2002-11-03 00:01:44 +00001019 char *local_args[2];
1020 char str[16];
Marian Balakowiczab00e022008-04-11 11:07:49 +02001021 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001022
1023#if defined(CONFIG_FIT)
1024 if (!images->legacy_hdr_valid) {
1025 fit_unsupported_reset ("QNX");
1026 do_reset (cmdtp, flag, argc, argv);
1027 }
1028#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001029
Marian Balakowicz41d71ed2008-01-08 18:14:09 +01001030 sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
wdenk47d1a6e2002-11-03 00:01:44 +00001031 local_args[0] = argv[0];
1032 local_args[1] = str; /* and provide it via the arguments */
1033 do_bootelf(cmdtp, 0, 2, local_args);
1034}
Jon Loeligerd704d912007-07-10 11:02:44 -05001035#endif
wdenke58b0dc2003-07-27 00:21:01 +00001036
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001037#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
1038static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
1039 int argc, char *argv[],
Marian Balakowicz61fde552008-02-27 11:01:04 +01001040 bootm_headers_t *images)
wdenk47d1a6e2002-11-03 00:01:44 +00001041{
1042 ulong top;
1043 char *s, *cmdline;
1044 char **fwenv, **ss;
1045 int i, j, nxt, len, envno, envsz;
1046 bd_t *kbd;
1047 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
Marian Balakowiczab00e022008-04-11 11:07:49 +02001048 image_header_t *hdr = &images->legacy_hdr_os_copy;
Marian Balakowiczdbdd16a2008-02-04 08:28:09 +01001049
1050#if defined(CONFIG_FIT)
1051 if (!images->legacy_hdr_valid) {
1052 fit_unsupported_reset ("ARTOS");
1053 do_reset (cmdtp, flag, argc, argv);
1054 }
1055#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001056
1057 /*
1058 * Booting an ARTOS kernel image + application
1059 */
1060
1061 /* this used to be the top of memory, but was wrong... */
1062#ifdef CONFIG_PPC
1063 /* get stack pointer */
1064 asm volatile ("mr %0,1" : "=r"(top) );
1065#endif
1066 debug ("## Current stack ends at 0x%08lX ", top);
1067
1068 top -= 2048; /* just to be sure */
1069 if (top > CFG_BOOTMAPSZ)
1070 top = CFG_BOOTMAPSZ;
1071 top &= ~0xF;
1072
1073 debug ("=> set upper limit to 0x%08lX\n", top);
1074
1075 /* first check the artos specific boot args, then the linux args*/
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001076 if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
wdenk47d1a6e2002-11-03 00:01:44 +00001077 s = "";
1078
1079 /* get length of cmdline, and place it */
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001080 len = strlen (s);
wdenk47d1a6e2002-11-03 00:01:44 +00001081 top = (top - (len + 1)) & ~0xF;
1082 cmdline = (char *)top;
1083 debug ("## cmdline at 0x%08lX ", top);
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001084 strcpy (cmdline, s);
wdenk47d1a6e2002-11-03 00:01:44 +00001085
1086 /* copy bdinfo */
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001087 top = (top - sizeof (bd_t)) & ~0xF;
wdenk47d1a6e2002-11-03 00:01:44 +00001088 debug ("## bd at 0x%08lX ", top);
1089 kbd = (bd_t *)top;
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001090 memcpy (kbd, gd->bd, sizeof (bd_t));
wdenk47d1a6e2002-11-03 00:01:44 +00001091
1092 /* first find number of env entries, and their size */
1093 envno = 0;
1094 envsz = 0;
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001095 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1096 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
wdenk47d1a6e2002-11-03 00:01:44 +00001097 ;
1098 envno++;
1099 envsz += (nxt - i) + 1; /* plus trailing zero */
1100 }
1101 envno++; /* plus the terminating zero */
1102 debug ("## %u envvars total size %u ", envno, envsz);
1103
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001104 top = (top - sizeof (char **) * envno) & ~0xF;
wdenk47d1a6e2002-11-03 00:01:44 +00001105 fwenv = (char **)top;
1106 debug ("## fwenv at 0x%08lX ", top);
1107
1108 top = (top - envsz) & ~0xF;
1109 s = (char *)top;
1110 ss = fwenv;
1111
1112 /* now copy them */
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001113 for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
1114 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
wdenk47d1a6e2002-11-03 00:01:44 +00001115 ;
1116 *ss++ = s;
1117 for (j = i; j < nxt; ++j)
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001118 *s++ = env_get_char (j);
wdenk47d1a6e2002-11-03 00:01:44 +00001119 *s++ = '\0';
1120 }
1121 *ss++ = NULL; /* terminate */
1122
Marian Balakowicz2df645e2008-01-08 18:17:10 +01001123 entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
1124 (*entry) (kbd, cmdline, fwenv, top);
wdenk47d1a6e2002-11-03 00:01:44 +00001125}
wdenk47d1a6e2002-11-03 00:01:44 +00001126#endif