Registered User mNo edit summary |
Registered User mNo edit summary |
||
(13 intermediate revisions by 3 users not shown) | |||
Line 2: | Line 2: | ||
== Article purpose == | == Article purpose == | ||
This article explains how to debug TF-A SP-MIN firmware.<br> | This article explains how to debug TF-A SP-MIN firmware.<br> | ||
Debug is specifically linked to the TrustZone environment. | Debug is specifically linked to the TrustZone<sup>®</sup> environment. | ||
There are two main ways to debug TF-A, using traces inside the code, or by using JTAG to access the secure world. | There are two main ways to debug TF-A, by using traces inside the code, or by using JTAG to access the secure world. | ||
This article focuses on the solution integrated in OpenSTLinux, debug over gdb (based on ST-Link or JTAG). | |||
, | |||
== Debugging == | == Debugging == | ||
=== TF-A | === TF-A version number === | ||
The starting point for debugging is to identify the TF-A BL2 version used in the target. Debug and release versions are displayed on the console with the following format:<br> | The starting point for debugging is to identify the TF-A BL2 version used in the target. Debug and release versions are displayed on the console with the following format:<br> | ||
Line 18: | Line 19: | ||
* <tag> : Git reference resulting from the '''git describe''' command at build time | * <tag> : Git reference resulting from the '''git describe''' command at build time | ||
=== | === Debugging with traces === | ||
TF-A allows RELEASE and DEBUG modes to be enabled: | TF-A allows RELEASE and DEBUG modes to be enabled: | ||
* RELEASE mode builds with default LOG_LEVEL to 20, which only prints ERROR and NOTICE traces | * RELEASE mode builds with default LOG_LEVEL to 20, which only prints ERROR and NOTICE traces. | ||
* DEBUG mode enables the -g build flag (for | * DEBUG mode enables the -g build flag (for debugging the build object), and set LOG_LEVEL default value to 40. | ||
With the debug LOG_LEVEL, you can add console traces such as ERROR, NOTICE, WARNING or INFO. Please refer to {{CodeSource | TF-A | include/common/debug.h}} | With the debug LOG_LEVEL, you can add console traces such as ERROR, NOTICE, WARNING or INFO. Please refer to {{CodeSource | TF-A | include/common/debug.h}} | ||
{{Warning| You cannot build code with LOG_LEVEL set to 50 (the highest level); | {{Warning| You cannot build code with LOG_LEVEL set to 50 (the highest level); this would generate too many traces and TF-A would not fit in the SYSRAM. If required, change some VERBOSE messages to INFO.}} | ||
For both modes, you must ensure that the UART is properly configured: | For both modes, you must ensure that the UART is properly configured: | ||
Line 35: | Line 36: | ||
</pre> | </pre> | ||
Traces | Traces are only available when the console has been fully registered. Prior to that call, the traces are not displayed and it is recommended to use the debugger. | ||
=== | === Debugging with GDB === | ||
TF-A SP-MIN is executed in CPU secure state. One can debug TF-A SP-MIN through JTAG using the embedded ST-Link or the JTAG output, if present on board. | TF-A SP-MIN is executed in CPU secure state. One can debug TF-A SP-MIN through JTAG using the embedded ST-Link or the JTAG output, if it is present on the board. | ||
For early SP-MIN | For early SP-MIN debugging purposes, it is recommended to use the [[Wrapper_for_FSBL_images|Wrapper for FSBL images]] that enables the debug link. | ||
==== | ==== Debugging boot sequence ==== | ||
The SP-MIN boot stage is executed during the boot sequence | The SP-MIN boot stage is executed during the boot sequence. It is also called at runtime when SMC calls are issued. To break into SP-MIN, connect to the target and break. | ||
When SP-MIN is compiled with the '''PIE''' feature, symbols must be loaded with the correct offset: | When SP-MIN is compiled with the '''PIE''' feature, symbols must be loaded with the correct offset: | ||
<pre> | <pre> | ||
(gdb) add-symbol-file <path_to_build_folder>/bl32.elf -o <offset> 0 | (gdb) add-symbol-file <path_to_build_folder>/bl32/bl32.elf -o <offset> 0 | ||
</pre> | </pre> | ||
The offset can be found in the [[ | The offset can be found in the [[How to configure TF-A FW CONFIG|firmware configuration file]] (see tos_fw load address property) or in the boot logs: | ||
INFO: BL2: Loading image id 4 | INFO: BL2: Loading image id 4 | ||
Line 56: | Line 57: | ||
In | In the above example: | ||
* BL32 load address is 0x2ffc5000. | * BL32 load address is 0x2ffc5000. | ||
You can load all your symbols | You can directly load all your symbols: | ||
(gdb) add-symbol-file <path_to_build_folder>/bl32.elf {{Highlight|-o 0x2ffc5000}} 0 | (gdb) add-symbol-file <path_to_build_folder>/bl32/bl32.elf {{Highlight|-o 0x2ffc5000}} 0 | ||
Set your hardware breakpoint and reset: | Set your hardware breakpoint and reset: | ||
Line 70: | Line 71: | ||
<noinclude> | <noinclude> | ||
{{PublicationRequestId}} | {{PublicationRequestId|19464|2120-04-01}} | ||
[[Category:Trusted Firmware-A (SP-MIN)|03]] | [[Category:Trusted Firmware-A (SP-MIN)|03]] | ||
[[Category:Tracing tools]] | [[Category:Tracing tools]] | ||
[[Category:Debugging tools]] | [[Category:Debugging tools]] | ||
</noinclude> | </noinclude> |
Latest revision as of 08:08, 1 April 2021
1. Article purpose[edit source]
This article explains how to debug TF-A SP-MIN firmware.
Debug is specifically linked to the TrustZone® environment.
There are two main ways to debug TF-A, by using traces inside the code, or by using JTAG to access the secure world. This article focuses on the solution integrated in OpenSTLinux, debug over gdb (based on ST-Link or JTAG). ,
2. Debugging[edit source]
2.1. TF-A version number[edit source]
The starting point for debugging is to identify the TF-A BL2 version used in the target. Debug and release versions are displayed on the console with the following format:
NOTICE: SP_MIN: v2.4-r1.0(debug):<tag>
- v2.4-r1.0 is the TF-A SP-MIN version used.
- (debug) : Build mode enable
- <tag> : Git reference resulting from the git describe command at build time
2.2. Debugging with traces[edit source]
TF-A allows RELEASE and DEBUG modes to be enabled:
- RELEASE mode builds with default LOG_LEVEL to 20, which only prints ERROR and NOTICE traces.
- DEBUG mode enables the -g build flag (for debugging the build object), and set LOG_LEVEL default value to 40.
With the debug LOG_LEVEL, you can add console traces such as ERROR, NOTICE, WARNING or INFO. Please refer to include/common/debug.h
![]() |
You cannot build code with LOG_LEVEL set to 50 (the highest level); this would generate too many traces and TF-A would not fit in the SYSRAM. If required, change some VERBOSE messages to INFO. |
For both modes, you must ensure that the UART is properly configured:
- SP-MIN: UART traces are default enabled
Traces and errors are available on the console defined in the chosen node of the device tree by the stdout-path property:
chosen {
stdout-path = "serial0:115200n8";
};
Traces are only available when the console has been fully registered. Prior to that call, the traces are not displayed and it is recommended to use the debugger.
2.3. Debugging with GDB[edit source]
TF-A SP-MIN is executed in CPU secure state. One can debug TF-A SP-MIN through JTAG using the embedded ST-Link or the JTAG output, if it is present on the board. For early SP-MIN debugging purposes, it is recommended to use the Wrapper for FSBL images that enables the debug link.
2.3.1. Debugging boot sequence[edit source]
The SP-MIN boot stage is executed during the boot sequence. It is also called at runtime when SMC calls are issued. To break into SP-MIN, connect to the target and break.
When SP-MIN is compiled with the PIE feature, symbols must be loaded with the correct offset:
(gdb) add-symbol-file <path_to_build_folder>/bl32/bl32.elf -o <offset> 0
The offset can be found in the firmware configuration file (see tos_fw load address property) or in the boot logs:
BL2: Loading image id 4 INFO: Loading image id=4 at address 0x2ffc5000 INFO: Image id=4 loaded: 0x2ffc5000 - 0x2ffd847cINFO:
In the above example:
- BL32 load address is 0x2ffc5000.
You can directly load all your symbols:
-o 0x2ffc5000 0(gdb) add-symbol-file <path_to_build_folder>/bl32/bl32.elf
Set your hardware breakpoint and reset:
(gdb) hb sp_min_entrypoint
(gdb) monitor reset halt
(gdb) continue