-
Notifications
You must be signed in to change notification settings - Fork 7.4k
fs: nvs: fix invalid block compare when data CRC is enabled #90311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fs: nvs: fix invalid block compare when data CRC is enabled #90311
Conversation
304591e
to
8bd42c3
Compare
@yolaval I think this should be considered a bug. Would it be possible for you to log Zephyr issue for this and mark this PR as a fix? |
@yolaval, thanks for the catch. I wouldn't consider this a bug as it merely uses flash in a less optimal way and only in case a rewrite of the same data is done (and who does that...). @RICCIARDI-Adrien could you have a look. |
Indeed, the data CRC is added in |
6739cb4
to
e6d35dc
Compare
When nvs_write is called, the nvs_flash_block_cmp is used to check if the new data to be written matches the data already on flash. This check always fail when CONFIG_NVS_DATA_CRC is enabled, caused by the NVS_DATA_CRC_SIZE being added to the len parameter. The pointer to the new data does not already have the CRC part added, while the data on flash does, and the size to be compared includes CRC section. By removing the addition of NVS_DATA_CRC_SIZE to the compare size, only the data without CRC is compared, which will make the compare work in both cases. Signed-off-by: Yonas Alizadeh <yonas.alizadeh@alfalaval.com>
e6d35dc
to
28cf85b
Compare
@Laczen sorry for new force push after approval. Had to fix a trailing whitespace that had sneaked in. |
|
Should there be issue logged in Zephyr for that? |
When
nvs_write
is called, thenvs_flash_block_cmp
is used to check if the new data to be written matches the data already on flash (flash write is skipped and 0 is returned if matching). This check always fail whenCONFIG_NVS_DATA_CRC
is enabled, caused by theNVS_DATA_CRC_SIZE
being added to thelen
parameter. The pointer to the new data passed to the compare function does not already have the CRC part added, while the data on flash does and the size to be compared includes the CRC section. By removing the addition ofNVS_DATA_CRC_SIZE
to the compare size, only the data without CRC is compared, which will make the compare work in both cases.Tested locally on my NUCLEO-G491RE board.