New tool fm10k-flash #1

Merged
DataHoarder merged 5 commits from fm10k-flash into master 2020-12-21 05:11:25 +00:00
2 changed files with 24 additions and 7 deletions
Showing only changes of commit c1ec526eb8 - Show all commits

View file

@ -175,12 +175,13 @@ int main(int argc, char** argv){
sleep(1);
for(uint32_t addr = 0; addr < bootImageSizeMax; addr += 4){
if(memcmp(valueBackup + addr, value + addr, 4) != 0){
printf("write @ 0x%08x: 0x%08x => 0x%08x\n", addr, *(uint32_t*)(valueBackup + addr), *(uint32_t*)(value + addr));
if(fm10k_uio_spi_WriteFlash((uintptr_t)memmapAddr, addr, value + addr, 4)){
for(uint32_t addr = 0; addr < bootImageSizeMax; addr += strideSize){
if(memcmp(valueBackup + addr, value + addr, strideSize) != 0){
printf("write @ 0x%08x\n", addr);
if(fm10k_uio_spi_WriteFlash((uintptr_t)memmapAddr, addr, value + addr, strideSize)){
return 2;
}
sleep(1);
}
}
@ -210,9 +211,12 @@ int main(int argc, char** argv){
printf("Data written mismatch! Replacing with backup.\n");
for(uint32_t addr = 0; addr < bootImageSizeMax; addr += strideSize){
printf("\rwrite backup @ 0x%08x / 0x%08x %d bytes", addr, bootImageSizeMax, strideSize);
if(fm10k_uio_spi_WriteFlash((uintptr_t)memmapAddr, addr, valueBackup + addr, strideSize)){
return 2;
if(memcmp(valueBackup + addr, valueCheck + addr, strideSize) != 0){
printf("write backup @ 0x%08x\n", addr);
if(fm10k_uio_spi_WriteFlash((uintptr_t)memmapAddr, addr, valueBackup + addr, strideSize)){
return 2;
}
sleep(1);
}
}
}else{

View file

@ -31,6 +31,7 @@
#include "fm10k.h"
#include <stdio.h>
#include <time.h>
KNOWN_FLASH_DEVICE KNOWN_FLASH_DEVICE_LIST[] = {
{{0x0101271f}, "Adesto AT45DB321E 32-Mbit", 32},
@ -286,6 +287,12 @@ uint32_t fm10k_uio_spi_EnableSectorProtection(uintptr_t mem){
return 1;
}
/* release CS */
spiCtrl.fields.Command = 0b1000;
if(fm10k_uio_spi_SetCtrlReg(mem, spiCtrl)){
return 1;
}
fm10k_uio_spi_Disable(mem);
return 0;
@ -324,6 +331,12 @@ uint32_t fm10k_uio_spi_DisableSectorProtection(uintptr_t mem){
return 1;
}
/* release CS */
spiCtrl.fields.Command = 0b1000;
if(fm10k_uio_spi_SetCtrlReg(mem, spiCtrl)){
return 1;
}
fm10k_uio_spi_Disable(mem);
return 0;