Skip to contentSkip to conversation

imx: Define common routines to set cpu and board environment variables

PATCH New Eric Nelson 3 participants 13 messages Nov 17, 2013 – Nov 19, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v3 cover imx: Define common routines to set cpu and board environment variables

This series adds support for two environment variables that are useful for use in scripting startup of an O/S in general, and specifically in computing DTB names.

Patches 1 and 2 implement the feature through arch_misc_init(), but don't enable it.

Patch 3 overrides board_name for the nitrogen6x board file, which is used for both Nitrogen6X and SABRE Lite boards.

Patch 4 enables the feature for nitrogen6x

Patch 5 enables the feature for Freescale mx6*sabre* boards

V3 reworks things completely based on feedback from the mailing list. In particular:

-- the variable names were changes from "cpu" and "board" to
"imx_type" and "board_name"
-- the arch_misc_init() routine was added
-- SABRE Lite environment was changed to use the feature

Eric Nelson (5):
i.MX5x: define cpu_type() to return processor portion of cpu rev.
imx: Define common routines to set cpu and board environment variables i.MX6: nitrogen6x/sabrelite: override set_board_name() i.MX6: nitrogen6x/sabrelite: initialize imx_type and board_name values i.MX6: mx6*sabre*: initialize imx_type and board_name values

 arch/arm/imx-common/cpu.c                 | 24 ++++++++++++++++++++++--
 arch/arm/include/asm/arch-mx5/sys_proto.h |  4 ++++
 board/boundary/nitrogen6x/nitrogen6x.c    | 14 +++++++++++++-
 include/configs/mx6sabre_common.h         |  1 +
 include/configs/nitrogen6x.h              |  9 ++++++++-
 5 files changed, 48 insertions(+), 4 deletions(-)
Signature · 1 line
1.8.1.2
#1 lore raw

PATCH v3 1/5 i.MX5x: define cpu_type() to return processor portion of cpu rev.

---
This patch is new in V3

 arch/arm/include/asm/arch-mx5/sys_proto.h | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/include/asm/arch-mx5/sys_proto.h +4 -0
index 9949ad1..9dad5fc 100644
@@ -17,6 +17,10 @@
 
 #define is_soc_rev(rev)	((get_cpu_rev() & 0xFF) - rev)
 u32 get_cpu_rev(void);
+
+/* returns MXC_CPU_ value */
+#define cpu_type(rev) (((rev) >> 12)&0xff)
+
 unsigned imx_ddr_size(void);
 void sdelay(unsigned long);
 void set_chipselect_size(int const);
Signature · 1 line
1.8.1.2
#2 lore raw

PATCH v3 1/5 i.MX5x: define cpu_type() to return processor portion of cpu rev.

Hi Eric,

Quoted 12 lines

---
This patch is new in V3

 arch/arm/include/asm/arch-mx5/sys_proto.h | 4 ++++
 1 file changed, 4 insertions(+)
(quoted diff) +0 -0

b/arch/arm/include/asm/arch-mx5/sys_proto.h index 9949ad1..9dad5fc 100644

arch/arm/include/asm/arch-mx5/sys_proto.h line 22

Quoted 6 lines
arch/arm/include/asm/arch-mx5/sys_proto.h +3 -0
@@ -17,6 +17,10 @@
 
 #define is_soc_rev(rev)	((get_cpu_rev() & 0xFF) - rev)
 u32 get_cpu_rev(void);
+
+/* returns MXC_CPU_ value */
+#define cpu_type(rev) (((rev) >> 12)&0xff)

Maybe you can implement it the same way as get_cpu_rev() and make it call get_cpu_rev() internally ? Then it'd be a function (with all the typechecking and stuff) and you won't need to pass extra param.

Best regards,
Marek Vasut

#3 lore raw

PATCH v3 1/5 i.MX5x: define cpu_type() to return processor portion of cpu rev.

In reply to Eric Nelson

Hi Eric,

Quoted 12 lines · Eric Nelson

