blob: 6f87a371b5e56f8d2f3585560f84f439aad1ae21 [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
9function fwbios() {
10 KERNEL_FIU_ID="c0000000.spi"
11 KERNEL_SYSFS_FIU="/sys/bus/platform/drivers/NPCM-FIU"
12
13 # switch the SPI mux from Host to BMC
Charles Boyeraf721712022-02-09 09:17:35 -060014 i2cset -y -f -a ${I2C_BMC_CPLD[0]} 0x${I2C_BMC_CPLD[1]} 0x10 0x01
Lancelot Kao4357d532021-02-22 15:20:35 -060015
16 # rescan the spi bus
17 if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then
18 echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind
19 sleep 1
20 fi
21 echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/bind
22
23 # write to the mtd device
Charles Boyer0dd80062022-03-17 14:57:50 -050024 BIOS_MTD=$(grep "bios" /proc/mtd | sed -n 's/^\(.*\):.*/\1/p')
Lancelot Kao4357d532021-02-22 15:20:35 -060025
Charles Boyer0dd80062022-03-17 14:57:50 -050026 if [ ! -f "$1" ]; then
27 echo " Cannot find the" "$1" "image file"
XP Chen0fb270a2021-08-26 17:30:19 -050028 return 1
Lancelot Kao4357d532021-02-22 15:20:35 -060029
Lancelot Kao96a7ee32021-02-22 18:50:48 -060030 fi
Charles Boyer0dd80062022-03-17 14:57:50 -050031 echo "Flashing BIOS @/dev/${BIOS_MTD}"
32 if [ "$(flashcp -v $1 /dev/${BIOS_MTD})" -ne 0 ]; then
XP Chenc4dc5d32021-07-27 11:33:13 -050033 echo "Flashing the bios failed " >&2
XP Chen0fb270a2021-08-26 17:30:19 -050034 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -050035 fi
Lancelot Kao4357d532021-02-22 15:20:35 -060036 wait
37
38 # switch the SPI mux from BMC to Host
39 if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then
40 echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind
41 fi
Charles Boyeraf721712022-02-09 09:17:35 -060042 i2cset -y -f -a ${I2C_BMC_CPLD[0]} 0x${I2C_BMC_CPLD[1]} 0x10 0x00
Lancelot Kao4357d532021-02-22 15:20:35 -060043
XP Chen78dbf472021-08-31 00:01:17 -050044 # Disable LPI mode NV_SI_CPU_LPI_FREQ_DISABLE for SCP 1.06 and older.
Charles Boyer0dd80062022-03-17 14:57:50 -050045 if [ "$(nvparm -s 0x1 -o 0x114090)" -ne 0 ]; then
46 echo "Setting LPI mode for SCP 1.06 and older failed " >&2
XP Chen0fb270a2021-08-26 17:30:19 -050047 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -050048 fi
49
Charles Boyer0dd80062022-03-17 14:57:50 -050050 # Disable LPI mode NV_SI_CPU_LPI_FREQ_DISABLE for SCP 1.07 and newer
51 if [ "$(nvparm -s 0x1 -o 0x02A8)" -ne 0 ]; then
52 echo "Setting LPI mode for SCP 1.07 and newer failed " >&2
53 return 1
54 fi
55
56 # Disable toggling of SMPro heartbeat
57 if [ "$(nvparm -s 0x0 -o 0x5F0638)" -ne 0 ]; then
58 echo "Setting SMpro heartbeat failed " >&2
59 return 1
60 fi
61
62 if [[ $(find "$1" -type f -size +17156k 2>/dev/null) ]]; then
Lancelot Kao4357d532021-02-22 15:20:35 -060063 echo "Extracting the SCP from the image"
Charles Boyer0dd80062022-03-17 14:57:50 -050064 dd if="$1" bs=1024 skip=17156 count=256 of=/run/initramfs/myscp.img
XP Chen0fb270a2021-08-26 17:30:19 -050065 # Update both primary and backup EEPROM
Lancelot Kao4357d532021-02-22 15:20:35 -060066 fwscp /run/initramfs/myscp.img
XP Chen0fb270a2021-08-26 17:30:19 -050067 fwscpback /run/initramfs/myscp.img
Lancelot Kao4357d532021-02-22 15:20:35 -060068 fi
XP Chenc4dc5d32021-07-27 11:33:13 -050069
XP Chen0fb270a2021-08-26 17:30:19 -050070
71 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -060072}
73
Lancelot Kao4357d532021-02-22 15:20:35 -060074function fwbmccpld() {
Charles Boyerd7d34232022-02-09 08:32:22 -060075 # BMC_JTAG_MUX_1 0:BMC 1:MB
76 set_gpio_ctrl MB_JTAG_MUX_SEL 0
Charles Boyer0dd80062022-03-17 14:57:50 -050077 if [ "$(loadsvf -d /dev/jtag0 -s $1 -m 0)" -ne 0 ]; then
XP Chenc4dc5d32021-07-27 11:33:13 -050078 echo "BMC CPLD update failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -050079 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -050080 fi
Lancelot Kao4357d532021-02-22 15:20:35 -060081 wait
Charles Boyerd7d34232022-02-09 08:32:22 -060082 set_gpio_ctrl MB_JTAG_MUX_SEL 1
XP Chen0fb270a2021-08-26 17:30:19 -050083
84 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -060085}
86
87function fwmbcpld() {
Charles Boyerd7d34232022-02-09 08:32:22 -060088 # BMC_JTAG_MUX_1 0:BMC 1:MB
89 # BMC_JTAG_SEL 0:BMC 1:CPU
90 set_gpio_ctrl MB_JTAG_MUX_SEL 1
91 set_gpio_ctrl BMC_JTAG_MUX_SEL 1
Charles Boyer0dd80062022-03-17 14:57:50 -050092 if [ "$(loadsvf -d /dev/jtag0 -s $1 -m 0)" -ne 0 ]; then
XP Chenc4dc5d32021-07-27 11:33:13 -050093 echo "Mobo CPLD update failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -050094 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -050095 fi
Lancelot Kao4357d532021-02-22 15:20:35 -060096 wait
XP Chen0fb270a2021-08-26 17:30:19 -050097
98 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -060099}
100
101function fwscp() {
Charles Boyerd7d34232022-02-09 08:32:22 -0600102 # BMC_I2C_BACKUP_SEL 0:failover, 1:main
103 # BMC_CPU_EEPROM_I2C_SEL 0:BMC, 1:CPU
104 scp_eeprom_sel=$(get_gpio_ctrl BACKUP_SCP_SEL)
105 set_gpio_ctrl BACKUP_SCP_SEL 1
106 set_gpio_ctrl CPU_EEPROM_SEL 0
Charles Boyeraf721712022-02-09 09:17:35 -0600107 if [ "$(ampere_eeprom_prog -b ${I2C_CPU_EEPROM[0]} -s 0x${I2C_CPU_EEPROM[1]} -p -f $1)" -ne 0 ]; then
XP Chenc4dc5d32021-07-27 11:33:13 -0500108 echo "SCP eeprom update failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -0500109 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -0500110 fi
Lancelot Kao4357d532021-02-22 15:20:35 -0600111 wait
Charles Boyerd7d34232022-02-09 08:32:22 -0600112 set_gpio_ctrl CPU_EEPROM_SEL 1
113 set_gpio_ctrl BACKUP_SCP_SEL "$scp_eeprom_sel"
XP Chen0fb270a2021-08-26 17:30:19 -0500114
115 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -0600116}
117
118function fwscpback() {
Charles Boyerd7d34232022-02-09 08:32:22 -0600119 # BMC_I2C_BACKUP_SEL 0:failover, 1:main
120 # BMC_CPU_EEPROM_I2C_SEL 0:BMC, 1:CPU
121 scp_eeprom_sel=$(get_gpio_ctrl BACKUP_SCP_SEL)
122 set_gpio_ctrl BACKUP_SCP_SEL 0
123 set_gpio_ctrl CPU_EEPROM_SEL 0
Charles Boyeraf721712022-02-09 09:17:35 -0600124 if [ "$(ampere_eeprom_prog -b ${I2C_CPU_EEPROM[0]} -s 0x${I2C_CPU_EEPROM[1]} -p -f $1)" -ne 0 ]; then
XP Chenc4dc5d32021-07-27 11:33:13 -0500125 echo "SCP BACKUP eeprom update failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -0500126 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -0500127 fi
Lancelot Kao4357d532021-02-22 15:20:35 -0600128 wait
Charles Boyerd7d34232022-02-09 08:32:22 -0600129 set_gpio_ctrl CPU_EEPROM_SEL 1
130 set_gpio_ctrl BACKUP_SCP_SEL "$scp_eeprom_sel"
XP Chen0fb270a2021-08-26 17:30:19 -0500131
132 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -0600133}
134
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500135function fwmb_pwr_seq(){
136 #$1 0x40 seq config file
137 #$2 0x41 seq config file
Charles Boyer0dd80062022-03-17 14:57:50 -0500138 if [[ ! -e "$1" ]]; then
139 echo "The file $1 does not exist"
XP Chen0fb270a2021-08-26 17:30:19 -0500140 return 1
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500141 fi
Charles Boyer0dd80062022-03-17 14:57:50 -0500142 if [[ ! -e "$2" ]]; then
143 echo "The file $2 file does not exist"
XP Chen0fb270a2021-08-26 17:30:19 -0500144 return 1
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500145 fi
Charles Boyeraf721712022-02-09 09:17:35 -0600146 echo ${I2C_MB_PWRSEQ1[0]}-00${I2C_MB_PWRSEQ1[1]} > /sys/bus/i2c/drivers/adm1266/unbind
147 echo ${I2C_MB_PWRSEQ2[0]}-00${I2C_MB_PWRSEQ2[1]} > /sys/bus/i2c/drivers/adm1266/unbind
Kyle Niemana28c4af2022-08-08 12:29:17 -0500148 #Parameters passed to adm1266_fw_fx to be used to flash PS
149 #1st I2C bus number of PS's
150 #2nd/3rd PS seq config file
151 if [ "$(adm1266_fw_fx ${I2C_MB_PWRSEQ1[0]} $1 $2)" -ne 0 ]; then
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500152 echo "The power seq flash failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -0500153 return 1
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500154 fi
Charles Boyeraf721712022-02-09 09:17:35 -0600155 echo ${I2C_MB_PWRSEQ1[0]}-00${I2C_MB_PWRSEQ1[1]} > /sys/bus/i2c/drivers/adm1266/bind
156 echo ${I2C_MB_PWRSEQ2[0]}-00${I2C_MB_PWRSEQ2[1]} > /sys/bus/i2c/drivers/adm1266/bind
XP Chen0fb270a2021-08-26 17:30:19 -0500157
158 return 0
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500159}
Lancelot Kao4357d532021-02-22 15:20:35 -0600160
XP Chenc4dc5d32021-07-27 11:33:13 -0500161if [[ ! $(which flashcp) ]]; then
162 echo "flashcp utility not installed"
163 exit 1
164fi
165if [[ ! $(which ampere_eeprom_prog) ]]; then
166 echo "ampere_eeprom_prog utility not installed"
167 exit 1
168fi
169if [[ ! $(which loadsvf) ]]; then
170 echo "loadsvf utility not installed"
171 exit 1
172fi
173if [[ ! -e /dev/jtag0 ]]; then
174 echo "Jtag device driver not functional"
175 exit 1
176fi
177
Lancelot Kao4357d532021-02-22 15:20:35 -0600178case $1 in
179 bios)
Charles Boyer0dd80062022-03-17 14:57:50 -0500180 fwbios "$2"
Lancelot Kao4357d532021-02-22 15:20:35 -0600181 ;;
182 bmccpld)
Charles Boyer0dd80062022-03-17 14:57:50 -0500183 fwbmccpld "$2"
Lancelot Kao4357d532021-02-22 15:20:35 -0600184 ;;
185 mbcpld)
Charles Boyer0dd80062022-03-17 14:57:50 -0500186 fwmbcpld "$2"
Lancelot Kao4357d532021-02-22 15:20:35 -0600187 ;;
188 scp)
Charles Boyer0dd80062022-03-17 14:57:50 -0500189 fwscp "$2"
Lancelot Kao4357d532021-02-22 15:20:35 -0600190 ;;
191 scpback)
Charles Boyer0dd80062022-03-17 14:57:50 -0500192 fwscpback "$2"
Lancelot Kao4357d532021-02-22 15:20:35 -0600193 ;;
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500194 mbseq)
Charles Boyer0dd80062022-03-17 14:57:50 -0500195 fwmb_pwr_seq "$2" "$3"
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500196 ;;
Lancelot Kao4357d532021-02-22 15:20:35 -0600197 *)
198 ;;
199esac
XP Chen0fb270a2021-08-26 17:30:19 -0500200ret=$?
201
Charles Boyer0dd80062022-03-17 14:57:50 -0500202rm -f "$2" "$3"
XP Chen0fb270a2021-08-26 17:30:19 -0500203
204exit $ret