Contribute
Register

[Guide] How to patch DSDT for working battery status

So I'm working to fix my DSDT for battery status.
Following the guide I've found 3 items larger than 8 bits and which are accessed.
Here they are:

- VER, 24, [line 3363] = 24 bits fix (3x8 bits)
- Accessed at line 18318, method WMAB: Store (VER, Local0)
- Fixing with these 3 patches:
Code:
into device label EC code_regex VER,\s+24, replace_matched begin ER00,8,ER01,8,ER02,8, end;

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

into method label WMAB code_regex \(VER, replaceall_matched begin B1B3(ER00,ER01,ER02), end;
- Result:
Code:
[line 3363] ER00,8,ER01,8,ER02,8,
[line 18318] Store (B1B3(ER00,ER01,ER02), Local0)

- CBT, 16, [line 3518] = 16 bits fix (2x8 bits)
- Accessed at line 17741, method WMBB: S_DW (Local0, 0x14, CBT)
- Fixing with these 3 patches:
Code:
into device label EC code_regex CBT,\s+16, replace_matched begin BT00,8,BT01,8, end;

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

into method label WMBB code_regex \CBT\) replaceall_matched begin B1B2(BT00,BT01)) end;
- Result:
Code:
[line 3518] BT00,8,BT01,8,
[line 17741] S_DW (Local0, 0x14, B1B2(BT00,BT01))

- BMFG, 72, [line 3519] = 72 bits buffer field (need help here)
- Accessed at line 4406, method XBIF: Store (ToString (BMFG, Ones), Index (PBIF, 0x09))
- I only have this 1 patch yet:
Code:
into device label EC code_regex (BMFG,)\s+(72) replace_matched begin MFGX,%2,//%1%2 end;
- Note: I can't figure out the offset which this field is placed. Here's a screenshot from the code: http://i.imgur.com/sa0kz19.png

Can someone help me with this? This is my first try patching the DSDT, if something is wrong please tell me.

Offset calculation for BMFG:
Code:
                        Offset (0x83),
                        BTY,    8, //83
                        BDCH,   8, //84
                        BDCL,   8, //85
                        BFCH,   8, //86
                        BFCL,   8, //87
                        BDVH,   8, //88
                        BDVL,   8, //89
                        BWCH,   8, //8a
                        BWCL,   8, //8b
                        BLCH,   8, //8c
                        BLCL,   8, //8d
                        BCG1,   16, //8e
                        BCG2,   16, //90
                        BSNH,   8, //92
                        BSNL,   8, //93
                        BPRH,   8, //94
                        BPRL,   8, //95
                        BRCH,   8, //96
                        BRCL,   8, //97
                        BPVH,   8, //98
                        BPVL,   8, //99
                        BTP,    16, //9a
                        CBT,    16, //9c
                        BMFG,   72, //9e

Also, is it possible to use both ACPI hotpatches and DSDT static patches? My HD4400 config.plist from RehabMan's repo has some hotpatches that seems to be working fine, I can boot my Hackintosh with them and also with the unmodified DSDT.aml.

Yes.
Since entries in config.plist/ACPI/DSDT/Patches apply to ACPI/patched/DSDT.aml, there is no issue...
 
Offset calculation for BMFG:
Code:
                        Offset (0x83),
                        BTY,    8, //83
                        BDCH,   8, //84
                        BDCL,   8, //85
                        BFCH,   8, //86
                        BFCL,   8, //87
                        BDVH,   8, //88
                        BDVL,   8, //89
                        BWCH,   8, //8a
                        BWCL,   8, //8b
                        BLCH,   8, //8c
                        BLCL,   8, //8d
                        BCG1,   16, //8e
                        BCG2,   16, //90
                        BSNH,   8, //92
                        BSNL,   8, //93
                        BPRH,   8, //94
                        BPRL,   8, //95
                        BRCH,   8, //96
                        BRCL,   8, //97
                        BPVH,   8, //98
                        BPVL,   8, //99
                        BTP,    16, //9a
                        CBT,    16, //9c
                        BMFG,   72, //9e



Yes.
Since entries in config.plist/ACPI/DSDT/Patches apply to ACPI/patched/DSDT.aml, there is no issue...

Thanks! My patch worked. BMFG was fixed using this:
Code:
into device label EC code_regex (BMFG,)\s+(72) replace_matched begin MFGX,%2,//%1%2 end;

