Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: FrameworkComputer/framework-system
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: main
Choose a base ref
...
head repository: FrameworkComputer/framework-system
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: sealed-analysis
Choose a head ref
Checking mergeability… Don’t worry, you can still create the pull request.
  • 18 commits
  • 2 files changed
  • 2 contributors

Commits on Dec 1, 2026

  1. --smartbattery: Retry MAC reads that race with the EC

    The EC reads OperationStatus (0x0054) through ManufacturerAccess on
    every charge loop iteration, in battery_get_disconnect_state() for
    batteries with FUEL_GAUGE_FLAG_MFGACC, e.g. NVT FRANDBAT01. If that
    lands between our write to 0x00 and our read from 0x44, we get the
    response for the EC's command. That happened on a few of every 30
    reads.
    
    Retry a few times before giving up. Always read the maximum block
    length, because the EC's response can be longer than the one we expect.
    
    It also works the other way around: if our write lands in between the
    EC's, the EC sees a mismatched echo and treats the battery as
    disconnected for one charge loop iteration. In normal operation that
    only delays leaving charge manager safe mode by one iteration.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    ecca491 View commit details
    Browse the repository at this point in the history
  2. --smartbattery: Read status and lifetime data without unsealing

    The SBS register aliases 0x50-0x77 (SafetyStatus, OperationStatus,
    LifeTimeDataBlock1-5, StateOfHealth, ...) NAK in SEALED mode, so
    without an unseal key none of this data was shown.
    
    The same data is available through ManufacturerBlockAccess (write the
    sub-command to 0x00, read 0x44), which works in SEALED mode too. Use
    that path in both cases.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    234642c View commit details
    Browse the repository at this point in the history
  3. --smartbattery: Show more SBS registers available while sealed

    Read and display registers the gauge answers in SEALED mode:
    
    - RunTimeToEmpty, AverageTimeToEmpty, AverageTimeToFull
    - StateOfHealth (0x4F, percent of design capacity) and MaxError
    - RemainingCapacityAlarm / RemainingTimeAlarm and BTP set points
    - SpecificationInfo and ManufacturerInfo
    - Turbo registers: max/sustained power and current, pack and system
      resistance, minimum system voltage
    
    Not every firmware revision has all of them, so they're optional and
    only written to and read from dump files when present.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    394936b View commit details
    Browse the repository at this point in the history
  4. --smartbattery: Decode charging, gauging and DA status

    Read and decode more ManufacturerAccess blocks, all accessible while
    sealed:
    
    - ChargingStatus (0x0055): temperature and voltage region, inhibit,
      suspend, termination flags. R3 inserted SU at bit 13, shifting the
      higher bits, so decode depending on R2/R3.
    - GaugingStatus (0x0056): Impedance Track state, e.g. whether QMax and
      resistance learning is qualified.
    - DAStatus1 (0x0071): per-cell voltage, current and power, BAT and PACK
      pin voltages, power and average power.
    - DAStatus2 (0x0072): internal, TS1-TS4, cell, FET and gauging
      temperatures. Out of range values are shown as not connected.
    - CBStatus (0x0076): calculated cell balancing time per cell.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    bacf62e View commit details
    Browse the repository at this point in the history
  5. --smartbattery: Decode bq40z50-R4 status additions

    Our packs (device 0x4500, FW 03.09) behave like the R4 TRM (SLUUCH2),
    which adds a few fields on top of R3:
    
    - ChargingStatus bits 22-23: charge degradation mode
    - GaugingStatus bit 14: OCVPRED
    - DAStatus2: cell voltages without IR loss compensation after the
      temperatures. The TRM also lists a User Temperature before them, but
      the packs return 24 bytes with 4 voltages at the end, so take those.
    
    These bits are reserved on R3, so decoding them there is harmless.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    90e6686 View commit details
    Browse the repository at this point in the history
  6. EXAMPLES_ADVANCED: Update --smartbattery example

    Show the output with everything that's now readable without unsealing,
    from a Framework Laptop 16 (AMD Ryzen AI 300) battery.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    c4c1f2f View commit details
    Browse the repository at this point in the history
  7. --smartbattery: Read Impedance Track status and time in ranges

    Read and display more ManufacturerAccess blocks, all accessible while
    sealed:
    
    - GaugeStatus1 (0x0073): true FCC and temperature compensated
      resistance per cell
    - GaugeStatus2 (0x0074): learned status of QMax and resistance table
    - GaugeStatus3 (0x0075): QMax (chemical capacity) per cell
    - LifeTime Data Blocks 6-12 (0x0065-0x006B): time spent in each RSOC
      range, one block per charge temperature range. Shown with the range
      names, because the temperature thresholds are in data flash, which
      can't be read while sealed.
    
    Not every firmware revision has them, so don't fail without them.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    50ff01d View commit details
    Browse the repository at this point in the history
  8. --smartbattery: Analyze health based on TI's checks

    Collect the analysis into findings with a severity, so they can be
    tested, and check more of the data that's readable while sealed. Use
    the bq40z50 protection and permanent fail defaults as thresholds where
    there is one.
    
    New checks:
    
    - Decoded Safety/PF status, and Safety/PF alerts about to trip
    - Cell capacity imbalance from per cell QMax (QIM threshold 10%)
    - Cell resistance imbalance
    - Lifetime cell balancing time difference (CB threshold 40h)
    - Deep discharge, CUV and other safety events with the cycle of the
      last one, over-temperature and short-circuit in charge events
    - Gauge watchdog resets
    - Gauge learning: Capacity never or not recently re-learned, Impedance
      Track disabled, condition cycle requested, MaxError above 10%
    - Capacity fading faster than 8% per 100 cycles
    - Much time in high temperature ranges or above 90% charge
    
    Changes to existing checks:
    
    - Use the StateOfHealth FCC for capacity retention, which the gauge
      simulates at 25C and typical load, instead of the runtime FCC.
    - The gauge also sets TCA on normal charge termination and TDA when
      nearly empty, so don't warn about them then.
    - Cells diverge naturally when nearly empty, so like the gauge, only
      check the current voltage imbalance above 3.5V. Only note the
      historical maximum delta above 300mV.
    - Not charging to full is informational, it's expected with a charge
      limit.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    9070cf5 View commit details
    Browse the repository at this point in the history
  9. --smartbattery: Show charge temperature ranges when unsealed

    ChargingStatus and LifeTime Data Blocks 6-12 refer to the charge
    temperature ranges (UT, LT, STL, RT, STH, HT, OT), but the thresholds
    between them are configured per pack in data flash. With TI's defaults
    the pack would report HT at 35C, but ours report STL, so they must be
    configured differently.
    
    When unsealed, read them through DataFlashAccess: block write the
    address to ManufacturerBlockAccess (0x44), then read 0x44. Only the
    address may be sent, further bytes would be written to data flash.
    
    The layout differs between revisions, tell them apart by the DAStatus2
    length:
    
    - R3 (16 bytes): 0x4DC2, T1-T6 and one hysteresis
    - R4 (24 bytes): 0x4F03, T1-T6 and one hysteresis per threshold
    
    R2 stores them in different units and isn't supported.
    
    A failure to read them is logged and doesn't fail the rest.
    
    Not tested on hardware yet, needs the unseal key.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    f516643 View commit details
    Browse the repository at this point in the history
  10. --smartbattery: Check that unsealing worked

    The gauge doesn't report a wrong unseal key, it just stays sealed.
    Since most data is readable while sealed now, everything else
    succeeded and only the data flash read failed, with the response of
    the EC's OperationStatus read still in ManufacturerBlockAccess.
    
    After sending the key, read OperationStatus and check that the
    security mode isn't SEALED anymore. Try twice, because the EC's own
    ManufacturerAccess writes can land between the two key words.
    Otherwise fail with a hint about the word order, without printing the
    key.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    191cc93 View commit details
    Browse the repository at this point in the history
  11. --smartbattery: Read temperature ranges from the R3 address

    Our packs report DAStatus2 with 24 bytes like the R4 TRM, so the
    temperature ranges were read from R4's data flash address 0x4F03. But
    FW 03.09 is an R3 firmware: what came back were R3 Elevated Degrade
    defaults (ERM Voltage Threshold 4000mV, ERM Time Threshold 10000h, ...),
    shown as temperatures over 2000C.
    
    Detect the revision by the firmware major version instead and only
    read the R3 layout at 0x4DC2 (T1-T6 and hysteresis). The R4 TRM doesn't
    say what version R4 firmware reports, so don't guess its address.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    c396ac1 View commit details
    Browse the repository at this point in the history
  12. --smartbattery: Show unused temperature ranges as such

    Our packs set T5 = T6 = 45C, so the RT range is empty. Show it as not
    used instead of "45.0C - 45.0C".
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    a6379c0 View commit details
    Browse the repository at this point in the history
  13. --smartbattery: Label time in ranges with temperature thresholds

    When unsealed, the temperature thresholds are known, so show them next
    to the range names in the time in temperature and charge ranges table,
    e.g. "STL  20-45C". Sealed output is unchanged.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    028fef0 View commit details
    Browse the repository at this point in the history
  14. --smartbattery: Show known temperature ranges while sealed

    The charge temperature thresholds are in data flash, which is only
    readable while unsealed. The EC's battery config only has the outer
    limits (charging_min_c/charging_max_c = T1/T4), not the ones between
    the ranges.
    
    Keep a table of thresholds read from real packs, by manufacturer and
    device name, and show them while sealed, marked as not read from the
    battery. For now only NVT FRANDBAT01: 0, 20, 45, 45, 52, 55C.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    5bdef4e View commit details
    Browse the repository at this point in the history
  15. --smartbattery: Check time above 45C using the temperature ranges

    The high temperature check counted the HT and OT rows of the time in
    ranges table. What they mean depends on the pack: with TI's defaults HT
    starts at 30C, on FRANDBAT01 at 52C, so time at 45-52C (STH) didn't
    count.
    
    When the thresholds are known (unsealed, or a known pack), count the
    ranges that start at 45C or above instead. Our packs reduce charging
    above 45C and the EC doesn't start charging above 45C on most packs.
    Otherwise keep counting HT and OT.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    5ea441b View commit details
    Browse the repository at this point in the history
  16. --smartbattery: Add known temperature ranges of ATC FRANEDA

    Read from a sakura pack (FW 03.09) while unsealed:
    0, 10, 25, 35, 45, 60C, hysteresis 0C.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    7645a62 View commit details
    Browse the repository at this point in the history
  17. --smartbattery: Add known temperature ranges of more packs

    Read while unsealed, all FW 03.09:
    
    - NVT FRANGWAT01:       0, 20, 45, 45, 45, 55C, hysteresis 1C
    - NVT Framework Laptop: 0, 20, 45, 45, 45, 55C, hysteresis 1C
    - ATC FRANDZG:          0, 10, 10, 45, 60, 60C, hysteresis 0C
    
    T1 and T4 match charging_min_c and charging_max_c in the EC's
    battery configs.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    c2699d8 View commit details
    Browse the repository at this point in the history
  18. --smartbattery: Name known packs by capacity

    Device names don't say which battery it is, so add the capacity to
    each entry's comment.
    
    Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
    JohnAZoidberg and claude committed Dec 1, 2026
    Configuration menu
    Copy the full SHA
    c658788 View commit details
    Browse the repository at this point in the history
Loading