diff mbox

[U-Boot,v3,01/15] imx6: Add imx6_src_get_boot_mode

Message ID 1486047373-31676-2-git-send-email-jagan@openedev.com
State Changes Requested
Delegated to: Stefano Babic
Headers show

Commit Message

Jagan Teki Feb. 2, 2017, 2:55 p.m. UTC
For i.MX6, the bootmode determine code is part of spl_boot_device,
but there is might be a possibility for other part the code need to
check the desired boot mode for adding new functionalities like
modeboot env variable, or changing boot order etc.

So introduced imx6_src_get_boot_mode which actually reading the
boot mode register for desired modes.

More cleanup will be add in future patches.

Cc: Stefano Babic <sbabic@denx.de>
Cc: Tim Harvey <tharvey@gateworks.com>
Cc: Matteo Lisi <matteo.lisi@engicam.com>
Cc: Michael Trimarchi <michael@amarulasolutions.com>
Signed-off-by: Jagan Teki <jagan@openedev.com>
---
 arch/arm/imx-common/init.c                  | 12 ++++++++++++
 arch/arm/imx-common/spl.c                   |  6 +++---
 arch/arm/include/asm/imx-common/sys_proto.h | 14 ++++++++++++++
 3 files changed, 29 insertions(+), 3 deletions(-)

Comments

Stefano Babic Feb. 19, 2017, 3:49 p.m. UTC | #1
Hi Jagan,

On 02/02/2017 15:55, Jagan Teki wrote:
> For i.MX6, the bootmode determine code is part of spl_boot_device,
> but there is might be a possibility for other part the code need to
> check the desired boot mode for adding new functionalities like
> modeboot env variable, or changing boot order etc.
> 
> So introduced imx6_src_get_boot_mode which actually reading the
> boot mode register for desired modes.
> 

This restores the old behavior before commit:

commit ac0a93fd21b815166c54b991659377f951d4d203
Author: Stefan Agner <stefan.agner@toradex.com>
Date:   Tue Dec 27 17:01:42 2016 +0100

    imx_common: check for bmode Serial Downloader

It was reported by Stefan that the unreserved value (not documented)
causes issue and boards cannot boot. I agree on your patch to cleanup
code, but it should not change the current behaviour or the reported
issue will come up again

Best regards,
Stefano Babic

> More cleanup will be add in future patches.
> 
> Cc: Stefano Babic <sbabic@denx.de>
> Cc: Tim Harvey <tharvey@gateworks.com>
> Cc: Matteo Lisi <matteo.lisi@engicam.com>
> Cc: Michael Trimarchi <michael@amarulasolutions.com>
> Signed-off-by: Jagan Teki <jagan@openedev.com>
> ---
>  arch/arm/imx-common/init.c                  | 12 ++++++++++++
>  arch/arm/imx-common/spl.c                   |  6 +++---
>  arch/arm/include/asm/imx-common/sys_proto.h | 14 ++++++++++++++
>  3 files changed, 29 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/arm/imx-common/init.c b/arch/arm/imx-common/init.c
> index e5dbd93..036ebb2 100644
> --- a/arch/arm/imx-common/init.c
> +++ b/arch/arm/imx-common/init.c
> @@ -115,3 +115,15 @@ void boot_mode_apply(unsigned cfg_val)
>  	writel(reg, &psrc->gpr10);
>  }
>  #endif
> +
> +#if defined(CONFIG_MX6)
> +u32 imx6_src_get_boot_mode(void)
> +{
> +	struct src *psrc = (struct src *)SRC_BASE_ADDR;
> +
> +	if (imx6_is_bmode_from_gpr9())
> +		return readl(&psrc->gpr9);
> +	else
> +		return readl(&psrc->sbmr1);
> +}
> +#endif
> diff --git a/arch/arm/imx-common/spl.c b/arch/arm/imx-common/spl.c
> index 60c4adf..a7f9705 100644
> --- a/arch/arm/imx-common/spl.c
> +++ b/arch/arm/imx-common/spl.c
> @@ -10,6 +10,7 @@
>  #include <common.h>
>  #include <asm/io.h>
>  #include <asm/arch/imx-regs.h>
> +#include <asm/arch/sys_proto.h>
>  #include <asm/spl.h>
>  #include <spl.h>
>  #include <asm/imx-common/hab.h>
> @@ -19,16 +20,15 @@
>  u32 spl_boot_device(void)
>  {
>  	struct src *psrc = (struct src *)SRC_BASE_ADDR;
> -	unsigned int gpr10_boot = readl(&psrc->gpr10) & (1 << 28);
> -	unsigned reg = gpr10_boot ? readl(&psrc->gpr9) : readl(&psrc->sbmr1);
>  	unsigned int bmode = readl(&psrc->sbmr2);
> +	u32 reg = imx6_src_get_boot_mode();
>  
>  	/*
>  	 * Check for BMODE if serial downloader is enabled
>  	 * BOOT_MODE - see IMX6DQRM Table 8-1
>  	 */
>  	if ((((bmode >> 24) & 0x03)  == 0x01) || /* Serial Downloader */
> -		(gpr10_boot && (reg == 1)))
> +		(imx6_is_bmode_from_gpr9() && (reg == 1)))
>  		return BOOT_DEVICE_UART;
>  	/* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */
>  	switch ((reg & 0x000000FF) >> 4) {
> diff --git a/arch/arm/include/asm/imx-common/sys_proto.h b/arch/arm/include/asm/imx-common/sys_proto.h
> index 539d34b..99e3869 100644
> --- a/arch/arm/include/asm/imx-common/sys_proto.h
> +++ b/arch/arm/include/asm/imx-common/sys_proto.h
> @@ -8,6 +8,7 @@
>  #ifndef _SYS_PROTO_H_
>  #define _SYS_PROTO_H_
>  
> +#include <asm/io.h>
>  #include <asm/imx-common/regs-common.h>
>  #include <common.h>
>  #include "../arch-imx/cpu.h"
> @@ -38,6 +39,19 @@
>  #define is_mx6ull() (is_cpu_type(MXC_CPU_MX6ULL))
>  #define is_mx6sll() (is_cpu_type(MXC_CPU_MX6SLL))
>  
> +#ifdef CONFIG_MX6
> +#define IMX6_SRC_GPR10_BMODE		BIT(28)
> +
> +static inline u8 imx6_is_bmode_from_gpr9(void)
> +{
> +	struct src *psrc = (struct src *)SRC_BASE_ADDR;
> +
> +	return readl(&psrc->gpr10) & IMX6_SRC_GPR10_BMODE;
> +}
> +
> +u32 imx6_src_get_boot_mode(void);
> +#endif /* CONFIG_MX6 */
> +
>  u32 get_nr_cpus(void);
>  u32 get_cpu_rev(void);
>  u32 get_cpu_speed_grade_hz(void);
>
diff mbox

Patch

diff --git a/arch/arm/imx-common/init.c b/arch/arm/imx-common/init.c
index e5dbd93..036ebb2 100644
--- a/arch/arm/imx-common/init.c
+++ b/arch/arm/imx-common/init.c
@@ -115,3 +115,15 @@  void boot_mode_apply(unsigned cfg_val)
 	writel(reg, &psrc->gpr10);
 }
 #endif
