From 3e8f296dd59a1edbbd666c534ae4c046cd369d54 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Thu, 1 Sep 2022 12:57:24 +0800 Subject: [PATCH] rp: invert success logic in rp_flash_write Target write operations return boolean values: `true` indicates a write was successful, while `false` indicates there was a failure. Inside the rpi target, there is a delegate function `rp_rom_call` that performs the heavy lifting. It also returns `true` on success and `false` on failure. The rp_flash_write() function was inverting this logic, which caused it to return `false` on success and `true` on failure. This behaviour was exhibited as only the first 0x89c bytes successfully write to the device. Invert this logic in order to get rpi working again. Signed-off-by: Sean Cross --- src/target/rp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/target/rp.c b/src/target/rp.c index 8ed22fa..d38f326 100644 --- a/src/target/rp.c +++ b/src/target/rp.c @@ -461,7 +461,7 @@ static bool rp_flash_write(target_flash_s *f, target_addr_t dest, const void *sr rp_priv_s *ps = (rp_priv_s *)t->target_storage; /* Write payload to target ram */ rp_flash_prepare(t); - bool ret = 0; + bool ret = true; #define MAX_WRITE_CHUNK 0x1000 while (len) { uint32_t chunksize = (len <= MAX_WRITE_CHUNK) ? len : MAX_WRITE_CHUNK; @@ -474,8 +474,8 @@ static bool rp_flash_write(target_flash_s *f, target_addr_t dest, const void *sr * however it takes much longer if the XOSC is not enabled * so lets give ourselves a little bit more time (x10) */ - ret |= rp_rom_call(t, ps->regs, ps->rom_flash_range_program, (3 * chunksize * 10) >> 8); - if (ret) { + ret = rp_rom_call(t, ps->regs, ps->rom_flash_range_program, (3 * chunksize * 10) >> 8); + if (!ret) { DEBUG_WARN("Write failed!\n"); break; } @@ -485,7 +485,7 @@ static bool rp_flash_write(target_flash_s *f, target_addr_t dest, const void *sr } rp_flash_resume(t); DEBUG_INFO("Write done!\n"); - return !ret; + return ret; } static bool rp_mass_erase(target *t)