2019-06-04 11:04:54 +02:00
|
|
|
#!/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.
|
2017-08-01 12:51:10 +03:00
|
|
|
|
|
|
|
# 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
|
2020-06-18 16:06:21 +02:00
|
|
|
[ "$(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
|
2020-06-18 16:06:21 +02:00
|
|
|
[ "$(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
|
|
|
{
|
2019-07-10 04:50:50 +02:00
|
|
|
if [[ -f $USERPATCHES_PATH/fel-boot.cmd ]]; then
|
2016-03-07 19:34:56 +03:00
|
|
|
display_alert "Using custom boot script" "userpatches/fel-boot.cmd" "info"
|
2019-07-10 04:50:50 +02:00
|
|
|
cp "$USERPATCHES_PATH"/fel-boot.cmd "${FEL_ROOTFS}"/boot/boot.cmd
|
2016-03-07 19:34:56 +03:00
|
|
|
else
|
2019-06-04 11:04:54 +02:00
|
|
|
cp "${SRC}"/config/templates/fel-boot.cmd.template "${FEL_ROOTFS}"/boot/boot.cmd
|
2016-03-07 19:34:56 +03:00
|
|
|
fi
|
2016-03-03 17:06:01 +03:00
|
|
|
if [[ -z $FEL_LOCAL_IP ]]; then
|
2019-06-04 11:04:54 +02:00
|
|
|
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
|
2019-06-04 11:04:54 +02:00
|
|
|
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
|
2019-06-04 11:04:54 +02:00
|
|
|
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-14 18:29:47 +03:00
|
|
|
}
|
2016-03-11 21:20:57 +03:00
|
|
|
|
2016-03-14 18:29:47 +03:00
|
|
|
fel_load()
|
|
|
|
{
|
|
|
|
# update each time in case boot/script.bin link was changed in multi-board images
|
2019-06-04 11:04:54 +02:00
|
|
|
local dtb_file
|
2016-03-14 21:54:03 +03:00
|
|
|
if [[ -n $FEL_DTB_FILE ]]; then
|
2019-06-04 11:04:54 +02:00
|
|
|
dtb_file=$FEL_DTB_FILE
|
2016-03-14 21:54:03 +03:00
|
|
|
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
|
2019-06-04 11:04:54 +02:00
|
|
|
dtb_file=boot/bin/$(basename "$(readlink "${FEL_ROOTFS}"/boot/script.bin)")
|
2016-03-04 13:30:15 +03:00
|
|
|
else
|
2019-06-04 11:04:54 +02:00
|
|
|
dtb_file=boot/script.bin
|
2016-03-04 13:30:15 +03:00
|
|
|
fi
|
2016-03-03 19:27:33 +03:00
|
|
|
else
|
2019-06-04 11:04:54 +02:00
|
|
|
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"
|
2020-06-18 16:06:21 +02:00
|
|
|
sunxi-fel "${FEL_EXTRA_ARGS}" -p uboot "${FEL_ROOTFS}/usr/lib/${CHOSEN_UBOOT}_${REVISION}_armhf/u-boot-sunxi-with-spl.bin" \
|
2019-06-04 11:04:54 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2019-07-10 04:50:50 +02: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"
|
2019-06-04 11:04:54 +02:00
|
|
|
# shellcheck source=/dev/null
|
2019-07-10 04:50:50 +02:00
|
|
|
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
|
2016-03-17 20:16:26 +01:00
|
|
|
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"
|
2019-06-04 11:04:54 +02:00
|
|
|
read -r
|
2016-03-06 17:02:32 +03:00
|
|
|
fi
|
2016-03-04 12:29:21 +03:00
|
|
|
fel_load
|
2016-03-17 20:16:26 +01:00
|
|
|
display_alert "Press any key to boot again, <q> to finish" "FEL" "info"
|
2019-06-04 11:04:54 +02:00
|
|
|
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
|