blob: b8e782438003baea65b6c9dfe6f7cb3741962839 [file] [log] [blame]
XP Chen0e483352021-05-12 09:44:26 -05001#!/bin/bash
2# help information
3
Charles Boyer2adad362021-11-24 15:58:03 -06004source /usr/libexec/kudo-fw/kudo-lib.sh
XP Chen0e483352021-05-12 09:44:26 -05005
6function usage_rst() {
7 echo " kudo rst [parameter]"
8 echo " hotswap --> reset the whole kudo node"
9 echo " system --> reset the host"
10 echo " btn --> trigger a power button event"
11 echo " shutdown --> send out shutdown signal to CPU"
12 echo " display --> "
13}
14
15function usage_led() {
XP Chen0e483352021-05-12 09:44:26 -050016 echo " kudo led 'att'/'boot' [parameter]"
17 echo " on --> change to CPU console"
18 echo " off --> change to CPU 0 SCP console"
19 echo " status --> change to CPU 1 SCP console"
20}
21
22function usage_uart() {
23 echo " kudo uart [parameter]"
Lancelot Kao19bfafb2021-05-25 15:04:57 -050024 echo " host --> show CPU console"
25 echo " scp --> show SCP0 console"
26 echo " swhost --> change to CPU console to ttyS1"
27 echo " swscp1 --> change to CPU 0 SCP console to ttyS3"
28 echo " swscp2 --> change to CPU 1 SCP console"
29 echo " swhosthr --> change CPU console to header"
30 echo " swscphr --> change SCP console to header"
XP Chen0e483352021-05-12 09:44:26 -050031 echo " display --> "
32}
33
34function usage() {
35 echo " kudo BMC console system utilities"
36 echo " kudo [optional] [parameter]"
37 echo " rst --> reset traget device"
38 echo " fw --> get version"
39 echo " uart --> control the uart mux"
40 echo " led --> control the leds"
41}
42
43function reset() {
44 case $1 in
45 hotswap)
46 # Virtual reset #94
47 set_gpio_ctrl 94 out 1
48 ;;
49 system)
50 # S0 system reset #65
51 set_gpio_ctrl 65 out 0
52 sleep 1
53 set_gpio_ctrl 65 out 1
54 ;;
55 btn)
56 # power button #203
57 set_gpio_ctrl 203 out 1
58 sleep 1
59 set_gpio_ctrl 203 out 0
60 ;;
61 shutdown)
62 # BMC_CPU_SHD_REQ #70
63 set_gpio_ctrl 70 out 0
64 sleep 3
65 set_gpio_ctrl 70 out 1
66 ;;
67 forceOff)
68 # power button #203
69 set_gpio_ctrl 203 out 1
70 sleep 6
71 set_gpio_ctrl 203 out 0
72 ;;
73 display)
Mohaimen Alsamaraia17ba542021-06-18 11:47:41 -050074 echo "Virtual reset #94" $(get_gpio_ctrl 94)
75 echo "S0 System reset #65" $(get_gpio_ctrl 65)
76 echo "Power Button #203" $(get_gpio_ctrl 203)
77 echo "BMC_CPU SHD Req #70" $(get_gpio_ctrl 70)
XP Chen0e483352021-05-12 09:44:26 -050078 ;;
79 *)
80 usage_rst
81 ;;
82 esac
83}
84
85function fw_rev() {
86 BMC_CPLD_VER_FILE="/run/cpld0.version"
87 MB_CPLD_VER_FILE="/run/cpld1.version"
88
89 cmd=$(cat $BMC_CPLD_VER_FILE)
90 echo " BMC_CPLD: " $cmd
91 cmd=$(cat $MB_CPLD_VER_FILE)
92 echo " MB_CPLD: " $cmd
93
XP Chen9d2a1e02021-08-25 16:40:01 -050094 # BMC Version
95
96 # Save VERSION_ID line in string "VERSION_ID=vXX.XX-XX-kudo"
97 StringVersion=$(cat /etc/os-release | awk '/VERSION_ID/')
98
99 #Save Major Version value between v and . "vXX." then convert Hex to Decimal
100 MajorVersion=${StringVersion#*v}
101 MajorVersion=$(( 16#${MajorVersion%.*}))
102
103 #Save SubMajor Version valeu between . and - ".XX-" then convert Hex to Decimal
104 SubMajorVersion=${StringVersion#*.}
105 SubMajorVersion=$(( 16#${SubMajorVersion%-*}))
106
107 #Save Minor Version value between - and - "-XX-" then convert Hex to Decimal
108 MinorVersion=${StringVersion#*-}
109 MinorVersion=$(( 16#${MinorVersion%-*}))
110
111 echo " BMC: " ${MajorVersion}.${SubMajorVersion}.${MinorVersion}
XP Chen0e483352021-05-12 09:44:26 -0500112
113 #BMC PWR Sequencer
114 i2cset -y -f -a 14 0x59 0xfe 0x0000 w
115 cmd=$(i2cget -y -f -a 14 0x59 0xfe i 2 | awk '{print substr($0,3)}')
116 echo " BMC PowerSequencer : ${cmd}"
117 #only display with smbios exists
118 if [[ -e /var/lib/smbios/smbios2 ]]; then
119 cmd=$(busctl introspect xyz.openbmc_project.Smbios.MDR_V2 \
120 /xyz/openbmc_project/inventory/system/chassis/motherboard/bios | grep Version | awk '{print $4}')
121 echo " Bios: $cmd"
122 fi
123
124 cmd=$(i2cget -f -y 2 0x4f 0x1 w);
125 echo " SCP Firmware: ${cmd}"
126
127 adm1266_ver | grep REVISION
128
129}
130
131function uartmux() {
132 case $1 in
133 host)
Lancelot Kao19bfafb2021-05-25 15:04:57 -0500134 if [ `tty` == "/dev/ttyS0" ]; then
135 echo "Couldn't redirect to the host console within BMC local console"
136 else
137 echo "Entering Console use 'shift ~~..' to quit"
138 obmc-console-client -c /etc/obmc-console/server.ttyS1.conf
139 fi
140 ;;
141 scp)
142 if [ `tty` == "/dev/ttyS0" ]; then
143 echo "Couldn't redirect to the scp console within BMC local console"
144 else
145 echo "Entering Console use 'shift ~~..' to quit"
146 obmc-console-client -c /etc/obmc-console/server.ttyS3.conf
147 fi
148 ;;
149 swhost)
XP Chen0e483352021-05-12 09:44:26 -0500150 set_gpio_ctrl 167 out 1
151 ;;
Lancelot Kao19bfafb2021-05-25 15:04:57 -0500152 swscp1)
XP Chen0e483352021-05-12 09:44:26 -0500153 set_gpio_ctrl 161 out 1
154 set_gpio_ctrl 177 out 1
155 set_gpio_ctrl 198 out 0
156 ;;
Lancelot Kao19bfafb2021-05-25 15:04:57 -0500157 swscp2)
XP Chen0e483352021-05-12 09:44:26 -0500158 set_gpio_ctrl 161 out 1
159 set_gpio_ctrl 177 out 1
160 set_gpio_ctrl 198 out 1
161 ;;
Lancelot Kao19bfafb2021-05-25 15:04:57 -0500162 swhosthr)
XP Chen0e483352021-05-12 09:44:26 -0500163 set_gpio_ctrl 167 out 0
164 ;;
Lancelot Kao19bfafb2021-05-25 15:04:57 -0500165 swscphr)
XP Chen0e483352021-05-12 09:44:26 -0500166 set_gpio_ctrl 161 out 0
167 set_gpio_ctrl 177 out 0
168 ;;
169 display)
170 if [ $(get_gpio_ctrl 167) -eq 1 ]; then
171 echo " CPU host to BMC console"
172 else
173 echo " CPU host to header"
174 fi
175 if [ $(get_gpio_ctrl 161) -eq 1 ] && [ $(get_gpio_ctrl 177) -eq 1 ]; then
176 if [ $(get_gpio_ctrl 198) -eq 1 ]; then
177 echo " SCP2 host to BMC console"
178 else
179 echo " SCP1 host to BMC console"
180 fi
181 elif [ $(get_gpio_ctrl 161) -eq 0 ] && [ $(get_gpio_ctrl 177) -eq 0 ]; then
182 if [ $(get_gpio_ctrl 198) -eq 1 ]; then
183 echo " SCP2 host to Header"
184 else
185 echo " SCP1 host to Header"
186 fi
187 else
188 echo "It's unknown status"
189 echo "167" $(get_gpio_ctrl 167)
190 echo "161" $(get_gpio_ctrl 161)
191 echo "177" $(get_gpio_ctrl 177)
192 echo "198" $(get_gpio_ctrl 198)
193 fi
194 ;;
195 *)
196 usage_uart
197 ;;
198 esac
199}
200
201function ledtoggle() {
202
203 CurrentLED=$( i2cget -y -f -a 34 0x76 0x05 i 1 | cut -d ' ' -f 2)
204 case $1 in
205 boot)
206 cmd=$((($CurrentLED & 0x40) != 0))
207 case $2 in
208 on)
209 #turn on LED
210 if [[ $cmd -eq 0 ]]; then
211 setValue=$(( 0x40 + $CurrentLED ))
212 i2cset -y -f -a 34 0x76 0x10 $setValue
213 fi
214 ;;
215 off)
216 #turn off led
217 if [[ $cmd -eq 1 ]]; then
218 setValue=$(( 0x80 & $CurrentLED ))
219 i2cset -y -f -a 34 0x76 0x10 $setValue
220 fi
221 ;;
222 toggle)
223 #turn on LED
224 setValue=$(( 0x40 ^ $CurrentLED ))
225 i2cset -y -f -a 34 0x76 0x10 $setValue
226 ;;
227 status)
228 #displayLED status
229 if [[ $cmd -eq 1 ]]; then
230 echo "on"
231 else
232 echo "off"
233 fi
234 ;;
235 *)
236 usage_led
237 ;;
238 esac
239 ;;
240 att)
241 cmd=$((($CurrentLED & 0x80) != 0))
242 case $2 in
243 on)
244 #turn on LED
245 if [[ $cmd -eq 0 ]]; then
246 setValue=$(( 0x80 + $CurrentLED ))
247 i2cset -y -f -a 34 0x76 0x10 $setValue
248 fi
249 ;;
250 off)
251 #turn off led
252 if [[ $cmd -eq 1 ]]; then
253 setValue=$(( 0x40 & $CurrentLED ))
254 i2cset -y -f -a 34 0x76 0x10 $setValue
255 fi
256 ;;
257 toggle)
258 #turn on LED
259 setValue=$(( 0x80 ^ $CurrentLED ))
260 i2cset -y -f -a 34 0x76 0x10 $setValue
261 ;;
262 status)
263 #displayLED status
264 if [[ $cmd -eq 1 ]]; then
265 echo "on"
266 else
267 echo "off"
268 fi
269 ;;
270 *)
271 usage_led
272 ;;
273 esac
274 ;;
275 *)
276 usage_led
277 ;;
278 esac
279}
280
281function usblist() {
282 for i in {0..8}
283 do
284 cmd="devmem 0xf083"$i"154"
285 printf "udc%d : 0xF803%d154-" "$i" "$i"
286 $cmd
287 done
288}
289
290case $1 in
291 rst)
292 reset $2
293 ;;
294 fw)
295 fw_rev
296 ;;
297 uart)
298 uartmux $2
299 ;;
300 usb)
301 usblist
302 ;;
303 led)
304 ledtoggle $2 $3
305 ;;
306 *)
307 usage
308 ;;
309esac