[RFC,03/13] external/pflash: Use ffs_entry_user_to_string() to standardise flag strings

Message ID 20170829062506.8317-4-cyril.bur@au1.ibm.com
State New
Headers show
Series
  • Rework flash TOC generation
Related show

Commit Message

Cyril Bur Aug. 29, 2017, 6:24 a.m.
Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
---
 external/pflash/pflash.c                 | 14 +++++---------
 external/pflash/test/results/01-info.out | 10 +++++-----
 2 files changed, 10 insertions(+), 14 deletions(-)

Comments

Stewart Smith Aug. 29, 2017, 9:34 a.m. | #1
Cyril Bur <cyril.bur@au1.ibm.com> writes:
> Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
> ---
>  external/pflash/pflash.c                 | 14 +++++---------
>  external/pflash/test/results/01-info.out | 10 +++++-----
>  2 files changed, 10 insertions(+), 14 deletions(-)

I think it'd be great if the available flags were in --help as
well. It's probably a good idea to document that CSV format somewhere,
and I can't think of anything better than --help atm :)
Cyril Bur Aug. 30, 2017, 1:48 a.m. | #2
On Tue, 2017-08-29 at 19:34 +1000, Stewart Smith wrote:
> Cyril Bur <cyril.bur@au1.ibm.com> writes:
> > Signed-off-by: Cyril Bur <cyril.bur@au1.ibm.com>
> > ---
> >  external/pflash/pflash.c                 | 14 +++++---------
> >  external/pflash/test/results/01-info.out | 10 +++++-----
> >  2 files changed, 10 insertions(+), 14 deletions(-)
> 
> I think it'd be great if the available flags were in --help as
> well. It's probably a good idea to document that CSV format somewhere,
> and I can't think of anything better than --help atm :)
> 

Yeah, I guess this patch was a bit halfbaked at trying to standardise
the character value of a flag - more than happy to add it to --help.

Might be worth reworking the patch to libffs to do more.

Patch

diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c
index a08ea946..3be43ac0 100644
--- a/external/pflash/pflash.c
+++ b/external/pflash/pflash.c
@@ -101,8 +101,8 @@  static uint32_t print_ffs_info(struct ffs_handle *ffsh, uint32_t toc)
 
 	for (i = 0;; i++) {
 		uint32_t start, size, act, end;
+		struct ffs_entry_user user;
 		char *name = NULL, *flags;
-		int l;
 
 		rc = ffs_part_info(ffsh, i, &name, &start, &size, &act, NULL);
 		if (rc == FFS_ERR_PART_NOT_FOUND)
@@ -115,17 +115,13 @@  static uint32_t print_ffs_info(struct ffs_handle *ffsh, uint32_t toc)
 		    goto out;
 		}
 
-		l = asprintf(&flags, "[%c%c%c%c%c]",
-				has_ecc(ent) ? 'E' : '-',
-				has_flag(ent, FFS_MISCFLAGS_PRESERVED) ? 'P' : '-',
-				has_flag(ent, FFS_MISCFLAGS_READONLY) ? 'R' : '-',
-				has_flag(ent, FFS_MISCFLAGS_BACKUP) ? 'B' : '-',
-				has_flag(ent, FFS_MISCFLAGS_REPROVISION) ? 'F' : '-');
-		if (l < 0)
+		user = ffs_entry_user_get(ent);
+		flags = ffs_entry_user_to_string(&user);
+		if (!flags)
 			goto out;
 
 		end = start + size;
-		printf("ID=%02d %15s 0x%08x..0x%08x (actual=0x%08x) %s\n",
+		printf("ID=%02d %15s 0x%08x..0x%08x (actual=0x%08x) [%s]\n",
 				i, name, start, end, act, flags);
 
 		if (strcmp(name, "OTHER_SIDE") == 0)
diff --git a/external/pflash/test/results/01-info.out b/external/pflash/test/results/01-info.out
index 43baf316..840890f4 100644
--- a/external/pflash/test/results/01-info.out
+++ b/external/pflash/test/results/01-info.out
@@ -6,8 +6,8 @@  Erase granule =  0KB           B:BACKUP, F:REPROVISION
 
 TOC@0x00000000 Partitions:
 -----------
-ID=00            part 0x00000000..0x00000300 (actual=0x00000300) [-----]
-ID=01             ONE 0x00000300..0x00000400 (actual=0x00000100) [E----]
-ID=02             TWO 0x00000400..0x00000500 (actual=0x00000100) [E---F]
-ID=03           THREE 0x00000500..0x00000600 (actual=0x00000100) [E---F]
-ID=04            FOUR 0x00000600..0x00000700 (actual=0x00000100) [E---F]
+ID=00            part 0x00000000..0x00000300 (actual=0x00000300) [-------]
+ID=01             ONE 0x00000300..0x00000400 (actual=0x00000100) [EV-----]
+ID=02             TWO 0x00000400..0x00000500 (actual=0x00000100) [E-----F]
+ID=03           THREE 0x00000500..0x00000600 (actual=0x00000100) [E-----F]
+ID=04            FOUR 0x00000600..0x00000700 (actual=0x00000100) [E-----F]