forked from wenyi0421/turing-pi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flash.sh
65 lines (53 loc) · 1.14 KB
/
flash.sh
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
#!/bin/sh
# flash BMC via SSH
# * only rootfs, no kernel
usage() {
cat >&2 <<EOF
${0##*/} [IMAGE] [HOSTSPEC]
* IMAGE must be a readable file
* HOSTSPEC can be either just a host or USER@HOST
EOF
}
IMAGE="$1"
if ! [ -r "$IMAGE" ]; then
echo "E: IMAGE '$1' does not exist or is empty." >&2
usage
exit 1
fi
HOST="$2"
if [ -z "$HOST" ]; then
echo "E: HOST not given." >&2
usage
exit 1
fi
ssh "$HOST" < "$IMAGE" '
set -e
set -x
ROOTDEV="$(awk "\$2 == \""/\"" {print \$1}" /proc/mounts)"
case "$ROOTDEV" in
ubi0_5 )
SWUPDATE_TARGET=upgrade_ubi6
UBOOT_TARGET=ubi0_6
;;
ubi0_6 )
SWUPDATE_TARGET=upgrade_ubi5
UBOOT_TARGET=ubi0_5
;;
* )
echo "E: /dev/$ROOTDEV cannot be updated this way." >&2
exit 1
;;
esac
# transfer the firmware file
trap "rm -f \"\$TMPFW\"" EXIT TERM KILL USR1 USR2 HUP QUIT INT
TMPFW="$(mktemp)"
cat > "$TMPFW"
# prevent writes on that device
mount -o remount,ro /
echo s > /proc/sysrq-trigger
echo u > /proc/sysrq-trigger
cd /tmp
swupdate -i "$TMPFW" -e stable,$SWUPDATE_TARGET
fw_setenv nand_root $UBOOT_TARGET
reboot
'