support erase on a cart with a mapper or through a mirror
authornotaz <notasas@gmail.com>
Mon, 7 Sep 2020 12:30:27 +0000 (15:30 +0300)
committernotaz <notasas@gmail.com>
Mon, 7 Sep 2020 12:30:27 +0000 (15:30 +0300)
flashkit.c

index 1dc54d9..9884dd6 100644 (file)
@@ -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;
                }
        }