How to get CRC of downloaded sketch like ESP.getSketchMD5() function?
Of course i mean ESP8266 platform.
Choose a function that implements one of the many different CRC algorithms, and pass all the downloaded bytes to it. The function result will be the CRC value of those bytes.
I create this func:
String esp_crc_sketch(uint32_t address, uint32_t sketch_size) {
CRC32 crc;
uint32_t CRC_int;
String CRC_string;
char crcBuffer[9]; // Buffer to hold the formatted CRC string
size_t len;
uint32_t total;
double start_time;
const uint32_t timeout = 1000;
uint8_t receive[256];
DEBG_PRINT(__func__);
//DEBG_PRINTF("Sketch size:%d\n", size);
//address = 0x40100000;//Start of sketch
DEBG_PRINTF("\nGet CRC of area from: %08X to %08X(%d bytes)\n", address, address + sketch_size, sketch_size);
crc.setPolynome(0x04C11DB7);
crc.setStartXOR(0xFFFFFFFF);
crc.setEndXOR(0xFFFFFFFF);
crc.setReverseIn(true);
crc.setReverseOut(true);
total = 0;
start_time = millis();
while (((millis() - start_time) < timeout) && (total < sketch_size)) {
debug.printf("Read:%d/%d bytes\n", total, sketch_size);
len = std::min(256u, (sketch_size - total));
if (ESP.flashRead(address, &receive[0], len)) {
crc.add(&receive[0], len);
total += len;
address += len;
start_time = millis();
}
else {
delay(20);
debug.print("Fail to read esp flash\n");
}
}
if (!(total > 0)) {
debug.print("Zero size read!\n");
return "NULL";
}
if (!((millis() - start_time) < timeout)) {
debug.print("Time out!\n");
return "NULL";
}
CRC_int = crc.getCRC();
// Format the CRC string with leading zeros
snprintf(crcBuffer, sizeof(crcBuffer), "%08x", CRC_int);
CRC_string = String(crcBuffer);
DEBG_PRINTF("CRC string: %s\n", CRC_string);
DEBG_PRINTF("CRC integer: %x\n", CRC_int);
return CRC_string;
}
And call it:
esp_crc_sketch(0x40100000, ESP.getSketchSize());
But 'ESP.flashRead' func always returns false.
Looks like my IDE uses this scheme of memory maping:
/* Flash Split for 4M chips */
/* sketch @0x40200000 (~1019KB) (1044464B) */
/* empty @0x402FEFF0 (~2052KB) (2101264B) */
/* spiffs @0x40500000 (~1000KB) (1024000B) */
/* eeprom @0x405FB000 (4KB) */
/* rfcal @0x405FC000 (4KB) */
/* wifi @0x405FD000 (12KB) */
MEMORY
{
dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x14000
irom0_0_seg : org = 0x40201010, len = 0xfeff0
}
PROVIDE ( _FS_start = 0x40500000 );
PROVIDE ( _FS_end = 0x405FA000 );
PROVIDE ( _FS_page = 0x100 );
PROVIDE ( _FS_block = 0x2000 );
PROVIDE ( _EEPROM_start = 0x405fb000 );
/* The following symbols are DEPRECATED and will be REMOVED in a future release */
PROVIDE ( _SPIFFS_start = 0x40500000 );
PROVIDE ( _SPIFFS_end = 0x405FA000 );
PROVIDE ( _SPIFFS_page = 0x100 );
PROVIDE ( _SPIFFS_block = 0x2000 );
INCLUDE "local.eagle.app.v6.common.ld"
Every this points does not read. The function return false and i dont know how to put debug to it.
Excuse me. My function works correct.
Just start from zero address:
esp_crc_sketch(0x0U, ESP.getSketchSize());
Result the same as output binary. Thank for reading
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.