root / hw / ppc405_boards.c @ a0b753df
History | View | Annotate | Download (19.4 kB)
1 |
/*
|
---|---|
2 |
* QEMU PowerPC 405 evaluation boards emulation
|
3 |
*
|
4 |
* Copyright (c) 2007 Jocelyn Mayer
|
5 |
*
|
6 |
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 |
* of this software and associated documentation files (the "Software"), to deal
|
8 |
* in the Software without restriction, including without limitation the rights
|
9 |
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10 |
* copies of the Software, and to permit persons to whom the Software is
|
11 |
* furnished to do so, subject to the following conditions:
|
12 |
*
|
13 |
* The above copyright notice and this permission notice shall be included in
|
14 |
* all copies or substantial portions of the Software.
|
15 |
*
|
16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
19 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22 |
* THE SOFTWARE.
|
23 |
*/
|
24 |
#include "hw.h" |
25 |
#include "ppc.h" |
26 |
#include "ppc405.h" |
27 |
#include "nvram.h" |
28 |
#include "flash.h" |
29 |
#include "sysemu.h" |
30 |
#include "block.h" |
31 |
#include "boards.h" |
32 |
#include "qemu-log.h" |
33 |
|
34 |
#define BIOS_FILENAME "ppc405_rom.bin" |
35 |
#undef BIOS_SIZE
|
36 |
#define BIOS_SIZE (2048 * 1024) |
37 |
|
38 |
#define KERNEL_LOAD_ADDR 0x00000000 |
39 |
#define INITRD_LOAD_ADDR 0x01800000 |
40 |
|
41 |
#define USE_FLASH_BIOS
|
42 |
|
43 |
#define DEBUG_BOARD_INIT
|
44 |
|
45 |
/*****************************************************************************/
|
46 |
/* PPC405EP reference board (IBM) */
|
47 |
/* Standalone board with:
|
48 |
* - PowerPC 405EP CPU
|
49 |
* - SDRAM (0x00000000)
|
50 |
* - Flash (0xFFF80000)
|
51 |
* - SRAM (0xFFF00000)
|
52 |
* - NVRAM (0xF0000000)
|
53 |
* - FPGA (0xF0300000)
|
54 |
*/
|
55 |
typedef struct ref405ep_fpga_t ref405ep_fpga_t; |
56 |
struct ref405ep_fpga_t {
|
57 |
uint8_t reg0; |
58 |
uint8_t reg1; |
59 |
}; |
60 |
|
61 |
static uint32_t ref405ep_fpga_readb (void *opaque, target_phys_addr_t addr) |
62 |
{ |
63 |
ref405ep_fpga_t *fpga; |
64 |
uint32_t ret; |
65 |
|
66 |
fpga = opaque; |
67 |
switch (addr) {
|
68 |
case 0x0: |
69 |
ret = fpga->reg0; |
70 |
break;
|
71 |
case 0x1: |
72 |
ret = fpga->reg1; |
73 |
break;
|
74 |
default:
|
75 |
ret = 0;
|
76 |
break;
|
77 |
} |
78 |
|
79 |
return ret;
|
80 |
} |
81 |
|
82 |
static void ref405ep_fpga_writeb (void *opaque, |
83 |
target_phys_addr_t addr, uint32_t value) |
84 |
{ |
85 |
ref405ep_fpga_t *fpga; |
86 |
|
87 |
fpga = opaque; |
88 |
switch (addr) {
|
89 |
case 0x0: |
90 |
/* Read only */
|
91 |
break;
|
92 |
case 0x1: |
93 |
fpga->reg1 = value; |
94 |
break;
|
95 |
default:
|
96 |
break;
|
97 |
} |
98 |
} |
99 |
|
100 |
static uint32_t ref405ep_fpga_readw (void *opaque, target_phys_addr_t addr) |
101 |
{ |
102 |
uint32_t ret; |
103 |
|
104 |
ret = ref405ep_fpga_readb(opaque, addr) << 8;
|
105 |
ret |= ref405ep_fpga_readb(opaque, addr + 1);
|
106 |
|
107 |
return ret;
|
108 |
} |
109 |
|
110 |
static void ref405ep_fpga_writew (void *opaque, |
111 |
target_phys_addr_t addr, uint32_t value) |
112 |
{ |
113 |
ref405ep_fpga_writeb(opaque, addr, (value >> 8) & 0xFF); |
114 |
ref405ep_fpga_writeb(opaque, addr + 1, value & 0xFF); |
115 |
} |
116 |
|
117 |
static uint32_t ref405ep_fpga_readl (void *opaque, target_phys_addr_t addr) |
118 |
{ |
119 |
uint32_t ret; |
120 |
|
121 |
ret = ref405ep_fpga_readb(opaque, addr) << 24;
|
122 |
ret |= ref405ep_fpga_readb(opaque, addr + 1) << 16; |
123 |
ret |= ref405ep_fpga_readb(opaque, addr + 2) << 8; |
124 |
ret |= ref405ep_fpga_readb(opaque, addr + 3);
|
125 |
|
126 |
return ret;
|
127 |
} |
128 |
|
129 |
static void ref405ep_fpga_writel (void *opaque, |
130 |
target_phys_addr_t addr, uint32_t value) |
131 |
{ |
132 |
ref405ep_fpga_writeb(opaque, addr, (value >> 24) & 0xFF); |
133 |
ref405ep_fpga_writeb(opaque, addr + 1, (value >> 16) & 0xFF); |
134 |
ref405ep_fpga_writeb(opaque, addr + 2, (value >> 8) & 0xFF); |
135 |
ref405ep_fpga_writeb(opaque, addr + 3, value & 0xFF); |
136 |
} |
137 |
|
138 |
static CPUReadMemoryFunc *ref405ep_fpga_read[] = {
|
139 |
&ref405ep_fpga_readb, |
140 |
&ref405ep_fpga_readw, |
141 |
&ref405ep_fpga_readl, |
142 |
}; |
143 |
|
144 |
static CPUWriteMemoryFunc *ref405ep_fpga_write[] = {
|
145 |
&ref405ep_fpga_writeb, |
146 |
&ref405ep_fpga_writew, |
147 |
&ref405ep_fpga_writel, |
148 |
}; |
149 |
|
150 |
static void ref405ep_fpga_reset (void *opaque) |
151 |
{ |
152 |
ref405ep_fpga_t *fpga; |
153 |
|
154 |
fpga = opaque; |
155 |
fpga->reg0 = 0x00;
|
156 |
fpga->reg1 = 0x0F;
|
157 |
} |
158 |
|
159 |
static void ref405ep_fpga_init (uint32_t base) |
160 |
{ |
161 |
ref405ep_fpga_t *fpga; |
162 |
int fpga_memory;
|
163 |
|
164 |
fpga = qemu_mallocz(sizeof(ref405ep_fpga_t));
|
165 |
fpga_memory = cpu_register_io_memory(0, ref405ep_fpga_read,
|
166 |
ref405ep_fpga_write, fpga); |
167 |
cpu_register_physical_memory(base, 0x00000100, fpga_memory);
|
168 |
ref405ep_fpga_reset(fpga); |
169 |
qemu_register_reset(&ref405ep_fpga_reset, fpga); |
170 |
} |
171 |
|
172 |
static void ref405ep_init (ram_addr_t ram_size, int vga_ram_size, |
173 |
const char *boot_device, |
174 |
const char *kernel_filename, |
175 |
const char *kernel_cmdline, |
176 |
const char *initrd_filename, |
177 |
const char *cpu_model) |
178 |
{ |
179 |
char buf[1024]; |
180 |
ppc4xx_bd_info_t bd; |
181 |
CPUPPCState *env; |
182 |
qemu_irq *pic; |
183 |
ram_addr_t sram_offset, bios_offset, bdloc; |
184 |
target_phys_addr_t ram_bases[2], ram_sizes[2]; |
185 |
target_ulong sram_size, bios_size; |
186 |
//int phy_addr = 0;
|
187 |
//static int phy_addr = 1;
|
188 |
target_ulong kernel_base, kernel_size, initrd_base, initrd_size; |
189 |
int linux_boot;
|
190 |
int fl_idx, fl_sectors, len;
|
191 |
int ppc_boot_device = boot_device[0]; |
192 |
int index;
|
193 |
|
194 |
/* XXX: fix this */
|
195 |
ram_bases[0] = qemu_ram_alloc(0x08000000); |
196 |
ram_sizes[0] = 0x08000000; |
197 |
ram_bases[1] = 0x00000000; |
198 |
ram_sizes[1] = 0x00000000; |
199 |
ram_size = 128 * 1024 * 1024; |
200 |
#ifdef DEBUG_BOARD_INIT
|
201 |
printf("%s: register cpu\n", __func__);
|
202 |
#endif
|
203 |
env = ppc405ep_init(ram_bases, ram_sizes, 33333333, &pic,
|
204 |
kernel_filename == NULL ? 0 : 1); |
205 |
/* allocate SRAM */
|
206 |
sram_size = 512 * 1024; |
207 |
sram_offset = qemu_ram_alloc(sram_size); |
208 |
#ifdef DEBUG_BOARD_INIT
|
209 |
printf("%s: register SRAM at offset %08lx\n", __func__, sram_offset);
|
210 |
#endif
|
211 |
cpu_register_physical_memory(0xFFF00000, sram_size,
|
212 |
sram_offset | IO_MEM_RAM); |
213 |
/* allocate and load BIOS */
|
214 |
#ifdef DEBUG_BOARD_INIT
|
215 |
printf("%s: register BIOS\n", __func__);
|
216 |
#endif
|
217 |
fl_idx = 0;
|
218 |
#ifdef USE_FLASH_BIOS
|
219 |
index = drive_get_index(IF_PFLASH, 0, fl_idx);
|
220 |
if (index != -1) { |
221 |
bios_size = bdrv_getlength(drives_table[index].bdrv); |
222 |
bios_offset = qemu_ram_alloc(bios_size); |
223 |
fl_sectors = (bios_size + 65535) >> 16; |
224 |
#ifdef DEBUG_BOARD_INIT
|
225 |
printf("Register parallel flash %d size " ADDRX " at offset %08lx " |
226 |
" addr " ADDRX " '%s' %d\n", |
227 |
fl_idx, bios_size, bios_offset, -bios_size, |
228 |
bdrv_get_device_name(drives_table[index].bdrv), fl_sectors); |
229 |
#endif
|
230 |
pflash_cfi02_register((uint32_t)(-bios_size), bios_offset, |
231 |
drives_table[index].bdrv, 65536, fl_sectors, 1, |
232 |
2, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA); |
233 |
fl_idx++; |
234 |
} else
|
235 |
#endif
|
236 |
{ |
237 |
#ifdef DEBUG_BOARD_INIT
|
238 |
printf("Load BIOS from file\n");
|
239 |
#endif
|
240 |
if (bios_name == NULL) |
241 |
bios_name = BIOS_FILENAME; |
242 |
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); |
243 |
bios_offset = qemu_ram_alloc(BIOS_SIZE); |
244 |
bios_size = load_image(buf, qemu_get_ram_ptr(bios_offset)); |
245 |
if (bios_size < 0 || bios_size > BIOS_SIZE) { |
246 |
fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n", buf);
|
247 |
exit(1);
|
248 |
} |
249 |
bios_size = (bios_size + 0xfff) & ~0xfff; |
250 |
cpu_register_physical_memory((uint32_t)(-bios_size), |
251 |
bios_size, bios_offset | IO_MEM_ROM); |
252 |
} |
253 |
/* Register FPGA */
|
254 |
#ifdef DEBUG_BOARD_INIT
|
255 |
printf("%s: register FPGA\n", __func__);
|
256 |
#endif
|
257 |
ref405ep_fpga_init(0xF0300000);
|
258 |
/* Register NVRAM */
|
259 |
#ifdef DEBUG_BOARD_INIT
|
260 |
printf("%s: register NVRAM\n", __func__);
|
261 |
#endif
|
262 |
m48t59_init(NULL, 0xF0000000, 0, 8192, 8); |
263 |
/* Load kernel */
|
264 |
linux_boot = (kernel_filename != NULL);
|
265 |
if (linux_boot) {
|
266 |
#ifdef DEBUG_BOARD_INIT
|
267 |
printf("%s: load kernel\n", __func__);
|
268 |
#endif
|
269 |
memset(&bd, 0, sizeof(bd)); |
270 |
bd.bi_memstart = 0x00000000;
|
271 |
bd.bi_memsize = ram_size; |
272 |
bd.bi_flashstart = -bios_size; |
273 |
bd.bi_flashsize = -bios_size; |
274 |
bd.bi_flashoffset = 0;
|
275 |
bd.bi_sramstart = 0xFFF00000;
|
276 |
bd.bi_sramsize = sram_size; |
277 |
bd.bi_bootflags = 0;
|
278 |
bd.bi_intfreq = 133333333;
|
279 |
bd.bi_busfreq = 33333333;
|
280 |
bd.bi_baudrate = 115200;
|
281 |
bd.bi_s_version[0] = 'Q'; |
282 |
bd.bi_s_version[1] = 'M'; |
283 |
bd.bi_s_version[2] = 'U'; |
284 |
bd.bi_s_version[3] = '\0'; |
285 |
bd.bi_r_version[0] = 'Q'; |
286 |
bd.bi_r_version[1] = 'E'; |
287 |
bd.bi_r_version[2] = 'M'; |
288 |
bd.bi_r_version[3] = 'U'; |
289 |
bd.bi_r_version[4] = '\0'; |
290 |
bd.bi_procfreq = 133333333;
|
291 |
bd.bi_plb_busfreq = 33333333;
|
292 |
bd.bi_pci_busfreq = 33333333;
|
293 |
bd.bi_opbfreq = 33333333;
|
294 |
bdloc = ppc405_set_bootinfo(env, &bd, 0x00000001);
|
295 |
env->gpr[3] = bdloc;
|
296 |
kernel_base = KERNEL_LOAD_ADDR; |
297 |
/* now we can load the kernel */
|
298 |
kernel_size = load_image_targphys(kernel_filename, kernel_base, |
299 |
ram_size - kernel_base); |
300 |
if (kernel_size < 0) { |
301 |
fprintf(stderr, "qemu: could not load kernel '%s'\n",
|
302 |
kernel_filename); |
303 |
exit(1);
|
304 |
} |
305 |
printf("Load kernel size " TARGET_FMT_ld " at " TARGET_FMT_lx, |
306 |
kernel_size, kernel_base); |
307 |
/* load initrd */
|
308 |
if (initrd_filename) {
|
309 |
initrd_base = INITRD_LOAD_ADDR; |
310 |
initrd_size = load_image_targphys(initrd_filename, initrd_base, |
311 |
ram_size - initrd_base); |
312 |
if (initrd_size < 0) { |
313 |
fprintf(stderr, "qemu: could not load initial ram disk '%s'\n",
|
314 |
initrd_filename); |
315 |
exit(1);
|
316 |
} |
317 |
} else {
|
318 |
initrd_base = 0;
|
319 |
initrd_size = 0;
|
320 |
} |
321 |
env->gpr[4] = initrd_base;
|
322 |
env->gpr[5] = initrd_size;
|
323 |
ppc_boot_device = 'm';
|
324 |
if (kernel_cmdline != NULL) { |
325 |
len = strlen(kernel_cmdline); |
326 |
bdloc -= ((len + 255) & ~255); |
327 |
cpu_physical_memory_write(bdloc, (void *)kernel_cmdline, len + 1); |
328 |
env->gpr[6] = bdloc;
|
329 |
env->gpr[7] = bdloc + len;
|
330 |
} else {
|
331 |
env->gpr[6] = 0; |
332 |
env->gpr[7] = 0; |
333 |
} |
334 |
env->nip = KERNEL_LOAD_ADDR; |
335 |
} else {
|
336 |
kernel_base = 0;
|
337 |
kernel_size = 0;
|
338 |
initrd_base = 0;
|
339 |
initrd_size = 0;
|
340 |
bdloc = 0;
|
341 |
} |
342 |
#ifdef DEBUG_BOARD_INIT
|
343 |
printf("%s: Done\n", __func__);
|
344 |
#endif
|
345 |
printf("bdloc %016lx\n", (unsigned long)bdloc); |
346 |
} |
347 |
|
348 |
QEMUMachine ref405ep_machine = { |
349 |
.name = "ref405ep",
|
350 |
.desc = "ref405ep",
|
351 |
.init = ref405ep_init, |
352 |
.ram_require = (128 * 1024 * 1024 + 4096 + 512 * 1024 + BIOS_SIZE) | RAMSIZE_FIXED, |
353 |
}; |
354 |
|
355 |
/*****************************************************************************/
|
356 |
/* AMCC Taihu evaluation board */
|
357 |
/* - PowerPC 405EP processor
|
358 |
* - SDRAM 128 MB at 0x00000000
|
359 |
* - Boot flash 2 MB at 0xFFE00000
|
360 |
* - Application flash 32 MB at 0xFC000000
|
361 |
* - 2 serial ports
|
362 |
* - 2 ethernet PHY
|
363 |
* - 1 USB 1.1 device 0x50000000
|
364 |
* - 1 LCD display 0x50100000
|
365 |
* - 1 CPLD 0x50100000
|
366 |
* - 1 I2C EEPROM
|
367 |
* - 1 I2C thermal sensor
|
368 |
* - a set of LEDs
|
369 |
* - bit-bang SPI port using GPIOs
|
370 |
* - 1 EBC interface connector 0 0x50200000
|
371 |
* - 1 cardbus controller + expansion slot.
|
372 |
* - 1 PCI expansion slot.
|
373 |
*/
|
374 |
typedef struct taihu_cpld_t taihu_cpld_t; |
375 |
struct taihu_cpld_t {
|
376 |
uint8_t reg0; |
377 |
uint8_t reg1; |
378 |
}; |
379 |
|
380 |
static uint32_t taihu_cpld_readb (void *opaque, target_phys_addr_t addr) |
381 |
{ |
382 |
taihu_cpld_t *cpld; |
383 |
uint32_t ret; |
384 |
|
385 |
cpld = opaque; |
386 |
switch (addr) {
|
387 |
case 0x0: |
388 |
ret = cpld->reg0; |
389 |
break;
|
390 |
case 0x1: |
391 |
ret = cpld->reg1; |
392 |
break;
|
393 |
default:
|
394 |
ret = 0;
|
395 |
break;
|
396 |
} |
397 |
|
398 |
return ret;
|
399 |
} |
400 |
|
401 |
static void taihu_cpld_writeb (void *opaque, |
402 |
target_phys_addr_t addr, uint32_t value) |
403 |
{ |
404 |
taihu_cpld_t *cpld; |
405 |
|
406 |
cpld = opaque; |
407 |
switch (addr) {
|
408 |
case 0x0: |
409 |
/* Read only */
|
410 |
break;
|
411 |
case 0x1: |
412 |
cpld->reg1 = value; |
413 |
break;
|
414 |
default:
|
415 |
break;
|
416 |
} |
417 |
} |
418 |
|
419 |
static uint32_t taihu_cpld_readw (void *opaque, target_phys_addr_t addr) |
420 |
{ |
421 |
uint32_t ret; |
422 |
|
423 |
ret = taihu_cpld_readb(opaque, addr) << 8;
|
424 |
ret |= taihu_cpld_readb(opaque, addr + 1);
|
425 |
|
426 |
return ret;
|
427 |
} |
428 |
|
429 |
static void taihu_cpld_writew (void *opaque, |
430 |
target_phys_addr_t addr, uint32_t value) |
431 |
{ |
432 |
taihu_cpld_writeb(opaque, addr, (value >> 8) & 0xFF); |
433 |
taihu_cpld_writeb(opaque, addr + 1, value & 0xFF); |
434 |
} |
435 |
|
436 |
static uint32_t taihu_cpld_readl (void *opaque, target_phys_addr_t addr) |
437 |
{ |
438 |
uint32_t ret; |
439 |
|
440 |
ret = taihu_cpld_readb(opaque, addr) << 24;
|
441 |
ret |= taihu_cpld_readb(opaque, addr + 1) << 16; |
442 |
ret |= taihu_cpld_readb(opaque, addr + 2) << 8; |
443 |
ret |= taihu_cpld_readb(opaque, addr + 3);
|
444 |
|
445 |
return ret;
|
446 |
} |
447 |
|
448 |
static void taihu_cpld_writel (void *opaque, |
449 |
target_phys_addr_t addr, uint32_t value) |
450 |
{ |
451 |
taihu_cpld_writel(opaque, addr, (value >> 24) & 0xFF); |
452 |
taihu_cpld_writel(opaque, addr + 1, (value >> 16) & 0xFF); |
453 |
taihu_cpld_writel(opaque, addr + 2, (value >> 8) & 0xFF); |
454 |
taihu_cpld_writeb(opaque, addr + 3, value & 0xFF); |
455 |
} |
456 |
|
457 |
static CPUReadMemoryFunc *taihu_cpld_read[] = {
|
458 |
&taihu_cpld_readb, |
459 |
&taihu_cpld_readw, |
460 |
&taihu_cpld_readl, |
461 |
}; |
462 |
|
463 |
static CPUWriteMemoryFunc *taihu_cpld_write[] = {
|
464 |
&taihu_cpld_writeb, |
465 |
&taihu_cpld_writew, |
466 |
&taihu_cpld_writel, |
467 |
}; |
468 |
|
469 |
static void taihu_cpld_reset (void *opaque) |
470 |
{ |
471 |
taihu_cpld_t *cpld; |
472 |
|
473 |
cpld = opaque; |
474 |
cpld->reg0 = 0x01;
|
475 |
cpld->reg1 = 0x80;
|
476 |
} |
477 |
|
478 |
static void taihu_cpld_init (uint32_t base) |
479 |
{ |
480 |
taihu_cpld_t *cpld; |
481 |
int cpld_memory;
|
482 |
|
483 |
cpld = qemu_mallocz(sizeof(taihu_cpld_t));
|
484 |
cpld_memory = cpu_register_io_memory(0, taihu_cpld_read,
|
485 |
taihu_cpld_write, cpld); |
486 |
cpu_register_physical_memory(base, 0x00000100, cpld_memory);
|
487 |
taihu_cpld_reset(cpld); |
488 |
qemu_register_reset(&taihu_cpld_reset, cpld); |
489 |
} |
490 |
|
491 |
static void taihu_405ep_init(ram_addr_t ram_size, int vga_ram_size, |
492 |
const char *boot_device, |
493 |
const char *kernel_filename, |
494 |
const char *kernel_cmdline, |
495 |
const char *initrd_filename, |
496 |
const char *cpu_model) |
497 |
{ |
498 |
char buf[1024]; |
499 |
CPUPPCState *env; |
500 |
qemu_irq *pic; |
501 |
ram_addr_t bios_offset; |
502 |
target_phys_addr_t ram_bases[2], ram_sizes[2]; |
503 |
target_ulong bios_size; |
504 |
target_ulong kernel_base, kernel_size, initrd_base, initrd_size; |
505 |
int linux_boot;
|
506 |
int fl_idx, fl_sectors;
|
507 |
int ppc_boot_device = boot_device[0]; |
508 |
int index;
|
509 |
|
510 |
/* RAM is soldered to the board so the size cannot be changed */
|
511 |
ram_bases[0] = qemu_ram_alloc(0x04000000); |
512 |
ram_sizes[0] = 0x04000000; |
513 |
ram_bases[1] = qemu_ram_alloc(0x04000000); |
514 |
ram_sizes[1] = 0x04000000; |
515 |
ram_size = 0x08000000;
|
516 |
#ifdef DEBUG_BOARD_INIT
|
517 |
printf("%s: register cpu\n", __func__);
|
518 |
#endif
|
519 |
env = ppc405ep_init(ram_bases, ram_sizes, 33333333, &pic,
|
520 |
kernel_filename == NULL ? 0 : 1); |
521 |
/* allocate and load BIOS */
|
522 |
#ifdef DEBUG_BOARD_INIT
|
523 |
printf("%s: register BIOS\n", __func__);
|
524 |
#endif
|
525 |
fl_idx = 0;
|
526 |
#if defined(USE_FLASH_BIOS)
|
527 |
index = drive_get_index(IF_PFLASH, 0, fl_idx);
|
528 |
if (index != -1) { |
529 |
bios_size = bdrv_getlength(drives_table[index].bdrv); |
530 |
/* XXX: should check that size is 2MB */
|
531 |
// bios_size = 2 * 1024 * 1024;
|
532 |
fl_sectors = (bios_size + 65535) >> 16; |
533 |
bios_offset = qemu_ram_alloc(bios_size); |
534 |
#ifdef DEBUG_BOARD_INIT
|
535 |
printf("Register parallel flash %d size " ADDRX " at offset %08lx " |
536 |
" addr " ADDRX " '%s' %d\n", |
537 |
fl_idx, bios_size, bios_offset, -bios_size, |
538 |
bdrv_get_device_name(drives_table[index].bdrv), fl_sectors); |
539 |
#endif
|
540 |
pflash_cfi02_register((uint32_t)(-bios_size), bios_offset, |
541 |
drives_table[index].bdrv, 65536, fl_sectors, 1, |
542 |
4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA); |
543 |
fl_idx++; |
544 |
} else
|
545 |
#endif
|
546 |
{ |
547 |
#ifdef DEBUG_BOARD_INIT
|
548 |
printf("Load BIOS from file\n");
|
549 |
#endif
|
550 |
if (bios_name == NULL) |
551 |
bios_name = BIOS_FILENAME; |
552 |
bios_offset = qemu_ram_alloc(BIOS_SIZE); |
553 |
snprintf(buf, sizeof(buf), "%s/%s", bios_dir, bios_name); |
554 |
bios_size = load_image(buf, qemu_get_ram_ptr(bios_offset)); |
555 |
if (bios_size < 0 || bios_size > BIOS_SIZE) { |
556 |
fprintf(stderr, "qemu: could not load PowerPC bios '%s'\n", buf);
|
557 |
exit(1);
|
558 |
} |
559 |
bios_size = (bios_size + 0xfff) & ~0xfff; |
560 |
cpu_register_physical_memory((uint32_t)(-bios_size), |
561 |
bios_size, bios_offset | IO_MEM_ROM); |
562 |
} |
563 |
/* Register Linux flash */
|
564 |
index = drive_get_index(IF_PFLASH, 0, fl_idx);
|
565 |
if (index != -1) { |
566 |
bios_size = bdrv_getlength(drives_table[index].bdrv); |
567 |
/* XXX: should check that size is 32MB */
|
568 |
bios_size = 32 * 1024 * 1024; |
569 |
fl_sectors = (bios_size + 65535) >> 16; |
570 |
#ifdef DEBUG_BOARD_INIT
|
571 |
printf("Register parallel flash %d size " ADDRX " at offset %08lx " |
572 |
" addr " ADDRX " '%s'\n", |
573 |
fl_idx, bios_size, bios_offset, (target_ulong)0xfc000000,
|
574 |
bdrv_get_device_name(drives_table[index].bdrv)); |
575 |
#endif
|
576 |
bios_offset = qemu_ram_alloc(bios_size); |
577 |
pflash_cfi02_register(0xfc000000, bios_offset,
|
578 |
drives_table[index].bdrv, 65536, fl_sectors, 1, |
579 |
4, 0x0001, 0x22DA, 0x0000, 0x0000, 0x555, 0x2AA); |
580 |
fl_idx++; |
581 |
} |
582 |
/* Register CLPD & LCD display */
|
583 |
#ifdef DEBUG_BOARD_INIT
|
584 |
printf("%s: register CPLD\n", __func__);
|
585 |
#endif
|
586 |
taihu_cpld_init(0x50100000);
|
587 |
/* Load kernel */
|
588 |
linux_boot = (kernel_filename != NULL);
|
589 |
if (linux_boot) {
|
590 |
#ifdef DEBUG_BOARD_INIT
|
591 |
printf("%s: load kernel\n", __func__);
|
592 |
#endif
|
593 |
kernel_base = KERNEL_LOAD_ADDR; |
594 |
/* now we can load the kernel */
|
595 |
kernel_size = load_image_targphys(kernel_filename, kernel_base, |
596 |
ram_size - kernel_base); |
597 |
if (kernel_size < 0) { |
598 |
fprintf(stderr, "qemu: could not load kernel '%s'\n",
|
599 |
kernel_filename); |
600 |
exit(1);
|
601 |
} |
602 |
/* load initrd */
|
603 |
if (initrd_filename) {
|
604 |
initrd_base = INITRD_LOAD_ADDR; |
605 |
initrd_size = load_image_targphys(initrd_filename, initrd_base, |
606 |
ram_size - initrd_base); |
607 |
if (initrd_size < 0) { |
608 |
fprintf(stderr, |
609 |
"qemu: could not load initial ram disk '%s'\n",
|
610 |
initrd_filename); |
611 |
exit(1);
|
612 |
} |
613 |
} else {
|
614 |
initrd_base = 0;
|
615 |
initrd_size = 0;
|
616 |
} |
617 |
ppc_boot_device = 'm';
|
618 |
} else {
|
619 |
kernel_base = 0;
|
620 |
kernel_size = 0;
|
621 |
initrd_base = 0;
|
622 |
initrd_size = 0;
|
623 |
} |
624 |
#ifdef DEBUG_BOARD_INIT
|
625 |
printf("%s: Done\n", __func__);
|
626 |
#endif
|
627 |
} |
628 |
|
629 |
QEMUMachine taihu_machine = { |
630 |
"taihu",
|
631 |
"taihu",
|
632 |
taihu_405ep_init, |
633 |
(128 * 1024 * 1024 + 4096 + BIOS_SIZE + 32 * 1024 * 1024) | RAMSIZE_FIXED, |
634 |
}; |