fix(storage/esp_partition): add option to control erase check during write for linux target

This commit is contained in:
Tomáš Rohlínek 2024-02-27 12:38:10 +01:00
parent 6e20be1d95
commit f753434640
No known key found for this signature in database
GPG Key ID: 288BC7E47BF1409B
2 changed files with 11 additions and 0 deletions

View File

@ -7,4 +7,13 @@ menu "Partition API Configuration"
help
This option enables gathering host test statistics and SPI flash wear levelling simulation.
config ESP_PARTITION_ERASE_CHECK
bool "Check if flash is erased before writing"
depends on IDF_TARGET_LINUX
default y
help
This option controls whether the partition implementation checks
if the flash is erased before writing to it.
This is necessary for SPIFFS, which expects to be able to write without erasing first.
endmenu

View File

@ -396,12 +396,14 @@ esp_err_t esp_partition_write(const esp_partition_t *partition, size_t dst_offse
for (size_t x = 0; x < new_size; x++) {
#ifdef CONFIG_ESP_PARTITION_ERASE_CHECK
// Check if address to be written was erased first
if((~((uint8_t *)dst_addr)[x] & ((uint8_t *)src)[x]) != 0) {
ESP_LOGW(TAG, "invalid flash operation detected");
ret = ESP_ERR_FLASH_OP_FAIL;
break;
}
#endif // CONFIG_ESP_PARTITION_ERASE_CHECK
// AND with destination byte (to emulate real NOR FLASH behavior)
((uint8_t *)dst_addr)[x] &= ((uint8_t *)src)[x];