blob: 852eefd28f70d6d1b6986717ab37d45c4aeb38ff [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
wdenkf72da342003-10-10 10:05:42 +0000120#ifdef CONFIG_SILENT_CONSOLE
121static void fixup_silent_linux (void);
122#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000123static boot_os_Fcn do_bootm_netbsd;
wdenkd791b1d2003-04-20 14:04:18 +0000124static boot_os_Fcn do_bootm_rtems;
wdenk47d1a6e2002-11-03 00:01:44 +0000125#if (CONFIG_COMMANDS & CFG_CMD_ELF)
126static boot_os_Fcn do_bootm_vxworks;
127static boot_os_Fcn do_bootm_qnxelf;
128int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
129int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
130#endif /* CFG_CMD_ELF */
wdenk7f70e852003-05-20 14:25:27 +0000131#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
132static boot_os_Fcn do_bootm_artos;
133#endif
wdenk1f4bb372003-07-27 00:21:01 +0000134#ifdef CONFIG_LYNXKDI
135static boot_os_Fcn do_bootm_lynxkdi;
136extern void lynxkdi_boot( image_header_t * );
137#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000138
139image_header_t header;
140
141ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
142
143int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
144{
145 ulong iflag;
146 ulong addr;
147 ulong data, len, checksum;
148 ulong *len_ptr;
wdenkc29fdfc2003-08-29 20:57:53 +0000149 uint unc_len = 0x400000;
wdenk47d1a6e2002-11-03 00:01:44 +0000150 int i, verify;
151 char *name, *s;
152 int (*appl)(cmd_tbl_t *, int, int, char *[]);
153 image_header_t *hdr = &header;
154
155 s = getenv ("verify");
156 verify = (s && (*s == 'n')) ? 0 : 1;
157
158 if (argc < 2) {
159 addr = load_addr;
160 } else {
161 addr = simple_strtoul(argv[1], NULL, 16);
162 }
163
164 SHOW_BOOT_PROGRESS (1);
165 printf ("## Booting image at %08lx ...\n", addr);
166
167 /* Copy header so we can blank CRC field for re-calculation */
wdenk2abbe072003-06-16 23:50:08 +0000168#ifdef CONFIG_HAS_DATAFLASH
169 if (addr_dataflash(addr)){
170 read_dataflash(addr, sizeof(image_header_t), (char *)&header);
171 } else
172#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000173 memmove (&header, (char *)addr, sizeof(image_header_t));
174
175 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
wdenk2262cfe2002-11-18 00:14:45 +0000176#ifdef __I386__ /* correct image format not implemented yet - fake it */
177 if (fake_header(hdr, (void*)addr, -1) != NULL) {
178 /* to compensate for the addition below */
179 addr -= sizeof(image_header_t);
180 /* turnof verify,
181 * fake_header() does not fake the data crc
182 */
183 verify = 0;
184 } else
185#endif /* __I386__ */
186 {
wdenk47d1a6e2002-11-03 00:01:44 +0000187 printf ("Bad Magic Number\n");
188 SHOW_BOOT_PROGRESS (-1);
189 return 1;
wdenk2262cfe2002-11-18 00:14:45 +0000190 }
wdenk47d1a6e2002-11-03 00:01:44 +0000191 }
192 SHOW_BOOT_PROGRESS (2);
193
194 data = (ulong)&header;
195 len = sizeof(image_header_t);
196
197 checksum = ntohl(hdr->ih_hcrc);
198 hdr->ih_hcrc = 0;
199
200 if (crc32 (0, (char *)data, len) != checksum) {
201 printf ("Bad Header Checksum\n");
202 SHOW_BOOT_PROGRESS (-2);
203 return 1;
204 }
205 SHOW_BOOT_PROGRESS (3);
206
207 /* for multi-file images we need the data part, too */
wdenka57a4962003-10-26 22:52:58 +0000208 print_image_hdr ((image_header_t *)addr);
wdenk47d1a6e2002-11-03 00:01:44 +0000209
210 data = addr + sizeof(image_header_t);
211 len = ntohl(hdr->ih_size);
212
wdenk2abbe072003-06-16 23:50:08 +0000213#ifdef CONFIG_HAS_DATAFLASH
214 if (addr_dataflash(addr)){
215 read_dataflash(data, len, (char *)CFG_LOAD_ADDR);
216 data = CFG_LOAD_ADDR;
217 }
wdenk8bde7f72003-06-27 21:31:46 +0000218#endif
wdenk2abbe072003-06-16 23:50:08 +0000219
wdenk47d1a6e2002-11-03 00:01:44 +0000220 if (verify) {
221 printf (" Verifying Checksum ... ");
222 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
223 printf ("Bad Data CRC\n");
224 SHOW_BOOT_PROGRESS (-3);
225 return 1;
226 }
227 printf ("OK\n");
228 }
229 SHOW_BOOT_PROGRESS (4);
230
231 len_ptr = (ulong *)data;
232
wdenk2262cfe2002-11-18 00:14:45 +0000233#if defined(__PPC__)
234 if (hdr->ih_arch != IH_CPU_PPC)
235#elif defined(__ARM__)
236 if (hdr->ih_arch != IH_CPU_ARM)
237#elif defined(__I386__)
238 if (hdr->ih_arch != IH_CPU_I386)
wdenk6069ff22003-02-28 00:49:47 +0000239#elif defined(__mips__)
wdenk8bde7f72003-06-27 21:31:46 +0000240 if (hdr->ih_arch != IH_CPU_MIPS)
wdenk4a551702003-10-08 23:26:14 +0000241#elif defined(__nios__)
242 if (hdr->ih_arch != IH_CPU_NIOS)
wdenk2262cfe2002-11-18 00:14:45 +0000243#else
244# error Unknown CPU type
245#endif
246 {
247 printf ("Unsupported Architecture 0x%x\n", hdr->ih_arch);
wdenk47d1a6e2002-11-03 00:01:44 +0000248 SHOW_BOOT_PROGRESS (-4);
249 return 1;
250 }
251 SHOW_BOOT_PROGRESS (5);
252
253 switch (hdr->ih_type) {
254 case IH_TYPE_STANDALONE: name = "Standalone Application";
wdenk4a551702003-10-08 23:26:14 +0000255 /* A second argument overwrites the load address */
256 if (argc > 2) {
257 hdr->ih_load = simple_strtoul(argv[2], NULL, 16);
258 }
wdenk47d1a6e2002-11-03 00:01:44 +0000259 break;
260 case IH_TYPE_KERNEL: name = "Kernel Image";
261 break;
262 case IH_TYPE_MULTI: name = "Multi-File Image";
263 len = ntohl(len_ptr[0]);
264 /* OS kernel is always the first image */
265 data += 8; /* kernel_len + terminator */
266 for (i=1; len_ptr[i]; ++i)
267 data += 4;
268 break;
269 default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
270 SHOW_BOOT_PROGRESS (-5);
271 return 1;
272 }
273 SHOW_BOOT_PROGRESS (6);
274
275 /*
276 * We have reached the point of no return: we are going to
277 * overwrite all exception vector code, so we cannot easily
278 * recover from any failures any more...
279 */
280
281 iflag = disable_interrupts();
282
wdenkc7de8292002-11-19 11:04:11 +0000283#ifdef CONFIG_AMIGAONEG3SE
284 /*
wdenk8bde7f72003-06-27 21:31:46 +0000285 * We've possible left the caches enabled during
wdenkc7de8292002-11-19 11:04:11 +0000286 * bios emulation, so turn them off again
287 */
288 icache_disable();
289 invalidate_l1_instruction_cache();
290 flush_data_cache();
291 dcache_disable();
292#endif
293
wdenk47d1a6e2002-11-03 00:01:44 +0000294 switch (hdr->ih_comp) {
295 case IH_COMP_NONE:
wdenk2262cfe2002-11-18 00:14:45 +0000296 if(ntohl(hdr->ih_load) == addr) {
wdenk47d1a6e2002-11-03 00:01:44 +0000297 printf (" XIP %s ... ", name);
298 } else {
299#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
300 size_t l = len;
301 void *to = (void *)ntohl(hdr->ih_load);
302 void *from = (void *)data;
303
304 printf (" Loading %s ... ", name);
305
306 while (l > 0) {
307 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
308 WATCHDOG_RESET();
309 memmove (to, from, tail);
310 to += tail;
311 from += tail;
312 l -= tail;
313 }
314#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
315 memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
316#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
317 }
318 break;
319 case IH_COMP_GZIP:
320 printf (" Uncompressing %s ... ", name);
wdenkc29fdfc2003-08-29 20:57:53 +0000321 if (gunzip ((void *)ntohl(hdr->ih_load), unc_len,
wdenk47d1a6e2002-11-03 00:01:44 +0000322 (uchar *)data, (int *)&len) != 0) {
323 printf ("GUNZIP ERROR - must RESET board to recover\n");
324 SHOW_BOOT_PROGRESS (-6);
325 do_reset (cmdtp, flag, argc, argv);
326 }
327 break;
wdenkc29fdfc2003-08-29 20:57:53 +0000328#ifdef CONFIG_BZIP2
329 case IH_COMP_BZIP2:
330 printf (" Uncompressing %s ... ", name);
331 i = BZ2_bzBuffToBuffDecompress ((char*)ntohl(hdr->ih_load),
332 &unc_len, (char *)data, len, 0, 0);
333 if (i != BZ_OK) {
334 printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
335 SHOW_BOOT_PROGRESS (-6);
336 udelay(100000);
337 do_reset (cmdtp, flag, argc, argv);
338 }
339 break;
340#endif /* CONFIG_BZIP2 */
wdenk47d1a6e2002-11-03 00:01:44 +0000341 default:
342 if (iflag)
343 enable_interrupts();
344 printf ("Unimplemented compression type %d\n", hdr->ih_comp);
345 SHOW_BOOT_PROGRESS (-7);
346 return 1;
347 }
348 printf ("OK\n");
349 SHOW_BOOT_PROGRESS (7);
350
351 switch (hdr->ih_type) {
352 case IH_TYPE_STANDALONE:
wdenk47d1a6e2002-11-03 00:01:44 +0000353 if (iflag)
354 enable_interrupts();
355
wdenk4a6fd342003-04-12 23:38:12 +0000356 /* load (and uncompress), but don't start if "autostart"
357 * is set to "no"
358 */
wdenk4a551702003-10-08 23:26:14 +0000359 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0)) {
360 char buf[32];
361 sprintf(buf, "%lX", len);
362 setenv("filesize", buf);
wdenk4a6fd342003-04-12 23:38:12 +0000363 return 0;
wdenk4a551702003-10-08 23:26:14 +0000364 }
wdenk4a6fd342003-04-12 23:38:12 +0000365 appl = (int (*)(cmd_tbl_t *, int, int, char *[]))ntohl(hdr->ih_ep);
wdenk47d1a6e2002-11-03 00:01:44 +0000366 (*appl)(cmdtp, flag, argc-1, &argv[1]);
wdenk4a6fd342003-04-12 23:38:12 +0000367 return 0;
wdenk47d1a6e2002-11-03 00:01:44 +0000368 case IH_TYPE_KERNEL:
369 case IH_TYPE_MULTI:
370 /* handled below */
371 break;
372 default:
373 if (iflag)
374 enable_interrupts();
375 printf ("Can't boot image type %d\n", hdr->ih_type);
376 SHOW_BOOT_PROGRESS (-8);
377 return 1;
378 }
379 SHOW_BOOT_PROGRESS (8);
380
381 switch (hdr->ih_os) {
382 default: /* handled by (original) Linux case */
383 case IH_OS_LINUX:
wdenkf72da342003-10-10 10:05:42 +0000384#ifdef CONFIG_SILENT_CONSOLE
385 fixup_silent_linux();
386#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000387 do_bootm_linux (cmdtp, flag, argc, argv,
388 addr, len_ptr, verify);
389 break;
390 case IH_OS_NETBSD:
391 do_bootm_netbsd (cmdtp, flag, argc, argv,
392 addr, len_ptr, verify);
393 break;
wdenk8bde7f72003-06-27 21:31:46 +0000394
wdenk1f4bb372003-07-27 00:21:01 +0000395#ifdef CONFIG_LYNXKDI
396 case IH_OS_LYNXOS:
397 do_bootm_lynxkdi (cmdtp, flag, argc, argv,
398 addr, len_ptr, verify);
399 break;
400#endif
401
wdenkd791b1d2003-04-20 14:04:18 +0000402 case IH_OS_RTEMS:
403 do_bootm_rtems (cmdtp, flag, argc, argv,
404 addr, len_ptr, verify);
405 break;
wdenk8bde7f72003-06-27 21:31:46 +0000406
wdenk47d1a6e2002-11-03 00:01:44 +0000407#if (CONFIG_COMMANDS & CFG_CMD_ELF)
408 case IH_OS_VXWORKS:
409 do_bootm_vxworks (cmdtp, flag, argc, argv,
410 addr, len_ptr, verify);
411 break;
412 case IH_OS_QNX:
413 do_bootm_qnxelf (cmdtp, flag, argc, argv,
414 addr, len_ptr, verify);
415 break;
416#endif /* CFG_CMD_ELF */
wdenk7f70e852003-05-20 14:25:27 +0000417#ifdef CONFIG_ARTOS
418 case IH_OS_ARTOS:
419 do_bootm_artos (cmdtp, flag, argc, argv,
420 addr, len_ptr, verify);
421 break;
422#endif
wdenk47d1a6e2002-11-03 00:01:44 +0000423 }
424
425 SHOW_BOOT_PROGRESS (-9);
426#ifdef DEBUG
427 printf ("\n## Control returned to monitor - resetting...\n");
428 do_reset (cmdtp, flag, argc, argv);
429#endif
430 return 1;
431}
432
wdenk0d498392003-07-01 21:06:45 +0000433U_BOOT_CMD(
434 bootm, CFG_MAXARGS, 1, do_bootm,
wdenk8bde7f72003-06-27 21:31:46 +0000435 "bootm - boot application image from memory\n",
436 "[addr [arg ...]]\n - boot application image stored in memory\n"
437 " passing arguments 'arg ...'; when booting a Linux kernel,\n"
438 " 'arg' can be the address of an initrd image\n"
439);
440
wdenkf72da342003-10-10 10:05:42 +0000441#ifdef CONFIG_SILENT_CONSOLE
442static void
443fixup_silent_linux ()
444{
445 DECLARE_GLOBAL_DATA_PTR;
446 char buf[256], *start, *end;
447 char *cmdline = getenv ("bootargs");
448
449 /* Only fix cmdline when requested */
450 if (!(gd->flags & GD_FLG_SILENT))
451 return;
452
453 debug ("before silent fix-up: %s\n", cmdline);
454 if (cmdline) {
455 if ((start = strstr (cmdline, "console=")) != NULL) {
456 end = strchr (start, ' ');
457 strncpy (buf, cmdline, (start - cmdline + 8));
458 if (end)
459 strcpy (buf + (start - cmdline + 8), end);
460 else
461 buf[start - cmdline + 8] = '\0';
462 } else {
463 strcpy (buf, cmdline);
464 strcat (buf, " console=");
465 }
466 } else {
467 strcpy (buf, "console=");
468 }
469
470 setenv ("bootargs", buf);
471 debug ("after silent fix-up: %s\n", buf);
472}
473#endif /* CONFIG_SILENT_CONSOLE */
474
wdenk2262cfe2002-11-18 00:14:45 +0000475#ifdef CONFIG_PPC
wdenk47d1a6e2002-11-03 00:01:44 +0000476static void
477do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
478 int argc, char *argv[],
479 ulong addr,
480 ulong *len_ptr,
481 int verify)
482{
483 DECLARE_GLOBAL_DATA_PTR;
484
485 ulong sp;
486 ulong len, checksum;
487 ulong initrd_start, initrd_end;
488 ulong cmd_start, cmd_end;
489 ulong initrd_high;
490 ulong data;
wdenk38b99262003-05-23 23:18:21 +0000491 int initrd_copy_to_ram = 1;
wdenk47d1a6e2002-11-03 00:01:44 +0000492 char *cmdline;
493 char *s;
494 bd_t *kbd;
495 void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
496 image_header_t *hdr = &header;
497
498 if ((s = getenv ("initrd_high")) != NULL) {
499 /* a value of "no" or a similar string will act like 0,
500 * turning the "load high" feature off. This is intentional.
501 */
502 initrd_high = simple_strtoul(s, NULL, 16);
wdenk38b99262003-05-23 23:18:21 +0000503 if (initrd_high == ~0)
504 initrd_copy_to_ram = 0;
wdenk228f29a2002-12-08 09:53:23 +0000505 } else { /* not set, no restrictions to load high */
wdenk47d1a6e2002-11-03 00:01:44 +0000506 initrd_high = ~0;
507 }
508
wdenk56f94be2002-11-05 16:35:14 +0000509#ifdef CONFIG_LOGBUFFER
wdenk6aff3112002-12-17 01:51:00 +0000510 kbd=gd->bd;
wdenk228f29a2002-12-08 09:53:23 +0000511 /* Prevent initrd from overwriting logbuffer */
512 if (initrd_high < (kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD))
513 initrd_high = kbd->bi_memsize-LOGBUFF_LEN-LOGBUFF_OVERHEAD;
514 debug ("## Logbuffer at 0x%08lX ", kbd->bi_memsize-LOGBUFF_LEN);
wdenk56f94be2002-11-05 16:35:14 +0000515#endif
516
wdenk47d1a6e2002-11-03 00:01:44 +0000517 /*
518 * Booting a (Linux) kernel image
519 *
520 * Allocate space for command line and board info - the
521 * address should be as high as possible within the reach of
522 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
523 * memory, which means far enough below the current stack
524 * pointer.
525 */
526
527 asm( "mr %0,1": "=r"(sp) : );
528
wdenk56f94be2002-11-05 16:35:14 +0000529 debug ("## Current stack ends at 0x%08lX ", sp);
530
wdenk47d1a6e2002-11-03 00:01:44 +0000531 sp -= 2048; /* just to be sure */
532 if (sp > CFG_BOOTMAPSZ)
533 sp = CFG_BOOTMAPSZ;
534 sp &= ~0xF;
535
wdenk56f94be2002-11-05 16:35:14 +0000536 debug ("=> set upper limit to 0x%08lX\n", sp);
537
wdenk47d1a6e2002-11-03 00:01:44 +0000538 cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
539 kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
540
541 if ((s = getenv("bootargs")) == NULL)
542 s = "";
543
544 strcpy (cmdline, s);
545
546 cmd_start = (ulong)&cmdline[0];
547 cmd_end = cmd_start + strlen(cmdline);
548
549 *kbd = *(gd->bd);
550
551#ifdef DEBUG
552 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
553
554 do_bdinfo (NULL, 0, 0, NULL);
555#endif
556
557 if ((s = getenv ("clocks_in_mhz")) != NULL) {
558 /* convert all clock information to MHz */
559 kbd->bi_intfreq /= 1000000L;
560 kbd->bi_busfreq /= 1000000L;
wdenk42d1f032003-10-15 23:53:47 +0000561#if defined(CONFIG_8260) || defined(CONFIG_MPC8560)
wdenk47d1a6e2002-11-03 00:01:44 +0000562 kbd->bi_cpmfreq /= 1000000L;
563 kbd->bi_brgfreq /= 1000000L;
564 kbd->bi_sccfreq /= 1000000L;
565 kbd->bi_vco /= 1000000L;
566#endif /* CONFIG_8260 */
wdenk945af8d2003-07-16 21:53:01 +0000567#if defined(CONFIG_MPC5XXXX)
568 kbd->bi_ipbfreq /= 1000000L;
569 kbd->bi_pcifreq /= 1000000L;
570#endif /* CONFIG_MPC5XXXX */
wdenk47d1a6e2002-11-03 00:01:44 +0000571 }
572
573 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep;
574
575 /*
576 * Check if there is an initrd image
577 */
578 if (argc >= 3) {
579 SHOW_BOOT_PROGRESS (9);
580
581 addr = simple_strtoul(argv[2], NULL, 16);
582
583 printf ("## Loading RAMDisk Image at %08lx ...\n", addr);
584
585 /* Copy header so we can blank CRC field for re-calculation */
586 memmove (&header, (char *)addr, sizeof(image_header_t));
587
588 if (hdr->ih_magic != IH_MAGIC) {
589 printf ("Bad Magic Number\n");
590 SHOW_BOOT_PROGRESS (-10);
591 do_reset (cmdtp, flag, argc, argv);
592 }
593
594 data = (ulong)&header;
595 len = sizeof(image_header_t);
596
597 checksum = hdr->ih_hcrc;
598 hdr->ih_hcrc = 0;
599
600 if (crc32 (0, (char *)data, len) != checksum) {
601 printf ("Bad Header Checksum\n");
602 SHOW_BOOT_PROGRESS (-11);
603 do_reset (cmdtp, flag, argc, argv);
604 }
605
606 SHOW_BOOT_PROGRESS (10);
607
608 print_image_hdr (hdr);
609
610 data = addr + sizeof(image_header_t);
611 len = hdr->ih_size;
612
613 if (verify) {
614 ulong csum = 0;
615#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
616 ulong cdata = data, edata = cdata + len;
617#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
618
619 printf (" Verifying Checksum ... ");
620
621#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
622
623 while (cdata < edata) {
624 ulong chunk = edata - cdata;
625
626 if (chunk > CHUNKSZ)
627 chunk = CHUNKSZ;
628 csum = crc32 (csum, (char *)cdata, chunk);
629 cdata += chunk;
630
631 WATCHDOG_RESET();
632 }
633#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
634 csum = crc32 (0, (char *)data, len);
635#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
636
637 if (csum != hdr->ih_dcrc) {
638 printf ("Bad Data CRC\n");
639 SHOW_BOOT_PROGRESS (-12);
640 do_reset (cmdtp, flag, argc, argv);
641 }
642 printf ("OK\n");
643 }
644
645 SHOW_BOOT_PROGRESS (11);
646
647 if ((hdr->ih_os != IH_OS_LINUX) ||
648 (hdr->ih_arch != IH_CPU_PPC) ||
649 (hdr->ih_type != IH_TYPE_RAMDISK) ) {
650 printf ("No Linux PPC Ramdisk Image\n");
651 SHOW_BOOT_PROGRESS (-13);
652 do_reset (cmdtp, flag, argc, argv);
653 }
654
655 /*
656 * Now check if we have a multifile image
657 */
658 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
659 u_long tail = ntohl(len_ptr[0]) % 4;
660 int i;
661
662 SHOW_BOOT_PROGRESS (13);
663
664 /* skip kernel length and terminator */
665 data = (ulong)(&len_ptr[2]);
666 /* skip any additional image length fields */
667 for (i=1; len_ptr[i]; ++i)
668 data += 4;
669 /* add kernel length, and align */
670 data += ntohl(len_ptr[0]);
671 if (tail) {
672 data += 4 - tail;
673 }
674
675 len = ntohl(len_ptr[1]);
676
677 } else {
678 /*
679 * no initrd image
680 */
681 SHOW_BOOT_PROGRESS (14);
682
683 len = data = 0;
684 }
685
wdenk47d1a6e2002-11-03 00:01:44 +0000686 if (!data) {
wdenk56f94be2002-11-05 16:35:14 +0000687 debug ("No initrd\n");
wdenk47d1a6e2002-11-03 00:01:44 +0000688 }
wdenk47d1a6e2002-11-03 00:01:44 +0000689
690 if (data) {
wdenk38b99262003-05-23 23:18:21 +0000691 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
692 initrd_start = data;
693 initrd_end = initrd_start + len;
694 } else {
wdenk47d1a6e2002-11-03 00:01:44 +0000695 initrd_start = (ulong)kbd - len;
696 initrd_start &= ~(4096 - 1); /* align on page */
697
698 if (initrd_high) {
699 ulong nsp;
700
701 /*
702 * the inital ramdisk does not need to be within
703 * CFG_BOOTMAPSZ as it is not accessed until after
704 * the mm system is initialised.
705 *
706 * do the stack bottom calculation again and see if
707 * the initrd will fit just below the monitor stack
708 * bottom without overwriting the area allocated
709 * above for command line args and board info.
710 */
711 asm( "mr %0,1": "=r"(nsp) : );
712 nsp -= 2048; /* just to be sure */
713 nsp &= ~0xF;
714 if (nsp > initrd_high) /* limit as specified */
715 nsp = initrd_high;
716 nsp -= len;
717 nsp &= ~(4096 - 1); /* align on page */
718 if (nsp >= sp)
719 initrd_start = nsp;
720 }
721
722 SHOW_BOOT_PROGRESS (12);
wdenk56f94be2002-11-05 16:35:14 +0000723
724 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
wdenk47d1a6e2002-11-03 00:01:44 +0000725 data, data + len - 1, len, len);
wdenk56f94be2002-11-05 16:35:14 +0000726
wdenk47d1a6e2002-11-03 00:01:44 +0000727 initrd_end = initrd_start + len;
728 printf (" Loading Ramdisk to %08lx, end %08lx ... ",
729 initrd_start, initrd_end);
730#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
731 {
732 size_t l = len;
733 void *to = (void *)initrd_start;
734 void *from = (void *)data;
735
736 while (l > 0) {
737 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
738 WATCHDOG_RESET();
739 memmove (to, from, tail);
740 to += tail;
741 from += tail;
742 l -= tail;
743 }
744 }
745#else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
746 memmove ((void *)initrd_start, (void *)data, len);
747#endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
748 printf ("OK\n");
wdenk38b99262003-05-23 23:18:21 +0000749 }
wdenk47d1a6e2002-11-03 00:01:44 +0000750 } else {
751 initrd_start = 0;
752 initrd_end = 0;
753 }
754
wdenk56f94be2002-11-05 16:35:14 +0000755
756 debug ("## Transferring control to Linux (at address %08lx) ...\n",
wdenk47d1a6e2002-11-03 00:01:44 +0000757 (ulong)kernel);
wdenk56f94be2002-11-05 16:35:14 +0000758
wdenk47d1a6e2002-11-03 00:01:44 +0000759 SHOW_BOOT_PROGRESS (15);
760
wdenk42d1f032003-10-15 23:53:47 +0000761#if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500)
wdenk47d1a6e2002-11-03 00:01:44 +0000762 unlock_ram_in_cache();
763#endif
764 /*
765 * Linux Kernel Parameters:
766 * r3: ptr to board info data
767 * r4: initrd_start or 0 if no initrd
768 * r5: initrd_end - unused if r4 is 0
769 * r6: Start of command line string
770 * r7: End of command line string
771 */
772 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
773}
wdenk1cb8e982003-03-06 21:55:29 +0000774#endif /* CONFIG_PPC */
wdenk47d1a6e2002-11-03 00:01:44 +0000775
776static void
777do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
778 int argc, char *argv[],
779 ulong addr,
780 ulong *len_ptr,
781 int verify)
782{
783 DECLARE_GLOBAL_DATA_PTR;
784
785 image_header_t *hdr = &header;
786
787 void (*loader)(bd_t *, image_header_t *, char *, char *);
788 image_header_t *img_addr;
789 char *consdev;
790 char *cmdline;
791
792
793 /*
794 * Booting a (NetBSD) kernel image
795 *
796 * This process is pretty similar to a standalone application:
797 * The (first part of an multi-) image must be a stage-2 loader,
798 * which in turn is responsible for loading & invoking the actual
799 * kernel. The only differences are the parameters being passed:
800 * besides the board info strucure, the loader expects a command
801 * line, the name of the console device, and (optionally) the
802 * address of the original image header.
803 */
804
805 img_addr = 0;
806 if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]))
807 img_addr = (image_header_t *) addr;
808
809
810 consdev = "";
811#if defined (CONFIG_8xx_CONS_SMC1)
812 consdev = "smc1";
813#elif defined (CONFIG_8xx_CONS_SMC2)
814 consdev = "smc2";
815#elif defined (CONFIG_8xx_CONS_SCC2)
816 consdev = "scc2";
817#elif defined (CONFIG_8xx_CONS_SCC3)
818 consdev = "scc3";
819#endif
820
821 if (argc > 2) {
822 ulong len;
823 int i;
824
825 for (i=2, len=0 ; i<argc ; i+=1)
826 len += strlen (argv[i]) + 1;
827 cmdline = malloc (len);
828
829 for (i=2, len=0 ; i<argc ; i+=1) {
830 if (i > 2)
831 cmdline[len++] = ' ';
832 strcpy (&cmdline[len], argv[i]);
833 len += strlen (argv[i]);
834 }
835 } else if ((cmdline = getenv("bootargs")) == NULL) {
836 cmdline = "";
837 }
838
839 loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
840
841 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
842 (ulong)loader);
843
844 SHOW_BOOT_PROGRESS (15);
845
846 /*
847 * NetBSD Stage-2 Loader Parameters:
848 * r3: ptr to board info data
849 * r4: image address
850 * r5: console device
851 * r6: boot args string
852 */
853 (*loader) (gd->bd, img_addr, consdev, cmdline);
854}
855
wdenk7f70e852003-05-20 14:25:27 +0000856#if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
857
858/* Function that returns a character from the environment */
859extern uchar (*env_get_char)(int);
860
861static void
862do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
863 int argc, char *argv[],
864 ulong addr,
865 ulong *len_ptr,
866 int verify)
867{
868 DECLARE_GLOBAL_DATA_PTR;
869 ulong top;
870 char *s, *cmdline;
871 char **fwenv, **ss;
872 int i, j, nxt, len, envno, envsz;
873 bd_t *kbd;
874 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
875 image_header_t *hdr = &header;
876
877 /*
878 * Booting an ARTOS kernel image + application
879 */
880
881 /* this used to be the top of memory, but was wrong... */
882#ifdef CONFIG_PPC
883 /* get stack pointer */
884 asm volatile ("mr %0,1" : "=r"(top) );
885#endif
886 debug ("## Current stack ends at 0x%08lX ", top);
887
888 top -= 2048; /* just to be sure */
889 if (top > CFG_BOOTMAPSZ)
890 top = CFG_BOOTMAPSZ;
891 top &= ~0xF;
892
893 debug ("=> set upper limit to 0x%08lX\n", top);
894
895 /* first check the artos specific boot args, then the linux args*/
896 if ((s = getenv("abootargs")) == NULL && (s = getenv("bootargs")) == NULL)
897 s = "";
898
899 /* get length of cmdline, and place it */
900 len = strlen(s);
901 top = (top - (len + 1)) & ~0xF;
902 cmdline = (char *)top;
903 debug ("## cmdline at 0x%08lX ", top);
904 strcpy(cmdline, s);
905
906 /* copy bdinfo */
907 top = (top - sizeof(bd_t)) & ~0xF;
908 debug ("## bd at 0x%08lX ", top);
909 kbd = (bd_t *)top;
910 memcpy(kbd, gd->bd, sizeof(bd_t));
911
912 /* first find number of env entries, and their size */
913 envno = 0;
914 envsz = 0;
915 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
916 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
917 ;
918 envno++;
919 envsz += (nxt - i) + 1; /* plus trailing zero */
920 }
921 envno++; /* plus the terminating zero */
922 debug ("## %u envvars total size %u ", envno, envsz);
923
924 top = (top - sizeof(char **)*envno) & ~0xF;
925 fwenv = (char **)top;
926 debug ("## fwenv at 0x%08lX ", top);
927
928 top = (top - envsz) & ~0xF;
929 s = (char *)top;
930 ss = fwenv;
931
932 /* now copy them */
933 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
934 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
935 ;
936 *ss++ = s;
937 for (j = i; j < nxt; ++j)
938 *s++ = env_get_char(j);
939 *s++ = '\0';
940 }
941 *ss++ = NULL; /* terminate */
942
943 entry = (void (*)(bd_t *, char *, char **, ulong))ntohl(hdr->ih_ep);
944 (*entry)(kbd, cmdline, fwenv, top);
945}
946#endif
947
948
wdenk47d1a6e2002-11-03 00:01:44 +0000949#if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
950int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
951{
952 int rcode = 0;
953#ifndef CFG_HUSH_PARSER
954 if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
955#else
956 if (parse_string_outer(getenv("bootcmd"),
957 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
958#endif
959 return rcode;
960}
wdenk8bde7f72003-06-27 21:31:46 +0000961
wdenk0d498392003-07-01 21:06:45 +0000962U_BOOT_CMD(
963 boot, 1, 1, do_bootd,
wdenk9d2b18a2003-06-28 23:11:04 +0000964 "boot - boot default, i.e., run 'bootcmd'\n",
965 NULL
966);
967
968/* keep old command name "bootd" for backward compatibility */
wdenk0d498392003-07-01 21:06:45 +0000969U_BOOT_CMD(
970 bootd, 1, 1, do_bootd,
wdenk8bde7f72003-06-27 21:31:46 +0000971 "bootd - boot default, i.e., run 'bootcmd'\n",
972 NULL
973);
974
wdenk47d1a6e2002-11-03 00:01:44 +0000975#endif
976
977#if (CONFIG_COMMANDS & CFG_CMD_IMI)
978int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
979{
980 int arg;
981 ulong addr;
982 int rcode=0;
983
984 if (argc < 2) {
985 return image_info (load_addr);
986 }
987
988 for (arg=1; arg <argc; ++arg) {
989 addr = simple_strtoul(argv[arg], NULL, 16);
990 if (image_info (addr) != 0) rcode = 1;
991 }
992 return rcode;
993}
994
995static int image_info (ulong addr)
996{
997 ulong data, len, checksum;
998 image_header_t *hdr = &header;
999
1000 printf ("\n## Checking Image at %08lx ...\n", addr);
1001
1002 /* Copy header so we can blank CRC field for re-calculation */
1003 memmove (&header, (char *)addr, sizeof(image_header_t));
1004
1005 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
1006 printf (" Bad Magic Number\n");
1007 return 1;
1008 }
1009
1010 data = (ulong)&header;
1011 len = sizeof(image_header_t);
1012
1013 checksum = ntohl(hdr->ih_hcrc);
1014 hdr->ih_hcrc = 0;
1015
1016 if (crc32 (0, (char *)data, len) != checksum) {
1017 printf (" Bad Header Checksum\n");
1018 return 1;
1019 }
1020
1021 /* for multi-file images we need the data part, too */
1022 print_image_hdr ((image_header_t *)addr);
1023
1024 data = addr + sizeof(image_header_t);
1025 len = ntohl(hdr->ih_size);
1026
1027 printf (" Verifying Checksum ... ");
1028 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
1029 printf (" Bad Data CRC\n");
1030 return 1;
1031 }
1032 printf ("OK\n");
1033 return 0;
1034}
wdenk0d498392003-07-01 21:06:45 +00001035
1036U_BOOT_CMD(
1037 iminfo, CFG_MAXARGS, 1, do_iminfo,
wdenk8bde7f72003-06-27 21:31:46 +00001038 "iminfo - print header information for application image\n",
1039 "addr [addr ...]\n"
1040 " - print header information for application image starting at\n"
1041 " address 'addr' in memory; this includes verification of the\n"
1042 " image contents (magic number, header and payload checksums)\n"
1043);
1044
wdenk47d1a6e2002-11-03 00:01:44 +00001045#endif /* CFG_CMD_IMI */
1046
wdenk27b207f2003-07-24 23:38:38 +00001047#if (CONFIG_COMMANDS & CFG_CMD_IMLS)
1048/*-----------------------------------------------------------------------
1049 * List all images found in flash.
1050 */
1051int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1052{
1053 flash_info_t *info;
1054 int i, j;
1055 image_header_t *hdr;
1056 ulong checksum;
1057
1058 for (i=0, info=&flash_info[0]; i<CFG_MAX_FLASH_BANKS; ++i, ++info) {
1059 if (info->flash_id == FLASH_UNKNOWN)
1060 goto next_bank;
1061 for (j=0; j<CFG_MAX_FLASH_SECT; ++j) {
1062
1063 if (!(hdr=(image_header_t *)info->start[j]) ||
1064 (ntohl(hdr->ih_magic) != IH_MAGIC))
1065 goto next_sector;
1066
1067 /* Copy header so we can blank CRC field for re-calculation */
1068 memmove (&header, (char *)hdr, sizeof(image_header_t));
1069
1070 checksum = ntohl(header.ih_hcrc);
1071 header.ih_hcrc = 0;
1072
1073 if (crc32 (0, (char *)&header, sizeof(image_header_t))
1074 != checksum)
1075 goto next_sector;
1076
1077 printf ("Image at %08lX:\n", (ulong)hdr);
1078 print_image_hdr( hdr );
1079 putc ('\n');
wdenkbdccc4f2003-08-05 17:43:17 +00001080next_sector: ;
wdenk27b207f2003-07-24 23:38:38 +00001081 }
wdenkbdccc4f2003-08-05 17:43:17 +00001082next_bank: ;
wdenk27b207f2003-07-24 23:38:38 +00001083 }
1084
1085 return (0);
1086}
1087
1088U_BOOT_CMD(
1089 imls, 1, 1, do_imls,
1090 "imls - list all images found in flash\n",
1091 "\n"
1092 " - Prints information about all images found at sector\n"
1093 " boundaries in flash.\n"
1094);
1095#endif /* CFG_CMD_IMLS */
1096
wdenk47d1a6e2002-11-03 00:01:44 +00001097void
1098print_image_hdr (image_header_t *hdr)
1099{
1100#if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
1101 time_t timestamp = (time_t)ntohl(hdr->ih_time);
1102 struct rtc_time tm;
1103#endif
1104
1105 printf (" Image Name: %.*s\n", IH_NMLEN, hdr->ih_name);
1106#if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
1107 to_tm (timestamp, &tm);
1108 printf (" Created: %4d-%02d-%02d %2d:%02d:%02d UTC\n",
1109 tm.tm_year, tm.tm_mon, tm.tm_mday,
1110 tm.tm_hour, tm.tm_min, tm.tm_sec);
1111#endif /* CFG_CMD_DATE, CONFIG_TIMESTAMP */
1112 printf (" Image Type: "); print_type(hdr); printf ("\n");
1113 printf (" Data Size: %d Bytes = ", ntohl(hdr->ih_size));
1114 print_size (ntohl(hdr->ih_size), "\n");
1115 printf (" Load Address: %08x\n", ntohl(hdr->ih_load));
1116 printf (" Entry Point: %08x\n", ntohl(hdr->ih_ep));
1117
1118 if (hdr->ih_type == IH_TYPE_MULTI) {
1119 int i;
1120 ulong len;
1121 ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
1122
1123 printf (" Contents:\n");
1124 for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
1125 printf (" Image %d: %8ld Bytes = ", i, len);
1126 print_size (len, "\n");
1127 }
1128 }
1129}
1130
1131
1132static void
1133print_type (image_header_t *hdr)
1134{
1135 char *os, *arch, *type, *comp;
1136
1137 switch (hdr->ih_os) {
1138 case IH_OS_INVALID: os = "Invalid OS"; break;
1139 case IH_OS_NETBSD: os = "NetBSD"; break;
1140 case IH_OS_LINUX: os = "Linux"; break;
1141 case IH_OS_VXWORKS: os = "VxWorks"; break;
1142 case IH_OS_QNX: os = "QNX"; break;
1143 case IH_OS_U_BOOT: os = "U-Boot"; break;
wdenkd791b1d2003-04-20 14:04:18 +00001144 case IH_OS_RTEMS: os = "RTEMS"; break;
wdenk7f70e852003-05-20 14:25:27 +00001145#ifdef CONFIG_ARTOS
1146 case IH_OS_ARTOS: os = "ARTOS"; break;
1147#endif
wdenk1f4bb372003-07-27 00:21:01 +00001148#ifdef CONFIG_LYNXKDI
1149 case IH_OS_LYNXOS: os = "LynxOS"; break;
1150#endif
wdenk47d1a6e2002-11-03 00:01:44 +00001151 default: os = "Unknown OS"; break;
1152 }
1153
1154 switch (hdr->ih_arch) {
1155 case IH_CPU_INVALID: arch = "Invalid CPU"; break;
1156 case IH_CPU_ALPHA: arch = "Alpha"; break;
1157 case IH_CPU_ARM: arch = "ARM"; break;
1158 case IH_CPU_I386: arch = "Intel x86"; break;
1159 case IH_CPU_IA64: arch = "IA64"; break;
1160 case IH_CPU_MIPS: arch = "MIPS"; break;
1161 case IH_CPU_MIPS64: arch = "MIPS 64 Bit"; break;
1162 case IH_CPU_PPC: arch = "PowerPC"; break;
1163 case IH_CPU_S390: arch = "IBM S390"; break;
1164 case IH_CPU_SH: arch = "SuperH"; break;
1165 case IH_CPU_SPARC: arch = "SPARC"; break;
1166 case IH_CPU_SPARC64: arch = "SPARC 64 Bit"; break;
wdenk8564acf2003-07-14 22:13:32 +00001167 case IH_CPU_M68K: arch = "M68K"; break;
wdenk47d1a6e2002-11-03 00:01:44 +00001168 default: arch = "Unknown Architecture"; break;
1169 }
1170
1171 switch (hdr->ih_type) {
1172 case IH_TYPE_INVALID: type = "Invalid Image"; break;
1173 case IH_TYPE_STANDALONE:type = "Standalone Program"; break;
1174 case IH_TYPE_KERNEL: type = "Kernel Image"; break;
1175 case IH_TYPE_RAMDISK: type = "RAMDisk Image"; break;
1176 case IH_TYPE_MULTI: type = "Multi-File Image"; break;
1177 case IH_TYPE_FIRMWARE: type = "Firmware"; break;
1178 case IH_TYPE_SCRIPT: type = "Script"; break;
1179 default: type = "Unknown Image"; break;
1180 }
1181
1182 switch (hdr->ih_comp) {
1183 case IH_COMP_NONE: comp = "uncompressed"; break;
1184 case IH_COMP_GZIP: comp = "gzip compressed"; break;
1185 case IH_COMP_BZIP2: comp = "bzip2 compressed"; break;
1186 default: comp = "unknown compression"; break;
1187 }
1188
1189 printf ("%s %s %s (%s)", arch, os, type, comp);
1190}
1191
1192#define ZALLOC_ALIGNMENT 16
1193
1194static void *zalloc(void *x, unsigned items, unsigned size)
1195{
1196 void *p;
1197
1198 size *= items;
1199 size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
1200
1201 p = malloc (size);
1202
1203 return (p);
1204}
1205
1206static void zfree(void *x, void *addr, unsigned nb)
1207{
1208 free (addr);
1209}
1210
1211#define HEAD_CRC 2
1212#define EXTRA_FIELD 4
1213#define ORIG_NAME 8
1214#define COMMENT 0x10
1215#define RESERVED 0xe0
1216
1217#define DEFLATED 8
1218
1219int gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
1220{
1221 z_stream s;
1222 int r, i, flags;
1223
1224 /* skip header */
1225 i = 10;
1226 flags = src[3];
1227 if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
1228 printf ("Error: Bad gzipped data\n");
1229 return (-1);
1230 }
1231 if ((flags & EXTRA_FIELD) != 0)
1232 i = 12 + src[10] + (src[11] << 8);
1233 if ((flags & ORIG_NAME) != 0)
1234 while (src[i++] != 0)
1235 ;
1236 if ((flags & COMMENT) != 0)
1237 while (src[i++] != 0)
1238 ;
1239 if ((flags & HEAD_CRC) != 0)
1240 i += 2;
1241 if (i >= *lenp) {
1242 printf ("Error: gunzip out of data in header\n");
1243 return (-1);
1244 }
1245
1246 s.zalloc = zalloc;
1247 s.zfree = zfree;
1248#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
1249 s.outcb = (cb_func)WATCHDOG_RESET;
1250#else
1251 s.outcb = Z_NULL;
1252#endif /* CONFIG_HW_WATCHDOG */
1253
1254 r = inflateInit2(&s, -MAX_WBITS);
1255 if (r != Z_OK) {
1256 printf ("Error: inflateInit2() returned %d\n", r);
1257 return (-1);
1258 }
1259 s.next_in = src + i;
1260 s.avail_in = *lenp - i;
1261 s.next_out = dst;
1262 s.avail_out = dstlen;
1263 r = inflate(&s, Z_FINISH);
1264 if (r != Z_OK && r != Z_STREAM_END) {
1265 printf ("Error: inflate() returned %d\n", r);
1266 return (-1);
1267 }
1268 *lenp = s.next_out - (unsigned char *) dst;
1269 inflateEnd(&s);
1270
1271 return (0);
1272}
1273
wdenkc29fdfc2003-08-29 20:57:53 +00001274#ifdef CONFIG_BZIP2
1275void bz_internal_error(int errcode)
1276{
1277 printf ("BZIP2 internal error %d\n", errcode);
1278}
1279#endif /* CONFIG_BZIP2 */
1280
wdenkd791b1d2003-04-20 14:04:18 +00001281static void
1282do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1283 ulong addr, ulong *len_ptr, int verify)
1284{
1285 DECLARE_GLOBAL_DATA_PTR;
1286 image_header_t *hdr = &header;
1287 void (*entry_point)(bd_t *);
1288
1289 entry_point = (void (*)(bd_t *)) hdr->ih_ep;
1290
1291 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1292 (ulong)entry_point);
1293
1294 SHOW_BOOT_PROGRESS (15);
1295
1296 /*
1297 * RTEMS Parameters:
1298 * r3: ptr to board info data
1299 */
1300
1301 (*entry_point ) ( gd->bd );
1302}
1303
wdenk47d1a6e2002-11-03 00:01:44 +00001304#if (CONFIG_COMMANDS & CFG_CMD_ELF)
1305static void
1306do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1307 ulong addr, ulong *len_ptr, int verify)
1308{
1309 image_header_t *hdr = &header;
1310 char str[80];
1311
1312 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1313 setenv("loadaddr", str);
1314 do_bootvx(cmdtp, 0, 0, NULL);
1315}
1316
1317static void
1318do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1319 ulong addr, ulong *len_ptr, int verify)
1320{
1321 image_header_t *hdr = &header;
1322 char *local_args[2];
1323 char str[16];
1324
1325 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1326 local_args[0] = argv[0];
1327 local_args[1] = str; /* and provide it via the arguments */
1328 do_bootelf(cmdtp, 0, 2, local_args);
1329}
1330#endif /* CFG_CMD_ELF */
wdenk1f4bb372003-07-27 00:21:01 +00001331
1332#ifdef CONFIG_LYNXKDI
1333static void
1334do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
1335 int argc, char *argv[],
1336 ulong addr,
1337 ulong *len_ptr,
1338 int verify)
1339{
1340 lynxkdi_boot( &header );
1341}
1342
1343#endif /* CONFIG_LYNXKDI */