Device getting reset when use printf() (or) printk() in secure functions while calling the secure functions from non-secure firmware

Hello,

We are developing a library which is intended to use the trustzone feature available with nrf5340 DK. We followed the instructions available in Using a custom Secure Partition Manager with your application and succeeded in adding custom secure services.

When we try to debug with secure services functions in SPM, we are facing the "device reset issue" when use the printf() (or) printk() function in secure functions while calling the secure function(spm_secure_function()) from non-secure firmware.

Is it a bug or a limitation imposed in SPM? Could you please help to clarify and also any solution to fix this problem for easy debugging with secure functions?

Device not reset case:

__TZ_NONSECURE_ENTRY_FUNC
void spm_secure_function(void)
{
    // DO SOMETHING
}

Device resetting case:

__TZ_NONSECURE_ENTRY_FUNC
void spm_secure_function(void)
{
   printf("spm_secure_function called\n");
}

Parents
  • I'm able to reproduce this. I added following to the prj.conf of the application:

    CONFIG_LOG=y
    CONFIG_RESET_ON_FATAL_ERROR=n
    CONFIG_THREAD_NAME=y

    Then I added a printk to the secure function, and built and flash the program (53 nonsecure). I got the following error:

    22 NRF_EGU2             Non-Secure	OK
    23 NRF_DPPIC            Non-Secure	OK
    24 NRF_GPIOTE1          Non-Secure	OK
    25 NRF_REGULATORS       Non-Secure	OK
    
    SPM: NS image at 0x8000
    SPM: NS MSP at 0x20008b58
    SPM: NS reset vector at 0x9ce1
    SPM: prepare to jump to Non-Secure image.
    *** Booting Zephyr OS build v2.4.0-ncs1  ***
    Hello World! nrf5340dk_nrf5340_cpuapp
    [00:00:00.007,751] [1B][1;31m<err> os: Exception occurred in Secure State[1B][0m
    [00:00:00.007,751] [1B][1;31m<err> os: ***** BUS FAULT *****[1B][0m
    [00:00:00.007,751] [1B][1;31m<err> os:   Precise data bus error[1B][0m
    [00:00:00.007,751] [1B][1;31m<err> os:   BFAR Address: 0x50008120[1B][0m
    [00:00:00.007,751] [1B][1;31m<err> os: r0/a1:  0x00000000  r1/a2:  0x0000c171  r2/a3:  0x00000000[1B][0m
    [00:00:00.007,781] [1B][1;31m<err> os: r3/a4:  0x00009ba3 r12/ip:  0x9284105e r14/lr:  0xb7e75c18[1B][0m
    [00:00:00.007,781] [1B][1;31m<err> os:  xpsr:  0x78854a00[1B][0m
    [00:00:00.007,781] [1B][1;31m<err> os: Faulting instruction address (r15/pc): 0xfbcb0978[1B][0m
    [00:00:00.007,781] [1B][1;31m<err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0[1B][0m
    [00:00:00.007,781] [1B][1;31m<err> os: Current thread: 0x20008208 (main)[1B][0m
    [00:00:00.076,934] [1B][1;31m<err> os: Halting system[1B][0m
    

    By looking at BFAR Address: 0x50008120, you can see that faults when it tries to access UART0 secure

    I will get back to you later with more information

    Best regards,

    Simon

Reply
  • I'm able to reproduce this. I added following to the prj.conf of the application:

    CONFIG_LOG=y
    CONFIG_RESET_ON_FATAL_ERROR=n
    CONFIG_THREAD_NAME=y

    Then I added a printk to the secure function, and built and flash the program (53 nonsecure). I got the following error:

    22 NRF_EGU2             Non-Secure	OK
    23 NRF_DPPIC            Non-Secure	OK
    24 NRF_GPIOTE1          Non-Secure	OK
    25 NRF_REGULATORS       Non-Secure	OK
    
    SPM: NS image at 0x8000
    SPM: NS MSP at 0x20008b58
    SPM: NS reset vector at 0x9ce1
    SPM: prepare to jump to Non-Secure image.
    *** Booting Zephyr OS build v2.4.0-ncs1  ***
    Hello World! nrf5340dk_nrf5340_cpuapp
    [00:00:00.007,751] [1B][1;31m<err> os: Exception occurred in Secure State[1B][0m
    [00:00:00.007,751] [1B][1;31m<err> os: ***** BUS FAULT *****[1B][0m
    [00:00:00.007,751] [1B][1;31m<err> os:   Precise data bus error[1B][0m
    [00:00:00.007,751] [1B][1;31m<err> os:   BFAR Address: 0x50008120[1B][0m
    [00:00:00.007,751] [1B][1;31m<err> os: r0/a1:  0x00000000  r1/a2:  0x0000c171  r2/a3:  0x00000000[1B][0m
    [00:00:00.007,781] [1B][1;31m<err> os: r3/a4:  0x00009ba3 r12/ip:  0x9284105e r14/lr:  0xb7e75c18[1B][0m
    [00:00:00.007,781] [1B][1;31m<err> os:  xpsr:  0x78854a00[1B][0m
    [00:00:00.007,781] [1B][1;31m<err> os: Faulting instruction address (r15/pc): 0xfbcb0978[1B][0m
    [00:00:00.007,781] [1B][1;31m<err> os: >>> ZEPHYR FATAL ERROR 0: CPU exception on CPU 0[1B][0m
    [00:00:00.007,781] [1B][1;31m<err> os: Current thread: 0x20008208 (main)[1B][0m
    [00:00:00.076,934] [1B][1;31m<err> os: Halting system[1B][0m
    

    By looking at BFAR Address: 0x50008120, you can see that faults when it tries to access UART0 secure

    I will get back to you later with more information

    Best regards,

    Simon

Children
No Data
Related