Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 3 | # Provide source directive to shellcheck. |
| 4 | # shellcheck source=meta-fii/meta-kudo/recipes-kudo/kudo-fw-utility/kudo-fw/kudo-lib.sh |
| 5 | # Disable check for globbing and word splitting within double quotes |
| 6 | # shellcheck disable=SC2086 |
Charles Boyer | 2adad36 | 2021-11-24 15:58:03 -0600 | [diff] [blame] | 7 | source /usr/libexec/kudo-fw/kudo-lib.sh |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 8 | |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 9 | devpath="/sys/bus/i2c/devices/13-0077/driver" |
| 10 | |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 11 | function fwbios() { |
| 12 | KERNEL_FIU_ID="c0000000.spi" |
| 13 | KERNEL_SYSFS_FIU="/sys/bus/platform/drivers/NPCM-FIU" |
| 14 | |
| 15 | # switch the SPI mux from Host to BMC |
| 16 | i2cset -y -f -a 13 0x76 0x10 0x01 |
| 17 | |
| 18 | # rescan the spi bus |
| 19 | if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then |
| 20 | echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind |
| 21 | sleep 1 |
| 22 | fi |
| 23 | echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/bind |
| 24 | |
| 25 | # write to the mtd device |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 26 | BIOS_MTD=$(grep "bios" /proc/mtd | sed -n 's/^\(.*\):.*/\1/p') |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 27 | |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 28 | if [ ! -f "$1" ]; then |
| 29 | echo " Cannot find the" "$1" "image file" |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 30 | return 1 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 31 | |
Lancelot Kao | 96a7ee3 | 2021-02-22 18:50:48 -0600 | [diff] [blame] | 32 | fi |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 33 | echo "Flashing BIOS @/dev/${BIOS_MTD}" |
| 34 | if [ "$(flashcp -v $1 /dev/${BIOS_MTD})" -ne 0 ]; then |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 35 | echo "Flashing the bios failed " >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 36 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 37 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 38 | wait |
| 39 | |
| 40 | # switch the SPI mux from BMC to Host |
| 41 | if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then |
| 42 | echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind |
| 43 | fi |
| 44 | i2cset -y -f -a 13 0x76 0x10 0x00 |
| 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.06 and older. |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 47 | if [ "$(nvparm -s 0x1 -o 0x114090)" -ne 0 ]; then |
| 48 | echo "Setting LPI mode for SCP 1.06 and older failed " >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 49 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 50 | fi |
| 51 | |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 52 | # Disable LPI mode NV_SI_CPU_LPI_FREQ_DISABLE for SCP 1.07 and newer |
| 53 | if [ "$(nvparm -s 0x1 -o 0x02A8)" -ne 0 ]; then |
| 54 | echo "Setting LPI mode for SCP 1.07 and newer failed " >&2 |
| 55 | return 1 |
| 56 | fi |
| 57 | |
| 58 | # Disable toggling of SMPro heartbeat |
| 59 | if [ "$(nvparm -s 0x0 -o 0x5F0638)" -ne 0 ]; then |
| 60 | echo "Setting SMpro heartbeat failed " >&2 |
| 61 | return 1 |
| 62 | fi |
| 63 | |
| 64 | if [[ $(find "$1" -type f -size +17156k 2>/dev/null) ]]; then |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 65 | echo "Extracting the SCP from the image" |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 66 | 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] | 67 | # Update both primary and backup EEPROM |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 68 | fwscp /run/initramfs/myscp.img |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 69 | fwscpback /run/initramfs/myscp.img |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 70 | fi |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 71 | |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 72 | |
| 73 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 74 | } |
| 75 | |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 76 | function fwbmccpld() { |
| 77 | # BMC_JTAG_MUX_1 #218 0:BMC 1:MB |
| 78 | set_gpio_ctrl 218 out 0 |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 79 | if [ "$(loadsvf -d /dev/jtag0 -s $1 -m 0)" -ne 0 ]; then |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 80 | echo "BMC CPLD update failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 81 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 82 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 83 | wait |
| 84 | set_gpio_ctrl 218 out 1 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 85 | |
| 86 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | function fwmbcpld() { |
| 90 | # BMC_JTAG_MUX_1 #218 0:BMC 1:MB |
| 91 | # BMC_JTAG_SEL #164 0:BMC 1:CPU |
| 92 | set_gpio_ctrl 218 out 1 |
| 93 | set_gpio_ctrl 164 out 1 |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 94 | if [ "$(loadsvf -d /dev/jtag0 -s $1 -m 0)" -ne 0 ]; then |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 95 | echo "Mobo CPLD update failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 96 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 97 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 98 | wait |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 99 | |
| 100 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | function fwscp() { |
| 104 | # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main |
| 105 | # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 106 | scp_eeprom_sel=$(get_gpio_ctrl 168) |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 107 | set_gpio_ctrl 168 out 1 |
| 108 | set_gpio_ctrl 85 out 0 |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 109 | #shellcheck disable=SC2010 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 110 | I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-) |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 111 | if [ "$(ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1)" -ne 0 ]; then |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 112 | echo "SCP eeprom update failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 113 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 114 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 115 | wait |
| 116 | set_gpio_ctrl 85 out 1 |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 117 | set_gpio_ctrl 168 out "$scp_eeprom_sel" |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 118 | |
| 119 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | function fwscpback() { |
| 123 | # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main |
| 124 | # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 125 | scp_eeprom_sel=$(get_gpio_ctrl 168) |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 126 | set_gpio_ctrl 168 out 0 |
| 127 | set_gpio_ctrl 85 out 0 |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 128 | #shellcheck disable=SC2010 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 129 | I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-) |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 130 | if [ "$(ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1)" -ne 0 ]; then |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 131 | echo "SCP BACKUP eeprom update failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 132 | return 1 |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 133 | fi |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 134 | wait |
| 135 | set_gpio_ctrl 85 out 1 |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 136 | set_gpio_ctrl 168 out "$scp_eeprom_sel" |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 137 | |
| 138 | return 0 |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 139 | } |
| 140 | |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 141 | function fwmb_pwr_seq(){ |
| 142 | #$1 0x40 seq config file |
| 143 | #$2 0x41 seq config file |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 144 | if [[ ! -e "$1" ]]; then |
| 145 | echo "The file $1 does not exist" |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 146 | return 1 |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 147 | fi |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 148 | if [[ ! -e "$2" ]]; then |
| 149 | echo "The file $2 file does not exist" |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 150 | return 1 |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 151 | fi |
| 152 | echo 32-0040 > /sys/bus/i2c/drivers/adm1266/unbind |
| 153 | echo 32-0041 > /sys/bus/i2c/drivers/adm1266/unbind |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 154 | if [ "$(adm1266_fw_fx $1 $2)" -ne 0 ]; then |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 155 | echo "The power seq flash failed" >&2 |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 156 | return 1 |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 157 | fi |
| 158 | echo 32-0040 > /sys/bus/i2c/drivers/adm1266/bind |
| 159 | echo 32-0041 > /sys/bus/i2c/drivers/adm1266/bind |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 160 | |
| 161 | return 0 |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 162 | } |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 163 | |
XP Chen | c4dc5d3 | 2021-07-27 11:33:13 -0500 | [diff] [blame] | 164 | if [[ ! $(which flashcp) ]]; then |
| 165 | echo "flashcp utility not installed" |
| 166 | exit 1 |
| 167 | fi |
| 168 | if [[ ! $(which ampere_eeprom_prog) ]]; then |
| 169 | echo "ampere_eeprom_prog utility not installed" |
| 170 | exit 1 |
| 171 | fi |
| 172 | if [[ ! $(which loadsvf) ]]; then |
| 173 | echo "loadsvf utility not installed" |
| 174 | exit 1 |
| 175 | fi |
| 176 | if [[ ! -e /dev/jtag0 ]]; then |
| 177 | echo "Jtag device driver not functional" |
| 178 | exit 1 |
| 179 | fi |
| 180 | |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 181 | case $1 in |
| 182 | bios) |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 183 | fwbios "$2" |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 184 | ;; |
| 185 | bmccpld) |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 186 | fwbmccpld "$2" |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 187 | ;; |
| 188 | mbcpld) |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 189 | fwmbcpld "$2" |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 190 | ;; |
| 191 | scp) |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 192 | fwscp "$2" |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 193 | ;; |
| 194 | scpback) |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 195 | fwscpback "$2" |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 196 | ;; |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 197 | mbseq) |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 198 | fwmb_pwr_seq "$2" "$3" |
Mohaimen Alsamarai | a17ba54 | 2021-06-18 11:47:41 -0500 | [diff] [blame] | 199 | ;; |
Lancelot Kao | 4357d53 | 2021-02-22 15:20:35 -0600 | [diff] [blame] | 200 | *) |
| 201 | ;; |
| 202 | esac |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 203 | ret=$? |
| 204 | |
Charles Boyer | 0dd8006 | 2022-03-17 14:57:50 -0500 | [diff] [blame^] | 205 | rm -f "$2" "$3" |
XP Chen | 0fb270a | 2021-08-26 17:30:19 -0500 | [diff] [blame] | 206 | |
| 207 | exit $ret |