Delete previous metadata when writing new file to flash in urclock

This commit is contained in:
Stefan Rueger 2022-11-20 13:02:51 +00:00
parent c0e4dd494e
commit 7f4474f049
No known key found for this signature in database
GPG Key ID: B0B4F1FD86B1EC55
1 changed files with 14 additions and 1 deletions

View File

@ -774,9 +774,22 @@ nopatch:
size = ur.blstart;
}
nopatch_nometa:
// Delete metadata on device (if any) that's between new input and metadata
if(!ur.urprotocol || (ur.urfeatures & UB_READ_FLASH)) { // Flash readable?
uint8_t devmcode; // Metadata marker on the device
if(ur.blstart && ur_readEF(pgm, p, &devmcode, ur.blstart-1, 1, 'F') == 0) {
int devnmeta=nmeta(devmcode, ur.uP.flashsize);
for(int addr=ur.blstart-devnmeta; addr < ur.blstart; addr++) {
if(!(flm->tags[addr] & TAG_ALLOCATED)) {
flm->tags[addr] |= TAG_ALLOCATED;
flm->buf[addr] = 0xff;
}
}
}
}
// Emulate chip erase if bootloader unable to: mark all bytes for upload on first -U flash:w:...
if(ur.emulate_ce) {
for(int ai = 0; ai < maxsize; ai++)