forked from OP-TEE/optee_os
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drivers: Implement semihosting based console driver for log
This commit implements a simple console driver which uses semihosting operations to read/write the character. There are two paths to output the log: - 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 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 <alvinga@andestech.com> Acked-by: Jerome Forissier <jerome.forissier@linaro.org> Reviewed-by: Jens Wiklander <jens.wiklander@linaro.org>
- Loading branch information
Showing
5 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
/* | ||
* Copyright (c) 2024 Andes Technology Corporation | ||
*/ | ||
|
||
#include <compiler.h> | ||
#include <console.h> | ||
#include <drivers/semihosting_console.h> | ||
#include <drivers/serial.h> | ||
#include <kernel/semihosting.h> | ||
#include <util.h> | ||
|
||
/* | ||
* struct semihosting_console_data - Structure for semihosting console driver | ||
* @chip - General structure for each serial chip | ||
* @fd - Handle of the file at @file_path when semihosting_console_init() is | ||
* called, or -1 if using the semihosting console | ||
*/ | ||
struct semihosting_console_data { | ||
struct serial_chip chip; | ||
int fd; | ||
}; | ||
|
||
static struct semihosting_console_data sh_console_data __nex_bss; | ||
|
||
static void semihosting_console_putc(struct serial_chip *chip __unused, int ch) | ||
{ | ||
semihosting_sys_writec(ch); | ||
} | ||
|
||
static int semihosting_console_getchar(struct serial_chip *chip __unused) | ||
{ | ||
return semihosting_sys_readc(); | ||
} | ||
|
||
static const struct serial_ops semihosting_console_ops = { | ||
.putc = semihosting_console_putc, | ||
.getchar = semihosting_console_getchar, | ||
}; | ||
DECLARE_KEEP_PAGER(semihosting_console_ops); | ||
|
||
static void semihosting_console_fd_putc(struct serial_chip *chip __unused, | ||
int ch) | ||
{ | ||
if (sh_console_data.fd >= 0) | ||
semihosting_write(sh_console_data.fd, &ch, 1); | ||
} | ||
|
||
static const struct serial_ops semihosting_console_fd_ops = { | ||
.putc = semihosting_console_fd_putc, | ||
}; | ||
DECLARE_KEEP_PAGER(semihosting_console_fd_ops); | ||
|
||
void semihosting_console_init(const char *file_path) | ||
{ | ||
if (file_path) { | ||
/* Output log to given file on the semihosting host system. */ | ||
sh_console_data.chip.ops = &semihosting_console_fd_ops; | ||
sh_console_data.fd = | ||
semihosting_open(file_path, O_RDWR | O_CREAT | O_TRUNC); | ||
} else { | ||
/* Output log to semihosting host debug console. */ | ||
sh_console_data.chip.ops = &semihosting_console_ops; | ||
sh_console_data.fd = -1; | ||
} | ||
|
||
register_serial_console(&sh_console_data.chip); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* SPDX-License-Identifier: BSD-2-Clause */ | ||
/* | ||
* Copyright (c) 2024 Andes Technology Corporation | ||
*/ | ||
#ifndef __DRIVERS_SEMIHOSTING_CONSOLE_H | ||
#define __DRIVERS_SEMIHOSTING_CONSOLE_H | ||
|
||
#ifdef CFG_SEMIHOSTING_CONSOLE | ||
/* | ||
* Initialize console which uses architecture-specific semihosting mechanism. | ||
* If @file_path is not NULL, OP-TEE OS will try to output log to that file, | ||
* which is on the semihosting host system. | ||
* Otherwise, if @file_path is NULL, OP-TEE OS will try to output log to the | ||
* semihosting host debug console. | ||
*/ | ||
void semihosting_console_init(const char *file_path); | ||
#else | ||
static inline void semihosting_console_init(const char *file_path __unused) | ||
{ | ||
} | ||
#endif | ||
|
||
#endif /* __DRIVERS_SEMIHOSTING_CONSOLE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters