2 years, 9 months ago.

mbedTLS Mutex Parameter Error

Hi,

I'm making a custom firmware update process on the Nordic nRF52832 using mbed-os and mbed-tls. I have build tools that put RSA-encrypted signature information in the application binary and the public key is stored elsewhere in flash.

I have it set up so far to transfer the binary over UART and save it into flash with the Nordic fstorage library (which requires the BLE stack/softdevice to be active and running). The binary is transferred properly and without error and in the past I was able to get the RSA signature verification to pass using mbed-tls libraries included with mbed-os.

After I realized a conflict with my structure and Nordic's requirements, I moved the signature data elsewhere in the binary. Everything transfers correctly again. The new transfer process uses slightly larger buffers (512 bytes as opposed to 80 bytes). Now when I execute the mbed-tls library function "mbedtls_rsa_pkcs1_verify" my program ends with an mbed_die and I get the following error message over the UART:

"Mutex 0x0 error -4: Parameter error"

Any clues as to what I should look for? I have started using the memory status library to track stack sizes and heap usage. Right before executing the verify function the memory status output looks like this:

"stack ( start: 200053D0 end: 200063D0 size: 00001000 used: 000004D8 ) thread ( id: 20005380 entry: 0003075D name: main_thread ) stack ( start: 20004058 end: 20004458 size: 00000400 used: 00000040 ) thread ( id: 20003FC8 entry: 00030865 name: unknown ) stack ( start: 20004458 end: 20004758 size: 00000300 used: 00000098 ) thread ( id: 20004010 entry: 00035D99 name: unknown ) stack ( start: 20006A38 end: 20007A38 size: 00001000 used: 000001D8 ) thread ( id: 200069E4 entry: 000360E5 name: application_unnamed_thread )"

It appears to be happening during an SVC call...

EDIT:

I found that if I moved BLE event processing to the main thread and used the spawned thread to run the encryption algorithms then I wouldn't encounter the crash/errors I was seeing before. I also reduced the stack size of the spawned thread until the encryption algorithm failed (it came back with a non-zero error) but even then mbed didn't crash.

Why would the specific thread I'm using for encryption algorithms have any effect on whether my program runs without crashing or not?

Be the first to answer this question.