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 | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 43 | # Disable LPI mode NV_SI_CPU_LPI_FREQ_DISABLE. |
| 44 | # Moved to before SCP as fwscp function returns 0 on success |
| 45 | nvparm -s 0x1 -o 0x114090 |
| 46 | # TODO: Disabled toggling of SMPro heartbeat (require CPLD v 1.12.0.0+) |
| 47 | # nvparm -s 0x1 -o 0x5F0638 |
| 48 | if [ $? -ne 0 ]; then |
| 49 | echo "Setting default nvparms failed " >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 50 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 51 | fi |
| 52 | |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 53 | if [[ $(find ${1} -type f -size +17156k 2>/dev/null) ]]; then |
| 54 | echo "Extracting the SCP from the image" |
| 55 | 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] | 56 | # Update both primary and backup EEPROM |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 57 | fwscp /run/initramfs/myscp.img |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 58 | fwscpback /run/initramfs/myscp.img |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 59 | fi |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 60 | |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 61 | |
| 62 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 63 | } |
| 64 | |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 65 | function fwbmccpld() { |
| 66 | # BMC_JTAG_MUX_1 #218 0:BMC 1:MB |
| 67 | set_gpio_ctrl 218 out 0 |
| 68 | loadsvf -d /dev/jtag0 -s $1 -m 0 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 69 | if [ $? -ne 0 ]; then |
| 70 | echo "BMC CPLD update failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 71 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 72 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 73 | wait |
| 74 | set_gpio_ctrl 218 out 1 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 75 | |
| 76 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | function fwmbcpld() { |
| 80 | # BMC_JTAG_MUX_1 #218 0:BMC 1:MB |
| 81 | # BMC_JTAG_SEL #164 0:BMC 1:CPU |
| 82 | set_gpio_ctrl 218 out 1 |
| 83 | set_gpio_ctrl 164 out 1 |
| 84 | loadsvf -d /dev/jtag0 -s $1 -m 0 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 85 | if [ $? -ne 0 ]; then |
| 86 | echo "Mobo CPLD update failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 87 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 88 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 89 | wait |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 90 | |
| 91 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | function fwscp() { |
| 95 | # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main |
| 96 | # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 97 | scp_eeprom_sel=`get_gpio_ctrl 168` |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 98 | set_gpio_ctrl 168 out 1 |
| 99 | set_gpio_ctrl 85 out 0 |
| 100 | I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-) |
| 101 | ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 102 | if [ $? -ne 0 ]; then |
| 103 | echo "SCP eeprom update failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 104 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 105 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 106 | wait |
| 107 | set_gpio_ctrl 85 out 1 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 108 | set_gpio_ctrl 168 out $scp_eeprom_sel |
| 109 | |
| 110 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | function fwscpback() { |
| 114 | # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main |
| 115 | # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 116 | scp_eeprom_sel=`get_gpio_ctrl 168` |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 117 | set_gpio_ctrl 168 out 0 |
| 118 | set_gpio_ctrl 85 out 0 |
| 119 | I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-) |
| 120 | ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 121 | if [ $? -ne 0 ]; then |
| 122 | echo "SCP BACKUP eeprom update failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 123 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 124 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 125 | wait |
| 126 | set_gpio_ctrl 85 out 1 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 127 | set_gpio_ctrl 168 out $scp_eeprom_sel |
| 128 | |
| 129 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 130 | } |
| 131 | |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 132 | function fwmb_pwr_seq(){ |
| 133 | #$1 0x40 seq config file |
| 134 | #$2 0x41 seq config file |
| 135 | if [[ ! -e $1 ]]; then |
| 136 | echo "$1 file does not exist" |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 137 | return 1 |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 138 | fi |
| 139 | if [[ ! -e $2 ]]; then |
| 140 | echo "$2 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 | echo 32-0040 > /sys/bus/i2c/drivers/adm1266/unbind |
| 144 | echo 32-0041 > /sys/bus/i2c/drivers/adm1266/unbind |
| 145 | adm1266_fw_fx $1 $2 |
| 146 | if [ $? -ne 0 ]; then |
| 147 | echo "The power seq flash failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 148 | return 1 |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 149 | fi |
| 150 | echo 32-0040 > /sys/bus/i2c/drivers/adm1266/bind |
| 151 | echo 32-0041 > /sys/bus/i2c/drivers/adm1266/bind |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 152 | |
| 153 | return 0 |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 154 | } |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 155 | |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 156 | if [[ ! $(which flashcp) ]]; then |
| 157 | echo "flashcp utility not installed" |
| 158 | exit 1 |
| 159 | fi |
| 160 | if [[ ! $(which ampere_eeprom_prog) ]]; then |
| 161 | echo "ampere_eeprom_prog utility not installed" |
| 162 | exit 1 |
| 163 | fi |
| 164 | if [[ ! $(which loadsvf) ]]; then |
| 165 | echo "loadsvf utility not installed" |
| 166 | exit 1 |
| 167 | fi |
| 168 | if [[ ! -e /dev/jtag0 ]]; then |
| 169 | echo "Jtag device driver not functional" |
| 170 | exit 1 |
| 171 | fi |
| 172 | |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 173 | case $1 in |
| 174 | bios) |
| 175 | fwbios $2 |
| 176 | ;; |
| 177 | bmccpld) |
| 178 | fwbmccpld $2 |
| 179 | ;; |
| 180 | mbcpld) |
| 181 | fwmbcpld $2 |
| 182 | ;; |
| 183 | scp) |
| 184 | fwscp $2 |
| 185 | ;; |
| 186 | scpback) |
| 187 | fwscpback $2 |
| 188 | ;; |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 189 | mbseq) |
| 190 | fwmb_pwr_seq $2 $3 |
| 191 | ;; |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 192 | *) |
| 193 | ;; |
| 194 | esac |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 195 | ret=$? |
| 196 | |
| 197 | rm -f $2 $3 |
| 198 | |
| 199 | exit $ret |