UEFI BIOS Debugging - The problesm and soluations
UEFI Debugging - PROBLEMS
The current popular method to debug the x86 system firmware is to use the hardware emulator. There are only one hardware emulator can used for this purpose. Of crouse it is ECM-XDP from American Arium. Intel uses their own simulator called ITP but never sold.
But XDP is really very expensive. It costs about 1W USD to for each. It's hard imagine that one comany can buy XDP for each engineers. So we have to find another ways to debug our low-level software.
YES, the soluations to this problems is to use software debuggers.
Basic Requirements for UEFI software debuggers:
- MUST support debug the UEFI system firmware
- Function at both PEI and DXE phrase.
- C Source level debugging support
- Load debuge modules through the remote connections
- Code Step Into/Over//Trace support
- Memory view/modify
- PCI/PCI-E configuration space access
- Target run Control
- Other useful functions
HOW TO IMPLEMENT?
The architecture for a remote debugger is hard to describe. Most of the programmers don't write a debugger in his/her life. Implementing a debugger needs some special technologies. For a remote debugger there are two components existed in the system. One is host, which executed in the OS and provide the UI of debugger. The other is debug agent, which intergrate into system firmware. The host gets the user input and send it to agent. The agent performs the operations directly and then send the result to host.
PROTOCOLS
The UEFI Specification defines two protocols and one table can be used to build a software debugger. They are:
EFI Debug Port Protocol
Provide the communication wapper for generic use. A debug agent can use this protocol to communicate with host. There is one and only one driver that produces this protocol allowed at runtime.
EFI Debug Support Protocol
This protocol is produced by a CPU specific driver. It based on the CPU's interrupt mechanism. It allows users to register some handlers what would execute on some conditions.
EFI Debug Table
This table is used to to secrach the modules that already loaded and called by the dispatcher.