-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-kernel
executable file
·297 lines (264 loc) · 9.34 KB
/
build-kernel
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
#!/bin/bash
set -e
if [[ -f ${HOME}/.ragnar.rc ]]; then
source ${HOME}/.ragnar.rc
else
TOP=${TOP:-"${HOME}/ragnar-artifacts"}
fi
mkdir -p ${TOP}
NUM_CPUS=${NUM_CPUS:-"$(getconf _NPROCESSORS_ONLN)"}
KDIR=${KDIR:-$(pwd)}
clean_build=0
build_deb_packages=0
build_kselftests=0
#ARCH=arm64
git_describe=$(git describe --long)
KERNEL_VERSION="linux-mainline"
VIRTIO_STUFF=0
usage() {
echo -e "$0's help text"
echo -e " -a ARCH, specify the architecture to build, default: arm64"
echo -e " -c, cleanup output and staging dir before building, default: 0"
echo -e " -d CONFIG_URL, specify a url to a config file,"
echo -e " default: ${CONFIG_URL}"
echo -e " -k KERNEL_VERSION, kernel version that you want to build, default: linux-mainline"
echo -e " KERNEL_VERSION's to choose from:"
echo -e " linux-mainline,"
echo -e " linux-next,"
echo -e " linux-stable-4.14,"
echo -e " ..."
echo -e " -i defconfig, defconfig to build in the src tree"
echo -e " -m MACHINE, add machine name"
echo -e " -p, build deb packages"
echo -e " -s, build kselftests, default: 0"
echo -e " -v, enable virtio stuff, default: 0"
echo -e " -h, prints out this help"
}
MAKE() {
make CROSS_COMPILE=${CROSS_COMPILE} ARCH=${ARCH} KDIR=${KDIR} O=${OUTPUT} "$@" ;
}
fixing_for_kvm() {
configfile=$1
# VIRTIO
sed -i 's/CONFIG_VIRTIO=.*/CONFIG_VIRTIO=y/g' $configfile
sed -i 's/CONFIG_VIRTIO_BALLOON=.*/CONFIG_VIRTIO_BALLOON=y/g' $configfile
sed -i 's/CONFIG_BLK_MQ_VIRTIO=.*/CONFIG_BLK_MQ_VIRTIO=y/g' $configfile
sed -i 's/CONFIG_SCSI_VIRTIO=.*/CONFIG_SCSI_VIRTIO=y/g' $configfile
sed -i 's/CONFIG_VIRTIO_BLK=.*/CONFIG_VIRTIO_BLK=y/g' $configfile
sed -i 's/CONFIG_VIRTIO_CONSOLE=.*/CONFIG_VIRTIO_CONSOLE=y/g' $configfile
sed -i 's/CONFIG_VIRTIO_INPUT=.*/CONFIG_VIRTIO_INPUT=y/g' $configfile
sed -i 's/CONFIG_VIRTIO_MENU=.*/CONFIG_VIRTIO_MENU=y/g' $configfile
sed -i 's/CONFIG_VIRTIO_MMIO=.*/CONFIG_VIRTIO_MMIO=y/g' $configfile
sed -i 's/CONFIG_VIRTIO_NET=.*/CONFIG_VIRTIO_NET=y/g' $configfile
sed -i 's/CONFIG_VIRTIO_PCI=.*/CONFIG_VIRTIO_PCI=y/g' $configfile
sed -i 's/CONFIG_VIRTIO_PCI_LEGACY=.*/CONFIG_VIRTIO_PCI_LEGACY=y/g' $configfile
sed -i 's/# CONFIG_VIRTIO is.*/CONFIG_VIRTIO=y/g' $configfile
sed -i 's/# CONFIG_VIRTIO_BALLOON is.*/CONFIG_VIRTIO_BALLOON=y/g' $configfile
sed -i 's/# CONFIG_BLK_MQ_VIRTIO is.*/CONFIG_BLK_MQ_VIRTIO=y/g' $configfile
sed -i 's/# CONFIG_SCSI_VIRTIO is.*/CONFIG_SCSI_VIRTIO=y/g' $configfile
sed -i 's/# CONFIG_VIRTIO_BLK is.*/CONFIG_VIRTIO_BLK=y/g' $configfile
sed -i 's/# CONFIG_VIRTIO_CONSOLE is.*/CONFIG_VIRTIO_CONSOLE=y/g' $configfile
sed -i 's/# CONFIG_VIRTIO_INPUT is.*/CONFIG_VIRTIO_INPUT=y/g' $configfile
sed -i 's/# CONFIG_VIRTIO_MENU is.*/CONFIG_VIRTIO_MENU=y/g' $configfile
sed -i 's/# CONFIG_VIRTIO_MMIO is.*/CONFIG_VIRTIO_MMIO=y/g' $configfile
sed -i 's/# CONFIG_VIRTIO_NET is.*/CONFIG_VIRTIO_NET=y/g' $configfile
sed -i 's/# CONFIG_VIRTIO_PCI is.*/CONFIG_VIRTIO_PCI=y/g' $configfile
sed -i 's/# CONFIG_VIRTIO_PCI_LEGACY is.*/CONFIG_VIRTIO_PCI_LEGACY=y/g' $configfile
sed -i 's/CONFIG_BLK_SCSI_REQUEST=.*/CONFIG_BLK_SCSI_REQUEST=y/g' $configfile
sed -i 's/CONFIG_VIRTIO_BLK_SCSI=.*/CONFIG_VIRTIO_BLK_SCSI=y/g' $configfile
sed -i 's/CONFIG_SCSI=.*/CONFIG_SCSI=y/g' $configfile
sed -i 's/CONFIG_SCSI_MOD=.*/CONFIG_SCSI_MOD=y/g' $configfile
sed -i 's/CONFIG_SCSI_DMA=.*/CONFIG_SCSI_DMA=y/g' $configfile
sed -i 's/# CONFIG_BLK_SCSI_REQUEST is.*/CONFIG_BLK_SCSI_REQUEST=y/g' $configfile
sed -i 's/# CONFIG_VIRTIO_BLK_SCSI is.*/CONFIG_VIRTIO_BLK_SCSI=y/g' $configfile
sed -i 's/# CONFIG_SCSI is.*/CONFIG_SCSI=y/g' $configfile
sed -i 's/# CONFIG_SCSI_MOD is.*/CONFIG_SCSI_MOD=y/g' $configfile
sed -i 's/# CONFIG_SCSI_DMA is.*/CONFIG_SCSI_DMA=y/g' $configfile
# NEEDED
sed -i 's/CONFIG_EXT4_FS=.*/CONFIG_EXT4_FS=y/g' $configfile
sed -i 's/# CONFIG_EXT4_FS is .*/CONFIG_EXT4_FS=y/g' $configfile
}
while getopts "a:cd:hk:i:m:psv" arg; do
case $arg in
a)
ARCH="$OPTARG"
;;
c)
clean_build=1
;;
d)
CONFIG_URL="$OPTARG"
;;
k)
KERNEL_VERSION="$OPTARG"
;;
i)
DEFCONFIG_FILENAME="$OPTARG"
;;
m)
MACHINE="$OPTARG"
;;
p)
build_deb_packages=1
;;
s)
build_kselftests=1
;;
v)
VIRTIO_STUFF=1
;;
h|*)
usage
exit 0
;;
esac
done
which_machine() {
case ${MACHINE} in
am57xx-evm)
ARCH=arm
CONFIG_URL=${CONFIG_URL:-"http://snapshots.linaro.org/openembedded/lkft/rocko/${MACHINE}/rpb/${KERNEL_VERSION}/latest/config"}
image_name=zImage
dtb_name="am57xx-beagle-x15"
;;
hikey)
ARCH=arm64
CONFIG_URL=${CONFIG_URL:-"http://snapshots.linaro.org/openembedded/lkft/rocko/${MACHINE}/rpb/${KERNEL_VERSION}/latest/config"}
image_name=Image
dtb_name="hi6220-hikey"
;;
intel-core2-32|intel-corei7-64)
ARCH=x86
CONFIG_URL=${CONFIG_URL:-"http://snapshots.linaro.org/openembedded/lkft/rocko/${MACHINE}/rpb/${KERNEL_VERSION}/latest/config"}
image_name=bzImage
;;
*)
usage
exit 1
;;
esac
OUTPUT=${OUTPUT:-"${TOP}/build_output/${ARCH}/${git_describe}"}
STAGING=${STAGING:-"${TOP}/staging/${ARCH}/${git_describe}"}
}
if [ $(grep -c "^WHAT IS LINUX" README) -ne 1 ] &&
[ $(grep -c "^Linux kernel" README) -ne 1 ]; then
echo -e "ERROR: Need to run this script $(basename $0),"
echo -e " from a kernel repository"
echo ""
usage
exit 1
fi
which_arch() {
case $ARCH in
arm)
[[ $(uname -m) == 'armv7l' ]] || CROSS_COMPILE=${CROSS_COMPILE:-"arm-linux-gnueabihf-"}
;;
arm64)
[[ $(uname -m) == 'aarch64' ]] || CROSS_COMPILE=${CROSS_COMPILE:-"aarch64-linux-gnu-"}
;;
x86)
[[ $(uname -m) == 'x86_64' ]] || CROSS_COMPILE=${CROSS_COMPILE:-"x86_64-linux-gnu-"}
;;
*)
esac
}
clean_build() {
if [[ $clean_build -eq 1 ]]; then
echo "Cleaning up output and staging dir before building!"
rm -rf ${OUTPUT}
rm -rf ${STAGING}
fi
}
create_dir() {
mkdir -p ${OUTPUT}
mkdir -p ${STAGING}
}
choose_config() {
if [[ -z ${DEFCONFIG_FILENAME} ]]; then
curl -sSL -o .config ${CONFIG_URL}
#echo CONFIG_MODULES=y >> .config
else
MAKE -j ${NUM_CPUS} ${DEFCONFIG_FILENAME} 2>&1 | tee ${STAGING}/make_config.log
fi
}
add_virtio() {
if [[ ${VIRTIO_STUFF} -eq 1 ]]; then
fixing_for_kvm .config
fi
}
make_config() {
MAKE -j ${NUM_CPUS} olddefconfig 2>&1 | tee ${STAGING}/make_config.log
rm .config
cp -f ${OUTPUT}/.config ${STAGING}/kernel-${git_describe}.config
}
make_build() {
MAKE -j ${NUM_CPUS} 2>&1 | tee ${STAGING}/make_build.log
}
make_dtb() {
if [[ -d arch/${ARCH}/boot/dts ]]; then
MAKE -j ${NUM_CPUS} INSTALL_DTBS_PATH=${STAGING}/dtbs dtbs_install 2>&1 | tee ${STAGING}/make_dts.log
for file in $(find ${STAGING}/dtbs -type f -name '*.dtb') ; do
if [[ ! $(basename ${file}) =~ ${git_describe}.dtb ]]; then
new_file=$(printf '%s\n' "${file%.dtb}-${git_describe}.dtb");
mv ${file} ${new_file}
fi
done
fi
if [[ ${ARCH} != "x86" ]]; then
cp -f $(find ${STAGING} -type f -name "*${dtb_name}-${git_describe}.dtb") ${STAGING}/
fi
}
make_modules() {
if [[ $(grep CONFIG_MODULES=y ${OUTPUT}/.config) ]]; then
MAKE -j ${NUM_CPUS} INSTALL_MOD_PATH=${STAGING} modules_install 2>&1 | tee ${STAGING}/make_modules.log
pushd ${STAGING}
tar -zcf modules-$(basename ${STAGING}).tar.gz lib/
popd
fi
}
make_image() {
MAKE -j ${NUM_CPUS} ${image_name} 2>&1 | tee ${STAGING}/make_image.log
cp -f ${OUTPUT}/arch/${ARCH}/boot/${image_name} ${STAGING}/${image_name}-${git_describe}
}
make_deb_packages() {
if [[ $build_deb_packages -eq 1 ]]; then
MAKE -j ${NUM_CPUS} bindeb-pkg 2>&1 | tee ${STAGING}/make_deb-pkg.log
mv -f ${OUTPUT}/../*$(basename ${OUTPUT} |awk -F'-' '{print $1-$2}')*.* ${STAGING}
fi
}
make_kselftests() {
if [[ $build_kselftests -eq 1 ]]; then
MAKE -C tools/testing/selftests 2>&1 | tee ${STAGING}/make_kselftest.log
MAKE -C tools/testing/selftests install 2>&1 | tee ${STAGING}/make_kselftest_install.log
fi
}
which_machine
which_arch
clean_build
create_dir
choose_config
add_virtio
make_config
make_build
make_dtb
make_modules
make_image
make_deb_packages
make_kselftests
echo ""
echo ""
echo "If build warnings or errors, they will be printed below:"
echo ""
echo ""
grep -i -A 4 -B 1 "\(warning\|error\):" ${STAGING}/make_build.log
echo ""
echo ""
if [[ $(grep CONFIG_MODULES=y ${OUTPUT}/.config) ]]; then
grep -i -A 4 -B 1 "\(warning\|error\):" ${STAGING}/make_modules.log
fi
echo ""
echo ""
if [[ $build_kselftests -eq 1 ]]; then
grep -i -A 4 -B 1 "\(warning\|error\):" ${STAGING}/make_kselftest.log
fi
## vim: set sw=4 sts=4 et foldmethod=syntax : ##