1b2398200SPatrick Williams#!/bin/bash -e
279f697e0SAnthony Wilson
379f697e0SAnthony Wilsonset -euo pipefail
479f697e0SAnthony Wilson
5189cf248SAnthony WilsonOPTS="bmcstate,bootprogress,chassiskill,chassisoff,chassison,chassisstate,hoststate,\
6a65d30d1SVishwanatha Subbannaosstate,power,poweroff,poweron,state,status,hostrebootoff,hostrebooton,recoveryoff,recoveryon,\
7*ad1afe58SAndrew Geisslerbmcrebootoff, bmcrebooton, listbootblock listlogs showlog deletelogs, stopofftargets"
80f35983dSAnthony Wilson
960c3ac8cSAndrew JefferyUSAGE="Usage: obmcutil [-h] [--wait] [--verbose]
100f35983dSAnthony Wilson                {$OPTS}"
1179f697e0SAnthony Wilson
1279f697e0SAnthony WilsonINTERFACE_ROOT=xyz.openbmc_project
1379f697e0SAnthony WilsonSTATE_INTERFACE=$INTERFACE_ROOT.State
146d3a2c54SVishwanatha SubbannaCONTROL_INTERFACE=$INTERFACE_ROOT.Control
1579f697e0SAnthony Wilson
1679f697e0SAnthony WilsonOBJECT_ROOT=/xyz/openbmc_project
1779f697e0SAnthony WilsonSTATE_OBJECT=$OBJECT_ROOT/state
186d3a2c54SVishwanatha SubbannaCONTROL_OBJECT=$OBJECT_ROOT/control
1979f697e0SAnthony Wilson
207a787dd7SVishwanatha SubbannaHOST_TIMEOUT_TARGET=obmc-host-timeout@0.target
2184b3b29eSVishwanatha SubbannaHOST_CRASH_TARGET=obmc-host-crash@0.target
227a787dd7SVishwanatha Subbanna
23acf54d08SAnthony Wilson## NOTE: The following global variables are used only in the run_timeout cmd.
24acf54d08SAnthony Wilson## By declaring these globally instead of passing them through the
25acf54d08SAnthony Wilson## intermediary functions, which may not be "best practice", the readability
26acf54d08SAnthony Wilson## and cleanliness of the code should at least be increased.
27acf54d08SAnthony Wilson
28acf54d08SAnthony Wilson# The command passed in to be executed (e.g. poweron/off, status, etc.)
29acf54d08SAnthony Wilson# This will be be used in some instances of error reporting
30acf54d08SAnthony WilsonG_ORIG_CMD=
31acf54d08SAnthony Wilson# The state an interface should be in after executing the requested command.
32acf54d08SAnthony WilsonG_REQUESTED_STATE=
33acf54d08SAnthony Wilson# The query to run during a poweron/off or chassison/off to check that
34acf54d08SAnthony Wilson# the requested state (G_REQUESTED_STATE) of the interface has been reached.
35acf54d08SAnthony WilsonG_QUERY=
36acf54d08SAnthony Wilson# Wait the set period of time for state transitions to be successful before
37acf54d08SAnthony Wilson# continuing on with the program or reporting an error if timeout reached.
38acf54d08SAnthony WilsonG_WAIT=
3960c3ac8cSAndrew Jeffery# Print the journal to the console
4060c3ac8cSAndrew JefferyG_VERBOSE=
41acf54d08SAnthony Wilson
42f3f16fa9SAnthony Wilsonprint_help ()
43f3f16fa9SAnthony Wilson{
44f3f16fa9SAnthony Wilson    echo "$USAGE"
45f3f16fa9SAnthony Wilson    echo ""
46f3f16fa9SAnthony Wilson    echo "positional arguments:"
470f35983dSAnthony Wilson    echo "  {$OPTS}"
48f3f16fa9SAnthony Wilson    echo ""
496d3a2c54SVishwanatha Subbanna    echo "Examples:"
506d3a2c54SVishwanatha Subbanna    echo ""
51a65d30d1SVishwanatha Subbanna    echo "obmcutil hostrebootoff Disable auto reboot of Host from Quiesce state"
523191be88SAndrew Geissler    echo "obmcutil hostrebootoffonetime Disable auto reboot of Host from"
533191be88SAndrew Geissler    echo "                              Quiesce state for a single boot"
54a65d30d1SVishwanatha Subbanna    echo "obmcutil hostrebooton   Enable auto reboot of Host from Quiesce state"
55a65d30d1SVishwanatha Subbanna    echo ""
56a65d30d1SVishwanatha Subbanna    echo "obmcutil bmcrebootoff   Disable reboot of BMC"
57a65d30d1SVishwanatha Subbanna    echo "obmcutil bmcrebooton    Enable reboot of BMC"
586d3a2c54SVishwanatha Subbanna    echo ""
5984b3b29eSVishwanatha Subbanna    echo "obmcutil recoveryoff    Disable handling boot watchdog timeout and host crash"
60a65d30d1SVishwanatha Subbanna    echo "                        Also, disable BMC and Host auto reboots"
61a65d30d1SVishwanatha Subbanna    echo ""
6284b3b29eSVishwanatha Subbanna    echo "obmcutil recoveryon     Enable handling boot watchdog timeout and host crash"
63a65d30d1SVishwanatha Subbanna    echo "                        Also, enable BMC and Host auto reboots"
647a787dd7SVishwanatha Subbanna    echo ""
653b7b5619SAndrew Geissler    echo "obmcutil listbootblock  Check for and list any errors blocking the boot"
663b7b5619SAndrew Geissler    echo "                        of the system"
673b7b5619SAndrew Geissler    echo ""
68295ee4fbSAndrew Geissler    echo "obmcutil listlogs       List all phosphor-logging entries on the"
69295ee4fbSAndrew Geissler    echo "                        system"
70295ee4fbSAndrew Geissler    echo ""
71d8c63204SAndrew Geissler    echo "obmcutil showlog <log>  Display details of input log. Format of <log>"
72d8c63204SAndrew Geissler    echo "                        should match listlogs output"
73d8c63204SAndrew Geissler    echo ""
7442f2898dSAndrew Geissler    echo "obmcutil deletelogs     Delete all phosphor-logging entries from"
7542f2898dSAndrew Geissler    echo "                        system"
76*ad1afe58SAndrew Geissler    echo "obmcutil stopofftargets Manually stop all obmc targets in power off"
77*ad1afe58SAndrew Geissler    echo "                        path"
7842f2898dSAndrew Geissler    echo ""
79d8779cd8SAndrew Geissler    echo "optional arguments (must precede the positional options above):"
80f3f16fa9SAnthony Wilson    echo "  -h, --help          show this help message and exit"
81acf54d08SAnthony Wilson    echo "  -w, --wait          block until state transition succeeds or fails"
8260c3ac8cSAndrew Jeffery    echo "  -v, --verbose       print the journal to stdout if --wait is supplied"
83f3f16fa9SAnthony Wilson    exit 0
84f3f16fa9SAnthony Wilson}
85f3f16fa9SAnthony Wilson
86acf54d08SAnthony Wilsonrun_timeout ()
87acf54d08SAnthony Wilson{
88acf54d08SAnthony Wilson    local timeout="$1"; shift
89b2398200SPatrick Williams    local cmd="$*"
9060c3ac8cSAndrew Jeffery    local verbose_child=
9160c3ac8cSAndrew Jeffery
922869a926SAndrew Jeffery    if [ -n "$G_VERBOSE" ]; then
9360c3ac8cSAndrew Jeffery        journalctl -f &
9460c3ac8cSAndrew Jeffery        verbose_child=$!
9560c3ac8cSAndrew Jeffery    fi
96acf54d08SAnthony Wilson
97acf54d08SAnthony Wilson    $cmd
98acf54d08SAnthony Wilson
99acf54d08SAnthony Wilson    # Run a background query for the transition to the expected state
100acf54d08SAnthony Wilson    # This will be killed if the transition doesn't succeed within
101acf54d08SAnthony Wilson    # a timeout period.
102acf54d08SAnthony Wilson    (
103b2398200SPatrick Williams        while ! grep -q "$G_REQUESTED_STATE" <<< "$(handle_cmd "$G_QUERY")" ; do
104acf54d08SAnthony Wilson            sleep 1
105acf54d08SAnthony Wilson        done
106acf54d08SAnthony Wilson    ) &
10760c3ac8cSAndrew Jeffery    wait_child=$!
108acf54d08SAnthony Wilson
109acf54d08SAnthony Wilson    # Could be bad if process is killed before 'timeout' occurs if
110acf54d08SAnthony Wilson    # transition doesn't succeed.
111acf54d08SAnthony Wilson    trap -- "" SIGTERM
112acf54d08SAnthony Wilson
113acf54d08SAnthony Wilson    # Workaround for lack of 'timeout' command.
114acf54d08SAnthony Wilson    (
115b2398200SPatrick Williams        sleep "$timeout"
11660c3ac8cSAndrew Jeffery        kill $wait_child
117acf54d08SAnthony Wilson    ) > /dev/null 2>&1 &
118acf54d08SAnthony Wilson
11960c3ac8cSAndrew Jeffery    if ! wait $wait_child; then
120acf54d08SAnthony Wilson        echo "Unable to confirm '$G_ORIG_CMD' success" \
121acf54d08SAnthony Wilson        "within timeout period (${timeout}s)"
122acf54d08SAnthony Wilson    fi
12360c3ac8cSAndrew Jeffery
1248be70293SAndrew Jeffery    if [ -n "$verbose_child" ]; then
12560c3ac8cSAndrew Jeffery        kill $verbose_child
12660c3ac8cSAndrew Jeffery    fi
127acf54d08SAnthony Wilson}
128acf54d08SAnthony Wilson
129acf54d08SAnthony Wilsonrun_cmd ()
130acf54d08SAnthony Wilson{
131b2398200SPatrick Williams    local cmd="$*";
132acf54d08SAnthony Wilson
133acf54d08SAnthony Wilson    if [ -n "$G_WAIT" ]; then
134b2398200SPatrick Williams        run_timeout "$G_WAIT" "$cmd"
135acf54d08SAnthony Wilson    else
136acf54d08SAnthony Wilson        $cmd
137acf54d08SAnthony Wilson    fi
138acf54d08SAnthony Wilson}
139acf54d08SAnthony Wilson
1403ae0a354SAnthony Wilsonset_property ()
1413ae0a354SAnthony Wilson{
142acf54d08SAnthony Wilson    run_cmd busctl set-property "$@"
1433ae0a354SAnthony Wilson}
1443ae0a354SAnthony Wilson
14579f697e0SAnthony Wilsonget_property ()
14679f697e0SAnthony Wilson{
147acf54d08SAnthony Wilson    G_WAIT=""
148acf54d08SAnthony Wilson    run_cmd busctl get-property "$@"
14979f697e0SAnthony Wilson}
15079f697e0SAnthony Wilson
15179f697e0SAnthony Wilsonstate_query ()
15279f697e0SAnthony Wilson{
153b2398200SPatrick Williams    local state
154b2398200SPatrick Williams    state=$(get_property "$@" | cut -d '"' -f2)
155b2398200SPatrick Williams    printf "%-20s: %s\n" "$4" "$state"
15679f697e0SAnthony Wilson}
15779f697e0SAnthony Wilson
158ea87db40SAnthony Wilsonprint_usage_err ()
159ea87db40SAnthony Wilson{
160ea87db40SAnthony Wilson    echo "ERROR: $1" >&2
161ea87db40SAnthony Wilson    echo "$USAGE"
162ea87db40SAnthony Wilson    exit 1
163ea87db40SAnthony Wilson}
164ea87db40SAnthony Wilson
1657a787dd7SVishwanatha Subbannamask_systemd_target ()
1667a787dd7SVishwanatha Subbanna{
167b2398200SPatrick Williams    target="$*"
168b2398200SPatrick Williams    systemctl mask "$target"
1697a787dd7SVishwanatha Subbanna}
1707a787dd7SVishwanatha Subbanna
1717a787dd7SVishwanatha Subbannaunmask_systemd_target ()
1727a787dd7SVishwanatha Subbanna{
173b2398200SPatrick Williams    target="$*"
174b2398200SPatrick Williams    systemctl unmask "$target"
1757a787dd7SVishwanatha Subbanna}
1767a787dd7SVishwanatha Subbanna
177a65d30d1SVishwanatha Subbannadisable_bmc_reboot ()
178a65d30d1SVishwanatha Subbanna{
179a65d30d1SVishwanatha Subbanna    dir="/run/systemd/system/"
180a65d30d1SVishwanatha Subbanna    file="reboot-guard.conf"
181a65d30d1SVishwanatha Subbanna    units=("reboot" "poweroff" "halt")
182a65d30d1SVishwanatha Subbanna
183a65d30d1SVishwanatha Subbanna    for unit in "${units[@]}"; do
184b2398200SPatrick Williams        mkdir -p "${dir}${unit}.target.d"
185b2398200SPatrick Williams        echo -e "[Unit]\nRefuseManualStart=yes" >> "${dir}${unit}.target.d/${file}"
186a65d30d1SVishwanatha Subbanna    done
187a65d30d1SVishwanatha Subbanna}
188a65d30d1SVishwanatha Subbanna
189a65d30d1SVishwanatha Subbannaenable_bmc_reboot ()
190a65d30d1SVishwanatha Subbanna{
191a65d30d1SVishwanatha Subbanna    dir="/run/systemd/system/"
192a65d30d1SVishwanatha Subbanna    file="reboot-guard.conf"
193a65d30d1SVishwanatha Subbanna    units=("reboot" "poweroff" "halt")
194a65d30d1SVishwanatha Subbanna
195a65d30d1SVishwanatha Subbanna    for unit in "${units[@]}"; do
196b2398200SPatrick Williams        rm -rf "${dir}${unit}.target.d/${file}"
197b2398200SPatrick Williams        rm -rf "${dir}${unit}.target.d"
198a65d30d1SVishwanatha Subbanna    done
199a65d30d1SVishwanatha Subbanna}
200a65d30d1SVishwanatha Subbanna
2013b7b5619SAndrew Geissler# will write blocking errors to stdout
2023b7b5619SAndrew Geisslercheck_boot_block_errors ()
2033b7b5619SAndrew Geissler{
2043b7b5619SAndrew Geissler    # array of boot block objects
2053b7b5619SAndrew Geissler    blockArray=()
2063b7b5619SAndrew Geissler
2073b7b5619SAndrew Geissler    # Look for any objects under logging that implement the
2083b7b5619SAndrew Geissler    # xyz.openbmc_project.Logging.ErrorBlocksTransition
2093b7b5619SAndrew Geissler    subtree="$(busctl call xyz.openbmc_project.ObjectMapper \
2103b7b5619SAndrew Geissler               /xyz/openbmc_project/object_mapper \
2113b7b5619SAndrew Geissler               xyz.openbmc_project.ObjectMapper \
2123b7b5619SAndrew Geissler               GetSubTree sias "/xyz/openbmc_project/logging/" 0 1 \
2133b7b5619SAndrew Geissler               xyz.openbmc_project.Logging.ErrorBlocksTransition)"
2143b7b5619SAndrew Geissler
2153b7b5619SAndrew Geissler    # remove quotation marks
216b2398200SPatrick Williams    # shellcheck disable=SC2001
217b2398200SPatrick Williams    subtree="$(echo "$subtree" | sed 's/\"//g')"
2183b7b5619SAndrew Geissler
2193b7b5619SAndrew Geissler    for entry in $subtree; do
2203b7b5619SAndrew Geissler        if [[ ${entry} =~ "xyz/openbmc_project/logging/block"* ]]; then
221b2398200SPatrick Williams            blockArray+=( "$entry" )
2223b7b5619SAndrew Geissler        fi
2233b7b5619SAndrew Geissler    done
2243b7b5619SAndrew Geissler
2253b7b5619SAndrew Geissler    # now find associated error log for each boot block error
2263b7b5619SAndrew Geissler    for berror in "${blockArray[@]}"; do
227b2398200SPatrick Williams        assocs="$(busctl call xyz.openbmc_project.Logging "$berror" \
2283b7b5619SAndrew Geissler                  org.freedesktop.DBus.Properties Get \
2293b7b5619SAndrew Geissler                  ss xyz.openbmc_project.Association.Definitions Associations)"
2303b7b5619SAndrew Geissler
2313b7b5619SAndrew Geissler        # remove quotation marks
232b2398200SPatrick Williams        # shellcheck disable=SC2001
233b2398200SPatrick Williams        assocs="$(echo "$assocs" | sed 's/\"//g')"
2343b7b5619SAndrew Geissler
2353b7b5619SAndrew Geissler        for entry in $assocs; do
2363b7b5619SAndrew Geissler            if [[ ${entry} =~ "xyz/openbmc_project/logging/entry"* ]]; then
2373b7b5619SAndrew Geissler                echo "Blocking Error: $entry"
2383b7b5619SAndrew Geissler            fi
2393b7b5619SAndrew Geissler        done
2403b7b5619SAndrew Geissler    done
2413b7b5619SAndrew Geissler}
2423b7b5619SAndrew Geissler
243deb6bb45SAndrew Geissler# helper function to check for boot block errors and notify user
244deb6bb45SAndrew Geisslercheck_and_warn_boot_block()
245deb6bb45SAndrew Geissler{
246deb6bb45SAndrew Geissler    blockingErrors=$(check_boot_block_errors)
247b2398200SPatrick Williams    if [ -n "$blockingErrors" ]; then
248deb6bb45SAndrew Geissler        echo !!!!!!!!!!
249deb6bb45SAndrew Geissler        echo "WARNING! System has blocking errors that will prevent boot"
250deb6bb45SAndrew Geissler        echo "$blockingErrors"
251deb6bb45SAndrew Geissler        echo !!!!!!!!!!
252deb6bb45SAndrew Geissler    fi
253deb6bb45SAndrew Geissler}
254deb6bb45SAndrew Geissler
255295ee4fbSAndrew Geissler# list all phosphor-logging entries
256295ee4fbSAndrew Geisslerlist_logs()
257295ee4fbSAndrew Geissler{
258295ee4fbSAndrew Geissler    # Look for any objects under logging that implement the
259295ee4fbSAndrew Geissler    # xyz.openbmc_project.Logging.Entry
260295ee4fbSAndrew Geissler    busctl -j call xyz.openbmc_project.ObjectMapper \
261295ee4fbSAndrew Geissler            /xyz/openbmc_project/object_mapper \
262295ee4fbSAndrew Geissler            xyz.openbmc_project.ObjectMapper \
263295ee4fbSAndrew Geissler            GetSubTreePaths sias "/xyz/openbmc_project/logging/" 0 1 \
264295ee4fbSAndrew Geissler            xyz.openbmc_project.Logging.Entry
265295ee4fbSAndrew Geissler}
266295ee4fbSAndrew Geissler
267d8c63204SAndrew Geissler# display input log details
268d8c63204SAndrew Geisslershow_log()
269d8c63204SAndrew Geissler{
270d8c63204SAndrew Geissler    busctl -j call xyz.openbmc_project.Logging \
271b2398200SPatrick Williams           "$1" \
272d8c63204SAndrew Geissler           org.freedesktop.DBus.Properties \
273d8c63204SAndrew Geissler           GetAll s xyz.openbmc_project.Logging.Entry
274d8c63204SAndrew Geissler}
275d8c63204SAndrew Geissler
27642f2898dSAndrew Geissler# delete all phosphor-logging entries
27742f2898dSAndrew Geisslerdelete_logs()
27842f2898dSAndrew Geissler{
27942f2898dSAndrew Geissler    busctl call xyz.openbmc_project.Logging \
28042f2898dSAndrew Geissler           /xyz/openbmc_project/logging \
28142f2898dSAndrew Geissler           xyz.openbmc_project.Collection.DeleteAll DeleteAll
28242f2898dSAndrew Geissler}
28342f2898dSAndrew Geissler
284*ad1afe58SAndrew Geissler# stop all targets associated with powering off a system
285*ad1afe58SAndrew Geisslerstop_off_targets()
286*ad1afe58SAndrew Geissler{
287*ad1afe58SAndrew Geissler    systemctl stop \
288*ad1afe58SAndrew Geissler        obmc-chassis-powered-off@0.target \
289*ad1afe58SAndrew Geissler        obmc-host-stop-pre@0.target \
290*ad1afe58SAndrew Geissler        obmc-host-stopped@0.target \
291*ad1afe58SAndrew Geissler        obmc-host-stopping@0.target \
292*ad1afe58SAndrew Geissler        obmc-power-off@0.target \
293*ad1afe58SAndrew Geissler        obmc-power-stop-pre@0.target \
294*ad1afe58SAndrew Geissler        obmc-power-stop@0.target
295*ad1afe58SAndrew Geissler}
296*ad1afe58SAndrew Geissler
29779f697e0SAnthony Wilsonhandle_cmd ()
29879f697e0SAnthony Wilson{
29979f697e0SAnthony Wilson    case "$1" in
3003ae0a354SAnthony Wilson        chassisoff)
3013ae0a354SAnthony Wilson            OBJECT=$STATE_OBJECT/chassis0
3023ae0a354SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
3033ae0a354SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Chassis
3043ae0a354SAnthony Wilson            PROPERTY=RequestedPowerTransition
3053ae0a354SAnthony Wilson            VALUE=$INTERFACE.Transition.Off
306acf54d08SAnthony Wilson            G_REQUESTED_STATE=$INTERFACE.PowerState.Off
307acf54d08SAnthony Wilson            G_QUERY="chassisstate"
308b2398200SPatrick Williams            set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
3093ae0a354SAnthony Wilson            ;;
3103ae0a354SAnthony Wilson        chassison)
311deb6bb45SAndrew Geissler            check_and_warn_boot_block
3123ae0a354SAnthony Wilson            OBJECT=$STATE_OBJECT/chassis0
3133ae0a354SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
3143ae0a354SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Chassis
3153ae0a354SAnthony Wilson            PROPERTY=RequestedPowerTransition
3163ae0a354SAnthony Wilson            VALUE=$INTERFACE.Transition.On
317acf54d08SAnthony Wilson            G_REQUESTED_STATE=$INTERFACE.PowerState.On
318acf54d08SAnthony Wilson            G_QUERY="chassisstate"
319b2398200SPatrick Williams            set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
3203ae0a354SAnthony Wilson            ;;
3213ae0a354SAnthony Wilson        poweroff)
3223ae0a354SAnthony Wilson            OBJECT=$STATE_OBJECT/host0
3233ae0a354SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
3243ae0a354SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Host
3253ae0a354SAnthony Wilson            PROPERTY=RequestedHostTransition
3263ae0a354SAnthony Wilson            VALUE=$INTERFACE.Transition.Off
327acf54d08SAnthony Wilson            G_REQUESTED_STATE=$INTERFACE.HostState.Off
328acf54d08SAnthony Wilson            G_QUERY="hoststate"
329b2398200SPatrick Williams            set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
3303ae0a354SAnthony Wilson            ;;
3313ae0a354SAnthony Wilson        poweron)
332deb6bb45SAndrew Geissler            check_and_warn_boot_block
3333ae0a354SAnthony Wilson            OBJECT=$STATE_OBJECT/host0
3343ae0a354SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
3353ae0a354SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Host
3363ae0a354SAnthony Wilson            PROPERTY=RequestedHostTransition
3373ae0a354SAnthony Wilson            VALUE=$INTERFACE.Transition.On
338acf54d08SAnthony Wilson            G_REQUESTED_STATE=$INTERFACE.HostState.Running
339acf54d08SAnthony Wilson            G_QUERY="hoststate"
340b2398200SPatrick Williams            set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "s" $VALUE
3413ae0a354SAnthony Wilson            ;;
34279f697e0SAnthony Wilson        bmcstate)
34379f697e0SAnthony Wilson            OBJECT=$STATE_OBJECT/bmc0
34479f697e0SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
34579f697e0SAnthony Wilson            INTERFACE=$STATE_INTERFACE.BMC
34679f697e0SAnthony Wilson            PROPERTY=CurrentBMCState
347b2398200SPatrick Williams            state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
34879f697e0SAnthony Wilson            ;;
34979f697e0SAnthony Wilson        chassisstate)
35079f697e0SAnthony Wilson            OBJECT=$STATE_OBJECT/chassis0
35179f697e0SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
35279f697e0SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Chassis
35379f697e0SAnthony Wilson            PROPERTY=CurrentPowerState
354b2398200SPatrick Williams            state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
35579f697e0SAnthony Wilson            ;;
35679f697e0SAnthony Wilson        hoststate)
35779f697e0SAnthony Wilson            OBJECT=$STATE_OBJECT/host0
35879f697e0SAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
35979f697e0SAnthony Wilson            INTERFACE=$STATE_INTERFACE.Host
36079f697e0SAnthony Wilson            PROPERTY=CurrentHostState
361b2398200SPatrick Williams            state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
36279f697e0SAnthony Wilson            ;;
36386cffd9cSAlexander Filippov        osstate)
36486cffd9cSAlexander Filippov            OBJECT=$STATE_OBJECT/host0
36586cffd9cSAlexander Filippov            SERVICE=$(mapper get-service $OBJECT)
36686cffd9cSAlexander Filippov            INTERFACE=$STATE_INTERFACE.OperatingSystem.Status
36786cffd9cSAlexander Filippov            PROPERTY=OperatingSystemState
368b2398200SPatrick Williams            state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
36986cffd9cSAlexander Filippov            ;;
37079f697e0SAnthony Wilson        state|status)
37186cffd9cSAlexander Filippov            for query in bmcstate chassisstate hoststate bootprogress osstate
37279f697e0SAnthony Wilson            do
37379f697e0SAnthony Wilson                handle_cmd $query
37479f697e0SAnthony Wilson            done
375deb6bb45SAndrew Geissler            check_and_warn_boot_block
37679f697e0SAnthony Wilson            ;;
37750c5f88dSAnthony Wilson        bootprogress)
37850c5f88dSAnthony Wilson            OBJECT=$STATE_OBJECT/host0
37950c5f88dSAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
38050c5f88dSAnthony Wilson            INTERFACE=$STATE_INTERFACE.Boot.Progress
38150c5f88dSAnthony Wilson            PROPERTY=BootProgress
382b2398200SPatrick Williams            state_query "$SERVICE" $OBJECT $INTERFACE $PROPERTY
38350c5f88dSAnthony Wilson            ;;
3840f35983dSAnthony Wilson        power)
3850f35983dSAnthony Wilson            OBJECT=/org/openbmc/control/power0
3860f35983dSAnthony Wilson            SERVICE=$(mapper get-service $OBJECT)
3870f35983dSAnthony Wilson            INTERFACE=org.openbmc.control.Power
3880f35983dSAnthony Wilson            for property in pgood state pgood_timeout
3890f35983dSAnthony Wilson            do
3900f35983dSAnthony Wilson                # get_property can potentially return several
3910f35983dSAnthony Wilson                # different formats of values, so we do the parsing outside
3920f35983dSAnthony Wilson                # of get_property depending on the query. These queries
3930f35983dSAnthony Wilson                # return 'i VALUE' formatted strings.
394b2398200SPatrick Williams                STATE=$(get_property "$SERVICE" $OBJECT $INTERFACE $property \
3950f35983dSAnthony Wilson                    | sed 's/i[ ^I]*//')
396b2398200SPatrick Williams                printf "%s = %s\n" $property "$STATE"
3970f35983dSAnthony Wilson            done
3980f35983dSAnthony Wilson            ;;
399189cf248SAnthony Wilson        chassiskill)
400189cf248SAnthony Wilson            /usr/libexec/chassiskill
401189cf248SAnthony Wilson            ;;
402a65d30d1SVishwanatha Subbanna        hostrebootoff)
4036d3a2c54SVishwanatha Subbanna            OBJECT=$CONTROL_OBJECT/host0/auto_reboot
4046d3a2c54SVishwanatha Subbanna            SERVICE=$(mapper get-service $OBJECT)
4056d3a2c54SVishwanatha Subbanna            INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy
4066d3a2c54SVishwanatha Subbanna            PROPERTY=AutoReboot
4076d3a2c54SVishwanatha Subbanna            VALUE=false
408b2398200SPatrick Williams            set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE
4096d3a2c54SVishwanatha Subbanna            ;;
4103191be88SAndrew Geissler        hostrebootoffonetime)
4113191be88SAndrew Geissler            OBJECT=$CONTROL_OBJECT/host0/auto_reboot/one_time
4123191be88SAndrew Geissler            SERVICE=$(mapper get-service $OBJECT)
4133191be88SAndrew Geissler            INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy
4143191be88SAndrew Geissler            PROPERTY=AutoReboot
4153191be88SAndrew Geissler            VALUE=false
416b2398200SPatrick Williams            set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE
4173191be88SAndrew Geissler        ;;
418a65d30d1SVishwanatha Subbanna        hostrebooton)
4196d3a2c54SVishwanatha Subbanna            OBJECT=$CONTROL_OBJECT/host0/auto_reboot
4206d3a2c54SVishwanatha Subbanna            SERVICE=$(mapper get-service $OBJECT)
4216d3a2c54SVishwanatha Subbanna            INTERFACE=$CONTROL_INTERFACE.Boot.RebootPolicy
4226d3a2c54SVishwanatha Subbanna            PROPERTY=AutoReboot
4236d3a2c54SVishwanatha Subbanna            VALUE=true
424b2398200SPatrick Williams            set_property "$SERVICE" $OBJECT $INTERFACE $PROPERTY "b" $VALUE
4256d3a2c54SVishwanatha Subbanna            ;;
426a65d30d1SVishwanatha Subbanna        bmcrebootoff)
427a65d30d1SVishwanatha Subbanna            disable_bmc_reboot
428a65d30d1SVishwanatha Subbanna            ;;
429a65d30d1SVishwanatha Subbanna        bmcrebooton)
430a65d30d1SVishwanatha Subbanna            enable_bmc_reboot
431a65d30d1SVishwanatha Subbanna            ;;
4327a787dd7SVishwanatha Subbanna        recoveryoff)
433a65d30d1SVishwanatha Subbanna            handle_cmd hostrebootoff
434a65d30d1SVishwanatha Subbanna            handle_cmd bmcrebootoff
4357a787dd7SVishwanatha Subbanna            mask_systemd_target $HOST_TIMEOUT_TARGET
43684b3b29eSVishwanatha Subbanna            mask_systemd_target $HOST_CRASH_TARGET
4377a787dd7SVishwanatha Subbanna            ;;
4387a787dd7SVishwanatha Subbanna        recoveryon)
439a65d30d1SVishwanatha Subbanna            handle_cmd hostrebooton
440a65d30d1SVishwanatha Subbanna            handle_cmd bmcrebooton
4417a787dd7SVishwanatha Subbanna            unmask_systemd_target $HOST_TIMEOUT_TARGET
44284b3b29eSVishwanatha Subbanna            unmask_systemd_target $HOST_CRASH_TARGET
4437a787dd7SVishwanatha Subbanna            ;;
4443b7b5619SAndrew Geissler        listbootblock)
4453b7b5619SAndrew Geissler            blockingErrors=$(check_boot_block_errors)
4463b7b5619SAndrew Geissler            if [ -z "$blockingErrors" ]; then
4473b7b5619SAndrew Geissler                echo "No blocking errors present"
4483b7b5619SAndrew Geissler            else
4493b7b5619SAndrew Geissler                echo "$blockingErrors"
4503b7b5619SAndrew Geissler            fi
4513b7b5619SAndrew Geissler            ;;
452295ee4fbSAndrew Geissler        listlogs)
453295ee4fbSAndrew Geissler            list_logs
454295ee4fbSAndrew Geissler            ;;
455d8c63204SAndrew Geissler        showlog)
456b2398200SPatrick Williams            show_log "$2"
457d8c63204SAndrew Geissler            ;;
45842f2898dSAndrew Geissler        deletelogs)
45942f2898dSAndrew Geissler            delete_logs
46042f2898dSAndrew Geissler            ;;
461*ad1afe58SAndrew Geissler        stopofftargets)
462*ad1afe58SAndrew Geissler            stop_off_targets
463*ad1afe58SAndrew Geissler            ;;
46479f697e0SAnthony Wilson        *)
465ea87db40SAnthony Wilson            print_usage_err "Invalid command '$1'"
46679f697e0SAnthony Wilson            ;;
46779f697e0SAnthony Wilson    esac
46879f697e0SAnthony Wilson}
46979f697e0SAnthony Wilson
470d8779cd8SAndrew Geisslershiftcnt=0
471ea87db40SAnthony Wilsonfor arg in "$@"; do
472ea87db40SAnthony Wilson    case $arg in
473acf54d08SAnthony Wilson        -w|--wait)
474acf54d08SAnthony Wilson            G_WAIT=30
475d8779cd8SAndrew Geissler            shiftcnt=$((shiftcnt+1))
476acf54d08SAnthony Wilson            continue
477acf54d08SAnthony Wilson            ;;
478ea87db40SAnthony Wilson        -h|--help)
479ea87db40SAnthony Wilson            print_help
480ea87db40SAnthony Wilson            ;;
48160c3ac8cSAndrew Jeffery        -v|--verbose)
48260c3ac8cSAndrew Jeffery            G_VERBOSE=y
483d8779cd8SAndrew Geissler            shiftcnt=$((shiftcnt+1))
48460c3ac8cSAndrew Jeffery            ;;
485ea87db40SAnthony Wilson        -*)
486ea87db40SAnthony Wilson            print_usage_err "Unknown option: $arg"
487ea87db40SAnthony Wilson            ;;
488ea87db40SAnthony Wilson        *)
489acf54d08SAnthony Wilson            G_ORIG_CMD=$arg
490d8779cd8SAndrew Geissler            # shift out the optional parameters
491d8779cd8SAndrew Geissler            shift $shiftcnt
492d8c63204SAndrew Geissler            # pass all arguments to handle_cmd in case command takes additional
493d8c63204SAndrew Geissler            # parameters
494d8c63204SAndrew Geissler            handle_cmd "$@"
495ea87db40SAnthony Wilson            break
496ea87db40SAnthony Wilson            ;;
497ea87db40SAnthony Wilson    esac
498ea87db40SAnthony Wilsondone
499