Skip to contentSkip to conversation

board: toradex: misc cleanups

PATCH New Francesco Dolcini 1 participant 16 messages Nov 11

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

cover board: toradex: misc cleanups

From: Francesco Dolcini <[email protected]>

A small series with small and misc cleanups on Toradex boards (based on next)

Francesco Dolcini (15):
board: toradex: tdx-cfg-block: fix carrier config block buffer
over-read
board: toradex: smarc-imx8mp: fix always-false phandle check
board: toradex: aquila-am69: initialize ret in spl_board_init()
board: toradex: apalis_imx6: fix do_fuse argv[1] NULL deref
board: toradex: colibri_imx6: fix do_fuse argv[1] NULL deref
board: toradex: apalis-imx8: report detected SoC variant in board_name
board: toradex: colibri-imx8x: report detected SoC variant in
board_name
board: toradex: colibri_imx7: un-nest board_late_init from
CONFIG_USB_EHCI_MX7
configs: verdin-imx8mm: remove empty #if/#endif block
board: toradex: apalis_imx6: remove dead ldo_mode_set()
board: toradex: colibri_imx6: remove dead ldo_mode_set()
board: toradex: apalis_imx6: drop dead TDX_APALIS_IMX6_V1_0 Kconfig
option
board: toradex: common: fix stale #endif comments in tdx-common.c
board: toradex: apalis_imx6: fix stale #endif comment in
board_late_init()
configs: colibri_imx7: add missing defined() in EMMC #elif

 board/toradex/apalis-imx8/apalis-imx8.c     |  2 +-
 board/toradex/apalis_imx6/Kconfig           | 10 ----------
 board/toradex/apalis_imx6/apalis_imx6.c     | 10 +---------
 board/toradex/apalis_imx6/do_fuse.c         |  4 ++--
 board/toradex/aquila-am69/aquila-am69.c     |  2 +-
 board/toradex/colibri-imx8x/colibri-imx8x.c |  2 +-
 board/toradex/colibri_imx6/colibri_imx6.c   |  8 --------
 board/toradex/colibri_imx6/do_fuse.c        |  4 ++--
 board/toradex/colibri_imx7/colibri_imx7.c   |  3 +--
 board/toradex/common/tdx-cfg-block.c        |  2 +-
 board/toradex/common/tdx-common.c           |  4 ++--
 board/toradex/smarc-imx8mp/smarc-imx8mp.c   |  2 +-
 include/configs/colibri_imx7.h              |  2 +-
 include/configs/verdin-imx8mm.h             |  4 ----
 14 files changed, 14 insertions(+), 45 deletions(-)
Signature · 1 line
2.47.3
#1 lore raw

PATCH 1/15 board: toradex: tdx-cfg-block: fix carrier config block buffer over-read

From: Francesco Dolcini <[email protected]>

read_tdx_cfg_block_carrier() allocates config_block with size TDX_CFG_BLOCK_EXTRA_MAX_SIZE (64 bytes), but the tag-parsing loop bound-checks offset against TDX_CFG_BLOCK_MAX_SIZE, which is 512 on any board with the config block in MMC. A malformed/garbage carrier EEPROM can walk the loop well past the 64-byte allocation.

Use TDX_CFG_BLOCK_EXTRA_MAX_SIZE, matching the actual buffer size.

Fixes 0c6b5588ef4a ("toradex: tdx-cfg-block: add support for EEPROM")
---
 board/toradex/common/tdx-cfg-block.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/toradex/common/tdx-cfg-block.c +1 -1
