mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Michael Riesch <michael.riesch@wolfvision.net>
To: barebox@lists.infradead.org
Cc: sha@pengutronix.de, a.fatoum@pengutronix.de
Subject: Re: [RFC PATCH] bootsource: add helper to set instance by name
Date: Fri, 14 Jan 2022 09:25:56 +0100	[thread overview]
Message-ID: <0a914276-723d-69fa-cee3-42b517435d6f@wolfvision.net> (raw)
In-Reply-To: <20211117142448.2091017-1-michael.riesch@wolfvision.net>

Hi Sascha and Ahmad,

On 11/17/21 15:24, Michael Riesch wrote:
> Instance numbers should be related to device tree aliases, which may be
> board-specific. In order to establish a board-independent link between
> the boot source and the actual alias, introduce a helper that sets the
> instance by the OF name.

Gentle ping here. A rough indication whether or not this is the correct
path would be great.

Since patch 2/3 has just been cherry-picked, I could prepare a v2 of the
remaining two patches as next step.

Best regards,
Michael

> 
> Signed-off-by: Michael Riesch <michael.riesch@wolfvision.net>
> ---
>  common/bootsource.c  | 74 ++++++++++++++++++++++++++++----------------
>  include/bootsource.h |  1 +
>  2 files changed, 48 insertions(+), 27 deletions(-)
> 
> diff --git a/common/bootsource.c b/common/bootsource.c
> index 1f8d053a8..1b45956a5 100644
> --- a/common/bootsource.c
> +++ b/common/bootsource.c
> @@ -9,6 +9,7 @@
>  #include <environment.h>
>  #include <magicvar.h>
>  #include <init.h>
> +#include <of.h>
>  
>  static const char *bootsource_str[] = {
>  	[BOOTSOURCE_UNKNOWN] = "unknown",
> @@ -33,31 +34,8 @@ static enum bootsource bootsource = BOOTSOURCE_UNKNOWN;
>  static int bootsource_instance = BOOTSOURCE_INSTANCE_UNKNOWN;
>  const char *bootsource_alias_name = NULL;
>  
> -/**
> - * bootsource_get_alias_name() - Get the name of the bootsource alias
> - *
> - * This function will return newly allocated string containing name of
> - * the alias that is expected to point to DTB node corresponding to
> - * detected bootsource
> - *
> - * NOTE: Caller is expected to free() the string allocated by this
> - * function
> - */
> -char *bootsource_get_alias_name(void)
> +static const char *bootsource_get_of_stem(void)
>  {
> -	const char *stem;
> -
> -	/*
> -	 * If alias name was overridden via
> -	 * bootsource_set_alias_name() return that value without
> -	 * asking any questions.
> -	 *
> -	 * Note that we have to strdup() the result to make it
> -	 * free-able.
> -	 */
> -	if (bootsource_alias_name)
> -		return strdup(bootsource_alias_name);
> -
>  	switch (bootsource) {
>  		/*
>  		 * For I2C and SPI EEPROMs we set the stem to be 'i2c'
> @@ -69,22 +47,50 @@ char *bootsource_get_alias_name(void)
>  		 * controller
>  		 */
>  	case BOOTSOURCE_I2C_EEPROM:
> -		stem = bootsource_str[BOOTSOURCE_I2C];
> +		return bootsource_str[BOOTSOURCE_I2C];
>  		break;
>  	case BOOTSOURCE_SPI_EEPROM:
>  	case BOOTSOURCE_SPI_NOR:
> -		stem = bootsource_str[BOOTSOURCE_SPI];
> +		return bootsource_str[BOOTSOURCE_SPI];
>  		break;
>  	case BOOTSOURCE_SERIAL:	/* FALLTHROUGH */
>  	case BOOTSOURCE_I2C:	/* FALLTHROUGH */
>  	case BOOTSOURCE_MMC:	/* FALLTHROUGH */
>  	case BOOTSOURCE_SPI:	/* FALLTHROUGH */
>  	case BOOTSOURCE_CAN:
> -		stem = bootsource_str[bootsource];
> +		return bootsource_str[bootsource];
>  		break;
>  	default:
>  		return NULL;
>  	}
> +}
> +
> +/**
> + * bootsource_get_alias_name() - Get the name of the bootsource alias
> + *
> + * This function will return newly allocated string containing name of
> + * the alias that is expected to point to DTB node corresponding to
> + * detected bootsource
> + *
> + * NOTE: Caller is expected to free() the string allocated by this
> + * function
> + */
> +char *bootsource_get_alias_name(void)
> +{
> +	const char *stem;
> +
> +	/*
> +	 * If alias name was overridden via
> +	 * bootsource_set_alias_name() return that value without
> +	 * asking any questions.
> +	 *
> +	 * Note that we have to strdup() the result to make it
> +	 * free-able.
> +	 */
> +	if (bootsource_alias_name)
> +		return strdup(bootsource_alias_name);
> +
> +	stem = bootsource_get_of_stem();
>  
>  	/*
>  	 * We expect SoC specific bootsource detection code to properly
> @@ -125,6 +131,20 @@ void bootsource_set_instance(int instance)
>  	setenv("bootsource_instance", buf);
>  }
>  
> +void bootsource_set_instance_by_of_name(const char *name)
> +{
> +	int instance = BOOTSOURCE_UNKNOWN;
> +	struct device_node *node;
> +
> +	node = of_find_node_by_name(of_get_root_node(), name);
> +	if (node) {
> +		instance = of_alias_get_id(node, bootsource_get_of_stem());
> +		if (instance < 0)
> +			instance = BOOTSOURCE_UNKNOWN;
> +	}
> +	bootsource_set_instance(instance);
> +}
> +
>  enum bootsource bootsource_get(void)
>  {
>  	return bootsource;
> diff --git a/include/bootsource.h b/include/bootsource.h
> index 646b0e91c..4dcb969ac 100644
> --- a/include/bootsource.h
> +++ b/include/bootsource.h
> @@ -28,6 +28,7 @@ enum bootsource bootsource_get(void);
>  int bootsource_get_instance(void);
>  void bootsource_set(enum bootsource src);
>  void bootsource_set_instance(int instance);
> +void bootsource_set_instance_by_of_name(const char *name);
>  void bootsource_set_alias_name(const char *name);
>  char *bootsource_get_alias_name(void);
>  

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


  reply	other threads:[~2022-01-14  8:27 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-11 14:03 [PATCH 0/3] arm: rockchip: minor fixes as preparation for mainline dts Michael Riesch
2021-11-11 14:03 ` [PATCH 1/3] arm: rockchip: rk3568: fix mmc boot source instances Michael Riesch
2021-11-15  7:51   ` Sascha Hauer
2021-11-15  8:06     ` Sascha Hauer
2021-11-15  9:24       ` Michael Riesch
2021-11-17 14:24         ` [RFC PATCH] bootsource: add helper to set instance by name Michael Riesch
2022-01-14  8:25           ` Michael Riesch [this message]
2022-01-14  9:15           ` Sascha Hauer
2021-11-11 14:03 ` [PATCH 2/3] net: designware: rockchip: remove unnecessary clock pclk_xpcs Michael Riesch
2022-01-14  5:24   ` Ahmad Fatoum
2022-01-14  8:16     ` Sascha Hauer
2021-11-11 14:03 ` [PATCH 3/3] pinctrl: rockchip: use alias rather than full of name Michael Riesch
2021-11-15  7:54   ` Sascha Hauer
2021-11-17 12:42     ` Michael Riesch

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0a914276-723d-69fa-cee3-42b517435d6f@wolfvision.net \
    --to=michael.riesch@wolfvision.net \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=sha@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox