]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - common/cmd_bootm.c
[new uImage] Add gen_get_image() routine
[karo-tx-uboot.git] / common / cmd_bootm.c
1 /*
2  * (C) Copyright 2000-2006
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 #define DEBUG
25
26 /*
27  * Boot support
28  */
29 #include <common.h>
30 #include <watchdog.h>
31 #include <command.h>
32 #include <image.h>
33 #include <malloc.h>
34 #include <zlib.h>
35 #include <bzlib.h>
36 #include <environment.h>
37 #include <asm/byteorder.h>
38
39 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
40 #include <rtc.h>
41 #endif
42
43 #ifdef CFG_HUSH_PARSER
44 #include <hush.h>
45 #endif
46
47 DECLARE_GLOBAL_DATA_PTR;
48
49 extern int gunzip (void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
50 #ifndef CFG_BOOTM_LEN
51 #define CFG_BOOTM_LEN   0x800000        /* use 8MByte as default max gunzip size */
52 #endif
53
54 #ifdef CONFIG_BZIP2
55 extern void bz_internal_error(int);
56 #endif
57
58 #if defined(CONFIG_CMD_IMI)
59 static int image_info (unsigned long addr);
60 #endif
61
62 #if defined(CONFIG_CMD_IMLS)
63 #include <flash.h>
64 extern flash_info_t flash_info[]; /* info for FLASH chips */
65 static int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
66 #endif
67
68 #ifdef CONFIG_SILENT_CONSOLE
69 static void fixup_silent_linux (void);
70 #endif
71
72 static void print_type (image_header_t *hdr);
73 static image_header_t *get_kernel (cmd_tbl_t *cmdtp, int flag,
74                 int argc, char *argv[], int verify,
75                 ulong *os_data, ulong *os_len);
76 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
77
78 /*
79  *  Continue booting an OS image; caller already has:
80  *  - copied image header to global variable `header'
81  *  - checked header magic number, checksums (both header & image),
82  *  - verified image architecture (PPC) and type (KERNEL or MULTI),
83  *  - loaded (first part of) image to header load address,
84  *  - disabled interrupts.
85  */
86 typedef void boot_os_fn (cmd_tbl_t *cmdtp, int flag,
87                         int argc, char *argv[],
88                         image_header_t *hdr,    /* of image to boot */
89                         int verify);            /* getenv("verify")[0] != 'n' */
90
91 extern boot_os_fn do_bootm_linux;
92 static boot_os_fn do_bootm_netbsd;
93 #if defined(CONFIG_LYNXKDI)
94 static boot_os_fn do_bootm_lynxkdi;
95 extern void lynxkdi_boot (image_header_t *);
96 #endif
97 static boot_os_fn do_bootm_rtems;
98 #if defined(CONFIG_CMD_ELF)
99 static boot_os_fn do_bootm_vxworks;
100 static boot_os_fn do_bootm_qnxelf;
101 int do_bootvx (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
102 int do_bootelf (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
103 #endif
104 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
105 extern uchar (*env_get_char)(int); /* Returns a character from the environment */
106 static boot_os_fn do_bootm_artos;
107 #endif
108
109 ulong load_addr = CFG_LOAD_ADDR;        /* Default Load Address */
110
111
112 /*******************************************************************/
113 /* bootm - boot application image from image in memory */
114 /*******************************************************************/
115 int do_bootm (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
116 {
117         ulong           iflag;
118         const char      *type_name;
119         uint            unc_len = CFG_BOOTM_LEN;
120         int             verify = getenv_verify();
121
122         image_header_t  *hdr;
123         ulong           os_data, os_len;
124
125         ulong           image_start, image_end;
126         ulong           load_start, load_end;
127
128         /* get kernel image header, start address and length */
129         hdr = get_kernel (cmdtp, flag, argc, argv, verify,
130                         &os_data, &os_len);
131         if (hdr == NULL)
132                 return 1;
133
134         show_boot_progress (6);
135
136         /*
137          * We have reached the point of no return: we are going to
138          * overwrite all exception vector code, so we cannot easily
139          * recover from any failures any more...
140          */
141         iflag = disable_interrupts();
142
143 #ifdef CONFIG_AMIGAONEG3SE
144         /*
145          * We've possible left the caches enabled during
146          * bios emulation, so turn them off again
147          */
148         icache_disable();
149         invalidate_l1_instruction_cache();
150         flush_data_cache();
151         dcache_disable();
152 #endif
153
154         type_name = image_get_type_name (image_get_type (hdr));
155
156         image_start = (ulong)hdr;
157         image_end = image_get_image_end (hdr);
158         load_start = image_get_load (hdr);
159         load_end = 0;
160
161         switch (image_get_comp (hdr)) {
162         case IH_COMP_NONE:
163                 if (image_get_load (hdr) == (ulong)hdr) {
164                         printf ("   XIP %s ... ", type_name);
165                 } else {
166                         printf ("   Loading %s ... ", type_name);
167
168                         memmove_wd ((void *)image_get_load (hdr),
169                                    (void *)os_data, os_len, CHUNKSZ);
170
171                         load_end = load_start + os_len;
172                         puts("OK\n");
173                 }
174                 break;
175         case IH_COMP_GZIP:
176                 printf ("   Uncompressing %s ... ", type_name);
177                 if (gunzip ((void *)image_get_load (hdr), unc_len,
178                                         (uchar *)os_data, &os_len) != 0) {
179                         puts ("GUNZIP ERROR - must RESET board to recover\n");
180                         show_boot_progress (-6);
181                         do_reset (cmdtp, flag, argc, argv);
182                 }
183
184                 load_end = load_start + os_len;
185                 break;
186 #ifdef CONFIG_BZIP2
187         case IH_COMP_BZIP2:
188                 printf ("   Uncompressing %s ... ", type_name);
189                 /*
190                  * If we've got less than 4 MB of malloc() space,
191                  * use slower decompression algorithm which requires
192                  * at most 2300 KB of memory.
193                  */
194                 int i = BZ2_bzBuffToBuffDecompress ((char*)image_get_load (hdr),
195                                         &unc_len, (char *)os_data, os_len,
196                                         CFG_MALLOC_LEN < (4096 * 1024), 0);
197                 if (i != BZ_OK) {
198                         printf ("BUNZIP2 ERROR %d - must RESET board to recover\n", i);
199                         show_boot_progress (-6);
200                         do_reset (cmdtp, flag, argc, argv);
201                 }
202
203                 load_end = load_start + unc_len;
204                 break;
205 #endif /* CONFIG_BZIP2 */
206         default:
207                 if (iflag)
208                         enable_interrupts();
209                 printf ("Unimplemented compression type %d\n", image_get_comp (hdr));
210                 show_boot_progress (-7);
211                 return 1;
212         }
213         puts ("OK\n");
214         debug ("   kernel loaded at 0x%08lx, end = 0x%08lx\n", load_start, load_end);
215         show_boot_progress (7);
216
217         if ((load_start < image_end) && (load_end > image_start)) {
218                 debug ("image_start = 0x%lX, image_end = 0x%lx\n", image_start, image_end);
219                 debug ("load_start = 0x%lx, load_end = 0x%lx\n", load_start, load_end);
220
221                 puts ("ERROR: image overwritten - must RESET the board to recover.\n");
222                 do_reset (cmdtp, flag, argc, argv);
223         }
224
225         show_boot_progress (8);
226
227         switch (image_get_os (hdr)) {
228         default:                        /* handled by (original) Linux case */
229         case IH_OS_LINUX:
230 #ifdef CONFIG_SILENT_CONSOLE
231             fixup_silent_linux();
232 #endif
233             do_bootm_linux (cmdtp, flag, argc, argv, hdr, verify);
234             break;
235
236         case IH_OS_NETBSD:
237             do_bootm_netbsd (cmdtp, flag, argc, argv, hdr, verify);
238             break;
239
240 #ifdef CONFIG_LYNXKDI
241         case IH_OS_LYNXOS:
242             do_bootm_lynxkdi (cmdtp, flag, argc, argv, hdr, verify);
243             break;
244 #endif
245
246         case IH_OS_RTEMS:
247             do_bootm_rtems (cmdtp, flag, argc, argv, hdr, verify);
248             break;
249
250 #if defined(CONFIG_CMD_ELF)
251         case IH_OS_VXWORKS:
252             do_bootm_vxworks (cmdtp, flag, argc, argv, hdr, verify);
253             break;
254
255         case IH_OS_QNX:
256             do_bootm_qnxelf (cmdtp, flag, argc, argv, hdr, verify);
257             break;
258 #endif
259
260 #ifdef CONFIG_ARTOS
261         case IH_OS_ARTOS:
262             do_bootm_artos (cmdtp, flag, argc, argv, hdr, verify);
263             break;
264 #endif
265         }
266
267         show_boot_progress (-9);
268 #ifdef DEBUG
269         puts ("\n## Control returned to monitor - resetting...\n");
270         do_reset (cmdtp, flag, argc, argv);
271 #endif
272         return 1;
273 }
274
275 /**
276  * get_kernel - find kernel image
277  * @os_data: pointer to a ulong variable, will hold os data start address
278  * @os_len: pointer to a ulong variable, will hold os data length
279  *
280  * get_kernel() tries to find a kernel image, verifies its integrity
281  * and locates kernel data.
282  *
283  * returns:
284  *     pointer to image header if valid image was found, plus kernel start
285  *     address and length, otherwise NULL
286  */
287 static image_header_t *get_kernel (cmd_tbl_t *cmdtp, int flag,
288                 int argc, char *argv[], int verify,
289                 ulong *os_data, ulong *os_len)
290 {
291         image_header_t  *hdr;
292         ulong           img_addr;
293
294         if (argc < 2) {
295                 img_addr = load_addr;
296         } else {
297                 img_addr = simple_strtoul(argv[1], NULL, 16);
298         }
299
300         show_boot_progress (1);
301         printf ("## Booting image at %08lx ...\n", img_addr);
302
303         /* copy from dataflash if needed */
304         img_addr = gen_get_image (img_addr);
305         hdr = (image_header_t *)img_addr;
306
307         if (!image_check_magic(hdr)) {
308                 puts ("Bad Magic Number\n");
309                 show_boot_progress (-1);
310                 return NULL;
311         }
312         show_boot_progress (2);
313
314         if (!image_check_hcrc (hdr)) {
315                 puts ("Bad Header Checksum\n");
316                 show_boot_progress (-2);
317                 return NULL;
318         }
319
320         show_boot_progress (3);
321         print_image_hdr (hdr);
322
323         if (verify) {
324                 puts ("   Verifying Checksum ... ");
325                 if (!image_check_dcrc (hdr)) {
326                         printf ("Bad Data CRC\n");
327                         show_boot_progress (-3);
328                         return NULL;
329                 }
330                 puts ("OK\n");
331         }
332         show_boot_progress (4);
333
334         if (!image_check_target_arch (hdr)) {
335                 printf ("Unsupported Architecture 0x%x\n", image_get_arch (hdr));
336                 show_boot_progress (-4);
337                 return NULL;
338         }
339         show_boot_progress (5);
340
341         switch (image_get_type (hdr)) {
342         case IH_TYPE_KERNEL:
343                 *os_data = image_get_data (hdr);
344                 *os_len = image_get_data_size (hdr);
345                 break;
346         case IH_TYPE_MULTI:
347                 image_multi_getimg (hdr, 0, os_data, os_len);
348                 break;
349         default:
350                 printf ("Wrong Image Type for %s command\n", cmdtp->name);
351                 show_boot_progress (-5);
352                 return NULL;
353         }
354         debug ("   kernel data at 0x%08lx, end = 0x%08lx\n",
355                         *os_data, *os_data + *os_len);
356
357         return hdr;
358 }
359
360 U_BOOT_CMD(
361         bootm,  CFG_MAXARGS,    1,      do_bootm,
362         "bootm   - boot application image from memory\n",
363         "[addr [arg ...]]\n    - boot application image stored in memory\n"
364         "\tpassing arguments 'arg ...'; when booting a Linux kernel,\n"
365         "\t'arg' can be the address of an initrd image\n"
366 #if defined(CONFIG_OF_LIBFDT)
367         "\tWhen booting a Linux kernel which requires a flat device-tree\n"
368         "\ta third argument is required which is the address of the\n"
369         "\tdevice-tree blob. To boot that kernel without an initrd image,\n"
370         "\tuse a '-' for the second argument. If you do not pass a third\n"
371         "\ta bd_info struct will be passed instead\n"
372 #endif
373 );
374
375 /*******************************************************************/
376 /* bootd - boot default image */
377 /*******************************************************************/
378 #if defined(CONFIG_CMD_BOOTD)
379 int do_bootd (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
380 {
381         int rcode = 0;
382
383 #ifndef CFG_HUSH_PARSER
384         if (run_command (getenv ("bootcmd"), flag) < 0)
385                 rcode = 1;
386 #else
387         if (parse_string_outer (getenv ("bootcmd"),
388                         FLAG_PARSE_SEMICOLON | FLAG_EXIT_FROM_LOOP) != 0)
389                 rcode = 1;
390 #endif
391         return rcode;
392 }
393
394 U_BOOT_CMD(
395         boot,   1,      1,      do_bootd,
396         "boot    - boot default, i.e., run 'bootcmd'\n",
397         NULL
398 );
399
400 /* keep old command name "bootd" for backward compatibility */
401 U_BOOT_CMD(
402         bootd, 1,       1,      do_bootd,
403         "bootd   - boot default, i.e., run 'bootcmd'\n",
404         NULL
405 );
406
407 #endif
408
409
410 /*******************************************************************/
411 /* iminfo - print header info for a requested image */
412 /*******************************************************************/
413 #if defined(CONFIG_CMD_IMI)
414 int do_iminfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
415 {
416         int     arg;
417         ulong   addr;
418         int     rcode = 0;
419
420         if (argc < 2) {
421                 return image_info (load_addr);
422         }
423
424         for (arg = 1; arg < argc; ++arg) {
425                 addr = simple_strtoul (argv[arg], NULL, 16);
426                 if (image_info (addr) != 0)
427                         rcode = 1;
428         }
429         return rcode;
430 }
431
432 static int image_info (ulong addr)
433 {
434         image_header_t *hdr = (image_header_t *)addr;
435
436         printf ("\n## Checking Image at %08lx ...\n", addr);
437
438         if (!image_check_magic (hdr)) {
439                 puts ("   Bad Magic Number\n");
440                 return 1;
441         }
442
443         if (!image_check_hcrc (hdr)) {
444                 puts ("   Bad Header Checksum\n");
445                 return 1;
446         }
447
448         print_image_hdr (hdr);
449
450         puts ("   Verifying Checksum ... ");
451         if (!image_check_dcrc (hdr)) {
452                 puts ("   Bad Data CRC\n");
453                 return 1;
454         }
455         puts ("OK\n");
456         return 0;
457 }
458
459 U_BOOT_CMD(
460         iminfo, CFG_MAXARGS,    1,      do_iminfo,
461         "iminfo  - print header information for application image\n",
462         "addr [addr ...]\n"
463         "    - print header information for application image starting at\n"
464         "      address 'addr' in memory; this includes verification of the\n"
465         "      image contents (magic number, header and payload checksums)\n"
466 );
467 #endif
468
469
470 /*******************************************************************/
471 /* imls - list all images found in flash */
472 /*******************************************************************/
473 #if defined(CONFIG_CMD_IMLS)
474 int do_imls (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
475 {
476         flash_info_t *info;
477         int i, j;
478         image_header_t *hdr;
479
480         for (i = 0, info = &flash_info[0];
481                 i < CFG_MAX_FLASH_BANKS; ++i, ++info) {
482
483                 if (info->flash_id == FLASH_UNKNOWN)
484                         goto next_bank;
485                 for (j = 0; j < info->sector_count; ++j) {
486
487                         hdr = (image_header_t *)info->start[j];
488
489                         if (!hdr || !image_check_magic (hdr))
490                                 goto next_sector;
491
492                         if (!image_check_hcrc (hdr))
493                                 goto next_sector;
494
495                         printf ("Image at %08lX:\n", (ulong)hdr);
496                         print_image_hdr (hdr);
497
498                         puts ("   Verifying Checksum ... ");
499                         if (!image_check_dcrc (hdr)) {
500                                 puts ("Bad Data CRC\n");
501                         } else {
502                                 puts ("OK\n");
503                         }
504 next_sector:            ;
505                 }
506 next_bank:      ;
507         }
508
509         return (0);
510 }
511
512 U_BOOT_CMD(
513         imls,   1,              1,      do_imls,
514         "imls    - list all images found in flash\n",
515         "\n"
516         "    - Prints information about all images found at sector\n"
517         "      boundaries in flash.\n"
518 );
519 #endif
520
521 /*******************************************************************/
522 /* helper routines */
523 /*******************************************************************/
524 void print_image_hdr (image_header_t *hdr)
525 {
526 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
527         time_t timestamp = (time_t)image_get_time (hdr);
528         struct rtc_time tm;
529 #endif
530
531         printf ("   Image Name:   %.*s\n", IH_NMLEN, image_get_name (hdr));
532
533 #if defined(CONFIG_TIMESTAMP) || defined(CONFIG_CMD_DATE)
534         to_tm (timestamp, &tm);
535         printf ("   Created:      %4d-%02d-%02d  %2d:%02d:%02d UTC\n",
536                 tm.tm_year, tm.tm_mon, tm.tm_mday,
537                 tm.tm_hour, tm.tm_min, tm.tm_sec);
538 #endif
539         puts ("   Image Type:   ");
540         print_type (hdr);
541
542         printf ("\n   Data Size:    %d Bytes = ", image_get_data_size (hdr));
543         print_size (image_get_data_size (hdr), "\n");
544         printf ("   Load Address: %08x\n"
545                 "   Entry Point:  %08x\n",
546                  image_get_load (hdr), image_get_ep (hdr));
547
548         if (image_check_type (hdr, IH_TYPE_MULTI)) {
549                 int i;
550                 ulong data, len;
551                 ulong count = image_multi_count (hdr);
552
553                 puts ("   Contents:\n");
554                 for (i = 0; i < count; i++) {
555                         image_multi_getimg (hdr, i, &data, &len);
556                         printf ("   Image %d: %8ld Bytes = ", i, len);
557                         print_size (len, "\n");
558                 }
559         }
560 }
561
562 static void print_type (image_header_t *hdr)
563 {
564         const char *os, *arch, *type, *comp;
565
566         os = image_get_os_name (image_get_os (hdr));
567         arch = image_get_arch_name (image_get_arch (hdr));
568         type = image_get_type_name (image_get_type (hdr));
569         comp = image_get_comp_name (image_get_comp (hdr));
570
571         printf ("%s %s %s (%s)", arch, os, type, comp);
572 }
573
574 #ifdef CONFIG_SILENT_CONSOLE
575 static void fixup_silent_linux ()
576 {
577         char buf[256], *start, *end;
578         char *cmdline = getenv ("bootargs");
579
580         /* Only fix cmdline when requested */
581         if (!(gd->flags & GD_FLG_SILENT))
582                 return;
583
584         debug ("before silent fix-up: %s\n", cmdline);
585         if (cmdline) {
586                 if ((start = strstr (cmdline, "console=")) != NULL) {
587                         end = strchr (start, ' ');
588                         strncpy (buf, cmdline, (start - cmdline + 8));
589                         if (end)
590                                 strcpy (buf + (start - cmdline + 8), end);
591                         else
592                                 buf[start - cmdline + 8] = '\0';
593                 } else {
594                         strcpy (buf, cmdline);
595                         strcat (buf, " console=");
596                 }
597         } else {
598                 strcpy (buf, "console=");
599         }
600
601         setenv ("bootargs", buf);
602         debug ("after silent fix-up: %s\n", buf);
603 }
604 #endif /* CONFIG_SILENT_CONSOLE */
605
606
607 /*******************************************************************/
608 /* OS booting routines */
609 /*******************************************************************/
610
611 static void do_bootm_netbsd (cmd_tbl_t *cmdtp, int flag,
612                             int argc, char *argv[],
613                             image_header_t *hdr, int verify)
614 {
615         void (*loader)(bd_t *, image_header_t *, char *, char *);
616         image_header_t *img_addr;
617         ulong kernel_data, kernel_len;
618         char *consdev;
619         char *cmdline;
620
621         /*
622          * Booting a (NetBSD) kernel image
623          *
624          * This process is pretty similar to a standalone application:
625          * The (first part of an multi-) image must be a stage-2 loader,
626          * which in turn is responsible for loading & invoking the actual
627          * kernel.  The only differences are the parameters being passed:
628          * besides the board info strucure, the loader expects a command
629          * line, the name of the console device, and (optionally) the
630          * address of the original image header.
631          */
632
633         img_addr = 0;
634         if (image_check_type (hdr, IH_TYPE_MULTI)) {
635                 image_multi_getimg (hdr, 1, &kernel_data, &kernel_len);
636                 if (kernel_len)
637                         img_addr = hdr;
638         }
639
640         consdev = "";
641 #if   defined (CONFIG_8xx_CONS_SMC1)
642         consdev = "smc1";
643 #elif defined (CONFIG_8xx_CONS_SMC2)
644         consdev = "smc2";
645 #elif defined (CONFIG_8xx_CONS_SCC2)
646         consdev = "scc2";
647 #elif defined (CONFIG_8xx_CONS_SCC3)
648         consdev = "scc3";
649 #endif
650
651         if (argc > 2) {
652                 ulong len;
653                 int   i;
654
655                 for (i = 2, len = 0; i < argc; i += 1)
656                         len += strlen (argv[i]) + 1;
657                 cmdline = malloc (len);
658
659                 for (i = 2, len = 0; i < argc; i += 1) {
660                         if (i > 2)
661                                 cmdline[len++] = ' ';
662                         strcpy (&cmdline[len], argv[i]);
663                         len += strlen (argv[i]);
664                 }
665         } else if ((cmdline = getenv ("bootargs")) == NULL) {
666                 cmdline = "";
667         }
668
669         loader = (void (*)(bd_t *, image_header_t *, char *, char *))image_get_ep (hdr);
670
671         printf ("## Transferring control to NetBSD stage-2 loader (at address %08lx) ...\n",
672                 (ulong)loader);
673
674         show_boot_progress (15);
675
676         /*
677          * NetBSD Stage-2 Loader Parameters:
678          *   r3: ptr to board info data
679          *   r4: image address
680          *   r5: console device
681          *   r6: boot args string
682          */
683         (*loader) (gd->bd, img_addr, consdev, cmdline);
684 }
685
686 #ifdef CONFIG_LYNXKDI
687 static void do_bootm_lynxkdi (cmd_tbl_t *cmdtp, int flag,
688                              int argc, char *argv[],
689                              image_header_t *hdr, int verify)
690 {
691         lynxkdi_boot (hdr);
692 }
693 #endif /* CONFIG_LYNXKDI */
694
695 static void do_bootm_rtems (cmd_tbl_t *cmdtp, int flag,
696                            int argc, char *argv[],
697                            image_header_t *hdr, int verify)
698 {
699         void (*entry_point)(bd_t *);
700
701         entry_point = (void (*)(bd_t *))image_get_ep (hdr);
702
703         printf ("## Transferring control to RTEMS (at address %08lx) ...\n",
704                 (ulong)entry_point);
705
706         show_boot_progress (15);
707
708         /*
709          * RTEMS Parameters:
710          *   r3: ptr to board info data
711          */
712         (*entry_point)(gd->bd);
713 }
714
715 #if defined(CONFIG_CMD_ELF)
716 static void do_bootm_vxworks (cmd_tbl_t *cmdtp, int flag,
717                              int argc, char *argv[],
718                              image_header_t *hdr, int verify)
719 {
720         char str[80];
721
722         sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
723         setenv("loadaddr", str);
724         do_bootvx(cmdtp, 0, 0, NULL);
725 }
726
727 static void do_bootm_qnxelf(cmd_tbl_t *cmdtp, int flag,
728                             int argc, char *argv[],
729                             image_header_t *hdr, int verify)
730 {
731         char *local_args[2];
732         char str[16];
733
734         sprintf(str, "%x", image_get_ep (hdr)); /* write entry-point into string */
735         local_args[0] = argv[0];
736         local_args[1] = str;    /* and provide it via the arguments */
737         do_bootelf(cmdtp, 0, 2, local_args);
738 }
739 #endif
740
741 #if defined(CONFIG_ARTOS) && defined(CONFIG_PPC)
742 static void do_bootm_artos (cmd_tbl_t *cmdtp, int flag,
743                            int argc, char *argv[],
744                            image_header_t *hdr, int verify)
745 {
746         ulong top;
747         char *s, *cmdline;
748         char **fwenv, **ss;
749         int i, j, nxt, len, envno, envsz;
750         bd_t *kbd;
751         void (*entry)(bd_t *bd, char *cmdline, char **fwenv, ulong top);
752
753         /*
754          * Booting an ARTOS kernel image + application
755          */
756
757         /* this used to be the top of memory, but was wrong... */
758 #ifdef CONFIG_PPC
759         /* get stack pointer */
760         asm volatile ("mr %0,1" : "=r"(top) );
761 #endif
762         debug ("## Current stack ends at 0x%08lX ", top);
763
764         top -= 2048;            /* just to be sure */
765         if (top > CFG_BOOTMAPSZ)
766                 top = CFG_BOOTMAPSZ;
767         top &= ~0xF;
768
769         debug ("=> set upper limit to 0x%08lX\n", top);
770
771         /* first check the artos specific boot args, then the linux args*/
772         if ((s = getenv( "abootargs")) == NULL && (s = getenv ("bootargs")) == NULL)
773                 s = "";
774
775         /* get length of cmdline, and place it */
776         len = strlen (s);
777         top = (top - (len + 1)) & ~0xF;
778         cmdline = (char *)top;
779         debug ("## cmdline at 0x%08lX ", top);
780         strcpy (cmdline, s);
781
782         /* copy bdinfo */
783         top = (top - sizeof (bd_t)) & ~0xF;
784         debug ("## bd at 0x%08lX ", top);
785         kbd = (bd_t *)top;
786         memcpy (kbd, gd->bd, sizeof (bd_t));
787
788         /* first find number of env entries, and their size */
789         envno = 0;
790         envsz = 0;
791         for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
792                 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
793                         ;
794                 envno++;
795                 envsz += (nxt - i) + 1; /* plus trailing zero */
796         }
797         envno++;        /* plus the terminating zero */
798         debug ("## %u envvars total size %u ", envno, envsz);
799
800         top = (top - sizeof (char **) * envno) & ~0xF;
801         fwenv = (char **)top;
802         debug ("## fwenv at 0x%08lX ", top);
803
804         top = (top - envsz) & ~0xF;
805         s = (char *)top;
806         ss = fwenv;
807
808         /* now copy them */
809         for (i = 0; env_get_char (i) != '\0'; i = nxt + 1) {
810                 for (nxt = i; env_get_char (nxt) != '\0'; ++nxt)
811                         ;
812                 *ss++ = s;
813                 for (j = i; j < nxt; ++j)
814                         *s++ = env_get_char (j);
815                 *s++ = '\0';
816         }
817         *ss++ = NULL;   /* terminate */
818
819         entry = (void (*)(bd_t *, char *, char **, ulong))image_get_ep (hdr);
820         (*entry) (kbd, cmdline, fwenv, top);
821 }
822 #endif