Vijay Khemka | 61aca58 | 2020-02-18 14:05:24 -0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | POWER_CMD="/usr/sbin/power-util mb" |
| 6 | IMAGE_FILE=$1/bios.bin |
| 7 | GPIO=389 |
| 8 | |
| 9 | IPMB_OBJ="xyz.openbmc_project.Ipmi.Channel.Ipmb" |
| 10 | IPMB_PATH="/xyz/openbmc_project/Ipmi/Channel/Ipmb" |
| 11 | IPMB_INTF="org.openbmc.Ipmb" |
| 12 | IPMB_CALL="sendRequest yyyyay" |
| 13 | ME_CMD_RECOVER="1 0x2e 0 0xdf 4 0x57 0x01 0x00 0x01" |
| 14 | ME_CMD_RESET="1 6 0 0x2 0" |
| 15 | SPI_DEV="1e630000.spi" |
| 16 | SPI_PATH="/sys/bus/platform/drivers/aspeed-smc" |
| 17 | |
| 18 | set_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 | |
| 39 | set_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 | |
| 62 | echo "Bios upgrade started at $(date)" |
| 63 | |
| 64 | #Power off host server. |
| 65 | echo "Power off host server" |
| 66 | $POWER_CMD off |
| 67 | sleep 15 |
| 68 | if [ $($POWER_CMD status) != "off" ]; |
| 69 | then |
| 70 | echo "Host server didn't power off" |
| 71 | echo "Bios upgrade failed" |
| 72 | exit -1 |
| 73 | fi |
| 74 | echo "Host server powered off" |
| 75 | |
| 76 | #Set ME to recovery mode |
| 77 | echo "Set ME to recovery mode" |
| 78 | busctl call $IPMB_OBJ $IPMB_PATH $IPMB_INTF $IPMB_CALL $ME_CMD_RECOVER |
| 79 | sleep 5 |
| 80 | |
| 81 | #Flip GPIO to access SPI flash used by host. |
| 82 | echo "Set GPIO $GPIO to access SPI flash from BMC used by host" |
| 83 | set_gpio_to_bmc |
| 84 | |
| 85 | #Bind spi driver to access flash |
| 86 | echo "bind aspeed-smc spi driver" |
| 87 | echo -n $SPI_DEV > $SPI_PATH/bind |
| 88 | sleep 1 |
| 89 | |
| 90 | #Flashcp image to device. |
| 91 | if [ -e "$IMAGE_FILE" ]; |
| 92 | then |
| 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 |
| 111 | else |
| 112 | echo "Bios image $IMAGE_FILE doesn't exist" |
| 113 | fi |
| 114 | |
| 115 | #Unbind spi driver |
| 116 | sleep 1 |
| 117 | echo "Unbind aspeed-smc spi driver" |
| 118 | echo -n $SPI_DEV > $SPI_PATH/unbind |
| 119 | sleep 10 |
| 120 | |
| 121 | #Flip GPIO back for host to access SPI flash |
| 122 | echo "Set GPIO $GPIO back for host to access SPI flash" |
| 123 | set_gpio_to_pch |
| 124 | sleep 5 |
| 125 | |
| 126 | #Reset ME to boot from new bios |
| 127 | echo "Reset ME to boot from new bios" |
| 128 | busctl call $IPMB_OBJ $IPMB_PATH $IPMB_INTF $IPMB_CALL $ME_CMD_RESET |
| 129 | sleep 10 |
| 130 | |
| 131 | #Power on server |
| 132 | echo "Power on server" |
| 133 | $POWER_CMD on |
| 134 | sleep 5 |
| 135 | |
| 136 | # Retry to power on once again if server didn't powered on |
| 137 | if [ $($POWER_CMD status) != "on" ]; |
| 138 | then |
| 139 | sleep 5 |
| 140 | echo "Powering on server again" |
| 141 | $POWER_CMD on |
| 142 | fi |