From: notaz Date: Mon, 7 Sep 2020 12:30:27 +0000 (+0300) Subject: support erase on a cart with a mapper or through a mirror X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f34ac796daecb84b7228c4eb6aa971039cb4dba8;p=flashkit-mdc.git support erase on a cart with a mapper or through a mirror --- diff --git a/flashkit.c b/flashkit.c index 1dc54d9..9884dd6 100644 --- a/flashkit.c +++ b/flashkit.c @@ -406,17 +406,23 @@ static void read_info(int fd) static uint32_t get_block_addr(uint32_t addr, uint32_t blk_offset) { - uint32_t i; + uint32_t i, base, faddr; assert(info.region_cnt); + assert(info.size); + + // get a flash address to allow mapper hardware + faddr = addr & (info.size - 1); + base = addr & ~(info.size - 1); + for (i = 0; i < info.region_cnt; i++) { - if (info.region[i].start <= addr - && addr < info.region[i].start + info.region[i].size) + if (info.region[i].start <= faddr + && faddr < info.region[i].start + info.region[i].size) { - uint32_t blk = (addr - info.region[i].start) + uint32_t blk = (faddr - info.region[i].start) / info.region[i].block_size + blk_offset; - return info.region[i].start + return base + info.region[i].start + blk * info.region[i].block_size; } }