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 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.
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, MA 02111-1307 USA
30 #include <environment.h>
31 #include <asm/byteorder.h>
33 DECLARE_GLOBAL_DATA_PTR;
37 #define LINUX_MAX_ENVS 256
38 #define LINUX_MAX_ARGS 256
40 #ifdef CONFIG_SHOW_BOOT_PROGRESS
41 # include <status_led.h>
42 # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
44 # define SHOW_BOOT_PROGRESS(arg)
47 extern image_header_t header;
49 int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
51 void do_bootm_linux(cmd_tbl_t * cmdtp, int flag,
52 int argc, char *argv[],
53 ulong addr, ulong * len_ptr, int verify)
57 ulong initrd_start, initrd_end;
58 ulong cmd_start, cmd_end;
61 int initrd_copy_to_ram = 1;
65 void (*kernel) (bd_t *, ulong, ulong, ulong, ulong);
66 image_header_t *hdr = &header;
68 if ((s = getenv("initrd_high")) != NULL) {
69 /* a value of "no" or a similar string will act like 0,
70 * turning the "load high" feature off. This is intentional.
72 initrd_high = simple_strtoul(s, NULL, 16);
73 if (initrd_high == ~0)
74 initrd_copy_to_ram = 0;
75 } else { /* not set, no restrictions to load high */
79 #ifdef CONFIG_LOGBUFFER
81 /* Prevent initrd from overwriting logbuffer */
82 if (initrd_high < (kbd->bi_memsize - LOGBUFF_LEN - LOGBUFF_OVERHEAD))
83 initrd_high = kbd->bi_memsize - LOGBUFF_LEN - LOGBUFF_OVERHEAD;
84 debug("## Logbuffer at 0x%08lX ", kbd->bi_memsize - LOGBUFF_LEN);
88 * Booting a (Linux) kernel image
90 * Allocate space for command line and board info - the
91 * address should be as high as possible within the reach of
92 * the kernel (see CFG_BOOTMAPSZ settings), but in unused
93 * memory, which means far enough below the current stack
96 asm("movel %%a7, %%d0\n"
97 "movel %%d0, %0\n": "=d"(sp): :"%d0");
99 debug("## Current stack ends at 0x%08lX ", sp);
101 sp -= 2048; /* just to be sure */
102 if (sp > CFG_BOOTMAPSZ)
106 debug("=> set upper limit to 0x%08lX\n", sp);
108 cmdline = (char *)((sp - CFG_BARGSIZE) & ~0xF);
109 kbd = (bd_t *) (((ulong) cmdline - sizeof(bd_t)) & ~0xF);
111 if ((s = getenv("bootargs")) == NULL)
116 cmd_start = (ulong) & cmdline[0];
117 cmd_end = cmd_start + strlen(cmdline);
122 printf("## cmdline at 0x%08lX ... 0x%08lX\n", cmd_start, cmd_end);
124 do_bdinfo(NULL, 0, 0, NULL);
127 if ((s = getenv("clocks_in_mhz")) != NULL) {
128 /* convert all clock information to MHz */
129 kbd->bi_intfreq /= 1000000L;
130 kbd->bi_busfreq /= 1000000L;
134 (void (*)(bd_t *, ulong, ulong, ulong, ulong))image_get_ep (hdr);
137 * Check if there is an initrd image
141 debug("Not skipping initrd\n");
142 SHOW_BOOT_PROGRESS(9);
144 addr = simple_strtoul(argv[2], NULL, 16);
145 hdr = (image_header_t *)addr;
147 printf("## Loading RAMDisk Image at %08lx ...\n", addr);
149 if (!image_check_magic (hdr)) {
150 puts("Bad Magic Number\n");
151 SHOW_BOOT_PROGRESS(-10);
152 do_reset(cmdtp, flag, argc, argv);
155 if (!image_check_hcrc (hdr)) {
156 puts("Bad Header Checksum\n");
157 SHOW_BOOT_PROGRESS(-11);
158 do_reset(cmdtp, flag, argc, argv);
161 SHOW_BOOT_PROGRESS(10);
163 print_image_hdr (hdr);
165 data = image_get_data (hdr);
166 len = image_get_data_size (hdr);
169 puts(" Verifying Checksum ... ");
170 if (!image_check_dcrc_wd (hdr, CHUNKSZ)) {
171 puts("Bad Data CRC\n");
172 SHOW_BOOT_PROGRESS(-12);
173 do_reset(cmdtp, flag, argc, argv);
178 SHOW_BOOT_PROGRESS(11);
180 if (!image_check_os (hdr, IH_OS_LINUX) ||
181 !image_check_arch (hdr, IH_ARCH_M68K) ||
182 !image_check_type (hdr, IH_TYPE_RAMDISK)) {
183 puts("No Linux ColdFire Ramdisk Image\n");
184 SHOW_BOOT_PROGRESS(-13);
185 do_reset(cmdtp, flag, argc, argv);
189 * Now check if we have a multifile image
191 } else if (image_check_type (hdr, IH_TYPE_MULTI) && (len_ptr[1])) {
192 u_long tail = image_to_cpu (len_ptr[0]) % 4;
195 SHOW_BOOT_PROGRESS(13);
197 /* skip kernel length and terminator */
198 data = (ulong) (&len_ptr[2]);
199 /* skip any additional image length fields */
200 for (i = 1; len_ptr[i]; ++i)
202 /* add kernel length, and align */
203 data += image_to_cpu (len_ptr[0]);
208 len = image_to_cpu (len_ptr[1]);
214 SHOW_BOOT_PROGRESS(14);
220 debug("No initrd\n");
224 if (!initrd_copy_to_ram) { /* zero-copy ramdisk support */
226 initrd_end = initrd_start + len;
228 initrd_start = (ulong) kbd - len;
229 initrd_start &= ~(4096 - 1); /* align on page */
235 * the inital ramdisk does not need to be within
236 * CFG_BOOTMAPSZ as it is not accessed until after
237 * the mm system is initialised.
239 * do the stack bottom calculation again and see if
240 * the initrd will fit just below the monitor stack
241 * bottom without overwriting the area allocated
242 * above for command line args and board info.
244 asm("movel %%a7, %%d0\n"
245 "movel %%d0, %0\n": "=d"(nsp): :"%d0");
247 nsp -= 2048; /* just to be sure */
250 if (nsp > initrd_high) /* limit as specified */
254 nsp &= ~(4096 - 1); /* align on page */
260 SHOW_BOOT_PROGRESS(12);
263 ("## initrd at 0x%08lX ... 0x%08lX (len=%ld=0x%lX)\n",
264 data, data + len - 1, len, len);
266 initrd_end = initrd_start + len;
267 printf(" Loading Ramdisk to %08lx, end %08lx ... ",
268 initrd_start, initrd_end);
269 #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
272 void *to = (void *)initrd_start;
273 void *from = (void *)data;
277 (l > CHUNKSZ) ? CHUNKSZ : l;
279 memmove(to, from, tail);
285 #else /* !(CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG) */
286 memmove((void *)initrd_start, (void *)data, len);
287 #endif /* CONFIG_HW_WATCHDOG || CONFIG_WATCHDOG */
295 debug("## Transferring control to Linux (at address %08lx) ...\n",
298 SHOW_BOOT_PROGRESS(15);
301 * Linux Kernel Parameters (passing board info data):
302 * r3: ptr to board info data
303 * r4: initrd_start or 0 if no initrd
304 * r5: initrd_end - unused if r4 is 0
305 * r6: Start of command line string
306 * r7: End of command line string
308 (*kernel) (kbd, initrd_start, initrd_end, cmd_start, cmd_end);
309 /* does not return */