Jump to content

fluid | fixed

Script to patch AppleHDA binary for osx10.7/10.8

AppleHDA binary patch

  • Please log in to reply
40 replies to this topic

#1
bcc9

bcc9

    InsanelyMac Legend

  • Coders
  • 1,155 posts
  • Gender:Male
I've recently written a script to auto-patch the AppleHDA binary to support hackintosh codecs under OSX 10.7 and 10.8.

Background:
Historically the binary patching of AppleHDA was simple, merely requiring replacement of the best matching codec id found in the driver with the codec id for your hardware.  In more recent releases of AppleHDA, the compiler is better optimizing its code and patching now often requires patching the AppleHDA binary in multiple places.  For some codecs, this has resulted in a patch that is different depending upon which release you're using.  The old strategy of using a perl one-liner to publish&distribute these patches thus became less practical than ever, leading to confusion, seemingly conflicting information and lists of questionable patches for one to try.  This script is meant to replace that.

The solution
The script is able to dynamically figure out which extra comparisons should be patched to get the matching to work properly.  The script contains a static list of hackintosh codecs (referred to as target ids in the script) and patch ids (the codecs built-in to AppleHDA which we have successfully used with hackintoshes).

Every OSX update that installs a new version of AppleHDA (that is, most of them) requires re-patching your system's AppleHDA.  That is unless you resort to other means such as rolling back your AppleHDA driver (not recommended).

I've included support for the codecs I have, those found in HDA wizard, as well as many more from the thread http://www.insanelym...-mountain-lion/

What this thread is not:
A complete solution for getting your AppleHDA audio working.
In addition to patching your AppleHDA binary, you need to also configure xml for your codec.  (A pathmap and pin configuration as it's referred to in the drivers).  See http://www.projectos...p?showtopic=465
Thirdly, you need a method to inject into your ioregistry the layout-id used by your pathmap and/or also some flags for working HDMI audio.  These edits can be done quite concisely via DSDT.  Alternatively you may also inject them into your ioregistry thru other means such as a kext.  Again see the above thread.

Usage:
Run this script from a terminal window, supplying the codec name or the hexadecimal codec id of the codec found on your hackintosh.  If your codec is in the database (patch-hda-codecs.pl) the script will patch things for you automatically.  Alternatively you can click on the patch-hda shell script from the finder.  

Implementation details:

The script accomplishes patching of the codec comparisons by zeroing out the codec ids found as operands to the applicable comparison instructions.  This is easier to do in a script than other patch methods such as jumping over unwanted comparisons.  The solution in this script is easier to implement as the script can avoid parsing AppleHDA's match routine's instructions to work successfully.  (see ati-personality.pl for an example of that more complicated kind of processing).

How to help
Please DO contribute updates to this script, especially the patch-hda-codecs.pl list, to support new hardware.  I do not have a lab of hardware to test against; I rely upon users to fill in the blanks as to what does/doesn't work.  I do not have time to test codecs for hardware I do not have; I barely had time to write this post.  Feel free to post revised versions of patch-hda-codecs.pl here.

Please DON'T post to this thread to beg for a solution for your codec.  It takes quite a bit of tinkering to make a working pathmap&pinconfig for a new codec.  And there are better threads for such discussion such as: http://www.insanelym...-mountain-lion/

Please DON'T PM me for tech support either, I likely don't even have time to answer.

This script resembles the concept of HDA wizard but instead of being GUI focused, it focuses on getting the AppleHDA binary patching done automatic&right across osx releases.

Examples, under 10.7:

% ./patch-hda.pl 111d7675
Patching AppleHDA codec 11d41984 with 111d7675
1 codec range comparison(s) to patch
Patching range comparison 11d41983
AppleHDA patched successfully.
under 10.8:
% ./patch-hda.pl 111d7675
Patching AppleHDA codec 11d41984 with 111d7675
No codec range comparisons require patching
AppleHDA patched successfully.
% ./patch-hda.pl 10ec0889
Patching AppleHDA codec 10ec0885 with 10ec0889
No codec range comparisons require patching
AppleHDA patched successfully.
% ./patch-hda.pl 'Realtek ALC889+inputs'
Patching AppleHDA codec 11d41984 with 10ec0889
No codec range comparisons require patching
AppleHDA patched successfully.
% ./patch-hda.pl
Usage: patch-hda.pl <codec-id>|<codec-name>
Examples: patch-hda.pl 111d7675
Examples: patch-hda.pl 'IDT 7675'
Supported codecs:
Target		  Patch		   Name
Codec ID		Codec ID
-------------------------------------------
111d7675		11d41984		IDT 7675
111d76d1		11d41984		IDT 76d1
111d76e0		11d4198b		IDT 76e0
10ec0269		11d41984		Realtek ALC269
10ec0889		10ec0885		Realtek ALC889
10ec0889		11d41984		Realtek ALC889+inputs
10ec0892		10ec0885		Realtek ALC892
10ec0662		10ec0885		Realtek ALC662
10ec0882		10ec0885		Realtek ALC882
10ec0883		10ec0885		Realtek ALC883
10ec0887		10ec0885		Realtek ALC887
10ec0888		10ec0885		Realtek ALC888
111d7603		11d41984		IDT 7603
111d7605		11d4198b		IDT 7605
11d4989b		11d4198b		ADI AD2000B
11060441		11d41984		VIA VT2021

%

Note: Since there is debate as to which codec to use for alc889, two choices are offered above.

Attached Files



#2
Micky1979

Micky1979

    I realized that I am lucky

  • Moderators
  • 1,283 posts
  • Gender:Male
  • Location:Italy
Hi bcc9,

now everyone has a point of reference for HDA binary patching, thank you very much for this Topic!

Micky

#3
bcc9

bcc9

    InsanelyMac Legend

  • Coders
  • 1,155 posts
  • Gender:Male

View PostMicky1979, on 29 October 2012 - 11:28 PM, said:

now everyone has a point of reference for HDA binary patching, thank you very much for this Topic!
Thanks, hope it works out that way.  It can if the codec list gets further contributions.


#4
Micky1979

Micky1979

    I realized that I am lucky

  • Moderators
  • 1,283 posts
  • Gender:Male
  • Location:Italy
The OSx86 scene has a new data collection point, and a powerful tool.
All who will use your script, I hope will give credit to this Topic in the web! ;)

