]>
Commit | Line | Data |
---|---|---|
d91fd756 AP |
1 | /* |
2 | * QEMU model of the Canon DIGIC boards (cameras indeed :). | |
3 | * | |
4 | * Copyright (C) 2013 Antony Pavlov <antonynpavlov@gmail.com> | |
5 | * | |
6 | * This model is based on reverse engineering efforts | |
7 | * made by CHDK (http://chdk.wikia.com) and | |
8 | * Magic Lantern (http://www.magiclantern.fm) projects | |
9 | * contributors. | |
10 | * | |
11 | * See docs here: | |
12 | * http://magiclantern.wikia.com/wiki/Register_Map | |
13 | * | |
14 | * This program is free software; you can redistribute it and/or modify | |
15 | * it under the terms of the GNU General Public License as published by | |
16 | * the Free Software Foundation; either version 2 of the License, or | |
17 | * (at your option) any later version. | |
18 | * | |
19 | * This program is distributed in the hope that it will be useful, | |
20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22 | * GNU General Public License for more details. | |
23 | * | |
24 | */ | |
25 | ||
12b16722 | 26 | #include "qemu/osdep.h" |
da34e65c | 27 | #include "qapi/error.h" |
4771d756 PB |
28 | #include "qemu-common.h" |
29 | #include "cpu.h" | |
d91fd756 AP |
30 | #include "hw/boards.h" |
31 | #include "exec/address-spaces.h" | |
32 | #include "qemu/error-report.h" | |
33 | #include "hw/arm/digic.h" | |
04234a37 AP |
34 | #include "hw/block/flash.h" |
35 | #include "hw/loader.h" | |
36 | #include "sysemu/sysemu.h" | |
37 | #include "sysemu/qtest.h" | |
4daf95d6 IM |
38 | #include "qemu/units.h" |
39 | #include "qemu/cutils.h" | |
04234a37 AP |
40 | |
41 | #define DIGIC4_ROM0_BASE 0xf0000000 | |
42 | #define DIGIC4_ROM1_BASE 0xf8000000 | |
43 | #define DIGIC4_ROM_MAX_SIZE 0x08000000 | |
d91fd756 | 44 | |
d91fd756 | 45 | typedef struct DigicBoard { |
4daf95d6 | 46 | void (*add_rom0)(DigicState *, hwaddr, const char *); |
04234a37 | 47 | const char *rom0_def_filename; |
4daf95d6 | 48 | void (*add_rom1)(DigicState *, hwaddr, const char *); |
04234a37 | 49 | const char *rom1_def_filename; |
d91fd756 AP |
50 | } DigicBoard; |
51 | ||
4daf95d6 | 52 | static void digic4_board_init(MachineState *machine, DigicBoard *board) |
d91fd756 AP |
53 | { |
54 | Error *err = NULL; | |
4daf95d6 IM |
55 | DigicState *s = DIGIC(object_new(TYPE_DIGIC)); |
56 | MachineClass *mc = MACHINE_GET_CLASS(machine); | |
57 | ||
58 | if (machine->ram_size != mc->default_ram_size) { | |
59 | char *sz = size_to_str(mc->default_ram_size); | |
60 | error_report("Invalid RAM size, should be %s", sz); | |
61 | g_free(sz); | |
62 | exit(EXIT_FAILURE); | |
63 | } | |
d91fd756 | 64 | |
4daf95d6 | 65 | object_property_set_bool(OBJECT(s), true, "realized", &err); |
d91fd756 | 66 | if (err != NULL) { |
c29b77f9 | 67 | error_reportf_err(err, "Couldn't realize DIGIC SoC: "); |
d91fd756 AP |
68 | exit(1); |
69 | } | |
70 | ||
4daf95d6 | 71 | memory_region_add_subregion(get_system_memory(), 0, machine->ram); |
04234a37 AP |
72 | |
73 | if (board->add_rom0) { | |
74 | board->add_rom0(s, DIGIC4_ROM0_BASE, board->rom0_def_filename); | |
75 | } | |
76 | ||
77 | if (board->add_rom1) { | |
78 | board->add_rom1(s, DIGIC4_ROM1_BASE, board->rom1_def_filename); | |
79 | } | |
80 | } | |
81 | ||
4daf95d6 | 82 | static void digic_load_rom(DigicState *s, hwaddr addr, |
04234a37 AP |
83 | hwaddr max_size, const char *def_filename) |
84 | { | |
85 | target_long rom_size; | |
86 | const char *filename; | |
87 | ||
88 | if (qtest_enabled()) { | |
89 | /* qtest runs no code so don't attempt a ROM load which | |
90 | * could fail and result in a spurious test failure. | |
91 | */ | |
92 | return; | |
93 | } | |
94 | ||
95 | if (bios_name) { | |
96 | filename = bios_name; | |
97 | } else { | |
98 | filename = def_filename; | |
99 | } | |
100 | ||
101 | if (filename) { | |
102 | char *fn = qemu_find_file(QEMU_FILE_TYPE_BIOS, filename); | |
103 | ||
104 | if (!fn) { | |
d448527a | 105 | error_report("Couldn't find rom image '%s'.", filename); |
04234a37 AP |
106 | exit(1); |
107 | } | |
108 | ||
109 | rom_size = load_image_targphys(fn, addr, max_size); | |
110 | if (rom_size < 0 || rom_size > max_size) { | |
d448527a | 111 | error_report("Couldn't load rom image '%s'.", filename); |
04234a37 AP |
112 | exit(1); |
113 | } | |
6e05a12f | 114 | g_free(fn); |
04234a37 AP |
115 | } |
116 | } | |
117 | ||
118 | /* | |
119 | * Samsung K8P3215UQB | |
120 | * 64M Bit (4Mx16) Page Mode / Multi-Bank NOR Flash Memory | |
121 | */ | |
4daf95d6 | 122 | static void digic4_add_k8p3215uqb_rom(DigicState *s, hwaddr addr, |
04234a37 AP |
123 | const char *def_filename) |
124 | { | |
125 | #define FLASH_K8P3215UQB_SIZE (4 * 1024 * 1024) | |
126 | #define FLASH_K8P3215UQB_SECTOR_SIZE (64 * 1024) | |
127 | ||
940d5b13 | 128 | pflash_cfi02_register(addr, "pflash", FLASH_K8P3215UQB_SIZE, |
04234a37 | 129 | NULL, FLASH_K8P3215UQB_SECTOR_SIZE, |
04234a37 AP |
130 | DIGIC4_ROM_MAX_SIZE / FLASH_K8P3215UQB_SIZE, |
131 | 4, | |
132 | 0x00EC, 0x007E, 0x0003, 0x0001, | |
133 | 0x0555, 0x2aa, 0); | |
134 | ||
135 | digic_load_rom(s, addr, FLASH_K8P3215UQB_SIZE, def_filename); | |
d91fd756 AP |
136 | } |
137 | ||
138 | static DigicBoard digic4_board_canon_a1100 = { | |
04234a37 AP |
139 | .add_rom1 = digic4_add_k8p3215uqb_rom, |
140 | .rom1_def_filename = "canon-a1100-rom1.bin", | |
d91fd756 AP |
141 | }; |
142 | ||
3ef96221 | 143 | static void canon_a1100_init(MachineState *machine) |
d91fd756 | 144 | { |
4daf95d6 | 145 | digic4_board_init(machine, &digic4_board_canon_a1100); |
d91fd756 AP |
146 | } |
147 | ||
e264d29d | 148 | static void canon_a1100_machine_init(MachineClass *mc) |
d91fd756 | 149 | { |
e264d29d EH |
150 | mc->desc = "Canon PowerShot A1100 IS"; |
151 | mc->init = &canon_a1100_init; | |
4672cbd7 | 152 | mc->ignore_memory_transaction_failures = true; |
4daf95d6 IM |
153 | mc->default_ram_size = 64 * MiB; |
154 | mc->default_ram_id = "ram"; | |
d91fd756 AP |
155 | } |
156 | ||
e264d29d | 157 | DEFINE_MACHINE("canon-a1100", canon_a1100_machine_init) |