2 * (C) Copyright 2000-2002
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
34 #include <environment.h>
35 #include <asm/byteorder.h>
38 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
40 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
44 #ifdef CFG_HUSH_PARSER
48 #ifdef CONFIG_SHOW_BOOT_PROGRESS
49 # include <status_led.h>
50 # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
52 # define SHOW_BOOT_PROGRESS(arg)
55 #ifdef CFG_INIT_RAM_LOCK
56 #include <asm/cache.h>
59 #ifdef CONFIG_LOGBUFFER
63 #ifdef CONFIG_HAS_DATAFLASH
64 #include <dataflash.h>
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.
72 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
73 # define CHUNKSZ (64 * 1024)
76 int gunzip (void *, int, unsigned char *, int *);
78 static void *zalloc(void *, unsigned, unsigned);
79 static void zfree(void *, void *, unsigned);
81 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
82 static int image_info (unsigned long addr);
85 #if (CONFIG_COMMANDS & CFG_CMD_IMLS)
87 extern flash_info_t flash_info[CFG_MAX_FLASH_BANKS]; /* info for FLASH chips */
88 static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
91 static void print_type (image_header_t *hdr);
94 image_header_t *fake_header(image_header_t *hdr, void *ptr, int size);
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.
105 typedef 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' */
112 extern int do_bdinfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
116 static boot_os_Fcn do_bootm_linux;
118 extern boot_os_Fcn do_bootm_linux;
120 #ifdef CONFIG_SILENT_CONSOLE
121 static void fixup_silent_linux (void);
123 static boot_os_Fcn do_bootm_netbsd;
124 static boot_os_Fcn do_bootm_rtems;
125 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
126 static boot_os_Fcn do_bootm_vxworks;
127 static boot_os_Fcn do_bootm_qnxelf;
128 int do_bootvx ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
129 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[] );
130 #endif /* CFG_CMD_ELF */
131 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
132 static boot_os_Fcn do_bootm_artos;
134 #ifdef CONFIG_LYNXKDI
135 static boot_os_Fcn do_bootm_lynxkdi;
136 extern void lynxkdi_boot( image_header_t * );
139 image_header_t header;
141 ulong load_addr = CFG_LOAD_ADDR; /* Default Load Address */
143 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
147 ulong data, len, checksum;
149 uint unc_len = 0x400000;
152 int (*appl)(cmd_tbl_t *, int, int, char *[]);
153 image_header_t *hdr = &header;
155 s = getenv ("verify");
156 verify = (s && (*s == 'n')) ? 0 : 1;
161 addr = simple_strtoul(argv[1], NULL, 16);
164 SHOW_BOOT_PROGRESS (1);
165 printf ("## Booting image at %08lx ...\n", addr);
167 /* Copy header so we can blank CRC field for re-calculation */
168 #ifdef CONFIG_HAS_DATAFLASH
169 if (addr_dataflash(addr)){
170 read_dataflash(addr, sizeof(image_header_t), (char *)&header);
173 memmove (&header, (char *)addr, sizeof(image_header_t));
175 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
176 #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);
181 * fake_header() does not fake the data crc
185 #endif /* __I386__ */
187 printf ("Bad Magic Number\n");
188 SHOW_BOOT_PROGRESS (-1);
192 SHOW_BOOT_PROGRESS (2);
194 data = (ulong)&header;
195 len = sizeof(image_header_t);
197 checksum = ntohl(hdr->ih_hcrc);
200 if (crc32 (0, (char *)data, len) != checksum) {
201 printf ("Bad Header Checksum\n");
202 SHOW_BOOT_PROGRESS (-2);
205 SHOW_BOOT_PROGRESS (3);
207 /* for multi-file images we need the data part, too */
208 print_image_hdr ((image_header_t *)addr);
210 data = addr + sizeof(image_header_t);
211 len = ntohl(hdr->ih_size);
213 #ifdef CONFIG_HAS_DATAFLASH
214 if (addr_dataflash(addr)){
215 read_dataflash(data, len, (char *)CFG_LOAD_ADDR);
216 data = CFG_LOAD_ADDR;
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);
229 SHOW_BOOT_PROGRESS (4);
231 len_ptr = (ulong *)data;
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)
239 #elif defined(__mips__)
240 if (hdr->ih_arch != IH_CPU_MIPS)
241 #elif defined(__nios__)
242 if (hdr->ih_arch != IH_CPU_NIOS)
244 # error Unknown CPU type
247 printf ("Unsupported Architecture 0x%x\n", hdr->ih_arch);
248 SHOW_BOOT_PROGRESS (-4);
251 SHOW_BOOT_PROGRESS (5);
253 switch (hdr->ih_type) {
254 case IH_TYPE_STANDALONE: name = "Standalone Application";
255 /* A second argument overwrites the load address */
257 hdr->ih_load = simple_strtoul(argv[2], NULL, 16);
260 case IH_TYPE_KERNEL: name = "Kernel Image";
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)
269 default: printf ("Wrong Image Type for %s command\n", cmdtp->name);
270 SHOW_BOOT_PROGRESS (-5);
273 SHOW_BOOT_PROGRESS (6);
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...
281 iflag = disable_interrupts();
283 #ifdef CONFIG_AMIGAONEG3SE
285 * We've possible left the caches enabled during
286 * bios emulation, so turn them off again
289 invalidate_l1_instruction_cache();
294 switch (hdr->ih_comp) {
296 if(ntohl(hdr->ih_load) == addr) {
297 printf (" XIP %s ... ", name);
299 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
301 void *to = (void *)ntohl(hdr->ih_load);
302 void *from = (void *)data;
304 printf (" Loading %s ... ", name);
307 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
309 memmove (to, from, tail);
314 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
315 memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
316 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
320 printf (" Uncompressing %s ... ", name);
321 if (gunzip ((void *)ntohl(hdr->ih_load), unc_len,
322 (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);
330 printf (" Uncompressing %s ... ", name);
331 i = BZ2_bzBuffToBuffDecompress ((char*)ntohl(hdr->ih_load),
332 &unc_len, (char *)data, len, 0, 0);
334 printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
335 SHOW_BOOT_PROGRESS (-6);
337 do_reset (cmdtp, flag, argc, argv);
340 #endif /* CONFIG_BZIP2 */
344 printf ("Unimplemented compression type %d\n", hdr->ih_comp);
345 SHOW_BOOT_PROGRESS (-7);
349 SHOW_BOOT_PROGRESS (7);
351 switch (hdr->ih_type) {
352 case IH_TYPE_STANDALONE:
356 /* load (and uncompress), but don't start if "autostart"
359 if (((s = getenv("autostart")) != NULL) && (strcmp(s,"no") == 0)) {
361 sprintf(buf, "%lX", len);
362 setenv("filesize", buf);
365 appl = (int (*)(cmd_tbl_t *, int, int, char *[]))ntohl(hdr->ih_ep);
366 (*appl)(cmdtp, flag, argc-1, &argv[1]);
375 printf ("Can't boot image type %d\n", hdr->ih_type);
376 SHOW_BOOT_PROGRESS (-8);
379 SHOW_BOOT_PROGRESS (8);
381 switch (hdr->ih_os) {
382 default: /* handled by (original) Linux case */
384 #ifdef CONFIG_SILENT_CONSOLE
385 fixup_silent_linux();
387 do_bootm_linux (cmdtp, flag, argc, argv,
388 addr, len_ptr, verify);
391 do_bootm_netbsd (cmdtp, flag, argc, argv,
392 addr, len_ptr, verify);
395 #ifdef CONFIG_LYNXKDI
397 do_bootm_lynxkdi (cmdtp, flag, argc, argv,
398 addr, len_ptr, verify);
403 do_bootm_rtems (cmdtp, flag, argc, argv,
404 addr, len_ptr, verify);
407 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
409 do_bootm_vxworks (cmdtp, flag, argc, argv,
410 addr, len_ptr, verify);
413 do_bootm_qnxelf (cmdtp, flag, argc, argv,
414 addr, len_ptr, verify);
416 #endif /* CFG_CMD_ELF */
419 do_bootm_artos (cmdtp, flag, argc, argv,
420 addr, len_ptr, verify);
425 SHOW_BOOT_PROGRESS (-9);
427 printf ("\n## Control returned to monitor - resetting...\n");
428 do_reset (cmdtp, flag, argc, argv);
434 bootm, CFG_MAXARGS, 1, do_bootm,
435 "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"
441 #ifdef CONFIG_SILENT_CONSOLE
443 fixup_silent_linux ()
445 DECLARE_GLOBAL_DATA_PTR;
446 char buf[256], *start, *end;
447 char *cmdline = getenv ("bootargs");
449 /* Only fix cmdline when requested */
450 if (!(gd->flags & GD_FLG_SILENT))
453 debug ("before silent fix-up: %s\n", cmdline);
455 if ((start = strstr (cmdline, "console=")) != NULL) {
456 end = strchr (start, ' ');
457 strncpy (buf, cmdline, (start - cmdline + 8));
459 strcpy (buf + (start - cmdline + 8), end);
461 buf[start - cmdline + 8] = '\0';
463 strcpy (buf, cmdline);
464 strcat (buf, " console=");
467 strcpy (buf, "console=");
470 setenv ("bootargs", buf);
471 debug ("after silent fix-up: %s\n", buf);
473 #endif /* CONFIG_SILENT_CONSOLE */
477 do_bootm_linux (cmd_tbl_t *cmdtp, int flag,
478 int argc, char *argv[],
483 DECLARE_GLOBAL_DATA_PTR;
487 ulong initrd_start, initrd_end;
488 ulong cmd_start, cmd_end;
491 int initrd_copy_to_ram = 1;
495 void (*kernel)(bd_t *, ulong, ulong, ulong, ulong);
496 image_header_t *hdr = &header;
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.
502 initrd_high = simple_strtoul(s, NULL, 16);
503 if (initrd_high == ~0)
504 initrd_copy_to_ram = 0;
505 } else { /* not set, no restrictions to load high */
509 #ifdef CONFIG_LOGBUFFER
511 /* 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);
518 * Booting a (Linux) kernel image
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
527 asm( "mr %0,1": "=r"(sp) : );
529 debug ("## Current stack ends at 0x%08lX ", sp);
531 sp -= 2048; /* just to be sure */
532 if (sp > CFG_BOOTMAPSZ)
536 debug ("=> set upper limit to 0x%08lX\n", sp);
538 cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
539 kbd = (bd_t *)(((ulong)cmdline - sizeof(bd_t)) & ~0xF);
541 if ((s = getenv("bootargs")) == NULL)
546 cmd_start = (ulong)&cmdline[0];
547 cmd_end = cmd_start + strlen(cmdline);
552 printf ("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
554 do_bdinfo (NULL, 0, 0, NULL);
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;
561 #if defined(CONFIG_8260) || defined(CONFIG_MPC8560)
562 kbd->bi_cpmfreq /= 1000000L;
563 kbd->bi_brgfreq /= 1000000L;
564 kbd->bi_sccfreq /= 1000000L;
565 kbd->bi_vco /= 1000000L;
566 #endif /* CONFIG_8260 */
567 #if defined(CONFIG_MPC5XXXX)
568 kbd->bi_ipbfreq /= 1000000L;
569 kbd->bi_pcifreq /= 1000000L;
570 #endif /* CONFIG_MPC5XXXX */
573 kernel = (void (*)(bd_t *, ulong, ulong, ulong, ulong))hdr->ih_ep;
576 * Check if there is an initrd image
579 SHOW_BOOT_PROGRESS (9);
581 addr = simple_strtoul(argv[2], NULL, 16);
583 printf ("## Loading RAMDisk Image at %08lx ...\n", addr);
585 /* Copy header so we can blank CRC field for re-calculation */
586 memmove (&header, (char *)addr, sizeof(image_header_t));
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);
594 data = (ulong)&header;
595 len = sizeof(image_header_t);
597 checksum = hdr->ih_hcrc;
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);
606 SHOW_BOOT_PROGRESS (10);
608 print_image_hdr (hdr);
610 data = addr + sizeof(image_header_t);
615 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
616 ulong cdata = data, edata = cdata + len;
617 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
619 printf (" Verifying Checksum ... ");
621 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
623 while (cdata < edata) {
624 ulong chunk = edata - cdata;
628 csum = crc32 (csum, (char *)cdata, chunk);
633 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
634 csum = crc32 (0, (char *)data, len);
635 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
637 if (csum != hdr->ih_dcrc) {
638 printf ("Bad Data CRC\n");
639 SHOW_BOOT_PROGRESS (-12);
640 do_reset (cmdtp, flag, argc, argv);
645 SHOW_BOOT_PROGRESS (11);
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);
656 * Now check if we have a multifile image
658 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
659 u_long tail = ntohl(len_ptr[0]) % 4;
662 SHOW_BOOT_PROGRESS (13);
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)
669 /* add kernel length, and align */
670 data += ntohl(len_ptr[0]);
675 len = ntohl(len_ptr[1]);
681 SHOW_BOOT_PROGRESS (14);
687 debug ("No initrd\n");
691 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
693 initrd_end = initrd_start + len;
695 initrd_start = (ulong)kbd - len;
696 initrd_start &= ~(4096 - 1); /* align on page */
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.
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.
711 asm( "mr %0,1": "=r"(nsp) : );
712 nsp -= 2048; /* just to be sure */
714 if (nsp > initrd_high) /* limit as specified */
717 nsp &= ~(4096 - 1); /* align on page */
722 SHOW_BOOT_PROGRESS (12);
724 debug ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
725 data, data + len - 1, len, len);
727 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)
733 void *to = (void *)initrd_start;
734 void *from = (void *)data;
737 size_t tail = (l > CHUNKSZ) ? CHUNKSZ : l;
739 memmove (to, from, tail);
745 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
746 memmove ((void *)initrd_start, (void *)data, len);
747 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
756 debug ("## Transferring control to Linux (at address %08lx) ...\n",
759 SHOW_BOOT_PROGRESS (15);
761 #if defined(CFG_INIT_RAM_LOCK) && !defined(CONFIG_E500)
762 unlock_ram_in_cache();
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
772 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
774 #endif /* CONFIG_PPC */
777 do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
778 int argc, char *argv[],
783 DECLARE_GLOBAL_DATA_PTR;
785 image_header_t *hdr = &header;
787 void (*loader)(bd_t *, image_header_t *, char *, char *);
788 image_header_t *img_addr;
794 * Booting a (NetBSD) kernel image
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.
806 if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1]))
807 img_addr = (image_header_t *) addr;
811 #if defined (CONFIG_8xx_CONS_SMC1)
813 #elif defined (CONFIG_8xx_CONS_SMC2)
815 #elif defined (CONFIG_8xx_CONS_SCC2)
817 #elif defined (CONFIG_8xx_CONS_SCC3)
825 for (i=2, len=0 ; i<argc ; i+=1)
826 len += strlen (argv[i]) + 1;
827 cmdline = malloc (len);
829 for (i=2, len=0 ; i<argc ; i+=1) {
831 cmdline[len++] = ' ';
832 strcpy (&cmdline[len], argv[i]);
833 len += strlen (argv[i]);
835 } else if ((cmdline = getenv("bootargs")) == NULL) {
839 loader = (void (*)(bd_t *, image_header_t *, char *, char *)) hdr->ih_ep;
841 printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
844 SHOW_BOOT_PROGRESS (15);
847 * NetBSD Stage-2 Loader Parameters:
848 * r3: ptr to board info data
851 * r6: boot args string
853 (*loader) (gd->bd, img_addr, consdev, cmdline);
856 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
858 /* Function that returns a character from the environment */
859 extern uchar (*env_get_char)(int);
862 do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
863 int argc, char *argv[],
868 DECLARE_GLOBAL_DATA_PTR;
872 int i, j, nxt, len, envno, envsz;
874 void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
875 image_header_t *hdr = &header;
878 * Booting an ARTOS kernel image + application
881 /* this used to be the top of memory, but was wrong... */
883 /* get stack pointer */
884 asm volatile ("mr %0,1" : "=r"(top) );
886 debug ("## Current stack ends at 0x%08lX ", top);
888 top -= 2048; /* just to be sure */
889 if (top > CFG_BOOTMAPSZ)
893 debug ("=> set upper limit to 0x%08lX\n", top);
895 /* first check the artos specific boot args, then the linux args*/
896 if ((s = getenv("abootargs")) == NULL && (s = getenv("bootargs")) == NULL)
899 /* get length of cmdline, and place it */
901 top = (top - (len + 1)) & ~0xF;
902 cmdline = (char *)top;
903 debug ("## cmdline at 0x%08lX ", top);
907 top = (top - sizeof(bd_t)) & ~0xF;
908 debug ("## bd at 0x%08lX ", top);
910 memcpy(kbd, gd->bd, sizeof(bd_t));
912 /* first find number of env entries, and their size */
915 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
916 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
919 envsz += (nxt - i) + 1; /* plus trailing zero */
921 envno++; /* plus the terminating zero */
922 debug ("## %u envvars total size %u ", envno, envsz);
924 top = (top - sizeof(char **)*envno) & ~0xF;
925 fwenv = (char **)top;
926 debug ("## fwenv at 0x%08lX ", top);
928 top = (top - envsz) & ~0xF;
933 for (i = 0; env_get_char(i) != '\0'; i = nxt + 1) {
934 for (nxt = i; env_get_char(nxt) != '\0'; ++nxt)
937 for (j = i; j < nxt; ++j)
938 *s++ = env_get_char(j);
941 *ss++ = NULL; /* terminate */
943 entry = (void (*)(bd_t *, char *, char **, ulong))ntohl(hdr->ih_ep);
944 (*entry)(kbd, cmdline, fwenv, top);
949 #if (CONFIG_COMMANDS & CFG_CMD_BOOTD)
950 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
953 #ifndef CFG_HUSH_PARSER
954 if (run_command (getenv ("bootcmd"), flag) < 0) rcode = 1;
956 if (parse_string_outer(getenv("bootcmd"),
957 FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0 ) rcode = 1;
963 boot, 1, 1, do_bootd,
964 "boot - boot default, i.e., run 'bootcmd'\n",
968 /* keep old command name "bootd" for backward compatibility */
970 bootd, 1, 1, do_bootd,
971 "bootd - boot default, i.e., run 'bootcmd'\n",
977 #if (CONFIG_COMMANDS & CFG_CMD_IMI)
978 int do_iminfo ( cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
985 return image_info (load_addr);
988 for (arg=1; arg <argc; ++arg) {
989 addr = simple_strtoul(argv[arg], NULL, 16);
990 if (image_info (addr) != 0) rcode = 1;
995 static int image_info (ulong addr)
997 ulong data, len, checksum;
998 image_header_t *hdr = &header;
1000 printf ("\n## Checking Image at %08lx ...\n", addr);
1002 /* Copy header so we can blank CRC field for re-calculation */
1003 memmove (&header, (char *)addr, sizeof(image_header_t));
1005 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
1006 printf (" Bad Magic Number\n");
1010 data = (ulong)&header;
1011 len = sizeof(image_header_t);
1013 checksum = ntohl(hdr->ih_hcrc);
1016 if (crc32 (0, (char *)data, len) != checksum) {
1017 printf (" Bad Header Checksum\n");
1021 /* for multi-file images we need the data part, too */
1022 print_image_hdr ((image_header_t *)addr);
1024 data = addr + sizeof(image_header_t);
1025 len = ntohl(hdr->ih_size);
1027 printf (" Verifying Checksum ... ");
1028 if (crc32 (0, (char *)data, len) != ntohl(hdr->ih_dcrc)) {
1029 printf (" Bad Data CRC\n");
1037 iminfo, CFG_MAXARGS, 1, do_iminfo,
1038 "iminfo - print header information for application image\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"
1045 #endif /* CFG_CMD_IMI */
1047 #if (CONFIG_COMMANDS & CFG_CMD_IMLS)
1048 /*-----------------------------------------------------------------------
1049 * List all images found in flash.
1051 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
1055 image_header_t *hdr;
1058 for (i=0, info=&flash_info[0]; i<CFG_MAX_FLASH_BANKS; ++i, ++info) {
1059 if (info->flash_id == FLASH_UNKNOWN)
1061 for (j=0; j<CFG_MAX_FLASH_SECT; ++j) {
1063 if (!(hdr=(image_header_t *)info->start[j]) ||
1064 (ntohl(hdr->ih_magic) != IH_MAGIC))
1067 /* Copy header so we can blank CRC field for re-calculation */
1068 memmove (&header, (char *)hdr, sizeof(image_header_t));
1070 checksum = ntohl(header.ih_hcrc);
1073 if (crc32 (0, (char *)&header, sizeof(image_header_t))
1077 printf ("Image at %08lX:\n", (ulong)hdr);
1078 print_image_hdr( hdr );
1089 imls, 1, 1, do_imls,
1090 "imls - list all images found in flash\n",
1092 " - Prints information about all images found at sector\n"
1093 " boundaries in flash.\n"
1095 #endif /* CFG_CMD_IMLS */
1098 print_image_hdr (image_header_t *hdr)
1100 #if (CONFIG_COMMANDS & CFG_CMD_DATE) || defined(CONFIG_TIMESTAMP)
1101 time_t timestamp = (time_t)ntohl(hdr->ih_time);
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));
1118 if (hdr->ih_type == IH_TYPE_MULTI) {
1121 ulong *len_ptr = (ulong *)((ulong)hdr + sizeof(image_header_t));
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");
1133 print_type (image_header_t *hdr)
1135 char *os, *arch, *type, *comp;
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;
1144 case IH_OS_RTEMS: os = "RTEMS"; break;
1146 case IH_OS_ARTOS: os = "ARTOS"; break;
1148 #ifdef CONFIG_LYNXKDI
1149 case IH_OS_LYNXOS: os = "LynxOS"; break;
1151 default: os = "Unknown OS"; break;
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;
1167 case IH_CPU_M68K: arch = "M68K"; break;
1168 default: arch = "Unknown Architecture"; break;
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;
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;
1189 printf ("%s %s %s (%s)", arch, os, type, comp);
1192 #define ZALLOC_ALIGNMENT 16
1194 static void *zalloc(void *x, unsigned items, unsigned size)
1199 size = (size + ZALLOC_ALIGNMENT - 1) & ~(ZALLOC_ALIGNMENT - 1);
1206 static void zfree(void *x, void *addr, unsigned nb)
1212 #define EXTRA_FIELD 4
1214 #define COMMENT 0x10
1215 #define RESERVED 0xe0
1219 int gunzip(void *dst, int dstlen, unsigned char *src, int *lenp)
1227 if (src[2] != DEFLATED || (flags & RESERVED) != 0) {
1228 printf ("Error: Bad gzipped data\n");
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)
1236 if ((flags & COMMENT) != 0)
1237 while (src[i++] != 0)
1239 if ((flags & HEAD_CRC) != 0)
1242 printf ("Error: gunzip out of data in header\n");
1248 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
1249 s.outcb = (cb_func)WATCHDOG_RESET;
1252 #endif /* CONFIG_HW_WATCHDOG */
1254 r = inflateInit2(&s, -MAX_WBITS);
1256 printf ("Error: inflateInit2() returned %d\n", r);
1259 s.next_in = src + i;
1260 s.avail_in = *lenp - i;
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);
1268 *lenp = s.next_out - (unsigned char *) dst;
1275 void bz_internal_error(int errcode)
1277 printf ("BZIP2 internal error %d\n", errcode);
1279 #endif /* CONFIG_BZIP2 */
1282 do_bootm_rtems (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1283 ulong addr, ulong *len_ptr, int verify)
1285 DECLARE_GLOBAL_DATA_PTR;
1286 image_header_t *hdr = &header;
1287 void (*entry_point)(bd_t *);
1289 entry_point = (void (*)(bd_t *)) hdr->ih_ep;
1291 printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
1292 (ulong)entry_point);
1294 SHOW_BOOT_PROGRESS (15);
1298 * r3: ptr to board info data
1301 (*entry_point ) ( gd->bd );
1304 #if (CONFIG_COMMANDS & CFG_CMD_ELF)
1306 do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1307 ulong addr, ulong *len_ptr, int verify)
1309 image_header_t *hdr = &header;
1312 sprintf(str, "%x", hdr->ih_ep); /* write entry-point into string */
1313 setenv("loadaddr", str);
1314 do_bootvx(cmdtp, 0, 0, NULL);
1318 do_bootm_qnxelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
1319 ulong addr, ulong *len_ptr, int verify)
1321 image_header_t *hdr = &header;
1322 char *local_args[2];
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);
1330 #endif /* CFG_CMD_ELF */
1332 #ifdef CONFIG_LYNXKDI
1334 do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
1335 int argc, char *argv[],
1340 lynxkdi_boot( &header );
1343 #endif /* CONFIG_LYNXKDI */