2 * QEMU model of the Canon DIGIC boards (cameras indeed :).
4 * Copyright (C) 2013 Antony Pavlov <antonynpavlov@gmail.com>
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
12 * http://magiclantern.wikia.com/wiki/Register_Map
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.
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.
26 #include "qemu/osdep.h"
27 #include "qapi/error.h"
28 #include "qemu-common.h"
30 #include "hw/boards.h"
31 #include "exec/address-spaces.h"
32 #include "qemu/error-report.h"
33 #include "hw/arm/digic.h"
34 #include "hw/block/flash.h"
35 #include "hw/loader.h"
36 #include "sysemu/sysemu.h"
37 #include "sysemu/qtest.h"
39 #define DIGIC4_ROM0_BASE 0xf0000000
40 #define DIGIC4_ROM1_BASE 0xf8000000
41 #define DIGIC4_ROM_MAX_SIZE 0x08000000
43 typedef struct DigicBoardState
{
48 typedef struct DigicBoard
{
50 void (*add_rom0
)(DigicBoardState
*, hwaddr
, const char *);
51 const char *rom0_def_filename
;
52 void (*add_rom1
)(DigicBoardState
*, hwaddr
, const char *);
53 const char *rom1_def_filename
;
56 static void digic4_board_init(DigicBoard
*board
)
60 DigicBoardState
*s
= g_new(DigicBoardState
, 1);
62 s
->digic
= DIGIC(object_new(TYPE_DIGIC
));
63 object_property_set_bool(OBJECT(s
->digic
), true, "realized", &err
);
65 error_reportf_err(err
, "Couldn't realize DIGIC SoC: ");
69 memory_region_allocate_system_memory(&s
->ram
, NULL
, "ram", board
->ram_size
);
70 memory_region_add_subregion(get_system_memory(), 0, &s
->ram
);
72 if (board
->add_rom0
) {
73 board
->add_rom0(s
, DIGIC4_ROM0_BASE
, board
->rom0_def_filename
);
76 if (board
->add_rom1
) {
77 board
->add_rom1(s
, DIGIC4_ROM1_BASE
, board
->rom1_def_filename
);
81 static void digic_load_rom(DigicBoardState
*s
, hwaddr addr
,
82 hwaddr max_size
, const char *def_filename
)
87 if (qtest_enabled()) {
88 /* qtest runs no code so don't attempt a ROM load which
89 * could fail and result in a spurious test failure.
97 filename
= def_filename
;
101 char *fn
= qemu_find_file(QEMU_FILE_TYPE_BIOS
, filename
);
104 error_report("Couldn't find rom image '%s'.", filename
);
108 rom_size
= load_image_targphys(fn
, addr
, max_size
);
109 if (rom_size
< 0 || rom_size
> max_size
) {
110 error_report("Couldn't load rom image '%s'.", filename
);
119 * 64M Bit (4Mx16) Page Mode / Multi-Bank NOR Flash Memory
121 static void digic4_add_k8p3215uqb_rom(DigicBoardState
*s
, hwaddr addr
,
122 const char *def_filename
)
124 #define FLASH_K8P3215UQB_SIZE (4 * 1024 * 1024)
125 #define FLASH_K8P3215UQB_SECTOR_SIZE (64 * 1024)
127 pflash_cfi02_register(addr
, "pflash", FLASH_K8P3215UQB_SIZE
,
128 NULL
, FLASH_K8P3215UQB_SECTOR_SIZE
,
129 DIGIC4_ROM_MAX_SIZE
/ FLASH_K8P3215UQB_SIZE
,
131 0x00EC, 0x007E, 0x0003, 0x0001,
134 digic_load_rom(s
, addr
, FLASH_K8P3215UQB_SIZE
, def_filename
);
137 static DigicBoard digic4_board_canon_a1100
= {
138 .ram_size
= 64 * 1024 * 1024,
139 .add_rom1
= digic4_add_k8p3215uqb_rom
,
140 .rom1_def_filename
= "canon-a1100-rom1.bin",
143 static void canon_a1100_init(MachineState
*machine
)
145 digic4_board_init(&digic4_board_canon_a1100
);
148 static void canon_a1100_machine_init(MachineClass
*mc
)
150 mc
->desc
= "Canon PowerShot A1100 IS";
151 mc
->init
= &canon_a1100_init
;
152 mc
->ignore_memory_transaction_failures
= true;
155 DEFINE_MACHINE("canon-a1100", canon_a1100_machine_init
)