Micky

View Postbcc9, on 29 October 2012 - 11:43 PM, said:

Thanks, hope it works out that way.  It can if the codec list gets further contributions.
According to you, the user, based on what evidence should choose a replacement for a specific codec?
Looking into AppleHDA, in the different layouts and their respective patmaps, we can guess how they work, but this can be of help in finding the right codec replacement?

Micky

#5
ErmaC

ErmaC

    127.0.0.1

  • Supervisors
  • 4,235 posts
  • Gender:Male
  • Location:Canary Islands
Excellent!

Topic pinned.

Fabio

#6
bcc9

bcc9

    InsanelyMac Legend

  • Coders
  • 1,155 posts
  • Gender:Male

View PostMicky1979, on 30 October 2012 - 12:08 AM, said:

According to you, the user, based on what evidence should choose a replacement for a specific codec?
Looking into AppleHDA, in the different layouts and their respective patmaps, we can guess how they work, but this can be of help in finding the right codec replacement?).
The codec replacements are fairly predictable - mostly all codecs from a particular vendor map to the same codec vendor within AppleHDA (for example almost all IDT codecs work with the ADI codec code, realtek work with ALC, etc.).  Some experimentation is often required (trying both ADI1984 and ADI 1984B for example).
Since the hardware vendors seem to be basing their codecs off of each other, there are a lot of similarities between vendors.  To dig deeper, one can always look at the ALSA open source code and see what quirks exist for a particular codec and what other codec(s) have comparable widget/amp driver support.

#7
Micky1979

Micky1979

    I realized that I am lucky

  • Moderators
  • 1,283 posts
  • Gender:Male
  • Location:Italy
