From dd58be19eef0be304e1b0530fe6e7408ab9b9b84 Mon Sep 17 00:00:00 2001 From: Luca Burelli Date: Thu, 21 Sep 2023 11:40:26 +0200 Subject: [PATCH] esp32: Fix Partition.writeblocks() partial write corruption. To simulate a partial erase, the code reads a native block, erases it, and writes back the data before and after the erased area. However, the current logic was filling the area after the erased block with data from the beginning of the native block-aligned data, instead of applying the proper offset. Fixes #12474. Signed-off-by: Luca Burelli --- ports/esp32/esp32_partition.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/esp32/esp32_partition.c b/ports/esp32/esp32_partition.c index 17aa34e560..3bca3b5273 100644 --- a/ports/esp32/esp32_partition.c +++ b/ports/esp32/esp32_partition.c @@ -200,7 +200,7 @@ STATIC mp_obj_t esp32_partition_writeblocks(size_t n_args, const mp_obj_t *args) check_esp_err(esp_partition_write(self->part, addr, self->cache, o)); } if (top_addr < addr + NATIVE_BLOCK_SIZE_BYTES) { - check_esp_err(esp_partition_write(self->part, top_addr, self->cache, addr + NATIVE_BLOCK_SIZE_BYTES - top_addr)); + check_esp_err(esp_partition_write(self->part, top_addr, self->cache + (top_addr - addr), addr + NATIVE_BLOCK_SIZE_BYTES - top_addr)); } o = 0; addr += NATIVE_BLOCK_SIZE_BYTES;