forked from syscl/XPS9350-macOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeploy.sh
executable file
·1588 lines (1412 loc) · 63.5 KB
/
Deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
#
# syscl/Yating Zhou/lighting from bbs.PCBeta.com
# Merge for Dell XPS 13 9350(Skylake)
#
#================================= GLOBAL VARS ==================================
#
# The script expects '0.5' but non-US localizations use '0,5' so we export
# LC_NUMERIC here (for the duration of the deploy.sh) to prevent errors.
#
export LC_NUMERIC="en_US.UTF-8"
#
# Prevent non-printable/control characters.
#
unset GREP_OPTIONS
unset GREP_COLORS
unset GREP_COLOR
#
# Display style setting.
#
BOLD="\033[1m"
RED="\033[1;31m"
GREEN="\033[1;32m"
BLUE="\033[1;34m"
OFF="\033[m"
#
# Define two status: 0 - Success, Turn on,
# 1 - Failure, Turn off
#
kBASHReturnSuccess=0
kBASHReturnFailure=1
#
# Located repository.
#
REPO=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
#
# Path and filename setup.
#
decompile="${REPO}/DSDT/raw/"
precompile="${REPO}/DSDT/precompile/"
compile="${REPO}/DSDT/compile/"
tools="${REPO}/tools/"
raw="${REPO}/DSDT/raw"
prepare="${REPO}/DSDT/prepare"
config_plist="/Volumes/EFI/EFI/CLOVER/config.plist"
EFI_INFO="${REPO}/DSDT/EFIINFO"
gInstall_Repo="/usr/local/sbin/"
gFrom="${REPO}/tools"
gUSBSleepConfig="/tmp/com.syscl.externalfix.sleepwatcher.plist"
gUSBSleepScript="/tmp/sysclusbfix.sleep"
gUSBWakeScript="/tmp/sysclusbfix.wake"
gRTWlan_kext=$(ls /Library/Extensions | grep -i "Rtw" | sed 's/.kext//')
gRTWlan_Repo="/Library/Extensions"
to_Plist="/Library/LaunchDaemons/com.syscl.externalfix.sleepwatcher.plist"
to_shell_sleep="/etc/sysclusbfix.sleep"
to_shell_wake="/etc/sysclusbfix.wake"
gRT_Config="/Applications/Wireless Network Utility.app"/${gMAC_adr}rfoff.rtl
drivers64UEFI="${REPO}/CLOVER/drivers64UEFI"
t_drivers64UEFI="/Volumes/EFI/EFI/CLOVER/drivers64UEFI"
clover_tools="${REPO}/CLOVER/tools"
t_clover_tools="/Volumes/EFI/EFI/CLOVER/tools"
#
# Define variables.
#
# Gvariables stands for getting datas from OS X.
#
gArgv=""
gDebug=${kBASHReturnFailure}
gProductVer=""
target_website=""
target_website_status=""
RETURN_VAL=""
gEDID=""
gHorizontalRez_pr=""
gHorizontalRez_st=""
gHorizontalRez=""
gVerticalRez_pr=""
gVerticalRez_st=""
gVerticalRez=""
gSystemRez=""
gSystemHorizontalRez=""
gSystemVerticalRez=""
gPatchIOKit=${kBASHReturnSuccess}
gClover_ig_platform_id=""
target_ig_platform_id=""
gTriggerLE=${kBASHReturnFailure}
gProductVer="$(sw_vers -productVersion)"
gOSVer=${gProductVer:0:5}
gMINOR_VER=${gProductVer:3:2}
gBak_Time=$(date +%Y-%m-%d-h%H_%M_%S)
gBak_Dir="${REPO}/Backups/${gBak_Time}"
gStop_Bak=${kBASHReturnFailure}
gRecoveryHD=""
gRecoveryHD_DMG="/Volumes/Recovery HD/com.apple.recovery.boot/BaseSystem.dmg"
gTarget_rhd_Framework=""
gTarget_Framework_Repo=""
gBluetooth_Brand_String=""
#
# Add: Comment(string), Disabled(bool), Find(data), Name(string), Replace(data)
# Set: $comment , false , syscl , $binary_name, syscl
#
gProperties_Name=(Comment Disabled Find Name Replace)
gProperties_Type=(string bool data string data)
#
# Kexts to patch
#
cLidWake=""
fLidWake=""
rLidWake=""
nLidWake=""
cIntelGraphicsFrameBuffer=""
fIntelGraphicsFrameBuffer=""
rIntelGraphicsFrameBuffer=""
nIntelGraphicsFrameBuffer=""
cHDMI=""
fHDMI=""
rHDMI=""
nHDMI=""
cHandoff=""
fHandoff=""
rHandoff=""
nHandoff=""
#
# Audio variables
#
gResources_xml_zlib=("layout1" "Platforms")
gExtensions_Repo=("/System/Library/Extensions" "/Library/Extensions")
gInjector_Repo="/tmp/AppleHDA_ALC668.kext"
gAppleHDA_Config="${gInjector_Repo}/Contents/Info.plist"
doCommands=("${REPO}/tools/iasl" "/usr/libexec/plistbuddy -c" "perl -p -e 's/(\d*\.\d*)/9\1/'")
#
# Set delimitation OS ver
#
let gDelimitation_OSVer=12
#
# Define target website
#
target_website=https://github.com/syscl/XPS9350-macOS
#
#--------------------------------------------------------------------------------
#
function _PRINT_MSG()
{
local message=$1
case "$message" in
OK* ) local message=$(echo $message | sed -e 's/.*OK://')
echo "[ ${GREEN}OK${OFF} ] ${message}."
;;
FAILED*) local message=$(echo $message | sed -e 's/.*://')
echo "[${RED}FAILED${OFF}] ${message}."
;;
---* ) local message=$(echo $message | sed -e 's/.*--->://')
echo "[ ${GREEN}--->${OFF} ] ${message}"
;;
NOTE* ) local message=$(echo $message | sed -e 's/.*NOTE://')
echo "[ ${RED}Note${OFF} ] ${message}."
;;
esac
}
#
#--------------------------------------------------------------------------------
#
function _update()
{
#
# Sync all files from https://github.com/syscl/XPS9350-macOS
#
# Check if github is available
#
local timeout=5
#
# Detect whether the website is available
#
_PRINT_MSG "--->: Updating files from ${BLUE}${target_website}...${OFF}"
target_website_status=`curl -I -s --connect-timeout $timeout ${target_website} -w %{http_code}`
if [[ `echo ${target_website_status} | grep -i "Status"` == *"OK"* && `echo ${target_website_status} | grep -i "Status"` == *"200"* ]]
then
cd ${REPO}
git pull
else
_PRINT_MSG "NOTE: ${BLUE}${target_website}${OFF} is not ${RED}available${OFF} at this time, please link ${BLUE}${target_website}${OFF} again next time."
fi
}
#
#--------------------------------------------------------------------------------
#
function _locate_rhd()
{
#
# Passing gRecoveryHD from ${targetEFI}
#
local gDisk_INF="$1"
#
# Example:
#
# disk0s3
# ^^^^^
diskutil list | grep -i "${gDisk_INF:0:5}" | grep "Recovery HD" |sed 's/.*MB //'
}
#
#--------------------------------------------------------------------------------
#
function _touch()
{
local target_file=$1
if [ ! -d ${target_file} ];
then
_tidy_exec "mkdir -p ${target_file}" "Create ${target_file}"
fi
}
#
#--------------------------------------------------------------------------------
#
function patch_acpi()
{
if [ "$2" == "syscl" ];
then
"${REPO}"/tools/patchmatic "${REPO}"/DSDT/raw/$1.dsl "${REPO}"/DSDT/patches/$3.txt "${REPO}"/DSDT/raw/$1.dsl
else
"${REPO}"/tools/patchmatic "${REPO}"/DSDT/raw/$1.dsl "${REPO}"/DSDT/patches/$2/$3.txt "${REPO}"/DSDT/raw/$1.dsl
fi
}
#
#--------------------------------------------------------------------------------
#
function _tidy_exec()
{
if [ $gDebug -eq 0 ];
then
#
# Using debug mode to output all the details.
#
_PRINT_MSG "DEBUG: $2"
$1
else
#
# Make the output clear.
#
$1 >/tmp/report 2>&1 && RETURN_VAL=${kBASHReturnSuccess} || RETURN_VAL=${kBASHReturnFailure}
if [ "${RETURN_VAL}" == ${kBASHReturnSuccess} ];
then
_PRINT_MSG "OK: $2"
else
_PRINT_MSG "FAILED: $2"
cat /tmp/report
fi
rm /tmp/report &> /dev/null
fi
}
#
#--------------------------------------------------------------------------------
#
function compile_table()
{
"${REPO}"/tools/iasl -vr -w1 -ve -p "${compile}"$1.aml "${precompile}"$1.dsl
}
#
#--------------------------------------------------------------------------------
#
function rebuild_kernel_cache()
{
#
# Repair the permission & refresh kernelcache.
#
if [ $gTriggerLE -eq 0 ];
then
#
# Yes, we do touch /L*/E*.
#
sudo touch /Library/Extensions
fi
#
# /S*/L*/E* must be touched to prevent some potential issues.
#
sudo touch /System/Library/Extensions
sudo /bin/kill -1 `ps -ax | awk '{print $1" "$5}' | grep kextd | awk '{print $1}'`
sudo kextcache -u /
}
#
#--------------------------------------------------------------------------------
#
function install_audio()
{
#
# Remove previous AppleHDA_ALC668.kext & CodecCommander.kext.
#
for extensions in ${gExtensions_Repo[@]}
do
_del $extensions/AppleHDA_ALC668.kext
_del $extensions/CodecCommander.kext
done
if [ $gMINOR_VER -ge $gDelimitation_OSVer ];
then
#
# 10.12+
#
_install_AppleHDA_Injector
fi
}
#
#--------------------------------------------------------------------------------
#
function _install_AppleHDA_Injector()
{
_del "${gInjector_Repo}"
_del "${KEXT_DIR}/AppleALC.kext"
#
# Generate audio from current system.
#
_PRINT_MSG "--->: Generating AppleHDA injector..."
cp -RX "${gExtensions_Repo[0]}/AppleHDA.kext" ${gInjector_Repo}
rm -rf ${gInjector_Repo}/Contents/Resources/*
_del ${gInjector_Repo}/Contents/PlugIns
_del ${gInjector_Repo}/Contents/_CodeSignature
_del ${gInjector_Repo}/Contents/MacOS/AppleHDA
_del ${gInjector_Repo}/Contents/version.plist
ln -s ${gExtensions_Repo[0]}/AppleHDA.kext/Contents/MacOS/AppleHDA ${gInjector_Repo}/Contents/MacOS/AppleHDA
for zlib in "${gResources_xml_zlib[@]}"
do
_tidy_exec "cp "${REPO}/Kexts/audio/Resources/layout/${zlib}.xml.zlib" "${gInjector_Repo}/Contents/Resources/"" "Copy ${zlib}"
done
replace=`${doCommands[1]} "Print :NSHumanReadableCopyright" ${gAppleHDA_Config} | ${doCommands[2]}`
${doCommands[1]} "Set :NSHumanReadableCopyright '$replace'" ${gAppleHDA_Config}
replace=`${doCommands[1]} "Print :CFBundleGetInfoString" ${gAppleHDA_Config} | ${doCommands[2]}`
${doCommands[1]} "Set :CFBundleGetInfoString '$replace'" ${gAppleHDA_Config}
replace=`${doCommands[1]} "Print :CFBundleVersion" ${gAppleHDA_Config} | ${doCommands[2]}`
${doCommands[1]} "Set :CFBundleVersion '$replace'" ${gAppleHDA_Config}
replace=`${doCommands[1]} "Print :CFBundleShortVersionString" ${gAppleHDA_Config} | ${doCommands[2]}`
${doCommands[1]} "Set :CFBundleShortVersionString '$replace'" ${gAppleHDA_Config}
${doCommands[1]} "Add ':HardwareConfigDriver_Temp' dict" ${gAppleHDA_Config}
${doCommands[1]} "Merge ${gExtensions_Repo[0]}/AppleHDA.kext/Contents/PlugIns/AppleHDAHardwareConfigDriver.kext/Contents/Info.plist ':HardwareConfigDriver_Temp'" ${gAppleHDA_Config}
${doCommands[1]} "Copy ':HardwareConfigDriver_Temp:IOKitPersonalities:HDA Hardware Config Resource' ':IOKitPersonalities:HDA Hardware Config Resource'" ${gAppleHDA_Config}
${doCommands[1]} "Delete ':HardwareConfigDriver_Temp'" ${gAppleHDA_Config}
${doCommands[1]} "Delete ':IOKitPersonalities:HDA Hardware Config Resource:HDAConfigDefault'" ${gAppleHDA_Config}
${doCommands[1]} "Delete ':IOKitPersonalities:HDA Hardware Config Resource:PostConstructionInitialization'" ${gAppleHDA_Config}
${doCommands[1]} "Add ':IOKitPersonalities:HDA Hardware Config Resource:IOProbeScore' integer" ${gAppleHDA_Config}
${doCommands[1]} "Set ':IOKitPersonalities:HDA Hardware Config Resource:IOProbeScore' 2000" ${gAppleHDA_Config}
${doCommands[1]} "Merge ${REPO}/Kexts/audio/Resources/ahhcd.plist ':IOKitPersonalities:HDA Hardware Config Resource'" ${gAppleHDA_Config}
_tidy_exec "sudo cp -RX "${gInjector_Repo}" "${gExtensions_Repo[1]}"" "Install AppleHDA_ALC668"
#
# Gain all binary patches from config.
#
gClover_kexts_to_patch_data=$(awk '/<key>KextsToPatch<\/key>.*/,/<\/array>/' ${config_plist})
#
# Added Clover patch for ALC668 in Sierra
#
# Stage 1 of 4
#
cALC668_Stage1="Enable Realtek ALC668 stage 1 of 4"
fALC668_Stage1="8408ec10"
rALC668_Stage1="00000000"
nALC668_Stage1="AppleHDA"
#
# Stage 2 of 4
#
cALC668_Stage2="Enable Realtek ALC668 stage 2 of 4"
fALC668_Stage2="8508ec10"
rALC668_Stage2="00000000"
nALC668_Stage2="AppleHDA"
#
# Stage 3 of 4
#
cALC668_Stage3="Enable Realtek ALC668 stage 3 of 4"
fALC668_Stage3="8B19D411"
rALC668_Stage3="6806ec10"
nALC668_Stage3="AppleHDA"
#
# Stage 4 of 4
#
cALC668_Stage5="Enable Realtek ALC668 stage 4 of 4"
fALC668_Stage5="8A19D411"
rALC668_Stage5="00000000"
nALC668_Stage5="AppleHDA"
#
# Chrome audio issues patch stage 1 of 2
#
cALC668_Stage6="Sleep loose sound issue patch 1 of 2"
fALC668_Stage6="41C60600 488BBB68"
rALC668_Stage6="41C60601 488BBB68"
nALC668_Stage6="AppleHDA"
#
# Chrome audio issues patch stage 2 of 2
#
cALC668_Stage7="Sleep loose sound issue patch 2 of 2"
fALC668_Stage7="41C68643 01000000"
rALC668_Stage7="41C68643 01000001"
nALC668_Stage7="AppleHDA"
#
# Now let's inject it.
#
cALC668Data=("$cALC668_Stage1" "$cALC668_Stage2" "$cALC668_Stage3" "$cALC668_Stage4" "$cALC668_Stage5" "$cALC668_Stage6" "$cALC668_Stage7")
fALC668Data=("$fALC668_Stage1" "$fALC668_Stage2" "$fALC668_Stage3" "$fALC668_Stage4" "$fALC668_Stage5" "$fALC668_Stage6" "$fALC668_Stage7")
rALC668Data=("$rALC668_Stage1" "$rALC668_Stage2" "$rALC668_Stage3" "$rALC668_Stage4" "$rALC668_Stage5" "$rALC668_Stage6" "$rALC668_Stage7")
nALC668Data=("$nALC668_Stage1" "$nALC668_Stage2" "$nALC668_Stage3" "$nALC668_Stage4" "$nALC668_Stage5" "$nALC668_Stage6" "$nALC668_Stage7")
for ((k=0; k<${#nALC668Data[@]}; ++k))
do
local gCmp_fString=$(_bin2base64 "$fALC668Data")
local gCmp_rString=$(_bin2base64 "$rALC668Data")
if [[ $gClover_kexts_to_patch_data != *"$gCmp_fString"* || $gClover_kexts_to_patch_data != *"$gCmp_rString"* ]];
then
#
# No patch existed in config.plist, add patch for it:
#
_kext2patch "${cALC668Data[k]}" "${fALC668Data[k]}" "${rALC668Data[k]}" "${nALC668Data[k]}"
fi
done
#
# Trigger /L*/E* to rebuild
#
gTriggerLE=0
}
#
#--------------------------------------------------------------------------------
#
function _initIntel()
{
if [[ `${doCommands[1]} "Print" "${config_plist}"` == *"Intel = false"* ]];
then
${doCommands[1]} "Set ':Graphics:Inject:Intel' true" "${config_plist}"
fi
}
#
#--------------------------------------------------------------------------------
#
function _getEDID()
{
#
# dump kext load status
#
local gKextStatus=$(kextstat)
#
# Whether the Intel Graphics kernel extensions are loaded in cache?
#
if [[ ${gKextStatus} == *"AppleIntelSKLGraphicsFramebuffer"* && ${gKextStatus} == *"AppleIntelSKLGraphics"* ]];
then
#
# Yes. Then we can directly assess EDID from ioreg.
#
# Get raw EDID.
#
gEDID=$(ioreg -lw0 | grep -i "IODisplayEDID" | sed -e 's/.*<//' -e 's/>//')
#
# Get native resolution(Rez) from $gEDID.
#
# Get horizontal resolution. Arrays start from 0.
#
# Examples:
#
# 00ffffffffffff004c2d240137314a4d0d1001036c221b782aaaa5a654549926145054bfef808180714f010101010101010101010101302a009851002a4030701300520e1100001e000000fd00384b1e510e000a202020202020000000fc0053796e634d61737465720a20
# ^
# ^^
# ^
# ^^
gHorizontalRez_pr=${gEDID:116:1}
gHorizontalRez_st=${gEDID:112:2}
gHorizontalRez=$((0x$gHorizontalRez_pr$gHorizontalRez_st))
#
# Get vertical resolution. Actually, Vertical rez is no more needed in this scenario, but we just use this to make the
# progress clear.
#
gVerticalRez_pr=${gEDID:122:1}
gVerticalRez_st=${gEDID:118:2}
gVerticalRez=$((0x$gVerticalRez_pr$gVerticalRez_st))
else
#
# No, we cannot assess EDID from ioreg. But now the resolution of current display has been forced to the highest resolution as vendor designed.
#
gSystemRez=$(system_profiler SPDisplaysDataType | grep -i "Resolution" | sed -e 's/.*://')
gSystemHorizontalRez=$(echo $gSystemRez | sed -e 's/x.*//')
gSystemVerticalRez=$(echo $gSystemRez | sed -e 's/.*x//')
fi
#
# Patch IOKit?
#
if [[ $gHorizontalRez -gt 1920 || $gSystemHorizontalRez -gt 1920 ]];
then
#
# Yes, We indeed require a patch to unlock the limitation of flash rate of IOKit to power up the QHD+/4K display.
#
# Note: the argument of gPatchIOKit is set to 0 as default if the examination of resolution fail, this argument can ensure all models being powered up.
#
gPatchIOKit=${kBASHReturnSuccess}
else
#
# No, patch IOKit is not required, we won't touch IOKit(for a more intergration/clean system since less is more).
#
gPatchIOKit=${kBASHReturnFailure}
fi
#
# Passing gPatchIOKit to gPatchRecoveryHD.
#
gPatchRecoveryHD=${gPatchIOKit}
}
#
#--------------------------------------------------------------------------------
#
function _unlock_pixel_clock()
{
if [ $gMINOR_VER -ge $gDelimitation_OSVer ];
then
#
# 10.12+
#
gTarget_rhd_Framework="$gMountPoint/System/Library/Frameworks/CoreDisplay.framework/Versions/Current/CoreDisplay"
else
#
# 10.12-
#
gTarget_rhd_Framework="$gMountPoint/System/Library/Frameworks/IOKit.framework/Versions/Current/IOKit"
fi
sudo perl -i.bak -pe 's|\xB8\x01\x00\x00\x00\xF6\xC1\x01\x0F\x85|\x33\xC0\x90\x90\x90\x90\x90\x90\x90\xE9|sg' ${gTarget_rhd_Framework}
_tidy_exec "sudo codesign -f -s - ${gTarget_rhd_Framework}" "Patch and sign framework for Recovery HD"
}
#
#--------------------------------------------------------------------------------
#
function _upd_EFI()
{
local gUPD=${kBASHReturnSuccess}
#
# Update EFI drivers/Clover.
#
if [ -f "$1" ];
then
local gMD_nd=$(md5 -q "$1")
else
local gUPD=${kBASHReturnFailure}
fi
#
# Target EFI/Clover files.
#
if [ -f "$2" ];
then
local gMD_nd=$(md5 -q "$2")
else
local gUPD=${kBASHReturnFailure}
fi
if [[ $gMD_st != $gMD_nd && $gUPD == ${kBASHReturnSuccess} ]];
then
#
# Yes, ne, update Clover.
#
_tidy_exec "cp "$1" "$2"" "Update $2"
fi
}
#
#--------------------------------------------------------------------------------
#
function _check_and_fix_config()
{
#
# Check if the ig-platform-id is correct(i.e. ig-platform-id = 0x19260004).
#
target_ig_platform_id="0x19260004"
gClover_ig_platform_id=$(awk '/<key>ig-platform-id<\/key>.*/,/<\/string>/' ${config_plist} | egrep -o '(<string>.*</string>)' | sed -e 's/<\/*string>//g')
#
# Added ig-platform-id injection.
#
if [ -z $gClover_ig_platform_id ];
then
${doCommands[1]} "Add ':Graphics:ig-platform-id' string" ${config_plist}
${doCommands[1]} "Set ':Graphics:ig-platform-id' $target_ig_platform_id" ${config_plist}
else
#
# ig-platform-id existed, check ig-platform-id.
#
if [[ $gClover_ig_platform_id != $target_ig_platform_id ]];
then
#
# Yes, we have to touch/modify the config.plist.
#
sed -ig "s/$gClover_ig_platform_id/$target_ig_platform_id/g" ${config_plist}
fi
fi
#
# Check SSDT-XPS13SKL.aml
#
local dCheck_SSDT="SSDT-XPS13SKL.aml"
local gSortedOrder=$(awk '/<key>SortedOrder<\/key>.*/,/<\/array>/' ${config_plist} | egrep -o '(<string>.*</string>)' | sed -e 's/<\/*string>//g')
local gSortedNumber=$(awk '/<key>SortedOrder<\/key>.*/,/<\/array>/' ${config_plist} | egrep -o '(<string>.*</string>)' | sed -e 's/<\/*string>//g' | wc -l)
if [[ $gSortedOrder != *"$dCheck_SSDT"* ]];
then
#
# $dCheck_SSDT no found. Insert it.
#
${doCommands[1]} "Add ':ACPI:SortedOrder:' string" ${config_plist}
${doCommands[1]} "Set ':ACPI:SortedOrder:$gSortedNumber' $dCheck_SSDT" ${config_plist}
fi
#
# Gain all binary patches from config.
#
if [ $gMINOR_VER -lt $gDelimitation_OSVer ];
then
#
# 10.12-, note: this detection will later remove due to optimization.
#
gClover_kexts_to_patch_data=$(awk '/<key>KextsToPatch<\/key>.*/,/<\/array>/' ${config_plist})
fi
#
# Repair the lid wake problem for 0x19260004 by syscl/lighting/Yating Zhou.
#
cLidWake_1="Enable lid wake for 0x19260004 #1 of 2 credit syscl/lighting/Yating Zhou"
fLidWake_1="0a0b0300 00070600 03000000 04000000"
rLidWake_1="0f090000 00000000 00000000 00000000"
nLidWake_1="AppleIntelSKLGraphicsFramebuffer"
cLidWake_2="Enable lid wake for 0x19260004 #2 of 2 credit syscl/lighting/Yating Zhou"
fLidWake_2="50ee1a00 00000000 00ef1a00 00000000"
rLidWake_2="50ee1a00 00000000 b0ee1a00 00000000"
nLidWake_2="AppleIntelSKLGraphicsFramebuffer"
#
# Enable 160MB BIOS, 48MB Framebuffer, 48MB Cursor for Skylake framebuffer 0x19260004.
#
cIntelGraphicsFrameBuffer="Enable 160MB BIOS, 48MB Framebuffer, 48MB Cursor for Skylake framebuffer 0x19260004"
fIntelGraphicsFrameBuffer="08002e0a 01030303 00000004 00002002 00005001"
rIntelGraphicsFrameBuffer="08002e0a 01030303 00000008 00000003 00000003"
nIntelGraphicsFrameBuffer="AppleIntelSKLGraphicsFramebuffer"
#
# Check if "Enable HD4600 HDMI Audio" is located in config.plist.
#
cHDMI="Enable HD4600 HDMI Audio"
fHDMI="3D0C0A00 00"
rHDMI="3D0C0C00 00"
nHDMI="AppleHDAController"
#
# Check if "BT4LE-Handoff-Hotspot" is in place of kextstopatch.
#
cHandoff="Enable BT4LE-Handoff-Hotspot"
fHandoff="4885ff74 47488b07"
rHandoff="41be0f00 0000eb44"
nHandoff="IOBluetoothFamily"
#
# Now let's inject it.
#
cBinData=("$cLidWake_1" "$cLidWake_2" "$cIntelGraphicsFrameBuffer" "$cHDMI" "$cHandoff")
fBinData=("$fLidWake_1" "$fLidWake_2" "$fIntelGraphicsFrameBuffer" "$fHDMI" "$fHandoff")
rBinData=("$rLidWake_1" "$rLidWake_2" "$rIntelGraphicsFrameBuffer" "$rHDMI" "$rHandoff")
nBinData=("$nLidWake_1" "$nLidWake_2" "$nIntelGraphicsFrameBuffer" "$nHDMI" "$nHandoff")
for ((j=0; j<${#nBinData[@]}; ++j))
do
local gCmp_fString=$(_bin2base64 "$fBinData")
local gCmp_rString=$(_bin2base64 "$rBinData")
if [[ $gClover_kexts_to_patch_data != *"$gCmp_fString"* || $gClover_kexts_to_patch_data != *"$gCmp_rString"* ]];
then
#
# No patch existed in config.plist, add patch for it:
#
_kext2patch "${cBinData[j]}" "${fBinData[j]}" "${rBinData[j]}" "${nBinData[j]}"
fi
done
#
# Gain boot argv.
#
local gBootArgv=$(awk '/<key>NoEarlyProgress<\/key>.*/,/<*\/>/' ${config_plist})
if [[ $gBootArgv != *"NoEarlyProgress"* ]];
then
#
# Add argv to prevent/remove "Welcome to Clover... Scan Entries" at early startup.
#
${doCommands[1]} "Add ':Boot:NoEarlyProgress' bool" "${config_plist}"
${doCommands[1]} "Set ':Boot:NoEarlyProgress' true" "${config_plist}"
else
if [[ $gBootArgv == *"false"* ]];
then
${doCommands[1]} "Set ':Boot:NoEarlyProgress' true" "${config_plist}"
fi
fi
}
#
#--------------------------------------------------------------------------------
#
function _kext2patch()
{
local comment=$1
local fBinaryEncode=$(_bin2base64 "$2")
local rBinaryEncode=$(_bin2base64 "$3")
local binary_name=$4
local gProperties_Data=("$comment" "false" "syscl" "$binary_name" "syscl")
index=$(awk '/<key>KextsToPatch<\/key>.*/,/<\/array>/' ${config_plist} | grep -i "Name" | wc -l)
#
# Inject dict with patch now.
#
${doCommands[1]} "Add ':KernelAndKextPatches:KextsToPatch:$index' dict" ${config_plist}
for ((i=0; i<${#gProperties_Name[@]}; ++i))
do
${doCommands[1]} "Add ':KernelAndKextPatches:KextsToPatch:$index:${gProperties_Name[i]}' ${gProperties_Type[i]}" ${config_plist}
${doCommands[1]} "Set ':KernelAndKextPatches:KextsToPatch:$index:${gProperties_Name[i]}' ${gProperties_Data[i]}" ${config_plist}
case "${gProperties_Name[i]}" in
Find ) sed -ig "s|c3lzY2w=|$fBinaryEncode|g" ${config_plist}
;;
Replace) sed -ig "s|c3lzY2w=|$rBinaryEncode|g" ${config_plist}
;;
esac
done
}
#
#--------------------------------------------------------------------------------
#
function _bin2base64()
{
echo $1 | xxd -r -p | base64
}
#
#--------------------------------------------------------------------------------
#
function _find_acpi()
{
#
# Search specification tables by syscl/Yating Zhou.
#
number=$(ls "${REPO}"/DSDT/raw/SSDT*.dsl | wc -l)
#
# Search DptfTa.
#
for ((index = 1; index <= ${number}; index++))
do
grep -i "DptfTa" "${REPO}"/DSDT/raw/SSDT-${index}.dsl &> /dev/null && RETURN_VAL=0 || RETURN_VAL=1
if [ "${RETURN_VAL}" == 0 ];
then
DptfTa=SSDT-${index}
fi
done
#
# Search SaSsdt.
#
for ((index = 1; index <= ${number}; index++))
do
grep -i "SaSsdt" "${REPO}"/DSDT/raw/SSDT-${index}.dsl &> /dev/null && RETURN_VAL=0 || RETURN_VAL=1
if [ "${RETURN_VAL}" == 0 ];
then
SaSsdt=SSDT-${index}
fi
done
}
#
#--------------------------------------------------------------------------------
#
function _update_clover()
{
KEXT_DIR=/Volumes/EFI/EFI/CLOVER/kexts/${gOSVer}
#
# Updating kexts. NOTE: This progress will remove any previous kexts.
#
_PRINT_MSG "--->: ${BLUE}Updating kexts...${OFF}"
_tidy_exec "rm -rf ${KEXT_DIR}" "Remove pervious kexts in ${KEXT_DIR}"
_tidy_exec "cp -R ./CLOVER/kexts/${gOSVer} /Volumes/EFI/EFI/CLOVER/kexts/" "Update kexts from ./CLOVER/kexts/${gOSVer}"
_tidy_exec "cp -R ./Kexts/*.kext ${KEXT_DIR}/" "Update kexts from ./Kexts"
#
# Decide which BT kext to use.
#
gBluetooth_Brand_String=$(ioreg | grep -i 'BCM' | grep -i 'Apple' | sed -e 's/.*-o //' -e 's/@.*//')
#
# Try to build injector instead of using BrcmPatchRAM.kext
#
if [[ `ioreg` == *"BCM20702A3"* ]];
then
#
# BCM20702A3 found.
#
_tidy_exec "rm -R ${KEXT_DIR}/BrcmFirmwareRepo.kext" "BCM20702A3 found"
else
#
# BCM2045A0 found. We remove BrcmFirmwareData.kext to prevent this driver crashes the whole system during boot.
#
_tidy_exec "rm -R ${KEXT_DIR}/BrcmFirmwareData.kext" "BCM2045A0 found"
fi
#
# Decide which kext to be installed for BT.
#
if [[ $gMINOR_VER -ge 11 ]];
then
#
# OS X is 10.11+.
#
_tidy_exec "rm -R ${KEXT_DIR}/BrcmPatchRAM.kext" "Remove redundant BT driver::BrcmPatchRAM.kext"
else
#
# OS X is 10.10-.
#
_tidy_exec "rm -R ${KEXT_DIR}/BrcmPatchRAM2.kext" "Remove redundant BT driver::BrcmPatchRAM2.kext"
fi
#
# gEFI.
#
drvEFI=("FSInject-64.efi" "HFSPlus.efi" "OsxAptioFix2Drv-64.efi" "OsxFatBinaryDrv-64.efi" "DataHubDxe-64.efi")
efiTOOL=("Shell.inf" "Shell32.efi" "Shell64.efi" "Shell64U.efi" "bdmesg-32.efi" "bdmesg.efi")
#
# Check if necessary to update Clover.
#
for filename in "${drvEFI[@]}"
do
_upd_EFI "${drivers64UEFI}/${filename}" "${t_drivers64UEFI}/${filename}"
done
for filename in "${efiTOOL[@]}"
do
_upd_EFI "${clover_tools}/${filename}" "${t_clover_tools}/${filename}"
done
#
# Update CLOVERX64.efi
#
_upd_EFI "${REPO}/CLOVER/CLOVERX64.efi" "/Volumes/EFI/EFI/CLOVER/CLOVERX64.efi"
}
#
#--------------------------------------------------------------------------------
#
function _update_thm()
{
if [ -d /Volumes/EFI/EFI/CLOVER/themes/bootcamp ];
then
if [[ `cat /Volumes/EFI/EFI/CLOVER/themes/bootcamp/theme.plist` != *"syscl"* ]];
then
#
# Yes we need to update themes.
#
_del /Volumes/EFI/EFI/CLOVER/themes/bootcamp
cp -R ${REPO}/CLOVER/themes/BootCamp /Volumes/EFI/EFI/CLOVER/themes
fi
fi
}
#
#--------------------------------------------------------------------------------
#
function _printUSBSleepConfig()
{
_del ${gUSBSleepConfig}
echo '<?xml version="1.0" encoding="UTF-8"?>' > "$gUSBSleepConfig"
echo '<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">' >> "$gUSBSleepConfig"
echo '<plist version="1.0">' >> "$gUSBSleepConfig"
echo '<dict>' >> "$gUSBSleepConfig"
echo ' <key>KeepAlive</key>' >> "$gUSBSleepConfig"
echo ' <true/>' >> "$gUSBSleepConfig"
echo ' <key>Label</key>' >> "$gUSBSleepConfig"
echo ' <string>com.syscl.externalfix.sleepwatcher</string>' >> "$gUSBSleepConfig"
echo ' <key>ProgramArguments</key>' >> "$gUSBSleepConfig"
echo ' <array>' >> "$gUSBSleepConfig"
echo ' <string>/usr/local/sbin/sleepwatcher</string>' >> "$gUSBSleepConfig"
echo ' <string>-V</string>' >> "$gUSBSleepConfig"
echo ' <string>-s /etc/sysclusbfix.sleep</string>' >> "$gUSBSleepConfig"
echo ' <string>-w /etc/sysclusbfix.wake</string>' >> "$gUSBSleepConfig"
echo ' </array>' >> "$gUSBSleepConfig"
echo ' <key>RunAtLoad</key>' >> "$gUSBSleepConfig"
echo ' <true/>' >> "$gUSBSleepConfig"
echo '</dict>' >> "$gUSBSleepConfig"
echo '</plist>' >> "$gUSBSleepConfig"
}
#
#--------------------------------------------------------------------------------
#
function _createUSB_Sleep_Script()
{
#
# Remove previous script.
#
_del ${gUSBSleepScript}
echo '#!/bin/sh' > "$gUSBSleepScript"
echo '#' >> "$gUSBSleepScript"
echo '# This script aims to unmount all external devices automatically before sleep.' >> "$gUSBSleepScript"
echo '#' >> "$gUSBSleepScript"
echo '# Without this procedure, various computers with OS X/Mac OS X(even on a real Mac) suffer from "Disk not ejected properly"' >> "$gUSBSleepScript"
echo '# issue when there're external devices plugged-in. That's the reason why I created this script to fix this issue. (syscl/lighting/Yating Zhou)' >> "$gUSBSleepScript"
echo '#' >> "$gUSBSleepScript"
echo '# All credit to Bernhard Baehr ([email protected]), without his great sleepwatcher dameon, this fix will not be created.' >> "$gUSBSleepScript"
echo '#' >> "$gUSBSleepScript"
echo '' >> "$gUSBSleepScript"
echo '#' >> "$gUSBSleepScript"
echo '# Added unmount Disk for "OS X" (c) syscl/lighting/Yating Zhou.' >> "$gUSBSleepScript"
echo '#' >> "$gUSBSleepScript"
echo 'gMountPartition="/tmp/com.syscl.externalfix"' >> "$gUSBSleepScript"
echo 'gDisk=($(diskutil list | grep -i "External" | sed -e "s| (external, physical):||" -e "s|\/dev\/||"))' >> "$gUSBSleepScript"
echo '' >> "$gUSBSleepScript"
echo 'for ((i=0; i<${#gDisk[@]}; ++i))' >> "$gUSBSleepScript"
echo 'do' >> "$gUSBSleepScript"
echo ' gCurrent_Partitions=($(diskutil list ${gDisk[i]} |grep -o "disk[0-9]s[0-9]"))' >> "$gUSBSleepScript"
echo ' for ((k=0; k<${#gCurrent_Partitions[@]}; ++k))' >> "$gUSBSleepScript"
echo ' do' >> "$gUSBSleepScript"
echo ' gConfirm_Mounted=$(diskutil info ${gCurrent_Partitions[k]} |grep -i 'Mounted' |sed -e "s| Mounted:||" -e "s| ||g")' >> "$gUSBSleepScript"
echo ' if [[ ${gConfirm_Mounted} == *"Yes"* ]];' >> "$gUSBSleepScript"
echo ' then' >> "$gUSBSleepScript"
echo ' echo ${gCurrent_Partitions[k]} >> ${gMountPartition}' >> "$gUSBSleepScript"
echo ' fi' >> "$gUSBSleepScript"
echo ' done' >> "$gUSBSleepScript"
echo 'done' >> "$gUSBSleepScript"
echo '' >> "$gUSBSleepScript"
echo 'diskutil list | grep -i "External" | sed -e "s| (external, physical):||" | xargs -I {} diskutil eject {}' >> "$gUSBSleepScript"
echo '' >> "$gUSBSleepScript"
#
# Add detection for RTLWlan USB
#
echo '#' >> "$gUSBSleepScript"
echo '# Fix RTLWlanUSB sleep problem credit B1anker & syscl/lighting/Yating Zhou. @PCBeta.' >> "$gUSBSleepScript"
echo '#' >> "$gUSBSleepScript"
echo '' >> "$gUSBSleepScript"
echo "gRTWlan_kext=$(echo $gRTWlan_kext)" >> "$gUSBSleepScript"
echo 'gMAC_adr=$(ioreg -rc $gRTWlan_kext | sed -n "/IOMACAddress/ s/.*= <\(.*\)>.*/\1/ p")' >> "$gUSBSleepScript"
echo '' >> "$gUSBSleepScript"