[PATCH 1/4] ARM: imx: Add bmode support for iMX7

Add the basic differentiation between i.MX6 and i.MX7 into the bmode command, the mechanism really works almost the same on both platforms.
Signed-off-by: Marek Vasut marex@denx.de Cc: Fabio Estevam festevam@gmail.com Cc: NXP i.MX U-Boot Team uboot-imx@nxp.com Cc: Peng Fan peng.fan@nxp.com Cc: Stefano Babic sbabic@denx.de --- arch/arm/include/asm/mach-imx/sys_proto.h | 6 +++++- arch/arm/mach-imx/Kconfig | 2 +- arch/arm/mach-imx/init.c | 12 +++++++++--- arch/arm/mach-imx/mx7/soc.c | 8 ++++++++ 4 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/arch/arm/include/asm/mach-imx/sys_proto.h b/arch/arm/include/asm/mach-imx/sys_proto.h index ab94024c9b..2d18b1f56b 100644 --- a/arch/arm/include/asm/mach-imx/sys_proto.h +++ b/arch/arm/include/asm/mach-imx/sys_proto.h @@ -78,7 +78,7 @@ struct bd_info; #define is_imx8qxp() (is_cpu_type(MXC_CPU_IMX8QXP))
#ifdef CONFIG_MX6 -#define IMX6_SRC_GPR10_BMODE BIT(28) +#define IMX6_SRC_GPR10_BMODE BIT(28)
#define IMX6_BMODE_MASK GENMASK(7, 0) #define IMX6_BMODE_SHIFT 4 @@ -126,6 +126,10 @@ void gpr_init(void);
#endif /* CONFIG_MX6 */
+#ifdef CONFIG_MX7 +#define IMX7_SRC_GPR10_BMODE BIT(28) +#endif + /* address translation table */ struct rproc_att { u32 da; /* device address (From Cortex M4 view) */ diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig index 1531d09f3b..8f64e23195 100644 --- a/arch/arm/mach-imx/Kconfig +++ b/arch/arm/mach-imx/Kconfig @@ -62,7 +62,7 @@ config CSF_SIZE config CMD_BMODE bool "Support the 'bmode' command" default y - depends on ARCH_MX6 || ARCH_MX5 + depends on ARCH_MX7 || ARCH_MX6 || ARCH_MX5 help This enables the 'bmode' (bootmode) command for forcing a boot from specific media. diff --git a/arch/arm/mach-imx/init.c b/arch/arm/mach-imx/init.c index 693b724429..e30d63b896 100644 --- a/arch/arm/mach-imx/init.c +++ b/arch/arm/mach-imx/init.c @@ -103,14 +103,20 @@ void init_src(void) #ifdef CONFIG_CMD_BMODE void boot_mode_apply(unsigned cfg_val) { - unsigned reg; +#ifdef CONFIG_MX6 + const u32 bmode = IMX6_SRC_GPR10_BMODE; +#elif CONFIG_MX7 + const u32 bmode = IMX7_SRC_GPR10_BMODE; +#endif struct src *psrc = (struct src *)SRC_BASE_ADDR; + unsigned reg; + writel(cfg_val, &psrc->gpr9); reg = readl(&psrc->gpr10); if (cfg_val) - reg |= IMX6_SRC_GPR10_BMODE; + reg |= bmode; else - reg &= ~IMX6_SRC_GPR10_BMODE; + reg &= ~bmode; writel(reg, &psrc->gpr10); } #endif diff --git a/arch/arm/mach-imx/mx7/soc.c b/arch/arm/mach-imx/mx7/soc.c index 8db672fb05..2698ae623e 100644 --- a/arch/arm/mach-imx/mx7/soc.c +++ b/arch/arm/mach-imx/mx7/soc.c @@ -13,6 +13,7 @@ #include <asm/mach-imx/hab.h> #include <asm/mach-imx/rdc-sema.h> #include <asm/arch/imx-rdc.h> +#include <asm/mach-imx/boot_mode.h> #include <asm/arch/crm_regs.h> #include <dm.h> #include <env.h> @@ -411,6 +412,13 @@ void s_init(void) return; }
+#ifndef CONFIG_SPL_BUILD +const struct boot_mode soc_boot_modes[] = { + {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)}, + {NULL, 0}, +}; +#endif + void reset_misc(void) { #ifndef CONFIG_SPL_BUILD

