This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to debug TF-M ns code on FVP_MPS2_AEMv8M?

I know how to debug mcuboot and tfm-s image, it can be done in this way:

Start the CADI Debug Server in one terminal:

/usr/local/DS-5_v5.27.1/bin/FVP_MPS2_AEMv8M --parameter fvp_mps2.platform_type=2 --parameter cpu0.baseline=0 --parameter cpu0.INITVTOR_S=0x10000000 --parameter cpu0.semihosting-enable=0 --parameter fvp_mps2.DISABLE_GATING=0 --parameter fvp_mps2.telnetterminal0.start_telnet=1 --parameter fvp_mps2.telnetterminal1.start_telnet=0 --parameter fvp_mps2.telnetterminal2.start_telnet=0 --parameter fvp_mps2.telnetterminal0.quiet=0 --parameter fvp_mps2.telnetterminal1.quiet=1 --parameter fvp_mps2.telnetterminal2.quiet=1 --application cpu0=~/TF-M/trusted-firmware-m/cmake_build/bl2/ext/mcuboot/mcuboot.axf --data cpu0=~/TF-M/trusted-firmware-m/cmake_build/tfm_sign.bin@0x10080000 -S

Start debugger in the other terminal to debug secure image:

/usr/local/DS-5_v5.27.1/bin/debugger --cdb-entry "ARM FVP::MPS2_AEMv8M::Bare Metal Debug::Bare Metal Debug::Debug AEMv8M_0" --image "trusted-firmware-m/cmake_build/app/secure_fw/tfm_s.axf"
Connected to stopped target ARM_AEMv8M_0
Semihosting server socket created at port 8000
Semihosting enabled automatically due to semihosting symbol detected in image 'tfm_s.axf'
>b main
Breakpoint 1 at 0x10085CD0
on file tfm_core.c, line 159
>c
Execution stopped in Secure Thread mode at breakpoint 1: 0x10085CD0
In tfm_core.c
0x10085CD0 159,0 {
>s
Execution stopped in Secure Thread mode at 0x10085CD8
0x10085CD8 160,5 uart_init(UART0_CHANNEL);

But if I try to debug the non-secure image:

/usr/local/DS-5_v5.27.1/bin/debugger --cdb-entry "ARM FVP::MPS2_AEMv8M::Bare Metal Debug::Bare Metal Debug::Debug AEMv8M_0" --image "trusted-firmware-m/cmake_build/app/tfm_ns.axf"
Connected to stopped target ARM_AEMv8M_0
Semihosting server socket created at port 8000
Semihosting enabled automatically due to semihosting symbol detected in image 'tfm_ns.axf'
>b main
Breakpoint 1 at 0x00102358
on file main_ns.c, line 100
>c
>s
ERROR(CMD440-COR89):
! Stepping failed
! Target is currently running

The execution simply cannot achieve achieve the main() of non-secure image. And I know the root cause of the problem is the execution entry point and secure non-secure switch. But I just don't know how to make it right. Any idea? Thanks. 

  • To debug non-secure image, I have to do it this way.

    In another terminal:
    /usr/local/DS-5_v5.27.1/bin/debugger --cdb-entry "ARM FVP::MPS2_AEMv8M::Bare Metal Debug::Bare Metal Debug::Debug AEMv8M_0" --image "trusted-firmware-m/cmake_build/app/secure_fw/tfm_s.axf"

    >add-symbol-file trusted-firmware-m/cmake_build/app/tfm_ns.axf
    >b trusted-firmware-m/cmake_build/app/tfm_ns.axf:main

    Then, everything works as expected.