[Skiboot] [PATCH 1/1] pflash option to retrieve PNOR partition flags

Stewart Smith stewart at linux.vnet.ibm.com
Wed May 10 15:41:48 AEST 2017


Michael Tritz <mtritz at us.ibm.com> writes:
> This commit extends pflash with an option to retrieve and print the
> partition flags for a particular partition. In a separate commit,
> the generate-squashfs tool will be updated to utilize this new
> option.
>
> Resolves openbmc/openbmc#1351
>
> Signed-off-by: Michael Tritz <mtritz at us.ibm.com>
> ---
>  external/pflash/pflash.c | 61 +++++++++++++++++++++++++++++++++++++++++++++---
>  libflash/libffs.c        | 32 +++++++++++++++++++++++++
>  libflash/libffs.h        |  5 ++++
>  3 files changed, 95 insertions(+), 3 deletions(-)
>
> diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c
> index a344987e..b9e5efd6 100644
> --- a/external/pflash/pflash.c
> +++ b/external/pflash/pflash.c
> @@ -413,6 +413,50 @@ static void disable_4B_addresses(void)
>  	}
>  }
>  
> +static void print_partition_flags(uint32_t part_ID)
> +{
> +	bool ecc, preserved, readonly, backup, reprovision;
> +
> +	struct ffs_handle *ffs_handle;
> +	int rc;
> +
> +	rc = ffs_init(0, fl_total_size, bl, &ffs_handle, 0);
> +	if (rc) {
> +		fprintf(stderr, "Error %d opening ffs !\n", rc);
> +		return;
> +	}
> +
> +	rc = ffs_part_flags(ffs_handle, part_ID, &ecc, &preserved, &readonly,
> +			&backup, &reprovision);
> +	if (rc == FFS_ERR_PART_NOT_FOUND){
> +		fprintf(stderr, "Partition not found! Can't read flags.\n");
> +		return;
> +	}
> +	if (rc) {
> +		fprintf(stderr, "Error %d scanning partitions\n", rc);
> +		return;
> +	}
> +
> +	ffs_close(ffs_handle);
> +
> +	if(ecc)
> +		printf("ECC%s", preserved||readonly||backup||reprovision ? "," : "");
> +
> +	if(preserved)
> +		printf("PRESERVED%s", readonly || backup || reprovision ? "," : "");
> +
> +	if(readonly)
> +		printf("READONLY%s", backup || reprovision ? "," : "");
> +
> +	if(backup)
> +		printf("BACKUP%s", reprovision ? "," : "");
> +
> +	if(reprovision)
> +		printf("REPROVISION");
> +
> +	return;

A simpler way to do the above would be to do:

  l = snprintf(buf, strlen("ECC,PRESERVED,READONLY,BACKUP,REPROVISION."),
                "%s%s%s%s%s",
                (ecc) ? "ECC," : "",
                (preserved) ? "PRESERVED,," : "",
                (readonly) ? "READONLY," : "",
                (backup) ? "BACKUP," : "",
                (reprovision) ? "REPROVISION." : "")
  if (l)
     buf[l-1] = '.';

which has the benefit of being a lot more compact and obviously correct.

It may also be useful to print out this information on "pflash -i"
invocation, maybe just one character per flag?

Could you also add a test to libflash/test and/or to
external/ffspart/test ?


-- 
Stewart Smith
OPAL Architect, IBM.



More information about the Skiboot mailing list