mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-14 20:10:18 +03:00
Add flash_scan to cli
This commit is contained in:
parent
c0ee056d68
commit
0e4cc5c3cf
3 changed files with 60 additions and 0 deletions
|
@ -2260,6 +2260,18 @@ static void cliFlashErase(char *cmdline)
|
||||||
|
|
||||||
#ifdef USE_FLASH_TOOLS
|
#ifdef USE_FLASH_TOOLS
|
||||||
|
|
||||||
|
static void cliFlashVerify(char *cmdline)
|
||||||
|
{
|
||||||
|
UNUSED(cmdline);
|
||||||
|
|
||||||
|
cliPrintLine("Verifying");
|
||||||
|
if (flashfsVerifyEntireFlash()) {
|
||||||
|
cliPrintLine("Success");
|
||||||
|
} else {
|
||||||
|
cliPrintLine("Failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void cliFlashWrite(char *cmdline)
|
static void cliFlashWrite(char *cmdline)
|
||||||
{
|
{
|
||||||
const uint32_t address = atoi(cmdline);
|
const uint32_t address = atoi(cmdline);
|
||||||
|
@ -5779,6 +5791,7 @@ const clicmd_t cmdTable[] = {
|
||||||
CLI_COMMAND_DEF("flash_info", "show flash chip info", NULL, cliFlashInfo),
|
CLI_COMMAND_DEF("flash_info", "show flash chip info", NULL, cliFlashInfo),
|
||||||
#ifdef USE_FLASH_TOOLS
|
#ifdef USE_FLASH_TOOLS
|
||||||
CLI_COMMAND_DEF("flash_read", NULL, "<length> <address>", cliFlashRead),
|
CLI_COMMAND_DEF("flash_read", NULL, "<length> <address>", cliFlashRead),
|
||||||
|
CLI_COMMAND_DEF("flash_scan", "scan flash device for errors", NULL, cliFlashVerify),
|
||||||
CLI_COMMAND_DEF("flash_write", NULL, "<address> <message>", cliFlashWrite),
|
CLI_COMMAND_DEF("flash_write", NULL, "<address> <message>", cliFlashWrite),
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -38,6 +38,7 @@
|
||||||
|
|
||||||
#include "platform.h"
|
#include "platform.h"
|
||||||
|
|
||||||
|
#include "common/printf.h"
|
||||||
#include "drivers/flash.h"
|
#include "drivers/flash.h"
|
||||||
|
|
||||||
#include "io/flashfs.h"
|
#include "io/flashfs.h"
|
||||||
|
@ -601,3 +602,46 @@ void flashfsInit(void)
|
||||||
flashfsSeekAbs(flashfsIdentifyStartOfFreeSpace());
|
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
|
||||||
|
|
|
@ -54,3 +54,6 @@ bool flashfsIsSupported(void);
|
||||||
|
|
||||||
bool flashfsIsReady(void);
|
bool flashfsIsReady(void);
|
||||||
bool flashfsIsEOF(void);
|
bool flashfsIsEOF(void);
|
||||||
|
|
||||||
|
bool flashfsVerifyEntireFlash(void);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue