blob: 694c23cc9b5920721d34666544dc3b51ef866838 [file] [log] [blame]
XP Chen0e483352021-05-12 09:44:26 -05001#!/bin/bash
2# help information
3
Charles Boyer0dd80062022-03-17 14:57:50 -05004# Provide source directive to shellcheck.
5# shellcheck source=meta-fii/meta-kudo/recipes-kudo/kudo-fw-utility/kudo-fw/kudo-lib.sh
Charles Boyer2adad362021-11-24 15:58:03 -06006source /usr/libexec/kudo-fw/kudo-lib.sh
XP Chen0e483352021-05-12 09:44:26 -05007
8function usage_rst() {
9 echo " kudo rst [parameter]"
10 echo " hotswap --> reset the whole kudo node"
11 echo " system --> reset the host"
12 echo " btn --> trigger a power button event"
13 echo " shutdown --> send out shutdown signal to CPU"
14 echo " display --> "
15}
16
17function usage_led() {
XP Chen0e483352021-05-12 09:44:26 -050018 echo " kudo led 'att'/'boot' [parameter]"
19 echo " on --> change to CPU console"
20 echo " off --> change to CPU 0 SCP console"
21 echo " status --> change to CPU 1 SCP console"
22}
23
24function usage_uart() {
25 echo " kudo uart [parameter]"
Lancelot Kao19bfafb2021-05-25 15:04:57 -050026 echo " host --> show CPU console"
27 echo " scp --> show SCP0 console"
28 echo " swhost --> change to CPU console to ttyS1"
29 echo " swscp1 --> change to CPU 0 SCP console to ttyS3"
30 echo " swscp2 --> change to CPU 1 SCP console"
31 echo " swhosthr --> change CPU console to header"
32 echo " swscphr --> change SCP console to header"
XP Chen0e483352021-05-12 09:44:26 -050033 echo " display --> "
34}
35
36function usage() {
37 echo " kudo BMC console system utilities"
38 echo " kudo [optional] [parameter]"
39 echo " rst --> reset traget device"
40 echo " fw --> get version"
41 echo " uart --> control the uart mux"
42 echo " led --> control the leds"
43}
44
45function reset() {
46 case $1 in
47 hotswap)
48 # Virtual reset #94
49 set_gpio_ctrl 94 out 1
50 ;;
51 system)
52 # S0 system reset #65
53 set_gpio_ctrl 65 out 0
54 sleep 1
55 set_gpio_ctrl 65 out 1
56 ;;
57 btn)
58 # power button #203
59 set_gpio_ctrl 203 out 1
60 sleep 1
61 set_gpio_ctrl 203 out 0
62 ;;
63 shutdown)
64 # BMC_CPU_SHD_REQ #70
65 set_gpio_ctrl 70 out 0
66 sleep 3
67 set_gpio_ctrl 70 out 1
68 ;;
69 forceOff)
70 # power button #203
71 set_gpio_ctrl 203 out 1
72 sleep 6
73 set_gpio_ctrl 203 out 0
74 ;;
75 display)
Charles Boyer0dd80062022-03-17 14:57:50 -050076 echo "Virtual reset #94" "$(get_gpio_ctrl 94)"
77 echo "S0 System reset #65" "$(get_gpio_ctrl 65)"
78 echo "Power Button #203" "$(get_gpio_ctrl 203)"
79 echo "BMC_CPU SHD Req #70" "$(get_gpio_ctrl 70)"
XP Chen0e483352021-05-12 09:44:26 -050080 ;;
81 *)
82 usage_rst
83 ;;
84 esac
85}
86
87function fw_rev() {
88 BMC_CPLD_VER_FILE="/run/cpld0.version"
89 MB_CPLD_VER_FILE="/run/cpld1.version"
90
Charles Boyer0dd80062022-03-17 14:57:50 -050091 cmd=$(cat ${BMC_CPLD_VER_FILE})
92 echo " BMC_CPLD: " "${cmd}"
93 cmd=$(cat ${MB_CPLD_VER_FILE})
94 echo " MB_CPLD: " "${cmd}"
XP Chen0e483352021-05-12 09:44:26 -050095
XP Chen9d2a1e02021-08-25 16:40:01 -050096 # BMC Version
97
98 # Save VERSION_ID line in string "VERSION_ID=vXX.XX-XX-kudo"
Charles Boyer0dd80062022-03-17 14:57:50 -050099 StringVersion=$(awk '/VERSION_ID/' /etc/os-release)
XP Chen9d2a1e02021-08-25 16:40:01 -0500100
101 #Save Major Version value between v and . "vXX." then convert Hex to Decimal
102 MajorVersion=${StringVersion#*v}
103 MajorVersion=$(( 16#${MajorVersion%.*}))
104
105 #Save SubMajor Version valeu between . and - ".XX-" then convert Hex to Decimal
Ashwin Muraliba38d482022-03-21 17:00:41 -0500106 SubMajorVersion=${StringVersion##*.}
107 SubMajorVersion=$(( 16#${SubMajorVersion%%-*}))
XP Chen9d2a1e02021-08-25 16:40:01 -0500108
109 #Save Minor Version value between - and - "-XX-" then convert Hex to Decimal
110 MinorVersion=${StringVersion#*-}
111 MinorVersion=$(( 16#${MinorVersion%-*}))
112
113 echo " BMC: " ${MajorVersion}.${SubMajorVersion}.${MinorVersion}
XP Chen0e483352021-05-12 09:44:26 -0500114
115 #BMC PWR Sequencer
116 i2cset -y -f -a 14 0x59 0xfe 0x0000 w
117 cmd=$(i2cget -y -f -a 14 0x59 0xfe i 2 | awk '{print substr($0,3)}')
118 echo " BMC PowerSequencer : ${cmd}"
119 #only display with smbios exists
120 if [[ -e /var/lib/smbios/smbios2 ]]; then
121 cmd=$(busctl introspect xyz.openbmc_project.Smbios.MDR_V2 \
122 /xyz/openbmc_project/inventory/system/chassis/motherboard/bios | grep Version | awk '{print $4}')
123 echo " Bios: $cmd"
124 fi
125
126 cmd=$(i2cget -f -y 2 0x4f 0x1 w);
127 echo " SCP Firmware: ${cmd}"
128
129 adm1266_ver | grep REVISION
130
131}
132
133function uartmux() {
134 case $1 in
135 host)
Charles Boyer0dd80062022-03-17 14:57:50 -0500136 if [ "$(tty)" == "/dev/ttyS0" ]; then
Lancelot Kao19bfafb2021-05-25 15:04:57 -0500137 echo "Couldn't redirect to the host console within BMC local console"
138 else
139 echo "Entering Console use 'shift ~~..' to quit"
140 obmc-console-client -c /etc/obmc-console/server.ttyS1.conf
141 fi
142 ;;
143 scp)
Charles Boyer0dd80062022-03-17 14:57:50 -0500144 if [ "$(tty)" == "/dev/ttyS0" ]; then
Lancelot Kao19bfafb2021-05-25 15:04:57 -0500145 echo "Couldn't redirect to the scp console within BMC local console"
146 else
147 echo "Entering Console use 'shift ~~..' to quit"
148 obmc-console-client -c /etc/obmc-console/server.ttyS3.conf
149 fi
150 ;;
151 swhost)
XP Chen0e483352021-05-12 09:44:26 -0500152 set_gpio_ctrl 167 out 1
153 ;;
Lancelot Kao19bfafb2021-05-25 15:04:57 -0500154 swscp1)
XP Chen0e483352021-05-12 09:44:26 -0500155 set_gpio_ctrl 161 out 1
156 set_gpio_ctrl 177 out 1
157 set_gpio_ctrl 198 out 0
158 ;;
Lancelot Kao19bfafb2021-05-25 15:04:57 -0500159 swscp2)
XP Chen0e483352021-05-12 09:44:26 -0500160 set_gpio_ctrl 161 out 1
161 set_gpio_ctrl 177 out 1
162 set_gpio_ctrl 198 out 1
163 ;;
Lancelot Kao19bfafb2021-05-25 15:04:57 -0500164 swhosthr)
XP Chen0e483352021-05-12 09:44:26 -0500165 set_gpio_ctrl 167 out 0
166 ;;
Lancelot Kao19bfafb2021-05-25 15:04:57 -0500167 swscphr)
XP Chen0e483352021-05-12 09:44:26 -0500168 set_gpio_ctrl 161 out 0
169 set_gpio_ctrl 177 out 0
170 ;;
171 display)
Charles Boyer0dd80062022-03-17 14:57:50 -0500172 if [ "$(get_gpio_ctrl 167)" -eq 1 ]; then
XP Chen0e483352021-05-12 09:44:26 -0500173 echo " CPU host to BMC console"
174 else
175 echo " CPU host to header"
176 fi
Charles Boyer0dd80062022-03-17 14:57:50 -0500177 if [ "$(get_gpio_ctrl 161)" -eq 1 ] && [ "$(get_gpio_ctrl 177)" -eq 1 ]; then
178 if [ "$(get_gpio_ctrl 198)" -eq 1 ]; then
XP Chen0e483352021-05-12 09:44:26 -0500179 echo " SCP2 host to BMC console"
180 else
181 echo " SCP1 host to BMC console"
182 fi
Charles Boyer0dd80062022-03-17 14:57:50 -0500183 elif [ "$(get_gpio_ctrl 161)" -eq 0 ] && [ "$(get_gpio_ctrl 177)" -eq 0 ]; then
184 if [ "$(get_gpio_ctrl 198)" -eq 1 ]; then
XP Chen0e483352021-05-12 09:44:26 -0500185 echo " SCP2 host to Header"
186 else
187 echo " SCP1 host to Header"
188 fi
189 else
190 echo "It's unknown status"
Charles Boyer0dd80062022-03-17 14:57:50 -0500191 echo "167" "$(get_gpio_ctrl 167)"
192 echo "161" "$(get_gpio_ctrl 161)"
193 echo "177" "$(get_gpio_ctrl 177)"
194 echo "198" "$(get_gpio_ctrl 198)"
XP Chen0e483352021-05-12 09:44:26 -0500195 fi
196 ;;
197 *)
198 usage_uart
199 ;;
200 esac
201}
202
203function ledtoggle() {
204
205 CurrentLED=$( i2cget -y -f -a 34 0x76 0x05 i 1 | cut -d ' ' -f 2)
206 case $1 in
207 boot)
Charles Boyer0dd80062022-03-17 14:57:50 -0500208 cmd=$(((CurrentLED & 0x40) != 0))
XP Chen0e483352021-05-12 09:44:26 -0500209 case $2 in
210 on)
211 #turn on LED
212 if [[ $cmd -eq 0 ]]; then
Charles Boyer0dd80062022-03-17 14:57:50 -0500213 setValue=$(( 0x40 + CurrentLED ))
214 i2cset -y -f -a 34 0x76 0x10 "$setValue"
XP Chen0e483352021-05-12 09:44:26 -0500215 fi
216 ;;
217 off)
218 #turn off led
219 if [[ $cmd -eq 1 ]]; then
Charles Boyer0dd80062022-03-17 14:57:50 -0500220 setValue=$(( 0x80 & CurrentLED ))
221 i2cset -y -f -a 34 0x76 0x10 "$setValue"
XP Chen0e483352021-05-12 09:44:26 -0500222 fi
223 ;;
224 toggle)
225 #turn on LED
Charles Boyer0dd80062022-03-17 14:57:50 -0500226 setValue=$(( 0x40 ^ CurrentLED ))
227 i2cset -y -f -a 34 0x76 0x10 "$setValue"
XP Chen0e483352021-05-12 09:44:26 -0500228 ;;
229 status)
230 #displayLED status
231 if [[ $cmd -eq 1 ]]; then
232 echo "on"
233 else
234 echo "off"
235 fi
236 ;;
237 *)
238 usage_led
239 ;;
240 esac
241 ;;
242 att)
Charles Boyer0dd80062022-03-17 14:57:50 -0500243 cmd=$(((CurrentLED & 0x80) != 0))
XP Chen0e483352021-05-12 09:44:26 -0500244 case $2 in
245 on)
246 #turn on LED
247 if [[ $cmd -eq 0 ]]; then
Charles Boyer0dd80062022-03-17 14:57:50 -0500248 setValue=$(( 0x80 + CurrentLED ))
249 i2cset -y -f -a 34 0x76 0x10 "$setValue"
XP Chen0e483352021-05-12 09:44:26 -0500250 fi
251 ;;
252 off)
253 #turn off led
254 if [[ $cmd -eq 1 ]]; then
Charles Boyer0dd80062022-03-17 14:57:50 -0500255 setValue=$(( 0x40 & CurrentLED ))
256 i2cset -y -f -a 34 0x76 0x10 "$setValue"
XP Chen0e483352021-05-12 09:44:26 -0500257 fi
258 ;;
259 toggle)
260 #turn on LED
Charles Boyer0dd80062022-03-17 14:57:50 -0500261 setValue=$(( 0x80 ^ CurrentLED ))
262 i2cset -y -f -a 34 0x76 0x10 "$setValue"
XP Chen0e483352021-05-12 09:44:26 -0500263 ;;
264 status)
265 #displayLED status
266 if [[ $cmd -eq 1 ]]; then
267 echo "on"
268 else
269 echo "off"
270 fi
271 ;;
272 *)
273 usage_led
274 ;;
275 esac
276 ;;
277 *)
278 usage_led
279 ;;
280 esac
281}
282
283function usblist() {
284 for i in {0..8}
285 do
Charles Boyer0dd80062022-03-17 14:57:50 -0500286 cmd=$(devmem 0xf083"${i}"154)
287 printf "udc%d : 0xF803%d154-" "${i}" "${i}"
XP Chen0e483352021-05-12 09:44:26 -0500288 $cmd
289 done
290}
291
292case $1 in
293 rst)
Charles Boyer0dd80062022-03-17 14:57:50 -0500294 reset "$2"
XP Chen0e483352021-05-12 09:44:26 -0500295 ;;
296 fw)
297 fw_rev
298 ;;
299 uart)
Charles Boyer0dd80062022-03-17 14:57:50 -0500300 uartmux "$2"
XP Chen0e483352021-05-12 09:44:26 -0500301 ;;
302 usb)
303 usblist
304 ;;
305 led)
Charles Boyer0dd80062022-03-17 14:57:50 -0500306 ledtoggle "$2" "$3"
XP Chen0e483352021-05-12 09:44:26 -0500307 ;;
308 *)
309 usage
310 ;;
311esac