[Skiboot] [PATCH 02/15] libffs: Standardise ffs partition flags

Cyril Bur cyril.bur at au1.ibm.com
Thu Mar 15 16:58:14 AEDT 2018


It seems we've developed a character respresentation for ffs partition
flags. Currently only pflash really prints them so it hasn't been a
problem but now ffspart wants to read them in from user input.

It is important that what libffs reads and what pflash prints remain
consistent, we should move the code into libffs to avoid problems.

Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>
---
 external/ffspart/ffspart.c                         |   4 +-
 external/ffspart/test/files/03-tiny-pnor.in        |   2 +-
 .../ffspart/test/files/03.1-tiny-pnor-backup.in    |   2 +-
 external/ffspart/test/files/04-tiny-pnor2.in       |   2 +-
 external/pflash/test/files/06-miscprint.ffs        |   2 +-
 external/pflash/test/results/01-info.out           |   4 +-
 libflash/ffs.h                                     |   1 +
 libflash/libffs.c                                  | 107 ++++++++++++++++++++-
 libflash/libffs.h                                  |   7 ++
 9 files changed, 122 insertions(+), 9 deletions(-)

diff --git a/external/ffspart/ffspart.c b/external/ffspart/ffspart.c
index 309f9b68..350d78b6 100644
--- a/external/ffspart/ffspart.c
+++ b/external/ffspart/ffspart.c
@@ -284,7 +284,7 @@ int main(int argc, char *argv[])
 			case 'E':
 				user.datainteg |= FFS_ENRY_INTEG_ECC;
 				break;
-			case 'V':
+			case 'L':
 				user.vercheck |= FFS_VERCHECK_SHA512V;
 				break;
 			case 'I':
@@ -299,7 +299,7 @@ int main(int argc, char *argv[])
 			case 'F':
 				user.miscflags |= FFS_MISCFLAGS_REPROVISION;
 				break;
-			case 'L':
+			case 'V':
 				user.miscflags |= FFS_MISCFLAGS_VOLATILE;
 				break;
 			case 'C':
diff --git a/external/ffspart/test/files/03-tiny-pnor.in b/external/ffspart/test/files/03-tiny-pnor.in
index 3c02b029..4fe1d4e1 100644
--- a/external/ffspart/test/files/03-tiny-pnor.in
+++ b/external/ffspart/test/files/03-tiny-pnor.in
@@ -1,4 +1,4 @@
-ONE,0x00400,0x00000100,EV,/dev/zero
+ONE,0x00400,0x00000100,EL,/dev/zero
 TWO,0x00500,0x00000100,EF,/dev/zero
 THREE,0x600,0x00000100,EF,/dev/zero
 FOUR,0x0700,0x00000100,EF,/dev/zero
diff --git a/external/ffspart/test/files/03.1-tiny-pnor-backup.in b/external/ffspart/test/files/03.1-tiny-pnor-backup.in
index b5527503..6209fbcc 100644
--- a/external/ffspart/test/files/03.1-tiny-pnor-backup.in
+++ b/external/ffspart/test/files/03.1-tiny-pnor-backup.in
@@ -1,4 +1,4 @@
-ONE,0x00400,0x100,EV,/dev/zero
+ONE,0x00400,0x100,EL,/dev/zero
 TWO,0x00500,0x100,EF,/dev/zero
 THREE,0x600,0x100,EF,/dev/zero
 FOUR,0x0700,0x100,EF,/dev/zero
diff --git a/external/ffspart/test/files/04-tiny-pnor2.in b/external/ffspart/test/files/04-tiny-pnor2.in
index 34bfbde9..5d1712c3 100644
--- a/external/ffspart/test/files/04-tiny-pnor2.in
+++ b/external/ffspart/test/files/04-tiny-pnor2.in
@@ -1,4 +1,4 @@
-ONE,0x00000300,0x00000100,EV,SEDCATCH_1
+ONE,0x00000300,0x00000100,EL,SEDCATCH_1
 TWO,0x00000400,0x00000100,EF,SEDCATCH_2
 THREE,0x00000500,0x00000100,EF,SEDCATCH_3
 FOUR,0x00000600,0x00000100,EF,SEDCATCH_4
