From patchwork Tue Aug 29 06:24:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 806969 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xhJwN5vlVz9ryr for ; Tue, 29 Aug 2017 16:42:28 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xhJwN54RBzDqqT for ; Tue, 29 Aug 2017 16:42:28 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 3xhJY41rcKzDqYs for ; Tue, 29 Aug 2017 16:25:44 +1000 (AEST) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7T6OCEN130601 for ; Tue, 29 Aug 2017 02:25:40 -0400 Received: from e23smtp03.au.ibm.com (e23smtp03.au.ibm.com [202.81.31.145]) by mx0a-001b2d01.pphosted.com with ESMTP id 2cn0dtappu-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 29 Aug 2017 02:25:40 -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 d23relay06.au.ibm.com (202.81.31.225) 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 d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay06.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7T6PZOs39649484 for ; Tue, 29 Aug 2017 16:25:35 +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 v7T6PZHA022622 for ; Tue, 29 Aug 2017 16:25:35 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v7T6PZMe022619; 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 0E79DA010B; 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:54 +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-00000154A484 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17082906-0009-0000-0000-00000987A78C Message-Id: <20170829062506.8317-2-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 01/13] external/ffspart: Allow # comments in input file 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" Signed-off-by: Cyril Bur --- external/ffspart/ffspart.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/external/ffspart/ffspart.c b/external/ffspart/ffspart.c index 77034775..73c02c40 100644 --- a/external/ffspart/ffspart.c +++ b/external/ffspart/ffspart.c @@ -224,6 +224,10 @@ int main(int argc, char *argv[]) int side = -1; uint32_t pbase, psize, pactual = 0; + /* Inline comments in input file */ + if (line[0] == '#') + continue; + if (line[strlen(line) - 1] == '\n') line[strlen(line) - 1] = '\0'; 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); From patchwork Tue Aug 29 06:24:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 806970 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xhJwT6Rhmz9t38 for ; Tue, 29 Aug 2017 16:42:33 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xhJwT5MJmzDqm8 for ; Tue, 29 Aug 2017 16:42:33 +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 3xhJY56p5hzDqZq for ; Tue, 29 Aug 2017 16:25:45 +1000 (AEST) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7T6OBoq119049 for ; Tue, 29 Aug 2017 02:25:41 -0400 Received: from e23smtp05.au.ibm.com (e23smtp05.au.ibm.com [202.81.31.147]) by mx0a-001b2d01.pphosted.com with ESMTP id 2cn1kje0me-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 29 Aug 2017 02:25:41 -0400 Received: from localhost by e23smtp05.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 29 Aug 2017 16:25:39 +1000 Received: from d23relay09.au.ibm.com (202.81.31.228) by e23smtp05.au.ibm.com (202.81.31.211) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 29 Aug 2017 16:25:36 +1000 Received: from d23av01.au.ibm.com (d23av01.au.ibm.com [9.190.234.96]) by d23relay09.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7T6PZIH38404256 for ; Tue, 29 Aug 2017 16:25:35 +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 v7T6PZTh022628 for ; Tue, 29 Aug 2017 16:25:35 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av01.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v7T6PZes022623; 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 29655A0259; 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:56 +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-0016-0000-0000-000002619C45 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17082906-0017-0000-0000-000006E4665A Message-Id: <20170829062506.8317-4-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 03/13] external/pflash: Use ffs_entry_user_to_string() to standardise flag strings 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" Signed-off-by: Cyril Bur --- external/pflash/pflash.c | 14 +++++--------- external/pflash/test/results/01-info.out | 10 +++++----- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c index a08ea946..3be43ac0 100644 --- a/external/pflash/pflash.c +++ b/external/pflash/pflash.c @@ -101,8 +101,8 @@ static uint32_t print_ffs_info(struct ffs_handle *ffsh, uint32_t toc) for (i = 0;; i++) { uint32_t start, size, act, end; + struct ffs_entry_user user; char *name = NULL, *flags; - int l; rc = ffs_part_info(ffsh, i, &name, &start, &size, &act, NULL); if (rc == FFS_ERR_PART_NOT_FOUND) @@ -115,17 +115,13 @@ static uint32_t print_ffs_info(struct ffs_handle *ffsh, uint32_t toc) goto out; } - l = asprintf(&flags, "[%c%c%c%c%c]", - has_ecc(ent) ? 'E' : '-', - has_flag(ent, FFS_MISCFLAGS_PRESERVED) ? 'P' : '-', - has_flag(ent, FFS_MISCFLAGS_READONLY) ? 'R' : '-', - has_flag(ent, FFS_MISCFLAGS_BACKUP) ? 'B' : '-', - has_flag(ent, FFS_MISCFLAGS_REPROVISION) ? 'F' : '-'); - if (l < 0) + user = ffs_entry_user_get(ent); + flags = ffs_entry_user_to_string(&user); + if (!flags) goto out; end = start + size; - printf("ID=%02d %15s 0x%08x..0x%08x (actual=0x%08x) %s\n", + printf("ID=%02d %15s 0x%08x..0x%08x (actual=0x%08x) [%s]\n", i, name, start, end, act, flags); if (strcmp(name, "OTHER_SIDE") == 0) diff --git a/external/pflash/test/results/01-info.out b/external/pflash/test/results/01-info.out index 43baf316..840890f4 100644 --- a/external/pflash/test/results/01-info.out +++ b/external/pflash/test/results/01-info.out @@ -6,8 +6,8 @@ Erase granule = 0KB B:BACKUP, F:REPROVISION TOC@0x00000000 Partitions: ----------- -ID=00 part 0x00000000..0x00000300 (actual=0x00000300) [-----] -ID=01 ONE 0x00000300..0x00000400 (actual=0x00000100) [E----] -ID=02 TWO 0x00000400..0x00000500 (actual=0x00000100) [E---F] -ID=03 THREE 0x00000500..0x00000600 (actual=0x00000100) [E---F] -ID=04 FOUR 0x00000600..0x00000700 (actual=0x00000100) [E---F] +ID=00 part 0x00000000..0x00000300 (actual=0x00000300) [-------] +ID=01 ONE 0x00000300..0x00000400 (actual=0x00000100) [EV-----] +ID=02 TWO 0x00000400..0x00000500 (actual=0x00000100) [E-----F] +ID=03 THREE 0x00000500..0x00000600 (actual=0x00000100) [E-----F] +ID=04 FOUR 0x00000600..0x00000700 (actual=0x00000100) [E-----F] From patchwork Tue Aug 29 06:24:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 806977 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xhJy550Lnz9ryr for ; Tue, 29 Aug 2017 16:43:57 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xhJy548klzDrJ5 for ; Tue, 29 Aug 2017 16:43:57 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 3xhJYH0MpPzDqTt for ; Tue, 29 Aug 2017 16:25:54 +1000 (AEST) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7T6OFNY015931 for ; Tue, 29 Aug 2017 02:25:48 -0400 Received: from e23smtp01.au.ibm.com (e23smtp01.au.ibm.com [202.81.31.143]) by mx0b-001b2d01.pphosted.com with ESMTP id 2cmx9uj77a-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 29 Aug 2017 02:25:47 -0400 Received: from localhost by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 29 Aug 2017 16:25:39 +1000 Received: from d23relay06.au.ibm.com (202.81.31.225) by e23smtp01.au.ibm.com (202.81.31.207) 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 d23relay06.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7T6Paav39649490 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 v7T6PZL2017741 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 v7T6PZIM017728; 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 35C99A0267; 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:57 +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-1617-0000-0000-000001FCFDE8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17082906-1618-0000-0000-00004849560A Message-Id: <20170829062506.8317-5-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 04/13] libflash/libffs: Add setter for a partitions actual size 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" Signed-off-by: Cyril Bur --- libflash/libffs.c | 13 +++++++++++++ libflash/libffs.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/libflash/libffs.c b/libflash/libffs.c index 66b1d3f2..1684388f 100644 --- a/libflash/libffs.c +++ b/libflash/libffs.c @@ -842,6 +842,19 @@ int ffs_entry_new(const char *name, uint32_t base, uint32_t size, struct ffs_ent return 0; } +int ffs_entry_set_act_size(struct ffs_entry *ent, uint32_t actual_size) +{ + if (!ent) + return -1; + + if (actual_size > ent->size) + return FFS_ERR_BAD_PART_SIZE; + + ent->actual = actual_size; + + return 0; +} + int ffs_hdr_new(uint32_t block_size, uint32_t block_count, struct ffs_hdr **r) { struct ffs_hdr *ret; diff --git a/libflash/libffs.h b/libflash/libffs.h index 6f8e34e3..2196d526 100644 --- a/libflash/libffs.h +++ b/libflash/libffs.h @@ -147,6 +147,8 @@ int ffs_entry_new(const char *name, uint32_t base, uint32_t size, struct ffs_ent int ffs_entry_user_set(struct ffs_entry *ent, struct ffs_entry_user *user); +int ffs_entry_set_act_size(struct ffs_entry *ent, uint32_t actual_size); + 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); From patchwork Tue Aug 29 06:24:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 806978 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 3xhJyB6JHHz9ryr for ; Tue, 29 Aug 2017 16:44:02 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xhJyB5SGtzDql8 for ; Tue, 29 Aug 2017 16:44:02 +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 3xhJZW1L6vzDqYN for ; Tue, 29 Aug 2017 16:26:59 +1000 (AEST) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7T6OCSe118678 for ; Tue, 29 Aug 2017 02:26:56 -0400 Received: from e23smtp06.au.ibm.com (e23smtp06.au.ibm.com [202.81.31.148]) by mx0a-001b2d01.pphosted.com with ESMTP id 2cmur5h2g8-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 29 Aug 2017 02:26:56 -0400 Received: from localhost by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 29 Aug 2017 16:26:53 +1000 Received: from d23relay07.au.ibm.com (202.81.31.226) by e23smtp06.au.ibm.com (202.81.31.212) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 29 Aug 2017 16:26:51 +1000 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay07.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7T6PaCP36241552 for ; Tue, 29 Aug 2017 16:25:36 +1000 Received: from d23av04.au.ibm.com (localhost [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v7T6Pav3017742 for ; Tue, 29 Aug 2017 16:25:36 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v7T6Patt017733; Tue, 29 Aug 2017 16:25:36 +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 4257CA0273; 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:58 +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-0040-0000-0000-00000351E32D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17082906-0041-0000-0000-00000CCFDD9E Message-Id: <20170829062506.8317-6-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=2 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 05/13] libflash/libffs: ffs_close() should use ffs_hdr_free() 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" Signed-off-by: Cyril Bur --- libflash/libffs.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/libflash/libffs.c b/libflash/libffs.c index 1684388f..822169b7 100644 --- a/libflash/libffs.c +++ b/libflash/libffs.c @@ -428,14 +428,32 @@ out: return rc; } -void ffs_close(struct ffs_handle *ffs) +static void __hdr_free(struct ffs_hdr *hdr) { struct ffs_entry *ent, *next; - list_for_each_safe(&ffs->hdr.entries, ent, next, list) { + list_for_each_safe(&hdr->entries, ent, next, list) { list_del(&ent->list); free(ent); } + if (hdr->side) { + hdr->side->side = NULL; + ffs_hdr_free(hdr->side); + } +} + +int ffs_hdr_free(struct ffs_hdr *hdr) +{ + printf("Freeing hdr\n"); + __hdr_free(hdr); + free(hdr); + + return 0; +} + +void ffs_close(struct ffs_handle *ffs) +{ + __hdr_free(&ffs->hdr); if (ffs->cache) free(ffs->cache); @@ -889,24 +907,6 @@ int ffs_hdr_new(uint32_t block_size, uint32_t block_count, struct ffs_hdr **r) return 0; } -int ffs_hdr_free(struct ffs_hdr *hdr) -{ - struct ffs_entry *ent, *next; - - printf("Freeing hdr\n"); - list_for_each_safe(&hdr->entries, ent, next, list) { - list_del(&ent->list); - free(ent); - } - if (hdr->side) { - hdr->side->side = NULL; - ffs_hdr_free(hdr->side); - } - free(hdr); - - return 0; -} - int ffs_update_act_size(struct ffs_handle *ffs, uint32_t part_idx, uint32_t act_size) { From patchwork Tue Aug 29 06:24:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 806967 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xhJvs5Yztz9ryr for ; Tue, 29 Aug 2017 16:42:01 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xhJvs4cLSzDrVh for ; Tue, 29 Aug 2017 16:42:01 +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 3xhJY32CQpzDqYs for ; Tue, 29 Aug 2017 16:25:43 +1000 (AEST) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7T6OHOL100265 for ; Tue, 29 Aug 2017 02:25:41 -0400 Received: from e23smtp04.au.ibm.com (e23smtp04.au.ibm.com [202.81.31.146]) by mx0a-001b2d01.pphosted.com with ESMTP id 2cmx61t72q-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 29 Aug 2017 02:25:41 -0400 Received: from localhost by e23smtp04.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 d23relay10.au.ibm.com (202.81.31.229) by e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 29 Aug 2017 16:25:36 +1000 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay10.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7T6Pa9p23593032 for ; Tue, 29 Aug 2017 16:25:36 +1000 Received: from d23av04.au.ibm.com (localhost [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v7T6PatS017773 for ; Tue, 29 Aug 2017 16:25:37 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v7T6PaBe017744; Tue, 29 Aug 2017 16:25:36 +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 4F2EBA0275; 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:59 +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-0012-0000-0000-0000025A9F59 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17082906-0013-0000-0000-0000077669DC Message-Id: <20170829062506.8317-7-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=29 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 06/13] external/ffspart: Remove side, order and backup options 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" These options are currently flakey in libflash/libffs so there isn't much point to being able to use them in ffspart. Future reworks planned for libflash/libffs will render these options redundant anyway. Signed-off-by: Cyril Bur --- external/ffspart/ffspart.c | 87 ++-------------------- external/ffspart/test/results/00-usage.out | 5 -- external/ffspart/test/tests/01-param-sanity | 6 +- external/ffspart/test/tests/02-param-sides | 6 +- external/ffspart/test/tests/03.1-tiny-pnor-backup | 4 + .../ffspart/test/tests/05.1-hdr-overlap-backup | 6 +- 6 files changed, 24 insertions(+), 90 deletions(-) diff --git a/external/ffspart/ffspart.c b/external/ffspart/ffspart.c index 73c02c40..bd223c78 100644 --- a/external/ffspart/ffspart.c +++ b/external/ffspart/ffspart.c @@ -52,11 +52,6 @@ #define MAX_LINE 100 #define SEPARATOR ',' -enum order { - ORDER_ADB, - ORDER_ABD -}; - /* Full version number (possibly includes gitid). */ extern const char version[]; @@ -76,23 +71,16 @@ static void print_help(const char *pname) printf("\t\tNumber of blocks on the flash\n\n"); printf("\t-i, --input=file\n"); printf("\t\tFile containing the required partition data\n\n"); - printf("\t-o, --order=( ADB | ABD )\n"); - printf("\t\tOrdering of the TOC, Data and Backup TOC. Currently only ADB (default)\n"); - printf("\t\tis supported\n"); printf("\t-p, --pnor=file\n"); printf("\t\tOutput file to write data\n\n"); - printf("\t-t, --sides=( 1 | 2 )\n"); - printf("\t\tNumber of sides to the flash (Default: 1)\n"); } int main(int argc, char *argv[]) { const char *pname = argv[0]; struct blocklevel_device *bl = NULL; - unsigned int sides = 1; uint32_t block_size = 0, block_count = 0; - enum order order = ORDER_ADB; - bool bad_input = false, backup_part = false; + bool bad_input = false; char *pnor = NULL, *input = NULL; struct ffs_hdr *new_hdr; FILE *in_file; @@ -101,25 +89,19 @@ int main(int argc, char *argv[]) while(1) { struct option long_opts[] = { - {"backup", no_argument, NULL, 'b'}, {"block_size", required_argument, NULL, 's'}, {"block_count", required_argument, NULL, 'c'}, {"debug", no_argument, NULL, 'g'}, {"input", required_argument, NULL, 'i'}, - {"order", required_argument, NULL, 'o'}, {"pnor", required_argument, NULL, 'p'}, - {"tocs", required_argument, NULL, 't'}, {NULL, 0, 0, 0} }; int c, oidx = 0; - c = getopt_long(argc, argv, "bc:gi:o:p:s:t:", long_opts, &oidx); + c = getopt_long(argc, argv, "c:gi:p:s:", long_opts, &oidx); if (c == EOF) break; switch(c) { - case 'b': - backup_part = true; - break; case 'c': block_count = strtoul(optarg, NULL, 0); break; @@ -129,52 +111,27 @@ int main(int argc, char *argv[]) case 'i': input = strdup(optarg); break; - case 'o': - if (strncmp(optarg, "ABD", 3) == 0) - order = ORDER_ABD; - else if (strncmp(optarg, "ADB", 3) == 0) - order = ORDER_ADB; - else - bad_input = true; - break; case 'p': pnor = strdup(optarg); break; case 's': block_size = strtoul(optarg, NULL, 0); break; - case 't': - sides = strtoul(optarg, NULL, 0); - break; default: exit(1); } } - if (sides == 0) - sides = 1; - - if (sides > 2) { - fprintf(stderr, "Greater than two sides is not supported\n"); - bad_input = true; - } - if (!block_size || !block_count || !input || !pnor) bad_input = true; - /* TODO Check assumption that sides divide the flash in half. */ - if (block_count % sides) { - fprintf(stderr, "Invalid block_count %u for sides %u\n", block_count, sides); - bad_input = true; - } - - if (bad_input || order == ORDER_ABD) { + if (bad_input) { print_help(pname); rc = 1; goto out; } - rc = ffs_hdr_new(block_size, block_count / sides, &new_hdr); + rc = ffs_hdr_new(block_size, block_count, &new_hdr); if (rc) { if (rc == FFS_ERR_BAD_SIZE) { /* Well this check is a tad redudant now */ @@ -185,14 +142,6 @@ int main(int argc, char *argv[]) goto out; } - if (sides == 2) { - rc = ffs_hdr_add_side(new_hdr); - if (rc) { - fprintf(stderr, "Couldn't add side to header\n"); - goto out_free_hdr; - } - } - in_file = fopen(input, "r"); if (!in_file) { rc = errno; @@ -221,7 +170,6 @@ int main(int argc, char *argv[]) struct ffs_entry_user user = { 0 }; char *pos, *old_pos; char *name, *endptr; - int side = -1; uint32_t pbase, psize, pactual = 0; /* Inline comments in input file */ @@ -303,20 +251,6 @@ int main(int argc, char *argv[]) case 'B': user.miscflags |= FFS_MISCFLAGS_BACKUP; break; - case '0': - case '1': - case '2': - /* - * There should only be one side specified, fail if - * we've already seen a side - */ - if (side != -1) { - rc = -1; - goto out_close_bl; - } else { - side = *pos - '0'; - } - break; default: fprintf(stderr, "Unknown flag '%c'\n", *pos); rc = -1; @@ -325,9 +259,6 @@ int main(int argc, char *argv[]) pos++; } - if (side == -1) /* Default to 0 */ - side = 0; - printf("Adding '%s' 0x%08x, 0x%08x\n", name, pbase, psize); rc = ffs_entry_new(name, pbase, psize, &new_entry); if (rc) { @@ -342,7 +273,7 @@ int main(int argc, char *argv[]) goto out_while; } - rc = ffs_entry_add(new_hdr, new_entry, side); + rc = ffs_entry_add(new_hdr, new_entry, 0); if (rc) { fprintf(stderr, "Couldn't add entry '%s' 0x%08x for 0x%08x\n", name, pbase, psize); @@ -411,14 +342,6 @@ out_while: goto out_close_bl; } - if (backup_part) { - rc = ffs_hdr_create_backup(new_hdr); - if (rc) { - fprintf(stderr, "Failed to create backup part\n"); - goto out_close_bl; - } - } - rc = ffs_hdr_finalise(bl, new_hdr); if (rc) fprintf(stderr, "Failed to write out TOC values\n"); diff --git a/external/ffspart/test/results/00-usage.out b/external/ffspart/test/results/00-usage.out index 19eedc74..3ad0441d 100644 --- a/external/ffspart/test/results/00-usage.out +++ b/external/ffspart/test/results/00-usage.out @@ -11,11 +11,6 @@ Usage: ./ffspart [options] -s size -c num -i layout_file -p pnor_file ... -i, --input=file File containing the required partition data - -o, --order=( ADB | ABD ) - Ordering of the TOC, Data and Backup TOC. Currently only ADB (default) - is supported -p, --pnor=file Output file to write data - -t, --sides=( 1 | 2 ) - Number of sides to the flash (Default: 1) diff --git a/external/ffspart/test/tests/01-param-sanity b/external/ffspart/test/tests/01-param-sanity index 9e28c45d..28acf511 100644 --- a/external/ffspart/test/tests/01-param-sanity +++ b/external/ffspart/test/tests/01-param-sanity @@ -1,6 +1,10 @@ #! /bin/sh -run_binary "./ffspart" "-t 3 -s 1 -c 3 -i /dev/null -p /dev/null" +#This test has become a little redundant now. +#TODO Do more sanity checking +return 0 + +run_binary "./ffspart" "-s 1 -c 3 -i /dev/null -p /dev/null" if [ "$?" -ne 1 ] ; then fail_test fi diff --git a/external/ffspart/test/tests/02-param-sides b/external/ffspart/test/tests/02-param-sides index cd7984b8..17a2461e 100644 --- a/external/ffspart/test/tests/02-param-sides +++ b/external/ffspart/test/tests/02-param-sides @@ -1,6 +1,10 @@ #! /bin/sh -run_binary "./ffspart" "-t 2 -s 1 -c 1 -i /dev/null -p /dev/null" +#The parameter has been removed +#TODO Something clever with this test +return 0 + +run_binary "./ffspart" "-s 1 -c 1 -i /dev/null -p /dev/null" if [ "$?" -ne 1 ] ; then fail_test fi diff --git a/external/ffspart/test/tests/03.1-tiny-pnor-backup b/external/ffspart/test/tests/03.1-tiny-pnor-backup index 3065c864..8fa8d4e4 100644 --- a/external/ffspart/test/tests/03.1-tiny-pnor-backup +++ b/external/ffspart/test/tests/03.1-tiny-pnor-backup @@ -1,5 +1,9 @@ #! /bin/sh +#The backup partition flag is gone +#disable this test temporarily +return 0 + touch $DATA_DIR/$CUR_TEST.gen run_binary "./ffspart" "-b -s 0x100 -c 15 -i $DATA_DIR/$CUR_TEST.in -p $DATA_DIR/$CUR_TEST.gen" diff --git a/external/ffspart/test/tests/05.1-hdr-overlap-backup b/external/ffspart/test/tests/05.1-hdr-overlap-backup index 5814ffff..0cbd9fa4 100644 --- a/external/ffspart/test/tests/05.1-hdr-overlap-backup +++ b/external/ffspart/test/tests/05.1-hdr-overlap-backup @@ -1,8 +1,12 @@ #! /bin/sh +#The backup partition flag is gone +#disable this test temporarily +return 0 + touch $DATA_DIR/$CUR_TEST.gen -run_binary "./ffspart" "-b -s 0x100 -c 10 -i $DATA_DIR/$CUR_TEST.in -p $DATA_DIR/$CUR_TEST.gen" +run_binary "./ffspart" "-s 0x100 -c 10 -i $DATA_DIR/$CUR_TEST.in -p $DATA_DIR/$CUR_TEST.gen" #expect this error code, which is FFS_ERR_BAD_PART_BASE becase we're #going to have too many partitions for header to fit before the first #partition From patchwork Tue Aug 29 06:25:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 806974 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 3xhJxR0BHjz9ryr for ; Tue, 29 Aug 2017 16:43:23 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xhJxQ6T4QzDqp3 for ; Tue, 29 Aug 2017 16:43:22 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 3xhJY83sZFzDqZq for ; Tue, 29 Aug 2017 16:25:48 +1000 (AEST) Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7T6OCRn076863 for ; Tue, 29 Aug 2017 02:25:42 -0400 Received: from e23smtp08.au.ibm.com (e23smtp08.au.ibm.com [202.81.31.141]) by mx0b-001b2d01.pphosted.com with ESMTP id 2cn1hye6n7-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 29 Aug 2017 02:25:41 -0400 Received: from localhost by e23smtp08.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 d23relay10.au.ibm.com (202.81.31.229) by e23smtp08.au.ibm.com (202.81.31.205) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 29 Aug 2017 16:25:37 +1000 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay10.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7T6PaJF23593034 for ; Tue, 29 Aug 2017 16:25:36 +1000 Received: from d23av04.au.ibm.com (localhost [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v7T6PaR8017768 for ; Tue, 29 Aug 2017 16:25:37 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v7T6PaU8017743; Tue, 29 Aug 2017 16:25:36 +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 5DC22A027E; 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:25:00 +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-0048-0000-0000-0000025A39C9 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17082906-0049-0000-0000-0000480E7DF1 Message-Id: <20170829062506.8317-8-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 07/13] libflash/libffs: Always add entries to the end of the TOC 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" It turns out that sorted order isn't the best idea. This removes flexibility from the caller. If the user wants their partitions in sorted order, they should insert them in sorted order. Signed-off-by: Cyril Bur --- libflash/libffs.c | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/libflash/libffs.c b/libflash/libffs.c index 822169b7..0159c07b 100644 --- a/libflash/libffs.c +++ b/libflash/libffs.c @@ -598,25 +598,7 @@ static int __ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry) return FFS_ERR_BAD_PART_BASE; } - /* - * A header can't have zero entries. Was asserted. - */ - list_for_each(&hdr->entries, ent, list) - if (entry->base < ent->base) - break; - - if (ent == list_top(&hdr->entries, struct ffs_entry, list)) { - /* - * This should never happen because the partition entry - * should ALWAYS be here - */ - fprintf(stderr, "Warning: replacing first entry in FFS header\n"); - list_add(&hdr->entries, &entry->list); - } else if (!ent) { - list_add_tail(&hdr->entries, &entry->list); - } else { - list_add_before(&hdr->entries, &entry->list, &ent->list); - } + list_add_tail(&hdr->entries, &entry->list); return 0; } From patchwork Tue Aug 29 06:25:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 806966 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xhJvf000qz9ryr for ; Tue, 29 Aug 2017 16:41:49 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xhJvd5stDzDrWm for ; Tue, 29 Aug 2017 16:41:49 +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 3xhJY324ZbzDqYV for ; Tue, 29 Aug 2017 16:25:43 +1000 (AEST) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7T6OHgW100276 for ; Tue, 29 Aug 2017 02:25:41 -0400 Received: from e23smtp01.au.ibm.com (e23smtp01.au.ibm.com [202.81.31.143]) by mx0a-001b2d01.pphosted.com with ESMTP id 2cmx61t732-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 29 Aug 2017 02:25:41 -0400 Received: from localhost by e23smtp01.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 e23smtp01.au.ibm.com (202.81.31.207) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 29 Aug 2017 16:25:36 +1000 Received: from d23av06.au.ibm.com (d23av06.au.ibm.com [9.190.235.151]) by d23relay09.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7T6PaD941484432 for ; Tue, 29 Aug 2017 16:25:36 +1000 Received: from d23av06.au.ibm.com (localhost [127.0.0.1]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v7T6PZEi016430 for ; Tue, 29 Aug 2017 16:25:36 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v7T6PZ6U016425; 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 6A6B0A0389; 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:25:01 +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-1617-0000-0000-000001FCFDEA X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17082906-1618-0000-0000-00004849560C Message-Id: <20170829062506.8317-9-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=2 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 08/13] libflash/libffs: Remove the 'sides' from the FFS TOC generation code 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" It turns out this code was messy and not all that reliable. Doing it at the library level adds complexity to the library and restrictions to the caller. A simpler approach can be achived with the just instantiating multiple ffs_header structures pointing to different parts of the same file. Signed-off-by: Cyril Bur --- external/ffspart/ffspart.c | 2 +- libflash/ffs.h | 2 -- libflash/libffs.c | 77 ++-------------------------------------------- libflash/libffs.h | 3 +- 4 files changed, 5 insertions(+), 79 deletions(-) diff --git a/external/ffspart/ffspart.c b/external/ffspart/ffspart.c index bd223c78..74e12ff6 100644 --- a/external/ffspart/ffspart.c +++ b/external/ffspart/ffspart.c @@ -273,7 +273,7 @@ int main(int argc, char *argv[]) goto out_while; } - rc = ffs_entry_add(new_hdr, new_entry, 0); + rc = ffs_entry_add(new_hdr, new_entry); if (rc) { fprintf(stderr, "Couldn't add entry '%s' 0x%08x for 0x%08x\n", name, pbase, psize); diff --git a/libflash/ffs.h b/libflash/ffs.h index 81818fdf..cc2460c8 100644 --- a/libflash/ffs.h +++ b/libflash/ffs.h @@ -205,7 +205,6 @@ struct __ffs_hdr { * @block_size: Size of block on device (in bytes) * @block_count: Number of blocks on device. * @backup The backup partition - * @side The ffs header for the other side * @entries: List of partition entries */ struct ffs_hdr { @@ -216,7 +215,6 @@ struct ffs_hdr { uint32_t block_count; struct ffs_entry *part; struct ffs_entry *backup; - struct ffs_hdr *side; struct list_head entries; }; diff --git a/libflash/libffs.c b/libflash/libffs.c index 0159c07b..e741121d 100644 --- a/libflash/libffs.c +++ b/libflash/libffs.c @@ -436,10 +436,6 @@ static void __hdr_free(struct ffs_hdr *hdr) list_del(&ent->list); free(ent); } - if (hdr->side) { - hdr->side->side = NULL; - ffs_hdr_free(hdr->side); - } } int ffs_hdr_free(struct ffs_hdr *hdr) @@ -603,10 +599,8 @@ static int __ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry) return 0; } -int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry, unsigned int side) +int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry) { - int rc; - /* * Refuse to add anything after BACKUP_PART has been added, not * sure why this is needed anymore @@ -614,36 +608,7 @@ int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry, unsigned int sid if (hdr->backup) return FLASH_ERR_PARM_ERROR; - if (side == 0) { /* Sideless... */ - rc = __ffs_entry_add(hdr, entry); - if (!rc && hdr->side) { - struct ffs_entry *other_ent; - - /* - * A rather sneaky copy is hidden here. - * It doesn't make sense for a consumer to be aware that structures - * must be duplicated. The entries list in the header could have - * been an array of pointers and no copy would have been required. - */ - other_ent = calloc(1, sizeof (struct ffs_entry)); - if (!other_ent) - /* TODO Remove the added entry from side 1 */ - return FLASH_ERR_PARM_ERROR; - memcpy(other_ent, entry, sizeof(struct ffs_entry)); - rc = __ffs_entry_add(hdr->side, other_ent); - if (rc) - /* TODO Remove the added entry from side 1 */ - free(other_ent); - } - } else if (side == 1) { - rc = __ffs_entry_add(hdr, entry); - } else if (side == 2 && hdr->side) { - rc = __ffs_entry_add(hdr->side, entry); - } else { - rc = FLASH_ERR_PARM_ERROR; - } - - return rc; + return __ffs_entry_add(hdr, entry); } /* This should be done last! */ @@ -675,29 +640,6 @@ int ffs_hdr_create_backup(struct ffs_hdr *hdr) hdr->backup = backup; - /* Do we try to roll back completely if that fails or leave what we've added? */ - if (hdr->side && hdr->base == 0) - rc = ffs_hdr_create_backup(hdr->side); - - return rc; -} - -int ffs_hdr_add_side(struct ffs_hdr *hdr) -{ - int rc; - - /* Only a second side for now */ - if (hdr->side) - return FLASH_ERR_PARM_ERROR; - - rc = ffs_hdr_new(hdr->block_size, hdr->block_count, &hdr->side); - if (rc) - return rc; - - hdr->side->base = hdr->block_size * hdr->block_count; - /* Sigh */ - hdr->side->side = hdr; - return rc; } @@ -713,16 +655,6 @@ int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr) if (num_entries == 0) return FFS_ERR_BAD_SIZE; - if (hdr->side) { - struct ffs_entry *other_side; - /* TODO: Change the hard coded 0x8000 */ - rc = ffs_entry_new("OTHER_SIDE", hdr->side->base, 0x8000, &other_side); - if (rc) - return rc; - list_add_tail(&hdr->entries, &other_side->list); - num_entries++; - } - real_hdr = malloc(ffs_hdr_raw_size(num_entries)); if (!real_hdr) return FLASH_ERR_MALLOC_FAILED; @@ -773,11 +705,6 @@ int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr) rc = blocklevel_write(bl, hdr->backup->base, real_hdr, ffs_hdr_raw_size(num_entries)); } - if (rc) - goto out; - - if (hdr->side && hdr->base == 0) - rc = ffs_hdr_finalise(bl, hdr->side); out: free(real_hdr); return rc; diff --git a/libflash/libffs.h b/libflash/libffs.h index 2196d526..d81b9dfe 100644 --- a/libflash/libffs.h +++ b/libflash/libffs.h @@ -149,10 +149,11 @@ int ffs_entry_user_set(struct ffs_entry *ent, struct ffs_entry_user *user); int ffs_entry_set_act_size(struct ffs_entry *ent, uint32_t actual_size); -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_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry); + int ffs_hdr_create_backup(struct ffs_hdr *hdr); int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr); From patchwork Tue Aug 29 06:25:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 806975 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 3xhJxb5rjjz9ryr for ; Tue, 29 Aug 2017 16:43:31 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xhJxb4q3hzDrWK for ; Tue, 29 Aug 2017 16:43:31 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 3xhJY83cXlzDqTm for ; Tue, 29 Aug 2017 16:25:48 +1000 (AEST) Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7T6OCRo076863 for ; Tue, 29 Aug 2017 02:25:42 -0400 Received: from e23smtp06.au.ibm.com (e23smtp06.au.ibm.com [202.81.31.148]) by mx0b-001b2d01.pphosted.com with ESMTP id 2cn1hye6p1-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 29 Aug 2017 02:25:42 -0400 Received: from localhost by e23smtp06.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 29 Aug 2017 16:25:39 +1000 Received: from d23relay10.au.ibm.com (202.81.31.229) by e23smtp06.au.ibm.com (202.81.31.212) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 29 Aug 2017 16:25:37 +1000 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay10.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7T6PaL73145832 for ; Tue, 29 Aug 2017 16:25:36 +1000 Received: from d23av04.au.ibm.com (localhost [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v7T6PbO6017786 for ; Tue, 29 Aug 2017 16:25:37 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v7T6Pas1017774; Tue, 29 Aug 2017 16:25:36 +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 7B8B5A010B; 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:25:02 +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-0040-0000-0000-00000351E322 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17082906-0041-0000-0000-00000CCFDD93 Message-Id: <20170829062506.8317-10-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=2 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 09/13] libflash/libffs: Remove backup partition from TOC generation code 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" It turns out this code was messy and not all that reliable. Doing it at the library level adds complexity to the library and restrictions to the caller. A simpler approach can be achived with the just instantiating multiple ffs_header structures pointing to different parts of the same file. Signed-off-by: Cyril Bur --- libflash/ffs.h | 2 -- libflash/libffs.c | 52 +--------------------------------------------------- libflash/libffs.h | 2 -- 3 files changed, 1 insertion(+), 55 deletions(-) diff --git a/libflash/ffs.h b/libflash/ffs.h index cc2460c8..957155b9 100644 --- a/libflash/ffs.h +++ b/libflash/ffs.h @@ -204,7 +204,6 @@ struct __ffs_hdr { * @size: Size of partition table (in bytes) * @block_size: Size of block on device (in bytes) * @block_count: Number of blocks on device. - * @backup The backup partition * @entries: List of partition entries */ struct ffs_hdr { @@ -214,7 +213,6 @@ struct ffs_hdr { uint32_t block_size; uint32_t block_count; struct ffs_entry *part; - struct ffs_entry *backup; struct list_head entries; }; diff --git a/libflash/libffs.c b/libflash/libffs.c index e741121d..5888c73f 100644 --- a/libflash/libffs.c +++ b/libflash/libffs.c @@ -546,7 +546,7 @@ int ffs_next_side(struct ffs_handle *ffs, struct ffs_handle **new_ffs, return ffs_init(offset, max_size, ffs->bl, new_ffs, mark_ecc); } -static int __ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry) +int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry) { struct ffs_entry *ent; uint32_t smallest_base; @@ -599,50 +599,6 @@ static int __ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry) return 0; } -int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry) -{ - /* - * Refuse to add anything after BACKUP_PART has been added, not - * sure why this is needed anymore - */ - if (hdr->backup) - return FLASH_ERR_PARM_ERROR; - - return __ffs_entry_add(hdr, entry); -} - -/* This should be done last! */ -int ffs_hdr_create_backup(struct ffs_hdr *hdr) -{ - struct ffs_entry *ent; - struct ffs_entry *backup; - uint32_t hdr_size, flash_end; - int rc = 0; - - ent = list_tail(&hdr->entries, struct ffs_entry, list); - if (!ent) { - return FLASH_ERR_PARM_ERROR; - } - - hdr_size = ffs_hdr_raw_size(ffs_num_entries(hdr) + 1); - /* Whole number of blocks BACKUP_PART needs to be */ - hdr_size = ((hdr_size + hdr->block_size) / hdr->block_size) * hdr->block_size; - flash_end = hdr->base + (hdr->block_size * hdr->block_count); - rc = ffs_entry_new("BACKUP_PART", flash_end - hdr_size, hdr_size, &backup); - if (rc) - return rc; - - rc = __ffs_entry_add(hdr, backup); - if (rc) { - free(backup); - return rc; - } - - hdr->backup = backup; - - return rc; -} - int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr) { int num_entries, i, rc = 0; @@ -699,12 +655,6 @@ int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr) if (rc) goto out; - if (hdr->backup) { - fprintf(stderr, "Actually writing backup part @ 0x%08x\n", hdr->backup->base); - blocklevel_erase(bl, hdr->backup->base, hdr->size); - rc = blocklevel_write(bl, hdr->backup->base, real_hdr, - ffs_hdr_raw_size(num_entries)); - } out: free(real_hdr); return rc; diff --git a/libflash/libffs.h b/libflash/libffs.h index d81b9dfe..56428a2c 100644 --- a/libflash/libffs.h +++ b/libflash/libffs.h @@ -154,8 +154,6 @@ struct ffs_entry_user ffs_entry_user_get(struct ffs_entry *ent); int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry); -int ffs_hdr_create_backup(struct ffs_hdr *hdr); - int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr); int ffs_hdr_free(struct ffs_hdr *hdr); From patchwork Tue Aug 29 06:25:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 806973 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 3xhJxJ4XfYz9ryr for ; Tue, 29 Aug 2017 16:43:16 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xhJxJ2LyhzDrL5 for ; Tue, 29 Aug 2017 16:43:16 +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 3xhJY6256FzDqZv for ; Tue, 29 Aug 2017 16:25:46 +1000 (AEST) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7T6ODtx118002 for ; Tue, 29 Aug 2017 02:25:42 -0400 Received: from e23smtp07.au.ibm.com (e23smtp07.au.ibm.com [202.81.31.140]) by mx0a-001b2d01.pphosted.com with ESMTP id 2cmwgam291-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 29 Aug 2017 02:25:41 -0400 Received: from localhost by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 29 Aug 2017 16:25:39 +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; Tue, 29 Aug 2017 16:25:37 +1000 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay08.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7T6PaYZ42991796 for ; Tue, 29 Aug 2017 16:25:36 +1000 Received: from d23av04.au.ibm.com (localhost [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v7T6PbQs017781 for ; Tue, 29 Aug 2017 16:25:37 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v7T6PaUA017743; Tue, 29 Aug 2017 16:25:36 +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 89FB7A038A; 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:25:03 +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-0044-0000-0000-0000028433F2 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17082906-0045-0000-0000-00000717AFD4 Message-Id: <20170829062506.8317-11-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=2 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 10/13] libflash/libffs: Switch to storing header entries in an array 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" Since the libffs no longer needs to sort the entries as they get added it makes little sense to have the complexity of a linked list when an array will suffice. Signed-off-by: Cyril Bur --- external/ffspart/test/results/05-hdr-overlap.out | 1 - external/ffspart/test/results/06-small-flash.out | 1 - external/ffspart/test/results/07-big-files.out | 1 - external/ffspart/test/results/08-small-files.out | 1 - external/ffspart/test/results/10-bad-input.out | 1 - external/ffspart/test/results/11-long-name.out | 1 - .../ffspart/test/results/12-bad-numbers-base.out | 1 - .../ffspart/test/results/13-bad-numbers-size.out | 1 - .../ffspart/test/results/14-bad-input-flags.out | 1 - .../test/results/15-overlapping-partitions.out | 1 - libflash/ffs.h | 8 +- libflash/libffs.c | 128 +++++++++++---------- 12 files changed, 70 insertions(+), 76 deletions(-) diff --git a/external/ffspart/test/results/05-hdr-overlap.out b/external/ffspart/test/results/05-hdr-overlap.out index dbcdcb1d..2dbf5a43 100644 --- a/external/ffspart/test/results/05-hdr-overlap.out +++ b/external/ffspart/test/results/05-hdr-overlap.out @@ -1,4 +1,3 @@ Adding 'ONE' 0x00000200, 0x00000100 Adding 'TWO' 0x00000300, 0x00000100 Adding 'THREE' 0x00000400, 0x00000100 -Freeing hdr diff --git a/external/ffspart/test/results/06-small-flash.out b/external/ffspart/test/results/06-small-flash.out index c59579eb..25214672 100644 --- a/external/ffspart/test/results/06-small-flash.out +++ b/external/ffspart/test/results/06-small-flash.out @@ -1,3 +1,2 @@ Adding 'ONE' 0x00000300, 0x00000100 Adding 'TWO' 0x00000400, 0x00000100 -Freeing hdr diff --git a/external/ffspart/test/results/07-big-files.out b/external/ffspart/test/results/07-big-files.out index 83929738..0555381e 100644 --- a/external/ffspart/test/results/07-big-files.out +++ b/external/ffspart/test/results/07-big-files.out @@ -1,2 +1 @@ Adding 'ONE' 0x00000300, 0x00000100 -Freeing hdr diff --git a/external/ffspart/test/results/08-small-files.out b/external/ffspart/test/results/08-small-files.out index 9c39b050..fdf70bf8 100644 --- a/external/ffspart/test/results/08-small-files.out +++ b/external/ffspart/test/results/08-small-files.out @@ -2,4 +2,3 @@ Adding 'ONE' 0x00000300, 0x00000100 Adding 'TWO' 0x00000400, 0x00000100 Adding 'THREE' 0x00000500, 0x00000100 Adding 'FOUR' 0x00000600, 0x00000100 -Freeing hdr diff --git a/external/ffspart/test/results/10-bad-input.out b/external/ffspart/test/results/10-bad-input.out index aad57ac2..e69de29b 100644 --- a/external/ffspart/test/results/10-bad-input.out +++ b/external/ffspart/test/results/10-bad-input.out @@ -1 +0,0 @@ -Freeing hdr diff --git a/external/ffspart/test/results/11-long-name.out b/external/ffspart/test/results/11-long-name.out index 030fc11b..2d7dcb32 100644 --- a/external/ffspart/test/results/11-long-name.out +++ b/external/ffspart/test/results/11-long-name.out @@ -2,4 +2,3 @@ Adding 'This_is_more_than_15_characters' 0x00000300, 0x00000100 Adding 'This_is_exactly' 0x00000400, 0x00000100 Adding 'This_is_one_le' 0x00000500, 0x00000100 Adding 'This_is_one_more' 0x00000600, 0x00000100 -Freeing hdr diff --git a/external/ffspart/test/results/12-bad-numbers-base.out b/external/ffspart/test/results/12-bad-numbers-base.out index aad57ac2..e69de29b 100644 --- a/external/ffspart/test/results/12-bad-numbers-base.out +++ b/external/ffspart/test/results/12-bad-numbers-base.out @@ -1 +0,0 @@ -Freeing hdr diff --git a/external/ffspart/test/results/13-bad-numbers-size.out b/external/ffspart/test/results/13-bad-numbers-size.out index aad57ac2..e69de29b 100644 --- a/external/ffspart/test/results/13-bad-numbers-size.out +++ b/external/ffspart/test/results/13-bad-numbers-size.out @@ -1 +0,0 @@ -Freeing hdr diff --git a/external/ffspart/test/results/14-bad-input-flags.out b/external/ffspart/test/results/14-bad-input-flags.out index aad57ac2..e69de29b 100644 --- a/external/ffspart/test/results/14-bad-input-flags.out +++ b/external/ffspart/test/results/14-bad-input-flags.out @@ -1 +0,0 @@ -Freeing hdr diff --git a/external/ffspart/test/results/15-overlapping-partitions.out b/external/ffspart/test/results/15-overlapping-partitions.out index 874953b2..04e04c30 100644 --- a/external/ffspart/test/results/15-overlapping-partitions.out +++ b/external/ffspart/test/results/15-overlapping-partitions.out @@ -1,3 +1,2 @@ Adding 'ONE' 0x00000300, 0x00000100 Adding 'TWO' 0x00000350, 0x00000100 -Freeing hdr diff --git a/libflash/ffs.h b/libflash/ffs.h index 957155b9..7a362215 100644 --- a/libflash/ffs.h +++ b/libflash/ffs.h @@ -159,7 +159,6 @@ struct ffs_entry { enum ffs_type type; uint32_t flags; struct ffs_entry_user user; - struct list_node list; }; @@ -204,7 +203,8 @@ struct __ffs_hdr { * @size: Size of partition table (in bytes) * @block_size: Size of block on device (in bytes) * @block_count: Number of blocks on device. - * @entries: List of partition entries + * @count: Count of the number of entires + * @entries: Array of partition entries. */ struct ffs_hdr { uint32_t version; @@ -212,8 +212,10 @@ struct ffs_hdr { uint32_t size; uint32_t block_size; uint32_t block_count; + uint32_t count; struct ffs_entry *part; - struct list_head entries; + struct ffs_entry **entries; + unsigned int entries_size; }; #endif /* __FFS_H__ */ diff --git a/libflash/libffs.c b/libflash/libffs.c index 5888c73f..8c46ce7e 100644 --- a/libflash/libffs.c +++ b/libflash/libffs.c @@ -36,6 +36,7 @@ static void *calloc(size_t num, size_t size) #include "ffs.h" #define __unused __attribute__((unused)) +#define HDR_ENTRIES_NUM 30 struct ffs_handle { struct ffs_hdr hdr; /* Converted header */ @@ -73,13 +74,9 @@ static size_t ffs_hdr_raw_size(int num_entries) static int ffs_num_entries(struct ffs_hdr *hdr) { - struct ffs_entry *ent; - int num_entries = 0; - list_for_each(&hdr->entries, ent, list) - num_entries++; - if (num_entries == 0) + if (hdr->count == 0) FL_DBG("%s returned zero!\n", __func__); - return num_entries; + return hdr->count; } static int ffs_check_convert_header(struct ffs_hdr *dst, struct __ffs_hdr *src) @@ -100,6 +97,7 @@ static int ffs_check_convert_header(struct ffs_hdr *dst, struct __ffs_hdr *src) dst->block_size = be32_to_cpu(src->block_size); dst->size = be32_to_cpu(src->size) * dst->block_size; dst->block_count = be32_to_cpu(src->block_count); + dst->entries_size = be32_to_cpu(src->entry_count); return 0; } @@ -129,21 +127,16 @@ static int ffs_entry_user_to_cpu(struct ffs_hdr *hdr __unused, static int ffs_entry_to_flash(struct ffs_hdr *hdr, struct __ffs_entry *dst, struct ffs_entry *src) { - int rc, index = 1; /* On flash indexes start at 1 */ - struct ffs_entry *ent = NULL; + int rc, index; if (!hdr || !dst || !src) return -1; - list_for_each(&hdr->entries, ent, list) { - if (ent == src) - break; - index++; - } + for (index = 0; index < hdr->count && hdr->entries[index] != src; index++); - if (!ent) + if (index == hdr->count) return FFS_ERR_PART_NOT_FOUND; - + index++; /* On flash indexes start at 1 */ /* * So that the checksum gets calculated correctly at least the * dst->checksum must be zero before calling ffs_entry_checksum() @@ -277,15 +270,9 @@ bool has_flag(struct ffs_entry *ent, uint16_t flag) struct ffs_entry *ffs_entry_get(struct ffs_handle *ffs, uint32_t index) { - int i = 0; - struct ffs_entry *ent = NULL; - - list_for_each(&ffs->hdr.entries, ent, list) - if (i++ == index) - return ent; - - /* Didn't find partition */ - return NULL; + if (!ffs || index >= ffs->hdr.count) + return NULL; + return ffs->hdr.entries[index]; } bool has_ecc(struct ffs_entry *ent) @@ -351,7 +338,6 @@ int ffs_init(uint32_t offset, uint32_t max_size, struct blocklevel_device *bl, f->toc_offset = offset; f->max_size = max_size; f->bl = bl; - list_head_init(&f->hdr.entries); /* Convert and check flash header */ rc = ffs_check_convert_header(&f->hdr, &raw_hdr); @@ -367,6 +353,8 @@ int ffs_init(uint32_t offset, uint32_t max_size, struct blocklevel_device *bl, goto out; } + f->hdr.entries = calloc(f->hdr.entries_size, sizeof(struct ffs_entry *)); + /* * Grab the entire partition header */ @@ -394,14 +382,14 @@ int ffs_init(uint32_t offset, uint32_t max_size, struct blocklevel_device *bl, goto out; } - for (i = 0; i < be32_to_cpu(raw_hdr.entry_count); i++) { + for (i = 0; i < f->hdr.entries_size; i++) { struct ffs_entry *ent = calloc(1, sizeof(struct ffs_entry)); if (!ent) { rc = FLASH_ERR_MALLOC_FAILED; goto out; } - list_add_tail(&f->hdr.entries, &ent->list); + f->hdr.entries[f->hdr.count++] = ent; rc = ffs_entry_to_cpu(&f->hdr, ent, &f->cache->entries[i]); if (rc) { FL_DBG("FFS: Failed checksum for partition %s\n", @@ -430,20 +418,20 @@ out: static void __hdr_free(struct ffs_hdr *hdr) { - struct ffs_entry *ent, *next; + int i; - list_for_each_safe(&hdr->entries, ent, next, list) { - list_del(&ent->list); - free(ent); - } + if (!hdr) + return; + + for (i = 0; i < hdr->count; i++) + free(hdr->entries[i]); + free(hdr->entries); } int ffs_hdr_free(struct ffs_hdr *hdr) { - printf("Freeing hdr\n"); __hdr_free(hdr); free(hdr); - return 0; } @@ -460,20 +448,20 @@ void ffs_close(struct ffs_handle *ffs) int ffs_lookup_part(struct ffs_handle *ffs, const char *name, uint32_t *part_idx) { - struct ffs_entry *ent = NULL; - int i = 0, rc = FFS_ERR_PART_NOT_FOUND; + struct ffs_entry **ents = ffs->hdr.entries; + int i; - list_for_each(&ffs->hdr.entries, ent, list) { - if (strncmp(name, ent->name, sizeof(ent->name)) == 0) { - rc = 0; - break; - } - i++; - } + for (i = 0; + i < ffs->hdr.count && + strncmp(name, ents[i]->name, FFS_PART_NAME_MAX); + i++); - if (rc == 0 && part_idx) + if (i == ffs->hdr.count) + return FFS_ERR_PART_NOT_FOUND; + + if (part_idx) *part_idx = i; - return rc; + return 0; } int ffs_part_info(struct ffs_handle *ffs, uint32_t part_idx, @@ -548,19 +536,25 @@ int ffs_next_side(struct ffs_handle *ffs, struct ffs_handle **new_ffs, int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry) { - struct ffs_entry *ent; - uint32_t smallest_base; const char *smallest_name; - int count = 0; - assert(!list_empty(&hdr->entries)); + uint32_t smallest_base; + int i; + if (hdr->count == 0) { + FL_DBG("Adding an entry to an empty header\n"); + hdr->entries[hdr->count++] = entry; + } if (entry->base + entry->size > hdr->block_size * hdr->block_count) return FFS_ERR_BAD_PART_SIZE; smallest_base = entry->base; smallest_name = entry->name; - /* Input validate first to a) fail early b) do it all together */ - list_for_each(&hdr->entries, ent, list) { + /* + * TODO: This may have assumed entries was sorted + */ + for (i = 0; i < hdr->count; i++) { + struct ffs_entry *ent = hdr->entries[i]; + /* Don't allow same names to differ only by case */ if (strncasecmp(entry->name, ent->name, FFS_PART_NAME_MAX) == 0) return FFS_ERR_BAD_PART_NAME; @@ -579,14 +573,12 @@ int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry) return FFS_ERR_BAD_PART_PID; /* Skip the first partition as it IS the partition table */ - if (ent->base < smallest_base && count > 0) { + if (ent->base < smallest_base && i > 0) { smallest_base = ent->base; smallest_name = ent->name; } - count++; } - - if ((count + 1) * sizeof(struct __ffs_entry) + + if ((hdr->count + 1) * sizeof(struct __ffs_entry) + sizeof(struct __ffs_hdr) > smallest_base) { fprintf(stderr, "Adding partition '%s' would cause partition '%s' at " "0x%08x to overlap with the header\n", entry->name, smallest_name, @@ -594,7 +586,18 @@ int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry) return FFS_ERR_BAD_PART_BASE; } - list_add_tail(&hdr->entries, &entry->list); + if (hdr->count == hdr->entries_size) { + struct ffs_entry **old = hdr->entries; + + hdr->entries = realloc(hdr->entries, + (HDR_ENTRIES_NUM + hdr->entries_size) * sizeof(struct ffs_entry *)); + if (!hdr->entries) { + hdr->entries = old; + return FLASH_ERR_MALLOC_FAILED; + } + hdr->entries_size += HDR_ENTRIES_NUM; + } + hdr->entries[hdr->count++] = entry; return 0; } @@ -602,7 +605,6 @@ int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry) int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr) { int num_entries, i, rc = 0; - struct ffs_entry *ent; struct __ffs_hdr *real_hdr; num_entries = ffs_num_entries(hdr); @@ -638,14 +640,12 @@ int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr) real_hdr->block_count = cpu_to_be32(hdr->block_count); real_hdr->checksum = ffs_hdr_checksum(real_hdr); - i = 0; - list_for_each(&hdr->entries, ent, list) { - rc = ffs_entry_to_flash(hdr, real_hdr->entries + i, ent); + for (i = 0; i < hdr->count; i++) { + rc = ffs_entry_to_flash(hdr, real_hdr->entries + i, hdr->entries[i]); if (rc) { fprintf(stderr, "Couldn't format all entries for new TOC\n"); goto out; } - i++; } /* Don't really care if this fails */ @@ -745,7 +745,8 @@ int ffs_hdr_new(uint32_t block_size, uint32_t block_count, struct ffs_hdr **r) ret->version = FFS_VERSION_1; ret->block_size = block_size; ret->block_count = block_count; - list_head_init(&ret->entries); + ret->entries = calloc(HDR_ENTRIES_NUM, sizeof(struct ffs_entry *)); + ret->entries_size = HDR_ENTRIES_NUM; /* Don't know how big it will be, ffs_hdr_finalise() will fix */ rc = ffs_entry_new("part", 0, 0, &part_table); @@ -759,7 +760,8 @@ int ffs_hdr_new(uint32_t block_size, uint32_t block_count, struct ffs_hdr **r) part_table->type = FFS_TYPE_PARTITION; part_table->flags = FFS_FLAGS_PROTECTED; - list_add(&ret->entries, &part_table->list); + ret->entries[0] = part_table; + ret->count = 1; *r = ret; From patchwork Tue Aug 29 06:25:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 806972 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 3xhJwq5ws0z9ryr for ; Tue, 29 Aug 2017 16:42:51 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xhJwq4HXQzDqZB for ; Tue, 29 Aug 2017 16:42:51 +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 3xhJY65Y3yzDqb5 for ; Tue, 29 Aug 2017 16:25:46 +1000 (AEST) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7T6OWCG120155 for ; Tue, 29 Aug 2017 02:25:41 -0400 Received: from e23smtp04.au.ibm.com (e23smtp04.au.ibm.com [202.81.31.146]) by mx0a-001b2d01.pphosted.com with ESMTP id 2cn1kje0kp-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 29 Aug 2017 02:25:40 -0400 Received: from localhost by e23smtp04.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 d23relay07.au.ibm.com (202.81.31.226) by e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 29 Aug 2017 16:25:37 +1000 Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay07.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7T6Pabe37355602 for ; Tue, 29 Aug 2017 16:25:36 +1000 Received: from d23av04.au.ibm.com (localhost [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v7T6PbgY017789 for ; Tue, 29 Aug 2017 16:25:37 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v7T6PaBg017744; Tue, 29 Aug 2017 16:25:36 +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 9C76DA0259; 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:25:04 +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-0012-0000-0000-0000025A9F5B X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17082906-0013-0000-0000-0000077669DE Message-Id: <20170829062506.8317-12-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=2 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 11/13] libflash/libffs: Refcount ffs entries 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" Currently consumers can add an new ffs entry to multiple headers, this is fine but freeing any of the headers will cause the entry to be freed, this causes double free problems. Even if only one header is uses, the consumer of the library still has a reference to the entry, which they may well reuse at some other point. libffs will now refcount entries and only free when there are no more references. This patch also removes the pointless return value of ffs_hdr_free() Signed-off-by: Cyril Bur --- external/ffspart/ffspart.c | 2 +- external/pflash/pflash.c | 2 ++ libflash/ffs.h | 2 ++ libflash/libffs.c | 38 +++++++++++++++++++++++++++++++------- libflash/libffs.h | 4 +++- 5 files changed, 39 insertions(+), 9 deletions(-) diff --git a/external/ffspart/ffspart.c b/external/ffspart/ffspart.c index 74e12ff6..cd944651 100644 --- a/external/ffspart/ffspart.c +++ b/external/ffspart/ffspart.c @@ -338,7 +338,7 @@ out_if: continue; out_while: - free(new_entry); + ffs_entry_put(new_entry); goto out_close_bl; } diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c index 3be43ac0..f7610710 100644 --- a/external/pflash/pflash.c +++ b/external/pflash/pflash.c @@ -116,6 +116,7 @@ static uint32_t print_ffs_info(struct ffs_handle *ffsh, uint32_t toc) } user = ffs_entry_user_get(ent); + ffs_entry_put(ent); flags = ffs_entry_user_to_string(&user); if (!flags) goto out; @@ -567,6 +568,7 @@ static void print_partition_detail(struct ffs_handle *ffsh, uint32_t part_id) has_flag(ent, FFS_MISCFLAGS_BACKUP) ? "BACKUP [B]\n" : "", has_flag(ent, FFS_MISCFLAGS_REPROVISION) ? "REPROVISION [F]\n" : ""); + ffs_entry_put(ent); if (l < 0) { fprintf(stderr, "Memory allocation failure printing flags!\n"); goto out; diff --git a/libflash/ffs.h b/libflash/ffs.h index 7a362215..6a5ad49f 100644 --- a/libflash/ffs.h +++ b/libflash/ffs.h @@ -149,6 +149,7 @@ struct __ffs_entry { * @type: Describe type of partition * @flags: Partition attributes (optional) * @user: User data (optional) + * @ref: Refcount */ struct ffs_entry { char name[FFS_PART_NAME_MAX + 1]; @@ -159,6 +160,7 @@ struct ffs_entry { enum ffs_type type; uint32_t flags; struct ffs_entry_user user; + unsigned int ref; }; diff --git a/libflash/libffs.c b/libflash/libffs.c index 8c46ce7e..a9a2b961 100644 --- a/libflash/libffs.c +++ b/libflash/libffs.c @@ -268,13 +268,35 @@ bool has_flag(struct ffs_entry *ent, uint16_t flag) return ((ent->user.miscflags & flag) != 0); } -struct ffs_entry *ffs_entry_get(struct ffs_handle *ffs, uint32_t index) +static struct ffs_entry *__ffs_entry_get(struct ffs_handle *ffs, uint32_t index) { - if (!ffs || index >= ffs->hdr.count) + if (index >= ffs->hdr.count) return NULL; return ffs->hdr.entries[index]; } +struct ffs_entry *ffs_entry_get(struct ffs_handle *ffs, uint32_t index) +{ + struct ffs_entry *ret = __ffs_entry_get(ffs, index); + if (ret) + ret->ref++; + return ret; +} + +struct ffs_entry *ffs_entry_put(struct ffs_entry *ent) +{ + if (!ent) + return NULL; + + ent->ref--; + if (ent->ref == 0) { + free(ent); + ent = NULL; + } + + return ent; +} + bool has_ecc(struct ffs_entry *ent) { return ((ent->user.datainteg & FFS_ENRY_INTEG_ECC) != 0); @@ -390,6 +412,7 @@ int ffs_init(uint32_t offset, uint32_t max_size, struct blocklevel_device *bl, } f->hdr.entries[f->hdr.count++] = ent; + ent->ref = 1; rc = ffs_entry_to_cpu(&f->hdr, ent, &f->cache->entries[i]); if (rc) { FL_DBG("FFS: Failed checksum for partition %s\n", @@ -424,15 +447,14 @@ static void __hdr_free(struct ffs_hdr *hdr) return; for (i = 0; i < hdr->count; i++) - free(hdr->entries[i]); + ffs_entry_put(hdr->entries[i]); free(hdr->entries); } -int ffs_hdr_free(struct ffs_hdr *hdr) +void ffs_hdr_free(struct ffs_hdr *hdr) { __hdr_free(hdr); free(hdr); - return 0; } void ffs_close(struct ffs_handle *ffs) @@ -471,7 +493,7 @@ int ffs_part_info(struct ffs_handle *ffs, uint32_t part_idx, struct ffs_entry *ent; char *n; - ent = ffs_entry_get(ffs, part_idx); + ent = __ffs_entry_get(ffs, part_idx); if (!ent) return FFS_ERR_PART_NOT_FOUND; @@ -597,6 +619,7 @@ int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry) } hdr->entries_size += HDR_ENTRIES_NUM; } + entry->ref++; hdr->entries[hdr->count++] = entry; return 0; @@ -714,6 +737,7 @@ int ffs_entry_new(const char *name, uint32_t base, uint32_t size, struct ffs_ent ret->actual = size; ret->pid = FFS_PID_TOPLEVEL; ret->type = FFS_TYPE_DATA; + ret->ref = 1; *r = ret; return 0; @@ -776,7 +800,7 @@ int ffs_update_act_size(struct ffs_handle *ffs, uint32_t part_idx, uint32_t offset; int rc; - ent = ffs_entry_get(ffs, part_idx); + ent = __ffs_entry_get(ffs, part_idx); if (!ent) { FL_DBG("FFS: Entry not found\n"); return FFS_ERR_PART_NOT_FOUND; diff --git a/libflash/libffs.h b/libflash/libffs.h index 56428a2c..eabca23a 100644 --- a/libflash/libffs.h +++ b/libflash/libffs.h @@ -145,6 +145,8 @@ int ffs_hdr_add_side(struct ffs_hdr *hdr); int ffs_entry_new(const char *name, uint32_t base, uint32_t size, struct ffs_entry **r); +struct ffs_entry *ffs_entry_put(struct ffs_entry *ent); + int ffs_entry_user_set(struct ffs_entry *ent, struct ffs_entry_user *user); int ffs_entry_set_act_size(struct ffs_entry *ent, uint32_t actual_size); @@ -156,5 +158,5 @@ int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry); int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr); -int ffs_hdr_free(struct ffs_hdr *hdr); +void ffs_hdr_free(struct ffs_hdr *hdr); #endif /* __LIBFFS_H */ From patchwork Tue Aug 29 06:25:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 806968 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 3xhJw20CLQz9ryr for ; Tue, 29 Aug 2017 16:42:10 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xhJw16PKFzDrJw for ; Tue, 29 Aug 2017 16:42:09 +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 3xhJY33HdHzDqYK for ; Tue, 29 Aug 2017 16:25:43 +1000 (AEST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7T6OFgq026392 for ; Tue, 29 Aug 2017 02:25:41 -0400 Received: from e23smtp04.au.ibm.com (e23smtp04.au.ibm.com [202.81.31.146]) by mx0a-001b2d01.pphosted.com with ESMTP id 2cmvyf64rv-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 29 Aug 2017 02:25:40 -0400 Received: from localhost by e23smtp04.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 e23smtp04.au.ibm.com (202.81.31.210) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 29 Aug 2017 16:25:37 +1000 Received: from d23av06.au.ibm.com (d23av06.au.ibm.com [9.190.235.151]) by d23relay09.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7T6PaEq27197564 for ; Tue, 29 Aug 2017 16:25:36 +1000 Received: from d23av06.au.ibm.com (localhost [127.0.0.1]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id v7T6PafZ016435 for ; Tue, 29 Aug 2017 16:25:36 +1000 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av06.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id v7T6PZ6W016425; Tue, 29 Aug 2017 16:25:36 +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 AB0C4A0273; 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:25:05 +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-0012-0000-0000-0000025A9F5A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17082906-0013-0000-0000-0000077669DD Message-Id: <20170829062506.8317-13-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=2 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 12/13] libflash/libffs: Allow caller to specifiy header partition 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" An FFS TOC is comprised of two parts. A small header which has a magic and very minimmal information about the TOC which will be common to all partitions, things like number of patritions, block sizes and the like. Following this small header are a series of entries. Importantly there is always an entry which encompases the TOC its self, this is usually called the 'part' partition. Currently libffs always assumes that the 'part' partition is at zero. While there is always a TOC and zero there doesn't actually have to be. PNORs may have multiple TOCs within them, therefore libffs needs to be flexible enough to allow callers to specify TOCs not at zero. The 'part' partition is otherwise a regular partition which may have flags associated with it. libffs should allow the user to set the flags for the 'part' partition. This patch achieves both by allowing the caller to specify the 'part' partition. The caller can not and libffs will provide a sensible default. Signed-off-by: Cyril Bur --- external/ffspart/ffspart.c | 2 +- libflash/ffs.h | 1 - libflash/libffs.c | 28 ++++++++++++++++++++-------- libflash/libffs.h | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/external/ffspart/ffspart.c b/external/ffspart/ffspart.c index cd944651..9b66f4fe 100644 --- a/external/ffspart/ffspart.c +++ b/external/ffspart/ffspart.c @@ -131,7 +131,7 @@ int main(int argc, char *argv[]) goto out; } - rc = ffs_hdr_new(block_size, block_count, &new_hdr); + rc = ffs_hdr_new(block_size, block_count, NULL, &new_hdr); if (rc) { if (rc == FFS_ERR_BAD_SIZE) { /* Well this check is a tad redudant now */ diff --git a/libflash/ffs.h b/libflash/ffs.h index 6a5ad49f..460f5ca2 100644 --- a/libflash/ffs.h +++ b/libflash/ffs.h @@ -210,7 +210,6 @@ struct __ffs_hdr { */ struct ffs_hdr { uint32_t version; - uint32_t base; uint32_t size; uint32_t block_size; uint32_t block_count; diff --git a/libflash/libffs.c b/libflash/libffs.c index a9a2b961..5accf1ff 100644 --- a/libflash/libffs.c +++ b/libflash/libffs.c @@ -672,8 +672,8 @@ int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr) } /* Don't really care if this fails */ - blocklevel_erase(bl, hdr->base, hdr->size); - rc = blocklevel_write(bl, hdr->base, real_hdr, + blocklevel_erase(bl, hdr->part->base, hdr->size); + rc = blocklevel_write(bl, hdr->part->base, real_hdr, ffs_hdr_raw_size(num_entries)); if (rc) goto out; @@ -756,7 +756,8 @@ int ffs_entry_set_act_size(struct ffs_entry *ent, uint32_t actual_size) return 0; } -int ffs_hdr_new(uint32_t block_size, uint32_t block_count, struct ffs_hdr **r) +int ffs_hdr_new(uint32_t block_size, uint32_t block_count, + struct ffs_entry **e, struct ffs_hdr **r) { struct ffs_hdr *ret; struct ffs_entry *part_table; @@ -772,12 +773,23 @@ int ffs_hdr_new(uint32_t block_size, uint32_t block_count, struct ffs_hdr **r) ret->entries = calloc(HDR_ENTRIES_NUM, sizeof(struct ffs_entry *)); ret->entries_size = HDR_ENTRIES_NUM; - /* Don't know how big it will be, ffs_hdr_finalise() will fix */ - rc = ffs_entry_new("part", 0, 0, &part_table); - if (rc) { - free(ret); - return rc; + if (!e || !(*e)) { + /* Don't know how big it will be, ffs_hdr_finalise() will fix */ + rc = ffs_entry_new("part", 0, 0, &part_table); + if (rc) { + free(ret); + return rc; + } + if (e) + *e = part_table; + } else { + part_table = *e; } + + /* If the user still holds a ref to e, then inc the refcount */ + if (e) + part_table->ref++; + ret->part = part_table; part_table->pid = FFS_PID_TOPLEVEL; diff --git a/libflash/libffs.h b/libflash/libffs.h index eabca23a..d820838c 100644 --- a/libflash/libffs.h +++ b/libflash/libffs.h @@ -139,7 +139,7 @@ int ffs_update_act_size(struct ffs_handle *ffs, uint32_t part_idx, uint32_t act_size); int ffs_hdr_new(uint32_t block_size, uint32_t block_count, - struct ffs_hdr **r); + struct ffs_entry **e, struct ffs_hdr **r); int ffs_hdr_add_side(struct ffs_hdr *hdr); From patchwork Tue Aug 29 06:25:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Bur X-Patchwork-Id: 806976 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xhJxl5gw3z9ryr for ; Tue, 29 Aug 2017 16:43:39 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3xhJxl4rW0zDrLy for ; Tue, 29 Aug 2017 16:43:39 +1000 (AEST) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 3xhJY932g1zDqZq for ; Tue, 29 Aug 2017 16:25:49 +1000 (AEST) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v7T6OCCf025387 for ; Tue, 29 Aug 2017 02:25:43 -0400 Received: from e23smtp06.au.ibm.com (e23smtp06.au.ibm.com [202.81.31.148]) by mx0b-001b2d01.pphosted.com with ESMTP id 2cmvhgxvh3-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 29 Aug 2017 02:25:41 -0400 Received: from localhost by e23smtp06.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 d23relay10.au.ibm.com (202.81.31.229) by e23smtp06.au.ibm.com (202.81.31.212) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 29 Aug 2017 16:25:37 +1000 Received: from d23av05.au.ibm.com (d23av05.au.ibm.com [9.190.234.119]) by d23relay10.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v7T6PaQ018546784 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 v7T6PatP017758 for ; Tue, 29 Aug 2017 16:25:36 +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 v7T6PaTP017752; Tue, 29 Aug 2017 16:25:36 +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 BC00BA0258; 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:25:06 +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-0040-0000-0000-00000351E323 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17082906-0041-0000-0000-00000CCFDD92 Message-Id: <20170829062506.8317-14-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=29 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 13/13] external/ffspart: Use new interface 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" This also updated the pflash tests which use ffspart to generate pnors Signed-off-by: Cyril Bur --- external/ffspart/ffspart.c | 527 +++++++++++++-------- external/ffspart/test/files/03-tiny-pnor.in | 8 +- .../ffspart/test/files/03.1-tiny-pnor-backup.in | 4 - .../ffspart/test/files/03.1-tiny-pnor-backup.out | Bin 3840 -> 0 bytes external/ffspart/test/files/04-tiny-pnor2.in | 8 +- external/ffspart/test/files/05-hdr-overlap.in | 8 +- .../ffspart/test/files/05.1-hdr-overlap-backup.in | 3 - external/ffspart/test/files/06-small-flash.in | 10 +- external/ffspart/test/files/07-big-files.in | 8 +- external/ffspart/test/files/08-small-files.in | 8 +- external/ffspart/test/files/10-bad-input.in | 8 +- external/ffspart/test/files/11-long-name.in | 8 +- external/ffspart/test/files/12-bad-numbers-base.in | 8 +- external/ffspart/test/files/13-bad-numbers-size.in | 8 +- external/ffspart/test/files/14-bad-input-flags.in | 8 +- .../test/files/15-overlapping-partitions.in | 8 +- external/ffspart/test/results/01-param-sanity.err | 1 - external/ffspart/test/results/01-param-sanity.out | 5 - .../ffspart/test/results/01.1-param-sanity.err | 0 .../{02-param-sides.out => 01.1-param-sanity.out} | 5 - external/ffspart/test/results/02-param-sides.err | 1 - external/ffspart/test/results/05-hdr-overlap.err | 5 +- external/ffspart/test/results/05-hdr-overlap.out | 3 - .../test/results/05.1-hdr-overlap-backup.err | 2 - .../test/results/05.1-hdr-overlap-backup.out | 4 - external/ffspart/test/results/06-small-flash.err | 5 +- external/ffspart/test/results/06-small-flash.out | 2 - external/ffspart/test/results/07-big-files.err | 5 +- external/ffspart/test/results/07-big-files.out | 1 - external/ffspart/test/results/08-small-files.err | 2 + external/ffspart/test/results/08-small-files.out | 4 - external/ffspart/test/results/10-bad-input.err | 5 +- external/ffspart/test/results/11-long-name.err | 6 +- external/ffspart/test/results/11-long-name.out | 4 - .../ffspart/test/results/12-bad-numbers-base.err | 5 +- .../ffspart/test/results/13-bad-numbers-size.err | 5 +- .../ffspart/test/results/14-bad-input-flags.err | 5 +- .../test/results/15-overlapping-partitions.err | 5 +- .../test/results/15-overlapping-partitions.out | 2 - external/ffspart/test/tests/01-param-sanity | 6 +- external/ffspart/test/tests/01.1-param-sanity | 12 + external/ffspart/test/tests/02-param-sides | 16 - external/ffspart/test/tests/03.1-tiny-pnor-backup | 19 - external/ffspart/test/tests/05-hdr-overlap | 7 +- .../ffspart/test/tests/05.1-hdr-overlap-backup | 19 - external/ffspart/test/tests/06-small-flash | 5 +- external/ffspart/test/tests/07-big-files | 4 + external/ffspart/test/tests/10-bad-input | 2 + external/ffspart/test/tests/12-bad-numbers-base | 2 + external/ffspart/test/tests/13-bad-numbers-size | 2 + external/ffspart/test/tests/14-bad-input-flags | 2 + .../ffspart/test/tests/15-overlapping-partitions | 4 +- external/pflash/test/files/01-info.ffs | 8 +- external/pflash/test/files/02-erase.ffs | 8 +- external/pflash/test/files/03-erase-parts.ffs | 8 +- external/pflash/test/files/04-program-rand.ffs | 8 +- external/pflash/test/files/05-bad-numbers.ffs | 8 +- external/pflash/test/files/06-miscprint.ffs | 8 +- external/pflash/test/results/06-miscprint.out | 2 +- libflash/libffs.c | 5 +- 60 files changed, 480 insertions(+), 389 deletions(-) delete mode 100644 external/ffspart/test/files/03.1-tiny-pnor-backup.in delete mode 100644 external/ffspart/test/files/03.1-tiny-pnor-backup.out delete mode 100644 external/ffspart/test/files/05.1-hdr-overlap-backup.in create mode 100644 external/ffspart/test/results/01.1-param-sanity.err rename external/ffspart/test/results/{02-param-sides.out => 01.1-param-sanity.out} (67%) delete mode 100644 external/ffspart/test/results/02-param-sides.err delete mode 100644 external/ffspart/test/results/05.1-hdr-overlap-backup.err delete mode 100644 external/ffspart/test/results/05.1-hdr-overlap-backup.out create mode 100644 external/ffspart/test/tests/01.1-param-sanity delete mode 100644 external/ffspart/test/tests/02-param-sides delete mode 100644 external/ffspart/test/tests/03.1-tiny-pnor-backup delete mode 100644 external/ffspart/test/tests/05.1-hdr-overlap-backup diff --git a/external/ffspart/ffspart.c b/external/ffspart/ffspart.c index 9b66f4fe..0f5d7d6f 100644 --- a/external/ffspart/ffspart.c +++ b/external/ffspart/ffspart.c @@ -1,4 +1,4 @@ -/* Copyright 2013-2016 IBM Corp. +/* Copyright 2013-2017 IBM Corp. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include #include #include @@ -50,11 +51,250 @@ * Lets do 50. */ #define MAX_LINE 100 +#define MAX_TOCS 10 #define SEPARATOR ',' /* Full version number (possibly includes gitid). */ extern const char version[]; +static int read_u32(const char *input, uint32_t *val) +{ + char *endptr; + *val = strtoul(input, &endptr, 0); + return (*endptr == SEPARATOR) ? 0 : 1; +} + +static const char *advance_line(const char *input) +{ + char *pos = strchr(input, SEPARATOR); + if (!pos) + return NULL; + return pos + 1; +} + +static struct ffs_hdr *parse_toc(const char *line, uint32_t block_size, + uint32_t block_count) +{ + struct ffs_entry_user user; + struct ffs_entry *ent; + struct ffs_hdr *hdr; + uint32_t tbase; + int rc; + + if (read_u32(line, &tbase)) { + fprintf(stderr, "Couldn't parse TOC base address\n"); + return NULL; + } + + line = advance_line(line); + if (!line) { + fprintf(stderr, "Couldn't find TOC flags\n"); + return NULL; + } + + rc = ffs_string_to_entry_user(line, strlen(line), &user); + if (rc) { + fprintf(stderr, "Couldn't parse TOC flags\n"); + return NULL; + } + + rc = ffs_entry_new("part", tbase, 0, &ent); + if (rc) { + fprintf(stderr, "Couldn't make entry for TOC@0x%08x\n", tbase); + return NULL; + } + + rc = ffs_entry_user_set(ent, &user); + if (rc) { + fprintf(stderr, "Invalid TOC flag\n"); + ffs_entry_put(ent); + return NULL; + } + + rc = ffs_hdr_new(block_size, block_count, &ent, &hdr); + if (rc) { + hdr = NULL; + fprintf(stderr, "Couldn't make header for TOC@0x%08x\n", tbase); + } + + ffs_entry_put(ent); + return hdr; +} + +static int parse_entry(struct blocklevel_device *bl, + struct ffs_hdr **tocs, const char *line) +{ + char name[FFS_PART_NAME_MAX + 2] = { 0 }; + struct ffs_entry_user user = { 0 }; + uint32_t pbase, psize, pactual; + struct ffs_entry *new_entry; + struct stat data_stat; + const char *filename; + bool added = false; + uint8_t *data_ptr; + int data_fd, rc; + char *pos; + + memcpy(name, line, FFS_PART_NAME_MAX + 1); + pos = strchr(name, SEPARATOR); + /* There is discussion to be had as to if we should bail here */ + if (!pos) { + fprintf(stderr, "WARNING: Long partition name will get truncated to '%s'\n", + name); + name[FFS_PART_NAME_MAX] = '\0'; + } else { + *pos = '\0'; + } + + line = advance_line(line); + if (!line || read_u32(line, &pbase)) { + fprintf(stderr, "Couldn't parse '%s' partition base address\n", + name); + return -1; + } + + line = advance_line(line); + if (!line || read_u32(line, &psize)) { + fprintf(stderr, "Couldn't parse '%s' partition length\n", + name); + return -1; + } + + line = advance_line(line); + if (!line || !advance_line(line)) { + fprintf(stderr, "Couldn't find '%s' partition flags\n", + name); + return -1; + } + + rc = ffs_string_to_entry_user(line, advance_line(line) - 1 - line, &user); + if (rc) { + fprintf(stderr, "Couldn't parse '%s' partition flags\n", + name); + return -1; + } + line = advance_line(line); + /* Already checked return value */ + + rc = ffs_entry_new(name, pbase, psize, &new_entry); + if (rc) { + fprintf(stderr, "Invalid entry '%s' 0x%08x for 0x%08x\n", + name, pbase, psize); + return -1; + } + + rc = ffs_entry_user_set(new_entry, &user); + if (rc) { + fprintf(stderr, "Couldn't set '%s' partition flags\n", + name); + ffs_entry_put(new_entry); + return -1; + } + + if (has_flag(new_entry, FFS_MISCFLAGS_BACKUP)) { + rc = ffs_entry_set_act_size(new_entry, 0); + if (rc) { + fprintf(stderr, "Couldn't set '%s' partition actual size\n", + name); + ffs_entry_put(new_entry); + return -1; + } + } + + if (!advance_line(line)) { + fprintf(stderr, "Missing TOC field for '%s' partition\n", + name); + ffs_entry_put(new_entry); + return -1; + } + + while (*line != SEPARATOR) { + int toc = *(line++); + + if (!isdigit(toc)) { + fprintf(stderr, "Bad TOC value %d (%c) for '%s' partition\n", + toc, toc, name); + ffs_entry_put(new_entry); + return -1; + } + toc -= '0'; + if (!tocs[toc]) { + fprintf(stderr, "No TOC with ID %d for '%s' partition\n", + toc, name); + ffs_entry_put(new_entry); + return -1; + } + rc = ffs_entry_add(tocs[toc], new_entry); + if (rc) { + fprintf(stderr, "Couldn't add '%s' parition to TOC %d\n", + name, toc); + ffs_entry_put(new_entry); + return rc; + } + added = true; + } + if (!added) { + /* + * They didn't specify a TOC in the TOC field, use + * TOC@0 as the default + */ + rc = ffs_entry_add(tocs[0], new_entry); + if (rc) { + fprintf(stderr, "Couldn't add '%s' partition to default TOC: %d\n", + name, rc); + ffs_entry_put(new_entry); + return rc; + } + } + ffs_entry_put(new_entry); + + if (*line != '\0' && *(line + 1) != '\0') { + filename = line + 1; + data_fd = open(filename, O_RDONLY); + if (data_fd == -1) { + fprintf(stderr, "Couldn't open file '%s' for '%s' partition " + "(%m)\n", filename, name); + return -1; + } + + if (fstat(data_fd, &data_stat) == -1) { + fprintf(stderr, "Couldn't stat file '%s' for '%s' partition " + "(%m)\n", filename, name); + close(data_fd); + return -1; + } + pactual = data_stat.st_size; + + /* + * Sanity check that the file isn't too large for + * partition + */ + if (pactual > psize) { + fprintf(stderr, "File '%s' for partition '%s' is too large\n", + filename, name); + close(data_fd); + return -1; + } + + data_ptr = mmap(NULL, pactual, PROT_READ, MAP_SHARED, data_fd, 0); + if (!data_ptr) { + fprintf(stderr, "Couldn't mmap file '%s' for '%s' partition " + "(%m)\n", filename, name); + close(data_fd); + return -1; + } + + rc = blocklevel_write(bl, pbase, data_ptr, pactual); + if (rc) + fprintf(stderr, "Couldn't write file '%s' for '%s' partition to PNOR " + "(%m)\n", filename, name); + munmap(data_ptr, pactual); + close(data_fd); + } + + return 0; +} + static void print_version(void) { printf("Open-Power FFS format tool %s\n", version); @@ -77,20 +317,19 @@ static void print_help(const char *pname) int main(int argc, char *argv[]) { - const char *pname = argv[0]; - struct blocklevel_device *bl = NULL; + char *pnor = NULL, *input = NULL, line[MAX_LINE]; + bool toc_created = false, bad_input = false; uint32_t block_size = 0, block_count = 0; - bool bad_input = false; - char *pnor = NULL, *input = NULL; - struct ffs_hdr *new_hdr; + struct ffs_hdr *tocs[MAX_TOCS] = { 0 }; + struct blocklevel_device *bl = NULL; + const char *pname = argv[0]; + int line_number, rc, i; FILE *in_file; - char line[MAX_LINE]; - int rc; while(1) { struct option long_opts[] = { - {"block_size", required_argument, NULL, 's'}, {"block_count", required_argument, NULL, 'c'}, + {"block_size", required_argument, NULL, 's'}, {"debug", no_argument, NULL, 'g'}, {"input", required_argument, NULL, 'i'}, {"pnor", required_argument, NULL, 'p'}, @@ -98,7 +337,7 @@ int main(int argc, char *argv[]) }; int c, oidx = 0; - c = getopt_long(argc, argv, "c:gi:p:s:", long_opts, &oidx); + c = getopt_long(argc, argv, "+:c:gi:p:s:", long_opts, &oidx); if (c == EOF) break; switch(c) { @@ -109,50 +348,55 @@ int main(int argc, char *argv[]) libflash_debug = true; break; case 'i': + free(input); input = strdup(optarg); + if (!input) + fprintf(stderr, "Out of memory!\n"); break; case 'p': + free(pnor); pnor = strdup(optarg); + if (!pnor) + fprintf(stderr, "Out of memory!\n"); break; case 's': block_size = strtoul(optarg, NULL, 0); break; + case ':': + fprintf(stderr, "Unrecognised option \"%s\" to '%c'\n", + optarg, optopt); + bad_input = true; + break; + case '?': + fprintf(stderr, "Unrecognised option '%c'\n", optopt); + bad_input = true; + break; default: - exit(1); + fprintf(stderr , "Encountered unknown error parsing options\n"); + bad_input = true; } } - if (!block_size || !block_count || !input || !pnor) - bad_input = true; - - if (bad_input) { + if (bad_input || !block_size || !block_count || !input || !pnor) { print_help(pname); - rc = 1; - goto out; - } - - rc = ffs_hdr_new(block_size, block_count, NULL, &new_hdr); - if (rc) { - if (rc == FFS_ERR_BAD_SIZE) { - /* Well this check is a tad redudant now */ - fprintf(stderr, "Bad parametres passed to libffs\n"); - } else { - fprintf(stderr, "Error %d initialising new TOC\n", rc); - } - goto out; + return 1; } in_file = fopen(input, "r"); if (!in_file) { - rc = errno; - fprintf(stderr, "Couldn't open your input file %s because %s\n", input, strerror(errno)); - goto out_free_hdr; + fprintf(stderr, "Couldn't open your input file %s: %m\n", input); + return 2; } + /* + * TODO: This won't create the file. + * We should do this + */ rc = arch_flash_init(&bl, pnor, true); if (rc) { fprintf(stderr, "Couldn't initialise architecture flash structures\n"); - goto out_close_f; + fclose(in_file); + return 3; } /* @@ -161,16 +405,14 @@ int main(int argc, char *argv[]) */ rc = blocklevel_erase(bl, 0, block_size * block_count); if (rc) { - fprintf(stderr, "Couldn't erase file\n"); - goto out_close_bl; + fprintf(stderr, "Couldn't erase '%s' pnor file\n", pnor); + fclose(in_file); + return 4; } + line_number = 0; while (fgets(line, MAX_LINE, in_file) != NULL) { - struct ffs_entry *new_entry; - struct ffs_entry_user user = { 0 }; - char *pos, *old_pos; - char *name, *endptr; - uint32_t pbase, psize, pactual = 0; + line_number++; /* Inline comments in input file */ if (line[0] == '#') @@ -179,180 +421,71 @@ int main(int argc, char *argv[]) if (line[strlen(line) - 1] == '\n') line[strlen(line) - 1] = '\0'; - pos = strchr(line, SEPARATOR); - if (!pos) { - fprintf(stderr, "Invalid input file format: Couldn't find name\n"); - rc = -1; - goto out_close_bl; - } - *pos = '\0'; - name = line; - /* There is discussion to be had as to if we should bail here */ - if (pos - line > FFS_PART_NAME_MAX) - fprintf(stderr, "WARNING: Long partition '%s' name will get truncated\n", - line); - - pos++; - old_pos = pos; - pos = strchr(pos, SEPARATOR); - if (!pos) { - fprintf(stderr, "Invalid input file format: Couldn't find base\n"); - rc = -1; - goto out_close_bl; - } - *pos = '\0'; - pbase = strtoul(old_pos, &endptr, 0); - if (*endptr != '\0') { - fprintf(stderr, "Invalid input file format: Couldn't parse " - "'%s' partition base address\n", name); - rc = -1; - goto out_close_bl; - } - - pos++; - old_pos = pos; - pos = strchr(pos, SEPARATOR); - if (!pos) { - fprintf(stderr, "Invalid input file format: Couldn't find size\n"); - rc = -1; - goto out_close_bl; - } - *pos = '\0'; - psize = strtoul(old_pos, &endptr, 0); - if (*endptr != '\0') { - fprintf(stderr, "Invalid input file format: Couldn't parse " - "'%s' partition length\n", name); - rc = -1; - goto out_close_bl; - } + if (line[0] == '@') { + int toc_num = line[1]; + rc = 5; - pos++; - while (*pos != '\0' && *pos != SEPARATOR) { - switch (*pos) { - 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 'F': - user.miscflags |= FFS_MISCFLAGS_REPROVISION; - break; - /* Not sure these are valid */ - case 'B': - user.miscflags |= FFS_MISCFLAGS_BACKUP; - break; - default: - fprintf(stderr, "Unknown flag '%c'\n", *pos); - rc = -1; - goto out_close_bl; + if (!isdigit(toc_num)) { + fprintf(stderr, "Invalid TOC ID %d (%c)\n", + toc_num, toc_num); + goto parse_out; } - pos++; - } - - printf("Adding '%s' 0x%08x, 0x%08x\n", name, pbase, psize); - rc = ffs_entry_new(name, pbase, psize, &new_entry); - if (rc) { - fprintf(stderr, "Invalid entry '%s' 0x%08x for 0x%08x\n", - name, pbase, psize); - goto out_close_bl; - } - rc = ffs_entry_user_set(new_entry, &user); - if (rc) { - fprintf(stderr, "Invalid flag passed to ffs_entry_user_set\n"); - goto out_while; - } + toc_num -= '0'; - rc = ffs_entry_add(new_hdr, new_entry); - if (rc) { - fprintf(stderr, "Couldn't add entry '%s' 0x%08x for 0x%08x\n", - name, pbase, psize); - goto out_while; - } + if (line[2] != SEPARATOR) { + fprintf(stderr, "TOC ID too long\n"); + goto parse_out; + } - if (*pos != '\0') { - struct stat data_stat; - int data_fd; - uint8_t *data_ptr; - char *data_fname = pos + 1; - - data_fd = open(data_fname, O_RDONLY); - if (data_fd == -1) { - fprintf(stderr, "Couldn't open data file for partition '%s' (filename: %s)\n", - name, data_fname); - rc = -1; - goto out_while; + if (tocs[toc_num]) { + fprintf(stderr, "Duplicate TOC ID %d\n", toc_num); + goto parse_out; } - if (fstat(data_fd, &data_stat) == -1) { - fprintf(stderr, "Couldn't stat data file for partition '%s': %s\n", - name, strerror(errno)); - rc = -1; - goto out_if; + tocs[toc_num] = parse_toc(&line[3], block_size, block_count); + if (!tocs[toc_num]) + goto parse_out; + toc_created = true; + } else { + if (!toc_created) { + fprintf(stderr, "WARNING: Attempting to parse a partition line without any TOCs created.\n"); + fprintf(stderr, " Generating a default TOC at zero\n"); + rc = ffs_hdr_new(block_size, block_count, NULL, &tocs[0]); + if (rc) { + rc = 7; + fprintf(stderr, "Couldn't generate a default TOC at zero\n"); + goto parse_out; + } + toc_created = true; } - pactual = data_stat.st_size; - - /* - * Sanity check that the file isn't too large for - * partition - */ - if (pactual > psize) { - fprintf(stderr, "Data file for partition '%s' is too large\n", - name); - rc = -1; - goto out_if; + rc = parse_entry(bl, tocs, line); + if (rc) { + rc = 6; + goto parse_out; } + } + } - data_ptr = mmap(NULL, pactual, PROT_READ, MAP_SHARED, data_fd, 0); - if (!data_ptr) { - fprintf(stderr, "Couldn't mmap data file for partition '%s': %s\n", - name, strerror(errno)); - rc = -1; - goto out_if; + for(i = 0; i < MAX_TOCS; i++) { + if (tocs[i]) { + rc = ffs_hdr_finalise(bl, tocs[i]); + if (rc) { + rc = 7; + fprintf(stderr, "Failed to write out TOC values\n"); + break; } - - rc = blocklevel_write(bl, pbase, data_ptr, pactual); - if (rc) - fprintf(stderr, "Couldn't write data file for partition '%s' to pnor file:" - " %s\n", name, strerror(errno)); - - munmap(data_ptr, pactual); -out_if: - close(data_fd); - if (rc) - goto out_while; - /* - * TODO: Update the actual size within the partition table. - */ } - - continue; -out_while: - ffs_entry_put(new_entry); - goto out_close_bl; } - rc = ffs_hdr_finalise(bl, new_hdr); - if (rc) - fprintf(stderr, "Failed to write out TOC values\n"); - -out_close_bl: +parse_out: + if (rc == 5 || rc == 6) + fprintf(stderr, "Failed to parse input file '%s' at line %d\n", + input, line_number); arch_flash_close(bl, pnor); -out_close_f: fclose(in_file); -out_free_hdr: - ffs_hdr_free(new_hdr); -out: + for(i = 0; i < MAX_TOCS; i++) + ffs_hdr_free(tocs[i]); free(input); free(pnor); return rc; diff --git a/external/ffspart/test/files/03-tiny-pnor.in b/external/ffspart/test/files/03-tiny-pnor.in index 3c02b029..90ad9c27 100644 --- a/external/ffspart/test/files/03-tiny-pnor.in +++ b/external/ffspart/test/files/03-tiny-pnor.in @@ -1,4 +1,4 @@ -ONE,0x00400,0x00000100,EV,/dev/zero -TWO,0x00500,0x00000100,EF,/dev/zero -THREE,0x600,0x00000100,EF,/dev/zero -FOUR,0x0700,0x00000100,EF,/dev/zero +ONE,0x00400,0x00000100,EV,,/dev/zero +TWO,0x00500,0x00000100,EF,,/dev/zero +THREE,0x600,0x00000100,EF,,/dev/zero +FOUR,0x0700,0x00000100,EF,,/dev/zero diff --git a/external/ffspart/test/files/03.1-tiny-pnor-backup.in b/external/ffspart/test/files/03.1-tiny-pnor-backup.in deleted file mode 100644 index b5527503..00000000 --- a/external/ffspart/test/files/03.1-tiny-pnor-backup.in +++ /dev/null @@ -1,4 +0,0 @@ -ONE,0x00400,0x100,EV,/dev/zero -TWO,0x00500,0x100,EF,/dev/zero -THREE,0x600,0x100,EF,/dev/zero -FOUR,0x0700,0x100,EF,/dev/zero diff --git a/external/ffspart/test/files/03.1-tiny-pnor-backup.out b/external/ffspart/test/files/03.1-tiny-pnor-backup.out deleted file mode 100644 index e173e9e75451d5359d97aca9e16e411bd255f0eb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3840 zcmWG=3<_ajU|BtL9G3q;0Azy9VTRBk@yZ_0N!Se{>zJKmnNjP``teV7H$^ z09`xr{M9=Qe};GjxuS&tFuvgSgTn%1BK7Tmw_In3n}28!nv2<5Pht?b{qKzqHD zqqBEtKzsls*@A8229mJ!2M!B}{nSr?EB9=E14?J3U^E0qLtr!nMnhmU1V%$(Xomo_ gApvSEff@`AKs?(11qK2(FxvhdZT}AK+>Ysb0KP^AFaQ7m diff --git a/external/ffspart/test/files/04-tiny-pnor2.in b/external/ffspart/test/files/04-tiny-pnor2.in index 34bfbde9..0369bf66 100644 --- a/external/ffspart/test/files/04-tiny-pnor2.in +++ b/external/ffspart/test/files/04-tiny-pnor2.in @@ -1,4 +1,4 @@ -ONE,0x00000300,0x00000100,EV,SEDCATCH_1 -TWO,0x00000400,0x00000100,EF,SEDCATCH_2 -THREE,0x00000500,0x00000100,EF,SEDCATCH_3 -FOUR,0x00000600,0x00000100,EF,SEDCATCH_4 +ONE,0x00000300,0x00000100,EV,,SEDCATCH_1 +TWO,0x00000400,0x00000100,EF,,SEDCATCH_2 +THREE,0x00000500,0x00000100,EF,,SEDCATCH_3 +FOUR,0x00000600,0x00000100,EF,,SEDCATCH_4 diff --git a/external/ffspart/test/files/05-hdr-overlap.in b/external/ffspart/test/files/05-hdr-overlap.in index 0dd37116..8af94d2d 100644 --- a/external/ffspart/test/files/05-hdr-overlap.in +++ b/external/ffspart/test/files/05-hdr-overlap.in @@ -1,4 +1,4 @@ -ONE,0x00000200,0x00000100,EV,/dev/zero -TWO,0x00000300,0x00000100,EF,/dev/zero -THREE,0x00000400,0x00000100,EF,/dev/zero -FOUR,0x00000500,0x00000100,EF,/dev/zero +ONE,0x00000200,0x00000100,EV,,/dev/zero +TWO,0x00000300,0x00000100,EF,,/dev/zero +THREE,0x00000400,0x00000100,EF,,/dev/zero +FOUR,0x00000500,0x00000100,EF,,/dev/zero diff --git a/external/ffspart/test/files/05.1-hdr-overlap-backup.in b/external/ffspart/test/files/05.1-hdr-overlap-backup.in deleted file mode 100644 index c6cf6e65..00000000 --- a/external/ffspart/test/files/05.1-hdr-overlap-backup.in +++ /dev/null @@ -1,3 +0,0 @@ -ONE,0x00000200,0x00000100,EV,/dev/zero -TWO,0x00000300,0x00000100,EF,/dev/zero -THREE,0x00000400,0x00000100,EF,/dev/zero diff --git a/external/ffspart/test/files/06-small-flash.in b/external/ffspart/test/files/06-small-flash.in index a4af6205..a717888b 100644 --- a/external/ffspart/test/files/06-small-flash.in +++ b/external/ffspart/test/files/06-small-flash.in @@ -1,5 +1,5 @@ -ONE,0x00000300,0x00000100,EV,/dev/zero -TWO,0x00000400,0x00000100,EF,/dev/zero -THREE,0x00000500,0x00000100,EF,/dev/zero -FOUR,0x00000600,0x00000100,EF,/dev/zero -FIVE,0x00000700,0x00000100,EF,/dev/zero +ONE,0x00000300,0x00000100,EV,,/dev/zero +TWO,0x00000400,0x00000100,EF,,/dev/zero +THREE,0x00000500,0x00000100,EF,,/dev/zero +FOUR,0x00000600,0x00000100,EF,,/dev/zero +FIVE,0x00000700,0x00000100,EF,,/dev/zero diff --git a/external/ffspart/test/files/07-big-files.in b/external/ffspart/test/files/07-big-files.in index 34bfbde9..0369bf66 100644 --- a/external/ffspart/test/files/07-big-files.in +++ b/external/ffspart/test/files/07-big-files.in @@ -1,4 +1,4 @@ -ONE,0x00000300,0x00000100,EV,SEDCATCH_1 -TWO,0x00000400,0x00000100,EF,SEDCATCH_2 -THREE,0x00000500,0x00000100,EF,SEDCATCH_3 -FOUR,0x00000600,0x00000100,EF,SEDCATCH_4 +ONE,0x00000300,0x00000100,EV,,SEDCATCH_1 +TWO,0x00000400,0x00000100,EF,,SEDCATCH_2 +THREE,0x00000500,0x00000100,EF,,SEDCATCH_3 +FOUR,0x00000600,0x00000100,EF,,SEDCATCH_4 diff --git a/external/ffspart/test/files/08-small-files.in b/external/ffspart/test/files/08-small-files.in index 34bfbde9..0369bf66 100644 --- a/external/ffspart/test/files/08-small-files.in +++ b/external/ffspart/test/files/08-small-files.in @@ -1,4 +1,4 @@ -ONE,0x00000300,0x00000100,EV,SEDCATCH_1 -TWO,0x00000400,0x00000100,EF,SEDCATCH_2 -THREE,0x00000500,0x00000100,EF,SEDCATCH_3 -FOUR,0x00000600,0x00000100,EF,SEDCATCH_4 +ONE,0x00000300,0x00000100,EV,,SEDCATCH_1 +TWO,0x00000400,0x00000100,EF,,SEDCATCH_2 +THREE,0x00000500,0x00000100,EF,,SEDCATCH_3 +FOUR,0x00000600,0x00000100,EF,,SEDCATCH_4 diff --git a/external/ffspart/test/files/10-bad-input.in b/external/ffspart/test/files/10-bad-input.in index 6015a521..5c4c90ee 100644 --- a/external/ffspart/test/files/10-bad-input.in +++ b/external/ffspart/test/files/10-bad-input.in @@ -1,4 +1,4 @@ -ONE0x00000300,0x00000100,EV,/dev/zero -TWO,0x00000400,0x00000100,EF,/dev/zero -THREE,0x00000500,0x00000100,EF,/dev/zero -FOUR,0x00000600,0x00000100,EF,/dev/zero +ONE0x00000300,0x00000100,EV,,/dev/zero +TWO,0x00000400,0x00000100,EF,,/dev/zero +THREE,0x00000500,0x00000100,EF,,/dev/zero +FOUR,0x00000600,0x00000100,EF,,/dev/zero diff --git a/external/ffspart/test/files/11-long-name.in b/external/ffspart/test/files/11-long-name.in index a194de0c..bd32ea89 100644 --- a/external/ffspart/test/files/11-long-name.in +++ b/external/ffspart/test/files/11-long-name.in @@ -1,4 +1,4 @@ -This_is_more_than_15_characters,0x00000300,0x00000100,EV,/dev/zero -This_is_exactly,0x00000400,0x00000100,EF,/dev/zero -This_is_one_le,0x00000500,0x00000100,EF,/dev/zero -This_is_one_more,0x00000600,0x00000100,EF,/dev/zero +This_is_more_than_15_characters,0x00000300,0x00000100,EV,,/dev/zero +This_is_exactly,0x00000400,0x00000100,EF,,/dev/zero +This_is_one_le,0x00000500,0x00000100,EF,,/dev/zero +This_is_one_more,0x00000600,0x00000100,EF,,/dev/zero diff --git a/external/ffspart/test/files/12-bad-numbers-base.in b/external/ffspart/test/files/12-bad-numbers-base.in index f3de343a..8f6fd27a 100644 --- a/external/ffspart/test/files/12-bad-numbers-base.in +++ b/external/ffspart/test/files/12-bad-numbers-base.in @@ -1,4 +1,4 @@ -ONE,0xg0000300,0x00000100,EV,/dev/zero -TWO,0x00000400,0x00000100,EF,/dev/zero -THREE,0x00000500,0x00000100,EF,/dev/zero -FOUR,0x00000600,0x00000100,EF,/dev/zero +ONE,0xg0000300,0x00000100,EV,,/dev/zero +TWO,0x00000400,0x00000100,EF,,/dev/zero +THREE,0x00000500,0x00000100,EF,,/dev/zero +FOUR,0x00000600,0x00000100,EF,,/dev/zero diff --git a/external/ffspart/test/files/13-bad-numbers-size.in b/external/ffspart/test/files/13-bad-numbers-size.in index 56fd5df1..b1dacc73 100644 --- a/external/ffspart/test/files/13-bad-numbers-size.in +++ b/external/ffspart/test/files/13-bad-numbers-size.in @@ -1,4 +1,4 @@ -ONE,0x00000300,0x00001g00,EV,/dev/zero -TWO,0x00000400,0x00000100,EF,/dev/zero -THREE,0x00000500,0x00000100,EF,/dev/zero -FOUR,0x00000600,0x00000100,EF,/dev/zero +ONE,0x00000300,0x00001g00,EV,,/dev/zero +TWO,0x00000400,0x00000100,EF,,/dev/zero +THREE,0x00000500,0x00000100,EF,,/dev/zero +FOUR,0x00000600,0x00000100,EF,,/dev/zero diff --git a/external/ffspart/test/files/14-bad-input-flags.in b/external/ffspart/test/files/14-bad-input-flags.in index c483f57f..dcf18f24 100644 --- a/external/ffspart/test/files/14-bad-input-flags.in +++ b/external/ffspart/test/files/14-bad-input-flags.in @@ -1,4 +1,4 @@ -ONE,0x00000300,0x00000100,EVZ,/dev/zero -TWO,0x00000400,0x00000100,EF,/dev/zero -THREE,0x00000500,0x00000100,EF,/dev/zero -FOUR,0x00000600,0x00000100,EF,/dev/zero +ONE,0x00000300,0x00000100,EVZ,,/dev/zero +TWO,0x00000400,0x00000100,EF,,/dev/zero +THREE,0x00000500,0x00000100,EF,,/dev/zero +FOUR,0x00000600,0x00000100,EF,,/dev/zero diff --git a/external/ffspart/test/files/15-overlapping-partitions.in b/external/ffspart/test/files/15-overlapping-partitions.in index 47c3837d..e496afa1 100644 --- a/external/ffspart/test/files/15-overlapping-partitions.in +++ b/external/ffspart/test/files/15-overlapping-partitions.in @@ -1,4 +1,4 @@ -ONE,0x00000300,0x00000100,EV,/dev/zero -TWO,0x00000350,0x00000100,EF,/dev/zero -THREE,0x00000500,0x00000100,EF,/dev/zero -FOUR,0x00000600,0x00000100,EF,/dev/zero +ONE,0x00000300,0x00000100,EV,,/dev/zero +TWO,0x00000350,0x00000100,EF,,/dev/zero +THREE,0x00000500,0x00000100,EF,,/dev/zero +FOUR,0x00000600,0x00000100,EF,,/dev/zero diff --git a/external/ffspart/test/results/01-param-sanity.err b/external/ffspart/test/results/01-param-sanity.err index 7b8bb3ba..e69de29b 100644 --- a/external/ffspart/test/results/01-param-sanity.err +++ b/external/ffspart/test/results/01-param-sanity.err @@ -1 +0,0 @@ -Greater than two sides is not supported diff --git a/external/ffspart/test/results/01-param-sanity.out b/external/ffspart/test/results/01-param-sanity.out index 19eedc74..3ad0441d 100644 --- a/external/ffspart/test/results/01-param-sanity.out +++ b/external/ffspart/test/results/01-param-sanity.out @@ -11,11 +11,6 @@ Usage: ./ffspart [options] -s size -c num -i layout_file -p pnor_file ... -i, --input=file File containing the required partition data - -o, --order=( ADB | ABD ) - Ordering of the TOC, Data and Backup TOC. Currently only ADB (default) - is supported -p, --pnor=file Output file to write data - -t, --sides=( 1 | 2 ) - Number of sides to the flash (Default: 1) diff --git a/external/ffspart/test/results/01.1-param-sanity.err b/external/ffspart/test/results/01.1-param-sanity.err new file mode 100644 index 00000000..e69de29b diff --git a/external/ffspart/test/results/02-param-sides.out b/external/ffspart/test/results/01.1-param-sanity.out similarity index 67% rename from external/ffspart/test/results/02-param-sides.out rename to external/ffspart/test/results/01.1-param-sanity.out index 19eedc74..3ad0441d 100644 --- a/external/ffspart/test/results/02-param-sides.out +++ b/external/ffspart/test/results/01.1-param-sanity.out @@ -11,11 +11,6 @@ Usage: ./ffspart [options] -s size -c num -i layout_file -p pnor_file ... -i, --input=file File containing the required partition data - -o, --order=( ADB | ABD ) - Ordering of the TOC, Data and Backup TOC. Currently only ADB (default) - is supported -p, --pnor=file Output file to write data - -t, --sides=( 1 | 2 ) - Number of sides to the flash (Default: 1) diff --git a/external/ffspart/test/results/02-param-sides.err b/external/ffspart/test/results/02-param-sides.err deleted file mode 100644 index faf9d9ff..00000000 --- a/external/ffspart/test/results/02-param-sides.err +++ /dev/null @@ -1 +0,0 @@ -Invalid block_count 1 for sides 2 diff --git a/external/ffspart/test/results/05-hdr-overlap.err b/external/ffspart/test/results/05-hdr-overlap.err index 55f07c6c..ff8aca20 100644 --- a/external/ffspart/test/results/05-hdr-overlap.err +++ b/external/ffspart/test/results/05-hdr-overlap.err @@ -1,2 +1,5 @@ +WARNING: Attempting to parse a partition line without any TOCs created. + Generating a default TOC at zero Adding partition 'THREE' would cause partition 'ONE' at 0x00000200 to overlap with the header -Couldn't add entry 'THREE' 0x00000400 for 0x00000100 +Couldn't add 'THREE' partition to default TOC: 107 +Failed to parse input file 'FILE' at line 3 diff --git a/external/ffspart/test/results/05-hdr-overlap.out b/external/ffspart/test/results/05-hdr-overlap.out index 2dbf5a43..e69de29b 100644 --- a/external/ffspart/test/results/05-hdr-overlap.out +++ b/external/ffspart/test/results/05-hdr-overlap.out @@ -1,3 +0,0 @@ -Adding 'ONE' 0x00000200, 0x00000100 -Adding 'TWO' 0x00000300, 0x00000100 -Adding 'THREE' 0x00000400, 0x00000100 diff --git a/external/ffspart/test/results/05.1-hdr-overlap-backup.err b/external/ffspart/test/results/05.1-hdr-overlap-backup.err deleted file mode 100644 index 55f07c6c..00000000 --- a/external/ffspart/test/results/05.1-hdr-overlap-backup.err +++ /dev/null @@ -1,2 +0,0 @@ -Adding partition 'THREE' would cause partition 'ONE' at 0x00000200 to overlap with the header -Couldn't add entry 'THREE' 0x00000400 for 0x00000100 diff --git a/external/ffspart/test/results/05.1-hdr-overlap-backup.out b/external/ffspart/test/results/05.1-hdr-overlap-backup.out deleted file mode 100644 index dbcdcb1d..00000000 --- a/external/ffspart/test/results/05.1-hdr-overlap-backup.out +++ /dev/null @@ -1,4 +0,0 @@ -Adding 'ONE' 0x00000200, 0x00000100 -Adding 'TWO' 0x00000300, 0x00000100 -Adding 'THREE' 0x00000400, 0x00000100 -Freeing hdr diff --git a/external/ffspart/test/results/06-small-flash.err b/external/ffspart/test/results/06-small-flash.err index a95149bd..a5316a90 100644 --- a/external/ffspart/test/results/06-small-flash.err +++ b/external/ffspart/test/results/06-small-flash.err @@ -1 +1,4 @@ -Couldn't add entry 'TWO' 0x00000400 for 0x00000100 +WARNING: Attempting to parse a partition line without any TOCs created. + Generating a default TOC at zero +Couldn't add 'TWO' partition to default TOC: 108 +Failed to parse input file 'FILE' at line 2 diff --git a/external/ffspart/test/results/06-small-flash.out b/external/ffspart/test/results/06-small-flash.out index 25214672..e69de29b 100644 --- a/external/ffspart/test/results/06-small-flash.out +++ b/external/ffspart/test/results/06-small-flash.out @@ -1,2 +0,0 @@ -Adding 'ONE' 0x00000300, 0x00000100 -Adding 'TWO' 0x00000400, 0x00000100 diff --git a/external/ffspart/test/results/07-big-files.err b/external/ffspart/test/results/07-big-files.err index f179a53d..083bad20 100644 --- a/external/ffspart/test/results/07-big-files.err +++ b/external/ffspart/test/results/07-big-files.err @@ -1 +1,4 @@ -Data file for partition 'ONE' is too large +WARNING: Attempting to parse a partition line without any TOCs created. + Generating a default TOC at zero +File 'FILE_ONE' for partition 'ONE' is too large +Failed to parse input file 'FILE' at line 1 diff --git a/external/ffspart/test/results/07-big-files.out b/external/ffspart/test/results/07-big-files.out index 0555381e..e69de29b 100644 --- a/external/ffspart/test/results/07-big-files.out +++ b/external/ffspart/test/results/07-big-files.out @@ -1 +0,0 @@ -Adding 'ONE' 0x00000300, 0x00000100 diff --git a/external/ffspart/test/results/08-small-files.err b/external/ffspart/test/results/08-small-files.err index e69de29b..c902b642 100644 --- a/external/ffspart/test/results/08-small-files.err +++ b/external/ffspart/test/results/08-small-files.err @@ -0,0 +1,2 @@ +WARNING: Attempting to parse a partition line without any TOCs created. + Generating a default TOC at zero diff --git a/external/ffspart/test/results/08-small-files.out b/external/ffspart/test/results/08-small-files.out index fdf70bf8..e69de29b 100644 --- a/external/ffspart/test/results/08-small-files.out +++ b/external/ffspart/test/results/08-small-files.out @@ -1,4 +0,0 @@ -Adding 'ONE' 0x00000300, 0x00000100 -Adding 'TWO' 0x00000400, 0x00000100 -Adding 'THREE' 0x00000500, 0x00000100 -Adding 'FOUR' 0x00000600, 0x00000100 diff --git a/external/ffspart/test/results/10-bad-input.err b/external/ffspart/test/results/10-bad-input.err index 08d2fcff..01c43d81 100644 --- a/external/ffspart/test/results/10-bad-input.err +++ b/external/ffspart/test/results/10-bad-input.err @@ -1 +1,4 @@ -Invalid input file format: Couldn't parse 'ONE0x00000300' partition length +WARNING: Attempting to parse a partition line without any TOCs created. + Generating a default TOC at zero +Couldn't parse 'ONE0x00000300' partition length +Failed to parse input file 'FILE' at line 1 diff --git a/external/ffspart/test/results/11-long-name.err b/external/ffspart/test/results/11-long-name.err index 824062ec..cf8dcc32 100644 --- a/external/ffspart/test/results/11-long-name.err +++ b/external/ffspart/test/results/11-long-name.err @@ -1,2 +1,4 @@ -WARNING: Long partition 'This_is_more_than_15_characters' name will get truncated -WARNING: Long partition 'This_is_one_more' name will get truncated +WARNING: Attempting to parse a partition line without any TOCs created. + Generating a default TOC at zero +WARNING: Long partition name will get truncated to 'This_is_more_tha' +WARNING: Long partition name will get truncated to 'This_is_one_more' diff --git a/external/ffspart/test/results/11-long-name.out b/external/ffspart/test/results/11-long-name.out index 2d7dcb32..e69de29b 100644 --- a/external/ffspart/test/results/11-long-name.out +++ b/external/ffspart/test/results/11-long-name.out @@ -1,4 +0,0 @@ -Adding 'This_is_more_than_15_characters' 0x00000300, 0x00000100 -Adding 'This_is_exactly' 0x00000400, 0x00000100 -Adding 'This_is_one_le' 0x00000500, 0x00000100 -Adding 'This_is_one_more' 0x00000600, 0x00000100 diff --git a/external/ffspart/test/results/12-bad-numbers-base.err b/external/ffspart/test/results/12-bad-numbers-base.err index 7312b034..cdd836ea 100644 --- a/external/ffspart/test/results/12-bad-numbers-base.err +++ b/external/ffspart/test/results/12-bad-numbers-base.err @@ -1 +1,4 @@ -Invalid input file format: Couldn't parse 'ONE' partition base address +WARNING: Attempting to parse a partition line without any TOCs created. + Generating a default TOC at zero +Couldn't parse 'ONE' partition base address +Failed to parse input file 'FILE' at line 1 diff --git a/external/ffspart/test/results/13-bad-numbers-size.err b/external/ffspart/test/results/13-bad-numbers-size.err index 592fec20..19078d5d 100644 --- a/external/ffspart/test/results/13-bad-numbers-size.err +++ b/external/ffspart/test/results/13-bad-numbers-size.err @@ -1 +1,4 @@ -Invalid input file format: Couldn't parse 'ONE' partition length +WARNING: Attempting to parse a partition line without any TOCs created. + Generating a default TOC at zero +Couldn't parse 'ONE' partition length +Failed to parse input file 'FILE' at line 1 diff --git a/external/ffspart/test/results/14-bad-input-flags.err b/external/ffspart/test/results/14-bad-input-flags.err index fecdb6ea..613525c3 100644 --- a/external/ffspart/test/results/14-bad-input-flags.err +++ b/external/ffspart/test/results/14-bad-input-flags.err @@ -1 +1,4 @@ -Unknown flag 'Z' +WARNING: Attempting to parse a partition line without any TOCs created. + Generating a default TOC at zero +Couldn't parse 'ONE' partition flags +Failed to parse input file 'FILE' at line 1 diff --git a/external/ffspart/test/results/15-overlapping-partitions.err b/external/ffspart/test/results/15-overlapping-partitions.err index d92f443e..c81d3c0e 100644 --- a/external/ffspart/test/results/15-overlapping-partitions.err +++ b/external/ffspart/test/results/15-overlapping-partitions.err @@ -1 +1,4 @@ -Couldn't add entry 'TWO' 0x00000350 for 0x00000100 +WARNING: Attempting to parse a partition line without any TOCs created. + Generating a default TOC at zero +Couldn't add 'TWO' partition to default TOC: 107 +Failed to parse input file 'FILE' at line 2 diff --git a/external/ffspart/test/results/15-overlapping-partitions.out b/external/ffspart/test/results/15-overlapping-partitions.out index 04e04c30..e69de29b 100644 --- a/external/ffspart/test/results/15-overlapping-partitions.out +++ b/external/ffspart/test/results/15-overlapping-partitions.out @@ -1,2 +0,0 @@ -Adding 'ONE' 0x00000300, 0x00000100 -Adding 'TWO' 0x00000350, 0x00000100 diff --git a/external/ffspart/test/tests/01-param-sanity b/external/ffspart/test/tests/01-param-sanity index 28acf511..d6373600 100644 --- a/external/ffspart/test/tests/01-param-sanity +++ b/external/ffspart/test/tests/01-param-sanity @@ -1,10 +1,6 @@ #! /bin/sh -#This test has become a little redundant now. -#TODO Do more sanity checking -return 0 - -run_binary "./ffspart" "-s 1 -c 3 -i /dev/null -p /dev/null" +run_binary "./ffspart" "-c 3 -i /dev/null -p /dev/null" if [ "$?" -ne 1 ] ; then fail_test fi diff --git a/external/ffspart/test/tests/01.1-param-sanity b/external/ffspart/test/tests/01.1-param-sanity new file mode 100644 index 00000000..1ce1f906 --- /dev/null +++ b/external/ffspart/test/tests/01.1-param-sanity @@ -0,0 +1,12 @@ +#! /bin/sh + +run_binary "./ffspart" "-s 1 -i /dev/null -p /dev/null" +if [ "$?" -ne 1 ] ; then + fail_test +fi + +strip_version_from_result "ffspart" + +diff_with_result + +pass_test diff --git a/external/ffspart/test/tests/02-param-sides b/external/ffspart/test/tests/02-param-sides deleted file mode 100644 index 17a2461e..00000000 --- a/external/ffspart/test/tests/02-param-sides +++ /dev/null @@ -1,16 +0,0 @@ -#! /bin/sh - -#The parameter has been removed -#TODO Something clever with this test -return 0 - -run_binary "./ffspart" "-s 1 -c 1 -i /dev/null -p /dev/null" -if [ "$?" -ne 1 ] ; then - fail_test -fi - -strip_version_from_result "ffspart" - -diff_with_result - -pass_test diff --git a/external/ffspart/test/tests/03.1-tiny-pnor-backup b/external/ffspart/test/tests/03.1-tiny-pnor-backup deleted file mode 100644 index 8fa8d4e4..00000000 --- a/external/ffspart/test/tests/03.1-tiny-pnor-backup +++ /dev/null @@ -1,19 +0,0 @@ -#! /bin/sh - -#The backup partition flag is gone -#disable this test temporarily -return 0 - -touch $DATA_DIR/$CUR_TEST.gen - -run_binary "./ffspart" "-b -s 0x100 -c 15 -i $DATA_DIR/$CUR_TEST.in -p $DATA_DIR/$CUR_TEST.gen" -if [ "$?" -ne 0 ] ; then - fail_test -fi - -if ! cmp -n $((0x100)) $DATA_DIR/$CUR_TEST.out $DATA_DIR/$CUR_TEST.gen ; then - echo "Output differs" - fail_test -fi - -pass_test diff --git a/external/ffspart/test/tests/05-hdr-overlap b/external/ffspart/test/tests/05-hdr-overlap index 2fa050b1..39a1a140 100644 --- a/external/ffspart/test/tests/05-hdr-overlap +++ b/external/ffspart/test/tests/05-hdr-overlap @@ -3,13 +3,12 @@ touch $DATA_DIR/$CUR_TEST.gen run_binary "./ffspart" "-s 0x100 -c 10 -i $DATA_DIR/$CUR_TEST.in -p $DATA_DIR/$CUR_TEST.gen" -#expect this error code, which is FFS_ERR_BAD_PART_BASE becase we're -#going to have too many partitions for header to fit before the first -#partition -if [ "$?" -ne 107 ] ; then +if [ "$?" -ne 6 ] ; then fail_test fi +sed -i "s|$DATA_DIR/$CUR_TEST.in|FILE|" "$STDERR_OUT" + diff_with_result pass_test diff --git a/external/ffspart/test/tests/05.1-hdr-overlap-backup b/external/ffspart/test/tests/05.1-hdr-overlap-backup deleted file mode 100644 index 0cbd9fa4..00000000 --- a/external/ffspart/test/tests/05.1-hdr-overlap-backup +++ /dev/null @@ -1,19 +0,0 @@ -#! /bin/sh - -#The backup partition flag is gone -#disable this test temporarily -return 0 - -touch $DATA_DIR/$CUR_TEST.gen - -run_binary "./ffspart" "-s 0x100 -c 10 -i $DATA_DIR/$CUR_TEST.in -p $DATA_DIR/$CUR_TEST.gen" -#expect this error code, which is FFS_ERR_BAD_PART_BASE becase we're -#going to have too many partitions for header to fit before the first -#partition -if [ "$?" -ne 107 ] ; then - fail_test -fi - -diff_with_result - -pass_test diff --git a/external/ffspart/test/tests/06-small-flash b/external/ffspart/test/tests/06-small-flash index b49f4578..7c41e33f 100644 --- a/external/ffspart/test/tests/06-small-flash +++ b/external/ffspart/test/tests/06-small-flash @@ -2,11 +2,12 @@ touch $DATA_DIR/$CUR_TEST.gen run_binary "./ffspart" "-s 0x100 -c 4 -i $DATA_DIR/$CUR_TEST.in -p $DATA_DIR/$CUR_TEST.gen" -#Expect FFS_ERR_BAD_PART_SIZE because the flash is too small -if [ "$?" -ne 108 ] ; then +if [ "$?" -ne 6 ] ; then fail_test fi +sed -i "s|$DATA_DIR/$CUR_TEST.in|FILE|" "$STDERR_OUT" + diff_with_result pass_test diff --git a/external/ffspart/test/tests/07-big-files b/external/ffspart/test/tests/07-big-files index 2381824f..f7a0064d 100644 --- a/external/ffspart/test/tests/07-big-files +++ b/external/ffspart/test/tests/07-big-files @@ -17,6 +17,10 @@ if [ "$?" -eq 0 ] ; then fail_test fi +sed -i "s|$DATA_DIR/$CUR_TEST.1|FILE_ONE|" "$STDERR_OUT" + +sed -i "s|$DATA_DIR/$CUR_TEST.in|FILE|" "$STDERR_OUT" + diff_with_result pass_test diff --git a/external/ffspart/test/tests/10-bad-input b/external/ffspart/test/tests/10-bad-input index e2f418ce..d7c43326 100644 --- a/external/ffspart/test/tests/10-bad-input +++ b/external/ffspart/test/tests/10-bad-input @@ -6,6 +6,8 @@ if [ "$?" -eq 0 ] ; then fail_test fi +sed -i "s|$DATA_DIR/$CUR_TEST.in|FILE|" "$STDERR_OUT" + diff_with_result pass_test diff --git a/external/ffspart/test/tests/12-bad-numbers-base b/external/ffspart/test/tests/12-bad-numbers-base index e2f418ce..d7c43326 100644 --- a/external/ffspart/test/tests/12-bad-numbers-base +++ b/external/ffspart/test/tests/12-bad-numbers-base @@ -6,6 +6,8 @@ if [ "$?" -eq 0 ] ; then fail_test fi +sed -i "s|$DATA_DIR/$CUR_TEST.in|FILE|" "$STDERR_OUT" + diff_with_result pass_test diff --git a/external/ffspart/test/tests/13-bad-numbers-size b/external/ffspart/test/tests/13-bad-numbers-size index e2f418ce..d7c43326 100644 --- a/external/ffspart/test/tests/13-bad-numbers-size +++ b/external/ffspart/test/tests/13-bad-numbers-size @@ -6,6 +6,8 @@ if [ "$?" -eq 0 ] ; then fail_test fi +sed -i "s|$DATA_DIR/$CUR_TEST.in|FILE|" "$STDERR_OUT" + diff_with_result pass_test diff --git a/external/ffspart/test/tests/14-bad-input-flags b/external/ffspart/test/tests/14-bad-input-flags index e2f418ce..d7c43326 100644 --- a/external/ffspart/test/tests/14-bad-input-flags +++ b/external/ffspart/test/tests/14-bad-input-flags @@ -6,6 +6,8 @@ if [ "$?" -eq 0 ] ; then fail_test fi +sed -i "s|$DATA_DIR/$CUR_TEST.in|FILE|" "$STDERR_OUT" + diff_with_result pass_test diff --git a/external/ffspart/test/tests/15-overlapping-partitions b/external/ffspart/test/tests/15-overlapping-partitions index 26c24d00..6d85748d 100644 --- a/external/ffspart/test/tests/15-overlapping-partitions +++ b/external/ffspart/test/tests/15-overlapping-partitions @@ -2,10 +2,12 @@ touch $DATA_DIR/$CUR_TEST.gen run_binary "./ffspart" "-s 0x100 -c 10 -i $DATA_DIR/$CUR_TEST.in -p $DATA_DIR/$CUR_TEST.gen" -if [ "$?" -ne 107 ] ; then +if [ "$?" -ne 6 ] ; then fail_test fi +sed -i "s|$DATA_DIR/$CUR_TEST.in|FILE|" "$STDERR_OUT" + diff_with_result pass_test diff --git a/external/pflash/test/files/01-info.ffs b/external/pflash/test/files/01-info.ffs index 517dc47b..a22143a3 100644 --- a/external/pflash/test/files/01-info.ffs +++ b/external/pflash/test/files/01-info.ffs @@ -1,4 +1,4 @@ -ONE,0x00000300,0x00000100,EV,/dev/zero -TWO,0x00000400,0x00000100,EF,/dev/zero -THREE,0x00000500,0x00000100,EF,/dev/zero -FOUR,0x00000600,0x00000100,EF,/dev/zero +ONE,0x00000300,0x00000100,EV,,/dev/zero +TWO,0x00000400,0x00000100,EF,,/dev/zero +THREE,0x00000500,0x00000100,EF,,/dev/zero +FOUR,0x00000600,0x00000100,EF,,/dev/zero diff --git a/external/pflash/test/files/02-erase.ffs b/external/pflash/test/files/02-erase.ffs index 7efcd717..ff64d4e6 100644 --- a/external/pflash/test/files/02-erase.ffs +++ b/external/pflash/test/files/02-erase.ffs @@ -1,4 +1,4 @@ -ONE,0x00000300,0x00000100,EV,/dev/urandom -TWO,0x00000400,0x00000100,EF,/dev/urandom -THREE,0x00000500,0x00000100,EF,/dev/urandom -FOUR,0x00000600,0x00000100,EF,/dev/urandom +ONE,0x00000300,0x00000100,EV,,/dev/urandom +TWO,0x00000400,0x00000100,EF,,/dev/urandom +THREE,0x00000500,0x00000100,EF,,/dev/urandom +FOUR,0x00000600,0x00000100,EF,,/dev/urandom diff --git a/external/pflash/test/files/03-erase-parts.ffs b/external/pflash/test/files/03-erase-parts.ffs index 7efcd717..ff64d4e6 100644 --- a/external/pflash/test/files/03-erase-parts.ffs +++ b/external/pflash/test/files/03-erase-parts.ffs @@ -1,4 +1,4 @@ -ONE,0x00000300,0x00000100,EV,/dev/urandom -TWO,0x00000400,0x00000100,EF,/dev/urandom -THREE,0x00000500,0x00000100,EF,/dev/urandom -FOUR,0x00000600,0x00000100,EF,/dev/urandom +ONE,0x00000300,0x00000100,EV,,/dev/urandom +TWO,0x00000400,0x00000100,EF,,/dev/urandom +THREE,0x00000500,0x00000100,EF,,/dev/urandom +FOUR,0x00000600,0x00000100,EF,,/dev/urandom diff --git a/external/pflash/test/files/04-program-rand.ffs b/external/pflash/test/files/04-program-rand.ffs index 7efcd717..ff64d4e6 100644 --- a/external/pflash/test/files/04-program-rand.ffs +++ b/external/pflash/test/files/04-program-rand.ffs @@ -1,4 +1,4 @@ -ONE,0x00000300,0x00000100,EV,/dev/urandom -TWO,0x00000400,0x00000100,EF,/dev/urandom -THREE,0x00000500,0x00000100,EF,/dev/urandom -FOUR,0x00000600,0x00000100,EF,/dev/urandom +ONE,0x00000300,0x00000100,EV,,/dev/urandom +TWO,0x00000400,0x00000100,EF,,/dev/urandom +THREE,0x00000500,0x00000100,EF,,/dev/urandom +FOUR,0x00000600,0x00000100,EF,,/dev/urandom diff --git a/external/pflash/test/files/05-bad-numbers.ffs b/external/pflash/test/files/05-bad-numbers.ffs index 7efcd717..ff64d4e6 100644 --- a/external/pflash/test/files/05-bad-numbers.ffs +++ b/external/pflash/test/files/05-bad-numbers.ffs @@ -1,4 +1,4 @@ -ONE,0x00000300,0x00000100,EV,/dev/urandom -TWO,0x00000400,0x00000100,EF,/dev/urandom -THREE,0x00000500,0x00000100,EF,/dev/urandom -FOUR,0x00000600,0x00000100,EF,/dev/urandom +ONE,0x00000300,0x00000100,EV,,/dev/urandom +TWO,0x00000400,0x00000100,EF,,/dev/urandom +THREE,0x00000500,0x00000100,EF,,/dev/urandom +FOUR,0x00000600,0x00000100,EF,,/dev/urandom diff --git a/external/pflash/test/files/06-miscprint.ffs b/external/pflash/test/files/06-miscprint.ffs index 8f916f39..160ed51f 100644 --- a/external/pflash/test/files/06-miscprint.ffs +++ b/external/pflash/test/files/06-miscprint.ffs @@ -1,4 +1,4 @@ -PRESERVED,0x00300,0x100,P,/dev/zero -READONLY,0x000400,0x100,R,/dev/zero -REPROVISION,0x500,0x100,F,/dev/zero -BACKUP,0x00000600,0x100,B,/dev/zero +PRESERVED,0x00300,0x100,P,,/dev/zero +READONLY,0x000400,0x100,R,,/dev/zero +REPROVISION,0x500,0x100,F,,/dev/zero +BACKUP,0x00000600,0x100,B,,/dev/zero diff --git a/external/pflash/test/results/06-miscprint.out b/external/pflash/test/results/06-miscprint.out index e90976d6..6d3377f1 100644 --- a/external/pflash/test/results/06-miscprint.out +++ b/external/pflash/test/results/06-miscprint.out @@ -30,7 +30,7 @@ Name: BACKUP (ID=04) Start End Actual -0x00000600 0x00000700 0x00000100 +0x00000600 0x00000700 0x00000000 Flags: BACKUP [B] diff --git a/libflash/libffs.c b/libflash/libffs.c index 5accf1ff..a1418f4f 100644 --- a/libflash/libffs.c +++ b/libflash/libffs.c @@ -562,8 +562,11 @@ int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry) uint32_t smallest_base; int i; + FL_DBG("LIBFFS: Adding '%s' at 0x%08x..0x%08x\n", + entry->name, entry->base, entry->base + entry->size); + if (hdr->count == 0) { - FL_DBG("Adding an entry to an empty header\n"); + FL_DBG("LIBFFS: Adding an entry to an empty header\n"); hdr->entries[hdr->count++] = entry; } if (entry->base + entry->size > hdr->block_size * hdr->block_count)