From 80dcef4de7806dd59ed68e4a91fe8c750cd52fc6 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Sun, 16 Feb 2020 23:23:45 +0800 Subject: [PATCH] arcade: support for DDR3 direct loading. --- support/arcade/romutils.cpp | 55 ++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 7 deletions(-) diff --git a/support/arcade/romutils.cpp b/support/arcade/romutils.cpp index c10527a..a993985 100644 --- a/support/arcade/romutils.cpp +++ b/support/arcade/romutils.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "../../sxmlc.h" #include "../../user_io.h" @@ -35,6 +36,7 @@ struct arc_struct { int ifrom; int ito; int imap; + uint32_t address; uint32_t crc; buffer_data *data; struct MD5Context context; @@ -222,7 +224,34 @@ static int rom_patch(const uint8_t *buf, int offset, uint16_t len) return 1; } -static void rom_finish(int send) +static void send_to_ddr(uint32_t address, void* buf, uint32_t len) +{ + int memfd = open("/dev/mem", O_RDWR | O_SYNC); + if (memfd == -1) + { + printf("Unable to open /dev/mem!\n"); + return; + } + + //make sure it's in FPGA address space + uint32_t map_addr = 0x20000000 | address; + + void *base = mmap(0, len, PROT_READ | PROT_WRITE, MAP_SHARED, memfd, map_addr); + if (base == (void *)-1) + { + printf("Unable to mmap (0x%X, %d)!\n", map_addr, len); + close(memfd); + return; + } + + memcpy(base, buf, len); + munmap(base, len); + + close(memfd); + return; +} + +static void rom_finish(int send, uint32_t address) { if (romlen[0] && romdata) { @@ -236,13 +265,20 @@ static void rom_finish(int send) uint8_t *data = romdata; int len = romlen[0]; - while (romlen[0] > 0) + if (address) { - uint16_t chunk = (romlen[0] > 4096) ? 4096 : romlen[0]; - user_io_file_tx_write(data, chunk); + send_to_ddr(address, data, len); + } + else + { + while (romlen[0] > 0) + { + uint16_t chunk = (romlen[0] > 4096) ? 4096 : romlen[0]; + user_io_file_tx_write(data, chunk); - romlen[0] -= chunk; - data += chunk; + romlen[0] -= chunk; + data += chunk; + } } // signal end of transmission @@ -354,6 +390,7 @@ static int xml_send_rom(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, cons arc_info->ito = 0; arc_info->imap = 0; arc_info->zipname[0] = 0; + arc_info->address = 0; MD5Init(&arc_info->context); } @@ -403,6 +440,10 @@ static int xml_send_rom(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, cons { arc_info->romindex = atoi(node->attributes[i].value); } + if (!strcasecmp(node->attributes[i].name, "address") && !strcasecmp(node->tag, "rom")) + { + arc_info->address = strtoul(node->attributes[i].value, NULL, 0); + } if (!strcasecmp(node->attributes[i].name, "names") && !strcasecmp(node->tag, "buttons")) { @@ -638,7 +679,7 @@ static int xml_send_rom(XMLEvent evt, const XMLNode* node, SXML_CHAR* text, cons } } - rom_finish(checksumsame); + rom_finish(checksumsame, arc_info->address); } arc_info->insiderom = 0; }