From patchwork Thu Nov 15 01:07:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 998003 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42wNXv2bBHz9s8F for ; Thu, 15 Nov 2018 12:08:47 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=aj.id.au Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="u/Is1a7+"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="Fvx7s10q"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42wNXv069qzF3XT for ; Thu, 15 Nov 2018 12:08:47 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=aj.id.au Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="u/Is1a7+"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="Fvx7s10q"; dkim-atps=neutral X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=aj.id.au (client-ip=66.111.4.29; helo=out5-smtp.messagingengine.com; envelope-from=andrew@aj.id.au; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=aj.id.au Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="u/Is1a7+"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="Fvx7s10q"; dkim-atps=neutral Received: from out5-smtp.messagingengine.com (out5-smtp.messagingengine.com [66.111.4.29]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42wNXh490FzF3Wy for ; Thu, 15 Nov 2018 12:08:36 +1100 (AEDT) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 8186A21CCA; Wed, 14 Nov 2018 20:08:31 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 14 Nov 2018 20:08:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aj.id.au; h=from :to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm1; bh=V3AuFCVt79kvQ0tdQgOWgwzlwG a4kErhJjMyGOG6o60=; b=u/Is1a7+huO2v/MB5Ki/92S9T2+ZFlIKXB3A1qfoN4 SXsf8OlvlY32iwkyr5WjXf4gNsOhyClACOfGv2dVXtVyc9SChetePbuv4u8i/iKc kgjDR7Yqd4F54QvDK1SLskwXp33H7aBEQ2g+V1sUv3IZ3PdcoP6AREhVf6O+38bE YsvhbJFJvCi5nd9qodLazc36JbfZsXteVzjPhcrqVPZrBinVC4muBIzTcF4cSv5b EQY41YFf7bvMydu7fFx+xJywZX2eVyLfArmlzk2+MUPcDU8fKthKjqOEXbibly/h XEYuS0TLa2Gw/+SRX/EQy5yir+RnKGI5SdeS55avS91w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=V3AuFCVt79kvQ0tdQ gOWgwzlwGa4kErhJjMyGOG6o60=; b=Fvx7s10qNdfUv1unyPI6y7yzuB+BtEwPy ui2yEGxVYLQKc01f6TgNF24R0t2yRpqIU9BSN9pbqb3DN+F5UzqypSMxkJKRx/Sp 3qRaZYMBx2bjoQSXlY65wUlG0/PanoDzUSbxEvHHA1Ax/t9fJVe4Bfg8XCS7i4cA oRnf2GkDX3MU5Aw1Kua3Yf0nF4gItQBsozWdic+MUe4GxPqq2kjB6LGgOWXLG8Qo oLzHO5VYepObdUfyOadZ9RszstQY7E7ZoaWIhQH/lvjiC/A5KdrAkxR9CLJ0orHP Uj1jSxv/kS0QMkc0sJSX25HlwRDlJPWydysC03inF10x0MwiXjDIQ== X-ME-Sender: X-ME-Proxy: Received: from localhost.localdomain (unknown [45.124.203.15]) by mail.messagingengine.com (Postfix) with ESMTPA id 05117E405B; Wed, 14 Nov 2018 20:08:21 -0500 (EST) From: Andrew Jeffery To: skiboot@lists.ozlabs.org Date: Thu, 15 Nov 2018 11:37:35 +1030 Message-Id: <20181115010735.1296-1-andrew@aj.id.au> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 Subject: [Skiboot] [PATCH] pflash: Don't try update RO ToC X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Jeffery Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" In the future it's likely the ToC will be marked as read-only. Don't error out by assuming its writable. Signed-off-by: Andrew Jeffery --- external/pflash/pflash.c | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c index c81520cb9039..18b1fddbfdeb 100644 --- a/external/pflash/pflash.c +++ b/external/pflash/pflash.c @@ -301,6 +301,7 @@ static int erase_range(struct flash_details *flash, struct ffs_handle *ffsh, int ffs_index) { uint32_t done = 0, erase_mask = flash->erase_granule - 1; + struct ffs_entry *toc; bool confirm; int rc; @@ -361,9 +362,17 @@ static int erase_range(struct flash_details *flash, /* If this is a flash partition, mark it empty if we aren't * going to program over it as well */ - if (ffsh && ffs_index >= 0 && !will_program) { - printf("Updating actual size in partition header...\n"); - ffs_update_act_size(ffsh, ffs_index, 0); + toc = ffs_entry_get(ffsh, 0); + if (toc) { + struct ffs_entry_user user; + bool rw_toc; + + user = ffs_entry_user_get(toc); + rw_toc = !(user.miscflags & FFS_MISCFLAGS_READONLY); + if (ffsh && ffs_index >= 0 && !will_program && rw_toc) { + printf("Updating actual size in partition header...\n"); + ffs_update_act_size(ffsh, ffs_index, 0); + } } return 0; } @@ -405,9 +414,10 @@ static int program_file(struct blocklevel_device *bl, const char *file, uint32_t start, uint32_t size, struct ffs_handle *ffsh, int ffs_index) { - bool confirm; - int fd, rc = 0; uint32_t actual_size = 0; + struct ffs_entry *toc; + int fd, rc = 0; + bool confirm; fd = open(file, O_RDONLY); if (fd == -1) { @@ -461,9 +471,17 @@ static int program_file(struct blocklevel_device *bl, progress_end(); /* If this is a flash partition, adjust its size */ - if (ffsh && ffs_index >= 0) { - printf("Updating actual size in partition header...\n"); - ffs_update_act_size(ffsh, ffs_index, actual_size); + toc = ffs_entry_get(ffsh, 0); + if (toc) { + struct ffs_entry_user user; + bool rw_toc; + + user = ffs_entry_user_get(toc); + rw_toc = !(user.miscflags & FFS_MISCFLAGS_READONLY); + if (ffsh && ffs_index >= 0 && rw_toc) { + printf("Updating actual size in partition header...\n"); + ffs_update_act_size(ffsh, ffs_index, actual_size); + } } out: close(fd);