Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | devpath="/sys/bus/i2c/devices/13-0077/driver" |
| 4 | |
Lancelot Kao | 96a7ee3 | 2021-02-22 18:50:48 -0600 | [diff] [blame] | 5 | source /usr/sbin/kudo-lib.sh |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 6 | |
| 7 | function 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 Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 26 | return 1 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 27 | |
Lancelot Kao | 96a7ee3 | 2021-02-22 18:50:48 -0600 | [diff] [blame] | 28 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 29 | echo "Flashing BIOS @/dev/$BIOS_MTD" |
| 30 | flashcp -v $1 /dev/$BIOS_MTD |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 31 | if [ $? -ne 0 ]; then |
| 32 | echo "Flashing the bios failed " >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 33 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 34 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 35 | 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 Chen | 78dbf47 | 2021-08-31 00:01:17 -0500 | [diff] [blame^] | 43 | # Disable LPI mode NV_SI_CPU_LPI_FREQ_DISABLE for SCP 1.06 and older. |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 44 | nvparm -s 0x1 -o 0x114090 |
XP Chen | 78dbf47 | 2021-08-31 00:01:17 -0500 | [diff] [blame^] | 45 | # Disable LPI mode NV_SI_CPU_LPI_FREQ_DISABLE for SCP 1.07 and newer |
| 46 | nvparm -s 0x1 -o 0x5F0638 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 47 | # 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 Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 51 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 52 | fi |
| 53 | |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 54 | 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 Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 57 | # Update both primary and backup EEPROM |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 58 | fwscp /run/initramfs/myscp.img |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 59 | fwscpback /run/initramfs/myscp.img |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 60 | fi |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 61 | |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 62 | |
| 63 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 64 | } |
| 65 | |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 66 | function 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 Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 70 | if [ $? -ne 0 ]; then |
| 71 | echo "BMC CPLD update failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 72 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 73 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 74 | wait |
| 75 | set_gpio_ctrl 218 out 1 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 76 | |
| 77 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | function 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 Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 86 | if [ $? -ne 0 ]; then |
| 87 | echo "Mobo CPLD update failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 88 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 89 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 90 | wait |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 91 | |
| 92 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | function fwscp() { |
| 96 | # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main |
| 97 | # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 98 | scp_eeprom_sel=`get_gpio_ctrl 168` |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 99 | 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 Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 103 | if [ $? -ne 0 ]; then |
| 104 | echo "SCP eeprom update failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 105 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 106 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 107 | wait |
| 108 | set_gpio_ctrl 85 out 1 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 109 | set_gpio_ctrl 168 out $scp_eeprom_sel |
| 110 | |
| 111 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | function fwscpback() { |
| 115 | # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main |
| 116 | # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 117 | scp_eeprom_sel=`get_gpio_ctrl 168` |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 118 | 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 Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 122 | if [ $? -ne 0 ]; then |
| 123 | echo "SCP BACKUP eeprom update failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 124 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 125 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 126 | wait |
| 127 | set_gpio_ctrl 85 out 1 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 128 | set_gpio_ctrl 168 out $scp_eeprom_sel |
| 129 | |
| 130 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 131 | } |
| 132 | |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 133 | function 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 Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 138 | return 1 |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 139 | fi |
| 140 | if [[ ! -e $2 ]]; then |
| 141 | echo "$2 file does not exist" |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 142 | return 1 |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 143 | 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 Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 149 | return 1 |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 150 | fi |
| 151 | echo 32-0040 > /sys/bus/i2c/drivers/adm1266/bind |
| 152 | echo 32-0041 > /sys/bus/i2c/drivers/adm1266/bind |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 153 | |
| 154 | return 0 |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 155 | } |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 156 | |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 157 | if [[ ! $(which flashcp) ]]; then |
| 158 | echo "flashcp utility not installed" |
| 159 | exit 1 |
| 160 | fi |
| 161 | if [[ ! $(which ampere_eeprom_prog) ]]; then |
| 162 | echo "ampere_eeprom_prog utility not installed" |
| 163 | exit 1 |
| 164 | fi |
| 165 | if [[ ! $(which loadsvf) ]]; then |
| 166 | echo "loadsvf utility not installed" |
| 167 | exit 1 |
| 168 | fi |
| 169 | if [[ ! -e /dev/jtag0 ]]; then |
| 170 | echo "Jtag device driver not functional" |
| 171 | exit 1 |
| 172 | fi |
| 173 | |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 174 | case $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 Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 190 | mbseq) |
| 191 | fwmb_pwr_seq $2 $3 |
| 192 | ;; |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 193 | *) |
| 194 | ;; |
| 195 | esac |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 196 | ret=$? |
| 197 | |
| 198 | rm -f $2 $3 |
| 199 | |
| 200 | exit $ret |