Implement versioned NVS key migration on ESP32-S3 firmware so OTA-updated firmware gracefully handles NVS written by older versions. - Add nvs_migration.c/h with migration framework - On boot, read schema_ver from NVS; initialize to 1 if missing - Run migrations sequentially if schema_ver < COMPILED_NVS_VERSION - Each migration commits after each write for durability - Log all migration steps to UART for debugging - Example migration v1→v2: rename 'ms_ip' to 'mothership_ip', add 'ntp_server' with default 'pool.ntp.org' - Migration failure leaves NVS in consistent state Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
15 lines
464 B
C
15 lines
464 B
C
#pragma once
|
|
|
|
#include "esp_err.h"
|
|
#include <stdint.h>
|
|
|
|
// Current compiled NVS schema version
|
|
// Increment this when adding new migrations
|
|
#define COMPILED_NVS_VERSION 1
|
|
|
|
// Run NVS schema migration on boot
|
|
// Opens 'spaxel' NVS namespace and reads schema_ver.
|
|
// If missing, initializes schema_ver to 1.
|
|
// If schema_ver < COMPILED_NVS_VERSION, runs migrations in order.
|
|
// Returns ESP_OK on success, or error code on failure.
|
|
esp_err_t nvs_migration_run(void);
|