-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeb-build-kernel
More file actions
executable file
·379 lines (338 loc) · 8.49 KB
/
deb-build-kernel
File metadata and controls
executable file
·379 lines (338 loc) · 8.49 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
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
#!/bin/bash -eu
#
# Build Debian kernel packages
#
function debian_arch()
{
case "${1}" in
amd64|x86_64) echo "amd64" ;;
arm64) echo "arm64" ;;
armhf|arm) echo "armhf" ;;
ppc64el|powerpc) echo "ppc64el" ;;
riscv64|riscv) echo "riscv64" ;;
s390x|s390) echo "s390x" ;;
*)
echo "Invalid architecture: ${1}" >&2
exit 1
;;
esac
}
function kernel_arch()
{
case "${1}" in
amd64|x86_64) echo "x86_64" ;;
arm64) echo "arm64" ;;
armhf|arm) echo "arm" ;;
ppc64el|powerpc) echo "powerpc" ;;
riscv64|riscv) echo "riscv" ;;
s390x|s390) echo "s390" ;;
*)
echo "Invalid architecture: ${1}" >&2
exit 1
;;
esac
}
function run()
{
local cmd
cmd=()
if [ -n "${SCHROOT}" ] ; then
cmd=("schroot" "-p" "-r" "-c" "${SCHROOT}" "--")
fi
cmd+=("${@}")
echo "-- Run: ${cmd[*]}"
if [ "${DRY_RUN}" -eq 0 ] ; then
"${cmd[@]}"
fi
}
function usage()
{
cat <<EOF
Usage: deb-build-kernel [-a ARCH] [-b ABI] [-c CPUS] [-d] [-g] [-h] [-l] [-n]
[-o CFG:VAL] [-s SCHROOT] [-v VERSION]
TARGET [-- ARGS...]
Build Debian kernel packages.
Positional arguments:
TARGET Build target (see below).
ARGS Additional arguments passed to kernel make. If not
provided, defaults to 'bindeb-pkg' (to build binary
Debian packages).
Supported TARGETs:
v6 Build an ARMv6 32-bit kernel.
v7 Build an ARMv7 32-bit kernel.
v7l Build an ARMv7 32-bit LPAE kernel.
v8 Build an ARMv8 64-bit kernel.
<defconfig> Build a kernel using the provided defconfig.
<arch>-<flavor> Build a kernel using the Ubuntu kernel config file.
<config_file> Build a kernel using the provided config file.
Optional arguments:
-a, --arch ARCH Kernel architecture.
-b, --abi ABI Kernel ABI number. If not provided, defaults to 9000.
-c, --cpus CPUS Number of CPUs to use for compiling. If not provided,
defaults to the number of online CPUs.
-d, --dry-run
-g, --dbg-pkg Enable build of kernel debug package.
-h, --help Show this help text and exit.
-l, --clean Run 'make clean' before the build.
-n, --config-only Only create the kernel config.
-o, --config CFG:VAL Set kernel config option CFG to value VAL.
Possible values for VAL:
e: Enable option
d: Disable option
m: Turn option into a module
u: Undefine option
s=foo: Set option to string 'foo'
v=bar: Set option to value bar
-s, --schroot SCHROOT Name of the schroot session to run the build in.
-v, --version VERSION
-x, --debug Set -x.
EOF
}
DRY_RUN=0
SCHROOT=
arch=$(dpkg-architecture -q DEB_HOST_ARCH)
abi=9000
cpus=$(getconf _NPROCESSORS_ONLN)
dbg_pkg=0
clean=0
config_only=0
configs=()
version=
target=
args=("bindeb-pkg")
while [ ${#} -gt 0 ] ; do
case "${1}" in
-a|--arch)
shift
arch=${1}
;;
-b|--abi)
shift
abi=${1}
;;
-c|--cpus)
shift
cpus=${1}
;;
-d|--dry-run)
DRY_RUN=1
;;
-g|--dbg-pkg)
dbg_pkg=1
;;
-h|--help)
usage
exit
;;
-l|--clean)
clean=1
;;
-n|--config-only)
config_only=1
;;
-o|--config)
shift
configs+=("${1}")
;;
-s|--schroot)
shift
SCHROOT=${1}
;;
-v|--version)
shift
version=${1}
;;
-x|--debug)
set -x
;;
--)
shift
args=("${@}")
break
;;
*)
if [ -n "${target}" ] ; then
echo "Invalid argument: ${1}" >&2
exit 2
fi
target=${1}
;;
esac
shift
done
if [ -z "${target}" ] ; then
usage
exit 2
fi
config=
subdir=
if [ -e "${target}" ] ; then
arch=$(sed -n 's,# Linux/,,p' "${target}" | sed 's, .*,,')
config=${target}
subdir=${target##*/}
else
case "${target}" in
v6)
arch=arm
config=bcmrpi_defconfig
version=v6
subdir=v6
;;
v7)
arch=arm
config=bcm2709_defconfig
version=v7
subdir=v7
;;
v7l)
arch=arm
config=bcm2711_defconfig
version=v7l
subdir=v7l
;;
v8)
arch=arm64
config=bcm2711_defconfig
version=v8
subdir=v8
;;
*defconfig)
config=${target}
subdir=${target}
;;
*-*)
arch=${target%%-*}
flavor=${target#*-}
config=UBUNTU
version=${abi}-${flavor}
subdir=${flavor}
;;
*)
echo "Invalid targt: ${target}" >&2
exit 2
;;
esac
fi
# Debian architecture name
arch=$(debian_arch "${arch}")
# Set environment variables for the build
ARCH=$(kernel_arch "${arch}")
CROSS_COMPILE=$(dpkg-architecture -a "${arch}" -q DEB_HOST_GNU_TYPE \
2>/dev/null)-
export ARCH CROSS_COMPILE
echo "-- Set ARCH=${ARCH} CROSS_COMPILE=${CROSS_COMPILE}"
# ----------------------------------------------------------------------------
# Initialize the build environment
# Initialize the build directory
buildd=$(pwd)/buildd/${ARCH}/${subdir}
if ! [ -d "${buildd}" ] ; then
mkdir -p "${buildd}"
fi
# Do some cleaning up first
if [ ${clean} -eq 1 ] ; then
run make O="${buildd}" clean
fi
# Initialize the build version
if ! [ -e "${buildd}"/.version ] ; then
echo 1 > "${buildd}"/.version
fi
# ----------------------------------------------------------------------------
# Generate the kernel config file
if [ "${config}" = "UBUNTU" ] ; then
echo "-- Use Ubuntu config ${arch}-${flavor}"
#run fakeroot ./debian/rules clean genconfigs || true
#cp CONFIGS/"${arch}"-config.flavour."${flavor}"
if [ ${DRY_RUN} -eq 0 ] ; then
run python3 ./debian/scripts/misc/annotations \
--arch "${arch}" --flavour "${flavor}" --export > \
"${buildd}"/.config
else
run python3 ./debian/scripts/misc/annotations \
--arch "${arch}" --flavour "${flavor}" --export \> \
"${buildd}"/.config
fi
elif [ -f "${config}" ] ; then
echo "-- Use config ${config}"
cp "${config}" "${buildd}"/.config
else
echo "-- Use config ${ARCH}/${config}"
run make O="${buildd}" "${config}"
fi
# ----------------------------------------------------------------------------
# Modify the kernel config file
# Disable the build of the debug package
if [ ${dbg_pkg} -eq 0 ] ; then
echo "-- Disable debug package"
configs+=("DEBUG_INFO:u")
configs+=("DEBUG_INFO_NONE:e")
fi
# Purge the local version
configs+=("LOCALVERSION:s=")
# Set/modify additional options
config_cmds=()
for cfg_val in "${configs[@]}" ; do
cfg=${cfg_val%%:*}
val=${cfg_val#*:}
case "${val}" in
e) config_cmds+=("-e" "${cfg}") ;;
d) config_cmds+=("-d" "${cfg}") ;;
m) config_cmds+=("-m" "${cfg}") ;;
u) config_cmds+=("-u" "${cfg}") ;;
s=*) config_cmds+=("--set-str" "${cfg}" "${val#*=}") ;;
v=*) config_cmds+=("--set-val" "${cfg}" "${val#*=}") ;;
*)
echo "-- Ignore invalid config option: ${cfg_val}" >&2
continue
;;
esac
done
if [ ${#config_cmds[@]} -gt 0 ] ; then
run ./scripts/config --file "${buildd}"/.config "${config_cmds[@]}"
fi
run make O="${buildd}" olddefconfig
if [ ${config_only} -eq 1 ] ; then
echo
echo "-- Kernel config written to ${buildd}/.config"
exit
fi
# ----------------------------------------------------------------------------
# Generate kernel and package versions
kernel_version=$(make -k kernelversion 2>/dev/null)
build_version=$(head -1 "${buildd}"/.version)
#abi_version=$((abi + build_version))
curr_commit=$(git rev-parse HEAD)
# FIXME
#if [ -n "${flavor}" ] ; then
# local_version=-${abi_version}-${flavor}
# pkg_version=${kernel_version}-${abi_version}+git${curr_commit::8}
#else
# if [ -n "${version}" ] ; then
# local_version=-${version}
# else
# local_version=
# fi
# pkg_version=${kernel_version}-${build_version}+git${curr_commit::8}
#fi
local_version=${version#-}
if [ -n "${local_version}" ] ; then
local_version=-${local_version}
fi
pkg_version=${kernel_version}-${build_version}+git${curr_commit::8}
echo "-- Kernel version: ${kernel_version}${local_version}"
echo "-- Package version: ${pkg_version}"
# ----------------------------------------------------------------------------
# Do the build
if [ "${config}" = "UBUNTU" ] ; then
# Generate signing and revocation certs
run fakeroot debian/rules clean
fi
make_opts=(
"O=${buildd}"
"LOCALVERSION=${local_version}"
"KDEB_PKGVERSION=${pkg_version}"
"-j${cpus}"
"${args[@]}"
)
run make "${make_opts[@]}" 2>&1 | tee deb-build-kernel.log
echo
echo "-- Debian packages: ${buildd%/*}/linux-*_${pkg_version}_${arch}.*"