@@ -1,6 +1,13 @@
#include "hw/boards.h"
#include "exec/address-spaces.h"
#include "hw/arm/digic.h"
+#include "hw/block/flash.h"
+#include "hw/loader.h"
+#include "sysemu/sysemu.h"
+
+#define DIGIC4_ROM0_BASE 0xf0000000
+#define DIGIC4_ROM1_BASE 0xf8000000
+# define DIGIC4_ROM_MAX_SIZE 0x08000000
typedef struct DigicBoardState {
DigicState *digic;
@@ -9,6 +16,10 @@ typedef struct DigicBoardState {
typedef struct DigicBoard {
hwaddr ram_size;
+ void (*add_rom0)(DigicBoardState *, hwaddr, const char *);
+ const char *rom0_def_filename;
+ void (*add_rom1)(DigicBoardState *, hwaddr, const char *);
+ const char *rom1_def_filename;
hwaddr start_addr;
} DigicBoard;
@@ -35,11 +46,67 @@ static void digic4_board_init(DigicBoard *board)
digic4_board_setup_ram(s, board->ram_size);
+ if (board->add_rom0) {
+ board->add_rom0(s, DIGIC4_ROM0_BASE, board->rom0_def_filename);
+ }
+
+ if (board->add_rom1) {
+ board->add_rom1(s, DIGIC4_ROM1_BASE, board->rom1_def_filename);
+ }
+
s->digic->cpu.env.regs[15] = board->start_addr;
}
+static void digic4_add_k8p3215uqb_rom(DigicBoardState *s, hwaddr addr,
+ const char *def_filename)
+{
+#define FLASH_K8P3215UQB_SIZE (4 * 1024 * 1024)
+#define FLASH_K8P3215UQB_SECTOR_SIZE (64 * 1024)
+
+ target_long rom_size;
+ const char *filename;
+
+ /*
+ * Samsung K8P3215UQB:
+ * * AMD command set;
+ * * multiple sector size: some sectors are 8K the other ones are 64K.
+ * Alas! The pflash_cfi02_register() function creates a flash
+ * device with unified sector size.
+ */
+ pflash_cfi02_register(addr, NULL, "pflash", FLASH_K8P3215UQB_SIZE,
+ NULL, FLASH_K8P3215UQB_SECTOR_SIZE,
+ FLASH_K8P3215UQB_SIZE / FLASH_K8P3215UQB_SECTOR_SIZE,
+ DIGIC4_ROM_MAX_SIZE / FLASH_K8P3215UQB_SIZE,
+ 4,
+ 0x00EC, 0x007E, 0x0003, 0x0001,
+ 0x0555, 0x2aa, 0);
+
+ if (bios_name) {
+ filename = bios_name;
+ } else {
+ filename = def_filename;
+ }
+
+ if (filename) {
+ char *fn = qemu_find_file(QEMU_FILE_TYPE_BIOS, filename);
+
+ if (!fn) {
+ fprintf(stderr, "Couldn't find rom image '%s'.\n", filename);
+ exit(1);
+ }
+
+ rom_size = load_image_targphys(fn, addr, FLASH_K8P3215UQB_SIZE);
+ if (rom_size < 0 || rom_size > FLASH_K8P3215UQB_SIZE) {
+ fprintf(stderr, "Couldn't load rom image '%s'\n", filename);
+ exit(1);
+ }
+ }
+}
+
static DigicBoard digic4_board_canon_a1100 = {
.ram_size = 64 * 1024 * 1024,
+ .add_rom1 = digic4_add_k8p3215uqb_rom,
+ .rom1_def_filename = "canon-a1100-rom1.bin",
/* CHDK recommends this address for ROM disassembly */
.start_addr = 0xffc00000,
};
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com> --- hw/arm/digic_boards.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+)