This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Unaligned memory access Fault using mbedTLS on nrf5340 cpuapp

I took the RSA example in /nrf/samples/crypto/rsa and added a function foo() to it. I am using nrf5340DK with nrfConnect v1.6.1 and build for cpuapp. 

my function foo() uses mbedtls functions heavily and makes a call to mbedtls_entropy_init(entropy

 I get the following exception when the mbedtls_entropy_init(entropy)  function is called from foo().

os: ***** USAGE FAULT ***** 
os:   Unaligned memory access 
r0/a1:  0x00000000  r1/a2:  0x00000000  r2/a3:  0x200331d4 
r3/a4:  0x00022845 r12/ip:  0x00000000 r14/lr:  0x00004621 
os:  xpsr:  0x69000000 
os: Faulting instruction address (r15/pc): 0x00023be8 
os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0 
os: Current thread: 0x200003c8 (unknown) 
fatal_error: Resetting system 

here is the stack call.
mbedtls_entropy_init( &drbg->entropy );
mbedtls_mutex_init( &ctx->mutex );
mutex_init_platform(){

...
     p_mutex = (struct k_mutex *)mutex->mutex;  //p_mutex is NOT aligned 0x00022875
     k_mutex_init(p_mutex);
...
}
k_mutex_init(p_mutex) --> z_impl_k_mutex_init()
mutex->owner = NULL; <<----- exception happens here.
The rsa program itself makes a call to mutex_init_platform() as well. I checked all the values of p_mutex and all of them are aligned by 8 bytes. However my mbedtls calls leads to unaligned p_mutex values.

I appreciate if you could help me resolve this issue.




Parents Reply Children
  • Thanks for clarification. I notice there is an alt implementation of mbedtls in the following link

    All I need is to be able to modify a function in the following file and/or add my own function there and being able to call it from my program( never mind the compatibility etc). I know how to modify it. But I don't know how to have it compiled and linked. 

    Function in this file make calls to CC_* functions. They are low level enough for me.

     modules/tee/tfm/trusted-firmware-m/lib/ext/cryptocell-312-runtime/codesafe/src/mbedtls_api/rsa_alt.c   

    Regards,
    P.

  • This is from the ARM version of the runtime library (used for the ARM Musca boards). As mentioned, the one used for Nordic devices is supplied as binary only. And that has a lot of our changes. I am afraid we cannot support bypassing all that. You are of course free to experiment on your own, though.

Related