blob: 697295d31bbf8887261dc5a88ccc2aafc3dfd415 [file] [log] [blame]
Patrick Williamsb2398202021-04-13 20:53:26 -05001#!/bin/bash -e
Anthony Wilson79f697e2018-09-13 13:48:52 -05002
3set -euo pipefail
4
Anthony Wilson189cf242018-10-23 01:18:21 -05005OPTS="bmcstate,bootprogress,chassiskill,chassisoff,chassison,chassisstate,hoststate,\
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -06006osstate,power,poweroff,poweron,state,status,hostrebootoff,hostrebooton,recoveryoff,recoveryon,\
Andrew Geisslerad1afe52022-02-23 16:07:06 -06007bmcrebootoff, bmcrebooton, listbootblock listlogs showlog deletelogs, stopofftargets"
Anthony Wilson0f359832018-09-13 14:28:07 -05008
Potin Lai0e044c42022-05-13 23:42:31 +08009USAGE="Usage: obmcutil [-h] [--wait] [--verbose] [--id=<INSTANCE_ID>]
Anthony Wilson0f359832018-09-13 14:28:07 -050010 {$OPTS}"
Anthony Wilson79f697e2018-09-13 13:48:52 -050011
12INTERFACE_ROOT=xyz.openbmc_project
13STATE_INTERFACE=$INTERFACE_ROOT.State
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -050014CONTROL_INTERFACE=$INTERFACE_ROOT.Control
Anthony Wilson79f697e2018-09-13 13:48:52 -050015
16OBJECT_ROOT=/xyz/openbmc_project
17STATE_OBJECT=$OBJECT_ROOT/state
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -050018CONTROL_OBJECT=$OBJECT_ROOT/control
Anthony Wilson79f697e2018-09-13 13:48:52 -050019
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -050020HOST_TIMEOUT_TARGET=obmc-host-timeout@0.target
Vishwanatha Subbanna84b3b292019-11-04 05:43:19 -060021HOST_CRASH_TARGET=obmc-host-crash@0.target
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -050022
Anthony Wilsonacf54d02018-09-20 15:19:28 -050023## NOTE: The following global variables are used only in the run_timeout cmd.
24## By declaring these globally instead of passing them through the
25## intermediary functions, which may not be "best practice", the readability
26## and cleanliness of the code should at least be increased.
27
28# The command passed in to be executed (e.g. poweron/off, status, etc.)
29# This will be be used in some instances of error reporting
30G_ORIG_CMD=
31# The state an interface should be in after executing the requested command.
32G_REQUESTED_STATE=
33# The query to run during a poweron/off or chassison/off to check that
34# the requested state (G_REQUESTED_STATE) of the interface has been reached.
35G_QUERY=
36# Wait the set period of time for state transitions to be successful before
37# continuing on with the program or reporting an error if timeout reached.
38G_WAIT=
Andrew Jeffery60c3ac82019-10-02 09:29:29 +093039# Print the journal to the console
40G_VERBOSE=
Potin Lai0e044c42022-05-13 23:42:31 +080041# Instance id, default 0
42G_INSTANCE_ID="0"
Anthony Wilsonacf54d02018-09-20 15:19:28 -050043
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050044print_help ()
45{
46 echo "$USAGE"
47 echo ""
48 echo "positional arguments:"
Anthony Wilson0f359832018-09-13 14:28:07 -050049 echo " {$OPTS}"
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050050 echo ""
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -050051 echo "Examples:"
52 echo ""
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -060053 echo "obmcutil hostrebootoff Disable auto reboot of Host from Quiesce state"
Andrew Geissler3191be82020-10-23 10:45:55 -050054 echo "obmcutil hostrebootoffonetime Disable auto reboot of Host from"
55 echo " Quiesce state for a single boot"
Andrew Geisslerad1afe52022-02-23 16:07:06 -060056 echo "obmcutil hostrebooton Enable auto reboot of Host from Quiesce state"
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -050057 echo ""
Andrew Geisslerad1afe52022-02-23 16:07:06 -060058 echo "obmcutil bmcrebootoff Disable reboot of BMC"
59 echo "obmcutil bmcrebooton Enable reboot of BMC"
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -060060 echo ""
Andrew Geisslerad1afe52022-02-23 16:07:06 -060061 echo "obmcutil recoveryoff Disable handling boot watchdog timeout and host crash"
62 echo " Also, disable BMC and Host auto reboots"
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -060063 echo ""
Andrew Geisslerad1afe52022-02-23 16:07:06 -060064 echo "obmcutil recoveryon Enable handling boot watchdog timeout and host crash"
65 echo " Also, enable BMC and Host auto reboots"
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -050066 echo ""
Andrew Geisslerad1afe52022-02-23 16:07:06 -060067 echo "obmcutil listbootblock Check for and list any errors blocking the boot"
68 echo " of the system"
Andrew Geissler3b7b5612020-05-14 10:45:29 -050069 echo ""
Andrew Geisslerad1afe52022-02-23 16:07:06 -060070 echo "obmcutil listlogs List all phosphor-logging entries on the"
71 echo " system"
Andrew Geissler295ee4f2020-05-14 14:14:05 -050072 echo ""
Andrew Geisslerad1afe52022-02-23 16:07:06 -060073 echo "obmcutil showlog <log> Display details of input log. Format of <log>"
74 echo " should match listlogs output"
Andrew Geisslerd8c63202020-05-14 15:06:31 -050075 echo ""
Andrew Geisslerad1afe52022-02-23 16:07:06 -060076 echo "obmcutil deletelogs Delete all phosphor-logging entries from"
77 echo " system"
78 echo "obmcutil stopofftargets Manually stop all obmc targets in power off"
79 echo " path"
Andrew Geissler42f28982020-05-14 15:12:42 -050080 echo ""
Andrew Geisslerd8779cd2020-06-11 10:48:40 -050081 echo "optional arguments (must precede the positional options above):"
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050082 echo " -h, --help show this help message and exit"
Anthony Wilsonacf54d02018-09-20 15:19:28 -050083 echo " -w, --wait block until state transition succeeds or fails"
Andrew Jeffery60c3ac82019-10-02 09:29:29 +093084 echo " -v, --verbose print the journal to stdout if --wait is supplied"
Potin Lai0e044c42022-05-13 23:42:31 +080085 echo " -i, -id instance id, default 0"
Anthony Wilsonf3f16fa2018-09-13 14:10:52 -050086 exit 0
87}
88
Anthony Wilsonacf54d02018-09-20 15:19:28 -050089run_timeout ()
90{
91 local timeout="$1"; shift
Patrick Williamsb2398202021-04-13 20:53:26 -050092 local cmd="$*"
Andrew Jeffery60c3ac82019-10-02 09:29:29 +093093 local verbose_child=
94
Andrew Jeffery2869a922019-10-18 14:42:34 +103095 if [ -n "$G_VERBOSE" ]; then
Andrew Jeffery60c3ac82019-10-02 09:29:29 +093096 journalctl -f &
97 verbose_child=$!
98 fi
Anthony Wilsonacf54d02018-09-20 15:19:28 -050099
100 $cmd
101
102 # Run a background query for the transition to the expected state
103 # This will be killed if the transition doesn't succeed within
104 # a timeout period.
105 (
Patrick Williamsb2398202021-04-13 20:53:26 -0500106 while ! grep -q "$G_REQUESTED_STATE" <<< "$(handle_cmd "$G_QUERY")" ; do
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500107 sleep 1
108 done
109 ) &
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930110 wait_child=$!
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500111
112 # Could be bad if process is killed before 'timeout' occurs if
113 # transition doesn't succeed.
114 trap -- "" SIGTERM
115
116 # Workaround for lack of 'timeout' command.
117 (
Patrick Williamsb2398202021-04-13 20:53:26 -0500118 sleep "$timeout"
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930119 kill $wait_child
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500120 ) > /dev/null 2>&1 &
121
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930122 if ! wait $wait_child; then
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500123 echo "Unable to confirm '$G_ORIG_CMD' success" \
124 "within timeout period (${timeout}s)"
125 fi
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930126
Andrew Jeffery8be70292019-11-01 08:56:49 +1030127 if [ -n "$verbose_child" ]; then
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930128 kill $verbose_child
129 fi
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500130}
131
132run_cmd ()
133{
Patrick Williamsb2398202021-04-13 20:53:26 -0500134 local cmd="$*";
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500135
136 if [ -n "$G_WAIT" ]; then
Patrick Williamsb2398202021-04-13 20:53:26 -0500137 run_timeout "$G_WAIT" "$cmd"
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500138 else
139 $cmd
140 fi
141}
142
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500143set_property ()
144{
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500145 run_cmd busctl set-property "$@"
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500146}
147
Anthony Wilson79f697e2018-09-13 13:48:52 -0500148get_property ()
149{
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500150 G_WAIT=""
151 run_cmd busctl get-property "$@"
Anthony Wilson79f697e2018-09-13 13:48:52 -0500152}
153
154state_query ()
155{
Patrick Williamsb2398202021-04-13 20:53:26 -0500156 local state
157 state=$(get_property "$@" | cut -d '"' -f2)
158 printf "%-20s: %s\n" "$4" "$state"
Anthony Wilson79f697e2018-09-13 13:48:52 -0500159}
160
Anthony Wilsonea87db42018-09-26 16:06:38 -0500161print_usage_err ()
162{
163 echo "ERROR: $1" >&2
164 echo "$USAGE"
165 exit 1
166}
167
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500168mask_systemd_target ()
169{
Patrick Williamsb2398202021-04-13 20:53:26 -0500170 target="$*"
171 systemctl mask "$target"
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500172}
173
174unmask_systemd_target ()
175{
Patrick Williamsb2398202021-04-13 20:53:26 -0500176 target="$*"
177 systemctl unmask "$target"
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500178}
179
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600180disable_bmc_reboot ()
181{
182 dir="/run/systemd/system/"
183 file="reboot-guard.conf"
184 units=("reboot" "poweroff" "halt")
185
186 for unit in "${units[@]}"; do
Patrick Williamsb2398202021-04-13 20:53:26 -0500187 mkdir -p "${dir}${unit}.target.d"
188 echo -e "[Unit]\nRefuseManualStart=yes" >> "${dir}${unit}.target.d/${file}"
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600189 done
190}
191
192enable_bmc_reboot ()
193{
194 dir="/run/systemd/system/"
195 file="reboot-guard.conf"
196 units=("reboot" "poweroff" "halt")
197
198 for unit in "${units[@]}"; do
Patrick Williamsb2398202021-04-13 20:53:26 -0500199 rm -rf "${dir}${unit}.target.d/${file}"
200 rm -rf "${dir}${unit}.target.d"
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600201 done
202}
203
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500204# will write blocking errors to stdout
205check_boot_block_errors ()
206{
207 # array of boot block objects
208 blockArray=()
209
210 # Look for any objects under logging that implement the
211 # xyz.openbmc_project.Logging.ErrorBlocksTransition
212 subtree="$(busctl call xyz.openbmc_project.ObjectMapper \
213 /xyz/openbmc_project/object_mapper \
214 xyz.openbmc_project.ObjectMapper \
215 GetSubTree sias "/xyz/openbmc_project/logging/" 0 1 \
216 xyz.openbmc_project.Logging.ErrorBlocksTransition)"
217
218 # remove quotation marks
Patrick Williamsb2398202021-04-13 20:53:26 -0500219 # shellcheck disable=SC2001
220 subtree="$(echo "$subtree" | sed 's/\"//g')"
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500221
222 for entry in $subtree; do
223 if [[ ${entry} =~ "xyz/openbmc_project/logging/block"* ]]; then
Patrick Williamsb2398202021-04-13 20:53:26 -0500224 blockArray+=( "$entry" )
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500225 fi
226 done
227
228 # now find associated error log for each boot block error
229 for berror in "${blockArray[@]}"; do
Patrick Williamsb2398202021-04-13 20:53:26 -0500230 assocs="$(busctl call xyz.openbmc_project.Logging "$berror" \
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500231 org.freedesktop.DBus.Properties Get \
232 ss xyz.openbmc_project.Association.Definitions Associations)"
233
234 # remove quotation marks
Patrick Williamsb2398202021-04-13 20:53:26 -0500235 # shellcheck disable=SC2001
236 assocs="$(echo "$assocs" | sed 's/\"//g')"
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500237
238 for entry in $assocs; do
239 if [[ ${entry} =~ "xyz/openbmc_project/logging/entry"* ]]; then
240 echo "Blocking Error: $entry"
241 fi
242 done
243 done
244}
245
Andrew Geisslerdeb6bb42020-05-14 13:44:57 -0500246# helper function to check for boot block errors and notify user
247check_and_warn_boot_block()
248{
249 blockingErrors=$(check_boot_block_errors)
Patrick Williamsb2398202021-04-13 20:53:26 -0500250 if [ -n "$blockingErrors" ]; then
Andrew Geisslerdeb6bb42020-05-14 13:44:57 -0500251 echo !!!!!!!!!!
252 echo "WARNING! System has blocking errors that will prevent boot"
253 echo "$blockingErrors"
254 echo !!!!!!!!!!
255 fi
256}
257
Andrew Geissler295ee4f2020-05-14 14:14:05 -0500258# list all phosphor-logging entries
259list_logs()
260{
261 # Look for any objects under logging that implement the
262 # xyz.openbmc_project.Logging.Entry
263 busctl -j call xyz.openbmc_project.ObjectMapper \
264 /xyz/openbmc_project/object_mapper \
265 xyz.openbmc_project.ObjectMapper \
266 GetSubTreePaths sias "/xyz/openbmc_project/logging/" 0 1 \
267 xyz.openbmc_project.Logging.Entry
268}
269
Andrew Geisslerd8c63202020-05-14 15:06:31 -0500270# display input log details
271show_log()
272{
273 busctl -j call xyz.openbmc_project.Logging \
Patrick Williamsb2398202021-04-13 20:53:26 -0500274 "$1" \
Andrew Geisslerd8c63202020-05-14 15:06:31 -0500275 org.freedesktop.DBus.Properties \
276 GetAll s xyz.openbmc_project.Logging.Entry
277}
278
Andrew Geissler42f28982020-05-14 15:12:42 -0500279# delete all phosphor-logging entries
280delete_logs()
281{
282 busctl call xyz.openbmc_project.Logging \
283 /xyz/openbmc_project/logging \
284 xyz.openbmc_project.Collection.DeleteAll DeleteAll
285}
286
Andrew Geisslerad1afe52022-02-23 16:07:06 -0600287# stop all targets associated with powering off a system
288stop_off_targets()
289{
290 systemctl stop \
291 obmc-chassis-powered-off@0.target \
292 obmc-host-stop-pre@0.target \
293 obmc-host-stopped@0.target \
294 obmc-host-stopping@0.target \
295 obmc-power-off@0.target \
296 obmc-power-stop-pre@0.target \
297 obmc-power-stop@0.target
298}
299
Anthony Wilson79f697e2018-09-13 13:48:52 -0500300handle_cmd ()
301{
302 case "$1" in
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500303 chassisoff)
Potin Lai0e044c42022-05-13 23:42:31 +0800304 OBJECT=$STATE_OBJECT/chassis$G_INSTANCE_ID
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500305 SERVICE=$(mapper get-service $OBJECT)
306 INTERFACE=$STATE_INTERFACE.Chassis
307 PROPERTY=RequestedPowerTransition
308 VALUE=$INTERFACE.Transition.Off
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500309 G_REQUESTED_STATE=$INTERFACE.PowerState.Off
310 G_QUERY="chassisstate"
Patrick Williamsb2398202021-04-13 20:53:26 -0500311 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500312 ;;
313 chassison)
Andrew Geisslerdeb6bb42020-05-14 13:44:57 -0500314 check_and_warn_boot_block
Potin Lai0e044c42022-05-13 23:42:31 +0800315 OBJECT=$STATE_OBJECT/chassis$G_INSTANCE_ID
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500316 SERVICE=$(mapper get-service $OBJECT)
317 INTERFACE=$STATE_INTERFACE.Chassis
318 PROPERTY=RequestedPowerTransition
319 VALUE=$INTERFACE.Transition.On
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500320 G_REQUESTED_STATE=$INTERFACE.PowerState.On
321 G_QUERY="chassisstate"
Patrick Williamsb2398202021-04-13 20:53:26 -0500322 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500323 ;;
324 poweroff)
Potin Lai0e044c42022-05-13 23:42:31 +0800325 OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500326 SERVICE=$(mapper get-service $OBJECT)
327 INTERFACE=$STATE_INTERFACE.Host
328 PROPERTY=RequestedHostTransition
329 VALUE=$INTERFACE.Transition.Off
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500330 G_REQUESTED_STATE=$INTERFACE.HostState.Off
331 G_QUERY="hoststate"
Patrick Williamsb2398202021-04-13 20:53:26 -0500332 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500333 ;;
334 poweron)
Andrew Geisslerdeb6bb42020-05-14 13:44:57 -0500335 check_and_warn_boot_block
Potin Lai0e044c42022-05-13 23:42:31 +0800336 OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500337 SERVICE=$(mapper get-service $OBJECT)
338 INTERFACE=$STATE_INTERFACE.Host
339 PROPERTY=RequestedHostTransition
340 VALUE=$INTERFACE.Transition.On
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500341 G_REQUESTED_STATE=$INTERFACE.HostState.Running
342 G_QUERY="hoststate"
Patrick Williamsb2398202021-04-13 20:53:26 -0500343 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
Anthony Wilson3ae0a352018-09-13 14:47:56 -0500344 ;;
Anthony Wilson79f697e2018-09-13 13:48:52 -0500345 bmcstate)
346 OBJECT=$STATE_OBJECT/bmc0
347 SERVICE=$(mapper get-service $OBJECT)
348 INTERFACE=$STATE_INTERFACE.BMC
349 PROPERTY=CurrentBMCState
Patrick Williamsb2398202021-04-13 20:53:26 -0500350 state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
Anthony Wilson79f697e2018-09-13 13:48:52 -0500351 ;;
352 chassisstate)
Potin Lai0e044c42022-05-13 23:42:31 +0800353 OBJECT=$STATE_OBJECT/chassis$G_INSTANCE_ID
Anthony Wilson79f697e2018-09-13 13:48:52 -0500354 SERVICE=$(mapper get-service $OBJECT)
355 INTERFACE=$STATE_INTERFACE.Chassis
356 PROPERTY=CurrentPowerState
Patrick Williamsb2398202021-04-13 20:53:26 -0500357 state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
Anthony Wilson79f697e2018-09-13 13:48:52 -0500358 ;;
359 hoststate)
Potin Lai0e044c42022-05-13 23:42:31 +0800360 OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID
Anthony Wilson79f697e2018-09-13 13:48:52 -0500361 SERVICE=$(mapper get-service $OBJECT)
362 INTERFACE=$STATE_INTERFACE.Host
363 PROPERTY=CurrentHostState
Patrick Williamsb2398202021-04-13 20:53:26 -0500364 state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
Anthony Wilson79f697e2018-09-13 13:48:52 -0500365 ;;
Alexander Filippov86cffd92019-04-03 16:29:57 +0300366 osstate)
Potin Lai0e044c42022-05-13 23:42:31 +0800367 OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID
Alexander Filippov86cffd92019-04-03 16:29:57 +0300368 SERVICE=$(mapper get-service $OBJECT)
369 INTERFACE=$STATE_INTERFACE.OperatingSystem.Status
370 PROPERTY=OperatingSystemState
Patrick Williamsb2398202021-04-13 20:53:26 -0500371 state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
Alexander Filippov86cffd92019-04-03 16:29:57 +0300372 ;;
Anthony Wilson79f697e2018-09-13 13:48:52 -0500373 state|status)
Alexander Filippov86cffd92019-04-03 16:29:57 +0300374 for query in bmcstate chassisstate hoststate bootprogress osstate
Anthony Wilson79f697e2018-09-13 13:48:52 -0500375 do
376 handle_cmd $query
377 done
Andrew Geisslerdeb6bb42020-05-14 13:44:57 -0500378 check_and_warn_boot_block
Anthony Wilson79f697e2018-09-13 13:48:52 -0500379 ;;
Anthony Wilson50c5f882018-09-13 14:19:37 -0500380 bootprogress)
Potin Lai0e044c42022-05-13 23:42:31 +0800381 OBJECT=$STATE_OBJECT/host$G_INSTANCE_ID
Anthony Wilson50c5f882018-09-13 14:19:37 -0500382 SERVICE=$(mapper get-service $OBJECT)
383 INTERFACE=$STATE_INTERFACE.Boot.Progress
384 PROPERTY=BootProgress
Patrick Williamsb2398202021-04-13 20:53:26 -0500385 state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
Anthony Wilson50c5f882018-09-13 14:19:37 -0500386 ;;
Anthony Wilson0f359832018-09-13 14:28:07 -0500387 power)
388 OBJECT=/org/openbmc/control/power0
389 SERVICE=$(mapper get-service $OBJECT)
390 INTERFACE=org.openbmc.control.Power
391 for property in pgood state pgood_timeout
392 do
393 # get_property can potentially return several
394 # different formats of values, so we do the parsing outside
395 # of get_property depending on the query. These queries
396 # return 'i VALUE' formatted strings.
Patrick Williamsb2398202021-04-13 20:53:26 -0500397 STATE=$(get_property "$SERVICE" $OBJECT $INTERFACE $property \
Anthony Wilson0f359832018-09-13 14:28:07 -0500398 | sed 's/i[ ^I]*//')
Patrick Williamsb2398202021-04-13 20:53:26 -0500399 printf "%s = %s\n" $property "$STATE"
Anthony Wilson0f359832018-09-13 14:28:07 -0500400 done
401 ;;
Anthony Wilson189cf242018-10-23 01:18:21 -0500402 chassiskill)
403 /usr/libexec/chassiskill
404 ;;
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600405 hostrebootoff)
Potin Lai0e044c42022-05-13 23:42:31 +0800406 OBJECT=$CONTROL_OBJECT/host$G_INSTANCE_ID/auto_reboot
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -0500407 SERVICE=$(mapper get-service $OBJECT)
408 INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy
409 PROPERTY=AutoReboot
410 VALUE=false
Patrick Williamsb2398202021-04-13 20:53:26 -0500411 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -0500412 ;;
Andrew Geissler3191be82020-10-23 10:45:55 -0500413 hostrebootoffonetime)
Potin Lai0e044c42022-05-13 23:42:31 +0800414 OBJECT=$CONTROL_OBJECT/host$G_INSTANCE_ID/auto_reboot/one_time
Andrew Geissler3191be82020-10-23 10:45:55 -0500415 SERVICE=$(mapper get-service $OBJECT)
416 INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy
417 PROPERTY=AutoReboot
418 VALUE=false
Patrick Williamsb2398202021-04-13 20:53:26 -0500419 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE
Andrew Geissler3191be82020-10-23 10:45:55 -0500420 ;;
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600421 hostrebooton)
Potin Lai0e044c42022-05-13 23:42:31 +0800422 OBJECT=$CONTROL_OBJECT/host$G_INSTANCE_ID/auto_reboot
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -0500423 SERVICE=$(mapper get-service $OBJECT)
424 INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy
425 PROPERTY=AutoReboot
426 VALUE=true
Patrick Williamsb2398202021-04-13 20:53:26 -0500427 set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE
Vishwanatha Subbanna6d3a2c52019-10-24 07:21:30 -0500428 ;;
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600429 bmcrebootoff)
430 disable_bmc_reboot
431 ;;
432 bmcrebooton)
433 enable_bmc_reboot
434 ;;
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500435 recoveryoff)
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600436 handle_cmd hostrebootoff
437 handle_cmd bmcrebootoff
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500438 mask_systemd_target $HOST_TIMEOUT_TARGET
Vishwanatha Subbanna84b3b292019-11-04 05:43:19 -0600439 mask_systemd_target $HOST_CRASH_TARGET
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500440 ;;
441 recoveryon)
Vishwanatha Subbannaa65d30d2019-11-13 01:26:12 -0600442 handle_cmd hostrebooton
443 handle_cmd bmcrebooton
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500444 unmask_systemd_target $HOST_TIMEOUT_TARGET
Vishwanatha Subbanna84b3b292019-11-04 05:43:19 -0600445 unmask_systemd_target $HOST_CRASH_TARGET
Vishwanatha Subbanna7a787dd2019-10-31 06:02:31 -0500446 ;;
Andrew Geissler3b7b5612020-05-14 10:45:29 -0500447 listbootblock)
448 blockingErrors=$(check_boot_block_errors)
449 if [ -z "$blockingErrors" ]; then
450 echo "No blocking errors present"
451 else
452 echo "$blockingErrors"
453 fi
454 ;;
Andrew Geissler295ee4f2020-05-14 14:14:05 -0500455 listlogs)
456 list_logs
457 ;;
Andrew Geisslerd8c63202020-05-14 15:06:31 -0500458 showlog)
Patrick Williamsb2398202021-04-13 20:53:26 -0500459 show_log "$2"
Andrew Geisslerd8c63202020-05-14 15:06:31 -0500460 ;;
Andrew Geissler42f28982020-05-14 15:12:42 -0500461 deletelogs)
462 delete_logs
463 ;;
Andrew Geisslerad1afe52022-02-23 16:07:06 -0600464 stopofftargets)
465 stop_off_targets
466 ;;
Anthony Wilson79f697e2018-09-13 13:48:52 -0500467 *)
Anthony Wilsonea87db42018-09-26 16:06:38 -0500468 print_usage_err "Invalid command '$1'"
Anthony Wilson79f697e2018-09-13 13:48:52 -0500469 ;;
470 esac
471}
472
Andrew Geisslerd8779cd2020-06-11 10:48:40 -0500473shiftcnt=0
Anthony Wilsonea87db42018-09-26 16:06:38 -0500474for arg in "$@"; do
475 case $arg in
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500476 -w|--wait)
477 G_WAIT=30
Andrew Geisslerd8779cd2020-06-11 10:48:40 -0500478 shiftcnt=$((shiftcnt+1))
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500479 continue
480 ;;
Anthony Wilsonea87db42018-09-26 16:06:38 -0500481 -h|--help)
482 print_help
483 ;;
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930484 -v|--verbose)
485 G_VERBOSE=y
Andrew Geisslerd8779cd2020-06-11 10:48:40 -0500486 shiftcnt=$((shiftcnt+1))
Andrew Jeffery60c3ac82019-10-02 09:29:29 +0930487 ;;
Potin Lai0e044c42022-05-13 23:42:31 +0800488 -i=*|--id=*)
489 G_INSTANCE_ID="${arg#*=}"
490 shiftcnt=$((shiftcnt+1))
491 ;;
Anthony Wilsonea87db42018-09-26 16:06:38 -0500492 -*)
493 print_usage_err "Unknown option: $arg"
494 ;;
495 *)
Anthony Wilsonacf54d02018-09-20 15:19:28 -0500496 G_ORIG_CMD=$arg
Andrew Geisslerd8779cd2020-06-11 10:48:40 -0500497 # shift out the optional parameters
498 shift $shiftcnt
Andrew Geisslerd8c63202020-05-14 15:06:31 -0500499 # pass all arguments to handle_cmd in case command takes additional
500 # parameters
501 handle_cmd "$@"
Anthony Wilsonea87db42018-09-26 16:06:38 -0500502 break
503 ;;
504 esac
505done