Files
ecflash/examples/read.rs
Tim Crawford b08db29313 Fix build warnings and errors on nightly
Update redox_hwio to fix building dependencies on nightly.

Fix warnings:

- deprecated
- bare_trait_objects
- unused_must_use
- clippy::chars_next_cmp
- clippy::while_let_on_iterator
- clippy::redundant_field_names
- clippy::needless_borrow
- clippy::println_empty_string

Silence warnings:

- dead_code
- clippy::missing_safety_doc
- clippy::needless_range_loop
- clippy::result_unit_err

Signed-off-by: Tim Crawford <tcrawford@system76.com>
2021-10-21 10:56:38 -06:00

36 lines
871 B
Rust

extern crate ecflash;
use ecflash::{EcFlash, Flasher};
use std::{fs, io, process};
fn main() {
extern {
fn iopl(level: isize) -> isize;
}
// Get I/O Permission
unsafe {
if iopl(3) < 0 {
eprintln!("Failed to get I/O permission: {}", io::Error::last_os_error());
process::exit(1);
}
let ec = EcFlash::new(true).expect("Failed to find EC");
let mut flasher = Flasher::new(ec);
if flasher.start() == Ok(51) {
if let Ok(data) = flasher.read(|x| { eprint!("\r{} KB", x / 1024) }) {
eprintln!();
let _ = fs::write("read.rom", data);
} else {
eprintln!("Failed to read data");
}
let _ = flasher.stop();
} else {
eprintln!("Failed to start flasher");
}
}
}