Ok, thanks, this will help to understand how to study....ALSA Wiki

Micky

#8
Hacktrix2006

Hacktrix2006

    InsanelyMac Sage

  • Members
  • PipPipPipPipPipPip
  • 419 posts
  • Gender:Male
Hi Bcc this look promising and a very great idea. I have just downloaded script 0.8 and there happens to be a set of errors throwing out here.

syntax error at /users/solidus1983/desktop/AudioPatching/hda/patch-hda.pl line 320, near ") exit"
syntax error at /users/solidus1983/desktop/AudioPatching/hda/patch-hda.pl line 322, near ") exit"
syntax error at /users/solidus1983/desktop/AudioPatching/hda/patch-hda.pl line 324, near ") exit"
syntax error at /users/solidus1983/desktop/AudioPatching/hda/patch-hda.pl line 326, near ") exit"
syntax error at /users/solidus1983/desktop/AudioPatching/hda/patch-hda.pl line 328, near ") exit"

Doesn't matter if you run the patch-hda.pl or patch-hda same error.

#9
bcc9

bcc9

    InsanelyMac Legend

  • Coders
  • 1,155 posts
  • Gender:Male

View PostHacktrix2006, on 31 October 2012 - 02:11 AM, said:

Hi Bcc this look promising and a very great idea. I have just downloaded script 0.8 and there happens to be a set of errors throwing out here.

syntax error at /users/solidus1983/desktop/AudioPatching/hda/patch-hda.pl line 320, near ") exit"
syntax error at /users/solidus1983/desktop/AudioPatching/hda/patch-hda.pl line 322, near ") exit"
syntax error at /users/solidus1983/desktop/AudioPatching/hda/patch-hda.pl line 324, near ") exit"
syntax error at /users/solidus1983/desktop/AudioPatching/hda/patch-hda.pl line 326, near ") exit"
syntax error at /users/solidus1983/desktop/AudioPatching/hda/patch-hda.pl line 328, near ") exit"

Doesn't matter if you run the patch-hda.pl or patch-hda same error.
Damn, I swear I had tested that last minute change before posting 0.8.  Fixed now, version 0.9.  Duh.



#10
Hacktrix2006

Hacktrix2006

    InsanelyMac Sage

  • Members
  • PipPipPipPipPipPip
  • 419 posts
  • Gender:Male
Thats ok bcc9. I looked in the script and its a great idea what you are doing its just a shame there is no way you can get the script to do everything for you. I.e mod the Platforms.xml.zlib Layoutxx.xml.zlib and info.plist automatically with everything needed to get the sound working.

Will try version 0.9 tonight.!

#11
bcc9

bcc9

    InsanelyMac Legend

  • Coders
  • 1,155 posts
  • Gender:Male
Perhaps someone would like to take the codec dump from alsa, parse it, and generate a candidate, or template, layout&pathmap xml for AppleHDA.  Then a database of modifications to make on top of that and you'd have something.


#12
Micky1979

Micky1979

    I realized that I am lucky

  • Moderators
  • 1,283 posts
  • Gender:Male
  • Location:Italy

View Postbcc9, on 31 October 2012 - 04:44 PM, said:

Perhaps someone would like to take the codec dump from alsa, parse it, and generate a candidate, or template, layout&pathmap xml for AppleHDA.  Then a database of modifications to make on top of that and you'd have something.
Something similar to the pre-defined templates where adding a new device (in Layoutxx.xml), and shares can be copied from a plist file ready to be pasted in a different sub in PathMaps?

Spoiler


Micky

#13
bcc9

bcc9

    InsanelyMac Legend

  • Coders
  • 1,155 posts
  • Gender:Male
Something like that.  With a program/script, one could compute the directed graph of nodes to use in the pathmap instead of having a user input them manually.  Basically implement the dynamic configuration detection from the alsa driver but instead of doing so as a driver, make the output just be xml for AppleHDA, and the input be the codec dump from alsa.



#14
Hacktrix2006

Hacktrix2006

    InsanelyMac Sage

  • Members
  • PipPipPipPipPipPip
  • 419 posts
  • Gender:Male
