[Skiboot] [PATCH] opal-prd: display explicit message on IBM Power systems

Cédric Le Goater clg at fr.ibm.com
Wed Nov 11 04:48:14 AEDT 2015


Today, when run on an IBM Power systems, opal-prd complains in syslog
with a set of messages similar to these :

	opal-prd: CTRL: Starting PRD daemon
	opal-prd: I2C: Found Chip: 00000000 engine 1 port 0
	opal-prd: I2C: Found Chip: 00000010 engine 1 port 0
	opal-prd: CTRL: Listening on control socket /run/opal-prd-control
	opal-prd: FW: Can't open PRD device /dev/opal-prd: No such file or directory
	opal-prd: FW: Error initialising PRD channel
	opal-prd: CTRL: stopping PRD daemon

Which are difficult to interpret for a person not initiated to power
firmware.

The patch below detects if the platform is an IBM or an Open Power
system by looking at the device tree property :

	/sys/firmware/devicetree/base/compatible

and stops opal-prd early in the main routine with an explicit
message for the user.

Signed-off-by: Cédric Le Goater <clg at fr.ibm.com>
---
 external/opal-prd/opal-prd.c |   61 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 61 insertions(+)

Index: skiboot.git/external/opal-prd/opal-prd.c
===================================================================
--- skiboot.git.orig/external/opal-prd/opal-prd.c
+++ skiboot.git/external/opal-prd/opal-prd.c
@@ -50,6 +50,8 @@
 #include <opal-api.h>
 #include <types.h>
 
+#include <ccan/array_size/array_size.h>
+
 #include "opal-prd.h"
 #include "hostboot-interface.h"
 #include "module.h"
@@ -1032,6 +1034,60 @@ out_free:
 	return rc;
 }
 
+bool find_string(const char *buffer, size_t len, const char *s)
+{
+	const char *c, *end;
+
+	if (!buffer)
+		return false;
+	c = buffer;
+	end = c + len;
+
+	while (c < end) {
+		if (!strcasecmp(s, c))
+			return true;
+		c += strlen(c) + 1;
+	}
+	return false;
+}
+
+static const char * const openpower_systems[] = {
+	"ibm,firestone", "tyan,habanero", "tyan,palmetto"
+};
+
+static int is_openpower(void)
+{
+	char *path;
+	int rc;
+	int len;
+	char *buf;
+	int i;
+
+	rc = asprintf(&path, "%s/compatible", devicetree_base);
+	if (rc < 0) {
+		pr_log(LOG_ERR, "FW: error creating 'compatible' node path: %m");
+		return -1;
+	}
+
+	rc = open_and_read(path, (void *) &buf, &len);
+	if (rc)
+		goto out_free;
+
+	if (buf[len - 1] != '\0')
+		pr_log(LOG_INFO, "FW: node %s is not nul-terminated", path);
+
+	for (i = 0; i < ARRAY_SIZE(openpower_systems); i++) {
+		if (find_string(buf, len, openpower_systems[i]))
+			break;
+	}
+
+	if (i == ARRAY_SIZE(openpower_systems))
+		rc = -1;
+out_free:
+	free(buf);
+	return rc;
+}
+
 static int prd_init(struct opal_prd_ctx *ctx)
 {
 	int rc;
@@ -1963,6 +2019,11 @@ int main(int argc, char *argv[])
 		action = ACTION_RUN_DAEMON;
 	}
 
+	if (is_openpower() < 0) {
+		pr_log(LOG_ERR, "CTRL: Can't run PRD commands on an IBM Power system");
+		return -1;
+	}
+
 	switch (action) {
 	case ACTION_RUN_DAEMON:
 		rc = run_prd_daemon(ctx);



More information about the Skiboot mailing list