forked from davidjo/snd_hda_macbookpro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.cirrus.driver.sh
executable file
·268 lines (217 loc) · 8.31 KB
/
install.cirrus.driver.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
#!/bin/bash
# NOTA BENE - this script should be run as root
set -e
while [ $# -gt 0 ]
do
case $1 in
-i|--install) dkms_action='install';;
-k|--kernel) UNAME=$2; [[ -z $UNAME ]] && echo '-k|--kernel must be followed by a kernel version' && exit 1;;
-r|--remove) dkms_action='remove';;
-u|--uninstall) dkms_action='remove';;
(-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
(*) break;;
esac
shift
done
UNAME=${1:-$(uname -r)}
kernel_version=$(echo $UNAME | cut -d '-' -f1) #ie 5.2.7
major_version=$(echo $kernel_version | cut -d '.' -f1)
minor_version=$(echo $kernel_version | cut -d '.' -f2)
major_minor=${major_version}${minor_version}
revision=$(echo $UNAME | cut -d '.' -f3)
revpart1=$(echo $revision | cut -d '-' -f1)
revpart2=$(echo $revision | cut -d '-' -f2)
revpart3=$(echo $revision | cut -d '-' -f3)
if [ $major_version -eq 5 -a $minor_version -lt 13 ]; then
sed -i 's/^BUILT_MODULE_NAME\[0\].*$/BUILT_MODULE_NAME[0]="snd-hda-codec-cirrus"/' dkms.conf
PATCH_CIRRUS=true
else
sed -i 's/^BUILT_MODULE_NAME\[0\].*$/BUILT_MODULE_NAME[0]="snd-hda-codec-cs8409"/' dkms.conf
PATCH_CIRRUS=false
fi
if [[ $dkms_action == 'install' ]]; then
bash dkms.sh
# note that Ubuntu, Debian, Fedora and others (see dkms man page) install to updates/dkms
# and ignore DEST_MODULE_LOCATION
# we DO want updates so that the original module is not overwritten
# (although the original module should be copied to under /var/lib/dkms if needed for other distributions)
update_dir="/lib/modules/${UNAME}/updates"
echo -e "\ncontents of $update_dir/dkms"
ls -lA $update_dir/dkms
exit
elif [[ $dkms_action == 'remove' ]]; then
bash dkms.sh -r
exit
fi
if [ $major_version == '4' ]; then
echo "Kernel 4 versions no longer supported"
fi
if [ $major_version -eq 5 -a $minor_version -lt 8 ]; then
echo "Kernel 5 versions less than 5.8 no longer supported"
fi
isdebian=0
isfedora=0
isarch=0
isvoid=0
if [ -d /usr/src/linux-headers-${UNAME} ]; then
# Debian Based Distro
isdebian=1
:
elif [ -d /usr/src/kernels/${UNAME} ]; then
# Fedora Based Distro
isfedora=1
:
elif [ -d /usr/lib/modules/${UNAME} ]; then
# Arch Based Distro
isarch=1
:
elif [ -d /usr/src/kernel-headers-${UNAME} ]; then
# Void Linux
isvoid=1
:
else
echo "linux kernel headers not found:"
echo "Debian (eg Ubuntu): /usr/src/linux-headers-${UNAME}"
echo "Fedora: /usr/src/kernels/${UNAME}"
echo "Arch: /usr/lib/modules/${UNAME}"
echo "Void: /usr/src/kernel-headers-${UNAME}"
echo "assuming the linux kernel headers package is not installed"
echo "please install the appropriate linux kernel headers package:"
echo "Debian/Ubuntu: sudo apt install linux-headers-${UNAME}"
echo "Fedora: sudo dnf install kernel-headers"
echo "Arch (also Manjaro): Linux: sudo pacman -S linux-headers"
echo "Void Linux: xbps-install -S linux-headers"
exit 1
fi
# note that the update_dir definition below relies on a symbolic link of /lib to /usr/lib on Arch
cur_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
build_dir='build'
patch_dir="$cur_dir/patch_cirrus"
hda_dir="$cur_dir/$build_dir/hda"
update_dir="/lib/modules/${UNAME}/updates"
[[ -d $hda_dir ]] && rm -rf $hda_dir
[[ ! -d $build_dir ]] && mkdir $build_dir
# fedora doesnt seem to install patch by default so need to explicitly install it
if [ $isfedora -ge 1 ]; then
echo "Ensure the patch package is installed"
[[ ! $(command -v patch) ]] && dnf install -y patch
fi
# we need to handle Ubuntu based distributions eg Mint here
isubuntu=0
if [ $(grep '^NAME=' /etc/os-release | grep -c Ubuntu) -eq 1 ]; then
isubuntu=1
fi
if [ $(grep '^NAME=' /etc/os-release | grep -c "Linux Mint") -eq 1 ]; then
isubuntu=1
fi
if [ $isubuntu -ge 1 ]; then
# NOTE for Ubuntu we need to use the distribution kernel sources as they seem
# to be significantly modified from the mainline kernel sources generally with backports from later kernels
# (so far the actual debian kernels seem to be close to mainline kernels)
# NOTA BENE this will likely NOT work for Ubuntu hwe kernels which are even more highly
# modified with extensive backports from later kernel versions
# (and in any case there is no linux-source-... package for hwe kernels)
if [ ! -e /usr/src/linux-source-$kernel_version.tar.bz2 ]; then
echo "Ubuntu linux kernel source not found in /usr/src: /usr/src/linux-source-$kernel_version.tar.bz2"
echo "assuming the linux kernel source package is not installed"
echo "please install the linux kernel source package:"
echo "sudo apt install linux-source-$kernel_version"
echo "NOTE - This does not work for HWE kernels"
exit 1
fi
tar --strip-components=3 -xvf /usr/src/linux-source-$kernel_version.tar.bz2 --directory=build/ linux-source-$kernel_version/sound/pci/hda
else
# here we assume the distribution kernel source is essentially the mainline kernel source
set +e
# attempt to download linux-x.x.x.tar.xz kernel
wget -c https://cdn.kernel.org/pub/linux/kernel/v$major_version.x/linux-$kernel_version.tar.xz -P $build_dir
if [[ $? -ne 0 ]]; then
echo "Failed to download linux-$kernel_version.tar.xz"
echo "Trying to download base kernel version linux-$major_version.$minor_version.tar.xz"
echo "This may lead to build failures as too old"
echo "If this is an Ubuntu-based distribution this almost certainly will fail to build"
echo ""
# if first attempt fails, attempt to download linux-x.x.tar.xz kernel
kernel_version=$major_version.$minor_version
wget -c https://cdn.kernel.org/pub/linux/kernel/v$major_version.x/linux-$kernel_version.tar.xz -P $build_dir
[[ $? -ne 0 ]] && echo "kernel could not be downloaded...exiting" && exit
fi
set -e
tar --strip-components=3 -xvf $build_dir/linux-$kernel_version.tar.xz --directory=build/ linux-$kernel_version/sound/pci/hda
fi
mv $hda_dir/Makefile $hda_dir/Makefile.orig
cp $patch_dir/Makefile $patch_dir/patch_cirrus_* $hda_dir
pushd $hda_dir > /dev/null
# define the ubuntu/mainline versions that work at the moment
# for ubuntu allow a range of revisions that work
current_major=5
current_minor=19
current_minor_ubuntu=15
current_rev_ubuntu=47
latest_rev_ubuntu=71
iscurrent=0
if [ $isubuntu -ge 1 ]; then
if [ $major_version -gt $current_major ]; then
iscurrent=2
elif [ $major_version -eq $current_major -a $minor_version -gt $current_minor_ubuntu ]; then
iscurrent=2
elif [ $major_version -eq $current_major -a $minor_version -eq $current_minor_ubuntu -a $revpart2 -gt $latest_rev_ubuntu ]; then
iscurrent=2
elif [ $major_version -eq $current_major -a $minor_version -eq $current_minor_ubuntu -a $revpart2 -gt $current_rev_ubuntu ]; then
iscurrent=1
elif [ $major_version -eq $current_major -a $minor_version -eq $current_minor_ubuntu -a $revpart2 -eq $current_rev_ubuntu ]; then
iscurrent=1
else
iscurrent=-1
fi
else
if [ $major_version -gt $current_major ]; then
iscurrent=2
elif [ $major_version -eq $current_major -a $minor_version -gt $current_minor ]; then
iscurrent=2
elif [ $major_version -eq $current_major -a $minor_version -eq $current_minor ]; then
iscurrent=1
else
iscurrent=-1
fi
fi
if [ $iscurrent -gt 1 ]; then
echo "Kernel version later than implemented version - there may be build problems"
fi
if [ $major_version -eq 5 -a $minor_version -lt 13 ]; then
patch -b -p2 <../../patch_patch_cirrus.c.diff
else
if [ $isubuntu -ge 1 ]; then
patch -b -p2 <../../patch_patch_cs8409.c.diff
if [ $iscurrent -ge 0 ]; then
patch -b -p2 <../../patch_patch_cs8409.h.diff
else
patch -b -p2 <../../patches/patch_patch_cs8409.h.ubuntu.pre51547.diff
fi
if [ $iscurrent -ge 0 ]; then
patch -b -p2 <../../patch_patch_cirrus_apple.h.diff
fi
else
patch -b -p2 <../../patch_patch_cs8409.c.diff
if [ $iscurrent -ge 0 ]; then
patch -b -p2 <../../patch_patch_cs8409.h.diff
else
patch -b -p2 <../../patches/patch_patch_cs8409.h.main.pre519.diff
fi
cp $patch_dir/Makefile $patch_dir/patch_cirrus_* $hda_dir/
if [ $iscurrent -ge 0 ]; then
patch -b -p2 <../../patch_patch_cirrus_apple.h.diff
fi
fi
fi
popd > /dev/null
[[ ! $dkms_action == 'install' ]] && [[ ! -d $update_dir ]] && mkdir $update_dir
if [ $PATCH_CIRRUS = true ]; then
make PATCH_CIRRUS=1
make install PATCH_CIRRUS=1
else
make KERNELRELEASE=$UNAME
make install KERNELRELEASE=$UNAME
fi
echo -e "\ncontents of $update_dir"
ls -lA $update_dir