Page 1 of 10

[Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 01 Jan 2019, 04:01
by onemanosx
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 [External Link Removed for Guests].

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

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 [External Link Removed for Guests].


Various laptop battery patches available in RH Repo using MacIASL

1. Download acpibatterymanager kext from RH bitbucket site [External Link Removed for Guests]. 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 [External Link Removed for Guests]
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.


Image


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

Code: [Local Link Removed for Guests]

OperationRegion (ERAM, EmbeddedControl, Zero, 0xFF)

Image



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

Code: [Local Link Removed for Guests]

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.


Image


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


Image


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


Image


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

Code: [Local Link Removed for Guests]

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

Code: [Local Link Removed for Guests]

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

Code: [Local Link Removed for Guests]

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.

Code: [Local Link Removed for Guests]

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


Image


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


Image


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


Fixing 16 bit Method


Lets look at the first error


Image


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

Code: [Local Link Removed for Guests]

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

Code: [Local Link Removed for Guests]

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

Image


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

Code: [Local Link Removed for Guests]

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


Image


After

Image


Next error also occurs for FRMS


Image


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

Code: [Local Link Removed for Guests]

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

After patching


Image



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 :? )

Code: [Local Link Removed for Guests]

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)

Code: [Local Link Removed for Guests]

#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 [Local Link Removed for Guests]


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 ....

[Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 01 Jan 2019, 04:02
by onemanosx
Update 3 Jan 2019

Dealing with 32 Bits

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

Code: [Local Link Removed for Guests]

BTY0,   32,
BTY1,   32,

The standard looking code with look like this

Code: [Local Link Removed for Guests]

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

Code: [Local Link Removed for Guests]

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

Code: [Local Link Removed for Guests]

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

Code: [Local Link Removed for Guests]


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

Code: [Local Link Removed for Guests]

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

Code: [Local Link Removed for Guests]

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

Code: [Local Link Removed for Guests]

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.

Code: [Local Link Removed for Guests]

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)


[Help Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 01 Jan 2019, 04:09
by erroruser
:guitar :guitar :guitar :guitar

[Help Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 01 Jan 2019, 05:12
by Sampath007
:superman :superman
Marvelous

[Help Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 01 Jan 2019, 06:11
by mathewgx
This patch is needed for showing battery percentage ?
On my laptop battery percentage works without this patch. Should I gain anything by using it ?

[Help Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 01 Jan 2019, 07:09
by onemanosx
mathewgx, why would you need to patch for something that is working? :lol:

No. No benefits at all 8-)

[Help Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 01 Jan 2019, 13:05
by mathewgx
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.

[Help Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 01 Jan 2019, 13:11
by onemanosx
[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]
01 Jan 2019, 13:05
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.

[Help Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 01 Jan 2019, 14:45
by MaLd0n
:guitar :cap

[Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 01 Jan 2019, 15:33
by mathewgx
[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]
01 Jan 2019, 13:11
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.

[Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 01 Jan 2019, 15:36
by onemanosx
[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]
01 Jan 2019, 15:33
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.

[Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 01 Jan 2019, 15:53
by mathewgx
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.

[Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 02 Jan 2019, 04:15
by onemanosx
[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]
01 Jan 2019, 15:53
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 MaLd0n is the best man for it. :mrgreen:

[Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 02 Jan 2019, 11:19
by onemanosx
mathewgx, 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. ;)

[Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 02 Jan 2019, 13:32
by mathewgx
I don't have any clue about what you said , but you know better.

[Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 02 Jan 2019, 23:39
by onemanosx
[Local Link Removed for Guests] wrote: [Local Link Removed for Guests]
02 Jan 2019, 13:32
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 ;)

[Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 05 Jan 2019, 01:40
by onemanosx
sarakabir,

Check for battery fix.
sarakabir BATFIX - DSDT.aml.zip
Download kext here [External Link Removed for Guests]

[Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 05 Jan 2019, 07:24
by bilal1947
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.

[Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 13 Jan 2019, 02:32
by onemanosx
ziomalex, check battery patch.
ZIOMALEX- BATTERY DSDT.aml.zip

[Guide] Laptop Battery Indicator - The DSDT Patching Horror

Posted: 13 Jan 2019, 03:29
by ziomalex
do I need to rename it? as I have DSDT.aml patched by mald0n in patched folder