Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
Merge #281
Browse files Browse the repository at this point in the history
281: Report flashing size using probe-rs's FlashProgress system. r=jonas-schievink a=jonathanpallant

We get an Initialized object at the start, and then one message per sector erase and one message per block write.

Co-authored-by: Jonathan Pallant (Ferrous Systems) <[email protected]>
  • Loading branch information
bors[bot] and jonathanpallant authored Nov 24, 2021
2 parents 25f8e32 + e9ec9c8 commit 3019fc1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
10 changes: 1 addition & 9 deletions src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use std::{collections::HashSet, convert::TryInto, env, ops::Deref};
use anyhow::{anyhow, bail};
use defmt_decoder::{Locations, Table};
use object::{
read::File as ObjectFile, Object as _, ObjectSection as _, ObjectSegment as _,
ObjectSymbol as _, SymbolSection,
read::File as ObjectFile, Object as _, ObjectSection as _, ObjectSymbol as _, SymbolSection,
};

use crate::cortexm;
Expand Down Expand Up @@ -55,13 +54,6 @@ impl<'file> Elf<'file> {
pub(crate) fn rtt_buffer_address(&self) -> Option<u32> {
self.symbols.rtt_buffer_address
}

/// Returns the size of the part of the program allocated in Flash
pub(crate) fn program_flash_size(&self) -> u64 {
// `segments` iterates only over *loadable* segments,
// which are the segments that will be loaded to Flash by probe-rs
self.elf.segments().map(|segment| segment.size()).sum()
}
}

impl<'elf> Deref for Elf<'elf> {
Expand Down
42 changes: 39 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,46 @@ fn run_target_program(elf_path: &Path, chip_name: &str, opts: &cli::Opts) -> any
if opts.no_flash {
log::info!("skipped flashing");
} else {
let size = elf.program_flash_size();
log::info!("flashing program ({:.02} KiB)", size as f64 / 1024.0);
let fp = flashing::FlashProgress::new(|evt| {
match evt {
// The flash layout has been built and the flashing procedure was initialized.
flashing::ProgressEvent::Initialized { flash_layout, .. } => {
let pages = flash_layout.pages();
let num_pages = pages.len();
let num_bytes: u64 = pages.iter().map(|x| x.size() as u64).sum();
log::info!(
"flashing program ({} pages / {:.02} KiB)",
num_pages,
num_bytes as f64 / 1024.0
);
}
// A sector has been erased. Sectors (usually) contain multiple pages.
flashing::ProgressEvent::SectorErased { size, time } => {
log::debug!(
"Erased sector of size {} bytes in {} ms",
size,
time.as_millis()
);
}
// A page has been programmed.
flashing::ProgressEvent::PageProgrammed { size, time } => {
log::debug!(
"Programmed page of size {} bytes in {} ms",
size,
time.as_millis()
);
}
_ => {
// Ignore other events
}
}
});

let mut options = flashing::DownloadOptions::default();
options.dry_run = false;
options.progress = Some(&fp);

flashing::download_file(&mut sess, elf_path, Format::Elf)?;
flashing::download_file_with_options(&mut sess, elf_path, Format::Elf, options)?;
log::info!("success!");
}

Expand Down

0 comments on commit 3019fc1

Please sign in to comment.