blob: d103747b23d29a3328f6a66a31631a7a2da419f7 [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
94
95case $1 in
96 bios)
97 fwbios $2
98 ;;
99 bmccpld)
100 fwbmccpld $2
101 ;;
102 mbcpld)
103 fwmbcpld $2
104 ;;
105 scp)
106 fwscp $2
107 ;;
108 scpback)
109 fwscpback $2
110 ;;
111 *)
112 ;;
113esac