| #!/bin/bash |
| |
| HELP_MSG=" |
| Usage: power-rail-event-logger <event> <id_gpio-name> |
| <event> is the power rail event to log, |
| e.g. assert / deassert. |
| |
| <id_gpio-name> is defined in json file, |
| e.g. 2_power-host-good |
| " |
| |
| if [ "$#" -ne 2 ]; then |
| echo "$HELP_MSG" |
| exit 1 |
| fi |
| |
| message="$2" |
| ASSERT_MSG_ID="xyz.openbmc_project.State.Power.PowerRailFault" |
| DEASSERT_MSG_ID="xyz.openbmc_project.State.Power.PowerRailFaultRecovered" |
| |
| # Extract board name and gpio name from the message amd build device path |
| # Supported message formats: |
| # 1. <board_name>_<gpio_name> |
| # Example: pdb_ABC |
| # Device path: /xyz/openbmc_project/inventory/system/board/Yosemite5_Medusa_Board/ABC |
| board="${message%%_*}" |
| gpio_name="${message#*_}" |
| |
| if [[ $board == pdb* ]]; then |
| device_path="/xyz/openbmc_project/inventory/system/board/Yosemite5_Medusa_Board/${gpio_name}" |
| elif [[ $board == mb* ]]; then |
| device_path="/xyz/openbmc_project/inventory/system/board/Yosemite5_MB/${gpio_name}" |
| else |
| echo "Unknown message format: $message" |
| exit 1 |
| fi |
| |
| stash_file="/run/${gpio_name}.log_entry" |
| |
| |
| case "$1" in |
| "assert") |
| if [ ! -s "$stash_file" ]; then |
| /usr/bin/log-create "$ASSERT_MSG_ID" --json \ |
| "{ \"POWER_RAIL\": \"${device_path}\", \"FAILURE_DATA\": \"${gpio_name}\"}" \ |
| > "${stash_file}" |
| fi |
| ;; |
| |
| "deassert") |
| # If the stash file exists, resolve the log entry and remove the stash file |
| if [ -s "${stash_file}" ]; then |
| log-resolve -p "$(< "${stash_file}")" && rm "${stash_file}" |
| fi |
| # Always create a deassert log entry |
| /usr/bin/log-create "$DEASSERT_MSG_ID" --json \ |
| "{ \"POWER_RAIL\": \"${device_path}\"}" |
| ;; |
| |
| *) |
| echo "Not supported event: $1" |
| echo "$HELP_MSG" |
| exit 1 |
| ;; |
| esac |
| |
| exit 0 |