Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong
GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/scripts/compilation.sh
23658 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 write_uboot_platform_ufs)
292
$(declare -f setup_write_uboot_platform)
293
EOF
294
295
# set up control file
296
cat <<-EOF > "$uboottempdir/${uboot_name}/DEBIAN/control"
297
Package: linux-u-boot-${BOARD}-${BRANCH}
298
Version: $REVISION
299
Architecture: $ARCH
300
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
301
Installed-Size: 1
302
Section: kernel
303
Priority: optional
304
Provides: orangepi-u-boot
305
Replaces: orangepi-u-boot
306
Conflicts: orangepi-u-boot, u-boot-sunxi
307
Description: Uboot loader $version
308
EOF
309
310
# copy config file to the package
311
# useful for FEL boot with overlayfs_wrapper
312
[[ -f .config && -n $BOOTCONFIG ]] && cp .config "$uboottempdir/${uboot_name}/usr/lib/u-boot/${BOOTCONFIG}"
313
# copy license files from typical locations
314
[[ -f COPYING ]] && cp COPYING "$uboottempdir/${uboot_name}/usr/lib/u-boot/LICENSE"
315
[[ -f Licenses/README ]] && cp Licenses/README "$uboottempdir/${uboot_name}/usr/lib/u-boot/LICENSE"
316
[[ -n $atftempdir && -f $atftempdir/license.md ]] && cp "${atftempdir}/license.md" "$uboottempdir/${uboot_name}/usr/lib/u-boot/LICENSE.atf"
317
318
display_alert "Building deb" "${uboot_name}.deb" "info"
319
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "$uboottempdir/${uboot_name}" "$uboottempdir/${uboot_name}.deb" >> "${DEST}"/${LOG_SUBPATH}/output.log 2>&1
320
rm -rf "$uboottempdir/${uboot_name}"
321
[[ -n $atftempdir ]] && rm -rf "${atftempdir}"
322
323
[[ ! -f $uboottempdir/${uboot_name}.deb ]] && exit_with_error "Building u-boot package failed"
324
325
rsync --remove-source-files -rq "$uboottempdir/${uboot_name}.deb" "${DEB_STORAGE}/u-boot/"
326
rm -rf "$uboottempdir"
327
328
fi
329
}
330
331
create_linux-source_package ()
332
{
333
ts=$(date +%s)
334
local sources_pkg_dir tmp_src_dir
335
tmp_src_dir=$(mktemp -d)
336
trap "ret=\$?; rm -rf \"${tmp_src_dir}\" ; exit \$ret" 0 1 2 3 15
337
sources_pkg_dir=${tmp_src_dir}/${CHOSEN_KSRC}_${REVISION}_all
338
mkdir -p "${sources_pkg_dir}"/usr/src/ \
339
"${sources_pkg_dir}"/usr/share/doc/linux-source-${version}-${LINUXFAMILY} \
340
"${sources_pkg_dir}"/DEBIAN
341
342
cp "${EXTER}/config/kernel/${LINUXCONFIG}.config" "default_${LINUXCONFIG}.config"
343
xz < .config > "${sources_pkg_dir}/usr/src/${LINUXCONFIG}_${version}_${REVISION}_config.xz"
344
345
display_alert "Compressing sources for the linux-source package"
346
tar cp --directory="$kerneldir" --exclude='.git' --owner=root . \
347
| pv -p -b -r -s "$(du -sb "$kerneldir" --exclude=='.git' | cut -f1)" \
348
| pixz -4 > "${sources_pkg_dir}/usr/src/linux-source-${version}-${LINUXFAMILY}.tar.xz"
349
cp COPYING "${sources_pkg_dir}/usr/share/doc/linux-source-${version}-${LINUXFAMILY}/LICENSE"
350
351
cat <<-EOF > "${sources_pkg_dir}"/DEBIAN/control
352
Package: linux-source-${version}-${BRANCH}-${LINUXFAMILY}
353
Version: ${version}-${BRANCH}-${LINUXFAMILY}+${REVISION}
354
Architecture: all
355
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
356
Section: kernel
357
Priority: optional
358
Depends: binutils, coreutils
359
Provides: linux-source, linux-source-${version}-${LINUXFAMILY}
360
Recommends: gcc, make
361
Description: This package provides the source code for the Linux kernel $version
362
EOF
363
364
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} -z0 "${sources_pkg_dir}" "${sources_pkg_dir}.deb"
365
rsync --remove-source-files -rq "${sources_pkg_dir}.deb" "${DEB_STORAGE}/"
366
367
te=$(date +%s)
368
display_alert "Make the linux-source package" "$(($te - $ts)) sec." "info"
369
rm -rf "${tmp_src_dir}"
370
}
371
372
compile_kernel()
373
{
374
if [[ $CLEAN_LEVEL == *make* ]]; then
375
display_alert "Cleaning" "$LINUXSOURCEDIR" "info"
376
(cd ${LINUXSOURCEDIR}; make ARCH="${ARCHITECTURE}" clean >/dev/null 2>&1)
377
fi
378
379
if [[ $USE_OVERLAYFS == yes ]]; then
380
local kerneldir
381
kerneldir=$(overlayfs_wrapper "wrap" "$LINUXSOURCEDIR" "kernel_${LINUXFAMILY}_${BRANCH}")
382
else
383
local kerneldir="$LINUXSOURCEDIR"
384
fi
385
cd "${kerneldir}" || exit
386
387
rm -f localversion
388
389
# read kernel version
390
local version hash
391
version=$(grab_version "$kerneldir")
392
393
# read kernel git hash
394
hash=$(improved_git --git-dir="$kerneldir"/.git rev-parse HEAD)
395
396
# Apply a series of patches if a series file exists
397
if test -f "${EXTER}"/patch/kernel/${KERNELPATCHDIR}/series.conf; then
398
display_alert "series.conf file visible. Apply"
399
series_conf="${SRC}"/patch/kernel/${KERNELPATCHDIR}/series.conf
400
401
# apply_patch_series <target dir> <full path to series file>
402
apply_patch_series "${kerneldir}" "$series_conf"
403
fi
404
405
# build 3rd party drivers
406
# compilation_prepare
407
408
advanced_patch "kernel" "$KERNELPATCHDIR" "$BOARD" "" "$BRANCH" "$LINUXFAMILY-$BRANCH"
409
410
# create patch for manual source changes in debug mode
411
[[ $CREATE_PATCHES == yes ]] && userpatch_create "kernel"
412
413
# re-read kernel version after patching
414
local version
415
version=$(grab_version "$kerneldir")
416
417
display_alert "Compiling $BRANCH kernel" "$version" "info"
418
419
# compare with the architecture of the current Debian node
420
# if it matches we use the system compiler
421
if $(dpkg-architecture -e "${ARCH}"); then
422
display_alert "Native compilation"
423
elif [[ $(dpkg --print-architecture) == amd64 ]]; then
424
local toolchain
425
toolchain=$(find_toolchain "$KERNEL_COMPILER" "$KERNEL_USE_GCC")
426
[[ -z $toolchain ]] && exit_with_error "Could not find required toolchain" "${KERNEL_COMPILER}gcc $KERNEL_USE_GCC"
427
else
428
exit_with_error "Architecture [$ARCH] is not supported"
429
fi
430
431
display_alert "Compiler version" "${KERNEL_COMPILER}gcc $(eval env PATH="${toolchain}:${PATH}" "${KERNEL_COMPILER}gcc" -dumpversion)" "info"
432
433
# copy kernel config
434
if [[ $KERNEL_KEEP_CONFIG == yes && -f "${DEST}"/config/$LINUXCONFIG.config ]]; then
435
display_alert "Using previous kernel config" "${DEST}/config/$LINUXCONFIG.config" "info"
436
cp -p "${DEST}/config/${LINUXCONFIG}.config" .config
437
else
438
if [[ -f $USERPATCHES_PATH/$LINUXCONFIG.config ]]; then
439
display_alert "Using kernel config provided by user" "userpatches/$LINUXCONFIG.config" "info"
440
cp -p "${USERPATCHES_PATH}/${LINUXCONFIG}.config" .config
441
else
442
display_alert "Using kernel config file" "${EXTER}/config/kernel/$LINUXCONFIG.config" "info"
443
cp -p "${EXTER}/config/kernel/${LINUXCONFIG}.config" .config
444
fi
445
fi
446
447
call_extension_method "custom_kernel_config" << 'CUSTOM_KERNEL_CONFIG'
448
*Kernel .config is in place, still clean from git version*
449
Called after ${LINUXCONFIG}.config is put in place (.config).
450
Before any olddefconfig any Kconfig make is called.
451
A good place to customize the .config directly.
452
CUSTOM_KERNEL_CONFIG
453
454
455
# hack for deb builder. To pack what's missing in headers pack.
456
cp "$EXTER"/patch/misc/headers-debian-byteshift.patch /tmp
457
458
if [[ $KERNEL_CONFIGURE != yes ]]; then
459
if [[ $BRANCH == legacy && ! $BOARDFAMILY =~ "rockchip-rk3588"|"rockchip-rk356x"|"sun60iw2" ]]; then
460
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
461
'make ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" silentoldconfig'
462
else
463
# TODO: check if required
464
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
465
'make ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" olddefconfig'
466
fi
467
else
468
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
469
'make $CTHREADS ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" oldconfig'
470
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
471
'make $CTHREADS ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" ${KERNEL_MENUCONFIG:-menuconfig}'
472
473
[[ ${PIPESTATUS[0]} -ne 0 ]] && exit_with_error "Error kernel menuconfig failed"
474
475
# store kernel config in easily reachable place
476
display_alert "Exporting new kernel config" "$DEST/config/$LINUXCONFIG.config" "info"
477
cp .config "${DEST}/config/${LINUXCONFIG}.config"
478
cp .config "${EXTER}/config/kernel/${LINUXCONFIG}.config"
479
# export defconfig too if requested
480
if [[ $KERNEL_EXPORT_DEFCONFIG == yes ]]; then
481
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
482
'make ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" savedefconfig'
483
[[ -f defconfig ]] && cp defconfig "${DEST}/config/${LINUXCONFIG}.defconfig"
484
fi
485
fi
486
487
# create linux-source package - with already patched sources
488
# We will build this package first and clear the memory.
489
if [[ $BUILD_KSRC != no ]]; then
490
create_linux-source_package
491
fi
492
493
echo -e "\n\t== kernel ==\n" >> "${DEST}"/${LOG_SUBPATH}/compilation.log
494
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
495
'make $CTHREADS ARCH=$ARCHITECTURE \
496
CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" \
497
$SRC_LOADADDR \
498
LOCALVERSION="-$LINUXFAMILY" \
499
$KERNEL_IMAGE_TYPE ${KERNEL_EXTRA_TARGETS:-modules dtbs} 2>>$DEST/${LOG_SUBPATH}/compilation.log' \
500
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/${LOG_SUBPATH}/compilation.log'} \
501
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" \
502
--progressbox "Compiling kernel..." $TTY_Y $TTY_X'} \
503
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
504
505
if [[ ${PIPESTATUS[0]} -ne 0 || ! -f arch/$ARCHITECTURE/boot/$KERNEL_IMAGE_TYPE ]]; then
506
grep -i error $DEST/${LOG_SUBPATH}/compilation.log
507
exit_with_error "Kernel was not built" "@host"
508
fi
509
510
if [[ ${BOARDFAMILY} == cix ]]; then
511
[[ -d ${SRC}/output/cix ]] && rm -rf ${SRC}/output/cix
512
mkdir -p ${SRC}/output/cix/ > /dev/null 2>&1
513
cp ${kerneldir}/arch/arm64/boot/Image ${SRC}/output/cix/
514
cp ${kerneldir}/arch/arm64/boot/dts/cix/sky1-*dtb ${SRC}/output/cix/
515
fi
516
517
# different packaging for 4.3+
518
if linux-version compare "${version}" ge 4.3; then
519
local kernel_packing="bindeb-pkg"
520
else
521
local kernel_packing="deb-pkg"
522
fi
523
524
#if [[ $BRANCH == legacy && $LINUXFAMILY =~ sun50iw2|sun50iw6|sun50iw9 ]]; then
525
# make -C modules/gpu LICHEE_MOD_DIR=${SRC}/.tmp/gpu_modules_${LINUXFAMILY} LICHEE_KDIR=${kerneldir} CROSS_COMPILE=$toolchain/$KERNEL_COMPILER ARCH=$ARCHITECTURE
526
#fi
527
528
if [[ $LINUXFAMILY =~ sun60iw2 ]]; then
529
make -C bsp/modules/gpu LICHEE_TOOLCHAIN_PATH=$toolchain LICHEE_CROSS_COMPILER=$KERNEL_COMPILER LICHEE_PLATFORM=linux LICHEE_MOD_DIR=${SRC}/.tmp/gpu_modules_${LINUXFAMILY} LICHEE_KERN_DIR=${kerneldir} CROSS_COMPILE=$toolchain/$KERNEL_COMPILER ARCH=$ARCHITECTURE
530
make -C bsp/modules/gpu modules_install LICHEE_TOOLCHAIN_PATH=$toolchain LICHEE_CROSS_COMPILER=$KERNEL_COMPILER LICHEE_PLATFORM=linux LICHEE_MOD_DIR=${SRC}/.tmp/gpu_modules_${LINUXFAMILY} LICHEE_KERN_DIR=${kerneldir} CROSS_COMPILE=$toolchain/$KERNEL_COMPILER ARCH=$ARCHITECTURE
531
fi
532
533
display_alert "Creating packages"
534
535
# produce deb packages: image, headers, firmware, dtb
536
echo -e "\n\t== deb packages: image, headers, firmware, dtb ==\n" >> "${DEST}"/${LOG_SUBPATH}/compilation.log
537
eval CCACHE_BASEDIR="$(pwd)" env PATH="${toolchain}:${PATH}" \
538
'make $CTHREADS $kernel_packing \
539
KDEB_PKGVERSION=$REVISION \
540
KDEB_COMPRESS=${DEB_COMPRESS} \
541
BRANCH=$BRANCH \
542
LOCALVERSION="-${LINUXFAMILY}" \
543
KBUILD_DEBARCH=$ARCH \
544
ARCH=$ARCHITECTURE \
545
DEBFULLNAME="$MAINTAINER" \
546
DEBEMAIL="$MAINTAINERMAIL" \
547
CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" 2>>$DEST/${LOG_SUBPATH}/compilation.log' \
548
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/${LOG_SUBPATH}/compilation.log'} \
549
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Creating kernel packages..." $TTY_Y $TTY_X'} \
550
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
551
552
cd .. || exit
553
# remove firmare image packages here - easier than patching ~40 packaging scripts at once
554
rm -f linux-firmware-image-*.deb
555
556
rsync --remove-source-files -rq ./*.deb "${DEB_STORAGE}/" || exit_with_error "Failed moving kernel DEBs"
557
558
[[ $(type -t family_tweaks_kernel) == function ]] && family_tweaks_kernel
559
560
# store git hash to the file and create a change log
561
#HASHTARGET="${EXTER}/cache/hash"$([[ ${BETA} == yes ]] && echo "-beta")"/linux-image-${BRANCH}-${LINUXFAMILY}"
562
#OLDHASHTARGET=$(head -1 "${HASHTARGET}.githash" 2>/dev/null)
563
564
# check if OLDHASHTARGET commit exists otherwise use oldest
565
#if [[ -z ${KERNEL_VERSION_LEVEL} ]]; then
566
# git -C ${kerneldir} cat-file -t ${OLDHASHTARGET} >/dev/null 2>&1
567
# [[ $? -ne 0 ]] && OLDHASHTARGET=$(git -C ${kerneldir} show HEAD~199 --pretty=format:"%H" --no-patch)
568
# else
569
# git -C ${kerneldir} cat-file -t ${OLDHASHTARGET} >/dev/null 2>&1
570
# [[ $? -ne 0 ]] && OLDHASHTARGET=$(git -C ${kerneldir} rev-list --max-parents=0 HEAD)
571
#fi
572
573
#[[ -z ${KERNELPATCHDIR} ]] && KERNELPATCHDIR=$LINUXFAMILY-$BRANCH
574
#[[ -z ${LINUXCONFIG} ]] && LINUXCONFIG=linux-$LINUXFAMILY-$BRANCH
575
576
# calculate URL
577
#if [[ "$KERNELSOURCE" == *"github.com"* ]]; then
578
# URL="${KERNELSOURCE/git:/https:}/commit/${HASH}"
579
#elif [[ "$KERNELSOURCE" == *"kernel.org"* ]]; then
580
# URL="${KERNELSOURCE/git:/https:}/commit/?h=$(echo $KERNELBRANCH | cut -d":" -f2)&id=${HASH}"
581
#else
582
# URL="${KERNELSOURCE}/+/$HASH"
583
#fi
584
585
# create change log
586
#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"
587
588
#echo "${hash}" > "${HASHTARGET}.githash"
589
#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)
590
#hash_watch_2=$(cat "${EXTER}/config/kernel/${LINUXCONFIG}.config")
591
#echo "${hash_watch_1}${hash_watch_2}" | improved_git hash-object --stdin >> "${HASHTARGET}.githash"
592
593
}
594
595
596
597
598
compile_firmware()
599
{
600
display_alert "Merging and packaging linux firmware" "@host" "info"
601
602
local firmwaretempdir plugin_dir
603
604
firmwaretempdir=$(mktemp -d)
605
chmod 700 ${firmwaretempdir}
606
trap "ret=\$?; rm -rf \"${firmwaretempdir}\" ; exit \$ret" 0 1 2 3 15
607
plugin_dir="orangepi-firmware${FULL}"
608
mkdir -p "${firmwaretempdir}/${plugin_dir}/lib/firmware"
609
610
if [[ $GITEE_SERVER == yes ]]; then
611
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "https://gitee.com/orangepi-xunlong/firmware" "${EXTER}/cache/sources/orangepi-firmware-git" "branch:master"
612
else
613
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "https://github.com/orangepi-xunlong/firmware" "${EXTER}/cache/sources/orangepi-firmware-git" "branch:master"
614
fi
615
616
if [[ -n $FULL ]]; then
617
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "$MAINLINE_FIRMWARE_SOURCE" "${EXTER}/cache/sources/linux-firmware-git" "branch:master"
618
# cp : create hardlinks
619
cp -af --reflink=auto "${EXTER}"/cache/sources/linux-firmware-git/* "${firmwaretempdir}/${plugin_dir}/lib/firmware/"
620
fi
621
# overlay our firmware
622
# cp : create hardlinks
623
cp -af --reflink=auto "${EXTER}"/cache/sources/orangepi-firmware-git/* "${firmwaretempdir}/${plugin_dir}/lib/firmware/"
624
625
# cleanup what's not needed for sure
626
rm -rf "${firmwaretempdir}/${plugin_dir}"/lib/firmware/{amdgpu,amd-ucode,radeon,nvidia,matrox,.git}
627
cd "${firmwaretempdir}/${plugin_dir}" || exit
628
629
# set up control file
630
mkdir -p DEBIAN
631
cat <<-END > DEBIAN/control
632
Package: orangepi-firmware${FULL}
633
Version: $REVISION
634
Architecture: all
635
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
636
Installed-Size: 1
637
Replaces: linux-firmware, firmware-brcm80211, firmware-ralink, firmware-samsung, firmware-realtek, orangepi-firmware${REPLACE}
638
Section: kernel
639
Priority: optional
640
Description: Linux firmware${FULL}
641
END
642
643
cd "${firmwaretempdir}" || exit
644
# pack
645
mv "orangepi-firmware${FULL}" "orangepi-firmware${FULL}_${REVISION}_all"
646
display_alert "Building firmware package" "orangepi-firmware${FULL}_${REVISION}_all" "info"
647
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "orangepi-firmware${FULL}_${REVISION}_all" >> "${DEST}"/${LOG_SUBPATH}/install.log 2>&1
648
mv "orangepi-firmware${FULL}_${REVISION}_all" "orangepi-firmware${FULL}"
649
rsync -rq "orangepi-firmware${FULL}_${REVISION}_all.deb" "${DEB_STORAGE}/"
650
651
# remove temp directory
652
rm -rf "${firmwaretempdir}"
653
}
654
655
656
657
658
compile_orangepi-zsh()
659
{
660
661
local tmp_dir orangepi_zsh_dir
662
tmp_dir=$(mktemp -d)
663
chmod 700 ${tmp_dir}
664
trap "rm -rf \"${tmp_dir}\" ; exit 0" 0 1 2 3 15
665
orangepi_zsh_dir=orangepi-zsh_${REVISION}_all
666
display_alert "Building deb" "orangepi-zsh" "info"
667
668
if [[ $GITEE_SERVER == yes ]]; then
669
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "https://gitee.com/orangepi-xunlong/oh-my-zsh" "${EXTER}/cache/sources/oh-my-zsh" "branch:master"
670
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "https://gitee.com/orangepi-xunlong/evalcache" "${EXTER}/cache/sources/evalcache" "branch:master"
671
else
672
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "https://github.com/robbyrussell/oh-my-zsh" "${EXTER}/cache/sources/oh-my-zsh" "branch:master"
673
[[ $IGNORE_UPDATES != yes ]] && fetch_from_repo "https://github.com/mroth/evalcache" "${EXTER}/cache/sources/evalcache" "branch:master"
674
fi
675
676
mkdir -p "${tmp_dir}/${orangepi_zsh_dir}"/{DEBIAN,etc/skel/,etc/oh-my-zsh/,/etc/skel/.oh-my-zsh/cache}
677
678
# set up control file
679
cat <<-END > "${tmp_dir}/${orangepi_zsh_dir}"/DEBIAN/control
680
Package: orangepi-zsh
681
Version: $REVISION
682
Architecture: all
683
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
684
Depends: zsh, tmux
685
Section: utils
686
Priority: optional
687
Description: Orange Pi improved ZShell
688
END
689
690
# set up post install script
691
cat <<-END > "${tmp_dir}/${orangepi_zsh_dir}"/DEBIAN/postinst
692
#!/bin/sh
693
694
# copy cache directory if not there yet
695
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 {}'
696
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 {}'
697
698
# fix owner permissions in home directory
699
awk -F'[:]' '{if (\$3 >= 1000 && \$3 != 65534 || \$3 == 0) print ""\$1":"\$3" "\$6"/.oh-my-zsh"}' /etc/passwd | xargs -n2 chown -R
700
awk -F'[:]' '{if (\$3 >= 1000 && \$3 != 65534 || \$3 == 0) print ""\$1":"\$3" "\$6"/.zshrc"}' /etc/passwd | xargs -n2 chown -R
701
702
# add support for bash profile
703
! grep emulate /etc/zsh/zprofile >/dev/null && echo "emulate sh -c 'source /etc/profile'" >> /etc/zsh/zprofile
704
exit 0
705
END
706
707
cp -R "${EXTER}"/cache/sources/oh-my-zsh "${tmp_dir}/${orangepi_zsh_dir}"/etc/
708
cp -R "${EXTER}"/cache/sources/evalcache "${tmp_dir}/${orangepi_zsh_dir}"/etc/oh-my-zsh/plugins
709
cp "${tmp_dir}/${orangepi_zsh_dir}"/etc/oh-my-zsh/templates/zshrc.zsh-template "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
710
711
chmod -R g-w,o-w "${tmp_dir}/${orangepi_zsh_dir}"/etc/oh-my-zsh/
712
713
# we have common settings
714
sed -i "s/^export ZSH=.*/export ZSH=\/etc\/oh-my-zsh/" "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
715
716
# user cache
717
sed -i "/^export ZSH=.*/a export ZSH_CACHE_DIR=~\/.oh-my-zsh\/cache" "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
718
719
# define theme
720
sed -i 's/^ZSH_THEME=.*/ZSH_THEME="mrtazz"/' "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
721
722
# disable prompt while update
723
sed -i 's/# DISABLE_UPDATE_PROMPT="true"/DISABLE_UPDATE_PROMPT="true"/g' "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
724
725
# disable auto update since we provide update via package
726
sed -i 's/# DISABLE_AUTO_UPDATE="true"/DISABLE_AUTO_UPDATE="true"/g' "${tmp_dir}/${orangepi_zsh_dir}"/etc/skel/.zshrc
727
728
# define default plugins
729
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
730
731
chmod 755 "${tmp_dir}/${orangepi_zsh_dir}"/DEBIAN/postinst
732
733
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "${tmp_dir}/${orangepi_zsh_dir}" >> "${DEST}"/${LOG_SUBPATH}/output.log 2>&1
734
rsync --remove-source-files -rq "${tmp_dir}/${orangepi_zsh_dir}.deb" "${DEB_STORAGE}/"
735
rm -rf "${tmp_dir}"
736
737
}
738
739
740
741
compile_plymouth-theme-orangepi()
742
{
743
744
local tmp_dir work_dir
745
tmp_dir=$(mktemp -d)
746
chmod 700 ${tmp_dir}
747
trap "ret=\$?; rm -rf \"${tmp_dir}\" ; exit \$ret" 0 1 2 3 15
748
plymouth_theme_orangepi_dir=orangepi-plymouth-theme_${REVISION}_all
749
display_alert "Building deb" "orangepi-plymouth-theme" "info"
750
751
mkdir -p "${tmp_dir}/${plymouth_theme_orangepi_dir}"/{DEBIAN,usr/share/plymouth/themes/orangepi}
752
753
# set up control file
754
cat <<- END > "${tmp_dir}/${plymouth_theme_orangepi_dir}"/DEBIAN/control
755
Package: orangepi-plymouth-theme
756
Version: $REVISION
757
Architecture: all
758
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
759
Depends: plymouth, plymouth-themes
760
Section: universe/x11
761
Priority: optional
762
Description: boot animation, logger and I/O multiplexer - orangepi theme
763
END
764
765
cp "${EXTER}"/packages/plymouth-theme-orangepi/debian/{postinst,prerm,postrm} \
766
"${tmp_dir}/${plymouth_theme_orangepi_dir}"/DEBIAN/
767
chmod 755 "${tmp_dir}/${plymouth_theme_orangepi_dir}"/DEBIAN/{postinst,prerm,postrm}
768
769
#convert -resize 256x256 \
770
# "${EXTER}"/packages/plymouth-theme-orangepi/orangepi-logo.png \
771
# "${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/bgrt-fallback.png
772
773
# convert -resize 52x52 \
774
# "${EXTER}"/packages/plymouth-theme-orangepi/spinner.gif \
775
# "${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/animation-%04d.png
776
777
convert -resize 52x52 \
778
"${EXTER}"/packages/plymouth-theme-orangepi/spinner.gif \
779
"${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/throbber-%04d.png
780
781
cp "${EXTER}"/packages/plymouth-theme-orangepi/watermark.png \
782
"${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/
783
784
cp "${EXTER}"/packages/plymouth-theme-orangepi/{bullet,capslock,entry,keyboard,keymap-render,lock}.png \
785
"${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/
786
787
cp "${EXTER}"/packages/plymouth-theme-orangepi/orangepi.plymouth \
788
"${tmp_dir}/${plymouth_theme_orangepi_dir}"/usr/share/plymouth/themes/orangepi/
789
790
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "${tmp_dir}/${plymouth_theme_orangepi_dir}" > /dev/null
791
rsync --remove-source-files -rq "${tmp_dir}/${plymouth_theme_orangepi_dir}.deb" "${DEB_STORAGE}/"
792
rm -rf "${tmp_dir}"
793
}
794
795
compile_orangepi-config()
796
{
797
local tmpdir=${SRC}/.tmp/orangepi-config_${REVISION}_all
798
799
display_alert "Building deb" "orangepi-config" "info"
800
801
802
mkdir -p "${tmpdir}"/{DEBIAN,usr/bin/,usr/sbin/,usr/lib/orangepi-config/}
803
804
# set up control file
805
cat <<-END > "${tmpdir}"/DEBIAN/control
806
Package: orangepi-config
807
Version: $REVISION
808
Architecture: all
809
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
810
Replaces: orangepi-bsp
811
Depends: bash, iperf3, psmisc, curl, bc, expect, dialog, pv, \
812
debconf-utils, unzip, build-essential, html2text, apt-transport-https, html2text, dirmngr, software-properties-common
813
Recommends: orangepi-bsp
814
Suggests: libpam-google-authenticator, qrencode, network-manager, sunxi-tools
815
Section: utils
816
Priority: optional
817
Description: Orange Pi configuration utility
818
END
819
820
install -m 755 $EXTER/cache/sources/orangepi-config/scripts/tv_grab_file $tmpdir/usr/bin/tv_grab_file
821
install -m 755 $EXTER/cache/sources/orangepi-config/debian-config $tmpdir/usr/sbin/orangepi-config
822
install -m 644 $EXTER/cache/sources/orangepi-config/debian-config-jobs $tmpdir/usr/lib/orangepi-config/jobs.sh
823
install -m 644 $EXTER/cache/sources/orangepi-config/debian-config-submenu $tmpdir/usr/lib/orangepi-config/submenu.sh
824
install -m 644 $EXTER/cache/sources/orangepi-config/debian-config-functions $tmpdir/usr/lib/orangepi-config/functions.sh
825
install -m 644 $EXTER/cache/sources/orangepi-config/debian-config-functions-network $tmpdir/usr/lib/orangepi-config/functions-network.sh
826
install -m 755 $EXTER/cache/sources/orangepi-config/softy $tmpdir/usr/sbin/softy
827
# fallback to replace orangepi-config in BSP
828
ln -sf /usr/sbin/orangepi-config $tmpdir/usr/bin/orangepi-config
829
ln -sf /usr/sbin/softy "${tmpdir}"/usr/bin/softy
830
831
fakeroot dpkg-deb -b -Z${DEB_COMPRESS} "${tmpdir}" >/dev/null
832
rsync --remove-source-files -rq "${tmpdir}.deb" "${DEB_STORAGE}/"
833
rm -rf "${tmpdir}"
834
}
835
836
837
838
839
compile_sunxi_tools()
840
{
841
# Compile and install only if git commit hash changed
842
cd $EXTER/cache/sources/sunxi-tools || exit
843
# need to check if /usr/local/bin/sunxi-fexc to detect new Docker containers with old cached sources
844
if [[ ! -f .commit_id || $(improved_git rev-parse @ 2>/dev/null) != $(<.commit_id) || ! -f /usr/local/bin/sunxi-fexc ]]; then
845
display_alert "Compiling" "sunxi-tools" "info"
846
make -s clean >/dev/null
847
make -s tools >/dev/null
848
mkdir -p /usr/local/bin/
849
make install-tools >/dev/null 2>&1
850
improved_git rev-parse @ 2>/dev/null > .commit_id
851
fi
852
}
853
854
install_rkbin_tools()
855
{
856
# install only if git commit hash changed
857
cd "${EXTER}"/cache/sources/rkbin-tools || exit
858
# need to check if /usr/local/bin/sunxi-fexc to detect new Docker containers with old cached sources
859
if [[ ! -f .commit_id || $(improved_git rev-parse @ 2>/dev/null) != $(<.commit_id) || ! -f /usr/local/bin/loaderimage ]]; then
860
display_alert "Installing" "rkbin-tools" "info"
861
mkdir -p /usr/local/bin/
862
install -m 755 tools/loaderimage /usr/local/bin/
863
install -m 755 tools/trust_merger /usr/local/bin/
864
improved_git rev-parse @ 2>/dev/null > .commit_id
865
fi
866
}
867
868
grab_version()
869
{
870
local ver=()
871
ver[0]=$(grep "^VERSION" "${1}"/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
872
ver[1]=$(grep "^PATCHLEVEL" "${1}"/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
873
ver[2]=$(grep "^SUBLEVEL" "${1}"/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^[[:digit:]]+')
874
ver[3]=$(grep "^EXTRAVERSION" "${1}"/Makefile | head -1 | awk '{print $(NF)}' | grep -oE '^-rc[[:digit:]]+')
875
echo "${ver[0]:-0}${ver[1]:+.${ver[1]}}${ver[2]:+.${ver[2]}}${ver[3]}"
876
}
877
878
# find_toolchain <compiler_prefix> <expression>
879
#
880
# returns path to toolchain that satisfies <expression>
881
#
882
find_toolchain()
883
{
884
[[ "${SKIP_EXTERNAL_TOOLCHAINS}" == "yes" ]] && { echo "/usr/bin"; return; }
885
local compiler=$1
886
local expression=$2
887
local dist=10
888
local toolchain=""
889
# extract target major.minor version from expression
890
local target_ver
891
target_ver=$(grep -oE "[[:digit:]]+\.[[:digit:]]" <<< "$expression")
892
for dir in "${SRC}"/toolchains/*/; do
893
# check if is a toolchain for current $ARCH
894
[[ ! -f ${dir}bin/${compiler}gcc ]] && continue
895
# get toolchain major.minor version
896
local gcc_ver
897
gcc_ver=$("${dir}bin/${compiler}gcc" -dumpversion | grep -oE "^[[:digit:]]+\.[[:digit:]]")
898
# check if toolchain version satisfies requirement
899
awk "BEGIN{exit ! ($gcc_ver $expression)}" >/dev/null || continue
900
# check if found version is the closest to target
901
# may need different logic here with more than 1 digit minor version numbers
902
# numbers: 3.9 > 3.10; versions: 3.9 < 3.10
903
# dpkg --compare-versions can be used here if operators are changed
904
local d
905
d=$(awk '{x = $1 - $2}{printf "%.1f\n", (x > 0) ? x : -x}' <<< "$target_ver $gcc_ver")
906
if awk "BEGIN{exit ! ($d < $dist)}" >/dev/null ; then
907
dist=$d
908
toolchain=${dir}bin
909
fi
910
done
911
echo "$toolchain"
912
# logging a stack of used compilers.
913
if [[ -f "${DEST}"/${LOG_SUBPATH}/compiler.log ]]; then
914
if ! grep -q "$toolchain" "${DEST}"/${LOG_SUBPATH}/compiler.log; then
915
echo "$toolchain" >> "${DEST}"/${LOG_SUBPATH}/compiler.log;
916
fi
917
else
918
echo "$toolchain" >> "${DEST}"/${LOG_SUBPATH}/compiler.log;
919
fi
920
}
921
922
# advanced_patch <dest> <family> <board> <target> <branch> <description>
923
#
924
# parameters:
925
# <dest>: u-boot, kernel, atf
926
# <family>: u-boot: u-boot; kernel: sunxi-next, ...
927
# <board>: orangepipcplus, orangepizero ...
928
# <target>: optional subdirectory
929
# <description>: additional description text
930
#
931
# priority:
932
# $USERPATCHES_PATH/<dest>/<family>/target_<target>
933
# $USERPATCHES_PATH/<dest>/<family>/board_<board>
934
# $USERPATCHES_PATH/<dest>/<family>/branch_<branch>
935
# $USERPATCHES_PATH/<dest>/<family>
936
# $EXTER/patch/<dest>/<family>/target_<target>
937
# $EXTER/patch/<dest>/<family>/board_<board>
938
# $EXTER/patch/<dest>/<family>/branch_<branch>
939
# $EXTER/patch/<dest>/<family>
940
#
941
advanced_patch()
942
{
943
local dest=$1
944
local family=$2
945
local board=$3
946
local target=$4
947
local branch=$5
948
local description=$6
949
950
display_alert "Started patching process for" "$dest $description" "info"
951
display_alert "Looking for user patches in" "userpatches/$dest/$family" "info"
952
953
local names=()
954
local dirs=(
955
"$USERPATCHES_PATH/$dest/$family/target_${target}:[\e[33mu\e[0m][\e[34mt\e[0m]"
956
"$USERPATCHES_PATH/$dest/$family/board_${board}:[\e[33mu\e[0m][\e[35mb\e[0m]"
957
"$USERPATCHES_PATH/$dest/$family/branch_${branch}:[\e[33mu\e[0m][\e[33mb\e[0m]"
958
"$USERPATCHES_PATH/$dest/$family:[\e[33mu\e[0m][\e[32mc\e[0m]"
959
"$EXTER/patch/$dest/$family/target_${target}:[\e[32ml\e[0m][\e[34mt\e[0m]"
960
"$EXTER/patch/$dest/$family/board_${board}:[\e[32ml\e[0m][\e[35mb\e[0m]"
961
"$EXTER/patch/$dest/$family/branch_${branch}:[\e[32ml\e[0m][\e[33mb\e[0m]"
962
"$EXTER/patch/$dest/$family:[\e[32ml\e[0m][\e[32mc\e[0m]"
963
)
964
local links=()
965
966
# required for "for" command
967
shopt -s nullglob dotglob
968
# get patch file names
969
for dir in "${dirs[@]}"; do
970
for patch in ${dir%%:*}/*.patch; do
971
names+=($(basename "${patch}"))
972
done
973
# add linked patch directories
974
if [[ -d ${dir%%:*} ]]; then
975
local findlinks
976
findlinks=$(find "${dir%%:*}" -maxdepth 1 -type l -print0 2>&1 | xargs -0)
977
[[ -n $findlinks ]] && readarray -d '' links < <(find "${findlinks}" -maxdepth 1 -type f -follow -print -iname "*.patch" -print | grep "\.patch$" | sed "s|${dir%%:*}/||g" 2>&1)
978
fi
979
done
980
# merge static and linked
981
names=("${names[@]}" "${links[@]}")
982
# remove duplicates
983
local names_s=($(echo "${names[@]}" | tr ' ' '\n' | LC_ALL=C sort -u | tr '\n' ' '))
984
# apply patches
985
for name in "${names_s[@]}"; do
986
for dir in "${dirs[@]}"; do
987
if [[ -f ${dir%%:*}/$name ]]; then
988
if [[ -s ${dir%%:*}/$name ]]; then
989
process_patch_file "${dir%%:*}/$name" "${dir##*:}"
990
else
991
display_alert "* ${dir##*:} $name" "skipped"
992
fi
993
break # next name
994
fi
995
done
996
done
997
}
998
999
# process_patch_file <file> <description>
1000
#
1001
# parameters:
1002
# <file>: path to patch file
1003
# <status>: additional status text
1004
#
1005
process_patch_file()
1006
{
1007
local patch=$1
1008
local status=$2
1009
1010
# detect and remove files which patch will create
1011
lsdiff -s --strip=1 "${patch}" | grep '^+' | awk '{print $2}' | xargs -I % sh -c 'rm -f %'
1012
1013
echo "Processing file $patch" >> "${DEST}"/${LOG_SUBPATH}/patching.log
1014
patch --batch --silent -p1 -N < "${patch}" >> "${DEST}"/${LOG_SUBPATH}/patching.log 2>&1
1015
1016
if [[ $? -ne 0 ]]; then
1017
display_alert "* $status $(basename "${patch}")" "failed" "wrn"
1018
[[ $EXIT_PATCHING_ERROR == yes ]] && exit_with_error "Aborting due to" "EXIT_PATCHING_ERROR"
1019
else
1020
display_alert "* $status $(basename "${patch}")" "" "info"
1021
fi
1022
echo >> "${DEST}"/${LOG_SUBPATH}/patching.log
1023
}
1024
1025
userpatch_create()
1026
{
1027
# create commit to start from clean source
1028
git add .
1029
git -c user.name='Orange Pi User' -c user.email='[email protected]' commit -q -m "Cleaning working copy"
1030
1031
local patch="$DEST/patch/$1-$LINUXFAMILY-$BRANCH.patch"
1032
1033
# apply previous user debug mode created patches
1034
if [[ -f $patch ]]; then
1035
display_alert "Applying existing $1 patch" "$patch" "wrn" && patch --batch --silent -p1 -N < "${patch}"
1036
# read title of a patch in case Git is configured
1037
if [[ -n $(git config user.email) ]]; then
1038
COMMIT_MESSAGE=$(cat "${patch}" | grep Subject | sed -n -e '0,/PATCH/s/.*PATCH]//p' | xargs)
1039
display_alert "Patch name extracted" "$COMMIT_MESSAGE" "wrn"
1040
fi
1041
fi
1042
1043
# prompt to alter source
1044
display_alert "Make your changes in this directory:" "$(pwd)" "wrn"
1045
display_alert "Press <Enter> after you are done" "waiting" "wrn"
1046
read -r </dev/tty
1047
tput cuu1
1048
git add .
1049
# create patch out of changes
1050
if ! git diff-index --quiet --cached HEAD; then
1051
# If Git is configured, create proper patch and ask for a name
1052
if [[ -n $(git config user.email) ]]; then
1053
display_alert "Add / change patch name" "$COMMIT_MESSAGE" "wrn"
1054
read -e -p "Patch description: " -i "$COMMIT_MESSAGE" COMMIT_MESSAGE
1055
[[ -z "$COMMIT_MESSAGE" ]] && COMMIT_MESSAGE="Patching something"
1056
git commit -s -m "$COMMIT_MESSAGE"
1057
git format-patch -1 HEAD --stdout --signature="Created with orangepi build tools https://github.com/orangepi-xunlong/build" > "${patch}"
1058
PATCHFILE=$(git format-patch -1 HEAD)
1059
rm $PATCHFILE # delete the actual file
1060
# create a symlink to have a nice name ready
1061
find $DEST/patch/ -type l -delete # delete any existing
1062
ln -sf $patch $DEST/patch/$PATCHFILE
1063
else
1064
git diff --staged > "${patch}"
1065
fi
1066
display_alert "You will find your patch here:" "$patch" "info"
1067
else
1068
display_alert "No changes found, skipping patch creation" "" "wrn"
1069
fi
1070
git reset --soft HEAD~
1071
for i in {3..1..1}; do echo -n "$i." && sleep 1; done
1072
}
1073
1074
# overlayfs_wrapper <operation> <workdir> <description>
1075
#
1076
# <operation>: wrap|cleanup
1077
# <workdir>: path to source directory
1078
# <description>: suffix for merged directory to help locating it in /tmp
1079
# return value: new directory
1080
#
1081
# Assumptions/notes:
1082
# - Ubuntu Xenial host
1083
# - /tmp is mounted as tmpfs
1084
# - there is enough space on /tmp
1085
# - UB if running multiple compilation tasks in parallel
1086
# - should not be used with CREATE_PATCHES=yes
1087
#
1088
overlayfs_wrapper()
1089
{
1090
local operation="$1"
1091
if [[ $operation == wrap ]]; then
1092
local srcdir="$2"
1093
local description="$3"
1094
mkdir -p /tmp/overlay_components/ /tmp/orangepi_build/
1095
local tempdir workdir mergeddir
1096
tempdir=$(mktemp -d --tmpdir="/tmp/overlay_components/")
1097
workdir=$(mktemp -d --tmpdir="/tmp/overlay_components/")
1098
mergeddir=$(mktemp -d --suffix="_$description" --tmpdir="/tmp/orangepi_build/")
1099
mount -t overlay overlay -o lowerdir="$srcdir",upperdir="$tempdir",workdir="$workdir" "$mergeddir"
1100
# this is executed in a subshell, so use temp files to pass extra data outside
1101
echo "$tempdir" >> /tmp/.overlayfs_wrapper_cleanup
1102
echo "$mergeddir" >> /tmp/.overlayfs_wrapper_umount
1103
echo "$mergeddir" >> /tmp/.overlayfs_wrapper_cleanup
1104
echo "$mergeddir"
1105
return
1106
fi
1107
if [[ $operation == cleanup ]]; then
1108
if [[ -f /tmp/.overlayfs_wrapper_umount ]]; then
1109
for dir in $(</tmp/.overlayfs_wrapper_umount); do
1110
[[ $dir == /tmp/* ]] && umount -l "$dir" > /dev/null 2>&1
1111
done
1112
fi
1113
if [[ -f /tmp/.overlayfs_wrapper_cleanup ]]; then
1114
for dir in $(</tmp/.overlayfs_wrapper_cleanup); do
1115
[[ $dir == /tmp/* ]] && rm -rf "$dir"
1116
done
1117
fi
1118
rm -f /tmp/.overlayfs_wrapper_umount /tmp/.overlayfs_wrapper_cleanup
1119
fi
1120
}
1121
1122