Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions tbf-parser/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,21 +94,19 @@ impl fmt::Debug for TbfParseError {
match self {
TbfParseError::NotEnoughFlash => write!(f, "Buffer too short to parse TBF header"),
TbfParseError::UnsupportedVersion(version) => {
write!(f, "TBF version {} unsupported", version)
write!(f, "TBF version {version} unsupported")
}
TbfParseError::ChecksumMismatch(app, calc) => write!(
f,
"Checksum verification failed: app:{:#x}, calc:{:#x}",
app, calc
"Checksum verification failed: app:{app:#x}, calc:{calc:#x}"
),
TbfParseError::BadTlvEntry(tipe) => write!(f, "TLV entry type {} is invalid", tipe),
TbfParseError::BadTlvEntry(tipe) => write!(f, "TLV entry type {tipe} is invalid"),
TbfParseError::BadProcessName => write!(f, "Process name not UTF-8"),
TbfParseError::InternalError => write!(f, "Internal kernel error. This is a bug."),
TbfParseError::TooManyEntries(tipe) => {
write!(
f,
"There are too many variable entries of {} for Tock to parse",
tipe
"There are too many variable entries of {tipe} for Tock to parse"
)
}
TbfParseError::PackageNameTooLong => write!(f, "The package name is too long."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ impl ComponentRender<()> for SetupPage {

let available_ports = match tokio_serial::available_ports() {
Ok(ports) => ports,
Err(error) => panic!("Error while searching for ports: {}", error),
Err(error) => panic!("Error while searching for ports: {error}"),
};

let mut vec_serial: Vec<Text> = vec![];
Expand Down Expand Up @@ -261,7 +261,7 @@ impl ComponentRender<()> for SetupPage {
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.fg(Color::Yellow)
.title(format!(" Number of boards found: {} ", boards_found))
.title(format!(" Number of boards found: {boards_found} "))
.title_style(Style::default().fg(Color::Blue)),
)
.highlight_style(Style::default().add_modifier(Modifier::BOLD))
Expand All @@ -275,12 +275,12 @@ impl ComponentRender<()> for SetupPage {
if self.show_state == ShowState::ShowBoardsOnly {
match self.probeinfo_sender.send(board_ports) {
Ok(data) => data,
Err(error) => println!("{}", error),
Err(error) => println!("{error}"),
};
} else if self.show_state == ShowState::ShowAllSerialPorts {
match self.probeinfo_sender.send(serial_ports) {
Ok(data) => data,
Err(error) => println!("{}", error),
Err(error) => println!("{error}"),
};
}

Expand Down Expand Up @@ -374,7 +374,7 @@ impl ComponentRender<()> for SetupPage {
frame.render_widget(help_text, help_text_h);

let error = if let Some(error) = &self.properties.error_message {
Text::from(format!("Error: {}", error))
Text::from(format!("Error: {error}"))
} else {
Text::from("")
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub struct UsageInfo {
}

fn key_to_span<'a>(key: &String) -> Span<'a> {
Span::from(format!("( {} )", key)).bold()
Span::from(format!("( {key} )")).bold()
}

pub fn widget_usage_to_text<'a>(usage: UsageInfo) -> Text<'a> {
Expand Down
4 changes: 4 additions & 0 deletions tockloader-cli/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use tockloader_lib::attributes::app_attributes::AppAttributes;
use tockloader_lib::attributes::system_attributes::SystemAttributes;

// TODO(george-cosma): Fix this
#[allow(clippy::uninlined_format_args)]
pub async fn print_list(app_details: &[AppAttributes]) {
for (i, details) in app_details.iter().enumerate() {
println!("\n\x1b[0m\x1b[1;35m ┏━━━━━━━━━━━━━━━━┓");
Expand Down Expand Up @@ -40,6 +42,8 @@ pub async fn print_list(app_details: &[AppAttributes]) {
}
}

// TODO(george-cosma): Fix this
#[allow(clippy::uninlined_format_args)]
pub async fn print_info(app_details: &mut [AppAttributes], system_details: &mut SystemAttributes) {
for (i, details) in app_details.iter().enumerate() {
println!("\n\x1b[0m\x1b[1;35m ┏━━━━━━━━━━━━━━━━┓");
Expand Down
51 changes: 30 additions & 21 deletions tockloader-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ use clap::ArgMatches;
use cli::make_cli;
use known_boards::KnownBoardNames;
use tockloader_lib::board_settings::BoardSettings;
use tockloader_lib::connection::{Connection, ConnectionInfo, ProbeTargetInfo, SerialTargetInfo};
use tockloader_lib::connection::{
Connection, ProbeRSConnection, ProbeTargetInfo, SerialConnection, SerialTargetInfo,
TockloaderConnection,
};
use tockloader_lib::known_boards::KnownBoard;
use tockloader_lib::tabs::tab::Tab;
use tockloader_lib::{list_debug_probes, list_serial_ports};
use tockloader_lib::{
list_debug_probes, list_serial_ports, CommandInfo, CommandInstall, CommandList,
};

fn get_serial_target_info(user_options: &ArgMatches) -> SerialTargetInfo {
let board = get_known_board(user_options);
Expand Down Expand Up @@ -83,7 +88,7 @@ fn get_known_board(user_options: &ArgMatches) -> Option<Box<dyn KnownBoard>> {
})
}

fn open_connection(user_options: &ArgMatches) -> Result<Connection> {
async fn open_connection(user_options: &ArgMatches) -> Result<TockloaderConnection> {
if using_serial(user_options) {
let path = if let Some(path) = user_options.get_one::<String>("port") {
path.clone()
Expand All @@ -96,22 +101,27 @@ fn open_connection(user_options: &ArgMatches) -> Result<Connection> {
.context("No device is connected.")?
};

Connection::open(ConnectionInfo::SerialInfo(
path,
get_serial_target_info(user_options),
))
.context("Failed to open serial connection.")
let mut conn: TockloaderConnection =
SerialConnection::new(path, get_serial_target_info(user_options)).into();
conn.open()
.await
.context("Failed to open serial connection.")?;

Ok(conn)
} else {
let ans =
inquire::Select::new("Which debug probe do you want to use?", list_debug_probes())
.prompt()
.context("No debug probe is connected.")?;

Connection::open(ConnectionInfo::ProbeInfo(
ans,
get_probe_target_info(user_options),
))
.context("Failed to open probe connection.")
let mut conn: TockloaderConnection =
ProbeRSConnection::new(ans, get_probe_target_info(user_options)).into();

conn.open()
.await
.context("Failed to open probe connection.")?;

Ok(conn)
}
}

Expand All @@ -130,21 +140,20 @@ async fn main() -> Result<()> {
Some(("list", sub_matches)) => {
cli::validate(&mut cmd, sub_matches);

let mut conn = open_connection(sub_matches)?;
let mut conn = open_connection(sub_matches).await?;
let settings = get_board_settings(sub_matches);

let app_details = tockloader_lib::list(&mut conn, &settings)
.await
.context("Failed to list apps.")?;
let app_details = conn.list(&settings).await.context("Failed to list apps.")?;

display::print_list(&app_details).await;
}
Some(("info", sub_matches)) => {
cli::validate(&mut cmd, sub_matches);
let mut conn = open_connection(sub_matches)?;
let mut conn = open_connection(sub_matches).await?;
let settings = get_board_settings(sub_matches);

let mut attributes = tockloader_lib::info(&mut conn, &settings)
let mut attributes = conn
.info(&settings)
.await
.context("Failed to get data from the board.")?;

Expand All @@ -155,10 +164,10 @@ async fn main() -> Result<()> {
let tab_file = Tab::open(sub_matches.get_one::<String>("tab").unwrap().to_string())
.context("Failed to use provided tab file.")?;

let mut conn = open_connection(sub_matches)?;
let mut conn = open_connection(sub_matches).await?;
let settings = get_board_settings(sub_matches);

tockloader_lib::install_app(&mut conn, &settings, tab_file)
conn.install_app(&settings, tab_file)
.await
.context("Failed to install app.")?;
}
Expand Down
1 change: 1 addition & 0 deletions tockloader-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ bytes = "1.7.1"
toml = "0.8.19"
serde = { version = "1.0.210", features = ["derive"] }
thiserror = "1.0.63"
async-trait = "0.1.88"
2 changes: 2 additions & 0 deletions tockloader-lib/src/attributes/app_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ impl TbfFooter {
}
}

// TODO(george-cosma): Could take advantages of the trait rework

impl AppAttributes {
pub(crate) fn new(header_data: TbfHeader, footers_data: Vec<TbfFooter>) -> AppAttributes {
AppAttributes {
Expand Down
2 changes: 2 additions & 0 deletions tockloader-lib/src/board_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ pub struct BoardSettings {
pub start_address: u64,
}

// TODO(george-cosma): Does a default implementation make sense for this? Is a
// 'None' architechture a sane idea?
impl Default for BoardSettings {
fn default() -> Self {
Self {
Expand Down
49 changes: 49 additions & 0 deletions tockloader-lib/src/command_impl/generalized.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
use async_trait::async_trait;

use crate::attributes::app_attributes::AppAttributes;
use crate::attributes::general_attributes::GeneralAttributes;
use crate::board_settings::BoardSettings;
use crate::connection::TockloaderConnection;
use crate::errors::TockloaderError;
use crate::tabs::tab::Tab;
use crate::{CommandInfo, CommandInstall, CommandList};

#[async_trait]
impl CommandList for TockloaderConnection {
async fn list(
&mut self,
settings: &BoardSettings,
) -> Result<Vec<AppAttributes>, TockloaderError> {
match self {
TockloaderConnection::ProbeRS(conn) => conn.list(settings).await,
TockloaderConnection::Serial(conn) => conn.list(settings).await,
}
}
}

#[async_trait]
impl CommandInfo for TockloaderConnection {
async fn info(
&mut self,
settings: &BoardSettings,
) -> Result<GeneralAttributes, TockloaderError> {
match self {
TockloaderConnection::ProbeRS(conn) => conn.info(settings).await,
TockloaderConnection::Serial(conn) => conn.info(settings).await,
}
}
}

#[async_trait]
impl CommandInstall for TockloaderConnection {
async fn install_app(
&mut self,
settings: &BoardSettings,
tab_file: Tab,
) -> Result<(), TockloaderError> {
match self {
TockloaderConnection::ProbeRS(conn) => conn.install_app(settings, tab_file).await,
TockloaderConnection::Serial(conn) => conn.install_app(settings, tab_file).await,
}
}
}
3 changes: 3 additions & 0 deletions tockloader-lib/src/command_impl/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod generalized;
pub mod probers;
pub mod serial;
33 changes: 33 additions & 0 deletions tockloader-lib/src/command_impl/probers/info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use async_trait::async_trait;

use crate::attributes::app_attributes::AppAttributes;
use crate::attributes::general_attributes::GeneralAttributes;
use crate::attributes::system_attributes::SystemAttributes;
use crate::board_settings::BoardSettings;
use crate::connection::{Connection, ProbeRSConnection};
use crate::errors::TockloaderError;
use crate::CommandInfo;

#[async_trait]
impl CommandInfo for ProbeRSConnection {
async fn info(
&mut self,
settings: &BoardSettings,
) -> Result<GeneralAttributes, TockloaderError> {
if !self.is_open() {
return Err(TockloaderError::ConnectionNotOpen);
}
let session = self.session.as_mut().expect("Board must be open");

let mut core = session
.core(self.target_info.core)
.map_err(|e| TockloaderError::CoreAccessError(self.target_info.core, e))?;

// TODO(george-cosma): extract these informations without bootloader
let system_attributes = SystemAttributes::read_system_attributes_probe(&mut core)?;
let app_attributes =
AppAttributes::read_apps_data_probe(&mut core, settings.start_address)?;

Ok(GeneralAttributes::new(system_attributes, app_attributes))
}
}
Loading
Loading