diff --git a/external/pflash/test/files/06-miscprint.ffs b/external/pflash/test/files/06-miscprint.ffs
index 885a6f22..58e84d59 100644
--- a/external/pflash/test/files/06-miscprint.ffs
+++ b/external/pflash/test/files/06-miscprint.ffs
@@ -2,5 +2,5 @@ PRESERVED,0x003000,0x1000,P,/dev/zero
 READONLY,0x0004000,0x1000,R,/dev/zero
 REPROVISION,0x5000,0x1000,F,/dev/zero
 BACKUP,0x000006000,0x1000,B,/dev/zero
-VOLATILE,0x000007000,0x1000,L,/dev/zero
+VOLATILE,0x000007000,0x1000,V,/dev/zero
 CLEARECC,0x000008000,0x1000,C,/dev/zero
diff --git a/external/pflash/test/results/01-info.out b/external/pflash/test/results/01-info.out
index 204d5947..7377c71a 100644
--- a/external/pflash/test/results/01-info.out
+++ b/external/pflash/test/results/01-info.out
@@ -7,9 +7,9 @@ Erase granule =  0KB           F:REPROVISION, V:VOLATILE, C:CLEARECC
 TOC at 0x00000000 Partitions:
 -----------
 ID=00            part 0x00000000..0x00001000 (actual=0x00001000) [-------]
-ID=01             ONE 0x00003000..0x00004000 (actual=0x00001000) [E------]
+ID=01             ONE 0x00003000..0x00004000 (actual=0x00001000) [E----V-]
 ID=02             TWO 0x00004000..0x00005000 (actual=0x00001000) [E---F--]
 ID=03           THREE 0x00005000..0x00006000 (actual=0x00001000) [E---F--]
 ID=04            FOUR 0x00006000..0x00007000 (actual=0x00001000) [E---F--]
-ID=05            FIVE 0x00007000..0x00008000 (actual=0x00001000) [-----V-]
+ID=05            FIVE 0x00007000..0x00008000 (actual=0x00001000) [-------]
 ID=06             SIX 0x00008000..0x00009000 (actual=0x00001000) [------C]
