|
23 | 23 | #include "eboot_command.h"
|
24 | 24 | #include <memory>
|
25 | 25 | #include "interrupts.h"
|
| 26 | +#include "MD5Builder.h" |
26 | 27 |
|
27 | 28 | extern "C" {
|
28 | 29 | #include "user_interface.h"
|
@@ -443,7 +444,22 @@ uint32_t EspClass::getSketchSize() {
|
443 | 444 | DEBUG_SERIAL.printf("section=%u size=%u pos=%u\r\n", section_index, section_header.size, pos);
|
444 | 445 | #endif
|
445 | 446 | }
|
446 |
| - result = pos; |
| 447 | + uint8_t buff[16] = {0}; |
| 448 | + |
| 449 | + if (spi_flash_read(pos, (uint32_t*) buff, 16)) { |
| 450 | + return 0; |
| 451 | + } |
| 452 | + uint8_t index = 0; |
| 453 | + for (index = 0; index < 16; index++) { |
| 454 | + if (buff[index] == 255) { break; } |
| 455 | + } |
| 456 | +#ifdef DEBUG_SERIAL |
| 457 | + DEBUG_SERIAL.printf("Last 16bytes: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\r\n", |
| 458 | + buff[0],buff[1],buff[2],buff[3],buff[4],buff[5],buff[6],buff[7], |
| 459 | + buff[8],buff[9],buff[10],buff[11],buff[12],buff[13],buff[14],buff[15]); |
| 460 | + DEBUG_SERIAL.printf("end offset index = %u\r\n", index ); |
| 461 | +#endif |
| 462 | + result = pos + index; |
447 | 463 | return result;
|
448 | 464 | }
|
449 | 465 |
|
@@ -519,3 +535,53 @@ bool EspClass::flashRead(uint32_t offset, uint32_t *data, size_t size) {
|
519 | 535 | ets_isr_unmask(FLASH_INT_MASK);
|
520 | 536 | return rc == 0;
|
521 | 537 | }
|
| 538 | + |
| 539 | + |
| 540 | + |
| 541 | +String EspClass::getSketchMD5() |
| 542 | +{ |
| 543 | + |
| 544 | + const int buf_size = 512; |
| 545 | + uint32_t offset = 0; |
| 546 | + uint32_t maxLengthLeft = getSketchSize(); |
| 547 | + uint8_t * buf = (uint8_t*) malloc(buf_size); |
| 548 | + uint8_t remainder = 0; |
| 549 | + |
| 550 | + if(!buf) { |
| 551 | + return "0"; |
| 552 | + } |
| 553 | + |
| 554 | + MD5Builder md5; |
| 555 | + md5.begin(); |
| 556 | + |
| 557 | + while( maxLengthLeft > 0) { |
| 558 | + |
| 559 | + size_t readBytes = maxLengthLeft; |
| 560 | + |
| 561 | + if (readBytes > buf_size) { |
| 562 | + readBytes = buf_size; |
| 563 | + } |
| 564 | + |
| 565 | + if (readBytes < 4) { |
| 566 | + remainder = readBytes; |
| 567 | + readBytes = 4; |
| 568 | + } |
| 569 | + |
| 570 | + if ( flashRead(offset, (uint32_t*)buf, readBytes) ) { |
| 571 | + if (!remainder) { |
| 572 | + md5.add(buf, readBytes); |
| 573 | + } else { |
| 574 | + md5.add(buf, remainder); |
| 575 | + } |
| 576 | + offset += readBytes; |
| 577 | + maxLengthLeft -= readBytes; |
| 578 | + |
| 579 | + } |
| 580 | + |
| 581 | + } |
| 582 | + |
| 583 | + md5.calculate(); |
| 584 | + |
| 585 | + return md5.toString(); |
| 586 | +} |
| 587 | + |
0 commit comments