-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Add getSketchMD5() to ESP.h and ESP.cpp #2164
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
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
5668927
Fix error in PR #2048: if ::available() is called before ::connect() …
ea44937
Abort update if http.begin() returns false. Fix a typo in httpUpdate.ino
aa1ab4c
Merge branch 'bugfix/HTTPUpdate' into development
cf9175b
Fixed flash size check and added SPIFFS size check
d22f225
Merge branch 'bugfix/HTTPUpdate2' into development
572b013
Merge branch 'master' into bugfix/HTTPUpdate2
9e629e7
Rewriting ESP.getFreeSketchSpace(), moving code from HTTPUpdate.cpp
7d1276a
Merge branch 'bugfix/HTTPUpdate2' into development
067b82c
Merge branch 'master' into development
0902ffa
Add getSketchMD5() to ESP.h and ESP.cpp
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
extern "C" { | ||
#include <esp_image_format.h> | ||
} | ||
#include <MD5Builder.h> | ||
|
||
/** | ||
* User-defined Literals | ||
|
@@ -158,16 +159,48 @@ static uint32_t sketchSize(sketchSize_t response) { | |
data.start_addr = running_pos.offset; | ||
esp_image_verify(ESP_IMAGE_VERIFY, &running_pos, &data); | ||
if (response) { | ||
return running_pos.size - data.image_len; | ||
return running_pos.size - data.image_len; | ||
} else { | ||
return data.image_len; | ||
return data.image_len; | ||
} | ||
} | ||
|
||
uint32_t EspClass::getSketchSize () { | ||
return sketchSize(SKETCH_SIZE_TOTAL); | ||
} | ||
|
||
String EspClass::getSketchMD5() | ||
{ | ||
static String result; | ||
if (result.length()) { | ||
return result; | ||
} | ||
uint32_t lengthLeft = getSketchSize(); | ||
|
||
const esp_partition_t *running = esp_ota_get_running_partition(); | ||
if (!running) return String(); | ||
const size_t bufSize = SPI_FLASH_SEC_SIZE; | ||
std::unique_ptr<uint8_t[]> buf(new uint8_t[bufSize]); | ||
uint32_t offset = 0; | ||
if(!buf.get()) { | ||
return String(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
MD5Builder md5; | ||
md5.begin(); | ||
while( lengthLeft > 0) { | ||
size_t readBytes = (lengthLeft < bufSize) ? lengthLeft : bufSize; | ||
if (!ESP.flashRead(running->address + offset, reinterpret_cast<uint32_t*>(buf.get()), (readBytes + 3) & ~3)) { | ||
return String(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
md5.add(buf.get(), readBytes); | ||
lengthLeft -= readBytes; | ||
offset += readBytes; | ||
} | ||
md5.calculate(); | ||
result = md5.toString(); | ||
return result; | ||
} | ||
|
||
uint32_t EspClass::getFreeSketchSpace () { | ||
const esp_partition_t* _partition = esp_ota_get_next_update_partition(NULL); | ||
if(!_partition){ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please do not use one liners like this :) also please add some
log_e
messages on why the call failed. It will be helpful if something goes wrong.