root / hw / arm_boot.c @ 1de7afc9
History | View | Annotate | Download (14.8 kB)
1 | 5fafdf24 | ths | /*
|
---|---|---|---|
2 | 16406950 | pbrook | * ARM kernel loader.
|
3 | 16406950 | pbrook | *
|
4 | 9ee6e8bb | pbrook | * Copyright (c) 2006-2007 CodeSourcery.
|
5 | 16406950 | pbrook | * Written by Paul Brook
|
6 | 16406950 | pbrook | *
|
7 | 8e31bf38 | Matthew Fernandez | * This code is licensed under the GPL.
|
8 | 16406950 | pbrook | */
|
9 | 16406950 | pbrook | |
10 | 412beee6 | Grant Likely | #include "config.h" |
11 | 87ecb68b | pbrook | #include "hw.h" |
12 | 87ecb68b | pbrook | #include "arm-misc.h" |
13 | 87ecb68b | pbrook | #include "sysemu.h" |
14 | 412beee6 | Grant Likely | #include "boards.h" |
15 | ca20cf32 | Blue Swirl | #include "loader.h" |
16 | ca20cf32 | Blue Swirl | #include "elf.h" |
17 | 412beee6 | Grant Likely | #include "device_tree.h" |
18 | 1de7afc9 | Paolo Bonzini | #include "qemu/config-file.h" |
19 | 16406950 | pbrook | |
20 | 16406950 | pbrook | #define KERNEL_ARGS_ADDR 0x100 |
21 | 16406950 | pbrook | #define KERNEL_LOAD_ADDR 0x00010000 |
22 | 16406950 | pbrook | |
23 | 16406950 | pbrook | /* The worlds second smallest bootloader. Set r0-r2, then jump to kernel. */
|
24 | 16406950 | pbrook | static uint32_t bootloader[] = {
|
25 | 16406950 | pbrook | 0xe3a00000, /* mov r0, #0 */ |
26 | f8414cb5 | Peter Maydell | 0xe59f1004, /* ldr r1, [pc, #4] */ |
27 | f8414cb5 | Peter Maydell | 0xe59f2004, /* ldr r2, [pc, #4] */ |
28 | f8414cb5 | Peter Maydell | 0xe59ff004, /* ldr pc, [pc, #4] */ |
29 | f8414cb5 | Peter Maydell | 0, /* Board ID */ |
30 | 16406950 | pbrook | 0, /* Address of kernel args. Set by integratorcp_init. */ |
31 | 16406950 | pbrook | 0 /* Kernel entry point. Set by integratorcp_init. */ |
32 | 16406950 | pbrook | }; |
33 | 16406950 | pbrook | |
34 | 9d5ba9bf | Mark Langsdorf | /* Handling for secondary CPU boot in a multicore system.
|
35 | 9d5ba9bf | Mark Langsdorf | * Unlike the uniprocessor/primary CPU boot, this is platform
|
36 | 9d5ba9bf | Mark Langsdorf | * dependent. The default code here is based on the secondary
|
37 | 9d5ba9bf | Mark Langsdorf | * CPU boot protocol used on realview/vexpress boards, with
|
38 | 9d5ba9bf | Mark Langsdorf | * some parameterisation to increase its flexibility.
|
39 | 9d5ba9bf | Mark Langsdorf | * QEMU platform models for which this code is not appropriate
|
40 | 9d5ba9bf | Mark Langsdorf | * should override write_secondary_boot and secondary_cpu_reset_hook
|
41 | 9d5ba9bf | Mark Langsdorf | * instead.
|
42 | 9d5ba9bf | Mark Langsdorf | *
|
43 | 9d5ba9bf | Mark Langsdorf | * This code enables the interrupt controllers for the secondary
|
44 | 9d5ba9bf | Mark Langsdorf | * CPUs and then puts all the secondary CPUs into a loop waiting
|
45 | 9d5ba9bf | Mark Langsdorf | * for an interprocessor interrupt and polling a configurable
|
46 | 9d5ba9bf | Mark Langsdorf | * location for the kernel secondary CPU entry point.
|
47 | 9d5ba9bf | Mark Langsdorf | */
|
48 | bf471f79 | Peter Maydell | #define DSB_INSN 0xf57ff04f |
49 | bf471f79 | Peter Maydell | #define CP15_DSB_INSN 0xee070f9a /* mcr cp15, 0, r0, c7, c10, 4 */ |
50 | bf471f79 | Peter Maydell | |
51 | 9ee6e8bb | pbrook | static uint32_t smpboot[] = {
|
52 | bf471f79 | Peter Maydell | 0xe59f2028, /* ldr r2, gic_cpu_if */ |
53 | bf471f79 | Peter Maydell | 0xe59f0028, /* ldr r0, startaddr */ |
54 | 078758d0 | Evgeny Voevodin | 0xe3a01001, /* mov r1, #1 */ |
55 | bf471f79 | Peter Maydell | 0xe5821000, /* str r1, [r2] - set GICC_CTLR.Enable */ |
56 | bf471f79 | Peter Maydell | 0xe3a010ff, /* mov r1, #0xff */ |
57 | bf471f79 | Peter Maydell | 0xe5821004, /* str r1, [r2, 4] - set GIC_PMR.Priority to 0xff */ |
58 | bf471f79 | Peter Maydell | DSB_INSN, /* dsb */
|
59 | 9ee6e8bb | pbrook | 0xe320f003, /* wfi */ |
60 | 9ee6e8bb | pbrook | 0xe5901000, /* ldr r1, [r0] */ |
61 | be0f204a | Paul Brook | 0xe1110001, /* tst r1, r1 */ |
62 | be0f204a | Paul Brook | 0x0afffffb, /* beq <wfi> */ |
63 | f7c70325 | Paul Brook | 0xe12fff11, /* bx r1 */ |
64 | 96eacf64 | Peter Maydell | 0, /* gic_cpu_if: base address of GIC CPU interface */ |
65 | 078758d0 | Evgeny Voevodin | 0 /* bootreg: Boot register address is held here */ |
66 | 9ee6e8bb | pbrook | }; |
67 | 9ee6e8bb | pbrook | |
68 | 9543b0cd | Andreas Färber | static void default_write_secondary(ARMCPU *cpu, |
69 | 9d5ba9bf | Mark Langsdorf | const struct arm_boot_info *info) |
70 | 9d5ba9bf | Mark Langsdorf | { |
71 | 9d5ba9bf | Mark Langsdorf | int n;
|
72 | 9d5ba9bf | Mark Langsdorf | smpboot[ARRAY_SIZE(smpboot) - 1] = info->smp_bootreg_addr;
|
73 | 96eacf64 | Peter Maydell | smpboot[ARRAY_SIZE(smpboot) - 2] = info->gic_cpu_if_addr;
|
74 | 9d5ba9bf | Mark Langsdorf | for (n = 0; n < ARRAY_SIZE(smpboot); n++) { |
75 | bf471f79 | Peter Maydell | /* Replace DSB with the pre-v7 DSB if necessary. */
|
76 | bf471f79 | Peter Maydell | if (!arm_feature(&cpu->env, ARM_FEATURE_V7) &&
|
77 | bf471f79 | Peter Maydell | smpboot[n] == DSB_INSN) { |
78 | bf471f79 | Peter Maydell | smpboot[n] = CP15_DSB_INSN; |
79 | bf471f79 | Peter Maydell | } |
80 | 9d5ba9bf | Mark Langsdorf | smpboot[n] = tswap32(smpboot[n]); |
81 | 9d5ba9bf | Mark Langsdorf | } |
82 | 9d5ba9bf | Mark Langsdorf | rom_add_blob_fixed("smpboot", smpboot, sizeof(smpboot), |
83 | 9d5ba9bf | Mark Langsdorf | info->smp_loader_start); |
84 | 9d5ba9bf | Mark Langsdorf | } |
85 | 9d5ba9bf | Mark Langsdorf | |
86 | 5d309320 | Andreas Färber | static void default_reset_secondary(ARMCPU *cpu, |
87 | 9d5ba9bf | Mark Langsdorf | const struct arm_boot_info *info) |
88 | 9d5ba9bf | Mark Langsdorf | { |
89 | 5d309320 | Andreas Färber | CPUARMState *env = &cpu->env; |
90 | 5d309320 | Andreas Färber | |
91 | 9d5ba9bf | Mark Langsdorf | stl_phys_notdirty(info->smp_bootreg_addr, 0);
|
92 | 9d5ba9bf | Mark Langsdorf | env->regs[15] = info->smp_loader_start;
|
93 | 9d5ba9bf | Mark Langsdorf | } |
94 | 9d5ba9bf | Mark Langsdorf | |
95 | 52b43737 | pbrook | #define WRITE_WORD(p, value) do { \ |
96 | 52b43737 | pbrook | stl_phys_notdirty(p, value); \ |
97 | 52b43737 | pbrook | p += 4; \
|
98 | 52b43737 | pbrook | } while (0) |
99 | 52b43737 | pbrook | |
100 | 761c9eb0 | Stefan Weil | static void set_kernel_args(const struct arm_boot_info *info) |
101 | 16406950 | pbrook | { |
102 | 761c9eb0 | Stefan Weil | int initrd_size = info->initrd_size;
|
103 | a8170e5e | Avi Kivity | hwaddr base = info->loader_start; |
104 | a8170e5e | Avi Kivity | hwaddr p; |
105 | 16406950 | pbrook | |
106 | 52b43737 | pbrook | p = base + KERNEL_ARGS_ADDR; |
107 | 16406950 | pbrook | /* ATAG_CORE */
|
108 | 52b43737 | pbrook | WRITE_WORD(p, 5);
|
109 | 52b43737 | pbrook | WRITE_WORD(p, 0x54410001);
|
110 | 52b43737 | pbrook | WRITE_WORD(p, 1);
|
111 | 52b43737 | pbrook | WRITE_WORD(p, 0x1000);
|
112 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
113 | 16406950 | pbrook | /* ATAG_MEM */
|
114 | f93eb9ff | balrog | /* TODO: handle multiple chips on one ATAG list */
|
115 | 52b43737 | pbrook | WRITE_WORD(p, 4);
|
116 | 52b43737 | pbrook | WRITE_WORD(p, 0x54410002);
|
117 | 52b43737 | pbrook | WRITE_WORD(p, info->ram_size); |
118 | 52b43737 | pbrook | WRITE_WORD(p, info->loader_start); |
119 | 16406950 | pbrook | if (initrd_size) {
|
120 | 16406950 | pbrook | /* ATAG_INITRD2 */
|
121 | 52b43737 | pbrook | WRITE_WORD(p, 4);
|
122 | 52b43737 | pbrook | WRITE_WORD(p, 0x54420005);
|
123 | fc53b7d4 | Peter Maydell | WRITE_WORD(p, info->initrd_start); |
124 | 52b43737 | pbrook | WRITE_WORD(p, initrd_size); |
125 | 16406950 | pbrook | } |
126 | f93eb9ff | balrog | if (info->kernel_cmdline && *info->kernel_cmdline) {
|
127 | 16406950 | pbrook | /* ATAG_CMDLINE */
|
128 | 16406950 | pbrook | int cmdline_size;
|
129 | 16406950 | pbrook | |
130 | f93eb9ff | balrog | cmdline_size = strlen(info->kernel_cmdline); |
131 | 52b43737 | pbrook | cpu_physical_memory_write(p + 8, (void *)info->kernel_cmdline, |
132 | 52b43737 | pbrook | cmdline_size + 1);
|
133 | 16406950 | pbrook | cmdline_size = (cmdline_size >> 2) + 1; |
134 | 52b43737 | pbrook | WRITE_WORD(p, cmdline_size + 2);
|
135 | 52b43737 | pbrook | WRITE_WORD(p, 0x54410009);
|
136 | 52b43737 | pbrook | p += cmdline_size * 4;
|
137 | 16406950 | pbrook | } |
138 | f93eb9ff | balrog | if (info->atag_board) {
|
139 | f93eb9ff | balrog | /* ATAG_BOARD */
|
140 | f93eb9ff | balrog | int atag_board_len;
|
141 | 52b43737 | pbrook | uint8_t atag_board_buf[0x1000];
|
142 | f93eb9ff | balrog | |
143 | 52b43737 | pbrook | atag_board_len = (info->atag_board(info, atag_board_buf) + 3) & ~3; |
144 | 52b43737 | pbrook | WRITE_WORD(p, (atag_board_len + 8) >> 2); |
145 | 52b43737 | pbrook | WRITE_WORD(p, 0x414f4d50);
|
146 | 52b43737 | pbrook | cpu_physical_memory_write(p, atag_board_buf, atag_board_len); |
147 | f93eb9ff | balrog | p += atag_board_len; |
148 | f93eb9ff | balrog | } |
149 | 16406950 | pbrook | /* ATAG_END */
|
150 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
151 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
152 | 16406950 | pbrook | } |
153 | 16406950 | pbrook | |
154 | 761c9eb0 | Stefan Weil | static void set_kernel_args_old(const struct arm_boot_info *info) |
155 | 2b8f2d41 | balrog | { |
156 | a8170e5e | Avi Kivity | hwaddr p; |
157 | 52b43737 | pbrook | const char *s; |
158 | 761c9eb0 | Stefan Weil | int initrd_size = info->initrd_size;
|
159 | a8170e5e | Avi Kivity | hwaddr base = info->loader_start; |
160 | 2b8f2d41 | balrog | |
161 | 2b8f2d41 | balrog | /* see linux/include/asm-arm/setup.h */
|
162 | 52b43737 | pbrook | p = base + KERNEL_ARGS_ADDR; |
163 | 2b8f2d41 | balrog | /* page_size */
|
164 | 52b43737 | pbrook | WRITE_WORD(p, 4096);
|
165 | 2b8f2d41 | balrog | /* nr_pages */
|
166 | 52b43737 | pbrook | WRITE_WORD(p, info->ram_size / 4096);
|
167 | 2b8f2d41 | balrog | /* ramdisk_size */
|
168 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
169 | 2b8f2d41 | balrog | #define FLAG_READONLY 1 |
170 | 2b8f2d41 | balrog | #define FLAG_RDLOAD 4 |
171 | 2b8f2d41 | balrog | #define FLAG_RDPROMPT 8 |
172 | 2b8f2d41 | balrog | /* flags */
|
173 | 52b43737 | pbrook | WRITE_WORD(p, FLAG_READONLY | FLAG_RDLOAD | FLAG_RDPROMPT); |
174 | 2b8f2d41 | balrog | /* rootdev */
|
175 | 52b43737 | pbrook | WRITE_WORD(p, (31 << 8) | 0); /* /dev/mtdblock0 */ |
176 | 2b8f2d41 | balrog | /* video_num_cols */
|
177 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
178 | 2b8f2d41 | balrog | /* video_num_rows */
|
179 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
180 | 2b8f2d41 | balrog | /* video_x */
|
181 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
182 | 2b8f2d41 | balrog | /* video_y */
|
183 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
184 | 2b8f2d41 | balrog | /* memc_control_reg */
|
185 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
186 | 2b8f2d41 | balrog | /* unsigned char sounddefault */
|
187 | 2b8f2d41 | balrog | /* unsigned char adfsdrives */
|
188 | 2b8f2d41 | balrog | /* unsigned char bytes_per_char_h */
|
189 | 2b8f2d41 | balrog | /* unsigned char bytes_per_char_v */
|
190 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
191 | 2b8f2d41 | balrog | /* pages_in_bank[4] */
|
192 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
193 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
194 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
195 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
196 | 2b8f2d41 | balrog | /* pages_in_vram */
|
197 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
198 | 2b8f2d41 | balrog | /* initrd_start */
|
199 | fc53b7d4 | Peter Maydell | if (initrd_size) {
|
200 | fc53b7d4 | Peter Maydell | WRITE_WORD(p, info->initrd_start); |
201 | fc53b7d4 | Peter Maydell | } else {
|
202 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
203 | fc53b7d4 | Peter Maydell | } |
204 | 2b8f2d41 | balrog | /* initrd_size */
|
205 | 52b43737 | pbrook | WRITE_WORD(p, initrd_size); |
206 | 2b8f2d41 | balrog | /* rd_start */
|
207 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
208 | 2b8f2d41 | balrog | /* system_rev */
|
209 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
210 | 2b8f2d41 | balrog | /* system_serial_low */
|
211 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
212 | 2b8f2d41 | balrog | /* system_serial_high */
|
213 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
214 | 2b8f2d41 | balrog | /* mem_fclk_21285 */
|
215 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
216 | 2b8f2d41 | balrog | /* zero unused fields */
|
217 | 52b43737 | pbrook | while (p < base + KERNEL_ARGS_ADDR + 256 + 1024) { |
218 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
219 | 52b43737 | pbrook | } |
220 | 52b43737 | pbrook | s = info->kernel_cmdline; |
221 | 52b43737 | pbrook | if (s) {
|
222 | 52b43737 | pbrook | cpu_physical_memory_write(p, (void *)s, strlen(s) + 1); |
223 | 52b43737 | pbrook | } else {
|
224 | 52b43737 | pbrook | WRITE_WORD(p, 0);
|
225 | 52b43737 | pbrook | } |
226 | 2b8f2d41 | balrog | } |
227 | 2b8f2d41 | balrog | |
228 | a8170e5e | Avi Kivity | static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo) |
229 | 412beee6 | Grant Likely | { |
230 | 412beee6 | Grant Likely | #ifdef CONFIG_FDT
|
231 | 9bfa659e | Peter Maydell | uint32_t *mem_reg_property; |
232 | 9bfa659e | Peter Maydell | uint32_t mem_reg_propsize; |
233 | 412beee6 | Grant Likely | void *fdt = NULL; |
234 | 412beee6 | Grant Likely | char *filename;
|
235 | 412beee6 | Grant Likely | int size, rc;
|
236 | 9bfa659e | Peter Maydell | uint32_t acells, scells, hival; |
237 | 412beee6 | Grant Likely | |
238 | 412beee6 | Grant Likely | filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, binfo->dtb_filename); |
239 | 412beee6 | Grant Likely | if (!filename) {
|
240 | 412beee6 | Grant Likely | fprintf(stderr, "Couldn't open dtb file %s\n", binfo->dtb_filename);
|
241 | 412beee6 | Grant Likely | return -1; |
242 | 412beee6 | Grant Likely | } |
243 | 412beee6 | Grant Likely | |
244 | 412beee6 | Grant Likely | fdt = load_device_tree(filename, &size); |
245 | 412beee6 | Grant Likely | if (!fdt) {
|
246 | 412beee6 | Grant Likely | fprintf(stderr, "Couldn't open dtb file %s\n", filename);
|
247 | 412beee6 | Grant Likely | g_free(filename); |
248 | 412beee6 | Grant Likely | return -1; |
249 | 412beee6 | Grant Likely | } |
250 | 412beee6 | Grant Likely | g_free(filename); |
251 | 412beee6 | Grant Likely | |
252 | 9bfa659e | Peter Maydell | acells = qemu_devtree_getprop_cell(fdt, "/", "#address-cells"); |
253 | 9bfa659e | Peter Maydell | scells = qemu_devtree_getprop_cell(fdt, "/", "#size-cells"); |
254 | 9bfa659e | Peter Maydell | if (acells == 0 || scells == 0) { |
255 | 9bfa659e | Peter Maydell | fprintf(stderr, "dtb file invalid (#address-cells or #size-cells 0)\n");
|
256 | 9bfa659e | Peter Maydell | return -1; |
257 | 9bfa659e | Peter Maydell | } |
258 | 9bfa659e | Peter Maydell | |
259 | 9bfa659e | Peter Maydell | mem_reg_propsize = acells + scells; |
260 | 9bfa659e | Peter Maydell | mem_reg_property = g_new0(uint32_t, mem_reg_propsize); |
261 | 9bfa659e | Peter Maydell | mem_reg_property[acells - 1] = cpu_to_be32(binfo->loader_start);
|
262 | 9bfa659e | Peter Maydell | hival = cpu_to_be32(binfo->loader_start >> 32);
|
263 | 9bfa659e | Peter Maydell | if (acells > 1) { |
264 | 9bfa659e | Peter Maydell | mem_reg_property[acells - 2] = hival;
|
265 | 9bfa659e | Peter Maydell | } else if (hival != 0) { |
266 | 9bfa659e | Peter Maydell | fprintf(stderr, "qemu: dtb file not compatible with "
|
267 | 9bfa659e | Peter Maydell | "RAM start address > 4GB\n");
|
268 | 9bfa659e | Peter Maydell | exit(1);
|
269 | 9bfa659e | Peter Maydell | } |
270 | 9bfa659e | Peter Maydell | mem_reg_property[acells + scells - 1] = cpu_to_be32(binfo->ram_size);
|
271 | 9bfa659e | Peter Maydell | hival = cpu_to_be32(binfo->ram_size >> 32);
|
272 | 9bfa659e | Peter Maydell | if (scells > 1) { |
273 | 9bfa659e | Peter Maydell | mem_reg_property[acells + scells - 2] = hival;
|
274 | 9bfa659e | Peter Maydell | } else if (hival != 0) { |
275 | 9bfa659e | Peter Maydell | fprintf(stderr, "qemu: dtb file not compatible with "
|
276 | 9bfa659e | Peter Maydell | "RAM size > 4GB\n");
|
277 | 9bfa659e | Peter Maydell | exit(1);
|
278 | 9bfa659e | Peter Maydell | } |
279 | 9bfa659e | Peter Maydell | |
280 | 412beee6 | Grant Likely | rc = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property, |
281 | 9bfa659e | Peter Maydell | mem_reg_propsize * sizeof(uint32_t));
|
282 | 412beee6 | Grant Likely | if (rc < 0) { |
283 | 412beee6 | Grant Likely | fprintf(stderr, "couldn't set /memory/reg\n");
|
284 | 412beee6 | Grant Likely | } |
285 | 412beee6 | Grant Likely | |
286 | 5e87975c | Peter A. G. Crosthwaite | if (binfo->kernel_cmdline && *binfo->kernel_cmdline) {
|
287 | 5e87975c | Peter A. G. Crosthwaite | rc = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs", |
288 | 5e87975c | Peter A. G. Crosthwaite | binfo->kernel_cmdline); |
289 | 5e87975c | Peter A. G. Crosthwaite | if (rc < 0) { |
290 | 5e87975c | Peter A. G. Crosthwaite | fprintf(stderr, "couldn't set /chosen/bootargs\n");
|
291 | 5e87975c | Peter A. G. Crosthwaite | } |
292 | 412beee6 | Grant Likely | } |
293 | 412beee6 | Grant Likely | |
294 | 412beee6 | Grant Likely | if (binfo->initrd_size) {
|
295 | 412beee6 | Grant Likely | rc = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start", |
296 | fc53b7d4 | Peter Maydell | binfo->initrd_start); |
297 | 412beee6 | Grant Likely | if (rc < 0) { |
298 | 412beee6 | Grant Likely | fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
|
299 | 412beee6 | Grant Likely | } |
300 | 412beee6 | Grant Likely | |
301 | 412beee6 | Grant Likely | rc = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end", |
302 | fc53b7d4 | Peter Maydell | binfo->initrd_start + binfo->initrd_size); |
303 | 412beee6 | Grant Likely | if (rc < 0) { |
304 | 412beee6 | Grant Likely | fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
|
305 | 412beee6 | Grant Likely | } |
306 | 412beee6 | Grant Likely | } |
307 | 412beee6 | Grant Likely | |
308 | 412beee6 | Grant Likely | cpu_physical_memory_write(addr, fdt, size); |
309 | 412beee6 | Grant Likely | |
310 | 412beee6 | Grant Likely | return 0; |
311 | 412beee6 | Grant Likely | |
312 | 412beee6 | Grant Likely | #else
|
313 | 412beee6 | Grant Likely | fprintf(stderr, "Device tree requested, "
|
314 | 412beee6 | Grant Likely | "but qemu was compiled without fdt support\n");
|
315 | 412beee6 | Grant Likely | return -1; |
316 | 412beee6 | Grant Likely | #endif
|
317 | 412beee6 | Grant Likely | } |
318 | 412beee6 | Grant Likely | |
319 | 6ed221b6 | Adam Lackorzynski | static void do_cpu_reset(void *opaque) |
320 | f2d74978 | Paul Brook | { |
321 | 351d5666 | Andreas Färber | ARMCPU *cpu = opaque; |
322 | 351d5666 | Andreas Färber | CPUARMState *env = &cpu->env; |
323 | 462a8bc6 | Stefan Weil | const struct arm_boot_info *info = env->boot_info; |
324 | f2d74978 | Paul Brook | |
325 | 351d5666 | Andreas Färber | cpu_reset(CPU(cpu)); |
326 | f2d74978 | Paul Brook | if (info) {
|
327 | f2d74978 | Paul Brook | if (!info->is_linux) {
|
328 | f2d74978 | Paul Brook | /* Jump to the entry point. */
|
329 | f2d74978 | Paul Brook | env->regs[15] = info->entry & 0xfffffffe; |
330 | f2d74978 | Paul Brook | env->thumb = info->entry & 1;
|
331 | f2d74978 | Paul Brook | } else {
|
332 | 6ed221b6 | Adam Lackorzynski | if (env == first_cpu) {
|
333 | 6ed221b6 | Adam Lackorzynski | env->regs[15] = info->loader_start;
|
334 | 412beee6 | Grant Likely | if (!info->dtb_filename) {
|
335 | 412beee6 | Grant Likely | if (old_param) {
|
336 | 412beee6 | Grant Likely | set_kernel_args_old(info); |
337 | 412beee6 | Grant Likely | } else {
|
338 | 412beee6 | Grant Likely | set_kernel_args(info); |
339 | 412beee6 | Grant Likely | } |
340 | 6ed221b6 | Adam Lackorzynski | } |
341 | f2d74978 | Paul Brook | } else {
|
342 | 5d309320 | Andreas Färber | info->secondary_cpu_reset_hook(cpu, info); |
343 | f2d74978 | Paul Brook | } |
344 | f2d74978 | Paul Brook | } |
345 | f2d74978 | Paul Brook | } |
346 | f2d74978 | Paul Brook | } |
347 | f2d74978 | Paul Brook | |
348 | 3aaa8dfa | Andreas Färber | void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info) |
349 | 16406950 | pbrook | { |
350 | 3aaa8dfa | Andreas Färber | CPUARMState *env = &cpu->env; |
351 | 16406950 | pbrook | int kernel_size;
|
352 | 16406950 | pbrook | int initrd_size;
|
353 | 16406950 | pbrook | int n;
|
354 | 1c7b3754 | pbrook | int is_linux = 0; |
355 | 1c7b3754 | pbrook | uint64_t elf_entry; |
356 | a8170e5e | Avi Kivity | hwaddr entry; |
357 | ca20cf32 | Blue Swirl | int big_endian;
|
358 | 412beee6 | Grant Likely | QemuOpts *machine_opts; |
359 | 16406950 | pbrook | |
360 | 16406950 | pbrook | /* Load the kernel. */
|
361 | f93eb9ff | balrog | if (!info->kernel_filename) {
|
362 | 16406950 | pbrook | fprintf(stderr, "Kernel image must be specified\n");
|
363 | 16406950 | pbrook | exit(1);
|
364 | 16406950 | pbrook | } |
365 | daf90626 | pbrook | |
366 | 412beee6 | Grant Likely | machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0); |
367 | 412beee6 | Grant Likely | if (machine_opts) {
|
368 | 412beee6 | Grant Likely | info->dtb_filename = qemu_opt_get(machine_opts, "dtb");
|
369 | 412beee6 | Grant Likely | } else {
|
370 | 412beee6 | Grant Likely | info->dtb_filename = NULL;
|
371 | 412beee6 | Grant Likely | } |
372 | 412beee6 | Grant Likely | |
373 | 9d5ba9bf | Mark Langsdorf | if (!info->secondary_cpu_reset_hook) {
|
374 | 9d5ba9bf | Mark Langsdorf | info->secondary_cpu_reset_hook = default_reset_secondary; |
375 | 9d5ba9bf | Mark Langsdorf | } |
376 | 9d5ba9bf | Mark Langsdorf | if (!info->write_secondary_boot) {
|
377 | 9d5ba9bf | Mark Langsdorf | info->write_secondary_boot = default_write_secondary; |
378 | 9d5ba9bf | Mark Langsdorf | } |
379 | 9d5ba9bf | Mark Langsdorf | |
380 | f2d74978 | Paul Brook | if (info->nb_cpus == 0) |
381 | f2d74978 | Paul Brook | info->nb_cpus = 1;
|
382 | f93eb9ff | balrog | |
383 | ca20cf32 | Blue Swirl | #ifdef TARGET_WORDS_BIGENDIAN
|
384 | ca20cf32 | Blue Swirl | big_endian = 1;
|
385 | ca20cf32 | Blue Swirl | #else
|
386 | ca20cf32 | Blue Swirl | big_endian = 0;
|
387 | ca20cf32 | Blue Swirl | #endif
|
388 | ca20cf32 | Blue Swirl | |
389 | fc53b7d4 | Peter Maydell | /* We want to put the initrd far enough into RAM that when the
|
390 | fc53b7d4 | Peter Maydell | * kernel is uncompressed it will not clobber the initrd. However
|
391 | fc53b7d4 | Peter Maydell | * on boards without much RAM we must ensure that we still leave
|
392 | fc53b7d4 | Peter Maydell | * enough room for a decent sized initrd, and on boards with large
|
393 | fc53b7d4 | Peter Maydell | * amounts of RAM we must avoid the initrd being so far up in RAM
|
394 | fc53b7d4 | Peter Maydell | * that it is outside lowmem and inaccessible to the kernel.
|
395 | fc53b7d4 | Peter Maydell | * So for boards with less than 256MB of RAM we put the initrd
|
396 | fc53b7d4 | Peter Maydell | * halfway into RAM, and for boards with 256MB of RAM or more we put
|
397 | fc53b7d4 | Peter Maydell | * the initrd at 128MB.
|
398 | fc53b7d4 | Peter Maydell | */
|
399 | fc53b7d4 | Peter Maydell | info->initrd_start = info->loader_start + |
400 | fc53b7d4 | Peter Maydell | MIN(info->ram_size / 2, 128 * 1024 * 1024); |
401 | fc53b7d4 | Peter Maydell | |
402 | 1c7b3754 | pbrook | /* Assume that raw images are linux kernels, and ELF images are not. */
|
403 | 409dbce5 | Aurelien Jarno | kernel_size = load_elf(info->kernel_filename, NULL, NULL, &elf_entry, |
404 | 409dbce5 | Aurelien Jarno | NULL, NULL, big_endian, ELF_MACHINE, 1); |
405 | 1c7b3754 | pbrook | entry = elf_entry; |
406 | 1c7b3754 | pbrook | if (kernel_size < 0) { |
407 | 5a9154e0 | aliguori | kernel_size = load_uimage(info->kernel_filename, &entry, NULL,
|
408 | 5a9154e0 | aliguori | &is_linux); |
409 | 1c7b3754 | pbrook | } |
410 | 1c7b3754 | pbrook | if (kernel_size < 0) { |
411 | f93eb9ff | balrog | entry = info->loader_start + KERNEL_LOAD_ADDR; |
412 | 3b760e04 | pbrook | kernel_size = load_image_targphys(info->kernel_filename, entry, |
413 | 0b944384 | Peter Maydell | info->ram_size - KERNEL_LOAD_ADDR); |
414 | 1c7b3754 | pbrook | is_linux = 1;
|
415 | 1c7b3754 | pbrook | } |
416 | 1c7b3754 | pbrook | if (kernel_size < 0) { |
417 | f93eb9ff | balrog | fprintf(stderr, "qemu: could not load kernel '%s'\n",
|
418 | f93eb9ff | balrog | info->kernel_filename); |
419 | 1c7b3754 | pbrook | exit(1);
|
420 | 1c7b3754 | pbrook | } |
421 | f2d74978 | Paul Brook | info->entry = entry; |
422 | f2d74978 | Paul Brook | if (is_linux) {
|
423 | f93eb9ff | balrog | if (info->initrd_filename) {
|
424 | 3b760e04 | pbrook | initrd_size = load_image_targphys(info->initrd_filename, |
425 | fc53b7d4 | Peter Maydell | info->initrd_start, |
426 | fc53b7d4 | Peter Maydell | info->ram_size - |
427 | fc53b7d4 | Peter Maydell | info->initrd_start); |
428 | daf90626 | pbrook | if (initrd_size < 0) { |
429 | daf90626 | pbrook | fprintf(stderr, "qemu: could not load initrd '%s'\n",
|
430 | f93eb9ff | balrog | info->initrd_filename); |
431 | daf90626 | pbrook | exit(1);
|
432 | daf90626 | pbrook | } |
433 | daf90626 | pbrook | } else {
|
434 | daf90626 | pbrook | initrd_size = 0;
|
435 | daf90626 | pbrook | } |
436 | 412beee6 | Grant Likely | info->initrd_size = initrd_size; |
437 | 412beee6 | Grant Likely | |
438 | f8414cb5 | Peter Maydell | bootloader[4] = info->board_id;
|
439 | 412beee6 | Grant Likely | |
440 | 412beee6 | Grant Likely | /* for device tree boot, we pass the DTB directly in r2. Otherwise
|
441 | 412beee6 | Grant Likely | * we point to the kernel args.
|
442 | 412beee6 | Grant Likely | */
|
443 | 412beee6 | Grant Likely | if (info->dtb_filename) {
|
444 | 412beee6 | Grant Likely | /* Place the DTB after the initrd in memory */
|
445 | fc53b7d4 | Peter Maydell | hwaddr dtb_start = TARGET_PAGE_ALIGN(info->initrd_start + |
446 | fc53b7d4 | Peter Maydell | initrd_size); |
447 | 412beee6 | Grant Likely | if (load_dtb(dtb_start, info)) {
|
448 | 412beee6 | Grant Likely | exit(1);
|
449 | 412beee6 | Grant Likely | } |
450 | 412beee6 | Grant Likely | bootloader[5] = dtb_start;
|
451 | 412beee6 | Grant Likely | } else {
|
452 | 412beee6 | Grant Likely | bootloader[5] = info->loader_start + KERNEL_ARGS_ADDR;
|
453 | 3871481c | Peter Maydell | if (info->ram_size >= (1ULL << 32)) { |
454 | 3871481c | Peter Maydell | fprintf(stderr, "qemu: RAM size must be less than 4GB to boot"
|
455 | 3871481c | Peter Maydell | " Linux kernel using ATAGS (try passing a device tree"
|
456 | 3871481c | Peter Maydell | " using -dtb)\n");
|
457 | 3871481c | Peter Maydell | exit(1);
|
458 | 3871481c | Peter Maydell | } |
459 | 412beee6 | Grant Likely | } |
460 | 1c7b3754 | pbrook | bootloader[6] = entry;
|
461 | 52b43737 | pbrook | for (n = 0; n < sizeof(bootloader) / 4; n++) { |
462 | f2d74978 | Paul Brook | bootloader[n] = tswap32(bootloader[n]); |
463 | 52b43737 | pbrook | } |
464 | f2d74978 | Paul Brook | rom_add_blob_fixed("bootloader", bootloader, sizeof(bootloader), |
465 | f2d74978 | Paul Brook | info->loader_start); |
466 | 52b43737 | pbrook | if (info->nb_cpus > 1) { |
467 | 9543b0cd | Andreas Färber | info->write_secondary_boot(cpu, info); |
468 | 52b43737 | pbrook | } |
469 | 16406950 | pbrook | } |
470 | f2d74978 | Paul Brook | info->is_linux = is_linux; |
471 | 6ed221b6 | Adam Lackorzynski | |
472 | 6ed221b6 | Adam Lackorzynski | for (; env; env = env->next_cpu) {
|
473 | 351d5666 | Andreas Färber | cpu = arm_env_get_cpu(env); |
474 | 6ed221b6 | Adam Lackorzynski | env->boot_info = info; |
475 | 351d5666 | Andreas Färber | qemu_register_reset(do_cpu_reset, cpu); |
476 | 6ed221b6 | Adam Lackorzynski | } |
477 | 16406950 | pbrook | } |