1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-24 00:35:39 +03:00

Add flash_scan to cli

This commit is contained in:
Dominic Clifton 2018-12-02 03:14:11 +01:00 committed by jflyper
parent c0ee056d68
commit 0e4cc5c3cf
3 changed files with 60 additions and 0 deletions

View file

@ -38,6 +38,7 @@
#include "platform.h"
#include "common/printf.h"
#include "drivers/flash.h"
#include "io/flashfs.h"
@ -601,3 +602,46 @@ void flashfsInit(void)
flashfsSeekAbs(flashfsIdentifyStartOfFreeSpace());
}
}
#ifdef USE_FLASH_TOOLS
bool flashfsVerifyEntireFlash(void)
{
flashEraseCompletely();
flashfsInit();
const flashGeometry_t *flashGeometry = flashfsGetGeometry();
uint32_t address = 0;
flashfsSeekAbs(address);
const int bufferSize = 32;
char buffer[bufferSize + 1];
const uint32_t testLimit = flashGeometry->totalSize;
for (address = 0; address < testLimit; address += bufferSize) {
tfp_sprintf(buffer, "%08x >> **0123456789ABCDEF**", address);
flashfsWrite((uint8_t*)buffer, strlen(buffer), true);
}
flashfsFlushSync();
flashfsClose();
char expectedBuffer[bufferSize + 1];
flashfsSeekAbs(0);
int verificationFailures = 0;
for (address = 0; address < testLimit; address += bufferSize) {
tfp_sprintf(expectedBuffer, "%08x >> **0123456789ABCDEF**", address);
memset(buffer, 0, sizeof(buffer));
int bytesRead = flashfsReadAbs(address, (uint8_t *)buffer, bufferSize);
int result = strncmp(buffer, expectedBuffer, bufferSize);
if (result != 0 || bytesRead != bufferSize) {
verificationFailures++;
}
}
return verificationFailures == 0;
}
#endif // USE_FLASH_TOOLS