-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce semihosting facilities and semihosting console driver #6700
Conversation
cbfaa08
to
ebef753
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- For "libutils: Move _ansi.h to include folder":
Reviewed-by: Jerome Forissier <[email protected]>
- For " libutils: Import part of sys/fcntl.h":
Please mention you are importing this from newlib in the commit description. One more comment below. - For "core: riscv: Add semihosting.S for semihosting instructions":
Acked-by: Jerome Forissier <[email protected]>
- For "core: kernel: Add semihosting functions": see comments below
- For "drivers: Implement semihosting based console driver for log":
Acked-by: Jerome Forissier <[email protected]>
It would be nice to be able to test this. Since the whole RISC-V QEMU environment is not ready yet, we should consider implementing __do_semihosting()
for Arm. I may give it a shot ;)
8201769
to
0a49e1c
Compare
Sure, do you have any suggestion to test this feature ?
Yes please! You may want to try this PR on ARM QEMUv8. |
0a49e1c
to
883e246
Compare
1723ab8
to
c4e2b5c
Compare
69a53ff
to
1bd1a1d
Compare
I have one question: |
1bd1a1d
to
d21e9f7
Compare
Yes, this is a good idea. This is a generic driver so the relate config switch deserve to be defined and documented in mk/config.mk. |
Thanks! I will add it. |
56e2bdf
to
0d902a0
Compare
Add dedicated 4b71811 for new configurations: |
I agree, but while we're at it, defining commit e66d6b8fa8b52a0eaa87de755fc6b0f434e07306 (HEAD -> wip/semihosting, jf/wip/semihosting)
Author: Jerome Forissier <[email protected]>
Date: Thu Feb 22 16:28:25 2024 +0100
qemuv8: use semihosting cosole driver when CFG_SEMIHOSTING_CONSOLE=y
Implement semihosting console for Aarch64 QEMU.
Signed-off-by: Jerome Forissier <[email protected]>
diff --git a/core/arch/arm/plat-vexpress/main.c b/core/arch/arm/plat-vexpress/main.c
index 42116c2f2..a02017bc6 100644
--- a/core/arch/arm/plat-vexpress/main.c
+++ b/core/arch/arm/plat-vexpress/main.c
@@ -10,6 +10,7 @@
#include <drivers/gic.h>
#include <drivers/hfic.h>
#include <drivers/pl011.h>
+#include <drivers/semihosting_console.h>
#include <drivers/tzc400.h>
#include <initcall.h>
#include <keep.h>
@@ -27,6 +28,7 @@
#include <trace.h>
static struct pl011_data console_data __nex_bss;
+static struct semihosting_console_data sh_console_data __nex_bss;
register_phys_mem_pgdir(MEM_AREA_IO_SEC, CONSOLE_UART_BASE, PL011_REG_SIZE);
#if defined(PLATFORM_FLAVOR_fvp)
@@ -82,9 +84,14 @@ void boot_primary_init_intc(void)
void console_init(void)
{
- pl011_init(&console_data, CONSOLE_UART_BASE, CONSOLE_UART_CLK_IN_HZ,
- CONSOLE_BAUDRATE);
- register_serial_console(&console_data.chip);
+ if (IS_ENABLED(CFG_SEMIHOSTING_CONSOLE)) {
+ semihosting_console_init(&sh_console_data, "optee.log");
+ register_serial_console(&sh_console_data.chip);
+ } else {
+ pl011_init(&console_data, CONSOLE_UART_BASE,
+ CONSOLE_UART_CLK_IN_HZ, CONSOLE_BAUDRATE);
+ register_serial_console(&console_data.chip);
+ }
}
#if (defined(CFG_GIC) || defined(CFG_CORE_HAFNIUM_INTC)) && \ |
@gagachang when adding fixup commits you should rather keep the subject of the original commit because it will help when it is time to rebase and squash the commits later at the end of the review. For example "drivers: Address comments for semihosting_console" could be "[Review] drivers: Implement semihosting based console driver for log". |
I am sorry for missing that. Subjects will be fixed in next force push. |
Maybe we can change the code in #ifdef CFG_SEMIHOSTING_CONSOLE
bl semihosting_console_init_helper // Helper prepares console data and file_path
#else
bl console_init
#endif |
3e7d68d
to
6f83af5
Compare
Or we could decide |
I successfully enabled the semihosting console for Aarch64 🎉 see 0a49e1c...jforissier:optee_os:semihosting-aarch64. I will create a PR after this PR is reviewed and merged for simplicity. |
49765c2
to
f542f6c
Compare
This commit is split and merged into previous two commits respectively, suggested by @jforissier . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Minor: I suggest applying "core: riscv: Add semihosting.S for semihosting instructions" after "core: kernel: Add semihosting functions".
- For "libutils: Import part of sys/fcntl.h":
Acked-by: Jerome Forissier <[email protected]>
- For "core: kernel: Add semihosting functions": one comment, with that:
Reviewed-by: Jerome Forissier <[email protected]>
- For "core: Refactor console_init() and introduce plat_console_init()":
Reviewed-by: Jerome Forissier <[email protected]>
- For "drivers: Implement semihosting based console driver for log":
You may remove the paragraph about semihosting and keep only "This commit implements a simple console driver...". Add it to commit description for "core: kernel: Add semihosting functions".
f542f6c
to
1f6295e
Compare
Yes it makes sense.
Done, the paragraph is moved to "core: kernel: Add semihosting functions". |
Tested on Aarch64 QEMU. I just had to add the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure we want to do "libutils: Move _ansi.h to include folder"
1f6295e
to
062625a
Compare
I remove this commit since we only copy necessary definitions into |
062625a
to
24d0645
Compare
My review/ack tags still apply. |
24d0645
to
35cb6b0
Compare
|
2234612
to
f8a34cb
Compare
Fix commit message of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acked-by: Etienne Carriere <[email protected]>
for commit
"libutils: Import part of sys/fcntl.h".
Reviewed-by: Etienne Carriere <[email protected]>
for commit
"core: Refactor console_init() and introduce plat_console_init()".
Comments for commit "drivers: Implement semihosting based console driver for log": we prefer have the commit message at the imperative mode:
-This commit implements a simple console driver which uses semihosting
+Implement a simple console driver which uses...
A equivalent (and late) comment for commit "core: riscv: Add semihosting.S for semihosting instructions":
RISC-V architecture has defined the semihosting binary interface, which
consists of a special trap instruction sequence, in:
https://github.com/riscv-non-isa/riscv-semihosting
-This commit adds semihosting.S into RISC-V architecture folder and
-implements the trap instruction sequence.
+Add semihosting.S into RISC-V kernel folder to implement the trap
+instruction sequence.
Import part of sys/fcntl.h for necessary file flags, from newlib: - newlib/newlib/libc/include/sys/fcntl.h Signed-off-by: Alvin Chang <[email protected]> Acked-by: Jerome Forissier <[email protected]> Acked-by: Etienne Carriere <[email protected]> Reviewed-by: Jens Wiklander <[email protected]>
Semihosting is a mechanism that enables target to communicate and use I/O facilities on a host computer which is running a debugger, such as GDB. The I/O facilities include character {read|write} {from|to} the semihosting host side console or a file. In other words, OP-TEE OS can output log to the host side console or the host side file, if there is a semihosting host and OP-TEE OS requests the semihosting operations to that host. If CFG_SEMIHOSTING is enabled, some semihosting functions will be compiled into OP-TEE kernel, including: - semihosting_sys_readc() - semihosting_sys_writec() - semihosting_open() - semihosting_read() - semihosting_write() - semihosting_close() Note that the architectures which support semihosting should provide their implementation of __do_semihosting(), which performs semihosting instruction to raise the semihosting request. Signed-off-by: Alvin Chang <[email protected]> Reviewed-by: Etienne Carriere <[email protected]> Reviewed-by: Jerome Forissier <[email protected]> Reviewed-by: Jens Wiklander <[email protected]>
RISC-V architecture has defined the semihosting binary interface, which consists of a special trap instruction sequence, in: https://github.com/riscv-non-isa/riscv-semihosting Add semihosting.S into RISC-V kernel folder to implement the trap instruction sequence. Signed-off-by: Alvin Chang <[email protected]> Acked-by: Jerome Forissier <[email protected]> Acked-by: Etienne Carriere <[email protected]> Reviewed-by: Jens Wiklander <[email protected]>
Since there are some cross-platform console drivers, we let console_init() be common code to have a chance to initialize those console drivers (e.g., semihosting console). If the cross-platform console drivers are not configured to be compiled, plat_console_init() will be invoked to initialize platform-specific console driver. Signed-off-by: Alvin Chang <[email protected]> Reviewed-by: Jerome Forissier <[email protected]> Reviewed-by: Jens Wiklander <[email protected]> Reviewed-by: Etienne Carriere <[email protected]>
f8a34cb
to
4779839
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment for commit
The commit message could be update accordingly:
- If the caller of semihosting_console_init() provides the path of the
file, the driver will try to open that file, and output the log to
that host side file.
- If the caller of semihosting_console_init() does not provide the path
+ of the file, the driver will try to output the log to host side
- of the file, the driver will connect the console to the host debug
console directly.
Implement a simple console driver which uses semihosting operations to read/write the trace messages. There are two paths to output the trace messages: - If the caller of semihosting_console_init() provides the path of the file, the driver will try to open that file, and output the log to that host side file. - If the caller of semihosting_console_init() does not provide the path of the file, the driver will connect the console to the host debug console directly. If CFG_SEMIHOSTING_CONSOLE is enabled, OP-TEE will try to initialize the semihosting console driver by given CFG_SEMIHOSTING_CONSOLE_FILE. Signed-off-by: Alvin Chang <[email protected]> Acked-by: Jerome Forissier <[email protected]> Reviewed-by: Jens Wiklander <[email protected]>
4779839
to
bd19a9b
Compare
@gagachang thanks! |
Hello,
This series implement semihosting facilities.
Please review it if this is feasible in OP-TEE system, thanks!
The new config option
CFG_SEMIHOSTING
is used to compile in-kernel semihosting functions.Architectures who support semihosting should provide their implementation of
__do_semihosting()
, which consists of special instructions to trigger the semihosting.In this series, we've implemented RISC-V version.
Currently we only implement semihosting open/read/write operations.
Based on this in-kernel semihosting, semihosting console driver is also introduced.
There are two paths to output the log:
The path is decided by
file_path
parameter provided by the caller ofsemihosting_console_init()
.The new config option
CFG_SEMIHOSTING_CONSOLE
is used to compile semihosting console driver.Example code to use semihosting console driver: