Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix HTTPUpdate flash size check and add SPIFFS size check #2161

Merged
merged 4 commits into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from 2 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
31 changes: 24 additions & 7 deletions libraries/HTTPUpdate/src/HTTPUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ String HTTPUpdate::getLastErrorString(void)
return "Verify Bin Header Failed";
case HTTP_UE_BIN_FOR_WRONG_FLASH:
return "New Binary Does Not Fit Flash Size";
case HTTP_UE_NO_PARTITION:
return "Partition Could Not be Found";
}

return String();
Expand Down Expand Up @@ -229,14 +231,25 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
if(len > 0) {
bool startUpdate = true;
if(spiffs) {
// To do size_t spiffsSize = ((size_t) &_SPIFFS_end - (size_t) &_SPIFFS_start);
// To do if(len > (int) spiffsSize) {
// To do log_e("spiffsSize to low (%d) needed: %d\n", spiffsSize, len);
// To do startUpdate = false;
// To do }
const esp_partition_t* _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL);
if(!_partition){
_lastError = HTTP_UE_NO_PARTITION;
return HTTP_UPDATE_FAILED;
}

if(len > _partition->size) {
log_e("spiffsSize to low (%d) needed: %d\n", _partition->size, len);
startUpdate = false;
}
} else {
if(len > (int) ESP.getFreeSketchSpace()) {
log_e("FreeSketchSpace to low (%d) needed: %d\n", ESP.getFreeSketchSpace(), len);
const esp_partition_t* _partition = esp_ota_get_next_update_partition(NULL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please move this logic to Esp.cpp and replace the one in ESP.getFreeSketchSpace. What is currently there makes no sense for any use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moving to ESP.cpp, replacing getFreeSketchSpace() with new code, in HTTUpdate.cpp calling getFreeSketchSpace() again.

if(!_partition){
_lastError = HTTP_UE_NO_PARTITION;
return HTTP_UPDATE_FAILED;
}

if(len > _partition->size) {
log_e("FreeSketchSpace to low (%d) needed: %d\n", _partition->size, len);
startUpdate = false;
}
}
Expand Down Expand Up @@ -366,6 +379,10 @@ bool HTTPUpdate::runUpdate(Stream& in, uint32_t size, String md5, int command)
}
}

// To do: the SHA256 could be checked if the server sends it

delay(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing...


if(Update.writeStream(in) != size) {
_lastError = Update.getError();
Update.printError(error);
Expand Down
1 change: 1 addition & 0 deletions libraries/HTTPUpdate/src/HTTPUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#define HTTP_UE_SERVER_FAULTY_MD5 (-105)
#define HTTP_UE_BIN_VERIFY_HEADER_FAILED (-106)
#define HTTP_UE_BIN_FOR_WRONG_FLASH (-107)
#define HTTP_UE_NO_PARTITION (-108)

enum HTTPUpdateResult {
HTTP_UPDATE_FAILED,
Expand Down
4 changes: 4 additions & 0 deletions libraries/WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,10 @@ int WiFiClient::peek()

int WiFiClient::available()
{
if(!_rxBuffer)
{
return 0;
}
int res = _rxBuffer->available();
if(_rxBuffer->failed()) {
log_e("%d", errno);
Expand Down