blob: 1ef73cc13e89cbfd509dd8086fba1acc2a8bf85a [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
44 rm -f $1
45}
46
Lancelot Kao4357d532021-02-22 15:20:35 -060047function fwbmccpld() {
48 # BMC_JTAG_MUX_1 #218 0:BMC 1:MB
49 set_gpio_ctrl 218 out 0
50 loadsvf -d /dev/jtag0 -s $1 -m 0
51 wait
52 set_gpio_ctrl 218 out 1
53 rm -f $1
54}
55
56function fwmbcpld() {
57 # BMC_JTAG_MUX_1 #218 0:BMC 1:MB
58 # BMC_JTAG_SEL #164 0:BMC 1:CPU
59 set_gpio_ctrl 218 out 1
60 set_gpio_ctrl 164 out 1
61 loadsvf -d /dev/jtag0 -s $1 -m 0
62 wait
63 rm -f $1
64}
65
66function fwscp() {
67 # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main
68 # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU
69 set_gpio_ctrl 168 out 1
70 set_gpio_ctrl 85 out 0
71 I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-)
72 ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1
73 wait
74 set_gpio_ctrl 85 out 1
75 set_gpio_ctrl 168 out 1
76 rm -f $1
77}
78
79function fwscpback() {
80 # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main
81 # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU
82 set_gpio_ctrl 168 out 0
83 set_gpio_ctrl 85 out 0
84 I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-)
85 ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1
86 wait
87 set_gpio_ctrl 85 out 1
88 set_gpio_ctrl 168 out 1
89 rm -f $1
90}
91
92
93case $1 in
94 bios)
95 fwbios $2
96 ;;
97 bmccpld)
98 fwbmccpld $2
99 ;;
100 mbcpld)
101 fwmbcpld $2
102 ;;
103 scp)
104 fwscp $2
105 ;;
106 scpback)
107 fwscpback $2
108 ;;
109 *)
110 ;;
111esac