Skip to content

Commit

Permalink
rfel: identify chip from fel version id field
Browse files Browse the repository at this point in the history
Signed-off-by: Zhouqi Jiang <[email protected]>
  • Loading branch information
luojia65 committed Oct 31, 2024
1 parent 5a63e45 commit e43e448
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions rfel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn main() {
let mut interface = device.claim_interface(0).expect("open USB interface 0");
let fel = Fel::open_usb_interface(&mut interface).expect("open usb interface as an FEL device");
let version = fel.get_version();
println!("{:?}", version);
println!("{:x?}", version);
}

struct Fel<'a> {
Expand Down Expand Up @@ -214,14 +214,34 @@ struct Version {
pad: [u8; 8],
}

impl Version {
/// Get chip from version.
fn chip(self) -> Option<Chip> {
match self.id {
0x00185900 => Some(Chip::D1),
_ => None,
}
}
}

impl fmt::Debug for Version {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_map()
.entry(&"magic", &String::from_utf8_lossy(&self.magic))
.entry(&"id", &self.id)
.entry(&"dflag", &self.dflag)
let mut map = f.debug_map();
map.entry(&"magic", &String::from_utf8_lossy(&self.magic));

Check warning on line 230 in rfel/src/main.rs

View workflow job for this annotation

GitHub Actions / Rustfmt all packages

Diff in /home/runner/work/allwinner-hal/allwinner-hal/rfel/src/main.rs
match self.chip() {
Some(chip) => map.entry(&"chip", &chip),
None => map.entry(&"id", &self.id)
};
map.entry(&"dflag", &self.dflag)
.entry(&"dlength", &self.dlength)
.entry(&"scratchpad", &self.scratchpad)
.finish()
}
}

#[derive(Debug)]
#[repr(u32)]
enum Chip {
/// D1-H, D1s or F133 chip.
D1 = 0x00185900,
}

0 comments on commit e43e448

Please sign in to comment.