root / hw / lm32_boards.c @ d821732a
History | View | Annotate | Download (10 kB)
1 | d821732a | Michael Walle | /*
|
---|---|---|---|
2 | d821732a | Michael Walle | * QEMU models for LatticeMico32 uclinux and evr32 boards.
|
3 | d821732a | Michael Walle | *
|
4 | d821732a | Michael Walle | * Copyright (c) 2010 Michael Walle <michael@walle.cc>
|
5 | d821732a | Michael Walle | *
|
6 | d821732a | Michael Walle | * This library is free software; you can redistribute it and/or
|
7 | d821732a | Michael Walle | * modify it under the terms of the GNU Lesser General Public
|
8 | d821732a | Michael Walle | * License as published by the Free Software Foundation; either
|
9 | d821732a | Michael Walle | * version 2 of the License, or (at your option) any later version.
|
10 | d821732a | Michael Walle | *
|
11 | d821732a | Michael Walle | * This library is distributed in the hope that it will be useful,
|
12 | d821732a | Michael Walle | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 | d821732a | Michael Walle | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14 | d821732a | Michael Walle | * Lesser General Public License for more details.
|
15 | d821732a | Michael Walle | *
|
16 | d821732a | Michael Walle | * You should have received a copy of the GNU Lesser General Public
|
17 | d821732a | Michael Walle | * License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
18 | d821732a | Michael Walle | */
|
19 | d821732a | Michael Walle | |
20 | d821732a | Michael Walle | #include "sysbus.h" |
21 | d821732a | Michael Walle | #include "hw.h" |
22 | d821732a | Michael Walle | #include "net.h" |
23 | d821732a | Michael Walle | #include "flash.h" |
24 | d821732a | Michael Walle | #include "sysemu.h" |
25 | d821732a | Michael Walle | #include "devices.h" |
26 | d821732a | Michael Walle | #include "boards.h" |
27 | d821732a | Michael Walle | #include "loader.h" |
28 | d821732a | Michael Walle | #include "blockdev.h" |
29 | d821732a | Michael Walle | #include "elf.h" |
30 | d821732a | Michael Walle | #include "lm32_hwsetup.h" |
31 | d821732a | Michael Walle | #include "lm32.h" |
32 | d821732a | Michael Walle | |
33 | d821732a | Michael Walle | typedef struct { |
34 | d821732a | Michael Walle | CPUState *env; |
35 | d821732a | Michael Walle | target_phys_addr_t bootstrap_pc; |
36 | d821732a | Michael Walle | target_phys_addr_t flash_base; |
37 | d821732a | Michael Walle | target_phys_addr_t hwsetup_base; |
38 | d821732a | Michael Walle | target_phys_addr_t initrd_base; |
39 | d821732a | Michael Walle | size_t initrd_size; |
40 | d821732a | Michael Walle | target_phys_addr_t cmdline_base; |
41 | d821732a | Michael Walle | } ResetInfo; |
42 | d821732a | Michael Walle | |
43 | d821732a | Michael Walle | static void cpu_irq_handler(void *opaque, int irq, int level) |
44 | d821732a | Michael Walle | { |
45 | d821732a | Michael Walle | CPUState *env = opaque; |
46 | d821732a | Michael Walle | |
47 | d821732a | Michael Walle | if (level) {
|
48 | d821732a | Michael Walle | cpu_interrupt(env, CPU_INTERRUPT_HARD); |
49 | d821732a | Michael Walle | } else {
|
50 | d821732a | Michael Walle | cpu_reset_interrupt(env, CPU_INTERRUPT_HARD); |
51 | d821732a | Michael Walle | } |
52 | d821732a | Michael Walle | } |
53 | d821732a | Michael Walle | |
54 | d821732a | Michael Walle | static void main_cpu_reset(void *opaque) |
55 | d821732a | Michael Walle | { |
56 | d821732a | Michael Walle | ResetInfo *reset_info = opaque; |
57 | d821732a | Michael Walle | CPUState *env = reset_info->env; |
58 | d821732a | Michael Walle | |
59 | d821732a | Michael Walle | cpu_reset(env); |
60 | d821732a | Michael Walle | |
61 | d821732a | Michael Walle | /* init defaults */
|
62 | d821732a | Michael Walle | env->pc = (uint32_t)reset_info->bootstrap_pc; |
63 | d821732a | Michael Walle | env->regs[R_R1] = (uint32_t)reset_info->hwsetup_base; |
64 | d821732a | Michael Walle | env->regs[R_R2] = (uint32_t)reset_info->cmdline_base; |
65 | d821732a | Michael Walle | env->regs[R_R3] = (uint32_t)reset_info->initrd_base; |
66 | d821732a | Michael Walle | env->regs[R_R4] = (uint32_t)(reset_info->initrd_base + |
67 | d821732a | Michael Walle | reset_info->initrd_size); |
68 | d821732a | Michael Walle | env->eba = reset_info->flash_base; |
69 | d821732a | Michael Walle | env->deba = reset_info->flash_base; |
70 | d821732a | Michael Walle | } |
71 | d821732a | Michael Walle | |
72 | d821732a | Michael Walle | static void lm32_evr_init(ram_addr_t ram_size_not_used, |
73 | d821732a | Michael Walle | const char *boot_device, |
74 | d821732a | Michael Walle | const char *kernel_filename, |
75 | d821732a | Michael Walle | const char *kernel_cmdline, |
76 | d821732a | Michael Walle | const char *initrd_filename, const char *cpu_model) |
77 | d821732a | Michael Walle | { |
78 | d821732a | Michael Walle | CPUState *env; |
79 | d821732a | Michael Walle | DriveInfo *dinfo; |
80 | d821732a | Michael Walle | ram_addr_t phys_ram; |
81 | d821732a | Michael Walle | ram_addr_t phys_flash; |
82 | d821732a | Michael Walle | qemu_irq *cpu_irq, irq[32];
|
83 | d821732a | Michael Walle | ResetInfo *reset_info; |
84 | d821732a | Michael Walle | int i;
|
85 | d821732a | Michael Walle | |
86 | d821732a | Michael Walle | /* memory map */
|
87 | d821732a | Michael Walle | target_phys_addr_t flash_base = 0x04000000;
|
88 | d821732a | Michael Walle | size_t flash_sector_size = 256 * 1024; |
89 | d821732a | Michael Walle | size_t flash_size = 32 * 1024 * 1024; |
90 | d821732a | Michael Walle | target_phys_addr_t ram_base = 0x08000000;
|
91 | d821732a | Michael Walle | size_t ram_size = 64 * 1024 * 1024; |
92 | d821732a | Michael Walle | target_phys_addr_t timer0_base = 0x80002000;
|
93 | d821732a | Michael Walle | target_phys_addr_t uart0_base = 0x80006000;
|
94 | d821732a | Michael Walle | target_phys_addr_t timer1_base = 0x8000a000;
|
95 | d821732a | Michael Walle | int uart0_irq = 0; |
96 | d821732a | Michael Walle | int timer0_irq = 1; |
97 | d821732a | Michael Walle | int timer1_irq = 3; |
98 | d821732a | Michael Walle | |
99 | d821732a | Michael Walle | reset_info = qemu_mallocz(sizeof(ResetInfo));
|
100 | d821732a | Michael Walle | |
101 | d821732a | Michael Walle | if (cpu_model == NULL) { |
102 | d821732a | Michael Walle | cpu_model = "lm32-full";
|
103 | d821732a | Michael Walle | } |
104 | d821732a | Michael Walle | env = cpu_init(cpu_model); |
105 | d821732a | Michael Walle | reset_info->env = env; |
106 | d821732a | Michael Walle | |
107 | d821732a | Michael Walle | reset_info->flash_base = flash_base; |
108 | d821732a | Michael Walle | |
109 | d821732a | Michael Walle | phys_ram = qemu_ram_alloc(NULL, "lm32_evr.sdram", ram_size); |
110 | d821732a | Michael Walle | cpu_register_physical_memory(ram_base, ram_size, phys_ram | IO_MEM_RAM); |
111 | d821732a | Michael Walle | |
112 | d821732a | Michael Walle | phys_flash = qemu_ram_alloc(NULL, "lm32_evr.flash", flash_size); |
113 | d821732a | Michael Walle | dinfo = drive_get(IF_PFLASH, 0, 0); |
114 | d821732a | Michael Walle | /* Spansion S29NS128P */
|
115 | d821732a | Michael Walle | pflash_cfi02_register(flash_base, phys_flash, |
116 | d821732a | Michael Walle | dinfo ? dinfo->bdrv : NULL, flash_sector_size,
|
117 | d821732a | Michael Walle | flash_size / flash_sector_size, 1, 2, |
118 | d821732a | Michael Walle | 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1); |
119 | d821732a | Michael Walle | |
120 | d821732a | Michael Walle | /* create irq lines */
|
121 | d821732a | Michael Walle | cpu_irq = qemu_allocate_irqs(cpu_irq_handler, env, 1);
|
122 | d821732a | Michael Walle | env->pic_state = lm32_pic_init(*cpu_irq); |
123 | d821732a | Michael Walle | for (i = 0; i < 32; i++) { |
124 | d821732a | Michael Walle | irq[i] = qdev_get_gpio_in(env->pic_state, i); |
125 | d821732a | Michael Walle | } |
126 | d821732a | Michael Walle | |
127 | d821732a | Michael Walle | sysbus_create_simple("lm32-uart", uart0_base, irq[uart0_irq]);
|
128 | d821732a | Michael Walle | sysbus_create_simple("lm32-timer", timer0_base, irq[timer0_irq]);
|
129 | d821732a | Michael Walle | sysbus_create_simple("lm32-timer", timer1_base, irq[timer1_irq]);
|
130 | d821732a | Michael Walle | |
131 | d821732a | Michael Walle | /* make sure juart isn't the first chardev */
|
132 | d821732a | Michael Walle | env->juart_state = lm32_juart_init(); |
133 | d821732a | Michael Walle | |
134 | d821732a | Michael Walle | reset_info->bootstrap_pc = flash_base; |
135 | d821732a | Michael Walle | |
136 | d821732a | Michael Walle | if (kernel_filename) {
|
137 | d821732a | Michael Walle | uint64_t entry; |
138 | d821732a | Michael Walle | int kernel_size;
|
139 | d821732a | Michael Walle | |
140 | d821732a | Michael Walle | kernel_size = load_elf(kernel_filename, NULL, NULL, &entry, NULL, NULL, |
141 | d821732a | Michael Walle | 1, ELF_MACHINE, 0); |
142 | d821732a | Michael Walle | reset_info->bootstrap_pc = entry; |
143 | d821732a | Michael Walle | |
144 | d821732a | Michael Walle | if (kernel_size < 0) { |
145 | d821732a | Michael Walle | kernel_size = load_image_targphys(kernel_filename, ram_base, |
146 | d821732a | Michael Walle | ram_size); |
147 | d821732a | Michael Walle | reset_info->bootstrap_pc = ram_base; |
148 | d821732a | Michael Walle | } |
149 | d821732a | Michael Walle | |
150 | d821732a | Michael Walle | if (kernel_size < 0) { |
151 | d821732a | Michael Walle | fprintf(stderr, "qemu: could not load kernel '%s'\n",
|
152 | d821732a | Michael Walle | kernel_filename); |
153 | d821732a | Michael Walle | exit(1);
|
154 | d821732a | Michael Walle | } |
155 | d821732a | Michael Walle | } |
156 | d821732a | Michael Walle | |
157 | d821732a | Michael Walle | qemu_register_reset(main_cpu_reset, reset_info); |
158 | d821732a | Michael Walle | } |
159 | d821732a | Michael Walle | |
160 | d821732a | Michael Walle | static void lm32_uclinux_init(ram_addr_t ram_size_not_used, |
161 | d821732a | Michael Walle | const char *boot_device, |
162 | d821732a | Michael Walle | const char *kernel_filename, |
163 | d821732a | Michael Walle | const char *kernel_cmdline, |
164 | d821732a | Michael Walle | const char *initrd_filename, const char *cpu_model) |
165 | d821732a | Michael Walle | { |
166 | d821732a | Michael Walle | CPUState *env; |
167 | d821732a | Michael Walle | DriveInfo *dinfo; |
168 | d821732a | Michael Walle | ram_addr_t phys_ram; |
169 | d821732a | Michael Walle | ram_addr_t phys_flash; |
170 | d821732a | Michael Walle | qemu_irq *cpu_irq, irq[32];
|
171 | d821732a | Michael Walle | HWSetup *hw; |
172 | d821732a | Michael Walle | ResetInfo *reset_info; |
173 | d821732a | Michael Walle | int i;
|
174 | d821732a | Michael Walle | |
175 | d821732a | Michael Walle | /* memory map */
|
176 | d821732a | Michael Walle | target_phys_addr_t flash_base = 0x04000000;
|
177 | d821732a | Michael Walle | size_t flash_sector_size = 256 * 1024; |
178 | d821732a | Michael Walle | size_t flash_size = 32 * 1024 * 1024; |
179 | d821732a | Michael Walle | target_phys_addr_t ram_base = 0x08000000;
|
180 | d821732a | Michael Walle | size_t ram_size = 64 * 1024 * 1024; |
181 | d821732a | Michael Walle | target_phys_addr_t uart0_base = 0x80000000;
|
182 | d821732a | Michael Walle | target_phys_addr_t timer0_base = 0x80002000;
|
183 | d821732a | Michael Walle | target_phys_addr_t timer1_base = 0x80010000;
|
184 | d821732a | Michael Walle | target_phys_addr_t timer2_base = 0x80012000;
|
185 | d821732a | Michael Walle | int uart0_irq = 0; |
186 | d821732a | Michael Walle | int timer0_irq = 1; |
187 | d821732a | Michael Walle | int timer1_irq = 20; |
188 | d821732a | Michael Walle | int timer2_irq = 21; |
189 | d821732a | Michael Walle | target_phys_addr_t hwsetup_base = 0x0bffe000;
|
190 | d821732a | Michael Walle | target_phys_addr_t cmdline_base = 0x0bfff000;
|
191 | d821732a | Michael Walle | target_phys_addr_t initrd_base = 0x08400000;
|
192 | d821732a | Michael Walle | size_t initrd_max = 0x01000000;
|
193 | d821732a | Michael Walle | |
194 | d821732a | Michael Walle | reset_info = qemu_mallocz(sizeof(ResetInfo));
|
195 | d821732a | Michael Walle | |
196 | d821732a | Michael Walle | if (cpu_model == NULL) { |
197 | d821732a | Michael Walle | cpu_model = "lm32-full";
|
198 | d821732a | Michael Walle | } |
199 | d821732a | Michael Walle | env = cpu_init(cpu_model); |
200 | d821732a | Michael Walle | reset_info->env = env; |
201 | d821732a | Michael Walle | |
202 | d821732a | Michael Walle | reset_info->flash_base = flash_base; |
203 | d821732a | Michael Walle | |
204 | d821732a | Michael Walle | phys_ram = qemu_ram_alloc(NULL, "lm32_uclinux.sdram", ram_size); |
205 | d821732a | Michael Walle | cpu_register_physical_memory(ram_base, ram_size, phys_ram | IO_MEM_RAM); |
206 | d821732a | Michael Walle | |
207 | d821732a | Michael Walle | phys_flash = qemu_ram_alloc(NULL, "lm32_uclinux.flash", flash_size); |
208 | d821732a | Michael Walle | dinfo = drive_get(IF_PFLASH, 0, 0); |
209 | d821732a | Michael Walle | /* Spansion S29NS128P */
|
210 | d821732a | Michael Walle | pflash_cfi02_register(flash_base, phys_flash, |
211 | d821732a | Michael Walle | dinfo ? dinfo->bdrv : NULL, flash_sector_size,
|
212 | d821732a | Michael Walle | flash_size / flash_sector_size, 1, 2, |
213 | d821732a | Michael Walle | 0x01, 0x7e, 0x43, 0x00, 0x555, 0x2aa, 1); |
214 | d821732a | Michael Walle | |
215 | d821732a | Michael Walle | /* create irq lines */
|
216 | d821732a | Michael Walle | cpu_irq = qemu_allocate_irqs(cpu_irq_handler, env, 1);
|
217 | d821732a | Michael Walle | env->pic_state = lm32_pic_init(*cpu_irq); |
218 | d821732a | Michael Walle | for (i = 0; i < 32; i++) { |
219 | d821732a | Michael Walle | irq[i] = qdev_get_gpio_in(env->pic_state, i); |
220 | d821732a | Michael Walle | } |
221 | d821732a | Michael Walle | |
222 | d821732a | Michael Walle | sysbus_create_simple("lm32-uart", uart0_base, irq[uart0_irq]);
|
223 | d821732a | Michael Walle | sysbus_create_simple("lm32-timer", timer0_base, irq[timer0_irq]);
|
224 | d821732a | Michael Walle | sysbus_create_simple("lm32-timer", timer1_base, irq[timer1_irq]);
|
225 | d821732a | Michael Walle | sysbus_create_simple("lm32-timer", timer2_base, irq[timer2_irq]);
|
226 | d821732a | Michael Walle | |
227 | d821732a | Michael Walle | /* make sure juart isn't the first chardev */
|
228 | d821732a | Michael Walle | env->juart_state = lm32_juart_init(); |
229 | d821732a | Michael Walle | |
230 | d821732a | Michael Walle | reset_info->bootstrap_pc = flash_base; |
231 | d821732a | Michael Walle | |
232 | d821732a | Michael Walle | if (kernel_filename) {
|
233 | d821732a | Michael Walle | uint64_t entry; |
234 | d821732a | Michael Walle | int kernel_size;
|
235 | d821732a | Michael Walle | |
236 | d821732a | Michael Walle | kernel_size = load_elf(kernel_filename, NULL, NULL, &entry, NULL, NULL, |
237 | d821732a | Michael Walle | 1, ELF_MACHINE, 0); |
238 | d821732a | Michael Walle | reset_info->bootstrap_pc = entry; |
239 | d821732a | Michael Walle | |
240 | d821732a | Michael Walle | if (kernel_size < 0) { |
241 | d821732a | Michael Walle | kernel_size = load_image_targphys(kernel_filename, ram_base, |
242 | d821732a | Michael Walle | ram_size); |
243 | d821732a | Michael Walle | reset_info->bootstrap_pc = ram_base; |
244 | d821732a | Michael Walle | } |
245 | d821732a | Michael Walle | |
246 | d821732a | Michael Walle | if (kernel_size < 0) { |
247 | d821732a | Michael Walle | fprintf(stderr, "qemu: could not load kernel '%s'\n",
|
248 | d821732a | Michael Walle | kernel_filename); |
249 | d821732a | Michael Walle | exit(1);
|
250 | d821732a | Michael Walle | } |
251 | d821732a | Michael Walle | } |
252 | d821732a | Michael Walle | |
253 | d821732a | Michael Walle | /* generate a rom with the hardware description */
|
254 | d821732a | Michael Walle | hw = hwsetup_init(); |
255 | d821732a | Michael Walle | hwsetup_add_cpu(hw, "LM32", 75000000); |
256 | d821732a | Michael Walle | hwsetup_add_flash(hw, "flash", flash_base, flash_size);
|
257 | d821732a | Michael Walle | hwsetup_add_ddr_sdram(hw, "ddr_sdram", ram_base, ram_size);
|
258 | d821732a | Michael Walle | hwsetup_add_timer(hw, "timer0", timer0_base, timer0_irq);
|
259 | d821732a | Michael Walle | hwsetup_add_timer(hw, "timer1_dev_only", timer1_base, timer1_irq);
|
260 | d821732a | Michael Walle | hwsetup_add_timer(hw, "timer2_dev_only", timer2_base, timer2_irq);
|
261 | d821732a | Michael Walle | hwsetup_add_uart(hw, "uart", uart0_base, uart0_irq);
|
262 | d821732a | Michael Walle | hwsetup_add_trailer(hw); |
263 | d821732a | Michael Walle | hwsetup_create_rom(hw, hwsetup_base); |
264 | d821732a | Michael Walle | hwsetup_free(hw); |
265 | d821732a | Michael Walle | |
266 | d821732a | Michael Walle | reset_info->hwsetup_base = hwsetup_base; |
267 | d821732a | Michael Walle | |
268 | d821732a | Michael Walle | if (kernel_cmdline && strlen(kernel_cmdline)) {
|
269 | d821732a | Michael Walle | pstrcpy_targphys("cmdline", cmdline_base, TARGET_PAGE_SIZE,
|
270 | d821732a | Michael Walle | kernel_cmdline); |
271 | d821732a | Michael Walle | reset_info->cmdline_base = cmdline_base; |
272 | d821732a | Michael Walle | } |
273 | d821732a | Michael Walle | |
274 | d821732a | Michael Walle | if (initrd_filename) {
|
275 | d821732a | Michael Walle | size_t initrd_size; |
276 | d821732a | Michael Walle | initrd_size = load_image_targphys(initrd_filename, initrd_base, |
277 | d821732a | Michael Walle | initrd_max); |
278 | d821732a | Michael Walle | reset_info->initrd_base = initrd_base; |
279 | d821732a | Michael Walle | reset_info->initrd_size = initrd_size; |
280 | d821732a | Michael Walle | } |
281 | d821732a | Michael Walle | |
282 | d821732a | Michael Walle | qemu_register_reset(main_cpu_reset, reset_info); |
283 | d821732a | Michael Walle | } |
284 | d821732a | Michael Walle | |
285 | d821732a | Michael Walle | static QEMUMachine lm32_evr_machine = {
|
286 | d821732a | Michael Walle | .name = "lm32-evr",
|
287 | d821732a | Michael Walle | .desc = "LatticeMico32 EVR32 eval system",
|
288 | d821732a | Michael Walle | .init = lm32_evr_init, |
289 | d821732a | Michael Walle | .is_default = 1
|
290 | d821732a | Michael Walle | }; |
291 | d821732a | Michael Walle | |
292 | d821732a | Michael Walle | static QEMUMachine lm32_uclinux_machine = {
|
293 | d821732a | Michael Walle | .name = "lm32-uclinux",
|
294 | d821732a | Michael Walle | .desc = "lm32 platform for uClinux and u-boot by Theobroma Systems",
|
295 | d821732a | Michael Walle | .init = lm32_uclinux_init, |
296 | d821732a | Michael Walle | .is_default = 0
|
297 | d821732a | Michael Walle | }; |
298 | d821732a | Michael Walle | |
299 | d821732a | Michael Walle | static void lm32_machine_init(void) |
300 | d821732a | Michael Walle | { |
301 | d821732a | Michael Walle | qemu_register_machine(&lm32_uclinux_machine); |
302 | d821732a | Michael Walle | qemu_register_machine(&lm32_evr_machine); |
303 | d821732a | Michael Walle | } |
304 | d821732a | Michael Walle | |
305 | d821732a | Michael Walle | machine_init(lm32_machine_init); |