Introduction
Arm's debugger includes a useful feature called semi-hosting, which can be used for SoC FPGA software development since Arm's Arm® Development Studio 5 Intel® SoC FPGA Edition (DS-5) debugger is used as the standard environment. This feature can be leveraged.
This article provides an overview of the semi-hosting feature and how it can be useful.
Overview of Semi-Hosting
Printf() is often used for software debugging and logging. Usually, the printf() statement is output via a UART, in which case printf() cannot be used until the UART is configured.
Semi-hosting is a mechanism for DS-5 to communicate I/O requests issued by application code on Arm to the host computer on which DS-5 is running via JTAG. This allows the use of printf() even when the UART is not configured for debugging.
For more information, please refer to Arm's web site below.
Reference: What is Semi-Hosting?
Reference: Semihosting: a life-saver during SoC and board bring-up | Arm® Community
Cases where semi-hosting is used
There are two possible cases to use semi-hosting.
Case 1: Debugging when the UART is not set
When the UART has not been initialized, or when the UART is not available, the log can be checked via JTAG by using the semi-hosting function.
In this case, it is necessary to configure the BSP-Generator (bsp-editor) (see figure below).
For more information about BSP Generator (bsp-editor), Intel® SoC FPGA Embedded Development Suite (SoC EDS) User Guide for more information about the BSP Generator (bsp-editor).
NOTES: For standalone booting, such as product releases, you will need binaries compiled with semi-hosting turned off.
If the target is an Arria® 10 SoC, there is no corresponding option in bsp-editor. Therefore, you need to enable CONFIG_SEMIHOSTING under the U-Boot source tree.
Specifically, CONFIG_SEMIHOSTING defined in the following file is enabled by changing it from #undef to #define (to turn off semihosting, change it back to #undef).
uboot-socfpga/include/configs/socfpga_arria10.h:39:#undef CONFIG_SEMIHOSTING
This case is also useful for debugging at board startup. Try this if the boot does not complete normally and nothing is logged in the UART terminal. Running the bootloader with semi-hosting enabled via the debugger may provide a bit more information.
See the following content for information on how to run the bootloader via the debugger.
Reference: How to run U-Boot on DS-5 for simple debugging! - (In Japanese)
Reference: How to Boot U-Boot on DS-5 for Arria® 10 SoC
Case 2: You want to save USB ports on your PC
When developing bare-metal applications, you are probably using a USB download cable. In some cases, there may not be enough USB ports to connect a UART to the PC, since two USB ports are used.
In such cases, semi-hosting does not require a UART cable because of JTAG, so only one USB cable is needed to check logs.
In addition to the convenience of USB ports and cables, it is also convenient when you simply want to save time and effort in preparing the verification environment (cable connection with the target board).
Sample of printf statement output on semi-hosting/UART on DS-5
The software samples included with the SoC FPGA Embedded Development Suite (SoC EDS) are all configured to use semi-hosting, so you can try semi-hosting with the included samples.
In addition to the included samples, the following links provide samples that support both semi-hosting and UART.
Reference: SoC FPGA Bare Metal All-in-One Application Samples
In this sample, the output destination of the printf() statement can be selected between UART/semi-hosting, so please use this sample to understand the difference between UART output and semi-hosting.
To switch between UART and semi-hosting, edit the comfig.mk file stored directly under the project.
The setting value (0 or 1) of PRINTF_UART below is used to switch between UART and semi-hosting.
##############################################
# Select printf target (0:Semihost / 1:UART) #
##################### #########################
PRINTF_UART := 1