mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] imx:boot: adapt boot device detection for imx8mp
@ 2022-10-14 11:53 Enrico Scholz
  2022-10-20  8:02 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Enrico Scholz @ 2022-10-14 11:53 UTC (permalink / raw)
  To: barebox; +Cc: Enrico Scholz

imx8mp uses sbmr2[27..24] for encoding the bootmode while existing
code reads only sbmr2[25..24].

This can detect BOOTSOURCE_SERIAL for the wrong mode.

Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
---
 arch/arm/mach-imx/boot.c | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
index 8c9febb50a65..daf1951a36c2 100644
--- a/arch/arm/mach-imx/boot.c
+++ b/arch/arm/mach-imx/boot.c
@@ -202,7 +202,8 @@ void imx51_boot_save_loc(void)
 }
 
 #define IMX53_SRC_SBMR	0x4
-#define SRC_SBMR_BMOD	GENMASK(25, 24)
+#define IMX53_SRC_SBMR_BMOD	GENMASK(25, 24)
+#define IMX8MP_SRC_SBMR_BMOD	GENMASK(27, 24)
 #define IMX53_BMOD_SERIAL	0b11
 
 #define __BOOT_CFG(n, m, l)	GENMASK((m) + ((n) - 1) * 8, \
@@ -234,7 +235,12 @@ __MAKE_BOOT_CFG_BITS(4)
 
 static unsigned int imx53_get_bmod(uint32_t r)
 {
-	return FIELD_GET(SRC_SBMR_BMOD, r);
+	return FIELD_GET(IMX53_SRC_SBMR_BMOD, r);
+}
+
+static unsigned int imx8mp_get_bmod(uint32_t r)
+{
+	return FIELD_GET(IMX8MP_SRC_SBMR_BMOD, r);
 }
 
 static int imx53_bootsource_internal(uint32_t r)
@@ -318,6 +324,8 @@ void imx53_boot_save_loc(void)
 #define IMX6_BMOD_SERIAL	0b01
 #define IMX6_BMOD_RESERVED	0b11
 #define IMX6_BMOD_FUSES		0b00
+#define IMX8MP_BMOD_FUSES	0b0000
+#define IMX8MP_BMOD_SERIAL	0b0001
 #define BT_FUSE_SEL		BIT(4)
 #define GPR10_BOOT_FROM_GPR9	BIT(28)
 
@@ -338,6 +346,26 @@ static bool imx6_bootsource_serial(uint32_t sbmr2)
 		!(sbmr2 & BT_FUSE_SEL));
 }
 
