Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add "Fix Battery" Option to Force Battery Health Data Resynchronization After Firmware Restore #687

Open
D33F4ULT opened this issue Oct 13, 2024 · 7 comments

Comments

@D33F4ULT
Copy link

I’d like to request a new feature to be added to the idevicerestore tool. Specifically, I'm looking for a "Fix Battery" option that forces iOS to resynchronize and retrieve fresh battery health data from the Battery Management System (BMS) during or after a firmware restore.

Background:
In tools like 3uTools, there is a useful feature called "Fix Battery" that is commonly used after replacing an iPhone battery. This option forces iOS to fetch accurate battery health information (capacity, cycle count, etc.) from the BMS chip, which can fix incorrect or missing battery health statistics in iOS.

Currently, when replacing an iPhone battery or after a firmware restore, iOS may not automatically refresh the battery health status, leading to inaccurate data being displayed in Settings. This feature is particularly useful in cases where:

  • The battery was recently replaced.
  • Battery health data was corrupted or not displayed properly.

Proposal:
I propose adding a flag (e.g., --fix-battery) in idevicerestore that will:

Force the iPhone to reset and re-read battery health data from the battery’s BMS after a firmware restore.
Potentially clear any cached or outdated battery health data, ensuring iOS retrieves the correct information from the battery.
This feature would be a valuable addition for users dealing with battery replacement and battery health display issues on iPhones. Any insights on the feasibility of this request or recommendations for how it might be implemented in libimobiledevice would be appreciated.

Thank you for your consideration!

@nikias
Copy link
Member

nikias commented Oct 14, 2024

I would add it if knew how it works...

@TheRealBoss
Copy link

TheRealBoss commented Oct 31, 2024

Found this on twitter:

Edit % battery health:

  • Edit: /var/MobileSoftwareUpdate/Hardware/Battery/Library/Preferences/com.apple.batteryhealthdata.plist (% health)
  • Delete: /var/MobileSoftwareUpdate/Hardware/Battery/Library/Preferences/com.apple.batterydata.cyclecount.plist

Might be what you are looking for? I need it aswell.

And restoring contains these lines
_hardware_folder_data_write_file: Attempting to recreate directory /mnt4/Hardware/Battery _hardware_folder_data_write_file: Successfully created directory /mnt4/Hardware/Battery _hardware_folder_data_write_file: Attempting to recreate directory /mnt4/Hardware/Battery/Library creating directory (owner=0 group=0 mode=40700, class=4) /mnt4/Hardware/Battery/Library _hardware_folder_data_write_file: Successfully created directory /mnt4/Hardware/Battery/Library _hardware_folder_data_write_file: Attempting to recreate directory /mnt4/Hardware/Battery/Library/Preferences creating directory (owner=0 group=0 mode=40700, class=4) /mnt4/Hardware/Battery/Library/Preferences _hardware_folder_data_write_file: Successfully created directory /mnt4/Hardware/Battery/Library/Preferences _hardware_folder_data_write_file: Attempting to recreate file /mnt4/Hardware/Battery/Library/Preferences/com.apple.batterydata.kioskmode.plist File /mnt4/Hardware/Battery/Library/Preferences/com.apple.batterydata.kioskmode.plist: wrote out 427 bytes. _hardware_folder_data_write_file: Attempting to recreate file /mnt4/Hardware/Battery/Library/Preferences/com.apple.thermalmonitor.agingcontroller.plist File /mnt4/Hardware/Battery/Library/Preferences/com.apple.thermalmonitor.agingcontroller.plist: wrote out 151 bytes. _hardware_folder_data_write_file: Attempting to recreate file /mnt4/Hardware/Battery/Library/Preferences/com.apple.batterydata.cyclecount.plist File /mnt4/Hardware/Battery/Library/Preferences/com.apple.batterydata.cyclecount.plist: wrote out 16167 bytes. _hardware_folder_data_write_file: Attempting to recreate file /mnt4/Hardware/Battery/Library/Preferences/com.apple.batteryhealthdata.plist File /mnt4/Hardware/Battery/Library/Preferences/com.apple.batteryhealthdata.plist: wrote out 177 bytes. Successfully persisted hardware folder contents

And here is some more info from restore logs when battery fix is enabled in 3uTools:

Unmounting Filesystem
Creating Partition Map
Creating Filesystem
FIXING BATTERY WEALTH
Detecting connection
Found a device with mode: Restore
Detecting ProductType
matching device type through original information
Detected iDevice did not exit the last restore process, try to reboot
Reboot

Then a battery disconnect-reconnect and it finishes it with a normal restore from there.

Battery fixing step takes a couple of minutes. I assume it's reading out some data, modifying it and writing back modified data. But I guess you might assume better. Modified ASR?

@Johnny314
Copy link

did you find anything on that @nikias @TheRealBoss @D33F4ULT

@TheRealBoss
Copy link

JC uses a tool separate from their main program called jcupdate.exe (in tools/jcupdateb folder). It uses libimobiledevice libraries like libplist, libirecovery etc and the .exe itself seems to be modified and made executable version of idevicerestore itself.
It has a few extra arguments, like -b for batteryfix and -i (for password to start the .exe ?!). So you can't really run it without knowing the arguments needed. But since I'm still a novice in disassembling, I still don't know much.

@nikias
Copy link
Member

nikias commented Nov 15, 2024

@TheRealBoss where can I find the tool? Thanks

@TheRealBoss
Copy link

By downloading JC repair tool and using the battery fix tool once. It will then download the tool.

@AiXanadu
Copy link

@nikias @TheRealBoss
The principle is that when it is marked to repair the battery health, if the current operation is CREATE_FILESYSTEM, then exit and re-flash the device. Because the file system is destroyed, the battery data will be rebuilt.
But I think you will have a better way.

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

No branches or pull requests

5 participants