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