3 * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4 * Marius Groeger <mgroeger@sysgo.de>
6 * Copyright (C) 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
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
29 #include <asm/byteorder.h>
31 #include <asm/setup.h>
32 #define tag_size(type) ((sizeof(struct tag_header) + sizeof(struct type)) >> 2)
33 #define tag_next(t) ((struct tag *)((u32 *)(t) + (t)->hdr.size))
35 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
36 defined (CONFIG_CMDLINE_TAG) || \
37 defined (CONFIG_INITRD_TAG) || \
39 static void setup_start_tag(bd_t *bd);
40 # ifdef CONFIG_SETUP_MEMORY_TAGS
41 static void setup_memory_tags(bd_t *bd);
43 static void setup_commandline_tag(bd_t *bd, char *commandline);
45 static void setup_ramdisk_tag(bd_t *bd);
47 # ifdef CONFIG_INITRD_TAG
48 static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end);
50 static void setup_end_tag(bd_t *bd);
51 # if defined (CONFIG_VFD)
52 static void setup_videolfb_tag(gd_t *gd);
56 static struct tag *params;
57 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
59 #ifdef CONFIG_SHOW_BOOT_PROGRESS
60 # include <status_led.h>
61 # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
63 # define SHOW_BOOT_PROGRESS(arg)
66 extern image_header_t header; /* from cmd_bootm.c */
69 void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
70 ulong addr, ulong *len_ptr, int verify)
72 DECLARE_GLOBAL_DATA_PTR;
74 ulong len = 0, checksum;
75 ulong initrd_start, initrd_end;
77 void (*theKernel)(int zero, int arch);
78 image_header_t *hdr = &header;
80 #ifdef CONFIG_CMDLINE_TAG
81 char *commandline = getenv("bootargs");
84 theKernel = (void (*)(int, int))ntohl(hdr->ih_ep);
87 * Check if there is an initrd image
90 SHOW_BOOT_PROGRESS (9);
92 addr = simple_strtoul(argv[2], NULL, 16);
94 printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
96 /* Copy header so we can blank CRC field for re-calculation */
97 memcpy (&header, (char *)addr, sizeof(image_header_t));
99 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
100 printf ("Bad Magic Number\n");
101 SHOW_BOOT_PROGRESS (-10);
102 do_reset (cmdtp, flag, argc, argv);
105 data = (ulong)&header;
106 len = sizeof(image_header_t);
108 checksum = ntohl(hdr->ih_hcrc);
111 if (crc32 (0, (char *)data, len) != checksum) {
112 printf ("Bad Header Checksum\n");
113 SHOW_BOOT_PROGRESS (-11);
114 do_reset (cmdtp, flag, argc, argv);
117 SHOW_BOOT_PROGRESS (10);
119 print_image_hdr (hdr);
121 data = addr + sizeof(image_header_t);
122 len = ntohl(hdr->ih_size);
127 printf (" Verifying Checksum ... ");
128 csum = crc32 (0, (char *)data, len);
129 if (csum != ntohl(hdr->ih_dcrc)) {
130 printf ("Bad Data CRC\n");
131 SHOW_BOOT_PROGRESS (-12);
132 do_reset (cmdtp, flag, argc, argv);
137 SHOW_BOOT_PROGRESS (11);
139 if ((hdr->ih_os != IH_OS_LINUX) ||
140 (hdr->ih_arch != IH_CPU_ARM) ||
141 (hdr->ih_type != IH_TYPE_RAMDISK) ) {
142 printf ("No Linux ARM Ramdisk Image\n");
143 SHOW_BOOT_PROGRESS (-13);
144 do_reset (cmdtp, flag, argc, argv);
148 * Now check if we have a multifile image
150 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
151 ulong tail = ntohl(len_ptr[0]) % 4;
154 SHOW_BOOT_PROGRESS (13);
156 /* skip kernel length and terminator */
157 data = (ulong)(&len_ptr[2]);
158 /* skip any additional image length fields */
159 for (i=1; len_ptr[i]; ++i)
161 /* add kernel length, and align */
162 data += ntohl(len_ptr[0]);
167 len = ntohl(len_ptr[1]);
173 SHOW_BOOT_PROGRESS (14);
180 printf ("No initrd\n");
186 initrd_end = initrd_start + len;
192 SHOW_BOOT_PROGRESS (15);
195 printf ("## Transferring control to Linux (at address %08lx) ...\n",
199 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
200 defined (CONFIG_CMDLINE_TAG) || \
201 defined (CONFIG_INITRD_TAG) || \
204 #ifdef CONFIG_SETUP_MEMORY_TAGS
205 setup_memory_tags(bd);
207 #ifdef CONFIG_CMDLINE_TAG
208 setup_commandline_tag(bd, commandline);
210 #ifdef CONFIG_INITRD_TAG
211 setup_initrd_tag(bd, initrd_start, initrd_end);
214 setup_ramdisk_tag(bd);
216 #if defined (CONFIG_VFD)
217 setup_videolfb_tag(gd);
222 /* we assume that the kernel is in place */
223 printf("\nStarting kernel ...\n\n");
225 cleanup_before_linux();
227 theKernel(0, bd->bi_arch_number);
231 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
232 defined (CONFIG_CMDLINE_TAG) || \
233 defined (CONFIG_INITRD_TAG) || \
235 static void setup_start_tag(bd_t *bd)
237 params = (struct tag *)bd->bi_boot_params;
239 params->hdr.tag = ATAG_CORE;
240 params->hdr.size = tag_size(tag_core);
242 params->u.core.flags = 0;
243 params->u.core.pagesize = 0;
244 params->u.core.rootdev = 0;
246 params = tag_next(params);
250 #ifdef CONFIG_SETUP_MEMORY_TAGS
251 static void setup_memory_tags(bd_t *bd)
255 for(i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
256 params->hdr.tag = ATAG_MEM;
257 params->hdr.size = tag_size(tag_mem32);
259 params->u.mem.start = bd->bi_dram[i].start;
260 params->u.mem.size = bd->bi_dram[i].size;
262 params = tag_next(params);
265 #endif /* CONFIG_SETUP_MEMORY_TAGS */
268 static void setup_commandline_tag(bd_t *bd, char *commandline)
272 /* eat leading white space */
273 for(p = commandline; *p == ' '; p++)
276 /* skip non-existent command lines so the kernel will still
277 * use its default command line.
282 params->hdr.tag = ATAG_CMDLINE;
283 params->hdr.size = (sizeof(struct tag_header) + strlen(p) + 1 + 4) >> 2;
285 strcpy(params->u.cmdline.cmdline, p);
287 params = tag_next(params);
292 #define ATAG_INITRD2 0x54420005
295 #ifdef CONFIG_INITRD_TAG
296 static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end)
298 /* an ATAG_INITRD node tells the kernel where the compressed
299 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
301 params->hdr.tag = ATAG_INITRD2;
302 params->hdr.size = tag_size(tag_initrd);
304 params->u.initrd.start = initrd_start;
305 params->u.initrd.size = initrd_end - initrd_start;
307 params = tag_next(params);
309 #endif /* CONFIG_INITRD_TAG */
313 static void setup_ramdisk_tag(bd_t *bd)
315 /* an ATAG_RAMDISK node tells the kernel how large the
316 * decompressed ramdisk will become.
318 params->hdr.tag = ATAG_RAMDISK;
319 params->hdr.size = tag_size(tag_ramdisk);
321 params->u.ramdisk.start = 0;
322 /*params->u.ramdisk.size = RAMDISK_SIZE; */
323 params->u.ramdisk.flags = 1; /* automatically load ramdisk */
325 params = tag_next(params);
329 #if defined (CONFIG_VFD)
330 static void setup_videolfb_tag(gd_t *gd)
332 /* An ATAG_VIDEOLFB node tells the kernel where and how large
333 * the framebuffer for video was allocated (among other things).
334 * Note that a _physical_ address is passed !
336 * We only use it to pass the address and size, the other entries
337 * in the tag_videolfb are not of interest.
339 params->hdr.tag = ATAG_VIDEOLFB;
340 params->hdr.size = tag_size(tag_videolfb);
342 params->u.videolfb.lfb_base = (u32)gd->fb_base;
343 /* 7168 = 256*4*56/8 - actually 2 pages (8192 bytes) are allocated */
344 params->u.videolfb.lfb_size = 7168;
346 params = tag_next(params);
350 static void setup_end_tag(bd_t *bd)
352 params->hdr.tag = ATAG_NONE;
353 params->hdr.size = 0;
356 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */