Gopichand Paturi | 24226c4 | 2024-05-16 14:51:22 -0500 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
Gopichand Paturi | 0d72381 | 2024-10-24 04:04:07 -0500 | [diff] [blame] | 3 | declare -rx TYPE_FAULTDATA="faultdata" |
Swarnendu-R-C | 1bee03b | 2024-06-13 09:21:56 -0500 | [diff] [blame^] | 4 | #Dump originator variables |
| 5 | declare -x ORIGINATOR_TYPE="" |
| 6 | declare -x ORIGINATOR_ID="" |
Gopichand Paturi | 0d72381 | 2024-10-24 04:04:07 -0500 | [diff] [blame] | 7 | |
Gopichand Paturi | 24226c4 | 2024-05-16 14:51:22 -0500 | [diff] [blame] | 8 | # @brief fetch serial number |
| 9 | # @param serial number |
| 10 | function fetch_serial_number() { |
| 11 | serialNo=$(busctl get-property xyz.openbmc_project.Inventory.Manager \ |
| 12 | /xyz/openbmc_project/inventory/system xyz.openbmc_project.Inventory.Decorator.Asset \ |
| 13 | SerialNumber | cut -d " " -f 2 | sed "s/^\(\"\)\(.*\)\1\$/\2/g") |
| 14 | |
| 15 | if [ -z "$serialNo" ]; then |
| 16 | serialNo="0000000" |
| 17 | fi |
| 18 | } |
| 19 | |
| 20 | # @brief Add BMC dump File Name |
| 21 | # @param BMC Dump File Name |
| 22 | function get_bmc_dump_filename() { |
| 23 | fetch_serial_number |
SwethaParasa | 9a39f43 | 2024-10-18 02:00:33 -0500 | [diff] [blame] | 24 | dump_id=$(printf %08d $dump_id) |
Gopichand Paturi | 24226c4 | 2024-05-16 14:51:22 -0500 | [diff] [blame] | 25 | if [ $dump_type = "$TYPE_FAULTDATA" ]; then |
| 26 | header_dump_name="FLTDUMP" |
| 27 | name="NAGDUMP.${serialNo}.${dump_id}.${dDay}" |
| 28 | else |
| 29 | header_dump_name="BMCDUMP" |
| 30 | name="BMCDUMP.${serialNo}.${dump_id}.${dDay}" |
| 31 | fi |
| 32 | } |
Swarnendu-R-C | 1bee03b | 2024-06-13 09:21:56 -0500 | [diff] [blame^] | 33 | |
| 34 | # @brief Function to get the Originator details |
| 35 | # @param Originator Type and Originator ID |
| 36 | function get_originator_details() { |
| 37 | if [ -z "$dump_dir" ]; then |
| 38 | return |
| 39 | fi |
| 40 | |
| 41 | dump_type_received="" |
| 42 | dump_entry_id="$dump_id" |
| 43 | |
| 44 | if [ "$1" = "bmc" ] || [ "$1" = "system" ]; then |
| 45 | dump_type_received="$1" |
| 46 | else |
| 47 | echo "Invalid dump type received" |
| 48 | return |
| 49 | fi |
| 50 | |
| 51 | if [ "$dump_type_received" = "bmc" ]; then |
| 52 | dump_entry_id=$(echo "$dump_entry_id" | sed "s/^0*//") |
| 53 | fi |
| 54 | |
| 55 | local DBUS_DUMP_MANAGER="xyz.openbmc_project.Dump.Manager" |
| 56 | local DBUS_DUMP_PATH="/xyz/openbmc_project/dump/$dump_type_received/entry/$dump_entry_id" |
| 57 | local DBUS_DUMP_ORIGINATOR_IFACE="xyz.openbmc_project.Common.OriginatedBy" |
| 58 | local DBUS_ORIGINATOR_TYPE_STRING="OriginatorType" |
| 59 | local DBUS_ORIGINATOR_ID_STRING="OriginatorId" |
| 60 | |
| 61 | ORIGINATOR_TYPE=$(busctl get-property "$DBUS_DUMP_MANAGER" \ |
| 62 | "$DBUS_DUMP_PATH" "$DBUS_DUMP_ORIGINATOR_IFACE" \ |
| 63 | "$DBUS_ORIGINATOR_TYPE_STRING") |
| 64 | |
| 65 | ORIGINATOR_ID=$(busctl get-property "$DBUS_DUMP_MANAGER" \ |
| 66 | "$DBUS_DUMP_PATH" "$DBUS_DUMP_ORIGINATOR_IFACE" \ |
| 67 | "$DBUS_ORIGINATOR_ID_STRING") |
| 68 | |
| 69 | # The following two lines would extract the originator type and id |
| 70 | # from the received long string in response of the above dbus calls |
| 71 | # like <s "xyz.openbmc_project.Common.OriginatedBy.OriginatorTypes.Internal"> |
| 72 | # to only <Internal> for the originator type and so on for the originator ID |
| 73 | ORIGINATOR_TYPE=$(echo "$ORIGINATOR_TYPE" | cut -d' ' -f 2 \ |
| 74 | | cut -d'.' -f 6 | cut -d'"' -f 1) |
| 75 | |
| 76 | ORIGINATOR_ID=$(echo "$ORIGINATOR_ID" | cut -d' ' -f 2 \ |
| 77 | | cut -d'"' -f 2) |
| 78 | |
| 79 | # This hash map for Originator Type is populated based on |
| 80 | # the info provided by the OriginatedBy.interface.yaml file under |
| 81 | # https://github.com/openbmc/phosphor-dbus-interfaces/ |
| 82 | # Feel free to amend the table as per the evolving requirement |
| 83 | local -A originator_type_enum_map |
| 84 | originator_type_enum_map["Client"]=0 |
| 85 | originator_type_enum_map["Internal"]=1 |
| 86 | originator_type_enum_map["SupportingService"]=2 |
| 87 | |
| 88 | local originator_type_mapped="$ORIGINATOR_TYPE" |
| 89 | # If the originator type comes something which is not known to |
| 90 | # the enum list/map then make it blank so that can be filled |
| 91 | # with null bytes in gendumpheader script and won't be |
| 92 | # breaking the dump extraction |
| 93 | ORIGINATOR_TYPE="" |
| 94 | for key in "${!originator_type_enum_map[@]}" |
| 95 | do |
| 96 | if [ "$key" = "$originator_type_mapped" ]; then |
| 97 | ORIGINATOR_TYPE="${originator_type_enum_map[$key]}" |
| 98 | break |
| 99 | fi |
| 100 | done |
| 101 | } |