Skip to contentSkip to conversation

mx6sabresd: Fix U-Boot corruption after saving the environment

PATCH Applied Fabio Estevam 3 participants 11 messages Feb 2, 2024 – Feb 8, 2024

Subsystems (2)
lore
Share & tools
lore

Fabio Estevam

author reviewer
#0 lore raw

PATCH v2 1/3 mx6sabresd: Fix U-Boot corruption after saving the environment

From: Fabio Estevam <[email protected]>

U-Boot binary has grown in such a way that it goes beyond the reserved area for the environment variables.

Running "saveenv" and rebooting the board causes U-Boot to hang because of this overlap.

Fix this problem by selecting CONFIG_LTO so that the U-Boot proper size can be reduced.

Also, to prevent this same problem to happen in the future, use CONFIG_BOARD_SIZE_LIMIT, which can detect the overlap in build-time.

CONFIG_BOARD_SIZE_LIMIT is calculated as follows:

CONFIG_BOARD_SIZE_LIMIT = CONFIG_ENV_OFFSET - u-boot-img.dtb offset CONFIG_BOARD_SIZE_LIMIT = 0xc000 - 69 * 1024 CONFIG_BOARD_SIZE_LIMIT = 715766

---
Changes since v1:
- Select LTO. (Tom)

 configs/mx6sabresd_defconfig | 3 +++
 1 file changed, 3 insertions(+)
configs/mx6sabresd_defconfig +3 -0
index a90efe4a7786..d4fb55622cf1 100644
@@ -21,6 +21,9 @@ CONFIG_SPL_SERIAL=y
 CONFIG_SPL=y
 CONFIG_SPL_LIBDISK_SUPPORT=y
 CONFIG_PCI=y
+CONFIG_LTO=y
+CONFIG_HAS_BOARD_SIZE_LIMIT=y
+CONFIG_BOARD_SIZE_LIMIT=715766
 CONFIG_FIT=y
 CONFIG_SPL_FIT_PRINT=y
 CONFIG_SPL_LOAD_FIT=y
Signature · 1 line
2.34.1
author reviewer
#1 lore raw

PATCH v2 2/3 mx6sabresd: Convert to watchdog driver model

From: Fabio Estevam <[email protected]>

Commit 68dcbdd594d4 ("ARM: imx: Add weak default reset_cpu()") caused the 'reset' command in U-Boot to not cause a board reset.

Fix it by switching to the watchdog driver model via sysreset, which is the preferred method for implementing the watchdog reset.

---
Changes since v1:
- None.

 arch/arm/dts/imx6qdl-sabresd-u-boot.dtsi | 9 +++++++++
 configs/mx6sabresd_defconfig             | 3 +++
 2 files changed, 12 insertions(+)
arch/arm/dts/imx6qdl-sabresd-u-boot.dtsi +9 -0
index 5c4101b76da2..9e9c4422f00e 100644
@@ -9,6 +9,11 @@
 	aliases {
 		mmc1 = &usdhc3;
 	};
+	wdt-reboot {
+		compatible = "wdt-reboot";
+		wdt = <&wdog2>;
+		bootph-pre-ram;
+	};
 };
 
 &usdhc3 {
@@ -18,3 +23,7 @@
 &pinctrl_usdhc3 {
 	bootph-pre-ram;
 };
+
+&wdog2 {
+	bootph-pre-ram;
+};
configs/mx6sabresd_defconfig +3 -0
index f19df607e7ae..69685f12eb10 100644
@@ -103,6 +103,8 @@ CONFIG_DM_REGULATOR_FIXED=y
 CONFIG_DM_REGULATOR_GPIO=y
 CONFIG_DM_SERIAL=y
 CONFIG_MXC_UART=y
+CONFIG_SYSRESET=y
+CONFIG_SYSRESET_WATCHDOG=y
 CONFIG_SPI=y
 CONFIG_DM_SPI=y
 CONFIG_MXC_SPI=y
@@ -129,3 +131,4 @@ CONFIG_IMX_HDMI=y
 CONFIG_SPLASH_SCREEN=y
 CONFIG_SPLASH_SCREEN_ALIGN=y
 CONFIG_BMP_16BPP=y
+CONFIG_IMX_WATCHDOG=y
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v2 2/3] mx6sabresd: Convert to watchdog driver model

