Skip to content

Commit b09c068

Browse files
committed
battery: read unseal key from input
Don't hardcode it, don't read it from commandline (to avoid saving in history) Signed-off-by: Daniel Schaefer <[email protected]>
1 parent 696abdc commit b09c068

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

framework_lib/src/battery.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use alloc::vec::Vec;
66
use sha1::{Sha1, Digest};
77
use std::thread;
88
use std::time::Duration;
9+
use std::io;
910

1011
use crate::chromium_ec::i2c_passthrough::*;
1112
use crate::chromium_ec::{CrosEc, EcResult, EcError};
@@ -247,8 +248,19 @@ impl SmartBattery {
247248
self.read_string(ec, SmartBatReg::ManufacturerName as u16)?
248249
);
249250

250-
// Default key - does not work on our battery, it's changed during manufacturing!
251-
self.unseal(ec, 0x0414, 0x3672).unwrap();
251+
// The default key is 0x0414, 0x3672 - but our platforms have a customized one.
252+
println!("Enter unseal key in hex format, or press enter to skip. Example: 04143672");
253+
let mut input_text = String::new();
254+
io::stdin()
255+
.read_line(&mut input_text)
256+
.expect("Failed to read line");
257+
let input_text = input_text.trim();
258+
if input_text.is_empty() {
259+
return Ok(());
260+
}
261+
let key: u32 = u32::from_str_radix(&input_text, 16)
262+
.expect("Couldn't parse Input as u32");
263+
self.unseal(ec, (key >> 16) as u16, key as u16).unwrap();
252264

253265
// Dummy code. Do not push real authentication key!
254266
// self.authenticate_battery(ec, &[0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]);
@@ -283,7 +295,7 @@ impl SmartBattery {
283295
self.read_i16(&ec, ManufReg::PFStatus as u16)?
284296
);
285297
let lifetime1 = self.read_bytes(ec, ManufReg::LifeTimeDataBlock1 as u16, 32)?;
286-
println!("LifeTime1");
298+
println!("LifeTime1 {:X?}", lifetime1);
287299
println!(
288300
" Cell 1 Max Voltage: {}mV",
289301
u16::from_le_bytes([lifetime1[0], lifetime1[1]])
@@ -361,7 +373,7 @@ impl SmartBattery {
361373
lifetime1[31]
362374
);
363375
let lifetime2 = self.read_bytes(ec, ManufReg::LifeTimeDataBlock2 as u16, 20)?; // 8?
364-
println!("LifeTime2");
376+
println!("LifeTime2 {:X?}", lifetime2);
365377
println!(" No. of Shutdowns: {}
366378
No. of Partial Resets: {}
367379
No. of Full Resets: {}

0 commit comments

Comments
 (0)