From e6016064f4ee3eb87a8ac7f32047772fbcab3cf5 Mon Sep 17 00:00:00 2001 From: liquidraver <504870+liquidraver@users.noreply.github.com> Date: Tue, 16 Jun 2026 21:20:27 +0200 Subject: [PATCH] activate NVS on ESP --- zephcore/boards/common/esp32_common.conf | 10 +++++ .../esp32/heltec_wifi_lora32_v3/board.overlay | 27 +++++++++++++- .../esp32/heltec_wifi_lora32_v4/board.overlay | 27 +++++++++++++- .../heltec_wifi_lora32_v43/board.overlay | 27 +++++++++++++- .../heltec_wireless_tracker/board.overlay | 27 +++++++++++++- .../esp32/lilygo_tlora_c6/board.overlay | 15 +++++++- .../boards/esp32/station_g2/board.overlay | 37 +++++++++++++++++-- .../boards/esp32/ttgo_lora32/board.overlay | 13 +++++++ .../boards/esp32/ttgo_tbeam/board.overlay | 13 +++++++ .../boards/esp32/xiao_esp32c3/board.overlay | 15 +++++++- .../boards/esp32/xiao_esp32c6/board.overlay | 15 +++++++- .../boards/esp32/xiao_esp32s3/board.overlay | 27 +++++++++++++- 12 files changed, 242 insertions(+), 11 deletions(-) diff --git a/zephcore/boards/common/esp32_common.conf b/zephcore/boards/common/esp32_common.conf index 051bb78..8498562 100644 --- a/zephcore/boards/common/esp32_common.conf +++ b/zephcore/boards/common/esp32_common.conf @@ -68,6 +68,16 @@ CONFIG_HEAP_MEM_POOL_SIZE=32768 # Station G2 (16MB) overrides in board.conf. CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +# ========== BLE bonds: dedicated NVS partition (not /lfs) ========== +# Bonds live in their own `storage_partition` NVS region (defined per board in +# board.overlay), isolated from the /lfs LittleFS volume that holds identity/ +# prefs/contacts. This overrides the file-backed default in zephcore_common.conf +# (loaded earlier): a busy bond store can no longer corrupt /lfs. Every ESP32 +# board.overlay defines a storage_partition, so this is safe platform-wide. +CONFIG_SETTINGS_FILE=n +CONFIG_NVS=y +CONFIG_SETTINGS_NVS=y + # ========== Debug ========== # CONFIG_ASSERT disabled for ESP32: Espressif's closed-source BLE controller # blob leaves IRQs in a state that triggers false "Context switching while diff --git a/zephcore/boards/esp32/heltec_wifi_lora32_v3/board.overlay b/zephcore/boards/esp32/heltec_wifi_lora32_v3/board.overlay index b0b441a..2543457 100644 --- a/zephcore/boards/esp32/heltec_wifi_lora32_v3/board.overlay +++ b/zephcore/boards/esp32/heltec_wifi_lora32_v3/board.overlay @@ -116,10 +116,35 @@ /delete-node/ &storage_partition; /delete-node/ &scratch_partition; /delete-node/ &coredump_partition; +/delete-node/ &slot0_partition; +/delete-node/ &slot1_partition; + +/ { + chosen { + zephyr,settings-partition = &storage_partition; + }; +}; &flash0 { partitions { - /* LittleFS 384KB for DataStore + file-based BLE settings */ + /* App slots — both trimmed 8KB so slot0 == slot1 (16KB total freed + * for the NVS partition below), keeping MCUboot swap-mode compatible, + * not just overwrite-only. slot0 start (0x20000) unchanged. */ + slot0_partition: partition@20000 { + label = "image-0"; + reg = <0x20000 0x3BE000>; + }; + slot1_partition: partition@3de000 { + label = "image-1"; + reg = <0x3DE000 0x3BE000>; + }; + /* BLE bond store — 16KB NVS, isolated from /lfs (see esp32_common.conf). + * Carved from the end of slot1 so lfs stays byte-identical. */ + storage_partition: partition@79c000 { + label = "storage"; + reg = <0x79C000 0x4000>; + }; + /* LittleFS 384KB for DataStore (identity, prefs, contacts) */ lfs_partition: partition@7a0000 { label = "lfs"; reg = <0x7A0000 0x60000>; diff --git a/zephcore/boards/esp32/heltec_wifi_lora32_v4/board.overlay b/zephcore/boards/esp32/heltec_wifi_lora32_v4/board.overlay index 78aa9eb..e3a8758 100644 --- a/zephcore/boards/esp32/heltec_wifi_lora32_v4/board.overlay +++ b/zephcore/boards/esp32/heltec_wifi_lora32_v4/board.overlay @@ -88,10 +88,35 @@ /delete-node/ &storage_partition; /delete-node/ &scratch_partition; /delete-node/ &coredump_partition; +/delete-node/ &slot0_partition; +/delete-node/ &slot1_partition; + +/ { + chosen { + zephyr,settings-partition = &storage_partition; + }; +}; &flash0 { partitions { - /* LittleFS 384 KB for DataStore + file-based BLE settings */ + /* App slots — both trimmed 8KB so slot0 == slot1 (16KB total freed + * for the NVS partition below), keeping MCUboot swap-mode compatible, + * not just overwrite-only. slot0 start (0x20000) unchanged. */ + slot0_partition: partition@20000 { + label = "image-0"; + reg = <0x20000 0x7BE000>; + }; + slot1_partition: partition@7de000 { + label = "image-1"; + reg = <0x7DE000 0x7BE000>; + }; + /* BLE bond store — 16KB NVS, isolated from /lfs (see esp32_common.conf). + * Carved from the end of slot1 so lfs stays byte-identical. */ + storage_partition: partition@f9c000 { + label = "storage"; + reg = <0xF9C000 0x4000>; + }; + /* LittleFS 384 KB for DataStore (identity, prefs, contacts) */ lfs_partition: partition@fa0000 { label = "lfs"; reg = <0xFA0000 0x60000>; diff --git a/zephcore/boards/esp32/heltec_wifi_lora32_v43/board.overlay b/zephcore/boards/esp32/heltec_wifi_lora32_v43/board.overlay index 1348209..3b1dfa6 100644 --- a/zephcore/boards/esp32/heltec_wifi_lora32_v43/board.overlay +++ b/zephcore/boards/esp32/heltec_wifi_lora32_v43/board.overlay @@ -88,10 +88,35 @@ /delete-node/ &storage_partition; /delete-node/ &scratch_partition; /delete-node/ &coredump_partition; +/delete-node/ &slot0_partition; +/delete-node/ &slot1_partition; + +/ { + chosen { + zephyr,settings-partition = &storage_partition; + }; +}; &flash0 { partitions { - /* LittleFS 384 KB for DataStore + file-based BLE settings */ + /* App slots — both trimmed 8KB so slot0 == slot1 (16KB total freed + * for the NVS partition below), keeping MCUboot swap-mode compatible, + * not just overwrite-only. slot0 start (0x20000) unchanged. */ + slot0_partition: partition@20000 { + label = "image-0"; + reg = <0x20000 0x7BE000>; + }; + slot1_partition: partition@7de000 { + label = "image-1"; + reg = <0x7DE000 0x7BE000>; + }; + /* BLE bond store — 16KB NVS, isolated from /lfs (see esp32_common.conf). + * Carved from the end of slot1 so lfs stays byte-identical. */ + storage_partition: partition@f9c000 { + label = "storage"; + reg = <0xF9C000 0x4000>; + }; + /* LittleFS 384 KB for DataStore (identity, prefs, contacts) */ lfs_partition: partition@fa0000 { label = "lfs"; reg = <0xFA0000 0x60000>; diff --git a/zephcore/boards/esp32/heltec_wireless_tracker/board.overlay b/zephcore/boards/esp32/heltec_wireless_tracker/board.overlay index 24f550c..0a6b0bf 100644 --- a/zephcore/boards/esp32/heltec_wireless_tracker/board.overlay +++ b/zephcore/boards/esp32/heltec_wireless_tracker/board.overlay @@ -234,10 +234,35 @@ /delete-node/ &storage_partition; /delete-node/ &scratch_partition; /delete-node/ &coredump_partition; +/delete-node/ &slot0_partition; +/delete-node/ &slot1_partition; + +/ { + chosen { + zephyr,settings-partition = &storage_partition; + }; +}; &flash0 { partitions { - /* LittleFS 384KB for DataStore + file-based BLE settings */ + /* App slots — both trimmed 8KB so slot0 == slot1 (16KB total freed + * for the NVS partition below), keeping MCUboot swap-mode compatible, + * not just overwrite-only. slot0 start (0x20000) unchanged. */ + slot0_partition: partition@20000 { + label = "image-0"; + reg = <0x20000 0x3BE000>; + }; + slot1_partition: partition@3de000 { + label = "image-1"; + reg = <0x3DE000 0x3BE000>; + }; + /* BLE bond store — 16KB NVS, isolated from /lfs (see esp32_common.conf). + * Carved from the end of slot1 so lfs stays byte-identical. */ + storage_partition: partition@79c000 { + label = "storage"; + reg = <0x79C000 0x4000>; + }; + /* LittleFS 384KB for DataStore (identity, prefs, contacts) */ lfs_partition: partition@7a0000 { label = "lfs"; reg = <0x7A0000 0x60000>; diff --git a/zephcore/boards/esp32/lilygo_tlora_c6/board.overlay b/zephcore/boards/esp32/lilygo_tlora_c6/board.overlay index 3829ed6..596390a 100644 --- a/zephcore/boards/esp32/lilygo_tlora_c6/board.overlay +++ b/zephcore/boards/esp32/lilygo_tlora_c6/board.overlay @@ -64,14 +64,27 @@ * 0x3B0000 - 0x3E0000 (192KB) LittleFS (identity, contacts, channels, BLE bonds) */ /delete-node/ &storage_partition; +/delete-node/ &scratch_partition; + +/ { + chosen { + zephyr,settings-partition = &storage_partition; + }; +}; &flash0 { partitions { - /* LittleFS 192KB for DataStore + file-based BLE settings */ + /* LittleFS 192KB for DataStore (identity, prefs, contacts) */ lfs_partition: partition@3b0000 { label = "lfs"; reg = <0x3B0000 0x30000>; }; + /* BLE bond store — 16KB NVS, isolated from /lfs (see esp32_common.conf). + * Placed in the unused scratch region just above lfs (lfs unchanged). */ + storage_partition: partition@3e0000 { + label = "storage"; + reg = <0x3E0000 0x4000>; + }; }; }; diff --git a/zephcore/boards/esp32/station_g2/board.overlay b/zephcore/boards/esp32/station_g2/board.overlay index 2590c9b..1d2cb2f 100644 --- a/zephcore/boards/esp32/station_g2/board.overlay +++ b/zephcore/boards/esp32/station_g2/board.overlay @@ -86,20 +86,51 @@ /* * Flash partitions — repartition default ESP32-S3 16 MB layout. - * Default storage_partition is 192 KB at 0xFB0000. * Delete unused partitions (lpcore, scratch, coredump) to reclaim space. * - * 0xFA0000 - 0x1000000 (384KB) LittleFS (identity, contacts, channels, BLE bonds) + * 0x7E0000 - 0xF9C000 (~7.7MB) OTA image-1 (slot1, trimmed 16KB) + * 0xF9C000 - 0xFA0000 (16KB) NVS BLE bonds (storage_partition) + * 0xFA0000 - 0x1000000 (384KB) LittleFS (identity, contacts, channels) + * + * Bonds live in the NVS storage_partition (isolated) instead of /lfs, so + * settings-write churn can't corrupt identity/prefs/contacts. The NVS + * region is carved from the end of slot1 (unused in the default simple-boot + * build) so lfs_partition stays byte-identical — existing user data survives. */ /delete-node/ &slot0_lpcore_partition; /delete-node/ &slot1_lpcore_partition; /delete-node/ &storage_partition; /delete-node/ &scratch_partition; /delete-node/ &coredump_partition; +/delete-node/ &slot0_partition; +/delete-node/ &slot1_partition; + +/ { + chosen { + zephyr,settings-partition = &storage_partition; + }; +}; &flash0 { partitions { - /* LittleFS 384KB for DataStore + file-based BLE settings */ + /* App slots — both trimmed 8KB so slot0 == slot1 (16KB total freed + * for the NVS partition below), keeping MCUboot swap-mode compatible, + * not just overwrite-only. slot0 start (0x20000) unchanged. */ + slot0_partition: partition@20000 { + label = "image-0"; + reg = <0x20000 0x7BE000>; + }; + slot1_partition: partition@7de000 { + label = "image-1"; + reg = <0x7DE000 0x7BE000>; + }; + /* BLE bond store — 16KB NVS, isolated from /lfs. label "storage" + * so the existing formatter/factory-reset paths erase it too. */ + storage_partition: partition@f9c000 { + label = "storage"; + reg = <0xF9C000 0x4000>; + }; + /* LittleFS 384KB for DataStore (identity, prefs, contacts) */ lfs_partition: partition@fa0000 { label = "lfs"; reg = <0xFA0000 0x60000>; diff --git a/zephcore/boards/esp32/ttgo_lora32/board.overlay b/zephcore/boards/esp32/ttgo_lora32/board.overlay index 01c4346..df00eff 100644 --- a/zephcore/boards/esp32/ttgo_lora32/board.overlay +++ b/zephcore/boards/esp32/ttgo_lora32/board.overlay @@ -30,6 +30,13 @@ * but we leave them to avoid changing the partition map. */ /delete-node/ &storage_partition; +/delete-node/ &scratch_partition; + +/ { + chosen { + zephyr,settings-partition = &storage_partition; + }; +}; &flash0 { partitions { @@ -38,6 +45,12 @@ label = "lfs"; reg = <0x3B0000 0x30000>; }; + /* BLE bond store — 16KB NVS, isolated from /lfs (see esp32_common.conf). + * Placed in the unused scratch region just above lfs (lfs unchanged). */ + storage_partition: partition@3e0000 { + label = "storage"; + reg = <0x3E0000 0x4000>; + }; }; }; diff --git a/zephcore/boards/esp32/ttgo_tbeam/board.overlay b/zephcore/boards/esp32/ttgo_tbeam/board.overlay index 1d3314b..679b59c 100644 --- a/zephcore/boards/esp32/ttgo_tbeam/board.overlay +++ b/zephcore/boards/esp32/ttgo_tbeam/board.overlay @@ -152,6 +152,13 @@ * LittleFS, same as ttgo_lora32. The 4MB AMP layout keeps its MCUboot slots. */ /delete-node/ &storage_partition; +/delete-node/ &scratch_partition; + +/ { + chosen { + zephyr,settings-partition = &storage_partition; + }; +}; &flash0 { partitions { @@ -160,6 +167,12 @@ label = "lfs"; reg = <0x3B0000 0x30000>; }; + /* BLE bond store — 16KB NVS, isolated from /lfs (see esp32_common.conf). + * Placed in the unused scratch region just above lfs (lfs unchanged). */ + storage_partition: partition@3e0000 { + label = "storage"; + reg = <0x3E0000 0x4000>; + }; }; }; diff --git a/zephcore/boards/esp32/xiao_esp32c3/board.overlay b/zephcore/boards/esp32/xiao_esp32c3/board.overlay index bcc4557..cc5b4f3 100644 --- a/zephcore/boards/esp32/xiao_esp32c3/board.overlay +++ b/zephcore/boards/esp32/xiao_esp32c3/board.overlay @@ -60,14 +60,27 @@ * 0x3B0000 - 0x3E0000 (192KB) LittleFS (identity, contacts, channels, BLE bonds) */ /delete-node/ &storage_partition; +/delete-node/ &scratch_partition; + +/ { + chosen { + zephyr,settings-partition = &storage_partition; + }; +}; &flash0 { partitions { - /* LittleFS 192KB for DataStore + file-based BLE settings */ + /* LittleFS 192KB for DataStore (identity, prefs, contacts) */ lfs_partition: partition@3b0000 { label = "lfs"; reg = <0x3B0000 0x30000>; }; + /* BLE bond store — 16KB NVS, isolated from /lfs (see esp32_common.conf). + * Placed in the unused scratch region just above lfs (lfs unchanged). */ + storage_partition: partition@3e0000 { + label = "storage"; + reg = <0x3E0000 0x4000>; + }; }; }; diff --git a/zephcore/boards/esp32/xiao_esp32c6/board.overlay b/zephcore/boards/esp32/xiao_esp32c6/board.overlay index 495d0c7..6778f40 100644 --- a/zephcore/boards/esp32/xiao_esp32c6/board.overlay +++ b/zephcore/boards/esp32/xiao_esp32c6/board.overlay @@ -60,14 +60,27 @@ * 0x3B0000 - 0x3E0000 (192KB) LittleFS (identity, contacts, channels, BLE bonds) */ /delete-node/ &storage_partition; +/delete-node/ &scratch_partition; + +/ { + chosen { + zephyr,settings-partition = &storage_partition; + }; +}; &flash0 { partitions { - /* LittleFS 192KB for DataStore + file-based BLE settings */ + /* LittleFS 192KB for DataStore (identity, prefs, contacts) */ lfs_partition: partition@3b0000 { label = "lfs"; reg = <0x3B0000 0x30000>; }; + /* BLE bond store — 16KB NVS, isolated from /lfs (see esp32_common.conf). + * Placed in the unused scratch region just above lfs (lfs unchanged). */ + storage_partition: partition@3e0000 { + label = "storage"; + reg = <0x3E0000 0x4000>; + }; }; }; diff --git a/zephcore/boards/esp32/xiao_esp32s3/board.overlay b/zephcore/boards/esp32/xiao_esp32s3/board.overlay index 54b9d91..9f88a21 100644 --- a/zephcore/boards/esp32/xiao_esp32s3/board.overlay +++ b/zephcore/boards/esp32/xiao_esp32s3/board.overlay @@ -73,10 +73,35 @@ /delete-node/ &storage_partition; /delete-node/ &scratch_partition; /delete-node/ &coredump_partition; +/delete-node/ &slot0_partition; +/delete-node/ &slot1_partition; + +/ { + chosen { + zephyr,settings-partition = &storage_partition; + }; +}; &flash0 { partitions { - /* LittleFS 384KB for DataStore + file-based BLE settings */ + /* App slots — both trimmed 8KB so slot0 == slot1 (16KB total freed + * for the NVS partition below), keeping MCUboot swap-mode compatible, + * not just overwrite-only. slot0 start (0x20000) unchanged. */ + slot0_partition: partition@20000 { + label = "image-0"; + reg = <0x20000 0x1BE000>; + }; + slot1_partition: partition@1de000 { + label = "image-1"; + reg = <0x1DE000 0x1BE000>; + }; + /* BLE bond store — 16KB NVS, isolated from /lfs (see esp32_common.conf). + * Carved from the end of slot1 so lfs stays byte-identical. */ + storage_partition: partition@39c000 { + label = "storage"; + reg = <0x39C000 0x4000>; + }; + /* LittleFS 384KB for DataStore (identity, prefs, contacts) */ lfs_partition: partition@3a0000 { label = "lfs"; reg = <0x3A0000 0x60000>;