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);