*RE1B and RECB methods*

into method label XBIF code_regex \(BMFG, replaceall_matched begin (RECB(0x9E,72), end;

KHthkBz.png


But it seems to be not right yet, at some point battery was stuck to 100%. Then I unplugged the AC adapter, it started draining a little bit fast, and it jumped from 95% to 91%. Could it be related to iGPU PM? I haven't generated the custom SSDT.aml using ssdtPRGen.sh, I used the experimental XCPM only technique. X86PlatformPlugin is loading fine.

Those messages I've reported on this separated thread are now gone: https://www.tonymacx86.com/threads/acpi-error-ae_bad_parameter-setup-works-fine.227195/

But now I've seen the boot log again and found out other few messages:
Code:
(AppleACPIPlatform) ACPI Error: No handler for Region [ECF2] (ffffff801271b130) [EmbeddedControl] (20140828/evregion-f9)
(AppleACPIPlatform) ACPI Error: Region EmbeddedControl (ID=3) has no handler (20140828/exfldio-187)
(AppleACPIPlatform) ACPI Error: Method parse/execution failed [\_SB_.PCI0.LPCB.EC__.CMB0._STA] (Node ffffff8012c72290), AE_NOT_EXIST (20140828/psparse-270)

I have no idea about the "no handler" issue. For the other error, here's the region code:
Code:
Method (_STA, 0, NotSerialized)  // _STA: Status
{
    If (ECON)
    {
        Acquire (BATM, 0xFFFF)
        Store (BAP1, BATS)
        Release (BATM)
    }
  
    If (LEqual (BATP, Zero))
    {
        Return (Zero)
    }
  
    If (LEqual (BATS, Zero))
    {
        Return (0x0F)
    }
    Else
    {
        Return (0x1F)
    }
}

Any idea?
 

Attachments

  • DSDT-FIXED-BATTERY.dsl
    720.8 KB · Views: 146
Thanks! My patch worked. BMFG was fixed using this:
Code:
into device label EC code_regex (BMFG,)\s+(72) replace_matched begin MFGX,%2,//%1%2 end;

*RE1B and RECB methods*

into method label XBIF code_regex \(BMFG, replaceall_matched begin (RECB(0x9E,72), end;

KHthkBz.png


But it seems to be not right yet, at some point battery was stuck to 100%. Then I unplugged the AC adapter, it started draining a little bit fast, and it jumped from 95% to 91%. Could it be related to iGPU PM? I haven't generated the custom SSDT.aml using ssdtPRGen.sh, I used the experimental XCPM only technique. X86PlatformPlugin is loading fine.

Those messages I've reported on this separated thread are now gone: https://www.tonymacx86.com/threads/acpi-error-ae_bad_parameter-setup-works-fine.227195/

But now I've seen the boot log again and found out other few messages:
Code:
(AppleACPIPlatform) ACPI Error: No handler for Region [ECF2] (ffffff801271b130) [EmbeddedControl] (20140828/evregion-f9)
(AppleACPIPlatform) ACPI Error: Region EmbeddedControl (ID=3) has no handler (20140828/exfldio-187)
(AppleACPIPlatform) ACPI Error: Method parse/execution failed [\_SB_.PCI0.LPCB.EC__.CMB0._STA] (Node ffffff8012c72290), AE_NOT_EXIST (20140828/psparse-270)

I have no idea about the "no handler" issue. For the other error, here's the region code:
Code:
Method (_STA, 0, NotSerialized)  // _STA: Status
{
    If (ECON)
    {
        Acquire (BATM, 0xFFFF)
        Store (BAP1, BATS)
        Release (BATM)
    }
 
    If (LEqual (BATP, Zero))
    {
        Return (Zero)
    }
 
    If (LEqual (BATS, Zero))
    {
        Return (0x0F)
    }
    Else
    {
        Return (0x1F)
    }
}

Any idea?

Read FAQ, "Problem Reporting"
https://www.tonymacx86.com/threads/faq-read-first-laptop-frequent-questions.164990/
 
Added new patch for "Lenovo Miix 720". Only change from Ideapad Y700 is BDN0 is 64 bits instead of 54. Your suggested changes missed that...

The other additional patches you added are not needed (the fields are not accessed).

Please test...

Hi, Rehabman. Sorry for the delay of feedback cuz I was on a fieldwork.

There’s a typo on line 156 of the patch and it should be (RECB(0x8f,72) there.

I applied the patch to DSDT and also created a hotpatch, however, none of these works with ACPIBatteryManager.

So I use your ACPIDebug to test and I can export the raw output of the battery detail. Is there something required to let the system recognize the data?

The following lines is append to _LID as the keyboard is detachable and could not call EC method.

Code:
                    \RMDT.P1 ("LID0._LID enter")
                    \RMDT.P1 ("Env Test")
                    \RMDT.P2 ("OSYS", OSYS)
                    \RMDT.P2 ("ECAV", ECAV)
                    If (LEqual (ECAV, One))
                    {
                        If (LEqual (Acquire (LFCM, 0xA000), Zero))
                        {
                            \RMDT.P1 ("PASS")
                        }
                    }

                    \RMDT.P1 ("8-Bit Register")
                    \RMDT.P2 ("B1TY != 1 for LiP", B1TY)
                    \RMDT.P2 ("B1ST Battery State", B1ST)
                    \RMDT.P1 ("16-Bit Register")
                    \RMDT.P2 ("B1AC Current", B1B2 (B2AC, B3AC))
                    \RMDT.P2 ("B1DA Method GSBI", B1B2 (B2DA, B3DA))
                    \RMDT.P2 ("B1DC Design Capacity", B1B2 (B2DC (), B3DC ()))
                    \RMDT.P2 ("B1DV Design voltage", B1B2 (B2DV, B3DV))
                    \RMDT.P2 ("B1FC Last Full Charge Capacity", B1B2 (B2FC, B3FC))
                    \RMDT.P2 ("B1FV Present Voltage", B1B2 (B2FV, B3FV))
                    \RMDT.P2 ("B1SN Serial number", B1B2 (B2SN, B3SN))
                    \RMDT.P2 ("B1RC Remaining Capacity", B1B2 (B2RC, B3RC))
                    \RMDT.P2 ("B1UD Method GSBI", B1B2 (B2UD, B3UD))
                    \RMDT.P1 ("32-Bit and over")
                    \RMDT.P2 ("BMN0/BMNX OEM Information", RECB (0x8F, 0x48))
                    \RMDT.P2 ("BDN0/BDNX Model number", RECB (0x98, 0x40))
                    \RMDT.P2 ("FWBT/FWBX Device VPC0", RECB (0x8F, 0x48))
                    \RMDT.P2 ("SMDA/SMDX Method MHPF", RECB (0x8F, 0x48))
                    Store (LIDX (), Local0)
                    \RMDT.P2 ("LID0._LID returning", Local0)
                    Return (Local0)

And I could get the following result shown that both B1B2 RECB works.

Code:
default    20:38:23.206972 +0800    kernel    ACPIDebug: "LID0._LID enter"
default    20:38:23.209015 +0800    kernel    ACPIDebug: "Env Test"
default    20:38:23.209844 +0800    kernel    ACPIDebug: { "OSYS", 0x7df, }
default    20:38:23.210673 +0800    kernel    ACPIDebug: { "ECAV", 0x1, }
default    20:38:23.211494 +0800    kernel    ACPIDebug: "PASS"
default    20:38:23.212322 +0800    kernel    ACPIDebug: "8-Bit Register"
default    20:38:23.213122 +0800    kernel    ACPIDebug: { "B1TY != 1 for LiP", 0x0, }
default    20:38:23.220845 +0800    kernel    ACPIDebug: { "B1ST Battery State?", 0x0, }
default    20:38:23.222640 +0800    kernel    ACPIDebug: "16-Bit Register"
default    20:38:23.223472 +0800    kernel    ACPIDebug: { "B1AC Current", 0x0, }
default    20:38:23.224332 +0800    kernel    ACPIDebug: { "B1DA Method GSBI", 0x4a33, }
default    20:38:23.226104 +0800    kernel    ACPIDebug: { "B1DC Design Capacity", 0x1004, }
default    20:38:23.228159 +0800    kernel    ACPIDebug: { "B1DV Design voltage", 0x1e28, }
default    20:38:23.237362 +0800    kernel    ACPIDebug: { "B1FC =Last Full Charge Capacity", 0xfc6, }
default    20:38:23.238105 +0800    kernel    ACPIDebug: { "B1FV Present Voltage", 0x2235, }
default    20:38:23.239563 +0800    kernel    ACPIDebug: { "B1SN Serial number", 0x3a9, }
default    20:38:23.240151 +0800    kernel    ACPIDebug: { "B1RC Remaining Capacity", 0xfc6, }
default    20:38:23.253817 +0800    kernel    ACPIDebug: { "B1UD Method GSBI", 0x4ad4, }
default    20:38:23.254378 +0800    kernel    ACPIDebug: "32-Bit and over"
default    20:38:23.254995 +0800    kernel    ACPIDebug: { "BMN0/BMNX OEM Information", { 4c 47 43 20 31 31 00 00 00 }, }
default    20:38:23.267006 +0800    kernel    ACPIDebug: { "BDN0/BDNX Model number", { 4c 31 35 4c 34 50 43 33 }, }
default    20:38:23.267834 +0800    kernel    ACPIDebug: { "FWBT/FWBX Device VPC0", { 4c 47 43 20 31 31 00 00 00 }, }
default    20:38:23.268661 +0800    kernel    ACPIDebug: { "SMDA/SMDX Method MHPF", { 4c 47 43 20 31 31 00 00 00 }, }
default    20:38:23.269465 +0800    kernel    ACPIDebug: { "LID0._LID returning", 0x1, }

Logs related to ACPISmartBattery only shows these:

Code:
2017-07-18 19:17:25.272759+0800 0x72       Default     0x0                  0      kernel: (ACPIBatteryManager) ACPIBatteryManager: BatteryTracker::start: entering init
2017-07-18 19:17:25.275180+0800 0x72       Default     0x0                  0      kernel: (ACPIBatteryManager) ACPIBatteryManager: BatteryTracker::start: entering start
2017-07-18 19:17:25.276812+0800 0x72       Default     0x0                  0      kernel: (ACPIBatteryManager) ACPIBatteryManager: starting BatteryTracker.
 

Attachments

  • SSDT-BATT.dsl
    29.5 KB · Views: 125
  • DSDT.aml
    131.8 KB · Views: 90
  • Zhen’s MacBook Air 07-18.ioreg
    9 MB · Views: 140
Hi, Rehabman. Sorry for the delay of feedback cuz I was on a fieldwork.

There’s a typo on line 156 of the patch and it should be (RECB(0x8f,72) there.

I applied the patch to DSDT and also created a hotpatch, however, none of these works with ACPIBatteryManager.

Read post #1, "Problem Reporting".
 
Read post #1, "Problem Reporting".

Files attached.:)

Code:
kextstat|grep -y acpiplat
   13    2 0xffffff7f83203000 0x66000    0x66000    com.apple.driver.AppleACPIPlatform (5.0) 65E05472-6AE7-3308-8CC8-FA6CB0DB2AEE <12 11 7 6 5 4 3 1>
kextstat|grep -y appleintelcpu
kextstat|grep -y applelpc
  102    0 0xffffff7f82998000 0x3000     0x3000     com.apple.driver.AppleLPC (3.1) F51595F0-F9B1-3B85-A1C3-F984DAD4107E <101 12 5 4 3>

sudo touch /System/Library/Extensions && sudo kextcache -u /
Password:
IOKitWaitQuiet() timed out.
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext FakeSMC.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext FakePCIID_Intel_HDMI_Audio.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext FakePCIID_Intel_HD_Graphics.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext FakePCIID_Broadcom_WiFi.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext FakePCIID.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext AppleBacklightInjector.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext ACPIBatteryManager.kext
kext-dev-mode allowing invalid signature -67013 0xFFFFFFFFFFFEFA3B for kext AppleMobileDevice.kext
kext-dev-mode allowing invalid signature -67030 0xFFFFFFFFFFFEFA2A for kext AppleIntelSKLGraphicsFramebuffer.kext
KernelCache ID: 487F7A1D440D7F68D2EC90CDA398EBF1
 

Attachments

  • RehabMan.zip
    66.1 KB · Views: 83
  • Zhen’s MacBook Air 07-18.ioreg.zip
    815.2 KB · Views: 70
  • CLOVER.zip
    3.5 MB · Views: 77
Files attached.:)

Code:
kextstat|grep -y acpiplat
   13    2 0xffffff7f83203000 0x66000    0x66000    com.apple.driver.AppleACPIPlatform (5.0) 65E05472-6AE7-3308-8CC8-FA6CB0DB2AEE <12 11 7 6 5 4 3 1>
kextstat|grep -y appleintelcpu
kextstat|grep -y applelpc
  102    0 0xffffff7f82998000 0x3000     0x3000     com.apple.driver.AppleLPC (3.1) F51595F0-F9B1-3B85-A1C3-F984DAD4107E <101 12 5 4 3>

sudo touch /System/Library/Extensions && sudo kextcache -u /
Password:
IOKitWaitQuiet() timed out.
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext FakeSMC.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext FakePCIID_Intel_HDMI_Audio.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext FakePCIID_Intel_HD_Graphics.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext FakePCIID_Broadcom_WiFi.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext FakePCIID.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext AppleBacklightInjector.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext ACPIBatteryManager.kext
kext-dev-mode allowing invalid signature -67013 0xFFFFFFFFFFFEFA3B for kext AppleMobileDevice.kext
kext-dev-mode allowing invalid signature -67030 0xFFFFFFFFFFFEFA2A for kext AppleIntelSKLGraphicsFramebuffer.kext
KernelCache ID: 487F7A1D440D7F68D2EC90CDA398EBF1

Do not attempt hotpatch until you have working battery status with static patch.

Note: If you attempt to disassemble your patchmatic -extract output with "iasl -da -dl *.aml", you will see serious problems with duplicate symbols.
 
Do not attempt hotpatch until you have working battery status with static patch.
As some of SSDT injected things such as NVMe properties, I continue use ssdt hotpatch for remaining SSDTs. So do I need to merge all these SSDTs or just the battery one?
 
As some of SSDT injected things such as NVMe properties, I continue use ssdt hotpatch for remaining SSDTs. So do I need to merge all these SSDTs or just the battery one?

My comment is regarding only battery status.
Merging SSDTs has nothing to do with static vs. hotpatch.
 
Note: If you attempt to disassemble your patchmatic -extract output with "iasl -da -dl *.aml", you will see serious problems with duplicate symbols.
The OEM DSDT has conflict between SSDT-4 [SaSsdt] and SSDT-6 [NvOptTbl]. The same problem appeared on my previous Yoga 3 14. https://www.tonymacx86.com/threads/guide-lenovo-yoga-3-14-broadwell-hd5500.187138/

He separately assembled excluding each of two ssdt and merge them later. I don't know why this situation continues, and SSDT-6 [NvOptTbl] just seems related to dGPU, but none configuration of this laptop contains a dGPU.

File updated and still cannot get battery fixed.

Code:
kextstat|grep -y acpiplat    
   13    2 0xffffff7f83203000 0x66000    0x66000    com.apple.driver.AppleACPIPlatform (5.0) 65E05472-6AE7-3308-8CC8-FA6CB0DB2AEE <12 11 7 6 5 4 3 1>
kextstat|grep -y appleintelcpukextstat|grep -y applelpc
  106    0 0xffffff7f82998000 0x3000     0x3000     com.apple.driver.AppleLPC (3.1) F51595F0-F9B1-3B85-A1C3-F984DAD4107E <95 12 5 4 3>

sudo touch /System/Library/Extensions && sudo kextcache -u /
Password:
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext FakeSMC.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext FakePCIID_Intel_HDMI_Audio.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext FakePCIID_Intel_HD_Graphics.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext FakePCIID_Broadcom_WiFi.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext FakePCIID.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext AppleBacklightInjector.kext
kext-dev-mode allowing invalid signature -67062 0xFFFFFFFFFFFEFA0A for kext ACPIBatteryManager.kext
kext-dev-mode allowing invalid signature -67013 0xFFFFFFFFFFFEFA3B for kext AppleMobileDevice.kext
kext-dev-mode allowing invalid signature -67030 0xFFFFFFFFFFFEFA2A for kext AppleIntelSKLGraphicsFramebuffer.kext
KernelCache ID: 487F7A1D440D7F68D2EC90CDA398EBF1
 

Attachments

  • CLOVER.zip
    3.5 MB · Views: 94
  • Zhen’s MacBook Air 07-18-2.ioreg.zip
    725 KB · Views: 75
  • RehabMan.zip
    64.3 KB · Views: 62
Back
Top