Skip to content

Commit

Permalink
libflash/libffs: Remove backup partition from TOC generation code
Browse files Browse the repository at this point in the history
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 <cyril.bur@au1.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.ibm.com>
  • Loading branch information
cyrilbur-ibm authored and stewartsmith committed Apr 9, 2018
1 parent 14ed1a2 commit 0744faa
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 55 deletions.
2 changes: 0 additions & 2 deletions libflash/ffs.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ struct __ffs_hdr {
* @size: Size of partition table (in bytes)
* @block_size: Size of block on device (in bytes)
* @block_count: Number of blocks on device.
* @backup The backup partition
* @entries: List of partition entries
*/
struct ffs_hdr {
Expand All @@ -216,7 +215,6 @@ struct ffs_hdr {
uint32_t block_size;
uint32_t block_count;
struct ffs_entry *part;
struct ffs_entry *backup;
struct list_head entries;
};

Expand Down
52 changes: 1 addition & 51 deletions libflash/libffs.c
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ int ffs_next_side(struct ffs_handle *ffs, struct ffs_handle **new_ffs,
return ffs_init(offset, max_size, ffs->bl, new_ffs, mark_ecc);
}

static int __ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry)
int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry)
{
struct ffs_entry *ent;
uint32_t smallest_base;
Expand Down Expand Up @@ -611,50 +611,6 @@ 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)
{
/*
* Refuse to add anything after BACKUP_PART has been added, not
* sure why this is needed anymore
*/
if (hdr->backup)
return FLASH_ERR_PARM_ERROR;

return __ffs_entry_add(hdr, entry);
}

/* This should be done last! */
int ffs_hdr_create_backup(struct ffs_hdr *hdr)
{
struct ffs_entry *ent;
struct ffs_entry *backup;
uint32_t hdr_size, flash_end;
int rc = 0;

ent = list_tail(&hdr->entries, struct ffs_entry, list);
if (!ent) {
return FLASH_ERR_PARM_ERROR;
}

hdr_size = ffs_hdr_raw_size(ffs_num_entries(hdr) + 1);
/* Whole number of blocks BACKUP_PART needs to be */
hdr_size = ((hdr_size + hdr->block_size) / hdr->block_size) * hdr->block_size;
flash_end = hdr->base + (hdr->block_size * hdr->block_count);
rc = ffs_entry_new("BACKUP_PART", flash_end - hdr_size, hdr_size, &backup);
if (rc)
return rc;

rc = __ffs_entry_add(hdr, backup);
if (rc) {
free(backup);
return rc;
}

hdr->backup = backup;

return rc;
}

int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr)
{
int num_entries, i, rc = 0;
Expand Down Expand Up @@ -711,12 +667,6 @@ int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr)
if (rc)
goto out;

if (hdr->backup) {
fprintf(stderr, "Actually writing backup part @ 0x%08x\n", hdr->backup->base);
blocklevel_erase(bl, hdr->backup->base, hdr->size);
rc = blocklevel_write(bl, hdr->backup->base, real_hdr,
ffs_hdr_raw_size(num_entries));
}
out:
free(real_hdr);
return rc;
Expand Down
2 changes: 0 additions & 2 deletions libflash/libffs.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,6 @@ 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);

int ffs_hdr_free(struct ffs_hdr *hdr);
Expand Down

0 comments on commit 0744faa

Please sign in to comment.