diff --git a/libflash/ffs.h b/libflash/ffs.h
index 433ecac9..72ba2576 100644
--- a/libflash/ffs.h
+++ b/libflash/ffs.h
@@ -78,6 +78,7 @@ enum ffs_type {
 #define FFS_MISCFLAGS_REPROVISION 0x10
 #define FFS_MISCFLAGS_VOLATILE 0x08
 #define FFS_MISCFLAGS_CLEARECC 0x04
+#define FFS_MISCFLAGS_GOLDEN 0x01
 
 /**
  * struct __ffs_entry_user - On flash user data entries
diff --git a/libflash/libffs.c b/libflash/libffs.c
index 57dca496..9a80a56e 100644
--- a/libflash/libffs.c
+++ b/libflash/libffs.c
@@ -188,6 +188,100 @@ static int ffs_entry_to_cpu(struct ffs_hdr *hdr,
 	return rc;
 }
 
+char *ffs_entry_user_to_string(struct ffs_entry_user *user)
+{
+	char *ret;
+
+	if (!user)
+		return NULL;
+
+	ret = strdup("----------");
+	if (!ret)
+		return NULL;
+
+	if (user->datainteg & FFS_ENRY_INTEG_ECC)
+		ret[0] = 'E';
+
+	if (user->vercheck & FFS_VERCHECK_SHA512V)
+		ret[1] = 'L';
+
+	if (user->vercheck & FFS_VERCHECK_SHA512EC)
+		ret[2] = 'I';
+
+	if (user->miscflags & FFS_MISCFLAGS_PRESERVED)
+		ret[3] = 'P';
+
+	if (user->miscflags & FFS_MISCFLAGS_READONLY)
+		ret[4] = 'R';
+
+	if (user->miscflags & FFS_MISCFLAGS_BACKUP)
+		ret[5] = 'B';
+
+	if (user->miscflags & FFS_MISCFLAGS_REPROVISION)
+		ret[6] = 'F';
+
+	if (user->miscflags & FFS_MISCFLAGS_GOLDEN)
+		ret[7] = 'G';
+
+	if (user->miscflags & FFS_MISCFLAGS_CLEARECC)
+		ret[8] = 'C';
+
+	if (user->miscflags & FFS_MISCFLAGS_VOLATILE)
+		ret[9] = 'V';
+
+	return ret;
+}
+
+int ffs_string_to_entry_user(const char *flags, int nflags,
+		struct ffs_entry_user *user)
+{
+	int i;
+
+	if (!user || !flags)
+		return FLASH_ERR_PARM_ERROR;
+
+	memset(user, 0, sizeof(struct ffs_entry_user));
+	for (i = 0; i < nflags; i++) {
+		switch (flags[i]) {
+		case 'E':
+			user->datainteg |= FFS_ENRY_INTEG_ECC;
+			break;
+		case 'L':
+			user->vercheck |= FFS_VERCHECK_SHA512V;
+			break;
+		case 'I':
+			user->vercheck |= FFS_VERCHECK_SHA512EC;
+			break;
+		case 'P':
+			user->miscflags |= FFS_MISCFLAGS_PRESERVED;
+			break;
+		case 'R':
+			user->miscflags |= FFS_MISCFLAGS_READONLY;
+			break;
+		case 'B':
+			user->miscflags |= FFS_MISCFLAGS_BACKUP;
+			break;
+		case 'F':
+			user->miscflags |= FFS_MISCFLAGS_REPROVISION;
+			break;
+		case 'G':
+			user->miscflags |= FFS_MISCFLAGS_GOLDEN;
+			break;
+		case 'C':
+			user->miscflags |= FFS_MISCFLAGS_CLEARECC;
+			break;
+		case 'V':
+			user->miscflags |= FFS_MISCFLAGS_VOLATILE;
+			break;
+		default:
+			FL_DBG("Unknown flag '%c'\n", flags[i]);
+			return FLASH_ERR_PARM_ERROR;
+		}
+	}
+
+	return 0;
+}
+
 bool has_flag(struct ffs_entry *ent, uint16_t flag)
 {
 	return ((ent->user.miscflags & flag) != 0);
@@ -724,13 +818,24 @@ int ffs_entry_user_set(struct ffs_entry *ent, struct ffs_entry_user *user)
 		return -1;
 	if (user->miscflags & ~(FFS_MISCFLAGS_PRESERVED | FFS_MISCFLAGS_BACKUP |
 				FFS_MISCFLAGS_READONLY | FFS_MISCFLAGS_REPROVISION |
-				FFS_MISCFLAGS_VOLATILE | FFS_MISCFLAGS_CLEARECC))
+				FFS_MISCFLAGS_VOLATILE | FFS_MISCFLAGS_GOLDEN |
+				FFS_MISCFLAGS_CLEARECC))
 		return -1;
 
 	memcpy(&ent->user, user, sizeof(*user));
 	return 0;
 }
 
+struct ffs_entry_user ffs_entry_user_get(struct ffs_entry *ent)
+{
+	struct ffs_entry_user user = { 0 };
+
+	if (ent)
+		memcpy(&user, &ent->user, sizeof(user));
+
+	return user;
+}
+
 int ffs_entry_new(const char *name, uint32_t base, uint32_t size, struct ffs_entry **r)
 {
 	struct ffs_entry *ret;
diff --git a/libflash/libffs.h b/libflash/libffs.h
index 47a3808d..dfdcbbc0 100644
--- a/libflash/libffs.h
+++ b/libflash/libffs.h
@@ -90,8 +90,13 @@ struct ffs_entry_user {
 #define FFS_MISCFLAGS_REPROVISION 0x10
 #define FFS_MISCFLAGS_VOLATILE 0x08
 #define FFS_MISCFLAGS_CLEARECC 0x04
+#define FFS_MISCFLAGS_GOLDEN 0x01
 
 
+int ffs_string_to_entry_user(const char *flags, int nflags,
+		struct ffs_entry_user *user);
+char *ffs_entry_user_to_string(struct ffs_entry_user *user);
+
 bool has_ecc(struct ffs_entry *ent);
 
 bool has_flag(struct ffs_entry *ent, uint16_t flag);
@@ -146,6 +151,8 @@ int ffs_entry_user_set(struct ffs_entry *ent, struct ffs_entry_user *user);
 
 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_hdr_create_backup(struct ffs_hdr *hdr);
 
 int ffs_hdr_finalise(struct blocklevel_device *bl, struct ffs_hdr *hdr);
-- 
2.16.2



More information about the Skiboot mailing list