-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
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. 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. Signed-off-by: Alvin Chang <[email protected]>
- Loading branch information
Showing
3 changed files
with
82 additions
and
0 deletions.
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,56 @@ | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
/* | ||
* Copyright (c) 2024 Andes Technology Corporation | ||
*/ | ||
|
||
#include <compiler.h> | ||
#include <drivers/semihosting_console.h> | ||
#include <kernel/semihosting.h> | ||
#include <util.h> | ||
|
||
static void semihosting_console_putc(struct serial_chip *chip __unused, int ch) | ||
{ | ||
semihosting_writec(ch); | ||
} | ||
|
||
static int semihosting_console_getchar(struct serial_chip *chip __unused) | ||
{ | ||
return semihosting_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) | ||
{ | ||
struct semihosting_console_data *pd = | ||
container_of(chip, struct semihosting_console_data, chip); | ||
|
||
semihosting_write(pd->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(struct semihosting_console_data *pd, | ||
const char *file_path) | ||
{ | ||
if (file_path) { | ||
/* Output log to given file. */ | ||
pd->chip.ops = &semihosting_console_fd_ops; | ||
pd->file_path = file_path; | ||
pd->fd = semihosting_open(pd->file_path, | ||
O_RDWR | O_CREAT | O_TRUNC); | ||
} else { | ||
/* Output log to semihosting console. */ | ||
pd->chip.ops = &semihosting_console_ops; | ||
pd->file_path = NULL; | ||
pd->fd = -1; | ||
} | ||
} |
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,25 @@ | ||
/* SPDX-License-Identifier: BSD-2-Clause */ | ||
/* | ||
* Copyright (c) 2024 Andes Technology Corporation | ||
*/ | ||
#ifndef __DRIVERS_SEMIHOSTING_CONSOLE_H | ||
#define __DRIVERS_SEMIHOSTING_CONSOLE_H | ||
|
||
#include <drivers/serial.h> | ||
|
||
struct semihosting_console_data { | ||
struct serial_chip chip; | ||
const char *file_path; | ||
int fd; | ||
}; | ||
|
||
/* | ||
* 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. | ||
* Otherwise, if "file_path" is NULL, OP-TEE OS will try to output log to the | ||
* semihosting console. | ||
*/ | ||
void semihosting_console_init(struct semihosting_console_data *pd, | ||
const char *file_path); | ||
|
||
#endif /* __DRIVERS_SEMIHOSTING_CONSOLE_H */ |