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
28 #include <asm/byteorder.h>
29 #ifdef CONFIG_HAS_DATAFLASH
30 #include <dataflash.h>
33 #include <asm/setup.h>
34 #define tag_size(type) ((sizeof(struct tag_header) + sizeof(struct type)) >> 2)
35 #define tag_next(t) ((struct tag *)((u32 *)(t) + (t)->hdr.size))
38 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
40 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
41 defined (CONFIG_CMDLINE_TAG) || \
42 defined (CONFIG_INITRD_TAG) || \
44 static void setup_start_tag (bd_t *bd);
46 # ifdef CONFIG_SETUP_MEMORY_TAGS
47 static void setup_memory_tags (bd_t *bd);
49 static void setup_commandline_tag (bd_t *bd, char *commandline);
52 static void setup_ramdisk_tag (bd_t *bd);
54 # ifdef CONFIG_INITRD_TAG
55 static void setup_initrd_tag (bd_t *bd, ulong initrd_start,
58 static void setup_end_tag (bd_t *bd);
60 # if defined (CONFIG_VFD)
61 static void setup_videolfb_tag (gd_t *gd);
65 static struct tag *params;
66 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
68 #ifdef CONFIG_SHOW_BOOT_PROGRESS
69 # include <status_led.h>
70 # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
72 # define SHOW_BOOT_PROGRESS(arg)
75 extern image_header_t header; /* from cmd_bootm.c */
78 void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
79 ulong addr, ulong *len_ptr, int verify)
81 DECLARE_GLOBAL_DATA_PTR;
83 ulong len = 0, checksum;
84 ulong initrd_start, initrd_end;
86 void (*theKernel) (int zero, int arch);
87 image_header_t *hdr = &header;
90 #ifdef CONFIG_CMDLINE_TAG
91 char *commandline = getenv ("bootargs");
94 theKernel = (void (*)(int, int)) ntohl (hdr->ih_ep);
97 * Check if there is an initrd image
100 SHOW_BOOT_PROGRESS (9);
102 addr = simple_strtoul (argv[2], NULL, 16);
104 printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
106 /* Copy header so we can blank CRC field for re-calculation */
107 #ifdef CONFIG_HAS_DATAFLASH
108 if (addr_dataflash (addr)) {
109 read_dataflash (addr, sizeof (image_header_t),
113 memcpy (&header, (char *) addr,
114 sizeof (image_header_t));
116 if (ntohl (hdr->ih_magic) != IH_MAGIC) {
117 printf ("Bad Magic Number\n");
118 SHOW_BOOT_PROGRESS (-10);
119 do_reset (cmdtp, flag, argc, argv);
122 data = (ulong) & header;
123 len = sizeof (image_header_t);
125 checksum = ntohl (hdr->ih_hcrc);
128 if (crc32 (0, (char *) data, len) != checksum) {
129 printf ("Bad Header Checksum\n");
130 SHOW_BOOT_PROGRESS (-11);
131 do_reset (cmdtp, flag, argc, argv);
134 SHOW_BOOT_PROGRESS (10);
136 print_image_hdr (hdr);
138 data = addr + sizeof (image_header_t);
139 len = ntohl (hdr->ih_size);
141 #ifdef CONFIG_HAS_DATAFLASH
142 if (addr_dataflash (addr)) {
143 read_dataflash (data, len, (char *) CFG_LOAD_ADDR);
144 data = CFG_LOAD_ADDR;
151 printf (" Verifying Checksum ... ");
152 csum = crc32 (0, (char *) data, len);
153 if (csum != ntohl (hdr->ih_dcrc)) {
154 printf ("Bad Data CRC\n");
155 SHOW_BOOT_PROGRESS (-12);
156 do_reset (cmdtp, flag, argc, argv);
161 SHOW_BOOT_PROGRESS (11);
163 if ((hdr->ih_os != IH_OS_LINUX) ||
164 (hdr->ih_arch != IH_CPU_ARM) ||
165 (hdr->ih_type != IH_TYPE_RAMDISK)) {
166 printf ("No Linux ARM Ramdisk Image\n");
167 SHOW_BOOT_PROGRESS (-13);
168 do_reset (cmdtp, flag, argc, argv);
172 * Now check if we have a multifile image
174 } else if ((hdr->ih_type == IH_TYPE_MULTI) && (len_ptr[1])) {
175 ulong tail = ntohl (len_ptr[0]) % 4;
178 SHOW_BOOT_PROGRESS (13);
180 /* skip kernel length and terminator */
181 data = (ulong) (&len_ptr[2]);
182 /* skip any additional image length fields */
183 for (i = 1; len_ptr[i]; ++i)
185 /* add kernel length, and align */
186 data += ntohl (len_ptr[0]);
191 len = ntohl (len_ptr[1]);
197 SHOW_BOOT_PROGRESS (14);
204 printf ("No initrd\n");
210 initrd_end = initrd_start + len;
216 SHOW_BOOT_PROGRESS (15);
218 debug ("## Transferring control to Linux (at address %08lx) ...\n",
221 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
222 defined (CONFIG_CMDLINE_TAG) || \
223 defined (CONFIG_INITRD_TAG) || \
225 setup_start_tag (bd);
226 #ifdef CONFIG_SETUP_MEMORY_TAGS
227 setup_memory_tags (bd);
229 #ifdef CONFIG_CMDLINE_TAG
230 setup_commandline_tag (bd, commandline);
232 #ifdef CONFIG_INITRD_TAG
233 if (initrd_start && initrd_end)
234 setup_initrd_tag (bd, initrd_start, initrd_end);
236 #if defined (CONFIG_VFD)
237 setup_videolfb_tag ((gd_t *) gd);
242 /* we assume that the kernel is in place */
243 printf ("\nStarting kernel ...\n\n");
245 cleanup_before_linux ();
247 theKernel (0, bd->bi_arch_number);
251 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
252 defined (CONFIG_CMDLINE_TAG) || \
253 defined (CONFIG_INITRD_TAG) || \
255 static void setup_start_tag (bd_t *bd)
257 params = (struct tag *) bd->bi_boot_params;
259 params->hdr.tag = ATAG_CORE;
260 params->hdr.size = tag_size (tag_core);
262 params->u.core.flags = 0;
263 params->u.core.pagesize = 0;
264 params->u.core.rootdev = 0;
266 params = tag_next (params);
270 #ifdef CONFIG_SETUP_MEMORY_TAGS
271 static void setup_memory_tags (bd_t *bd)
275 for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
276 params->hdr.tag = ATAG_MEM;
277 params->hdr.size = tag_size (tag_mem32);
279 params->u.mem.start = bd->bi_dram[i].start;
280 params->u.mem.size = bd->bi_dram[i].size;
282 params = tag_next (params);
285 #endif /* CONFIG_SETUP_MEMORY_TAGS */
288 static void setup_commandline_tag (bd_t *bd, char *commandline)
292 /* eat leading white space */
293 for (p = commandline; *p == ' '; p++);
295 /* skip non-existent command lines so the kernel will still
296 * use its default command line.
301 params->hdr.tag = ATAG_CMDLINE;
303 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
305 strcpy (params->u.cmdline.cmdline, p);
307 params = tag_next (params);
312 #define ATAG_INITRD2 0x54420005
315 #ifdef CONFIG_INITRD_TAG
316 static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
318 /* an ATAG_INITRD node tells the kernel where the compressed
319 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
321 params->hdr.tag = ATAG_INITRD2;
322 params->hdr.size = tag_size (tag_initrd);
324 params->u.initrd.start = initrd_start;
325 params->u.initrd.size = initrd_end - initrd_start;
327 params = tag_next (params);
329 #endif /* CONFIG_INITRD_TAG */
332 #if defined (CONFIG_VFD)
333 static void setup_videolfb_tag (gd_t *gd)
335 /* An ATAG_VIDEOLFB node tells the kernel where and how large
336 * the framebuffer for video was allocated (among other things).
337 * Note that a _physical_ address is passed !
339 * We only use it to pass the address and size, the other entries
340 * in the tag_videolfb are not of interest.
342 params->hdr.tag = ATAG_VIDEOLFB;
343 params->hdr.size = tag_size (tag_videolfb);
345 params->u.videolfb.lfb_base = (u32) gd->fb_base;
346 /* 7168 = 256*4*56/8 - actually 2 pages (8192 bytes) are allocated */
347 params->u.videolfb.lfb_size = 7168;
349 params = tag_next (params);
353 static void setup_end_tag (bd_t *bd)
355 params->hdr.tag = ATAG_NONE;
356 params->hdr.size = 0;
359 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */