blob: a6e91436625eb005768d6fe7825ba2e26e0765e9 [file] [log] [blame]
ths5fafdf22007-09-16 21:08:06 +00001/*
pbrook16406952006-04-27 23:15:07 +00002 * ARM kernel loader.
3 *
pbrook9ee6e8b2007-11-11 00:04:49 +00004 * Copyright (c) 2006-2007 CodeSourcery.
pbrook16406952006-04-27 23:15:07 +00005 * Written by Paul Brook
6 *
Matthew Fernandez8e31bf32011-06-26 12:21:35 +10007 * This code is licensed under the GPL.
pbrook16406952006-04-27 23:15:07 +00008 */
9
Grant Likely412beee2012-03-02 11:56:38 +000010#include "config.h"
pbrook87ecb682007-11-17 17:14:51 +000011#include "hw.h"
12#include "arm-misc.h"
13#include "sysemu.h"
Grant Likely412beee2012-03-02 11:56:38 +000014#include "boards.h"
Blue Swirlca20cf32009-09-20 14:58:02 +000015#include "loader.h"
16#include "elf.h"
Grant Likely412beee2012-03-02 11:56:38 +000017#include "device_tree.h"
pbrook16406952006-04-27 23:15:07 +000018
19#define KERNEL_ARGS_ADDR 0x100
20#define KERNEL_LOAD_ADDR 0x00010000
Peter Maydell756ba3b2011-04-19 16:32:34 +010021#define INITRD_LOAD_ADDR 0x00d00000
pbrook16406952006-04-27 23:15:07 +000022
23/* The worlds second smallest bootloader. Set r0-r2, then jump to kernel. */
24static uint32_t bootloader[] = {
25 0xe3a00000, /* mov r0, #0 */
Peter Maydellf8414cb2012-01-26 11:43:48 +000026 0xe59f1004, /* ldr r1, [pc, #4] */
27 0xe59f2004, /* ldr r2, [pc, #4] */
28 0xe59ff004, /* ldr pc, [pc, #4] */
29 0, /* Board ID */
pbrook16406952006-04-27 23:15:07 +000030 0, /* Address of kernel args. Set by integratorcp_init. */
31 0 /* Kernel entry point. Set by integratorcp_init. */
32};
33
Mark Langsdorf9d5ba9b2012-01-26 11:43:48 +000034/* Handling for secondary CPU boot in a multicore system.
35 * Unlike the uniprocessor/primary CPU boot, this is platform
36 * dependent. The default code here is based on the secondary
37 * CPU boot protocol used on realview/vexpress boards, with
38 * some parameterisation to increase its flexibility.
39 * QEMU platform models for which this code is not appropriate
40 * should override write_secondary_boot and secondary_cpu_reset_hook
41 * instead.
42 *
43 * This code enables the interrupt controllers for the secondary
44 * CPUs and then puts all the secondary CPUs into a loop waiting
45 * for an interprocessor interrupt and polling a configurable
46 * location for the kernel secondary CPU entry point.
47 */
pbrook9ee6e8b2007-11-11 00:04:49 +000048static uint32_t smpboot[] = {
Peter Maydell96eacf62012-02-16 09:56:09 +000049 0xe59f201c, /* ldr r2, gic_cpu_if */
Evgeny Voevodin078758d2012-01-13 20:52:40 +000050 0xe59f001c, /* ldr r0, startaddr */
51 0xe3a01001, /* mov r1, #1 */
Peter Maydell96eacf62012-02-16 09:56:09 +000052 0xe5821000, /* str r1, [r2] */
pbrook9ee6e8b2007-11-11 00:04:49 +000053 0xe320f003, /* wfi */
54 0xe5901000, /* ldr r1, [r0] */
Paul Brookbe0f2042009-11-11 19:59:29 +000055 0xe1110001, /* tst r1, r1 */
56 0x0afffffb, /* beq <wfi> */
Paul Brookf7c70322009-11-19 16:45:21 +000057 0xe12fff11, /* bx r1 */
Peter Maydell96eacf62012-02-16 09:56:09 +000058 0, /* gic_cpu_if: base address of GIC CPU interface */
Evgeny Voevodin078758d2012-01-13 20:52:40 +000059 0 /* bootreg: Boot register address is held here */
pbrook9ee6e8b2007-11-11 00:04:49 +000060};
61
Andreas Färber9543b0c2012-05-14 00:08:10 +020062static void default_write_secondary(ARMCPU *cpu,
Mark Langsdorf9d5ba9b2012-01-26 11:43:48 +000063 const struct arm_boot_info *info)
64{
65 int n;
66 smpboot[ARRAY_SIZE(smpboot) - 1] = info->smp_bootreg_addr;
Peter Maydell96eacf62012-02-16 09:56:09 +000067 smpboot[ARRAY_SIZE(smpboot) - 2] = info->gic_cpu_if_addr;
Mark Langsdorf9d5ba9b2012-01-26 11:43:48 +000068 for (n = 0; n < ARRAY_SIZE(smpboot); n++) {
69 smpboot[n] = tswap32(smpboot[n]);
70 }
71 rom_add_blob_fixed("smpboot", smpboot, sizeof(smpboot),
72 info->smp_loader_start);
73}
74
Andreas Färber5d309322012-05-14 01:05:40 +020075static void default_reset_secondary(ARMCPU *cpu,
Mark Langsdorf9d5ba9b2012-01-26 11:43:48 +000076 const struct arm_boot_info *info)
77{
Andreas Färber5d309322012-05-14 01:05:40 +020078 CPUARMState *env = &cpu->env;
79
Mark Langsdorf9d5ba9b2012-01-26 11:43:48 +000080 stl_phys_notdirty(info->smp_bootreg_addr, 0);
81 env->regs[15] = info->smp_loader_start;
82}
83
pbrook52b43732009-04-09 17:19:47 +000084#define WRITE_WORD(p, value) do { \
85 stl_phys_notdirty(p, value); \
86 p += 4; \
87} while (0)
pbrook16406952006-04-27 23:15:07 +000088
Stefan Weil761c9eb2012-01-29 08:52:15 +010089static void set_kernel_args(const struct arm_boot_info *info)
pbrook52b43732009-04-09 17:19:47 +000090{
Stefan Weil761c9eb2012-01-29 08:52:15 +010091 int initrd_size = info->initrd_size;
92 target_phys_addr_t base = info->loader_start;
Anthony Liguoric227f092009-10-01 16:12:16 -050093 target_phys_addr_t p;
pbrook52b43732009-04-09 17:19:47 +000094
95 p = base + KERNEL_ARGS_ADDR;
pbrook16406952006-04-27 23:15:07 +000096 /* ATAG_CORE */
pbrook52b43732009-04-09 17:19:47 +000097 WRITE_WORD(p, 5);
98 WRITE_WORD(p, 0x54410001);
99 WRITE_WORD(p, 1);
100 WRITE_WORD(p, 0x1000);
101 WRITE_WORD(p, 0);
pbrook16406952006-04-27 23:15:07 +0000102 /* ATAG_MEM */
balrogf93eb9f2008-04-14 20:27:51 +0000103 /* TODO: handle multiple chips on one ATAG list */
pbrook52b43732009-04-09 17:19:47 +0000104 WRITE_WORD(p, 4);
105 WRITE_WORD(p, 0x54410002);
106 WRITE_WORD(p, info->ram_size);
107 WRITE_WORD(p, info->loader_start);
pbrook16406952006-04-27 23:15:07 +0000108 if (initrd_size) {
109 /* ATAG_INITRD2 */
pbrook52b43732009-04-09 17:19:47 +0000110 WRITE_WORD(p, 4);
111 WRITE_WORD(p, 0x54420005);
112 WRITE_WORD(p, info->loader_start + INITRD_LOAD_ADDR);
113 WRITE_WORD(p, initrd_size);
pbrook16406952006-04-27 23:15:07 +0000114 }
balrogf93eb9f2008-04-14 20:27:51 +0000115 if (info->kernel_cmdline && *info->kernel_cmdline) {
pbrook16406952006-04-27 23:15:07 +0000116 /* ATAG_CMDLINE */
117 int cmdline_size;
118
balrogf93eb9f2008-04-14 20:27:51 +0000119 cmdline_size = strlen(info->kernel_cmdline);
pbrook52b43732009-04-09 17:19:47 +0000120 cpu_physical_memory_write(p + 8, (void *)info->kernel_cmdline,
121 cmdline_size + 1);
pbrook16406952006-04-27 23:15:07 +0000122 cmdline_size = (cmdline_size >> 2) + 1;
pbrook52b43732009-04-09 17:19:47 +0000123 WRITE_WORD(p, cmdline_size + 2);
124 WRITE_WORD(p, 0x54410009);
125 p += cmdline_size * 4;
pbrook16406952006-04-27 23:15:07 +0000126 }
balrogf93eb9f2008-04-14 20:27:51 +0000127 if (info->atag_board) {
128 /* ATAG_BOARD */
129 int atag_board_len;
pbrook52b43732009-04-09 17:19:47 +0000130 uint8_t atag_board_buf[0x1000];
balrogf93eb9f2008-04-14 20:27:51 +0000131
pbrook52b43732009-04-09 17:19:47 +0000132 atag_board_len = (info->atag_board(info, atag_board_buf) + 3) & ~3;
133 WRITE_WORD(p, (atag_board_len + 8) >> 2);
134 WRITE_WORD(p, 0x414f4d50);
135 cpu_physical_memory_write(p, atag_board_buf, atag_board_len);
balrogf93eb9f2008-04-14 20:27:51 +0000136 p += atag_board_len;
137 }
pbrook16406952006-04-27 23:15:07 +0000138 /* ATAG_END */
pbrook52b43732009-04-09 17:19:47 +0000139 WRITE_WORD(p, 0);
140 WRITE_WORD(p, 0);
pbrook16406952006-04-27 23:15:07 +0000141}
142
Stefan Weil761c9eb2012-01-29 08:52:15 +0100143static void set_kernel_args_old(const struct arm_boot_info *info)
balrog2b8f2d42007-07-27 22:08:46 +0000144{
Anthony Liguoric227f092009-10-01 16:12:16 -0500145 target_phys_addr_t p;
pbrook52b43732009-04-09 17:19:47 +0000146 const char *s;
Stefan Weil761c9eb2012-01-29 08:52:15 +0100147 int initrd_size = info->initrd_size;
148 target_phys_addr_t base = info->loader_start;
balrog2b8f2d42007-07-27 22:08:46 +0000149
150 /* see linux/include/asm-arm/setup.h */
pbrook52b43732009-04-09 17:19:47 +0000151 p = base + KERNEL_ARGS_ADDR;
balrog2b8f2d42007-07-27 22:08:46 +0000152 /* page_size */
pbrook52b43732009-04-09 17:19:47 +0000153 WRITE_WORD(p, 4096);
balrog2b8f2d42007-07-27 22:08:46 +0000154 /* nr_pages */
pbrook52b43732009-04-09 17:19:47 +0000155 WRITE_WORD(p, info->ram_size / 4096);
balrog2b8f2d42007-07-27 22:08:46 +0000156 /* ramdisk_size */
pbrook52b43732009-04-09 17:19:47 +0000157 WRITE_WORD(p, 0);
balrog2b8f2d42007-07-27 22:08:46 +0000158#define FLAG_READONLY 1
159#define FLAG_RDLOAD 4
160#define FLAG_RDPROMPT 8
161 /* flags */
pbrook52b43732009-04-09 17:19:47 +0000162 WRITE_WORD(p, FLAG_READONLY | FLAG_RDLOAD | FLAG_RDPROMPT);
balrog2b8f2d42007-07-27 22:08:46 +0000163 /* rootdev */
pbrook52b43732009-04-09 17:19:47 +0000164 WRITE_WORD(p, (31 << 8) | 0); /* /dev/mtdblock0 */
balrog2b8f2d42007-07-27 22:08:46 +0000165 /* video_num_cols */
pbrook52b43732009-04-09 17:19:47 +0000166 WRITE_WORD(p, 0);
balrog2b8f2d42007-07-27 22:08:46 +0000167 /* video_num_rows */
pbrook52b43732009-04-09 17:19:47 +0000168 WRITE_WORD(p, 0);
balrog2b8f2d42007-07-27 22:08:46 +0000169 /* video_x */
pbrook52b43732009-04-09 17:19:47 +0000170 WRITE_WORD(p, 0);
balrog2b8f2d42007-07-27 22:08:46 +0000171 /* video_y */
pbrook52b43732009-04-09 17:19:47 +0000172 WRITE_WORD(p, 0);
balrog2b8f2d42007-07-27 22:08:46 +0000173 /* memc_control_reg */
pbrook52b43732009-04-09 17:19:47 +0000174 WRITE_WORD(p, 0);
balrog2b8f2d42007-07-27 22:08:46 +0000175 /* unsigned char sounddefault */
176 /* unsigned char adfsdrives */
177 /* unsigned char bytes_per_char_h */
178 /* unsigned char bytes_per_char_v */
pbrook52b43732009-04-09 17:19:47 +0000179 WRITE_WORD(p, 0);
balrog2b8f2d42007-07-27 22:08:46 +0000180 /* pages_in_bank[4] */
pbrook52b43732009-04-09 17:19:47 +0000181 WRITE_WORD(p, 0);
182 WRITE_WORD(p, 0);
183 WRITE_WORD(p, 0);
184 WRITE_WORD(p, 0);
balrog2b8f2d42007-07-27 22:08:46 +0000185 /* pages_in_vram */
pbrook52b43732009-04-09 17:19:47 +0000186 WRITE_WORD(p, 0);
balrog2b8f2d42007-07-27 22:08:46 +0000187 /* initrd_start */
188 if (initrd_size)
pbrook52b43732009-04-09 17:19:47 +0000189 WRITE_WORD(p, info->loader_start + INITRD_LOAD_ADDR);
balrog2b8f2d42007-07-27 22:08:46 +0000190 else
pbrook52b43732009-04-09 17:19:47 +0000191 WRITE_WORD(p, 0);
balrog2b8f2d42007-07-27 22:08:46 +0000192 /* initrd_size */
pbrook52b43732009-04-09 17:19:47 +0000193 WRITE_WORD(p, initrd_size);
balrog2b8f2d42007-07-27 22:08:46 +0000194 /* rd_start */
pbrook52b43732009-04-09 17:19:47 +0000195 WRITE_WORD(p, 0);
balrog2b8f2d42007-07-27 22:08:46 +0000196 /* system_rev */
pbrook52b43732009-04-09 17:19:47 +0000197 WRITE_WORD(p, 0);
balrog2b8f2d42007-07-27 22:08:46 +0000198 /* system_serial_low */
pbrook52b43732009-04-09 17:19:47 +0000199 WRITE_WORD(p, 0);
balrog2b8f2d42007-07-27 22:08:46 +0000200 /* system_serial_high */
pbrook52b43732009-04-09 17:19:47 +0000201 WRITE_WORD(p, 0);
balrog2b8f2d42007-07-27 22:08:46 +0000202 /* mem_fclk_21285 */
pbrook52b43732009-04-09 17:19:47 +0000203 WRITE_WORD(p, 0);
balrog2b8f2d42007-07-27 22:08:46 +0000204 /* zero unused fields */
pbrook52b43732009-04-09 17:19:47 +0000205 while (p < base + KERNEL_ARGS_ADDR + 256 + 1024) {
206 WRITE_WORD(p, 0);
207 }
208 s = info->kernel_cmdline;
209 if (s) {
210 cpu_physical_memory_write(p, (void *)s, strlen(s) + 1);
211 } else {
212 WRITE_WORD(p, 0);
213 }
balrog2b8f2d42007-07-27 22:08:46 +0000214}
215
Grant Likely412beee2012-03-02 11:56:38 +0000216static int load_dtb(target_phys_addr_t addr, const struct arm_boot_info *binfo)
217{
218#ifdef CONFIG_FDT
Peter Maydell9bfa6592012-07-20 13:34:50 +0100219 uint32_t *mem_reg_property;
220 uint32_t mem_reg_propsize;
Grant Likely412beee2012-03-02 11:56:38 +0000221 void *fdt = NULL;
222 char *filename;
223 int size, rc;
Peter Maydell9bfa6592012-07-20 13:34:50 +0100224 uint32_t acells, scells, hival;
Grant Likely412beee2012-03-02 11:56:38 +0000225
226 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, binfo->dtb_filename);
227 if (!filename) {
228 fprintf(stderr, "Couldn't open dtb file %s\n", binfo->dtb_filename);
229 return -1;
230 }
231
232 fdt = load_device_tree(filename, &size);
233 if (!fdt) {
234 fprintf(stderr, "Couldn't open dtb file %s\n", filename);
235 g_free(filename);
236 return -1;
237 }
238 g_free(filename);
239
Peter Maydell9bfa6592012-07-20 13:34:50 +0100240 acells = qemu_devtree_getprop_cell(fdt, "/", "#address-cells");
241 scells = qemu_devtree_getprop_cell(fdt, "/", "#size-cells");
242 if (acells == 0 || scells == 0) {
243 fprintf(stderr, "dtb file invalid (#address-cells or #size-cells 0)\n");
244 return -1;
245 }
246
247 mem_reg_propsize = acells + scells;
248 mem_reg_property = g_new0(uint32_t, mem_reg_propsize);
249 mem_reg_property[acells - 1] = cpu_to_be32(binfo->loader_start);
250 hival = cpu_to_be32(binfo->loader_start >> 32);
251 if (acells > 1) {
252 mem_reg_property[acells - 2] = hival;
253 } else if (hival != 0) {
254 fprintf(stderr, "qemu: dtb file not compatible with "
255 "RAM start address > 4GB\n");
256 exit(1);
257 }
258 mem_reg_property[acells + scells - 1] = cpu_to_be32(binfo->ram_size);
259 hival = cpu_to_be32(binfo->ram_size >> 32);
260 if (scells > 1) {
261 mem_reg_property[acells + scells - 2] = hival;
262 } else if (hival != 0) {
263 fprintf(stderr, "qemu: dtb file not compatible with "
264 "RAM size > 4GB\n");
265 exit(1);
266 }
267
Grant Likely412beee2012-03-02 11:56:38 +0000268 rc = qemu_devtree_setprop(fdt, "/memory", "reg", mem_reg_property,
Peter Maydell9bfa6592012-07-20 13:34:50 +0100269 mem_reg_propsize * sizeof(uint32_t));
Grant Likely412beee2012-03-02 11:56:38 +0000270 if (rc < 0) {
271 fprintf(stderr, "couldn't set /memory/reg\n");
272 }
273
Peter A. G. Crosthwaite5e879752012-06-17 15:35:36 +0000274 if (binfo->kernel_cmdline && *binfo->kernel_cmdline) {
275 rc = qemu_devtree_setprop_string(fdt, "/chosen", "bootargs",
276 binfo->kernel_cmdline);
277 if (rc < 0) {
278 fprintf(stderr, "couldn't set /chosen/bootargs\n");
279 }
Grant Likely412beee2012-03-02 11:56:38 +0000280 }
281
282 if (binfo->initrd_size) {
283 rc = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-start",
284 binfo->loader_start + INITRD_LOAD_ADDR);
285 if (rc < 0) {
286 fprintf(stderr, "couldn't set /chosen/linux,initrd-start\n");
287 }
288
289 rc = qemu_devtree_setprop_cell(fdt, "/chosen", "linux,initrd-end",
290 binfo->loader_start + INITRD_LOAD_ADDR +
291 binfo->initrd_size);
292 if (rc < 0) {
293 fprintf(stderr, "couldn't set /chosen/linux,initrd-end\n");
294 }
295 }
296
297 cpu_physical_memory_write(addr, fdt, size);
298
299 return 0;
300
301#else
302 fprintf(stderr, "Device tree requested, "
303 "but qemu was compiled without fdt support\n");
304 return -1;
305#endif
306}
307
Adam Lackorzynski6ed221b2011-03-05 13:51:45 +0100308static void do_cpu_reset(void *opaque)
Paul Brookf2d74972009-11-11 18:07:53 +0000309{
Andreas Färber351d5662012-05-05 12:40:39 +0200310 ARMCPU *cpu = opaque;
311 CPUARMState *env = &cpu->env;
Stefan Weil462a8bc2011-06-23 17:53:48 +0200312 const struct arm_boot_info *info = env->boot_info;
Paul Brookf2d74972009-11-11 18:07:53 +0000313
Andreas Färber351d5662012-05-05 12:40:39 +0200314 cpu_reset(CPU(cpu));
Paul Brookf2d74972009-11-11 18:07:53 +0000315 if (info) {
316 if (!info->is_linux) {
317 /* Jump to the entry point. */
318 env->regs[15] = info->entry & 0xfffffffe;
319 env->thumb = info->entry & 1;
320 } else {
Adam Lackorzynski6ed221b2011-03-05 13:51:45 +0100321 if (env == first_cpu) {
322 env->regs[15] = info->loader_start;
Grant Likely412beee2012-03-02 11:56:38 +0000323 if (!info->dtb_filename) {
324 if (old_param) {
325 set_kernel_args_old(info);
326 } else {
327 set_kernel_args(info);
328 }
Adam Lackorzynski6ed221b2011-03-05 13:51:45 +0100329 }
Paul Brookf2d74972009-11-11 18:07:53 +0000330 } else {
Andreas Färber5d309322012-05-14 01:05:40 +0200331 info->secondary_cpu_reset_hook(cpu, info);
Paul Brookf2d74972009-11-11 18:07:53 +0000332 }
333 }
334 }
Paul Brookf2d74972009-11-11 18:07:53 +0000335}
336
Andreas Färber3aaa8df2012-05-14 02:39:57 +0200337void arm_load_kernel(ARMCPU *cpu, struct arm_boot_info *info)
pbrook16406952006-04-27 23:15:07 +0000338{
Andreas Färber3aaa8df2012-05-14 02:39:57 +0200339 CPUARMState *env = &cpu->env;
pbrook16406952006-04-27 23:15:07 +0000340 int kernel_size;
341 int initrd_size;
342 int n;
pbrook1c7b3752007-03-06 23:52:01 +0000343 int is_linux = 0;
344 uint64_t elf_entry;
Anthony Liguoric227f092009-10-01 16:12:16 -0500345 target_phys_addr_t entry;
Blue Swirlca20cf32009-09-20 14:58:02 +0000346 int big_endian;
Grant Likely412beee2012-03-02 11:56:38 +0000347 QemuOpts *machine_opts;
pbrook16406952006-04-27 23:15:07 +0000348
349 /* Load the kernel. */
balrogf93eb9f2008-04-14 20:27:51 +0000350 if (!info->kernel_filename) {
pbrook16406952006-04-27 23:15:07 +0000351 fprintf(stderr, "Kernel image must be specified\n");
352 exit(1);
353 }
pbrookdaf90622007-01-16 18:54:31 +0000354
Grant Likely412beee2012-03-02 11:56:38 +0000355 machine_opts = qemu_opts_find(qemu_find_opts("machine"), 0);
356 if (machine_opts) {
357 info->dtb_filename = qemu_opt_get(machine_opts, "dtb");
358 } else {
359 info->dtb_filename = NULL;
360 }
361
Mark Langsdorf9d5ba9b2012-01-26 11:43:48 +0000362 if (!info->secondary_cpu_reset_hook) {
363 info->secondary_cpu_reset_hook = default_reset_secondary;
364 }
365 if (!info->write_secondary_boot) {
366 info->write_secondary_boot = default_write_secondary;
367 }
368
Paul Brookf2d74972009-11-11 18:07:53 +0000369 if (info->nb_cpus == 0)
370 info->nb_cpus = 1;
balrogf93eb9f2008-04-14 20:27:51 +0000371
Blue Swirlca20cf32009-09-20 14:58:02 +0000372#ifdef TARGET_WORDS_BIGENDIAN
373 big_endian = 1;
374#else
375 big_endian = 0;
376#endif
377
pbrook1c7b3752007-03-06 23:52:01 +0000378 /* Assume that raw images are linux kernels, and ELF images are not. */
Aurelien Jarno409dbce2010-03-14 21:20:59 +0100379 kernel_size = load_elf(info->kernel_filename, NULL, NULL, &elf_entry,
380 NULL, NULL, big_endian, ELF_MACHINE, 1);
pbrook1c7b3752007-03-06 23:52:01 +0000381 entry = elf_entry;
382 if (kernel_size < 0) {
aliguori5a9154e2008-11-20 22:14:40 +0000383 kernel_size = load_uimage(info->kernel_filename, &entry, NULL,
384 &is_linux);
pbrook1c7b3752007-03-06 23:52:01 +0000385 }
386 if (kernel_size < 0) {
balrogf93eb9f2008-04-14 20:27:51 +0000387 entry = info->loader_start + KERNEL_LOAD_ADDR;
pbrook3b760e02009-04-09 17:30:32 +0000388 kernel_size = load_image_targphys(info->kernel_filename, entry,
Peter Maydell0b944382012-07-20 13:34:50 +0100389 info->ram_size - KERNEL_LOAD_ADDR);
pbrook1c7b3752007-03-06 23:52:01 +0000390 is_linux = 1;
391 }
392 if (kernel_size < 0) {
balrogf93eb9f2008-04-14 20:27:51 +0000393 fprintf(stderr, "qemu: could not load kernel '%s'\n",
394 info->kernel_filename);
pbrook1c7b3752007-03-06 23:52:01 +0000395 exit(1);
396 }
Paul Brookf2d74972009-11-11 18:07:53 +0000397 info->entry = entry;
398 if (is_linux) {
balrogf93eb9f2008-04-14 20:27:51 +0000399 if (info->initrd_filename) {
pbrook3b760e02009-04-09 17:30:32 +0000400 initrd_size = load_image_targphys(info->initrd_filename,
401 info->loader_start
402 + INITRD_LOAD_ADDR,
Peter Maydell0b944382012-07-20 13:34:50 +0100403 info->ram_size
404 - INITRD_LOAD_ADDR);
pbrookdaf90622007-01-16 18:54:31 +0000405 if (initrd_size < 0) {
406 fprintf(stderr, "qemu: could not load initrd '%s'\n",
balrogf93eb9f2008-04-14 20:27:51 +0000407 info->initrd_filename);
pbrookdaf90622007-01-16 18:54:31 +0000408 exit(1);
409 }
410 } else {
411 initrd_size = 0;
412 }
Grant Likely412beee2012-03-02 11:56:38 +0000413 info->initrd_size = initrd_size;
414
Peter Maydellf8414cb2012-01-26 11:43:48 +0000415 bootloader[4] = info->board_id;
Grant Likely412beee2012-03-02 11:56:38 +0000416
417 /* for device tree boot, we pass the DTB directly in r2. Otherwise
418 * we point to the kernel args.
419 */
420 if (info->dtb_filename) {
421 /* Place the DTB after the initrd in memory */
422 target_phys_addr_t dtb_start = TARGET_PAGE_ALIGN(info->loader_start
423 + INITRD_LOAD_ADDR
424 + initrd_size);
425 if (load_dtb(dtb_start, info)) {
426 exit(1);
427 }
428 bootloader[5] = dtb_start;
429 } else {
430 bootloader[5] = info->loader_start + KERNEL_ARGS_ADDR;
Peter Maydell38714812012-07-20 13:34:50 +0100431 if (info->ram_size >= (1ULL << 32)) {
432 fprintf(stderr, "qemu: RAM size must be less than 4GB to boot"
433 " Linux kernel using ATAGS (try passing a device tree"
434 " using -dtb)\n");
435 exit(1);
436 }
Grant Likely412beee2012-03-02 11:56:38 +0000437 }
pbrook1c7b3752007-03-06 23:52:01 +0000438 bootloader[6] = entry;
pbrook52b43732009-04-09 17:19:47 +0000439 for (n = 0; n < sizeof(bootloader) / 4; n++) {
Paul Brookf2d74972009-11-11 18:07:53 +0000440 bootloader[n] = tswap32(bootloader[n]);
pbrook52b43732009-04-09 17:19:47 +0000441 }
Paul Brookf2d74972009-11-11 18:07:53 +0000442 rom_add_blob_fixed("bootloader", bootloader, sizeof(bootloader),
443 info->loader_start);
pbrook52b43732009-04-09 17:19:47 +0000444 if (info->nb_cpus > 1) {
Andreas Färber9543b0c2012-05-14 00:08:10 +0200445 info->write_secondary_boot(cpu, info);
pbrook52b43732009-04-09 17:19:47 +0000446 }
pbrook16406952006-04-27 23:15:07 +0000447 }
Paul Brookf2d74972009-11-11 18:07:53 +0000448 info->is_linux = is_linux;
Adam Lackorzynski6ed221b2011-03-05 13:51:45 +0100449
450 for (; env; env = env->next_cpu) {
Andreas Färber351d5662012-05-05 12:40:39 +0200451 cpu = arm_env_get_cpu(env);
Adam Lackorzynski6ed221b2011-03-05 13:51:45 +0100452 env->boot_info = info;
Andreas Färber351d5662012-05-05 12:40:39 +0200453 qemu_register_reset(do_cpu_reset, cpu);
Adam Lackorzynski6ed221b2011-03-05 13:51:45 +0100454 }
pbrook16406952006-04-27 23:15:07 +0000455}