index f01f3ea68f88..b55fde388a2d 100644
@@ -613,7 +613,7 @@ int read_tdx_cfg_block_carrier(void)
 	offset = 4;
 
 	while (offset + sizeof(struct toradex_tag) +
-	       sizeof(struct toradex_hw) < TDX_CFG_BLOCK_MAX_SIZE) {
+	       sizeof(struct toradex_hw) < TDX_CFG_BLOCK_EXTRA_MAX_SIZE) {
 		tag = (struct toradex_tag *)(config_block + offset);
 		offset += 4;
 		if (tag->id == TAG_INVALID)
Signature · 1 line
2.47.3
#2 lore raw

PATCH 2/15 board: toradex: smarc-imx8mp: fix always-false phandle check

In reply to Francesco Dolcini

From: Francesco Dolcini <[email protected]>

fdt_get_phandle() returns uint32_t and 0 on failure, so "phandle < 0" is never true. On a missing pinctrl phandle this fell through to fdt_setprop_u32(..., "pinctrl-0", 0), corrupting the DT instead of bailing out.

Fixes dde53eae88d6 ("board: toradex: add Toradex SMARC iMX8MP")
---
 board/toradex/smarc-imx8mp/smarc-imx8mp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/toradex/smarc-imx8mp/smarc-imx8mp.c +1 -1
index 38fb3d61f5bf..e3fab50f6424 100644
@@ -62,7 +62,7 @@ static void ft_board_assign_uart(void *blob)
 		return;
 
 	phandle = fdt_get_phandle(blob, pinctrl_offset);
-	if (phandle < 0)
+	if (!phandle)
 		return;
 
 	fdt_setprop_u32(blob, uart_offset, "pinctrl-0", phandle);
Signature · 1 line
2.47.3
#3 lore raw

PATCH 3/15 board: toradex: aquila-am69: initialize ret in spl_board_init()

In reply to Francesco Dolcini

From: Francesco Dolcini <[email protected]>

If CONFIG_ESM_K3 is disabled, ret is read uninitialized by the subsequent "IS_ENABLED(CONFIG_ESM_PMIC) && ret == 0" check, making whether ESM PMIC init runs depend on stack garbage.

Fixes 3f0528882c0d ("board: toradex: add aquila am69 support")
---
 board/toradex/aquila-am69/aquila-am69.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/toradex/aquila-am69/aquila-am69.c +1 -1
index 45fba1bbfe80..9c9962d3d7db 100644
@@ -204,7 +204,7 @@ int ft_board_setup(void *blob, struct bd_info *bd)
 void spl_board_init(void)
 {
 	struct udevice *dev;
-	int ret;
+	int ret = 0;
 
 	if (IS_ENABLED(CONFIG_ESM_K3)) {
 		const char * const esms[] = {"esm@700000", "esm@40800000", "esm@42080000"};
Signature · 1 line
2.47.3
#4 lore raw

PATCH 4/15 board: toradex: apalis_imx6: fix do_fuse argv[1] NULL deref

In reply to Francesco Dolcini

From: Francesco Dolcini <[email protected]>

argv[0] is the command name itself, so argv[1] is only valid once argc >= 2. Running "updt_fuse" with no arguments has argc == 1 but still dereferences argv[1] in strcmp(), reading past the argv array.

Fixes 592f4aed6db7 ("arm: imx: initial support for apalis imx6")
---
 board/toradex/apalis_imx6/do_fuse.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
board/toradex/apalis_imx6/do_fuse.c +2 -2
index 8721276bed83..411a6300e1cb 100644
@@ -54,10 +54,10 @@ int do_updt_fuse(struct cmd_tbl *cmdtp, int flag, int argc,
 {
 	unsigned val;
 	int ret;
-	int confirmed = argc >= 1 && !strcmp(argv[1], "-y");
+	int confirmed = argc >= 2 && !strcmp(argv[1], "-y");
 
 	/* can be used in scripts for command availability check */
-	if (argc >= 1 && !strcmp(argv[1], "-n"))
+	if (argc >= 2 && !strcmp(argv[1], "-n"))
 		return CMD_RET_SUCCESS;
 
 	/* boot cfg */
Signature · 1 line
2.47.3
#5 lore raw

PATCH 5/15 board: toradex: colibri_imx6: fix do_fuse argv[1] NULL deref

In reply to Francesco Dolcini

From: Francesco Dolcini <[email protected]>

argv[0] is the command name itself, so argv[1] is only valid once argc >= 2. Running "updt_fuse" with no arguments has argc == 1 but still dereferences argv[1] in strcmp(), reading past the argv array.

Fixes a02d517b0182 ("arm: imx: initial support for colibri imx6")
---
 board/toradex/colibri_imx6/do_fuse.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
board/toradex/colibri_imx6/do_fuse.c +2 -2
index 8721276bed83..411a6300e1cb 100644
@@ -54,10 +54,10 @@ int do_updt_fuse(struct cmd_tbl *cmdtp, int flag, int argc,
 {
 	unsigned val;
 	int ret;
-	int confirmed = argc >= 1 && !strcmp(argv[1], "-y");
+	int confirmed = argc >= 2 && !strcmp(argv[1], "-y");
 
 	/* can be used in scripts for command availability check */
-	if (argc >= 1 && !strcmp(argv[1], "-n"))
+	if (argc >= 2 && !strcmp(argv[1], "-n"))
 		return CMD_RET_SUCCESS;
 
 	/* boot cfg */
Signature · 1 line
2.47.3
#6 lore raw

PATCH 6/15 board: toradex: apalis-imx8: report detected SoC variant in board_name

In reply to Francesco Dolcini

From: Francesco Dolcini <[email protected]>

board_late_init() hardcoded "board_name" to "Apalis iMX8QM" even though select_dt_from_module_version() (called right after) already detects QP modules via is_imx8qp() and sets "soc" accordingly. board_name now matches the detected variant.

Fixes fe7b2b322ec4 ("apalis-imx8: implement pcb version and soc variant handling")
---
 board/toradex/apalis-imx8/apalis-imx8.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/toradex/apalis-imx8/apalis-imx8.c +1 -1
index ba0e05a5e39e..09223441fbb1 100644
@@ -361,7 +361,7 @@ int board_late_init(void)
 {
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 /* TODO move to common */
-	env_set("board_name", "Apalis iMX8QM");
+	env_set("board_name", is_imx8qp() ? "Apalis iMX8QP" : "Apalis iMX8QM");
 	env_set("board_rev", "v1.0");
 #endif
 
Signature · 1 line
2.47.3
#7 lore raw

PATCH 7/15 board: toradex: colibri-imx8x: report detected SoC variant in board_name

In reply to Francesco Dolcini

From: Francesco Dolcini <[email protected]>

board_late_init() hardcoded "board_name" to "Colibri iMX8QXP" even though select_dt_from_module_version() (called right after) already detects DX modules via is_imx8dx() and sets "soc" accordingly. board_name now matches the detected variant.

Fixes de666551b304 ("colibri-imx8x: construct fdtfile dynamically")
---
 board/toradex/colibri-imx8x/colibri-imx8x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/toradex/colibri-imx8x/colibri-imx8x.c +1 -1
index 0a86420700dd..f8cbdc33f28e 100644
@@ -141,7 +141,7 @@ int board_late_init(void)
 {
 #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
 /* TODO move to common */
-	env_set("board_name", "Colibri iMX8QXP");
+	env_set("board_name", is_imx8dx() ? "Colibri iMX8DX" : "Colibri iMX8QXP");
 	env_set("board_rev", "v1.0");
 #endif
 
Signature · 1 line
2.47.3
#8 lore raw

PATCH 8/15 board: toradex: colibri_imx7: un-nest board_late_init from CONFIG_USB_EHCI_MX7

In reply to Francesco Dolcini

From: Francesco Dolcini <[email protected]>

board_late_init() (USB recovery bootcmd and NAND/eMMC variant selection) was nested inside "#ifdef CONFIG_USB_EHCI_MX7", which guards the unrelated board_fix_fdt() USB quirk. CONFIG_USB_EHCI_MX7 defaults to y but is user-selectable, so disabling it silently dropped board_late_init() entirely.

Fixes 46307ef01e08 ("board: colibri_imx7: use SDP if USB serial downloader has been used")
---
 board/toradex/colibri_imx7/colibri_imx7.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
board/toradex/colibri_imx7/colibri_imx7.c +1 -2
index c63812bd966c..234d86dde609 100644
@@ -342,6 +342,7 @@ int board_fix_fdt(void *rw_fdt_blob)
 
 	return 0;
 }
+#endif /* CONFIG_USB_EHCI_MX7 */
 
 #if defined(CONFIG_BOARD_LATE_INIT)
 int board_late_init(void)
@@ -369,5 +370,3 @@ int board_late_init(void)
 	return 0;
 }
 #endif /* CONFIG_BOARD_LATE_INIT */
-
-#endif /* CONFIG_USB_EHCI_MX7 */
Signature · 1 line
2.47.3
#9 lore raw

PATCH 9/15 configs: verdin-imx8mm: remove empty #if/#endif block

In reply to Francesco Dolcini

From: Francesco Dolcini <[email protected]>

The CONFIG_ENV_IS_IN_MMC block has no content, only a comment; it has never contained any code since the file was introduced.

Fixes 7d080773347c ("Convert CONFIG_SYS_MMC_ENV_DEV et al to Kconfig")
---
 include/configs/verdin-imx8mm.h | 4 ----
 1 file changed, 4 deletions(-)
include/configs/verdin-imx8mm.h +0 -4
index c54383b886eb..c79df4ab46e6 100644
@@ -51,10 +51,6 @@
 #define CFG_SYS_INIT_RAM_ADDR        0x40000000
 #define CFG_SYS_INIT_RAM_SIZE        SZ_2M
 
-#if defined(CONFIG_ENV_IS_IN_MMC)
-/* Environment in eMMC, before config block at the end of 1st "boot sector" */
-#endif
-
 #define CFG_SYS_SDRAM_BASE           0x40000000
 
 /* SDRAM configuration */
Signature · 1 line
2.47.3
#10 lore raw

PATCH 10/15 board: toradex: apalis_imx6: remove dead ldo_mode_set()

In reply to Francesco Dolcini

From: Francesco Dolcini <[email protected]>

CONFIG_LDO_BYPASS_CHECK is never defined by any Kconfig/defconfig in the tree; it's leftover from the NXP freescale board template this file was copied from at initial import. The guarded stub has never been compiled in.

Fixes 592f4aed6db7 ("arm: imx: initial support for apalis imx6")
---
 board/toradex/apalis_imx6/apalis_imx6.c | 8 --------
 1 file changed, 8 deletions(-)
board/toradex/apalis_imx6/apalis_imx6.c +0 -8
index 542c7ba4608d..e0cc4498d8a9 100644
@@ -781,14 +781,6 @@ int misc_init_r(void)
 	return 0;
 }
 
-#ifdef CONFIG_LDO_BYPASS_CHECK
-/* TODO, use external pmic, for now always ldo_enable */
-void ldo_mode_set(int ldo_bypass)
-{
-	return;
-}
-#endif
-
 #ifdef CONFIG_XPL_BUILD
 #include <spl.h>
 #include <linux/libfdt.h>
Signature · 1 line
2.47.3
#11 lore raw

PATCH 11/15 board: toradex: colibri_imx6: remove dead ldo_mode_set()

In reply to Francesco Dolcini

From: Francesco Dolcini <[email protected]>

CONFIG_LDO_BYPASS_CHECK is never defined by any Kconfig/defconfig in the tree; it's leftover from the NXP freescale board template this file was copied from at initial import. The guarded stub has never been compiled in.

Fixes a02d517b0182 ("arm: imx: initial support for colibri imx6")
---
 board/toradex/colibri_imx6/colibri_imx6.c | 8 --------
 1 file changed, 8 deletions(-)
board/toradex/colibri_imx6/colibri_imx6.c +0 -8
index 69a3c5f3dfd6..9e736d178dc6 100644
@@ -700,14 +700,6 @@ int misc_init_r(void)
 	return 0;
 }
 
-#ifdef CONFIG_LDO_BYPASS_CHECK
-/* TODO, use external pmic, for now always ldo_enable */
-void ldo_mode_set(int ldo_bypass)
-{
-	return;
-}
-#endif
-
 #ifdef CONFIG_XPL_BUILD
 #include <spl.h>
 #include <linux/libfdt.h>
Signature · 1 line
2.47.3
#12 lore raw

PATCH 12/15 board: toradex: apalis_imx6: drop dead TDX_APALIS_IMX6_V1_0 Kconfig option

In reply to Francesco Dolcini

From: Francesco Dolcini <[email protected]>

All code reading CONFIG_TDX_APALIS_IMX6_V1_0 was removed when V1.0 HW support was dropped, but the Kconfig prompt itself was left behind. Enabling it currently has no effect at all.

Fixes 405c97fd1dc8 ("configs: tdx: apalis_imx6: drop hw v1.0 support")
---
 board/toradex/apalis_imx6/Kconfig | 10 ----------
 1 file changed, 10 deletions(-)
board/toradex/apalis_imx6/Kconfig +0 -10
index fc4cbe3323c7..8da291e59642 100644
@@ -39,16 +39,6 @@ config TDX_CMD_IMX_MFGR
 	  If executed on already fused modules it doesn't change any fuse setting.
 	default y
 
-config TDX_APALIS_IMX6_V1_0
-	bool "Apalis iMX6 V1.0 HW"
-	help
-	  Apalis iMX6 V1.0 HW has a different pinout for the UART.
-	  The UARTs must be used in DCE mode, RTS/CTS are swapped and
-	  thus unusable on standard carrier boards.
-	  This option configures DCE mode unconditionally. Whithout this
-	  option the config block stating V1.0 HW selects DCE mode,
-	  otherwise the UARTs are configuered in DTE mode.
-
 source "board/toradex/common/Kconfig"
 
 endif
Signature · 1 line
2.47.3
#13 lore raw

PATCH 13/15 board: toradex: common: fix stale #endif comments in tdx-common.c

In reply to Francesco Dolcini

From: Francesco Dolcini <[email protected]>

get_board_rev()/CONFIG_REVISION_TAG were renamed to get_board_revision()/CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG, but two trailing #endif comments still named the old macros.

Fixes 9774462e34fa ("arm: Disable ATAGs support")
---
 board/toradex/common/tdx-common.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
board/toradex/common/tdx-common.c +2 -2
index 2a8589f5e41c..5c0b5d0ef159 100644
@@ -46,7 +46,7 @@ u32 get_board_revision(void)
 		((tdx_hw_tag.ver_minor & 0xf) << 4) |
 		((tdx_hw_tag.ver_assembly & 0xf) + 0xa);
 }
-#endif /* CONFIG_TDX_CFG_BLOCK */
+#endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
 
 #ifdef CONFIG_SERIAL_TAG
 void get_board_serial(struct tag_serialnr *serialnr)
@@ -306,7 +306,7 @@ u32 get_board_revision(void)
 {
 	return 0;
 }
-#endif /* CONFIG_REVISION_TAG */
+#endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
 
 #ifdef CONFIG_SERIAL_TAG
 u32 get_board_serial(void)
Signature · 1 line
2.47.3
#14 lore raw

PATCH 14/15 board: toradex: apalis_imx6: fix stale #endif comment in board_late_init()

In reply to Francesco Dolcini

From: Francesco Dolcini <[email protected]>

The inner #endif at line 743 closes the
"#if defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)" block, not CONFIG_BOARD_LATE_INIT (which is closed further down, already correctly labeled). Introduced when two adjacent #endif's were collapsed into one while dropping V1.0 HW support.

Fixes 405c97fd1dc8 ("configs: tdx: apalis_imx6: drop hw v1.0 support")
---
 board/toradex/apalis_imx6/apalis_imx6.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
board/toradex/apalis_imx6/apalis_imx6.c +1 -1
index e0cc4498d8a9..faca55ef6e30 100644
@@ -740,7 +740,7 @@ int board_late_init(void)
 	rev = get_board_revision();
 	snprintf(env_str, ARRAY_SIZE(env_str), "%.4x", rev);
 	env_set("board_rev", env_str);
-#endif /* CONFIG_BOARD_LATE_INIT */
+#endif /* CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG */
 
 	if (IS_ENABLED(CONFIG_USB) && is_boot_from_usb()) {
 		env_set("bootdelay", "0");
Signature · 1 line
2.47.3
#15 lore raw

PATCH 15/15 configs: colibri_imx7: add missing defined() in EMMC #elif

In reply to Francesco Dolcini

From: Francesco Dolcini <[email protected]>

"#elif CONFIG_TARGET_COLIBRI_IMX7_EMMC" was missing defined(), unlike every other conditional on this symbol in the file. Harmless today since an undefined macro evaluates to 0 in a preprocessor expression, but inconsistent and -Wundef-unsafe.

Fixes a62c60610f51 ("colibri_imx7_emmc: add Colibri iMX7D 1GB (eMMC) module support")
---
 include/configs/colibri_imx7.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/configs/colibri_imx7.h +1 -1
index c340dfb11894..b6a0183494e9 100644
@@ -17,7 +17,7 @@
 #define CFG_SYS_FSL_ESDHC_ADDR	0
 #ifdef CONFIG_TARGET_COLIBRI_IMX7_NAND
 #define CFG_SYS_FSL_USDHC_NUM	1
-#elif CONFIG_TARGET_COLIBRI_IMX7_EMMC
+#elif defined(CONFIG_TARGET_COLIBRI_IMX7_EMMC)
 #define CFG_SYS_FSL_USDHC_NUM	2
 #endif
 
Signature · 1 line
2.47.3