]> git.sur5r.net Git - u-boot/blob - lib_m68k/bootm.c
3fd38e98d15c1760a22983d55e3cc1f0ec9372fe
[u-boot] / lib_m68k / bootm.c
1 /*
2  * (C) Copyright 2003
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 modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (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, MA  02111-1307  USA
21  *
22  */
23
24 #include <common.h>
25 #include <command.h>
26 #include <image.h>
27 #include <zlib.h>
28 #include <bzlib.h>
29 #include <watchdog.h>
30 #include <environment.h>
31 #include <asm/byteorder.h>
32
33 DECLARE_GLOBAL_DATA_PTR;
34
35 #define PHYSADDR(x) x
36
37 #define LINUX_MAX_ENVS          256
38 #define LINUX_MAX_ARGS          256
39
40 #ifdef CONFIG_SHOW_BOOT_PROGRESS
41 # include <status_led.h>
42 # define SHOW_BOOT_PROGRESS(arg)        show_boot_progress(arg)
43 #else
44 # define SHOW_BOOT_PROGRESS(arg)
45 #endif
46
47 static ulong get_sp (void);
48
49 void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
50                     int argc, char *argv[],
51                     image_header_t *hdr, int verify)
52 {
53         ulong sp_limit;
54
55         ulong rd_data_start, rd_data_end, rd_len;
56         ulong initrd_start, initrd_end;
57
58         ulong cmd_start, cmd_end;
59         char *cmdline;
60         char *s;
61         bd_t *kbd;
62         void (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
63
64         /*
65          * Booting a (Linux) kernel image
66          *
67          * Allocate space for command line and board info - the
68          * address should be as high as possible within the reach of
69          * the kernel (see CFG_BOOTMAPSZ settings), but in unused
70          * memory, which means far enough below the current stack
71          * pointer.
72          */
73         sp_limit = get_sp();
74
75         debug("## Current stack ends at 0x%08lX ", sp_limit);
76
77         sp_limit -= 2048;               /* just to be sure */
78         if (sp_limit > CFG_BOOTMAPSZ)
79                 sp_limit = CFG_BOOTMAPSZ;
80         sp_limit &= ~0xF;
81
82         debug("=> set upper limit to 0x%08lX\n", sp_limit);
83
84         cmdline = (char *)((sp_limit - CFG_BARGSIZE) & ~0xF);
85         kbd = (bd_t *) (((ulong) cmdline - sizeof(bd_t)) & ~0xF);
86
87         if ((s = getenv("bootargs")) == NULL)
88                 s = "";
89
90         strcpy(cmdline, s);
91
92         cmd_start = (ulong) & cmdline[0];
93         cmd_end = cmd_start + strlen(cmdline);
94
95         *kbd = *(gd->bd);
96
97 #ifdef  DEBUG
98         printf("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
99
100         do_bdinfo(NULL, 0, 0, NULL);
101 #endif
102
103         if ((s = getenv("clocks_in_mhz")) != NULL) {
104                 /* convert all clock information to MHz */
105                 kbd->bi_intfreq /= 1000000L;
106                 kbd->bi_busfreq /= 1000000L;
107         }
108
109         /* find kernel */
110         kernel =
111             (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr);
112
113         /* find ramdisk */
114         get_ramdisk (cmdtp, flag, argc, argv, hdr, verify,
115                         IH_ARCH_M68K, &rd_data_start, &rd_data_end);
116
117         rd_len = rd_data_end - rd_data_start;
118         ramdisk_high (rd_data_start, rd_len, kdb, sp_limit, get_sp (),
119                         &initrd_start, &initrd_end);
120
121         debug("## Transferring control to Linux (at address %08lx) ...\n",
122               (ulong) kernel);
123
124         SHOW_BOOT_PROGRESS(15);
125
126         /*
127          * Linux Kernel Parameters (passing board info data):
128          *   r3: ptr to board info data
129          *   r4: initrd_start or 0 if no initrd
130          *   r5: initrd_end - unused if r4 is 0
131          *   r6: Start of command line string
132          *   r7: End   of command line string
133          */
134         (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
135         /* does not return */
136 }
137
138 static ulong get_sp (void)
139 {
140         ulong sp;
141
142         asm("movel %%a7, %%d0\n"
143             "movel %%d0, %0\n": "=d"(sp): :"%d0");
144
145         return sp;
146 }