blob: 0f8868f073442b45bd6ecbf407ee348d6f4b13b2 [file] [log] [blame]
Lancelot Kao4357d532021-02-22 15:20:35 -06001#!/bin/bash
2
3devpath="/sys/bus/i2c/devices/13-0077/driver"
4
Charles Boyer2adad362021-11-24 15:58:03 -06005source /usr/libexec/kudo-fw/kudo-lib.sh
Lancelot Kao4357d532021-02-22 15:20:35 -06006
7function fwbios() {
8 KERNEL_FIU_ID="c0000000.spi"
9 KERNEL_SYSFS_FIU="/sys/bus/platform/drivers/NPCM-FIU"
10
11 # switch the SPI mux from Host to BMC
12 i2cset -y -f -a 13 0x76 0x10 0x01
13
14 # rescan the spi bus
15 if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then
16 echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind
17 sleep 1
18 fi
19 echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/bind
20
21 # write to the mtd device
22 BIOS_MTD=$(cat /proc/mtd | grep "bios" | sed -n 's/^\(.*\):.*/\1/p')
23
24 if [ ! -f $1 ]; then
25 echo " Cannot find the" $1 "image file"
XP Chen0fb270a2021-08-26 17:30:19 -050026 return 1
Lancelot Kao4357d532021-02-22 15:20:35 -060027
Lancelot Kao96a7ee32021-02-22 18:50:48 -060028 fi
Lancelot Kao4357d532021-02-22 15:20:35 -060029 echo "Flashing BIOS @/dev/$BIOS_MTD"
30 flashcp -v $1 /dev/$BIOS_MTD
XP Chenc4dc5d32021-07-27 11:33:13 -050031 if [ $? -ne 0 ]; then
32 echo "Flashing the bios failed " >&2
XP Chen0fb270a2021-08-26 17:30:19 -050033 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -050034 fi
Lancelot Kao4357d532021-02-22 15:20:35 -060035 wait
36
37 # switch the SPI mux from BMC to Host
38 if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then
39 echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind
40 fi
41 i2cset -y -f -a 13 0x76 0x10 0x00
42
XP Chen78dbf472021-08-31 00:01:17 -050043 # Disable LPI mode NV_SI_CPU_LPI_FREQ_DISABLE for SCP 1.06 and older.
XP Chenc4dc5d32021-07-27 11:33:13 -050044 nvparm -s 0x1 -o 0x114090
Charles Boyer1c51ca52021-08-24 11:25:03 -050045
XP Chen78dbf472021-08-31 00:01:17 -050046 # Disable LPI mode NV_SI_CPU_LPI_FREQ_DISABLE for SCP 1.07 and newer
Charles Boyerc6001342021-11-08 15:58:21 -060047 nvparm -s 0x1 -o 0x02A8
Charles Boyer1c51ca52021-08-24 11:25:03 -050048
49 # Disable toggling of SMPro heartbeat
50 nvparm -s 0x0 -o 0x5F0638
51
XP Chenc4dc5d32021-07-27 11:33:13 -050052 if [ $? -ne 0 ]; then
53 echo "Setting default nvparms failed " >&2
XP Chen0fb270a2021-08-26 17:30:19 -050054 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -050055 fi
56
Lancelot Kao4357d532021-02-22 15:20:35 -060057 if [[ $(find ${1} -type f -size +17156k 2>/dev/null) ]]; then
58 echo "Extracting the SCP from the image"
59 dd if=$1 bs=1024 skip=17156 count=256 of=/run/initramfs/myscp.img
XP Chen0fb270a2021-08-26 17:30:19 -050060 # Update both primary and backup EEPROM
Lancelot Kao4357d532021-02-22 15:20:35 -060061 fwscp /run/initramfs/myscp.img
XP Chen0fb270a2021-08-26 17:30:19 -050062 fwscpback /run/initramfs/myscp.img
Lancelot Kao4357d532021-02-22 15:20:35 -060063 fi
XP Chenc4dc5d32021-07-27 11:33:13 -050064
XP Chen0fb270a2021-08-26 17:30:19 -050065
66 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -060067}
68
Lancelot Kao4357d532021-02-22 15:20:35 -060069function fwbmccpld() {
70 # BMC_JTAG_MUX_1 #218 0:BMC 1:MB
71 set_gpio_ctrl 218 out 0
72 loadsvf -d /dev/jtag0 -s $1 -m 0
XP Chenc4dc5d32021-07-27 11:33:13 -050073 if [ $? -ne 0 ]; then
74 echo "BMC CPLD update failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -050075 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -050076 fi
Lancelot Kao4357d532021-02-22 15:20:35 -060077 wait
78 set_gpio_ctrl 218 out 1
XP Chen0fb270a2021-08-26 17:30:19 -050079
80 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -060081}
82
83function fwmbcpld() {
84 # BMC_JTAG_MUX_1 #218 0:BMC 1:MB
85 # BMC_JTAG_SEL #164 0:BMC 1:CPU
86 set_gpio_ctrl 218 out 1
87 set_gpio_ctrl 164 out 1
88 loadsvf -d /dev/jtag0 -s $1 -m 0
XP Chenc4dc5d32021-07-27 11:33:13 -050089 if [ $? -ne 0 ]; then
90 echo "Mobo CPLD update failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -050091 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -050092 fi
Lancelot Kao4357d532021-02-22 15:20:35 -060093 wait
XP Chen0fb270a2021-08-26 17:30:19 -050094
95 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -060096}
97
98function fwscp() {
99 # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main
100 # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU
XP Chen0fb270a2021-08-26 17:30:19 -0500101 scp_eeprom_sel=`get_gpio_ctrl 168`
Lancelot Kao4357d532021-02-22 15:20:35 -0600102 set_gpio_ctrl 168 out 1
103 set_gpio_ctrl 85 out 0
104 I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-)
105 ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1
XP Chenc4dc5d32021-07-27 11:33:13 -0500106 if [ $? -ne 0 ]; then
107 echo "SCP eeprom update failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -0500108 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -0500109 fi
Lancelot Kao4357d532021-02-22 15:20:35 -0600110 wait
111 set_gpio_ctrl 85 out 1
XP Chen0fb270a2021-08-26 17:30:19 -0500112 set_gpio_ctrl 168 out $scp_eeprom_sel
113
114 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -0600115}
116
117function fwscpback() {
118 # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main
119 # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU
XP Chen0fb270a2021-08-26 17:30:19 -0500120 scp_eeprom_sel=`get_gpio_ctrl 168`
Lancelot Kao4357d532021-02-22 15:20:35 -0600121 set_gpio_ctrl 168 out 0
122 set_gpio_ctrl 85 out 0
123 I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-)
124 ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1
XP Chenc4dc5d32021-07-27 11:33:13 -0500125 if [ $? -ne 0 ]; then
126 echo "SCP BACKUP eeprom update failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -0500127 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -0500128 fi
Lancelot Kao4357d532021-02-22 15:20:35 -0600129 wait
130 set_gpio_ctrl 85 out 1
XP Chen0fb270a2021-08-26 17:30:19 -0500131 set_gpio_ctrl 168 out $scp_eeprom_sel
132
133 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -0600134}
135
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500136function fwmb_pwr_seq(){
137 #$1 0x40 seq config file
138 #$2 0x41 seq config file
139 if [[ ! -e $1 ]]; then
140 echo "$1 file does not exist"
XP Chen0fb270a2021-08-26 17:30:19 -0500141 return 1
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500142 fi
143 if [[ ! -e $2 ]]; then
144 echo "$2 file does not exist"
XP Chen0fb270a2021-08-26 17:30:19 -0500145 return 1
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500146 fi
147 echo 32-0040 > /sys/bus/i2c/drivers/adm1266/unbind
148 echo 32-0041 > /sys/bus/i2c/drivers/adm1266/unbind
149 adm1266_fw_fx $1 $2
150 if [ $? -ne 0 ]; then
151 echo "The power seq flash failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -0500152 return 1
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500153 fi
154 echo 32-0040 > /sys/bus/i2c/drivers/adm1266/bind
155 echo 32-0041 > /sys/bus/i2c/drivers/adm1266/bind
XP Chen0fb270a2021-08-26 17:30:19 -0500156
157 return 0
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500158}
Lancelot Kao4357d532021-02-22 15:20:35 -0600159
XP Chenc4dc5d32021-07-27 11:33:13 -0500160if [[ ! $(which flashcp) ]]; then
161 echo "flashcp utility not installed"
162 exit 1
163fi
164if [[ ! $(which ampere_eeprom_prog) ]]; then
165 echo "ampere_eeprom_prog utility not installed"
166 exit 1
167fi
168if [[ ! $(which loadsvf) ]]; then
169 echo "loadsvf utility not installed"
170 exit 1
171fi
172if [[ ! -e /dev/jtag0 ]]; then
173 echo "Jtag device driver not functional"
174 exit 1
175fi
176
Lancelot Kao4357d532021-02-22 15:20:35 -0600177case $1 in
178 bios)
179 fwbios $2
180 ;;
181 bmccpld)
182 fwbmccpld $2
183 ;;
184 mbcpld)
185 fwmbcpld $2
186 ;;
187 scp)
188 fwscp $2
189 ;;
190 scpback)
191 fwscpback $2
192 ;;
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500193 mbseq)
194 fwmb_pwr_seq $2 $3
195 ;;
Lancelot Kao4357d532021-02-22 15:20:35 -0600196 *)
197 ;;
198esac
XP Chen0fb270a2021-08-26 17:30:19 -0500199ret=$?
200
201rm -f $2 $3
202
203exit $ret