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