diff --git a/libraries/ArduinoOTA/src/ArduinoOTA.cpp b/libraries/ArduinoOTA/src/ArduinoOTA.cpp index 308660c3ce7..c5214171012 100644 --- a/libraries/ArduinoOTA/src/ArduinoOTA.cpp +++ b/libraries/ArduinoOTA/src/ArduinoOTA.cpp @@ -182,7 +182,7 @@ String ArduinoOTAClass::readStringUntil(char end) { void ArduinoOTAClass::_onRx() { if (_state == OTA_IDLE) { int cmd = parseInt(); - if (cmd != U_FLASH && cmd != U_SPIFFS) { + if (cmd != U_FLASH && cmd != U_FLASHFS) { return; } _cmd = cmd; diff --git a/libraries/HTTPUpdate/src/HTTPUpdate.cpp b/libraries/HTTPUpdate/src/HTTPUpdate.cpp index b463ffe2e83..4159ad0b919 100644 --- a/libraries/HTTPUpdate/src/HTTPUpdate.cpp +++ b/libraries/HTTPUpdate/src/HTTPUpdate.cpp @@ -52,11 +52,31 @@ HTTPUpdateResult HTTPUpdate::update(NetworkClient &client, const String &url, co if (!http.begin(client, url)) { return HTTP_UPDATE_FAILED; } - return handleUpdate(http, currentVersion, false, requestCB); + return handleUpdate(http, currentVersion, U_FLASH, requestCB); +} + +HTTPUpdateResult HTTPUpdate::updateFs(HTTPClient &httpClient, const String ¤tVersion, HTTPUpdateRequestCB requestCB) { + return handleUpdate(httpClient, currentVersion, U_FLASHFS, requestCB); } HTTPUpdateResult HTTPUpdate::updateSpiffs(HTTPClient &httpClient, const String ¤tVersion, HTTPUpdateRequestCB requestCB) { - return handleUpdate(httpClient, currentVersion, true, requestCB); + return handleUpdate(httpClient, currentVersion, U_SPIFFS, requestCB); +} + +HTTPUpdateResult HTTPUpdate::updateFatfs(HTTPClient &httpClient, const String ¤tVersion, HTTPUpdateRequestCB requestCB) { + return handleUpdate(httpClient, currentVersion, U_FATFS, requestCB); +} + +HTTPUpdateResult HTTPUpdate::updateLittlefs(HTTPClient &httpClient, const String ¤tVersion, HTTPUpdateRequestCB requestCB) { + return handleUpdate(httpClient, currentVersion, U_LITTLEFS, requestCB); +} + +HTTPUpdateResult HTTPUpdate::updateFs(NetworkClient &client, const String &url, const String ¤tVersion, HTTPUpdateRequestCB requestCB) { + HTTPClient http; + if (!http.begin(client, url)) { + return HTTP_UPDATE_FAILED; + } + return handleUpdate(http, currentVersion, U_FLASHFS, requestCB); } HTTPUpdateResult HTTPUpdate::updateSpiffs(NetworkClient &client, const String &url, const String ¤tVersion, HTTPUpdateRequestCB requestCB) { @@ -64,11 +84,27 @@ HTTPUpdateResult HTTPUpdate::updateSpiffs(NetworkClient &client, const String &u if (!http.begin(client, url)) { return HTTP_UPDATE_FAILED; } - return handleUpdate(http, currentVersion, true, requestCB); + return handleUpdate(http, currentVersion, U_SPIFFS, requestCB); +} + +HTTPUpdateResult HTTPUpdate::updateFatfs(NetworkClient &client, const String &url, const String ¤tVersion, HTTPUpdateRequestCB requestCB) { + HTTPClient http; + if (!http.begin(client, url)) { + return HTTP_UPDATE_FAILED; + } + return handleUpdate(http, currentVersion, U_FATFS, requestCB); +} + +HTTPUpdateResult HTTPUpdate::updateLittlefs(NetworkClient &client, const String &url, const String ¤tVersion, HTTPUpdateRequestCB requestCB) { + HTTPClient http; + if (!http.begin(client, url)) { + return HTTP_UPDATE_FAILED; + } + return handleUpdate(http, currentVersion, U_LITTLEFS, requestCB); } HTTPUpdateResult HTTPUpdate::update(HTTPClient &httpClient, const String ¤tVersion, HTTPUpdateRequestCB requestCB) { - return handleUpdate(httpClient, currentVersion, false, requestCB); + return handleUpdate(httpClient, currentVersion, U_FLASH, requestCB); } HTTPUpdateResult @@ -77,7 +113,7 @@ HTTPUpdateResult if (!http.begin(client, host, port, uri)) { return HTTP_UPDATE_FAILED; } - return handleUpdate(http, currentVersion, false, requestCB); + return handleUpdate(http, currentVersion, U_FLASH, requestCB); } /** @@ -158,7 +194,7 @@ String getSketchSHA256() { * @param currentVersion const char * * @return HTTPUpdateResult */ -HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String ¤tVersion, bool spiffs, HTTPUpdateRequestCB requestCB) { +HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String ¤tVersion, uint8_t type, HTTPUpdateRequestCB requestCB) { HTTPUpdateResult ret = HTTP_UPDATE_FAILED; @@ -187,8 +223,14 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String ¤ http.addHeader("x-ESP32-chip-size", String(ESP.getFlashChipSize())); http.addHeader("x-ESP32-sdk-version", ESP.getSdkVersion()); - if (spiffs) { + if (type == U_SPIFFS) { http.addHeader("x-ESP32-mode", "spiffs"); + } else if (type == U_FATFS) { + http.addHeader("x-ESP32-mode", "fatfs"); + } else if (type == U_LITTLEFS) { + http.addHeader("x-ESP32-mode", "littlefs"); + } else if (type == U_FLASHFS) { + http.addHeader("x-ESP32-mode", "flashfs"); } else { http.addHeader("x-ESP32-mode", "sketch"); } @@ -251,8 +293,24 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String ¤ case HTTP_CODE_OK: ///< OK (Start Update) if (len > 0) { bool startUpdate = true; - if (spiffs) { - const esp_partition_t *_partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL); + if (type != U_FLASH) { + const esp_partition_t *_partition = NULL; + if (type == U_SPIFFS) { + _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL); + } else if (type == U_FATFS) { + _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL); + } else if (type == U_LITTLEFS) { + _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_LITTLEFS, NULL); + } else if (type == U_FLASHFS) { + _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL); + if (!_partition) { + _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL); + } + if (!_partition) { + _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_LITTLEFS, NULL); + } + } + if (!_partition) { _lastError = HTTP_UE_NO_PARTITION; return HTTP_UPDATE_FAILED; @@ -291,17 +349,15 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String ¤ delay(100); - int command; + int command = type; - if (spiffs) { - command = U_SPIFFS; - log_d("runUpdate spiffs...\n"); - } else { - command = U_FLASH; + if (type == U_FLASH) { log_d("runUpdate flash...\n"); + } else { + log_d("runUpdate file system...\n"); } - if (!spiffs) { + if (type == U_FLASH) { /* To do uint8_t buf[4]; if(tcp->peekBytes(&buf[0], 4) != 4) { @@ -341,7 +397,7 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String ¤ _cbEnd(); } - if (_rebootOnUpdate && !spiffs) { + if (_rebootOnUpdate && type == U_FLASH) { ESP.restart(); } diff --git a/libraries/HTTPUpdate/src/HTTPUpdate.h b/libraries/HTTPUpdate/src/HTTPUpdate.h index a48d1a89a3e..ad38701b948 100644 --- a/libraries/HTTPUpdate/src/HTTPUpdate.h +++ b/libraries/HTTPUpdate/src/HTTPUpdate.h @@ -98,11 +98,17 @@ class HTTPUpdate { NetworkClient &client, const String &host, uint16_t port, const String &uri = "/", const String ¤tVersion = "", HTTPUpdateRequestCB requestCB = NULL ); + t_httpUpdate_return updateFs(NetworkClient &client, const String &url, const String ¤tVersion = "", HTTPUpdateRequestCB requestCB = NULL); t_httpUpdate_return updateSpiffs(NetworkClient &client, const String &url, const String ¤tVersion = "", HTTPUpdateRequestCB requestCB = NULL); + t_httpUpdate_return updateFatfs(NetworkClient &client, const String &url, const String ¤tVersion = "", HTTPUpdateRequestCB requestCB = NULL); + t_httpUpdate_return updateLittlefs(NetworkClient &client, const String &url, const String ¤tVersion = "", HTTPUpdateRequestCB requestCB = NULL); t_httpUpdate_return update(HTTPClient &httpClient, const String ¤tVersion = "", HTTPUpdateRequestCB requestCB = NULL); + t_httpUpdate_return updateFs(HTTPClient &httpClient, const String ¤tVersion = "", HTTPUpdateRequestCB requestCB = NULL); t_httpUpdate_return updateSpiffs(HTTPClient &httpClient, const String ¤tVersion = "", HTTPUpdateRequestCB requestCB = NULL); + t_httpUpdate_return updateFatfs(HTTPClient &httpClient, const String ¤tVersion = "", HTTPUpdateRequestCB requestCB = NULL); + t_httpUpdate_return updateLittlefs(HTTPClient &httpClient, const String ¤tVersion = "", HTTPUpdateRequestCB requestCB = NULL); // Notification callbacks void onStart(HTTPUpdateStartCB cbOnStart) { @@ -122,7 +128,7 @@ class HTTPUpdate { String getLastErrorString(void); protected: - t_httpUpdate_return handleUpdate(HTTPClient &http, const String ¤tVersion, bool spiffs = false, HTTPUpdateRequestCB requestCB = NULL); + t_httpUpdate_return handleUpdate(HTTPClient &http, const String ¤tVersion, uint8_t type = U_FLASH, HTTPUpdateRequestCB requestCB = NULL); bool runUpdate(Stream &in, uint32_t size, String md5, int command = U_FLASH); // Set the error and potentially use a CB to notify the application diff --git a/libraries/HTTPUpdateServer/src/HTTPUpdateServer.h b/libraries/HTTPUpdateServer/src/HTTPUpdateServer.h index 952711bef66..d9e9b9ea2d5 100644 --- a/libraries/HTTPUpdateServer/src/HTTPUpdateServer.h +++ b/libraries/HTTPUpdateServer/src/HTTPUpdateServer.h @@ -122,7 +122,7 @@ class HTTPUpdateServer { Serial.printf("Update: %s\n", upload.filename.c_str()); } if (upload.name == "filesystem") { - if (!Update.begin(UPDATE_SIZE_UNKNOWN, U_SPIFFS)) { //Instead of SPIFFS.totalBytes(). Fix https://github.com/espressif/arduino-esp32/issues/9967 + if (!Update.begin(UPDATE_SIZE_UNKNOWN, U_FLASHFS)) { //Instead of SPIFFS.totalBytes(). Fix https://github.com/espressif/arduino-esp32/issues/9967 if (_serial_output) { Update.printError(Serial); } diff --git a/libraries/Update/examples/HTTP_Server_AES_OTA_Update/HTTP_Server_AES_OTA_Update.ino b/libraries/Update/examples/HTTP_Server_AES_OTA_Update/HTTP_Server_AES_OTA_Update.ino index 5af4f1bf9f4..f9216f678a5 100644 --- a/libraries/Update/examples/HTTP_Server_AES_OTA_Update/HTTP_Server_AES_OTA_Update.ino +++ b/libraries/Update/examples/HTTP_Server_AES_OTA_Update/HTTP_Server_AES_OTA_Update.ino @@ -18,7 +18,7 @@ defaults:- {if not set ie. "Update.setupCrypt();" } OTA_MODE options:- U_AES_DECRYPT_NONE decryption disabled, loads OTA image files as sent(plain) - U_AES_DECRYPT_AUTO auto loads both plain & encrypted OTA FLASH image files, and plain OTA SPIFFS image files + U_AES_DECRYPT_AUTO auto loads both plain & encrypted OTA FLASH image files, and plain OTA File System image files U_AES_DECRYPT_ON decrypts OTA image files https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/ @@ -36,7 +36,6 @@ espsecure.py encrypt_flash_data = runs the idf encryption function to make a en #include #include -#include #include #include #include @@ -145,7 +144,7 @@ void setupHttpUpdateServer() { if (upload.status == UPLOAD_FILE_START) { Serial.printf("Update: %s\n", upload.filename.c_str()); if (upload.name == "filesystem") { - if (!Update.begin(SPIFFS.totalBytes(), U_SPIFFS)) { //start with max available size + if (!Update.begin(UPDATE_SIZE_UNKNOWN, U_FLASHFS)) { //start with max available size Update.printError(Serial); } } else { diff --git a/libraries/Update/src/Update.h b/libraries/Update/src/Update.h index 9a4d3e02489..5f52e6b3b73 100644 --- a/libraries/Update/src/Update.h +++ b/libraries/Update/src/Update.h @@ -29,9 +29,12 @@ #define UPDATE_SIZE_UNKNOWN 0xFFFFFFFF -#define U_FLASH 0 -#define U_SPIFFS 100 -#define U_AUTH 200 +#define U_FLASH 0 +#define U_FLASHFS 100 +#define U_SPIFFS 101 +#define U_FATFS 102 +#define U_LITTLEFS 103 +#define U_AUTH 200 #define ENCRYPTED_BLOCK_SIZE 16 #define ENCRYPTED_TWEAK_BLOCK_SIZE 32 @@ -267,7 +270,6 @@ class UpdateClass { size_t _size; THandlerFunction_Progress _progress_callback; uint32_t _progress; - uint32_t _paroffset; uint32_t _command; const esp_partition_t *_partition; diff --git a/libraries/Update/src/Updater.cpp b/libraries/Update/src/Updater.cpp index 3b0c517431d..e9f39f729d3 100644 --- a/libraries/Update/src/Updater.cpp +++ b/libraries/Update/src/Updater.cpp @@ -75,7 +75,7 @@ UpdateClass::UpdateClass() #ifndef UPDATE_NOCRYPT _cryptKey(0), _cryptBuffer(0), #endif /* UPDATE_NOCRYPT */ - _buffer(0), _skipBuffer(0), _bufferLen(0), _size(0), _progress_callback(NULL), _progress(0), _paroffset(0), _command(U_FLASH), _partition(NULL) + _buffer(0), _skipBuffer(0), _bufferLen(0), _size(0), _progress_callback(NULL), _progress(0), _command(U_FLASH), _partition(NULL) #ifndef UPDATE_NOCRYPT , _cryptMode(U_AES_DECRYPT_AUTO), _cryptAddress(0), _cryptCfg(0xf) @@ -154,16 +154,39 @@ bool UpdateClass::begin(size_t size, int command, int ledPin, uint8_t ledOn, con } log_d("OTA Partition: %s", _partition->label); } else if (command == U_SPIFFS) { - _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, label); - _paroffset = 0; + _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL); + if (!_partition) { + _error = UPDATE_ERROR_NO_PARTITION; + return false; + } + log_d("SPIFFS Partition: %s", _partition->label); + } else if (command == U_FATFS) { + _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL); + if (!_partition) { + _error = UPDATE_ERROR_NO_PARTITION; + return false; + } + log_d("FATFS Partition: %s", _partition->label); + } else if (command == U_LITTLEFS) { + _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_LITTLEFS, NULL); + if (!_partition) { + _error = UPDATE_ERROR_NO_PARTITION; + return false; + } + log_d("LittleFS Partition: %s", _partition->label); + } else if (command == U_FLASHFS) { + _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL); if (!_partition) { _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_FAT, NULL); - _paroffset = 0x1000; //Offset for ffat, assuming size is already corrected - if (!_partition) { - _error = UPDATE_ERROR_NO_PARTITION; - return false; - } } + if (!_partition) { + _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_LITTLEFS, NULL); + } + if (!_partition) { + _error = UPDATE_ERROR_NO_PARTITION; + return false; + } + log_d("FS Partition: %s", _partition->label); } else { _error = UPDATE_ERROR_BAD_ARGUMENT; log_e("bad command %u", command); @@ -452,7 +475,7 @@ bool UpdateClass::_verifyHeader(uint8_t data) { return false; } return true; - } else if (_command == U_SPIFFS) { + } else { return true; } return false; @@ -471,7 +494,7 @@ bool UpdateClass::_verifyEnd() { } _reset(); return true; - } else if (_command == U_SPIFFS) { + } else { _reset(); return true; }