Jump to content
onemanosx

[Guide] Laptop Battery Indicator - The DSDT Patching Horror

Recommended Posts

Disclaimer: This is not meant to be a thorough help guide. In fact, this write up is a simpler way to guide through new hackintoshers without going into details. Read in-depth guide from the established writer Rehabman in his original article here https://github.com/RehabMan/OS-X-ACPI-Battery-Driver.

++++++++++++++++++++++++++++++

Note:

1. If you are using virtualsmc instead of fakesmc, then you will need SMCBatteryManager.kext instead of ACPIBatteryManager.kext.

2. You should also remove voodoobattery kext from your system.

3. If you'd like assistance on how to start, you should at least find all the used byte called in your EmbeddedControl. Read the guide below on how to achieve that.

++++++++++++++++++++++++++++++

New hackintoshers may not realise that Rehabman's repo may already have patches ready for their laptops. This can be easily accessed by going through RH Github Repo here https://github.com/RehabMan/Laptop-DSDT-Patch/tree/master/battery.

 

Various laptop battery patches available in RH Repo using MacIASL

 

1. Download acpibatterymanager kext from RH bitbucket site https://bitbucket.org/RehabMan/os-x-acpi-battery-driver/downloads. Place the kext at Clover/kexts/other folder. Reboot.

2. Download a copy of MacIASL app. The app can be found in "Files" folder of Olarila's image USB stick or simply download a release from HERE

3. Open MacIASL app, click the Patch icon on the top section of the app and scroll to [bat] -->Battery Patches.

Click any model on the left pane and you will also see other laptop models, on the right pane where the patch is also compatible with.

 

Go through each section to see if your laptop model is available.

QO77BCc.png 

If you had gone through all the sections and did not find a match, you are then expected to create your own DSDT patches.

 

How to Start?

 

In this example, we will use a table attached here Sample - DSDT.aml.zip

 

1. Find EC region

 

OperationRegion (ERAM, EmbeddedControl, Zero, 0xFF)
 

1OyHMUE.png 

 

2. In the ERAM field, search for all bytes more than 8. Thus we will find the list below

 

SMD0,   32
MBCT,   16, 
RCAP,   16,
MBC2,   16,  
MBVT,   16, 
RCA2,   16, 
MBV2,   16,
DBAT,   16, 
FRMS,   16, 
FRS2,   16, 
MDCP,   16, 
MBCP,   16,
MBDV,   16, 
RSOC,   8, 
BTMP,   16,
BASN,   16, 
MBDN,   120,
NMON,   16, 
CYCL,   16,
 

3. From the list above, we determine if each integers are being called in the DSDT. Lets look for SMD0 and we will find its not called up in the EC0 region. We will omit this integer from our list.

r7lhmmW.png 

 

4. Next we continue to look for the next integer, MBCT and found its called up down the EC0 region.

BMjgi2D.png 

 

5. For MBC2, we find it is not called up anywhere else. So we can omit this integer.

9lGwAVj.png 

 

Going through all the list, we then find only these integers are being called and in use.

 

MBCT,   16, 
RCAP,   16, 
MBVT,   16, 
DBAT,   16, 
FRMS,   16, 
FRS2,   16, 
MDCP,   16, 
MBCP,   16,
MBDV,   16
 

Fixing 16-bit registers

 

Just use the below code format as an example. For MBCT we are "splitting" 16 bits to two 8 bits. The 8 bit renaming is easier to just use the last three alphabets (or first three. Your choice, really). Just make sure the renames do not start with a decimal but an alphabet instead.

 

So, MBCT will become BCT0 & BCT1. And the resulting format will be as such

 

into device label EC0 code_regex MBCT,\s+16, replace_matched begin BCT0,8,BCT1,8, end;
 

As for RCAP will become CAP0 & CAP1 and the resulting code format will be

 

into device label EC0 code_regex RCAP,\s+16, replace_matched begin CAP0,8,CAP1,8, end;
 