Quoted 34 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

Commit 68dcbdd594d4 ("ARM: imx: Add weak default reset_cpu()") caused the 'reset' command in U-Boot to not cause a board reset.

Fix it by switching to the watchdog driver model via sysreset, which is the preferred method for implementing the watchdog reset.

---
Changes since v1:
- None.

 arch/arm/dts/imx6qdl-sabresd-u-boot.dtsi | 9 +++++++++
 configs/mx6sabresd_defconfig             | 3 +++
 2 files changed, 12 insertions(+)
arch/arm/dts/imx6qdl-sabresd-u-boot.dtsi +5 -0
index 5c4101b76da2..9e9c4422f00e 100644
@@ -9,6 +9,11 @@
 	aliases {
 		mmc1 = &usdhc3;
 	};
+	wdt-reboot {
+		compatible = "wdt-reboot";
+		wdt = <&wdog2>;
+		bootph-pre-ram;
+	};
 };
 
 &usdhc3 {

arch/arm/dts/imx6qdl-sabresd-u-boot.dtsi line 29

Quoted 7 lines
arch/arm/dts/imx6qdl-sabresd-u-boot.dtsi +4 -0
@@ -18,3 +23,7 @@
 &pinctrl_usdhc3 {
 	bootph-pre-ram;
 };
+
+&wdog2 {
+	bootph-pre-ram;
+};

Can all of this be upstreamed as well?

Signature · 1 line
Tom
author reviewer
#3 lore raw

Re: [PATCH v2 2/3] mx6sabresd: Convert to watchdog driver model

Quoted 1 line · Tom Rini

Can all of this be upstreamed as well?

I can try it, but that would go into kernel 6.9 in the best case.

For now, let's keep it in u-boot.dtsi.

#4 lore raw

Re: [PATCH v2 2/3] mx6sabresd: Convert to watchdog driver model

Quoted 7 lines · Fabio Estevam
Quoted 1 line · Tom Rini

Can all of this be upstreamed as well?

I can try it, but that would go into kernel 6.9 in the best case.

For now, let's keep it in u-boot.dtsi.

Yes, sorry, I'm not saying don't do this here, but can you please submit it so that long term this can be converted to OF_UPSTREAM and also not have a -u-boot.dtsi potentially.

Signature · 1 line
Tom
author reviewer
#5 lore raw

PATCH v2 3/3 mx6sabresd: Remove board_phy_config()

In reply to Fabio Estevam

From: Fabio Estevam <[email protected]>

With Ethernet DM in place, there is no longer the need for having the board_phy_config() anymore.

Remove it.

Confirmed that TFTP transfer still works fine without board_phy_config().

---
Changes since v1:
- Newly introduced.

 board/freescale/mx6sabresd/mx6sabresd.c | 34 -------------------------
 1 file changed, 34 deletions(-)
board/freescale/mx6sabresd/mx6sabresd.c +0 -34
index b558a596dff8..bb066a5d36c3 100644
@@ -7,7 +7,6 @@
 
 #include <image.h>
 #include <init.h>
-#include <net.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/imx-regs.h>
 #include <asm/arch/iomux.h>
@@ -254,39 +253,6 @@ int board_mmc_init(struct bd_info *bis)
 }
 #endif
 
-static int ar8031_phy_fixup(struct phy_device *phydev)
-{
-	unsigned short val;
-
-	/* To enable AR8031 ouput a 125MHz clk from CLK_25M */
-	phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
-	phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
-	phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
-
-	val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
-	val &= 0xffe3;
-	val |= 0x18;
-	phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
-
-	/* introduce tx clock delay */
-	phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
-	val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
-	val |= 0x0100;
-	phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
-
-	return 0;
-}
-
-int board_phy_config(struct phy_device *phydev)
-{
-	ar8031_phy_fixup(phydev);
-
-	if (phydev->drv->config)
-		phydev->drv->config(phydev);
-
-	return 0;
-}
-
 #if defined(CONFIG_VIDEO_IPUV3)
 static void disable_lvds(struct display_info_t const *dev)
 {
Signature · 1 line
2.34.1
Reviewed-by on v2 3/3
#6 lore raw

Re: [PATCH v2 3/3] mx6sabresd: Remove board_phy_config()

Hello Fabio,

Quoted 71 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

With Ethernet DM in place, there is no longer the need for having the board_phy_config() anymore.

Remove it.

Confirmed that TFTP transfer still works fine without board_phy_config().

---
Changes since v1:
- Newly introduced.

 board/freescale/mx6sabresd/mx6sabresd.c | 34 -------------------------
 1 file changed, 34 deletions(-)
board/freescale/mx6sabresd/mx6sabresd.c +0 -35
index b558a596dff8..bb066a5d36c3 100644
@@ -7,7 +7,6 @@
 
 #include <image.h>
 #include <init.h>
-#include <net.h>
 #include <asm/arch/clock.h>
 #include <asm/arch/imx-regs.h>
 #include <asm/arch/iomux.h>
@@ -254,39 +253,6 @@ int board_mmc_init(struct bd_info *bis)
 }
 #endif
 
-static int ar8031_phy_fixup(struct phy_device *phydev)
-{
-       unsigned short val;
-
-       /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
-       phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
-       phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
-       phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
-
-       val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
-       val &= 0xffe3;
-       val |= 0x18;
-       phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
-
-       /* introduce tx clock delay */
-       phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
-       val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
-       val |= 0x0100;
-       phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
-
-       return 0;
-}
-
-int board_phy_config(struct phy_device *phydev)
-{
-       ar8031_phy_fixup(phydev);
-
-       if (phydev->drv->config)
-               phydev->drv->config(phydev);
-
-       return 0;
-}
-
 #if defined(CONFIG_VIDEO_IPUV3)
 static void disable_lvds(struct display_info_t const *dev)
 {
--
Quoted 2 lines

2.34.1

Signature · 6 lines
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk
Senior Software Engineer, Embedded & Security
E: [email protected]
W: www.foundries.io
Reviewed-by on v2 1/3
#7 lore raw
In reply to Fabio Estevam
Quoted 14 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

U-Boot binary has grown in such a way that it goes beyond the reserved area for the environment variables.

Running "saveenv" and rebooting the board causes U-Boot to hang because of this overlap.

Fix this problem by selecting CONFIG_LTO so that the U-Boot proper size can be reduced.

Also, to prevent this same problem to happen in the future, use CONFIG_BOARD_SIZE_LIMIT, which can detect the overlap in build-time.

Quoted 7 lines

CONFIG_BOARD_SIZE_LIMIT is calculated as follows:

CONFIG_BOARD_SIZE_LIMIT = CONFIG_ENV_OFFSET - u-boot-img.dtb offset CONFIG_BOARD_SIZE_LIMIT = 0xc000 - 69 * 1024 CONFIG_BOARD_SIZE_LIMIT = 715766

Thanks!

Signature · 1 line
Tom
Reviewed-by on v2 1/3
#8 lore raw
In reply to Fabio Estevam
Quoted 44 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

U-Boot binary has grown in such a way that it goes beyond the reserved area for the environment variables.

Running "saveenv" and rebooting the board causes U-Boot to hang because of this overlap.

Fix this problem by selecting CONFIG_LTO so that the U-Boot proper size can be reduced.

Also, to prevent this same problem to happen in the future, use CONFIG_BOARD_SIZE_LIMIT, which can detect the overlap in build-time.

CONFIG_BOARD_SIZE_LIMIT is calculated as follows:

CONFIG_BOARD_SIZE_LIMIT = CONFIG_ENV_OFFSET - u-boot-img.dtb offset CONFIG_BOARD_SIZE_LIMIT = 0xc000 - 69 * 1024 CONFIG_BOARD_SIZE_LIMIT = 715766

---
Changes since v1:
- Select LTO. (Tom)

 configs/mx6sabresd_defconfig | 3 +++
 1 file changed, 3 insertions(+)
configs/mx6sabresd_defconfig +3 -1
index a90efe4a7786..d4fb55622cf1 100644
@@ -21,6 +21,9 @@ CONFIG_SPL_SERIAL=y
 CONFIG_SPL=y
 CONFIG_SPL_LIBDISK_SUPPORT=y
 CONFIG_PCI=y
+CONFIG_LTO=y
+CONFIG_HAS_BOARD_SIZE_LIMIT=y
+CONFIG_BOARD_SIZE_LIMIT=715766
 CONFIG_FIT=y
 CONFIG_SPL_FIT_PRINT=y
 CONFIG_SPL_LOAD_FIT=y
--
Quoted 2 lines

2.34.1

btw, from my experience, the same issue will probably occur again in future, especially when the current U-Boot size is already close to the defined limit (yes, with this patch it will be reported during compile time, but still).

Have you considered adjusting the boot image layout instead (moving CONFIG_ENV_OFFSET, so unlikely
U-Boot image will overlap again) to tackle feature problems?

Signature · 6 lines
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk
Senior Software Engineer, Embedded & Security
E: [email protected]
W: www.foundries.io
#9 lore raw
Quoted 50 lines · Igor Opaniuk
Quoted 44 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

U-Boot binary has grown in such a way that it goes beyond the reserved area for the environment variables.

Running "saveenv" and rebooting the board causes U-Boot to hang because of this overlap.

Fix this problem by selecting CONFIG_LTO so that the U-Boot proper size can be reduced.

Also, to prevent this same problem to happen in the future, use CONFIG_BOARD_SIZE_LIMIT, which can detect the overlap in build-time.

CONFIG_BOARD_SIZE_LIMIT is calculated as follows:

CONFIG_BOARD_SIZE_LIMIT = CONFIG_ENV_OFFSET - u-boot-img.dtb offset CONFIG_BOARD_SIZE_LIMIT = 0xc000 - 69 * 1024 CONFIG_BOARD_SIZE_LIMIT = 715766

---
Changes since v1:
- Select LTO. (Tom)

 configs/mx6sabresd_defconfig | 3 +++
 1 file changed, 3 insertions(+)
configs/mx6sabresd_defconfig +3 -1
index a90efe4a7786..d4fb55622cf1 100644
@@ -21,6 +21,9 @@ CONFIG_SPL_SERIAL=y
 CONFIG_SPL=y
 CONFIG_SPL_LIBDISK_SUPPORT=y
 CONFIG_PCI=y
+CONFIG_LTO=y
+CONFIG_HAS_BOARD_SIZE_LIMIT=y
+CONFIG_BOARD_SIZE_LIMIT=715766
 CONFIG_FIT=y
 CONFIG_SPL_FIT_PRINT=y
 CONFIG_SPL_LOAD_FIT=y
--
Quoted 2 lines

2.34.1

Quoted 7 lines

btw, from my experience, the same issue will probably occur again in future, especially when the current U-Boot size is already close to the defined limit (yes, with this patch it will be reported during compile time, but still).

Have you considered adjusting the boot image layout instead (moving CONFIG_ENV_OFFSET, so unlikely
U-Boot image will overlap again) to tackle feature problems?

I've just checked the previous patch version, where
you addressed that exactly with CONFIG_ENV_OFFSET change and following suggestions/objections from Tom, so sorry for the noise :)

Quoted 8 lines

--
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk
Senior Software Engineer, Embedded & Security
E: [email protected]
W: www.foundries.io

Signature · 6 lines
Best regards - Freundliche Grüsse - Meilleures salutations

Igor Opaniuk
Senior Software Engineer, Embedded & Security
E: [email protected]
W: www.foundries.io
author reviewer Applied
#10 lore raw
In reply to Fabio Estevam
Quoted 15 lines · Fabio Estevam

From: Fabio Estevam <[email protected]>

U-Boot binary has grown in such a way that it goes beyond the reserved area for the environment variables.

Running "saveenv" and rebooting the board causes U-Boot to hang because of this overlap.

Fix this problem by selecting CONFIG_LTO so that the U-Boot proper size can be reduced.

Also, to prevent this same problem to happen in the future, use CONFIG_BOARD_SIZE_LIMIT, which can detect the overlap in build-time.

Quoted 7 lines

CONFIG_BOARD_SIZE_LIMIT is calculated as follows:

CONFIG_BOARD_SIZE_LIMIT = CONFIG_ENV_OFFSET - u-boot-img.dtb offset CONFIG_BOARD_SIZE_LIMIT = 0xc000 - 69 * 1024 CONFIG_BOARD_SIZE_LIMIT = 715766

Applied all, thanks.