---
This patch is new in V3

 arch/arm/include/asm/arch-mx5/sys_proto.h | 4 ++++
 1 file changed, 4 insertions(+)
arch/arm/include/asm/arch-mx5/sys_proto.h +0 -0
index 9949ad1..9dad5fc 100644

arch/arm/include/asm/arch-mx5/sys_proto.h line 23

Quoted 7 lines
arch/arm/include/asm/arch-mx5/sys_proto.h +4 -0
@@ -17,6 +17,10 @@
 
 #define is_soc_rev(rev)	((get_cpu_rev() & 0xFF) - rev)
 u32 get_cpu_rev(void);
+
+/* returns MXC_CPU_ value */
+#define cpu_type(rev) (((rev) >> 12)&0xff)
+

There is already a get_cpu_type() for other architectures (OMAP). We do not need to reinvent the wheel this time, and it is correct to add get_cpu_type(void) to sys_proto.h.

This lets also easier to understand the code because it can be directly derived from the User's Manual: shifting 12 bit in your macro is only because this is done in get_cpu_rev(), not because this is the offset in the i.MX6 register.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
#4 lore raw

PATCH v3 1/5 i.MX5x: define cpu_type() to return processor portion of cpu rev.

Hi Stefano,

Quoted 27 lines · Stefano Babic

Hi Eric,

Quoted 12 lines · Eric Nelson

---
This patch is new in V3

  arch/arm/include/asm/arch-mx5/sys_proto.h | 4 ++++
  1 file changed, 4 insertions(+)
arch/arm/include/asm/arch-mx5/sys_proto.h +0 -0
index 9949ad1..9dad5fc 100644

arch/arm/include/asm/arch-mx5/sys_proto.h line 23

Quoted 7 lines
arch/arm/include/asm/arch-mx5/sys_proto.h +4 -0
@@ -17,6 +17,10 @@
 
  #define is_soc_rev(rev)	((get_cpu_rev() & 0xFF) - rev)
  u32 get_cpu_rev(void);
+
+/* returns MXC_CPU_ value */
+#define cpu_type(rev) (((rev) >> 12)&0xff)
+

There is already a get_cpu_type() for other architectures (OMAP). We do not need to reinvent the wheel this time, and it is correct to add get_cpu_type(void) to sys_proto.h.

Quoted 5 lines

This lets also easier to understand the code because it can be directly derived from the User's Manual: shifting 12 bit in your macro is only because this is done in get_cpu_rev(), not because this is the offset in the i.MX6 register.

Okay. I'll re-submit with get_cpu_type(void) implemented imx-common/cpu.c.

I still question the fact that we have two header files for i.MX5x and i.MX6x declaring the returns implemented there.

It seems that we should have a single header for routines implemented there.

Perhaps arch/arm/include/imx-common/cpu.h?

Please advise,

Eric

#5 lore raw

PATCH v3 1/5 i.MX5x: define cpu_type() to return processor portion of cpu rev.

Hi Eric,

Quoted 2 lines · Eric Nelson

I still question the fact that we have two header files for i.MX5x and i.MX6x declaring the returns implemented there.

Good point.

Quoted 5 lines

It seems that we should have a single header for routines implemented there.

Perhaps arch/arm/include/imx-common/cpu.h?

+1

Quoted 2 lines

Please advise,

Nice if you clean up also this point !

Best regards,
Stefano

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
#6 lore raw

PATCH v3 2/5 imx: Define common routines to set cpu and board environment variables

In reply to Eric Nelson

Defines two environment variables for use in producing DTB file names, among other uses:

imx_type: defines the CPU variant through the get_imx_type() routine
board_name: environment variable equivalent of CONFIG_SYS_BOARD_NAME

Both can be over-ridden by a user. This is expected to be most useful when transitioning to a custom board.

---
 arch/arm/imx-common/cpu.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)
arch/arm/imx-common/cpu.c +22 -2
index 0cd2538..7c434c7 100644
@@ -99,8 +99,6 @@ unsigned imx_ddr_size(void)
 }
 #endif
 
