-
Notifications
You must be signed in to change notification settings - Fork 782
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[opentitantool] Add ability to access underlying serial device
Some transports/debuggers expose the serial ports in a way that can be accessed by other programs, without necessarily going through opentitanlib. This CL introduces a new `uart` top level command and `os-device` under it, (in hindsigt, `console` and `rescue` probably beloned under the same top-level, in order to share some flag processing.) The idea is that `opentitantool` can be queried, using a set of configuration file with aliases and command line usb serial number, and will print the path of the underlying OS device corresponding to the given port of the given debugger: ``` opentitantool --conf ... --usb-serial ... uart --uart=EC os-device { path: "/dev/ttyUSB6" } ``` This can be used in cases where processing of output from the OpenTitan chip takes place in external scripts or programs. Such cases currently will have to use an `opentitantool console` process to pass data between the serial device and its stdin/stdout pipes to the actual script doing the actual processing, which is wasteful. Change-Id: Id4dfff38fbc74ec65366d3a7e49a6844ae52c8ee Signed-off-by: Jes B. Klinke <[email protected]>
- Loading branch information
Showing
10 changed files
with
98 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
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
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
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
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,65 @@ | ||
// Copyright lowRISC contributors (OpenTitan project). | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use anyhow::Result; | ||
use clap::{Args, Subcommand}; | ||
use serde_annotate::Annotate; | ||
use std::any::Any; | ||
|
||
use opentitanlib::app::command::CommandDispatch; | ||
use opentitanlib::app::TransportWrapper; | ||
use opentitanlib::io::uart::UartParams; | ||
|
||
/// Outputs `"/dev/ttyUSBn"` or similar OS device path usable by external programs for directly | ||
/// accessing the given serial port of the debugger. | ||
#[derive(Debug, Args)] | ||
pub struct UartOsDevice { | ||
} | ||
|
||
|
||
#[derive(Debug, serde::Serialize)] | ||
pub struct UartOsDeviceResponse { | ||
path: String, | ||
} | ||
|
||
impl CommandDispatch for UartOsDevice { | ||
fn run( | ||
&self, | ||
context: &dyn Any, | ||
transport: &TransportWrapper, | ||
) -> Result<Option<Box<dyn Annotate>>> { | ||
let context = context.downcast_ref::<UartCommand>().unwrap(); | ||
let uart = context.params.create(transport)?; | ||
Ok(Some(Box::new(UartOsDeviceResponse { | ||
path: uart.get_device_path()?, | ||
}))) | ||
} | ||
} | ||
|
||
/// Commands for interacting with a UART. | ||
#[derive(Debug, Subcommand, CommandDispatch)] | ||
pub enum InternalUartCommand { | ||
OsDevice(UartOsDevice), | ||
} | ||
|
||
#[derive(Debug, Args)] | ||
pub struct UartCommand { | ||
#[command(flatten)] | ||
params: UartParams, | ||
|
||
#[command(subcommand)] | ||
command: InternalUartCommand, | ||
} | ||
|
||
impl CommandDispatch for UartCommand { | ||
fn run( | ||
&self, | ||
_context: &dyn Any, | ||
transport: &TransportWrapper, | ||
) -> Result<Option<Box<dyn Annotate>>> { | ||
// None of the UART commands care about the prior context, but they do | ||
// care about the `UartParams` parameter in the current node. | ||
self.command.run(self, transport) | ||
} | ||
} |
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