DangerousBatteryChargerExperiments » History » Revision 1

Revision 1/12 | Next »
Denis 'GNUtoo' Carikli, 12/20/2019 02:23 AM


Messing with batteries is dangerous

Messing with battery charging is very dangerous:
  • Batteries regularly explode in laptops and smartphones. The press often talks about that.
  • Exploding batteries can cause dangerous fires.
  • Messing with charging values can really cause batteries to explode or take fire.

So really make sure you know what you're doing if you mess with that.

This is not the usual warning that is there just because of legal requirements, in order to prevent potential lawsuits, and that tells you that the documentation may eat your cat.

Batteries issues are real.

See The Wikipedia page on the Galaxy Note 6 for a famous examples of a battery issue.

Here the cause was due to the fact that the battery was non-removable and that the case didn't have enough extra space for the battery.

Other warnings

You could also break your phone or have other issues if you mess up with battery charging values, but given that battery can explode or take fire the other issues are probably usually very minor compared to that.

Disabling the charge

The max77693 driver in the Replicant 6 kernel has a "function to enable and disable charge":

As this driver is used on a Galaxy SIII we tried to disable the charge by setting the last bit of the MAX77693_CHG_REG_CHG_CNFG_00 to 0.

 i2cget -f 17 0x66 0xB7                                                                                                  
i2cget: WARNING! This program can confuse your I2C bus
Continue? [y/N] y
# i2cset -f 17 0x66 0xB7 0x4                                                                                                                    
i2cset: WARNING! This program can confuse your I2C bus
Continue? [y/N] y

This stopped the charge:

# grep POWER_SUPPLY_STATUS /sys/class/power_supply/battery/uevent                                                       

We did that while the driver as it already disables the charger register protection.

However we didn't check if the driver could also be accessing that register while we were trying the i2cset command.

If the driver also access and changes that register, we could have a race condition where we read a value (0x05) and then the kernel does some stuff and changes it to 0xf5 for instance and then userspace would change it back to 0x04 messing up things.

So really use with caution.

We also didn't get any review of what we were doing here.

How to properly disable charging

In order to minimize the risk it would be best to have the upstream kernel review process involved.

To do that, first you need your device to be ported to Replicant 9. The Galaxy SIII already boots under Replicant 9 and uses a kernel that is very closely based on upstream.

You can then take advantage of the Linux review process to be extra sure that you didn't mess up. You can send a patch that disable charging in the max77693_charger driver, enabling to disable charging through a sysfs node.

This way userspace could easily stop the charging process.

Note that upstream still requires you to test (and probably understand) the code you are writing, so you still need to know what you are doing.

If you don't know what you are doing, try instead to find someone who does and who is willing to do it for you.

Updated by Denis 'GNUtoo' Carikli almost 4 years ago · 1 revisions

Also available in: PDF HTML TXT