Do the same for all of our 16 bits findings

 

We will finally achieve the below codes for the rest of our findings.

 

into device label EC0 code_regex MBCT,\s+16, replace_matched begin BCT0,8,BCT1,8, end;
into device label EC0 code_regex RCAP,\s+16, replace_matched begin CAP0,8,CAP1,8, end;
into device label EC0 code_regex MBVT,\s+16, replace_matched begin BVT0,8,BVT1,8, end;
into device label EC0 code_regex DBAT,\s+16, replace_matched begin DBA0,8,DBA1,8, end;
into device label EC0 code_regex FRMS,\s+16, replace_matched begin RMS0,8,RMS1,8, end;
into device label EC0 code_regex FRS2,\s+16, replace_matched begin RS20,8,RS21,8, end;
into device label EC0 code_regex MDCP,\s+16, replace_matched begin DCP0,8,DCP1,8, end;
into device label EC0 code_regex MBCP,\s+16, replace_matched begin BCP0,8,BCP1,8, end;
into device label EC0 code_regex MBDV,\s+16, replace_matched begin BDV0,8,BDV1,8, end;
 

Patching DSDT with 16 bit registers

 

Open MacIASL, click the Patch tab and paste the codes in the box

s9S7Cqo.png 

When we hit apply, we will find errors when trying to compile the DSDT. This is expected.

Zn3SY5N.png 

What we need to do next is fix these errors individually.

 

Fixing 16 bit Method

 

Lets look at the first error

Fv1dJDG.png 

Since we had "split" 16 bit FRMS into two 8 bits RMS0 and RMS1,

 

into device label EC0 code_regex FRMS,\s+16, replace_matched begin RMS0,8,RMS1,8, end;
 

we will now need to introduce a standard B1B2 method into our DSDT

 

into method label B1B2 remove_entry;
into definitionblock code_regex . insert
begin
Method (B1B2, 2, NotSerialized) { Return(Or(Arg0, ShiftLeft(Arg1, 8))) }\n
end;
 

1FT3TwG.png 

Next we will manually patch the FRMS error with the code format below

 

B1B2(\_SB.PCI0.LPCB.EC0.RMS0,\_SB.PCI0.LPCB.EC0.RMS1)
 

Before

PgxcqIS.png 

 

After

AQnBNGd.png 

 

Next error also occurs for FRMS

JABnhva.png 

 

This time round we fix the error using the code format below

 

B1B2(^^PCI0.LPCB.EC0.RMS0,^^PCI0.LPCB.EC0.RMS1)
 

After patching

b7b2nJ4.png 

 

Again, for the rest of the 16 bit integers, we will find the codes below to manually fix our errors. (Manually, because I cannot find a solution to automate the tedious process :? )

 

FRMS -> B1B2(\_SB.PCI0.LPCB.EC0.RMS0,\_SB.PCI0.LPCB.EC0.RMS1) 
FRMS -> B1B2(^^PCI0.LPCB.EC0.RMS0,^^PCI0.LPCB.EC0.RMS1)
FRS2 -> B1B2(^^PCI0.LPCB.EC0.RS20,^^PCI0.LPCB.EC0.RS21)
DBAT -> B1B2(\_SB.PCI0.LPCB.EC0.DBA0,\_SB.PCI0.LPCB.EC0.DBA1) 
DBAT -> B1B2(^^PCI0.LPCB.EC0.DBA0,^^PCI0.LPCB.EC0.DBA1)
MDCP -> B1B2(^^PCI0.LPCB.EC0.DCP0,^^PCI0.LPCB.EC0.DCP1)
MBCP -> B1B2(^^PCI0.LPCB.EC0.BCP0,^^PCI0.LPCB.EC0.BCP1)
MBDV -> B1B2(^^PCI0.LPCB.EC0.BDV0,^^PCI0.LPCB.EC0.BDV1)
MBCP -> B1B2(^^PCI0.LPCB.EC0.BCP0,^^PCI0.LPCB.EC0.BCP1)
MBCT -> B1B2(^^PCI0.LPCB.EC0.BCT0,^^PCI0.LPCB.EC0.BCT1)
MBVT -> B1B2(^^PCI0.LPCB.EC0.BVT0,^^PCI0.LPCB.EC0.BVT1)
RCAP -> B1B2(^^PCI0.LPCB.EC0.CAP0,^^PCI0.LPCB.EC0.CAP1)
 

