blob: dce6e6ccaaeed163d39771adccd34e405af9158a [file] [log] [blame]
Chanh Nguyenb50fedb2022-10-24 15:29:56 +07001#!/bin/bash
2
3# Helper script to flash FRU and Boot EEPROM devices.
4#
5# Syntax for FRU:
6# ampere_firmware_upgrade.sh fru <image> [<dev>]
7# dev: 1 for MB FRU (default), 2 for BMC FRU.
8#
9# Syntax for EEPROM:
10# ampere_firmware_upgrade.sh eeprom <image> [<dev>]
11# dev: 1 for main Boot EEPROM (default), 2 for secondary Boot EEPROM (if supported)
12#
13# Syntax for Mainboard CPLD:
14# ampere_firmware_upgrade.sh main_cpld <image>
15#
16# Syntax for BMC CPLD:
17# ampere_firmware_upgrade.sh bmc_cpld <image>
18#
19# Syntax for Backplane CPLD:
20# ampere_firmware_upgrade.sh bp_cpld <image> [<target>]
21# target: 1 for Front Backplane 1
22# 2 for Front Backplane 2
23# 3 for Front Backplane 3
24# 4 for Rear Backplane 1
25# 5 for Rear Backplane 2
26#
27
28# shellcheck disable=SC2046
29
30do_eeprom_flash() {
31 FIRMWARE_IMAGE=$IMAGE
32 BACKUP_SEL=$2
33
34 # Turn off the Host if it is currently ON
35 chassisstate=$(obmcutil chassisstate | awk -F. '{print $NF}')
36 echo "Current Chassis State: $chassisstate"
37 if [ "$chassisstate" == 'On' ];
38 then
39 echo "Turning the Chassis off"
40 obmcutil chassisoff
41 sleep 15
42 # Check if HOST was OFF
43 chassisstate_off=$(obmcutil chassisstate | awk -F. '{print $NF}')
44 if [ "$chassisstate_off" == 'On' ];
45 then
46 echo "Error : Failed turning the Chassis off"
47 exit 1
48 fi
49 fi
50
51 # Switch EEPROM control to BMC AST2600 I2C
52 # BMC_GPIOW6_SPI0_PROGRAM_SEL
53 gpioset $(gpiofind spi0-program-sel)=1
54
55 # BMC_GPIOX0_I2C_BACKUP_SEL (GPIO 184)
56 if [[ $BACKUP_SEL == 1 ]]; then
57 echo "Run update Primary EEPROM"
58 gpioset $(gpiofind i2c-backup-sel)=0
59 elif [[ $BACKUP_SEL == 2 ]]; then
60 echo "Run update Failover EEPROM"
61 gpioset $(gpiofind i2c-backup-sel)=1
62 else
63 echo "Please choose Primary EEPROM (1) or Failover EEPROM (2)"
64 exit 0
65 fi
66
67 # The EEPROM (AT24C64WI) with address 0x50 at BMC_I2C11 bus
68 # Write Firmware to EEPROM and read back for validation
69 ampere_eeprom_prog -b 10 -s 0x50 -p -f "$FIRMWARE_IMAGE"
70
71 # Switch to primary EEPROM
72 gpioset $(gpiofind i2c-backup-sel)=0
73
74 # Switch EEPROM control to CPU HOST
75 gpioset $(gpiofind spi0-program-sel)=0
76
77 if [ "$chassisstate" == 'On' ];
78 then
79 sleep 5
80 echo "Turn on the Host"
81 obmcutil poweron
82 fi
83}
84
85do_fru_flash() {
86 FRU_IMAGE=$1
87 FRU_DEV=$2
88
89 if [[ $FRU_DEV == 1 ]]; then
90 if [ -f /sys/bus/i2c/devices/4-0050/eeprom ]; then
91 FRU_DEVICE="/sys/bus/i2c/devices/4-0050/eeprom"
92 else
93 FRU_DEVICE="/sys/bus/i2c/devices/3-0050/eeprom"
94 fi
95 echo "Flash MB FRU with image $IMAGE at $FRU_DEVICE"
96 elif [[ $FRU_DEV == 2 ]]; then
97 FRU_DEVICE="/sys/bus/i2c/devices/14-0050/eeprom"
98 echo "Flash BMC FRU with image $IMAGE at $FRU_DEVICE"
99 else
100 echo "Please select MB FRU (1) or BMC FRU (2)"
101 exit 0
102 fi
103
104 ampere_fru_upgrade -d "$FRU_DEVICE" -f "$FRU_IMAGE"
105
106 systemctl restart xyz.openbmc_project.FruDevice.service
107 systemctl restart phosphor-ipmi-host.service
108
109 echo "Done"
110}
111
112do_mb_cpld_flash() {
113 MB_CPLD_IMAGE=$1
114 echo "Flashing MB CPLD"
115 gpioset $(gpiofind hpm-fw-recovery)=1
116 gpioset $(gpiofind jtag-program-sel)=1
117 sleep 2
118 ampere_cpldupdate_jtag -t 1 -p "$MB_CPLD_IMAGE"
119 gpioset $(gpiofind hpm-fw-recovery)=0
120 echo "Done"
121}
122
123do_bmc_cpld_flash() {
124 BMC_CPLD_IMAGE=$1
125 echo "Flashing BMC CPLD"
126 gpioset $(gpiofind jtag-program-sel)=0
127 sleep 2
128 ampere_cpldupdate_jtag -t 1 -p "$BMC_CPLD_IMAGE"
129 echo "Done"
130}
131
132do_bp_cpld_flash() {
133 BP_CPLD_IMAGE=$1
134 BP_TARGET=$2
135 if [[ $BP_TARGET == 1 ]]; then
136 echo "Flashing Front Backplane 1 CPLD"
137 ampere_cpldupdate_i2c -b 101 -s 0x40 -t 2 -p "$BP_CPLD_IMAGE"
138 elif [[ $BP_TARGET == 2 ]]; then
139 echo "Flashing Front Backplane 2 CPLD"
140 ampere_cpldupdate_i2c -b 102 -s 0x40 -t 2 -p "$BP_CPLD_IMAGE"
141 elif [[ $BP_TARGET == 3 ]]; then
142 echo "Flashing Front Backplane 3 CPLD"
143 ampere_cpldupdate_i2c -b 100 -s 0x40 -t 2 -p "$BP_CPLD_IMAGE"
144 elif [[ $BP_TARGET == 4 ]]; then
145 echo "Flashing Rear Backplane 1 CPLD"
146 ampere_cpldupdate_i2c -b 103 -s 0x40 -t 2 -p "$BP_CPLD_IMAGE"
147 elif [[ $BP_TARGET == 5 ]]; then
148 echo "Flashing Rear Backplane 2 CPLD"
149 ampere_cpldupdate_i2c -b 104 -s 0x40 -t 2 -p "$BP_CPLD_IMAGE"
150 fi
151
152 echo "Done"
153}
154
155if [ $# -eq 0 ]; then
156 echo "Usage:"
157 echo " - Flash Boot EEPROM"
158 echo " $(basename "$0") eeprom <Image file>"
159 echo " - Flash FRU"
160 echo " $(basename "$0") fru <Image file> [dev]"
161 echo " Where:"
162 echo " dev: 1 - MB FRU, 2 - BMC FRU"
163 echo " - Flash Mainboard CPLD"
164 echo " $(basename "$0") mb_cpld <Image file>"
165 echo " - Flash BMC CPLD (only for DC-SCM BMC board)"
166 echo " $(basename "$0") bmc_cpld <Image file>"
167 echo " - Flash Backplane CPLD"
168 echo " $(basename "$0") bp_cpld <Image file> <Target> "
169 echo " Where:"
170 echo " Target: 1 - FrontBP1, 2 - FrontBP2, 3 - FrontBP3"
171 echo " 4 - RearBP1, 5 - RearBP2"
172 exit 0
173fi
174
175TYPE=$1
176IMAGE=$2
177TARGET=$3
178if [ -z "$3" ]; then
179 BACKUP_SEL=1
180else
181 BACKUP_SEL=$3
182fi
183
184if [[ $TYPE == "eeprom" ]]; then
185 # Run EEPROM update: write/read/validation with CRC32 checksum
186 do_eeprom_flash "$IMAGE" "$BACKUP_SEL"
187elif [[ $TYPE == "fru" ]]; then
188 # Run FRU update
189 do_fru_flash "$IMAGE" "$BACKUP_SEL"
190elif [[ $TYPE == "mb_cpld" ]]; then
191 # Run Mainboard CPLD update
192 do_mb_cpld_flash "$IMAGE"
193elif [[ $TYPE == "bmc_cpld" ]]; then
194 # Run CPLD BMC update
195 do_bmc_cpld_flash "$IMAGE"
196elif [[ $TYPE == "bp_cpld" ]]; then
197 # Run Backplane CPLD update
198 do_bp_cpld_flash "$IMAGE" "$TARGET"
199fi
200
201exit 0