匿名
未登录
登录
百问网嵌入式Linux wiki
搜索
查看“U-Boot - How to debug”的源代码
来自百问网嵌入式Linux wiki
名字空间
页面
讨论
更多
更多
页面选项
Read
查看源代码
历史
←
U-Boot - How to debug
因为以下原因,您没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
== Debug with console == 跟踪和错误在设备树的'''chosen''' 节点中通过 '''stdout-path''' 字段定义的控制台上可用,例如在serial0 = uart4上: chosen { stdout-path = " {{Highlight|serial0}}:115200n8"; }; aliases { {{Highlight|serial0}} = &{{Highlight|uart4}}; }; 默认情况下,U-Boot使用的宏 (debug(), pr_debug()...)不打印任何跟踪;要激活特定文件上的调试跟踪,需要启用 '''DEBUG''' 编译标志并更改文件的LOGLEVEL: * 在<file>.c文件包含任何之前定义调试 #define DEBUG #undef CONFIG_LOGLEVEL #define CONFIG_LOGLEVEL 8 * 使用 Makefile CFLAGS_<file>.o+= -DDEBUG -DCONFIG_LOGLEVEL=8 如果在配置控制台之前(在执行U-Boot的第一阶段)U-Boot失败,则跟踪不可用。 在这种情况下,您需要: * 用GDB调试 (请参阅下一章) 或, * 激活调试UART功能: ** 在[[U-Boot_overview#U-Boot_configuration|U-Boot configuration]]的defconfig中添加 *** {{Highlight|CONFIG_DEBUG_UART}} *** {{Highlight|CONFIG_DEBUG_UART_STM32}} ** adpat 这个函数 {{Highlight|board_debug_uart_init()}}: 在通过U-Boot驱动程序初始化之前配置所需的资源 (pad, clock)。<br/>此功能需要针对您的主板进行调整。 == Debug with GDB == With OpenSTLinux, you can directly use GDB script Setup.gdb: * [[GDB#U-Boot_execution_phase]] * [[GDB#U-Boot_boot_case]] Or for manual GDB connection, you need to: # get the [[U-Boot_overview#Output_files|elf files]] for U-Boot and/or SPL<br/>(u-boot and u-boot-spl available in the build directory) # connect [[GDB]] to the target # '''reset with attach''' the target with the gdb {{Highlight|"monitor reset halt"}} command:<br/>execution is stopped in ROM code or at the beginning of FSBL execution. # load the symbols of the binary to be debugged with commands available in next chapter:<br/>[[#Load U-Boot symbol]], [[#Load SPL symbol]], [[#Load SPL code and debug]] # start execution with the {{Highlight|"continue"}} command === Load U-Boot symbol === With [[U-Boot_overview#U-Boot_phases|U-Boot relocation]], symbols are more difficult to load. See https://www.denx.de/wiki/DULG/DebuggingUBoot If you connect GDB on running target, you can load the debug symbols: * Before relocation with {{Highlight|"symbol-file"}} command: {{GDB$}} {{Highlight|symbol-file u-boot}} * After relocation with {{Highlight|"add-symbol-file"}} command to relocate the symbol with the code offset = gd->relocaddr: {{GDB$}} symbol-file u-boot {{Highlight|--> only for "gd_t" definition}} {{GDB$}} set $offset = ((gd_t *)$r9)->relocaddr {{Highlight|--> get relocation offset}} {{GDB$}} symbol-file {{Highlight|--> clear previous symbol }} {{GDB$}} {{Highlight|add-symbol-file u-boot $offset}} The following GDB example script automatically loads the U-Boot symbol before and after relocation for a programmed board, after {{Highlight|"monitor reset halt"}} command: {{GDB$}} thbreak *0xC0100000 {{GDB$}} commands > symbol-file u-boot > thbreak relocate_code > commands > print "RELOCATE U-Boot..." > set $offset = ((gd_t *)$r9)->relocaddr > print $offset > symbol-file > add-symbol-file u-boot $offset > thbreak boot_jump_linux > continue > end > continue > end This script uses a temporary hardware breakpoint {{Highlight|"thbreak"}} to load the symbol when U-Boot code is loaded in DDR by FSBL = TF-A or SPL at the U-Boot entry point (CONFIG_SYS_TEXT_BASE = 0xC0100000). It allows the symbol to be loaded only when code is executed to avoid DDR access before DDR initialization. === Load SPL symbol === To debug SPL with GDB on a Flashed device, ROM code loads the binary and the GDB script just loads the SPL symbols: {{GDB$}} symbol-file u-boot-spl === Load SPL code and debug === Sometimes you need to debug SPL execution on an unprogrammed target (for example for board bring-up), so you can use GDB to load the SPL code in embedded RAM and execute it. When execution is stopped in ROM code, you need to execute the {{Highlight|"load"}} commands, depending on the compilation flags defined in [[U-Boot_overview#Device_tree|U-Boot device tree]] to load the SPL code and the associated device tree: * CONFIG_OF_SEPARATE = dtb appended at the end of the code, not present in the elf file (default configuration) {{GDB$}} file u-boot-spl {{GDB$}} load {{GDB$}} set $dtb = __bss_end {{GDB$}} restore spl/dt.dtb binary $dtb * CONFIG_OF_EMBED = dtb embedded in the elf file (debug configuration) {{GDB$}} file u-boot-spl {{GDB$}} load === Debug the first SPL instructions === Sometime the SPL code execution is stopped by the gdb command "monitor reset halt" after the first instructions. To debug this part, you can modify the code: add a infinite loop in SPL code to wait the gdb connection. For example in {{CodeSource | U-Boot | arch/arm/mach-stm32mp/spl.c}} : <syntaxhighlight lang="c"> void board_init_f(ulong dummy) { struct udevice *dev; int ret; /* volatile is needed to avoid gcc optimization */ volatile int stop = 0; /* infinite debug loop */ while ( !stop ) ; arch_cpu_init(); </syntaxhighlight> when gdb is attached and the SPL symbols are loaded, the infinite loop is interrupted by : {{GDB$}} set var stop=1 And you can debug the SPL first instruction by gdb commands. <noinclude> [[Category:U-Boot]] [[Category:Tracing tools]] [[Category:Debugging tools]] {{PublicationRequestId | 12894 | 2019-08-01}} </noinclude>
该页面使用的模板:
模板:CodeSource
(
查看源代码
)
模板:GDB$
(
查看源代码
)
模板:Highlight
(
查看源代码
)
返回至
U-Boot - How to debug
。
导航
导航
WIKI首页
官方店铺
资料下载
交流社区
所有页面
所有产品
MPU-Linux开发板
MCU-单片机开发板
Linux开发系列视频
单片机开发系列视频
所有模块配件
Wiki工具
Wiki工具
特殊页面
页面工具
页面工具
用户页面工具
更多
链入页面
相关更改
页面信息
页面日志