Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reboot before formatting LittleFS #5900

Merged
merged 2 commits into from
Jan 20, 2025
Merged

Conversation

esev
Copy link
Contributor

@esev esev commented Jan 20, 2025

Fixes #5896

@esev
Copy link
Contributor Author

esev commented Jan 20, 2025

Tested by pressing a in the serial console to trigger lfs_assert directly.

diff --git a/src/mesh/StreamAPI.cpp b/src/mesh/StreamAPI.cpp
index 4a42e519..0d36e7a5 100644
--- a/src/mesh/StreamAPI.cpp
+++ b/src/mesh/StreamAPI.cpp
@@ -1,8 +1,13 @@
+#include <flash/flash_nrf5x.h>
 #include "StreamAPI.h"
+#include "FSCommon.h"
 #include "PowerFSM.h"
 #include "RTC.h"
+#include "SPILock.h"
 #include "Throttle.h"
 #include "configuration.h"
+#include "main.h"
+#include "mesh/NodeDB.h"
 
 #define START1 0x94
 #define START2 0xc3
@@ -43,8 +48,46 @@ int32_t StreamAPI::readStream()
             // console->printf("rxPtr %d ptr=%d c=0x%x\n", rxPtr, ptr, c);
 
             if (ptr == 0) { // looking for START1
-                if (c != START1)
-                    rxPtr = 0;     // failed to find framing
+                if (c != START1) {
+                    rxPtr = 0; // failed to find framing
+                    switch (c) {
+                    case 'a':
+                        lfs_assert("StreamAPI");
+                        break;
+                    case 'd':
+                        enterDfuMode();
+                        break;
+                    case 'e': {
+#ifdef NRF52840_XXAA
+  #define LFS_FLASH_ADDR        0xED000
+#else
+  #define LFS_FLASH_ADDR        0x6D000
+#endif
+#define FLASH_NRF52_PAGE_SIZE   4096
+#define LFS_FLASH_TOTAL_SIZE  (7*FLASH_NRF52_PAGE_SIZE)
+                        // Erase all sectors of internal flash region for Filesystem.
+                        for (uint32_t addr = LFS_FLASH_ADDR; addr < LFS_FLASH_ADDR + LFS_FLASH_TOTAL_SIZE;
+                             addr += FLASH_NRF52_PAGE_SIZE) {
+                            flash_nrf5x_erase(addr);
+                        }
+
+                    } break;
+                    case 'l': {
+                        spiLock->lock();
+                        auto filesManifest = getFiles("/", 10);
+                        spiLock->unlock();
+                        for (const auto &file : filesManifest) {
+                            LOG_INFO("%s: %d", file.file_name, file.size_bytes);
+                        }
+                    } break;
+                    case 'r':
+                        rebootAtMsec = 2000;
+                        break;
+                    case 's':
+                        nodeDB->saveToDisk();
+                        break;
+                    }
+                }
             } else if (ptr == 1) { // looking for START2
                 if (c != START2)
                     rxPtr = 0;                             // failed to find framing

@VeggieVampire
Copy link

Is there a temporary fix that could help us get the device working again in the meantime?

@thebentern thebentern merged commit c4fcbad into meshtastic:master Jan 20, 2025
49 checks passed
@esev
Copy link
Contributor Author

esev commented Jan 20, 2025

Is there a temporary fix that could help us get the device working again in the meantime?

The nrf_erase tool should clear up this issue for now. You can get it by clicking the little trash can icon in the web flasher.

@cpatulea
Copy link
Contributor

👋

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: FSCom.format() freezes device from lfs_assert
4 participants