blob: fd1c52b2ab64d98a4ca4bf1b7acc24e7c37753bf [file] [log] [blame]
Vijay Khemka2d9fe0f2020-02-18 14:05:24 -08001#!/bin/bash
2
3set -e
4
5POWER_CMD="/usr/sbin/power-util mb"
6IMAGE_FILE=$1/bios.bin
7GPIO=389
8
9IPMB_OBJ="xyz.openbmc_project.Ipmi.Channel.Ipmb"
10IPMB_PATH="/xyz/openbmc_project/Ipmi/Channel/Ipmb"
11IPMB_INTF="org.openbmc.Ipmb"
12IPMB_CALL="sendRequest yyyyay"
13ME_CMD_RECOVER="1 0x2e 0 0xdf 4 0x57 0x01 0x00 0x01"
14ME_CMD_RESET="1 6 0 0x2 0"
15SPI_DEV="1e630000.spi"
16SPI_PATH="/sys/bus/platform/drivers/aspeed-smc"
17
18set_gpio_to_bmc()
19{
20 echo "switch bios GPIO to bmc"
21 if [ ! -d /sys/class/gpio/gpio$GPIO ]; then
22 cd /sys/class/gpio
23 echo $GPIO > export
24 cd gpio$GPIO
25 else
26 cd /sys/class/gpio/gpio$GPIO
27 fi
28 direc=`cat direction`
29 if [ $direc == "in" ]; then
30 echo "out" > direction
31 fi
32 data=`cat value`
33 if [ "$data" == "0" ]; then
34 echo 1 > value
35 fi
36 return 0
37}
38
39set_gpio_to_pch()
40{
41 echo "switch bios GPIO to pch"
42 if [ ! -d /sys/class/gpio/gpio$GPIO ]; then
43 cd /sys/class/gpio
44 echo $GPIO > export
45 cd gpio$GPIO
46 else
47 cd /sys/class/gpio/gpio$GPIO
48 fi
49 direc=`cat direction`
50 if [ $direc == "in" ]; then
51 echo "out" > direction
52 fi
53 data=`cat value`
54 if [ "$data" == "1" ]; then
55 echo 0 > value
56 fi
57 echo "in" > direction
58 echo $GPIO > /sys/class/gpio/unexport
59 return 0
60}
61
62echo "Bios upgrade started at $(date)"
63
64#Power off host server.
65echo "Power off host server"
66$POWER_CMD off
67sleep 15
68if [ $($POWER_CMD status) != "off" ];
69then
70 echo "Host server didn't power off"
71 echo "Bios upgrade failed"
72 exit -1
73fi
74echo "Host server powered off"
75
76#Set ME to recovery mode
77echo "Set ME to recovery mode"
78busctl call $IPMB_OBJ $IPMB_PATH $IPMB_INTF $IPMB_CALL $ME_CMD_RECOVER
79sleep 5
80
81#Flip GPIO to access SPI flash used by host.
82echo "Set GPIO $GPIO to access SPI flash from BMC used by host"
83set_gpio_to_bmc
84
85#Bind spi driver to access flash
86echo "bind aspeed-smc spi driver"
87echo -n $SPI_DEV > $SPI_PATH/bind
88sleep 1
89
90#Flashcp image to device.
91if [ -e "$IMAGE_FILE" ];
92then
93 echo "Bios image is $IMAGE_FILE"
94 for d in mtd6 mtd7 ; do
95 if [ -e "/dev/$d" ]; then
96 mtd=`cat /sys/class/mtd/$d/name`
97 if [ $mtd == "pnor" ]; then
98 echo "Flashing bios image to $d..."
99 flashcp -v $IMAGE_FILE /dev/$d
100 if [ $? -eq 0 ]; then
101 echo "bios updated successfully..."
102 else
103 echo "bios update failed..."
104 fi
105 break
106 fi
107 echo "$d is not a pnor device"
108 fi
109 echo "$d not available"
110 done
111else
112 echo "Bios image $IMAGE_FILE doesn't exist"
113fi
114
115#Unbind spi driver
116sleep 1
117echo "Unbind aspeed-smc spi driver"
118echo -n $SPI_DEV > $SPI_PATH/unbind
119sleep 10
120
121#Flip GPIO back for host to access SPI flash
122echo "Set GPIO $GPIO back for host to access SPI flash"
123set_gpio_to_pch
124sleep 5
125
126#Reset ME to boot from new bios
127echo "Reset ME to boot from new bios"
128busctl call $IPMB_OBJ $IPMB_PATH $IPMB_INTF $IPMB_CALL $ME_CMD_RESET
129sleep 10
130
131#Power on server
132echo "Power on server"
133$POWER_CMD on
134sleep 5
135
136# Retry to power on once again if server didn't powered on
137if [ $($POWER_CMD status) != "on" ];
138then
139 sleep 5
140 echo "Powering on server again"
141 $POWER_CMD on
142fi