Skip to content

Commit 4d7b007

Browse files
committed
Check if board partition table is compatible with OTA before starting
1 parent 90c9375 commit 4d7b007

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

Diff for: src/Arduino_ESP32_OTA.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ Arduino_ESP32_OTA::Error Arduino_ESP32_OTA::begin()
7171

7272
/* ... initialize CRC ... */
7373
_crc32 = 0xFFFFFFFF;
74+
75+
if(!isCapable()) {
76+
DEBUG_ERROR("%s: board is not capable to perform OTA", __FUNCTION__);
77+
return Error::NoOtaStorage;
78+
}
7479

7580
if(!Update.begin(UPDATE_SIZE_UNKNOWN)) {
7681
DEBUG_ERROR("%s: failed to initialize flash update", __FUNCTION__);
@@ -279,3 +284,10 @@ void Arduino_ESP32_OTA::reset()
279284
{
280285
ESP.restart();
281286
}
287+
288+
bool Arduino_ESP32_OTA::isCapable()
289+
{
290+
const esp_partition_t * ota_0 = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_0, NULL);
291+
const esp_partition_t * ota_1 = esp_partition_find_first(ESP_PARTITION_TYPE_APP, ESP_PARTITION_SUBTYPE_APP_OTA_1, NULL);
292+
return ((ota_0 != nullptr) && (ota_1 != nullptr));
293+
}

Diff for: src/Arduino_ESP32_OTA.h

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class Arduino_ESP32_OTA
8787
void write_byte_to_flash(uint8_t data);
8888
Arduino_ESP32_OTA::Error update();
8989
void reset();
90+
static bool isCapable();
9091

9192
private:
9293

0 commit comments

Comments
 (0)