From 09b044e3514957a19dd53a8399b4e522fab6fc9d Mon Sep 17 00:00:00 2001 From: dragonmux Date: Sat, 6 Aug 2022 04:05:18 +0100 Subject: [PATCH] rp: Cleanup in the Flash write/erase routines --- src/target/rp.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/target/rp.c b/src/target/rp.c index 1ccdd7e..4d0c99f 100644 --- a/src/target/rp.c +++ b/src/target/rp.c @@ -383,11 +383,12 @@ static void rp_flash_resume(target *t) } } -/* FLASHCMD_SECTOR_ERASE 45/ 400 ms - * 32k block erase 120/ 1600 ms - * 64k block erase 150/ 2000 ms - * chip erase 5000/25000 ms - * page programm 0.4/ 3 ms +/* + * 4k sector erase 45/ 400 ms + * 32k block erase 120/ 1600 ms + * 64k block erase 150/ 2000 ms + * chip erase 5000/25000 ms + * page programm 0.4/ 3 ms */ static int rp_flash_erase(target_flash_s *f, target_addr addr, size_t len) { @@ -397,13 +398,13 @@ static int rp_flash_erase(target_flash_s *f, target_addr addr, size_t len) DEBUG_WARN("Unaligned erase\n"); return -1; } - if ((addr < t->flash->start) || (addr >= t->flash->start + t->flash->length)) { + if ((addr < f->start) || (addr >= f->start + f->length)) { DEBUG_WARN("Address is invalid\n"); return -1; } - addr -= t->flash->start; + addr -= f->start; len = ALIGN(len, FLASHSIZE_4K_SECTOR); - len = MIN(len, t->flash->length - addr); + len = MIN(len, f->length - addr); rp_priv_s *ps = (rp_priv_s *)t->target_storage; const bool full_erase = addr == f->start && len == f->length; platform_timeout timeout; @@ -462,7 +463,7 @@ static int rp_flash_write(target_flash_s *f, target_addr dest, const void *src, DEBUG_WARN("Unaligned write\n"); return -1; } - dest -= t->flash->start; + dest -= f->start; rp_priv_s *ps = (rp_priv_s *)t->target_storage; /* Write payload to target ram */ rp_flash_prepare(t);