aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--external/ffspart/ffspart.c2
-rw-r--r--libflash/ffs.h1
-rw-r--r--libflash/libffs.c28
-rw-r--r--libflash/libffs.h2
4 files changed, 22 insertions, 11 deletions
diff --git a/external/ffspart/ffspart.c b/external/ffspart/ffspart.c
index fd5075d..c355952 100644
--- a/external/ffspart/ffspart.c
+++ b/external/ffspart/ffspart.c
@@ -131,7 +131,7 @@ int main(int argc, char *argv[])
goto out;
}
- rc = ffs_hdr_new(block_size, block_count, &new_hdr);
+ rc = ffs_hdr_new(block_size, block_count, NULL, &new_hdr);
if (rc) {
if (rc == FFS_ERR_BAD_SIZE) {
/* Well this check is a tad redudant now */
diff --git a/libflash/ffs.h b/libflash/ffs.h
index 4c757c6..b147396 100644
--- a/libflash/ffs.h
+++ b/libflash/ffs.h
@@ -212,7 +212,6 @@ struct __ffs_hdr {
*/
struct ffs_hdr {
uint32_t version;
- uint32_t base;
uint32_t size;
uint32_t block_size;
uint32_t block_count;
diff --git a/libflash/libffs.c b/libflash/libffs.c
index b4a8116..ceaf0fd 100644
--- a/libflash/libffs.c
+++ b/libflash/libffs.c
@@ -684,8 +684,8 @@ int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr)
}
/* Don't really care if this fails */
- blocklevel_erase(bl, hdr->base, hdr->size);
- rc = blocklevel_write(bl, hdr->base, real_hdr,
+ blocklevel_erase(bl, hdr->part->base, hdr->size);
+ rc = blocklevel_write(bl, hdr->part->base, real_hdr,
ffs_hdr_raw_size(num_entries));
if (rc)
goto out;
@@ -770,7 +770,8 @@ int ffs_entry_set_act_size(struct ffs_entry *ent, uint32_t actual_size)
return 0;
}
-int ffs_hdr_new(uint32_t block_size, uint32_t block_count, struct ffs_hdr **r)
+int ffs_hdr_new(uint32_t block_size, uint32_t block_count,
+ struct ffs_entry **e, struct ffs_hdr **r)
{
struct ffs_hdr *ret;
struct ffs_entry *part_table;
@@ -786,12 +787,23 @@ int ffs_hdr_new(uint32_t block_size, uint32_t block_count, struct ffs_hdr **r)
ret->entries = calloc(HDR_ENTRIES_NUM, sizeof(struct ffs_entry *));
ret->entries_size = HDR_ENTRIES_NUM;
- /* Don't know how big it will be, ffs_hdr_finalise() will fix */
- rc = ffs_entry_new("part", 0, 0, &part_table);
- if (rc) {
- free(ret);
- return rc;
+ if (!e || !(*e)) {
+ /* Don't know how big it will be, ffs_hdr_finalise() will fix */
+ rc = ffs_entry_new("part", 0, 0, &part_table);
+ if (rc) {
+ free(ret);
+ return rc;
+ }
+ if (e)
+ *e = part_table;
+ } else {
+ part_table = *e;
}
+
+ /* If the user still holds a ref to e, then inc the refcount */
+ if (e)
+ part_table->ref++;
+
ret->part = part_table;
part_table->pid = FFS_PID_TOPLEVEL;
diff --git a/libflash/libffs.h b/libflash/libffs.h
index c56574d..f149fd8 100644
--- a/libflash/libffs.h
+++ b/libflash/libffs.h
@@ -141,7 +141,7 @@ int ffs_update_act_size(struct ffs_handle *ffs, uint32_t part_idx,
uint32_t act_size);
int ffs_hdr_new(uint32_t block_size, uint32_t block_count,
- struct ffs_hdr **r);
+ struct ffs_entry **e, struct ffs_hdr **r);
int ffs_hdr_add_side(struct ffs_hdr *hdr);