service: device-tree node vpd to d-bus hw id data
A daemon for transferring Viable Product Data (VPD) from device-tree
nodes to D-Bus as described in the design doc @
https://gerrit.openbmc.org/c/openbmc/docs/+/66369
and discussed in this Technical Oversight Forum topic @
https://github.com/openbmc/technical-oversight-forum/issues/38
Tested:
Ensure 'model' and/or 'serial-number' nodes are populated in
/proc/device-tree. Can be hardcoded into platform DTS via
linux-kernel recipe if needed.
'''
After OBMC boot, calling
> busctl introspect xyz.openbmc_project.MachineContext /xyz/openbmc_project/MachineContext
produces the following output:
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
...
xyz.openbmc_project.Inventory.Decorator.Asset interface - - -
.BuildDate property s "" emits-change writable
.Manufacturer property s "" emits-change writable
.Model property s "hpe,dl360" emits-change writable
.PartNumber property s "" emits-change writable
.SerialNumber property s "t5texpl" emits-change writable
...
Note: Writing to one of these properties will update the property on D-Bus without affecting the
underlying device-tree node. An 'updated' event will be fired, so Entity-Manager probes monitoring
a given property would recognize the new value and key off it.
'''
Change-Id: Id52d1fc3b26010c864c7e64d3dfdf0a2b5de9294
Signed-off-by: Chris Sides <Christopher.Sides@hpe.com>
diff --git a/.gitignore b/.gitignore
index b7c3a2c..6be2471 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,5 @@
build*/*
subprojects/*
!subprojects/*.wrap
-subprojects/phosphor-dbus-interfaces.wrap
!subprojects/.clang-tidy
!subprojects/.clang-format
diff --git a/meson.build b/meson.build
index dfef6dd..4c76439 100644
--- a/meson.build
+++ b/meson.build
@@ -34,6 +34,10 @@
i2c = cpp.find_library('i2c')
endif
+if get_option('devicetree-vpd')
+ phosphor_dbus_interfaces_dep = dependency('phosphor-dbus-interfaces', include_type: 'system')
+endif
+
nlohmann_json_dep = dependency('nlohmann_json', include_type: 'system')
sdbusplus = dependency('sdbusplus', include_type: 'system')
phosphor_logging_dep = dependency('phosphor-logging')
diff --git a/meson_options.txt b/meson_options.txt
index ad9f7ed..d81ab9c 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -2,11 +2,14 @@
'tests', type: 'feature', description: 'Build tests.',
)
option(
- 'fru-device', type: 'boolean', description: 'Build fru-device.',
+ 'fru-device', type: 'boolean', description: 'Build fru-device VPD parser.',
)
option(
'fru-device-resizefru', value : false, type: 'boolean', description: 'Allow FruDevice to resize FRU areas.',
)
option(
+ 'devicetree-vpd', type: 'boolean', description: 'Build device-tree VPD parser'
+)
+option(
'validate-json', type: 'boolean', value: true, description: 'Run JSON schema validation during the build.',
)
diff --git a/service_files/devicetree-vpd-parser.service b/service_files/devicetree-vpd-parser.service
new file mode 100644
index 0000000..4a5ff19
--- /dev/null
+++ b/service_files/devicetree-vpd-parser.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Makes data from device-tree nodes avaliable thru D-Bus
+After=dbus.service
+
+[Service]
+ExecStart=/usr/libexec/entity-manager/devicetree-vpd-parser
+Type=dbus
+BusName=xyz.openbmc_project.MachineContext
+
+[Install]
+WantedBy=basic.target
diff --git a/service_files/meson.build b/service_files/meson.build
index 30d8377..c145401 100644
--- a/service_files/meson.build
+++ b/service_files/meson.build
@@ -1,6 +1,7 @@
unit_files = [
['xyz.openbmc_project.FruDevice.service', 'fru-device'],
['xyz.openbmc_project.EntityManager.service', ''],
+ ['devicetree-vpd-parser.service', 'devicetree-vpd'],
]
foreach u : unit_files
diff --git a/src/devicetree_vpd_parser.cpp b/src/devicetree_vpd_parser.cpp
new file mode 100644
index 0000000..87bd2d7
--- /dev/null
+++ b/src/devicetree_vpd_parser.cpp
@@ -0,0 +1,44 @@
+#include "machine_context.hpp"
+
+#include <memory>
+
+int main()
+{
+ static constexpr auto reqDBusPath = "/xyz/openbmc_project/MachineContext";
+ static constexpr auto reqDBusName = "xyz.openbmc_project.MachineContext";
+
+ /*Note: OpenBMC convention typically has service name = bus name,
+ where the bus name is representative of the underlying hardware.
+
+ In the case of MachineContext, the BMC is not gathering data from
+ specific hardware, but is instead parsing device-tree nodes for
+ context about the hardware OpenBMC is running on.
+
+ Because the VPD data being parsed is coming from device-tree,
+ the daemon and matching service name reflect that.
+
+ Because the parsed data represents 'machine context' data,
+ the bus name and associated path the daemon writes to
+ reflects that instead.
+ */
+
+ sdbusplus::async::context ctx;
+ sdbusplus::server::manager_t manager{ctx, reqDBusPath};
+
+ std::unique_ptr<MachineContext> mc = nullptr;
+ if (MachineContext::keyNodeExists())
+ {
+ mc = std::make_unique<MachineContext>(ctx, reqDBusPath);
+ mc->populateFromDeviceTree();
+ }
+
+ // NOLINTNEXTLINE(readability-static-accessed-through-instance)
+ ctx.spawn([](sdbusplus::async::context& ctx) -> sdbusplus::async::task<> {
+ ctx.request_name(reqDBusName);
+ co_return;
+ }(ctx));
+
+ ctx.run();
+
+ return 0;
+};
diff --git a/src/machine_context.cpp b/src/machine_context.cpp
new file mode 100644
index 0000000..6f2c956
--- /dev/null
+++ b/src/machine_context.cpp
@@ -0,0 +1,45 @@
+/*
+// Copyright (c) 2024 Hewlett Packard Enterprise
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#include "machine_context.hpp"
+
+#include <filesystem>
+#include <fstream>
+
+void MachineContext::populateFromDeviceTree()
+{
+ std::string nodeVal;
+ std::ifstream vpdStream(nodeBasePath + std::string("model"));
+ if (vpdStream && std::getline(vpdStream, nodeVal))
+ {
+ MachineContext::Asset::model(nodeVal);
+ vpdStream.close();
+ }
+
+ vpdStream.open(nodeBasePath + std::string("serial-number"));
+ if (vpdStream && std::getline(vpdStream, nodeVal))
+ {
+ MachineContext::Asset::serial_number(nodeVal);
+ vpdStream.close();
+ }
+};
+
+bool MachineContext::keyNodeExists()
+{
+ std::filesystem::path nodePath{nodeBasePath + std::string("model")};
+
+ return std::filesystem::exists(nodePath);
+};
diff --git a/src/machine_context.hpp b/src/machine_context.hpp
new file mode 100644
index 0000000..fca2a33
--- /dev/null
+++ b/src/machine_context.hpp
@@ -0,0 +1,37 @@
+/*
+// Copyright (c) 2024 Hewlett Packard Enterprise
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
+
+#pragma once
+
+#include <sdbusplus/async.hpp>
+#include <xyz/openbmc_project/Inventory/Decorator/Asset/aserver.hpp>
+
+class MachineContext :
+ public sdbusplus::aserver::xyz::openbmc_project::inventory::decorator::
+ Asset<MachineContext>
+{
+ public:
+ explicit MachineContext(sdbusplus::async::context& ctx, auto path) :
+ sdbusplus::aserver::xyz::openbmc_project::inventory::decorator::Asset<
+ MachineContext>(ctx, path) {};
+
+ void populateFromDeviceTree();
+
+ static bool keyNodeExists();
+
+ private:
+ static constexpr auto nodeBasePath = "/proc/device-tree/";
+};
diff --git a/src/meson.build b/src/meson.build
index 6565efc..00b006f 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -49,3 +49,19 @@
install_dir: installdir,
)
endif
+
+if get_option('devicetree-vpd')
+ cpp_args_fd = cpp_args
+ executable(
+ 'devicetree-vpd-parser',
+ 'machine_context.cpp',
+ 'devicetree_vpd_parser.cpp',
+ cpp_args: cpp_args_fd,
+ dependencies: [
+ sdbusplus,
+ phosphor_dbus_interfaces_dep,
+ ],
+ install: true,
+ install_dir: installdir,
+ )
+endif
diff --git a/subprojects/phosphor-dbus-interfaces.wrap b/subprojects/phosphor-dbus-interfaces.wrap
new file mode 100644
index 0000000..0bf731e
--- /dev/null
+++ b/subprojects/phosphor-dbus-interfaces.wrap
@@ -0,0 +1,7 @@
+
+[wrap-git]
+url = https://github.com/openbmc/phosphor-dbus-interfaces.git
+revision = HEAD
+
+[provide]
+phosphor-dbus-interfaces = phosphor_dbus_interfaces_dep