diff mbox series

pflash: Don't try update RO ToC

Message ID 20181115010735.1296-1-andrew@aj.id.au
State Superseded
Headers show
Series pflash: Don't try update RO ToC | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success master/apply_patch Successfully applied
snowpatch_ozlabs/snowpatch_job_snowpatch-skiboot fail Test snowpatch/job/snowpatch-skiboot on branch master

Commit Message

Andrew Jeffery Nov. 15, 2018, 1:07 a.m. UTC
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 <andrew@aj.id.au>
---
 external/pflash/pflash.c | 34 ++++++++++++++++++++++++++--------
 1 file changed, 26 insertions(+), 8 deletions(-)

Comments

Andrew Donnellan Nov. 28, 2018, 4:24 a.m. UTC | #1
On 15/11/18 12:07 pm, Andrew Jeffery wrote:
> 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 <andrew@aj.id.au>

snowpatch is reporting issues: 
https://openpower.xyz/job/snowpatch/job/snowpatch-skiboot/218//artifact/skiboot/check.log/*view*/
Andrew Jeffery Nov. 28, 2018, 5:41 a.m. UTC | #2
On Wed, 28 Nov 2018, at 14:54, Andrew Donnellan wrote:
> On 15/11/18 12:07 pm, Andrew Jeffery wrote:
> > 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 <andrew@aj.id.au>
> 
> snowpatch is reporting issues: 
> https://openpower.xyz/job/snowpatch/job/snowpatch-skiboot/218//artifact/skiboot/check.log/*view*/

Yep, thanks for the reminder.

> 
> -- 
> Andrew Donnellan              OzLabs, ADL Canberra
> andrew.donnellan@au1.ibm.com  IBM Australia Limited
>
diff mbox series

Patch

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