We will install TRACE32 software, rebuild kernel to support TRACE32 debug, and prepare a Linux attach script.
Download TRACE32 Software from https://www.lauterbach.com/support-and-training/downloads, then install to your Windows PC.
The Linux Kernel version in this example is 5.15.52.
If your kernel is 6.1.x, please add "nokaslr" to uboot bootargs, to disable KASLR (Kernel Address Space Layout Randomization).
To support TRACE32 debugging, build Linux Kernel with below configuration
Enable CONFIG_KALLSYMS
General setup ---> -*- Load all symbols for debugging/ksymoops
Enable CONFIG_KALLSYMS_ALL
General setup ---> [*] Include all symbols in kallsyms
Enable CONFIG_DEBUG_INFO
Kernel hacking ---> Compile-time checks and compiler options ---> [*] Compile the kernel with debug info
Disable CONFIG_DEBUG_INFO_REDUCED
Kernel hacking ---> Compile-time checks and compiler options ---> [ ] Reduce debugging information
After kernel building, copy vmlinux to your Windows PC which has TRACE32 software installed.
Copy Linux kernel source code to your Windows PC.
If you have mapped Linux building server to Windows network driver through samba, you don't need to do the copy.
In TRACE32 installation folder, there is a Linux attach script template at C:\T32\demo\arm\kernel\linux\board\imx8m\linux-attach.cmm. We can create i.MX8MP Linux script based on it.
Below commands can be found in linux-attach.cmm, copy these commands to a new file, name it as imx8mp-linux-attach-temp.cmm.
RESet
SYStem.RESet
SYStem.CPU IMX8M*
; Assign all cores used by Linux to the debug session
; e.g. for i.MX8MQ all CA53 - CORE.ASSIGN 1. 2. 3. 4.
CORE.ASSIGN <tbd.x> [<tbd.y> [<tbd.z> [...]]]
SYStem.Option MMUSPACES ON
SYStem.Option IMASKASM ON
SYStem.Mode Attach
; load kernel debug symbols
Data.LOAD.Elf <tbd.path to>/vmlinux /NoCODE
IF STATE.RUN()
Break
Base on above command, do below changes:
1. Change SYStem.CPU IMX8M* to SYStem.CPU IMX8MQ.
2. Change CORE.ASSIGN <tbd.x> [<tbd.y> [<tbd.z> [...]]] to CORE.ASSIGN 1. 2. 3. 4.
3. Edit Data.LOAD.Elf <tbd.path to>/vmlinux /NoCODE, add /StripPART and /SOURCEPATH.
/NoCODE: The option /NOCODE should be used to only load the symbols without kernel code.
/STRIPPART: With the option /STRIPPART you can remove parts of the path stored in the object file.
/SOURCEPATH: With the option /SourcePATH you can specify a basis directory for the source files.
For example, if you have compiled your kernel on a Linux machine in the directory /home/user/linux-kernel/linux-imx, and you are running TRACE32 on a Windows machine where you have the kernel source files tree under C:\Debugging\Linux\Sources\linux-imx, set /STRIPPART to “linux-kernel”, and set /SOURCEPATH to C:\Debugging\Linux\Sources.
With above setting, to look for the source file init/main.c, the debugger will here use the path
C:\Debugging\Linux\Sources\ + /home/user/linux-kernel/linux-imx/init/
thus
C:\Debugging\Linux\Sources\linux-imx\init
Finally, the Data.LOAD.Elf command in this example becomes to
Data.LOAD.Elf C:\Debugging\Linux\Sources\linux-imx\vmlinux /NoCODE /STRIPPART "linux-kernel" /SOURCEPATH C:\Debugging\Linux\Sources
If your TRACE32 PowerView is R_2023_02_000159199 or newer, you don't need to setup debugger address translation, you can skip this step.
For Linux 6.1.x, suggest to update TRACE32 PowerView to R_2023_02_000159199 or newer.
For older TRACE32 PowerView, here are the steps to setup address translation.
Boot up your board with the Image compiled in "1.2 Linux kernel configuration", disable cpu idle with commands
echo 1 > /sys/devices/system/cpu/cpu0/cpuidle/state1/disable
echo 1 > /sys/devices/system/cpu/cpu1/cpuidle/state1/disable
echo 1 > /sys/devices/system/cpu/cpu2/cpuidle/state1/disable
echo 1 > /sys/devices/system/cpu/cpu3/cpuidle/state1/disable
echo 1 > /sys/devices/system/cpu/cpu0/cpuidle/state0/disable
echo 1 > /sys/devices/system/cpu/cpu1/cpuidle/state0/disable
echo 1 > /sys/devices/system/cpu/cpu2/cpuidle/state0/disable
echo 1 > /sys/devices/system/cpu/cpu3/cpuidle/state0/disable
Connect TRACE32 to JTAG port, open TRACE32 ICE Arm USB, from “File->Run Script...”, run imx8mp-linux-attach-temp.cmm.
In TRACE32 install folder, there is a template script which can get the Address Translation information. Suppose you have installed TRACE32 software in C:/T32 folder, from “File->Run Script...”, run "C:\T32\demo\arm\kernel\linux\board\generic-template\detect_translation.cmm", you will get below output, copy to your temporary script, rename it to imx8mp-linux-attach.cmm.
MMU.FORMAT LINUXSWAP3 A:0x0000000040400000+(ADDRESS.OFFSET(\\vmlinux\\swapper_pg_dir)-ADDRESS.OFFSET(sYmbol.SECADDRESS(\\vmlinux\.head.text)))
TRANSlation.COMMON 0xf000000000000000--0xffffffffffffffff
TRANSlation.TableWalk ON
TRANSlation.ON
TASK.CONFIG ~~/demo/arm/kernel/linux/awareness/linux.t32
MENU.ReProgram ~~/demo/arm/kernel/linux/awareness/linux.men
imx8mp-linux-attach.cmm is the final script.
If your TRACE32 PowerView is R_2023_02_000159199 or newer, you have skipped step 1.3.2, so imx8mp-linux-attach-temp.cmm is the final script, rename it to imx8mp-linux-attach.cmm.
To attach TRACE32 to i.MX8MP Linux, run below steps:
echo 1 > /sys/devices/system/cpu/cpu0/cpuidle/state1/disable
echo 1 > /sys/devices/system/cpu/cpu1/cpuidle/state1/disable
echo 1 > /sys/devices/system/cpu/cpu2/cpuidle/state1/disable
echo 1 > /sys/devices/system/cpu/cpu3/cpuidle/state1/disable
echo 1 > /sys/devices/system/cpu/cpu0/cpuidle/state0/disable
echo 1 > /sys/devices/system/cpu/cpu1/cpuidle/state0/disable
echo 1 > /sys/devices/system/cpu/cpu2/cpuidle/state0/disable
echo 1 > /sys/devices/system/cpu/cpu3/cpuidle/state0/disable
If you find below warning message in View->Message Area window, the debugger can't find Linux source files. Please check your /STRIPPART and /SOURCEPATH setting.
If you get below bus error, please check if you have disabled cpu idle mode.
If your TRACE32 PowerView can't parse kernel symbol, please check if your kernel is 6.1.x, you must disable KASLR in uboot bootargs for Linux-6.1.x.
By default, imx8-media-dev.ko in rootfs/lib/modules/.../imx/ will be insmod automatically after Linux bootup, but since we have change kernel configuration, we need to rebuild Linux module and insmod the imx8-media-dev.ko manually, this example will show how to debug module when insmod it.
1. Rebuild Linux module and copy drivers/staging/media/imx/imx8-media-dev.ko to your board.
2. Follow "2. Attach TRACE32 to i.MX8MP Linux" to connect TRACE32 to i.MX8MP Linux, then press Go button.
3. Press Linux->Module Debugging->Debug Module on init..., In a popup window, input module name imx8-media-dev.
4. In i.MX8MP Linux terminal, insmod the module
insmod imx8-media-dev.ko
5. In TRACE32 window, a Searching symbols window will popup. Browse and open imx8-media-dev.ko, you will see below window. You can switch to source code view by pressing B:List.auto Mode button.
We will use a simple example hello.c to show how to debug Linux app, you can get the source code in attachment.
1. Set cross compiler and build app with -g compiler option to enable debug information, copy app hello to your board.
$(CC) -g -lpthread -o hello hello.c
2. Follow "2. Attach TRACE32 to i.MX8MP Linux" to attachTRACE32 to i.MX8MP Linux, then press Go button.
3. Press Linux->Process Debugging->Debug New Process, In a popup window, input process name hello
4. In i.MX8MP Linux terminal, run app hello
5. In TRACE32 window, a Search symbols windows will popup, browse and open app hello, you will see below window, you can switch to source code view by pressing B:List.auto Mode button. Now you can start to debug the app.
只有注册用户才能在此添加评论。 如果您已经注册,请登录。 如果您还没有注册,请注册并登录。