Add print command

This commit is contained in:
Jeremy Soller 2020-03-14 21:13:07 -06:00
parent 8a8ab165a7
commit 25a60568d0
No known key found for this signature in database
GPG Key ID: E988B49EE78A7FB1
2 changed files with 41 additions and 1 deletions

View File

@ -16,7 +16,7 @@ pub enum Cmd {
Probe = 1,
Board = 2,
Version = 3,
Debug = 4,
Print = 4,
Spi = 5,
Reset = 6,
}
@ -151,6 +151,23 @@ impl<T: Timeout> Ec<T> {
Ok(i)
}
pub unsafe fn print(&mut self, data: &[u8]) -> Result<usize, Error> {
let flags = 0;
for chunk in data.chunks(256 - 4) {
for i in 0..chunk.len() {
self.write(i as u8 + 4, chunk[i]);
}
self.write(2, flags);
self.write(3, chunk.len() as u8);
self.command(Cmd::Print)?;
if self.read(3) != chunk.len() as u8 {
return Err(Error::Verify);
}
}
Ok(data.len())
}
pub unsafe fn spi(&mut self, target: SpiTarget, scratch: bool) -> Result<EcSpi<T>, Error> {
let mut spi = EcSpi {
ec: self,

View File

@ -262,10 +262,23 @@ unsafe fn info() -> Result<(), Error> {
Ok(())
}
unsafe fn print(message: &[u8]) -> Result<(), Error> {
iopl();
let mut ec = Ec::new(
StdTimeout::new(Duration::new(1, 0)),
)?;
ec.print(message)?;
Ok(())
}
fn usage() {
eprintln!(" console");
eprintln!(" flash [file]");
eprintln!(" info");
eprintln!(" print [message]");
}
fn main() {
@ -300,6 +313,16 @@ fn main() {
process::exit(1);
},
},
"print" => for mut arg in args {
arg.push('\n');
match unsafe { print(&arg.as_bytes()) } {
Ok(()) => (),
Err(err) => {
eprintln!("failed to print '{}': {:X?}", arg, err);
process::exit(1);
},
}
},
_ => {
eprintln!("unknown subcommand '{}'", arg);
usage();