The i.MX6/i.MX7 is capable of booting a secondary "redundant" system image in case the primary one is corrupted. The user can force this boot mode as well by explicitly setting SRC GPR10 bit 30. This can be potentially useful when upgrading the bootloader itself. Expose this functionality to the user.
Signed-off-by: Marek Vasut marex@denx.de Cc: Fabio Estevam festevam@gmail.com Cc: NXP i.MX U-Boot Team uboot-imx@nxp.com Cc: Peng Fan peng.fan@nxp.com Cc: Stefano Babic sbabic@denx.de --- arch/arm/include/asm/mach-imx/boot_mode.h | 2 ++ arch/arm/include/asm/mach-imx/sys_proto.h | 2 ++ arch/arm/mach-imx/init.c | 22 +++++++++++++++------- arch/arm/mach-imx/mx7/soc.c | 2 ++ 4 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/arch/arm/include/asm/mach-imx/boot_mode.h b/arch/arm/include/asm/mach-imx/boot_mode.h index 3a483b6afa..6dc5855968 100644 --- a/arch/arm/include/asm/mach-imx/boot_mode.h +++ b/arch/arm/include/asm/mach-imx/boot_mode.h @@ -7,6 +7,8 @@ #define _ASM_BOOT_MODE_H #define MAKE_CFGVAL(cfg1, cfg2, cfg3, cfg4) \ ((cfg4) << 24) | ((cfg3) << 16) | ((cfg2) << 8) | (cfg1) +#define MAKE_CFGVAL_PRIMARY_BOOT 0xfffffff0 +#define MAKE_CFGVAL_SECONDARY_BOOT 0xffffffff
enum boot_device { WEIM_NOR_BOOT, diff --git a/arch/arm/include/asm/mach-imx/sys_proto.h b/arch/arm/include/asm/mach-imx/sys_proto.h index 2d18b1f56b..15d1cba8e7 100644 --- a/arch/arm/include/asm/mach-imx/sys_proto.h +++ b/arch/arm/include/asm/mach-imx/sys_proto.h @@ -79,6 +79,7 @@ struct bd_info;
#ifdef CONFIG_MX6 #define IMX6_SRC_GPR10_BMODE BIT(28) +#define IMX6_SRC_GPR10_PERSIST_SECONDARY_BOOT BIT(30)
#define IMX6_BMODE_MASK GENMASK(7, 0) #define IMX6_BMODE_SHIFT 4 @@ -128,6 +129,7 @@ void gpr_init(void);
#ifdef CONFIG_MX7 #define IMX7_SRC_GPR10_BMODE BIT(28) +#define IMX7_SRC_GPR10_PERSIST_SECONDARY_BOOT BIT(30) #endif
/* address translation table */ diff --git a/arch/arm/mach-imx/init.c b/arch/arm/mach-imx/init.c index e30d63b896..ce3eb4b0b8 100644 --- a/arch/arm/mach-imx/init.c +++ b/arch/arm/mach-imx/init.c @@ -104,20 +104,28 @@ void init_src(void) void boot_mode_apply(unsigned cfg_val) { #ifdef CONFIG_MX6 + const u32 persist_sec = IMX6_SRC_GPR10_PERSIST_SECONDARY_BOOT; const u32 bmode = IMX6_SRC_GPR10_BMODE; #elif CONFIG_MX7 + const u32 persist_sec = IMX7_SRC_GPR10_PERSIST_SECONDARY_BOOT; const u32 bmode = IMX7_SRC_GPR10_BMODE; #endif struct src *psrc = (struct src *)SRC_BASE_ADDR; unsigned reg;
- writel(cfg_val, &psrc->gpr9); - reg = readl(&psrc->gpr10); - if (cfg_val) - reg |= bmode; - else - reg &= ~bmode; - writel(reg, &psrc->gpr10); + if (cfg_val == MAKE_CFGVAL_PRIMARY_BOOT) + clrbits_le32(&psrc->gpr10, persist_sec); + else if (cfg_val == MAKE_CFGVAL_SECONDARY_BOOT) + setbits_le32(&psrc->gpr10, persist_sec); + else { + writel(cfg_val, &psrc->gpr9); + reg = readl(&psrc->gpr10); + if (cfg_val) + reg |= bmode; + else + reg &= ~bmode; + writel(reg, &psrc->gpr10); + } } #endif
diff --git a/arch/arm/mach-imx/mx7/soc.c b/arch/arm/mach-imx/mx7/soc.c index 2698ae623e..b6fd25a991 100644 --- a/arch/arm/mach-imx/mx7/soc.c +++ b/arch/arm/mach-imx/mx7/soc.c @@ -415,6 +415,8 @@ void s_init(void) #ifndef CONFIG_SPL_BUILD const struct boot_mode soc_boot_modes[] = { {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)}, + {"primary", MAKE_CFGVAL_PRIMARY_BOOT}, + {"secondary", MAKE_CFGVAL_SECONDARY_BOOT}, {NULL, 0}, }; #endif

On 05.08.20 15:34, Marek Vasut wrote:
The i.MX6/i.MX7 is capable of booting a secondary "redundant" system image in case the primary one is corrupted. The user can force this boot mode as well by explicitly setting SRC GPR10 bit 30. This can be potentially useful when upgrading the bootloader itself. Expose this functionality to the user.
Signed-off-by: Marek Vasut marex@denx.de Cc: Fabio Estevam festevam@gmail.com Cc: NXP i.MX U-Boot Team uboot-imx@nxp.com Cc: Peng Fan peng.fan@nxp.com Cc: Stefano Babic sbabic@denx.de
arch/arm/include/asm/mach-imx/boot_mode.h | 2 ++ arch/arm/include/asm/mach-imx/sys_proto.h | 2 ++ arch/arm/mach-imx/init.c | 22 +++++++++++++++------- arch/arm/mach-imx/mx7/soc.c | 2 ++ 4 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/arch/arm/include/asm/mach-imx/boot_mode.h b/arch/arm/include/asm/mach-imx/boot_mode.h index 3a483b6afa..6dc5855968 100644 --- a/arch/arm/include/asm/mach-imx/boot_mode.h +++ b/arch/arm/include/asm/mach-imx/boot_mode.h @@ -7,6 +7,8 @@ #define _ASM_BOOT_MODE_H #define MAKE_CFGVAL(cfg1, cfg2, cfg3, cfg4) \ ((cfg4) << 24) | ((cfg3) << 16) | ((cfg2) << 8) | (cfg1) +#define MAKE_CFGVAL_PRIMARY_BOOT 0xfffffff0 +#define MAKE_CFGVAL_SECONDARY_BOOT 0xffffffff
enum boot_device { WEIM_NOR_BOOT, diff --git a/arch/arm/include/asm/mach-imx/sys_proto.h b/arch/arm/include/asm/mach-imx/sys_proto.h index 2d18b1f56b..15d1cba8e7 100644 --- a/arch/arm/include/asm/mach-imx/sys_proto.h +++ b/arch/arm/include/asm/mach-imx/sys_proto.h @@ -79,6 +79,7 @@ struct bd_info;
#ifdef CONFIG_MX6 #define IMX6_SRC_GPR10_BMODE BIT(28) +#define IMX6_SRC_GPR10_PERSIST_SECONDARY_BOOT BIT(30)
#define IMX6_BMODE_MASK GENMASK(7, 0) #define IMX6_BMODE_SHIFT 4 @@ -128,6 +129,7 @@ void gpr_init(void);
#ifdef CONFIG_MX7 #define IMX7_SRC_GPR10_BMODE BIT(28) +#define IMX7_SRC_GPR10_PERSIST_SECONDARY_BOOT BIT(30) #endif
/* address translation table */ diff --git a/arch/arm/mach-imx/init.c b/arch/arm/mach-imx/init.c index e30d63b896..ce3eb4b0b8 100644 --- a/arch/arm/mach-imx/init.c +++ b/arch/arm/mach-imx/init.c @@ -104,20 +104,28 @@ void init_src(void) void boot_mode_apply(unsigned cfg_val) { #ifdef CONFIG_MX6
- const u32 persist_sec = IMX6_SRC_GPR10_PERSIST_SECONDARY_BOOT; const u32 bmode = IMX6_SRC_GPR10_BMODE;
#elif CONFIG_MX7
- const u32 persist_sec = IMX7_SRC_GPR10_PERSIST_SECONDARY_BOOT; const u32 bmode = IMX7_SRC_GPR10_BMODE;
#endif struct src *psrc = (struct src *)SRC_BASE_ADDR; unsigned reg;
- writel(cfg_val, &psrc->gpr9);
- reg = readl(&psrc->gpr10);
- if (cfg_val)
reg |= bmode;
- else
reg &= ~bmode;
- writel(reg, &psrc->gpr10);
- if (cfg_val == MAKE_CFGVAL_PRIMARY_BOOT)
clrbits_le32(&psrc->gpr10, persist_sec);
- else if (cfg_val == MAKE_CFGVAL_SECONDARY_BOOT)
setbits_le32(&psrc->gpr10, persist_sec);
- else {
writel(cfg_val, &psrc->gpr9);
reg = readl(&psrc->gpr10);
if (cfg_val)
reg |= bmode;
else
reg &= ~bmode;
writel(reg, &psrc->gpr10);
- }
} #endif
diff --git a/arch/arm/mach-imx/mx7/soc.c b/arch/arm/mach-imx/mx7/soc.c index 2698ae623e..b6fd25a991 100644 --- a/arch/arm/mach-imx/mx7/soc.c +++ b/arch/arm/mach-imx/mx7/soc.c @@ -415,6 +415,8 @@ void s_init(void) #ifndef CONFIG_SPL_BUILD const struct boot_mode soc_boot_modes[] = { {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
- {"primary", MAKE_CFGVAL_PRIMARY_BOOT},
- {"secondary", MAKE_CFGVAL_SECONDARY_BOOT}, {NULL, 0},
}; #endif
Reviewed-by: Stefano Babic sbabic@denx.de
Regards, Stefano

The i.MX6/i.MX7 is capable of booting a secondary "redundant" system image in case the primary one is corrupted. The user can force this boot mode as well by explicitly setting SRC GPR10 bit 30. This can be potentially useful when upgrading the bootloader itself. Expose this functionality to the user. Signed-off-by: Marek Vasut marex@denx.de Cc: Fabio Estevam festevam@gmail.com Cc: NXP i.MX U-Boot Team uboot-imx@nxp.com Cc: Peng Fan peng.fan@nxp.com Cc: Stefano Babic sbabic@denx.de Reviewed-by: Stefano Babic sbabic@denx.de
Applied to u-boot-imx, master, thanks !
Best regards, Stefano Babic

Add new 'getprisec' subcommand to 'bmode' command, which sets the return value of the 'bmode' command to either 0 if the system booted from primary copy or to 1 if the system booted from secondary copy. This can be used e.g. in 'test' command to determine which copy of the system is running.
Signed-off-by: Marek Vasut marex@denx.de Cc: Fabio Estevam festevam@gmail.com Cc: NXP i.MX U-Boot Team uboot-imx@nxp.com Cc: Peng Fan peng.fan@nxp.com Cc: Stefano Babic sbabic@denx.de --- arch/arm/mach-imx/cmd_bmode.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/arch/arm/mach-imx/cmd_bmode.c b/arch/arm/mach-imx/cmd_bmode.c index 19bfd9f9a0..cb317499d5 100644 --- a/arch/arm/mach-imx/cmd_bmode.c +++ b/arch/arm/mach-imx/cmd_bmode.c @@ -51,9 +51,19 @@ static int create_usage(char *dest) if (dest) memcpy(dest - 1, " [noreset]", 11); /* include trailing 0 */ size += 10; + + if (dest) + memcpy(dest - 1, "\nbmode - getprisec", 19); + size += 18; + return size; }
+__weak int boot_mode_getprisec(void) +{ + return 0; +} + static int do_boot_mode(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -62,6 +72,8 @@ static int do_boot_mode(struct cmd_tbl *cmdtp, int flag, int argc,
if (argc < 2) return CMD_RET_USAGE; + if (!strcmp(argv[1], "getprisec")) + return boot_mode_getprisec(); p = search_modes(argv[1]); if (!p) return CMD_RET_USAGE;

On 05.08.20 15:34, Marek Vasut wrote:
Add new 'getprisec' subcommand to 'bmode' command, which sets the return value of the 'bmode' command to either 0 if the system booted from primary copy or to 1 if the system booted from secondary copy. This can be used e.g. in 'test' command to determine which copy of the system is running.
Signed-off-by: Marek Vasut marex@denx.de Cc: Fabio Estevam festevam@gmail.com Cc: NXP i.MX U-Boot Team uboot-imx@nxp.com Cc: Peng Fan peng.fan@nxp.com Cc: Stefano Babic sbabic@denx.de
arch/arm/mach-imx/cmd_bmode.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/arch/arm/mach-imx/cmd_bmode.c b/arch/arm/mach-imx/cmd_bmode.c index 19bfd9f9a0..cb317499d5 100644 --- a/arch/arm/mach-imx/cmd_bmode.c +++ b/arch/arm/mach-imx/cmd_bmode.c @@ -51,9 +51,19 @@ static int create_usage(char *dest) if (dest) memcpy(dest - 1, " [noreset]", 11); /* include trailing 0 */ size += 10;
- if (dest)
memcpy(dest - 1, "\nbmode - getprisec", 19);
- size += 18;
- return size;
}
+__weak int boot_mode_getprisec(void) +{
- return 0;
+}
static int do_boot_mode(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) { @@ -62,6 +72,8 @@ static int do_boot_mode(struct cmd_tbl *cmdtp, int flag, int argc,
if (argc < 2) return CMD_RET_USAGE;
- if (!strcmp(argv[1], "getprisec"))
p = search_modes(argv[1]); if (!p) return CMD_RET_USAGE;return boot_mode_getprisec();
Reviewed-by: Stefano Babic sbabic@denx.de
Best regards, Stefano Babic

Add new 'getprisec' subcommand to 'bmode' command, which sets the return value of the 'bmode' command to either 0 if the system booted from primary copy or to 1 if the system booted from secondary copy. This can be used e.g. in 'test' command to determine which copy of the system is running. Signed-off-by: Marek Vasut marex@denx.de Cc: Fabio Estevam festevam@gmail.com Cc: NXP i.MX U-Boot Team uboot-imx@nxp.com Cc: Peng Fan peng.fan@nxp.com Cc: Stefano Babic sbabic@denx.de Reviewed-by: Stefano Babic sbabic@denx.de
Applied to u-boot-imx, master, thanks !
Best regards, Stefano Babic

Implement the 'getprisec' subcommand of 'bmode' command for i.MX7 by reading out the SRC GPR10 bit 30. This bit is either set by the BootROM if it switched to the secondary copy due to primary copy being corrupted OR it can be overridden by the user.
Signed-off-by: Marek Vasut marex@denx.de Cc: Fabio Estevam festevam@gmail.com Cc: NXP i.MX U-Boot Team uboot-imx@nxp.com Cc: Peng Fan peng.fan@nxp.com Cc: Stefano Babic sbabic@denx.de --- arch/arm/mach-imx/mx7/soc.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/arch/arm/mach-imx/mx7/soc.c b/arch/arm/mach-imx/mx7/soc.c index b6fd25a991..c90f7354ea 100644 --- a/arch/arm/mach-imx/mx7/soc.c +++ b/arch/arm/mach-imx/mx7/soc.c @@ -419,6 +419,13 @@ const struct boot_mode soc_boot_modes[] = { {"secondary", MAKE_CFGVAL_SECONDARY_BOOT}, {NULL, 0}, }; + +int boot_mode_getprisec(void) +{ + struct src *psrc = (struct src *)SRC_BASE_ADDR; + + return !!(readl(&psrc->gpr10) & IMX7_SRC_GPR10_PERSIST_SECONDARY_BOOT); +} #endif
void reset_misc(void)

On 05.08.20 15:34, Marek Vasut wrote:
Implement the 'getprisec' subcommand of 'bmode' command for i.MX7 by reading out the SRC GPR10 bit 30. This bit is either set by the BootROM if it switched to the secondary copy due to primary copy being corrupted OR it can be overridden by the user.
Signed-off-by: Marek Vasut marex@denx.de Cc: Fabio Estevam festevam@gmail.com Cc: NXP i.MX U-Boot Team uboot-imx@nxp.com Cc: Peng Fan peng.fan@nxp.com Cc: Stefano Babic sbabic@denx.de
arch/arm/mach-imx/mx7/soc.c | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/arch/arm/mach-imx/mx7/soc.c b/arch/arm/mach-imx/mx7/soc.c index b6fd25a991..c90f7354ea 100644 --- a/arch/arm/mach-imx/mx7/soc.c +++ b/arch/arm/mach-imx/mx7/soc.c @@ -419,6 +419,13 @@ const struct boot_mode soc_boot_modes[] = { {"secondary", MAKE_CFGVAL_SECONDARY_BOOT}, {NULL, 0}, };
+int boot_mode_getprisec(void) +{
- struct src *psrc = (struct src *)SRC_BASE_ADDR;
- return !!(readl(&psrc->gpr10) & IMX7_SRC_GPR10_PERSIST_SECONDARY_BOOT);
+} #endif
void reset_misc(void)
Reviewed-by: Stefano Babic sbabic@denx.de
Best regards, Stefano Babic

Implement the 'getprisec' subcommand of 'bmode' command for i.MX7 by reading out the SRC GPR10 bit 30. This bit is either set by the BootROM if it switched to the secondary copy due to primary copy being corrupted OR it can be overridden by the user. Signed-off-by: Marek Vasut marex@denx.de Cc: Fabio Estevam festevam@gmail.com Cc: NXP i.MX U-Boot Team uboot-imx@nxp.com Cc: Peng Fan peng.fan@nxp.com Cc: Stefano Babic sbabic@denx.de Reviewed-by: Stefano Babic sbabic@denx.de
Applied to u-boot-imx, master, thanks !
Best regards, Stefano Babic

Hi Marek,
On 05.08.20 15:34, Marek Vasut wrote:
Add the basic differentiation between i.MX6 and i.MX7 into the bmode command, the mechanism really works almost the same on both platforms.
Signed-off-by: Marek Vasut marex@denx.de Cc: Fabio Estevam festevam@gmail.com Cc: NXP i.MX U-Boot Team uboot-imx@nxp.com Cc: Peng Fan peng.fan@nxp.com Cc: Stefano Babic sbabic@denx.de
arch/arm/include/asm/mach-imx/sys_proto.h | 6 +++++- arch/arm/mach-imx/Kconfig | 2 +- arch/arm/mach-imx/init.c | 12 +++++++++--- arch/arm/mach-imx/mx7/soc.c | 8 ++++++++ 4 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/arch/arm/include/asm/mach-imx/sys_proto.h b/arch/arm/include/asm/mach-imx/sys_proto.h index ab94024c9b..2d18b1f56b 100644 --- a/arch/arm/include/asm/mach-imx/sys_proto.h +++ b/arch/arm/include/asm/mach-imx/sys_proto.h @@ -78,7 +78,7 @@ struct bd_info; #define is_imx8qxp() (is_cpu_type(MXC_CPU_IMX8QXP))
#ifdef CONFIG_MX6 -#define IMX6_SRC_GPR10_BMODE BIT(28) +#define IMX6_SRC_GPR10_BMODE BIT(28)
#define IMX6_BMODE_MASK GENMASK(7, 0) #define IMX6_BMODE_SHIFT 4 @@ -126,6 +126,10 @@ void gpr_init(void);
#endif /* CONFIG_MX6 */
+#ifdef CONFIG_MX7 +#define IMX7_SRC_GPR10_BMODE BIT(28) +#endif
It is questionable why we need two different defines, that also have exactly the same definition. Do we really need to differentiate and to use #ifdef ?
/* address translation table */ struct rproc_att { u32 da; /* device address (From Cortex M4 view) */ diff --git a/arch/arm/mach-imx/Kconfig b/arch/arm/mach-imx/Kconfig index 1531d09f3b..8f64e23195 100644 --- a/arch/arm/mach-imx/Kconfig +++ b/arch/arm/mach-imx/Kconfig @@ -62,7 +62,7 @@ config CSF_SIZE config CMD_BMODE bool "Support the 'bmode' command" default y
- depends on ARCH_MX6 || ARCH_MX5
- depends on ARCH_MX7 || ARCH_MX6 || ARCH_MX5 help This enables the 'bmode' (bootmode) command for forcing a boot from specific media.
diff --git a/arch/arm/mach-imx/init.c b/arch/arm/mach-imx/init.c index 693b724429..e30d63b896 100644 --- a/arch/arm/mach-imx/init.c +++ b/arch/arm/mach-imx/init.c @@ -103,14 +103,20 @@ void init_src(void) #ifdef CONFIG_CMD_BMODE void boot_mode_apply(unsigned cfg_val) {
- unsigned reg;
+#ifdef CONFIG_MX6
- const u32 bmode = IMX6_SRC_GPR10_BMODE;
+#elif CONFIG_MX7
- const u32 bmode = IMX7_SRC_GPR10_BMODE;
+#endif
Ditto.
struct src *psrc = (struct src *)SRC_BASE_ADDR;
- unsigned reg;
- writel(cfg_val, &psrc->gpr9); reg = readl(&psrc->gpr10); if (cfg_val)
reg |= IMX6_SRC_GPR10_BMODE;
elsereg |= bmode;
reg &= ~IMX6_SRC_GPR10_BMODE;
writel(reg, &psrc->gpr10);reg &= ~bmode;
} #endif diff --git a/arch/arm/mach-imx/mx7/soc.c b/arch/arm/mach-imx/mx7/soc.c index 8db672fb05..2698ae623e 100644 --- a/arch/arm/mach-imx/mx7/soc.c +++ b/arch/arm/mach-imx/mx7/soc.c @@ -13,6 +13,7 @@ #include <asm/mach-imx/hab.h> #include <asm/mach-imx/rdc-sema.h> #include <asm/arch/imx-rdc.h> +#include <asm/mach-imx/boot_mode.h> #include <asm/arch/crm_regs.h> #include <dm.h> #include <env.h> @@ -411,6 +412,13 @@ void s_init(void) return; }
+#ifndef CONFIG_SPL_BUILD +const struct boot_mode soc_boot_modes[] = {
- {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
- {NULL, 0},
+}; +#endif
void reset_misc(void) { #ifndef CONFIG_SPL_BUILD
Regards, Stefano

On 8/5/20 3:59 PM, Stefano Babic wrote:
Hi Marek,
Hi,
On 05.08.20 15:34, Marek Vasut wrote:
Add the basic differentiation between i.MX6 and i.MX7 into the bmode command, the mechanism really works almost the same on both platforms.
Signed-off-by: Marek Vasut marex@denx.de Cc: Fabio Estevam festevam@gmail.com Cc: NXP i.MX U-Boot Team uboot-imx@nxp.com Cc: Peng Fan peng.fan@nxp.com Cc: Stefano Babic sbabic@denx.de
arch/arm/include/asm/mach-imx/sys_proto.h | 6 +++++- arch/arm/mach-imx/Kconfig | 2 +- arch/arm/mach-imx/init.c | 12 +++++++++--- arch/arm/mach-imx/mx7/soc.c | 8 ++++++++ 4 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/arch/arm/include/asm/mach-imx/sys_proto.h b/arch/arm/include/asm/mach-imx/sys_proto.h index ab94024c9b..2d18b1f56b 100644 --- a/arch/arm/include/asm/mach-imx/sys_proto.h +++ b/arch/arm/include/asm/mach-imx/sys_proto.h @@ -78,7 +78,7 @@ struct bd_info; #define is_imx8qxp() (is_cpu_type(MXC_CPU_IMX8QXP))
#ifdef CONFIG_MX6 -#define IMX6_SRC_GPR10_BMODE BIT(28) +#define IMX6_SRC_GPR10_BMODE BIT(28)
#define IMX6_BMODE_MASK GENMASK(7, 0) #define IMX6_BMODE_SHIFT 4 @@ -126,6 +126,10 @@ void gpr_init(void);
#endif /* CONFIG_MX6 */
+#ifdef CONFIG_MX7 +#define IMX7_SRC_GPR10_BMODE BIT(28) +#endif
It is questionable why we need two different defines, that also have exactly the same definition. Do we really need to differentiate and to use #ifdef ?
Yes, because this file is also used by iMXes which are not 6/7 .

On 05.08.20 16:40, Marek Vasut wrote:
On 8/5/20 3:59 PM, Stefano Babic wrote:
Hi Marek,
Hi,
On 05.08.20 15:34, Marek Vasut wrote:
Add the basic differentiation between i.MX6 and i.MX7 into the bmode command, the mechanism really works almost the same on both platforms.
Signed-off-by: Marek Vasut marex@denx.de Cc: Fabio Estevam festevam@gmail.com Cc: NXP i.MX U-Boot Team uboot-imx@nxp.com Cc: Peng Fan peng.fan@nxp.com Cc: Stefano Babic sbabic@denx.de
arch/arm/include/asm/mach-imx/sys_proto.h | 6 +++++- arch/arm/mach-imx/Kconfig | 2 +- arch/arm/mach-imx/init.c | 12 +++++++++--- arch/arm/mach-imx/mx7/soc.c | 8 ++++++++ 4 files changed, 23 insertions(+), 5 deletions(-)
diff --git a/arch/arm/include/asm/mach-imx/sys_proto.h b/arch/arm/include/asm/mach-imx/sys_proto.h index ab94024c9b..2d18b1f56b 100644 --- a/arch/arm/include/asm/mach-imx/sys_proto.h +++ b/arch/arm/include/asm/mach-imx/sys_proto.h @@ -78,7 +78,7 @@ struct bd_info; #define is_imx8qxp() (is_cpu_type(MXC_CPU_IMX8QXP))
#ifdef CONFIG_MX6 -#define IMX6_SRC_GPR10_BMODE BIT(28) +#define IMX6_SRC_GPR10_BMODE BIT(28)
#define IMX6_BMODE_MASK GENMASK(7, 0) #define IMX6_BMODE_SHIFT 4 @@ -126,6 +126,10 @@ void gpr_init(void);
#endif /* CONFIG_MX6 */
+#ifdef CONFIG_MX7 +#define IMX7_SRC_GPR10_BMODE BIT(28) +#endif
It is questionable why we need two different defines, that also have exactly the same definition. Do we really need to differentiate and to use #ifdef ?
Yes, because this file is also used by iMXes which are not 6/7 .
Yes, but does it disturb ? There should be a define SRC_GPR10_BMODE that is not used at all if we build for mx3/mx5. I just prefer to reduce the number of #ifdef, when they are not strictly required.
Regards, Stefano

On 8/5/20 4:54 PM, Stefano Babic wrote: [...]
#define is_imx8qxp() (is_cpu_type(MXC_CPU_IMX8QXP))
#ifdef CONFIG_MX6 -#define IMX6_SRC_GPR10_BMODE BIT(28) +#define IMX6_SRC_GPR10_BMODE BIT(28)
#define IMX6_BMODE_MASK GENMASK(7, 0) #define IMX6_BMODE_SHIFT 4 @@ -126,6 +126,10 @@ void gpr_init(void);
#endif /* CONFIG_MX6 */
+#ifdef CONFIG_MX7 +#define IMX7_SRC_GPR10_BMODE BIT(28) +#endif
It is questionable why we need two different defines, that also have exactly the same definition. Do we really need to differentiate and to use #ifdef ?
Yes, because this file is also used by iMXes which are not 6/7 .
Yes, but does it disturb ? There should be a define SRC_GPR10_BMODE that is not used at all if we build for mx3/mx5. I just prefer to reduce the number of #ifdef, when they are not strictly required.
Its putting macros into the preprocessor which don't need to be there. Otherwise, it is inline with the style in the rest of the file.

Add the basic differentiation between i.MX6 and i.MX7 into the bmode command, the mechanism really works almost the same on both platforms. Signed-off-by: Marek Vasut marex@denx.de Cc: Fabio Estevam festevam@gmail.com Cc: NXP i.MX U-Boot Team uboot-imx@nxp.com Cc: Peng Fan peng.fan@nxp.com Cc: Stefano Babic sbabic@denx.de
Applied to u-boot-imx, master, thanks !
Best regards, Stefano Babic
participants (3)
-
Marek Vasut
-
sbabic@denx.de
-
Stefano Babic