mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-09 14:42:05 +00:00
Enhanced t-echo file system integrity check
This commit is contained in:
parent
cbf20e4cee
commit
8886d2df55
@ -205,6 +205,63 @@ void rmDir(const char *dirname)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool fsCheck()
|
||||||
|
{
|
||||||
|
#if defined(ARCH_NRF52)
|
||||||
|
size_t write_size = 0;
|
||||||
|
size_t read_size = 0;
|
||||||
|
char buf[32] = {0};
|
||||||
|
while (!Serial);
|
||||||
|
|
||||||
|
Adafruit_LittleFS_Namespace::File file(FSCom);
|
||||||
|
const char *text = "meshtastic fs test";
|
||||||
|
size_t text_length = strlen(text);
|
||||||
|
const char *filename = "/meshtastic.txt";
|
||||||
|
|
||||||
|
LOG_DEBUG("Try create file .\n");
|
||||||
|
if (file.open(filename, FILE_O_WRITE)) {
|
||||||
|
write_size = file.write(text);
|
||||||
|
} else {
|
||||||
|
LOG_DEBUG("Open file failed .\n");;
|
||||||
|
goto FORMAT_FS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (write_size != text_length) {
|
||||||
|
LOG_DEBUG("Text bytes do not match .\n");
|
||||||
|
file.close();
|
||||||
|
goto FORMAT_FS;
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
if (!file.open(filename, FILE_O_READ)) {
|
||||||
|
LOG_DEBUG("Open file failed .\n");
|
||||||
|
goto FORMAT_FS;
|
||||||
|
}
|
||||||
|
|
||||||
|
read_size = file.readBytes(buf, text_length);
|
||||||
|
if (read_size != text_length) {
|
||||||
|
LOG_DEBUG("Text bytes do not match .\n");
|
||||||
|
file.close();
|
||||||
|
goto FORMAT_FS;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (memcmp(buf, text, text_length) != 0) {
|
||||||
|
LOG_DEBUG("The written bytes do not match the read bytes .\n");
|
||||||
|
file.close();
|
||||||
|
goto FORMAT_FS;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
FORMAT_FS:
|
||||||
|
LOG_DEBUG("Format FS ....\n");
|
||||||
|
FSCom.format();
|
||||||
|
FSCom.begin();
|
||||||
|
return false;
|
||||||
|
#else
|
||||||
|
return true;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void fsInit()
|
void fsInit()
|
||||||
{
|
{
|
||||||
#ifdef FSCom
|
#ifdef FSCom
|
||||||
@ -219,15 +276,28 @@ void fsInit()
|
|||||||
* nRF52840 has a certain chance of automatic formatting failure.
|
* nRF52840 has a certain chance of automatic formatting failure.
|
||||||
* Try to create a file after initializing the file system. If the creation fails,
|
* Try to create a file after initializing the file system. If the creation fails,
|
||||||
* it means that the file system is not working properly. Please format it manually again.
|
* it means that the file system is not working properly. Please format it manually again.
|
||||||
|
* To check the normality of the file system, you need to disable the LFS_NO_ASSERT assertion.
|
||||||
|
* Otherwise, the assertion will be entered at the moment of reading or opening, and the FS will not be formatted.
|
||||||
* */
|
* */
|
||||||
Adafruit_LittleFS_Namespace::File file(FSCom);
|
bool ret = false;
|
||||||
const char *filename = "/meshtastic.txt";
|
uint8_t retry = 3;
|
||||||
if (!file.open(filename, FILE_O_WRITE)) {
|
|
||||||
LOG_DEBUG("Format ....");
|
while (retry--) {
|
||||||
FSCom.format();
|
ret = fsCheck();
|
||||||
FSCom.begin();
|
if (ret) {
|
||||||
} else {
|
LOG_DEBUG("File system check is OK.\n");
|
||||||
file.close();
|
break;
|
||||||
|
}
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
|
||||||
|
// It may not be possible to reach this step.
|
||||||
|
// Add a loop here to prevent unpredictable situations from happening.
|
||||||
|
// Can add a screen to display error status later.
|
||||||
|
if (!ret) {
|
||||||
|
while (1) {
|
||||||
|
Serial.println("The file system is damaged and cannot proceed to the next step.\n"); delay(1000);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
LOG_DEBUG("Filesystem files:\n");
|
LOG_DEBUG("Filesystem files:\n");
|
||||||
|
@ -17,6 +17,7 @@ build_flags = ${nrf52840_base.build_flags} -Ivariants/t-echo
|
|||||||
-DEINK_LIMIT_RATE_RESPONSIVE_SEC=1 ; Minimum interval between RESPONSIVE updates
|
-DEINK_LIMIT_RATE_RESPONSIVE_SEC=1 ; Minimum interval between RESPONSIVE updates
|
||||||
-DEINK_LIMIT_GHOSTING_PX=2000 ; (Optional) How much image ghosting is tolerated
|
-DEINK_LIMIT_GHOSTING_PX=2000 ; (Optional) How much image ghosting is tolerated
|
||||||
-DEINK_BACKGROUND_USES_FAST ; (Optional) Use FAST refresh for both BACKGROUND and RESPONSIVE, until a limit is reached.
|
-DEINK_BACKGROUND_USES_FAST ; (Optional) Use FAST refresh for both BACKGROUND and RESPONSIVE, until a limit is reached.
|
||||||
|
-DLFS_NO_ASSERT ; Disable LFS assertions
|
||||||
build_src_filter = ${nrf52_base.build_src_filter} +<../variants/t-echo>
|
build_src_filter = ${nrf52_base.build_src_filter} +<../variants/t-echo>
|
||||||
lib_deps =
|
lib_deps =
|
||||||
${nrf52840_base.lib_deps}
|
${nrf52840_base.lib_deps}
|
||||||
|
Loading…
Reference in New Issue
Block a user