2016-04-25 19:01:58 +02:00
|
|
|
#!/bin/bash
|
2014-10-07 20:49:46 +02:00
|
|
|
#
|
2015-12-02 20:33:32 +01:00
|
|
|
# Copyright (c) 2015 Igor Pecovnik, igor.pecovnik@gma**.com
|
|
|
|
#
|
|
|
|
# This file is licensed under the terms of the GNU General Public
|
|
|
|
# License version 2. This program is licensed "as is" without any
|
|
|
|
# warranty of any kind, whether express or implied.
|
|
|
|
#
|
|
|
|
# This file is a part of tool chain https://github.com/igorpecovnik/lib
|
2014-10-07 20:49:46 +02:00
|
|
|
#
|
|
|
|
|
2015-12-18 12:22:42 +03:00
|
|
|
# Functions:
|
|
|
|
# compile_uboot
|
|
|
|
# compile_kernel
|
2016-10-24 18:02:58 +03:00
|
|
|
# compile_sunxi_tools
|
2016-04-20 15:38:09 +03:00
|
|
|
# find_toolchain
|
2016-04-18 18:21:43 +03:00
|
|
|
# advanced_patch
|
|
|
|
# process_patch_file
|
2015-12-18 12:22:42 +03:00
|
|
|
# install_external_applications
|
2015-12-25 20:04:33 +03:00
|
|
|
# write_uboot
|
2016-03-19 17:26:15 +03:00
|
|
|
# customize_image
|
2016-10-24 18:02:58 +03:00
|
|
|
# userpatch_create
|
|
|
|
# overlayfs_wrapper
|
2014-10-07 20:49:46 +02:00
|
|
|
|
2016-06-15 19:44:14 +03:00
|
|
|
compile_uboot()
|
|
|
|
{
|
2016-12-09 14:03:39 +03:00
|
|
|
# not optimal, but extra cleaning before overlayfs_wrapper should keep sources directory clean
|
2016-12-08 18:44:41 +03:00
|
|
|
if [[ $CLEAN_LEVEL == *make* ]]; then
|
|
|
|
display_alert "Cleaning" "$BOOTSOURCEDIR" "info"
|
|
|
|
(cd $SOURCES/$BOOTSOURCEDIR; make clean > /dev/null 2>&1)
|
|
|
|
fi
|
|
|
|
|
2016-11-03 20:57:56 +03:00
|
|
|
if [[ $USE_OVERLAYFS == yes ]]; then
|
|
|
|
local ubootdir=$(overlayfs_wrapper "wrap" "$SOURCES/$BOOTSOURCEDIR" "u-boot_${LINUXFAMILY}_${BRANCH}")
|
|
|
|
else
|
|
|
|
local ubootdir="$SOURCES/$BOOTSOURCEDIR"
|
|
|
|
fi
|
2016-10-24 18:02:58 +03:00
|
|
|
cd "$ubootdir"
|
2016-06-14 16:14:40 +03:00
|
|
|
|
2016-10-24 18:02:58 +03:00
|
|
|
# read uboot version
|
|
|
|
local version=$(grab_version "$ubootdir")
|
|
|
|
|
2016-12-20 00:17:11 +03:00
|
|
|
display_alert "Compiling u-boot" "$version" "info"
|
|
|
|
|
|
|
|
local toolchain=""
|
2017-04-29 13:32:09 +03:00
|
|
|
if [[ -n $UBOOT_USE_GCC ]]; then
|
|
|
|
toolchain=$(find_toolchain "$UBOOT_COMPILER" "$UBOOT_USE_GCC")
|
|
|
|
[[ -z $toolchain ]] && exit_with_error "Could not find required toolchain" "${UBOOT_COMPILER}gcc $UBOOT_USE_GCC"
|
2016-12-20 00:17:11 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
display_alert "Compiler version" "${UBOOT_COMPILER}gcc $(eval ${toolchain:+env PATH=$toolchain:$PATH} ${UBOOT_COMPILER}gcc -dumpversion)" "info"
|
2016-03-17 20:16:26 +01:00
|
|
|
|
2016-12-09 14:03:39 +03:00
|
|
|
# create directory structure for the .deb package
|
2016-03-23 20:58:58 +01:00
|
|
|
local uboot_name=${CHOSEN_UBOOT}_${REVISION}_${ARCH}
|
2016-11-03 20:57:56 +03:00
|
|
|
rm -rf $uboot_name
|
|
|
|
mkdir -p $uboot_name/usr/lib/{u-boot,$uboot_name} $uboot_name/DEBIAN
|
2016-03-17 20:16:26 +01:00
|
|
|
|
2016-12-09 14:03:39 +03:00
|
|
|
# process compilation for one or multiple targets
|
|
|
|
while read -r target; do
|
|
|
|
local target_make=$(cut -d';' -f1 <<< $target)
|
|
|
|
local target_patchdir=$(cut -d';' -f2 <<< $target)
|
|
|
|
local target_files=$(cut -d';' -f3 <<< $target)
|
|
|
|
|
2016-12-09 21:13:34 +03:00
|
|
|
display_alert "Checking out sources"
|
|
|
|
git checkout -f -q HEAD
|
|
|
|
|
2016-12-09 14:03:39 +03:00
|
|
|
if [[ $CLEAN_LEVEL == *make* ]]; then
|
|
|
|
display_alert "Cleaning" "$BOOTSOURCEDIR" "info"
|
|
|
|
(cd $SOURCES/$BOOTSOURCEDIR; make clean > /dev/null 2>&1)
|
|
|
|
fi
|
|
|
|
|
2017-01-31 19:21:09 +03:00
|
|
|
[[ $FORCE_CHECKOUT == yes ]] && advanced_patch "u-boot" "$BOOTPATCHDIR" "$BOARD" "$target_patchdir" "$BRANCH" "${LINUXFAMILY}-${BOARD}-${BRANCH}"
|
2016-12-09 14:03:39 +03:00
|
|
|
|
|
|
|
# create patch for manual source changes
|
|
|
|
[[ $CREATE_PATCHES == yes ]] && userpatch_create "u-boot"
|
|
|
|
|
2016-12-20 00:17:11 +03:00
|
|
|
eval CCACHE_BASEDIR="$(pwd)" ${toolchain:+env PATH=$toolchain:$PATH} \
|
2016-12-09 14:03:39 +03:00
|
|
|
'make $CTHREADS $BOOTCONFIG CROSS_COMPILE="$CCACHE $UBOOT_COMPILER"' 2>&1 \
|
|
|
|
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/compilation.log'} \
|
|
|
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
|
|
|
|
|
|
|
[[ -f .config ]] && sed -i 's/CONFIG_LOCALVERSION=""/CONFIG_LOCALVERSION="-armbian"/g' .config
|
|
|
|
[[ -f .config ]] && sed -i 's/CONFIG_LOCALVERSION_AUTO=.*/# CONFIG_LOCALVERSION_AUTO is not set/g' .config
|
2017-03-26 20:54:34 +02:00
|
|
|
[[ -f tools/logos/udoo.bmp ]] && cp $SRC/lib/bin/splash/udoo.bmp tools/logos/udoo.bmp
|
2016-12-09 14:03:39 +03:00
|
|
|
touch .scmversion
|
|
|
|
|
|
|
|
# $BOOTDELAY can be set in board family config, ensure autoboot can be stopped even if set to 0
|
|
|
|
[[ $BOOTDELAY == 0 ]] && echo -e "CONFIG_ZERO_BOOTDELAY_CHECK=y" >> .config
|
|
|
|
[[ -n $BOOTDELAY ]] && sed -i "s/^CONFIG_BOOTDELAY=.*/CONFIG_BOOTDELAY=${BOOTDELAY}/" .config || [[ -f .config ]] && echo "CONFIG_BOOTDELAY=${BOOTDELAY}" >> .config
|
|
|
|
|
2016-12-20 00:17:11 +03:00
|
|
|
eval CCACHE_BASEDIR="$(pwd)" ${toolchain:+env PATH=$toolchain:$PATH} \
|
2016-12-09 14:03:39 +03:00
|
|
|
'make $target_make $CTHREADS CROSS_COMPILE="$CCACHE $UBOOT_COMPILER"' 2>&1 \
|
|
|
|
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/compilation.log'} \
|
|
|
|
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Compiling u-boot..." $TTY_Y $TTY_X'} \
|
|
|
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
|
|
|
|
|
|
|
[[ ${PIPESTATUS[0]} -ne 0 ]] && exit_with_error "U-boot compilation failed"
|
|
|
|
|
|
|
|
# copy files to build directory
|
|
|
|
for f in $target_files; do
|
|
|
|
local f_src=$(cut -d':' -f1 <<< $f)
|
|
|
|
if [[ $f == *:* ]]; then
|
|
|
|
local f_dst=$(cut -d':' -f2 <<< $f)
|
|
|
|
else
|
2016-12-13 17:43:50 +03:00
|
|
|
local f_dst=$(basename $f_src)
|
2016-12-09 14:03:39 +03:00
|
|
|
fi
|
|
|
|
[[ ! -f $f_src ]] && exit_with_error "U-boot file not found" "$(basename $f_src)"
|
|
|
|
cp $f_src $uboot_name/usr/lib/$uboot_name/$f_dst
|
|
|
|
done
|
|
|
|
done <<< "$UBOOT_TARGET_MAP"
|
|
|
|
|
2016-05-03 22:38:14 +03:00
|
|
|
# set up postinstall script
|
2016-11-03 20:57:56 +03:00
|
|
|
cat <<-EOF > $uboot_name/DEBIAN/postinst
|
2016-06-27 14:13:27 +03:00
|
|
|
#!/bin/bash
|
2016-10-06 18:37:20 +03:00
|
|
|
source /usr/lib/u-boot/platform_install.sh
|
2016-06-27 14:13:27 +03:00
|
|
|
[[ \$DEVICE == /dev/null ]] && exit 0
|
|
|
|
[[ -z \$DEVICE ]] && DEVICE="/dev/mmcblk0"
|
2016-10-23 01:05:54 +03:00
|
|
|
[[ \$(type -t setup_write_uboot_platform) == function ]] && setup_write_uboot_platform
|
2016-10-23 14:18:14 +03:00
|
|
|
echo "Updating u-boot on device \$DEVICE" >&2
|
2016-06-27 14:13:27 +03:00
|
|
|
write_uboot_platform \$DIR \$DEVICE
|
2016-10-30 19:10:05 +03:00
|
|
|
sync
|
2016-06-27 14:13:27 +03:00
|
|
|
exit 0
|
|
|
|
EOF
|
2016-11-03 20:57:56 +03:00
|
|
|
chmod 755 $uboot_name/DEBIAN/postinst
|
2016-05-03 22:38:14 +03:00
|
|
|
|
2016-10-22 18:34:18 +03:00
|
|
|
# declare -f on non-defined function does not do anything
|
2016-11-03 20:57:56 +03:00
|
|
|
cat <<-EOF > $uboot_name/usr/lib/u-boot/platform_install.sh
|
2016-10-06 18:37:20 +03:00
|
|
|
DIR=/usr/lib/$uboot_name
|
|
|
|
$(declare -f write_uboot_platform)
|
2016-10-22 18:34:18 +03:00
|
|
|
$(declare -f setup_write_uboot_platform)
|
2016-10-06 18:37:20 +03:00
|
|
|
EOF
|
|
|
|
|
2016-05-03 22:38:14 +03:00
|
|
|
# set up control file
|
2016-11-03 20:57:56 +03:00
|
|
|
cat <<-END > $uboot_name/DEBIAN/control
|
2016-05-03 22:38:14 +03:00
|
|
|
Package: linux-u-boot-${BOARD}-${BRANCH}
|
|
|
|
Version: $REVISION
|
|
|
|
Architecture: $ARCH
|
|
|
|
Maintainer: $MAINTAINER <$MAINTAINERMAIL>
|
|
|
|
Installed-Size: 1
|
|
|
|
Section: kernel
|
|
|
|
Priority: optional
|
2016-09-29 19:05:14 +03:00
|
|
|
Provides: armbian-u-boot
|
|
|
|
Replaces: armbian-u-boot
|
2016-10-05 19:33:12 +03:00
|
|
|
Conflicts: armbian-u-boot, u-boot-sunxi
|
2016-08-30 19:25:32 +03:00
|
|
|
Description: Uboot loader $version
|
2016-05-03 22:38:14 +03:00
|
|
|
END
|
|
|
|
|
2017-01-04 21:22:53 +03:00
|
|
|
# copy config file to the package
|
|
|
|
# useful for FEL boot with overlayfs_wrapper
|
|
|
|
[[ -f .config && -n $BOOTCONFIG ]] && cp .config $uboot_name/usr/lib/u-boot/$BOOTCONFIG
|
|
|
|
|
2016-11-03 20:57:56 +03:00
|
|
|
display_alert "Building deb" "${uboot_name}.deb" "info"
|
2016-09-01 13:10:31 +03:00
|
|
|
eval 'dpkg -b $uboot_name 2>&1' ${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/compilation.log'}
|
2016-03-14 21:54:03 +03:00
|
|
|
rm -rf $uboot_name
|
2014-10-24 18:56:18 +02:00
|
|
|
|
2016-12-09 14:03:39 +03:00
|
|
|
[[ ! -f ${uboot_name}.deb || $(stat -c '%s' "${uboot_name}.deb") -lt 5000 ]] && exit_with_error "Building u-boot package failed"
|
2015-12-09 09:54:58 +01:00
|
|
|
|
2016-11-03 20:57:56 +03:00
|
|
|
mv ${uboot_name}.deb $DEST/debs/
|
2014-10-07 20:49:46 +02:00
|
|
|
}
|
|
|
|
|
2016-06-15 19:44:14 +03:00
|
|
|
compile_kernel()
|
2016-06-15 17:11:01 +02:00
|
|
|
{
|
2016-12-08 18:44:41 +03:00
|
|
|
if [[ $CLEAN_LEVEL == *make* ]]; then
|
|
|
|
display_alert "Cleaning" "$LINUXSOURCEDIR" "info"
|
|
|
|
(cd $SOURCES/$LINUXSOURCEDIR; make ARCH=$ARCHITECTURE clean >/dev/null 2>&1)
|
|
|
|
fi
|
|
|
|
|
2016-11-03 20:57:56 +03:00
|
|
|
if [[ $USE_OVERLAYFS == yes ]]; then
|
|
|
|
local kerneldir=$(overlayfs_wrapper "wrap" "$SOURCES/$LINUXSOURCEDIR" "kernel_${LINUXFAMILY}_${BRANCH}")
|
|
|
|
else
|
|
|
|
local kerneldir="$SOURCES/$LINUXSOURCEDIR"
|
|
|
|
fi
|
2016-10-24 18:02:58 +03:00
|
|
|
cd "$kerneldir"
|
|
|
|
|
|
|
|
# this is a patch that Ubuntu Trusty compiler works
|
|
|
|
# TODO: Check if still required
|
|
|
|
if [[ $(patch --dry-run -t -p1 < $SRC/lib/patch/kernel/compiler.patch | grep Reversed) != "" ]]; then
|
|
|
|
display_alert "Patching kernel for compiler support"
|
|
|
|
[[ $FORCE_CHECKOUT == yes ]] && patch --batch --silent -t -p1 < $SRC/lib/patch/kernel/compiler.patch >> $DEST/debug/output.log 2>&1
|
2016-03-05 21:26:01 +03:00
|
|
|
fi
|
2016-03-17 20:16:26 +01:00
|
|
|
|
2017-05-02 12:50:35 +03:00
|
|
|
[[ $FORCE_CHECKOUT == yes ]] && advanced_patch "kernel" "$KERNELPATCHDIR" "$BOARD" "" "$BRANCH" "$LINUXFAMILY-$BRANCH"
|
2014-12-11 19:41:07 +01:00
|
|
|
|
2016-06-13 21:02:39 +02:00
|
|
|
# create patch for manual source changes in debug mode
|
2016-09-17 19:44:46 +02:00
|
|
|
[[ $CREATE_PATCHES == yes ]] && userpatch_create "kernel"
|
2016-07-26 15:53:10 +03:00
|
|
|
|
2016-10-24 18:02:58 +03:00
|
|
|
# read kernel version
|
|
|
|
local version=$(grab_version "$kerneldir")
|
|
|
|
|
2016-08-30 19:25:32 +03:00
|
|
|
display_alert "Compiling $BRANCH kernel" "$version" "info"
|
2016-12-20 00:17:11 +03:00
|
|
|
|
|
|
|
local toolchain=""
|
2017-04-29 13:32:09 +03:00
|
|
|
if [[ -n $KERNEL_USE_GCC ]]; then
|
|
|
|
toolchain=$(find_toolchain "$KERNEL_COMPILER" "$KERNEL_USE_GCC")
|
|
|
|
[[ -z $toolchain ]] && exit_with_error "Could not find required toolchain" "${KERNEL_COMPILER}gcc $KERNEL_USE_GCC"
|
2016-12-20 00:17:11 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
display_alert "Compiler version" "${KERNEL_COMPILER}gcc $(eval ${toolchain:+env PATH=$toolchain:$PATH} ${KERNEL_COMPILER}gcc -dumpversion)" "info"
|
2014-12-11 19:41:07 +01:00
|
|
|
|
2015-12-09 14:39:27 +01:00
|
|
|
# use proven config
|
2016-10-24 18:02:58 +03:00
|
|
|
if [[ $KERNEL_KEEP_CONFIG != yes || ! -f .config ]]; then
|
2016-04-20 15:38:09 +03:00
|
|
|
if [[ -f $SRC/userpatches/$LINUXCONFIG.config ]]; then
|
2015-12-27 17:02:03 +03:00
|
|
|
display_alert "Using kernel config provided by user" "userpatches/$LINUXCONFIG.config" "info"
|
2016-10-24 18:02:58 +03:00
|
|
|
cp $SRC/userpatches/$LINUXCONFIG.config .config
|
2015-12-27 17:02:03 +03:00
|
|
|
else
|
2016-04-25 19:00:37 +02:00
|
|
|
display_alert "Using kernel config file" "lib/config/kernel/$LINUXCONFIG.config" "info"
|
2016-10-24 18:02:58 +03:00
|
|
|
cp $SRC/lib/config/kernel/$LINUXCONFIG.config .config
|
2015-12-27 17:02:03 +03:00
|
|
|
fi
|
2015-12-09 14:39:27 +01:00
|
|
|
fi
|
2014-12-11 19:41:07 +01:00
|
|
|
|
2015-12-09 14:39:27 +01:00
|
|
|
# hack for deb builder. To pack what's missing in headers pack.
|
|
|
|
cp $SRC/lib/patch/misc/headers-debian-byteshift.patch /tmp
|
2014-12-17 20:10:02 +01:00
|
|
|
|
2016-04-19 13:04:53 +03:00
|
|
|
export LOCALVERSION="-$LINUXFAMILY"
|
2014-12-11 19:41:07 +01:00
|
|
|
|
2016-05-05 16:49:46 +03:00
|
|
|
sed -i 's/EXTRAVERSION = .*/EXTRAVERSION =/' Makefile
|
2016-05-04 20:52:34 +03:00
|
|
|
|
2016-04-20 15:38:09 +03:00
|
|
|
if [[ $KERNEL_CONFIGURE != yes ]]; then
|
|
|
|
if [[ $BRANCH == default ]]; then
|
2016-12-20 00:17:11 +03:00
|
|
|
make $CTHREADS ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" silentoldconfig
|
2015-12-09 14:39:27 +01:00
|
|
|
else
|
2016-12-20 00:17:11 +03:00
|
|
|
make $CTHREADS ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" olddefconfig
|
2015-12-09 14:39:27 +01:00
|
|
|
fi
|
2015-12-08 17:09:13 +03:00
|
|
|
else
|
2016-12-20 00:17:11 +03:00
|
|
|
make $CTHREADS ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" oldconfig
|
|
|
|
make $CTHREADS ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" menuconfig
|
2016-11-21 19:01:48 +03:00
|
|
|
# store kernel config in easily reachable place
|
2017-01-31 12:05:50 +03:00
|
|
|
cp .config $DEST/$LINUXCONFIG.config
|
2015-12-08 17:09:13 +03:00
|
|
|
fi
|
2014-12-11 19:41:07 +01:00
|
|
|
|
2016-12-20 00:17:11 +03:00
|
|
|
eval CCACHE_BASEDIR="$(pwd)" ${toolchain:+env PATH=$toolchain:$PATH} \
|
2016-07-27 20:38:29 +03:00
|
|
|
'make $CTHREADS ARCH=$ARCHITECTURE CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" $KERNEL_IMAGE_TYPE modules dtbs 2>&1' \
|
2016-03-05 21:26:01 +03:00
|
|
|
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/compilation.log'} \
|
2016-03-07 18:29:48 +01:00
|
|
|
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Compiling kernel..." $TTY_Y $TTY_X'} \
|
2016-03-05 21:26:01 +03:00
|
|
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
2014-12-11 19:41:07 +01:00
|
|
|
|
2016-04-24 17:51:19 +03:00
|
|
|
if [[ ${PIPESTATUS[0]} -ne 0 || ! -f arch/$ARCHITECTURE/boot/$KERNEL_IMAGE_TYPE ]]; then
|
2016-04-23 19:06:39 +03:00
|
|
|
exit_with_error "Kernel was not built" "@host"
|
2016-03-05 21:26:01 +03:00
|
|
|
fi
|
2014-11-17 16:20:02 +01:00
|
|
|
|
2016-05-24 18:12:48 +03:00
|
|
|
# different packaging for 4.3+
|
2016-03-05 21:26:01 +03:00
|
|
|
KERNEL_PACKING="deb-pkg"
|
2016-08-30 19:25:32 +03:00
|
|
|
IFS='.' read -a array <<< "$version"
|
2016-03-05 21:26:01 +03:00
|
|
|
if (( "${array[0]}" == "4" )) && (( "${array[1]}" >= "3" )); then
|
|
|
|
KERNEL_PACKING="bindeb-pkg"
|
|
|
|
fi
|
|
|
|
|
2016-04-08 00:38:59 +03:00
|
|
|
# produce deb packages: image, headers, firmware, dtb
|
2016-12-20 00:17:11 +03:00
|
|
|
eval CCACHE_BASEDIR="$(pwd)" ${toolchain:+env PATH=$toolchain:$PATH} \
|
2016-07-27 20:38:29 +03:00
|
|
|
'make -j1 $KERNEL_PACKING KDEB_PKGVERSION=$REVISION LOCALVERSION="-"$LINUXFAMILY \
|
|
|
|
KBUILD_DEBARCH=$ARCH ARCH=$ARCHITECTURE DEBFULLNAME="$MAINTAINER" DEBEMAIL="$MAINTAINERMAIL" CROSS_COMPILE="$CCACHE $KERNEL_COMPILER" 2>&1' \
|
2016-03-05 21:26:01 +03:00
|
|
|
${PROGRESS_LOG_TO_FILE:+' | tee -a $DEST/debug/compilation.log'} \
|
2016-03-07 18:29:48 +01:00
|
|
|
${OUTPUT_DIALOG:+' | dialog --backtitle "$backtitle" --progressbox "Creating kernel packages..." $TTY_Y $TTY_X'} \
|
2016-03-05 21:26:01 +03:00
|
|
|
${OUTPUT_VERYSILENT:+' >/dev/null 2>/dev/null'}
|
|
|
|
|
|
|
|
cd ..
|
|
|
|
mv *.deb $DEST/debs/ || exit_with_error "Failed moving kernel DEBs"
|
2014-10-07 20:49:46 +02:00
|
|
|
}
|
|
|
|
|
2016-10-24 18:02:58 +03:00
|
|
|
compile_sunxi_tools()
|
|
|
|
{
|
|
|
|
fetch_from_repo "https://github.com/linux-sunxi/sunxi-tools.git" "sunxi-tools" "branch:master"
|
|
|
|
# Compile and install only if git commit hash changed
|
|
|
|
cd $SOURCES/sunxi-tools
|
|
|
|
if [[ ! -f .commit_id || $(git rev-parse @ 2>/dev/null) != $(<.commit_id) ]]; then
|
|
|
|
display_alert "Compiling" "sunxi-tools" "info"
|
|
|
|
make -s clean >/dev/null
|
|
|
|
make -s tools >/dev/null
|
|
|
|
mkdir -p /usr/local/bin/
|
|
|
|
make install-tools >/dev/null 2>&1
|
|
|
|
git rev-parse @ 2>/dev/null > .commit_id
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-12-20 00:17:11 +03:00
|
|
|
# find_toolchain <compiler_prefix> <expression>
|
2016-04-20 15:38:09 +03:00
|
|
|
#
|
2016-12-20 00:17:11 +03:00
|
|
|
# returns path to toolchain that satisfies <expression>
|
2016-04-20 15:38:09 +03:00
|
|
|
#
|
|
|
|
find_toolchain()
|
|
|
|
{
|
2016-12-20 00:17:11 +03:00
|
|
|
local compiler=$1
|
2016-05-04 12:10:45 +03:00
|
|
|
local expression=$2
|
2016-04-20 15:38:09 +03:00
|
|
|
local dist=10
|
|
|
|
local toolchain=""
|
2016-05-01 17:49:29 +03:00
|
|
|
# extract target major.minor version from expression
|
|
|
|
local target_ver=$(grep -oE "[[:digit:]].[[:digit:]]" <<< "$expression")
|
2016-04-20 15:38:09 +03:00
|
|
|
for dir in $SRC/toolchains/*/; do
|
|
|
|
# check if is a toolchain for current $ARCH
|
2016-05-04 12:10:45 +03:00
|
|
|
[[ ! -f ${dir}bin/${compiler}gcc ]] && continue
|
2016-04-20 15:38:09 +03:00
|
|
|
# get toolchain major.minor version
|
2016-05-04 12:10:45 +03:00
|
|
|
local gcc_ver=$(${dir}bin/${compiler}gcc -dumpversion | grep -oE "^[[:digit:]].[[:digit:]]")
|
2016-04-20 15:38:09 +03:00
|
|
|
# check if toolchain version satisfies requirement
|
2016-12-20 00:17:11 +03:00
|
|
|
awk "BEGIN{exit ! ($gcc_ver $expression)}" >/dev/null || continue
|
2016-04-20 15:38:09 +03:00
|
|
|
# check if found version is the closest to target
|
|
|
|
local d=$(awk '{x = $1 - $2}{printf "%.1f\n", (x > 0) ? x : -x}' <<< "$target_ver $gcc_ver")
|
2016-12-20 00:17:11 +03:00
|
|
|
if awk "BEGIN{exit ! ($d < $dist)}" >/dev/null ; then
|
2016-04-20 15:38:09 +03:00
|
|
|
dist=$d
|
|
|
|
toolchain=${dir}bin
|
|
|
|
fi
|
|
|
|
done
|
2016-12-20 00:17:11 +03:00
|
|
|
echo "$toolchain"
|
2016-04-20 15:38:09 +03:00
|
|
|
}
|
|
|
|
|
2017-01-31 19:21:09 +03:00
|
|
|
# advanced_patch <dest> <family> <board> <target> <branch> <description>
|
2016-04-18 18:21:43 +03:00
|
|
|
#
|
|
|
|
# parameters:
|
|
|
|
# <dest>: u-boot, kernel
|
|
|
|
# <family>: u-boot: u-boot, u-boot-neo; kernel: sun4i-default, sunxi-next, ...
|
2016-12-09 13:37:20 +03:00
|
|
|
# <board>: cubieboard, cubieboard2, cubietruck, ...
|
|
|
|
# <target>: optional subdirectory
|
2016-04-18 18:21:43 +03:00
|
|
|
# <description>: additional description text
|
|
|
|
#
|
|
|
|
# priority:
|
2016-12-09 13:37:20 +03:00
|
|
|
# $SRC/userpatches/<dest>/<family>/target_<target>
|
|
|
|
# $SRC/userpatches/<dest>/<family>/board_<board>
|
2017-01-31 19:21:09 +03:00
|
|
|
# $SRC/userpatches/<dest>/<family>/branch_<branch>
|
2016-04-18 18:21:43 +03:00
|
|
|
# $SRC/userpatches/<dest>/<family>
|
2016-12-09 13:37:20 +03:00
|
|
|
# $SRC/lib/patch/<dest>/<family>/target_<target>
|
|
|
|
# $SRC/lib/patch/<dest>/<family>/board_<board>
|
2017-01-31 19:21:09 +03:00
|
|
|
# $SRC/lib/patch/<dest>/<family>/branch_<branch>
|
2016-04-18 18:21:43 +03:00
|
|
|
# $SRC/lib/patch/<dest>/<family>
|
|
|
|
#
|
2016-09-29 19:42:17 +03:00
|
|
|
advanced_patch()
|
|
|
|
{
|
2016-04-18 18:21:43 +03:00
|
|
|
local dest=$1
|
|
|
|
local family=$2
|
2016-12-09 13:37:20 +03:00
|
|
|
local board=$3
|
|
|
|
local target=$4
|
2017-01-31 19:21:09 +03:00
|
|
|
local branch=$5
|
|
|
|
local description=$6
|
2016-04-18 18:21:43 +03:00
|
|
|
|
|
|
|
display_alert "Started patching process for" "$dest $description" "info"
|
|
|
|
display_alert "Looking for user patches in" "userpatches/$dest/$family" "info"
|
|
|
|
|
|
|
|
local names=()
|
2016-12-09 13:37:20 +03:00
|
|
|
local dirs=(
|
|
|
|
"$SRC/userpatches/$dest/$family/target_${target}:[\e[33mu\e[0m][\e[34mt\e[0m]"
|
|
|
|
"$SRC/userpatches/$dest/$family/board_${board}:[\e[33mu\e[0m][\e[35mb\e[0m]"
|
2017-01-31 19:21:09 +03:00
|
|
|
"$SRC/userpatches/$dest/$family/branch_${branch}:[\e[33mu\e[0m][\e[33mb\e[0m]"
|
2016-12-09 13:37:20 +03:00
|
|
|
"$SRC/userpatches/$dest/$family:[\e[33mu\e[0m][\e[32mc\e[0m]"
|
|
|
|
"$SRC/lib/patch/$dest/$family/target_${target}:[\e[32ml\e[0m][\e[34mt\e[0m]"
|
|
|
|
"$SRC/lib/patch/$dest/$family/board_${board}:[\e[32ml\e[0m][\e[35mb\e[0m]"
|
2017-01-31 19:21:09 +03:00
|
|
|
"$SRC/lib/patch/$dest/$family/branch_${branch}:[\e[32ml\e[0m][\e[33mb\e[0m]"
|
2016-12-09 13:37:20 +03:00
|
|
|
"$SRC/lib/patch/$dest/$family:[\e[32ml\e[0m][\e[32mc\e[0m]"
|
|
|
|
)
|
2016-04-18 18:21:43 +03:00
|
|
|
|
|
|
|
# required for "for" command
|
|
|
|
shopt -s nullglob dotglob
|
|
|
|
# get patch file names
|
|
|
|
for dir in "${dirs[@]}"; do
|
2016-12-09 13:37:20 +03:00
|
|
|
for patch in ${dir%%:*}/*.patch; do
|
2016-04-18 18:21:43 +03:00
|
|
|
names+=($(basename $patch))
|
|
|
|
done
|
|
|
|
done
|
|
|
|
# remove duplicates
|
|
|
|
local names_s=($(echo "${names[@]}" | tr ' ' '\n' | LC_ALL=C sort -u | tr '\n' ' '))
|
|
|
|
# apply patches
|
|
|
|
for name in "${names_s[@]}"; do
|
|
|
|
for dir in "${dirs[@]}"; do
|
2016-12-09 13:37:20 +03:00
|
|
|
if [[ -f ${dir%%:*}/$name ]]; then
|
|
|
|
if [[ -s ${dir%%:*}/$name ]]; then
|
|
|
|
process_patch_file "${dir%%:*}/$name" "${dir##*:}"
|
2016-04-18 18:21:43 +03:00
|
|
|
else
|
2016-12-09 13:37:20 +03:00
|
|
|
display_alert "... ${dir##*:} $name" "skipped"
|
2016-04-18 18:21:43 +03:00
|
|
|
fi
|
|
|
|
break # next name
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# process_patch_file <file> <description>
|
|
|
|
#
|
|
|
|
# parameters:
|
|
|
|
# <file>: path to patch file
|
2016-12-09 13:37:20 +03:00
|
|
|
# <status>: additional status text
|
2016-04-18 18:21:43 +03:00
|
|
|
#
|
2016-09-29 19:42:17 +03:00
|
|
|
process_patch_file()
|
|
|
|
{
|
2016-04-18 18:21:43 +03:00
|
|
|
local patch=$1
|
2016-12-09 13:37:20 +03:00
|
|
|
local status=$2
|
2016-04-18 18:21:43 +03:00
|
|
|
|
|
|
|
# detect and remove files which patch will create
|
2016-11-11 14:27:08 +03:00
|
|
|
lsdiff -s --strip=1 $patch | grep '^+' | awk '{print $2}' | xargs -I % sh -c 'rm -f %'
|
2016-04-18 18:21:43 +03:00
|
|
|
|
2016-09-03 16:42:03 +03:00
|
|
|
echo "Processing file $patch" >> $DEST/debug/patching.log
|
2016-06-27 14:13:27 +03:00
|
|
|
patch --batch --silent -p1 -N < $patch >> $DEST/debug/patching.log 2>&1
|
2016-04-18 18:21:43 +03:00
|
|
|
|
2016-04-29 12:54:41 +03:00
|
|
|
if [[ $? -ne 0 ]]; then
|
2016-12-09 13:37:20 +03:00
|
|
|
display_alert "... $status $(basename $patch)" "failed" "wrn"
|
2016-06-14 16:14:40 +03:00
|
|
|
[[ $EXIT_PATCHING_ERROR == yes ]] && exit_with_error "Aborting due to" "EXIT_PATCHING_ERROR"
|
2016-04-18 18:21:43 +03:00
|
|
|
else
|
2016-12-09 13:37:20 +03:00
|
|
|
display_alert "... $status $(basename $patch)" "succeeded" "info"
|
2016-04-18 18:21:43 +03:00
|
|
|
fi
|
2016-12-09 20:18:16 +03:00
|
|
|
echo >> $DEST/debug/patching.log
|
2016-04-18 18:21:43 +03:00
|
|
|
}
|
2014-10-07 20:49:46 +02:00
|
|
|
|
2016-06-15 19:44:14 +03:00
|
|
|
install_external_applications()
|
2016-04-08 16:36:56 +03:00
|
|
|
{
|
2014-10-08 09:53:25 +02:00
|
|
|
#--------------------------------------------------------------------------------------------------------------------------------
|
2015-12-02 20:33:32 +01:00
|
|
|
# Install external applications example
|
2014-10-08 09:53:25 +02:00
|
|
|
#--------------------------------------------------------------------------------------------------------------------------------
|
2016-08-30 19:25:32 +03:00
|
|
|
display_alert "Installing extra applications and drivers" "" "info"
|
|
|
|
|
|
|
|
for plugin in $SRC/lib/extras/*.sh; do
|
|
|
|
source $plugin
|
|
|
|
done
|
2014-10-07 20:49:46 +02:00
|
|
|
}
|
|
|
|
|
2015-12-25 20:04:33 +03:00
|
|
|
# write_uboot <loopdev>
|
|
|
|
#
|
|
|
|
# writes u-boot to loop device
|
|
|
|
# Parameters:
|
|
|
|
# loopdev: loop device with mounted rootfs image
|
|
|
|
write_uboot()
|
|
|
|
{
|
2016-05-03 22:38:14 +03:00
|
|
|
local loop=$1
|
2016-09-17 18:40:04 +02:00
|
|
|
display_alert "Writing U-boot bootloader" "$loop" "info"
|
2016-08-09 18:26:22 +03:00
|
|
|
mkdir -p /tmp/u-boot/
|
|
|
|
dpkg -x ${DEST}/debs/${CHOSEN_UBOOT}_${REVISION}_${ARCH}.deb /tmp/u-boot/
|
2016-08-10 07:22:40 +02:00
|
|
|
write_uboot_platform "/tmp/u-boot/usr/lib/${CHOSEN_UBOOT}_${REVISION}_${ARCH}" "$loop"
|
2016-09-17 18:40:04 +02:00
|
|
|
[[ $? -ne 0 ]] && exit_with_error "U-boot bootloader failed to install" "@host"
|
2016-08-09 18:26:22 +03:00
|
|
|
rm -r /tmp/u-boot/
|
2015-12-25 20:04:33 +03:00
|
|
|
sync
|
|
|
|
}
|
2016-03-19 17:26:15 +03:00
|
|
|
|
|
|
|
customize_image()
|
|
|
|
{
|
2016-06-18 12:51:57 +03:00
|
|
|
# for users that need to prepare files at host
|
|
|
|
[[ -f $SRC/userpatches/customize-image-host.sh ]] && source $SRC/userpatches/customize-image-host.sh
|
2016-11-26 17:06:58 +03:00
|
|
|
cp $SRC/userpatches/customize-image.sh $CACHEDIR/$SDCARD/tmp/customize-image.sh
|
|
|
|
chmod +x $CACHEDIR/$SDCARD/tmp/customize-image.sh
|
|
|
|
mkdir -p $CACHEDIR/$SDCARD/tmp/overlay
|
2016-07-29 12:15:43 +03:00
|
|
|
if [[ $(lsb_release -sc) == xenial ]]; then
|
|
|
|
# util-linux >= 2.27 required
|
2016-11-26 17:06:58 +03:00
|
|
|
mount -o bind,ro $SRC/userpatches/overlay $CACHEDIR/$SDCARD/tmp/overlay
|
2016-07-29 12:15:43 +03:00
|
|
|
else
|
2016-11-26 17:06:58 +03:00
|
|
|
mount -o bind $SRC/userpatches/overlay $CACHEDIR/$SDCARD/tmp/overlay
|
2016-07-29 12:15:43 +03:00
|
|
|
fi
|
2016-03-19 17:26:15 +03:00
|
|
|
display_alert "Calling image customization script" "customize-image.sh" "info"
|
2017-02-01 12:37:44 +03:00
|
|
|
chroot $CACHEDIR/$SDCARD /bin/bash -c "/tmp/customize-image.sh $RELEASE $LINUXFAMILY $BOARD $BUILD_DESKTOP"
|
2016-11-26 17:06:58 +03:00
|
|
|
umount $CACHEDIR/$SDCARD/tmp/overlay
|
|
|
|
mountpoint -q $CACHEDIR/$SDCARD/tmp/overlay || rm -r $CACHEDIR/$SDCARD/tmp/overlay
|
2016-03-19 17:26:15 +03:00
|
|
|
}
|
2016-06-13 21:02:39 +02:00
|
|
|
|
|
|
|
userpatch_create()
|
|
|
|
{
|
2016-07-26 15:53:10 +03:00
|
|
|
# create commit to start from clean source
|
|
|
|
git add .
|
|
|
|
git -c user.name='Armbian User' -c user.email='user@example.org' commit -q -m "Cleaning working copy"
|
|
|
|
|
2017-05-04 10:55:37 +03:00
|
|
|
local patch="$SRC/userpatches/CREATE_PATCHES/$1-$LINUXFAMILY-$BRANCH.patch"
|
2016-07-26 15:53:10 +03:00
|
|
|
|
|
|
|
# apply previous user debug mode created patches
|
2016-10-24 18:02:58 +03:00
|
|
|
[[ -f $patch ]] && display_alert "Applying existing $1 patch" "$patch" "wrn" && patch --batch --silent -p1 -N < $patch
|
2016-07-26 15:53:10 +03:00
|
|
|
|
|
|
|
# prompt to alter source
|
|
|
|
display_alert "Make your changes in this directory:" "$(pwd)" "wrn"
|
|
|
|
display_alert "Press <Enter> after you are done" "waiting" "wrn"
|
2016-12-19 22:04:58 +03:00
|
|
|
read </dev/tty
|
2016-07-26 15:53:10 +03:00
|
|
|
tput cuu1
|
|
|
|
git add .
|
|
|
|
# create patch out of changes
|
|
|
|
if ! git diff-index --quiet --cached HEAD; then
|
|
|
|
git diff --staged > $patch
|
|
|
|
display_alert "You will find your patch here:" "$patch" "info"
|
|
|
|
else
|
|
|
|
display_alert "No changes found, skipping patch creation" "" "wrn"
|
2016-06-13 21:02:39 +02:00
|
|
|
fi
|
2016-07-26 15:53:10 +03:00
|
|
|
git reset --soft HEAD~
|
2016-10-24 18:02:58 +03:00
|
|
|
for i in {3..1..1}; do echo -n "$i." && sleep 1; done
|
|
|
|
}
|
|
|
|
|
2016-10-31 20:05:24 +03:00
|
|
|
# overlayfs_wrapper <operation> <workdir> <description>
|
2016-10-24 18:02:58 +03:00
|
|
|
#
|
|
|
|
# <operation>: wrap|cleanup
|
|
|
|
# <workdir>: path to source directory
|
2016-10-31 20:05:24 +03:00
|
|
|
# <description>: suffix for merged directory to help locating it in /tmp
|
2016-10-24 18:02:58 +03:00
|
|
|
# return value: new directory
|
|
|
|
#
|
|
|
|
# Assumptions/notes:
|
|
|
|
# - Ubuntu Xenial host
|
|
|
|
# - /tmp is mounted as tmpfs
|
|
|
|
# - there is enough space on /tmp
|
|
|
|
# - UB if running multiple compilation tasks in parallel
|
|
|
|
# - should not be used with CREATE_PATCHES=yes
|
|
|
|
#
|
|
|
|
overlayfs_wrapper()
|
|
|
|
{
|
|
|
|
local operation="$1"
|
|
|
|
if [[ $operation == wrap ]]; then
|
|
|
|
local srcdir="$2"
|
2016-10-31 20:05:24 +03:00
|
|
|
local description="$3"
|
2016-11-18 16:35:46 +03:00
|
|
|
mkdir -p /tmp/overlay_components/ /tmp/armbian_build/
|
2016-11-07 18:10:15 +03:00
|
|
|
local tempdir=$(mktemp -d --tmpdir="/tmp/overlay_components/")
|
|
|
|
local workdir=$(mktemp -d --tmpdir="/tmp/overlay_components/")
|
2016-11-18 16:35:46 +03:00
|
|
|
local mergeddir=$(mktemp -d --suffix="_$description" --tmpdir="/tmp/armbian_build/")
|
2016-10-24 18:02:58 +03:00
|
|
|
mount -t overlay overlay -o lowerdir="$srcdir",upperdir="$tempdir",workdir="$workdir" "$mergeddir"
|
2016-10-25 23:12:08 +03:00
|
|
|
# this is executed in a subshell, so use temp files to pass extra data outside
|
|
|
|
echo "$tempdir" >> /tmp/.overlayfs_wrapper_cleanup
|
|
|
|
echo "$mergeddir" >> /tmp/.overlayfs_wrapper_umount
|
2016-11-10 19:58:07 +03:00
|
|
|
echo "$mergeddir" >> /tmp/.overlayfs_wrapper_cleanup
|
2016-10-24 18:02:58 +03:00
|
|
|
echo "$mergeddir"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
if [[ $operation == cleanup ]]; then
|
2016-10-26 16:48:27 +03:00
|
|
|
if [[ -f /tmp/.overlayfs_wrapper_umount ]]; then
|
|
|
|
for dir in $(</tmp/.overlayfs_wrapper_umount); do
|
2016-11-10 19:58:07 +03:00
|
|
|
[[ $dir == /tmp/* ]] && umount -l "$dir" > /dev/null 2>&1
|
2016-10-26 16:48:27 +03:00
|
|
|
done
|
|
|
|
fi
|
|
|
|
if [[ -f /tmp/.overlayfs_wrapper_cleanup ]]; then
|
|
|
|
for dir in $(</tmp/.overlayfs_wrapper_cleanup); do
|
|
|
|
[[ $dir == /tmp/* ]] && rm -rf "$dir"
|
|
|
|
done
|
|
|
|
fi
|
2016-10-25 23:12:08 +03:00
|
|
|
rm -f /tmp/.overlayfs_wrapper_umount /tmp/.overlayfs_wrapper_cleanup
|
2016-10-24 18:02:58 +03:00
|
|
|
fi
|
2016-07-26 15:53:10 +03:00
|
|
|
}
|