No description
Find a file
2023-01-08 19:13:49 +01:00
do_not_charge Initial git import of project 2023-01-08 18:59:16 +01:00
ectool Initial git import of project 2023-01-08 18:59:16 +01:00
pixelbook-bin.tar.bz2 Initial git import of project 2023-01-08 18:59:16 +01:00
README.md more README doc 2023-01-08 19:13:49 +01:00

Pixelbook Charge Control

Goal

This is a small project I hacked together to preserve the battery of a Pixelbook running vanilla Linux (in my case Debian).

What I want to achieve is that the battery is not constantly being charged to and held at 100%, which will quickly destroy the battery.

Implementation

The Pixelbook ChromeOS Linux runtime contains a tool called "ectool" which can control the charge control code embedded in the EC. Newer EC version also allow for a "battery sustainer" pretty much implementing what I want but the Pixelbook (aka Eve) EC is too old to use this.

So I came up with a bash script that can run in the background.

For it to work you need the "ectool" in Linux. I tried to compile the ectool from source under Debian but failed. So I took the alternative path and used teh ChromeOS binary. But this will also not run diretcly under normal Linux due to libc version conflicts. So I copied all necessary files one by one and created a subdir that one can chroot into to execute the ectool:

# tar tvf pixelbook-bin.tar.bz2 
drwxr-xr-x root/root         0 2022-11-14 06:19 pixelbook-bin/
drwxr-xr-x root/root         0 2022-11-14 06:40 pixelbook-bin/sbin/
-rwxr-xr-x root/root   1035536 2022-11-14 06:34 pixelbook-bin/sbin/ldconfig
-rwxr-xr-x root/root     38408 2022-11-14 06:40 pixelbook-bin/sbin/ec_sb_firmware_update
-rwxr-xr-x root/root    210192 2022-11-14 06:20 pixelbook-bin/sbin/ectool
-rwx------ root/root      5960 2022-11-14 06:40 pixelbook-bin/sbin/ec_battery_wa
-rwxr-xr-x root/root     10536 2022-11-14 06:40 pixelbook-bin/sbin/ec_parse_panicinfo
drwxr-xr-x root/root         0 2022-11-14 06:37 pixelbook-bin/lib64/
-rwxr-xr-x root/root   2060112 2022-11-14 06:19 pixelbook-bin/lib64/libc-2.33.so
-rwxr-xr-x root/root    222152 2022-11-14 06:19 pixelbook-bin/lib64/ld-2.33.so
-rwxr-xr-x root/root    138360 2022-11-14 06:28 pixelbook-bin/lib64/libpthread.so.0
-rwxr-xr-x root/root     42096 2022-11-14 06:27 pixelbook-bin/lib64/libftdi1.so.2
-rwxr-xr-x root/root    222152 2022-11-14 06:19 pixelbook-bin/lib64/ld-linux-x86-64.so.2
-rwxr-xr-x root/root    112456 2022-11-14 06:37 pixelbook-bin/lib64/libudev.so.1
-rwxr-xr-x root/root     82520 2022-11-14 06:36 pixelbook-bin/lib64/libusb-1.0.so.0
-rwxr-xr-x root/root   2060112 2022-11-14 06:19 pixelbook-bin/lib64/libc.so.6

This needs to be placed into some known folder. I currently put this in the root user's home dir. Then I added ~root/bin/ to teh root user's PATH so that scripts placed in ~root/bin/ will be found.

In ~root/bin/ I first placed a simple script that will chroot exec the real ectool:

#!/bin/sh
chroot /root/pixelbook-bin /sbin/ectool $*

Somewhat crude but works.

The second script in ~root/bin/ is the one controlling the charge control then, currently called do_not_charge. It will by default disable charging under almost any circumstance, except the battery state of charge (SOC) has dropped below 30%. Only then it will allow the charger to become or remain active until SOF is > 80% again. In other words it will stop charging at 80%. The script loops with a 10 second delay to re-evaluate. I run it in a root shell from terminal, which can look like this:

# do_not_charge
on AC
current=0
charger state OK, idling...
0 0

This should be kept running all the time then.

With this I still get more than enough charge in the Pixelbook for all my tasks but on the other hand prevent the battery from premature aging. Each charge cycle means wear to the battery.

Please note that all this of course only works as long as the operating system is running. Each time power is disconnected and reconnected the EC reset the charge logic. So if the laptop is in suspend and you disconnect and reconnect the charger it will again charge to 100% no matter what.

Enjoy! Feedback welcome.

Outlook

Running this as a shell script with root priviledges is probably not teh greatest idea, but right it is a 'works for me' approach. The Pixelbook has some more features I would also like to make more use of, like a light sensor and LCD/keyboard backlight control. In ChromeOS this really worked super nicely, almost always the right backlight based on the light sensor readings. In Linux and I use GNOME the keyboard backlight can not be controlled by default at all (see here: https://www.dpin.de/nf/google-pixelbook-eve-plain-linux/ ) and the automatic LCD brightness control is just horrible, too big steps and no way to control the brightness vs. ambient light thresholds. This makes no sense to me, it just results in awkward brightness settings and too abrupt changes, very distracting and sometimes even unusable.

So maybe some fine day I need to dig into either implementing this in something like upwerd (I think this is on control of these things) or write my own little daemon running in the background.