root / hw / arm_boot.c @ 42fc925e
History | View | Annotate | Download (3 kB)
1 |
/*
|
---|---|
2 |
* ARM kernel loader.
|
3 |
*
|
4 |
* Copyright (c) 2006 CodeSourcery.
|
5 |
* Written by Paul Brook
|
6 |
*
|
7 |
* This code is licenced under the GPL.
|
8 |
*/
|
9 |
|
10 |
#include "vl.h" |
11 |
|
12 |
#define KERNEL_ARGS_ADDR 0x100 |
13 |
#define KERNEL_LOAD_ADDR 0x00010000 |
14 |
#define INITRD_LOAD_ADDR 0x00800000 |
15 |
|
16 |
/* The worlds second smallest bootloader. Set r0-r2, then jump to kernel. */
|
17 |
static uint32_t bootloader[] = {
|
18 |
0xe3a00000, /* mov r0, #0 */ |
19 |
0xe3a01000, /* mov r1, #0x?? */ |
20 |
0xe3811c00, /* orr r1, r1, #0x??00 */ |
21 |
0xe59f2000, /* ldr r2, [pc, #0] */ |
22 |
0xe59ff000, /* ldr pc, [pc, #0] */ |
23 |
0, /* Address of kernel args. Set by integratorcp_init. */ |
24 |
0 /* Kernel entry point. Set by integratorcp_init. */ |
25 |
}; |
26 |
|
27 |
static void set_kernel_args(uint32_t ram_size, int initrd_size, |
28 |
const char *kernel_cmdline) |
29 |
{ |
30 |
uint32_t *p; |
31 |
|
32 |
p = (uint32_t *)(phys_ram_base + KERNEL_ARGS_ADDR); |
33 |
/* ATAG_CORE */
|
34 |
stl_raw(p++, 5);
|
35 |
stl_raw(p++, 0x54410001);
|
36 |
stl_raw(p++, 1);
|
37 |
stl_raw(p++, 0x1000);
|
38 |
stl_raw(p++, 0);
|
39 |
/* ATAG_MEM */
|
40 |
stl_raw(p++, 4);
|
41 |
stl_raw(p++, 0x54410002);
|
42 |
stl_raw(p++, ram_size); |
43 |
stl_raw(p++, 0);
|
44 |
if (initrd_size) {
|
45 |
/* ATAG_INITRD2 */
|
46 |
stl_raw(p++, 4);
|
47 |
stl_raw(p++, 0x54420005);
|
48 |
stl_raw(p++, INITRD_LOAD_ADDR); |
49 |
stl_raw(p++, initrd_size); |
50 |
} |
51 |
if (kernel_cmdline && *kernel_cmdline) {
|
52 |
/* ATAG_CMDLINE */
|
53 |
int cmdline_size;
|
54 |
|
55 |
cmdline_size = strlen(kernel_cmdline); |
56 |
memcpy (p + 2, kernel_cmdline, cmdline_size + 1); |
57 |
cmdline_size = (cmdline_size >> 2) + 1; |
58 |
stl_raw(p++, cmdline_size + 2);
|
59 |
stl_raw(p++, 0x54410009);
|
60 |
p += cmdline_size; |
61 |
} |
62 |
/* ATAG_END */
|
63 |
stl_raw(p++, 0);
|
64 |
stl_raw(p++, 0);
|
65 |
} |
66 |
|
67 |
void arm_load_kernel(int ram_size, const char *kernel_filename, |
68 |
const char *kernel_cmdline, const char *initrd_filename, |
69 |
int board_id)
|
70 |
{ |
71 |
int kernel_size;
|
72 |
int initrd_size;
|
73 |
int n;
|
74 |
|
75 |
/* Load the kernel. */
|
76 |
if (!kernel_filename) {
|
77 |
fprintf(stderr, "Kernel image must be specified\n");
|
78 |
exit(1);
|
79 |
} |
80 |
kernel_size = load_image(kernel_filename, |
81 |
phys_ram_base + KERNEL_LOAD_ADDR); |
82 |
if (kernel_size < 0) { |
83 |
fprintf(stderr, "qemu: could not load kernel '%s'\n", kernel_filename);
|
84 |
exit(1);
|
85 |
} |
86 |
if (initrd_filename) {
|
87 |
initrd_size = load_image(initrd_filename, |
88 |
phys_ram_base + INITRD_LOAD_ADDR); |
89 |
if (initrd_size < 0) { |
90 |
fprintf(stderr, "qemu: could not load initrd '%s'\n",
|
91 |
initrd_filename); |
92 |
exit(1);
|
93 |
} |
94 |
} else {
|
95 |
initrd_size = 0;
|
96 |
} |
97 |
bootloader[1] |= board_id & 0xff; |
98 |
bootloader[2] |= (board_id >> 8) & 0xff; |
99 |
bootloader[5] = KERNEL_ARGS_ADDR;
|
100 |
bootloader[6] = KERNEL_LOAD_ADDR;
|
101 |
for (n = 0; n < sizeof(bootloader) / 4; n++) |
102 |
stl_raw(phys_ram_base + (n * 4), bootloader[n]);
|
103 |
set_kernel_args(ram_size, initrd_size, kernel_cmdline); |
104 |
} |
105 |
|