X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fflash%2Fnor%2Fnrf51.c;h=bfa199a2ffc415a7b8c5e010427b80b60ff833de;hp=2a4b88764eb8b8252fb562a2dcd3a34c72b0ade8;hb=56802d794e9b23c290ccb373c44b86999f35ca20;hpb=f7ffd142ee0be266a18be074f53fcd284244c527 diff --git a/src/flash/nor/nrf51.c b/src/flash/nor/nrf51.c index 2a4b88764e..bfa199a2ff 100644 --- a/src/flash/nor/nrf51.c +++ b/src/flash/nor/nrf51.c @@ -73,7 +73,7 @@ enum nrf51_uicr_registers { NRF51_UICR_BASE = 0x10001000, /* User Information * Configuration Regsters */ - NRF51_UICR_SIZE = 252, + NRF51_UICR_SIZE = 0x100, #define NRF51_UICR_REG(offset) (NRF51_UICR_BASE + offset) @@ -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; }; @@ -629,13 +637,13 @@ static int nrf51_write_page(struct flash_bank *bank, uint32_t offset, const uint struct flash_sector *sector = nrf51_find_sector_by_address(bank, offset); if (!sector) - goto error; + return ERROR_FLASH_SECTOR_INVALID; if (sector->is_protected) 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; } @@ -920,8 +928,9 @@ static int nrf51_info(struct flash_bank *bank, char *buf, int buf_size) if (res != ERROR_OK) return res; - struct { - uint32_t address, value; + static struct { + const uint32_t address; + uint32_t value; } ficr[] = { { .address = NRF51_FICR_CODEPAGESIZE }, { .address = NRF51_FICR_CODESIZE },