forked from piCorePlayer/pCP-Kernels
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pcp_prepare_kernel_src
executable file
·179 lines (156 loc) · 5.24 KB
/
pcp_prepare_kernel_src
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
#!/bin/sh
. /etc/init.d/tc-functions
checknotroot
usage() {
echo ""
echo "Usage: $(basename $0) -k <kernel release> -s <path to kernel source>"
echo " -k Build for kernel xxx. Will default to running kernel version if not set."
echo " current kernel name is $(uname -r)"
echo " -s This is the location of the kernel source. Will clone pCP kernel repo if needed"
echo ""
exit 2
}
trimval() {
echo $1 | cut -d '=' -f2 | xargs
}
while getopts k:s: OPTION; do
case ${OPTION} in
k) K_VER=${OPTARG} ;;
s) DIR=$(readlink -f ${OPTARG})
if [ "$DIR" = "" ]; then
LINUX_SRC_DIR=${OPTARG}
else
LINUX_SRC_DIR=$(readlink -f ${OPTARG})
fi
;;
*) usage ;;
esac
done
[ "$LINUX_SRC_DIR" = "" ] && usage
KERNELVER=${K_VER:-$(uname -r)}
if [ ! -d $LINUX_SRC_DIR ]; then
mkdir -p $LINUX_SRC_DIR
if [ $? -ne 0 ]; then
echo "Error creating src dir"
exit 1
fi
DIR=$(readlink -f $LINUX_SRC_DIR)
LINUX_SRC_DIR=${DIR}
fi
if [ ! -w $LINUX_SRC_DIR ]; then
echo "Kernel source dir is not writtable. Check permissions"
exit 1
fi
echo "[ INFO ] Preparing kernel for version: $KERNELVER"
echo "[ INFO ] piCore Repo Version: $PICOREVER"
echo "[ INFO ] Saving Kernel sources to: $LINUX_SRC_DIR"
echo "[ INFO ] Loading Build dependancies"
STD_DEPS=""
BUILD_DEPS="compiletc squashfs-tools perl5 openssl-dev git bash"
TCZ_DEPS=""
DEV_TCZ_DEPS=""
FULL_DEPS="$STD_DEPS $BUILD_DEPS"
for deps in $FULL_DEPS; do
tce-status -i | grep -q ${deps%.*}
if [ $? -ne 0 ]; then
if [ ! -f /etc/sysconfig/tcedir/optional/$deps.tcz ]; then
echo "Downloading $deps"
tce-load -w $deps
fi
tce-load -i $deps >/dev/null 2>&1
if [ $? -eq 0 ]; then
echo "[ INFO ] Loaded $deps..."
else
echo "[ ERROR ] Failed to load $deps... exiting"
exit 1
fi
fi
done
### Get linux source
if [ -f $LINUX_SRC_DIR/Makefile ]; then
#Check to see if the source is the right version
while read LINE; do
case $LINE in
VERSION*) VERSION=$(trimval "${LINE}");;
PATCHLEVEL*) PATCHLEVEL=$(trimval "${LINE}");;
SUBLEVEL*) SUBLEVEL=$(trimval "${LINE}");;
NAME*) break;;
*);;
esac
done < $LINUX_SRC_DIR/Makefile
CURRENTKERNELSRC="$VERSION.$PATCHLEVEL.$SUBLEVEL"
if [ $(echo $KERNELVER | cut -d'-' -f1) = "$CURRENTKERNELSRC" ]; then
echo "[ INFO ] Kernel source directory is the correct version"
KSRC="OK"
else
echo "[ ERROR] Source directory is not the correct version, please select a new directory"
exit 1
fi
fi
if [ "$KSRC" != "OK" ]; then
KSRC="rpi-$(echo $KERNELVER | cut -d'-' -f1)-pcpPatched.zip"
echo "[ INFO ] Downloading linux source from pCP github($KSRC)."
wget -c https://github.com/piCorePlayer/linux/archive/refs/heads/$KSRC -P /tmp
if [ $? -ne 0 ]; then
echo "[ ERROR ] Error getting kernel source"
exit 1
fi
echo "[ INFO ] Extracting kernel source to $LINUX_SRC_DIR"
unzip -q -d "$LINUX_SRC_DIR" "/tmp/$KSRC"
cd $LINUX_SRC_DIR/linux*
if [ -f Makefile ]; then
ls -A1 | xargs -r -I {} mv {} ..
cd ..
rmdir linux-*
rm /tmp/$KSRC
else
echo "Linux source not found"
exit 1
fi
fi
KBASE=$(echo $KERNELVER | awk -F'.' '{ print $1 "." $2 }')
KREVISION=$(echo $KERNELVER | awk -F'-' '{ print $1 }')
SYM_REPO="https://github.com/piCorePlayer/pCP-Kernels/raw/master/${KBASE}/${KREVISION}"
### Get Symbols.
echo "[ INFO ] Downloading symbols from ${SYM_REPO}/${KERNELVER}"
if [ ! -f /tmp/config.xz ]; then
busybox wget ${SYM_REPO}/${KERNELVER}_.config.xz -O /tmp/config.xz
[ $? -ne 0 ] && (echo "[ERROR] config archive not found."; exit 1)
fi
if [ ! -f /tmp/Module.symvers.xz ]; then
busybox wget ${SYM_REPO}/${KERNELVER}_Module.symvers.xz -O /tmp/Module.symvers.xz
[ $? -ne 0 ] && (echo "[ERROR] symvers archive not found."; exit 1)
fi
if [ ! -f /tmp/System.map.xz ]; then
busybox wget ${SYM_REPO}/${KERNELVER}_System.map.xz -O /tmp/System.map.xz
[ $? -ne 0 ] && (echo "[ERROR] System.map archive not found."; exit 1)
fi
cd $LINUX_SRC_DIR
echo "[ INFO ] Cleaning linux source tree"
make -s mrproper
echo "[ INFO ] Copying configs and symbols"
xz -d -kc /tmp/config.xz > .config
xz -d -kc /tmp/System.map.xz > System.map
xz -d -kc /tmp/Module.symvers.xz > Module.symvers
sudo rm /lib/modules/${KERNELVER}/build
[ ! -d /lib/modules/${KERNELVER} ] && sudo mkdir -p /lib/modules/${KERNELVER}
sudo ln -sv $LINUX_SRC_DIR /lib/modules/${KERNELVER}/build
echo "[ INFO ] Preparing Kernel"
make -s -j4 KERNELRELEASE=$KERNELVER scripts
make -s -j4 KERNELRELEASE=$KERNELVER modules_prepare
touch /tmp/mark
MARK=$(ls -l /tmp/mark |awk -F' ' '{print $6 " " $7 " " $8}')
export KVER=$KERNELVER
echo "[ INFO ] Setting mark timestamp to $MARK. This allows finding installed files after build"
echo " If you perform multiple driver installations, please run \"touch /tmp/mark\" beore"
echo " running \"make\" for your driver."
echo ""
echo "[ INFO ] Now download source for your driver, cd to the root directory of the driver"
echo " read the the pCP-KERNEL readme.md, edit the Makefile, and then build the"
echo " driver by running \"make\" KVER=$KERNELVER -j<number of jobs>"
echo ""
echo "[ INFO ] If the driver is successfully built, then from the driver source directory, run"
echo " pcp_make_module_extension -k $KERNELVER -e <name of extension>"
echo ""
echo " i.e. pcp_make_module_extension -k $KERNELVER -e rtl8812au"
echo ""