Files
firmware/src/platform
IxitxachitlandBen Meadors e8d4573af7 fix(t-watch-ultra): wrap esp_flash_read so NVS survives, keeping BLE bonds (#11583)
* fix(t-watch-ultra): wrap esp_flash_read so NVS survives, keeping BLE bonds

The IDF 5.5 manual-read regression on this board's flash is already worked
around for esp_partition_read, but nvs_flash does not use that API: it reads
the NVS partition through the lower-level esp_flash_read, which still returns
0x00. NVS therefore initialised empty on every boot -- zero entries, zero
namespaces -- even though the data was intact on flash.

Everything stored through NVS was lost each boot, including NimBLE's bond
table. A phone that had already paired was not recognised on reconnect, so
the device ran a fresh pairing and displayed a new passkey every time. The
PIN worked, but the bond never persisted.

Wrap esp_flash_read the same way, using the raw (non-partition) spi_flash_mmap
so it serves callers that never go through the esp_partition_t API. Reads for
any chip other than the default fall back to the real implementation, as do
mmap failures. Gated on T_WATCH_ULTRA; no other board is affected.

* fix(t-watch-ultra): keep the raw-read contract when flash encryption is on

esp_flash_read is specified to return raw, still-encrypted bytes; the flash
cache is what decrypts transparently. Reading through spi_flash_mmap therefore
hands back plaintext where the caller asked for ciphertext.

No target here enables CONFIG_SECURE_FLASH_ENC_ENABLED, so nothing is affected
today, but --wrap is a global interposition and encryption can be burned into
efuse independently of the build config. Check at runtime and leave encrypted
flash to the real implementation.

---------

Co-authored-by: Ben Meadors <benmmeadors@gmail.com>
2026-08-24 23:02:04 +00:00
..