Skip to content

Commit

Permalink
pflash: Don't try update RO ToC
Browse files Browse the repository at this point in the history
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>
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
  • Loading branch information
amboar authored and stewartsmith committed Feb 19, 2019
1 parent fd09504 commit 9636295
Showing 1 changed file with 34 additions and 8 deletions.
42 changes: 34 additions & 8 deletions external/pflash/pflash.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,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;

Expand Down Expand Up @@ -360,13 +361,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;
}

Expand Down Expand Up @@ -407,9 +421,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) {
Expand Down Expand Up @@ -462,10 +477,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);
Expand Down

0 comments on commit 9636295

Please sign in to comment.