Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libraries/ArduinoOTA/src/ArduinoOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
90 changes: 73 additions & 17 deletions libraries/HTTPUpdate/src/HTTPUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,59 @@ 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 &currentVersion, HTTPUpdateRequestCB requestCB) {
return handleUpdate(httpClient, currentVersion, U_FLASHFS, requestCB);
}

HTTPUpdateResult HTTPUpdate::updateSpiffs(HTTPClient &httpClient, const String &currentVersion, HTTPUpdateRequestCB requestCB) {
return handleUpdate(httpClient, currentVersion, true, requestCB);
return handleUpdate(httpClient, currentVersion, U_SPIFFS, requestCB);
}

HTTPUpdateResult HTTPUpdate::updateFatfs(HTTPClient &httpClient, const String &currentVersion, HTTPUpdateRequestCB requestCB) {
return handleUpdate(httpClient, currentVersion, U_FATFS, requestCB);
}

HTTPUpdateResult HTTPUpdate::updateLittlefs(HTTPClient &httpClient, const String &currentVersion, HTTPUpdateRequestCB requestCB) {
return handleUpdate(httpClient, currentVersion, U_LITTLEFS, requestCB);
}

HTTPUpdateResult HTTPUpdate::updateFs(NetworkClient &client, const String &url, const String &currentVersion, 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 &currentVersion, HTTPUpdateRequestCB requestCB) {
HTTPClient http;
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 &currentVersion, 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 &currentVersion, 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 &currentVersion, HTTPUpdateRequestCB requestCB) {
return handleUpdate(httpClient, currentVersion, false, requestCB);
return handleUpdate(httpClient, currentVersion, U_FLASH, requestCB);
}

HTTPUpdateResult
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -158,7 +194,7 @@ String getSketchSHA256() {
* @param currentVersion const char *
* @return HTTPUpdateResult
*/
HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String &currentVersion, bool spiffs, HTTPUpdateRequestCB requestCB) {
HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String &currentVersion, uint8_t type, HTTPUpdateRequestCB requestCB) {

HTTPUpdateResult ret = HTTP_UPDATE_FAILED;

Expand Down Expand Up @@ -187,8 +223,14 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String &curren
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");
}
Expand Down Expand Up @@ -251,8 +293,24 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String &curren
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;
Expand Down Expand Up @@ -291,17 +349,15 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String &curren

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) {
Expand Down Expand Up @@ -341,7 +397,7 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient &http, const String &curren
_cbEnd();
}

if (_rebootOnUpdate && !spiffs) {
if (_rebootOnUpdate && type == U_FLASH) {
ESP.restart();
}

Expand Down
8 changes: 7 additions & 1 deletion libraries/HTTPUpdate/src/HTTPUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,17 @@ class HTTPUpdate {
NetworkClient &client, const String &host, uint16_t port, const String &uri = "/", const String &currentVersion = "", HTTPUpdateRequestCB requestCB = NULL
);

t_httpUpdate_return updateFs(NetworkClient &client, const String &url, const String &currentVersion = "", HTTPUpdateRequestCB requestCB = NULL);
t_httpUpdate_return updateSpiffs(NetworkClient &client, const String &url, const String &currentVersion = "", HTTPUpdateRequestCB requestCB = NULL);
t_httpUpdate_return updateFatfs(NetworkClient &client, const String &url, const String &currentVersion = "", HTTPUpdateRequestCB requestCB = NULL);
t_httpUpdate_return updateLittlefs(NetworkClient &client, const String &url, const String &currentVersion = "", HTTPUpdateRequestCB requestCB = NULL);

t_httpUpdate_return update(HTTPClient &httpClient, const String &currentVersion = "", HTTPUpdateRequestCB requestCB = NULL);

t_httpUpdate_return updateFs(HTTPClient &httpClient, const String &currentVersion = "", HTTPUpdateRequestCB requestCB = NULL);
t_httpUpdate_return updateSpiffs(HTTPClient &httpClient, const String &currentVersion = "", HTTPUpdateRequestCB requestCB = NULL);
t_httpUpdate_return updateFatfs(HTTPClient &httpClient, const String &currentVersion = "", HTTPUpdateRequestCB requestCB = NULL);
t_httpUpdate_return updateLittlefs(HTTPClient &httpClient, const String &currentVersion = "", HTTPUpdateRequestCB requestCB = NULL);

// Notification callbacks
void onStart(HTTPUpdateStartCB cbOnStart) {
Expand All @@ -122,7 +128,7 @@ class HTTPUpdate {
String getLastErrorString(void);

protected:
t_httpUpdate_return handleUpdate(HTTPClient &http, const String &currentVersion, bool spiffs = false, HTTPUpdateRequestCB requestCB = NULL);
t_httpUpdate_return handleUpdate(HTTPClient &http, const String &currentVersion, 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
Expand Down
2 changes: 1 addition & 1 deletion libraries/HTTPUpdateServer/src/HTTPUpdateServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -36,7 +36,6 @@ espsecure.py encrypt_flash_data = runs the idf encryption function to make a en

#include <WiFi.h>
#include <NetworkClient.h>
#include <SPIFFS.h>
#include <Update.h>
#include <WebServer.h>
#include <ESPmDNS.h>
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 6 additions & 4 deletions libraries/Update/src/Update.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down
43 changes: 33 additions & 10 deletions libraries/Update/src/Updater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -452,7 +475,7 @@ bool UpdateClass::_verifyHeader(uint8_t data) {
return false;
}
return true;
} else if (_command == U_SPIFFS) {
} else {
return true;
}
return false;
Expand All @@ -471,7 +494,7 @@ bool UpdateClass::_verifyEnd() {
}
_reset();
return true;
} else if (_command == U_SPIFFS) {
} else {
_reset();
return true;
}
Expand Down
Loading