]> git.proxmox.com Git - mirror_qemu.git/blob - hw/ppc/sam460ex.c
Merge remote-tracking branch 'remotes/ehabkost/tags/machine-next-pull-request' into...
[mirror_qemu.git] / hw / ppc / sam460ex.c
1 /*
2 * QEMU aCube Sam460ex board emulation
3 *
4 * Copyright (c) 2012 François Revol
5 * Copyright (c) 2016-2018 BALATON Zoltan
6 *
7 * This file is derived from hw/ppc440_bamboo.c,
8 * the copyright for that material belongs to the original owners.
9 *
10 * This work is licensed under the GNU GPL license version 2 or later.
11 *
12 */
13
14 #include "qemu/osdep.h"
15 #include "qemu/units.h"
16 #include "qemu-common.h"
17 #include "qemu/error-report.h"
18 #include "qapi/error.h"
19 #include "hw/hw.h"
20 #include "hw/boards.h"
21 #include "sysemu/kvm.h"
22 #include "kvm_ppc.h"
23 #include "sysemu/device_tree.h"
24 #include "sysemu/block-backend.h"
25 #include "hw/loader.h"
26 #include "elf.h"
27 #include "exec/address-spaces.h"
28 #include "exec/memory.h"
29 #include "ppc440.h"
30 #include "ppc405.h"
31 #include "hw/block/flash.h"
32 #include "sysemu/sysemu.h"
33 #include "sysemu/qtest.h"
34 #include "hw/sysbus.h"
35 #include "hw/char/serial.h"
36 #include "hw/i2c/ppc4xx_i2c.h"
37 #include "hw/i2c/smbus.h"
38 #include "hw/usb/hcd-ehci.h"
39 #include "hw/ppc/fdt.h"
40
41 #include <libfdt.h>
42
43 #define BINARY_DEVICE_TREE_FILE "canyonlands.dtb"
44 #define UBOOT_FILENAME "u-boot-sam460-20100605.bin"
45 /* to extract the official U-Boot bin from the updater: */
46 /* dd bs=1 skip=$(($(stat -c '%s' updater/updater-460) - 0x80000)) \
47 if=updater/updater-460 of=u-boot-sam460-20100605.bin */
48
49 /* from Sam460 U-Boot include/configs/Sam460ex.h */
50 #define FLASH_BASE 0xfff00000
51 #define FLASH_BASE_H 0x4
52 #define FLASH_SIZE (1 * MiB)
53 #define UBOOT_LOAD_BASE 0xfff80000
54 #define UBOOT_SIZE 0x00080000
55 #define UBOOT_ENTRY 0xfffffffc
56
57 /* from U-Boot */
58 #define EPAPR_MAGIC (0x45504150)
59 #define KERNEL_ADDR 0x1000000
60 #define FDT_ADDR 0x1800000
61 #define RAMDISK_ADDR 0x1900000
62
63 /* Sam460ex IRQ MAP:
64 IRQ0 = ETH_INT
65 IRQ1 = FPGA_INT
66 IRQ2 = PCI_INT (PCIA, PCIB, PCIC, PCIB)
67 IRQ3 = FPGA_INT2
68 IRQ11 = RTC_INT
69 IRQ12 = SM502_INT
70 */
71
72 #define CPU_FREQ 1150000000
73 #define PLB_FREQ 230000000
74 #define OPB_FREQ 115000000
75 #define EBC_FREQ 115000000
76 #define UART_FREQ 11059200
77 #define SDRAM_NR_BANKS 4
78
79 /* FIXME: See u-boot.git 8ac41e, also fix in ppc440_uc.c */
80 static const unsigned int ppc460ex_sdram_bank_sizes[] = {
81 1 * GiB, 512 * MiB, 256 * MiB, 128 * MiB, 64 * MiB, 32 * MiB, 0
82 };
83
84 struct boot_info {
85 uint32_t dt_base;
86 uint32_t dt_size;
87 uint32_t entry;
88 };
89
90 /*****************************************************************************/
91 /* SPD eeprom content from mips_malta.c */
92
93 struct _eeprom24c0x_t {
94 uint8_t tick;
95 uint8_t address;
96 uint8_t command;
97 uint8_t ack;
98 uint8_t scl;
99 uint8_t sda;
100 uint8_t data;
101 uint8_t contents[256];
102 };
103
104 typedef struct _eeprom24c0x_t eeprom24c0x_t;
105
106 static eeprom24c0x_t spd_eeprom = {
107 .contents = {
108 /* 00000000: */ 0x80, 0x08, 0xFF, 0x0D, 0x0A, 0xFF, 0x40, 0x00,
109 /* 00000008: */ 0x04, 0x75, 0x54, 0x00, 0x82, 0x08, 0x00, 0x01,
110 /* 00000010: */ 0x8F, 0x04, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00,
111 /* 00000018: */ 0x00, 0x00, 0x00, 0x14, 0x0F, 0x14, 0x2D, 0xFF,
112 /* 00000020: */ 0x15, 0x08, 0x15, 0x08, 0x00, 0x00, 0x00, 0x00,
113 /* 00000028: */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
114 /* 00000030: */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
115 /* 00000038: */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0xD0,
116 /* 00000040: */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
117 /* 00000048: */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
118 /* 00000050: */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
119 /* 00000058: */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
120 /* 00000060: */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
121 /* 00000068: */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
122 /* 00000070: */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
123 /* 00000078: */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0xF4,
124 },
125 };
126
127 static void generate_eeprom_spd(uint8_t *eeprom, ram_addr_t ram_size)
128 {
129 enum { SDR = 0x4, DDR1 = 0x7, DDR2 = 0x8 } type;
130 uint8_t *spd = spd_eeprom.contents;
131 uint8_t nbanks = 0;
132 uint16_t density = 0;
133 int i;
134
135 /* work in terms of MB */
136 ram_size /= MiB;
137
138 while ((ram_size >= 4) && (nbanks <= 2)) {
139 int sz_log2 = MIN(31 - clz32(ram_size), 14);
140 nbanks++;
141 density |= 1 << (sz_log2 - 2);
142 ram_size -= 1 << sz_log2;
143 }
144
145 /* split to 2 banks if possible */
146 if ((nbanks == 1) && (density > 1)) {
147 nbanks++;
148 density >>= 1;
149 }
150
151 if (density & 0xff00) {
152 density = (density & 0xe0) | ((density >> 8) & 0x1f);
153 type = DDR2;
154 } else if (!(density & 0x1f)) {
155 type = DDR2;
156 } else {
157 type = SDR;
158 }
159
160 if (ram_size) {
161 warn_report("SPD cannot represent final " RAM_ADDR_FMT "MB"
162 " of SDRAM", ram_size);
163 }
164
165 /* fill in SPD memory information */
166 spd[2] = type;
167 spd[5] = nbanks;
168 spd[31] = density;
169
170 /* XXX: this is totally random */
171 spd[9] = 0x10; /* CAS tcyc */
172 spd[18] = 0x20; /* CAS bit */
173 spd[23] = 0x10; /* CAS tcyc */
174 spd[25] = 0x10; /* CAS tcyc */
175
176 /* checksum */
177 spd[63] = 0;
178 for (i = 0; i < 63; i++) {
179 spd[63] += spd[i];
180 }
181
182 /* copy for SMBUS */
183 memcpy(eeprom, spd, sizeof(spd_eeprom.contents));
184 }
185
186 static void generate_eeprom_serial(uint8_t *eeprom)
187 {
188 int i, pos = 0;
189 uint8_t mac[6] = { 0x00 };
190 uint8_t sn[5] = { 0x01, 0x23, 0x45, 0x67, 0x89 };
191
192 /* version */
193 eeprom[pos++] = 0x01;
194
195 /* count */
196 eeprom[pos++] = 0x02;
197
198 /* MAC address */
199 eeprom[pos++] = 0x01; /* MAC */
200 eeprom[pos++] = 0x06; /* length */
201 memcpy(&eeprom[pos], mac, sizeof(mac));
202 pos += sizeof(mac);
203
204 /* serial number */
205 eeprom[pos++] = 0x02; /* serial */
206 eeprom[pos++] = 0x05; /* length */
207 memcpy(&eeprom[pos], sn, sizeof(sn));
208 pos += sizeof(sn);
209
210 /* checksum */
211 eeprom[pos] = 0;
212 for (i = 0; i < pos; i++) {
213 eeprom[pos] += eeprom[i];
214 }
215 }
216
217 /*****************************************************************************/
218
219 static int sam460ex_load_uboot(void)
220 {
221 DriveInfo *dinfo;
222 BlockBackend *blk = NULL;
223 hwaddr base = FLASH_BASE | ((hwaddr)FLASH_BASE_H << 32);
224 long bios_size = FLASH_SIZE;
225 int fl_sectors;
226
227 dinfo = drive_get(IF_PFLASH, 0, 0);
228 if (dinfo) {
229 blk = blk_by_legacy_dinfo(dinfo);
230 bios_size = blk_getlength(blk);
231 }
232 fl_sectors = (bios_size + 65535) >> 16;
233
234 if (!pflash_cfi01_register(base, NULL, "sam460ex.flash", bios_size,
235 blk, 64 * KiB, fl_sectors,
236 1, 0x89, 0x18, 0x0000, 0x0, 1)) {
237 error_report("qemu: Error registering flash memory.");
238 /* XXX: return an error instead? */
239 exit(1);
240 }
241
242 if (!blk) {
243 /*error_report("No flash image given with the 'pflash' parameter,"
244 " using default u-boot image");*/
245 base = UBOOT_LOAD_BASE | ((hwaddr)FLASH_BASE_H << 32);
246 rom_add_file_fixed(UBOOT_FILENAME, base, -1);
247 }
248
249 return 0;
250 }
251
252 static int sam460ex_load_device_tree(hwaddr addr,
253 uint32_t ramsize,
254 hwaddr initrd_base,
255 hwaddr initrd_size,
256 const char *kernel_cmdline)
257 {
258 uint32_t mem_reg_property[] = { 0, 0, cpu_to_be32(ramsize) };
259 char *filename;
260 int fdt_size;
261 void *fdt;
262 uint32_t tb_freq = CPU_FREQ;
263 uint32_t clock_freq = CPU_FREQ;
264 int offset;
265
266 filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, BINARY_DEVICE_TREE_FILE);
267 if (!filename) {
268 error_report("Couldn't find dtb file `%s'", BINARY_DEVICE_TREE_FILE);
269 exit(1);
270 }
271 fdt = load_device_tree(filename, &fdt_size);
272 g_free(filename);
273 if (!fdt) {
274 error_report("Couldn't load dtb file `%s'", filename);
275 exit(1);
276 }
277
278 /* Manipulate device tree in memory. */
279
280 qemu_fdt_setprop(fdt, "/memory", "reg", mem_reg_property,
281 sizeof(mem_reg_property));
282
283 /* default FDT doesn't have a /chosen node... */
284 qemu_fdt_add_subnode(fdt, "/chosen");
285
286 qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start", initrd_base);
287
288 qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end",
289 (initrd_base + initrd_size));
290
291 qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", kernel_cmdline);
292
293 /* Copy data from the host device tree into the guest. Since the guest can
294 * directly access the timebase without host involvement, we must expose
295 * the correct frequencies. */
296 if (kvm_enabled()) {
297 tb_freq = kvmppc_get_tbfreq();
298 clock_freq = kvmppc_get_clockfreq();
299 }
300
301 qemu_fdt_setprop_cell(fdt, "/cpus/cpu@0", "clock-frequency",
302 clock_freq);
303 qemu_fdt_setprop_cell(fdt, "/cpus/cpu@0", "timebase-frequency",
304 tb_freq);
305
306 /* Remove cpm node if it exists (it is not emulated) */
307 offset = fdt_path_offset(fdt, "/cpm");
308 if (offset >= 0) {
309 _FDT(fdt_nop_node(fdt, offset));
310 }
311
312 /* set serial port clocks */
313 offset = fdt_node_offset_by_compatible(fdt, -1, "ns16550");
314 while (offset >= 0) {
315 _FDT(fdt_setprop_cell(fdt, offset, "clock-frequency", UART_FREQ));
316 offset = fdt_node_offset_by_compatible(fdt, offset, "ns16550");
317 }
318
319 /* some more clocks */
320 qemu_fdt_setprop_cell(fdt, "/plb", "clock-frequency",
321 PLB_FREQ);
322 qemu_fdt_setprop_cell(fdt, "/plb/opb", "clock-frequency",
323 OPB_FREQ);
324 qemu_fdt_setprop_cell(fdt, "/plb/opb/ebc", "clock-frequency",
325 EBC_FREQ);
326
327 rom_add_blob_fixed(BINARY_DEVICE_TREE_FILE, fdt, fdt_size, addr);
328 g_free(fdt);
329
330 return fdt_size;
331 }
332
333 /* Create reset TLB entries for BookE, mapping only the flash memory. */
334 static void mmubooke_create_initial_mapping_uboot(CPUPPCState *env)
335 {
336 ppcemb_tlb_t *tlb = &env->tlb.tlbe[0];
337
338 /* on reset the flash is mapped by a shadow TLB,
339 * but since we don't implement them we need to use
340 * the same values U-Boot will use to avoid a fault.
341 */
342 tlb->attr = 0;
343 tlb->prot = PAGE_VALID | ((PAGE_READ | PAGE_WRITE | PAGE_EXEC) << 4);
344 tlb->size = 0x10000000; /* up to 0xffffffff */
345 tlb->EPN = 0xf0000000 & TARGET_PAGE_MASK;
346 tlb->RPN = (0xf0000000 & TARGET_PAGE_MASK) | 0x4;
347 tlb->PID = 0;
348 }
349
350 /* Create reset TLB entries for BookE, spanning the 32bit addr space. */
351 static void mmubooke_create_initial_mapping(CPUPPCState *env,
352 target_ulong va,
353 hwaddr pa)
354 {
355 ppcemb_tlb_t *tlb = &env->tlb.tlbe[0];
356
357 tlb->attr = 0;
358 tlb->prot = PAGE_VALID | ((PAGE_READ | PAGE_WRITE | PAGE_EXEC) << 4);
359 tlb->size = 1 << 31; /* up to 0x80000000 */
360 tlb->EPN = va & TARGET_PAGE_MASK;
361 tlb->RPN = pa & TARGET_PAGE_MASK;
362 tlb->PID = 0;
363 }
364
365 static void main_cpu_reset(void *opaque)
366 {
367 PowerPCCPU *cpu = opaque;
368 CPUPPCState *env = &cpu->env;
369 struct boot_info *bi = env->load_info;
370
371 cpu_reset(CPU(cpu));
372
373 /* either we have a kernel to boot or we jump to U-Boot */
374 if (bi->entry != UBOOT_ENTRY) {
375 env->gpr[1] = (16 * MiB) - 8;
376 env->gpr[3] = FDT_ADDR;
377 env->nip = bi->entry;
378
379 /* Create a mapping for the kernel. */
380 mmubooke_create_initial_mapping(env, 0, 0);
381 env->gpr[6] = tswap32(EPAPR_MAGIC);
382 env->gpr[7] = (16 * MiB) - 8; /* bi->ima_size; */
383
384 } else {
385 env->nip = UBOOT_ENTRY;
386 mmubooke_create_initial_mapping_uboot(env);
387 }
388 }
389
390 static void sam460ex_init(MachineState *machine)
391 {
392 MemoryRegion *address_space_mem = get_system_memory();
393 MemoryRegion *isa = g_new(MemoryRegion, 1);
394 MemoryRegion *ram_memories = g_new(MemoryRegion, SDRAM_NR_BANKS);
395 hwaddr ram_bases[SDRAM_NR_BANKS];
396 hwaddr ram_sizes[SDRAM_NR_BANKS];
397 MemoryRegion *l2cache_ram = g_new(MemoryRegion, 1);
398 qemu_irq *irqs, *uic[4];
399 PCIBus *pci_bus;
400 PowerPCCPU *cpu;
401 CPUPPCState *env;
402 PPC4xxI2CState *i2c[2];
403 hwaddr entry = UBOOT_ENTRY;
404 hwaddr loadaddr = 0;
405 target_long initrd_size = 0;
406 DeviceState *dev;
407 SysBusDevice *sbdev;
408 int success;
409 int i;
410 struct boot_info *boot_info;
411 const size_t smbus_eeprom_size = 8 * 256;
412 uint8_t *smbus_eeprom_buf = g_malloc0(smbus_eeprom_size);
413
414 cpu = POWERPC_CPU(cpu_create(machine->cpu_type));
415 env = &cpu->env;
416 if (env->mmu_model != POWERPC_MMU_BOOKE) {
417 error_report("Only MMU model BookE is supported by this machine.");
418 exit(1);
419 }
420
421 #ifdef TARGET_PPCEMB
422 if (!qtest_enabled()) {
423 warn_report("qemu-system-ppcemb is deprecated, "
424 "please use qemu-system-ppc instead.");
425 }
426 #endif
427
428 qemu_register_reset(main_cpu_reset, cpu);
429 boot_info = g_malloc0(sizeof(*boot_info));
430 env->load_info = boot_info;
431
432 ppc_booke_timers_init(cpu, CPU_FREQ, 0);
433 ppc_dcr_init(env, NULL, NULL);
434
435 /* PLB arbitrer */
436 ppc4xx_plb_init(env);
437
438 /* interrupt controllers */
439 irqs = g_malloc0(sizeof(*irqs) * PPCUIC_OUTPUT_NB);
440 irqs[PPCUIC_OUTPUT_INT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_INT];
441 irqs[PPCUIC_OUTPUT_CINT] = ((qemu_irq *)env->irq_inputs)[PPC40x_INPUT_CINT];
442 uic[0] = ppcuic_init(env, irqs, 0xc0, 0, 1);
443 uic[1] = ppcuic_init(env, &uic[0][30], 0xd0, 0, 1);
444 uic[2] = ppcuic_init(env, &uic[0][10], 0xe0, 0, 1);
445 uic[3] = ppcuic_init(env, &uic[0][16], 0xf0, 0, 1);
446
447 /* SDRAM controller */
448 memset(ram_bases, 0, sizeof(ram_bases));
449 memset(ram_sizes, 0, sizeof(ram_sizes));
450 /* put all RAM on first bank because board has one slot
451 * and firmware only checks that */
452 machine->ram_size = ppc4xx_sdram_adjust(machine->ram_size, 1,
453 ram_memories, ram_bases, ram_sizes,
454 ppc460ex_sdram_bank_sizes);
455
456 /* FIXME: does 460EX have ECC interrupts? */
457 ppc440_sdram_init(env, SDRAM_NR_BANKS, ram_memories,
458 ram_bases, ram_sizes, 1);
459
460 /* generate SPD EEPROM data */
461 for (i = 0; i < SDRAM_NR_BANKS; i++) {
462 generate_eeprom_spd(&smbus_eeprom_buf[i * 256], ram_sizes[i]);
463 }
464 generate_eeprom_serial(&smbus_eeprom_buf[4 * 256]);
465 generate_eeprom_serial(&smbus_eeprom_buf[6 * 256]);
466
467 /* IIC controllers */
468 dev = sysbus_create_simple(TYPE_PPC4xx_I2C, 0x4ef600700, uic[0][2]);
469 i2c[0] = PPC4xx_I2C(dev);
470 object_property_set_bool(OBJECT(dev), true, "realized", NULL);
471 smbus_eeprom_init(i2c[0]->bus, 8, smbus_eeprom_buf, smbus_eeprom_size);
472 g_free(smbus_eeprom_buf);
473 i2c_create_slave(i2c[0]->bus, "m41t80", 0x68);
474
475 dev = sysbus_create_simple(TYPE_PPC4xx_I2C, 0x4ef600800, uic[0][3]);
476 i2c[1] = PPC4xx_I2C(dev);
477
478 /* External bus controller */
479 ppc405_ebc_init(env);
480
481 /* CPR */
482 ppc4xx_cpr_init(env);
483
484 /* PLB to AHB bridge */
485 ppc4xx_ahb_init(env);
486
487 /* System DCRs */
488 ppc4xx_sdr_init(env);
489
490 /* MAL */
491 ppc4xx_mal_init(env, 4, 16, &uic[2][3]);
492
493 /* DMA */
494 ppc4xx_dma_init(env, 0x200);
495
496 /* 256K of L2 cache as memory */
497 ppc4xx_l2sram_init(env);
498 /* FIXME: remove this after fixing l2sram mapping in ppc440_uc.c? */
499 memory_region_init_ram(l2cache_ram, NULL, "ppc440.l2cache_ram", 256 * KiB,
500 &error_abort);
501 memory_region_add_subregion(address_space_mem, 0x400000000LL, l2cache_ram);
502
503 /* USB */
504 sysbus_create_simple(TYPE_PPC4xx_EHCI, 0x4bffd0400, uic[2][29]);
505 dev = qdev_create(NULL, "sysbus-ohci");
506 qdev_prop_set_string(dev, "masterbus", "usb-bus.0");
507 qdev_prop_set_uint32(dev, "num-ports", 6);
508 qdev_init_nofail(dev);
509 sbdev = SYS_BUS_DEVICE(dev);
510 sysbus_mmio_map(sbdev, 0, 0x4bffd0000);
511 sysbus_connect_irq(sbdev, 0, uic[2][30]);
512 usb_create_simple(usb_bus_find(-1), "usb-kbd");
513 usb_create_simple(usb_bus_find(-1), "usb-mouse");
514
515 /* PCI bus */
516 ppc460ex_pcie_init(env);
517 /* FIXME: is this correct? */
518 dev = sysbus_create_varargs("ppc440-pcix-host", 0xc0ec00000,
519 uic[1][0], uic[1][20], uic[1][21], uic[1][22],
520 NULL);
521 pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci.0");
522 if (!pci_bus) {
523 error_report("couldn't create PCI controller!");
524 exit(1);
525 }
526 memory_region_init_alias(isa, NULL, "isa_mmio", get_system_io(),
527 0, 0x10000);
528 memory_region_add_subregion(get_system_memory(), 0xc08000000, isa);
529
530 /* PCI devices */
531 pci_create_simple(pci_bus, PCI_DEVFN(6, 0), "sm501");
532 /* SoC has a single SATA port but we don't emulate that yet
533 * However, firmware and usual clients have driver for SiI311x
534 * so add one for convenience by default */
535 if (defaults_enabled()) {
536 pci_create_simple(pci_bus, -1, "sii3112");
537 }
538
539 /* SoC has 4 UARTs
540 * but board has only one wired and two are present in fdt */
541 if (serial_hd(0) != NULL) {
542 serial_mm_init(address_space_mem, 0x4ef600300, 0, uic[1][1],
543 PPC_SERIAL_MM_BAUDBASE, serial_hd(0),
544 DEVICE_BIG_ENDIAN);
545 }
546 if (serial_hd(1) != NULL) {
547 serial_mm_init(address_space_mem, 0x4ef600400, 0, uic[0][1],
548 PPC_SERIAL_MM_BAUDBASE, serial_hd(1),
549 DEVICE_BIG_ENDIAN);
550 }
551
552 /* Load U-Boot image. */
553 if (!machine->kernel_filename) {
554 success = sam460ex_load_uboot();
555 if (success < 0) {
556 error_report("qemu: could not load firmware");
557 exit(1);
558 }
559 }
560
561 /* Load kernel. */
562 if (machine->kernel_filename) {
563 success = load_uimage(machine->kernel_filename, &entry, &loadaddr,
564 NULL, NULL, NULL);
565 if (success < 0) {
566 uint64_t elf_entry, elf_lowaddr;
567
568 success = load_elf(machine->kernel_filename, NULL, NULL, &elf_entry,
569 &elf_lowaddr, NULL, 1, PPC_ELF_MACHINE, 0, 0);
570 entry = elf_entry;
571 loadaddr = elf_lowaddr;
572 }
573 /* XXX try again as binary */
574 if (success < 0) {
575 error_report("qemu: could not load kernel '%s'",
576 machine->kernel_filename);
577 exit(1);
578 }
579 }
580
581 /* Load initrd. */
582 if (machine->initrd_filename) {
583 initrd_size = load_image_targphys(machine->initrd_filename,
584 RAMDISK_ADDR,
585 machine->ram_size - RAMDISK_ADDR);
586 if (initrd_size < 0) {
587 error_report("qemu: could not load ram disk '%s' at %x",
588 machine->initrd_filename, RAMDISK_ADDR);
589 exit(1);
590 }
591 }
592
593 /* If we're loading a kernel directly, we must load the device tree too. */
594 if (machine->kernel_filename) {
595 int dt_size;
596
597 dt_size = sam460ex_load_device_tree(FDT_ADDR, machine->ram_size,
598 RAMDISK_ADDR, initrd_size,
599 machine->kernel_cmdline);
600
601 boot_info->dt_base = FDT_ADDR;
602 boot_info->dt_size = dt_size;
603 }
604
605 boot_info->entry = entry;
606 }
607
608 static void sam460ex_machine_init(MachineClass *mc)
609 {
610 mc->desc = "aCube Sam460ex";
611 mc->init = sam460ex_init;
612 mc->default_cpu_type = POWERPC_CPU_TYPE_NAME("460exb");
613 mc->default_ram_size = 512 * MiB;
614 }
615
616 DEFINE_MACHINE("sam460ex", sam460ex_machine_init)