Added flash backup for unknown tag types

This commit is contained in:
Jelmer
2023-05-19 00:40:39 +02:00
parent 1123e5cb9e
commit ed0189ceb1
3 changed files with 33 additions and 2 deletions

View File

@@ -44,6 +44,15 @@
"type":1,
"note":"2.9 v033 FW"
},
{
"name":"2.9 White - 2nd",
"mac_offset":64518,
"mac_format":1,
"mac_suffix":"3B10",
"MD5":"4FFCE4402E1540824BDDA62BC93FC3D9",
"type":1,
"note":"2.9 v033 FW - 2nd version"
},
{
"name":"2.9 White + NFC UC8151",
"mac_offset":64518,

View File

@@ -5,5 +5,9 @@ bool checkForcedAPFlash();
bool doForcedAPFlash();
bool doAPFlash();
bool doAPUpdate(uint8_t type);
void flashCountDown(uint8_t c);
#ifdef OPENEPAPERLINK_PCB
bool extTagConnected();
bool doTagFlash();
void flashCountDown(uint8_t c);
#endif

View File

@@ -82,6 +82,8 @@ class flasher {
void getMacFromWiFi();
bool prepareInfoBlock();
bool backupFlash();
bool writeFlash(uint8_t *flashbuffer, uint16_t size);
bool writeFlashFromPack(String filename, uint8_t type);
bool writeFlashFromPackOffset(fs::File *file, uint16_t length);
@@ -283,6 +285,18 @@ void flasher::getMacFromWiFi() {
esp_read_mac(mac + 2, ESP_MAC_WIFI_SOFTAP);
}
bool flasher::backupFlash() {
getFirmwareMD5();
if (!zbs->select_flash(0)) return false;
md5char[16]=0x00;
fs::File backup = LittleFS.open("/" + (String)md5char + "_backup.bin", "w", true);
for (uint32_t c = 0; c < 65535; c++) {
backup.write(zbs->read_flash(c));
}
backup.close();
return true;
}
// extract original mac from firmware (1.54" and 2.9") and make it 2 bytes longer based on info in settings.h
void flasher::get_mac_format1() {
zbs->select_flash(0);
@@ -553,6 +567,8 @@ bool doAPFlash() {
// used tag, but recognized
} else {
// unknown tag, bailing out.
f->backupFlash();
Serial.printf("Found a tag, but don't know what to do with it. Consider flashing using a file called \"AP_force_flash.bin\"\n");
delete f;
return false;
@@ -624,6 +640,7 @@ bool doTagFlash() {
f->prepareInfoBlock();
f->writeInfoBlock();
f->writeFlashFromPack("/Tag_FW_Pack.bin", f->tagtype);
f->zbs->reset();
} else if (f->getInfoBlockMD5()) {
// did find an infoblock MD5 that looks valid
if (f->findTagByMD5()) {
@@ -641,8 +658,9 @@ bool doTagFlash() {
} else {
// We couldn't recognize the tag from it's fingerprint...
Serial.printf("Found a tag but didn't recognize its fingerprint\n", f->md5char);
f->backupFlash();
Serial.printf("Saved this MD5 binary to filesystem\n");
}
delete f;
return false;
}