+static bool imx8mp_bootsource_serial(uint32_t sbmr2)
+{
+	return imx8mp_get_bmod(sbmr2) == IMX8MP_BMOD_SERIAL ||
+		/*
+		 * If boot from fuses is selected and fuses are not
+		 * programmed by setting BT_FUSE_SEL, ROM code will
+		 * fallback to serial mode
+		 */
+		(imx8mp_get_bmod(sbmr2) == IMX8MP_BMOD_FUSES &&
+		 !(sbmr2 & BT_FUSE_SEL));
+}
+
+static bool imx_bootsource_serial(uint32_t sbmr2)
+{
+	if (cpu_is_mx8mp())
+		return imx8mp_bootsource_serial(sbmr2);
+	else
+		return imx6_bootsource_serial(sbmr2);
+}
+
 static bool imx6_bootsource_serial_forced(uint32_t bootmode)
 {
 	if (cpu_mx6_is_mx6ul() || cpu_mx6_is_mx6ull())
@@ -497,7 +525,7 @@ static void __imx7_get_boot_source(enum bootsource *src, int *instance,
 {
 	const struct imx_boot_sw_info *info;
 
-	if (imx6_bootsource_serial(sbmr2)) {
+	if (imx_bootsource_serial(sbmr2)) {
 		*src = BOOTSOURCE_SERIAL;
 		return;
 	}
-- 
2.37.3




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] imx:boot: adapt boot device detection for imx8mp
  2022-10-14 11:53 [PATCH] imx:boot: adapt boot device detection for imx8mp Enrico Scholz
@ 2022-10-20  8:02 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2022-10-20  8:02 UTC (permalink / raw)
  To: Enrico Scholz; +Cc: barebox

On Fri, Oct 14, 2022 at 01:53:54PM +0200, Enrico Scholz wrote:
> imx8mp uses sbmr2[27..24] for encoding the bootmode while existing
> code reads only sbmr2[25..24].
> 
> This can detect BOOTSOURCE_SERIAL for the wrong mode.
> 
> Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
> ---
>  arch/arm/mach-imx/boot.c | 34 +++++++++++++++++++++++++++++++---
>  1 file changed, 31 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm/mach-imx/boot.c b/arch/arm/mach-imx/boot.c
> index 8c9febb50a65..daf1951a36c2 100644
> --- a/arch/arm/mach-imx/boot.c
> +++ b/arch/arm/mach-imx/boot.c
> @@ -202,7 +202,8 @@ void imx51_boot_save_loc(void)
>  }
>  
>  #define IMX53_SRC_SBMR	0x4
> -#define SRC_SBMR_BMOD	GENMASK(25, 24)
> +#define IMX53_SRC_SBMR_BMOD	GENMASK(25, 24)
> +#define IMX8MP_SRC_SBMR_BMOD	GENMASK(27, 24)
>  #define IMX53_BMOD_SERIAL	0b11
>  
>  #define __BOOT_CFG(n, m, l)	GENMASK((m) + ((n) - 1) * 8, \
> @@ -234,7 +235,12 @@ __MAKE_BOOT_CFG_BITS(4)
>  
>  static unsigned int imx53_get_bmod(uint32_t r)
>  {
> -	return FIELD_GET(SRC_SBMR_BMOD, r);
> +	return FIELD_GET(IMX53_SRC_SBMR_BMOD, r);
> +}
> +
> +static unsigned int imx8mp_get_bmod(uint32_t r)
> +{
> +	return FIELD_GET(IMX8MP_SRC_SBMR_BMOD, r);
>  }
>  
>  static int imx53_bootsource_internal(uint32_t r)
> @@ -318,6 +324,8 @@ void imx53_boot_save_loc(void)
>  #define IMX6_BMOD_SERIAL	0b01
>  #define IMX6_BMOD_RESERVED	0b11
>  #define IMX6_BMOD_FUSES		0b00
> +#define IMX8MP_BMOD_FUSES	0b0000
> +#define IMX8MP_BMOD_SERIAL	0b0001
>  #define BT_FUSE_SEL		BIT(4)
>  #define GPR10_BOOT_FROM_GPR9	BIT(28)
>  
> @@ -338,6 +346,26 @@ static bool imx6_bootsource_serial(uint32_t sbmr2)
>  		!(sbmr2 & BT_FUSE_SEL));
>  }
>  
> +static bool imx8mp_bootsource_serial(uint32_t sbmr2)
> +{
> +	return imx8mp_get_bmod(sbmr2) == IMX8MP_BMOD_SERIAL ||
> +		/*
> +		 * If boot from fuses is selected and fuses are not
> +		 * programmed by setting BT_FUSE_SEL, ROM code will
> +		 * fallback to serial mode
> +		 */
> +		(imx8mp_get_bmod(sbmr2) == IMX8MP_BMOD_FUSES &&
> +		 !(sbmr2 & BT_FUSE_SEL));
> +}
> +
> +static bool imx_bootsource_serial(uint32_t sbmr2)
> +{
> +	if (cpu_is_mx8mp())
> +		return imx8mp_bootsource_serial(sbmr2);
> +	else
> +		return imx6_bootsource_serial(sbmr2);
> +}

You can't use cpu_is_mx8mp() properly here. cpu_is_mx8mp() uses the
variable imx_cpu_type which is only initialized in barebox proper, but
this code here is also used in PBL.
I had a look at the manuals and saw that i.MX8MN also uses four bit for
the boot modes.

I prepared a series from that, maybe you can give it a test/review.

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-20  8:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-14 11:53 [PATCH] imx:boot: adapt boot device detection for imx8mp Enrico Scholz
2022-10-20  8:02 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox