/
upload_image_emmc
executable file
·70 lines (56 loc) · 1.36 KB
/
upload_image_emmc
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
#!/bin/bash
Usage(){
echo "$(basename "${0}")" "[bmc image] [BMC IP]"
echo " [bmc image]: the BMC firmware image for eMMC"
echo " [bmc IP]: the BMC IP address"
echo ""
echo "Upload BMC image via scp and Openbmc update script"
echo "Note: The script depend on ssh, please consider "
echo " run ssh-copy-id first to prevent enter password."
exit 1
}
toggle(){
if [ "$1" == "bootside=a" ];then
echo "b"
else
echo "a"
fi
}
# basic check
# this script base on ssh not token, so we don't need basic_check
# mode option/check
if [ ! -f "$1" ]; then
echo "No valid file found, $1"
Usage
fi
image="$1"
if [ -z "$2" ]; then
if [ -z "$bmc_ip" ]; then
Usage
else
BMC_IP="$bmc_ip"
fi
else
BMC_IP="$2"
fi
# run command
set -e
## upload image
IMG_DIR="/tmp/images/"
## clean up upload dir to avoid confuse
ssh "root@${BMC_IP}" "rm -rf ${IMG_DIR}/*"
scp "${image}" "root@${BMC_IP}:${IMG_DIR}"
id=$(ssh "root@${BMC_IP}" "ls ${IMG_DIR}")
if [ -z "${id}" ]; then
echo "no valid image"
exit 1
fi
## perform update image
ssh "root@${BMC_IP}" "obmc-flash-bmc mmc ${id} ${IMG_DIR}"
## update bootside to another
bootside=$(ssh "root@${BMC_IP}" "fw_printenv bootside")
boot=$(toggle "${bootside}")
ssh "root@${BMC_IP}" "fw_setenv bootside ${boot}"
set +e
# echo result
echo "update success, run reboot for make change effect"