diff mbox series

[v2] pflash: Don't try update RO ToC

Message ID 20190108025814.12046-1-andrew@aj.id.au
State Accepted
Headers show
Series [v2] 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 success Test snowpatch/job/snowpatch-skiboot on branch master

Commit Message

Andrew Jeffery Jan. 8, 2019, 2:58 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>
---

v2: Minor rework to pass tests (ffsh can be NULL)

 external/pflash/pflash.c | 42 ++++++++++++++++++++++++++++++++--------
 1 file changed, 34 insertions(+), 8 deletions(-)

Comments

Stewart Smith Feb. 19, 2019, 4:48 a.m. UTC | #1
Andrew Jeffery <andrew@aj.id.au> writes:
> 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>
> ---
>
> v2: Minor rework to pass tests (ffsh can be NULL)

and with me slacking a bit, finally merged to master as of
963629523084aeaa780174415fb8204f7cceb198
Vasant Hegde Feb. 19, 2019, 6:24 a.m. UTC | #2
On 02/19/2019 10:18 AM, Stewart Smith wrote:
> Andrew Jeffery <andrew@aj.id.au> writes:
>> 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>
>> ---
>>
>> v2: Minor rework to pass tests (ffsh can be NULL)
> 
> and with me slacking a bit, finally merged to master as of
> 963629523084aeaa780174415fb8204f7cceb198

I know this is user space bit.. But may be its good to pick for Stable #6.2.x.

-Vasant
diff mbox series

Patch

diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c
index c81520cb9039..96ecf1fc6cf8 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;
 
@@ -358,13 +359,26 @@  static int erase_range(struct flash_details *flash,
 		progress_tick(done);
 	}
 	progress_end();
+
+	if (!ffsh)
+		return 0;
+
 	/* 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 (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 +419,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) {
@@ -460,10 +475,21 @@  static int program_file(struct blocklevel_device *bl,
 	}
 	progress_end();
 
+	if (!ffsh)
+		goto out;
+
 	/* 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 (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);