Skip to content

Commit 9ac6a62

Browse files
committed
ESP32: use partition API to access flash
This takes into account partition encryption flag
1 parent cbd2bd6 commit 9ac6a62

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

src/esp32/esp32_vfs_dev_partition.c

+3-16
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,7 @@ static enum mgos_vfs_dev_err esp32_vfs_dev_partition_read(
6161
esp_err_t eres = ESP_OK;
6262
enum mgos_vfs_dev_err res = MGOS_VFS_DEV_ERR_INVAL;
6363
const esp_partition_t *p = (esp_partition_t *) dev->dev_data;
64-
if (len > p->size || offset + len > p->address + p->size) {
65-
LOG(LL_ERROR, ("%s: invalid read args: %u @ %u", p->label, len, offset));
66-
goto out;
67-
}
68-
if ((eres = spi_flash_read(p->address + offset, dst, len)) != ESP_OK) {
64+
if ((eres = esp_partition_read(p, offset, dst, len)) != ESP_OK) {
6965
res = MGOS_VFS_DEV_ERR_IO;
7066
goto out;
7167
}
@@ -81,11 +77,7 @@ static enum mgos_vfs_dev_err esp32_vfs_dev_partition_write(
8177
esp_err_t eres = ESP_OK;
8278
enum mgos_vfs_dev_err res = MGOS_VFS_DEV_ERR_INVAL;
8379
const esp_partition_t *p = (esp_partition_t *) dev->dev_data;
84-
if (len > p->size || len + len > p->address + p->size) {
85-
LOG(LL_ERROR, ("%s: invalid write args: %u @ %u", p->label, len, offset));
86-
goto out;
87-
}
88-
if ((eres = spi_flash_write(p->address + offset, src, len)) != ESP_OK) {
80+
if ((eres = esp_partition_write(p, offset, src, len)) != ESP_OK) {
8981
res = MGOS_VFS_DEV_ERR_IO;
9082
goto out;
9183
}
@@ -101,12 +93,7 @@ static enum mgos_vfs_dev_err esp32_vfs_dev_partition_erase(
10193
esp_err_t eres = ESP_OK;
10294
enum mgos_vfs_dev_err res = MGOS_VFS_DEV_ERR_INVAL;
10395
const esp_partition_t *p = (esp_partition_t *) dev->dev_data;
104-
if (len > p->size || offset + len > p->address + p->size ||
105-
offset % SPI_FLASH_SEC_SIZE != 0 || len % SPI_FLASH_SEC_SIZE != 0) {
106-
LOG(LL_ERROR, ("Invalid erase args: %u @ %u", len, offset));
107-
goto out;
108-
}
109-
if ((eres = spi_flash_erase_range(p->address + offset, len)) != ESP_OK) {
96+
if ((eres = esp_partition_erase_range(p, offset, len)) != ESP_OK) {
11097
res = MGOS_VFS_DEV_ERR_IO;
11198
goto out;
11299
}

0 commit comments

Comments
 (0)