“TF-A - How to debug”的版本间的差异

来自百问网嵌入式Linux wiki
(创建页面,内容为“__TOC__ == Article Purpose == This article explains how to debug TF-A firmware.<br> Debug is specifically linked to the TrustZone environment. There are two main wa…”)
 
 
(未显示同一用户的2个中间版本)
第1行: 第1行:
 
__TOC__
 
__TOC__
 
== Article Purpose ==
 
== Article Purpose ==
This article explains how to debug TF-A firmware.<br>
+
本文介绍了如何调试TF-A固件。<br>
Debug is specifically linked to the TrustZone environment.
+
调试专门链接到TrustZone环境。
 
+
调试TF-A的主要方法有两种,一种是使用代码内部的跟踪,另一种是使用JTAG来访问安全环境。
There are two main ways to debug TF-A, using traces inside the code, or by using JTAG to access the secure world.
+
这里的重点是集成在OpenSTLinux中的解决方案:通过gdb调试(基于ST-Link或JTAG)。
The focus here is on the solution integrated in OpenSTLinux: debug over gdb (ST-Link or JTAG based)
 
  
 
== Debugging ==
 
== Debugging ==
 
=== TF-A Version number ===
 
=== TF-A Version number ===
  
The starting point for debugging is to identify the TF-A version used in the target. Debug and release versions are displayed on the console with the following format:<br>
+
调试的起点是确定目标中使用的TF-A版本。 调试和发行版本以以下格式显示在控制台上:<br>
 
<pre>
 
<pre>
 
NOTICE: BL2: v2.0(debug):<tag>
 
NOTICE: BL2: v2.0(debug):<tag>
 
</pre>
 
</pre>
* v2.0 is the TF-A version used.
+
* v2.0是使用的TF-A版本。
* (debug) : Build mode enable
+
* (debug) :启用构建模式。
* <tag> : Git reference resulting from the '''git describe''' command at build time
+
* <tag> : 在构建时由'''git describe'''命令生成的Git参考。
  
 
=== Debug with traces ===
 
