Common shared memory module. Using O_CLOEXEC for opened files.

This commit is contained in:
sorgelig
2021-04-16 23:12:46 +08:00
parent 2899437499
commit 9cd404ea65
22 changed files with 186 additions and 240 deletions

View File

@@ -4,7 +4,6 @@
#include <sys/stat.h>
#include <dirent.h>
#include <ctype.h>
#include <sys/mman.h>
#include "../../sxmlc.h"
#include "../../user_io.h"
@@ -13,6 +12,7 @@
#include "../../menu.h"
#include "../../fpga_io.h"
#include "../../lib/md5/md5.h"
#include "../../shmem.h"
#include "buffer.h"
#include "mra_loader.h"
@@ -292,33 +292,6 @@ static int rom_patch(const uint8_t *buf, int offset, uint16_t len, int dataop)
return 1;
}
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, int index)
{
if (romlen[0] && romdata)
@@ -336,7 +309,7 @@ static void rom_finish(int send, uint32_t address, int index)
if (address)
{
send_to_ddr(address, data, len);
shmem_put(fpga_mem(address), len, data);
}
else
{