Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
orangepi-xunlong
GitHub Repository: orangepi-xunlong/orangepi-build
Path: blob/next/scripts/fel-load.sh
13066 views
1
#!/bin/bash
2
#
3
# Copyright (c) 2015 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
# FEL_ROOTFS should be set to path to debootstrapped root filesystem
10
# unless you want to kill your /etc/fstab and share your rootfs on NFS
11
# without any access control
12
13
fel_prepare_host()
14
{
15
# Start rpcbind for NFS if inside docker container
16
[ "$(systemd-detect-virt)" == 'docker' ] && service rpcbind start
17
18
# remove and re-add NFS share
19
rm -f /etc/exports.d/orangepi.exports
20
mkdir -p /etc/exports.d
21
echo "$FEL_ROOTFS *(rw,async,no_subtree_check,no_root_squash,fsid=root)" > /etc/exports.d/orangepi.exports
22
# Start NFS server if inside docker container
23
[ "$(systemd-detect-virt)" == 'docker' ] && service nfs-kernel-server start
24
exportfs -ra
25
}
26
27
fel_prepare_target()
28
{
29
if [[ -f $USERPATCHES_PATH/fel-boot.cmd ]]; then
30
display_alert "Using custom boot script" "userpatches/fel-boot.cmd" "info"
31
cp "$USERPATCHES_PATH"/fel-boot.cmd "${FEL_ROOTFS}"/boot/boot.cmd
32
else
33
cp "${EXTER}"/config/templates/fel-boot.cmd.template "${FEL_ROOTFS}"/boot/boot.cmd
34
fi
35
if [[ -z $FEL_LOCAL_IP ]]; then
36
FEL_LOCAL_IP=$(ifconfig "${NET_IFNAME}" | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
37
fi
38
sed -i "s#BRANCH#$BRANCH#" "${FEL_ROOTFS}"/boot/boot.cmd
39
sed -i "s#FEL_LOCAL_IP#$FEL_LOCAL_IP#" "${FEL_ROOTFS}"/boot/boot.cmd
40
sed -i "s#FEL_ROOTFS#$FEL_ROOTFS#" "${FEL_ROOTFS}"/boot/boot.cmd
41
mkimage -C none -A arm -T script -d "${FEL_ROOTFS}"/boot/boot.cmd "${FEL_ROOTFS}"/boot/boot.scr > /dev/null
42
43
# kill /etc/fstab on target
44
echo > "${FEL_ROOTFS}"/etc/fstab
45
echo "/dev/nfs / nfs defaults 0 0" >> "${FEL_ROOTFS}"/etc/fstab
46
echo "tmpfs /tmp tmpfs defaults,nosuid 0 0" >> "${FEL_ROOTFS}"/etc/fstab
47
}
48
49
fel_load()
50
{
51
# update each time in case boot/script.bin link was changed in multi-board images
52
local dtb_file
53
if [[ -n $FEL_DTB_FILE ]]; then
54
dtb_file=$FEL_DTB_FILE
55
else
56
if [[ $BRANCH == legacy ]]; then
57
# script.bin is either regular file or absolute symlink
58
if [[ -L $FEL_ROOTFS/boot/script.bin ]]; then
59
dtb_file=boot/bin/$(basename "$(readlink "${FEL_ROOTFS}"/boot/script.bin)")
60
else
61
dtb_file=boot/script.bin
62
fi
63
else
64
dtb_file=boot/dtb/$(grep CONFIG_DEFAULT_DEVICE_TREE "${FEL_ROOTFS}/usr/lib/u-boot/${BOOTCONFIG}" | cut -d '"' -f2).dtb
65
fi
66
fi
67
[[ $(type -t fel_pre_load) == function ]] && fel_pre_load
68
69
display_alert "Loading files via" "FEL USB" "info"
70
sunxi-fel "${FEL_EXTRA_ARGS}" -p uboot "${FEL_ROOTFS}/usr/lib/${CHOSEN_UBOOT}_${REVISION}_armhf/u-boot-sunxi-with-spl.bin" \
71
write 0x42000000 "${FEL_ROOTFS}"/boot/zImage \
72
write 0x43000000 "${FEL_ROOTFS}/${dtb_file}" \
73
write 0x43300000 "${FEL_ROOTFS}"/boot/uInitrd \
74
write 0x43100000 "${FEL_ROOTFS}"/boot/boot.scr
75
}
76
77
if [[ -f $USERPATCHES_PATH/fel-hooks.sh ]]; then
78
display_alert "Using additional FEL hooks in" "external/userpatches/fel-hooks.sh" "info"
79
# shellcheck source=/dev/null
80
source "$USERPATCHES_PATH"/fel-hooks.sh
81
fi
82
83
# basic sanity check
84
if [[ -n $FEL_ROOTFS ]]; then
85
fel_prepare_host
86
fel_prepare_target
87
[[ $(type -t fel_post_prepare) == function ]] && fel_post_prepare
88
RES=b
89
while [[ $RES != q ]]; do
90
if [[ $FEL_AUTO != yes ]]; then
91
display_alert "Connect device in FEL mode and press" "<Enter>" "info"
92
read -r
93
fi
94
fel_load
95
display_alert "Press any key to boot again, <q> to finish" "FEL" "info"
96
read -r -n 1 RES
97
echo
98
done
99
service nfs-kernel-server restart
100
fi
101
102