aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomas Vanek <vanekt@fbl.cz>2019-03-02 09:51:23 +0100
committerMatthias Welwarsky <matthias@welwarsky.de>2019-03-27 08:53:29 +0000
commit21ef7e30d4f47a78e2b3aacedd425f0966465352 (patch)
tree86c9fdd15481914b11b4d6df91bbfa86338fb6da
parentbc72695f6738951571502706bd48680de5ccc84c (diff)
downloadriscv-openocd-21ef7e30d4f47a78e2b3aacedd425f0966465352.zip
riscv-openocd-21ef7e30d4f47a78e2b3aacedd425f0966465352.tar.gz
riscv-openocd-21ef7e30d4f47a78e2b3aacedd425f0966465352.tar.bz2
flash/nor/core: adjust flash_iterate_address_range_inner() for 64-bit
Use target_addr_t exclusively for comparison of sector boudaries and address range. Use the last addres for both address range end and sector end. It avoids problems with a flash bank mapped at the very end of target address space. Change-Id: Idf97c837453d97cbc4cf8a1c76ad799f4142f19e Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-on: http://openocd.zylin.com/4985 Tested-by: jenkins Reviewed-by: Tim Newsome <tim@sifive.com> Reviewed-by: Matthias Welwarsky <matthias@welwarsky.de>
-rw-r--r--src/flash/nor/core.c36
1 files changed, 17 insertions, 19 deletions
diff --git a/src/flash/nor/core.c b/src/flash/nor/core.c
index 11b7ce4..043ff13 100644
--- a/src/flash/nor/core.c
+++ b/src/flash/nor/core.c
@@ -422,7 +422,7 @@ static int flash_iterate_address_range_inner(struct target *target,
{
struct flash_bank *c;
struct flash_sector *block_array;
- target_addr_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,12 +488,12 @@ 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 " TARGET_ADDR_FMT,
+ TARGET_ADDR_FMT " .. " TARGET_ADDR_FMT,
pad_reason,
- (unsigned) f->offset,
+ sector_addr,
addr - 1);
first = i;
} else
@@ -503,7 +501,7 @@ static int flash_iterate_address_range_inner(struct target *target,
}
/* is this (also?) the last sector? */
- if (last_addr == end) {
+ if (last_addr == sector_last_addr) {
last = i;
break;
}
@@ -511,19 +509,19 @@ 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;
}
@@ -531,8 +529,8 @@ static int flash_iterate_address_range_inner(struct target *target,
if (first == -1 || last == -1) {
LOG_ERROR("address range " TARGET_ADDR_FMT " .. " TARGET_ADDR_FMT
" is not sector-aligned",
- c->base + addr,
- c->base + last_addr - 1);
+ addr,
+ last_addr);
return ERROR_FLASH_DST_BREAKS_ALIGNMENT;
}