From f34ac796daecb84b7228c4eb6aa971039cb4dba8 Mon Sep 17 00:00:00 2001 From: notaz Date: Mon, 7 Sep 2020 15:30:27 +0300 Subject: [PATCH] support erase on a cart with a mapper or through a mirror --- flashkit.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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; } } -- 2.39.5