]>
git.ipfire.org Git - people/ms/u-boot.git/blob - lib_arm/armlinux.c
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 DECLARE_GLOBAL_DATA_PTR
;
36 extern int do_reset (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
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) || \
45 static void setup_start_tag (bd_t
*bd
);
47 # ifdef CONFIG_SETUP_MEMORY_TAGS
48 static void setup_memory_tags (bd_t
*bd
);
50 static void setup_commandline_tag (bd_t
*bd
, char *commandline
);
53 static void setup_ramdisk_tag (bd_t
*bd
);
55 # ifdef CONFIG_INITRD_TAG
56 static void setup_initrd_tag (bd_t
*bd
, ulong initrd_start
,
59 static void setup_end_tag (bd_t
*bd
);
61 # if defined (CONFIG_VFD) || defined (CONFIG_LCD)
62 static void setup_videolfb_tag (gd_t
*gd
);
66 static struct tag
*params
;
67 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
69 extern image_header_t header
; /* from cmd_bootm.c */
72 void do_bootm_linux (cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[],
73 ulong addr
, ulong
*len_ptr
, int verify
)
75 ulong len
= 0, checksum
;
76 ulong initrd_start
, initrd_end
;
78 void (*theKernel
)(int zero
, int arch
, uint params
);
79 image_header_t
*hdr
= &header
;
81 int machid
= bd
->bi_arch_number
;
84 #ifdef CONFIG_CMDLINE_TAG
85 char *commandline
= getenv ("bootargs");
88 theKernel
= (void (*)(int, int, uint
))ntohl(hdr
->ih_ep
);
90 s
= getenv ("machid");
92 machid
= simple_strtoul (s
, NULL
, 16);
93 printf ("Using machid 0x%x from environment\n", machid
);
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, (unsigned 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, (unsigned 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
);
171 #if defined(CONFIG_B2) || defined(CONFIG_EVB4510) || \
172 defined(CONFIG_ARMADILLO) || defined(CONFIG_M501SK)
174 *we need to copy the ramdisk to SRAM to let Linux boot
176 memmove ((void *) ntohl(hdr
->ih_load
), (uchar
*)data
, len
);
177 data
= ntohl(hdr
->ih_load
);
178 #endif /* CONFIG_B2 || CONFIG_EVB4510 */
181 * Now check if we have a multifile image
183 } else if ((hdr
->ih_type
== IH_TYPE_MULTI
) && (len_ptr
[1])) {
184 ulong tail
= ntohl (len_ptr
[0]) % 4;
187 show_boot_progress (13);
189 /* skip kernel length and terminator */
190 data
= (ulong
) (&len_ptr
[2]);
191 /* skip any additional image length fields */
192 for (i
= 1; len_ptr
[i
]; ++i
)
194 /* add kernel length, and align */
195 data
+= ntohl (len_ptr
[0]);
200 len
= ntohl (len_ptr
[1]);
206 show_boot_progress (14);
213 printf ("No initrd\n");
219 initrd_end
= initrd_start
+ len
;
225 show_boot_progress (15);
227 debug ("## Transferring control to Linux (at address %08lx) ...\n",
230 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
231 defined (CONFIG_CMDLINE_TAG) || \
232 defined (CONFIG_INITRD_TAG) || \
233 defined (CONFIG_SERIAL_TAG) || \
234 defined (CONFIG_REVISION_TAG) || \
235 defined (CONFIG_LCD) || \
237 setup_start_tag (bd
);
238 #ifdef CONFIG_SERIAL_TAG
239 setup_serial_tag (¶ms
);
241 #ifdef CONFIG_REVISION_TAG
242 setup_revision_tag (¶ms
);
244 #ifdef CONFIG_SETUP_MEMORY_TAGS
245 setup_memory_tags (bd
);
247 #ifdef CONFIG_CMDLINE_TAG
248 setup_commandline_tag (bd
, commandline
);
250 #ifdef CONFIG_INITRD_TAG
251 if (initrd_start
&& initrd_end
)
252 setup_initrd_tag (bd
, initrd_start
, initrd_end
);
254 #if defined (CONFIG_VFD) || defined (CONFIG_LCD)
255 setup_videolfb_tag ((gd_t
*) gd
);
260 /* we assume that the kernel is in place */
261 printf ("\nStarting kernel ...\n\n");
263 #ifdef CONFIG_USB_DEVICE
265 extern void udc_disconnect (void);
270 cleanup_before_linux ();
272 theKernel (0, machid
, bd
->bi_boot_params
);
276 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
277 defined (CONFIG_CMDLINE_TAG) || \
278 defined (CONFIG_INITRD_TAG) || \
279 defined (CONFIG_SERIAL_TAG) || \
280 defined (CONFIG_REVISION_TAG) || \
281 defined (CONFIG_LCD) || \
283 static void setup_start_tag (bd_t
*bd
)
285 params
= (struct tag
*) bd
->bi_boot_params
;
287 params
->hdr
.tag
= ATAG_CORE
;
288 params
->hdr
.size
= tag_size (tag_core
);
290 params
->u
.core
.flags
= 0;
291 params
->u
.core
.pagesize
= 0;
292 params
->u
.core
.rootdev
= 0;
294 params
= tag_next (params
);
298 #ifdef CONFIG_SETUP_MEMORY_TAGS
299 static void setup_memory_tags (bd_t
*bd
)
303 for (i
= 0; i
< CONFIG_NR_DRAM_BANKS
; i
++) {
304 params
->hdr
.tag
= ATAG_MEM
;
305 params
->hdr
.size
= tag_size (tag_mem32
);
307 params
->u
.mem
.start
= bd
->bi_dram
[i
].start
;
308 params
->u
.mem
.size
= bd
->bi_dram
[i
].size
;
310 params
= tag_next (params
);
313 #endif /* CONFIG_SETUP_MEMORY_TAGS */
316 static void setup_commandline_tag (bd_t
*bd
, char *commandline
)
323 /* eat leading white space */
324 for (p
= commandline
; *p
== ' '; p
++);
326 /* skip non-existent command lines so the kernel will still
327 * use its default command line.
332 params
->hdr
.tag
= ATAG_CMDLINE
;
334 (sizeof (struct tag_header
) + strlen (p
) + 1 + 4) >> 2;
336 strcpy (params
->u
.cmdline
.cmdline
, p
);
338 params
= tag_next (params
);
342 #ifdef CONFIG_INITRD_TAG
343 static void setup_initrd_tag (bd_t
*bd
, ulong initrd_start
, ulong initrd_end
)
345 /* an ATAG_INITRD node tells the kernel where the compressed
346 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
348 params
->hdr
.tag
= ATAG_INITRD2
;
349 params
->hdr
.size
= tag_size (tag_initrd
);
351 params
->u
.initrd
.start
= initrd_start
;
352 params
->u
.initrd
.size
= initrd_end
- initrd_start
;
354 params
= tag_next (params
);
356 #endif /* CONFIG_INITRD_TAG */
359 #if defined (CONFIG_VFD) || defined (CONFIG_LCD)
360 extern ulong
calc_fbsize (void);
361 static void setup_videolfb_tag (gd_t
*gd
)
363 /* An ATAG_VIDEOLFB node tells the kernel where and how large
364 * the framebuffer for video was allocated (among other things).
365 * Note that a _physical_ address is passed !
367 * We only use it to pass the address and size, the other entries
368 * in the tag_videolfb are not of interest.
370 params
->hdr
.tag
= ATAG_VIDEOLFB
;
371 params
->hdr
.size
= tag_size (tag_videolfb
);
373 params
->u
.videolfb
.lfb_base
= (u32
) gd
->fb_base
;
374 /* Fb size is calculated according to parameters for our panel
376 params
->u
.videolfb
.lfb_size
= calc_fbsize();
378 params
= tag_next (params
);
380 #endif /* CONFIG_VFD || CONFIG_LCD */
382 #ifdef CONFIG_SERIAL_TAG
383 void setup_serial_tag (struct tag
**tmp
)
385 struct tag
*params
= *tmp
;
386 struct tag_serialnr serialnr
;
387 void get_board_serial(struct tag_serialnr
*serialnr
);
389 get_board_serial(&serialnr
);
390 params
->hdr
.tag
= ATAG_SERIAL
;
391 params
->hdr
.size
= tag_size (tag_serialnr
);
392 params
->u
.serialnr
.low
= serialnr
.low
;
393 params
->u
.serialnr
.high
= serialnr
.high
;
394 params
= tag_next (params
);
399 #ifdef CONFIG_REVISION_TAG
400 void setup_revision_tag(struct tag
**in_params
)
403 u32
get_board_rev(void);
405 rev
= get_board_rev();
406 params
->hdr
.tag
= ATAG_REVISION
;
407 params
->hdr
.size
= tag_size (tag_revision
);
408 params
->u
.revision
.rev
= rev
;
409 params
= tag_next (params
);
411 #endif /* CONFIG_REVISION_TAG */
414 static void setup_end_tag (bd_t
*bd
)
416 params
->hdr
.tag
= ATAG_NONE
;
417 params
->hdr
.size
= 0;
420 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */