1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include "qemu/osdep.h"
26#include "qemu/units.h"
27#include "qapi/error.h"
28#include "qemu/error-report.h"
29#include "hw/boards.h"
30#include "hw/qdev-properties.h"
31#include "hw/arm/boot.h"
32#include "hw/qdev-clock.h"
33#include "exec/address-spaces.h"
34#include "hw/arm/msf2-soc.h"
35
36#define DDR_BASE_ADDRESS 0xA0000000
37#define DDR_SIZE (64 * MiB)
38
39#define M2S010_ENVM_SIZE (256 * KiB)
40#define M2S010_ESRAM_SIZE (64 * KiB)
41
42static void emcraft_sf2_s2s010_init(MachineState *machine)
43{
44 DeviceState *dev;
45 DeviceState *spi_flash;
46 MSF2State *soc;
47 MachineClass *mc = MACHINE_GET_CLASS(machine);
48 DriveInfo *dinfo = drive_get(IF_MTD, 0, 0);
49 qemu_irq cs_line;
50 BusState *spi_bus;
51 MemoryRegion *sysmem = get_system_memory();
52 MemoryRegion *ddr = g_new(MemoryRegion, 1);
53 Clock *m3clk;
54
55 if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) {
56 error_report("This board can only be used with CPU %s",
57 mc->default_cpu_type);
58 exit(1);
59 }
60
61 memory_region_init_ram(ddr, NULL, "ddr-ram", DDR_SIZE,
62 &error_fatal);
63 memory_region_add_subregion(sysmem, DDR_BASE_ADDRESS, ddr);
64
65 dev = qdev_new(TYPE_MSF2_SOC);
66 qdev_prop_set_string(dev, "part-name", "M2S010");
67 qdev_prop_set_string(dev, "cpu-type", mc->default_cpu_type);
68
69 qdev_prop_set_uint64(dev, "eNVM-size", M2S010_ENVM_SIZE);
70 qdev_prop_set_uint64(dev, "eSRAM-size", M2S010_ESRAM_SIZE);
71
72
73
74
75
76
77
78 m3clk = clock_new(OBJECT(machine), "m3clk");
79 clock_set_hz(m3clk, 142 * 1000000);
80 qdev_connect_clock_in(dev, "m3clk", m3clk);
81 qdev_prop_set_uint32(dev, "apb0div", 2);
82 qdev_prop_set_uint32(dev, "apb1div", 2);
83
84 sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
85
86 soc = MSF2_SOC(dev);
87
88
89 spi_bus = qdev_get_child_bus(dev, "spi0");
90 spi_flash = qdev_new("s25sl12801");
91 qdev_prop_set_uint8(spi_flash, "spansion-cr2nv", 1);
92 if (dinfo) {
93 qdev_prop_set_drive_err(spi_flash, "drive",
94 blk_by_legacy_dinfo(dinfo), &error_fatal);
95 }
96 qdev_realize_and_unref(spi_flash, spi_bus, &error_fatal);
97 cs_line = qdev_get_gpio_in_named(spi_flash, SSI_GPIO_CS, 0);
98 sysbus_connect_irq(SYS_BUS_DEVICE(&soc->spi[0]), 1, cs_line);
99
100 armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,
101 0, soc->envm_size);
102}
103
104static void emcraft_sf2_machine_init(MachineClass *mc)
105{
106 mc->desc = "SmartFusion2 SOM kit from Emcraft (M2S010)";
107 mc->init = emcraft_sf2_s2s010_init;
108 mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m3");
109}
110
111DEFINE_MACHINE("emcraft-sf2", emcraft_sf2_machine_init)
112