Skip to content

Commit

Permalink
fixing OTA on partition just at the end of the flash
Browse files Browse the repository at this point in the history
  • Loading branch information
kohait00 committed Oct 25, 2023
1 parent 8fc8f3f commit c62e4b5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions components/app_update/esp_ota_ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ esp_err_t esp_ota_write(esp_ota_handle_t handle, const void *data, size_t size)
uint32_t first_sector = it->wrote_size / SPI_FLASH_SEC_SIZE;
uint32_t last_sector = (it->wrote_size + size) / SPI_FLASH_SEC_SIZE;

if(last_sector * SPI_FLASH_SEC_SIZE >= it->part->size)
{
//special case of having arrived passed the end of the flash, so move to the real last sector
//it probably has been erased previously, if last_sector==first_sector
last_sector = (it->part->size / SPI_FLASH_SEC_SIZE) - 1;
}

ret = ESP_OK;
if ((it->wrote_size % SPI_FLASH_SEC_SIZE) == 0) {
ret = esp_partition_erase_range(it->part, it->wrote_size, ((last_sector - first_sector) + 1) * SPI_FLASH_SEC_SIZE);
Expand Down

0 comments on commit c62e4b5

Please sign in to comment.