From a28a8755942e651ed21949a39e1c3447195c93f6 Mon Sep 17 00:00:00 2001 From: Reuven Date: Tue, 10 Mar 2026 08:40:47 -0400 Subject: [PATCH] fix(firmware): provision.py nvs import + partition config template Fixes #215: provision.py now correctly imports from esp_idf_nvs_partition_gen package (the pip-installable version) before falling back to legacy import. Fixes #216: Added sdkconfig.defaults.template with custom partition table configuration for 8MB flash boards. Copy to sdkconfig.defaults before build: cp sdkconfig.defaults.template sdkconfig.defaults Changes: - firmware/esp32-csi-node/provision.py: Try esp_idf_nvs_partition_gen first - scripts/provision.py: Same import fix - firmware/esp32-csi-node/sdkconfig.defaults.template: 8MB flash config with 2MB OTA partitions, compiler size optimization, and CSI enabled Co-Authored-By: claude-flow --- firmware/esp32-csi-node/provision.py | 11 ++++++- .../sdkconfig.defaults.template | 32 +++++++++++++++++++ scripts/provision.py | 11 ++++++- 3 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 firmware/esp32-csi-node/sdkconfig.defaults.template diff --git a/firmware/esp32-csi-node/provision.py b/firmware/esp32-csi-node/provision.py index b6d98bb1..752044fe 100644 --- a/firmware/esp32-csi-node/provision.py +++ b/firmware/esp32-csi-node/provision.py @@ -76,7 +76,16 @@ def generate_nvs_binary(csv_content, size): bin_path = csv_path.replace(".csv", ".bin") try: - # Try the pip-installed version first + # Try the pip-installed version first (esp_idf_nvs_partition_gen package) + try: + from esp_idf_nvs_partition_gen import nvs_partition_gen + nvs_partition_gen.generate(csv_path, bin_path, size) + with open(bin_path, "rb") as f: + return f.read() + except ImportError: + pass + + # Try legacy import name (older versions) try: import nvs_partition_gen nvs_partition_gen.generate(csv_path, bin_path, size) diff --git a/firmware/esp32-csi-node/sdkconfig.defaults.template b/firmware/esp32-csi-node/sdkconfig.defaults.template new file mode 100644 index 00000000..be8a09a0 --- /dev/null +++ b/firmware/esp32-csi-node/sdkconfig.defaults.template @@ -0,0 +1,32 @@ +# ESP32-S3 CSI Node — Default SDK Configuration +# This file is applied automatically by idf.py when no sdkconfig exists. + +# Target: ESP32-S3 +CONFIG_IDF_TARGET="esp32s3" + +# Use custom partition table (8MB flash with OTA — ADR-045) +CONFIG_PARTITION_TABLE_CUSTOM=y +CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions_display.csv" + +# Flash configuration: 8MB (Quad SPI) +CONFIG_ESPTOOLPY_FLASHSIZE_8MB=y +CONFIG_ESPTOOLPY_FLASHSIZE="8MB" + +# Compiler optimization: optimize for size to reduce binary +CONFIG_COMPILER_OPTIMIZATION_SIZE=y + +# Enable CSI (Channel State Information) in WiFi driver +CONFIG_ESP_WIFI_CSI_ENABLED=y + +# Enable NVS encryption for secure credential storage +CONFIG_NVS_ENCRYPTION=y + +# Disable unused features to reduce binary size +CONFIG_BOOTLOADER_LOG_LEVEL_WARN=y +CONFIG_LOG_DEFAULT_LEVEL_INFO=y + +# LWIP: enable extended socket options for UDP multicast +CONFIG_LWIP_SO_RCVBUF=y + +# FreeRTOS: increase task stack for CSI processing +CONFIG_ESP_MAIN_TASK_STACK_SIZE=8192 diff --git a/scripts/provision.py b/scripts/provision.py index 71d4b1b8..f46f1543 100644 --- a/scripts/provision.py +++ b/scripts/provision.py @@ -80,7 +80,16 @@ def generate_nvs_binary(csv_content, size): bin_path = csv_path.replace(".csv", ".bin") try: - # Try the pip-installed version first + # Try the pip-installed version first (esp_idf_nvs_partition_gen package) + try: + from esp_idf_nvs_partition_gen import nvs_partition_gen + nvs_partition_gen.generate(csv_path, bin_path, size) + with open(bin_path, "rb") as f: + return f.read() + except ImportError: + pass + + # Try legacy import name (older versions) try: import nvs_partition_gen nvs_partition_gen.generate(csv_path, bin_path, size)