]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - lib_arm/armlinux.c
Support for Artila M-501 starter kit
[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 <image.h>
27 #include <zlib.h>
28 #include <asm/byteorder.h>
29 #ifdef CONFIG_HAS_DATAFLASH
30 #include <dataflash.h>
31 #endif
32
33 DECLARE_GLOBAL_DATA_PTR;
34
35 /*cmd_boot.c*/
36 extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]);
37
38 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
39     defined (CONFIG_CMDLINE_TAG) || \
40     defined (CONFIG_INITRD_TAG) || \
41     defined (CONFIG_SERIAL_TAG) || \
42     defined (CONFIG_REVISION_TAG) || \
43     defined (CONFIG_VFD) || \
44     defined (CONFIG_LCD)
45 static void setup_start_tag (bd_t *bd);
46
47 # ifdef CONFIG_SETUP_MEMORY_TAGS
48 static void setup_memory_tags (bd_t *bd);
49 # endif
50 static void setup_commandline_tag (bd_t *bd, char *commandline);
51
52 #if 0
53 static void setup_ramdisk_tag (bd_t *bd);
54 #endif
55 # ifdef CONFIG_INITRD_TAG
56 static void setup_initrd_tag (bd_t *bd, ulong initrd_start,
57                               ulong initrd_end);
58 # endif
59 static void setup_end_tag (bd_t *bd);
60
61 # if defined (CONFIG_VFD) || defined (CONFIG_LCD)
62 static void setup_videolfb_tag (gd_t *gd);
63 # endif
64
65
66 static struct tag *params;
67 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
68
69 extern image_header_t header;   /* from cmd_bootm.c */
70
71
72 void do_bootm_linux (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[],
73                      ulong addr, ulong *len_ptr, int verify)
74 {
75         ulong len = 0, checksum;
76         ulong initrd_start, initrd_end;
77         ulong data;
78         void (*theKernel)(int zero, int arch, uint params);
79         image_header_t *hdr = &header;
80         bd_t *bd = gd->bd;
81
82 #ifdef CONFIG_CMDLINE_TAG
83         char *commandline = getenv ("bootargs");
84 #endif
85
86         theKernel = (void (*)(int, int, uint))ntohl(hdr->ih_ep);
87
88         /*
89          * Check if there is an initrd image
90          */
91         if (argc >= 3) {
92                 show_boot_progress (9);
93
94                 addr = simple_strtoul (argv[2], NULL, 16);
95
96                 printf ("## Loading Ramdisk Image at %08lx ...\n", addr);
97
98                 /* Copy header so we can blank CRC field for re-calculation */
99 #ifdef CONFIG_HAS_DATAFLASH
100                 if (addr_dataflash (addr)) {
101                         read_dataflash (addr, sizeof (image_header_t),
102                                         (char *) &header);
103                 } else
104 #endif
105                         memcpy (&header, (char *) addr,
106                                 sizeof (image_header_t));
107
108                 if (ntohl (hdr->ih_magic) != IH_MAGIC) {
109                         printf ("Bad Magic Number\n");
110                         show_boot_progress (-10);
111                         do_reset (cmdtp, flag, argc, argv);
112                 }
113
114                 data = (ulong) & header;
115                 len = sizeof (image_header_t);
116
117                 checksum = ntohl (hdr->ih_hcrc);
118                 hdr->ih_hcrc = 0;
119
120                 if (crc32 (0, (unsigned char *) data, len) != checksum) {
121                         printf ("Bad Header Checksum\n");
122                         show_boot_progress (-11);
123                         do_reset (cmdtp, flag, argc, argv);
124                 }
125
126                 show_boot_progress (10);
127
128                 print_image_hdr (hdr);
129
130                 data = addr + sizeof (image_header_t);
131                 len = ntohl (hdr->ih_size);
132
133 #ifdef CONFIG_HAS_DATAFLASH
134                 if (addr_dataflash (addr)) {
135                         read_dataflash (data, len, (char *) CFG_LOAD_ADDR);
136                         data = CFG_LOAD_ADDR;
137                 }
138 #endif
139
140                 if (verify) {
141                         ulong csum = 0;
142
143                         printf ("   Verifying Checksum ... ");
144                         csum = crc32 (0, (unsigned char *) data, len);
145                         if (csum != ntohl (hdr->ih_dcrc)) {
146                                 printf ("Bad Data CRC\n");
147                                 show_boot_progress (-12);
148                                 do_reset (cmdtp, flag, argc, argv);
149                         }
150                         printf ("OK\n");
151                 }
152
153                 show_boot_progress (11);
154
155                 if ((hdr->ih_os != IH_OS_LINUX) ||
156                     (hdr->ih_arch != IH_CPU_ARM) ||
157                     (hdr->ih_type != IH_TYPE_RAMDISK)) {
158                         printf ("No Linux ARM Ramdisk Image\n");
159                         show_boot_progress (-13);
160                         do_reset (cmdtp, flag, argc, argv);
161                 }
162
163 #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) ||    \
164                 defined(CONFIG_ARMADILLO) || defined(CONFIG_M501SK)
165                 /*
166                  *we need to copy the ramdisk to SRAM to let Linux boot
167                  */
168                 memmove ((void *) ntohl(hdr->ih_load), (uchar *)data, len);
169                 data = ntohl(hdr->ih_load);
170 #endif /* CONFIG_B2 || CONFIG_EVB4510 */
171
172                 /*
173                  * Now check if we have a multifile image
174                  */
175         } else if ((hdr->ih_type == IH_TYPE_MULTI) && (len_ptr[1])) {
176                 ulong tail = ntohl (len_ptr[0]) % 4;
177                 int i;
178
179                 show_boot_progress (13);
180
181                 /* skip kernel length and terminator */
182                 data = (ulong) (&len_ptr[2]);
183                 /* skip any additional image length fields */
184                 for (i = 1; len_ptr[i]; ++i)
185                         data += 4;
186                 /* add kernel length, and align */
187                 data += ntohl (len_ptr[0]);
188                 if (tail) {
189                         data += 4 - tail;
190                 }
191
192                 len = ntohl (len_ptr[1]);
193
194         } else {
195                 /*
196                  * no initrd image
197                  */
198                 show_boot_progress (14);
199
200                 len = data = 0;
201         }
202
203 #ifdef  DEBUG
204         if (!data) {
205                 printf ("No initrd\n");
206         }
207 #endif
208
209         if (data) {
210                 initrd_start = data;
211                 initrd_end = initrd_start + len;
212         } else {
213                 initrd_start = 0;
214                 initrd_end = 0;
215         }
216
217         show_boot_progress (15);
218
219         debug ("## Transferring control to Linux (at address %08lx) ...\n",
220                (ulong) theKernel);
221
222 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
223     defined (CONFIG_CMDLINE_TAG) || \
224     defined (CONFIG_INITRD_TAG) || \
225     defined (CONFIG_SERIAL_TAG) || \
226     defined (CONFIG_REVISION_TAG) || \
227     defined (CONFIG_LCD) || \
228     defined (CONFIG_VFD)
229         setup_start_tag (bd);
230 #ifdef CONFIG_SERIAL_TAG
231         setup_serial_tag (&params);
232 #endif
233 #ifdef CONFIG_REVISION_TAG
234         setup_revision_tag (&params);
235 #endif
236 #ifdef CONFIG_SETUP_MEMORY_TAGS
237         setup_memory_tags (bd);
238 #endif
239 #ifdef CONFIG_CMDLINE_TAG
240         setup_commandline_tag (bd, commandline);
241 #endif
242 #ifdef CONFIG_INITRD_TAG
243         if (initrd_start && initrd_end)
244                 setup_initrd_tag (bd, initrd_start, initrd_end);
245 #endif
246 #if defined (CONFIG_VFD) || defined (CONFIG_LCD)
247         setup_videolfb_tag ((gd_t *) gd);
248 #endif
249         setup_end_tag (bd);
250 #endif
251
252         /* we assume that the kernel is in place */
253         printf ("\nStarting kernel ...\n\n");
254
255 #ifdef CONFIG_USB_DEVICE
256         {
257                 extern void udc_disconnect (void);
258                 udc_disconnect ();
259         }
260 #endif
261
262         cleanup_before_linux ();
263
264         theKernel (0, bd->bi_arch_number, bd->bi_boot_params);
265 }
266
267
268 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
269     defined (CONFIG_CMDLINE_TAG) || \
270     defined (CONFIG_INITRD_TAG) || \
271     defined (CONFIG_SERIAL_TAG) || \
272     defined (CONFIG_REVISION_TAG) || \
273     defined (CONFIG_LCD) || \
274     defined (CONFIG_VFD)
275 static void setup_start_tag (bd_t *bd)
276 {
277         params = (struct tag *) bd->bi_boot_params;
278
279         params->hdr.tag = ATAG_CORE;
280         params->hdr.size = tag_size (tag_core);
281
282         params->u.core.flags = 0;
283         params->u.core.pagesize = 0;
284         params->u.core.rootdev = 0;
285
286         params = tag_next (params);
287 }
288
289
290 #ifdef CONFIG_SETUP_MEMORY_TAGS
291 static void setup_memory_tags (bd_t *bd)
292 {
293         int i;
294
295         for (i = 0; i < CONFIG_NR_DRAM_BANKS; i++) {
296                 params->hdr.tag = ATAG_MEM;
297                 params->hdr.size = tag_size (tag_mem32);
298
299                 params->u.mem.start = bd->bi_dram[i].start;
300                 params->u.mem.size = bd->bi_dram[i].size;
301
302                 params = tag_next (params);
303         }
304 }
305 #endif /* CONFIG_SETUP_MEMORY_TAGS */
306
307
308 static void setup_commandline_tag (bd_t *bd, char *commandline)
309 {
310         char *p;
311
312         if (!commandline)
313                 return;
314
315         /* eat leading white space */
316         for (p = commandline; *p == ' '; p++);
317
318         /* skip non-existent command lines so the kernel will still
319          * use its default command line.
320          */
321         if (*p == '\0')
322                 return;
323
324         params->hdr.tag = ATAG_CMDLINE;
325         params->hdr.size =
326                 (sizeof (struct tag_header) + strlen (p) + 1 + 4) >> 2;
327
328         strcpy (params->u.cmdline.cmdline, p);
329
330         params = tag_next (params);
331 }
332
333
334 #ifdef CONFIG_INITRD_TAG
335 static void setup_initrd_tag (bd_t *bd, ulong initrd_start, ulong initrd_end)
336 {
337         /* an ATAG_INITRD node tells the kernel where the compressed
338          * ramdisk can be found. ATAG_RDIMG is a better name, actually.
339          */
340         params->hdr.tag = ATAG_INITRD2;
341         params->hdr.size = tag_size (tag_initrd);
342
343         params->u.initrd.start = initrd_start;
344         params->u.initrd.size = initrd_end - initrd_start;
345
346         params = tag_next (params);
347 }
348 #endif /* CONFIG_INITRD_TAG */
349
350
351 #if defined (CONFIG_VFD) || defined (CONFIG_LCD)
352 extern ulong calc_fbsize (void);
353 static void setup_videolfb_tag (gd_t *gd)
354 {
355         /* An ATAG_VIDEOLFB node tells the kernel where and how large
356          * the framebuffer for video was allocated (among other things).
357          * Note that a _physical_ address is passed !
358          *
359          * We only use it to pass the address and size, the other entries
360          * in the tag_videolfb are not of interest.
361          */
362         params->hdr.tag = ATAG_VIDEOLFB;
363         params->hdr.size = tag_size (tag_videolfb);
364
365         params->u.videolfb.lfb_base = (u32) gd->fb_base;
366         /* Fb size is calculated according to parameters for our panel
367          */
368         params->u.videolfb.lfb_size = calc_fbsize();
369
370         params = tag_next (params);
371 }
372 #endif /* CONFIG_VFD || CONFIG_LCD */
373
374 #ifdef CONFIG_SERIAL_TAG
375 void setup_serial_tag (struct tag **tmp)
376 {
377         struct tag *params = *tmp;
378         struct tag_serialnr serialnr;
379         void get_board_serial(struct tag_serialnr *serialnr);
380
381         get_board_serial(&serialnr);
382         params->hdr.tag = ATAG_SERIAL;
383         params->hdr.size = tag_size (tag_serialnr);
384         params->u.serialnr.low = serialnr.low;
385         params->u.serialnr.high= serialnr.high;
386         params = tag_next (params);
387         *tmp = params;
388 }
389 #endif
390
391 #ifdef CONFIG_REVISION_TAG
392 void setup_revision_tag(struct tag **in_params)
393 {
394         u32 rev = 0;
395         u32 get_board_rev(void);
396
397         rev = get_board_rev();
398         params->hdr.tag = ATAG_REVISION;
399         params->hdr.size = tag_size (tag_revision);
400         params->u.revision.rev = rev;
401         params = tag_next (params);
402 }
403 #endif  /* CONFIG_REVISION_TAG */
404
405
406 static void setup_end_tag (bd_t *bd)
407 {
408         params->hdr.tag = ATAG_NONE;
409         params->hdr.size = 0;
410 }
411
412 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */