From patchwork Tue Nov 10 17:48:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 542546 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 547F6140D9D for ; Wed, 11 Nov 2015 04:48:42 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4062B1A0371 for ; Wed, 11 Nov 2015 04:48:42 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from e06smtp08.uk.ibm.com (e06smtp08.uk.ibm.com [195.75.94.104]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id A23CB1A0272 for ; Wed, 11 Nov 2015 04:48:37 +1100 (AEDT) Received: from localhost by e06smtp08.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 10 Nov 2015 17:48:32 -0000 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp08.uk.ibm.com (192.168.101.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 10 Nov 2015 17:48:20 -0000 X-IBM-Helo: d06dlp03.portsmouth.uk.ibm.com X-IBM-MailFrom: clg@fr.ibm.com X-IBM-RcptTo: skiboot@lists.ozlabs.org Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 250221B08070 for ; Tue, 10 Nov 2015 17:48:37 +0000 (GMT) Received: from d06av08.portsmouth.uk.ibm.com (d06av08.portsmouth.uk.ibm.com [9.149.37.249]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id tAAHmKha66519152 for ; Tue, 10 Nov 2015 17:48:20 GMT Received: from d06av08.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id tAAHmJgQ005756 for ; Tue, 10 Nov 2015 10:48:20 -0700 Received: from hermes.kaod.org (sig-9-84-102-134.evts.de.ibm.com [9.84.102.134]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id tAAHmJ2w005740; Tue, 10 Nov 2015 10:48:19 -0700 From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: skiboot@lists.ozlabs.org Date: Tue, 10 Nov 2015 18:48:14 +0100 Message-Id: <1447177694-14661-1-git-send-email-clg@fr.ibm.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15111017-0033-0000-0000-000004BC95C2 Subject: [Skiboot] [PATCH] opal-prd: display explicit message on IBM Power systems X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" 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 --- 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 #include +#include + #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);