From patchwork Tue Aug 29 06:24:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 806971 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 3xhJwg75llz9ryr for ; Tue, 29 Aug 2017 16:42:43 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xhJwg6FwVzDrLC for ; Tue, 29 Aug 2017 16:42:43 +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 3xhJY71989zDqfg for ; Tue, 29 Aug 2017 16:25:46 +1000 (AEST) Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7T6OEMH001439 for ; Tue, 29 Aug 2017 02:25:41 -0400 Received: from e23smtp03.au.ibm.com (e23smtp03.au.ibm.com [202.81.31.145]) by mx0a-001b2d01.pphosted.com with ESMTP id 2cmyn1webd-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 29 Aug 2017 02:25:41 -0400 Received: from localhost by e23smtp03.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 29 Aug 2017 16:25:38 +1000 Received: from d23relay09.au.ibm.com (202.81.31.228) by e23smtp03.au.ibm.com (202.81.31.209) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 29 Aug 2017 16:25:36 +1000 Received: from d23av05.au.ibm.com (d23av05.au.ibm.com [9.190.234.119]) by d23relay09.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7T6PaZj38404258 for ; Tue, 29 Aug 2017 16:25:36 +1000 Received: from d23av05.au.ibm.com (localhost [127.0.0.1]) by d23av05.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v7T6PZVp017737 for ; Tue, 29 Aug 2017 16:25:35 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av05.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v7T6PZNT017727; Tue, 29 Aug 2017 16:25:35 +1000 Received: from camb691.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) (using TLSv1.2 with cipher DHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 1AABDA0258; Tue, 29 Aug 2017 16:25:35 +1000 (AEST) From: Cyril Bur To: skiboot@lists.ozlabs.org, stewart@linux.vnet.ibm.com Date: Tue, 29 Aug 2017 16:24:55 +1000 X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170829062506.8317-1-cyril.bur@au1.ibm.com> References: <20170829062506.8317-1-cyril.bur@au1.ibm.com> X-TM-AS-MML: disable x-cbid: 17082906-0008-0000-0000-00000154A485 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17082906-0009-0000-0000-00000987A78D Message-Id: <20170829062506.8317-3-cyril.bur@au1.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-08-29_01:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1707230000 definitions=main-1708290096 Subject: [Skiboot] [RFC PATCH 02/13] libflash/libffs: Add helpers for the treatment of partition flags 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: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" There is an increasing number of programs wanting to print partition flags as strings or wanting to parse strings back into a binary structure. This patch introduces a to_string() function and its complement so that there can be one place where the code exists. Signed-off-by: Cyril Bur --- libflash/ffs.h | 1 + libflash/libffs.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- libflash/libffs.h | 7 +++++ 3 files changed, 101 insertions(+), 1 deletion(-) diff --git a/libflash/ffs.h b/libflash/ffs.h index 18722538..81818fdf 100644 --- a/libflash/ffs.h +++ b/libflash/ffs.h @@ -76,6 +76,7 @@ enum ffs_type { #define FFS_MISCFLAGS_READONLY 0x40 #define FFS_MISCFLAGS_BACKUP 0x20 #define FFS_MISCFLAGS_REPROVISION 0x10 +#define FFS_MISCFLAGS_GOLDEN 0x01 /** * struct __ffs_entry_user - On flash user data entries diff --git a/libflash/libffs.c b/libflash/libffs.c index 038f5942..66b1d3f2 100644 --- a/libflash/libffs.c +++ b/libflash/libffs.c @@ -188,6 +188,88 @@ static int ffs_entry_to_cpu(struct ffs_hdr *hdr, return rc; } +char *ffs_entry_user_to_string(struct ffs_entry_user *user) +{ + char *ret; + + if (!user) + return NULL; + + ret = strdup("-------"); + if (!ret) + return NULL; + + if (user->datainteg & FFS_ENRY_INTEG_ECC) + ret[0] = 'E'; + + if (user->vercheck & FFS_VERCHECK_SHA512V) + ret[1] = 'V'; + + if (user->vercheck & FFS_VERCHECK_SHA512EC) + ret[2] = 'I'; + + if (user->miscflags & FFS_MISCFLAGS_PRESERVED) + ret[3] = 'P'; + + if (user->miscflags & FFS_MISCFLAGS_READONLY) + ret[4] = 'R'; + + if (user->miscflags & FFS_MISCFLAGS_BACKUP) + ret[5] = 'B'; + + if (user->miscflags & FFS_MISCFLAGS_REPROVISION) + ret[6] = 'F'; + + if (user->miscflags & FFS_MISCFLAGS_GOLDEN) + ret[7] = 'G'; + + return ret; +} + +int ffs_string_to_entry_user(const char *flags, int nflags, + struct ffs_entry_user *user) +{ + int i; + + if (!user || !flags) + return FLASH_ERR_PARM_ERROR; + + memset(user, 0, sizeof(struct ffs_entry_user)); + for (i = 0; i < nflags; i++) { + switch (flags[i]) { + case 'E': + user->datainteg |= FFS_ENRY_INTEG_ECC; + break; + case 'V': + user->vercheck |= FFS_VERCHECK_SHA512V; + break; + case 'I': + user->vercheck |= FFS_VERCHECK_SHA512EC; + break; + case 'P': + user->miscflags |= FFS_MISCFLAGS_PRESERVED; + break; + case 'R': + user->miscflags |= FFS_MISCFLAGS_READONLY; + break; + case 'B': + user->miscflags |= FFS_MISCFLAGS_BACKUP; + break; + case 'F': + user->miscflags |= FFS_MISCFLAGS_REPROVISION; + break; + case 'G': + user->miscflags |= FFS_MISCFLAGS_GOLDEN; + break; + default: + FL_DBG("Unknown flag '%c'\n", flags[i]); + return FLASH_ERR_PARM_ERROR; + } + } + + return 0; +} + bool has_flag(struct ffs_entry *ent, uint16_t flag) { return ((ent->user.miscflags & flag) != 0); @@ -723,13 +805,23 @@ int ffs_entry_user_set(struct ffs_entry *ent, struct ffs_entry_user *user) if (user->vercheck & ~(FFS_VERCHECK_SHA512V | FFS_VERCHECK_SHA512EC)) return -1; if (user->miscflags & ~(FFS_MISCFLAGS_PRESERVED | FFS_MISCFLAGS_BACKUP | - FFS_MISCFLAGS_READONLY | FFS_MISCFLAGS_REPROVISION)) + FFS_MISCFLAGS_READONLY | FFS_MISCFLAGS_REPROVISION | FFS_MISCFLAGS_GOLDEN)) return -1; memcpy(&ent->user, user, sizeof(*user)); return 0; } +struct ffs_entry_user ffs_entry_user_get(struct ffs_entry *ent) +{ + struct ffs_entry_user user = { 0 }; + + if (ent) + memcpy(&user, &ent->user, sizeof(user)); + + return user; +} + int ffs_entry_new(const char *name, uint32_t base, uint32_t size, struct ffs_entry **r) { struct ffs_entry *ret; diff --git a/libflash/libffs.h b/libflash/libffs.h index a0f65a05..6f8e34e3 100644 --- a/libflash/libffs.h +++ b/libflash/libffs.h @@ -88,8 +88,13 @@ struct ffs_entry_user { #define FFS_MISCFLAGS_READONLY 0x40 #define FFS_MISCFLAGS_BACKUP 0x20 #define FFS_MISCFLAGS_REPROVISION 0x10 +#define FFS_MISCFLAGS_GOLDEN 0x01 +int ffs_string_to_entry_user(const char *flags, int nflags, + struct ffs_entry_user *user); +char *ffs_entry_user_to_string(struct ffs_entry_user *user); + bool has_ecc(struct ffs_entry *ent); bool has_flag(struct ffs_entry *ent, uint16_t flag); @@ -144,6 +149,8 @@ int ffs_entry_user_set(struct ffs_entry *ent, struct ffs_entry_user *user); int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry, unsigned int side); +struct ffs_entry_user ffs_entry_user_get(struct ffs_entry *ent); + int ffs_hdr_create_backup(struct ffs_hdr *hdr); int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr);