Skip to content

Commit

Permalink
libflash/libffs: Remove the 'sides' from the FFS 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 0673f62 commit 14ed1a2
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 79 deletions.
2 changes: 1 addition & 1 deletion external/ffspart/ffspart.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ int main(int argc, char *argv[])
goto out_while;
}

rc = ffs_entry_add(new_hdr, new_entry, 0);
rc = ffs_entry_add(new_hdr, new_entry);
if (rc) {
fprintf(stderr, "Couldn't add entry '%s' 0x%08x for 0x%08x\n",
name, pbase, psize);
Expand Down
2 changes: 0 additions & 2 deletions libflash/ffs.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ struct __ffs_hdr {
* @block_size: Size of block on device (in bytes)
* @block_count: Number of blocks on device.
* @backup The backup partition
* @side The ffs header for the other side
* @entries: List of partition entries
*/
struct ffs_hdr {
Expand All @@ -218,7 +217,6 @@ struct ffs_hdr {
uint32_t block_count;
struct ffs_entry *part;
struct ffs_entry *backup;
struct ffs_hdr *side;
struct list_head entries;
};

Expand Down
77 changes: 2 additions & 75 deletions libflash/libffs.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,6 @@ static void __hdr_free(struct ffs_hdr *hdr)
list_del(&ent->list);
free(ent);
}
if (hdr->side) {
hdr->side->side = NULL;
ffs_hdr_free(hdr->side);
}
}

int ffs_hdr_free(struct ffs_hdr *hdr)
Expand Down Expand Up @@ -615,47 +611,16 @@ 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, unsigned int side)
int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry)
{
int rc;

/*
* 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;

if (side == 0) { /* Sideless... */
rc = __ffs_entry_add(hdr, entry);
if (!rc && hdr->side) {
struct ffs_entry *other_ent;

/*
* A rather sneaky copy is hidden here.
* It doesn't make sense for a consumer to be aware that structures
* must be duplicated. The entries list in the header could have
* been an array of pointers and no copy would have been required.
*/
other_ent = calloc(1, sizeof (struct ffs_entry));
if (!other_ent)
/* TODO Remove the added entry from side 1 */
return FLASH_ERR_PARM_ERROR;
memcpy(other_ent, entry, sizeof(struct ffs_entry));
rc = __ffs_entry_add(hdr->side, other_ent);
if (rc)
/* TODO Remove the added entry from side 1 */
free(other_ent);
}
} else if (side == 1) {
rc = __ffs_entry_add(hdr, entry);
} else if (side == 2 && hdr->side) {
rc = __ffs_entry_add(hdr->side, entry);
} else {
rc = FLASH_ERR_PARM_ERROR;
}

return rc;
return __ffs_entry_add(hdr, entry);
}

/* This should be done last! */
Expand Down Expand Up @@ -687,29 +652,6 @@ int ffs_hdr_create_backup(struct ffs_hdr *hdr)

hdr->backup = backup;

/* Do we try to roll back completely if that fails or leave what we've added? */
if (hdr->side && hdr->base == 0)
rc = ffs_hdr_create_backup(hdr->side);

return rc;
}

int ffs_hdr_add_side(struct ffs_hdr *hdr)
{
int rc;

/* Only a second side for now */
if (hdr->side)
return FLASH_ERR_PARM_ERROR;

rc = ffs_hdr_new(hdr->block_size, hdr->block_count, &hdr->side);
if (rc)
return rc;

hdr->side->base = hdr->block_size * hdr->block_count;
/* Sigh */
hdr->side->side = hdr;

return rc;
}

Expand All @@ -725,16 +667,6 @@ int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr)
if (num_entries == 0)
return FFS_ERR_BAD_SIZE;

if (hdr->side) {
struct ffs_entry *other_side;
/* TODO: Change the hard coded 0x8000 */
rc = ffs_entry_new("OTHER_SIDE", hdr->side->base, 0x8000, &other_side);
if (rc)
return rc;
list_add_tail(&hdr->entries, &other_side->list);
num_entries++;
}

real_hdr = malloc(ffs_hdr_raw_size(num_entries));
if (!real_hdr)
return FLASH_ERR_MALLOC_FAILED;
Expand Down Expand Up @@ -785,11 +717,6 @@ int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr)
rc = blocklevel_write(bl, hdr->backup->base, real_hdr,
ffs_hdr_raw_size(num_entries));
}
if (rc)
goto out;

if (hdr->side && hdr->base == 0)
rc = ffs_hdr_finalise(bl, hdr->side);
out:
free(real_hdr);
return rc;
Expand Down
3 changes: 2 additions & 1 deletion libflash/libffs.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ int ffs_entry_user_set(struct ffs_entry *ent, struct ffs_entry_user *user);

int ffs_entry_set_act_size(struct ffs_entry *ent, uint32_t actual_size);

int ffs_entry_add(struct ffs_hdr *hdr, struct ffs_entry *entry, unsigned int side);

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

0 comments on commit 14ed1a2

Please sign in to comment.