-
Notifications
You must be signed in to change notification settings - Fork 73
/
Deploy.sh
executable file
·2246 lines (2012 loc) · 90.3 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
#
# (c) 2017-2018 syscl @ https://github.com/syscl
# 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"
export MG_DEBUG=0
#
# 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
#
gESPMountPoint=""
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=""
#gConfigBuffer=$(cat ${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=""
clover_tools="${REPO}/CLOVER/tools"
t_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}
# get increment version e.g. 10.x.y => y
gINCR_VER=$(printf ${gProductVer} | awk -F. '{print $NF}')
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=""
gModelType=1 # 0 stands for non-Iris model, 1 stands for Iris model
#
# 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=("/Library/Extensions" "/System/Library/Extensions")
gInjector_Repo="/tmp/AppleHDA_ALC256.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
# contains(string, substring)
#
# Returns 0 if the specified string contains the specified substring,
# otherwise returns 1.
function contains() {
string="$1"
substring="$2"
if test "${string#*$substring}" != "$string"
then
return 0 # $substring is in $string
else
return 1 # $substring is not in $string
fi
}
#
# Get Current OS ver
#
current_OSVer=`sw_vers -productVersion`
contains "${current_OSVer}" "10.12"
if [ "$?" -eq "0" ]; then
isSierra=1 #true: MacOS Sierra
else
isSierra=0 #false: MacOS High Sierra
fi
#
# 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 -i "Recovery HD" |grep -i -o "disk[0-9]s[0-9]"
}
#
#--------------------------------------------------------------------------------
#
function _getESPMntPoint()
{
local gESPIndentifier="$1"
gESPMountPoint=$(diskutil info ${gESPIndentifier} |grep -i 'Mount Point' |grep -i -o "/.*")
}
#
#--------------------------------------------------------------------------------
#
function _setESPVariable()
{
config_plist="${gESPMountPoint}/EFI/CLOVER/config.plist"
t_drivers64UEFI="${gESPMountPoint}/EFI/CLOVER/drivers64UEFI"
t_clover_tools="${gESPMountPoint}/EFI/CLOVER/tools"
}
#
#--------------------------------------------------------------------------------
#
function _touch()
{
local target_file=$1
if [ ! -d ${target_file} ];
then
_tidy_exec "mkdir -p ${target_file}" "Create ${target_file}"
fi
}
#
#--------------------------------------------------------------------------------
#
function patch_acpi()
{
#
# create a backup of current error-free DSDT
#
cp "${REPO}"/DSDT/raw/$1.dsl "${REPO}"/DSDT/raw/$1_backup.dsl
#
# apply the patch
#
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
#
# check if patched DSDT has errors
#
"${REPO}"/tools/iasl -vr -p "${REPO}"/DSDT/raw/$1temp.aml "${REPO}"/DSDT/raw/$1.dsl
if [ -e "${REPO}"/DSDT/raw/$1temp.aml ]
then
rm "${REPO}"/DSDT/raw/$1temp.aml
rm "${REPO}"/DSDT/raw/$1_backup.dsl
else
_PRINT_MSG "NOTE: $3 was not applied as it was causing errors."
rm "${REPO}"/DSDT/raw/$1.dsl
mv "${REPO}"/DSDT/raw/$1_backup.dsl "${REPO}"/DSDT/raw/$1.dsl
fi
}
function patch_acpi_force()
{
#
# apply the patch
#
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 -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 /
sudo kextcache -i /
}
#
#--------------------------------------------------------------------------------
#
function rebuild_dyld_shared_cache()
{
#
# rebuild dyld_shared_cache to resolve display framework issues
#
sudo update_dyld_shared_cache -force
}
#
#--------------------------------------------------------------------------------
#
function install_audio()
{
#
# Remove previous AppleHDA_ALC256.kext & CodecCommander.kext
# Note: don't use cp/mv directly, in macOS, you have to use rm then cp! syscl
#
for extensions in ${gExtensions_Repo[@]}
do
_del $extensions/AppleHDA_ALC256.kext
_del $extensions/CodecCommander.kext
done
_del /Library/LaunchAgents/com.XPS.ComboJack.plist
_del /usr/local/sbin/ComboJack
if [ $gMINOR_VER -ge $gDelimitation_OSVer ];
then
#
# 10.12+
#
#_install_AppleHDA_Injector
#install combo-jack
bash ${REPO}/Kexts/combojack/ComboJack_Installer/install.sh
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} | perl -Xpi -e 's/(\d*\.\d*)/9\1/'`
${doCommands[1]} "Set :NSHumanReadableCopyright '$replace'" ${gAppleHDA_Config}
replace=`${doCommands[1]} "Print :CFBundleGetInfoString" ${gAppleHDA_Config} | perl -Xpi -e 's/(\d*\.\d*)/9\1/'`
${doCommands[1]} "Set :CFBundleGetInfoString '$replace'" ${gAppleHDA_Config}
replace=`${doCommands[1]} "Print :CFBundleVersion" ${gAppleHDA_Config} | perl -Xpi -e 's/(\d*\.\d*)/9\1/'`
${doCommands[1]} "Set :CFBundleVersion '$replace'" ${gAppleHDA_Config}
replace=`${doCommands[1]} "Print :CFBundleShortVersionString" ${gAppleHDA_Config} | perl -Xpi -e 's/(\d*\.\d*)/9\1/'`
${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}
#
# Cause high CPU percentage occupation, don't use this
#
# ${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[0]}"" "Install AppleHDA_ALC256"
_tidy_exec "sudo cp -RX "${REPO}/Kexts/audio/CodecCommander.kext" "${gExtensions_Repo[0]}"" "Fix headphone static issue"
#
# Gain all binary patches from config.
#
gClover_kexts_to_patch_data=$(awk '/<key>KextsToPatch<\/key>.*/,/<\/array>/' ${config_plist})
#
# Added Clover patch for ALC256 in Sierra
#
# Enable Realtek ALC256 1/5
#
cALC256_Stage1="Enable Realtek ALC256 1/5"
fALC256_Stage1="6102EC10"
rALC256_Stage1="00000000"
nALC256_Stage1="AppleHDA"
#
# Enable Realtek ALC256 2/5
#
cALC256_Stage2="Enable Realtek ALC256 2/5"
fALC256_Stage2="6202EC10"
rALC256_Stage2="00000000"
nALC256_Stage2="AppleHDA"
#
# Enable Realtek ALC256 3/5
#
cALC256_Stage3="Enable Realtek ALC256 3/5"
fALC256_Stage3="8508EC10"
rALC256_Stage3="00000000"
nALC256_Stage3="AppleHDA"
#
# Enable Realtek ALC256 4/5
#
cALC256_Stage5="Enable Realtek ALC256 4/5"
fALC256_Stage5="8419D411"
rALC256_Stage5="5602EC10"
nALC256_Stage5="AppleHDA"
#
# Enable Realtek ALC256 5/5
#
cALC256_Stage5="Enable Realtek ALC256 5/5"
fALC256_Stage5="8319D411"
rALC256_Stage5="00000000"
nALC256_Stage5="AppleHDA"
#
# Now let's inject it.
#
cALC256Data=("$cALC256_Stage1" "$cALC256_Stage2" "$cALC256_Stage3" "$cALC256_Stage4" "$cALC256_Stage5")
fALC256Data=("$fALC256_Stage1" "$fALC256_Stage2" "$fALC256_Stage3" "$fALC256_Stage4" "$fALC256_Stage5")
rALC256Data=("$rALC256_Stage1" "$rALC256_Stage2" "$rALC256_Stage3" "$rALC256_Stage4" "$rALC256_Stage5")
nALC256Data=("$nALC256_Stage1" "$nALC256_Stage2" "$nALC256_Stage3" "$nALC256_Stage4" "$nALC256_Stage5")
for ((k=0; k<${#nALC256Data[@]}; ++k))
do
local gCmp_fString=$(_bin2base64 "$fALC256Data")
local gCmp_rString=$(_bin2base64 "$rALC256Data")
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 "${cALC256Data[k]}" "${fALC256Data[k]}" "${rALC256Data[k]}" "${nALC256Data[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/CoreDisplay?
#
local gIntelGraphicsCardInfo=$(ioreg -lw0 |grep -i "Intel Iris Graphics" |sed -e "/[^<]*<\"/s///" -e "s/\"\>//")
if [[ "${gIntelGraphicsCardInfo}" != *"Iris"* ]] && [[ $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 under non-Iris version
#
# 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/CoreDisplay (for a more clean system).
#
gPatchIOKit=${kBASHReturnFailure}
fi
#
# Passing gPatchIOKit to gPatchRecoveryHD.
#
gPatchRecoveryHD=${gPatchIOKit}
}
#
#--------------------------------------------------------------------------------
#
function _unlock_pixel_clock()
{
#
# $1 for the mount point
#
# Patch CoreDisplay/IOKit
#
_PRINT_MSG "--->: ${BLUE}Unlocking maximum pixel clock...${OFF}"
if [ $gMINOR_VER -ge $gDelimitation_OSVer ]; then
#
# 10.12+
#
gTarget_Framework_Repo="$1/System/Library/Frameworks/CoreDisplay.framework/Versions/Current/CoreDisplay"
else
#
# 10.12-
#
gTarget_Framework_Repo="$1/System/Library/Frameworks/IOKit.framework/Versions/Current/IOKit"
fi
if [[ $gMINOR_VER -ge 13 && $gINCR_VER -ge 4 ]]; then
# 10.13.4+
sudo perl -i.bak -pe 's|\xBB\xE6\x02\x00\xE0\x85\xC0|\xBB\xE6\x02\x00\xE0\x31\xC0|sg' ${gTarget_Framework_Repo}
sudo perl -i.bak -pe 's|\x85\xC0\xBB\xE6\x02\x00\xE0|\x31\xC0\xBB\xE6\x02\x00\xE0|sg' ${gTarget_Framework_Repo}
else
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_Framework_Repo}
fi
_tidy_exec "sudo codesign -f -s - ${gTarget_Framework_Repo}" "Patch and sign CoreDisplay/IOKit framework"
#
# rebuild dyld_shared_cache to resolve display framework issues
#
_tidy_exec "sudo update_dyld_shared_cache -force" "Update dyld shared cache"
}
#
#--------------------------------------------------------------------------------
#
function _hwpArgvChk()
{
gRm_SSDT_pr=${kBASHReturnFailure}
gCp_SSDT_pr=${kBASHReturnFailure}
#
# hwp enable is ready
#
local ghwpArgvChk=$(grep -i -A 1 "HWPEnable" ${config_plist})
if [[ "${ghwpArgvChk}" == *"true"* ]]; then
#
# hwp is enable, disable old style power management
#
gRm_SSDT_pr=${kBASHReturnSuccess}
gCp_SSDT_pr=${kBASHReturnSuccess}
fi
}
#
#--------------------------------------------------------------------------------
#
function _setModelType()
{
#
# set model type
#
local gCPUInfo=$(sysctl machdep.cpu.brand_string |sed -e "/.*) /s///" -e "/ CPU.*/s///")
if [[ ${gCPUInfo} == *"i7-6560U"* ]];
then
#
# Iris version(i7-6560U)
#
_PRINT_MSG "NOTE: Your laptop is Iris version(${BLUE}${gCPUInfo}${OFF})"
gModelType=1
else
#
# Non-Iris version(i5-6200U, i7-6500U)
#
_PRINT_MSG "NOTE: Your laptop is non-Iris version(${BLUE}${gCPUInfo}${OFF})"
gModelType=0
fi
}
#
#--------------------------------------------------------------------------------
#
function _setPlatformId()
{
if [ ${gModelType} == 1 ];
then
#
# Iris version(i7-6560U)
#
target_ig_platform_id="0x19260004"
else
#
# Non-Iris version(i5-6200U, i7-6500U)
#
target_ig_platform_id="0x19160000"
fi
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
}
#
#--------------------------------------------------------------------------------
#
function _check_and_fix_config()
{
#
# Check if tinySSDT items are existed
#
local dCheck_SSDT=("SSDT-XPS13SKL" "SSDT-ARPT-RP05" "SSDT-XHC" "SSDT-PNLF" "SSDT-ALC256")
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)
for tinySSDT in "${dCheck_SSDT[@]}"
do
if [[ $gSortedOrder != *"${tinySSDT}"* ]]; then
#
# tinySSDT no found, insert it
#
${doCommands[1]} "Add ':ACPI:SortedOrder:' string" ${config_plist}
${doCommands[1]} "Set ':ACPI:SortedOrder:$gSortedNumber' ${tinySSDT}.aml" ${config_plist}
fi
#
# Index changed, increment by 1
#
((gSortedNumber++))
done
#
# Gain all binary patches from config.
#
gClover_kexts_to_patch_data=$(awk '/<key>KextsToPatch<\/key>.*/,/<\/array>/' ${config_plist})
if [ $gMINOR_VER -ge $gDelimitation_OSVer ];
then
if [ $isSierra -eq 1 ];
then
#
# Repair the lid wake problem for 0x19260004 by syscl/lighting/Yating Zhou.
#
cLidWake="Enable lid wake for 0x19260004 credit syscl/lighting/Yating Zhou"
fLidWake="0a0b0300 00070600 03000000 04000000"
rLidWake="0f0b0300 00070600 03000000 04000000"
nLidWake="AppleIntelSKLGraphicsFramebuffer"
#
# eDP, port 0000, 0x19160000 credit syscl
#
cIntelGraphicsFrameBuffer="eDP, port 0000, 0x19160000 credit syscl"
fIntelGraphicsFrameBuffer="00000000 00000000 00000800 02000000 98040000"
rIntelGraphicsFrameBuffer="00000000 00000000 00000800 00040000 98040000"
nIntelGraphicsFrameBuffer="AppleIntelSKLGraphicsFramebuffer"
#
# 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" "$cIntelGraphicsFrameBuffer" "$cHandoff")
fBinData=("$fLidWake" "$fIntelGraphicsFrameBuffer" "$fHandoff")
rBinData=("$rLidWake" "$rIntelGraphicsFrameBuffer" "$rHandoff")
nBinData=("$nLidWake" "$nIntelGraphicsFrameBuffer" "$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
else
#
# 10.13 config.plist patches
#
local gHeaderFix=$(awk '/<key>FixHeaders<\/key>.*/,/<*\/>/' ${config_plist})
if [[ $gHeaderFix != *"FixHeaders"* ]];
then
#
# Add FixHeaders_20000000 to Clover (Needed to boot High Sierra)
#
${doCommands[1]} "Add ':ACPI:DSDT:Fixes:FixHeaders' bool" "${config_plist}"
${doCommands[1]} "Set ':ACPI:DSDT:Fixes:FixHeaders' true" "${config_plist}"
else
if [[ $gHeaderFix == *"false"* ]];
then
${doCommands[1]} "Set ':ACPI:DSDT:Fixes:FixHeaders' true" "${config_plist}"
fi
fi
fi
fi
#
# 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
#
# Search sensrhub
#
for ((index = 1; index <= ${number}; index++))
do
grep -i "sensrhub" "${REPO}"/DSDT/raw/SSDT-${index}.dsl &> /dev/null && RETURN_VAL=0 || RETURN_VAL=1
if [ "${RETURN_VAL}" == 0 ]; then
sensrhub=SSDT-${index}
fi
done
#
# Search FACP
#
FACP=FACP
#
# Tables to be eliminated: Ther_Rvp, CpuSsdt, Cpu0Cst, ApCst, Cpu0Hwp, ApHwp, HwpLvt
#
# Search sensrhub
#
for ((index = 1; index <= ${number}; index++))
do
grep -i "Ther_Rvp" "${REPO}"/DSDT/raw/SSDT-${index}.dsl &> /dev/null && RETURN_VAL=0 || RETURN_VAL=1