From b0e3b6f4a05f531e30419d1ae93b28fadee8b2b6 Mon Sep 17 00:00:00 2001 From: Matt Spencer Date: Sat, 17 Oct 2026 16:13:47 +0100 Subject: [PATCH] fix(flash): give zigbee persistence its own partition The default espflash layout hands the whole 0x10000..0x400000 span to the app partition, so the storage range sat inside it. Shrink the app and reserve a dedicated storage partition above it. --- .cargo/config.toml | 2 +- partitions.csv | 7 +++++++ src/zigbee_stack.rs | 8 ++++---- 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 partitions.csv diff --git a/.cargo/config.toml b/.cargo/config.toml index 6fd40dd..76aad10 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -2,7 +2,7 @@ target = "riscv32imac-unknown-none-elf" [target.riscv32imac-unknown-none-elf] -runner = "espflash flash --monitor" +runner = "espflash flash --monitor --partition-table partitions.csv" rustflags = [ "-C", "link-arg=-Tlinkall.x", "-C", "force-frame-pointers", diff --git a/partitions.csv b/partitions.csv new file mode 100644 index 0000000..b299717 --- /dev/null +++ b/partitions.csv @@ -0,0 +1,7 @@ +# Name, Type, SubType, Offset, Size, Flags +nvs, data, nvs, 0x9000, 0x6000, +phy_init, data, phy, 0xf000, 0x1000, +factory, app, factory, 0x10000, 0x3D0000, +# Zigbee persistence: the stack writes this region directly, so it must not +# overlap the app partition. Keep in sync with FLASH_RANGE in zigbee_stack.rs. +storage, data, nvs, 0x3E0000, 0x20000, diff --git a/src/zigbee_stack.rs b/src/zigbee_stack.rs index f4f66d4..53d4361 100644 --- a/src/zigbee_stack.rs +++ b/src/zigbee_stack.rs @@ -41,10 +41,10 @@ use crate::light; /// Flash region reserved for Zigbee persistence. /// -/// MUST match the partition table: erase-sector aligned (4 KiB) and at least -/// two sectors so sequential-storage has a spare for garbage collection. The -/// address assumes the 4 MiB flash of the XIAO ESP32C6. -pub const FLASH_RANGE: Range = 0x3f_0000..0x3f_4000; +/// MUST match the `storage` partition in partitions.csv: erase-sector aligned +/// (4 KiB) and at least two sectors so sequential-storage has a spare for +/// garbage collection. +pub const FLASH_RANGE: Range = 0x3e_0000..0x3e_4000; /// Extended PAN ID of the network to join. ///