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
  • I appreciate sending the links they are very helpful.

    The process of linking to a library in Zephyr is not very clear to me. Do I add the cryptocell-312-runtime source to my code and try to compile or the cryptocell-312-runtime library is already linked (this is probably the case, because I use mbedTLS)? 

    But when I makes calls to cryptocell Iibrary, I get errors.

    If you cannot respond to this I understand. Thanks for the help so far.

Children
  • Hi,

    persimmon said:
    Do I add the cryptocell-312-runtime source to my code and try to compile

    You cannot simply build the CC312 runtime library and make it work with the nRF. There is a platform abstraction layer etc that needs to be implemented. The implementation used in the nrfxlib is not available in source so I cannot share that unfortunately. I do not recommend going down the path of using the CC312 library directly, and we cannot provide support for it. But as you see it is available and you can use it as you want.

    persimmon said:
    or the cryptocell-312-runtime library is already linked (this is probably the case, because I use mbedTLS)?

    Yes, it is part of the cc312_mbedcrypto library.

Related