The Final Step

 

Add the below standard codes to our DSDT, press Apply and make sure no error in our compile.

(Note: You may need to change EC0 to H_EC or EC depending on your own DSDT)

 

#utility methods to read/write buffers from/to EC

into method label RE1B parent_label H_EC remove_entry;
into method label RECB parent_label H_EC remove_entry;
into device label EC0 insert
begin
Method (RE1B, 1, NotSerialized)\n
{\n
OperationRegion(ERAM, EmbeddedControl, Arg0, 1)\n
Field(ERAM, ByteAcc, NoLock, Preserve) { BYTE, 8 }\n
Return(BYTE)\n
}\n
Method (RECB, 2, Serialized)\n
{\n
ShiftRight(Arg1, 3, Arg1)\n
Name(TEMP, Buffer(Arg1) { })\n
Add(Arg0, Arg1, Arg1)\n
Store(0, Local0)\n
While (LLess(Arg0, Arg1))\n
{
	Store(RE1B(Arg0), Index(TEMP, Local0))\n
	Increment(Arg0)\n
	Increment(Local0)\n
}\n
Return(TEMP)\n
}\n
end;

into device label EC0 insert
begin
Method (WE1B, 2, NotSerialized)\n
{\n
   OperationRegion(ERAM, EmbeddedControl, Arg0, 1)\n
   Field(ERAM, ByteAcc, NoLock, Preserve) { BYTE, 8 }\n
   Store(Arg1, BYTE)\n
}\n
Method (WECB, 3, Serialized)\n
{\n
   ShiftRight(Arg1, 3, Arg1)\n
   Name(TEMP, Buffer(Arg1) { })\n
   Store(Arg2, TEMP)\n
   Add(Arg0, Arg1, Arg1)\n
   Store(0, Local0)\n
   While (LLess(Arg0, Arg1))\n
   {\n
       WE1B(Arg0, DerefOf(Index(TEMP, Local0)))\n
       Increment(Arg0)\n
       Increment(Local0)\n
   }\n
}\n
end;
 

The DSDT is now ready to be placed in Clover/ACPI/Patched folder. Reboot and see if your hard work paid off.

 

If you face any issues and would like help from others in this community, attach your post with Laptop model and dump files using this app https://www.olarila.com/files/Utils/RunMe.app.zip

 

If you find this guide useful and would like to contribute your successful patch, just make a post with Laptop model details, patch codes and attach an original DSDT.

 

To be continued ...

Share this post


Link to post
Share on other sites

Update 3 Jan 2019

 

Dealing with 32 Bits

 

Dealing with 32 bits is fairly similar to that of 16 bit. Lets say we have

 

BTY0,   32,
BTY1,   32,
 

The standard looking code with look like this

 

into device label H_EC code_regex BTY0,\s+32 replace_matched begin TY00,8,TY01,8,TY02,8,TY03,8 end;
into device label H_EC code_regex BTY1,\s+32 replace_matched begin TY10,8,TY11,8,TY12,8,TY13,8 end;
 

And we will have the fix 32 bit method code which looks similar to this

 

