Avoid repeated missing SPIFFS scans during ESP32 startup

This commit is contained in:
mikecarper committed 2026-10-05 14:12:44 -07:00
1 parent 47f10c0735
commit a0de63ab5e
16 files changed
+1158

No files matched your search

+57
View File
@@ -5,6 +5,7 @@
#include <helpers/ui/DisplayPowerSettings.h>
#include <helpers/UsbLoggingWatchdog.h>
#include <helpers/UsbLoggingClientActivity.h>
#include <helpers/HilStartupTrace.h>
#if MESH_PACKET_LOGGING
#include <helpers/SerialPacketLog.h>
#endif
@@ -15,6 +16,7 @@
#endif
#if defined(ESP32_PLATFORM)
#include <helpers/ESP32TrueRandom.h>
#include <helpers/esp32/BootFileSystem.h>
#endif
#if defined(NRF52_PLATFORM)
#include <helpers/nrf52/InternalPrimaryFsBoot.h>
@@ -105,12 +107,16 @@ void setup() {
#if MESH_PACKET_LOGGING
mesh::serialLogBegin();
#endif
mesh::hilStartupTrace("serial_ready");
mesh::hilStartupTrace("board_begin");
board.begin();
mesh::hilStartupTrace("board_ready");
#ifdef HAS_EXTERNAL_WATCHDOG
external_watchdog.begin();
#endif
mesh::hilStartupTrace("fs_begin");
FILESYSTEM* fs;
#if defined(NRF52_PLATFORM)
bool volatile_primary_fs = false;
@@ -146,7 +152,9 @@ void setup() {
#else
#error "need to define filesystem"
#endif
mesh::hilStartupTrace("fs_ready");
#ifdef DISPLAY_CLASS
mesh::hilStartupTrace("display_begin");
mesh::ui::loadDisplayPowerSettings(fs, false);
mesh::ui::StartupScreen startup_screen;
display_ready = display.begin();
@@ -154,6 +162,7 @@ void setup() {
startup_screen.begin(&display,
board.isExternalPowered() || board.isUsbHostConnected());
}
mesh::hilStartupTrace("display_ready");
#endif
// Let serial settle after the display is already showing startup.
@@ -165,6 +174,7 @@ void setup() {
delay(5000);
#endif
mesh::hilStartupTrace("radio_begin");
int radioinit_attempts = 0;
while (!radio_init()) {
++radioinit_attempts;
@@ -198,9 +208,11 @@ void setup() {
}
delay(500);
}
mesh::hilStartupTrace("radio_ready");
fast_rng.begin(radio_driver.getRngSeed());
mesh::hilStartupTrace("identity_begin");
#if defined(NRF52_PLATFORM)
IdentityLoadResult identity_load = volatile_primary_fs
? store.loadResult("_main", the_mesh.self_id)
@@ -250,6 +262,15 @@ void setup() {
board.reboot();
return;
}
mesh::hilStartupTrace("identity_ready");
#if defined(ESP32_PLATFORM)
// Identity recovery/persistence has finished before taking the inventory.
// The mesh retains this FS view after setup, so the view has static lifetime.
static mesh::Esp32BootFileSystem boot_fs(*fs);
fs = &boot_fs;
boot_fs.beginInventory();
#endif
// Print the running firmware version at boot so it's visible after an OTA
// reboot without having to issue `ver` manually.
@@ -276,10 +297,15 @@ void setup() {
}
#endif
mesh::hilStartupTrace("sensors_begin");
sensors.begin();
mesh::hilStartupTrace("sensors_ready");
mesh::hilStartupTrace("mesh_begin");
the_mesh.begin(fs);
mesh::hilStartupTrace("mesh_ready");
mesh::hilStartupTrace("watchdog_begin");
#if defined(NRF52_PLATFORM)
mesh::loadUsbLoggingWatchdog(fs, !volatile_primary_fs,
[]() -> uint32_t { return rtc_clock.getCurrentTime(); });
@@ -287,6 +313,7 @@ void setup() {
mesh::loadUsbLoggingWatchdog(fs, true,
[]() -> uint32_t { return rtc_clock.getCurrentTime(); });
#endif
mesh::hilStartupTrace("watchdog_ready");
#if defined(NRF52_PLATFORM)
if (volatile_primary_fs) {
@@ -300,6 +327,7 @@ void setup() {
#ifdef DISPLAY_CLASS
if (display_ready) {
mesh::hilStartupTrace("display_task_begin");
#ifdef WITH_MQTT_BRIDGE
ui_task.setObserverPrefs(the_mesh.getObserverPrefs());
#endif
@@ -307,6 +335,7 @@ void setup() {
ui_task.setActivityWindow(the_mesh.getActivityWindow());
#endif
ui_task.begin(the_mesh.getNodePrefs(), FIRMWARE_BUILD_DATE, FIRMWARE_VERSION);
mesh::hilStartupTrace("display_task_ready");
}
#endif
@@ -319,10 +348,25 @@ void setup() {
the_mesh.sendSelfAdvertisement(16000, false);
#endif
mesh::hilStartupTrace("boot_complete_begin");
#if defined(ESP32_PLATFORM)
mesh::endEsp32BootFileInventory();
#endif
board.onBootComplete();
mesh::hilStartupTrace("boot_complete_ready");
}
static void __attribute__((noinline)) serviceCommandInterfaces() {
#if defined(MESH_HIL_STARTUP_TRACE) && MESH_HIL_STARTUP_TRACE
static bool first_cli_entry = true;
static bool first_cli_ready = true;
static bool first_cli_blocked = true;
static bool first_cli_rx = true;
if (first_cli_entry) {
first_cli_entry = false;
mesh::hilStartupTrace("cli_first_entry");
}
#endif
bool usb_ready = true;
#if MESH_USB_CONSOLE_COOPERATIVE
mesh::serviceUsbLoggingPort();
@@ -339,6 +383,19 @@ static void __attribute__((noinline)) serviceCommandInterfaces() {
&& mesh::canAcceptUsbConsoleCommand();
#endif
Stream& console = mesh::usbConsolePort();
#if defined(MESH_HIL_STARTUP_TRACE) && MESH_HIL_STARTUP_TRACE
if (usb_ready && first_cli_ready) {
first_cli_ready = false;
mesh::hilStartupTrace("cli_ready");
} else if (!usb_ready && first_cli_blocked) {
first_cli_blocked = false;
mesh::hilStartupTrace("cli_gate_blocked");
}
if (usb_ready && first_cli_rx && console.available() > 0) {
first_cli_rx = false;
mesh::hilStartupTrace("cli_rx_seen");
}
#endif
// Handle Serial CLI
int len = strlen(command);
bool line_complete = false;