blob: 560716c234d1bf81b156c98015f81b54bb5ac51a [file] [log] [blame]
Lancelot Kao4357d532021-02-22 15:20:35 -06001#!/bin/bash
2
3devpath="/sys/bus/i2c/devices/13-0077/driver"
4
Lancelot Kao96a7ee32021-02-22 18:50:48 -06005source /usr/sbin/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
XP Chen78dbf472021-08-31 00:01:17 -050045 # Disable LPI mode NV_SI_CPU_LPI_FREQ_DISABLE for SCP 1.07 and newer
46 nvparm -s 0x1 -o 0x5F0638
XP Chenc4dc5d32021-07-27 11:33:13 -050047 # TODO: Disabled toggling of SMPro heartbeat (require CPLD v 1.12.0.0+)
48 # nvparm -s 0x1 -o 0x5F0638
49 if [ $? -ne 0 ]; then
50 echo "Setting default nvparms failed " >&2
XP Chen0fb270a2021-08-26 17:30:19 -050051 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -050052 fi
53
Lancelot Kao4357d532021-02-22 15:20:35 -060054 if [[ $(find ${1} -type f -size +17156k 2>/dev/null) ]]; then
55 echo "Extracting the SCP from the image"
56 dd if=$1 bs=1024 skip=17156 count=256 of=/run/initramfs/myscp.img
XP Chen0fb270a2021-08-26 17:30:19 -050057 # Update both primary and backup EEPROM
Lancelot Kao4357d532021-02-22 15:20:35 -060058 fwscp /run/initramfs/myscp.img
XP Chen0fb270a2021-08-26 17:30:19 -050059 fwscpback /run/initramfs/myscp.img
Lancelot Kao4357d532021-02-22 15:20:35 -060060 fi
XP Chenc4dc5d32021-07-27 11:33:13 -050061
XP Chen0fb270a2021-08-26 17:30:19 -050062
63 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -060064}
65
Lancelot Kao4357d532021-02-22 15:20:35 -060066function fwbmccpld() {
67 # BMC_JTAG_MUX_1 #218 0:BMC 1:MB
68 set_gpio_ctrl 218 out 0
69 loadsvf -d /dev/jtag0 -s $1 -m 0
XP Chenc4dc5d32021-07-27 11:33:13 -050070 if [ $? -ne 0 ]; then
71 echo "BMC CPLD update failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -050072 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -050073 fi
Lancelot Kao4357d532021-02-22 15:20:35 -060074 wait
75 set_gpio_ctrl 218 out 1
XP Chen0fb270a2021-08-26 17:30:19 -050076
77 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -060078}
79
80function fwmbcpld() {
81 # BMC_JTAG_MUX_1 #218 0:BMC 1:MB
82 # BMC_JTAG_SEL #164 0:BMC 1:CPU
83 set_gpio_ctrl 218 out 1
84 set_gpio_ctrl 164 out 1
85 loadsvf -d /dev/jtag0 -s $1 -m 0
XP Chenc4dc5d32021-07-27 11:33:13 -050086 if [ $? -ne 0 ]; then
87 echo "Mobo CPLD update failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -050088 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -050089 fi
Lancelot Kao4357d532021-02-22 15:20:35 -060090 wait
XP Chen0fb270a2021-08-26 17:30:19 -050091
92 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -060093}
94
95function fwscp() {
96 # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main
97 # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU
XP Chen0fb270a2021-08-26 17:30:19 -050098 scp_eeprom_sel=`get_gpio_ctrl 168`
Lancelot Kao4357d532021-02-22 15:20:35 -060099 set_gpio_ctrl 168 out 1
100 set_gpio_ctrl 85 out 0
101 I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-)
102 ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1
XP Chenc4dc5d32021-07-27 11:33:13 -0500103 if [ $? -ne 0 ]; then
104 echo "SCP eeprom update failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -0500105 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -0500106 fi
Lancelot Kao4357d532021-02-22 15:20:35 -0600107 wait
108 set_gpio_ctrl 85 out 1
XP Chen0fb270a2021-08-26 17:30:19 -0500109 set_gpio_ctrl 168 out $scp_eeprom_sel
110
111 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -0600112}
113
114function fwscpback() {
115 # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main
116 # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU
XP Chen0fb270a2021-08-26 17:30:19 -0500117 scp_eeprom_sel=`get_gpio_ctrl 168`
Lancelot Kao4357d532021-02-22 15:20:35 -0600118 set_gpio_ctrl 168 out 0
119 set_gpio_ctrl 85 out 0
120 I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-)
121 ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1
XP Chenc4dc5d32021-07-27 11:33:13 -0500122 if [ $? -ne 0 ]; then
123 echo "SCP BACKUP eeprom update failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -0500124 return 1
XP Chenc4dc5d32021-07-27 11:33:13 -0500125 fi
Lancelot Kao4357d532021-02-22 15:20:35 -0600126 wait
127 set_gpio_ctrl 85 out 1
XP Chen0fb270a2021-08-26 17:30:19 -0500128 set_gpio_ctrl 168 out $scp_eeprom_sel
129
130 return 0
Lancelot Kao4357d532021-02-22 15:20:35 -0600131}
132
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500133function fwmb_pwr_seq(){
134 #$1 0x40 seq config file
135 #$2 0x41 seq config file
136 if [[ ! -e $1 ]]; then
137 echo "$1 file does not exist"
XP Chen0fb270a2021-08-26 17:30:19 -0500138 return 1
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500139 fi
140 if [[ ! -e $2 ]]; then
141 echo "$2 file does not exist"
XP Chen0fb270a2021-08-26 17:30:19 -0500142 return 1
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500143 fi
144 echo 32-0040 > /sys/bus/i2c/drivers/adm1266/unbind
145 echo 32-0041 > /sys/bus/i2c/drivers/adm1266/unbind
146 adm1266_fw_fx $1 $2
147 if [ $? -ne 0 ]; then
148 echo "The power seq flash failed" >&2
XP Chen0fb270a2021-08-26 17:30:19 -0500149 return 1
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500150 fi
151 echo 32-0040 > /sys/bus/i2c/drivers/adm1266/bind
152 echo 32-0041 > /sys/bus/i2c/drivers/adm1266/bind
XP Chen0fb270a2021-08-26 17:30:19 -0500153
154 return 0
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500155}
Lancelot Kao4357d532021-02-22 15:20:35 -0600156
XP Chenc4dc5d32021-07-27 11:33:13 -0500157if [[ ! $(which flashcp) ]]; then
158 echo "flashcp utility not installed"
159 exit 1
160fi
161if [[ ! $(which ampere_eeprom_prog) ]]; then
162 echo "ampere_eeprom_prog utility not installed"
163 exit 1
164fi
165if [[ ! $(which loadsvf) ]]; then
166 echo "loadsvf utility not installed"
167 exit 1
168fi
169if [[ ! -e /dev/jtag0 ]]; then
170 echo "Jtag device driver not functional"
171 exit 1
172fi
173
Lancelot Kao4357d532021-02-22 15:20:35 -0600174case $1 in
175 bios)
176 fwbios $2
177 ;;
178 bmccpld)
179 fwbmccpld $2
180 ;;
181 mbcpld)
182 fwmbcpld $2
183 ;;
184 scp)
185 fwscp $2
186 ;;
187 scpback)
188 fwscpback $2
189 ;;
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500190 mbseq)
191 fwmb_pwr_seq $2 $3
192 ;;
Lancelot Kao4357d532021-02-22 15:20:35 -0600193 *)
194 ;;
195esac
XP Chen0fb270a2021-08-26 17:30:19 -0500196ret=$?
197
198rm -f $2 $3
199
200exit $ret