Thang Q. Nguyen | 25254b7 | 2021-01-07 07:16:50 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (c) 2021 Ampere Computing LLC |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | do_flash () { |
| 18 | # Check the PNOR partition available |
| 19 | HOST_MTD=$(cat /proc/mtd | grep "pnor" | sed -n 's/^\(.*\):.*/\1/p') |
| 20 | if [ -z "$HOST_MTD" ]; |
| 21 | then |
| 22 | # If the PNOR partition is not available, then bind again driver |
| 23 | echo "--- Bind the ASpeed SMC driver" |
| 24 | echo 1e630000.spi > /sys/bus/platform/drivers/aspeed-smc/bind |
| 25 | sleep 2 |
| 26 | |
| 27 | HOST_MTD=$(cat /proc/mtd | grep "pnor" | sed -n 's/^\(.*\):.*/\1/p') |
| 28 | if [ -z "$HOST_MTD" ]; |
| 29 | then |
| 30 | echo "Fail to probe Host SPI-NOR device" |
| 31 | exit 1 |
| 32 | fi |
| 33 | |
| 34 | echo "--- Flashing firmware to @/dev/$HOST_MTD" |
| 35 | flash_eraseall /dev/$HOST_MTD |
| 36 | flashcp -v $IMAGE /dev/$HOST_MTD |
| 37 | |
| 38 | echo "--- Unbind the ASpeed SMC driver" |
| 39 | echo 1e630000.spi > /sys/bus/platform/drivers/aspeed-smc/unbind |
| 40 | else |
| 41 | echo "--- Flashing firmware to @/dev/$HOST_MTD" |
| 42 | flash_eraseall /dev/$HOST_MTD |
| 43 | flashcp -v $IMAGE /dev/$HOST_MTD |
| 44 | fi |
| 45 | } |
| 46 | |
| 47 | |
| 48 | if [ $# -eq 0 ]; then |
| 49 | echo "Usage: $(basename $0) <BIOS image file>" |
| 50 | exit 0 |
| 51 | fi |
| 52 | |
| 53 | IMAGE="$1" |
| 54 | if [ ! -f $IMAGE ]; then |
| 55 | echo $IMAGE |
| 56 | echo "The image file $IMAGE does not exist" |
| 57 | exit 1 |
| 58 | fi |
| 59 | |
| 60 | # Turn off the Host if it is currently ON |
| 61 | chassisstate=$(obmcutil chassisstate | awk -F. '{print $NF}') |
| 62 | echo "--- Current Chassis State: $chassisstate" |
| 63 | if [ "$chassisstate" == 'On' ]; |
| 64 | then |
| 65 | echo "--- Turning the Chassis off" |
| 66 | obmcutil chassisoff |
| 67 | sleep 10 |
| 68 | # Check if HOST was OFF |
| 69 | chassisstate_off=$(obmcutil chassisstate | awk -F. '{print $NF}') |
| 70 | if [ "$chassisstate_off" == 'On' ]; |
| 71 | then |
| 72 | echo "--- Error : Failed turning the Chassis off" |
| 73 | exit 1 |
| 74 | fi |
| 75 | fi |
| 76 | |
| 77 | # Switch the host SPI bus to BMC" |
| 78 | echo "--- Switch the host SPI bus to BMC." |
| 79 | gpioset 0 226=0 |
| 80 | |
| 81 | if [[ $? -ne 0 ]]; then |
| 82 | echo "ERROR: Switch the host SPI bus to BMC. Please check gpio state" |
| 83 | exit 1 |
| 84 | fi |
| 85 | |
| 86 | # Flash the firmware |
| 87 | do_flash |
| 88 | |
| 89 | # Switch the host SPI bus to HOST." |
| 90 | echo "--- Switch the host SPI bus to HOST." |
| 91 | gpioset 0 226=1 |
| 92 | |
| 93 | if [[ $? -ne 0 ]]; then |
| 94 | echo "ERROR: Switch the host SPI bus to HOST. Please check gpio state" |
| 95 | exit 1 |
| 96 | fi |
| 97 | |
| 98 | if [ "$chassisstate" == 'On' ]; |
| 99 | then |
| 100 | sleep 5 |
| 101 | echo "Turn on the Host" |
| 102 | obmcutil chassison |
| 103 | fi |