New tool fm10k-flash #1
2 changed files with 24 additions and 7 deletions
|
@ -175,12 +175,13 @@ int main(int argc, char** argv){
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
|
||||||
|
|
||||||
for(uint32_t addr = 0; addr < bootImageSizeMax; addr += 4){
|
for(uint32_t addr = 0; addr < bootImageSizeMax; addr += strideSize){
|
||||||
if(memcmp(valueBackup + addr, value + addr, 4) != 0){
|
if(memcmp(valueBackup + addr, value + addr, strideSize) != 0){
|
||||||
printf("write @ 0x%08x: 0x%08x => 0x%08x\n", addr, *(uint32_t*)(valueBackup + addr), *(uint32_t*)(value + addr));
|
printf("write @ 0x%08x\n", addr);
|
||||||
if(fm10k_uio_spi_WriteFlash((uintptr_t)memmapAddr, addr, value + addr, 4)){
|
if(fm10k_uio_spi_WriteFlash((uintptr_t)memmapAddr, addr, value + addr, strideSize)){
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
sleep(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,10 +211,13 @@ int main(int argc, char** argv){
|
||||||
printf("Data written mismatch! Replacing with backup.\n");
|
printf("Data written mismatch! Replacing with backup.\n");
|
||||||
|
|
||||||
for(uint32_t addr = 0; addr < bootImageSizeMax; addr += strideSize){
|
for(uint32_t addr = 0; addr < bootImageSizeMax; addr += strideSize){
|
||||||
printf("\rwrite backup @ 0x%08x / 0x%08x %d bytes", addr, bootImageSizeMax, strideSize);
|
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)){
|
if(fm10k_uio_spi_WriteFlash((uintptr_t)memmapAddr, addr, valueBackup + addr, strideSize)){
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
printf("Data written verified.\n");
|
printf("Data written verified.\n");
|
||||||
|
|
13
src/fm10k.c
13
src/fm10k.c
|
@ -31,6 +31,7 @@
|
||||||
|
|
||||||
#include "fm10k.h"
|
#include "fm10k.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
KNOWN_FLASH_DEVICE KNOWN_FLASH_DEVICE_LIST[] = {
|
KNOWN_FLASH_DEVICE KNOWN_FLASH_DEVICE_LIST[] = {
|
||||||
{{0x0101271f}, "Adesto AT45DB321E 32-Mbit", 32},
|
{{0x0101271f}, "Adesto AT45DB321E 32-Mbit", 32},
|
||||||
|
@ -286,6 +287,12 @@ uint32_t fm10k_uio_spi_EnableSectorProtection(uintptr_t mem){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* release CS */
|
||||||
|
spiCtrl.fields.Command = 0b1000;
|
||||||
|
if(fm10k_uio_spi_SetCtrlReg(mem, spiCtrl)){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
fm10k_uio_spi_Disable(mem);
|
fm10k_uio_spi_Disable(mem);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -324,6 +331,12 @@ uint32_t fm10k_uio_spi_DisableSectorProtection(uintptr_t mem){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* release CS */
|
||||||
|
spiCtrl.fields.Command = 0b1000;
|
||||||
|
if(fm10k_uio_spi_SetCtrlReg(mem, spiCtrl)){
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
fm10k_uio_spi_Disable(mem);
|
fm10k_uio_spi_Disable(mem);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in a new issue