Skip to content

Commit

Permalink
SPIFFS fix for ota sequence correct
Browse files Browse the repository at this point in the history
  • Loading branch information
gb88 committed Jul 13, 2023
1 parent dfb1779 commit e067a61
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
39 changes: 30 additions & 9 deletions src/esp32FOTA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,27 @@ bool esp32FOTA::execOTA()
return ret;
}

// OTA Logic
bool esp32FOTA::execSPIFFSOTA()
{
bool ret;
setupStream();

if( !_flashFileSystemUrl.isEmpty() ) { // a data partition was specified in the json manifest, handle the spiffs partition first
if( _fs ) { // Possible risk of overwriting certs and signatures, cancel flashing!
log_e("Cowardly refusing to overwrite U_SPIFFS with %s. Use setCertFileSystem(nullptr) along with setPubKey()/setCAPem() to enable this feature.", _flashFileSystemUrl);
return false;
} else {
log_i("Will check if U_SPIFFS needs updating");
ret = execOTA( U_SPIFFS, false );
}
} else {
log_i("This update is for U_FLASH only");
}
stopStream();
return ret;
}


bool esp32FOTA::execOTA( int partition, bool restart_after )
{
Expand Down Expand Up @@ -855,48 +876,48 @@ String esp32FOTA::getDeviceID()


// Force a firmware update regardless on current version
void esp32FOTA::forceUpdate(const char* firmwareURL, bool validate )
bool esp32FOTA::forceUpdate(const char* firmwareURL, bool validate )
{
_firmwareUrl = firmwareURL;
_cfg.check_sig = validate;
execOTA();
return execOTA();
}

// Force a firmware update regardless on current version
void esp32FOTA::forceUpdateSPIFFS(const char* firmwareURL, bool validate )
bool esp32FOTA::forceUpdateSPIFFS(const char* firmwareURL, bool validate )
{
_firmwareUrl = firmwareURL;
_flashFileSystemUrl = firmwareURL;
_cfg.check_sig = validate;
execOTA();
return execSPIFFSOTA();
}


void esp32FOTA::forceUpdate(const char* firmwareHost, uint16_t firmwarePort, const char* firmwarePath, bool validate )
bool esp32FOTA::forceUpdate(const char* firmwareHost, uint16_t firmwarePort, const char* firmwarePath, bool validate )
{
static String firmwareURL("http");
if ( firmwarePort == 443 || firmwarePort == 4433 ) firmwareURL += "s";
firmwareURL += String(firmwareHost);
firmwareURL += ":";
firmwareURL += String(firmwarePort);
firmwareURL += firmwarePath;
forceUpdate( firmwareURL.c_str(), validate );
return forceUpdate( firmwareURL.c_str(), validate );
}


void esp32FOTA::forceUpdate(bool validate )
bool esp32FOTA::forceUpdate(bool validate )
{
// Forces an update from a manifest, ignoring the version check
if(!execHTTPcheck()) {
if (!_firmwareUrl) {
// execHTTPcheck returns false when the manifest is malformed or when the version isn't
// an upgrade. If _firmwareUrl isn't set we can't force an upgrade.
log_e("forceUpdate called, but unable to get _firmwareUrl from manifest via execHTTPcheck.");
return;
return false;
}
}
_cfg.check_sig = validate;
execOTA();
return execOTA();
}


Expand Down
9 changes: 5 additions & 4 deletions src/esp32FOTA.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,16 @@ class esp32FOTA
template <typename T> void setPubKey( T* asset ) { _cfg.pub_key = (CryptoAsset*)asset; _cfg.check_sig = true; }
template <typename T> void setRootCA( T* asset ) { _cfg.root_ca = (CryptoAsset*)asset; _cfg.unsafe = false; }

void forceUpdate(const char* firmwareHost, uint16_t firmwarePort, const char* firmwarePath, bool validate );
void forceUpdate(const char* firmwareURL, bool validate );
void forceUpdate(bool validate );
bool forceUpdate(const char* firmwareHost, uint16_t firmwarePort, const char* firmwarePath, bool validate );
bool forceUpdate(const char* firmwareURL, bool validate );
bool forceUpdate(bool validate );

void forceUpdateSPIFFS(const char* firmwareURL, bool validate );
bool forceUpdateSPIFFS(const char* firmwareURL, bool validate );

void handle();

bool execOTA();
bool execSPIFFSOTA();
bool execOTA( int partition, bool restart_after = true );
bool execHTTPcheck();

Expand Down

0 comments on commit e067a61

Please sign in to comment.