blob: bb3ded21c6df20fcb450492de0dd0cc42ade16dd [file] [log] [blame]
Charles Boyer765c66a2022-05-03 11:01:24 -05001#!/bin/bash
2# help information
3
4# Provide source directive to shellcheck.
5# shellcheck source=meta-fii/meta-mori/recipes-mori/mori-fw-utility/mori-fw/mori-lib.sh
6source /usr/libexec/mori-fw/mori-lib.sh
7
8function usage_rst() {
9 echo " mori rst [parameter]"
10 echo " hotswap --> reset the whole mori 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() {
18 echo " mori led 'attn'/'boot' [parameter]"
19 echo " on --> turn led on"
20 echo " off --> turn led off"
21 echo " toggle --> toggle led"
22 echo " status --> get status of led"
23}
24
25function usage_uart() {
26 echo " mori uart [parameter]"
27 echo " host --> show CPU console"
28 echo " mpro --> show Mpro console"
29 echo " swhost --> change to CPU console to ttyS1"
30 echo " swmpro --> change to CPU 0 Mpro console to ttyS3"
31 echo " swhosthr --> change CPU console to header"
32 echo " swmprohr --> change Mpro console to header"
33 echo " display --> "
34}
35
36function usage() {
37 echo " mori BMC console system utilities"
38 echo " mori [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 AC reset
49 echo "mori.sh rst hotswap occurred"
50 set_gpio_ctrl HOTSWAP 1
51 ;;
52 system)
53 # S0 system reset
54 set_gpio_ctrl S0_SYSRESET 0
55 sleep 1
56 set_gpio_ctrl S0_SYSRESET 1
57 ;;
58 btn)
59 # virtual power button on
60 set_gpio_ctrl POWER_OUT 0
61 sleep 1
62 set_gpio_ctrl POWER_OUT 1
63 ;;
64 shutdown)
65 # request host shutdown
66 set_gpio_ctrl S0_SHD_REQ 0
67 sleep 3
68 set_gpio_ctrl S0_SHD_REQ 1
69 ;;
70 forceOff)
71 # virtual power button off
72 set_gpio_ctrl POWER_OUT 0
73 sleep 6
74 set_gpio_ctrl POWER_OUT 1
75 ;;
76 display)
77 echo "Virtual AC Reset: GPIO$(get_gpio_num HOTSWAP)" "State:$(get_gpio_ctrl HOTSWAP)"
78 echo "Virtual Power Button: GPIO$(get_gpio_num POWER_OUT)" "State:$(get_gpio_ctrl POWER_OUT)"
79 echo "S0 System Reset: GPIO$(get_gpio_num S0_SYSRESET)" "State:$(get_gpio_ctrl S0_SYSRESET)"
80 echo "S0 Shutdown Request: GPIO$(get_gpio_num S0_SHD_REQ)" "State:$(get_gpio_ctrl S0_SHD_REQ)"
81 ;;
82 *)
83 usage_rst
84 ;;
85 esac
86}
87
88function fw_rev() {
89 BMC_CPLD_VER_FILE="/run/cpld0.version"
90 MB_CPLD_VER_FILE="/run/cpld1.version"
91
92 cmd=$(cat ${BMC_CPLD_VER_FILE})
93 echo " BMC_CPLD: " "${cmd}"
94 cmd=$(cat ${MB_CPLD_VER_FILE})
95 echo " MB_CPLD: " "${cmd}"
96
97 major=$(ipmitool mc info | grep "Firmware Revision" | awk '{print $4}')
98 cmd=$(ipmitool mc info | tail -4 | tr -s '\t' ' ' | tr -s '\n' ' ')
99
100 for hex in $cmd; do
101 minor="${hex:2}$minor";
102 done
103
104 minor=$(echo "obase=10; ibase=16; ${minor^^}" | bc)
105 echo " BMC : " "${major}"."${minor}"
106
107 #BMC PWR Sequencer
108 i2cset -y -f -a "${I2C_BMC_PWRSEQ[0]}" 0x"${I2C_BMC_PWRSEQ[1]}" 0xfe 0x0000 w
109 cmd=$(i2cget -y -f -a "${I2C_BMC_PWRSEQ[0]}" 0x"${I2C_BMC_PWRSEQ[1]}" 0xfe i 2 | awk '{print substr($0,3)}')
110 echo " BMC PowerSequencer : ${cmd}"
111 #only display with smbios exists
112 if [[ -e /var/lib/smbios/smbios2 ]]; then
113 cmd=$(busctl introspect xyz.openbmc_project.Smbios.MDR_V2 \
114 /xyz/openbmc_project/inventory/system/chassis/motherboard/bios | grep Version | awk '{print $4}')
115 echo " Bios: $cmd"
116 fi
117
Kyle Niemanc48d4272022-08-08 09:41:43 -0500118 adm1266_ver "${I2C_MB_PWRSEQ[0]}" | grep REVISION
Charles Boyer765c66a2022-05-03 11:01:24 -0500119
120}
121
122function uartmux() {
123 case $1 in
124 host)
125 if [ "$(tty)" == "/dev/ttyS0" ]; then
126 echo "Couldn't redirect to the host console within BMC local console"
127 else
128 echo "Entering Console use 'shift ~~..' to quit"
129 obmc-console-client -c /etc/obmc-console/server.ttyS1.conf
130 fi
131 ;;
132 mpro)
133 if [ "$(tty)" == "/dev/ttyS0" ]; then
134 echo "Couldn't redirect to the Mpro console within BMC local console"
135 else
136 echo "Entering Console use 'shift ~~..' to quit"
137 obmc-console-client -c /etc/obmc-console/server.ttyS3.conf
138 fi
139 ;;
140 swhost)
141 set_gpio_ctrl S0_UART0_BMC_SEL 1
142 ;;
143 swmpro)
144 set_gpio_ctrl S0_UART1_BMC_SEL 1
145 ;;
146 swhosthr)
147 set_gpio_ctrl S0_UART0_BMC_SEL 0
148 ;;
149 swmprohr)
150 set_gpio_ctrl S0_UART1_BMC_SEL 0
151 ;;
152 display)
153 if [ "$(get_gpio_ctrl S0_UART0_BMC_SEL)" -eq 1 ]; then
154 echo " CPU host to BMC console"
155 else
156 echo " CPU host to header"
157 fi
158
159 if [ "$(get_gpio_ctrl S0_UART1_BMC_SEL)" -eq 1 ]; then
160 echo " Mpro host to BMC console"
161 else
162 echo " Mpro host to header"
163 fi
164 ;;
165 *)
166 usage_uart
167 ;;
168 esac
169}
170
171function ledtoggle() {
172 case $1 in
173 boot)
174 cmd=$(get_gpio_ctrl SYS_BOOT_STATUS_LED)
175 case $2 in
176 on)
177 #turn on LED
178 set_gpio_ctrl SYS_BOOT_STATUS_LED 1
179 ;;
180 off)
181 #turn off LED
182 set_gpio_ctrl SYS_BOOT_STATUS_LED 0
183 ;;
184 toggle)
185 #toggle off LED
186 if [[ $cmd -eq 1 ]]; then
187 set_gpio_ctrl SYS_BOOT_STATUS_LED 0
188 fi
189
190 #toggle on LED
191 if [[ $cmd -eq 0 ]]; then
192 set_gpio_ctrl SYS_BOOT_STATUS_LED 1
193 fi
194 ;;
195 status)
196 #displayLED status
197 if [[ $cmd -eq 1 ]]; then
198 echo "on"
199 else
200 echo "off"
201 fi
202 ;;
203 *)
204 usage_led
205 ;;
206 esac
207 ;;
208 attn)
209 cmd=$(get_gpio_ctrl SYS_ERROR_LED)
210 case $2 in
211 on)
212 #turn on LED
213 set_gpio_ctrl SYS_ERROR_LED 1
214 ;;
215 off)
216 #turn off LED
217 set_gpio_ctrl SYS_ERROR_LED 0
218 ;;
219 toggle)
220 #toggle off LED
221 if [[ $cmd -eq 1 ]]; then
222 set_gpio_ctrl SYS_ERROR_LED 0
223 fi
224
225 #toggle on LED
226 if [[ $cmd -eq 0 ]]; then
227 set_gpio_ctrl SYS_ERROR_LED 1
228 fi
229 ;;
230 status)
231 #displayLED status
232 if [[ $cmd -eq 1 ]]; then
233 echo "on"
234 else
235 echo "off"
236 fi
237 ;;
238 *)
239 usage_led
240 ;;
241 esac
242 ;;
243 *)
244 usage_led
245 ;;
246 esac
247}
248
249case $1 in
250 rst)
251 reset "$2"
252 ;;
253 fw)
254 fw_rev
255 ;;
256 uart)
257 uartmux "$2"
258 ;;
259 led)
260 ledtoggle "$2" "$3"
261 ;;
262 *)
263 usage
264 ;;
265esac
266