Skip to content

Add getting battery info thorugh SMBUS#350

Merged
JohnAZoidberg merged 14 commits into
mainfrom
battery-smbus-clean
Jul 2, 2026
Merged

Add getting battery info thorugh SMBUS#350
JohnAZoidberg merged 14 commits into
mainfrom
battery-smbus-clean

Conversation

@JohnAZoidberg

Copy link
Copy Markdown
Member

No description provided.

@JohnAZoidberg JohnAZoidberg force-pushed the battery-smbus-clean branch from 416dfd9 to 63d9117 Compare July 2, 2026 07:10
Add a new --smartbattery command to read basic Smart Battery System
(SBS) information via I2C passthrough to the EC. This includes:
- Battery mode, serial number, manufacture date
- Temperature, voltage, individual cell voltages
- Cycle count, device name, manufacturer name

Reference: TI Smart Battery System specification

Signed-off-by: Daniel Schaefer <dhs@frame.work>
Add support for reading TI BQ40z50 ManufacturerAccess registers:
- Unseal/seal commands for protected data access
- OperationStatus, SafetyAlert/Status, PFAlert/Status registers
- LifeTimeDataBlocks 1-5 with detailed field decoding
- State of Health (remaining capacity in mAh/Wh)

Features:
- Hidden input for unseal key (no terminal echo)
- Multi-line operation status display with flag decoding
- Detailed lifetime statistics (voltages, temps, currents, events)

Requires nix "term" feature for Unix terminal control.

Signed-off-by: Daniel Schaefer <dhs@frame.work>
Add BatteryData struct for collecting and serializing battery data:
- write_to_file/read_from_file for simple text-based dump format
- collect_data() method to gather all data into struct
- display_battery_data() function for formatted output
- Refactor dump_data() to use collect_data + display_battery_data
- dump_to_file() method for saving data to file

Add unit tests for:
- Parsing battery dump files
- Lifetime data validation
- Hex encode/decode roundtrip
- Manufacture date decoding
- Temperature unit conversion

Signed-off-by: Daniel Schaefer <dhs@frame.work>
Add analyze_health() function to evaluate battery condition:
- Safety and permanent failure status check
- Cell voltage balance analysis (current and historical)
- Temperature extreme detection
- Safety event counting (over-voltage, under-voltage, over-current)
- Gauging health metrics (charge termination rate, resistance updates)

Prints a summary with status (HEALTHY/GOOD/NEEDS ATTENTION),
any issues or warnings, and key statistics including cycle count,
remaining capacity, and cell balancing times.

Signed-off-by: Daniel Schaefer <dhs@frame.work>
The --smartbattery flag now accepts an optional file path to load
previously dumped battery data instead of reading from the actual
battery. This enables offline analysis and debugging.

Signed-off-by: Daniel Schaefer <dhs@frame.work>
Add battery authentication using TI's nested SHA-1 HMAC method:
- calculate_ti_hmac(): Implements SHA1(Key || SHA1(Key || Challenge))
- authenticate_battery(): Challenge-response authentication flow
- interactive_authenticate(): CLI interface with unseal/auth key prompts

The authentication verifies battery authenticity by:
1. Sending a random 20-byte challenge to the battery
2. Waiting 250ms for the gauge to compute the response
3. Computing expected response locally using the auth key
4. Comparing responses to verify genuineness

Add --smartbattery-auth CLI flag for interactive authentication.
Requires sha1 and rand crate dependencies.

Signed-off-by: Daniel Schaefer <dhs@frame.work>
Signed-off-by: Daniel Schaefer <dhs@frame.work>
Signed-off-by: Daniel Schaefer <dhs@frame.work>
Signed-off-by: Daniel Schaefer <dhs@frame.work>
Signed-off-by: Daniel Schaefer <dhs@frame.work>
Signed-off-by: Daniel Schaefer <dhs@frame.work>
Read standard SBS registers (current, charge state, capacity, design
specs, battery status, chemistry) that are always available without
unsealing. Also attempt MAC block reads (lifetime, safety, SOH) in
sealed mode with fallback, and reorder display to group identity fields.
Signed-off-by: Daniel Schaefer <dhs@frame.work>
Signed-off-by: Daniel Schaefer <dhs@frame.work>
@JohnAZoidberg JohnAZoidberg force-pushed the battery-smbus-clean branch from 6711269 to 56c98f1 Compare July 2, 2026 07:20
@JohnAZoidberg JohnAZoidberg merged commit a5d8c7d into main Jul 2, 2026
11 checks passed
@JohnAZoidberg JohnAZoidberg deleted the battery-smbus-clean branch July 2, 2026 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant