Hello,
In my project, I use both a Bluetooth interface for communication and the PSA functionalities to store and read/use keys.
I use the following configuration (excerpt) for the respective functionality:
CONFIG_MAIN_STACK_SIZE=8192 CONFIG_BT=y CONFIG_BT_SMP=y CONFIG_BT_SETTINGS=y CONFIG_BT_RX_STACK_SIZE=4096 CONFIG_BT_PERIPHERAL=y CONFIG_BT_MAX_PAIRED=9 CONFIG_MBEDTLS_PSA_CRYPTO_STORAGE_C=y CONFIG_MBEDTLS_HEAP_SIZE=8192 CONFIG_PSA_WANT_ALG_CTR=y CONFIG_TFM_ITS_ENCRYPTED=y CONFIG_HEAP_MEM_POOL_SIZE=8192 CONFIG_FLASH=y CONFIG_FLASH_PAGE_LAYOUT=y CONFIG_FLASH_MAP=y CONFIG_NVS=y CONFIG_SETTINGS=y CONFIG_SETTINGS_NVS=y CONFIG_TRUSTED_STORAGE=y
Both implementations (BLE, PSA) store their keys or settings in the ITS (Internal Trusted Storage).
The ITS is mapped to the internal flash. The following configuration is created in pm_static.yml for the corresponding partition:
settings_storage: address: 0xf0000 end_address: 0x100000 region: flash_primary size: 0x10000
During initial startup, keys are stored in the ITS via the PSA_ functions on my device. These are then used for authentication later on.
It can be assumed that the device with the error was paired with several devices via Bluetooth.
One device (out of several others) crashes (presumably with an exception) when I try to read a key with psa_export_key in order to use it later on.
The error can be fixed by calling bt_unpair for all bonding information on the device. From this point on, psa_export_key runs normally and also returns the expected key.
Unfortunately, I am unable to debug the code on the devices where the error occurs. And I have not yet been able to reproduce the error artificially.
I have already increased (doubled) the heap and stack on a trial basis, but this did not fix the error.
Has anyone here already experienced a crash with psa_export_key?
I don't understand:
- Is the error due to fragmentation of the memory area?
- What causes fragmentation of the ITS?
- Why can the error be fixed by calling bt_unpair?
- Are there any ideas on how I can artificially provoke the error?
Thanks in advance.
BR, Tom