Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·169 lines (147 loc) · 3.75 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·169 lines (147 loc) · 3.75 KB
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
#!/usr/bin/env bash
set -e
# set -x
PWD=$(pwd)
SRC_DIR=${SRC_DIR:-${PWD}/src/linux}
BUILD_DIR=/lib/modules/"$(uname -r)"/build
SUBDIR="drivers/net/wireless/ath"
PATCH_FILES=(
'402-ath_regd_optional.patch'
'406-ath_relax_default_regd.patch'
)
usage() {
cat <<-EOF
$0 COMMAND
Available commands:
prepare_patches
Download OpenWrt patches and modify them for building against
a normal Linux kernel.
download_src [KVER]
Try to download a Linux source tarball from kernel.org which
matches the running kernel version (or KVER if specified).
patch_src
Apply the kernel patches.
build
Build all the kernel modules under '$SUBDIR'.
install
Install the kernel modules and strip debug symbols.
dkms_{ build | install | remove }
Perform the indicated function through DKMS.
EOF
exit 1
}
_get_kernel_version() {
KVER=${1:-$(uname -r)}
KARR=($(sed -E 's/^([0-9])\.([0-9]+)\.?([0-9]+)?.*/\1 \2 \3/' <<< $KVER))
KMAJ=${KARR[0]}
KMIN=${KARR[1]}
KREV=${KARR[2]}
MODULE_VERSION=${KMAJ}.${KMIN}
}
download_src() {
if { env | grep -q SRC_DIR ; } ; then
printf "SRC_DIR set in environment, skipping download\n"
return 0
fi
_get_kernel_version "$1"
KERNEL_SRC=linux-${KMAJ}.${KMIN}.tar.xz
mkdir -p $SRC_DIR
test -f src/$KERNEL_SRC || {
printf "Download %s from kernel.org\n" $KERNEL_SRC
wget -q https://cdn.kernel.org/pub/linux/kernel/v${KMAJ}.x/${KERNEL_SRC} -O src/${KERNEL_SRC}
}
printf "Extract kernel source to %s\n" $SRC_DIR
tar xf src/${KERNEL_SRC} --strip-components=1 -C $SRC_DIR
printf "Kernel source extracted successfully\n"
}
prepare_patches() {
mkdir -p patches
for patch in "${PATCH_FILES[@]}"; do
wget -q "https://git.openwrt.org/?p=openwrt/openwrt.git;a=blob_plain;f=package/kernel/mac80211/patches/ath/${patch};hb=refs/heads/master" -O patches/${patch}
done
patch --strip 1 <patches/0001-patch-the-patches.patch
}
patch_src() {
for patch in "${PATCH_FILES[@]}"; do
patch --directory $SRC_DIR --strip 1 <"patches/$patch"
done
}
build_modules() {
cp "${BUILD_DIR}/.config" "${SRC_DIR}/"
cp "${BUILD_DIR}/Module.symvers" "${SRC_DIR}/"
make -C "${SRC_DIR}" olddefconfig
make -j"$(nproc)" -C "${BUILD_DIR}" M="${SRC_DIR}/${SUBDIR}"
}
install_modules() {
make -C "$BUILD_DIR" M="${SRC_DIR}/${SUBDIR}" KERNELRELEASE="$(uname -r)" \
INSTALL_MOD_PATH="${PWD}/build" \
INSTALL_MOD_DIR=updates \
modules_install
}
strip_debug() {
printf "Stripping debug symbols\n"
find $SRC_DIR -name "*.ko" -exec strip -g {} \;
}
dkms_build() {
_get_kernel_version "$1"
printf "Add and build DKMS module v%s for running kernel\n" "$MODULE_VERSION"
rsync -a src/linux/ patches dkms_*.sh /usr/src/ath_user_regd-${MODULE_VERSION}/
sed -E "s/(PACKAGE_VERSION=)/\1${MODULE_VERSION}/" dkms.conf > /usr/src/ath_user_regd-${MODULE_VERSION}/dkms.conf
dkms build "ath_user_regd/${MODULE_VERSION}"
}
dkms_install() {
_get_kernel_version "$1"
printf "Install DKMS module v%s for running kernel\n" "$MODULE_VERSION"
dkms install "ath_user_regd/${MODULE_VERSION}"
}
dkms_remove() {
_get_kernel_version "$1"
printf "Remove DKMS module v%s\n" "$MODULE_VERSION"
dkms remove "ath_user_regd/${MODULE_VERSION}" || true
rm -rf /usr/src/ath_user_regd-${MODULE_VERSION}
rm -rf /var/lib/dkms/ath_user_regd/${MODULE_VERSION}
}
main() {
# prepare_patches
download_src
patch_src
build_modules
install_modules
strip_debug
}
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
case $1 in
prepare_patches)
prepare_patches
;;
download_src)
shift
download_src "$1"
;;
patch_src)
patch_src
;;
build)
build_modules
;;
install)
strip_debug
install
;;
dkms_build)
shift
dkms_build "$1"
;;
dkms_install)
shift
dkms_install "$1"
;;
dkms_remove)
shift
dkms_remove "$1"
;;
*)
usage
;;
esac
fi