mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-19 23:22:16 +03:00
Fix ESP.getSketchSize, add ESP.getSketchMD5 (#2158)
* return true sketch size using ESP.getSketchSize() https://github.com/esp8266/Arduino/issues/2153 add MD5 for current binary ESP.getSketchMD5() * Simplify ESP.getSketchSize, fix ESP.getSketchMD5
This commit is contained in:
parent
44d27228c5
commit
1640cc302d
@ -23,6 +23,7 @@
|
||||
#include "eboot_command.h"
|
||||
#include <memory>
|
||||
#include "interrupts.h"
|
||||
#include "MD5Builder.h"
|
||||
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
@ -443,7 +444,7 @@ uint32_t EspClass::getSketchSize() {
|
||||
DEBUG_SERIAL.printf("section=%u size=%u pos=%u\r\n", section_index, section_header.size, pos);
|
||||
#endif
|
||||
}
|
||||
result = pos;
|
||||
result = (pos + 16) & ~15;
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -519,3 +520,33 @@ bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size) {
|
||||
ets_isr_unmask(FLASH_INT_MASK);
|
||||
return rc == 0;
|
||||
}
|
||||
|
||||
String EspClass::getSketchMD5()
|
||||
{
|
||||
static String result;
|
||||
if (result.length()) {
|
||||
return result;
|
||||
}
|
||||
uint32_t lengthLeft = getSketchSize();
|
||||
const size_t bufSize = 512;
|
||||
std::unique_ptr<uint8_t[]> buf(new uint8_t[bufSize]);
|
||||
uint32_t offset = 0;
|
||||
if(!buf.get()) {
|
||||
return String();
|
||||
}
|
||||
MD5Builder md5;
|
||||
md5.begin();
|
||||
while( lengthLeft > 0) {
|
||||
size_t readBytes = (lengthLeft < bufSize) ? lengthLeft : bufSize;
|
||||
if (!flashRead(offset, reinterpret_cast<uint32_t*>(buf.get()), (readBytes + 3) & ~3)) {
|
||||
return String();
|
||||
}
|
||||
md5.add(buf.get(), readBytes);
|
||||
lengthLeft -= readBytes;
|
||||
offset += readBytes;
|
||||
}
|
||||
md5.calculate();
|
||||
result = md5.toString();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -133,6 +133,7 @@ class EspClass {
|
||||
bool flashRead(uint32_t offset, uint32_t *data, size_t size);
|
||||
|
||||
uint32_t getSketchSize();
|
||||
String getSketchMD5();
|
||||
uint32_t getFreeSketchSpace();
|
||||
bool updateSketch(Stream& in, uint32_t size, bool restartOnFail = false, bool restartOnSuccess = true);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user