Popular Post bcc9 Posted October 29, 2012 Popular Post Share Posted October 29, 2012 I've written a script to auto-patch the AppleHDA binary to support hackintosh codecs under OSX 10.7 thru 10.9.patch-hda.3.4.zip 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 includes an associated codec config database, patch-hda-codecs.pl. This database contains two tables, first there is the codec_names_to_num table which provides the simple mapping between codec names and their codec id. Second is codecs_map which maps one's hackintosh codec name to the runtime AppleHDA codec (target codec), again referenced by name. This second table allows for multiple choices, so for example, the hackintosh realtek alc889 can be patched to either alc 885 or adi 1984. -c 1 lets you select choice #1 (the default), -c 2 the second choice, and so on. The script also attempts to auto-detect your system's codec and offers that as a default choice for the codec to patch into AppleHDA (the patch codec id). Early versions of this script required the patch codec id to be present in the patch-hda-codecs.pl database, but the current version does not. You can now specify any codec ID you wish and the script will attempt to patch your codec into the ADI 1984 choice (the most common). 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 this thread 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.projectosx.com/forum/index.php?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. Command line switches -y Makes the script use the auto-detected codec without running the script interactively. -c <choice number> For codecs with multiple known working choices for the runtime AppleHDA codec (target codec) to use, this option selects the choice. -c 1 lets you select choice #1 (the default), -c 2 the second choice, and so on. -s <directory> to specify an alternative to /System/Library/Extensions -r <volume root> to specify an alternate disk volume to use as the root for everything (particularly useful when you have multiple installs of OSX and you want to patch OSX on one of those other volumes. Also, for both of the above the script determines the OS release based upon the AppleHDA kext version. If for some reason the script gets this wrong, there's also -o <os version number> to override the auto-detected OS version (10.7/10.8/10.9) -t to run the script in test-only mode, where AppleHDA is not actually patched. 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.insanelymac.com/forum/topic/280468-applehda-patching-in-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' -c 2 Patching AppleHDA codec 11d41984 with 10ec0889 No codec range comparisons require patching AppleHDA patched successfully. % ./patch-hda.pl 0x10ec0801 OSX version 10.8 detected Couldn't find a codec map to apply for '0x10ec0801'. Would you like to try using ADI 1984 (the default) (Y/N)? y Patching AppleHDA codec 11d41984 with 10ec0801 2 codec range comparison(s) to patch Patching range comparison 10ec0884 Patching range comparison 10ec0885 AppleHDA patched successfully. % ./patch-hda.pl OSX version 10.9 detected Enter codec-id or codec-name for AppleHDA patch. Eg. 111d7675 or IDT 7675 Press enter for default, or ? for help ? ? Usage: patch-hda.pl <codec-id>|<codec-name> Command line switches: -y Use the auto-detected codec without running the script interactively. -c <choice> For codecs with multiple known working choices for the runtime AppleHDA codec (target codec) to use, this option selects the choice. -c 1 lets you select choice #1 (the default), -c 2 the second choice, and so on. -s <directory> kext directory to use instead of /System/Library/Extensions -r <volume root> specify an alternate disk volume to use as the root for everything -o <os vers number> override auto-detected OS version (10.7/10.8/10.9) -t run the script in test-only mode, where AppleHDA is not actually patched. Examples: patch-hda.pl 111d7675 patch-hda.pl 'IDT 7675' patch-hda.pl -c 2 'Realtek ALC892' patch-hda.pl -y Supported codecs: Target Target Patch Codec ID Name Codec Name ------------------------------------------- 10ec0662 Realtek ALC662 ALC 885 111d7603 IDT 7603 ADI 1984 10ec0272 Realtek ALC272 ADI 1984 111d76e0 IDT 76e0 ADI 1984B 10ec0889 Realtek ALC889 Choice 1: ALC 885 Choice 2: ADI 1984 111d7675 IDT 7675 ADI 1984 10ec0892 Realtek ALC892 Choice 1: ALC 885 Choice 2: ADI 1984B 10ec0883 Realtek ALC883 ALC 885 10ec0270 Realtek ALC270 ADI 1984 11060441 VIA VT2021 ADI 1984 10ec0887 Realtek ALC887 ADI 1984B 11d4989b ADI AD2000B ADI 1984B 111d76d1 IDT 76d1 ADI 1984 10ec0269 Realtek ALC269 ADI 1984 10ec0888 Realtek ALC888 ALC 885 10ec0882 Realtek ALC882 ALC 885 111d7605 IDT 7605 ADI 1984B ?For interactive use: % ./patch-hda.pl OSX version 10.9 detected Default target codec: 10ec0892 detected. Enter codec-id or codec-name for AppleHDA patch. Eg. 111d7675 or IDT 7675 Press enter for default, or ? for help (Default: 10ec0892) ? <enter> There are 2 choices for target codec Choose codec number to patch to (1 thru 2) (default 1) Choice 1: ALC 885 Choice 2: ADI 1984B ? 2 Patching AppleHDA codec 11d4198b with 10ec0892 1 codec range comparison(s) to patch Patching range comparison 11d41984 This script requires superuser access to update AppleHDA Password: /System/Library/Extensions/AppleHDA.kext/Contents/MacOS/AppleHDA patched successfully. % The new command line argument -y allows you to pick up the auto-detected codec without running the script interactively. So the non-interactive equivlanet of the above: sudo ./patch-hda.pl -y -c 2Note: For some codecs, there are multiple choices for the target codec to patch to. (See alc889 and alc892 above). For these codecs, use the command line argument -c to specify which choice you wish to use (or leave the argument off and get choice #1). 28 Link to comment Share on other sites More sharing options...
Micky1979 Posted October 29, 2012 Share Posted October 29, 2012 Hi bcc9, now everyone has a point of reference for HDA binary patching, thank you very much for this Topic! Micky 1 Link to comment Share on other sites More sharing options...
bcc9 Posted October 29, 2012 Author Share Posted October 29, 2012 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. Link to comment Share on other sites More sharing options...
Micky1979 Posted October 30, 2012 Share Posted October 30, 2012 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 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 Link to comment Share on other sites More sharing options...
ErmaC Posted October 30, 2012 Share Posted October 30, 2012 Excellent! Topic pinned. Fabio Link to comment Share on other sites More sharing options...
bcc9 Posted October 30, 2012 Author Share Posted October 30, 2012 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. Link to comment Share on other sites More sharing options...
Micky1979 Posted October 30, 2012 Share Posted October 30, 2012 Ok, thanks, this will help to understand how to study....ALSA Wiki Micky Link to comment Share on other sites More sharing options...
Hacktrix2006 Posted October 31, 2012 Share Posted October 31, 2012 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. Link to comment Share on other sites More sharing options...
bcc9 Posted October 31, 2012 Author Share Posted October 31, 2012 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. 1 Link to comment Share on other sites More sharing options...
Hacktrix2006 Posted October 31, 2012 Share Posted October 31, 2012 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.! Link to comment Share on other sites More sharing options...
bcc9 Posted October 31, 2012 Author Share Posted October 31, 2012 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. 1 Link to comment Share on other sites More sharing options...
Micky1979 Posted October 31, 2012 Share Posted October 31, 2012 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? Platforms.xlm Micky 1 Link to comment Share on other sites More sharing options...
bcc9 Posted October 31, 2012 Author Share Posted October 31, 2012 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. Link to comment Share on other sites More sharing options...
Hacktrix2006 Posted October 31, 2012 Share Posted October 31, 2012 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. Link to comment Share on other sites More sharing options...
Micky1979 Posted October 31, 2012 Share Posted October 31, 2012 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? ======|> bcc9 :wink2: Micky Link to comment Share on other sites More sharing options...
Hacktrix2006 Posted October 31, 2012 Share Posted October 31, 2012 Micky your a classic. Problem is how can one parse a .svg file how ever i have found this http://www.kernel.org/doc/Documentation/sound/alsa/HD-Audio.txt interesting read though. Link to comment Share on other sites More sharing options...
bcc9 Posted October 31, 2012 Author Share Posted October 31, 2012 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. edit/deploy on codecgraph and verbit? would be nice ....but who do this? ======|> bcc9 :wink2: 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. 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/content/dam/www/public/us/en/documents/product-specifications/high-definition-audio-specification.pdf is also mandatory background reading for such a project. 1 Link to comment Share on other sites More sharing options...
Mirone Posted November 7, 2012 Share Posted November 7, 2012 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? Link to comment Share on other sites More sharing options...
Micky1979 Posted November 7, 2012 Share Posted November 7, 2012 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 Link to comment Share on other sites More sharing options...
bcc9 Posted November 8, 2012 Author Share Posted November 8, 2012 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. Link to comment Share on other sites More sharing options...
Mirone Posted November 8, 2012 Share Posted November 8, 2012 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. In the case of ALC272, 270 I applied the patch in ADI1984 ie the same thing that your script makes for ALC269 on lion replaces 8419d11 to 6902ec10 and zeroed the ALC884 ie 8408ec10 to 00000000 and it worked like a charm. in Mountain lion and Lion. 1 Link to comment Share on other sites More sharing options...
bcc9 Posted November 12, 2012 Author Share Posted November 12, 2012 In the case of ALC272, 270 I applied the patch in ADI1984 ie the same thing that your script makes for ALC269 on lion replaces 8419d11 to 6902ec10 and zeroed the ALC884 ie 8408ec10 to 00000000 and it worked like a charm. in Mountain lion and Lion. Not clear *exactly* what changes you're proposing for patch-hda-codecs.pl. You mention alc272 & alc270 which I should think would be 10ec0272 & 10ec0270 but you only list one target hex value that doesn't match either of those.Again, if you want to post the lines you added to the script or the whole new version, I can add them to the copy in post #1. Link to comment Share on other sites More sharing options...
Mirone Posted November 12, 2012 Share Posted November 12, 2012 Not clear *exactly* what changes you're proposing for patch-hda-codecs.pl. You mention alc272 & alc270 which I should think would be 10ec0272 & 10ec0270 but you only list one target hex value that doesn't match either of those. Again, if you want to post the lines you added to the script or the whole new version, I can add them to the copy in post #1. bcc9 hi, well I did this in two ways: 1-I ran your script to correct ALC269 (0x10ec0269) then after replacing the line already corrected for 6902ec10 to 7002ec10 (ALC270) it worked for ALC272. both codecs worked well. 2-I just changed the line ADI1984 (0x11d41984) for ALC270, ALC269 and zeroed checking 84 08 ec 10 worked very well. Link to comment Share on other sites More sharing options...
plsh2me Posted November 12, 2012 Share Posted November 12, 2012 Hi bcc9, I have got following error while run the script on 10.7.5 Thank you Link to comment Share on other sites More sharing options...
bcc9 Posted November 13, 2012 Author Share Posted November 13, 2012 bcc9 hi, well I did this in two ways: 1-I ran your script to correct ALC269 (0x10ec0269) then after replacing the line already corrected for 6902ec10 to 7002ec10 (ALC270) it worked for ALC272. both codecs worked well. 2-I just changed the line ADI1984 (0x11d41984) for ALC270, ALC269 and zeroed checking 84 08 ec 10 worked very well. I'm still not sure I understand your writing.I think what you mean is that we should add: { name => 'Realtek ALC270', target_id => 0x10ec0270, patch_id => 0x11d41984 #ADI 1984 }, { name => 'Realtek ALC272', target_id => 0x10ec0272, patch_id => 0x11d41984 #ADI 1984 }, to patch-hda-codecs.pl ? Link to comment Share on other sites More sharing options...
Recommended Posts