]>
git.ipfire.org Git - people/ms/u-boot.git/blob - lib_avr32/avr32_linux.c
2 * Copyright (C) 2004-2006 Atmel Corporation
4 * See file CREDITS for list of people who contributed to this
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 #include <asm/byteorder.h>
27 #include <asm/addrspace.h>
29 #include <asm/setup.h>
30 #include <asm/arch/clk.h>
32 DECLARE_GLOBAL_DATA_PTR
;
34 extern int do_reset(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[]);
36 /* CPU-specific hook to allow flushing of caches, etc. */
37 extern void prepare_to_boot(void);
39 extern image_header_t header
; /* from cmd_bootm.c */
41 static struct tag
*setup_start_tag(struct tag
*params
)
43 params
->hdr
.tag
= ATAG_CORE
;
44 params
->hdr
.size
= tag_size(tag_core
);
46 params
->u
.core
.flags
= 0;
47 params
->u
.core
.pagesize
= 4096;
48 params
->u
.core
.rootdev
= 0;
50 return tag_next(params
);
53 static struct tag
*setup_memory_tags(struct tag
*params
)
58 for (i
= 0; i
< CONFIG_NR_DRAM_BANKS
; i
++) {
59 params
->hdr
.tag
= ATAG_MEM
;
60 params
->hdr
.size
= tag_size(tag_mem_range
);
62 params
->u
.mem_range
.addr
= bd
->bi_dram
[i
].start
;
63 params
->u
.mem_range
.size
= bd
->bi_dram
[i
].size
;
65 params
= tag_next(params
);
71 static struct tag
*setup_commandline_tag(struct tag
*params
, char *cmdline
)
76 /* eat leading white space */
77 while (*cmdline
== ' ') cmdline
++;
80 * Don't include tags for empty command lines; let the kernel
81 * use its default command line.
86 params
->hdr
.tag
= ATAG_CMDLINE
;
88 (sizeof (struct tag_header
) + strlen(cmdline
) + 1 + 3) >> 2;
89 strcpy(params
->u
.cmdline
.cmdline
, cmdline
);
91 return tag_next(params
);
94 static struct tag
*setup_ramdisk_tag(struct tag
*params
,
95 unsigned long rd_start
,
98 if (rd_start
== rd_end
)
101 params
->hdr
.tag
= ATAG_RDIMG
;
102 params
->hdr
.size
= tag_size(tag_mem_range
);
104 params
->u
.mem_range
.addr
= rd_start
;
105 params
->u
.mem_range
.size
= rd_end
- rd_start
;
107 return tag_next(params
);
110 static struct tag
*setup_clock_tags(struct tag
*params
)
112 params
->hdr
.tag
= ATAG_CLOCK
;
113 params
->hdr
.size
= tag_size(tag_clock
);
114 params
->u
.clock
.clock_id
= ACLOCK_BOOTCPU
;
115 params
->u
.clock
.clock_flags
= 0;
116 params
->u
.clock
.clock_hz
= gd
->cpu_hz
;
118 #ifdef CONFIG_AT32AP7000
120 * New kernels don't need this, but we should be backwards
121 * compatible for a while...
123 params
= tag_next(params
);
125 params
->hdr
.tag
= ATAG_CLOCK
;
126 params
->hdr
.size
= tag_size(tag_clock
);
127 params
->u
.clock
.clock_id
= ACLOCK_HSB
;
128 params
->u
.clock
.clock_flags
= 0;
129 params
->u
.clock
.clock_hz
= get_hsb_clk_rate();
132 return tag_next(params
);
135 static struct tag
*setup_ethernet_tag(struct tag
*params
,
136 char *addr
, int index
)
141 params
->hdr
.tag
= ATAG_ETHERNET
;
142 params
->hdr
.size
= tag_size(tag_ethernet
);
144 params
->u
.ethernet
.mac_index
= index
;
145 params
->u
.ethernet
.mii_phy_addr
= gd
->bd
->bi_phy_id
[index
];
148 for (i
= 0; i
< 6; i
++) {
149 params
->u
.ethernet
.hw_address
[i
] = simple_strtoul(s
, &e
, 16);
153 return tag_next(params
);
156 static struct tag
*setup_ethernet_tags(struct tag
*params
)
158 char name
[16] = "ethaddr";
165 params
= setup_ethernet_tag(params
, addr
, i
);
166 sprintf(name
, "eth%daddr", ++i
);
172 static void setup_end_tag(struct tag
*params
)
174 params
->hdr
.tag
= ATAG_NONE
;
175 params
->hdr
.size
= 0;
178 void do_bootm_linux(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[],
179 unsigned long addr
, unsigned long *len_ptr
, int verify
)
181 unsigned long data
, len
= 0;
182 unsigned long initrd_start
, initrd_end
;
183 unsigned long image_start
, image_end
;
184 unsigned long checksum
;
185 void (*theKernel
)(int magic
, void *tagtable
);
187 struct tag
*params
, *params_start
;
188 char *commandline
= getenv("bootargs");
190 hdr
= (image_header_t
*)addr
;
192 image_end
= addr
+ hdr
->ih_size
;
194 theKernel
= (void *)ntohl(hdr
->ih_ep
);
197 * Check if there is an initrd image
200 show_boot_progress (9);
202 addr
= simple_strtoul(argv
[2], NULL
, 16);
204 printf("## Loading RAMDISK image at %08lx ...\n", addr
);
206 memcpy(&header
, (char *)addr
, sizeof(header
));
209 if (ntohl(hdr
->ih_magic
) != IH_MAGIC
) {
210 puts("Bad Magic Number\n");
211 show_boot_progress (-10);
212 do_reset(cmdtp
, flag
, argc
, argv
);
215 data
= (unsigned long)hdr
;
217 checksum
= ntohl(hdr
->ih_hcrc
);
220 if (crc32(0, (unsigned char *)data
, len
) != checksum
) {
221 puts("Bad Header Checksum\n");
222 show_boot_progress (-11);
223 do_reset(cmdtp
, flag
, argc
, argv
);
226 show_boot_progress (10);
228 print_image_hdr(hdr
);
230 data
= addr
+ sizeof(header
);
231 len
= ntohl(hdr
->ih_size
);
234 unsigned long csum
= 0;
236 puts(" Verifying Checksum ... ");
237 csum
= crc32(0, (unsigned char *)data
, len
);
238 if (csum
!= ntohl(hdr
->ih_dcrc
)) {
239 puts("Bad Data CRC\n");
240 show_boot_progress (-12);
241 do_reset(cmdtp
, flag
, argc
, argv
);
246 show_boot_progress (11);
248 if ((hdr
->ih_os
!= IH_OS_LINUX
) ||
249 (hdr
->ih_arch
!= IH_CPU_AVR32
) ||
250 (hdr
->ih_type
!= IH_TYPE_RAMDISK
)) {
251 puts("Not a Linux/AVR32 RAMDISK image\n");
252 show_boot_progress (-13);
253 do_reset(cmdtp
, flag
, argc
, argv
);
255 } else if ((hdr
->ih_type
== IH_TYPE_MULTI
) && (len_ptr
[1])) {
256 ulong tail
= ntohl (len_ptr
[0]) % 4;
259 show_boot_progress (13);
261 /* skip kernel length and terminator */
262 data
= (ulong
) (&len_ptr
[2]);
263 /* skip any additional image length fields */
264 for (i
= 1; len_ptr
[i
]; ++i
)
266 /* add kernel length, and align */
267 data
+= ntohl (len_ptr
[0]);
272 len
= ntohl (len_ptr
[1]);
274 /* no initrd image */
275 show_boot_progress (14);
281 initrd_end
= initrd_start
+ len
;
287 show_boot_progress (15);
289 params
= params_start
= (struct tag
*)gd
->bd
->bi_boot_params
;
290 params
= setup_start_tag(params
);
291 params
= setup_memory_tags(params
);
293 params
= setup_ramdisk_tag(params
,
294 PHYSADDR(initrd_start
),
295 PHYSADDR(initrd_end
));
297 params
= setup_commandline_tag(params
, commandline
);
298 params
= setup_clock_tags(params
);
299 params
= setup_ethernet_tags(params
);
300 setup_end_tag(params
);
302 printf("\nStarting kernel at %p (params at %p)...\n\n",
303 theKernel
, params_start
);
307 theKernel(ATAG_MAGIC
, params_start
);