X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fflash%2Fnor%2Fnrf51.c;h=bfa199a2ffc415a7b8c5e010427b80b60ff833de;hp=8f6760d8c457ba018352e96f7bc6213c7d4c1e2e;hb=56802d794e9b23c290ccb373c44b86999f35ca20;hpb=6412b0656bb5122f3b7d59729a42191f3ebde9fb diff --git a/src/flash/nor/nrf51.c b/src/flash/nor/nrf51.c index 8f6760d8c4..bfa199a2ff 100644 --- a/src/flash/nor/nrf51.c +++ b/src/flash/nor/nrf51.c @@ -562,14 +562,16 @@ static int nrf51_erase_all(struct nrf51_info *chip) 0x00000001); } -static int nrf51_erase_page(struct nrf51_info *chip, struct flash_sector *sector) +static int nrf51_erase_page(struct flash_bank *bank, + struct nrf51_info *chip, + struct flash_sector *sector) { int res; if (sector->is_protected) return ERROR_FAIL; - if (sector->offset == NRF51_UICR_BASE) { + if (bank->base == NRF51_UICR_BASE) { uint32_t ppfc; res = target_read_u32(chip->target, NRF51_FICR_PPFC, &ppfc); @@ -579,6 +581,12 @@ static int nrf51_erase_page(struct nrf51_info *chip, struct flash_sector *sector } if ((ppfc & 0xFF) == 0xFF) { + /* We can't erase the UICR. Double-check to + see if it's already erased before complaining. */ + default_flash_blank_check(bank); + if (sector->is_erased == 1) + return ERROR_OK; + LOG_ERROR("The chip was not pre-programmed with SoftDevice stack and UICR cannot be erased separately. Please issue mass erase before trying to write to this region"); return ERROR_FAIL; }; @@ -635,7 +643,7 @@ static int nrf51_write_page(struct flash_bank *bank, uint32_t offset, const uint goto error; if (!sector->is_erased) { - res = nrf51_erase_page(chip, sector); + res = nrf51_erase_page(bank, chip, sector); if (res != ERROR_OK) { LOG_ERROR("Failed to erase sector @ 0x%08"PRIx32, sector->offset); goto error; @@ -672,7 +680,7 @@ static int nrf51_erase(struct flash_bank *bank, int first, int last) /* For each sector to be erased */ for (int s = first; s <= last && res == ERROR_OK; s++) - res = nrf51_erase_page(chip, &bank->sectors[s]); + res = nrf51_erase_page(bank, chip, &bank->sectors[s]); return res; } @@ -777,7 +785,7 @@ static int nrf51_uicr_flash_write(struct flash_bank *bank, return res; if (!sector->is_erased) { - res = nrf51_erase_page(chip, sector); + res = nrf51_erase_page(bank, chip, sector); if (res != ERROR_OK) return res; }