blob: 58a2826e0b9cddd9cc6d5d4c28f32094819285dd [file] [log] [blame]
Lancelot Kao4357d532021-02-22 15:20:35 -06001#!/bin/bash
2
3devpath="/sys/bus/i2c/devices/13-0077/driver"
4
Lancelot Kao96a7ee32021-02-22 18:50:48 -06005source /usr/sbin/kudo-lib.sh
Lancelot Kao4357d532021-02-22 15:20:35 -06006
7function 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"
26 exit 1
Lancelot Kao4357d532021-02-22 15:20:35 -060027
Lancelot Kao96a7ee32021-02-22 18:50:48 -060028 fi
Lancelot Kao4357d532021-02-22 15:20:35 -060029 echo "Flashing BIOS @/dev/$BIOS_MTD"
30 flashcp -v $1 /dev/$BIOS_MTD
31 wait
32
33 # switch the SPI mux from BMC to Host
34 if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then
35 echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind
36 fi
37 i2cset -y -f -a 13 0x76 0x10 0x00
38
39 if [[ $(find ${1} -type f -size +17156k 2>/dev/null) ]]; then
40 echo "Extracting the SCP from the image"
41 dd if=$1 bs=1024 skip=17156 count=256 of=/run/initramfs/myscp.img
42 fwscp /run/initramfs/myscp.img
43 fi
XP Chen06bb2752021-06-17 16:45:18 -050044 # Disable LPI mode NV_SI_CPU_LPI_FREQ_DISABLE.
45 nvparm -s 0x1 -o 0x114090
Lancelot Kao4357d532021-02-22 15:20:35 -060046 rm -f $1
47}
48
Lancelot Kao4357d532021-02-22 15:20:35 -060049function fwbmccpld() {
50 # BMC_JTAG_MUX_1 #218 0:BMC 1:MB
51 set_gpio_ctrl 218 out 0
52 loadsvf -d /dev/jtag0 -s $1 -m 0
53 wait
54 set_gpio_ctrl 218 out 1
55 rm -f $1
56}
57
58function fwmbcpld() {
59 # BMC_JTAG_MUX_1 #218 0:BMC 1:MB
60 # BMC_JTAG_SEL #164 0:BMC 1:CPU
61 set_gpio_ctrl 218 out 1
62 set_gpio_ctrl 164 out 1
63 loadsvf -d /dev/jtag0 -s $1 -m 0
64 wait
65 rm -f $1
66}
67
68function fwscp() {
69 # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main
70 # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU
71 set_gpio_ctrl 168 out 1
72 set_gpio_ctrl 85 out 0
73 I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-)
74 ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1
75 wait
76 set_gpio_ctrl 85 out 1
77 set_gpio_ctrl 168 out 1
78 rm -f $1
79}
80
81function fwscpback() {
82 # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main
83 # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU
84 set_gpio_ctrl 168 out 0
85 set_gpio_ctrl 85 out 0
86 I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-)
87 ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1
88 wait
89 set_gpio_ctrl 85 out 1
90 set_gpio_ctrl 168 out 1
91 rm -f $1
92}
93
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -050094function fwmb_pwr_seq(){
95 #$1 0x40 seq config file
96 #$2 0x41 seq config file
97 if [[ ! -e $1 ]]; then
98 echo "$1 file does not exist"
99 exit 1
100 fi
101 if [[ ! -e $2 ]]; then
102 echo "$2 file does not exist"
103 exit 1
104 fi
105 echo 32-0040 > /sys/bus/i2c/drivers/adm1266/unbind
106 echo 32-0041 > /sys/bus/i2c/drivers/adm1266/unbind
107 adm1266_fw_fx $1 $2
108 if [ $? -ne 0 ]; then
109 echo "The power seq flash failed" >&2
110 exit 1
111 fi
112 echo 32-0040 > /sys/bus/i2c/drivers/adm1266/bind
113 echo 32-0041 > /sys/bus/i2c/drivers/adm1266/bind
114 rm -f $1
115 rm -f $2
116 exit 0
117}
Lancelot Kao4357d532021-02-22 15:20:35 -0600118
119case $1 in
120 bios)
121 fwbios $2
122 ;;
123 bmccpld)
124 fwbmccpld $2
125 ;;
126 mbcpld)
127 fwmbcpld $2
128 ;;
129 scp)
130 fwscp $2
131 ;;
132 scpback)
133 fwscpback $2
134 ;;
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -0500135 mbseq)
136 fwmb_pwr_seq $2 $3
137 ;;
Lancelot Kao4357d532021-02-22 15:20:35 -0600138 *)
139 ;;
140esac