]> git.proxmox.com Git - qemu.git/blob - hw/arm_boot.c
ARM boot fix (Jason Wessel).
[qemu.git] / hw / arm_boot.c
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(CPUState *env, 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 uint64_t entry;
75
76 /* Load the kernel. */
77 if (!kernel_filename) {
78 fprintf(stderr, "Kernel image must be specified\n");
79 exit(1);
80 }
81
82 kernel_size = load_elf(kernel_filename, 0, &entry);
83 if (kernel_size >= 0) {
84 /* An ELF image. Jump to the entry point. */
85 env->regs[15] = entry & 0xfffffffe;
86 env->thumb = entry & 1;
87 } else {
88 /* Raw binary image. Assume it is a Linux zImage. */
89 kernel_size = load_image(kernel_filename,
90 phys_ram_base + KERNEL_LOAD_ADDR);
91 if (kernel_size < 0) {
92 fprintf(stderr, "qemu: could not load kernel '%s'\n", kernel_filename);
93 exit(1);
94 }
95 if (initrd_filename) {
96 initrd_size = load_image(initrd_filename,
97 phys_ram_base + INITRD_LOAD_ADDR);
98 if (initrd_size < 0) {
99 fprintf(stderr, "qemu: could not load initrd '%s'\n",
100 initrd_filename);
101 exit(1);
102 }
103 } else {
104 initrd_size = 0;
105 }
106 bootloader[1] |= board_id & 0xff;
107 bootloader[2] |= (board_id >> 8) & 0xff;
108 bootloader[5] = KERNEL_ARGS_ADDR;
109 bootloader[6] = KERNEL_LOAD_ADDR;
110 for (n = 0; n < sizeof(bootloader) / 4; n++)
111 stl_raw(phys_ram_base + (n * 4), bootloader[n]);
112 set_kernel_args(ram_size, initrd_size, kernel_cmdline);
113 }
114 }
115