Browse Source

rp: Refactor rp_flash_erase

Always align erase length to 4k sector size.
Check that start address and length are actually inside the flash.
pull/1066/head
James Turton 2 years ago
committed by Rachel Mant
parent
commit
f4261c465e
  1. 18
      src/target/rp.c

18
src/target/rp.c

@ -216,22 +216,22 @@ static void rp_flash_resume(target *t)
static int rp_flash_erase(struct target_flash *f, target_addr addr, static int rp_flash_erase(struct target_flash *f, target_addr addr,
size_t len) size_t len)
{ {
DEBUG_INFO("Erase addr 0x%08" PRIx32 " len 0x%" PRIx32 "\n", addr, (uint32_t)len);
target *t = f->t;
if (addr & (FLASHSIZE_4K_SECTOR - 1)) { if (addr & (FLASHSIZE_4K_SECTOR - 1)) {
DEBUG_WARN("Unaligned erase\n"); DEBUG_WARN("Unaligned erase\n");
return -1; return -1;
} }
if (len & (FLASHSIZE_4K_SECTOR - 1)) { if ((addr < t->flash->start) || (addr >= t->flash->start + t->flash->length)) {
DEBUG_WARN("Unaligned len\n"); DEBUG_WARN("Address is invalid\n");
len = ALIGN(len, FLASHSIZE_4K_SECTOR); return -1;
} }
DEBUG_INFO("Erase addr 0x%08" PRIx32 " len 0x%" PRIx32 "\n", addr, (uint32_t)len); addr -= t->flash->start;
target *t = f->t; len = ALIGN(len, FLASHSIZE_4K_SECTOR);
rp_flash_prepare(t); len = MIN(len, t->flash->length - addr);
struct rp_priv_s *ps = (struct rp_priv_s*)t->target_storage; struct rp_priv_s *ps = (struct rp_priv_s*)t->target_storage;
/* Register playground*/
/* erase */ /* erase */
addr -= t->flash->start; rp_flash_prepare(t);
len = MIN(len, t->flash->length);
bool ret = 0; bool ret = 0;
while (len) { while (len) {
if (len >= FLASHSIZE_64K_BLOCK) { if (len >= FLASHSIZE_64K_BLOCK) {

Loading…
Cancel
Save