Ken Chen | e4bdcf7 | 2018-03-07 10:24:42 +0800 | [diff] [blame] | 1 | #!/bin/sh -e |
| 2 | # SOC update tool, need two parameter(soc update file name and TFTP ip) |
| 3 | |
| 4 | if [ ! -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 |
| 9 | fi |
| 10 | |
| 11 | echo "SOC update start." |
| 12 | |
| 13 | echo "Check BMC status." |
| 14 | checkbmc='gpioutil -p Q4' |
| 15 | if $checkbmc = "1"; then |
| 16 | echo "BMC is ready." |
| 17 | else |
| 18 | echo "BMC isn't ready." |
| 19 | exit |
| 20 | fi |
| 21 | |
| 22 | echo "Check SOC image does it exist." |
| 23 | cd /tmp/ |
| 24 | FILEEXIST=0 |
| 25 | if [ -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 |
| 33 | fi |
| 34 | |
| 35 | if [ $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 |
| 74 | fi |
| 75 | sleep 3 |
| 76 | |
| 77 | echo "Switch the host SPI bus to BMC." |
| 78 | cmd='gpioutil -p C7 -v 1' |
| 79 | if $cmd 1>/dev/null 2>&1; then |
| 80 | echo "Switch completed." |
| 81 | else |
| 82 | echo "Switch failed." |
| 83 | fi |
| 84 | echo "Load the ASpeed SMC driver" |
| 85 | echo 1e630000.flash-controller > /sys/bus/platform/drivers/aspeed-smc/bind |
| 86 | sleep 2 |
| 87 | chassisstate=$(obmcutil chassisstate | awk -F. '{print $NF}') |
| 88 | echo "---Current Chassisstate $chassisstate---" |
| 89 | if [ "$chassisstate" == 'On' ]; |
| 90 | then |
| 91 | echo "---Chassis on turning it off---" |
| 92 | obmcutil chassisoff |
| 93 | sleep 10 |
| 94 | fi |
| 95 | |
| 96 | echo "Flashcp to update SOC." |
| 97 | echo "Please wait a few minutes." |
| 98 | flashcp -v /tmp/$1 /dev/mtd6 |
| 99 | sleep 3 |
| 100 | |
| 101 | echo "Switch the host SPI bus to HOST." |
| 102 | cmd1='gpioutil -p C7 -v 0' |
| 103 | if $cmd1 1>/dev/null 2>&1; then |
| 104 | echo "Switch completed." |
| 105 | else |
| 106 | echo "Switch failed." |
| 107 | fi |
| 108 | echo "unLoad the ASpeed SMC driver" |
| 109 | echo 1e630000.flash-controller > /sys/bus/platform/drivers/aspeed-smc/unbind |
| 110 | echo -ne "SOC update steps is complete.\n" |
| 111 | if [ "$chassisstate" == 'On' ]; |
| 112 | then |
| 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 |
| 129 | fi |