blob: e42795f0c468dabcd858bf86eea0314538629f71 [file] [log] [blame]
Lancelot Kao4357d532021-02-22 15:20:35 -06001#!/bin/bash
2
3devpath="/sys/bus/i2c/devices/13-0077/driver"
4
5# set_gpio_ctrl
6# pin #, direction, high(1)/low(0)
7function set_gpio_ctrl() {
8 echo $1 > /sys/class/gpio/export
9 echo $2 > /sys/class//gpio/gpio$1/direction
10 echo $3 > /sys/class/gpio/gpio$1/value
11 echo $1 > /sys/class/gpio/unexport
12 sleep 1
13}
14
15function fwbios() {
16 KERNEL_FIU_ID="c0000000.spi"
17 KERNEL_SYSFS_FIU="/sys/bus/platform/drivers/NPCM-FIU"
18
19 # switch the SPI mux from Host to BMC
20 i2cset -y -f -a 13 0x76 0x10 0x01
21
22 # rescan the spi bus
23 if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then
24 echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind
25 sleep 1
26 fi
27 echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/bind
28
29 # write to the mtd device
30 BIOS_MTD=$(cat /proc/mtd | grep "bios" | sed -n 's/^\(.*\):.*/\1/p')
31
32 if [ ! -f $1 ]; then
33 echo " Cannot find the" $1 "image file"
34 exit 1
35 fi
36
37 echo "Flashing BIOS @/dev/$BIOS_MTD"
38 flashcp -v $1 /dev/$BIOS_MTD
39 wait
40
41 # switch the SPI mux from BMC to Host
42 if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then
43 echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind
44 fi
45 i2cset -y -f -a 13 0x76 0x10 0x00
46
47 if [[ $(find ${1} -type f -size +17156k 2>/dev/null) ]]; then
48 echo "Extracting the SCP from the image"
49 dd if=$1 bs=1024 skip=17156 count=256 of=/run/initramfs/myscp.img
50 fwscp /run/initramfs/myscp.img
51 fi
52 rm -f $1
53}
54
55
56function fwbmccpld() {
57 # BMC_JTAG_MUX_1 #218 0:BMC 1:MB
58 set_gpio_ctrl 218 out 0
59 loadsvf -d /dev/jtag0 -s $1 -m 0
60 wait
61 set_gpio_ctrl 218 out 1
62 rm -f $1
63}
64
65function fwmbcpld() {
66 # BMC_JTAG_MUX_1 #218 0:BMC 1:MB
67 # BMC_JTAG_SEL #164 0:BMC 1:CPU
68 set_gpio_ctrl 218 out 1
69 set_gpio_ctrl 164 out 1
70 loadsvf -d /dev/jtag0 -s $1 -m 0
71 wait
72 rm -f $1
73}
74
75function fwscp() {
76 # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main
77 # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU
78 set_gpio_ctrl 168 out 1
79 set_gpio_ctrl 85 out 0
80 I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-)
81 ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1
82 wait
83 set_gpio_ctrl 85 out 1
84 set_gpio_ctrl 168 out 1
85 rm -f $1
86}
87
88function fwscpback() {
89 # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main
90 # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU
91 set_gpio_ctrl 168 out 0
92 set_gpio_ctrl 85 out 0
93 I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-)
94 ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1
95 wait
96 set_gpio_ctrl 85 out 1
97 set_gpio_ctrl 168 out 1
98 rm -f $1
99}
100
101
102case $1 in
103 bios)
104 fwbios $2
105 ;;
106 bmccpld)
107 fwbmccpld $2
108 ;;
109 mbcpld)
110 fwmbcpld $2
111 ;;
112 scp)
113 fwscp $2
114 ;;
115 scpback)
116 fwscpback $2
117 ;;
118 *)
119 ;;
120esac