Skip to content

Commit

Permalink
Add bootloader updater support
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLafleur committed Oct 27, 2024
1 parent 774d0c7 commit b29cbf2
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
10 changes: 10 additions & 0 deletions conUDS/src/arguments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct Arguments {
pub enum ArgSubCommands {
Download(SubArgDownload),
Reset(SubArgReset),
BootloaderDownload(SubArgBootloaderDownload),
}

/// Download an application to an ECU
Expand All @@ -39,6 +40,15 @@ pub struct SubArgDownload {
pub binary: PathBuf,
}

/// Download a bootloader to an ECU
#[derive(Debug, FromArgs)]
#[argh(subcommand, name = "bootloader-download")]
pub struct SubArgBootloaderDownload {
/// path to the binary file to flash
#[argh(positional)]
pub binary: PathBuf,
}

/// Reset an ECU
#[derive(Debug, FromArgs)]
#[argh(subcommand, name = "reset")]
Expand Down
23 changes: 21 additions & 2 deletions conUDS/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ async fn main() -> Result<()> {
"Downloading binary at '{:#?}' to node `{}`",
dl.binary, args.node
);
uds_client.ecu_reset(SupportedResetTypes::Hard).await;
let _ = uds_client.ecu_reset(SupportedResetTypes::Hard).await;
uds_client.start_persistent_tp().await?;

info!("Waiting for the user to hit enter before continuing with download");
Expand All @@ -121,7 +121,26 @@ async fn main() -> Result<()> {
}
info!("Enter key detected, proceeding with download");

if let Err(e) = uds_client.app_download(dl.binary).await {
if let Err(e) = uds_client.app_download(dl.binary, 0x08002000).await {
error!("While downloading app: {}", e);
}
}
ArgSubCommands::BootloaderDownload(dl) => {
debug!(
"Downloading binary at '{:#?}' to node `{}`",
dl.binary, args.node
);
let _ = uds_client.ecu_reset(SupportedResetTypes::Hard).await;
uds_client.start_persistent_tp().await?;

info!("Waiting for the user to hit enter before continuing with download");
let mut garbage = String::new();
while stdin().read_line(&mut garbage).is_err() {
// wait for user to hit enter
}
info!("Enter key detected, proceeding with download");

if let Err(e) = uds_client.app_download(dl.binary, 0x08000000).await {
error!("While downloading app: {}", e);
}
}
Expand Down
10 changes: 7 additions & 3 deletions conUDS/src/modules/uds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use anyhow::anyhow;
use anyhow::Result;
use automotive_diag::uds::UdsCommand;
use automotive_diag::uds::UdsErrorByte;
use automotive_diag::uds::UdsError;
use automotive_diag::uds::{ResetType, RoutineControlType};
use ecu_diagnostics::dynamic_diag::EcuNRC;
use indicatif::{ProgressBar, ProgressStyle};
Expand Down Expand Up @@ -63,7 +64,10 @@ impl UdsClient {
.await?
.await?;
info!("ECU Reset results: {:02x?}", resp);

let nrc = UdsErrorByte::from(*resp.last().unwrap());
if nrc == ecu_diagnostics::Standard(UdsError::ConditionsNotCorrect) {
error!("ECU Reset conditions have not been met. If this is a bootloader updater, reflash with a correct hex.");
}
Ok(())
}

Expand Down Expand Up @@ -297,7 +301,7 @@ impl UdsClient {
///
/// Starts by telling the device to erase the current app, then starts the app download, and lastly
/// starts actually transferring the app
pub async fn app_download(&mut self, file: PathBuf) -> Result<()> {
pub async fn app_download(&mut self, file: PathBuf, address: u32) -> Result<()> {
// disable tester present. bootloader is not currently robust to having tester present enabled
// during an app download
self.send_cmd(PrdCmd::PersistentTesterPresent(false))
Expand All @@ -312,7 +316,7 @@ impl UdsClient {
// start the download, which returns the parameters to use for the subsequent transmissions
let mut dl_params = self
.download_start(UdsDownloadStart::default(
0x08002000,
address,
file_len_bytes.try_into()?,
))
.await?;
Expand Down

0 comments on commit b29cbf2

Please sign in to comment.