File tree Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Expand file tree Collapse file tree 2 files changed +36
-2
lines changed Original file line number Diff line number Diff line change 30
30
extern " C" {
31
31
#include < esp_image_format.h>
32
32
}
33
+ #include < MD5Builder.h>
33
34
34
35
/* *
35
36
* User-defined Literals
@@ -158,16 +159,48 @@ static uint32_t sketchSize(sketchSize_t response) {
158
159
data.start_addr = running_pos.offset ;
159
160
esp_image_verify (ESP_IMAGE_VERIFY, &running_pos, &data);
160
161
if (response) {
161
- return running_pos.size - data.image_len ;
162
+ return running_pos.size - data.image_len ;
162
163
} else {
163
- return data.image_len ;
164
+ return data.image_len ;
164
165
}
165
166
}
166
167
167
168
uint32_t EspClass::getSketchSize () {
168
169
return sketchSize (SKETCH_SIZE_TOTAL);
169
170
}
170
171
172
+ String EspClass::getSketchMD5 ()
173
+ {
174
+ static String result;
175
+ if (result.length ()) {
176
+ return result;
177
+ }
178
+ uint32_t lengthLeft = getSketchSize ();
179
+
180
+ const esp_partition_t *running = esp_ota_get_running_partition ();
181
+ if (!running) return String ();
182
+ const size_t bufSize = SPI_FLASH_SEC_SIZE;
183
+ std::unique_ptr<uint8_t []> buf (new uint8_t [bufSize]);
184
+ uint32_t offset = 0 ;
185
+ if (!buf.get ()) {
186
+ return String ();
187
+ }
188
+ MD5Builder md5;
189
+ md5.begin ();
190
+ while ( lengthLeft > 0 ) {
191
+ size_t readBytes = (lengthLeft < bufSize) ? lengthLeft : bufSize;
192
+ if (!ESP.flashRead (running->address + offset, reinterpret_cast <uint32_t *>(buf.get ()), (readBytes + 3 ) & ~3 )) {
193
+ return String ();
194
+ }
195
+ md5.add (buf.get (), readBytes);
196
+ lengthLeft -= readBytes;
197
+ offset += readBytes;
198
+ }
199
+ md5.calculate ();
200
+ result = md5.toString ();
201
+ return result;
202
+ }
203
+
171
204
uint32_t EspClass::getFreeSketchSpace () {
172
205
const esp_partition_t * _partition = esp_ota_get_next_update_partition (NULL );
173
206
if (!_partition){
Original file line number Diff line number Diff line change @@ -90,6 +90,7 @@ class EspClass
90
90
FlashMode_t magicFlashChipMode (uint8_t byte);
91
91
92
92
uint32_t getSketchSize ();
93
+ String getSketchMD5 ();
93
94
uint32_t getFreeSketchSpace ();
94
95
95
96
bool flashEraseSector (uint32_t sector);
You can’t perform that action at this time.
0 commit comments