summaryrefslogtreecommitdiff
path: root/meta-fii/meta-kudo/recipes-kudo/kudo-fw-utility/kudo-fw/kudo-fw.sh
blob: 5e0763a64b0fd4e46185e766eb6dcc8a8cda9ae4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash

devpath="/sys/bus/i2c/devices/13-0077/driver"

source /usr/sbin/kudo-lib.sh

function fwbios() {
  KERNEL_FIU_ID="c0000000.spi"
  KERNEL_SYSFS_FIU="/sys/bus/platform/drivers/NPCM-FIU"

  # switch the SPI mux from Host to BMC
  i2cset -y -f -a 13 0x76 0x10 0x01

  # rescan the spi bus
  if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then
    echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind
    sleep 1
  fi
  echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/bind

  # write to the mtd device
  BIOS_MTD=$(cat /proc/mtd | grep "bios" | sed -n 's/^\(.*\):.*/\1/p')

  if [ ! -f $1 ]; then
    echo " Cannot find the" $1 "image file"
    return 1

  fi
  echo "Flashing BIOS @/dev/$BIOS_MTD"
  flashcp -v $1 /dev/$BIOS_MTD
  if [ $? -ne  0 ]; then
    echo "Flashing the bios failed " >&2
    return 1
  fi
  wait

  # switch the SPI mux from BMC to Host
  if [ -d "${KERNEL_SYSFS_FIU}/${KERNEL_FIU_ID}" ]; then
    echo "${KERNEL_FIU_ID}" > "${KERNEL_SYSFS_FIU}"/unbind
  fi
  i2cset -y -f -a 13 0x76 0x10 0x00

  # Disable LPI mode NV_SI_CPU_LPI_FREQ_DISABLE.
  # Moved to before SCP as fwscp function returns 0 on success
  nvparm -s 0x1 -o 0x114090
  # TODO: Disabled toggling of SMPro heartbeat (require CPLD v 1.12.0.0+)
  # nvparm -s 0x1 -o 0x5F0638
  if [ $? -ne  0 ]; then
    echo "Setting default nvparms failed " >&2
    return 1
  fi

  if [[ $(find ${1} -type f -size +17156k 2>/dev/null) ]]; then
    echo "Extracting the SCP from the image"
    dd if=$1 bs=1024 skip=17156 count=256 of=/run/initramfs/myscp.img
    # Update both primary and backup EEPROM
    fwscp /run/initramfs/myscp.img
    fwscpback /run/initramfs/myscp.img
  fi


  return 0
}

function fwbmccpld() {
  # BMC_JTAG_MUX_1 #218 0:BMC 1:MB
  set_gpio_ctrl 218 out 0
  loadsvf -d /dev/jtag0 -s $1 -m 0
  if [ $? -ne  0 ]; then
    echo "BMC CPLD update failed" >&2
    return 1
  fi
  wait
  set_gpio_ctrl 218 out 1

  return 0
}

function fwmbcpld() {
  # BMC_JTAG_MUX_1 #218 0:BMC 1:MB
  # BMC_JTAG_SEL #164 0:BMC 1:CPU
  set_gpio_ctrl 218 out 1
  set_gpio_ctrl 164 out 1
  loadsvf -d /dev/jtag0 -s $1 -m 0
  if [ $? -ne  0 ]; then
    echo "Mobo CPLD update failed" >&2
    return 1
  fi
  wait

  return 0
}

function fwscp() {
  # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main
  # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU
  scp_eeprom_sel=`get_gpio_ctrl 168`
  set_gpio_ctrl 168 out 1
  set_gpio_ctrl 85 out 0
  I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-)
  ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1
  if [ $? -ne  0 ]; then
    echo "SCP eeprom update failed" >&2
    return 1
  fi
  wait
  set_gpio_ctrl 85 out 1
  set_gpio_ctrl 168 out $scp_eeprom_sel

  return 0
}

function fwscpback() {
  # BMC_I2C_BACKUP_SEL #168 0:failover, 1:main
  # BMC_CPU_EEPROM_I2C_SEL #85 0:BMC, 1:CPU
  scp_eeprom_sel=`get_gpio_ctrl 168`
  set_gpio_ctrl 168 out 0
  set_gpio_ctrl 85 out 0
  I2C_BUS_DEV=$(ls -l $devpath/"13-0077/" | grep channel-0 | awk '{ print $11}' | cut -c 8-)
  ampere_eeprom_prog -b $I2C_BUS_DEV -s 0x50 -p -f $1
  if [ $? -ne  0 ]; then
    echo "SCP BACKUP eeprom update failed" >&2
    return 1
  fi
  wait
  set_gpio_ctrl 85 out 1
  set_gpio_ctrl 168 out $scp_eeprom_sel

  return 0
}

function fwmb_pwr_seq(){
  #$1 0x40 seq config file
  #$2 0x41 seq config file
  if [[ ! -e $1 ]]; then
    echo "$1 file does not exist"
    return 1
  fi
  if [[ ! -e $2 ]]; then
    echo "$2 file does not exist"
    return 1
  fi
  echo 32-0040 > /sys/bus/i2c/drivers/adm1266/unbind
  echo 32-0041 > /sys/bus/i2c/drivers/adm1266/unbind
  adm1266_fw_fx $1 $2
  if [ $? -ne  0 ]; then
    echo "The power seq flash failed" >&2
    return 1
  fi
  echo 32-0040 > /sys/bus/i2c/drivers/adm1266/bind
  echo 32-0041 > /sys/bus/i2c/drivers/adm1266/bind

  return 0
}

if [[ ! $(which flashcp) ]]; then
    echo "flashcp utility not installed"
    exit 1
fi
if [[ ! $(which ampere_eeprom_prog) ]]; then
    echo "ampere_eeprom_prog utility not installed"
    exit 1
fi
if [[ ! $(which loadsvf) ]]; then
    echo "loadsvf utility not installed"
    exit 1
fi
if [[ ! -e /dev/jtag0 ]]; then
    echo "Jtag device driver not functional"
    exit 1
fi

case $1 in
  bios)
    fwbios $2
    ;;
  bmccpld)
    fwbmccpld $2
    ;;
  mbcpld)
    fwmbcpld $2
    ;;
  scp)
    fwscp $2
    ;;
  scpback)
    fwscpback $2
    ;;
  mbseq)
    fwmb_pwr_seq $2 $3
    ;;
  *)
    ;;
esac
ret=$?

rm -f $2 $3

exit $ret