blob: 6231aeb49f445f270c8e2bfb19203b3e48f68c6a [file] [log] [blame]
Lancelot Kao4357d532021-02-22 15:20:35 -06001#!/bin/bash
2
Charles Boyer0dd80062022-03-17 14:57:50 -05003# Provide source directive to shellcheck.
4# shellcheck source=meta-fii/meta-kudo/recipes-kudo/kudo-fw-utility/kudo-fw/kudo-lib.sh
5# Disable check for globbing and word splitting within double quotes
6# shellcheck disable=SC2086
Charles Boyer2adad362021-11-24 15:58:03 -06007source /usr/libexec/kudo-fw/kudo-lib.sh
Lancelot Kao4357d532021-02-22 15:20:35 -06008
Charles Boyer0dd80062022-03-17 14:57:50 -05009devpath="/sys/bus/i2c/devices/13-0077/driver"
10
Lancelot Kao4357d532021-02-22 15:20:35 -060011function fwbios() {
12 KERNEL_FIU_ID="c0000000.spi"
13 KERNEL_SYSFS_FIU="/sys/bus/platform/drivers/NPCM-FIU"
14
15 # switch the SPI mux from Host to BMC
16 i2cset -y -f -a 13 0x76 0x10 0x01
17
18 # rescan the spi bus
19 if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then
20 echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind
21 sleep 1
22 fi
23 echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/bind
24
25 # write to the mtd device
Charles Boyer0dd80062022-03-17 14:57:50 -050026 BIOS_MTD=$(grep "bios" /proc/mtd | sed -n 's/^\(.*\):.*/\1/p')
Lancelot Kao4357d532021-02-22 15:20:35 -060027
Charles Boyer0dd80062022-03-17 14:57:50 -050028 if [ ! -f "$1" ]; then
29 echo " Cannot find the" "$1" "image file"
XP Chen0fb270a2021-08-26 17:30:19 -050030 return 1
Lancelot Kao4357d532021-02-22 15:20:35 -060031
Lancelot Kao96a7ee32021-02-22 18:50:48 -060032 fi
Charles Boyer0dd80062022-03-17 14:57:50 -050033 echo "Flashing BIOS @/dev/${BIOS_MTD}"
34 if [ "$(flashcp -v $1 /dev/${BIOS_MTD})" -ne 0 ]; then
XP Chenc4dc5d32021-07-27 11:33:13 -050035 echo "Flashing the bios failed " >&2
XP Chen0fb270a2021-08-26 17:30:19 -050036 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -050037 fi
Lancelot Kao4357d532021-02-22 15:20:35 -060038 wait
39
40 # switch the SPI mux from BMC to Host
41 if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then
42 echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind
43 fi
44 i2cset -y -f -a 13 0x76 0x10 0x00
45
XP Chen78dbf472021-08-31 00:01:17 -050046 # Disable LPI mode NV_SI_CPU_LPI_FREQ_DISABLE for SCP 1.06 and older.
Charles Boyer0dd80062022-03-17 14:57:50 -050047 if [ "$(nvparm -s 0x1 -o 0x114090)" -ne 0 ]; then
48 echo "Setting LPI mode for SCP 1.06 and older failed " >&2
XP Chen0fb270a2021-08-26 17:30:19 -050049 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -050050 fi
51
Charles Boyer0dd80062022-03-17 14:57:50 -050052 # Disable LPI mode NV_SI_CPU_LPI_FREQ_DISABLE for SCP 1.07 and newer
53 if [ "$(nvparm -s 0x1 -o 0x02A8)" -ne 0 ]; then
54 echo "Setting LPI mode for SCP 1.07 and newer failed " >&2
55 return 1
56 fi
57
58 # Disable toggling of SMPro heartbeat
59 if [ "$(nvparm -s 0x0 -o 0x5F0638)" -ne 0 ]; then
60 echo "Setting SMpro heartbeat failed " >&2
61 return 1
62 fi
63
64 if [[ $(find "$1" -type f -size +17156k 2>/dev/null) ]]; then
Lancelot Kao4357d532021-02-22 15:20:35 -060065 echo "Extracting the SCP from the image"
Charles Boyer0dd80062022-03-17 14:57:50 -050066 dd if="$1" bs=1024 skip=17156 count=256 of=/run/initramfs/myscp.img
XP Chen0fb270a2021-08-26 17:30:19 -050067 # Update both primary and backup EEPROM
Lancelot Kao4357d532021-02-22 15:20:35 -060068 fwscp /run/initramfs/myscp.img
XP Chen0fb270a2021-08-26 17:30:19 -050069 fwscpback /run/initramfs/myscp.img
Lancelot Kao4357d532021-02-22 15:20:35 -060070 fi
XP Chenc4dc5d32021-07-27 11:33:13 -050071
XP Chen0fb270a2021-08-26 17:30:19 -050072
73 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -060074}
75
Lancelot Kao4357d532021-02-22 15:20:35 -060076function fwbmccpld() {
77 # BMC_JTAG_MUX_1 #218 0:BMC 1:MB
78 set_gpio_ctrl 218 out 0
Charles Boyer0dd80062022-03-17 14:57:50 -050079 if [ "$(loadsvf -d /dev/jtag0 -s $1 -m 0)" -ne 0 ]; then
XP Chenc4dc5d32021-07-27 11:33:13 -050080 echo "BMC CPLD update failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -050081 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -050082 fi
Lancelot Kao4357d532021-02-22 15:20:35 -060083 wait
84 set_gpio_ctrl 218 out 1
XP Chen0fb270a2021-08-26 17:30:19 -050085
86 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -060087}
88
89function fwmbcpld() {
90 # BMC_JTAG_MUX_1 #218 0:BMC 1:MB
91 # BMC_JTAG_SEL #164 0:BMC 1:CPU
92 set_gpio_ctrl 218 out 1
93 set_gpio_ctrl 164 out 1
Charles Boyer0dd80062022-03-17 14:57:50 -050094 if [ "$(loadsvf -d /dev/jtag0 -s $1 -m 0)" -ne 0 ]; then
XP Chenc4dc5d32021-07-27 11:33:13 -050095 echo "Mobo CPLD update failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -050096 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -050097 fi
Lancelot Kao4357d532021-02-22 15:20:35 -060098 wait
XP Chen0fb270a2021-08-26 17:30:19 -050099
100 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -0600101}
102
103function fwscp() {
104 # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main
105 # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU
Charles Boyer0dd80062022-03-17 14:57:50 -0500106 scp_eeprom_sel=$(get_gpio_ctrl 168)
Lancelot Kao4357d532021-02-22 15:20:35 -0600107 set_gpio_ctrl 168 out 1
108 set_gpio_ctrl 85 out 0
Charles Boyer0dd80062022-03-17 14:57:50 -0500109 #shellcheck disable=SC2010
Lancelot Kao4357d532021-02-22 15:20:35 -0600110 I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-)
Charles Boyer0dd80062022-03-17 14:57:50 -0500111 if [ "$(ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1)" -ne 0 ]; then
XP Chenc4dc5d32021-07-27 11:33:13 -0500112 echo "SCP eeprom update failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -0500113 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -0500114 fi
Lancelot Kao4357d532021-02-22 15:20:35 -0600115 wait
116 set_gpio_ctrl 85 out 1
Charles Boyer0dd80062022-03-17 14:57:50 -0500117 set_gpio_ctrl 168 out "$scp_eeprom_sel"
XP Chen0fb270a2021-08-26 17:30:19 -0500118
119 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -0600120}
121
122function fwscpback() {
123 # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main
124 # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU
Charles Boyer0dd80062022-03-17 14:57:50 -0500125 scp_eeprom_sel=$(get_gpio_ctrl 168)
Lancelot Kao4357d532021-02-22 15:20:35 -0600126 set_gpio_ctrl 168 out 0
127 set_gpio_ctrl 85 out 0
Charles Boyer0dd80062022-03-17 14:57:50 -0500128 #shellcheck disable=SC2010
Lancelot Kao4357d532021-02-22 15:20:35 -0600129 I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-)
Charles Boyer0dd80062022-03-17 14:57:50 -0500130 if [ "$(ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1)" -ne 0 ]; then
XP Chenc4dc5d32021-07-27 11:33:13 -0500131 echo "SCP BACKUP eeprom update failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -0500132 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -0500133 fi
Lancelot Kao4357d532021-02-22 15:20:35 -0600134 wait
135 set_gpio_ctrl 85 out 1
Charles Boyer0dd80062022-03-17 14:57:50 -0500136 set_gpio_ctrl 168 out "$scp_eeprom_sel"
XP Chen0fb270a2021-08-26 17:30:19 -0500137
138 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -0600139}
140
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500141function fwmb_pwr_seq(){
142 #$1 0x40 seq config file
143 #$2 0x41 seq config file
Charles Boyer0dd80062022-03-17 14:57:50 -0500144 if [[ ! -e "$1" ]]; then
145 echo "The file $1 does not exist"
XP Chen0fb270a2021-08-26 17:30:19 -0500146 return 1
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500147 fi
Charles Boyer0dd80062022-03-17 14:57:50 -0500148 if [[ ! -e "$2" ]]; then
149 echo "The file $2 file does not exist"
XP Chen0fb270a2021-08-26 17:30:19 -0500150 return 1
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500151 fi
152 echo 32-0040 > /sys/bus/i2c/drivers/adm1266/unbind
153 echo 32-0041 > /sys/bus/i2c/drivers/adm1266/unbind
Charles Boyer0dd80062022-03-17 14:57:50 -0500154 if [ "$(adm1266_fw_fx $1 $2)" -ne 0 ]; then
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500155 echo "The power seq flash failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -0500156 return 1
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500157 fi
158 echo 32-0040 > /sys/bus/i2c/drivers/adm1266/bind
159 echo 32-0041 > /sys/bus/i2c/drivers/adm1266/bind
XP Chen0fb270a2021-08-26 17:30:19 -0500160
161 return 0
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500162}
Lancelot Kao4357d532021-02-22 15:20:35 -0600163
XP Chenc4dc5d32021-07-27 11:33:13 -0500164if [[ ! $(which flashcp) ]]; then
165 echo "flashcp utility not installed"
166 exit 1
167fi
168if [[ ! $(which ampere_eeprom_prog) ]]; then
169 echo "ampere_eeprom_prog utility not installed"
170 exit 1
171fi
172if [[ ! $(which loadsvf) ]]; then
173 echo "loadsvf utility not installed"
174 exit 1
175fi
176if [[ ! -e /dev/jtag0 ]]; then
177 echo "Jtag device driver not functional"
178 exit 1
179fi
180
Lancelot Kao4357d532021-02-22 15:20:35 -0600181case $1 in
182 bios)
Charles Boyer0dd80062022-03-17 14:57:50 -0500183 fwbios "$2"
Lancelot Kao4357d532021-02-22 15:20:35 -0600184 ;;
185 bmccpld)
Charles Boyer0dd80062022-03-17 14:57:50 -0500186 fwbmccpld "$2"
Lancelot Kao4357d532021-02-22 15:20:35 -0600187 ;;
188 mbcpld)
Charles Boyer0dd80062022-03-17 14:57:50 -0500189 fwmbcpld "$2"
Lancelot Kao4357d532021-02-22 15:20:35 -0600190 ;;
191 scp)
Charles Boyer0dd80062022-03-17 14:57:50 -0500192 fwscp "$2"
Lancelot Kao4357d532021-02-22 15:20:35 -0600193 ;;
194 scpback)
Charles Boyer0dd80062022-03-17 14:57:50 -0500195 fwscpback "$2"
Lancelot Kao4357d532021-02-22 15:20:35 -0600196 ;;
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500197 mbseq)
Charles Boyer0dd80062022-03-17 14:57:50 -0500198 fwmb_pwr_seq "$2" "$3"
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500199 ;;
Lancelot Kao4357d532021-02-22 15:20:35 -0600200 *)
201 ;;
202esac
XP Chen0fb270a2021-08-26 17:30:19 -0500203ret=$?
204
Charles Boyer0dd80062022-03-17 14:57:50 -0500205rm -f "$2" "$3"
XP Chen0fb270a2021-08-26 17:30:19 -0500206
207exit $ret