]>
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 #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
);
45 # ifdef CONFIG_SETUP_MEMORY_TAGS
46 static void setup_memory_tags(bd_t
*bd
);
48 static void setup_commandline_tag(bd_t
*bd
, char *commandline
);
50 static void setup_ramdisk_tag(bd_t
*bd
);
52 # ifdef CONFIG_INITRD_TAG
53 static void setup_initrd_tag(bd_t
*bd
, ulong initrd_start
, ulong initrd_end
);
55 static void setup_end_tag(bd_t
*bd
);
56 # if defined (CONFIG_VFD)
57 static void setup_videolfb_tag(gd_t
*gd
);
61 static struct tag
*params
;
62 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
64 #ifdef CONFIG_SHOW_BOOT_PROGRESS
65 # include <status_led.h>
66 # define SHOW_BOOT_PROGRESS(arg) show_boot_progress(arg)
68 # define SHOW_BOOT_PROGRESS(arg)
71 extern image_header_t header
; /* from cmd_bootm.c */
74 void do_bootm_linux(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[],
75 ulong addr
, ulong
*len_ptr
, int verify
)
77 DECLARE_GLOBAL_DATA_PTR
;
79 ulong len
= 0, checksum
;
80 ulong initrd_start
, initrd_end
;
82 void (*theKernel
)(int zero
, int arch
);
83 image_header_t
*hdr
= &header
;
85 #ifdef CONFIG_CMDLINE_TAG
86 char *commandline
= getenv("bootargs");
89 theKernel
= (void (*)(int, int))ntohl(hdr
->ih_ep
);
92 * Check if there is an initrd image
95 SHOW_BOOT_PROGRESS (9);
97 addr
= simple_strtoul(argv
[2], NULL
, 16);
99 printf ("## Loading Ramdisk Image at %08lx ...\n", addr
);
101 /* Copy header so we can blank CRC field for re-calculation */
102 #ifdef CONFIG_HAS_DATAFLASH
103 if (addr_dataflash(addr
)){
104 read_dataflash(addr
, sizeof(image_header_t
), (char *)&header
);
107 memcpy (&header
, (char *)addr
, sizeof(image_header_t
));
109 if (ntohl(hdr
->ih_magic
) != IH_MAGIC
) {
110 printf ("Bad Magic Number\n");
111 SHOW_BOOT_PROGRESS (-10);
112 do_reset (cmdtp
, flag
, argc
, argv
);
115 data
= (ulong
)&header
;
116 len
= sizeof(image_header_t
);
118 checksum
= ntohl(hdr
->ih_hcrc
);
121 if (crc32 (0, (char *)data
, len
) != checksum
) {
122 printf ("Bad Header Checksum\n");
123 SHOW_BOOT_PROGRESS (-11);
124 do_reset (cmdtp
, flag
, argc
, argv
);
127 SHOW_BOOT_PROGRESS (10);
129 print_image_hdr (hdr
);
131 data
= addr
+ sizeof(image_header_t
);
132 len
= ntohl(hdr
->ih_size
);
134 #ifdef CONFIG_HAS_DATAFLASH
135 if (addr_dataflash(addr
)){
136 read_dataflash(data
, len
, (char *)CFG_LOAD_ADDR
);
137 data
= CFG_LOAD_ADDR
;
144 printf (" Verifying Checksum ... ");
145 csum
= crc32 (0, (char *)data
, len
);
146 if (csum
!= ntohl(hdr
->ih_dcrc
)) {
147 printf ("Bad Data CRC\n");
148 SHOW_BOOT_PROGRESS (-12);
149 do_reset (cmdtp
, flag
, argc
, argv
);
154 SHOW_BOOT_PROGRESS (11);
156 if ((hdr
->ih_os
!= IH_OS_LINUX
) ||
157 (hdr
->ih_arch
!= IH_CPU_ARM
) ||
158 (hdr
->ih_type
!= IH_TYPE_RAMDISK
) ) {
159 printf ("No Linux ARM Ramdisk Image\n");
160 SHOW_BOOT_PROGRESS (-13);
161 do_reset (cmdtp
, flag
, argc
, argv
);
165 * Now check if we have a multifile image
167 } else if ((hdr
->ih_type
==IH_TYPE_MULTI
) && (len_ptr
[1])) {
168 ulong tail
= ntohl(len_ptr
[0]) % 4;
171 SHOW_BOOT_PROGRESS (13);
173 /* skip kernel length and terminator */
174 data
= (ulong
)(&len_ptr
[2]);
175 /* skip any additional image length fields */
176 for (i
=1; len_ptr
[i
]; ++i
)
178 /* add kernel length, and align */
179 data
+= ntohl(len_ptr
[0]);
184 len
= ntohl(len_ptr
[1]);
190 SHOW_BOOT_PROGRESS (14);
197 printf ("No initrd\n");
203 initrd_end
= initrd_start
+ len
;
209 SHOW_BOOT_PROGRESS (15);
212 printf ("## Transferring control to Linux (at address %08lx) ...\n",
216 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
217 defined (CONFIG_CMDLINE_TAG) || \
218 defined (CONFIG_INITRD_TAG) || \
221 #ifdef CONFIG_SETUP_MEMORY_TAGS
222 setup_memory_tags(bd
);
224 #ifdef CONFIG_CMDLINE_TAG
225 setup_commandline_tag(bd
, commandline
);
227 #ifdef CONFIG_INITRD_TAG
228 setup_initrd_tag(bd
, initrd_start
, initrd_end
);
231 setup_ramdisk_tag(bd
);
233 #if defined (CONFIG_VFD)
234 setup_videolfb_tag(gd
);
239 /* we assume that the kernel is in place */
240 printf("\nStarting kernel ...\n\n");
242 cleanup_before_linux();
244 theKernel(0, bd
->bi_arch_number
);
248 #if defined (CONFIG_SETUP_MEMORY_TAGS) || \
249 defined (CONFIG_CMDLINE_TAG) || \
250 defined (CONFIG_INITRD_TAG) || \
252 static void setup_start_tag(bd_t
*bd
)
254 params
= (struct tag
*)bd
->bi_boot_params
;
256 params
->hdr
.tag
= ATAG_CORE
;
257 params
->hdr
.size
= tag_size(tag_core
);
259 params
->u
.core
.flags
= 0;
260 params
->u
.core
.pagesize
= 0;
261 params
->u
.core
.rootdev
= 0;
263 params
= tag_next(params
);
267 #ifdef CONFIG_SETUP_MEMORY_TAGS
268 static void setup_memory_tags(bd_t
*bd
)
272 for(i
= 0; i
< CONFIG_NR_DRAM_BANKS
; i
++) {
273 params
->hdr
.tag
= ATAG_MEM
;
274 params
->hdr
.size
= tag_size(tag_mem32
);
276 params
->u
.mem
.start
= bd
->bi_dram
[i
].start
;
277 params
->u
.mem
.size
= bd
->bi_dram
[i
].size
;
279 params
= tag_next(params
);
282 #endif /* CONFIG_SETUP_MEMORY_TAGS */
285 static void setup_commandline_tag(bd_t
*bd
, char *commandline
)
289 /* eat leading white space */
290 for(p
= commandline
; *p
== ' '; p
++)
293 /* skip non-existent command lines so the kernel will still
294 * use its default command line.
299 params
->hdr
.tag
= ATAG_CMDLINE
;
300 params
->hdr
.size
= (sizeof(struct tag_header
) + strlen(p
) + 1 + 4) >> 2;
302 strcpy(params
->u
.cmdline
.cmdline
, p
);
304 params
= tag_next(params
);
309 #define ATAG_INITRD2 0x54420005
312 #ifdef CONFIG_INITRD_TAG
313 static void setup_initrd_tag(bd_t
*bd
, ulong initrd_start
, ulong initrd_end
)
315 /* an ATAG_INITRD node tells the kernel where the compressed
316 * ramdisk can be found. ATAG_RDIMG is a better name, actually.
318 params
->hdr
.tag
= ATAG_INITRD2
;
319 params
->hdr
.size
= tag_size(tag_initrd
);
321 params
->u
.initrd
.start
= initrd_start
;
322 params
->u
.initrd
.size
= initrd_end
- initrd_start
;
324 params
= tag_next(params
);
326 #endif /* CONFIG_INITRD_TAG */
330 static void setup_ramdisk_tag(bd_t
*bd
)
332 /* an ATAG_RAMDISK node tells the kernel how large the
333 * decompressed ramdisk will become.
335 params
->hdr
.tag
= ATAG_RAMDISK
;
336 params
->hdr
.size
= tag_size(tag_ramdisk
);
338 params
->u
.ramdisk
.start
= 0;
339 /*params->u.ramdisk.size = RAMDISK_SIZE; */
340 params
->u
.ramdisk
.flags
= 1; /* automatically load ramdisk */
342 params
= tag_next(params
);
346 #if defined (CONFIG_VFD)
347 static void setup_videolfb_tag(gd_t
*gd
)
349 /* An ATAG_VIDEOLFB node tells the kernel where and how large
350 * the framebuffer for video was allocated (among other things).
351 * Note that a _physical_ address is passed !
353 * We only use it to pass the address and size, the other entries
354 * in the tag_videolfb are not of interest.
356 params
->hdr
.tag
= ATAG_VIDEOLFB
;
357 params
->hdr
.size
= tag_size(tag_videolfb
);
359 params
->u
.videolfb
.lfb_base
= (u32
)gd
->fb_base
;
360 /* 7168 = 256*4*56/8 - actually 2 pages (8192 bytes) are allocated */
361 params
->u
.videolfb
.lfb_size
= 7168;
363 params
= tag_next(params
);
367 static void setup_end_tag(bd_t
*bd
)
369 params
->hdr
.tag
= ATAG_NONE
;
370 params
->hdr
.size
= 0;
373 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */