Debugging TF-A and UEFI/EDK2 Using Eclipse
Get Eclipse
Go to https://www.eclipse.org/downloads/packages/ and scroll down to "Eclipse IDE for Embedded C/C++ Developers".
Select the appropriate operating system and architecture.
Once downloaded, untar the file. You can then run Eclipse with "./eclipse/eclipse".
Building TF-A and EDK2 for the SBSA-REF platform
export CROSS_COMPILE=aarch64-none-linux-gnu- cd ~/src/trusted-firwmare-a
Edit plat/qemu/common/qemu_bl31_setup.c, and add to bl31_plat_arch_setup:
volatile int loop; for (loop = 0; loop == 0;) { ; }
make PLAT=qemu_sbsa DEBUG=1 lOGLEVEL=40 CFLAGS="-ggdb" all fip cp -fv build/qemu_sbsa/debug/bl1.bin build/qemu_sbsa/debug/fip.bin \ ../uefi/edk2-non-osi/Platform/Qemu/Sbsa/ cd ../uefi export WORKSPACE=$PWD export PACKAGES_PATH=$PWD/edk2:$PWD/edk2-platforms:$PWD/edk2-non-osi . ./edk2/edksetup.sh export GCC5_AARCH64_PREFIX=aarch64-none-linux-gnu-
Edit Platform/Qemu/SbsaQemu/OemMiscLib/OemMiscLib.c and add a CpuDeadLoop() to OemGetProcessorInformation.
build -p Platform/Qemu/SbsaQemu/SbsaQemu.dsc -a AARCH64 -t GCC5 -b NOOPT truncate -s256M ./Build/SbsaQemu/NOOPT_GCC5/FV/SBSA_FLASH*.fd git clone -b BZ3500-gdb https://github.com/ajfish/edk2.git
Running the VM
qemu-system-aarch64 -M sbsa-ref -cpu max -s -monitor pty -serial stdio \ -nographic -display none \ -pflash ./Build/SbsaQemu/NOOPT_GCC5/FV/SBSA_FLASH0.fd \ -pflash ./Build/SbsaQemu/NOOPT_GCC5/FV/SBSA_FLASH1.fd
Configuring Eclipse
Launch Eclipse.
Select File → New → Makefile Project with Existing Code
Enter the path to the edk2 source tree.
Select "Arm Cross GCC" for the "Toolchain for Indexer Settings"
Do the same for edk2-platforms and trusted-firmware-a.
Select Run → Debug Configurations...
Select GDB Hardware Debugging, right-click, New Configuration.
"Main" tab - for debugging EDK2
Main tab: Project: edk2-platforms
C/C++ Application: browse and select ~/src/uefi/Build/SbsaQemu/NOOPT_GCC5/AARCH64/SmbiosDxe.debug
In "Build (if required) before launching" select "Disable auto build".
"Main" tab - for debugging TF-A
Main tab: Project: trusted-firmware-a
C/C++ Application: browse and select ~/src/trusted-firmware-a/build/qemu_sbsa/debug/bl31/bl31.elf
In "Build (if required) before launching" select "Disable auto build".
In the Debugger tab, GDB Setup → GDB Command: enter correct command (e.g. gdb-multiarch on Debian/Ubuntu/etc.)
Remote Target → GDB Connection String → 127.0.0.1:1234