Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Verified Commit 9a80b4d2 authored by Ayush Singh's avatar Ayush Singh
Browse files

bb-imager: Improve sd card flashing performance


- Decreses sd card flashing time by 57% (only tested on Linux).
- Still slower than bb-imager but not by much.

Signed-off-by: Ayush Singh's avatarAyush Singh <ayush@beagleboard.org>
parent 3a055f25
Branches
Tags
1 merge request!32bb-imager: Improve sd card flashing performance
......@@ -2657,6 +2657,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "603222e049bf0da71529325ada5d02dc3871cbd3679cf905429f7f0de93da87b"
dependencies = [
"liblzma-sys",
"num_cpus",
]
[[package]]
......
......@@ -8,7 +8,7 @@ repository.workspace = true
license.workspace = true
[dependencies]
liblzma = { version = "0.3.5", features = ["static"] }
liblzma = { version = "0.3.5", features = ["static", "parallel"] }
chrono = { version = "0.4.38", features = ["serde"] }
const-hex = { version = "1.13.1", features = ["serde"] }
crc32fast = "1.4.2"
......
......@@ -15,7 +15,7 @@ use crate::{
util,
};
pub(crate) const BUF_SIZE: usize = 32 * 1024;
pub(crate) const BUF_SIZE: usize = 128 * 1024;
#[derive(Error, Debug)]
pub enum Error {
......
......@@ -26,23 +26,17 @@ fn read_aligned(img: &mut crate::img::OsImage, buf: &mut [u8]) -> Result<usize>
let count = img.read(&mut buf[pos..])?;
if count == 0 {
break;
let end = pos + pos % 512;
buf[pos..end].fill(0);
return Ok(end);
}
pos += count;
// The buffer size is always a multiple of 512
if pos % 512 == 0 {
break;
return Ok(pos);
}
}
if pos == 0 || pos % 512 == 0 {
Ok(pos)
} else {
let rem = pos % 512;
buf[pos..rem].fill(0);
Ok(pos + rem)
}
}
pub(crate) async fn flash<W>(
......@@ -67,14 +61,14 @@ where
break;
}
tracing::debug!("Write: {} bytes", count);
sd.write_all(&buf[..count]).await?;
pos += count;
let _ = chan.try_send(DownloadFlashingStatus::FlashingProgress(
pos as f32 / size as f32,
));
tracing::debug!("Write: {} bytes", count);
sd.write_all(&buf[..count]).await?;
}
if verify {
......
......@@ -63,7 +63,7 @@ impl OsImage {
let size = liblzma::uncompressed_size(&mut file)?;
file.seek(std::io::SeekFrom::Start(0))?;
let img = liblzma::read::XzDecoder::new(file);
let img = liblzma::read::XzDecoder::new_parallel(file);
let hasher = Sha256::new();
Ok(Self {
......
......@@ -26,16 +26,16 @@ pub(crate) async fn sha256_reader_progress<R: tokio::io::AsyncReadExt + Unpin>(
loop {
let count = reader.read(&mut buffer).await?;
pos += count;
let _ = chan.try_send(crate::DownloadFlashingStatus::VerifyingProgress(
pos as f32 / size as f32,
));
if count == 0 {
break;
}
hasher.update(&buffer[..count]);
pos += count;
let _ = chan.try_send(crate::DownloadFlashingStatus::VerifyingProgress(
pos as f32 / size as f32,
));
}
let hash = hasher
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment