build/lib/fel-load.sh

104 lines
3.6 KiB
Bash
Raw Permalink Normal View History

#!/bin/bash
#
2016-03-03 17:06:01 +03: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 the Armbian build script
# https://github.com/armbian/build/
2016-03-03 17:06:01 +03:00
2016-03-04 21:11:58 +03:00
# FEL_ROOTFS should be set to path to debootstrapped root filesystem
# unless you want to kill your /etc/fstab and share your rootfs on NFS
# without any access control
2016-03-03 17:06:01 +03:00
fel_prepare_host()
{
2020-04-16 18:26:45 +02:00
# Start rpcbind for NFS if inside docker container
[ "$(systemd-detect-virt)" == 'docker' ] && service rpcbind start
2020-04-16 18:26:45 +02:00
2016-03-04 12:29:21 +03:00
# remove and re-add NFS share
rm -f /etc/exports.d/armbian.exports
mkdir -p /etc/exports.d
echo "$FEL_ROOTFS *(rw,async,no_subtree_check,no_root_squash,fsid=root)" > /etc/exports.d/armbian.exports
2020-04-16 18:26:45 +02:00
# Start NFS server if inside docker container
[ "$(systemd-detect-virt)" == 'docker' ] && service nfs-kernel-server start
2016-03-04 12:29:21 +03:00
exportfs -ra
2016-03-03 17:06:01 +03:00
}
2016-03-04 12:29:21 +03:00
fel_prepare_target()
2016-03-03 17:06:01 +03:00
{
if [[ -f $USERPATCHES_PATH/fel-boot.cmd ]]; then
display_alert "Using custom boot script" "userpatches/fel-boot.cmd" "info"
cp "$USERPATCHES_PATH"/fel-boot.cmd "${FEL_ROOTFS}"/boot/boot.cmd
else
cp "${SRC}"/config/templates/fel-boot.cmd.template "${FEL_ROOTFS}"/boot/boot.cmd
fi
2016-03-03 17:06:01 +03:00
if [[ -z $FEL_LOCAL_IP ]]; then
FEL_LOCAL_IP=$(ifconfig "${FEL_NET_IFNAME}" | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
2016-03-03 17:06:01 +03:00
fi
sed -i "s#BRANCH#$BRANCH#" "${FEL_ROOTFS}"/boot/boot.cmd
sed -i "s#FEL_LOCAL_IP#$FEL_LOCAL_IP#" "${FEL_ROOTFS}"/boot/boot.cmd
sed -i "s#FEL_ROOTFS#$FEL_ROOTFS#" "${FEL_ROOTFS}"/boot/boot.cmd
mkimage -C none -A arm -T script -d "${FEL_ROOTFS}"/boot/boot.cmd "${FEL_ROOTFS}"/boot/boot.scr > /dev/null
2016-03-03 17:06:01 +03:00
2016-03-04 12:29:21 +03:00
# kill /etc/fstab on target
echo > "${FEL_ROOTFS}"/etc/fstab
echo "/dev/nfs / nfs defaults 0 0" >> "${FEL_ROOTFS}"/etc/fstab
echo "tmpfs /tmp tmpfs defaults,nosuid 0 0" >> "${FEL_ROOTFS}"/etc/fstab
}
2016-03-11 21:20:57 +03:00
fel_load()
{
# update each time in case boot/script.bin link was changed in multi-board images
local dtb_file
if [[ -n $FEL_DTB_FILE ]]; then
dtb_file=$FEL_DTB_FILE
else
2016-03-03 19:27:33 +03:00
if [[ $BRANCH == default ]]; then
2016-03-04 13:30:15 +03:00
# script.bin is either regular file or absolute symlink
if [[ -L $FEL_ROOTFS/boot/script.bin ]]; then
dtb_file=boot/bin/$(basename "$(readlink "${FEL_ROOTFS}"/boot/script.bin)")
2016-03-04 13:30:15 +03:00
else
dtb_file=boot/script.bin
2016-03-04 13:30:15 +03:00
fi
2016-03-03 19:27:33 +03:00
else
dtb_file=boot/dtb/$(grep CONFIG_DEFAULT_DEVICE_TREE "${FEL_ROOTFS}/usr/lib/u-boot/${BOOTCONFIG}" | cut -d '"' -f2).dtb
2016-03-03 19:27:33 +03:00
fi
2016-03-03 17:06:01 +03:00
fi
2016-03-16 19:53:45 +03:00
[[ $(type -t fel_pre_load) == function ]] && fel_pre_load
2016-03-04 12:29:21 +03:00
2016-03-03 17:06:01 +03:00
display_alert "Loading files via" "FEL USB" "info"
sunxi-fel "${FEL_EXTRA_ARGS}" -p uboot "${FEL_ROOTFS}/usr/lib/${CHOSEN_UBOOT}_${REVISION}_armhf/u-boot-sunxi-with-spl.bin" \
write 0x42000000 "${FEL_ROOTFS}"/boot/zImage \
write 0x43000000 "${FEL_ROOTFS}/${dtb_file}" \
write 0x43300000 "${FEL_ROOTFS}"/boot/uInitrd \
write 0x43100000 "${FEL_ROOTFS}"/boot/boot.scr
2016-03-03 17:06:01 +03:00
}
if [[ -f $USERPATCHES_PATH/fel-hooks.sh ]]; then
2016-03-16 19:53:45 +03:00
display_alert "Using additional FEL hooks in" "userpatches/fel-hooks.sh" "info"
# shellcheck source=/dev/null
source "$USERPATCHES_PATH"/fel-hooks.sh
2016-03-16 19:53:45 +03:00
fi
2016-03-04 12:29:21 +03:00
# basic sanity check
if [[ -n $FEL_ROOTFS ]]; then
fel_prepare_host
fel_prepare_target
2016-03-16 19:53:45 +03:00
[[ $(type -t fel_post_prepare) == function ]] && fel_post_prepare
2016-03-04 12:29:21 +03:00
RES=b
while [[ $RES != q ]]; do
2016-03-06 17:02:32 +03:00
if [[ $FEL_AUTO != yes ]]; then
display_alert "Connect device in FEL mode and press" "<Enter>" "info"
read -r
2016-03-06 17:02:32 +03:00
fi
2016-03-04 12:29:21 +03:00
fel_load
display_alert "Press any key to boot again, <q> to finish" "FEL" "info"
read -r -n 1 RES
2016-03-06 13:01:05 +03:00
echo
2016-03-04 12:29:21 +03:00
done
service nfs-kernel-server restart
fi