arm-sdk/lib/helpers

153 lines
3.6 KiB
Bash

#!/usr/bin/env zsh
# Copyright (c) 2016-2021 Ivan J. <parazyd@dyne.org>
# This file is part of arm-sdk
#
# This source code is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this source code. If not, see <http://www.gnu.org/licenses/>.
## helper functions for arm-sdk
get-kernel-sources() {
fn get-kernel-sources
req=(R device_name gitkernel gitbranch)
ckreq || return 1
notice "grabbing kernel sources"
if [[ $gitkernel = mainline ]]; then
clone-git "$linuxmainline" "$R/tmp/kernels/$device_name/${device_name}-linux"
else
clone-git "$gitkernel" "$R/tmp/kernels/$device_name/${device_name}-linux" "$gitbranch"
fi
}
get-kernel-firmware() {
fn get-kernel-firmware
req=(linuxfirmware R)
ckreq || return 1
notice "grabbing latest linux-firmware"
clone-git "$linuxfirmware" "$R/tmp/linux-firmware"
}
install-kernel-mods() {
fn install-kernel-mods
req=(MAKEOPTS PATH compiler strapdir)
ckreq || return 1
# We need this function to avoid sudo -E calls, which are
# forbidden by jenkins.
cat <<EOF > install_mods
#!/bin/sh
export PATH="${PATH}"
make \
${MAKEOPTS} \
ARCH="${1}" \
CROSS_COMPILE=${compiler} \
INSTALL_MOD_PATH=${strapdir} \
modules_install || exit 1
EOF
chmod +x install_mods || zerr
sudo ./install_mods || zerr
}
clone-git() {
fn clone-git "$@"
req=(giturl clonepath)
local giturl="$1"
local clonepath="$2"
local gitbr="$3"
ckreq || return 1
notice "grabbing $(basename $clonepath)"
if [[ -d $clonepath ]]; then
pushd $clonepath
git pull
popd
else
[[ -n $gitbr ]] && gitbr="$gitbr" || gitbr="master"
git clone --depth 1 -b "$gitbr" "$giturl" "$clonepath"
fi
}
copy-kernel-config() {
fn copy-kernel-config
req=(device_name)
ckreq || return 1
notice "copying available kernel config"
cp -f $R/boards/kernel-configs/${device_name}.config \
$R/tmp/kernels/$device_name/${device_name}-linux/.config
}
vars+=(skip_arm_generic_root skip_arm_device_root)
copy-root-overlay() {
fn copy-root-overlay
req=(strapdir device_name R)
ckreq || return 1
if [ -z "$skip_arm_generic_root" ]; then
if [ -d "$R/extra/generic-root" ]; then
notice "copying generic-root"
sudo cp -rfv "$R/extra/generic-root"/* "$strapdir"
fi
fi
if [ -z "$skip_arm_device_root" ]; then
if [ -d "$R/extra/$device_name" ]; then
notice "copyring ${device_name}-root"
sudo cp -rfv "$R/extra/$device_name"/* "$strapdir"
fi
fi
sudo sed -e "s/{{{BOOTFS}}}/$bootfs/" -i "$strapdir/etc/fstab"
return 0
}
postbuild-clean() {
fn postbuild-clean
req=(strapdir release)
ckreq || return 1
case "$release" in
jessie)
cat <<EOF | sudo tee ${strapdir}/postbuild >/dev/null
#!/bin/sh
# jessie-backports e2fsprogs because 4.x kernels
apt-get update
apt-get --yes --force-yes -t jessie-backports install e2fsprogs
EOF
chroot-script -d postbuild || zerr
;;
esac
cat <<EOF | sudo tee ${strapdir}/postbuild >/dev/null
#!/bin/sh
apt-get update
apt-get --yes --force-yes upgrade
apt-get --yes --force-yes autoremove
apt-get clean
EOF
chroot-script -d postbuild || zerr
[[ -n "$BLEND" ]] || sudo rm -f \
"$strapdir/$armel_qemu_bin" \
"$strapdir/$armhf_qemu_bin" \
"$strapdir/$arm64_qemu_bin"
return 0
}