bare-metal-host-monitor: Add dbus configurations
Currently, the dbus service name, object, and property are all
hard-coded, but we need to be able to configure these dbus details for
different platforms. This commit introduces some meson build options for
this purpose. The default values can be overridden in a bbappend file.
Tested:
Set the bare metal flag /var/google/config-package/enable-bm.flag
Power cycled the machine, and confirmed that host-gpio-monitor@1.service
and host-gpio-monitor@2.service started.
Rebooted host 2, and confirmed this message showed up:
<6> Post Complete state is InReset
Change-Id: I100ed2e450dbedf52565e0f35f50edba229ef800
Signed-off-by: John Wedig <johnwedig@google.com>
diff --git a/subprojects/bare-metal-host-monitor/host_gpio_monitor.cpp b/subprojects/bare-metal-host-monitor/host_gpio_monitor.cpp
index 5deea2a..2a32f31 100644
--- a/subprojects/bare-metal-host-monitor/host_gpio_monitor.cpp
+++ b/subprojects/bare-metal-host-monitor/host_gpio_monitor.cpp
@@ -2,6 +2,8 @@
#include "absl/flags/flag.h"
#include "absl/flags/parse.h"
+#include "host_gpio_monitor_conf.hpp"
+
#include <boost/asio/io_context.hpp>
#include <boost/asio/steady_timer.hpp>
#include <phosphor-logging/lg2.hpp>
@@ -15,14 +17,6 @@
ABSL_FLAG(std::string, host_label, "0",
"Label for the host in question. Usually this is an integer.");
-const constexpr char* OperatingSystemService =
- "xyz.openbmc_project.State.OperatingSystem{}";
-const constexpr char* OperatingSystemPath = "/xyz/openbmc_project/state/os";
-const constexpr char* OperatingSystemStatusInterface =
- "xyz.openbmc_project.State.OperatingSystem.Status";
-const constexpr char* OperatingSystemStateProperty = "OperatingSystemState";
-const constexpr char* OperatingSystemStateStandby =
- "xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Standby";
const constexpr char* OperatingSystemStateInactive =
"xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive";
const constexpr char* BareMetalActiveTargetTemplate =
@@ -50,9 +44,9 @@
const std::string& host_instance)
{
sdbusplus::asio::getProperty<std::string>(
- bus, std::format(OperatingSystemService, host_instance),
- OperatingSystemPath, OperatingSystemStatusInterface,
- OperatingSystemStateProperty,
+ bus, std::format(DBUS_SERVICE_NAME, host_instance),
+ std::format(DBUS_OBJECT_PATH, host_instance), DBUS_INTERFACE,
+ DBUS_PROPERTY_NAME,
[&, state, action](const boost::system::error_code& ec,
const std::string& postCompleteState) {
if (ec)
@@ -65,9 +59,10 @@
postCompleteState);
/*
- * If state is Standby, enable the bare-metal-active systemd
- * target.
- * If state is Inactive, no-op cause IPMI is enabled by default.
+ * If the host OS is running (e.g. OperatingSystemState is Standby),
+ * enable the bare-metal-active systemd target.
+ * If the host CPU is in reset (e.g. OperatingSystemState is
+ * Inactive), no-op cause IPMI is enabled by default.
*/
if (postCompleteState == state)
{
@@ -80,14 +75,16 @@
void checkPostCompleteStartup(sdbusplus::asio::connection& bus,
const std::string& host_instance)
{
- checkPostComplete(bus, OperatingSystemStateStandby, true, host_instance);
+ checkPostComplete(bus, DBUS_PROPERTY_HOST_RUNNING_VALUE, true,
+ host_instance);
}
/* Gets called when a GPIO state change is detected. */
void checkPostCompleteEvent(sdbusplus::asio::connection& bus,
const std::string& host_instance)
{
- checkPostComplete(bus, OperatingSystemStateInactive, false, host_instance);
+ checkPostComplete(bus, DBUS_PROPERTY_HOST_IN_RESET_VALUE, false,
+ host_instance);
}
int main(int argc, char** argv)
@@ -108,12 +105,18 @@
*/
boost::asio::steady_timer filterTimer(io);
+ /*
+ * Prepare object path we want to monitor, substituting in the host
+ * label, if needed.
+ */
+ std::string objectPath = std::format(DBUS_OBJECT_PATH, host_label);
+
auto match = std::make_unique<sdbusplus::bus::match_t>(
static_cast<sdbusplus::bus_t&>(conn),
std::format(
"type='signal',member='PropertiesChanged',path_namespace='"
- "/xyz/openbmc_project/state/os',arg0namespace='{}'",
- OperatingSystemStatusInterface),
+ "{}',arg0namespace='{}'",
+ objectPath, DBUS_INTERFACE),
[&](sdbusplus::message_t& message) {
if (message.is_method_error())
{
diff --git a/subprojects/bare-metal-host-monitor/meson.build b/subprojects/bare-metal-host-monitor/meson.build
index 51f6268..d60f308 100644
--- a/subprojects/bare-metal-host-monitor/meson.build
+++ b/subprojects/bare-metal-host-monitor/meson.build
@@ -16,6 +16,7 @@
'host_gpio_monitor',
'host_gpio_monitor.cpp',
implicit_include_directories: false,
+ include_directories : include_directories('.'),
dependencies: [
dependency('stdplus'),
dependency('phosphor-logging'),
@@ -37,3 +38,25 @@
install_mode: 'rw-r--r--',
install_dir: systemunitdir,
)
+
+# Set up config file with the dbus information that needs to be monitored.
+conf_data = configuration_data()
+conf_data.set_quoted(
+ 'DBUS_SERVICE_NAME',
+ get_option('host_monitor_service_name')
+)
+conf_data.set_quoted('DBUS_OBJECT_PATH', get_option('host_monitor_object_path'))
+conf_data.set_quoted('DBUS_INTERFACE', get_option('host_monitor_interface'))
+conf_data.set_quoted('DBUS_PROPERTY_NAME', get_option('host_monitor_property'))
+conf_data.set_quoted(
+ 'DBUS_PROPERTY_HOST_IN_RESET_VALUE',
+ get_option('host_monitor_host_in_reset_value')
+)
+conf_data.set_quoted(
+ 'DBUS_PROPERTY_HOST_RUNNING_VALUE',
+ get_option('host_monitor_host_running_value')
+)
+configure_file(
+ output: 'host_gpio_monitor_conf.hpp',
+ configuration: conf_data
+)
diff --git a/subprojects/bare-metal-host-monitor/meson_options.txt b/subprojects/bare-metal-host-monitor/meson_options.txt
new file mode 100644
index 0000000..43267b6
--- /dev/null
+++ b/subprojects/bare-metal-host-monitor/meson_options.txt
@@ -0,0 +1,36 @@
+option(
+ 'host_monitor_service_name',
+ type: 'string',
+ value: 'xyz.openbmc_project.State.OperatingSystem{}',
+ description: 'Dbus service to monitor. Use {} in string if host number needs to be inserted'
+)
+option(
+ 'host_monitor_object_path',
+ type: 'string',
+ value: '/xyz/openbmc_project/state/os',
+ description: 'Dbus object path to monitor. Use {} in string if host number needs to be inserted'
+)
+option(
+ 'host_monitor_interface',
+ type: 'string',
+ value: 'xyz.openbmc_project.State.OperatingSystem.Status',
+ description: 'Dbus interface, where the monitored property is located.',
+)
+option(
+ 'host_monitor_property',
+ type: 'string',
+ value: 'OperatingSystemState',
+ description: 'Dbus property to monitor',
+)
+option(
+ 'host_monitor_host_in_reset_value',
+ type: 'string',
+ value: 'xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Inactive',
+ description: 'Dbus property value that indicates the host is in reset',
+)
+option(
+ 'host_monitor_host_running_value',
+ type: 'string',
+ value: 'xyz.openbmc_project.State.OperatingSystem.Status.OSStatus.Standby',
+ description: 'Dbus property value that indicates the host OS is running',
+)