kopia lustrzana https://github.com/bristol-seds/pico-tracker
[loader] initial fix of flash checking
rodzic
91bfcb9d58
commit
7e7dbc10ae
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
void mem_read_memory(unsigned int* address, uint8_t* buffer, uint32_t length);
|
void mem_read_memory(unsigned int* address, uint8_t* buffer, uint32_t length);
|
||||||
void mem_write_word(unsigned int* address, uint32_t word);
|
void mem_write_word(unsigned int* address, uint32_t word);
|
||||||
void mem_write_sector(unsigned int* address, uint8_t* buffer);
|
void mem_write_sector(unsigned int* address, unsigned int* buffer);
|
||||||
void mem_erase_sector(unsigned int* address);
|
void mem_erase_sector(unsigned int* address);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -155,9 +155,9 @@ void update_checksums(const uint32_t* nvm, uint32_t* ram, int sectors)
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < sectors; i++,
|
for (i = 0; i < sectors; i++,
|
||||||
nvm += SECTOR_SIZE, ram += SECTOR_SIZE) {
|
nvm += 64, ram += 64) {
|
||||||
mem_erase_sector((unsigned int*)nvm);
|
mem_erase_sector((unsigned int*)nvm);
|
||||||
mem_write_sector((unsigned int*)nvm, (uint8_t*)ram);
|
mem_write_sector((unsigned int*)nvm, (unsigned int*)ram);
|
||||||
|
|
||||||
kick_the_watchdog();
|
kick_the_watchdog();
|
||||||
}
|
}
|
||||||
|
@ -182,7 +182,7 @@ uint32_t check_and_repair_memory(void)
|
||||||
|
|
||||||
/* foreach sector */
|
/* foreach sector */
|
||||||
for (i = 0; i < D1_SECTORS; i++,
|
for (i = 0; i < D1_SECTORS; i++,
|
||||||
address1 += SECTOR_SIZE, address2 += SECTOR_SIZE) {
|
address1 += 64, address2 += 64) {
|
||||||
/* calculate checksums */
|
/* calculate checksums */
|
||||||
check1 = checksum_sector(address1);
|
check1 = checksum_sector(address1);
|
||||||
check2 = checksum_sector(address2);
|
check2 = checksum_sector(address2);
|
||||||
|
@ -196,7 +196,7 @@ uint32_t check_and_repair_memory(void)
|
||||||
(check2 == d2_checksums_ram[i])) {
|
(check2 == d2_checksums_ram[i])) {
|
||||||
/* restore d1 */
|
/* restore d1 */
|
||||||
mem_erase_sector(address1);
|
mem_erase_sector(address1);
|
||||||
mem_write_sector(address1, (uint8_t*)address2);
|
mem_write_sector(address1, address2);
|
||||||
|
|
||||||
/* update d1 checksum */
|
/* update d1 checksum */
|
||||||
d1_checksums_ram[i] = check2;
|
d1_checksums_ram[i] = check2;
|
||||||
|
@ -209,7 +209,7 @@ uint32_t check_and_repair_memory(void)
|
||||||
(check2 != d2_checksums_ram[i])) {
|
(check2 != d2_checksums_ram[i])) {
|
||||||
/* restore d2 */
|
/* restore d2 */
|
||||||
mem_erase_sector(address2);
|
mem_erase_sector(address2);
|
||||||
mem_write_sector(address2, (uint8_t*)address1);
|
mem_write_sector(address2, address1);
|
||||||
|
|
||||||
/* update d2 checksum */
|
/* update d2 checksum */
|
||||||
d2_checksums_ram[i] = check1;
|
d2_checksums_ram[i] = check1;
|
||||||
|
@ -222,7 +222,7 @@ uint32_t check_and_repair_memory(void)
|
||||||
/* both bad, restore d2 and calculate both checksums */
|
/* both bad, restore d2 and calculate both checksums */
|
||||||
/* restore d2 */
|
/* restore d2 */
|
||||||
mem_erase_sector(address2);
|
mem_erase_sector(address2);
|
||||||
mem_write_sector(address2, (uint8_t*)address1);
|
mem_write_sector(address2, address1);
|
||||||
|
|
||||||
/* update both checksums */
|
/* update both checksums */
|
||||||
d1_checksums_ram[i] = check1;
|
d1_checksums_ram[i] = check1;
|
||||||
|
|
|
@ -86,10 +86,9 @@ void mem_write_word(unsigned int* address, uint32_t word)
|
||||||
/**
|
/**
|
||||||
* Write 256-byte sector. Address must be sector aligned
|
* Write 256-byte sector. Address must be sector aligned
|
||||||
*/
|
*/
|
||||||
void mem_write_sector(unsigned int* address, uint8_t* buffer)
|
void mem_write_sector(unsigned int* address, unsigned int* buffer)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
uint8_t tempbuf[0x40];
|
|
||||||
|
|
||||||
#ifdef FIX_ERRATA_REV_C_FLASH_10804
|
#ifdef FIX_ERRATA_REV_C_FLASH_10804
|
||||||
/* save CTRLB and disable cache */
|
/* save CTRLB and disable cache */
|
||||||
|
@ -103,9 +102,12 @@ void mem_write_sector(unsigned int* address, uint8_t* buffer)
|
||||||
for (i = 0; i < 4; i++) { /* write by page */
|
for (i = 0; i < 4; i++) { /* write by page */
|
||||||
/* write address */
|
/* write address */
|
||||||
NVMCTRL->ADDR.reg = (uint32_t)(address) >> 1;
|
NVMCTRL->ADDR.reg = (uint32_t)(address) >> 1;
|
||||||
|
|
||||||
/* write page. length must be multiple of two */
|
/* write page. length must be multiple of two */
|
||||||
memcpy((void*)tempbuf, buffer, 0x40);
|
for (int j = 0; j < 0x10; j++) {
|
||||||
memcpy((void*)address, tempbuf, 0x40);
|
address[j] = buffer[j];
|
||||||
|
}
|
||||||
|
|
||||||
/* unlock */
|
/* unlock */
|
||||||
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_UR;
|
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_UR;
|
||||||
/* write page */
|
/* write page */
|
||||||
|
@ -115,8 +117,8 @@ void mem_write_sector(unsigned int* address, uint8_t* buffer)
|
||||||
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_LR;
|
NVMCTRL->CTRLA.reg = NVMCTRL_CTRLA_CMDEX_KEY | NVMCTRL_CTRLA_CMD_LR;
|
||||||
|
|
||||||
/* next page */
|
/* next page */
|
||||||
address += 0x40;
|
address += 0x10;
|
||||||
buffer += 0x40;
|
buffer += 0x10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue