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/arm/boot.h"
31#include "exec/address-spaces.h"
32#include "hw/arm/msf2-soc.h"
33#include "cpu.h"
34
35#define DDR_BASE_ADDRESS 0xA0000000
36#define DDR_SIZE (64 * MiB)
37
38#define M2S010_ENVM_SIZE (256 * KiB)
39#define M2S010_ESRAM_SIZE (64 * KiB)
40
41static void emcraft_sf2_s2s010_init(MachineState *machine)
42{
43 DeviceState *dev;
44 DeviceState *spi_flash;
45 MSF2State *soc;
46 MachineClass *mc = MACHINE_GET_CLASS(machine);
47 DriveInfo *dinfo = drive_get_next(IF_MTD);
48 qemu_irq cs_line;
49 SSIBus *spi_bus;
50 MemoryRegion *sysmem = get_system_memory();
51 MemoryRegion *ddr = g_new(MemoryRegion, 1);
52
53 if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) {
54 error_report("This board can only be used with CPU %s",
55 mc->default_cpu_type);
56 exit(1);
57 }
58
59 memory_region_init_ram(ddr, NULL, "ddr-ram", DDR_SIZE,
60 &error_fatal);
61 memory_region_add_subregion(sysmem, DDR_BASE_ADDRESS, ddr);
62
63 dev = qdev_create(NULL, TYPE_MSF2_SOC);
64 qdev_prop_set_string(dev, "part-name", "M2S010");
65 qdev_prop_set_string(dev, "cpu-type", mc->default_cpu_type);
66
67 qdev_prop_set_uint64(dev, "eNVM-size", M2S010_ENVM_SIZE);
68 qdev_prop_set_uint64(dev, "eSRAM-size", M2S010_ESRAM_SIZE);
69
70
71
72
73
74
75 qdev_prop_set_uint32(dev, "m3clk", 142 * 1000000);
76 qdev_prop_set_uint32(dev, "apb0div", 2);
77 qdev_prop_set_uint32(dev, "apb1div", 2);
78
79 object_property_set_bool(OBJECT(dev), true, "realized", &error_fatal);
80
81 soc = MSF2_SOC(dev);
82
83
84 spi_bus = (SSIBus *)qdev_get_child_bus(dev, "spi0");
85 spi_flash = ssi_create_slave_no_init(spi_bus, "s25sl12801");
86 qdev_prop_set_uint8(spi_flash, "spansion-cr2nv", 1);
87 if (dinfo) {
88 qdev_prop_set_drive(spi_flash, "drive", blk_by_legacy_dinfo(dinfo),
89 &error_fatal);
90 }
91 qdev_init_nofail(spi_flash);
92 cs_line = qdev_get_gpio_in_named(spi_flash, SSI_GPIO_CS, 0);
93 sysbus_connect_irq(SYS_BUS_DEVICE(&soc->spi[0]), 1, cs_line);
94
95 armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename,
96 soc->envm_size);
97}
98
99static void emcraft_sf2_machine_init(MachineClass *mc)
100{
101 mc->desc = "SmartFusion2 SOM kit from Emcraft (M2S010)";
102 mc->init = emcraft_sf2_s2s010_init;
103 mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-m3");
104}
105
106DEFINE_MACHINE("emcraft-sf2", emcraft_sf2_machine_init)
107