Today I fixed a bug in the Zephyr RTOS Flash Simulator (#100352 and #100400).
The Bug
The simulated flash driver incorrectly applied the no_explicit_erase capability. It was overriding the Kconfig settings with a missing Devicetree property since it used a global fallback but couldn’t accommodate boolean properties naturally. This caused even RAM-like configurations (which do not require erasing before writing) to wrongly report needing explicit erases.
The Fix
To resolve this issue, I submitted PR #105035 with the following targeted fixes:
- Added
no-explicit-eraseto Devicetree Bindings: I extendedzephyr,sim-flash.yamlto accept a booleanno-explicit-eraseproperty, allowing per-instance configuration without relying entirely on a global Kconfig. - Updated the Initialization Macro: In
flash_simulator.c, I added theFLASH_SIMULATOR_NO_EXPLICIT_ERASEmacro. This performs a logical OR between the Devicetree property and the Kconfig fallback, ensuring that the runtime capability accurately reflects either option correctly. - Added Unit Tests: I wrote
test_erase_capabilityas a new ztest suite scenario to fully verifyflash_params_get_erase_cap(). Now I evaluate the runtimecaps.no_explicit_erasevalue instead of relying purely on#ifcompile-time guards.
Planning & Root Cause Analysis
If you want to read deeper into my initial plan, the specific root cause analysis, and the different approaches I considered, check out the full fix plan document here: