Skip to content

Commit

Permalink
Check if board partition table is compatible with OTA before starting
Browse files Browse the repository at this point in the history
  • Loading branch information
pennam committed Oct 16, 2023
1 parent 90c9375 commit 4d7b007
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Arduino_ESP32_OTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ Arduino_ESP32_OTA::Error Arduino_ESP32_OTA::begin()

/* ... initialize CRC ... */
_crc32 = 0xFFFFFFFF;

if(!isCapable()) {
DEBUG_ERROR("%s: board is not capable to perform OTA", __FUNCTION__);
return Error::NoOtaStorage;
}

if(!Update.begin(UPDATE_SIZE_UNKNOWN)) {
DEBUG_ERROR("%s: failed to initialize flash update", __FUNCTION__);
Expand Down Expand Up @@ -279,3 +284,10 @@ void Arduino_ESP32_OTA::reset()
{
ESP.restart();
}

bool Arduino_ESP32_OTA::isCapable()
{
const esp_partition_t * ota_0 = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_0, NULL);
const esp_partition_t * ota_1 = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL);
return ((ota_0 != nullptr) && (ota_1 != nullptr));
}
1 change: 1 addition & 0 deletions src/Arduino_ESP32_OTA.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class Arduino_ESP32_OTA
void write_byte_to_flash(uint8_t data);
Arduino_ESP32_OTA::Error update();
void reset();
static bool isCapable();

private:

Expand Down

0 comments on commit 4d7b007

Please sign in to comment.