summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/configuration/entity-manager/0002-Entity-manager-Add-support-to-update-assetTag.patch
blob: 12a0ce5ca27e993457902a19a5eafabc48a39e53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
From 31f3f766c9c6cc6c0b7c722030dbbf6de65b7e2f Mon Sep 17 00:00:00 2001
From: mansijos <mansi.joshi@intel.com>
Date: Mon, 3 Jan 2022 19:44:09 +0000
Subject: [PATCH] Entity-manager: Add support to update assetTag

Asset tag is an updateable property from User level interface like
Redfish. User-level interface will update Asset tag in entity-manager,
which will further update the needed FRU interface property exposed.

Tested:
Successfully updated in assetTag interface as well as in fru interface
while using set-property and using redfish as well.
The new value is preserved after BMC resets.

Signed-off-by: mansijos <mansi.joshi@intel.com>
---
 src/EntityManager.cpp | 83 ++++++++++++++++++++++++++++++++++++++++---
 src/PerformScan.cpp   | 11 ++++++
 2 files changed, 90 insertions(+), 4 deletions(-)

diff --git a/src/EntityManager.cpp b/src/EntityManager.cpp
index d327f2b..5fade71 100644
--- a/src/EntityManager.cpp
+++ b/src/EntityManager.cpp
@@ -51,6 +51,13 @@ constexpr const char* currentConfiguration = "/var/configuration/system.json";
 constexpr const char* globalSchema = "global.json";
 constexpr const bool debug = false;
 
+using foundProbeData = std::map<std::string, std::string>;
+static foundProbeData foundData;
+static std::map<std::string, foundProbeData> mapFoundData;
+
+constexpr const char* fruConn = "xyz.openbmc_project.FruDevice";
+constexpr const char* fruIntf = "xyz.openbmc_project.FruDevice";
+
 const boost::container::flat_map<const char*, probe_type_codes, CmpStr>
     probeTypes{{{"FALSE", probe_type_codes::FALSE_T},
                 {"TRUE", probe_type_codes::TRUE_T},
@@ -205,6 +212,43 @@ void addArrayToDbus(const std::string& name, const nlohmann::json& array,
     }
 }
 
+template <typename PropertyType>
+bool persistAssetTag(const PropertyType& newVal,
+                     const std::string& jsonPointerString)
+{
+    std::size_t found = jsonPointerString.find_last_of("/\\");
+    std::string jsonPointerPath = jsonPointerString.substr(0, found);
+
+    auto it = mapFoundData.find(jsonPointerPath);
+    if (it == mapFoundData.end())
+    {
+        std::cerr << "Error in finding jsonPointerPath in mapFoundData"
+                  << "\n";
+        return false;
+    }
+
+    foundProbeData& tmpMap = it->second;
+    auto foundPath = tmpMap.find("foundPath");
+    if (foundPath == tmpMap.end())
+    {
+        std::cerr << "No prob object data is avaliable in foundProbeData"
+                  << "\n";
+        return false;
+    }
+
+    systemBus->async_method_call(
+        [](const boost::system::error_code& ec) {
+            if (ec)
+            {
+                std::cerr << "Error setting AssetTag in FRU interface " << ec
+                          << "\n";
+            }
+        },
+        fruConn, foundPath->second, "org.freedesktop.DBus.Properties", "Set",
+        fruIntf, "PRODUCT_ASSET_TAG", std::variant<PropertyType>(newVal));
+    return true;
+}
+
 template <typename PropertyType>
 void addProperty(const std::string& propertyName, const PropertyType& value,
                  sdbusplus::asio::dbus_interface* iface,
@@ -219,9 +263,18 @@ void addProperty(const std::string& propertyName, const PropertyType& value,
     }
     iface->register_property(
         propertyName, value,
-        [&systemConfiguration,
+        [propertyName, &systemConfiguration,
          jsonPointerString{std::string(jsonPointerString)}](
             const PropertyType& newVal, PropertyType& val) {
+            if (propertyName == "AssetTag")
+            {
+                if (!persistAssetTag(newVal, jsonPointerString))
+                {
+                    std::cerr << "error setting AssetTag in FRU interface\n";
+                    return -1;
+                }
+            }
+
             val = newVal;
             if (!setJsonFromPointer(jsonPointerString, val,
                                     systemConfiguration))
@@ -621,6 +674,9 @@ void postToDbus(const nlohmann::json& newConfiguration,
         populateInterfaceFromJson(systemConfiguration, jsonPointerPath,
                                   boardIface, boardValues, objServer);
         jsonPointerPath += "/";
+
+        std::string foundPath;
+
         // iterate through board properties
         for (auto& boardField : boardValues.items())
         {
@@ -630,9 +686,28 @@ void postToDbus(const nlohmann::json& newConfiguration,
                     createInterface(objServer, boardName, boardField.key(),
                                     boardKeyOrig);
 
-                populateInterfaceFromJson(systemConfiguration,
-                                          jsonPointerPath + boardField.key(),
-                                          iface, boardField.value(), objServer);
+                if (boardField.key() == "FoundProbe")
+                {
+                    foundPath = boardField.value()["Path"];
+                }
+                if (boardField.key() ==
+                    "xyz.openbmc_project.Inventory.Decorator.AssetTag")
+                {
+                    foundData["foundPath"] = foundPath;
+                    mapFoundData[jsonPointerPath + boardField.key()] =
+                        foundData;
+
+                    populateInterfaceFromJson(
+                        systemConfiguration, jsonPointerPath + boardField.key(),
+                        iface, boardField.value(), objServer,
+                        sdbusplus::asio::PropertyPermission::readWrite);
+                }
+                else
+                {
+                    populateInterfaceFromJson(
+                        systemConfiguration, jsonPointerPath + boardField.key(),
+                        iface, boardField.value(), objServer);
+                }
             }
         }
 
diff --git a/src/PerformScan.cpp b/src/PerformScan.cpp
index 5978710..5261ef7 100644
--- a/src/PerformScan.cpp
+++ b/src/PerformScan.cpp
@@ -38,6 +38,8 @@ constexpr const int32_t maxMapperDepth = 0;
 
 constexpr const bool debug = false;
 
+constexpr const char* foundObject = "FoundProbe";
+
 void getInterfaces(
     const std::tuple<std::string, std::string, std::string>& call,
     const std::vector<std::shared_ptr<PerformProbe>>& probeVector,
@@ -359,6 +361,11 @@ void PerformScan::run()
                             {
                                 continue; // non-numeric replacement
                             }
+
+                            nlohmann::json recordVal = *recordPtr;
+                            // Save the dbus path info of the device
+                            recordVal[foundObject]["Path"] = std::get<1>(*itr);
+
                             usedNames.insert(nameIt.value());
                             auto usedIt = std::find(indexes.begin(),
                                                     indexes.end(), index);
@@ -436,6 +443,10 @@ void PerformScan::run()
                         }
                     }
 
+                    // Save the dbus path info of the device
+                    record[foundObject]["Path"] =
+                        std::get<1>(foundDeviceAndPath);
+
                     if (replaceStr)
                     {
                         std::cerr << "Duplicates found, replacing "
-- 
2.17.1