]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - lib_arm/armlinux.c
* Switch LWMON board default config from FRAM to EEPROM;
[karo-tx-uboot.git] / lib_arm / armlinux.c
1 /*
2  * (C) Copyright 2002
3  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
4  * Marius Groeger <mgroeger@sysgo.de>
5  *
6  * Copyright (C) 2001  Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
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 <cmd_boot.h>
27 #include <image.h>
28 #include <zlib.h>
29 #include <asm/byteorder.h>
30
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))
34
35 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
36     defined (CONFIG_CMDLINE_TAG) || \
37     defined (CONFIG_INITRD_TAG) || \
38     defined (CONFIG_VFD)
39 static void setup_start_tag(bd_t *bd);
40 # ifdef CONFIG_SETUP_MEMORY_TAGS
41 static void setup_memory_tags(bd_t *bd);
42 # endif
43 static void setup_commandline_tag(bd_t *bd, char *commandline);
44 #if 0
45 static void setup_ramdisk_tag(bd_t *bd);
46 #endif
47 # ifdef CONFIG_INITRD_TAG
48 static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end);
49 # endif
50 static void setup_end_tag(bd_t *bd);
51 # if defined (CONFIG_VFD)
52 static void setup_videolfb_tag(gd_t *gd);
53 # endif
54
55
56 static struct tag *params;
57 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
58
59 #ifdef CONFIG_SHOW_BOOT_PROGRESS
60 # include <status_led.h>
61 # define SHOW_BOOT_PROGRESS(arg)        show_boot_progress(arg)
62 #else
63 # define SHOW_BOOT_PROGRESS(arg)
64 #endif
65
66 extern image_header_t header;           /* from cmd_bootm.c */
67
68
69 void do_bootm_linux(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
70                 ulong addr, ulong *len_ptr, int   verify)
71 {
72         DECLARE_GLOBAL_DATA_PTR;
73
74     ulong len = 0, checksum;
75     ulong initrd_start, initrd_end;
76     ulong data;
77     void (*theKernel)(int zero, int arch);
78     image_header_t *hdr = &header;
79     bd_t *bd = gd->bd;
80 #ifdef CONFIG_CMDLINE_TAG
81     char *commandline = getenv("bootargs");
82 #endif
83
84     theKernel = (void (*)(int, int))ntohl(hdr->ih_ep);
85
86     /*
87      * Check if there is an initrd image
88      */
89     if (argc >= 3) {
90         SHOW_BOOT_PROGRESS (9);
91
92         addr = simple_strtoul(argv[2], NULL, 16);
93
94         printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
95
96         /* Copy header so we can blank CRC field for re-calculation */
97         memcpy (&header, (char *)addr, sizeof(image_header_t));
98
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);
103         }
104
105         data = (ulong)&header;
106         len  = sizeof(image_header_t);
107
108         checksum = ntohl(hdr->ih_hcrc);
109         hdr->ih_hcrc = 0;
110
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);
115         }
116
117         SHOW_BOOT_PROGRESS (10);
118
119         print_image_hdr (hdr);
120
121         data = addr + sizeof(image_header_t);
122         len  = ntohl(hdr->ih_size);
123
124         if (verify) {
125             ulong csum = 0;
126
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);
133             }
134             printf ("OK\n");
135         }
136
137         SHOW_BOOT_PROGRESS (11);
138
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);
145         }
146
147         /*
148          * Now check if we have a multifile image
149          */
150     } else if ((hdr->ih_type==IH_TYPE_MULTI) && (len_ptr[1])) {
151         ulong tail    = ntohl(len_ptr[0]) % 4;
152         int i;
153
154         SHOW_BOOT_PROGRESS (13);
155
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)
160           data += 4;
161         /* add kernel length, and align */
162         data += ntohl(len_ptr[0]);
163         if (tail) {
164             data += 4 - tail;
165         }
166
167         len   = ntohl(len_ptr[1]);
168
169     } else {
170         /*
171          * no initrd image
172          */
173         SHOW_BOOT_PROGRESS (14);
174
175         data = 0;
176     }
177
178 #ifdef  DEBUG
179     if (!data) {
180         printf ("No initrd\n");
181     }
182 #endif
183
184     if (data) {
185         initrd_start = data;
186         initrd_end   = initrd_start + len;
187     } else {
188         initrd_start = 0;
189         initrd_end = 0;
190     }
191
192     SHOW_BOOT_PROGRESS (15);
193
194 #ifdef DEBUG
195     printf ("## Transferring control to Linux (at address %08lx) ...\n",
196             (ulong)theKernel);
197 #endif
198
199 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
200     defined (CONFIG_CMDLINE_TAG) || \
201     defined (CONFIG_INITRD_TAG) || \
202     defined (CONFIG_VFD)
203     setup_start_tag(bd);
204 #ifdef CONFIG_SETUP_MEMORY_TAGS
205     setup_memory_tags(bd);
206 #endif
207 #ifdef CONFIG_CMDLINE_TAG
208     setup_commandline_tag(bd, commandline);
209 #endif
210 #ifdef CONFIG_INITRD_TAG
211     setup_initrd_tag(bd, initrd_start, initrd_end);
212 #endif
213 #if 0
214     setup_ramdisk_tag(bd);
215 #endif
216 #if defined (CONFIG_VFD)
217     setup_videolfb_tag(gd);
218 #endif
219     setup_end_tag(bd);
220 #endif
221
222     /* we assume that the kernel is in place */
223     printf("\nStarting kernel ...\n\n");
224
225     cleanup_before_linux();
226
227     theKernel(0, bd->bi_arch_number);
228 }
229
230
231 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
232     defined (CONFIG_CMDLINE_TAG) || \
233     defined (CONFIG_INITRD_TAG) || \
234     defined (CONFIG_VFD)
235 static void setup_start_tag(bd_t *bd)
236 {
237     params = (struct tag *)bd->bi_boot_params;
238
239     params->hdr.tag = ATAG_CORE;
240     params->hdr.size = tag_size(tag_core);
241
242     params->u.core.flags = 0;
243     params->u.core.pagesize = 0;
244     params->u.core.rootdev = 0;
245
246     params = tag_next(params);
247 }
248
249
250 #ifdef CONFIG_SETUP_MEMORY_TAGS
251 static void setup_memory_tags(bd_t *bd)
252 {
253     int i;
254
255     for(i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
256         params->hdr.tag = ATAG_MEM;
257         params->hdr.size = tag_size(tag_mem32);
258
259         params->u.mem.start = bd->bi_dram[i].start;
260         params->u.mem.size = bd->bi_dram[i].size;
261
262         params = tag_next(params);
263     }
264 }
265 #endif  /* CONFIG_SETUP_MEMORY_TAGS */
266
267
268 static void setup_commandline_tag(bd_t *bd, char *commandline)
269 {
270     char *p;
271
272     /* eat leading white space */
273     for(p = commandline; *p == ' '; p++)
274       ;
275
276     /* skip non-existent command lines so the kernel will still
277      * use its default command line.
278      */
279     if(*p == '\0')
280       return;
281
282     params->hdr.tag = ATAG_CMDLINE;
283     params->hdr.size = (sizeof(struct tag_header) + strlen(p) + 1 + 4) >> 2;
284
285     strcpy(params->u.cmdline.cmdline, p);
286
287     params = tag_next(params);
288 }
289
290
291 #ifndef ATAG_INITRD2
292 #define ATAG_INITRD2    0x54420005
293 #endif
294
295 #ifdef CONFIG_INITRD_TAG
296 static void setup_initrd_tag(bd_t *bd, ulong initrd_start, ulong initrd_end)
297 {
298     /* an ATAG_INITRD node tells the kernel where the compressed
299      * ramdisk can be found. ATAG_RDIMG is a better name, actually.
300      */
301     params->hdr.tag = ATAG_INITRD2;
302     params->hdr.size = tag_size(tag_initrd);
303
304     params->u.initrd.start = initrd_start;
305     params->u.initrd.size = initrd_end - initrd_start;
306
307     params = tag_next(params);
308 }
309 #endif  /* CONFIG_INITRD_TAG */
310
311
312 #if 0
313 static void setup_ramdisk_tag(bd_t *bd)
314 {
315     /* an ATAG_RAMDISK node tells the kernel how large the
316      * decompressed ramdisk will become.
317      */
318     params->hdr.tag = ATAG_RAMDISK;
319     params->hdr.size = tag_size(tag_ramdisk);
320
321     params->u.ramdisk.start = 0;
322     /*params->u.ramdisk.size = RAMDISK_SIZE; */
323     params->u.ramdisk.flags = 1;        /* automatically load ramdisk */
324
325     params = tag_next(params);
326 }
327 #endif /* 0 */
328
329 #if defined (CONFIG_VFD)
330 static void setup_videolfb_tag(gd_t *gd)
331 {
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 !
335      *
336      * We only use it to pass the address and size, the other entries
337      * in the tag_videolfb are not of interest.
338      */
339     params->hdr.tag = ATAG_VIDEOLFB;
340     params->hdr.size = tag_size(tag_videolfb);
341
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;
345
346     params = tag_next(params);
347 }
348 #endif
349
350 static void setup_end_tag(bd_t *bd)
351 {
352     params->hdr.tag = ATAG_NONE;
353     params->hdr.size = 0;
354 }
355
356 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */