blob: 876671c1bb9aaa7173f38da695801da1e4bde9be [file] [log] [blame]
Thang Q. Nguyen25254b72021-01-07 07:16:50 +00001#!/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
17do_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
48if [ $# -eq 0 ]; then
49 echo "Usage: $(basename $0) <BIOS image file>"
50 exit 0
51fi
52
53IMAGE="$1"
54if [ ! -f $IMAGE ]; then
55 echo $IMAGE
56 echo "The image file $IMAGE does not exist"
57 exit 1
58fi
59
60# Turn off the Host if it is currently ON
61chassisstate=$(obmcutil chassisstate | awk -F. '{print $NF}')
62echo "--- Current Chassis State: $chassisstate"
63if [ "$chassisstate" == 'On' ];
64then
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
75fi
76
77# Switch the host SPI bus to BMC"
78echo "--- Switch the host SPI bus to BMC."
79gpioset 0 226=0
80
81if [[ $? -ne 0 ]]; then
82 echo "ERROR: Switch the host SPI bus to BMC. Please check gpio state"
83 exit 1
84fi
85
86# Flash the firmware
87do_flash
88
89# Switch the host SPI bus to HOST."
90echo "--- Switch the host SPI bus to HOST."
91gpioset 0 226=1
92
93if [[ $? -ne 0 ]]; then
94 echo "ERROR: Switch the host SPI bus to HOST. Please check gpio state"
95 exit 1
96fi
97
98if [ "$chassisstate" == 'On' ];
99then
100 sleep 5
101 echo "Turn on the Host"
102 obmcutil chassison
103fi