CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/scripts/compilation.sh
Views: 3960
1
#!/bin/bash
2
#
3
# Copyright (c) 2013-2021 Igor Pecovnik, igor.pecovnik@gma**.com
4
#
5
# This file is licensed under the terms of the GNU General Public
6
# License version 2. This program is licensed "as is" without any
7
# warranty of any kind, whether express or implied.
8
9
10
# Functions:
11
12
# compile_atf
13
# compile_uboot
14
# compile_kernel
15
# compile_firmware
16
# compile_orangepi-config
17
# compile_sunxi_tools
18
# install_rkbin_tools
19
# grab_version
20
# find_toolchain
21
# advanced_patch
22
# process_patch_file
23
# userpatch_create
24
# overlayfs_wrapper
25
26
27
28
29
compile_atf()
30
{
31
if [[ $CLEAN_LEVEL == *make* ]]; then
32
display_alert "Cleaning" "$ATFSOURCEDIR" "info"
33
(cd "${EXTER}/cache/sources/${ATFSOURCEDIR}"; make distclean > /dev/null 2>&1)
34
fi
35
36
if [[ $USE_OVERLAYFS == yes ]]; then
37
local atfdir
38
atfdir=$(overlayfs_wrapper "wrap" "$EXTER/cache/sources/$ATFSOURCEDIR" "atf_${LINUXFAMILY}_${BRANCH}")
39
else
40
local atfdir="$EXTER/cache/sources/$ATFSOURCEDIR"
41
fi
42
cd "$atfdir" || exit
43
44
display_alert "Compiling ATF" "" "info"
45
46
# build aarch64
47
if [[ $(dpkg --print-architecture) == amd64 ]]; then
48
49
local toolchain
50
toolchain=$(find_toolchain "$ATF_COMPILER" "$ATF_USE_GCC")
51
[[ -z $toolchain ]] && exit_with_error "Could not find required toolchain" "${ATF_COMPILER}gcc $ATF_USE_GCC"
52
53
if [[ -n $ATF_TOOLCHAIN2 ]]; then
54
local toolchain2_type toolchain2_ver toolchain2
55
toolchain2_type=$(cut -d':' -f1 <<< "${ATF_TOOLCHAIN2}")
56
toolchain2_ver=$(cut -d':' -f2 <<< "${ATF_TOOLCHAIN2}")
57
toolchain2=$(find_toolchain "$toolchain2_type" "$toolchain2_ver")
58
[[ -z $toolchain2 ]] && exit_with_error "Could not find required toolchain" "${toolchain2_type}gcc $toolchain2_ver"
59
fi
60
61
# build aarch64
62
fi
63
64
display_alert "Compiler version" "${ATF_COMPILER}gcc $(eval env PATH="${toolchain}:${PATH}" "${ATF_COMPILER}gcc" -dumpversion)" "info"
65
66
local target_make target_patchdir target_files
67
target_make=$(cut -d';' -f1 <<< "${ATF_TARGET_MAP}")
68
target_patchdir=$(cut -d';' -f2 <<< "${ATF_TARGET_MAP}")
69
target_files=$(cut -d';' -f3 <<< "${ATF_TARGET_MAP}")
70
71
advanced_patch "atf" "${ATFPATCHDIR}" "$BOARD" "$target_patchdir" "$BRANCH" "${LINUXFAMILY}-${BOARD}-${BRANCH}"
72
73
# create patch for manual source changes
74
[[ $CREATE_PATCHES == yes ]] && userpatch_create "atf"
75
76
echo -e "\n\t== atf ==\n" >> "${DEST}"/${LOG_SUBPATH}/compilation.log
77
# ENABLE_BACKTRACE="0" has been added to workaround a regression in ATF.
78
# Check: https://github.com/armbian/build/issues/1157
79
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${toolchain2}:${PATH}" \
80
'make ENABLE_BACKTRACE="0" $target_make $CTHREADS \
81
CROSS_COMPILE="$CCACHE $ATF_COMPILER"' 2>> "${DEST}"/${LOG_SUBPATH}/compilation.log \
82
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/${LOG_SUBPATH}/compilation.log'} \
83
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Compiling ATF..." $TTY_Y $TTY_X'} \
84
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
85
86
[[ ${PIPESTATUS[0]} -ne 0 ]] && exit_with_error "ATF compilation failed"
87
88
[[ $(type -t atf_custom_postprocess) == function ]] && atf_custom_postprocess
89
90
atftempdir=$(mktemp -d)
91
chmod 700 ${atftempdir}
92
trap "rm -rf \"${atftempdir}\" ; exit 0" 0 1 2 3 15
93
94
# copy files to temp directory
95
for f in $target_files; do
96
local f_src
97
f_src=$(cut -d':' -f1 <<< "${f}")
98
if [[ $f == *:* ]]; then
99
local f_dst
100
f_dst=$(cut -d':' -f2 <<< "${f}")
101
else
102
local f_dst
103
f_dst=$(basename "${f_src}")
104
fi
105
[[ ! -f $f_src ]] && exit_with_error "ATF file not found" "$(basename "${f_src}")"
106
cp "${f_src}" "${atftempdir}/${f_dst}"
107
done
108
109
# copy license file to pack it to u-boot package later
110
[[ -f license.md ]] && cp license.md "${atftempdir}"/
111
}
112
113
compile_uboot()
114
{
115
116
if [[ ${BOARDFAMILY} == "sun50iw9" && ${BRANCH} =~ legacy|current && $(dpkg --print-architecture) == arm64 ]]; then
117
118
local uboot_name=${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb
119
display_alert "Compile u-boot is not supported, only copy precompiled deb package" "$uboot_name" "info"
120
cp "${EXTER}/cache/debs/h618/$uboot_name" "${DEB_STORAGE}/u-boot/"
121
else
122
123
# not optimal, but extra cleaning before overlayfs_wrapper should keep sources directory clean
124
if [[ $CLEAN_LEVEL == *make* ]]; then
125
display_alert "Cleaning" "$BOOTSOURCEDIR" "info"
126
(cd $BOOTSOURCEDIR; make clean > /dev/null 2>&1)
127
fi
128
129
if [[ $USE_OVERLAYFS == yes ]]; then
130
local ubootdir
131
ubootdir=$(overlayfs_wrapper "wrap" "$BOOTSOURCEDIR" "u-boot_${LINUXFAMILY}_${BRANCH}")
132
else
133
local ubootdir="$BOOTSOURCEDIR"
134
fi
135
cd "${ubootdir}" || exit
136
137
# read uboot version
138
local version hash
139
version=$(grab_version "$ubootdir")
140
hash=$(improved_git --git-dir="$ubootdir"/.git rev-parse HEAD)
141
142
display_alert "Compiling u-boot" "v$version" "info"
143
144
# build aarch64
145
if [[ $(dpkg --print-architecture) == amd64 ]]; then
146
147
local toolchain
148
toolchain=$(find_toolchain "$UBOOT_COMPILER" "$UBOOT_USE_GCC")
149
[[ -z $toolchain ]] && exit_with_error "Could not find required toolchain" "${UBOOT_COMPILER}gcc $UBOOT_USE_GCC"
150
151
if [[ -n $UBOOT_TOOLCHAIN2 ]]; then
152
local toolchain2_type toolchain2_ver toolchain2
153
toolchain2_type=$(cut -d':' -f1 <<< "${UBOOT_TOOLCHAIN2}")
154
toolchain2_ver=$(cut -d':' -f2 <<< "${UBOOT_TOOLCHAIN2}")
155
toolchain2=$(find_toolchain "$toolchain2_type" "$toolchain2_ver")
156
[[ -z $toolchain2 ]] && exit_with_error "Could not find required toolchain" "${toolchain2_type}gcc $toolchain2_ver"
157
fi
158
159
# build aarch64
160
fi
161
162
display_alert "Compiler version" "${UBOOT_COMPILER}gcc $(eval env PATH="${toolchain}:${toolchain2}:${PATH}" "${UBOOT_COMPILER}gcc" -dumpversion)" "info"
163
[[ -n $toolchain2 ]] && display_alert "Additional compiler version" "${toolchain2_type}gcc $(eval env PATH="${toolchain}:${toolchain2}:${PATH}" "${toolchain2_type}gcc" -dumpversion)" "info"
164
165
# create directory structure for the .deb package
166
uboottempdir=$(mktemp -d)
167
chmod 700 ${uboottempdir}
168
trap "ret=\$?; rm -rf \"${uboottempdir}\" ; exit \$ret" 0 1 2 3 15
169
local uboot_name=${CHOSEN_UBOOT}_${REVISION}_${ARCH}
170
rm -rf $uboottempdir/$uboot_name
171
mkdir -p $uboottempdir/$uboot_name/usr/lib/{u-boot,$uboot_name} $uboottempdir/$uboot_name/DEBIAN
172
173
# process compilation for one or multiple targets
174
while read -r target; do
175
local target_make target_patchdir target_files
176
target_make=$(cut -d';' -f1 <<< "${target}")
177
target_patchdir=$(cut -d';' -f2 <<< "${target}")
178
target_files=$(cut -d';' -f3 <<< "${target}")
179
180
# needed for multiple targets and for calling compile_uboot directly
181
#display_alert "Checking out to clean sources"
182
#improved_git checkout -f -q HEAD
183
184
if [[ $CLEAN_LEVEL == *make* ]]; then
185
display_alert "Cleaning" "$BOOTSOURCEDIR" "info"
186
(cd "${BOOTSOURCEDIR}"; make clean > /dev/null 2>&1)
187
fi
188
189
advanced_patch "u-boot" "$BOOTPATCHDIR" "$BOARD" "$target_patchdir" "$BRANCH" "${LINUXFAMILY}-${BOARD}-${BRANCH}"
190
191
# create patch for manual source changes
192
[[ $CREATE_PATCHES == yes ]] && userpatch_create "u-boot"
193
194
if [[ -n $ATFSOURCE ]]; then
195
cp -Rv "${atftempdir}"/*.bin .
196
rm -rf "${atftempdir}"
197
fi
198
199
echo -e "\n\t== u-boot make $BOOTCONFIG ==\n" >> "${DEST}"/${LOG_SUBPATH}/compilation.log
200
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${toolchain2}:${PATH}" \
201
'make $CTHREADS $BOOTCONFIG \
202
CROSS_COMPILE="$CCACHE $UBOOT_COMPILER"' 2>> "${DEST}"/${LOG_SUBPATH}/compilation.log \
203
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/${LOG_SUBPATH}/compilation.log'} \
204
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
205
206
if [[ "${version}" != 2014.07 ]]; then
207
208
# orangepi specifics u-boot settings
209
[[ -f .config ]] && sed -i 's/CONFIG_LOCALVERSION=""/CONFIG_LOCALVERSION="-orangepi"/g' .config
210
[[ -f .config ]] && sed -i 's/CONFIG_LOCALVERSION_AUTO=.*/# CONFIG_LOCALVERSION_AUTO is not set/g' .config
211
212
# for modern kernel and non spi targets
213
if [[ ${BOOTBRANCH} =~ ^tag:v201[8-9](.*) && ${target} != "spi" && -f .config ]]; then
214
215
sed -i 's/^.*CONFIG_ENV_IS_IN_FAT.*/# CONFIG_ENV_IS_IN_FAT is not set/g' .config
216
sed -i 's/^.*CONFIG_ENV_IS_IN_EXT4.*/CONFIG_ENV_IS_IN_EXT4=y/g' .config
217
sed -i 's/^.*CONFIG_ENV_IS_IN_MMC.*/# CONFIG_ENV_IS_IN_MMC is not set/g' .config
218
sed -i 's/^.*CONFIG_ENV_IS_NOWHERE.*/# CONFIG_ENV_IS_NOWHERE is not set/g' .config | echo \
219
"# CONFIG_ENV_IS_NOWHERE is not set" >> .config
220
echo 'CONFIG_ENV_EXT4_INTERFACE="mmc"' >> .config
221
echo 'CONFIG_ENV_EXT4_DEVICE_AND_PART="0:auto"' >> .config
222
echo 'CONFIG_ENV_EXT4_FILE="/boot/boot.env"' >> .config
223
224
fi
225
226
[[ -f tools/logos/udoo.bmp ]] && cp "${EXTER}"/packages/blobs/splash/udoo.bmp tools/logos/udoo.bmp
227
touch .scmversion
228
229
# $BOOTDELAY can be set in board family config, ensure autoboot can be stopped even if set to 0
230
[[ $BOOTDELAY == 0 ]] && echo -e "CONFIG_ZERO_BOOTDELAY_CHECK=y" >> .config
231
[[ -n $BOOTDELAY ]] && sed -i "s/^CONFIG_BOOTDELAY=.*/CONFIG_BOOTDELAY=${BOOTDELAY}/" .config || [[ -f .config ]] && echo "CONFIG_BOOTDELAY=${BOOTDELAY}" >> .config
232
233
fi
234
235
# workaround when two compilers are needed
236
cross_compile="CROSS_COMPILE=$CCACHE $UBOOT_COMPILER";
237
[[ -n $UBOOT_TOOLCHAIN2 ]] && cross_compile="ORANGEPI=foe"; # empty parameter is not allowed
238
239
echo -e "\n\t== u-boot make $target_make ==\n" >> "${DEST}"/${LOG_SUBPATH}/compilation.log
240
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${toolchain2}:${PATH}" \
241
'make $target_make $CTHREADS \
242
"${cross_compile}"' 2>>"${DEST}"/${LOG_SUBPATH}/compilation.log \
243
${PROGRESS_LOG_TO_FILE:+' | tee -a "${DEST}"/${LOG_SUBPATH}/compilation.log'} \
244
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Compiling u-boot..." $TTY_Y $TTY_X'} \
245
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'} ';EVALPIPE=(${PIPESTATUS[@]})'
246
247
[[ ${EVALPIPE[0]} -ne 0 ]] && exit_with_error "U-boot compilation failed"
248
249
[[ $(type -t uboot_custom_postprocess) == function ]] && uboot_custom_postprocess
250
251
# copy files to build directory
252
for f in $target_files; do
253
local f_src
254
f_src=$(cut -d':' -f1 <<< "${f}")
255
if [[ $f == *:* ]]; then
256
local f_dst
257
f_dst=$(cut -d':' -f2 <<< "${f}")
258
else
259
local f_dst
260
f_dst=$(basename "${f_src}")
261
fi
262
[[ ! -f $f_src ]] && exit_with_error "U-boot file not found" "$(basename "${f_src}")"
263
if [[ "${version}" =~ 2014.07|2011.09 ]]; then
264
cp "${f_src}" "$uboottempdir/packout/${f_dst}"
265
else
266
cp "${f_src}" "$uboottempdir/${uboot_name}/usr/lib/${uboot_name}/${f_dst}"
267
fi
268
done
269
done <<< "$UBOOT_TARGET_MAP"
270
271
if [[ $PACK_UBOOT == "yes" ]];then
272
if [[ $BOARDFAMILY =~ sun50iw1 ]]; then
273
if [[ $(type -t u-boot_tweaks) == function ]]; then
274
u-boot_tweaks ${uboot_name}
275
else
276
exit_with_error "U-boot pack failed"
277
fi
278
else
279
pack_uboot
280
cp $uboottempdir/packout/{boot0_sdcard.fex,boot_package.fex} "${SRC}/.tmp/${uboot_name}/usr/lib/${uboot_name}/"
281
cp $uboottempdir/packout/dts/${BOARD}-u-boot.dts "${SRC}/.tmp/${uboot_name}/usr/lib/u-boot/"
282
fi
283
cd "${ubootdir}" || exit
284
fi
285
286
# declare -f on non-defined function does not do anything
287
cat <<-EOF > "$uboottempdir/${uboot_name}/usr/lib/u-boot/platform_install.sh"
288
DIR=/usr/lib/$uboot_name
289
$(declare -f write_uboot_platform)
290
$(declare -f write_uboot_platform_mtd)
291
$(declare -f setup_write_uboot_platform)
292
EOF
293
294
# set up control file
295
cat <<-EOF > "$uboottempdir/${uboot_name}/DEBIAN/control"
296
Package: linux-u-boot-${BOARD}-${BRANCH}
297
Version: $REVISION
298
Architecture: $ARCH
299
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
300
Installed-Size: 1
301
Section: kernel
302
Priority: optional
303
Provides: orangepi-u-boot
304
Replaces: orangepi-u-boot
305
Conflicts: orangepi-u-boot, u-boot-sunxi
306
Description: Uboot loader $version
307
EOF
308
309
# copy config file to the package
310
# useful for FEL boot with overlayfs_wrapper
311
[[ -f .config && -n $BOOTCONFIG ]] && cp .config "$uboottempdir/${uboot_name}/usr/lib/u-boot/${BOOTCONFIG}"
312
# copy license files from typical locations
313
[[ -f COPYING ]] && cp COPYING "$uboottempdir/${uboot_name}/usr/lib/u-boot/LICENSE"
314
[[ -f Licenses/README ]] && cp Licenses/README "$uboottempdir/${uboot_name}/usr/lib/u-boot/LICENSE"
315
[[ -n $atftempdir && -f $atftempdir/license.md ]] && cp "${atftempdir}/license.md" "$uboottempdir/${uboot_name}/usr/lib/u-boot/LICENSE.atf"
316
317
display_alert "Building deb" "${uboot_name}.deb" "info"
318
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "$uboottempdir/${uboot_name}" "$uboottempdir/${uboot_name}.deb" >> "${DEST}"/${LOG_SUBPATH}/output.log 2>&1
319
rm -rf "$uboottempdir/${uboot_name}"
320
[[ -n $atftempdir ]] && rm -rf "${atftempdir}"
321
322
[[ ! -f $uboottempdir/${uboot_name}.deb ]] && exit_with_error "Building u-boot package failed"
323
324
rsync --remove-source-files -rq "$uboottempdir/${uboot_name}.deb" "${DEB_STORAGE}/u-boot/"
325
rm -rf "$uboottempdir"
326
327
fi
328
}
329
330
create_linux-source_package ()
331
{
332
ts=$(date +%s)
333
local sources_pkg_dir tmp_src_dir
334
tmp_src_dir=$(mktemp -d)
335
trap "ret=\$?; rm -rf \"${tmp_src_dir}\" ; exit \$ret" 0 1 2 3 15
336
sources_pkg_dir=${tmp_src_dir}/${CHOSEN_KSRC}_${REVISION}_all
337
mkdir -p "${sources_pkg_dir}"/usr/src/ \
338
"${sources_pkg_dir}"/usr/share/doc/linux-source-${version}-${LINUXFAMILY} \
339
"${sources_pkg_dir}"/DEBIAN
340
341
cp "${EXTER}/config/kernel/${LINUXCONFIG}.config" "default_${LINUXCONFIG}.config"
342
xz < .config > "${sources_pkg_dir}/usr/src/${LINUXCONFIG}_${version}_${REVISION}_config.xz"
343
344
display_alert "Compressing sources for the linux-source package"
345
tar cp --directory="$kerneldir" --exclude='.git' --owner=root . \
346
| pv -p -b -r -s "$(du -sb "$kerneldir" --exclude=='.git' | cut -f1)" \
347
| pixz -4 > "${sources_pkg_dir}/usr/src/linux-source-${version}-${LINUXFAMILY}.tar.xz"
348
cp COPYING "${sources_pkg_dir}/usr/share/doc/linux-source-${version}-${LINUXFAMILY}/LICENSE"
349
350
cat <<-EOF > "${sources_pkg_dir}"/DEBIAN/control
351
Package: linux-source-${version}-${BRANCH}-${LINUXFAMILY}
352
Version: ${version}-${BRANCH}-${LINUXFAMILY}+${REVISION}
353
Architecture: all
354
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
355
Section: kernel
356
Priority: optional
357
Depends: binutils, coreutils
358
Provides: linux-source, linux-source-${version}-${LINUXFAMILY}
359
Recommends: gcc, make
360
Description: This package provides the source code for the Linux kernel $version
361
EOF
362
363
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} -z0 "${sources_pkg_dir}" "${sources_pkg_dir}.deb"
364
rsync --remove-source-files -rq "${sources_pkg_dir}.deb" "${DEB_STORAGE}/"
365
366
te=$(date +%s)
367
display_alert "Make the linux-source package" "$(($te - $ts)) sec." "info"
368
rm -rf "${tmp_src_dir}"
369
}
370
371
compile_kernel()
372
{
373
if [[ $CLEAN_LEVEL == *make* ]]; then
374
display_alert "Cleaning" "$LINUXSOURCEDIR" "info"
375
(cd ${LINUXSOURCEDIR}; make ARCH="${ARCHITECTURE}" clean >/dev/null 2>&1)
376
fi
377
378
if [[ $USE_OVERLAYFS == yes ]]; then
379
local kerneldir
380
kerneldir=$(overlayfs_wrapper "wrap" "$LINUXSOURCEDIR" "kernel_${LINUXFAMILY}_${BRANCH}")
381
else
382
local kerneldir="$LINUXSOURCEDIR"
383
fi
384
cd "${kerneldir}" || exit
385
386
rm -f localversion
387
388
# read kernel version
389
local version hash
390
version=$(grab_version "$kerneldir")
391
392
# read kernel git hash
393
hash=$(improved_git --git-dir="$kerneldir"/.git rev-parse HEAD)
394
395
# Apply a series of patches if a series file exists
396
if test -f "${EXTER}"/patch/kernel/${KERNELPATCHDIR}/series.conf; then
397
display_alert "series.conf file visible. Apply"
398
series_conf="${SRC}"/patch/kernel/${KERNELPATCHDIR}/series.conf
399
400
# apply_patch_series <target dir> <full path to series file>
401
apply_patch_series "${kerneldir}" "$series_conf"
402
fi
403
404
# build 3rd party drivers
405
# compilation_prepare
406
407
advanced_patch "kernel" "$KERNELPATCHDIR" "$BOARD" "" "$BRANCH" "$LINUXFAMILY-$BRANCH"
408
409
# create patch for manual source changes in debug mode
410
[[ $CREATE_PATCHES == yes ]] && userpatch_create "kernel"
411
412
# re-read kernel version after patching
413
local version
414
version=$(grab_version "$kerneldir")
415
416
display_alert "Compiling $BRANCH kernel" "$version" "info"
417
418
# compare with the architecture of the current Debian node
419
# if it matches we use the system compiler
420
if $(dpkg-architecture -e "${ARCH}"); then
421
display_alert "Native compilation"
422
elif [[ $(dpkg --print-architecture) == amd64 ]]; then
423
local toolchain
424
toolchain=$(find_toolchain "$KERNEL_COMPILER" "$KERNEL_USE_GCC")
425
[[ -z $toolchain ]] && exit_with_error "Could not find required toolchain" "${KERNEL_COMPILER}gcc $KERNEL_USE_GCC"
426
else
427
exit_with_error "Architecture [$ARCH] is not supported"
428
fi
429
430
display_alert "Compiler version" "${KERNEL_COMPILER}gcc $(eval env PATH="${toolchain}:${PATH}" "${KERNEL_COMPILER}gcc" -dumpversion)" "info"
431
432
# copy kernel config
433
if [[ $KERNEL_KEEP_CONFIG == yes && -f "${DEST}"/config/$LINUXCONFIG.config ]]; then
434
display_alert "Using previous kernel config" "${DEST}/config/$LINUXCONFIG.config" "info"
435
cp -p "${DEST}/config/${LINUXCONFIG}.config" .config
436
else
437
if [[ -f $USERPATCHES_PATH/$LINUXCONFIG.config ]]; then
438
display_alert "Using kernel config provided by user" "userpatches/$LINUXCONFIG.config" "info"
439
cp -p "${USERPATCHES_PATH}/${LINUXCONFIG}.config" .config
440
else
441
display_alert "Using kernel config file" "${EXTER}/config/kernel/$LINUXCONFIG.config" "info"
442
cp -p "${EXTER}/config/kernel/${LINUXCONFIG}.config" .config
443
fi
444
fi
445
446
call_extension_method "custom_kernel_config" << 'CUSTOM_KERNEL_CONFIG'
447
*Kernel .config is in place, still clean from git version*
448
Called after ${LINUXCONFIG}.config is put in place (.config).
449
Before any olddefconfig any Kconfig make is called.
450
A good place to customize the .config directly.
451
CUSTOM_KERNEL_CONFIG
452
453
454
# hack for deb builder. To pack what's missing in headers pack.
455
cp "$EXTER"/patch/misc/headers-debian-byteshift.patch /tmp
456
457
if [[ $KERNEL_CONFIGURE != yes ]]; then
458
if [[ $BRANCH == legacy && ! $BOARDFAMILY =~ "rockchip-rk3588"|"rockchip-rk356x" ]]; then
459
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
460
'make ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" silentoldconfig'
461
else
462
# TODO: check if required
463
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
464
'make ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" olddefconfig'
465
fi
466
else
467
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
468
'make $CTHREADS ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" oldconfig'
469
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
470
'make $CTHREADS ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" ${KERNEL_MENUCONFIG:-menuconfig}'
471
472
[[ ${PIPESTATUS[0]} -ne 0 ]] && exit_with_error "Error kernel menuconfig failed"
473
474
# store kernel config in easily reachable place
475
display_alert "Exporting new kernel config" "$DEST/config/$LINUXCONFIG.config" "info"
476
cp .config "${DEST}/config/${LINUXCONFIG}.config"
477
cp .config "${EXTER}/config/kernel/${LINUXCONFIG}.config"
478
# export defconfig too if requested
479
if [[ $KERNEL_EXPORT_DEFCONFIG == yes ]]; then
480
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
481
'make ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" savedefconfig'
482
[[ -f defconfig ]] && cp defconfig "${DEST}/config/${LINUXCONFIG}.defconfig"
483
fi
484
fi
485
486
# create linux-source package - with already patched sources
487
# We will build this package first and clear the memory.
488
if [[ $BUILD_KSRC != no ]]; then
489
create_linux-source_package
490
fi
491
492
echo -e "\n\t== kernel ==\n" >> "${DEST}"/${LOG_SUBPATH}/compilation.log
493
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
494
'make $CTHREADS ARCH=$ARCHITECTURE \
495
CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" \
496
$SRC_LOADADDR \
497
LOCALVERSION="-$LINUXFAMILY" \
498
$KERNEL_IMAGE_TYPE ${KERNEL_EXTRA_TARGETS:-modules dtbs} 2>>$DEST/${LOG_SUBPATH}/compilation.log' \
499
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/${LOG_SUBPATH}/compilation.log'} \
500
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" \
501
--progressbox "Compiling kernel..." $TTY_Y $TTY_X'} \
502
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
503
504
if [[ ${PIPESTATUS[0]} -ne 0 || ! -f arch/$ARCHITECTURE/boot/$KERNEL_IMAGE_TYPE ]]; then
505
grep -i error $DEST/${LOG_SUBPATH}/compilation.log
506
exit_with_error "Kernel was not built" "@host"
507
fi
508
509
# different packaging for 4.3+
510
if linux-version compare "${version}" ge 4.3; then
511
local kernel_packing="bindeb-pkg"
512
else
513
local kernel_packing="deb-pkg"
514
fi
515
516
#if [[ $BRANCH == legacy && $LINUXFAMILY =~ sun50iw2|sun50iw6|sun50iw9 ]]; then
517
# make -C modules/gpu LICHEE_MOD_DIR=${SRC}/.tmp/gpu_modules_${LINUXFAMILY} LICHEE_KDIR=${kerneldir} CROSS_COMPILE=$toolchain/$KERNEL_COMPILER ARCH=$ARCHITECTURE
518
#fi
519
520
display_alert "Creating packages"
521
522
# produce deb packages: image, headers, firmware, dtb
523
echo -e "\n\t== deb packages: image, headers, firmware, dtb ==\n" >> "${DEST}"/${LOG_SUBPATH}/compilation.log
524
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
525
'make $CTHREADS $kernel_packing \
526
KDEB_PKGVERSION=$REVISION \
527
KDEB_COMPRESS=${DEB_COMPRESS} \
528
BRANCH=$BRANCH \
529
LOCALVERSION="-${LINUXFAMILY}" \
530
KBUILD_DEBARCH=$ARCH \
531
ARCH=$ARCHITECTURE \
532
DEBFULLNAME="$MAINTAINER" \
533
DEBEMAIL="$MAINTAINERMAIL" \
534
CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" 2>>$DEST/${LOG_SUBPATH}/compilation.log' \
535
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/${LOG_SUBPATH}/compilation.log'} \
536
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Creating kernel packages..." $TTY_Y $TTY_X'} \
537
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
538
539
cd .. || exit
540
# remove firmare image packages here - easier than patching ~40 packaging scripts at once
541
rm -f linux-firmware-image-*.deb
542
543
rsync --remove-source-files -rq ./*.deb "${DEB_STORAGE}/" || exit_with_error "Failed moving kernel DEBs"
544
545
# store git hash to the file and create a change log
546
#HASHTARGET="${EXTER}/cache/hash"$([[ ${BETA} == yes ]] && echo "-beta")"/linux-image-${BRANCH}-${LINUXFAMILY}"
547
#OLDHASHTARGET=$(head -1 "${HASHTARGET}.githash" 2>/dev/null)
548
549
# check if OLDHASHTARGET commit exists otherwise use oldest
550
#if [[ -z ${KERNEL_VERSION_LEVEL} ]]; then
551
# git -C ${kerneldir} cat-file -t ${OLDHASHTARGET} >/dev/null 2>&1
552
# [[ $? -ne 0 ]] && OLDHASHTARGET=$(git -C ${kerneldir} show HEAD~199 --pretty=format:"%H" --no-patch)
553
# else
554
# git -C ${kerneldir} cat-file -t ${OLDHASHTARGET} >/dev/null 2>&1
555
# [[ $? -ne 0 ]] && OLDHASHTARGET=$(git -C ${kerneldir} rev-list --max-parents=0 HEAD)
556
#fi
557
558
#[[ -z ${KERNELPATCHDIR} ]] && KERNELPATCHDIR=$LINUXFAMILY-$BRANCH
559
#[[ -z ${LINUXCONFIG} ]] && LINUXCONFIG=linux-$LINUXFAMILY-$BRANCH
560
561
# calculate URL
562
#if [[ "$KERNELSOURCE" == *"github.com"* ]]; then
563
# URL="${KERNELSOURCE/git:/https:}/commit/${HASH}"
564
#elif [[ "$KERNELSOURCE" == *"kernel.org"* ]]; then
565
# URL="${KERNELSOURCE/git:/https:}/commit/?h=$(echo $KERNELBRANCH | cut -d":" -f2)&id=${HASH}"
566
#else
567
# URL="${KERNELSOURCE}/+/$HASH"
568
#fi
569
570
# create change log
571
#git --no-pager -C ${kerneldir} log --abbrev-commit --oneline --no-patch --no-merges --date-order --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%C(black bold)%ad%Creset%C(auto) | %s | <%an> | <a href='$URL'%H>%H</a>' ${OLDHASHTARGET}..${hash} > "${HASHTARGET}.gitlog"
572
573
#echo "${hash}" > "${HASHTARGET}.githash"
574
#hash_watch_1=$(LC_COLLATE=C find -L "${EXTER}/patch/kernel/${KERNELPATCHDIR}"/ -name '*.patch' -mindepth 1 -maxdepth 1 -printf '%s %P\n' 2> /dev/null | LC_COLLATE=C sort -n)
575
#hash_watch_2=$(cat "${EXTER}/config/kernel/${LINUXCONFIG}.config")
576
#echo "${hash_watch_1}${hash_watch_2}" | improved_git hash-object --stdin >> "${HASHTARGET}.githash"
577
578
}
579
580
581
582
583
compile_firmware()
584
{
585
display_alert "Merging and packaging linux firmware" "@host" "info"
586
587
local firmwaretempdir plugin_dir
588
589
firmwaretempdir=$(mktemp -d)
590
chmod 700 ${firmwaretempdir}
591
trap "ret=\$?; rm -rf \"${firmwaretempdir}\" ; exit \$ret" 0 1 2 3 15
592
plugin_dir="orangepi-firmware${FULL}"
593
mkdir -p "${firmwaretempdir}/${plugin_dir}/lib/firmware"
594
595
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "https://github.com/orangepi-xunlong/firmware" "${EXTER}/cache/sources/orangepi-firmware-git" "branch:master"
596
if [[ -n $FULL ]]; then
597
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "$MAINLINE_FIRMWARE_SOURCE" "${EXTER}/cache/sources/linux-firmware-git" "branch:master"
598
# cp : create hardlinks
599
cp -af --reflink=auto "${EXTER}"/cache/sources/linux-firmware-git/* "${firmwaretempdir}/${plugin_dir}/lib/firmware/"
600
fi
601
# overlay our firmware
602
# cp : create hardlinks
603
cp -af --reflink=auto "${EXTER}"/cache/sources/orangepi-firmware-git/* "${firmwaretempdir}/${plugin_dir}/lib/firmware/"
604
605
# cleanup what's not needed for sure
606
rm -rf "${firmwaretempdir}/${plugin_dir}"/lib/firmware/{amdgpu,amd-ucode,radeon,nvidia,matrox,.git}
607
cd "${firmwaretempdir}/${plugin_dir}" || exit
608
609
# set up control file
610
mkdir -p DEBIAN
611
cat <<-END > DEBIAN/control
612
Package: orangepi-firmware${FULL}
613
Version: $REVISION
614
Architecture: all
615
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
616
Installed-Size: 1
617
Replaces: linux-firmware, firmware-brcm80211, firmware-ralink, firmware-samsung, firmware-realtek, orangepi-firmware${REPLACE}
618
Section: kernel
619
Priority: optional
620
Description: Linux firmware${FULL}
621
END
622
623
cd "${firmwaretempdir}" || exit
624
# pack
625
mv "orangepi-firmware${FULL}" "orangepi-firmware${FULL}_${REVISION}_all"
626
display_alert "Building firmware package" "orangepi-firmware${FULL}_${REVISION}_all" "info"
627
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "orangepi-firmware${FULL}_${REVISION}_all" >> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
628
mv "orangepi-firmware${FULL}_${REVISION}_all" "orangepi-firmware${FULL}"
629
rsync -rq "orangepi-firmware${FULL}_${REVISION}_all.deb" "${DEB_STORAGE}/"
630
631
# remove temp directory
632
rm -rf "${firmwaretempdir}"
633
}
634
635
636
637
638
compile_orangepi-zsh()
639
{
640
641
local tmp_dir orangepi_zsh_dir
642
tmp_dir=$(mktemp -d)
643
chmod 700 ${tmp_dir}
644
trap "rm -rf \"${tmp_dir}\" ; exit 0" 0 1 2 3 15
645
orangepi_zsh_dir=orangepi-zsh_${REVISION}_all
646
display_alert "Building deb" "orangepi-zsh" "info"
647
648
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "https://github.com/robbyrussell/oh-my-zsh" "${EXTER}/cache/sources/oh-my-zsh" "branch:master"
649
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "https://github.com/mroth/evalcache" "${EXTER}/cache/sources/evalcache" "branch:master"
650
651
mkdir -p "${tmp_dir}/${orangepi_zsh_dir}"/{DEBIAN,etc/skel/,etc/oh-my-zsh/,/etc/skel/.oh-my-zsh/cache}
652
653
# set up control file
654
cat <<-END > "${tmp_dir}/${orangepi_zsh_dir}"/DEBIAN/control
655
Package: orangepi-zsh
656
Version: $REVISION
657
Architecture: all
658
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
659
Depends: zsh, tmux
660
Section: utils
661
Priority: optional
662
Description: Orange Pi improved ZShell
663
END
664
665
# set up post install script
666
cat <<-END > "${tmp_dir}/${orangepi_zsh_dir}"/DEBIAN/postinst
667
#!/bin/sh
668
669
# copy cache directory if not there yet
670
awk -F'[:]' '{if (\$3 >= 1000 && \$3 != 65534 || \$3 == 0) print ""\$6"/.oh-my-zsh"}' /etc/passwd | xargs -i sh -c 'test ! -d {} && cp -R --attributes-only /etc/skel/.oh-my-zsh {}'
671
awk -F'[:]' '{if (\$3 >= 1000 && \$3 != 65534 || \$3 == 0) print ""\$6"/.zshrc"}' /etc/passwd | xargs -i sh -c 'test ! -f {} && cp -R /etc/skel/.zshrc {}'
672
673
# fix owner permissions in home directory
674
awk -F'[:]' '{if (\$3 >= 1000 && \$3 != 65534 || \$3 == 0) print ""\$1":"\$3" "\$6"/.oh-my-zsh"}' /etc/passwd | xargs -n2 chown -R
675
awk -F'[:]' '{if (\$3 >= 1000 && \$3 != 65534 || \$3 == 0) print ""\$1":"\$3" "\$6"/.zshrc"}' /etc/passwd | xargs -n2 chown -R
676
677
# add support for bash profile
678
! grep emulate /etc/zsh/zprofile >/dev/null && echo "emulate sh -c 'source /etc/profile'" >> /etc/zsh/zprofile
679
exit 0
680
END
681
682
cp -R "${EXTER}"/cache/sources/oh-my-zsh "${tmp_dir}/${orangepi_zsh_dir}"/etc/
683
cp -R "${EXTER}"/cache/sources/evalcache "${tmp_dir}/${orangepi_zsh_dir}"/etc/oh-my-zsh/plugins
684
cp "${tmp_dir}/${orangepi_zsh_dir}"/etc/oh-my-zsh/templates/zshrc.zsh-template "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
685
686
chmod -R g-w,o-w "${tmp_dir}/${orangepi_zsh_dir}"/etc/oh-my-zsh/
687
688
# we have common settings
689
sed -i "s/^export ZSH=.*/export ZSH=\/etc\/oh-my-zsh/" "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
690
691
# user cache
692
sed -i "/^export ZSH=.*/a export ZSH_CACHE_DIR=~\/.oh-my-zsh\/cache" "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
693
694
# define theme
695
sed -i 's/^ZSH_THEME=.*/ZSH_THEME="mrtazz"/' "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
696
697
# disable prompt while update
698
sed -i 's/# DISABLE_UPDATE_PROMPT="true"/DISABLE_UPDATE_PROMPT="true"/g' "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
699
700
# disable auto update since we provide update via package
701
sed -i 's/# DISABLE_AUTO_UPDATE="true"/DISABLE_AUTO_UPDATE="true"/g' "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
702
703
# define default plugins
704
sed -i 's/^plugins=.*/plugins=(evalcache git git-extras debian tmux screen history extract colorize web-search docker)/' "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
705
706
chmod 755 "${tmp_dir}/${orangepi_zsh_dir}"/DEBIAN/postinst
707
708
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "${tmp_dir}/${orangepi_zsh_dir}" >> "${DEST}"/${LOG_SUBPATH}/output.log 2>&1
709
rsync --remove-source-files -rq "${tmp_dir}/${orangepi_zsh_dir}.deb" "${DEB_STORAGE}/"
710
rm -rf "${tmp_dir}"
711
712
}
713
714
715
716
compile_plymouth-theme-orangepi()
717
{
718
719
local tmp_dir work_dir
720
tmp_dir=$(mktemp -d)
721
chmod 700 ${tmp_dir}
722
trap "ret=\$?; rm -rf \"${tmp_dir}\" ; exit \$ret" 0 1 2 3 15
723
plymouth_theme_orangepi_dir=orangepi-plymouth-theme_${REVISION}_all
724
display_alert "Building deb" "orangepi-plymouth-theme" "info"
725
726
mkdir -p "${tmp_dir}/${plymouth_theme_orangepi_dir}"/{DEBIAN,usr/share/plymouth/themes/orangepi}
727
728
# set up control file
729
cat <<- END > "${tmp_dir}/${plymouth_theme_orangepi_dir}"/DEBIAN/control
730
Package: orangepi-plymouth-theme
731
Version: $REVISION
732
Architecture: all
733
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
734
Depends: plymouth, plymouth-themes
735
Section: universe/x11
736
Priority: optional
737
Description: boot animation, logger and I/O multiplexer - orangepi theme
738
END
739
740
cp "${EXTER}"/packages/plymouth-theme-orangepi/debian/{postinst,prerm,postrm} \
741
"${tmp_dir}/${plymouth_theme_orangepi_dir}"/DEBIAN/
742
chmod 755 "${tmp_dir}/${plymouth_theme_orangepi_dir}"/DEBIAN/{postinst,prerm,postrm}
743
744
#convert -resize 256x256 \
745
# "${EXTER}"/packages/plymouth-theme-orangepi/orangepi-logo.png \
746
# "${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/bgrt-fallback.png
747
748
# convert -resize 52x52 \
749
# "${EXTER}"/packages/plymouth-theme-orangepi/spinner.gif \
750
# "${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/animation-%04d.png
751
752
convert -resize 52x52 \
753
"${EXTER}"/packages/plymouth-theme-orangepi/spinner.gif \
754
"${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/throbber-%04d.png
755
756
cp "${EXTER}"/packages/plymouth-theme-orangepi/watermark.png \
757
"${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/
758
759
cp "${EXTER}"/packages/plymouth-theme-orangepi/{bullet,capslock,entry,keyboard,keymap-render,lock}.png \
760
"${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/
761
762
cp "${EXTER}"/packages/plymouth-theme-orangepi/orangepi.plymouth \
763
"${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/
764
765
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "${tmp_dir}/${plymouth_theme_orangepi_dir}" > /dev/null
766
rsync --remove-source-files -rq "${tmp_dir}/${plymouth_theme_orangepi_dir}.deb" "${DEB_STORAGE}/"
767
rm -rf "${tmp_dir}"
768
}
769
770
compile_orangepi-config()
771
{
772
local tmpdir=${SRC}/.tmp/orangepi-config_${REVISION}_all
773
774
display_alert "Building deb" "orangepi-config" "info"
775
776
777
mkdir -p "${tmpdir}"/{DEBIAN,usr/bin/,usr/sbin/,usr/lib/orangepi-config/}
778
779
# set up control file
780
cat <<-END > "${tmpdir}"/DEBIAN/control
781
Package: orangepi-config
782
Version: $REVISION
783
Architecture: all
784
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
785
Replaces: orangepi-bsp
786
Depends: bash, iperf3, psmisc, curl, bc, expect, dialog, pv, \
787
debconf-utils, unzip, build-essential, html2text, apt-transport-https, html2text, dirmngr, software-properties-common
788
Recommends: orangepi-bsp
789
Suggests: libpam-google-authenticator, qrencode, network-manager, sunxi-tools
790
Section: utils
791
Priority: optional
792
Description: Orange Pi configuration utility
793
END
794
795
install -m 755 $EXTER/cache/sources/orangepi-config/scripts/tv_grab_file $tmpdir/usr/bin/tv_grab_file
796
install -m 755 $EXTER/cache/sources/orangepi-config/debian-config $tmpdir/usr/sbin/orangepi-config
797
install -m 644 $EXTER/cache/sources/orangepi-config/debian-config-jobs $tmpdir/usr/lib/orangepi-config/jobs.sh
798
install -m 644 $EXTER/cache/sources/orangepi-config/debian-config-submenu $tmpdir/usr/lib/orangepi-config/submenu.sh
799
install -m 644 $EXTER/cache/sources/orangepi-config/debian-config-functions $tmpdir/usr/lib/orangepi-config/functions.sh
800
install -m 644 $EXTER/cache/sources/orangepi-config/debian-config-functions-network $tmpdir/usr/lib/orangepi-config/functions-network.sh
801
install -m 755 $EXTER/cache/sources/orangepi-config/softy $tmpdir/usr/sbin/softy
802
# fallback to replace orangepi-config in BSP
803
ln -sf /usr/sbin/orangepi-config $tmpdir/usr/bin/orangepi-config
804
ln -sf /usr/sbin/softy "${tmpdir}"/usr/bin/softy
805
806
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "${tmpdir}" >/dev/null
807
rsync --remove-source-files -rq "${tmpdir}.deb" "${DEB_STORAGE}/"
808
rm -rf "${tmpdir}"
809
}
810
811
812
813
814
compile_sunxi_tools()
815
{
816
# Compile and install only if git commit hash changed
817
cd $EXTER/cache/sources/sunxi-tools || exit
818
# need to check if /usr/local/bin/sunxi-fexc to detect new Docker containers with old cached sources
819
if [[ ! -f .commit_id || $(improved_git rev-parse @ 2>/dev/null) != $(<.commit_id) || ! -f /usr/local/bin/sunxi-fexc ]]; then
820
display_alert "Compiling" "sunxi-tools" "info"
821
make -s clean >/dev/null
822
make -s tools >/dev/null
823
mkdir -p /usr/local/bin/
824
make install-tools >/dev/null 2>&1
825
improved_git rev-parse @ 2>/dev/null > .commit_id
826
fi
827
}
828
829
install_rkbin_tools()
830
{
831
# install only if git commit hash changed
832
cd "${EXTER}"/cache/sources/rkbin-tools || exit
833
# need to check if /usr/local/bin/sunxi-fexc to detect new Docker containers with old cached sources
834
if [[ ! -f .commit_id || $(improved_git rev-parse @ 2>/dev/null) != $(<.commit_id) || ! -f /usr/local/bin/loaderimage ]]; then
835
display_alert "Installing" "rkbin-tools" "info"
836
mkdir -p /usr/local/bin/
837
install -m 755 tools/loaderimage /usr/local/bin/
838
install -m 755 tools/trust_merger /usr/local/bin/
839
improved_git rev-parse @ 2>/dev/null > .commit_id
840
fi
841
}
842
843
grab_version()
844
{
845
local ver=()
846
ver[0]=$(grep "^VERSION" "${1}"/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
847
ver[1]=$(grep "^PATCHLEVEL" "${1}"/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
848
ver[2]=$(grep "^SUBLEVEL" "${1}"/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
849
ver[3]=$(grep "^EXTRAVERSION" "${1}"/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^-rc[[:digit:]]+')
850
echo "${ver[0]:-0}${ver[1]:+.${ver[1]}}${ver[2]:+.${ver[2]}}${ver[3]}"
851
}
852
853
# find_toolchain <compiler_prefix> <expression>
854
#
855
# returns path to toolchain that satisfies <expression>
856
#
857
find_toolchain()
858
{
859
[[ "${SKIP_EXTERNAL_TOOLCHAINS}" == "yes" ]] && { echo "/usr/bin"; return; }
860
local compiler=$1
861
local expression=$2
862
local dist=10
863
local toolchain=""
864
# extract target major.minor version from expression
865
local target_ver
866
target_ver=$(grep -oE "[[:digit:]]+\.[[:digit:]]" <<< "$expression")
867
for dir in "${SRC}"/toolchains/*/; do
868
# check if is a toolchain for current $ARCH
869
[[ ! -f ${dir}bin/${compiler}gcc ]] && continue
870
# get toolchain major.minor version
871
local gcc_ver
872
gcc_ver=$("${dir}bin/${compiler}gcc" -dumpversion | grep -oE "^[[:digit:]]+\.[[:digit:]]")
873
# check if toolchain version satisfies requirement
874
awk "BEGIN{exit ! ($gcc_ver $expression)}" >/dev/null || continue
875
# check if found version is the closest to target
876
# may need different logic here with more than 1 digit minor version numbers
877
# numbers: 3.9 > 3.10; versions: 3.9 < 3.10
878
# dpkg --compare-versions can be used here if operators are changed
879
local d
880
d=$(awk '{x = $1 - $2}{printf "%.1f\n", (x > 0) ? x : -x}' <<< "$target_ver $gcc_ver")
881
if awk "BEGIN{exit ! ($d < $dist)}" >/dev/null ; then
882
dist=$d
883
toolchain=${dir}bin
884
fi
885
done
886
echo "$toolchain"
887
# logging a stack of used compilers.
888
if [[ -f "${DEST}"/${LOG_SUBPATH}/compiler.log ]]; then
889
if ! grep -q "$toolchain" "${DEST}"/${LOG_SUBPATH}/compiler.log; then
890
echo "$toolchain" >> "${DEST}"/${LOG_SUBPATH}/compiler.log;
891
fi
892
else
893
echo "$toolchain" >> "${DEST}"/${LOG_SUBPATH}/compiler.log;
894
fi
895
}
896
897
# advanced_patch <dest> <family> <board> <target> <branch> <description>
898
#
899
# parameters:
900
# <dest>: u-boot, kernel, atf
901
# <family>: u-boot: u-boot; kernel: sunxi-next, ...
902
# <board>: orangepipcplus, orangepizero ...
903
# <target>: optional subdirectory
904
# <description>: additional description text
905
#
906
# priority:
907
# $USERPATCHES_PATH/<dest>/<family>/target_<target>
908
# $USERPATCHES_PATH/<dest>/<family>/board_<board>
909
# $USERPATCHES_PATH/<dest>/<family>/branch_<branch>
910
# $USERPATCHES_PATH/<dest>/<family>
911
# $EXTER/patch/<dest>/<family>/target_<target>
912
# $EXTER/patch/<dest>/<family>/board_<board>
913
# $EXTER/patch/<dest>/<family>/branch_<branch>
914
# $EXTER/patch/<dest>/<family>
915
#
916
advanced_patch()
917
{
918
local dest=$1
919
local family=$2
920
local board=$3
921
local target=$4
922
local branch=$5
923
local description=$6
924
925
display_alert "Started patching process for" "$dest $description" "info"
926
display_alert "Looking for user patches in" "userpatches/$dest/$family" "info"
927
928
local names=()
929
local dirs=(
930
"$USERPATCHES_PATH/$dest/$family/target_${target}:[\e[33mu\e[0m][\e[34mt\e[0m]"
931
"$USERPATCHES_PATH/$dest/$family/board_${board}:[\e[33mu\e[0m][\e[35mb\e[0m]"
932
"$USERPATCHES_PATH/$dest/$family/branch_${branch}:[\e[33mu\e[0m][\e[33mb\e[0m]"
933
"$USERPATCHES_PATH/$dest/$family:[\e[33mu\e[0m][\e[32mc\e[0m]"
934
"$EXTER/patch/$dest/$family/target_${target}:[\e[32ml\e[0m][\e[34mt\e[0m]"
935
"$EXTER/patch/$dest/$family/board_${board}:[\e[32ml\e[0m][\e[35mb\e[0m]"
936
"$EXTER/patch/$dest/$family/branch_${branch}:[\e[32ml\e[0m][\e[33mb\e[0m]"
937
"$EXTER/patch/$dest/$family:[\e[32ml\e[0m][\e[32mc\e[0m]"
938
)
939
local links=()
940
941
# required for "for" command
942
shopt -s nullglob dotglob
943
# get patch file names
944
for dir in "${dirs[@]}"; do
945
for patch in ${dir%%:*}/*.patch; do
946
names+=($(basename "${patch}"))
947
done
948
# add linked patch directories
949
if [[ -d ${dir%%:*} ]]; then
950
local findlinks
951
findlinks=$(find "${dir%%:*}" -maxdepth 1 -type l -print0 2>&1 | xargs -0)
952
[[ -n $findlinks ]] && readarray -d '' links < <(find "${findlinks}" -maxdepth 1 -type f -follow -print -iname "*.patch" -print | grep "\.patch$" | sed "s|${dir%%:*}/||g" 2>&1)
953
fi
954
done
955
# merge static and linked
956
names=("${names[@]}" "${links[@]}")
957
# remove duplicates
958
local names_s=($(echo "${names[@]}" | tr ' ' '\n' | LC_ALL=C sort -u | tr '\n' ' '))
959
# apply patches
960
for name in "${names_s[@]}"; do
961
for dir in "${dirs[@]}"; do
962
if [[ -f ${dir%%:*}/$name ]]; then
963
if [[ -s ${dir%%:*}/$name ]]; then
964
process_patch_file "${dir%%:*}/$name" "${dir##*:}"
965
else
966
display_alert "* ${dir##*:} $name" "skipped"
967
fi
968
break # next name
969
fi
970
done
971
done
972
}
973
974
# process_patch_file <file> <description>
975
#
976
# parameters:
977
# <file>: path to patch file
978
# <status>: additional status text
979
#
980
process_patch_file()
981
{
982
local patch=$1
983
local status=$2
984
985
# detect and remove files which patch will create
986
lsdiff -s --strip=1 "${patch}" | grep '^+' | awk '{print $2}' | xargs -I % sh -c 'rm -f %'
987
988
echo "Processing file $patch" >> "${DEST}"/${LOG_SUBPATH}/patching.log
989
patch --batch --silent -p1 -N < "${patch}" >> "${DEST}"/${LOG_SUBPATH}/patching.log 2>&1
990
991
if [[ $? -ne 0 ]]; then
992
display_alert "* $status $(basename "${patch}")" "failed" "wrn"
993
[[ $EXIT_PATCHING_ERROR == yes ]] && exit_with_error "Aborting due to" "EXIT_PATCHING_ERROR"
994
else
995
display_alert "* $status $(basename "${patch}")" "" "info"
996
fi
997
echo >> "${DEST}"/${LOG_SUBPATH}/patching.log
998
}
999
1000
userpatch_create()
1001
{
1002
# create commit to start from clean source
1003
git add .
1004
git -c user.name='Orange Pi User' -c user.email='[email protected]' commit -q -m "Cleaning working copy"
1005
1006
local patch="$DEST/patch/$1-$LINUXFAMILY-$BRANCH.patch"
1007
1008
# apply previous user debug mode created patches
1009
if [[ -f $patch ]]; then
1010
display_alert "Applying existing $1 patch" "$patch" "wrn" && patch --batch --silent -p1 -N < "${patch}"
1011
# read title of a patch in case Git is configured
1012
if [[ -n $(git config user.email) ]]; then
1013
COMMIT_MESSAGE=$(cat "${patch}" | grep Subject | sed -n -e '0,/PATCH/s/.*PATCH]//p' | xargs)
1014
display_alert "Patch name extracted" "$COMMIT_MESSAGE" "wrn"
1015
fi
1016
fi
1017
1018
# prompt to alter source
1019
display_alert "Make your changes in this directory:" "$(pwd)" "wrn"
1020
display_alert "Press <Enter> after you are done" "waiting" "wrn"
1021
read -r </dev/tty
1022
tput cuu1
1023
git add .
1024
# create patch out of changes
1025
if ! git diff-index --quiet --cached HEAD; then
1026
# If Git is configured, create proper patch and ask for a name
1027
if [[ -n $(git config user.email) ]]; then
1028
display_alert "Add / change patch name" "$COMMIT_MESSAGE" "wrn"
1029
read -e -p "Patch description: " -i "$COMMIT_MESSAGE" COMMIT_MESSAGE
1030
[[ -z "$COMMIT_MESSAGE" ]] && COMMIT_MESSAGE="Patching something"
1031
git commit -s -m "$COMMIT_MESSAGE"
1032
git format-patch -1 HEAD --stdout --signature="Created with orangepi build tools https://github.com/orangepi-xunlong/build" > "${patch}"
1033
PATCHFILE=$(git format-patch -1 HEAD)
1034
rm $PATCHFILE # delete the actual file
1035
# create a symlink to have a nice name ready
1036
find $DEST/patch/ -type l -delete # delete any existing
1037
ln -sf $patch $DEST/patch/$PATCHFILE
1038
else
1039
git diff --staged > "${patch}"
1040
fi
1041
display_alert "You will find your patch here:" "$patch" "info"
1042
else
1043
display_alert "No changes found, skipping patch creation" "" "wrn"
1044
fi
1045
git reset --soft HEAD~
1046
for i in {3..1..1}; do echo -n "$i." && sleep 1; done
1047
}
1048
1049
# overlayfs_wrapper <operation> <workdir> <description>
1050
#
1051
# <operation>: wrap|cleanup
1052
# <workdir>: path to source directory
1053
# <description>: suffix for merged directory to help locating it in /tmp
1054
# return value: new directory
1055
#
1056
# Assumptions/notes:
1057
# - Ubuntu Xenial host
1058
# - /tmp is mounted as tmpfs
1059
# - there is enough space on /tmp
1060
# - UB if running multiple compilation tasks in parallel
1061
# - should not be used with CREATE_PATCHES=yes
1062
#
1063
overlayfs_wrapper()
1064
{
1065
local operation="$1"
1066
if [[ $operation == wrap ]]; then
1067
local srcdir="$2"
1068
local description="$3"
1069
mkdir -p /tmp/overlay_components/ /tmp/orangepi_build/
1070
local tempdir workdir mergeddir
1071
tempdir=$(mktemp -d --tmpdir="/tmp/overlay_components/")
1072
workdir=$(mktemp -d --tmpdir="/tmp/overlay_components/")
1073
mergeddir=$(mktemp -d --suffix="_$description" --tmpdir="/tmp/orangepi_build/")
1074
mount -t overlay overlay -o lowerdir="$srcdir",upperdir="$tempdir",workdir="$workdir" "$mergeddir"
1075
# this is executed in a subshell, so use temp files to pass extra data outside
1076
echo "$tempdir" >> /tmp/.overlayfs_wrapper_cleanup
1077
echo "$mergeddir" >> /tmp/.overlayfs_wrapper_umount
1078
echo "$mergeddir" >> /tmp/.overlayfs_wrapper_cleanup
1079
echo "$mergeddir"
1080
return
1081
fi
1082
if [[ $operation == cleanup ]]; then
1083
if [[ -f /tmp/.overlayfs_wrapper_umount ]]; then
1084
for dir in $(</tmp/.overlayfs_wrapper_umount); do
1085
[[ $dir == /tmp/* ]] && umount -l "$dir" > /dev/null 2>&1
1086
done
1087
fi
1088
if [[ -f /tmp/.overlayfs_wrapper_cleanup ]]; then
1089
for dir in $(</tmp/.overlayfs_wrapper_cleanup); do
1090
[[ $dir == /tmp/* ]] && rm -rf "$dir"
1091
done
1092
fi
1093
rm -f /tmp/.overlayfs_wrapper_umount /tmp/.overlayfs_wrapper_cleanup
1094
fi
1095
}
1096
1097