[Skiboot] [RFC PATCH 09/13] libflash/libffs: Remove backup partition from TOC generation code

Cyril Bur cyril.bur at au1.ibm.com
Tue Aug 29 16:25:02 AEST 2017


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 at au1.ibm.com>
---
 libflash/ffs.h    |  2 --
 libflash/libffs.c | 52 +---------------------------------------------------
 libflash/libffs.h |  2 --
 3 files changed, 1 insertion(+), 55 deletions(-)

diff --git a/libflash/ffs.h b/libflash/ffs.h
index cc2460c8..957155b9 100644
--- a/libflash/ffs.h
+++ b/libflash/ffs.h
@@ -204,7 +204,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 {
@@ -214,7 +213,6 @@ struct ffs_hdr {
 	uint32_t block_size;
 	uint32_t block_count;
 	struct ffs_entry *part;
-	struct ffs_entry *backup;
 	struct list_head entries;
 };
 
diff --git a/libflash/libffs.c b/libflash/libffs.c
index e741121d..5888c73f 100644
--- a/libflash/libffs.c
+++ b/libflash/libffs.c
@@ -546,7 +546,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;
@@ -599,50 +599,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;
@@ -699,12 +655,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;
diff --git a/libflash/libffs.h b/libflash/libffs.h
index d81b9dfe..56428a2c 100644
--- a/libflash/libffs.h
+++ b/libflash/libffs.h
@@ -154,8 +154,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);
-- 
2.14.1



More information about the Skiboot mailing list