Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong
GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/scripts/compilation.sh
17683 views
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
if [[ ${BOARDFAMILY} == cix ]]; then
510
[[ -d ${SRC}/output/cix ]] && rm -rf ${SRC}/output/cix
511
mkdir -p ${SRC}/output/cix/ > /dev/null 2>&1
512
cp ${kerneldir}/arch/arm64/boot/Image ${SRC}/output/cix/
513
cp ${kerneldir}/arch/arm64/boot/dts/cix/sky1-*dtb ${SRC}/output/cix/
514
fi
515
516
# different packaging for 4.3+
517
if linux-version compare "${version}" ge 4.3; then
518
local kernel_packing="bindeb-pkg"
519
else
520
local kernel_packing="deb-pkg"
521
fi
522
523
#if [[ $BRANCH == legacy && $LINUXFAMILY =~ sun50iw2|sun50iw6|sun50iw9 ]]; then
524
# make -C modules/gpu LICHEE_MOD_DIR=${SRC}/.tmp/gpu_modules_${LINUXFAMILY} LICHEE_KDIR=${kerneldir} CROSS_COMPILE=$toolchain/$KERNEL_COMPILER ARCH=$ARCHITECTURE
525
#fi
526
527
display_alert "Creating packages"
528
529
# produce deb packages: image, headers, firmware, dtb
530
echo -e "\n\t== deb packages: image, headers, firmware, dtb ==\n" >> "${DEST}"/${LOG_SUBPATH}/compilation.log
531
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
532
'make $CTHREADS $kernel_packing \
533
KDEB_PKGVERSION=$REVISION \
534
KDEB_COMPRESS=${DEB_COMPRESS} \
535
BRANCH=$BRANCH \
536
LOCALVERSION="-${LINUXFAMILY}" \
537
KBUILD_DEBARCH=$ARCH \
538
ARCH=$ARCHITECTURE \
539
DEBFULLNAME="$MAINTAINER" \
540
DEBEMAIL="$MAINTAINERMAIL" \
541
CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" 2>>$DEST/${LOG_SUBPATH}/compilation.log' \
542
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/${LOG_SUBPATH}/compilation.log'} \
543
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Creating kernel packages..." $TTY_Y $TTY_X'} \
544
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
545
546
cd .. || exit
547
# remove firmare image packages here - easier than patching ~40 packaging scripts at once
548
rm -f linux-firmware-image-*.deb
549
550
rsync --remove-source-files -rq ./*.deb "${DEB_STORAGE}/" || exit_with_error "Failed moving kernel DEBs"
551
552
[[ $(type -t family_tweaks_kernel) == function ]] && family_tweaks_kernel
553
554
# store git hash to the file and create a change log
555
#HASHTARGET="${EXTER}/cache/hash"$([[ ${BETA} == yes ]] && echo "-beta")"/linux-image-${BRANCH}-${LINUXFAMILY}"
556
#OLDHASHTARGET=$(head -1 "${HASHTARGET}.githash" 2>/dev/null)
557
558
# check if OLDHASHTARGET commit exists otherwise use oldest
559
#if [[ -z ${KERNEL_VERSION_LEVEL} ]]; then
560
# git -C ${kerneldir} cat-file -t ${OLDHASHTARGET} >/dev/null 2>&1
561
# [[ $? -ne 0 ]] && OLDHASHTARGET=$(git -C ${kerneldir} show HEAD~199 --pretty=format:"%H" --no-patch)
562
# else
563
# git -C ${kerneldir} cat-file -t ${OLDHASHTARGET} >/dev/null 2>&1
564
# [[ $? -ne 0 ]] && OLDHASHTARGET=$(git -C ${kerneldir} rev-list --max-parents=0 HEAD)
565
#fi
566
567
#[[ -z ${KERNELPATCHDIR} ]] && KERNELPATCHDIR=$LINUXFAMILY-$BRANCH
568
#[[ -z ${LINUXCONFIG} ]] && LINUXCONFIG=linux-$LINUXFAMILY-$BRANCH
569
570
# calculate URL
571
#if [[ "$KERNELSOURCE" == *"github.com"* ]]; then
572
# URL="${KERNELSOURCE/git:/https:}/commit/${HASH}"
573
#elif [[ "$KERNELSOURCE" == *"kernel.org"* ]]; then
574
# URL="${KERNELSOURCE/git:/https:}/commit/?h=$(echo $KERNELBRANCH | cut -d":" -f2)&id=${HASH}"
575
#else
576
# URL="${KERNELSOURCE}/+/$HASH"
577
#fi
578
579
# create change log
580
#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"
581
582
#echo "${hash}" > "${HASHTARGET}.githash"
583
#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)
584
#hash_watch_2=$(cat "${EXTER}/config/kernel/${LINUXCONFIG}.config")
585
#echo "${hash_watch_1}${hash_watch_2}" | improved_git hash-object --stdin >> "${HASHTARGET}.githash"
586
587
}
588
589
590
591
592
compile_firmware()
593
{
594
display_alert "Merging and packaging linux firmware" "@host" "info"
595
596
local firmwaretempdir plugin_dir
597
598
firmwaretempdir=$(mktemp -d)
599
chmod 700 ${firmwaretempdir}
600
trap "ret=\$?; rm -rf \"${firmwaretempdir}\" ; exit \$ret" 0 1 2 3 15
601
plugin_dir="orangepi-firmware${FULL}"
602
mkdir -p "${firmwaretempdir}/${plugin_dir}/lib/firmware"
603
604
if [[ $GITEE_SERVER == yes ]]; then
605
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "https://gitee.com/orangepi-xunlong/firmware" "${EXTER}/cache/sources/orangepi-firmware-git" "branch:master"
606
else
607
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "https://github.com/orangepi-xunlong/firmware" "${EXTER}/cache/sources/orangepi-firmware-git" "branch:master"
608
fi
609
610
if [[ -n $FULL ]]; then
611
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "$MAINLINE_FIRMWARE_SOURCE" "${EXTER}/cache/sources/linux-firmware-git" "branch:master"
612
# cp : create hardlinks
613
cp -af --reflink=auto "${EXTER}"/cache/sources/linux-firmware-git/* "${firmwaretempdir}/${plugin_dir}/lib/firmware/"
614
fi
615
# overlay our firmware
616
# cp : create hardlinks
617
cp -af --reflink=auto "${EXTER}"/cache/sources/orangepi-firmware-git/* "${firmwaretempdir}/${plugin_dir}/lib/firmware/"
618
619
# cleanup what's not needed for sure
620
rm -rf "${firmwaretempdir}/${plugin_dir}"/lib/firmware/{amdgpu,amd-ucode,radeon,nvidia,matrox,.git}
621
cd "${firmwaretempdir}/${plugin_dir}" || exit
622
623
# set up control file
624
mkdir -p DEBIAN
625
cat <<-END > DEBIAN/control
626
Package: orangepi-firmware${FULL}
627
Version: $REVISION
628
Architecture: all
629
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
630
Installed-Size: 1
631
Replaces: linux-firmware, firmware-brcm80211, firmware-ralink, firmware-samsung, firmware-realtek, orangepi-firmware${REPLACE}
632
Section: kernel
633
Priority: optional
634
Description: Linux firmware${FULL}
635
END
636
637
cd "${firmwaretempdir}" || exit
638
# pack
639
mv "orangepi-firmware${FULL}" "orangepi-firmware${FULL}_${REVISION}_all"
640
display_alert "Building firmware package" "orangepi-firmware${FULL}_${REVISION}_all" "info"
641
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "orangepi-firmware${FULL}_${REVISION}_all" >> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
642
mv "orangepi-firmware${FULL}_${REVISION}_all" "orangepi-firmware${FULL}"
643
rsync -rq "orangepi-firmware${FULL}_${REVISION}_all.deb" "${DEB_STORAGE}/"
644
645
# remove temp directory
646
rm -rf "${firmwaretempdir}"
647
}
648
649
650
651
652
compile_orangepi-zsh()
653
{
654
655
local tmp_dir orangepi_zsh_dir
656
tmp_dir=$(mktemp -d)
657
chmod 700 ${tmp_dir}
658
trap "rm -rf \"${tmp_dir}\" ; exit 0" 0 1 2 3 15
659
orangepi_zsh_dir=orangepi-zsh_${REVISION}_all
660
display_alert "Building deb" "orangepi-zsh" "info"
661
662
if [[ $GITEE_SERVER == yes ]]; then
663
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "https://gitee.com/orangepi-xunlong/oh-my-zsh" "${EXTER}/cache/sources/oh-my-zsh" "branch:master"
664
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "https://gitee.com/orangepi-xunlong/evalcache" "${EXTER}/cache/sources/evalcache" "branch:master"
665
else
666
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "https://github.com/robbyrussell/oh-my-zsh" "${EXTER}/cache/sources/oh-my-zsh" "branch:master"
667
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "https://github.com/mroth/evalcache" "${EXTER}/cache/sources/evalcache" "branch:master"
668
fi
669
670
mkdir -p "${tmp_dir}/${orangepi_zsh_dir}"/{DEBIAN,etc/skel/,etc/oh-my-zsh/,/etc/skel/.oh-my-zsh/cache}
671
672
# set up control file
673
cat <<-END > "${tmp_dir}/${orangepi_zsh_dir}"/DEBIAN/control
674
Package: orangepi-zsh
675
Version: $REVISION
676
Architecture: all
677
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
678
Depends: zsh, tmux
679
Section: utils
680
Priority: optional
681
Description: Orange Pi improved ZShell
682
END
683
684
# set up post install script
685
cat <<-END > "${tmp_dir}/${orangepi_zsh_dir}"/DEBIAN/postinst
686
#!/bin/sh
687
688
# copy cache directory if not there yet
689
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 {}'
690
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 {}'
691
692
# fix owner permissions in home directory
693
awk -F'[:]' '{if (\$3 >= 1000 && \$3 != 65534 || \$3 == 0) print ""\$1":"\$3" "\$6"/.oh-my-zsh"}' /etc/passwd | xargs -n2 chown -R
694
awk -F'[:]' '{if (\$3 >= 1000 && \$3 != 65534 || \$3 == 0) print ""\$1":"\$3" "\$6"/.zshrc"}' /etc/passwd | xargs -n2 chown -R
695
696
# add support for bash profile
697
! grep emulate /etc/zsh/zprofile >/dev/null && echo "emulate sh -c 'source /etc/profile'" >> /etc/zsh/zprofile
698
exit 0
699
END
700
701
cp -R "${EXTER}"/cache/sources/oh-my-zsh "${tmp_dir}/${orangepi_zsh_dir}"/etc/
702
cp -R "${EXTER}"/cache/sources/evalcache "${tmp_dir}/${orangepi_zsh_dir}"/etc/oh-my-zsh/plugins
703
cp "${tmp_dir}/${orangepi_zsh_dir}"/etc/oh-my-zsh/templates/zshrc.zsh-template "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
704
705
chmod -R g-w,o-w "${tmp_dir}/${orangepi_zsh_dir}"/etc/oh-my-zsh/
706
707
# we have common settings
708
sed -i "s/^export ZSH=.*/export ZSH=\/etc\/oh-my-zsh/" "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
709
710
# user cache
711
sed -i "/^export ZSH=.*/a export ZSH_CACHE_DIR=~\/.oh-my-zsh\/cache" "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
712
713
# define theme
714
sed -i 's/^ZSH_THEME=.*/ZSH_THEME="mrtazz"/' "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
715
716
# disable prompt while update
717
sed -i 's/# DISABLE_UPDATE_PROMPT="true"/DISABLE_UPDATE_PROMPT="true"/g' "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
718
719
# disable auto update since we provide update via package
720
sed -i 's/# DISABLE_AUTO_UPDATE="true"/DISABLE_AUTO_UPDATE="true"/g' "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
721
722
# define default plugins
723
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
724
725
chmod 755 "${tmp_dir}/${orangepi_zsh_dir}"/DEBIAN/postinst
726
727
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "${tmp_dir}/${orangepi_zsh_dir}" >> "${DEST}"/${LOG_SUBPATH}/output.log 2>&1
728
rsync --remove-source-files -rq "${tmp_dir}/${orangepi_zsh_dir}.deb" "${DEB_STORAGE}/"
729
rm -rf "${tmp_dir}"
730
731
}
732
733
734
735
compile_plymouth-theme-orangepi()
736
{
737
738
local tmp_dir work_dir
739
tmp_dir=$(mktemp -d)
740
chmod 700 ${tmp_dir}
741
trap "ret=\$?; rm -rf \"${tmp_dir}\" ; exit \$ret" 0 1 2 3 15
742
plymouth_theme_orangepi_dir=orangepi-plymouth-theme_${REVISION}_all
743
display_alert "Building deb" "orangepi-plymouth-theme" "info"
744
745
mkdir -p "${tmp_dir}/${plymouth_theme_orangepi_dir}"/{DEBIAN,usr/share/plymouth/themes/orangepi}
746
747
# set up control file
748
cat <<- END > "${tmp_dir}/${plymouth_theme_orangepi_dir}"/DEBIAN/control
749
Package: orangepi-plymouth-theme
750
Version: $REVISION
751
Architecture: all
752
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
753
Depends: plymouth, plymouth-themes
754
Section: universe/x11
755
Priority: optional
756
Description: boot animation, logger and I/O multiplexer - orangepi theme
757
END
758
759
cp "${EXTER}"/packages/plymouth-theme-orangepi/debian/{postinst,prerm,postrm} \
760
"${tmp_dir}/${plymouth_theme_orangepi_dir}"/DEBIAN/
761
chmod 755 "${tmp_dir}/${plymouth_theme_orangepi_dir}"/DEBIAN/{postinst,prerm,postrm}
762
763
#convert -resize 256x256 \
764
# "${EXTER}"/packages/plymouth-theme-orangepi/orangepi-logo.png \
765
# "${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/bgrt-fallback.png
766
767
# convert -resize 52x52 \
768
# "${EXTER}"/packages/plymouth-theme-orangepi/spinner.gif \
769
# "${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/animation-%04d.png
770
771
convert -resize 52x52 \
772
"${EXTER}"/packages/plymouth-theme-orangepi/spinner.gif \
773
"${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/throbber-%04d.png
774
775
cp "${EXTER}"/packages/plymouth-theme-orangepi/watermark.png \
776
"${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/
777
778
cp "${EXTER}"/packages/plymouth-theme-orangepi/{bullet,capslock,entry,keyboard,keymap-render,lock}.png \
779
"${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/
780
781
cp "${EXTER}"/packages/plymouth-theme-orangepi/orangepi.plymouth \
782
"${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/
783
784
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "${tmp_dir}/${plymouth_theme_orangepi_dir}" > /dev/null
785
rsync --remove-source-files -rq "${tmp_dir}/${plymouth_theme_orangepi_dir}.deb" "${DEB_STORAGE}/"
786
rm -rf "${tmp_dir}"
787
}
788
789
compile_orangepi-config()
790
{
791
local tmpdir=${SRC}/.tmp/orangepi-config_${REVISION}_all
792
793
display_alert "Building deb" "orangepi-config" "info"
794
795
796
mkdir -p "${tmpdir}"/{DEBIAN,usr/bin/,usr/sbin/,usr/lib/orangepi-config/}
797
798
# set up control file
799
cat <<-END > "${tmpdir}"/DEBIAN/control
800
Package: orangepi-config
801
Version: $REVISION
802
Architecture: all
803
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
804
Replaces: orangepi-bsp
805
Depends: bash, iperf3, psmisc, curl, bc, expect, dialog, pv, \
806
debconf-utils, unzip, build-essential, html2text, apt-transport-https, html2text, dirmngr, software-properties-common
807
Recommends: orangepi-bsp
808
Suggests: libpam-google-authenticator, qrencode, network-manager, sunxi-tools
809
Section: utils
810
Priority: optional
811
Description: Orange Pi configuration utility
812
END
813
814
install -m 755 $EXTER/cache/sources/orangepi-config/scripts/tv_grab_file $tmpdir/usr/bin/tv_grab_file
815
install -m 755 $EXTER/cache/sources/orangepi-config/debian-config $tmpdir/usr/sbin/orangepi-config
816
install -m 644 $EXTER/cache/sources/orangepi-config/debian-config-jobs $tmpdir/usr/lib/orangepi-config/jobs.sh
817
install -m 644 $EXTER/cache/sources/orangepi-config/debian-config-submenu $tmpdir/usr/lib/orangepi-config/submenu.sh
818
install -m 644 $EXTER/cache/sources/orangepi-config/debian-config-functions $tmpdir/usr/lib/orangepi-config/functions.sh
819
install -m 644 $EXTER/cache/sources/orangepi-config/debian-config-functions-network $tmpdir/usr/lib/orangepi-config/functions-network.sh
820
install -m 755 $EXTER/cache/sources/orangepi-config/softy $tmpdir/usr/sbin/softy
821
# fallback to replace orangepi-config in BSP
822
ln -sf /usr/sbin/orangepi-config $tmpdir/usr/bin/orangepi-config
823
ln -sf /usr/sbin/softy "${tmpdir}"/usr/bin/softy
824
825
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "${tmpdir}" >/dev/null
826
rsync --remove-source-files -rq "${tmpdir}.deb" "${DEB_STORAGE}/"
827
rm -rf "${tmpdir}"
828
}
829
830
831
832
833
compile_sunxi_tools()
834
{
835
# Compile and install only if git commit hash changed
836
cd $EXTER/cache/sources/sunxi-tools || exit
837
# need to check if /usr/local/bin/sunxi-fexc to detect new Docker containers with old cached sources
838
if [[ ! -f .commit_id || $(improved_git rev-parse @ 2>/dev/null) != $(<.commit_id) || ! -f /usr/local/bin/sunxi-fexc ]]; then
839
display_alert "Compiling" "sunxi-tools" "info"
840
make -s clean >/dev/null
841
make -s tools >/dev/null
842
mkdir -p /usr/local/bin/
843
make install-tools >/dev/null 2>&1
844
improved_git rev-parse @ 2>/dev/null > .commit_id
845
fi
846
}
847
848
install_rkbin_tools()
849
{
850
# install only if git commit hash changed
851
cd "${EXTER}"/cache/sources/rkbin-tools || exit
852
# need to check if /usr/local/bin/sunxi-fexc to detect new Docker containers with old cached sources
853
if [[ ! -f .commit_id || $(improved_git rev-parse @ 2>/dev/null) != $(<.commit_id) || ! -f /usr/local/bin/loaderimage ]]; then
854
display_alert "Installing" "rkbin-tools" "info"
855
mkdir -p /usr/local/bin/
856
install -m 755 tools/loaderimage /usr/local/bin/
857
install -m 755 tools/trust_merger /usr/local/bin/
858
improved_git rev-parse @ 2>/dev/null > .commit_id
859
fi
860
}
861
862
grab_version()
863
{
864
local ver=()
865
ver[0]=$(grep "^VERSION" "${1}"/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
866
ver[1]=$(grep "^PATCHLEVEL" "${1}"/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
867
ver[2]=$(grep "^SUBLEVEL" "${1}"/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
868
ver[3]=$(grep "^EXTRAVERSION" "${1}"/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^-rc[[:digit:]]+')
869
echo "${ver[0]:-0}${ver[1]:+.${ver[1]}}${ver[2]:+.${ver[2]}}${ver[3]}"
870
}
871
872
# find_toolchain <compiler_prefix> <expression>
873
#
874
# returns path to toolchain that satisfies <expression>
875
#
876
find_toolchain()
877
{
878
[[ "${SKIP_EXTERNAL_TOOLCHAINS}" == "yes" ]] && { echo "/usr/bin"; return; }
879
local compiler=$1
880
local expression=$2
881
local dist=10
882
local toolchain=""
883
# extract target major.minor version from expression
884
local target_ver
885
target_ver=$(grep -oE "[[:digit:]]+\.[[:digit:]]" <<< "$expression")
886
for dir in "${SRC}"/toolchains/*/; do
887
# check if is a toolchain for current $ARCH
888
[[ ! -f ${dir}bin/${compiler}gcc ]] && continue
889
# get toolchain major.minor version
890
local gcc_ver
891
gcc_ver=$("${dir}bin/${compiler}gcc" -dumpversion | grep -oE "^[[:digit:]]+\.[[:digit:]]")
892
# check if toolchain version satisfies requirement
893
awk "BEGIN{exit ! ($gcc_ver $expression)}" >/dev/null || continue
894
# check if found version is the closest to target
895
# may need different logic here with more than 1 digit minor version numbers
896
# numbers: 3.9 > 3.10; versions: 3.9 < 3.10
897
# dpkg --compare-versions can be used here if operators are changed
898
local d
899
d=$(awk '{x = $1 - $2}{printf "%.1f\n", (x > 0) ? x : -x}' <<< "$target_ver $gcc_ver")
900
if awk "BEGIN{exit ! ($d < $dist)}" >/dev/null ; then
901
dist=$d
902
toolchain=${dir}bin
903
fi
904
done
905
echo "$toolchain"
906
# logging a stack of used compilers.
907
if [[ -f "${DEST}"/${LOG_SUBPATH}/compiler.log ]]; then
908
if ! grep -q "$toolchain" "${DEST}"/${LOG_SUBPATH}/compiler.log; then
909
echo "$toolchain" >> "${DEST}"/${LOG_SUBPATH}/compiler.log;
910
fi
911
else
912
echo "$toolchain" >> "${DEST}"/${LOG_SUBPATH}/compiler.log;
913
fi
914
}
915
916
# advanced_patch <dest> <family> <board> <target> <branch> <description>
917
#
918
# parameters:
919
# <dest>: u-boot, kernel, atf
920
# <family>: u-boot: u-boot; kernel: sunxi-next, ...
921
# <board>: orangepipcplus, orangepizero ...
922
# <target>: optional subdirectory
923
# <description>: additional description text
924
#
925
# priority:
926
# $USERPATCHES_PATH/<dest>/<family>/target_<target>
927
# $USERPATCHES_PATH/<dest>/<family>/board_<board>
928
# $USERPATCHES_PATH/<dest>/<family>/branch_<branch>
929
# $USERPATCHES_PATH/<dest>/<family>
930
# $EXTER/patch/<dest>/<family>/target_<target>
931
# $EXTER/patch/<dest>/<family>/board_<board>
932
# $EXTER/patch/<dest>/<family>/branch_<branch>
933
# $EXTER/patch/<dest>/<family>
934
#
935
advanced_patch()
936
{
937
local dest=$1
938
local family=$2
939
local board=$3
940
local target=$4
941
local branch=$5
942
local description=$6
943
944
display_alert "Started patching process for" "$dest $description" "info"
945
display_alert "Looking for user patches in" "userpatches/$dest/$family" "info"
946
947
local names=()
948
local dirs=(
949
"$USERPATCHES_PATH/$dest/$family/target_${target}:[\e[33mu\e[0m][\e[34mt\e[0m]"
950
"$USERPATCHES_PATH/$dest/$family/board_${board}:[\e[33mu\e[0m][\e[35mb\e[0m]"
951
"$USERPATCHES_PATH/$dest/$family/branch_${branch}:[\e[33mu\e[0m][\e[33mb\e[0m]"
952
"$USERPATCHES_PATH/$dest/$family:[\e[33mu\e[0m][\e[32mc\e[0m]"
953
"$EXTER/patch/$dest/$family/target_${target}:[\e[32ml\e[0m][\e[34mt\e[0m]"
954
"$EXTER/patch/$dest/$family/board_${board}:[\e[32ml\e[0m][\e[35mb\e[0m]"
955
"$EXTER/patch/$dest/$family/branch_${branch}:[\e[32ml\e[0m][\e[33mb\e[0m]"
956
"$EXTER/patch/$dest/$family:[\e[32ml\e[0m][\e[32mc\e[0m]"
957
)
958
local links=()
959
960
# required for "for" command
961
shopt -s nullglob dotglob
962
# get patch file names
963
for dir in "${dirs[@]}"; do
964
for patch in ${dir%%:*}/*.patch; do
965
names+=($(basename "${patch}"))
966
done
967
# add linked patch directories
968
if [[ -d ${dir%%:*} ]]; then
969
local findlinks
970
findlinks=$(find "${dir%%:*}" -maxdepth 1 -type l -print0 2>&1 | xargs -0)
971
[[ -n $findlinks ]] && readarray -d '' links < <(find "${findlinks}" -maxdepth 1 -type f -follow -print -iname "*.patch" -print | grep "\.patch$" | sed "s|${dir%%:*}/||g" 2>&1)
972
fi
973
done
974
# merge static and linked
975
names=("${names[@]}" "${links[@]}")
976
# remove duplicates
977
local names_s=($(echo "${names[@]}" | tr ' ' '\n' | LC_ALL=C sort -u | tr '\n' ' '))
978
# apply patches
979
for name in "${names_s[@]}"; do
980
for dir in "${dirs[@]}"; do
981
if [[ -f ${dir%%:*}/$name ]]; then
982
if [[ -s ${dir%%:*}/$name ]]; then
983
process_patch_file "${dir%%:*}/$name" "${dir##*:}"
984
else
985
display_alert "* ${dir##*:} $name" "skipped"
986
fi
987
break # next name
988
fi
989
done
990
done
991
}
992
993
# process_patch_file <file> <description>
994
#
995
# parameters:
996
# <file>: path to patch file
997
# <status>: additional status text
998
#
999
process_patch_file()
1000
{
1001
local patch=$1
1002
local status=$2
1003
1004
# detect and remove files which patch will create
1005
lsdiff -s --strip=1 "${patch}" | grep '^+' | awk '{print $2}' | xargs -I % sh -c 'rm -f %'
1006
1007
echo "Processing file $patch" >> "${DEST}"/${LOG_SUBPATH}/patching.log
1008
patch --batch --silent -p1 -N < "${patch}" >> "${DEST}"/${LOG_SUBPATH}/patching.log 2>&1
1009
1010
if [[ $? -ne 0 ]]; then
1011
display_alert "* $status $(basename "${patch}")" "failed" "wrn"
1012
[[ $EXIT_PATCHING_ERROR == yes ]] && exit_with_error "Aborting due to" "EXIT_PATCHING_ERROR"
1013
else
1014
display_alert "* $status $(basename "${patch}")" "" "info"
1015
fi
1016
echo >> "${DEST}"/${LOG_SUBPATH}/patching.log
1017
}
1018
1019
userpatch_create()
1020
{
1021
# create commit to start from clean source
1022
git add .
1023
git -c user.name='Orange Pi User' -c user.email='[email protected]' commit -q -m "Cleaning working copy"
1024
1025
local patch="$DEST/patch/$1-$LINUXFAMILY-$BRANCH.patch"
1026
1027
# apply previous user debug mode created patches
1028
if [[ -f $patch ]]; then
1029
display_alert "Applying existing $1 patch" "$patch" "wrn" && patch --batch --silent -p1 -N < "${patch}"
1030
# read title of a patch in case Git is configured
1031
if [[ -n $(git config user.email) ]]; then
1032
COMMIT_MESSAGE=$(cat "${patch}" | grep Subject | sed -n -e '0,/PATCH/s/.*PATCH]//p' | xargs)
1033
display_alert "Patch name extracted" "$COMMIT_MESSAGE" "wrn"
1034
fi
1035
fi
1036
1037
# prompt to alter source
1038
display_alert "Make your changes in this directory:" "$(pwd)" "wrn"
1039
display_alert "Press <Enter> after you are done" "waiting" "wrn"
1040
read -r </dev/tty
1041
tput cuu1
1042
git add .
1043
# create patch out of changes
1044
if ! git diff-index --quiet --cached HEAD; then
1045
# If Git is configured, create proper patch and ask for a name
1046
if [[ -n $(git config user.email) ]]; then
1047
display_alert "Add / change patch name" "$COMMIT_MESSAGE" "wrn"
1048
read -e -p "Patch description: " -i "$COMMIT_MESSAGE" COMMIT_MESSAGE
1049
[[ -z "$COMMIT_MESSAGE" ]] && COMMIT_MESSAGE="Patching something"
1050
git commit -s -m "$COMMIT_MESSAGE"
1051
git format-patch -1 HEAD --stdout --signature="Created with orangepi build tools https://github.com/orangepi-xunlong/build" > "${patch}"
1052
PATCHFILE=$(git format-patch -1 HEAD)
1053
rm $PATCHFILE # delete the actual file
1054
# create a symlink to have a nice name ready
1055
find $DEST/patch/ -type l -delete # delete any existing
1056
ln -sf $patch $DEST/patch/$PATCHFILE
1057
else
1058
git diff --staged > "${patch}"
1059
fi
1060
display_alert "You will find your patch here:" "$patch" "info"
1061
else
1062
display_alert "No changes found, skipping patch creation" "" "wrn"
1063
fi
1064
git reset --soft HEAD~
1065
for i in {3..1..1}; do echo -n "$i." && sleep 1; done
1066
}
1067
1068
# overlayfs_wrapper <operation> <workdir> <description>
1069
#
1070
# <operation>: wrap|cleanup
1071
# <workdir>: path to source directory
1072
# <description>: suffix for merged directory to help locating it in /tmp
1073
# return value: new directory
1074
#
1075
# Assumptions/notes:
1076
# - Ubuntu Xenial host
1077
# - /tmp is mounted as tmpfs
1078
# - there is enough space on /tmp
1079
# - UB if running multiple compilation tasks in parallel
1080
# - should not be used with CREATE_PATCHES=yes
1081
#
1082
overlayfs_wrapper()
1083
{
1084
local operation="$1"
1085
if [[ $operation == wrap ]]; then
1086
local srcdir="$2"
1087
local description="$3"
1088
mkdir -p /tmp/overlay_components/ /tmp/orangepi_build/
1089
local tempdir workdir mergeddir
1090
tempdir=$(mktemp -d --tmpdir="/tmp/overlay_components/")
1091
workdir=$(mktemp -d --tmpdir="/tmp/overlay_components/")
1092
mergeddir=$(mktemp -d --suffix="_$description" --tmpdir="/tmp/orangepi_build/")
1093
mount -t overlay overlay -o lowerdir="$srcdir",upperdir="$tempdir",workdir="$workdir" "$mergeddir"
1094
# this is executed in a subshell, so use temp files to pass extra data outside
1095
echo "$tempdir" >> /tmp/.overlayfs_wrapper_cleanup
1096
echo "$mergeddir" >> /tmp/.overlayfs_wrapper_umount
1097
echo "$mergeddir" >> /tmp/.overlayfs_wrapper_cleanup
1098
echo "$mergeddir"
1099
return
1100
fi
1101
if [[ $operation == cleanup ]]; then
1102
if [[ -f /tmp/.overlayfs_wrapper_umount ]]; then
1103
for dir in $(</tmp/.overlayfs_wrapper_umount); do
1104
[[ $dir == /tmp/* ]] && umount -l "$dir" > /dev/null 2>&1
1105
done
1106
fi
1107
if [[ -f /tmp/.overlayfs_wrapper_cleanup ]]; then
1108
for dir in $(</tmp/.overlayfs_wrapper_cleanup); do
1109
[[ $dir == /tmp/* ]] && rm -rf "$dir"
1110
done
1111
fi
1112
rm -f /tmp/.overlayfs_wrapper_umount /tmp/.overlayfs_wrapper_cleanup
1113
fi
1114
}
1115
1116