Matter : SRP update error: domain name or RRset is duplicated when using external flash for settings_storage using "nordic,qspi-nor" compatible flash.

First, I'm using an NRF connect 2.3.0 and applying the light_bulb sample with a custom nrf52840 board with an external is25wp064a flash using QSPI.

Moving the settings_storage to the external flash I had problems commissioning the device using HomeKit (previously worked with the internal flash), I always got the error [DL] Error from SRP Update: The domain name or RRset is duplicated.

I'm using "nordic_qspi_nor" compatible flash.

After several investigations and troubleshooting and inspired by the answer for case 300157 (also referring to the openthread issue https://github.com/openthread/openthread/issues/8056), where it says that SRP updates are signed at using ECDSA.
Adding additional traces, I first realized that openthread wanted to save the ECDSA_KEY setting from a word unaligned memory location which will lead the nrfx_qspi code to return an NRFX_ERROR_INVALID_ADDR error from the qspi_xfer function.
Apparently the qspi_nor_write function (in nrf_qspi_nor.c the base code) only calls the write_from_nvmc function for "src" memory not in ram (!nrfx_is_in_ram), and does not test its alignment.
Thus, by adding in the qspi_nor_write function the condition (!nrfx_is_word_aligned) to force a call to the write_from_nvmc function for an unaligned memory source, remove the NRFX_ERROR_INVALID_ADDR error.
However, for the commissioning to happen totally, that was not enough, the saved ECDSA_KEY is corrupted, reading the parameter Openthread got a key with the last 2 bytes with a value that is not the same at the time he save it!
Further investigation into the write_from_nvmc function when openthread tries to save ECDSA_KEY reveals to me another problem in the write_from_nvmc function itself.
if the length of the buffer to write (slen) is not a multiple of CONFIG_NORDIC_QSPI_NOR_STACK_WRITE_BUFFER_SIZE than the case of an ECDSA_KEY, the nrfx_qspi_write function is always called using sizeof(buf) as tx_buffer_length.
To handle this case it has to be called using the "len" variable which is the min between the remaining part and the buffer size.

By changing "res = nrfx_qspi_write(buf, sizeof(buf), addr);" with "res = nrfx_qspi_write(buf, len, addr);" now solve the last problem preventing the commission from happening.
I can now commission the device using HomeKit having the setting saved in the external flash :-)
Looking at the latest version in GitHub https://github.com/nrfconnect/sdk-zephyr/blob/main/drivers/flash/nrf_qspi_nor.c , it looks like the latest version of the code still doesn't fix this issue.
Can you take a look and see if these qspi_nor_write issues can be officially resolved.

Thank you Best regards
Parents Reply Children
No Data
Related