BTY0 - (B1B4(\_SB.PCI0.LPCB.H_EC.TY00,\_SB.PCI0.LPCB.H_EC.TY01,\_SB.PCI0.LPCB.H_EC.TY02,\_SB.PCI0.LPCB.H_EC.TY03), end;
BTY1 - (B1B4(\_SB.PCI0.LPCB.H_EC.TY10,\_SB.PCI0.LPCB.H_EC.TY11,\_SB.PCI0.LPCB.H_EC.TY12,\_SB.PCI0.LPCB.H_EC.TY13), end;
 

And the Standard Code for fixing 32 bit register

 

into method label B1B4 remove_entry;
into definitionblock code_regex . insert
begin
Method (B1B4, 4, NotSerialized)\n
{\n
   Store(Arg3, Local0)\n
   Or(Arg2, ShiftLeft(Local0, 8), Local0)\n
   Or(Arg1, ShiftLeft(Local0, 8), Local0)\n
   Or(Arg0, ShiftLeft(Local0, 8), Local0)\n
   Return(Local0)\n
}\n
end;
 

++++++++++++++++++++++++++++++++++++

 

Fixing Larger than 32 bits

 

I was going through my note for an update to fix integers larger than 32 bit, when I realized RH perhaps has the best explanation laid out.

 

In short, for integers larger than 32 bit, we will need to find each offset values which is the tricky part (HINT: Observe the pattern)

 

We have these 2 values larger than 32 bits

 

Field (ERAM, ByteAcc, Lock, Preserve)
                   {
                       Offset (0x02), <<--Hex
                       PSTD,   8, 
                       Offset (0x18), <<-- HEX
                       SMPR,   8, 
                       SMST,   8, 
                       SMAD,   8, 
                       SMCM,   8, 
                       SMD0,   264, 
                       Offset (0xA0), <<-- HEX
	        BBAR,   136,
 

This is how the offset values are attained

 

Field (ERAM, ByteAcc, Lock, Preserve)
                   {
                       Offset (0x02),  
                       PSTD,   8, 
                       Offset (0x18), <<-->> HEX to DEC -->> //24
                       SMPR,   8, // 24 <<-->> DEC to HEX -->>(0X18)
                       SMST,   8, //24+(8/8) = 25 <<-->> DEC to HEX -->>(0X19)
                       SMAD,   8, // 24+(8/8)+(8/8) = 26 <<-->> DEC to HEX -->>(0X1A)
                       SMCM,   8, //24+(8/8)+(8/8)+(8/8)= 27 <<-->> DEC to HEX -->>(0X1B)
                       SMD0,   264, //24+(8/8)+(8/8)+(8/8)+(8/8) = 28 <<-->> DEC to HEX -->>(0X1C) <<-- 
		Offset (0xA0), //
		BBAR,   136,// (0XA0)

 

From the above, our offset values for SMD0 and BBAR is achieved by a simple calculation. HINT: Unless specified by an Offset directive, the offset of any register is the offset of the previous register + previous register size

 

Next, we will rename SMD0 and BBAR to SMDX and BBAX respectively

 

into device label EC0 code_regex (SMD0,)\s+(264) replace_matched begin SMDX,%2,//%1%2 end;
into device label EC0 code_regex (BBAR,)\s+(136) replace_matched begin BBAX,%2,//%1%2 end;
 

And the fix method code will look similarly as

 

SMD0 -  \_SB.PCI0.LPCB.EC0.RECB(0X1C,264)
BBAR -  \_SB.PCI0.LPCB.EC0.RECB(0XA0,136)

 

That is all on fixing larger than 32 bit integers.

 

Are you sure the offset values are derived that way?

 

If you are not yet convinced on how I attained the offset values, you may compare the below calculation and its result with RH's example. I hope its useful for some of our readers.

 

Field (ECF2, ByteAcc, Lock, Preserve)
  {
      Offset (0x10), 
      BDN0,   56,     // (0x10)
      Offset (0x18),
      BME0,   8, // (0x18) 
      Offset (0x20),// <<—- Hex to decimal is 32
      BMN0,   32,     // 32 (0x20) 
      BMN2,   8,     // 32+(32/8)=36 //result in Dec and convert to Hex —>> (0x24)
      BMN4,   88,    //32+(32/8)+(8/8) = 37 //result in Dec and convert to Hex —>>(0x25)
      BCT0,   128,     //!! 32+(32/8)+(8/8)+(88/8) = 48 //result in Dec and convert to Hex —>>(0x30)
      BDN1,   56,     //!! 32+(32/8)+(8/8)+(88/8)+(128/8) = 64 //result in Dec and convert to Hex —>>(0x40)
      Offset (0x48),
      BME1,   8, //(0x48)
      Offset (0x50),
      BMN1,   32,     // (0x50)>> <<—- Hex to decimal is 80 
      BMN3,   8,     // 80+(32/8) = 84 //result in Dec and convert to Hex —>>(0x54)
      BMN5,   88,     // 80+(32/8)+(8/8) = 85 //result in Dec and convert to Hex —>>(0x55)
      BCT1,   128,     //!! 80+(32/8)+(8/8)+(88/8) = 96 //result in Dec and convert to Hex —>>(0x60)

 

Share this post


Link to post
Share on other sites

This patch is needed for showing battery percentage ?

On my laptop battery percentage works without this patch. Should I gain anything by using it ?

Share this post


Link to post
Share on other sites

Ok.

Just thought that it would be something like more accurate for example. And it seemed stranged that mine is working without any battery patch.

Share this post


Link to post
Share on other sites

And it seemed stranged that mine is working without any battery patch.

There is no harm double checking against your DSDT and the guide though.

Share this post


Link to post
Share on other sites

There is no harm double checking against your DSDT and the guide though.

That's the strange part.

I don't use dsdt , I use hotpatch with no battery patch at all.

Share this post


Link to post
Share on other sites

I don't use dsdt , I use hotpatch with no battery patch at all.

When you dont specify DSDT file in Clover/ACPI/Patched, Clover automatically uses your native DSDT for use.

Share this post


Link to post
Share on other sites

Oh I see.


Your guides are great.

Wish you make a guide for acpi hotpatching , too. I would like a bit of a help with mine.

Share this post


Link to post
Share on other sites

Your guides are great.

Wish you make a guide for acpi hot patching , too. I would like a bit of a help with mine.

Thank you. That's very heartwarming to hear :D


Its too wide of a topic to talk about clover's hot patching in one single post and [ref]MaLd0n[/ref] is the best man for it. :mrgreen:

Share this post


Link to post
Share on other sites

[ref]mathewgx[/ref], The reason you dont require any patching for battery status is probably due to all the 8 bits count only in your embedded field values. ;)

Share this post


Link to post
Share on other sites

I don't have any clue about what you said , but you know better.

I am still learning, the reason I know is because I opened up your DSDT from the previous post where you uploaded your send_me file ;)

Share this post


Link to post
Share on other sites

Dear why don't you guys make 2 or 3 video tutorial along with verbal instructions this will educate more instead of pasting above readings will not educate until you will guide exact steps in video.

Share this post


Link to post
Share on other sites

thank you it is working now perfect so I need to make only sleep wake to work and my laptop will be fully functional as hackintosh

Share this post


Link to post
Share on other sites

[ref]ziomalex[/ref], Please upload new send me files for checking. Thanks.


Sleep wake function may or may not work in hackintosh. Its a known issue, I think.

Share this post


Link to post
Share on other sites

ok good to know. I have been trying to make it work but there was no luck, I have been trying even to update to Mojave but not working after boot I have backlighted black screen whatever platform id I choose so I stick whith high Sierra and at least is 98% functional.

Thank you again for helping with battery

Share this post


Link to post
Share on other sites

[ref]ziomalex[/ref], No problem.


Update Status for : Dell Inspiron 5577 Battery Status



30vKwTo.png

795198174_ScreenShot2019-01-13at12_49_18PM.thumb.png.3194d437a57528fc828cad351a808bc7.png

Edited by Guest

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...