-#if defined(CONFIG_DISPLAY_CPUINFO)
-
 const char *get_imx_type(u32 imxtype)
 {
 	switch (imxtype) {
@@ -121,6 +119,28 @@ const char *get_imx_type(u32 imxtype)
 	}
 }
 
+#ifdef CONFIG_ARCH_MISC_INIT
+void __weak set_imx_type(void)
+{
+	setenv("imx_type", get_imx_type(cpu_type(get_cpu_rev())));
+}
+
+void __weak set_board_name(void)
+{
+	char *old = getenv("board_name");
+	if (!old)
+		setenv("board_name", CONFIG_SYS_BOARD);
+}
+
+int arch_misc_init(void)
+{
+	set_imx_type();
+	set_board_name();
+	return 0;
+}
+#endif
+
+#if defined(CONFIG_DISPLAY_CPUINFO)
 int print_cpuinfo(void)
 {
 	u32 cpurev;
Signature · 1 line
1.8.1.2
#7 lore raw

PATCH v3 3/5 i.MX6: nitrogen6x/sabrelite: override set_board_name()

In reply to Eric Nelson

Since the nitrogen6x board file auto-detects Nitrogen6x and SABRE Lite boards, override set_board_name to produce one of two values for board_name.

---
 board/boundary/nitrogen6x/nitrogen6x.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
board/boundary/nitrogen6x/nitrogen6x.c +13 -1
index 616ad55..aa9717a 100644
@@ -756,9 +756,14 @@ int board_init(void)
 	return 0;
 }
 
+static inline int is_n6x(void)
+{
+	return gpio_get_value(WL12XX_WL_IRQ_GP);
+}
+
 int checkboard(void)
 {
-	if (gpio_get_value(WL12XX_WL_IRQ_GP))
+	if (is_n6x())
 		puts("Board: Nitrogen6X\n");
 	else
 		puts("Board: SABRE Lite\n");
@@ -766,6 +771,13 @@ int checkboard(void)
 	return 0;
 }
 
+void set_board_name(void)
+{
+	char *old = getenv("board_name");
+	if (!old)
+		setenv("board_name", is_n6x() ? "nitrogen6x" : "sabrelite");
+}
+
 struct button_key {
 	char const	*name;
 	unsigned	gpnum;
Signature · 1 line
1.8.1.2
#8 lore raw

PATCH 3/5 i.MX6: nitrogen6x/sabrelite: override set_board_name()

Hi Eric,

Quoted 30 lines · Eric Nelson

Since the nitrogen6x board file auto-detects Nitrogen6x and SABRE Lite boards, override set_board_name to produce one of two values for board_name.

---
 board/boundary/nitrogen6x/nitrogen6x.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
board/boundary/nitrogen6x/nitrogen6x.c +6 -1
index 616ad55..aa9717a 100644
@@ -756,9 +756,14 @@ int board_init(void)
 	return 0;
 }
 
+static inline int is_n6x(void)
+{
+	return gpio_get_value(WL12XX_WL_IRQ_GP);
+}
+
 int checkboard(void)
 {
-	if (gpio_get_value(WL12XX_WL_IRQ_GP))
+	if (is_n6x())
 		puts("Board: Nitrogen6X\n");
 	else
 		puts("Board: SABRE Lite\n");

board/boundary/nitrogen6x/nitrogen6x.c int checkboard(void) · line 776

Quoted 6 lines
board/boundary/nitrogen6x/nitrogen6x.c +3 -0
@@ -766,6 +771,13 @@ int checkboard(void)
 	return 0;
 }
 