=== Debug with traces ===
TF-A allows RELEASE and DEBUG modes to be enabled:
+
TF-A允许启用RELEASE和DEBUG模式:
* RELEASE mode builds with default LOG_LEVEL to 20, which only prints ERROR and NOTICE traces
+
* RELEASE模式在默认LOG_LEVEL为 20 的情况下构建,仅打印ERROR和NOTICE的跟踪
* DEBUG mode enables the -g build flag (for debug build object), and defaults LOG_LEVEL to 40  
+
* DEBUG模式启用 -g 构建标志(用于调试构建对象),并将LOG_LEVEL缺省为 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'''.
+
使用DEBUG LOG_LEVEL,您可以添加控制台跟踪,如错误、通知、警告或信息。 请参阅'''include/common/debug.h'''.
{{Warning| You cannot build code with LOG_LEVEL set to 50 (the highest level); there are too many traces and TF-A does not fit in the SYSRAM. If required, change some VERBOSE settings to INFO.}}
+
{{Warning| 您无法将LOG_LEVEL设置为50(最高级别)来构建代码; 跟踪太多,并且TF-A不适合SYSRAM。如果需要,将某些VERBOSE设置更改为INFO。}}
  
For both modes, you must ensure that the UART is properly configured:
+
对于这两种模式,必须确保正确配置了UART:
* BL2: UART traces are enabled by default
+
* BL2: 默认情况下启用UART跟踪
* BL32: UART traces are enabled by default<br>
+
* BL32: 默认情况下启用UART跟踪<br>
  
Traces and errors are available on the console defined in the chosen node of the device tree by the stdout-path property:
+
在stdout-path属性的设备树的所选节点中定义的控制台上可以找到跟踪和错误:
 
<pre>
 
<pre>
 
chosen {
 
chosen {
第37行: 第36行:
  
 
=== Debug with GDB ===
 
=== Debug with GDB ===
TF-A runs in SYSRAM and is executed in CPU secure state. One can debug TF-A through JTAG using an ST-Link or the JTAG output, depending on the board.
+
TF-A在SYSRAM中运行,并在CPU安全状态下执行。根据板卡的不同,可以使用ST-Link或JTAG输出通过JTAG调试TF-A。
  
 
==== Debug boot sequence ====
 
==== Debug boot sequence ====
The BL2 boot stage is only executed during a boot sequence. To break into BL2, connect to the target and break.
+
BL2引导阶段仅在引导序列期间执行。要闯入BL2,请连接到目标并闯入。
  
Load symbols to the correct offset:
+
将符号加载到正确的偏移量:
 
<pre>
 
<pre>
 
(gdb) add-symbol-file <path_to_build_folder>/tf-a-bl2.elf (or bl2.elf) <load_address>
 
(gdb) add-symbol-file <path_to_build_folder>/tf-a-bl2.elf (or bl2.elf) <load_address>
 
</pre>
 
</pre>
  
BL2 and BL32 load addresses can be found in the generated '''tf-a-stm32mp157c-<board>.map''' file:
+
可以在生成的 '''tf-a-stm32mp157c-<board>.map''' 文件中找到BL2和BL32加载地址:
 
<pre>
 
<pre>
 
...
 
...
第65行: 第64行:
 
...
 
...
 
</pre>
 
</pre>
In this example:
+
在此示例中:
* BL2 load address is 0x2ffd3000.
+
* BL2 加载地址为 0x2ffd3000
* BL32 load address is 0x2ffe7000.
+
* BL32 加载地址为 0x2ffe7000  
  
You can load all your symbols directly:
+
您可以直接加载所有符号:
 
<pre>
 
<pre>
 
(gdb) add-symbol-file <path_to_build_folder>/tf-a-bl2.elf 0x2ffd3000
 
(gdb) add-symbol-file <path_to_build_folder>/tf-a-bl2.elf 0x2ffd3000
第75行: 第74行:
 
</pre>
 
</pre>
  
Set your hardware breakpoint and reset:
+
设置您的硬件断点并重置:
 
<pre>
 
<pre>
 
(gdb) hb bl2_early_platform_setup
 
(gdb) hb bl2_early_platform_setup
第82行: 第81行:
  
 
==== Debugging during runtime execution ====
 
==== Debugging during runtime execution ====
Once [[U-Boot overview|U-Boot]] or the Linux kernel is running, you cannot access secure memory or regions, but you can break, set a hardware breakpoint into SMC handler (in BL32). [[GDB]] breaks once it has switched into the secure world and reached the break instruction. Once halted in the secure monitor, [[GDB]] can access secure resources as IPs or memory. For example, one can break into kernel:
+
一旦运行[[U-Boot overview|U-Boot]] 或Linux内核,就无法访​​问安全内存或区域,但可以中断,并在SMC处理程序中设置硬件断点(在BL32中)。一旦[[GDB]] 进入安全区域并到达中断指令,它就会中断。一旦在安全监视器中暂停,[[GDB]] 可以访问安全资源,如IP或内存。 例如,可以闯入内核:
 
<pre>
 
<pre>
 
(gdb) hb stm32mp1_svc_smc_handler
 
(gdb) hb stm32mp1_svc_smc_handler
第88行: 第87行:
 
</pre>
 
</pre>
  
On the first SMC call occurence [[GDB]] breaks the stm32mp1_svc_smc_handler() entry in BL32.
+
在第一次进行SMC调用时,[[GDB]]中断了BL32中的stm32mp1_svc_smc_handler()条目。
 
 
<noinclude>
 
{{PublicationRequestId | 9776 | 2018-11-22 | PhilipeS}}
 
[[Category:Trusted Firmware-A (TF-A)]]
 
[[Category:Tracing tools]]
 
[[Category:Debugging tools]]
 
</noinclude>
 

2020年11月2日 (一) 11:35的最新版本

Article Purpose

本文介绍了如何调试TF-A固件。
调试专门链接到TrustZone环境。 调试TF-A的主要方法有两种,一种是使用代码内部的跟踪,另一种是使用JTAG来访问安全环境。 这里的重点是集成在OpenSTLinux中的解决方案:通过gdb调试(基于ST-Link或JTAG)。

Debugging

TF-A Version number

调试的起点是确定目标中使用的TF-A版本。 调试和发行版本以以下格式显示在控制台上:

NOTICE: BL2: v2.0(debug):<tag>
  • v2.0是使用的TF-A版本。
  • (debug) :启用构建模式。
  • <tag> : 在构建时由git describe命令生成的Git参考。

Debug with traces

TF-A允许启用RELEASE和DEBUG模式:

  • RELEASE模式在默认LOG_LEVEL为 20 的情况下构建,仅打印ERROR和NOTICE的跟踪
  • DEBUG模式启用 -g 构建标志(用于调试构建对象),并将LOG_LEVEL缺省为 40

使用DEBUG LOG_LEVEL,您可以添加控制台跟踪,如错误、通知、警告或信息。 请参阅include/common/debug.h.

Warning.png 您无法将LOG_LEVEL设置为50(最高级别)来构建代码; 跟踪太多,并且TF-A不适合SYSRAM。如果需要,将某些VERBOSE设置更改为INFO。

对于这两种模式,必须确保正确配置了UART:

  • BL2: 默认情况下启用UART跟踪
  • BL32: 默认情况下启用UART跟踪

在stdout-path属性的设备树的所选节点中定义的控制台上可以找到跟踪和错误:

chosen {
        stdout-path = "serial0:115200n8";
};

Debug with GDB

TF-A在SYSRAM中运行,并在CPU安全状态下执行。根据板卡的不同,可以使用ST-Link或JTAG输出通过JTAG调试TF-A。

Debug boot sequence

BL2引导阶段仅在引导序列期间执行。要闯入BL2,请连接到目标并闯入。

将符号加载到正确的偏移量:

(gdb) add-symbol-file <path_to_build_folder>/tf-a-bl2.elf (or bl2.elf) <load_address>

可以在生成的 tf-a-stm32mp157c-<board>.map 文件中找到BL2和BL32加载地址:

...
 *fill*         0x000000002ffce000     0x5000 
                0x000000002ffd3000                __BL2_IMAGE_START__ = .  -> BL2 Load address
 *(.bl2_image*)
 .bl2_image     0x000000002ffd3000    0x1166c build/stm32mp1/stm32mp1.o
                0x000000002ffe466c                __BL2_IMAGE_END__ = .
                0x0000000000024b00                . = 0x24b00
 *fill*         0x000000002ffe466c     0x2994 
                0x000000002ffe7000                __BL32_IMAGE_START__ = . -> BL32 Load address
 *(.bl32_image*)
 .bl32_image    0x000000002ffe7000    0x1744c build/stm32mp1/stm32mp1.o
                0x000000002fffe44c                __BL32_IMAGE_END__ = .
                0x000000002fffe44c                __DATA_END__ = .
                0x000000002fffe44c                __TF_END__ = .
...

在此示例中:

  • BL2 加载地址为 0x2ffd3000
  • BL32 加载地址为 0x2ffe7000

您可以直接加载所有符号:

(gdb) add-symbol-file <path_to_build_folder>/tf-a-bl2.elf 0x2ffd3000
(gdb) add-symbol-file <path_to_build_folder>/tf-a-bl32.elf 0x2ffe7000

设置您的硬件断点并重置:

(gdb) hb bl2_early_platform_setup
(gdb) monitor reset halt

Debugging during runtime execution

一旦运行U-Boot 或Linux内核,就无法访​​问安全内存或区域,但可以中断,并在SMC处理程序中设置硬件断点(在BL32中)。一旦GDB 进入安全区域并到达中断指令,它就会中断。一旦在安全监视器中暂停,GDB 可以访问安全资源,如IP或内存。 例如,可以闯入内核:

(gdb) hb stm32mp1_svc_smc_handler
(gdb) continue

在第一次进行SMC调用时,GDB中断了BL32中的stm32mp1_svc_smc_handler()条目。