blob: 7a9ace30e6894dfeb5716ef67596b69f13ef2a94 [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 () {
Thang Q. Nguyen509991d2021-07-20 15:48:50 +070018 OFFSET=$1
19
Thang Q. Nguyen25254b72021-01-07 07:16:50 +000020 # 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. Nguyen25254b72021-01-07 07:16:50 +000035 fi
Thang Q. Nguyen509991d2021-07-20 15:48:50 +070036
37 echo "--- Flashing firmware to @/dev/$HOST_MTD offset=$OFFSET"
38 flashcp -v $IMAGE /dev/$HOST_MTD $OFFSET
Thang Q. Nguyen25254b72021-01-07 07:16:50 +000039}
40
41
42if [ $# -eq 0 ]; then
43 echo "Usage: $(basename $0) <BIOS image file>"
44 exit 0
45fi
46
47IMAGE="$1"
48if [ ! -f $IMAGE ]; then
49 echo $IMAGE
50 echo "The image file $IMAGE does not exist"
51 exit 1
52fi
53
54# Turn off the Host if it is currently ON
55chassisstate=$(obmcutil chassisstate | awk -F. '{print $NF}')
56echo "--- Current Chassis State: $chassisstate"
57if [ "$chassisstate" == 'On' ];
58then
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
69fi
70
71# Switch the host SPI bus to BMC"
72echo "--- Switch the host SPI bus to BMC."
73gpioset 0 226=0
74
75if [[ $? -ne 0 ]]; then
76 echo "ERROR: Switch the host SPI bus to BMC. Please check gpio state"
77 exit 1
78fi
79
80# Flash the firmware
Thang Q. Nguyen509991d2021-07-20 15:48:50 +070081do_flash 0x400000
Thang Q. Nguyen25254b72021-01-07 07:16:50 +000082
83# Switch the host SPI bus to HOST."
84echo "--- Switch the host SPI bus to HOST."
85gpioset 0 226=1
86
87if [[ $? -ne 0 ]]; then
88 echo "ERROR: Switch the host SPI bus to HOST. Please check gpio state"
89 exit 1
90fi
91
92if [ "$chassisstate" == 'On' ];
93then
94 sleep 5
95 echo "Turn on the Host"
Thang Q. Nguyen509991d2021-07-20 15:48:50 +070096 obmcutil poweron
Thang Q. Nguyen25254b72021-01-07 07:16:50 +000097fi