forked from superna9999/pyamlboot
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·135 lines (120 loc) · 3.13 KB
/
run.sh
File metadata and controls
executable file
·135 lines (120 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
set -e
cd $(readlink -f $(dirname ${BASH_SOURCE[0]}))
AML_USB_ID="1b8e:c003"
LC_USB_ID="1b8e:fada"
if [ -z "$WAIT_TIME" ]; then
WAIT_TIME=60
fi
if [ -z "$LOOP" ]; then
LOOP=0
fi
. board.sh
if [ -z "$1" ]; then
echo "$0 board firmware-update"
echo "$0 board firmware-flash [config]"
echo "$0 board list"
echo "$0 board [action]"
exit 1
fi
board="${1,,}"
board_check "$board"
if ! python3 -c "import usb.core"; then
echo "pyamlboot requires python3-usb"
exit 1
fi
if [ ! -z "$2" ] && [ "$2" = "firmware-update" -o "$2" = "firmware-flash" ]; then
if ! which dfu-util; then
echo "firmware-update requires dfu-util"
exit 1
fi
if [ -z "$firmware" ]; then
if [ "$board" = "aml-s905x-cc" ]; then
read -n 1 -p "AML-S905X-CC does not have onboard firmware. This will update the eMMC/SD firmware. Press Control+C to cancel."
fi
firmware=$(mktemp)
trap "rm \"$firmware\"" EXIT
wget -O "$firmware" "https://boot.libre.computer/ci/$board-spi"
fi
fi
if [ ! -z "$2" ] && [ "$2" = "firmware-flash" ]; then
fit="${firmware%.*}.fit"
if [ ! -f "$fit" ]; then
echo "ERROR: Overlay FIT not found: $fit" >&2
exit 1
fi
if [ ! -z "$3" ] && [ ! -f "$3" ]; then
echo "ERROR: Config file not found: $3" >&2
exit 1
fi
fi
if [[ -v "BOARD_GXL[$board]" ]]; then
platform=$PLATFORM_GXL
if [ ! -z "$2" ] && [ "$2" != "firmware-update" ] && [ "$2" != "firmware-flash" ]; then
if [ "$2" = "list" ]; then
for script in scripts/*.scr; do
if [ -h "$script" ]; then
continue
fi
echo "${script/scripts\//}" | sed "s/.scr\$//"
done
exit
else
if [ ! -f "scripts/$2.scr" ]; then
echo "ACTION: $2 does not exist." >&2
exit 1
fi
action="--script scripts/$2.scr"
fi
fi
if [ ! -z "$2" ] && [ "$2" = "firmware-flash" ]; then
action="--script scripts/dfu-sf.scr"
fi
elif [[ -v "BOARD_G12[$board]" ]]; then
platform=$PLATFORM_G12
if [ ! -z "$2" ] && [ "$2" != "firmware-update" ] && [ "$2" != "firmware-flash" ]; then
echo "PLATFORM: $platform does not support actions." >&2
exit 1
fi
else
echo "BOARD: $board does not exist."
exit 1
fi
while true; do
wait_time=0
while ! lsusb -d "$AML_USB_ID" > /dev/null 2>&1; do
if [ "$wait_time" -eq 0 ]; then
echo -n "Please plug in the board's OTG port with the USB/BOOT button held down."
if [ "$WAIT_TIME" -ne 0 ]; then
echo " Waiting for ${WAIT_TIME}s..."
fi
fi
sleep 1
wait_time=$((wait_time+1))
echo -en "\rWaiting for device enumeration...${wait_time}s"
if [ "$WAIT_TIME" -ne 0 ] && [ "$wait_time" = "$WAIT_TIME" ]; then
echo -en "\nDevice could not be found after ${WAIT_TIME}s"
exit 1
fi
done
echo
set -x
if [ "$platform" = $PLATFORM_GXL ]; then
./boot.py $action "${BOARD_GXL[$board]}"
else
./boot-g12.py --board-name "${BOARD_G12[$board]}"
fi
if [ ! -z "$2" ] && [ "$2" = "firmware-update" ]; then
dfu-util --device "$LC_USB_ID" -a 0 -w -D "$firmware"
fi
if [ ! -z "$2" ] && [ "$2" = "firmware-flash" ]; then
dfu-util --device "$LC_USB_ID" -a u-boot-bin -w -D "$firmware"
dfu-util --device "$LC_USB_ID" -a fit -D "$fit"
if [ ! -z "$3" ]; then
dfu-util --device "$LC_USB_ID" -a config -D "$3"
fi
fi
if [ "$LOOP" -eq 0 ]; then
break
fi
done