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;
}
}