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
26#include "qemu/osdep.h"
27#include "qapi/error.h"
28#include "qemu/datadir.h"
29#include "hw/boards.h"
30#include "qemu/error-report.h"
31#include "hw/arm/digic.h"
32#include "hw/block/flash.h"
33#include "hw/loader.h"
34#include "sysemu/qtest.h"
35#include "qemu/units.h"
36#include "qemu/cutils.h"
37
38#define DIGIC4_ROM0_BASE 0xf0000000
39#define DIGIC4_ROM1_BASE 0xf8000000
40#define DIGIC4_ROM_MAX_SIZE 0x08000000
41
42typedef struct DigicBoard {
43 void (*add_rom0)(DigicState *, hwaddr, const char *);
44 const char *rom0_def_filename;
45 void (*add_rom1)(DigicState *, hwaddr, const char *);
46 const char *rom1_def_filename;
47} DigicBoard;
48
49static void digic4_board_init(MachineState *machine, DigicBoard *board)
50{
51 Error *err = NULL;
52 DigicState *s = DIGIC(object_new(TYPE_DIGIC));
53 MachineClass *mc = MACHINE_GET_CLASS(machine);
54
55 if (machine->ram_size != mc->default_ram_size) {
56 char *sz = size_to_str(mc->default_ram_size);
57 error_report("Invalid RAM size, should be %s", sz);
58 g_free(sz);
59 exit(EXIT_FAILURE);
60 }
61
62 if (!qdev_realize(DEVICE(s), NULL, &err)) {
63 error_reportf_err(err, "Couldn't realize DIGIC SoC: ");
64 exit(1);
65 }
66
67 memory_region_add_subregion(get_system_memory(), 0, machine->ram);
68
69 if (board->add_rom0) {
70 board->add_rom0(s, DIGIC4_ROM0_BASE,
71 machine->firmware ?: board->rom0_def_filename);
72 }
73
74 if (board->add_rom1) {
75 board->add_rom1(s, DIGIC4_ROM1_BASE,
76 machine->firmware ?: board->rom1_def_filename);
77 }
78}
79
80static void digic_load_rom(DigicState *s, hwaddr addr,
81 hwaddr max_size, const char *filename)
82{
83 target_long rom_size;
84
85 if (qtest_enabled()) {
86
87
88
89 return;
90 }
91
92 if (filename) {
93 char *fn = qemu_find_file(QEMU_FILE_TYPE_BIOS, filename);
94
95 if (!fn) {
96 error_report("Couldn't find rom image '%s'.", filename);
97 exit(1);
98 }
99
100 rom_size = load_image_targphys(fn, addr, max_size);
101 if (rom_size < 0 || rom_size > max_size) {
102 error_report("Couldn't load rom image '%s'.", filename);
103 exit(1);
104 }
105 g_free(fn);
106 }
107}
108
109
110
111
112
113static void digic4_add_k8p3215uqb_rom(DigicState *s, hwaddr addr,
114 const char *filename)
115{
116#define FLASH_K8P3215UQB_SIZE (4 * 1024 * 1024)
117#define FLASH_K8P3215UQB_SECTOR_SIZE (64 * 1024)
118
119 pflash_cfi02_register(addr, "pflash", FLASH_K8P3215UQB_SIZE,
120 NULL, FLASH_K8P3215UQB_SECTOR_SIZE,
121 DIGIC4_ROM_MAX_SIZE / FLASH_K8P3215UQB_SIZE,
122 4,
123 0x00EC, 0x007E, 0x0003, 0x0001,
124 0x0555, 0x2aa, 0);
125
126 digic_load_rom(s, addr, FLASH_K8P3215UQB_SIZE, filename);
127}
128
129static DigicBoard digic4_board_canon_a1100 = {
130 .add_rom1 = digic4_add_k8p3215uqb_rom,
131 .rom1_def_filename = "canon-a1100-rom1.bin",
132};
133
134static void canon_a1100_init(MachineState *machine)
135{
136 digic4_board_init(machine, &digic4_board_canon_a1100);
137}
138
139static void canon_a1100_machine_init(MachineClass *mc)
140{
141 mc->desc = "Canon PowerShot A1100 IS (ARM946)";
142 mc->init = &canon_a1100_init;
143 mc->ignore_memory_transaction_failures = true;
144 mc->default_ram_size = 64 * MiB;
145 mc->default_ram_id = "ram";
146}
147
148DEFINE_MACHINE("canon-a1100", canon_a1100_machine_init)
149