From 90c937580fcc5b8392f048aa3744a02c4e389054 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 16 Oct 2023 14:40:29 +0200 Subject: [PATCH 1/2] Fix typo --- src/Arduino_ESP32_OTA.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Arduino_ESP32_OTA.cpp b/src/Arduino_ESP32_OTA.cpp index 9839e0a..97d8a62 100644 --- a/src/Arduino_ESP32_OTA.cpp +++ b/src/Arduino_ESP32_OTA.cpp @@ -195,7 +195,7 @@ int Arduino_ESP32_OTA::download(const char * ota_url) return static_cast(Error::HttpResponse); } - /* Extract concent length from HTTP header. A typical entry looks like + /* Extract content length from HTTP header. A typical entry looks like * "Content-Length: 123456" */ char const * content_length_ptr = strstr(http_header.c_str(), "Content-Length"); From 4d7b0079ae938ec0cbf48404d4c92588d40c6787 Mon Sep 17 00:00:00 2001 From: pennam Date: Mon, 16 Oct 2023 14:41:44 +0200 Subject: [PATCH 2/2] Check if board partition table is compatible with OTA before starting --- src/Arduino_ESP32_OTA.cpp | 12 ++++++++++++ src/Arduino_ESP32_OTA.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/Arduino_ESP32_OTA.cpp b/src/Arduino_ESP32_OTA.cpp index 97d8a62..b6335b4 100644 --- a/src/Arduino_ESP32_OTA.cpp +++ b/src/Arduino_ESP32_OTA.cpp @@ -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__); @@ -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)); +} diff --git a/src/Arduino_ESP32_OTA.h b/src/Arduino_ESP32_OTA.h index 5062003..069d22b 100644 --- a/src/Arduino_ESP32_OTA.h +++ b/src/Arduino_ESP32_OTA.h @@ -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: