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 () { |
Thang Q. Nguyen | 509991d | 2021-07-20 15:48:50 +0700 | [diff] [blame] | 18 | OFFSET=$1 |
| 19 | |
Thang Q. Nguyen | 25254b7 | 2021-01-07 07:16:50 +0000 | [diff] [blame] | 20 | # Check the PNOR partition available |
| 21 | HOST_MTD=$(cat /proc/mtd | grep "pnor" | sed -n 's/^\(.*\):.*/\1/p') |
| 22 | if [ -z "$HOST_MTD" ]; |
| 23 | then |
| 24 | # If the PNOR partition is not available, then bind again driver |
| 25 | echo "--- Bind the ASpeed SMC driver" |
| 26 | echo 1e630000.spi > /sys/bus/platform/drivers/aspeed-smc/bind |
| 27 | sleep 2 |
| 28 | |
| 29 | HOST_MTD=$(cat /proc/mtd | grep "pnor" | sed -n 's/^\(.*\):.*/\1/p') |
| 30 | if [ -z "$HOST_MTD" ]; |
| 31 | then |
| 32 | echo "Fail to probe Host SPI-NOR device" |
| 33 | exit 1 |
| 34 | fi |
Thang Q. Nguyen | 25254b7 | 2021-01-07 07:16:50 +0000 | [diff] [blame] | 35 | fi |
Thang Q. Nguyen | 509991d | 2021-07-20 15:48:50 +0700 | [diff] [blame] | 36 | |
| 37 | echo "--- Flashing firmware to @/dev/$HOST_MTD offset=$OFFSET" |
| 38 | flashcp -v $IMAGE /dev/$HOST_MTD $OFFSET |
Thang Q. Nguyen | 25254b7 | 2021-01-07 07:16:50 +0000 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | |
| 42 | if [ $# -eq 0 ]; then |
| 43 | echo "Usage: $(basename $0) <BIOS image file>" |
| 44 | exit 0 |
| 45 | fi |
| 46 | |
| 47 | IMAGE="$1" |
| 48 | if [ ! -f $IMAGE ]; then |
| 49 | echo $IMAGE |
| 50 | echo "The image file $IMAGE does not exist" |
| 51 | exit 1 |
| 52 | fi |
| 53 | |
| 54 | # Turn off the Host if it is currently ON |
| 55 | chassisstate=$(obmcutil chassisstate | awk -F. '{print $NF}') |
| 56 | echo "--- Current Chassis State: $chassisstate" |
| 57 | if [ "$chassisstate" == 'On' ]; |
| 58 | then |
| 59 | echo "--- Turning the Chassis off" |
| 60 | obmcutil chassisoff |
| 61 | sleep 10 |
| 62 | # Check if HOST was OFF |
| 63 | chassisstate_off=$(obmcutil chassisstate | awk -F. '{print $NF}') |
| 64 | if [ "$chassisstate_off" == 'On' ]; |
| 65 | then |
| 66 | echo "--- Error : Failed turning the Chassis off" |
| 67 | exit 1 |
| 68 | fi |
| 69 | fi |
| 70 | |
| 71 | # Switch the host SPI bus to BMC" |
| 72 | echo "--- Switch the host SPI bus to BMC." |
| 73 | gpioset 0 226=0 |
| 74 | |
| 75 | if [[ $? -ne 0 ]]; then |
| 76 | echo "ERROR: Switch the host SPI bus to BMC. Please check gpio state" |
| 77 | exit 1 |
| 78 | fi |
| 79 | |
| 80 | # Flash the firmware |
Thang Q. Nguyen | 509991d | 2021-07-20 15:48:50 +0700 | [diff] [blame] | 81 | do_flash 0x400000 |
Thang Q. Nguyen | 25254b7 | 2021-01-07 07:16:50 +0000 | [diff] [blame] | 82 | |
| 83 | # Switch the host SPI bus to HOST." |
| 84 | echo "--- Switch the host SPI bus to HOST." |
| 85 | gpioset 0 226=1 |
| 86 | |
| 87 | if [[ $? -ne 0 ]]; then |
| 88 | echo "ERROR: Switch the host SPI bus to HOST. Please check gpio state" |
| 89 | exit 1 |
| 90 | fi |
| 91 | |
| 92 | if [ "$chassisstate" == 'On' ]; |
| 93 | then |
| 94 | sleep 5 |
| 95 | echo "Turn on the Host" |
Thang Q. Nguyen | 509991d | 2021-07-20 15:48:50 +0700 | [diff] [blame] | 96 | obmcutil poweron |
Thang Q. Nguyen | 25254b7 | 2021-01-07 07:16:50 +0000 | [diff] [blame] | 97 | fi |