Contribute
Register

<< Solved >> OpenCore battery patch

Joined
Mar 8, 2017
Messages
721
Motherboard
Lenovo ThinkPad T480s (OpenCore)
CPU
i7-8550U
Graphics
UHD 620, 2560x1440
Mobile Phone
  1. Android
Hello, guys!

// Comment:

If you need any help, just post your native DSDT along with an existing rehabman patch, if it exists. Otherwise, I'll try to patch it from scratch. If you want me to implement it properly, post your EFI folder aswell.

I will help as many people as possible!

My solution was: https://www.tonymacx86.com/threads/opencore-battery-patch.295289/post-2101803

I am working on getting my laptop up and running with OpenCore, switching from clover right now... What works: Audio, USB, USBC (Data + External Monitors), Trackpad, Touchscreen, WiFi & BT. What doesn't: My DAMN battery indicator...

// Note: DO NOT follow this immense amount of GARBAGE I did below, it will only screw your system up. Scroll down further, I have this solved, use the other approach instead. (https://www.tonymacx86.com/threads/opencore-battery-patch.295289/post-2101803)

This patch works 100% for my laptop (with clover, patching DSDT): https://github.com/RehabMan/Laptop-DSDT-Patch/blob/master/battery/battery_Razer-Blade-2014.txt

