summaryrefslogtreecommitdiff
path: root/meta-openbmc-mods/meta-common/recipes-phosphor/configuration/entity-manager/0002-Entity-manager-Add-support-to-update-assetTag.patch
blob: 0fea3e8a0947cf87b7b33eeffa231a1e6b7e19d1 (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
From 0941036f4206d74bfc3d3e505a5d269fb39c48ff Mon Sep 17 00:00:00 2001
From: mansijos <mansi.joshi@intel.com>
Date: Tue, 6 Apr 2021 02:12:56 +0530
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.

Change-Id: If7fbfd8325488280f500ab0e2c8b38475813cc3f
Signed-off-by: mansijos <mansi.joshi@intel.com>
---
 src/EntityManager.cpp | 95 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 91 insertions(+), 4 deletions(-)

diff --git a/src/EntityManager.cpp b/src/EntityManager.cpp
index 490c0f5..139ba9a 100644
--- a/src/EntityManager.cpp
+++ b/src/EntityManager.cpp
@@ -48,9 +48,19 @@ constexpr const char* lastConfiguration = "/tmp/configuration/last.json";
 constexpr const char* currentConfiguration = "/var/configuration/system.json";
 constexpr const char* globalSchema = "global.json";
 constexpr const int32_t maxMapperDepth = 0;
+constexpr const char* foundObject = "FoundProbe";
 
 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";
+
 struct CmpStr
 {
     bool operator()(const char* a, const char* b) const
@@ -577,6 +587,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,
@@ -591,9 +638,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))
@@ -993,6 +1049,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())
         {
@@ -1002,9 +1061,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);
+                }
             }
         }
 
@@ -1362,6 +1440,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);
@@ -1439,6 +1522,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