fix: auto_erase/verif?
This commit is contained in:
@@ -46,6 +46,7 @@ int __attribute__((section(".vectors"))) main(void) {
|
||||
/* clear block protection */
|
||||
FLASH_SetStatusBits(0x1c, 0);
|
||||
printf("[FLASH] Block protection cleared\n");
|
||||
// uint32_t erase_sector_addr = 0;
|
||||
|
||||
while (1) {
|
||||
FLASH_CONTROL->start = 0;
|
||||
@@ -81,6 +82,13 @@ int __attribute__((section(".vectors"))) main(void) {
|
||||
|
||||
for (uint32_t offset = 0; offset < FLASH_CONTROL->len; offset += 4) {
|
||||
uint32_t write_addr = FLASH_CONTROL->offset + offset;
|
||||
uint32_t sector_addr1 = write_addr & 0xFFFFF000;
|
||||
// if (sector_addr1 >=
|
||||
// erase_sector_addr) { // relate to rtl8710_flasher_auto_erase
|
||||
// FLASH_Erase(2, sector_addr1);
|
||||
// erase_sector_addr =
|
||||
// sector_addr1 + 0x1000; // next sector we should erase
|
||||
// }
|
||||
FLASH_TxData12B(write_addr, 4,
|
||||
(uint8_t *)&FLASH_CONTROL->data[offset]);
|
||||
}
|
||||
@@ -88,24 +96,39 @@ int __attribute__((section(".vectors"))) main(void) {
|
||||
printf("[FLASHER] Write completed successfully\n");
|
||||
break;
|
||||
|
||||
case CMD_VERIFY:
|
||||
for (uint32_t i = 0; i < FLASH_CONTROL->len; i += VERIFY_CHUNK_SIZE) {
|
||||
size_t bytes_to_compare = MIN(4, FLASH_CONTROL->len - i);
|
||||
const void *flash_addr =
|
||||
(const void *)(SPI_FLASH_BASE + FLASH_CONTROL->offset + i);
|
||||
case CMD_VERIFY: {
|
||||
uint8_t tbuf[4];
|
||||
printf("Verify: FLASH_CONTROL->data = %p\n", FLASH_CONTROL->data);
|
||||
printf("Verify: Reading from flash base %p\n", (void *)SPI_FLASH_BASE);
|
||||
printf("Verify: With offset %x\n", FLASH_CONTROL->offset);
|
||||
|
||||
if (memcmp(flash_addr, (const void *)&FLASH_CONTROL->data[i],
|
||||
bytes_to_compare) != 0) {
|
||||
for (uint32_t i = 0; i < FLASH_CONTROL->len; i += 4) {
|
||||
volatile uint32_t *flash_addr =
|
||||
(volatile uint32_t *)(SPI_FLASH_BASE + FLASH_CONTROL->offset + i);
|
||||
*((uint32_t *)tbuf) = *flash_addr;
|
||||
|
||||
size_t l = MIN(4, FLASH_CONTROL->len - i);
|
||||
size_t k;
|
||||
for (k = 0; k < l; k++) {
|
||||
if (tbuf[k] != FLASH_CONTROL->data[i + k]) {
|
||||
printf("Verify mismatch at offset %x: flash=%02x buf=%02x\n",
|
||||
i + k, tbuf[k], FLASH_CONTROL->data[i + k]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (k < l) {
|
||||
FLASH_CONTROL->status = 1;
|
||||
FLASH_CONTROL->param = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
FLASH_CONTROL->status = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user