blob: 79b763ec13648f129a404669f089e965a91c0423 [file] [log] [blame]
wdenk47d1a6e2002-11-03 00:01:44 +00001/*
2 * (C) Copyright 2000-2002
3 * 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
24/*
25 * Boot support
26 */
27#include <common.h>
28#include <watchdog.h>
29#include <command.h>
wdenk47d1a6e2002-11-03 00:01:44 +000030#include <image.h>
31#include <malloc.h>
32#include <zlib.h>
wdenkc29fdfc2003-08-29 20:57:53 +000033#include <bzlib.h>
wdenk7f70e852003-05-20 14:25:27 +000034#include <environment.h>
wdenk47d1a6e2002-11-03 00:01:44 +000035#include <asm/byteorder.h>
wdenk8bde7f72003-06-27 21:31:46 +000036
37 /*cmd_boot.c*/
38 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
39
wdenk47d1a6e2002-11-03 00:01:44 +000040#if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
41#include <rtc.h>
42#endif
43
44#ifdef CFG_HUSH_PARSER
45#include <hush.h>
46#endif
47
48#ifdef CONFIG_SHOW_BOOT_PROGRESS
49# include <status_led.h>
50# define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
51#else
52# define SHOW_BOOT_PROGRESS(arg)
53#endif
54
55#ifdef CFG_INIT_RAM_LOCK
56#include <asm/cache.h>
57#endif
58
wdenk228f29a2002-12-08 09:53:23 +000059#ifdef CONFIG_LOGBUFFER
60#include <logbuff.h>
61#endif
62
wdenk2abbe072003-06-16 23:50:08 +000063#ifdef CONFIG_HAS_DATAFLASH
64#include <dataflash.h>
65#endif
66
wdenk47d1a6e2002-11-03 00:01:44 +000067/*
68 * Some systems (for example LWMON) have very short watchdog periods;
69 * we must make sure to split long operations like memmove() or
70 * crc32() into reasonable chunks.
71 */
72#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
73# define CHUNKSZ (64 * 1024)
74#endif
75
76int gunzip (void *, int, unsigned char *, int *);
77
78static void *zalloc(void *, unsigned, unsigned);
79static void zfree(void *, void *, unsigned);
80
81#if (CONFIG_COMMANDS & CFG_CMD_IMI)
82static int image_info (unsigned long addr);
83#endif
wdenk27b207f2003-07-24 23:38:38 +000084
85#if (CONFIG_COMMANDS & CFG_CMD_IMLS)
86#include <flash.h>
87extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
88static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
89#endif
90
wdenk47d1a6e2002-11-03 00:01:44 +000091static void print_type (image_header_t *hdr);
92
wdenk2262cfe2002-11-18 00:14:45 +000093#ifdef __I386__
94image_header_t *fake_header(image_header_t *hdr, void *ptr, int size);
95#endif
96
wdenk47d1a6e2002-11-03 00:01:44 +000097/*
98 * Continue booting an OS image; caller already has:
99 * - copied image header to global variable `header'
100 * - checked header magic number, checksums (both header & image),
101 * - verified image architecture (PPC) and type (KERNEL or MULTI),
102 * - loaded (first part of) image to header load address,
103 * - disabled interrupts.
104 */
105typedef void boot_os_Fcn (cmd_tbl_t *cmdtp, int flag,
106 int argc, char *argv[],
107 ulong addr, /* of image to boot */
108 ulong *len_ptr, /* multi-file image length table */
109 int verify); /* getenv("verify")[0] != 'n' */
110
wdenk8bde7f72003-06-27 21:31:46 +0000111#ifdef DEBUG
112extern int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
113#endif
114
wdenk2262cfe2002-11-18 00:14:45 +0000115#ifdef CONFIG_PPC
wdenk47d1a6e2002-11-03 00:01:44 +0000116static boot_os_Fcn do_bootm_linux;
117#else
118extern boot_os_Fcn do_bootm_linux;
119#endif
120static boot_os_Fcn do_bootm_netbsd;
wdenkd791b1d2003-04-20 14:04:18 +0000121static boot_os_Fcn do_bootm_rtems;
wdenk47d1a6e2002-11-03 00:01:44 +0000122#if (CONFIG_COMMANDS & CFG_CMD_ELF)
123static boot_os_Fcn do_bootm_vxworks;
124static boot_os_Fcn do_bootm_qnxelf;
125int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
126int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
127#endif /* CFG_CMD_ELF */
wdenk7f70e852003-05-20 14:25:27 +0000128#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
129static boot_os_Fcn do_bootm_artos;
130#endif
wdenk1f4bb372003-07-27 00:21:01 +0000131#ifdef CONFIG_LYNXKDI
132static boot_os_Fcn do_bootm_lynxkdi;
133extern void lynxkdi_boot( image_header_t * );
134#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000135
136image_header_t header;
137
138ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
139
140int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
141{
142 ulong iflag;
143 ulong addr;
144 ulong data, len, checksum;
145 ulong *len_ptr;
wdenkc29fdfc2003-08-29 20:57:53 +0000146 uint unc_len = 0x400000;
wdenk47d1a6e2002-11-03 00:01:44 +0000147 int i, verify;
148 char *name, *s;
149 int (*appl)(cmd_tbl_t *, int, int, char *[]);
150 image_header_t *hdr = &header;
151
152 s = getenv ("verify");
153 verify = (s && (*s == 'n')) ? 0 : 1;
154
155 if (argc < 2) {
156 addr = load_addr;
157 } else {
158 addr = simple_strtoul(argv[1], NULL, 16);
159 }
160
161 SHOW_BOOT_PROGRESS (1);
162 printf ("## Booting image at %08lx ...\n", addr);
163
164 /* Copy header so we can blank CRC field for re-calculation */
wdenk2abbe072003-06-16 23:50:08 +0000165#ifdef CONFIG_HAS_DATAFLASH
166 if (addr_dataflash(addr)){
167 read_dataflash(addr, sizeof(image_header_t), (char *)&header);
168 } else
169#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000170 memmove (&header, (char *)addr, sizeof(image_header_t));
171
172 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
wdenk2262cfe2002-11-18 00:14:45 +0000173#ifdef __I386__ /* correct image format not implemented yet - fake it */
174 if (fake_header(hdr, (void*)addr, -1) != NULL) {
175 /* to compensate for the addition below */
176 addr -= sizeof(image_header_t);
177 /* turnof verify,
178 * fake_header() does not fake the data crc
179 */
180 verify = 0;
181 } else
182#endif /* __I386__ */
183 {
wdenk47d1a6e2002-11-03 00:01:44 +0000184 printf ("Bad Magic Number\n");
185 SHOW_BOOT_PROGRESS (-1);
186 return 1;
wdenk2262cfe2002-11-18 00:14:45 +0000187 }
wdenk47d1a6e2002-11-03 00:01:44 +0000188 }
189 SHOW_BOOT_PROGRESS (2);
190
191 data = (ulong)&header;
192 len = sizeof(image_header_t);
193
194 checksum = ntohl(hdr->ih_hcrc);
195 hdr->ih_hcrc = 0;
196
197 if (crc32 (0, (char *)data, len) != checksum) {
198 printf ("Bad Header Checksum\n");
199 SHOW_BOOT_PROGRESS (-2);
200 return 1;
201 }
202 SHOW_BOOT_PROGRESS (3);
203
204 /* for multi-file images we need the data part, too */
wdenk2262cfe2002-11-18 00:14:45 +0000205 print_image_hdr (hdr);
wdenk47d1a6e2002-11-03 00:01:44 +0000206
207 data = addr + sizeof(image_header_t);
208 len = ntohl(hdr->ih_size);
209
wdenk2abbe072003-06-16 23:50:08 +0000210#ifdef CONFIG_HAS_DATAFLASH
211 if (addr_dataflash(addr)){
212 read_dataflash(data, len, (char *)CFG_LOAD_ADDR);
213 data = CFG_LOAD_ADDR;
214 }
wdenk8bde7f72003-06-27 21:31:46 +0000215#endif
wdenk2abbe072003-06-16 23:50:08 +0000216
wdenk47d1a6e2002-11-03 00:01:44 +0000217 if (verify) {
218 printf (" Verifying Checksum ... ");
219 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
220 printf ("Bad Data CRC\n");
221 SHOW_BOOT_PROGRESS (-3);
222 return 1;
223 }
224 printf ("OK\n");
225 }
226 SHOW_BOOT_PROGRESS (4);
227
228 len_ptr = (ulong *)data;
229
wdenk2262cfe2002-11-18 00:14:45 +0000230#if defined(__PPC__)
231 if (hdr->ih_arch != IH_CPU_PPC)
232#elif defined(__ARM__)
233 if (hdr->ih_arch != IH_CPU_ARM)
234#elif defined(__I386__)
235 if (hdr->ih_arch != IH_CPU_I386)
wdenk6069ff22003-02-28 00:49:47 +0000236#elif defined(__mips__)
wdenk8bde7f72003-06-27 21:31:46 +0000237 if (hdr->ih_arch != IH_CPU_MIPS)
wdenk4a551702003-10-08 23:26:14 +0000238#elif defined(__nios__)
239 if (hdr->ih_arch != IH_CPU_NIOS)
wdenk2262cfe2002-11-18 00:14:45 +0000240#else
241# error Unknown CPU type
242#endif
243 {
244 printf ("Unsupported Architecture 0x%x\n", hdr->ih_arch);
wdenk47d1a6e2002-11-03 00:01:44 +0000245 SHOW_BOOT_PROGRESS (-4);
246 return 1;
247 }
248 SHOW_BOOT_PROGRESS (5);
249
250 switch (hdr->ih_type) {
251 case IH_TYPE_STANDALONE: name = "Standalone Application";
wdenk4a551702003-10-08 23:26:14 +0000252 /* A second argument overwrites the load address */
253 if (argc > 2) {
254 hdr->ih_load = simple_strtoul(argv[2], NULL, 16);
255 }
wdenk47d1a6e2002-11-03 00:01:44 +0000256 break;
257 case IH_TYPE_KERNEL: name = "Kernel Image";
258 break;
259 case IH_TYPE_MULTI: name = "Multi-File Image";
260 len = ntohl(len_ptr[0]);
261 /* OS kernel is always the first image */
262 data += 8; /* kernel_len + terminator */
263 for (i=1; len_ptr[i]; ++i)
264 data += 4;
265 break;
266 default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
267 SHOW_BOOT_PROGRESS (-5);
268 return 1;
269 }
270 SHOW_BOOT_PROGRESS (6);
271
272 /*
273 * We have reached the point of no return: we are going to
274 * overwrite all exception vector code, so we cannot easily
275 * recover from any failures any more...
276 */
277
278 iflag = disable_interrupts();
279
wdenkc7de8292002-11-19 11:04:11 +0000280#ifdef CONFIG_AMIGAONEG3SE
281 /*
wdenk8bde7f72003-06-27 21:31:46 +0000282 * We've possible left the caches enabled during
wdenkc7de8292002-11-19 11:04:11 +0000283 * bios emulation, so turn them off again
284 */
285 icache_disable();
286 invalidate_l1_instruction_cache();
287 flush_data_cache();
288 dcache_disable();
289#endif
290
wdenk47d1a6e2002-11-03 00:01:44 +0000291 switch (hdr->ih_comp) {
292 case IH_COMP_NONE:
wdenk2262cfe2002-11-18 00:14:45 +0000293 if(ntohl(hdr->ih_load) == addr) {
wdenk47d1a6e2002-11-03 00:01:44 +0000294 printf (" XIP %s ... ", name);
295 } else {
296#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
297 size_t l = len;
298 void *to = (void *)ntohl(hdr->ih_load);
299 void *from = (void *)data;
300
301 printf (" Loading %s ... ", name);
302
303 while (l > 0) {
304 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
305 WATCHDOG_RESET();
306 memmove (to, from, tail);
307 to += tail;
308 from += tail;
309 l -= tail;
310 }
311#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
312 memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
313#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
314 }
315 break;
316 case IH_COMP_GZIP:
317 printf (" Uncompressing %s ... ", name);
wdenkc29fdfc2003-08-29 20:57:53 +0000318 if (gunzip ((void *)ntohl(hdr->ih_load), unc_len,
wdenk47d1a6e2002-11-03 00:01:44 +0000319 (uchar *)data, (int *)&len) != 0) {
320 printf ("GUNZIP ERROR - must RESET board to recover\n");
321 SHOW_BOOT_PROGRESS (-6);
322 do_reset (cmdtp, flag, argc, argv);
323 }
324 break;
wdenkc29fdfc2003-08-29 20:57:53 +0000325#ifdef CONFIG_BZIP2
326 case IH_COMP_BZIP2:
327 printf (" Uncompressing %s ... ", name);
328 i = BZ2_bzBuffToBuffDecompress ((char*)ntohl(hdr->ih_load),
329 &unc_len, (char *)data, len, 0, 0);
330 if (i != BZ_OK) {
331 printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
332 SHOW_BOOT_PROGRESS (-6);
333 udelay(100000);
334 do_reset (cmdtp, flag, argc, argv);
335 }
336 break;
337#endif /* CONFIG_BZIP2 */
wdenk47d1a6e2002-11-03 00:01:44 +0000338 default:
339 if (iflag)
340 enable_interrupts();
341 printf ("Unimplemented compression type %d\n", hdr->ih_comp);
342 SHOW_BOOT_PROGRESS (-7);
343 return 1;
344 }
345 printf ("OK\n");
346 SHOW_BOOT_PROGRESS (7);
347
348 switch (hdr->ih_type) {
349 case IH_TYPE_STANDALONE:
wdenk47d1a6e2002-11-03 00:01:44 +0000350 if (iflag)
351 enable_interrupts();
352
wdenk4a6fd342003-04-12 23:38:12 +0000353 /* load (and uncompress), but don't start if "autostart"
354 * is set to "no"
355 */
wdenk4a551702003-10-08 23:26:14 +0000356 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0)) {
357 char buf[32];
358 sprintf(buf, "%lX", len);
359 setenv("filesize", buf);
wdenk4a6fd342003-04-12 23:38:12 +0000360 return 0;
wdenk4a551702003-10-08 23:26:14 +0000361 }
wdenk4a6fd342003-04-12 23:38:12 +0000362 appl = (int (*)(cmd_tbl_t *, int, int, char *[]))ntohl(hdr->ih_ep);
wdenk47d1a6e2002-11-03 00:01:44 +0000363 (*appl)(cmdtp, flag, argc-1, &argv[1]);
wdenk4a6fd342003-04-12 23:38:12 +0000364 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000365 case IH_TYPE_KERNEL:
366 case IH_TYPE_MULTI:
367 /* handled below */
368 break;
369 default:
370 if (iflag)
371 enable_interrupts();
372 printf ("Can't boot image type %d\n", hdr->ih_type);
373 SHOW_BOOT_PROGRESS (-8);
374 return 1;
375 }
376 SHOW_BOOT_PROGRESS (8);
377
378 switch (hdr->ih_os) {
379 default: /* handled by (original) Linux case */
380 case IH_OS_LINUX:
381 do_bootm_linux (cmdtp, flag, argc, argv,
382 addr, len_ptr, verify);
383 break;
384 case IH_OS_NETBSD:
385 do_bootm_netbsd (cmdtp, flag, argc, argv,
386 addr, len_ptr, verify);
387 break;
wdenk8bde7f72003-06-27 21:31:46 +0000388
wdenk1f4bb372003-07-27 00:21:01 +0000389#ifdef CONFIG_LYNXKDI
390 case IH_OS_LYNXOS:
391 do_bootm_lynxkdi (cmdtp, flag, argc, argv,
392 addr, len_ptr, verify);
393 break;
394#endif
395
wdenkd791b1d2003-04-20 14:04:18 +0000396 case IH_OS_RTEMS:
397 do_bootm_rtems (cmdtp, flag, argc, argv,
398 addr, len_ptr, verify);
399 break;
wdenk8bde7f72003-06-27 21:31:46 +0000400
wdenk47d1a6e2002-11-03 00:01:44 +0000401#if (CONFIG_COMMANDS & CFG_CMD_ELF)
402 case IH_OS_VXWORKS:
403 do_bootm_vxworks (cmdtp, flag, argc, argv,
404 addr, len_ptr, verify);
405 break;
406 case IH_OS_QNX:
407 do_bootm_qnxelf (cmdtp, flag, argc, argv,
408 addr, len_ptr, verify);
409 break;
410#endif /* CFG_CMD_ELF */
wdenk7f70e852003-05-20 14:25:27 +0000411#ifdef CONFIG_ARTOS
412 case IH_OS_ARTOS:
413 do_bootm_artos (cmdtp, flag, argc, argv,
414 addr, len_ptr, verify);
415 break;
416#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000417 }
418
419 SHOW_BOOT_PROGRESS (-9);
420#ifdef DEBUG
421 printf ("\n## Control returned to monitor - resetting...\n");
422 do_reset (cmdtp, flag, argc, argv);
423#endif
424 return 1;
425}
426
wdenk0d498392003-07-01 21:06:45 +0000427U_BOOT_CMD(
428 bootm, CFG_MAXARGS, 1, do_bootm,
wdenk8bde7f72003-06-27 21:31:46 +0000429 "bootm - boot application image from memory\n",
430 "[addr [arg ...]]\n - boot application image stored in memory\n"
431 " passing arguments 'arg ...'; when booting a Linux kernel,\n"
432 " 'arg' can be the address of an initrd image\n"
433);
434
wdenk2262cfe2002-11-18 00:14:45 +0000435#ifdef CONFIG_PPC
wdenk47d1a6e2002-11-03 00:01:44 +0000436static void
437do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
438 int argc, char *argv[],
439 ulong addr,
440 ulong *len_ptr,
441 int verify)
442{
443 DECLARE_GLOBAL_DATA_PTR;
444
445 ulong sp;
446 ulong len, checksum;
447 ulong initrd_start, initrd_end;
448 ulong cmd_start, cmd_end;
449 ulong initrd_high;
450 ulong data;
wdenk38b99262003-05-23 23:18:21 +0000451 int initrd_copy_to_ram = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000452 char *cmdline;
453 char *s;
454 bd_t *kbd;
455 void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
456 image_header_t *hdr = &header;
457
458 if ((s = getenv ("initrd_high")) != NULL) {
459 /* a value of "no" or a similar string will act like 0,
460 * turning the "load high" feature off. This is intentional.
461 */
462 initrd_high = simple_strtoul(s, NULL, 16);
wdenk38b99262003-05-23 23:18:21 +0000463 if (initrd_high == ~0)
464 initrd_copy_to_ram = 0;
wdenk228f29a2002-12-08 09:53:23 +0000465 } else { /* not set, no restrictions to load high */
wdenk47d1a6e2002-11-03 00:01:44 +0000466 initrd_high = ~0;
467 }
468
wdenk56f94be2002-11-05 16:35:14 +0000469#ifdef CONFIG_LOGBUFFER
wdenk6aff3112002-12-17 01:51:00 +0000470 kbd=gd->bd;
wdenk228f29a2002-12-08 09:53:23 +0000471 /* Prevent initrd from overwriting logbuffer */
472 if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
473 initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
474 debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
wdenk56f94be2002-11-05 16:35:14 +0000475#endif
476
wdenk47d1a6e2002-11-03 00:01:44 +0000477 /*
478 * Booting a (Linux) kernel image
479 *
480 * Allocate space for command line and board info - the
481 * address should be as high as possible within the reach of
482 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
483 * memory, which means far enough below the current stack
484 * pointer.
485 */
486
487 asm( "mr %0,1": "=r"(sp) : );
488
wdenk56f94be2002-11-05 16:35:14 +0000489 debug ("## Current stack ends at 0x%08lX ", sp);
490
wdenk47d1a6e2002-11-03 00:01:44 +0000491 sp -= 2048; /* just to be sure */
492 if (sp > CFG_BOOTMAPSZ)
493 sp = CFG_BOOTMAPSZ;
494 sp &= ~0xF;
495
wdenk56f94be2002-11-05 16:35:14 +0000496 debug ("=> set upper limit to 0x%08lX\n", sp);
497
wdenk47d1a6e2002-11-03 00:01:44 +0000498 cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
499 kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
500
501 if ((s = getenv("bootargs")) == NULL)
502 s = "";
503
504 strcpy (cmdline, s);
505
506 cmd_start = (ulong)&cmdline[0];
507 cmd_end = cmd_start + strlen(cmdline);
508
509 *kbd = *(gd->bd);
510
511#ifdef DEBUG
512 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
513
514 do_bdinfo (NULL, 0, 0, NULL);
515#endif
516
517 if ((s = getenv ("clocks_in_mhz")) != NULL) {
518 /* convert all clock information to MHz */
519 kbd->bi_intfreq /= 1000000L;
520 kbd->bi_busfreq /= 1000000L;
521#if defined(CONFIG_8260)
522 kbd->bi_cpmfreq /= 1000000L;
523 kbd->bi_brgfreq /= 1000000L;
524 kbd->bi_sccfreq /= 1000000L;
525 kbd->bi_vco /= 1000000L;
526#endif /* CONFIG_8260 */
wdenk945af8d2003-07-16 21:53:01 +0000527#if defined(CONFIG_MPC5XXXX)
528 kbd->bi_ipbfreq /= 1000000L;
529 kbd->bi_pcifreq /= 1000000L;
530#endif /* CONFIG_MPC5XXXX */
wdenk47d1a6e2002-11-03 00:01:44 +0000531 }
532
533 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep;
534
535 /*
536 * Check if there is an initrd image
537 */
538 if (argc >= 3) {
539 SHOW_BOOT_PROGRESS (9);
540
541 addr = simple_strtoul(argv[2], NULL, 16);
542
543 printf ("## Loading RAMDisk Image at %08lx ...\n", addr);
544
545 /* Copy header so we can blank CRC field for re-calculation */
546 memmove (&header, (char *)addr, sizeof(image_header_t));
547
548 if (hdr->ih_magic != IH_MAGIC) {
549 printf ("Bad Magic Number\n");
550 SHOW_BOOT_PROGRESS (-10);
551 do_reset (cmdtp, flag, argc, argv);
552 }
553
554 data = (ulong)&header;
555 len = sizeof(image_header_t);
556
557 checksum = hdr->ih_hcrc;
558 hdr->ih_hcrc = 0;
559
560 if (crc32 (0, (char *)data, len) != checksum) {
561 printf ("Bad Header Checksum\n");
562 SHOW_BOOT_PROGRESS (-11);
563 do_reset (cmdtp, flag, argc, argv);
564 }
565
566 SHOW_BOOT_PROGRESS (10);
567
568 print_image_hdr (hdr);
569
570 data = addr + sizeof(image_header_t);
571 len = hdr->ih_size;
572
573 if (verify) {
574 ulong csum = 0;
575#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
576 ulong cdata = data, edata = cdata + len;
577#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
578
579 printf (" Verifying Checksum ... ");
580
581#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
582
583 while (cdata < edata) {
584 ulong chunk = edata - cdata;
585
586 if (chunk > CHUNKSZ)
587 chunk = CHUNKSZ;
588 csum = crc32 (csum, (char *)cdata, chunk);
589 cdata += chunk;
590
591 WATCHDOG_RESET();
592 }
593#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
594 csum = crc32 (0, (char *)data, len);
595#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
596
597 if (csum != hdr->ih_dcrc) {
598 printf ("Bad Data CRC\n");
599 SHOW_BOOT_PROGRESS (-12);
600 do_reset (cmdtp, flag, argc, argv);
601 }
602 printf ("OK\n");
603 }
604
605 SHOW_BOOT_PROGRESS (11);
606
607 if ((hdr->ih_os != IH_OS_LINUX) ||
608 (hdr->ih_arch != IH_CPU_PPC) ||
609 (hdr->ih_type != IH_TYPE_RAMDISK) ) {
610 printf ("No Linux PPC Ramdisk Image\n");
611 SHOW_BOOT_PROGRESS (-13);
612 do_reset (cmdtp, flag, argc, argv);
613 }
614
615 /*
616 * Now check if we have a multifile image
617 */
618 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
619 u_long tail = ntohl(len_ptr[0]) % 4;
620 int i;
621
622 SHOW_BOOT_PROGRESS (13);
623
624 /* skip kernel length and terminator */
625 data = (ulong)(&len_ptr[2]);
626 /* skip any additional image length fields */
627 for (i=1; len_ptr[i]; ++i)
628 data += 4;
629 /* add kernel length, and align */
630 data += ntohl(len_ptr[0]);
631 if (tail) {
632 data += 4 - tail;
633 }
634
635 len = ntohl(len_ptr[1]);
636
637 } else {
638 /*
639 * no initrd image
640 */
641 SHOW_BOOT_PROGRESS (14);
642
643 len = data = 0;
644 }
645
wdenk47d1a6e2002-11-03 00:01:44 +0000646 if (!data) {
wdenk56f94be2002-11-05 16:35:14 +0000647 debug ("No initrd\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000648 }
wdenk47d1a6e2002-11-03 00:01:44 +0000649
650 if (data) {
wdenk38b99262003-05-23 23:18:21 +0000651 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
652 initrd_start = data;
653 initrd_end = initrd_start + len;
654 } else {
wdenk47d1a6e2002-11-03 00:01:44 +0000655 initrd_start = (ulong)kbd - len;
656 initrd_start &= ~(4096 - 1); /* align on page */
657
658 if (initrd_high) {
659 ulong nsp;
660
661 /*
662 * the inital ramdisk does not need to be within
663 * CFG_BOOTMAPSZ as it is not accessed until after
664 * the mm system is initialised.
665 *
666 * do the stack bottom calculation again and see if
667 * the initrd will fit just below the monitor stack
668 * bottom without overwriting the area allocated
669 * above for command line args and board info.
670 */
671 asm( "mr %0,1": "=r"(nsp) : );
672 nsp -= 2048; /* just to be sure */
673 nsp &= ~0xF;
674 if (nsp > initrd_high) /* limit as specified */
675 nsp = initrd_high;
676 nsp -= len;
677 nsp &= ~(4096 - 1); /* align on page */
678 if (nsp >= sp)
679 initrd_start = nsp;
680 }
681
682 SHOW_BOOT_PROGRESS (12);
wdenk56f94be2002-11-05 16:35:14 +0000683
684 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
wdenk47d1a6e2002-11-03 00:01:44 +0000685 data, data + len - 1, len, len);
wdenk56f94be2002-11-05 16:35:14 +0000686
wdenk47d1a6e2002-11-03 00:01:44 +0000687 initrd_end = initrd_start + len;
688 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
689 initrd_start, initrd_end);
690#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
691 {
692 size_t l = len;
693 void *to = (void *)initrd_start;
694 void *from = (void *)data;
695
696 while (l > 0) {
697 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
698 WATCHDOG_RESET();
699 memmove (to, from, tail);
700 to += tail;
701 from += tail;
702 l -= tail;
703 }
704 }
705#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
706 memmove ((void *)initrd_start, (void *)data, len);
707#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
708 printf ("OK\n");
wdenk38b99262003-05-23 23:18:21 +0000709 }
wdenk47d1a6e2002-11-03 00:01:44 +0000710 } else {
711 initrd_start = 0;
712 initrd_end = 0;
713 }
714
wdenk56f94be2002-11-05 16:35:14 +0000715
716 debug ("## Transferring control to Linux (at address %08lx) ...\n",
wdenk47d1a6e2002-11-03 00:01:44 +0000717 (ulong)kernel);
wdenk56f94be2002-11-05 16:35:14 +0000718
wdenk47d1a6e2002-11-03 00:01:44 +0000719 SHOW_BOOT_PROGRESS (15);
720
721#ifdef CFG_INIT_RAM_LOCK
722 unlock_ram_in_cache();
723#endif
724 /*
725 * Linux Kernel Parameters:
726 * r3: ptr to board info data
727 * r4: initrd_start or 0 if no initrd
728 * r5: initrd_end - unused if r4 is 0
729 * r6: Start of command line string
730 * r7: End of command line string
731 */
732 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
733}
wdenk1cb8e982003-03-06 21:55:29 +0000734#endif /* CONFIG_PPC */
wdenk47d1a6e2002-11-03 00:01:44 +0000735
736static void
737do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
738 int argc, char *argv[],
739 ulong addr,
740 ulong *len_ptr,
741 int verify)
742{
743 DECLARE_GLOBAL_DATA_PTR;
744
745 image_header_t *hdr = &header;
746
747 void (*loader)(bd_t *, image_header_t *, char *, char *);
748 image_header_t *img_addr;
749 char *consdev;
750 char *cmdline;
751
752
753 /*
754 * Booting a (NetBSD) kernel image
755 *
756 * This process is pretty similar to a standalone application:
757 * The (first part of an multi-) image must be a stage-2 loader,
758 * which in turn is responsible for loading & invoking the actual
759 * kernel. The only differences are the parameters being passed:
760 * besides the board info strucure, the loader expects a command
761 * line, the name of the console device, and (optionally) the
762 * address of the original image header.
763 */
764
765 img_addr = 0;
766 if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]))
767 img_addr = (image_header_t *) addr;
768
769
770 consdev = "";
771#if defined (CONFIG_8xx_CONS_SMC1)
772 consdev = "smc1";
773#elif defined (CONFIG_8xx_CONS_SMC2)
774 consdev = "smc2";
775#elif defined (CONFIG_8xx_CONS_SCC2)
776 consdev = "scc2";
777#elif defined (CONFIG_8xx_CONS_SCC3)
778 consdev = "scc3";
779#endif
780
781 if (argc > 2) {
782 ulong len;
783 int i;
784
785 for (i=2, len=0 ; i<argc ; i+=1)
786 len += strlen (argv[i]) + 1;
787 cmdline = malloc (len);
788
789 for (i=2, len=0 ; i<argc ; i+=1) {
790 if (i > 2)
791 cmdline[len++] = ' ';
792 strcpy (&cmdline[len], argv[i]);
793 len += strlen (argv[i]);
794 }
795 } else if ((cmdline = getenv("bootargs")) == NULL) {
796 cmdline = "";
797 }
798
799 loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
800
801 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
802 (ulong)loader);
803
804 SHOW_BOOT_PROGRESS (15);
805
806 /*
807 * NetBSD Stage-2 Loader Parameters:
808 * r3: ptr to board info data
809 * r4: image address
810 * r5: console device
811 * r6: boot args string
812 */
813 (*loader) (gd->bd, img_addr, consdev, cmdline);
814}
815
wdenk7f70e852003-05-20 14:25:27 +0000816#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
817
818/* Function that returns a character from the environment */
819extern uchar (*env_get_char)(int);
820
821static void
822do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
823 int argc, char *argv[],
824 ulong addr,
825 ulong *len_ptr,
826 int verify)
827{
828 DECLARE_GLOBAL_DATA_PTR;
829 ulong top;
830 char *s, *cmdline;
831 char **fwenv, **ss;
832 int i, j, nxt, len, envno, envsz;
833 bd_t *kbd;
834 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
835 image_header_t *hdr = &header;
836
837 /*
838 * Booting an ARTOS kernel image + application
839 */
840
841 /* this used to be the top of memory, but was wrong... */
842#ifdef CONFIG_PPC
843 /* get stack pointer */
844 asm volatile ("mr %0,1" : "=r"(top) );
845#endif
846 debug ("## Current stack ends at 0x%08lX ", top);
847
848 top -= 2048; /* just to be sure */
849 if (top > CFG_BOOTMAPSZ)
850 top = CFG_BOOTMAPSZ;
851 top &= ~0xF;
852
853 debug ("=> set upper limit to 0x%08lX\n", top);
854
855 /* first check the artos specific boot args, then the linux args*/
856 if ((s = getenv("abootargs")) == NULL && (s = getenv("bootargs")) == NULL)
857 s = "";
858
859 /* get length of cmdline, and place it */
860 len = strlen(s);
861 top = (top - (len + 1)) & ~0xF;
862 cmdline = (char *)top;
863 debug ("## cmdline at 0x%08lX ", top);
864 strcpy(cmdline, s);
865
866 /* copy bdinfo */
867 top = (top - sizeof(bd_t)) & ~0xF;
868 debug ("## bd at 0x%08lX ", top);
869 kbd = (bd_t *)top;
870 memcpy(kbd, gd->bd, sizeof(bd_t));
871
872 /* first find number of env entries, and their size */
873 envno = 0;
874 envsz = 0;
875 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
876 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
877 ;
878 envno++;
879 envsz += (nxt - i) + 1; /* plus trailing zero */
880 }
881 envno++; /* plus the terminating zero */
882 debug ("## %u envvars total size %u ", envno, envsz);
883
884 top = (top - sizeof(char **)*envno) & ~0xF;
885 fwenv = (char **)top;
886 debug ("## fwenv at 0x%08lX ", top);
887
888 top = (top - envsz) & ~0xF;
889 s = (char *)top;
890 ss = fwenv;
891
892 /* now copy them */
893 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
894 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
895 ;
896 *ss++ = s;
897 for (j = i; j < nxt; ++j)
898 *s++ = env_get_char(j);
899 *s++ = '\0';
900 }
901 *ss++ = NULL; /* terminate */
902
903 entry = (void (*)(bd_t *, char *, char **, ulong))ntohl(hdr->ih_ep);
904 (*entry)(kbd, cmdline, fwenv, top);
905}
906#endif
907
908
wdenk47d1a6e2002-11-03 00:01:44 +0000909#if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
910int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
911{
912 int rcode = 0;
913#ifndef CFG_HUSH_PARSER
914 if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
915#else
916 if (parse_string_outer(getenv("bootcmd"),
917 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
918#endif
919 return rcode;
920}
wdenk8bde7f72003-06-27 21:31:46 +0000921
wdenk0d498392003-07-01 21:06:45 +0000922U_BOOT_CMD(
923 boot, 1, 1, do_bootd,
wdenk9d2b18a2003-06-28 23:11:04 +0000924 "boot - boot default, i.e., run 'bootcmd'\n",
925 NULL
926);
927
928/* keep old command name "bootd" for backward compatibility */
wdenk0d498392003-07-01 21:06:45 +0000929U_BOOT_CMD(
930 bootd, 1, 1, do_bootd,
wdenk8bde7f72003-06-27 21:31:46 +0000931 "bootd - boot default, i.e., run 'bootcmd'\n",
932 NULL
933);
934
wdenk47d1a6e2002-11-03 00:01:44 +0000935#endif
936
937#if (CONFIG_COMMANDS & CFG_CMD_IMI)
938int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
939{
940 int arg;
941 ulong addr;
942 int rcode=0;
943
944 if (argc < 2) {
945 return image_info (load_addr);
946 }
947
948 for (arg=1; arg <argc; ++arg) {
949 addr = simple_strtoul(argv[arg], NULL, 16);
950 if (image_info (addr) != 0) rcode = 1;
951 }
952 return rcode;
953}
954
955static int image_info (ulong addr)
956{
957 ulong data, len, checksum;
958 image_header_t *hdr = &header;
959
960 printf ("\n## Checking Image at %08lx ...\n", addr);
961
962 /* Copy header so we can blank CRC field for re-calculation */
963 memmove (&header, (char *)addr, sizeof(image_header_t));
964
965 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
966 printf (" Bad Magic Number\n");
967 return 1;
968 }
969
970 data = (ulong)&header;
971 len = sizeof(image_header_t);
972
973 checksum = ntohl(hdr->ih_hcrc);
974 hdr->ih_hcrc = 0;
975
976 if (crc32 (0, (char *)data, len) != checksum) {
977 printf (" Bad Header Checksum\n");
978 return 1;
979 }
980
981 /* for multi-file images we need the data part, too */
982 print_image_hdr ((image_header_t *)addr);
983
984 data = addr + sizeof(image_header_t);
985 len = ntohl(hdr->ih_size);
986
987 printf (" Verifying Checksum ... ");
988 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
989 printf (" Bad Data CRC\n");
990 return 1;
991 }
992 printf ("OK\n");
993 return 0;
994}
wdenk0d498392003-07-01 21:06:45 +0000995
996U_BOOT_CMD(
997 iminfo, CFG_MAXARGS, 1, do_iminfo,
wdenk8bde7f72003-06-27 21:31:46 +0000998 "iminfo - print header information for application image\n",
999 "addr [addr ...]\n"
1000 " - print header information for application image starting at\n"
1001 " address 'addr' in memory; this includes verification of the\n"
1002 " image contents (magic number, header and payload checksums)\n"
1003);
1004
wdenk47d1a6e2002-11-03 00:01:44 +00001005#endif /* CFG_CMD_IMI */
1006
wdenk27b207f2003-07-24 23:38:38 +00001007#if (CONFIG_COMMANDS & CFG_CMD_IMLS)
1008/*-----------------------------------------------------------------------
1009 * List all images found in flash.
1010 */
1011int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1012{
1013 flash_info_t *info;
1014 int i, j;
1015 image_header_t *hdr;
1016 ulong checksum;
1017
1018 for (i=0, info=&flash_info[0]; i<CFG_MAX_FLASH_BANKS; ++i, ++info) {
1019 if (info->flash_id == FLASH_UNKNOWN)
1020 goto next_bank;
1021 for (j=0; j<CFG_MAX_FLASH_SECT; ++j) {
1022
1023 if (!(hdr=(image_header_t *)info->start[j]) ||
1024 (ntohl(hdr->ih_magic) != IH_MAGIC))
1025 goto next_sector;
1026
1027 /* Copy header so we can blank CRC field for re-calculation */
1028 memmove (&header, (char *)hdr, sizeof(image_header_t));
1029
1030 checksum = ntohl(header.ih_hcrc);
1031 header.ih_hcrc = 0;
1032
1033 if (crc32 (0, (char *)&header, sizeof(image_header_t))
1034 != checksum)
1035 goto next_sector;
1036
1037 printf ("Image at %08lX:\n", (ulong)hdr);
1038 print_image_hdr( hdr );
1039 putc ('\n');
wdenkbdccc4f2003-08-05 17:43:17 +00001040next_sector: ;
wdenk27b207f2003-07-24 23:38:38 +00001041 }
wdenkbdccc4f2003-08-05 17:43:17 +00001042next_bank: ;
wdenk27b207f2003-07-24 23:38:38 +00001043 }
1044
1045 return (0);
1046}
1047
1048U_BOOT_CMD(
1049 imls, 1, 1, do_imls,
1050 "imls - list all images found in flash\n",
1051 "\n"
1052 " - Prints information about all images found at sector\n"
1053 " boundaries in flash.\n"
1054);
1055#endif /* CFG_CMD_IMLS */
1056
wdenk47d1a6e2002-11-03 00:01:44 +00001057void
1058print_image_hdr (image_header_t *hdr)
1059{
1060#if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
1061 time_t timestamp = (time_t)ntohl(hdr->ih_time);
1062 struct rtc_time tm;
1063#endif
1064
1065 printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
1066#if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
1067 to_tm (timestamp, &tm);
1068 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
1069 tm.tm_year, tm.tm_mon, tm.tm_mday,
1070 tm.tm_hour, tm.tm_min, tm.tm_sec);
1071#endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
1072 printf (" Image Type: "); print_type(hdr); printf ("\n");
1073 printf (" Data Size: %d Bytes = ", ntohl(hdr->ih_size));
1074 print_size (ntohl(hdr->ih_size), "\n");
1075 printf (" Load Address: %08x\n", ntohl(hdr->ih_load));
1076 printf (" Entry Point: %08x\n", ntohl(hdr->ih_ep));
1077
1078 if (hdr->ih_type == IH_TYPE_MULTI) {
1079 int i;
1080 ulong len;
1081 ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
1082
1083 printf (" Contents:\n");
1084 for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
1085 printf (" Image %d: %8ld Bytes = ", i, len);
1086 print_size (len, "\n");
1087 }
1088 }
1089}
1090
1091
1092static void
1093print_type (image_header_t *hdr)
1094{
1095 char *os, *arch, *type, *comp;
1096
1097 switch (hdr->ih_os) {
1098 case IH_OS_INVALID: os = "Invalid OS"; break;
1099 case IH_OS_NETBSD: os = "NetBSD"; break;
1100 case IH_OS_LINUX: os = "Linux"; break;
1101 case IH_OS_VXWORKS: os = "VxWorks"; break;
1102 case IH_OS_QNX: os = "QNX"; break;
1103 case IH_OS_U_BOOT: os = "U-Boot"; break;
wdenkd791b1d2003-04-20 14:04:18 +00001104 case IH_OS_RTEMS: os = "RTEMS"; break;
wdenk7f70e852003-05-20 14:25:27 +00001105#ifdef CONFIG_ARTOS
1106 case IH_OS_ARTOS: os = "ARTOS"; break;
1107#endif
wdenk1f4bb372003-07-27 00:21:01 +00001108#ifdef CONFIG_LYNXKDI
1109 case IH_OS_LYNXOS: os = "LynxOS"; break;
1110#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001111 default: os = "Unknown OS"; break;
1112 }
1113
1114 switch (hdr->ih_arch) {
1115 case IH_CPU_INVALID: arch = "Invalid CPU"; break;
1116 case IH_CPU_ALPHA: arch = "Alpha"; break;
1117 case IH_CPU_ARM: arch = "ARM"; break;
1118 case IH_CPU_I386: arch = "Intel x86"; break;
1119 case IH_CPU_IA64: arch = "IA64"; break;
1120 case IH_CPU_MIPS: arch = "MIPS"; break;
1121 case IH_CPU_MIPS64: arch = "MIPS 64 Bit"; break;
1122 case IH_CPU_PPC: arch = "PowerPC"; break;
1123 case IH_CPU_S390: arch = "IBM S390"; break;
1124 case IH_CPU_SH: arch = "SuperH"; break;
1125 case IH_CPU_SPARC: arch = "SPARC"; break;
1126 case IH_CPU_SPARC64: arch = "SPARC 64 Bit"; break;
wdenk8564acf2003-07-14 22:13:32 +00001127 case IH_CPU_M68K: arch = "M68K"; break;
wdenk47d1a6e2002-11-03 00:01:44 +00001128 default: arch = "Unknown Architecture"; break;
1129 }
1130
1131 switch (hdr->ih_type) {
1132 case IH_TYPE_INVALID: type = "Invalid Image"; break;
1133 case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
1134 case IH_TYPE_KERNEL: type = "Kernel Image"; break;
1135 case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
1136 case IH_TYPE_MULTI: type = "Multi-File Image"; break;
1137 case IH_TYPE_FIRMWARE: type = "Firmware"; break;
1138 case IH_TYPE_SCRIPT: type = "Script"; break;
1139 default: type = "Unknown Image"; break;
1140 }
1141
1142 switch (hdr->ih_comp) {
1143 case IH_COMP_NONE: comp = "uncompressed"; break;
1144 case IH_COMP_GZIP: comp = "gzip compressed"; break;
1145 case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
1146 default: comp = "unknown compression"; break;
1147 }
1148
1149 printf ("%s %s %s (%s)", arch, os, type, comp);
1150}
1151
1152#define ZALLOC_ALIGNMENT 16
1153
1154static void *zalloc(void *x, unsigned items, unsigned size)
1155{
1156 void *p;
1157
1158 size *= items;
1159 size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
1160
1161 p = malloc (size);
1162
1163 return (p);
1164}
1165
1166static void zfree(void *x, void *addr, unsigned nb)
1167{
1168 free (addr);
1169}
1170
1171#define HEAD_CRC 2
1172#define EXTRA_FIELD 4
1173#define ORIG_NAME 8
1174#define COMMENT 0x10
1175#define RESERVED 0xe0
1176
1177#define DEFLATED 8
1178
1179int gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
1180{
1181 z_stream s;
1182 int r, i, flags;
1183
1184 /* skip header */
1185 i = 10;
1186 flags = src[3];
1187 if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
1188 printf ("Error: Bad gzipped data\n");
1189 return (-1);
1190 }
1191 if ((flags & EXTRA_FIELD) != 0)
1192 i = 12 + src[10] + (src[11] << 8);
1193 if ((flags & ORIG_NAME) != 0)
1194 while (src[i++] != 0)
1195 ;
1196 if ((flags & COMMENT) != 0)
1197 while (src[i++] != 0)
1198 ;
1199 if ((flags & HEAD_CRC) != 0)
1200 i += 2;
1201 if (i >= *lenp) {
1202 printf ("Error: gunzip out of data in header\n");
1203 return (-1);
1204 }
1205
1206 s.zalloc = zalloc;
1207 s.zfree = zfree;
1208#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
1209 s.outcb = (cb_func)WATCHDOG_RESET;
1210#else
1211 s.outcb = Z_NULL;
1212#endif /* CONFIG_HW_WATCHDOG */
1213
1214 r = inflateInit2(&s, -MAX_WBITS);
1215 if (r != Z_OK) {
1216 printf ("Error: inflateInit2() returned %d\n", r);
1217 return (-1);
1218 }
1219 s.next_in = src + i;
1220 s.avail_in = *lenp - i;
1221 s.next_out = dst;
1222 s.avail_out = dstlen;
1223 r = inflate(&s, Z_FINISH);
1224 if (r != Z_OK && r != Z_STREAM_END) {
1225 printf ("Error: inflate() returned %d\n", r);
1226 return (-1);
1227 }
1228 *lenp = s.next_out - (unsigned char *) dst;
1229 inflateEnd(&s);
1230
1231 return (0);
1232}
1233
wdenkc29fdfc2003-08-29 20:57:53 +00001234#ifdef CONFIG_BZIP2
1235void bz_internal_error(int errcode)
1236{
1237 printf ("BZIP2 internal error %d\n", errcode);
1238}
1239#endif /* CONFIG_BZIP2 */
1240
wdenkd791b1d2003-04-20 14:04:18 +00001241static void
1242do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1243 ulong addr, ulong *len_ptr, int verify)
1244{
1245 DECLARE_GLOBAL_DATA_PTR;
1246 image_header_t *hdr = &header;
1247 void (*entry_point)(bd_t *);
1248
1249 entry_point = (void (*)(bd_t *)) hdr->ih_ep;
1250
1251 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1252 (ulong)entry_point);
1253
1254 SHOW_BOOT_PROGRESS (15);
1255
1256 /*
1257 * RTEMS Parameters:
1258 * r3: ptr to board info data
1259 */
1260
1261 (*entry_point ) ( gd->bd );
1262}
1263
wdenk47d1a6e2002-11-03 00:01:44 +00001264#if (CONFIG_COMMANDS & CFG_CMD_ELF)
1265static void
1266do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1267 ulong addr, ulong *len_ptr, int verify)
1268{
1269 image_header_t *hdr = &header;
1270 char str[80];
1271
1272 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1273 setenv("loadaddr", str);
1274 do_bootvx(cmdtp, 0, 0, NULL);
1275}
1276
1277static void
1278do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1279 ulong addr, ulong *len_ptr, int verify)
1280{
1281 image_header_t *hdr = &header;
1282 char *local_args[2];
1283 char str[16];
1284
1285 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1286 local_args[0] = argv[0];
1287 local_args[1] = str; /* and provide it via the arguments */
1288 do_bootelf(cmdtp, 0, 2, local_args);
1289}
1290#endif /* CFG_CMD_ELF */
wdenk1f4bb372003-07-27 00:21:01 +00001291
1292#ifdef CONFIG_LYNXKDI
1293static void
1294do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
1295 int argc, char *argv[],
1296 ulong addr,
1297 ulong *len_ptr,
1298 int verify)
1299{
1300 lynxkdi_boot( &header );
1301}
1302
1303#endif /* CONFIG_LYNXKDI */
1304