flash/nor/nrf5: remove is_erased setting and autoerase before write
Cached flash erase state in sectors[].is_erased is not reliable as running target can change the flash. Autoerase was issued before flash write on condition is_erased != 1 Remove autoerase completely as it is a quite non-standard feature. Change-Id: I19bef459e6afdc4c5fcaa2ccd194cf05be8a42b6 Signed-off-by: Tomas Vanek <vanekt@fbl.cz> Reviewed-on: http://openocd.zylin.com/4400 Tested-by: jenkinsbscan_tunnel
parent
7b03129916
commit
f05bcdebbb
|
@ -531,7 +531,6 @@ static int nrf5_probe(struct flash_bank *bank)
|
|||
bank->sectors[0].size = bank->size;
|
||||
bank->sectors[0].offset = 0;
|
||||
|
||||
/* mark as unknown */
|
||||
bank->sectors[0].is_erased = 0;
|
||||
bank->sectors[0].is_protected = 0;
|
||||
|
||||
|
@ -553,17 +552,6 @@ static int nrf5_auto_probe(struct flash_bank *bank)
|
|||
return nrf5_probe(bank);
|
||||
}
|
||||
|
||||
static struct flash_sector *nrf5_find_sector_by_address(struct flash_bank *bank, uint32_t address)
|
||||
{
|
||||
struct nrf5_info *chip = bank->driver_priv;
|
||||
|
||||
for (int i = 0; i < bank->num_sectors; i++)
|
||||
if (bank->sectors[i].offset <= address &&
|
||||
address < (bank->sectors[i].offset + chip->code_page_size))
|
||||
return &bank->sectors[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int nrf5_erase_all(struct nrf5_info *chip)
|
||||
{
|
||||
LOG_DEBUG("Erasing all non-volatile memory");
|
||||
|
@ -615,9 +603,6 @@ static int nrf5_erase_page(struct flash_bank *bank,
|
|||
sector->offset);
|
||||
}
|
||||
|
||||
if (res == ERROR_OK)
|
||||
sector->is_erased = 1;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -743,48 +728,22 @@ static int nrf5_write_pages(struct flash_bank *bank, uint32_t start, uint32_t en
|
|||
{
|
||||
int res = ERROR_FAIL;
|
||||
struct nrf5_info *chip = bank->driver_priv;
|
||||
struct flash_sector *sector;
|
||||
uint32_t offset;
|
||||
|
||||
assert(start % chip->code_page_size == 0);
|
||||
assert(end % chip->code_page_size == 0);
|
||||
|
||||
/* Erase all sectors */
|
||||
for (offset = start; offset < end; offset += chip->code_page_size) {
|
||||
sector = nrf5_find_sector_by_address(bank, offset);
|
||||
if (!sector) {
|
||||
LOG_ERROR("Invalid sector @ 0x%08"PRIx32, offset);
|
||||
return ERROR_FLASH_SECTOR_INVALID;
|
||||
}
|
||||
|
||||
if (sector->is_protected) {
|
||||
LOG_ERROR("Can't erase protected sector @ 0x%08"PRIx32, offset);
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (sector->is_erased != 1) { /* 1 = erased, 0= not erased, -1 = unknown */
|
||||
res = nrf5_erase_page(bank, chip, sector);
|
||||
if (res != ERROR_OK) {
|
||||
LOG_ERROR("Failed to erase sector @ 0x%08"PRIx32, sector->offset);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
sector->is_erased = 0;
|
||||
}
|
||||
|
||||
res = nrf5_nvmc_write_enable(chip);
|
||||
if (res != ERROR_OK)
|
||||
goto error;
|
||||
|
||||
res = nrf5_ll_flash_write(chip, start, buffer, (end - start));
|
||||
if (res != ERROR_OK)
|
||||
goto set_read_only;
|
||||
goto error;
|
||||
|
||||
return nrf5_nvmc_read_only(chip);
|
||||
|
||||
set_read_only:
|
||||
nrf5_nvmc_read_only(chip);
|
||||
error:
|
||||
nrf5_nvmc_read_only(chip);
|
||||
LOG_ERROR("Failed to write to nrf5 flash");
|
||||
return res;
|
||||
}
|
||||
|
@ -876,11 +835,9 @@ static int nrf5_uicr_flash_write(struct flash_bank *bank,
|
|||
if (res != ERROR_OK)
|
||||
return res;
|
||||
|
||||
if (sector->is_erased != 1) {
|
||||
res = nrf5_erase_page(bank, chip, sector);
|
||||
if (res != ERROR_OK)
|
||||
return res;
|
||||
}
|
||||
res = nrf5_erase_page(bank, chip, sector);
|
||||
if (res != ERROR_OK)
|
||||
return res;
|
||||
|
||||
res = nrf5_nvmc_write_enable(chip);
|
||||
if (res != ERROR_OK)
|
||||
|
@ -992,9 +949,6 @@ COMMAND_HANDLER(nrf5_handle_mass_erase_command)
|
|||
return res;
|
||||
}
|
||||
|
||||
for (int i = 0; i < bank->num_sectors; i++)
|
||||
bank->sectors[i].is_erased = 1;
|
||||
|
||||
res = nrf5_protect_check(bank);
|
||||
if (res != ERROR_OK) {
|
||||
LOG_ERROR("Failed to check chip's write protection");
|
||||
|
@ -1005,8 +959,6 @@ COMMAND_HANDLER(nrf5_handle_mass_erase_command)
|
|||
if (res != ERROR_OK)
|
||||
return res;
|
||||
|
||||
bank->sectors[0].is_erased = 1;
|
||||
|
||||
return ERROR_OK;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue