Skip to content

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
wants to merge 10 commits into from
Closed

Add getSketchMD5() to ESP.h and ESP.cpp #2164

wants to merge 10 commits into from

Conversation

Jeroen88
Copy link
Contributor

@Jeroen88 Jeroen88 commented Dec 7, 2018

With this change it is possible to calculate the MD5 hash of the running sketch. This can be used to create a unique 'fingerprint' of the running sketch.

uint32_t lengthLeft = getSketchSize();

const esp_partition_t *running = esp_ota_get_running_partition();
if (!running) return String();
Copy link
Member

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.

std::unique_ptr<uint8_t[]> buf(new uint8_t[bufSize]);
uint32_t offset = 0;
if(!buf.get()) {
return String();
Copy link
Member

Choose a reason for hiding this comment

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

log_e here also

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();
Copy link
Member

Choose a reason for hiding this comment

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

log_e here also

@Jeroen88
Copy link
Contributor Author

Replaced by PR #2176.

@Jeroen88 Jeroen88 closed this Dec 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants