diff options
Diffstat (limited to 'src/flash/nor/core.c')
-rw-r--r-- | src/flash/nor/core.c | 59 |
1 files changed, 29 insertions, 30 deletions
diff --git a/src/flash/nor/core.c b/src/flash/nor/core.c index d26894b..043ff13 100644 --- a/src/flash/nor/core.c +++ b/src/flash/nor/core.c @@ -99,7 +99,7 @@ int flash_driver_write(struct flash_bank *bank, retval = bank->driver->write(bank, buffer, offset, count); if (retval != ERROR_OK) { LOG_ERROR( - "error writing to flash at address 0x%08" TARGET_PRIxADDR + "error writing to flash at address " TARGET_ADDR_FMT " at offset 0x%8.8" PRIx32, bank->base, offset); @@ -118,7 +118,7 @@ int flash_driver_read(struct flash_bank *bank, retval = bank->driver->read(bank, buffer, offset, count); if (retval != ERROR_OK) { LOG_ERROR( - "error reading to flash at address 0x%08" TARGET_PRIxADDR + "error reading to flash at address " TARGET_ADDR_FMT " at offset 0x%8.8" PRIx32, bank->base, offset); @@ -270,7 +270,7 @@ int get_flash_bank_by_num(int num, struct flash_bank **bank) /* lookup flash bank by address, bank not found is success, but * result_bank is set to NULL. */ int get_flash_bank_by_addr(struct target *target, - uint32_t addr, + target_addr_t addr, bool check, struct flash_bank **result_bank) { @@ -296,7 +296,7 @@ int get_flash_bank_by_addr(struct target *target, } *result_bank = NULL; if (check) { - LOG_ERROR("No flash at address 0x%08" PRIx32, addr); + LOG_ERROR("No flash at address " TARGET_ADDR_FMT, addr); return ERROR_FAIL; } return ERROR_OK; @@ -416,13 +416,13 @@ int default_flash_blank_check(struct flash_bank *bank) * warning about those additions. */ static int flash_iterate_address_range_inner(struct target *target, - char *pad_reason, uint32_t addr, uint32_t length, + char *pad_reason, target_addr_t addr, uint32_t length, bool iterate_protect_blocks, int (*callback)(struct flash_bank *bank, int first, int last)) { struct flash_bank *c; struct flash_sector *block_array; - uint32_t last_addr = addr + length; /* first address AFTER end */ + target_addr_t last_addr = addr + length - 1; /* the last address of range */ int first = -1; int last = -1; int i; @@ -448,7 +448,7 @@ static int flash_iterate_address_range_inner(struct target *target, } /* check whether it all fits in this bank */ - if (addr + length - 1 > c->base + c->size - 1) { + if (last_addr > c->base + c->size - 1) { LOG_ERROR("Flash access does not fit into bank."); return ERROR_FLASH_DST_BREAKS_ALIGNMENT; } @@ -466,21 +466,19 @@ static int flash_iterate_address_range_inner(struct target *target, num_blocks = c->num_sectors; } - addr -= c->base; - last_addr -= c->base; - for (i = 0; i < num_blocks; i++) { struct flash_sector *f = &block_array[i]; - uint32_t end = f->offset + f->size; + target_addr_t sector_addr = c->base + f->offset; + target_addr_t sector_last_addr = sector_addr + f->size - 1; /* start only on a sector boundary */ if (first < 0) { /* scanned past the first sector? */ - if (addr < f->offset) + if (addr < sector_addr) break; /* is this the first sector? */ - if (addr == f->offset) + if (addr == sector_addr) first = i; /* Does this need head-padding? If so, pad and warn; @@ -490,20 +488,20 @@ static int flash_iterate_address_range_inner(struct target *target, * ever know if that data was in use. The warning * should help users sort out messes later. */ - else if (addr < end && pad_reason) { + else if (addr <= sector_last_addr && pad_reason) { /* FIXME say how many bytes (e.g. 80 KB) */ LOG_WARNING("Adding extra %s range, " - "%#8.8x to %#8.8x", + TARGET_ADDR_FMT " .. " TARGET_ADDR_FMT, pad_reason, - (unsigned) f->offset, - (unsigned) addr - 1); + sector_addr, + addr - 1); first = i; } else continue; } /* is this (also?) the last sector? */ - if (last_addr == end) { + if (last_addr == sector_last_addr) { last = i; break; } @@ -511,28 +509,28 @@ static int flash_iterate_address_range_inner(struct target *target, /* Does this need tail-padding? If so, pad and warn; * or else force an error. */ - if (last_addr < end && pad_reason) { + if (last_addr < sector_last_addr && pad_reason) { /* FIXME say how many bytes (e.g. 80 KB) */ LOG_WARNING("Adding extra %s range, " - "%#8.8x to %#8.8x", + TARGET_ADDR_FMT " .. " TARGET_ADDR_FMT, pad_reason, - (unsigned) last_addr, - (unsigned) end - 1); + last_addr + 1, + sector_last_addr); last = i; break; } /* MUST finish on a sector boundary */ - if (last_addr <= f->offset) + if (last_addr < sector_addr) break; } /* invalid start or end address? */ if (first == -1 || last == -1) { - LOG_ERROR("address range 0x%8.8x .. 0x%8.8x " - "is not sector-aligned", - (unsigned) (c->base + addr), - (unsigned) (c->base + last_addr - 1)); + LOG_ERROR("address range " TARGET_ADDR_FMT " .. " TARGET_ADDR_FMT + " is not sector-aligned", + addr, + last_addr); return ERROR_FLASH_DST_BREAKS_ALIGNMENT; } @@ -547,7 +545,7 @@ static int flash_iterate_address_range_inner(struct target *target, * multiple chips. */ static int flash_iterate_address_range(struct target *target, - char *pad_reason, uint32_t addr, uint32_t length, + char *pad_reason, target_addr_t addr, uint32_t length, bool iterate_protect_blocks, int (*callback)(struct flash_bank *bank, int first, int last)) { @@ -581,7 +579,7 @@ static int flash_iterate_address_range(struct target *target, } int flash_erase_address_range(struct target *target, - bool pad, uint32_t addr, uint32_t length) + bool pad, target_addr_t addr, uint32_t length) { return flash_iterate_address_range(target, pad ? "erase" : NULL, addr, length, false, &flash_driver_erase); @@ -592,7 +590,8 @@ static int flash_driver_unprotect(struct flash_bank *bank, int first, int last) return flash_driver_protect(bank, 0, first, last); } -int flash_unlock_address_range(struct target *target, uint32_t addr, uint32_t length) +int flash_unlock_address_range(struct target *target, target_addr_t addr, + uint32_t length) { /* By default, pad to sector boundaries ... the real issue here * is that our (only) caller *permanently* removes protection, |