I tried my BEST to get this working in OpenCore. What I came up with (step by step, so you get my train of thought right now):
* Renamed eisaID PNP0C0A to PNP0C99 (to disable DSDT BAT0 hooking from SMCBattery)
* Renamed Device BAT0 to BATX (to don't have overlapping names in same scope)
* Renamed eisaID PNP0C0D to PNP0C98 (to disable DSDT LID0 hooking from SMCBattery)
* Renamed Device LID0 to LIDX (to don't have overlapping names in same scope)
* Renamed eisaID PNP0C09 to PNP0C00 (to disable DSDT EC0 hooking from AppleACPIEC)

Then, I re-defined those devices in SSDTs. The SSDT-EC contains EC, LID0 and BAT0, copied from the Clover DSDT which got patched with the above patch from RehabMan. I added the External lines, which should point to the correct resources in main DSDT, at least I hope I did it correctly.

Now - what's the outcome? I actually got a battery indicator! And it goes down! But - it just does not go up or show the charging bolt symbol, so it's partially corruped. I have no further ideas, since my knowledge is very limited in the ASL language.

Attached: My OC EFI, my IOREG and my origin from clover - already run through iasl decompile.

Please - if someone has any ideas - help me out here, I would be so happy if open core would finally be complete - I'm pretty close! :)
Thank you lots!
 

Attachments

  • EFI.zip
    2.2 MB · Views: 438
  • MacBook Pro.ioreg
    11.2 MB · Views: 138
  • origin.zip
    220.9 KB · Views: 139
Last edited:
Joined
Mar 8, 2017
Messages
721
Motherboard
Lenovo ThinkPad T480s (OpenCore)
CPU
i7-8550U
Graphics
UHD 620, 2560x1440
Mobile Phone
  1. Android
#push

Any ideas? And yes... I know. Renaming eisaids to some random stuff that just does not exist in my DSDT is no good idea - but I don't know how else to disable the binding of drivers.
 
Joined
Mar 8, 2017
Messages
721
Motherboard
Lenovo ThinkPad T480s (OpenCore)
CPU
i7-8550U
Graphics
UHD 620, 2560x1440
Mobile Phone
  1. Android
After a full day of trying to understand ASL, I think I now may have understood what garbage I tried before. In this process, I came up with another idea on how to implement this patch. I don't get any errors at booting what so ever, but the battery also does not show up. Good and bad at the same moment, right?

The way you "override" a method f.e. is (afaik) you rename the existing one in DSDT to something else, f.e. _BIF to XBIF, then you re-implement it in the SSDT in correct scope. That's what I did. My steps were the following:

* Rename EC0 to EC (because if I don't do this, NOTHING works, so I'll keep that, no matter what OC docs say, also I need it for battery management, can't just use a fake EC)
* Rename _BIF (Battery Information) to XBIF
* Rename _BST (Battery Status) to XBST

Then, I wrote the attached SSDT. The EC has a (as far as I understood) Memory Map, which uses the registers in EmbeddedController, starting at 0x0 with 0xFF bytes length. It is defined in the DSDT already, I didn't know how to deactivate it, so I just re-defined it in there. I think the OperationRegion can be called as often as you want to, and the Field just overrides memory location - so the last one wins, which should be my implementation (I hope that's not completely wrong). Methods RE1B and RECB have just been added, _BIF and _BST were re-implemented with the correct code. Also, B1B2 has been added at root scope, just like the patch did. I only changed what the patch would change. Please read it.

Sadly, with the SMCBatteryManager injected, no battery shows up...
Has anyone got an idea on why this may be the case? This felt like the right way to solve this, but I might still be on a completely wrong path.

// Edit: Oh, it seems like there are some errors during boot. I will look at this after getting some sleep.
 

Attachments

  • SSDT-BATT.aml
    1.6 KB · Views: 320
Last edited:
Joined
Mar 8, 2017
Messages
721
Motherboard
Lenovo ThinkPad T480s (OpenCore)
CPU
i7-8550U
Graphics
UHD 620, 2560x1440
Mobile Phone
  1. Android
I think that my BAT0 Device patches work, but the EC OperationRegion patch just does not work. I've attached a screenshot of the patch needed to be done, left is what's needed, right is what I currently have in DSDT. Have no idea how to override this :(
 

Attachments

  • Screenshot 2020-04-11 at 19.17.26.png
    Screenshot 2020-04-11 at 19.17.26.png
    254.1 KB · Views: 474
Joined
Mar 8, 2017
Messages
721
Motherboard
Lenovo ThinkPad T480s (OpenCore)
CPU
i7-8550U
Graphics
UHD 620, 2560x1440
Mobile Phone
  1. Android
I got it working! :D

What helped me to understand the functionallity of operation regions is the following document: https://acpica.org/sites/acpica/files/asl_tutorial_v20190625.pdf

With this, I saw why just overriding the whole EmbeddedControl's memory is a very bad idea. I now made the needed variables in the right address-areas, just like the patch did in the DSDT from clover. I made two regions:

ERM2 (EC RAM 2) - Starting at 0x90 with 0xA entries - all the IFXX

For the second one I thought: 0x90 plus 0xA plus 0x8 (BIF5->8) = 0xA2
ERM3 (EC RAM 3) - Starting at 0xA2 with 0x8 entries - all the STXX

Those two regions now provided the correct variables in the EC's scope. Copied over RE1B and RECB from patch, re-defined _BIF by renaming to XBIF and re-implementing in SSDT, same for _BST. The method-bodies I also just copied from the patched clover DSDT. Method B1B2 also got duplicated over into root scope.

And guess what - I rebooted and it worked! Charging, going up and down. You won't believe me how relieved I feel right now... I hope that I did this correctly - time will show if there are any bugs. I'd love to hear improvement ideas aswell, would love to learn more about ASL.

I attached the now working SSDT for others to look at or maybe even use for a Razer Blade 2018 Advanced Model. Since bios updates may change the original region, you'll have to alter it a bit.
 

Attachments

  • SSDT-BATT.aml
    1.5 KB · Views: 872
Joined
Mar 8, 2017
Messages
721
Motherboard
Lenovo ThinkPad T480s (OpenCore)
CPU
i7-8550U
Graphics
UHD 620, 2560x1440
Mobile Phone
  1. Android
@Guiltys33d

Yes, I am running Catalina and I'm even thinking about installing the latest update. But this will work on previous versions aswell, if you use the right battery kext.

You know, I would like to make a guide (and I will), but you need something to start off: A working battery patch for MaciASL's patch window. I am by far not good enough to write one up myself.

All I learned in the last few days was how to translate that "hardcoded" DSDT patch for Clover into an SSDT one for OpenCore.
 
Joined
Dec 8, 2011
Messages
546
Motherboard
Razer Blade 15 - Clover
CPU
i7-8750H
Graphics
UHD 630/GTX 1060 - 1920x1080
Mac
  1. MacBook Pro
Mobile Phone
  1. Android
@Guiltys33d

Yes, I am running Catalina and I'm even thinking about installing the latest update. But this will work on previous versions aswell, if you use the right battery kext.

You know, I would like to make a guide (and I will), but you need something to start off: A working battery patch for MaciASL's patch window. I am by far not good enough to write one up myself.

All I learned in the last few days was how to translate that "hardcoded" DSDT patch for Clover into an SSDT one for OpenCore.


Can you explain exactly what you did to make this SSDT by any chance? I tried using it as is in a 2018 Razerblade Advanced, but it didn't work. Trying to figure out what exactly I need to rename to make it work properly
 
Joined
Mar 8, 2017
Messages
721
Motherboard
Lenovo ThinkPad T480s (OpenCore)
CPU
i7-8550U
Graphics
UHD 620, 2560x1440
Mobile Phone
  1. Android
@vettz500

Oh, so you do own a Razer Blade 2018 Advanced Model aswell? Nice!
I am going to try to help you out, just please do me these favors:

1. Question: When using clover, does RehabMan's DSDT patch work out for you?
2: Question: Have you also applied my specified renames in OC's config?
3: Please provide your extracted DSDT for me to have a look at - I can check whether you need to alter anything. Please also provide your config.plist, so I can check if you implemented it correctly.
 
Joined
Dec 8, 2011
Messages
546
Motherboard
Razer Blade 15 - Clover
CPU
i7-8750H
Graphics
UHD 630/GTX 1060 - 1920x1080
Mac
  1. MacBook Pro
Mobile Phone
  1. Android
@vettz500

Oh, so you do own a Razer Blade 2018 Advanced Model aswell? Nice!
I am going to try to help you out, just please do me these favors:

1. Question: When using clover, does RehabMan's DSDT patch work out for you?
2: Question: Have you also applied my specified renames in OC's config?
3: Please provide your extracted DSDT for me to have a look at - I can check whether you need to alter anything. Please also provide your config.plist, so I can check if you implemented it correctly.
Thanks for the quick response!

1. Yes RehabMan's DSDT Patch worked for me when I was using Clover.
2. Yes I have applied the specified renames in OC's config.
3. Attached
4. Also attached
 

Attachments

  • DSDT.aml
    255.7 KB · Views: 194
  • OC.zip
    1.8 MB · Views: 338
Top