Thats the main issue i have, I have the Codec Verbs not a problem i look at the pinout and its a brain mess for me.

A script that could say do the Verb and Read the SVG file then parse it to .xml would be great. But how one can do that i don't know.

From reading the how too's the main issue really is layout and platforms.xml thats where most get stuck.

#15
Micky1979

Micky1979

    I realized that I am lucky

  • Moderators
  • 1,283 posts
  • Gender:Male
  • Location:Italy

View Postbcc9, on 31 October 2012 - 06:45 PM, said:

Something like that.  With a program/script, one could compute the directed graph of nodes to use in the pathmap instead of having a user input them manually.  Basically implement the dynamic configuration detection from the alsa driver but instead of doing so as a driver, make the output just be xml for AppleHDA, and the input be the codec dump from alsa.
edit/deploy on codecgraph and verbit? would be nice ....but who do this? :whistle: ======|>
Spoiler

Micky

#16
Hacktrix2006

Hacktrix2006

    InsanelyMac Sage

  • Members
  • PipPipPipPipPipPip
  • 419 posts
  • Gender:Male
Micky your a classic. Problem is how can one parse a .svg file how ever i have found this http://www.kernel.or...sa/HD-Audio.txt interesting read though.

#17
bcc9

bcc9

    InsanelyMac Legend

  • Coders
  • 1,155 posts
  • Gender:Male

View PostHacktrix2006, on 31 October 2012 - 06:58 PM, said:

A script that could say do the Verb and Read the SVG file then parse it to .xml would be great. But how one can do that i don't know.
Or maybe just use the alsa codec dump parsing code from codecgraph that generates a .svg as a starting point for a new tool that generates xml instead.

View PostMicky1979, on 31 October 2012 - 08:42 PM, said:

edit/deploy on codecgraph and verbit? would be nice ....but who do this? :whistle: ======|>
Spoiler
Ha, it was by design that I only tackled the easier part of patching the AppleHDA binary.  I don't have time to take on the more ambitious project.

Actually I'm kind of surprised that  by now AppleHDA itself hadn't been cleaned up to work without any static xml codec config.

View PostHacktrix2006, on 31 October 2012 - 09:37 PM, said:

Micky your a classic. Problem is how can one parse a .svg file how ever i have found this http://www.kernel.or...sa/HD-Audio.txt interesting read though.
The HDA audio spec http://www.intel.com...ecification.pdf is also mandatory background reading for such a project.

#18
mirone23

mirone23

    InsanelyMac Protégé

  • Members
  • Pip
  • 44 posts
  • Gender:Male
  • Location:Brasil
A really quality post.
I have corrected some AppleHDA for ALC272, ALC270 and others.
What I have to do so that you can include these codecs in your script?

#19
Micky1979

Micky1979

    I realized that I am lucky

  • Moderators
  • 1,283 posts
  • Gender:Male
  • Location:Italy

View Postmirone23, on 07 November 2012 - 02:57 PM, said:

A really quality post.
I have corrected some AppleHDA for ALC272, ALC270 and others.
What I have to do so that you can include these codecs in your script?
You must publish what codec you have patched, and what did you replace on the binary.
Of course you  tried and have seen if it work in Mountain Lion.
If you read above, instances of change in AppleHDA binary, can change between Lion and Mountain Lion (read the "range comparisons" at first post):
only way is to tell bcc9, "I tried it, and it works!"


Micky1979

#20
bcc9

bcc9

    InsanelyMac Legend

  • Coders
  • 1,155 posts
  • Gender:Male

View PostMicky1979, on 07 November 2012 - 06:25 PM, said:

You must publish what codec you have patched, and what did you replace on the binary.
Exactly.  Presumably the changes are a few added lines to patch-hda-codecs.pl, and you can either just post the lines you added or the whole new version, and I'll add them to the .zip.
Seems like a default wildcard for realtek codecs: 10ec:* => alc885 might be in order.










1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users

© 2013 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Mac Netbook  |   Web hosting by CatN  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy