[Skiboot] [PATCH 3/5] external/common: Rename arch_flash_bmc() to arch_flash_access()

Cyril Bur cyrilbur at gmail.com
Fri Oct 21 20:35:53 AEDT 2016


On Fri, 2016-10-21 at 19:52 +1100, Cyril Bur wrote:
> Honestly the first name was terrible. Initially this was intended
> only
> to serve for BMC/ARM flash access, however, it should be more generic
> as
> it is in the external/common arch code it should play nice on all
> architectures.
> 
> This change also paves the way to change the default flash access
> methods in pflash.
> 
> Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>
> ---
>  external/common/arch_flash.h         |  6 +++---
>  external/common/arch_flash_arm.c     | 12 ++++++------
>  external/common/arch_flash_common.c  |  6 ++++--
>  external/common/arch_flash_powerpc.c | 14 ++++++++++++++
>  external/pflash/pflash.c             |  4 ++--
>  5 files changed, 29 insertions(+), 13 deletions(-)
> 
> diff --git a/external/common/arch_flash.h
> b/external/common/arch_flash.h
> index aae9e10..c1be706 100644
> --- a/external/common/arch_flash.h
> +++ b/external/common/arch_flash.h
> @@ -20,7 +20,7 @@
>  #include <getopt.h>
>  #include <libflash/blocklevel.h>
>  
> -enum bmc_access {
> +enum flash_access {
>  	PNOR_DIRECT,
>  	PNOR_MTD,
>  	BMC_DIRECT,
> @@ -40,8 +40,8 @@ void arch_flash_close(struct blocklevel_device *bl,
> const char *file);
>   * accessed.
>   * If called AFTER init, then this returns how the flash is being
> accessed.
>   */
> -enum bmc_access arch_flash_bmc(struct blocklevel_device *bl,
> -		enum bmc_access access);
> +enum flash_access arch_flash_access(struct blocklevel_device *bl,
> +		enum flash_access access);
>  
>  int arch_flash_erase_chip(struct blocklevel_device *bl);
>  int arch_flash_4b_mode(struct blocklevel_device *bl, int set_4b);
> diff --git a/external/common/arch_flash_arm.c
> b/external/common/arch_flash_arm.c
> index 0776436..697609d 100644
> --- a/external/common/arch_flash_arm.c
> +++ b/external/common/arch_flash_arm.c
> @@ -43,7 +43,7 @@ static struct arch_arm_data {
>  	size_t ahb_flash_base;
>  	size_t ahb_flash_size;
>  	void *ahb_flash_map;
> -	enum bmc_access access;
> +	enum flash_access access;
>  	struct flash_chip *flash_chip;
>  	struct blocklevel_device *init_bl;
>  } arch_data;
> @@ -156,7 +156,7 @@ static void close_devs(void)
>  	 */
>  }
>  
> -static int open_devs(enum bmc_access access)
> +static int open_devs(enum flash_access access)
>  {
>  	if (access != BMC_DIRECT && access != PNOR_DIRECT)
>  		return -1;
> @@ -190,7 +190,7 @@ static int open_devs(enum bmc_access access)
>  	return 0;
>  }
>  
> -static struct blocklevel_device *flash_setup(enum bmc_access access)
> +static struct blocklevel_device *flash_setup(enum flash_access
> access)
>  {
>  	int rc;
>  	struct blocklevel_device *bl;
> @@ -237,7 +237,7 @@ static bool is_pnor_part(const char *str) {
>  	return strcasestr(str, "pnor");
>  }
>  
> -static char *get_dev_mtd(enum bmc_access access)
> +static char *get_dev_mtd(enum flash_access access)
>  {
>  	FILE *f;
>  	char *ret = NULL, *pos = NULL;
> @@ -276,8 +276,8 @@ static char *get_dev_mtd(enum bmc_access access)
>  	return ret;
>  }
>  
> -enum bmc_access arch_flash_bmc(struct blocklevel_device *bl,
> -		enum bmc_access access)
> +enum flash_access arch_flash_access(struct blocklevel_device *bl,
> +		enum flash_access access)
>  {
>  	if (access == ACCESS_INVAL)
>  		return ACCESS_INVAL;
> diff --git a/external/common/arch_flash_common.c
> b/external/common/arch_flash_common.c
> index ef4669a..ba06fb2 100644
> --- a/external/common/arch_flash_common.c
> +++ b/external/common/arch_flash_common.c
> @@ -16,6 +16,8 @@
>  
>  #include <libflash/blocklevel.h>
>  
> +#include "arch_flash.h"
> +
>  /* Default implmentations */
>  int __attribute__((weak)) arch_flash_erase_chip(struct
> blocklevel_device *bl)
>  {
> @@ -27,9 +29,9 @@ int __attribute__((weak)) arch_flash_4b_mode(struct
> blocklevel_device *bl, int s
>  	return -1;
>  }
>  
> -int __attribute__((weak)) arch_flash_bmc(struct blocklevel_device
> *bl, int bmc)
> +enum flash_access __attribute__((weak)) arch_flash_access(struct
> blocklevel_device *bl, enum flash_access access)
>  {
> -	return -1;
> +	return ACCESS_INVAL;
>  }
>  
>  int __attribute__((weak)) arch_flash_set_wrprotect(struct
> blocklevel_device *bl, int set)
> diff --git a/external/common/arch_flash_powerpc.c
> b/external/common/arch_flash_powerpc.c
> index 7ce962e..829d97b 100644
> --- a/external/common/arch_flash_powerpc.c
> +++ b/external/common/arch_flash_powerpc.c
> @@ -213,10 +213,24 @@ int arch_flash_set_wrprotect(struct
> blocklevel_device *bl, int set)
>  	return 0;
>  }
>  
> +enum flash_access arch_flash_access(struct blocklevel_device *bl,
> +		enum flash_access access)
> +{
> +	if (access != PNOR_MTD)
> +		return ACCESS_INVAL;

Oops, this generates a warning. I'll send a V2 of the series once
Stewart has had a look and we bikeshed the helptext in 5/5 some more.

> +}
> +
>  int arch_flash_init(struct blocklevel_device **r_bl, const char
> *file, bool keep_alive)
>  {
>  	struct blocklevel_device *new_bl;
>  
> +	/*
> +	 * In theory here we should check that something crazy
> wasn't
> +	 * passed to arch_flash_access() and refuse to init.
> +	 * However, arch_flash_access won't accept anything except
> +	 * PNOR_MTD, if they want something different then they
> should
> +	 * have checked with arch_flash_access()
> +	 */
>  	new_bl = arch_init_blocklevel(file, keep_alive);
>  	if (!new_bl)
>  		return -1;
> diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c
> index bece12a..002d0dc 100644
> --- a/external/pflash/pflash.c
> +++ b/external/pflash/pflash.c
> @@ -762,14 +762,14 @@ int main(int argc, char *argv[])
>  		 * This helps give a more meaningful error messages.
>  		 */
>  
> -		if (arch_flash_bmc(NULL, BMC_DIRECT) ==
> ACCESS_INVAL) {
> +		if (arch_flash_access(NULL, BMC_DIRECT) ==
> ACCESS_INVAL) {
>  			fprintf(stderr, "Can't access BMC flash on
> this architecture\n");
>  			exit(1);
>  		}
>  	}
>  
>  	if (mtd) {
> -		if (arch_flash_bmc(NULL, bmc_flash ? BMC_MTD :
> PNOR_MTD) == ACCESS_INVAL) {
> +		if (arch_flash_access(NULL, bmc_flash ? BMC_MTD :
> PNOR_MTD) == ACCESS_INVAL) {
>  			fprintf(stderr, "Can't access %s flash
> through MTD on this architecture\n",
>  			        bmc_flash ? "BMC" : "PNOR");
>  			exit(1);


More information about the Skiboot mailing list