]>
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 static struct tag
*setup_start_tag(struct tag
*params
)
41 params
->hdr
.tag
= ATAG_CORE
;
42 params
->hdr
.size
= tag_size(tag_core
);
44 params
->u
.core
.flags
= 0;
45 params
->u
.core
.pagesize
= 4096;
46 params
->u
.core
.rootdev
= 0;
48 return tag_next(params
);
51 static struct tag
*setup_memory_tags(struct tag
*params
)
56 for (i
= 0; i
< CONFIG_NR_DRAM_BANKS
; i
++) {
57 params
->hdr
.tag
= ATAG_MEM
;
58 params
->hdr
.size
= tag_size(tag_mem_range
);
60 params
->u
.mem_range
.addr
= bd
->bi_dram
[i
].start
;
61 params
->u
.mem_range
.size
= bd
->bi_dram
[i
].size
;
63 params
= tag_next(params
);
69 static struct tag
*setup_commandline_tag(struct tag
*params
, char *cmdline
)
74 /* eat leading white space */
75 while (*cmdline
== ' ') cmdline
++;
78 * Don't include tags for empty command lines; let the kernel
79 * use its default command line.
84 params
->hdr
.tag
= ATAG_CMDLINE
;
86 (sizeof (struct tag_header
) + strlen(cmdline
) + 1 + 3) >> 2;
87 strcpy(params
->u
.cmdline
.cmdline
, cmdline
);
89 return tag_next(params
);
92 static struct tag
*setup_ramdisk_tag(struct tag
*params
,
93 unsigned long rd_start
,
96 if (rd_start
== rd_end
)
99 params
->hdr
.tag
= ATAG_RDIMG
;
100 params
->hdr
.size
= tag_size(tag_mem_range
);
102 params
->u
.mem_range
.addr
= rd_start
;
103 params
->u
.mem_range
.size
= rd_end
- rd_start
;
105 return tag_next(params
);
108 static struct tag
*setup_clock_tags(struct tag
*params
)
110 params
->hdr
.tag
= ATAG_CLOCK
;
111 params
->hdr
.size
= tag_size(tag_clock
);
112 params
->u
.clock
.clock_id
= ACLOCK_BOOTCPU
;
113 params
->u
.clock
.clock_flags
= 0;
114 params
->u
.clock
.clock_hz
= gd
->cpu_hz
;
116 #ifdef CONFIG_AT32AP7000
118 * New kernels don't need this, but we should be backwards
119 * compatible for a while...
121 params
= tag_next(params
);
123 params
->hdr
.tag
= ATAG_CLOCK
;
124 params
->hdr
.size
= tag_size(tag_clock
);
125 params
->u
.clock
.clock_id
= ACLOCK_HSB
;
126 params
->u
.clock
.clock_flags
= 0;
127 params
->u
.clock
.clock_hz
= get_hsb_clk_rate();
130 return tag_next(params
);
133 static struct tag
*setup_ethernet_tag(struct tag
*params
,
134 char *addr
, int index
)
139 params
->hdr
.tag
= ATAG_ETHERNET
;
140 params
->hdr
.size
= tag_size(tag_ethernet
);
142 params
->u
.ethernet
.mac_index
= index
;
143 params
->u
.ethernet
.mii_phy_addr
= gd
->bd
->bi_phy_id
[index
];
146 for (i
= 0; i
< 6; i
++) {
147 params
->u
.ethernet
.hw_address
[i
] = simple_strtoul(s
, &e
, 16);
151 return tag_next(params
);
154 static struct tag
*setup_ethernet_tags(struct tag
*params
)
156 char name
[16] = "ethaddr";
163 params
= setup_ethernet_tag(params
, addr
, i
);
164 sprintf(name
, "eth%daddr", ++i
);
170 static void setup_end_tag(struct tag
*params
)
172 params
->hdr
.tag
= ATAG_NONE
;
173 params
->hdr
.size
= 0;
176 void do_bootm_linux(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char *argv
[],
177 unsigned long addr
, unsigned long *len_ptr
, int verify
)
179 unsigned long data
, len
= 0;
180 unsigned long initrd_start
, initrd_end
;
181 unsigned long image_start
, image_end
;
182 void (*theKernel
)(int magic
, void *tagtable
);
184 struct tag
*params
, *params_start
;
185 char *commandline
= getenv("bootargs");
187 hdr
= (image_header_t
*)addr
;
189 image_end
= addr
+ image_get_data_size (hdr
);
191 theKernel
= (void *)image_get_ep (hdr
);
194 * Check if there is an initrd image
197 show_boot_progress (9);
199 addr
= simple_strtoul(argv
[2], NULL
, 16);
200 hdr
= (image_header_t
*)addr
;
202 printf("## Loading RAMDISK image at %08lx ...\n", addr
);
204 if (!image_check_magic (hdr
)) {
205 puts("Bad Magic Number\n");
206 show_boot_progress (-10);
207 do_reset(cmdtp
, flag
, argc
, argv
);
210 if (!image_check_hcrc (hdr
)) {
211 puts("Bad Header Checksum\n");
212 show_boot_progress (-11);
213 do_reset(cmdtp
, flag
, argc
, argv
);
216 show_boot_progress (10);
217 print_image_hdr (hdr
);
220 puts(" Verifying Checksum ... ");
221 if (!image_check_dcrc (hdr
)) {
222 puts("Bad Data CRC\n");
223 show_boot_progress (-12);
224 do_reset(cmdtp
, flag
, argc
, argv
);
229 show_boot_progress (11);
231 if (!image_check_os (hdr
, IH_OS_LINUX
) ||
232 !image_check_arch (hdr
, IH_ARCH_AVR32
) ||
233 !image_check_type (hdr
, IH_TYPE_RAMDISK
)) {
234 puts("Not a Linux/AVR32 RAMDISK image\n");
235 show_boot_progress (-13);
236 do_reset(cmdtp
, flag
, argc
, argv
);
239 data
= image_get_data (hdr
);
240 len
= image_get_data_size (hdr
);
242 } else if (image_check_type (hdr
, IH_TYPE_MULTI
) && (len_ptr
[1])) {
243 ulong tail
= image_to_cpu (len_ptr
[0]) % 4;
246 show_boot_progress (13);
248 /* skip kernel length and terminator */
249 data
= (ulong
) (&len_ptr
[2]);
250 /* skip any additional image length fields */
251 for (i
= 1; len_ptr
[i
]; ++i
)
253 /* add kernel length, and align */
254 data
+= image_to_cpu (len_ptr
[0]);
259 len
= image_to_cpu (len_ptr
[1]);
261 /* no initrd image */
262 show_boot_progress (14);
268 initrd_end
= initrd_start
+ len
;
274 show_boot_progress (15);
276 params
= params_start
= (struct tag
*)gd
->bd
->bi_boot_params
;
277 params
= setup_start_tag(params
);
278 params
= setup_memory_tags(params
);
280 params
= setup_ramdisk_tag(params
,
281 PHYSADDR(initrd_start
),
282 PHYSADDR(initrd_end
));
284 params
= setup_commandline_tag(params
, commandline
);
285 params
= setup_clock_tags(params
);
286 params
= setup_ethernet_tags(params
);
287 setup_end_tag(params
);
289 printf("\nStarting kernel at %p (params at %p)...\n\n",
290 theKernel
, params_start
);
294 theKernel(ATAG_MAGIC
, params_start
);