blob: 67d70633970e488592b85e05e77a783b2b030f8f [file] [log] [blame]
Ken Chene4bdcf72018-03-07 10:24:42 +08001#!/bin/sh -e
2# SOC update tool, need two parameter(soc update file name and TFTP ip)
3
4if [ ! -n "$1" -o ! -n "$2" ] ;then
5 echo "Please enter SOC-ImageName and TFTP-IP."
6 echo "Format: socupdate.sh FileName IP"
7 echo "Example: socupdate.sh 0ACJAXXX.ROM 192.168.1.1"
8 exit
9fi
10
11echo "SOC update start."
12
13echo "Check BMC status."
14checkbmc='gpioutil -p Q4'
15if $checkbmc = "1"; then
16 echo "BMC is ready."
17else
18 echo "BMC isn't ready."
19 exit
20fi
21
22echo "Check SOC image does it exist."
23cd /tmp/
24FILEEXIST=0
25if [ -f "/tmp/$1" ]; then
26 GETFILE=`du -k $1 | awk '{print $1}'`
27 if [ "$GETFILE" -eq "65536" ]; then
28 FILEEXIST=1
29 echo "SOC image is exist."
30 else
31 FILEEXIST=0
32 fi
33fi
34
35if [ $FILEEXIST -eq 0 ]; then
36 echo "Get SOC image from TFTP server."
37 echo "Please wait a few minutes."
38 tftp -g -r $1 $2 &
39 sleep 2
40 LENGTH=0
41 ERRCOUNT=0
42 while true
43 do
44 echo -ne "\r["
45 usleep 500000
46 while [ $LENGTH -le 30 ]
47 do
48 usleep 500000
49 echo -n ">"
50 LENGTH=$(($LENGTH+1))
51 if [ -f "/tmp/$1" ]; then
52 GETFILE=`du -k $1 | awk '{print $1}'`
53 if [ $GETFILE -eq 65536 ]; then
54 echo -en "\r"
55 echo -en "--- Image download completed --- \n"
56 usleep 1000000
57 break 2
58 fi
59 else
60 ERRCOUNT=$(($ERRCOUNT+1))
61 if [ $ERRCOUNT -le 10 ]; then
62 echo -en "\r"
63 echo -en "SOC-ImageName or TFTP-IP is ERROR. \n"
64 usleep 500000
65 exit
66 fi
67 fi
68 done
69 echo -n "]"
70 LENGTH=0
71 usleep 500000
72 echo -en "\r "
73 done
74fi
75sleep 3
76
77echo "Switch the host SPI bus to BMC."
78cmd='gpioutil -p C7 -v 1'
79if $cmd 1>/dev/null 2>&1; then
80 echo "Switch completed."
81else
82 echo "Switch failed."
83fi
84echo "Load the ASpeed SMC driver"
85echo 1e630000.flash-controller > /sys/bus/platform/drivers/aspeed-smc/bind
86sleep 2
87chassisstate=$(obmcutil chassisstate | awk -F. '{print $NF}')
88echo "---Current Chassisstate $chassisstate---"
89if [ "$chassisstate" == 'On' ];
90then
91 echo "---Chassis on turning it off---"
92 obmcutil chassisoff
93 sleep 10
94fi
95
96echo "Flashcp to update SOC."
97echo "Please wait a few minutes."
98flashcp -v /tmp/$1 /dev/mtd6
99sleep 3
100
101echo "Switch the host SPI bus to HOST."
102cmd1='gpioutil -p C7 -v 0'
103if $cmd1 1>/dev/null 2>&1; then
104 echo "Switch completed."
105else
106 echo "Switch failed."
107fi
108echo "unLoad the ASpeed SMC driver"
109echo 1e630000.flash-controller > /sys/bus/platform/drivers/aspeed-smc/unbind
110echo -ne "SOC update steps is complete.\n"
111if [ "$chassisstate" == 'On' ];
112then
113 echo "5 sec later will be power-on."
114 echo "If wantn't power-on, please CTRL + C leave script."
115 WAITSEC=5
116 while [ $WAITSEC -ge 0 ]
117 do
118 echo -n "Countdown seconds:$WAITSEC"
119 sleep 1
120 echo -en "\r"
121 WAITSEC=$(($WAITSEC-1))
122 if [ $WAITSEC -eq 0 ]; then
123 echo -en "\r"
124 echo -en "--- Power-on --- \n"
125 obmcutil chassison
126 break 1
127 fi
128 done
129fi