diff --git a/boards/gearup/airbrainh743/src/init.c b/boards/gearup/airbrainh743/src/init.c index 0f2a75d6d2..2577ce282e 100644 --- a/boards/gearup/airbrainh743/src/init.c +++ b/boards/gearup/airbrainh743/src/init.c @@ -45,6 +45,8 @@ #include #include #include +#include +#include #include #include @@ -188,7 +190,26 @@ __EXPORT int board_app_initialize(uintptr_t arg) syslog(LOG_INFO, "[boot] W25N MTD registered at /dev/mtd0\n"); #ifdef CONFIG_FS_LITTLEFS - ret = nx_mount("/dev/mtd0", "/fs/microsd", "littlefs", 0, "autoformat"); + ret = nx_mount("/dev/mtd0", "/fs/microsd", "littlefs", 0, NULL); + + if (ret == 0) { + /* Verify the filesystem is usable by creating a test file */ + int fd = open("/fs/microsd/.mount_test", O_CREAT | O_WRONLY | O_TRUNC); + + if (fd >= 0) { + close(fd); + unlink("/fs/microsd/.mount_test"); + + } else { + syslog(LOG_WARNING, "[boot] littlefs mounted but not usable, reformatting\n"); + nx_umount2("/fs/microsd", 0); + ret = -1; + } + } + + if (ret < 0) { + ret = nx_mount("/dev/mtd0", "/fs/microsd", "littlefs", 0, "forceformat"); + } if (ret < 0) { syslog(LOG_ERR, "[boot] FAILED to mount littlefs: %d\n", ret);