+void set_board_name(void)
+{
+	char *old = getenv("board_name");

Agree on the name: board_name was already introduced in u-boot.

board/boundary/nitrogen6x/nitrogen6x.c int checkboard(void) · line 778

Quoted 2 lines
board/boundary/nitrogen6x/nitrogen6x.c +2 -0
+	if (!old)
+		setenv("board_name", is_n6x() ? "nitrogen6x" : "sabrelite");

I have a major question: if it is possible to detect at runtime, as you have already implemented, which is the board where code is running, why is it possible to override it for the operator ? I agree that forcing environment variables inside code is bad, but in this case it is a hardware related stuff. It is like to the processor type or the serial-id of the processor (variable dieid# on OMAP). Overriding seems weird.

Best regards,
Stefano Babic

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
#9 lore raw

PATCH v3 3/5 i.MX6: nitrogen6x/sabrelite: override set_board_name()

Hi Stefano,

Quoted 42 lines · Stefano Babic

Hi Eric,

Quoted 30 lines · Eric Nelson

Since the nitrogen6x board file auto-detects Nitrogen6x and SABRE Lite boards, override set_board_name to produce one of two values for board_name.

---
  board/boundary/nitrogen6x/nitrogen6x.c | 14 +++++++++++++-
  1 file changed, 13 insertions(+), 1 deletion(-)
board/boundary/nitrogen6x/nitrogen6x.c +6 -1
index 616ad55..aa9717a 100644
@@ -756,9 +756,14 @@ int board_init(void)
  	return 0;
  }
 
+static inline int is_n6x(void)
+{
+	return gpio_get_value(WL12XX_WL_IRQ_GP);
+}
+
  int checkboard(void)
  {
-	if (gpio_get_value(WL12XX_WL_IRQ_GP))
+	if (is_n6x())
  		puts("Board: Nitrogen6X\n");
  	else
  		puts("Board: SABRE Lite\n");

board/boundary/nitrogen6x/nitrogen6x.c int checkboard(void) · line 776

Quoted 6 lines
board/boundary/nitrogen6x/nitrogen6x.c +3 -0
@@ -766,6 +771,13 @@ int checkboard(void)
  	return 0;
  }
 
+void set_board_name(void)user
+{
+	char *old = getenv("board_name");

Agree on the name: board_name was already introduced in u-boot.

Quoted 7 lines

board/boundary/nitrogen6x/nitrogen6x.c int checkboard(void) · line 778

Quoted 2 lines
board/boundary/nitrogen6x/nitrogen6x.c +2 -0
+	if (!old)
+		setenv("board_name", is_n6x() ? "nitrogen6x" : "sabrelite");

I have a major question: if it is possible to detect at runtime, as you have already implemented, which is the board where code is running, why is it possible to override it for the operator ?

First off, I want to clarify things. There are two levels of override possible here:
- weak functions can be over-ridden by board files
- environment variables can be overridden through saveenv()

The first is to allow auto-detection of a "board" as shown in nitrogen6x.c. I assume you're okay with that bit.

Quoted 5 lines

I agree that forcing environment variables inside code is bad, but in this case it is a hardware related stuff. It is like to the processor type or the serial-id of the processor (variable dieid# on OMAP). Overriding seems weird.

There is a reason for this, and it mostly involves custom pin-muxing.

All of our boards support a wide variety of peripherals, and we make assumptions about what the various connectors will be used for.

For instance, we define a particular connector for use as a parallel (RGB) display.

Lots of customers have other needs though, and through the magic of pin-muxing, they build their own "board" files in the kernel and use the parallel display pins for connecting SPI devices or additional I2C or RS-232 pins. Or simply as GPIOs.

The easiest, most maintainable way to do that is by cloning our board files and editing the pin muxes.

With the addition of device tree support, this becomes even easier.

So is it a different board? Maybe not, but it's useful to name things differently in the kernel tree so you can easily perform a diff against the original or boot to the original DTB for comparison.

SOM customers blur the lines even further, and it's not uncommon for someone to boot a different carrier with our stock U-Boot if the changes are minor or their needs are modest.

Re-reading the patch, it seems that there's no good reason to have set_imx_type(void) declared __weak.

Regards,

Eric

#10 lore raw

PATCH 3/5 i.MX6: nitrogen6x/sabrelite: override set_board_name()

Hi Eric,

Quoted 11 lines · Eric Nelson
Quoted 4 lines

I have a major question: if it is possible to detect at runtime, as you have already implemented, which is the board where code is running, why is it possible to override it for the operator ?

First off, I want to clarify things. There are two levels of override possible here:
- weak functions can be over-ridden by board files
- environment variables can be overridden through saveenv()

The first is to allow auto-detection of a "board" as shown in nitrogen6x.c. I assume you're okay with that bit.

Right.

Quoted 23 lines
Quoted 5 lines

I agree that forcing environment variables inside code is bad, but in this case it is a hardware related stuff. It is like to the processor type or the serial-id of the processor (variable dieid# on OMAP). Overriding seems weird.

There is a reason for this, and it mostly involves custom pin-muxing.

All of our boards support a wide variety of peripherals, and we make assumptions about what the various connectors will be used for.

For instance, we define a particular connector for use as a parallel (RGB) display.

Lots of customers have other needs though, and through the magic of pin-muxing, they build their own "board" files in the kernel and use the parallel display pins for connecting SPI devices or additional I2C or RS-232 pins. Or simply as GPIOs.

The easiest, most maintainable way to do that is by cloning our board files and editing the pin muxes.

With the addition of device tree support, this becomes even easier.

Quoted 7 lines

So is it a different board? Maybe not, but it's useful to name things differently in the kernel tree so you can easily perform a diff against the original or boot to the original DTB for comparison.

SOM customers blur the lines even further, and it's not uncommon for someone to boot a different carrier with our stock U-Boot if the changes are minor or their needs are modest.

ok, understood, thanks for clarification.

Quoted 3 lines

Re-reading the patch, it seems that there's no good reason to have set_imx_type(void) declared __weak.

Agree.

Best regards,
Stefano

Signature · 5 lines
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================
#11 lore raw

PATCH v3 4/5 i.MX6: nitrogen6x/sabrelite: initialize imx_type and board_name values

In reply to Eric Nelson

Use them to produce FDT file name in mx6qsabrelite_config.

---
 include/configs/nitrogen6x.h | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
include/configs/nitrogen6x.h +8 -1
index 3df8de0..361e69d 100644
@@ -188,7 +188,6 @@
 	"console=ttymxc1\0" \
 	"fdt_high=0xffffffff\0" \
 	"initrd_high=0xffffffff\0" \
-	"fdt_file=imx6q-sabrelite.dtb\0" \
 	"fdt_addr=0x11000000\0" \
 	"boot_fdt=try\0" \
 	"ip_dyn=yes\0" \
@@ -244,6 +243,12 @@
 		"fi;\0"
 
 #define CONFIG_BOOTCOMMAND \
+	   "if itest.s x6Q == x${imx_type}; then " \
+		"fdt_file=imx6q ; " \
+	   "else " \
+		"fdt_file=imx6dl ; " \
+	   "fi; " \
+	   "fdt_file=${fdt_file}-${board_name}.dtb;" \
 	   "mmc dev ${mmcdev}; if mmc rescan; then " \
 		   "if run loadbootscript; then " \
 			   "run bootscript; " \
@@ -361,4 +366,6 @@
 #define CONFIG_SUPPORT_RAW_INITRD
 #define CONFIG_CMD_FS_GENERIC
 
+#define CONFIG_ARCH_MISC_INIT
+
 #endif	       /* __CONFIG_H */
Signature · 1 line
1.8.1.2
#12 lore raw

PATCH v3 5/5 i.MX6: mx6*sabre*: initialize imx_type and board_name values

In reply to Eric Nelson

These will need to be computed if/when boards support multiple processor variants.

---
 include/configs/mx6sabre_common.h | 1 +
 1 file changed, 1 insertion(+)
include/configs/mx6sabre_common.h +1 -0
index 79d1f34..092b764 100644
@@ -27,6 +27,7 @@
 /* Size of malloc() pool */
 #define CONFIG_SYS_MALLOC_LEN		(10 * SZ_1M)
 
+#define CONFIG_ARCH_MISC_INIT
 #define CONFIG_BOARD_EARLY_INIT_F
 #define CONFIG_BOARD_LATE_INIT
 #define CONFIG_MXC_GPIO
Signature · 1 line
1.8.1.2