Skip to content

Commit e067a61

Browse files
committed
SPIFFS fix for ota sequence correct
1 parent dfb1779 commit e067a61

File tree

2 files changed

+35
-13
lines changed

2 files changed

+35
-13
lines changed

src/esp32FOTA.cpp

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,27 @@ bool esp32FOTA::execOTA()
473473
return ret;
474474
}
475475

476+
// OTA Logic
477+
bool esp32FOTA::execSPIFFSOTA()
478+
{
479+
bool ret;
480+
setupStream();
481+
482+
if( !_flashFileSystemUrl.isEmpty() ) { // a data partition was specified in the json manifest, handle the spiffs partition first
483+
if( _fs ) { // Possible risk of overwriting certs and signatures, cancel flashing!
484+
log_e("Cowardly refusing to overwrite U_SPIFFS with %s. Use setCertFileSystem(nullptr) along with setPubKey()/setCAPem() to enable this feature.", _flashFileSystemUrl);
485+
return false;
486+
} else {
487+
log_i("Will check if U_SPIFFS needs updating");
488+
ret = execOTA( U_SPIFFS, false );
489+
}
490+
} else {
491+
log_i("This update is for U_FLASH only");
492+
}
493+
stopStream();
494+
return ret;
495+
}
496+
476497

477498
bool esp32FOTA::execOTA( int partition, bool restart_after )
478499
{
@@ -855,48 +876,48 @@ String esp32FOTA::getDeviceID()
855876

856877

857878
// Force a firmware update regardless on current version
858-
void esp32FOTA::forceUpdate(const char* firmwareURL, bool validate )
879+
bool esp32FOTA::forceUpdate(const char* firmwareURL, bool validate )
859880
{
860881
_firmwareUrl = firmwareURL;
861882
_cfg.check_sig = validate;
862-
execOTA();
883+
return execOTA();
863884
}
864885

865886
// Force a firmware update regardless on current version
866-
void esp32FOTA::forceUpdateSPIFFS(const char* firmwareURL, bool validate )
887+
bool esp32FOTA::forceUpdateSPIFFS(const char* firmwareURL, bool validate )
867888
{
868889
_firmwareUrl = firmwareURL;
869890
_flashFileSystemUrl = firmwareURL;
870891
_cfg.check_sig = validate;
871-
execOTA();
892+
return execSPIFFSOTA();
872893
}
873894

874895

875-
void esp32FOTA::forceUpdate(const char* firmwareHost, uint16_t firmwarePort, const char* firmwarePath, bool validate )
896+
bool esp32FOTA::forceUpdate(const char* firmwareHost, uint16_t firmwarePort, const char* firmwarePath, bool validate )
876897
{
877898
static String firmwareURL("http");
878899
if ( firmwarePort == 443 || firmwarePort == 4433 ) firmwareURL += "s";
879900
firmwareURL += String(firmwareHost);
880901
firmwareURL += ":";
881902
firmwareURL += String(firmwarePort);
882903
firmwareURL += firmwarePath;
883-
forceUpdate( firmwareURL.c_str(), validate );
904+
return forceUpdate( firmwareURL.c_str(), validate );
884905
}
885906

886907

887-
void esp32FOTA::forceUpdate(bool validate )
908+
bool esp32FOTA::forceUpdate(bool validate )
888909
{
889910
// Forces an update from a manifest, ignoring the version check
890911
if(!execHTTPcheck()) {
891912
if (!_firmwareUrl) {
892913
// execHTTPcheck returns false when the manifest is malformed or when the version isn't
893914
// an upgrade. If _firmwareUrl isn't set we can't force an upgrade.
894915
log_e("forceUpdate called, but unable to get _firmwareUrl from manifest via execHTTPcheck.");
895-
return;
916+
return false;
896917
}
897918
}
898919
_cfg.check_sig = validate;
899-
execOTA();
920+
return execOTA();
900921
}
901922

902923

src/esp32FOTA.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,15 +243,16 @@ class esp32FOTA
243243
template <typename T> void setPubKey( T* asset ) { _cfg.pub_key = (CryptoAsset*)asset; _cfg.check_sig = true; }
244244
template <typename T> void setRootCA( T* asset ) { _cfg.root_ca = (CryptoAsset*)asset; _cfg.unsafe = false; }
245245

246-
void forceUpdate(const char* firmwareHost, uint16_t firmwarePort, const char* firmwarePath, bool validate );
247-
void forceUpdate(const char* firmwareURL, bool validate );
248-
void forceUpdate(bool validate );
246+
bool forceUpdate(const char* firmwareHost, uint16_t firmwarePort, const char* firmwarePath, bool validate );
247+
bool forceUpdate(const char* firmwareURL, bool validate );
248+
bool forceUpdate(bool validate );
249249

250-
void forceUpdateSPIFFS(const char* firmwareURL, bool validate );
250+
bool forceUpdateSPIFFS(const char* firmwareURL, bool validate );
251251

252252
void handle();
253253

254254
bool execOTA();
255+
bool execSPIFFSOTA();
255256
bool execOTA( int partition, bool restart_after = true );
256257
bool execHTTPcheck();
257258

0 commit comments

Comments
 (0)