public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Tommaso Merciai <tomm.merciai@gmail.com>
To: "Marek Behún" <marek.behun@nic.cz>
Cc: michael@amarulasolutions.com,
	andrey.zhizhikin@leica-geosystems.com,
	Stefano Babic <sbabic@denx.de>,
	Fabio Estevam <festevam@gmail.com>,
	"NXP i.MX U-Boot Team" <uboot-imx@nxp.com>,
	Peng Fan <peng.fan@nxp.com>, Ye Li <ye.li@nxp.com>,
	Marek Vasut <marex@denx.de>, Simon Glass <sjg@chromium.org>,
	Frieder Schrempf <frieder.schrempf@kontron.de>,
	Harald Seiler <hws@denx.de>,
	"Ying-Chun Liu (PaulLiu)" <paulliu@debian.org>,
	u-boot@lists.denx.de
Subject: Re: [RFC PATCH 3/3] imx: imx8mp_evk: override env_get_location
Date: Sun, 28 Nov 2021 18:47:11 +0100	[thread overview]
Message-ID: <20211128174711.GA4938@tom-desktop> (raw)
In-Reply-To: <20211126190021.7d8428af@thinkpad>

On Fri, Nov 26, 2021 at 07:00:21PM +0100, Marek Behún wrote:
> On Fri, 26 Nov 2021 18:43:31 +0100
> Tommaso Merciai <tomm.merciai@gmail.com> wrote:
> 
> > Override env_get_location function at board level, previously dropped
> > down from soc.c
> > 
> > References:
> >  - commit f1575f23df1ef704051f218d5bc4aeeb20c2c542
> > 
> > Signed-off-by: Tommaso Merciai <tomm.merciai@gmail.com>
> > ---
> > Changes since v1:
> >  - Remove wrong env_get_offset function from commit
> > 
> >  board/freescale/imx8mp_evk/imx8mp_evk.c | 41 +++++++++++++++++++++++++
> >  1 file changed, 41 insertions(+)
> > 
> > diff --git a/board/freescale/imx8mp_evk/imx8mp_evk.c b/board/freescale/imx8mp_evk/imx8mp_evk.c
> > index 62096c24fb..6b2eeaf152 100644
> > --- a/board/freescale/imx8mp_evk/imx8mp_evk.c
> > +++ b/board/freescale/imx8mp_evk/imx8mp_evk.c
> > @@ -5,6 +5,7 @@
> >  
> >  #include <common.h>
> >  #include <env.h>
> > +#include <env_internal.h>
> >  #include <errno.h>
> >  #include <init.h>
> >  #include <miiphy.h>
> > @@ -17,6 +18,7 @@
> >  #include <asm/arch/clock.h>
> >  #include <asm/arch/sys_proto.h>
> >  #include <asm/mach-imx/gpio.h>
> > +#include <asm/mach-imx/boot_mode.h>
> >  
> >  DECLARE_GLOBAL_DATA_PTR;
> >  
> > @@ -32,6 +34,45 @@ static iomux_v3_cfg_t const wdog_pads[] = {
> >  	MX8MP_PAD_GPIO1_IO02__WDOG1_WDOG_B  | MUX_PAD_CTRL(WDOG_PAD_CTRL),
> >  };
> >  
> > +enum env_location env_get_location(enum env_operation op, int prio)
> > +{
> > +	enum boot_device dev = get_boot_device();
> > +	enum env_location env_loc = ENVL_UNKNOWN;
> > +
> > +	if (prio)
> > +		return env_loc;
> > +
> > +	switch (dev) {
> > +#ifdef CONFIG_ENV_IS_IN_SPI_FLASH
> > +	case QSPI_BOOT:
> > +		env_loc = ENVL_SPI_FLASH;
> > +		break;
> > +#endif
> > +#ifdef CONFIG_ENV_IS_IN_NAND
> > +	case NAND_BOOT:
> > +		env_loc = ENVL_NAND;
> > +		break;
> > +#endif
> > +#ifdef CONFIG_ENV_IS_IN_MMC
> > +	case SD1_BOOT:
> > +	case SD2_BOOT:
> > +	case SD3_BOOT:
> > +	case MMC1_BOOT:
> > +	case MMC2_BOOT:
> > +	case MMC3_BOOT:
> > +		env_loc =  ENVL_MMC;
> > +		break;
> > +#endif
> > +	default:
> > +#if defined(CONFIG_ENV_IS_NOWHERE)
> > +		env_loc = ENVL_NOWHERE;
> > +#endif
> 
> Using
>   if (IS_ENABLED(CONFIG_ENV_IS_NOWHERE))
> instead of #ifdefs is preferred because the compiler then warns about
> bugs even in the disabled codepaths (that's why checkpatch complains
> about #ifdefs).
> 
> I know that this cannot be combined with switch() in a simple way,
> though.
> 
> Do you need to use switch? Can't you rewrite it to use if()s and use
> IS_ENABLED()?
> 
> Marek

Hi Marek,
Thanks for your review. What do you think about this solution?

enum env_location env_get_location(enum env_operation op, int prio)
{
	enum boot_device dev = get_boot_device();
	enum env_location env_loc = ENVL_UNKNOWN;

	if (prio)
		return env_loc;

	if (IS_ENABLED(CONFIG_ENV_IS_IN_SPI_FLASH) && dev == QSPI_BOOT) {
		env_loc = ENVL_SPI_FLASH;
	}
	else if (IS_ENABLED(CONFIG_ENV_IS_IN_NAND) && dev == NAND_BOOT) {
		env_loc = ENVL_NAND;
	}
	else if (IS_ENABLED(CONFIG_ENV_IS_IN_MMC)) {
		switch (dev) {
			case SD1_BOOT:
			case SD2_BOOT:
			case SD3_BOOT:
			case MMC1_BOOT:
			case MMC2_BOOT:
			case MMC3_BOOT:
				env_loc = ENVL_MMC;
				break;
		default:
			break;
		}
	}
	else if (IS_ENABLED(CONFIG_ENV_IS_NOWHERE)) {
		env_loc = ENVL_MMC;
	}

	return env_loc;
}

Let me know.

Thanks,
tommaso

  reply	other threads:[~2021-11-28 17:47 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-26 17:43 [RFC PATCH 0/3] imx8m: move env_get_location for imx8mn and imx8mp at board level Tommaso Merciai
2021-11-26 17:43 ` [RFC PATCH 1/3] imx8m: drop env_get_location for imx8mn and imx8mp Tommaso Merciai
2021-11-26 17:43 ` [RFC PATCH 2/3] imx: imx8mn_evk: override env_get_location Tommaso Merciai
2021-11-26 17:43 ` [RFC PATCH 3/3] imx: imx8mp_evk: " Tommaso Merciai
2021-11-26 18:00   ` Marek Behún
2021-11-28 17:47     ` Tommaso Merciai [this message]
2021-11-29 12:17       ` Marek Behún
2021-11-30 20:23         ` Tommaso Merciai
2021-12-07 18:13           ` Tommaso Merciai
2021-11-29  8:38 ` [RFC PATCH 0/3] imx8m: move env_get_location for imx8mn and imx8mp at board level ZHIZHIKIN Andrey
2021-11-29  8:40   ` Michael Nazzareno Trimarchi
2021-11-29  8:46     ` ZHIZHIKIN Andrey
2021-11-29  8:48       ` Michael Nazzareno Trimarchi

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=20211128174711.GA4938@tom-desktop \
    --to=tomm.merciai@gmail.com \
    --cc=andrey.zhizhikin@leica-geosystems.com \
    --cc=festevam@gmail.com \
    --cc=frieder.schrempf@kontron.de \
    --cc=hws@denx.de \
    --cc=marek.behun@nic.cz \
    --cc=marex@denx.de \
    --cc=michael@amarulasolutions.com \
    --cc=paulliu@debian.org \
    --cc=peng.fan@nxp.com \
    --cc=sbabic@denx.de \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    --cc=uboot-imx@nxp.com \
    --cc=ye.li@nxp.com \
    /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