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 static void setup_memory_tags(bd_t *bd);
41 static void setup_commandline_tag(bd_t *bd, char *commandline);
43 static void setup_ramdisk_tag(bd_t *bd);
45 static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end);
46 static void setup_end_tag(bd_t *bd);
47 #if defined (CONFIG_VFD)
48 static void setup_videolfb_tag(gd_t *gd);
52 static struct tag *params;
53 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
55 extern image_header_t header; /* from cmd_bootm.c */
58 void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
59 ulong addr, ulong *len_ptr, int verify)
61 DECLARE_GLOBAL_DATA_PTR;
63 ulong len = 0, checksum;
64 ulong initrd_start, initrd_end;
66 void (*theKernel)(int zero, int arch);
67 image_header_t *hdr = &header;
69 #ifdef CONFIG_CMDLINE_TAG
70 char *commandline = getenv("bootargs");
73 theKernel = (void (*)(int, int))ntohl(hdr->ih_ep);
76 * Check if there is an initrd image
79 addr = simple_strtoul(argv[2], NULL, 16);
81 printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
83 /* Copy header so we can blank CRC field for re-calculation */
84 memcpy (&header, (char *)addr, sizeof(image_header_t));
86 if (ntohl(hdr->ih_magic) != IH_MAGIC) {
87 printf ("Bad Magic Number\n");
88 do_reset (cmdtp, flag, argc, argv);
91 data = (ulong)&header;
92 len = sizeof(image_header_t);
94 checksum = ntohl(hdr->ih_hcrc);
97 if (crc32 (0, (char *)data, len) != checksum) {
98 printf ("Bad Header Checksum\n");
99 do_reset (cmdtp, flag, argc, argv);
102 print_image_hdr (hdr);
104 data = addr + sizeof(image_header_t);
105 len = ntohl(hdr->ih_size);
110 printf (" Verifying Checksum ... ");
111 csum = crc32 (0, (char *)data, len);
112 if (csum != ntohl(hdr->ih_dcrc)) {
113 printf ("Bad Data CRC\n");
114 do_reset (cmdtp, flag, argc, argv);
119 if ((hdr->ih_os != IH_OS_LINUX) ||
120 (hdr->ih_arch != IH_CPU_ARM) ||
121 (hdr->ih_type != IH_TYPE_RAMDISK) ) {
122 printf ("No Linux ARM Ramdisk Image\n");
123 do_reset (cmdtp, flag, argc, argv);
127 * Now check if we have a multifile image
129 } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
130 ulong tail = ntohl(len_ptr[0]) % 4;
133 /* skip kernel length and terminator */
134 data = (ulong)(&len_ptr[2]);
135 /* skip any additional image length fields */
136 for (i=1; len_ptr[i]; ++i)
138 /* add kernel length, and align */
139 data += ntohl(len_ptr[0]);
144 len = ntohl(len_ptr[1]);
155 printf ("No initrd\n");
161 initrd_end = initrd_start + len;
168 printf ("## Transferring control to Linux (at address %08lx) ...\n",
172 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
173 defined (CONFIG_CMDLINE_TAG) || \
174 defined (CONFIG_INITRD_TAG) || \
177 #ifdef CONFIG_SETUP_MEMORY_TAGS
178 setup_memory_tags(bd);
180 #ifdef CONFIG_CMDLINE_TAG
181 setup_commandline_tag(bd, commandline);
183 #ifdef CONFIG_INITRD_TAG
184 setup_initrd_tag(bd, initrd_start, initrd_end);
187 setup_ramdisk_tag(bd);
189 #if defined (CONFIG_VFD)
190 setup_videolfb_tag(gd);
195 /* we assume that the kernel is in place */
196 printf("\nStarting kernel ...\n\n");
198 cleanup_before_linux();
200 theKernel(0, bd->bi_arch_number);
204 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
205 defined (CONFIG_CMDLINE_TAG) || \
206 defined (CONFIG_INITRD_TAG) || \
208 static void setup_start_tag(bd_t *bd)
210 params = (struct tag *)bd->bi_boot_params;
212 params->hdr.tag = ATAG_CORE;
213 params->hdr.size = tag_size(tag_core);
215 params->u.core.flags = 0;
216 params->u.core.pagesize = 0;
217 params->u.core.rootdev = 0;
219 params = tag_next(params);
223 static void setup_memory_tags(bd_t *bd)
227 for(i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
228 params->hdr.tag = ATAG_MEM;
229 params->hdr.size = tag_size(tag_mem32);
231 params->u.mem.start = bd->bi_dram[i].start;
232 params->u.mem.size = bd->bi_dram[i].size;
234 params = tag_next(params);
239 static void setup_commandline_tag(bd_t *bd, char *commandline)
243 /* eat leading white space */
244 for(p = commandline; *p == ' '; p++)
247 /* skip non-existent command lines so the kernel will still
248 * use its default command line.
253 params->hdr.tag = ATAG_CMDLINE;
254 params->hdr.size = (sizeof(struct tag_header) + strlen(p) + 1 + 4) >> 2;
256 strcpy(params->u.cmdline.cmdline, p);
258 params = tag_next(params);
263 #define ATAG_INITRD2 0x54420005
265 static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end)
267 /* an ATAG_INITRD node tells the kernel where the compressed
268 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
270 params->hdr.tag = ATAG_INITRD2;
271 params->hdr.size = tag_size(tag_initrd);
273 params->u.initrd.start = initrd_start;
274 params->u.initrd.size = initrd_end - initrd_start;
276 params = tag_next(params);
281 static void setup_ramdisk_tag(bd_t *bd)
283 /* an ATAG_RAMDISK node tells the kernel how large the
284 * decompressed ramdisk will become.
286 params->hdr.tag = ATAG_RAMDISK;
287 params->hdr.size = tag_size(tag_ramdisk);
289 params->u.ramdisk.start = 0;
290 /*params->u.ramdisk.size = RAMDISK_SIZE; */
291 params->u.ramdisk.flags = 1; /* automatically load ramdisk */
293 params = tag_next(params);
297 #if defined (CONFIG_VFD)
298 static void setup_videolfb_tag(gd_t *gd)
300 /* An ATAG_VIDEOLFB node tells the kernel where and how large
301 * the framebuffer for video was allocated (among other things).
302 * Note that a _physical_ address is passed !
304 * We only use it to pass the address and size, the other entries
305 * in the tag_videolfb are not of interest.
307 params->hdr.tag = ATAG_VIDEOLFB;
308 params->hdr.size = tag_size(tag_videolfb);
310 params->u.videolfb.lfb_base = (u32)gd->fb_base;
311 /* 7168 = 256*4*56/8 - actually 2 pages (8192 bytes) are allocated */
312 params->u.videolfb.lfb_size = 7168;
314 params = tag_next(params);
318 static void setup_end_tag(bd_t *bd)
320 params->hdr.tag = ATAG_NONE;
321 params->hdr.size = 0;
324 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */