Skip to content

Commit cf9175b

Browse files
author
Jeroen88
committed
Fixed flash size check and added SPIFFS size check
1 parent 5668927 commit cf9175b

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

libraries/HTTPUpdate/src/HTTPUpdate.cpp

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ String HTTPUpdate::getLastErrorString(void)
118118
return "Verify Bin Header Failed";
119119
case HTTP_UE_BIN_FOR_WRONG_FLASH:
120120
return "New Binary Does Not Fit Flash Size";
121+
case HTTP_UE_NO_PARTITION:
122+
return "Partition Could Not be Found";
121123
}
122124

123125
return String();
@@ -229,14 +231,25 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
229231
if(len > 0) {
230232
bool startUpdate = true;
231233
if(spiffs) {
232-
// To do size_t spiffsSize = ((size_t) &_SPIFFS_end - (size_t) &_SPIFFS_start);
233-
// To do if(len > (int) spiffsSize) {
234-
// To do log_e("spiffsSize to low (%d) needed: %d\n", spiffsSize, len);
235-
// To do startUpdate = false;
236-
// To do }
234+
const esp_partition_t* _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL);
235+
if(!_partition){
236+
_lastError = HTTP_UE_NO_PARTITION;
237+
return HTTP_UPDATE_FAILED;
238+
}
239+
240+
if(len > _partition->size) {
241+
log_e("spiffsSize to low (%d) needed: %d\n", _partition->size, len);
242+
startUpdate = false;
243+
}
237244
} else {
238-
if(len > (int) ESP.getFreeSketchSpace()) {
239-
log_e("FreeSketchSpace to low (%d) needed: %d\n", ESP.getFreeSketchSpace(), len);
245+
const esp_partition_t* _partition = esp_ota_get_next_update_partition(NULL);
246+
if(!_partition){
247+
_lastError = HTTP_UE_NO_PARTITION;
248+
return HTTP_UPDATE_FAILED;
249+
}
250+
251+
if(len > _partition->size) {
252+
log_e("FreeSketchSpace to low (%d) needed: %d\n", _partition->size, len);
240253
startUpdate = false;
241254
}
242255
}
@@ -366,6 +379,10 @@ bool HTTPUpdate::runUpdate(Stream& in, uint32_t size, String md5, int command)
366379
}
367380
}
368381

382+
// To do: the SHA256 could be checked if the server sends it
383+
384+
delay(0);
385+
369386
if(Update.writeStream(in) != size) {
370387
_lastError = Update.getError();
371388
Update.printError(error);

libraries/HTTPUpdate/src/HTTPUpdate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#define HTTP_UE_SERVER_FAULTY_MD5 (-105)
4343
#define HTTP_UE_BIN_VERIFY_HEADER_FAILED (-106)
4444
#define HTTP_UE_BIN_FOR_WRONG_FLASH (-107)
45+
#define HTTP_UE_NO_PARTITION (-108)
4546

4647
enum HTTPUpdateResult {
4748
HTTP_UPDATE_FAILED,

0 commit comments

Comments
 (0)