+
+#if defined(CONFIG_MX6)
+u32 imx6_src_get_boot_mode(void)
+{
+	struct src *psrc = (struct src *)SRC_BASE_ADDR;
+
+	if (imx6_is_bmode_from_gpr9())
+		return readl(&psrc->gpr9);
+	else
+		return readl(&psrc->sbmr1);
+}
+#endif
diff --git a/arch/arm/imx-common/spl.c b/arch/arm/imx-common/spl.c
index 60c4adf..a7f9705 100644
--- a/arch/arm/imx-common/spl.c
+++ b/arch/arm/imx-common/spl.c
@@ -10,6 +10,7 @@ 
 #include <common.h>
 #include <asm/io.h>
 #include <asm/arch/imx-regs.h>
+#include <asm/arch/sys_proto.h>
 #include <asm/spl.h>
 #include <spl.h>
 #include <asm/imx-common/hab.h>
@@ -19,16 +20,15 @@ 
 u32 spl_boot_device(void)
 {
 	struct src *psrc = (struct src *)SRC_BASE_ADDR;
-	unsigned int gpr10_boot = readl(&psrc->gpr10) & (1 << 28);
-	unsigned reg = gpr10_boot ? readl(&psrc->gpr9) : readl(&psrc->sbmr1);
 	unsigned int bmode = readl(&psrc->sbmr2);
+	u32 reg = imx6_src_get_boot_mode();
 
 	/*
 	 * Check for BMODE if serial downloader is enabled
 	 * BOOT_MODE - see IMX6DQRM Table 8-1
 	 */
 	if ((((bmode >> 24) & 0x03)  == 0x01) || /* Serial Downloader */
-		(gpr10_boot && (reg == 1)))
+		(imx6_is_bmode_from_gpr9() && (reg == 1)))
 		return BOOT_DEVICE_UART;
 	/* BOOT_CFG1[7:4] - see IMX6DQRM Table 8-8 */
 	switch ((reg & 0x000000FF) >> 4) {
diff --git a/arch/arm/include/asm/imx-common/sys_proto.h b/arch/arm/include/asm/imx-common/sys_proto.h
index 539d34b..99e3869 100644
--- a/arch/arm/include/asm/imx-common/sys_proto.h
+++ b/arch/arm/include/asm/imx-common/sys_proto.h
@@ -8,6 +8,7 @@ 
 #ifndef _SYS_PROTO_H_
 #define _SYS_PROTO_H_
 
+#include <asm/io.h>
 #include <asm/imx-common/regs-common.h>
 #include <common.h>
 #include "../arch-imx/cpu.h"
@@ -38,6 +39,19 @@ 
 #define is_mx6ull() (is_cpu_type(MXC_CPU_MX6ULL))
 #define is_mx6sll() (is_cpu_type(MXC_CPU_MX6SLL))
 
+#ifdef CONFIG_MX6
+#define IMX6_SRC_GPR10_BMODE		BIT(28)
+
+static inline u8 imx6_is_bmode_from_gpr9(void)
+{
+	struct src *psrc = (struct src *)SRC_BASE_ADDR;
+
+	return readl(&psrc->gpr10) & IMX6_SRC_GPR10_BMODE;
+}
+
+u32 imx6_src_get_boot_mode(void);
+#endif /* CONFIG_MX6 */
+
 u32 get_nr_cpus(void);
 u32 get_cpu_rev(void);
 u32 get_cpu_speed_grade_hz(void);