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 | |
Charles Boyer | 2adad36 | 2021-11-24 15:58:03 -0600 | [diff] [blame] | 5 | source /usr/libexec/kudo-fw/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 |
Charles Boyer | 1c51ca5 | 2021-08-24 11:25:03 -0500 | [diff] [blame] | 45 | |
XP Chen | 78dbf47 | 2021-08-31 00:01:17 -0500 | [diff] [blame] | 46 | # Disable LPI mode NV_SI_CPU_LPI_FREQ_DISABLE for SCP 1.07 and newer |
Charles Boyer | c600134 | 2021-11-08 15:58:21 -0600 | [diff] [blame] | 47 | nvparm -s 0x1 -o 0x02A8 |
Charles Boyer | 1c51ca5 | 2021-08-24 11:25:03 -0500 | [diff] [blame] | 48 | |
| 49 | # Disable toggling of SMPro heartbeat |
| 50 | nvparm -s 0x0 -o 0x5F0638 |
| 51 | |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 52 | if [ $? -ne 0 ]; then |
| 53 | echo "Setting default nvparms failed " >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 54 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 55 | fi |
| 56 | |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 57 | 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 Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 60 | # Update both primary and backup EEPROM |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 61 | fwscp /run/initramfs/myscp.img |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 62 | fwscpback /run/initramfs/myscp.img |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 63 | fi |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 64 | |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 65 | |
| 66 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 67 | } |
| 68 | |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 69 | function 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 Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 73 | if [ $? -ne 0 ]; then |
| 74 | echo "BMC CPLD update failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 75 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 76 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 77 | wait |
| 78 | set_gpio_ctrl 218 out 1 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 79 | |
| 80 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | function 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 Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 89 | if [ $? -ne 0 ]; then |
| 90 | echo "Mobo CPLD update failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 91 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 92 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 93 | wait |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 94 | |
| 95 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | function fwscp() { |
| 99 | # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main |
| 100 | # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 101 | scp_eeprom_sel=`get_gpio_ctrl 168` |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 102 | 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 Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 106 | if [ $? -ne 0 ]; then |
| 107 | echo "SCP eeprom update failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 108 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 109 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 110 | wait |
| 111 | set_gpio_ctrl 85 out 1 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 112 | set_gpio_ctrl 168 out $scp_eeprom_sel |
| 113 | |
| 114 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | function fwscpback() { |
| 118 | # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main |
| 119 | # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 120 | scp_eeprom_sel=`get_gpio_ctrl 168` |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 121 | 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 Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 125 | if [ $? -ne 0 ]; then |
| 126 | echo "SCP BACKUP eeprom update failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 127 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 128 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 129 | wait |
| 130 | set_gpio_ctrl 85 out 1 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 131 | set_gpio_ctrl 168 out $scp_eeprom_sel |
| 132 | |
| 133 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 134 | } |
| 135 | |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 136 | function 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 Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 141 | return 1 |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 142 | fi |
| 143 | if [[ ! -e $2 ]]; then |
| 144 | echo "$2 file does not exist" |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 145 | return 1 |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 146 | 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 Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 152 | return 1 |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 153 | fi |
| 154 | echo 32-0040 > /sys/bus/i2c/drivers/adm1266/bind |
| 155 | echo 32-0041 > /sys/bus/i2c/drivers/adm1266/bind |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 156 | |
| 157 | return 0 |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 158 | } |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 159 | |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 160 | if [[ ! $(which flashcp) ]]; then |
| 161 | echo "flashcp utility not installed" |
| 162 | exit 1 |
| 163 | fi |
| 164 | if [[ ! $(which ampere_eeprom_prog) ]]; then |
| 165 | echo "ampere_eeprom_prog utility not installed" |
| 166 | exit 1 |
| 167 | fi |
| 168 | if [[ ! $(which loadsvf) ]]; then |
| 169 | echo "loadsvf utility not installed" |
| 170 | exit 1 |
| 171 | fi |
| 172 | if [[ ! -e /dev/jtag0 ]]; then |
| 173 | echo "Jtag device driver not functional" |
| 174 | exit 1 |
| 175 | fi |
| 176 | |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 177 | case $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 Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 193 | mbseq) |
| 194 | fwmb_pwr_seq $2 $3 |
| 195 | ;; |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 196 | *) |
| 197 | ;; |
| 198 | esac |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 199 | ret=$? |
| 200 | |
| 201 | rm -f $2 $3 |
| 202 | |
| 203 | exit $ret |