Controlling the Battery on the Framework

A plot with capacity as a green line, which has quite a few major jumps but generally a downward slope from 160 down to 80 and then up again to perhaps 120.  There's also a lot of purple dots corresponding to charging levels besteen 100 and 0.

Charge (purple) and estimated capacity (green) of the large battery in the later life of my old Lenovo X240. The deep dips in capacity were when I used a smaller battery for a while. The main message is: For a long and healthy life of your battery, be nice to it and only rarely charge to 100%[1].

The figure above shows: If you charge a (notebook) battery to only about 80% unless you have a strong reason to top it up, and don't discharge it too deeply in daily operations, it can keep a good part of its capacity over thousands of cycles.

Thus, when I got my new Framework, among the first things I wanted to figure out is how to control the charging policy. I was delighted to see that Framework's UEFI firmware already has a menu entry to set a charge limit.

However, that was not good enough for me, because occasionally I do want to go to 100% for some extra run time (and because I strongly believe that going to 100% is less damaging than going below 20%[2]). I certainly do not want to reboot my machine into the UEFI menu just to request some extra runtime. Thus, I need a userspace tool.

What I used on the X240 to configure charging limits from within a running machine, tlp, employs Thinkpad-specific mechanisms to talk to its specific embedded controller. Neither is present on the Framework.

Instead, on the Framework there is a program called ectool (ec as in embedded controller), which somehow derives from something on ChromeOS. Regrettably, I have not found it in any Debian package. The ectool binary that is in coreboot-utils is a different thing, and while it could probably be used to hack together similar functionality, it would be a lot more effort.

So, I'm afraid you have to build from source. This would work somewhat like this (cave curlbashware; poke me and I'll think about properly packaging it):

sudo apt install cmake build-essential
git clone https://github.com/DHowett/ectool.git
cd ectool
cmake
make
sudo cp src/ectool /usr/local/bin/

Setting the charging limit is then simply a matter of calling ectool fwchargelimit <percent>.

However, back in the Thinkpad years, when this was a bit more complicated and involved two batteries, I wrote a small wrapper script that lets you quickly switch between travel (topping up), normal (charge to 80%), and nocharge (e.g., when running from an external battery). I liked the <cough> UX of this, and so I ported the script to ectool's facilities. The result is this:

#!/bin/sh
if id | grep root 2>&1 > /dev/null
then
        true
else
        exec sudo $0 $*
fi

usage() {
        echo "Usage: $0 [show|travel|normal|nocharge]"
        exit 1
}

case "$1" in
show)
        ectool fwchargelimit
        ;;
travel)
        ectool fwchargelimit 95
        ;;
normal)
        ectool fwchargelimit 80
        ;;
nocharge)
        ectool fwchargelimit 10
        ;;
*)
        usage
        ;;
esac

I have this as chargeconfig on my path.

[1]The big jump up around 2022/2023 must have been when I replaced the hardware with a copy I got from eBay and that thing came with another big battery. I had completely forgotten about it, which somewhat weakens my story of the benefits of being nice to the battery. But it does not weaken it much; the purple dots in the plot above show that the battery went through many cycles, and you can see that it still had about half the capacity after eight years (I only started taking this data after two years or so). On that box, even half the capacity on the big battery still meant perhaps 10 hours of a reasonable load mix.
[2]By the way, an 80% charge corresponds to again more than 10 hours of light duty (such as writing plog posts) on a new 13th Gen Framework 13.
Kategorie: edv

Letzte Ergänzungen