From patchwork Fri Jul 7 09:03:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasant Hegde X-Patchwork-Id: 785395 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 ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3x3pZN4CL7z9s7B for ; Fri, 7 Jul 2017 19:04:12 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3x3pZN1ZGszDr8k for ; Fri, 7 Jul 2017 19:04:12 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3x3pZG4zFNzDr5N for ; Fri, 7 Jul 2017 19:04:06 +1000 (AEST) Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v6793vo9084716 for ; Fri, 7 Jul 2017 05:04:04 -0400 Received: from e23smtp07.au.ibm.com (e23smtp07.au.ibm.com [202.81.31.140]) by mx0a-001b2d01.pphosted.com with ESMTP id 2bj5mruqw5-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 07 Jul 2017 05:04:04 -0400 Received: from localhost by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 7 Jul 2017 19:04:01 +1000 Received: from d23relay08.au.ibm.com (202.81.31.227) by e23smtp07.au.ibm.com (202.81.31.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 7 Jul 2017 19:04:00 +1000 Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay08.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v6793x6U10486138 for ; Fri, 7 Jul 2017 19:03:59 +1000 Received: from d23av01.au.ibm.com (localhost [127.0.0.1]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v6793xN4022581 for ; Fri, 7 Jul 2017 19:03:59 +1000 Received: from hegdevasant.in.ibm.com ([9.195.46.8]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v6793umL022475; Fri, 7 Jul 2017 19:03:57 +1000 From: Vasant Hegde To: skiboot@lists.ozlabs.org Date: Fri, 7 Jul 2017 14:33:42 +0530 X-Mailer: git-send-email 2.9.3 X-TM-AS-MML: disable x-cbid: 17070709-0044-0000-0000-0000027BE1F0 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17070709-0045-0000-0000-0000070C1F92 Message-Id: <20170707090342.6167-1-hegdevasant@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-07-07_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1703280000 definitions=main-1707070151 Subject: [Skiboot] [PATCH] DT: Add ibm,firmware-versions node X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mukesh Ojha MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" In P8, hostboot provides mini device tree. It contains /ibm,firmware-versions node which has various firmware component version details. In P9, OPAL is building device tree. This patch adds support to parse VERSION section of PNOR and create "/ibm,firmware-versions" device tree node. Sample output: /sys/firmware/devicetree/base/ibm,firmware-versions # lsprop . occ "6a00709" skiboot "v5.7-rc1-p344fb62" buildroot "2017.02.2-7-g23118ce" capp-ucode "9c73e9f" petitboot "v1.4.3-p98b6d83" sbe "02021c6" open-power "witherspoon-v1.17-128-gf1b53c7-dirty" .... .... Signed-off-by: Vasant Hegde Signed-off-by: Mukesh Ojha Acked-By: Samuel Mendoza-Jonas --- core/flash.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/core/flash.c b/core/flash.c index 8a908e5..219e6e0 100644 --- a/core/flash.c +++ b/core/flash.c @@ -148,6 +148,107 @@ out: return rc; } +static void flash_dt_add_fw_version(struct dt_node *fw_version, char* data) +{ + char *prop; + int version_len, i; + int len = strlen(data); + const char * version_str[] = {"open-power", "buildroot", "skiboot", + "hostboot-binaries", "hostboot", "linux", + "petitboot", "occ", "capp-ucode", "sbe"}; + /* + * PNOR version strings are not easily consumable. Split them into + * property, value. + * + * Example input from PNOR : + * "open-power-firestone-v1.8" + * "linux-4.4.6-openpower1-8420e0f" + * + * Desired output in device tree: + * open-power = "firestone-v1.8"; + * linux = "4.4.6-openpower1-8420e0f"; + */ + for(i = 0; i < ARRAY_SIZE(version_str); i++) + { + version_len = strlen(version_str[i]); + if (len < version_len) + continue; + + if (memcmp(data, version_str[i], version_len) != 0) + continue; + + /* Found a match, add property */ + if (dt_find_property(fw_version, version_str[i])) + continue; + + /* Increment past "key-" */ + prop = data + version_len + 1; + dt_add_property_string(fw_version, version_str[i], prop); + } +} + +static int flash_fw_version_probe(struct flash *flash, struct ffs_handle *ffs) +{ + bool ecc; + char *buf; + uint8_t version_data[80]; + int rc; + int numbytes = 0, i = 0; + uint32_t start, size, part, version_size; + struct dt_node *fw_version; + + if (proc_gen < proc_gen_p9) + return 0; + + prlog(PR_INFO, "FLASH: probing for VERSION\n"); + + rc = ffs_lookup_part(ffs, "VERSION", &part); + if (rc) { + prlog(PR_WARNING, "FLASH: No VERSION partition found\n"); + return OPAL_HARDWARE; + } + + rc = ffs_part_info(ffs, part, NULL, &start, &size, NULL, &ecc); + if (rc) { + prlog(PR_WARNING, "FLASH: Can't parse ffs info for VERSION\n"); + return OPAL_HARDWARE; + } + + buf = malloc(size); + if (!buf) { + prlog(PR_WARNING, "FLASH: Failed to allocate memory\n"); + return OPAL_RESOURCE; + } + + rc = blocklevel_read(flash->bl, start, buf, size); + if (rc) { + prlog(PR_WARNING, "FLASH: Couldn't read from flash at 0x%08x " + "for len 0x%08x [rc = %d]\n", start, size, rc); + return rc; + } + + version_size = ecc ? ecc_buffer_size_minus_ecc(size) : size; + fw_version = dt_new(dt_root, "ibm,firmware-versions"); + assert(fw_version); + + for ( ; (numbytes < version_size) && buf[numbytes]; numbytes++) { + if (buf[numbytes] == '\n') { + version_data[i] = '\0'; + flash_dt_add_fw_version(fw_version, version_data); + memset(version_data, 0, sizeof(version_data)); + i = 0; + continue; + } else if (buf[numbytes] == '\t') { + continue; /* skip tabs */ + } + + version_data[i++] = buf[numbytes]; + } + + free(buf); + return 0; +} + static int flash_nvram_probe(struct flash *flash, struct ffs_handle *ffs) { uint32_t start, size, part; @@ -238,6 +339,7 @@ static void setup_system_flash(struct flash *flash, struct dt_node *node, prlog(PR_INFO, "FLASH: registered system flash device %s\n", name); + flash_fw_version_probe(flash, ffs); flash_nvram_probe(flash, ffs); }