Fix regression caused in Verdin boards by 42b3ee7fa524
cover Fix regression caused in Verdin boards by 42b3ee7fa524
Recently, I made a patch series [0] that added firewalls to K3 boards. This was merged. Francesco reported [1] that the series broke boot in Verdin boards. This issue occurred only in Verdin devices, and not in the other boards, due to dram_init() invoking get_ram_size() even at the A53 stage.
This patch attempts to fix the issue.
NOTE: I have *NOT* tested this. I don't have a Verdin board with me. I request Francesco to test this and please let us know if this works.
[0] https://lore.kernel.org/u-boot/[email protected]/
[1] https://lore.kernel.org/u-boot/20260209083855.GA9367@francesco-nb/
Suhaas Joshi (1):
board: toradex: Make A53 get RAM size from DT in K3 boards
board/toradex/verdin-am62/verdin-am62.c | 10 ++++++++++ board/toradex/verdin-am62p/verdin-am62p.c | 11 +++++++++++ 2 files changed, 21 insertions(+)
Signature · 1 line
2.34.1
PATCH 1/1 board: toradex: Make A53 get RAM size from DT in K3 boards
dram_init() is called by R5 SPL and U-Boot, both. It starts by computing the size of the RAM. In verdin-am62(p), it does so by calling get_ram_size(). This function computes the size of the RAM by writing over the RAM.
When R5 computes the size of the RAM, it does not update the DT with this size. As a result, when A53 invokes dram_init() again, it has to compute the size through get_ram_size() again.
Commit 13c54cf588d82 and 0c3a6f748c9 add firewall over ATF's and OPTEE's regions. This firewall is added during the R5 SPL stage of boot. So when A53 attempts to write over RAM in get_ram_size(), it writes over the protected region. Since A53 is a non-secure core, this is blocked by the firewall.
To fix this, do the following:
* Implement spl_perform_board_fixups() function for verdin-am62 and verdin-am62p. Make this function call fixup_memory_node(), which updates the DT.
* Add an if-block in dram_init(), to ensure that only R5 is able to call get_ram_size(), and that A53 reads this size from the DT.
--- board/toradex/verdin-am62/verdin-am62.c | 10 ++++++++++ board/toradex/verdin-am62p/verdin-am62p.c | 11 +++++++++++ 2 files changed, 21 insertions(+)
board/toradex/verdin-am62/verdin-am62.c +10 -0
@@ -24,6 +24,9 @@ DECLARE_GLOBAL_DATA_PTR;int dram_init (void ) { +if (!IS_ENABLED (CONFIG_CPU_V7R )) +return fdtdec_setup_mem_size_base (); + gd->ram_size =get_ram_size ((long *)CFG_SYS_SDRAM_BASE ,CFG_SYS_SDRAM_SIZE );if (gd->ram_size <SZ_512M )
@@ -103,6 +106,13 @@ int board_late_init(void)return 0 ; } +#if IS_ENABLED (CONFIG_XPL_BUILD ) +void spl_perform_board_fixups (struct spl_image_info *spl_image) +{ +fixup_memory_node (spl_image); +} +#endif +#define CTRLMMR_USB0_PHY_CTRL 0x43004008#define CTRLMMR_USB1_PHY_CTRL 0x43004018#define CORE_VOLTAGE 0x80000000
board/toradex/verdin-am62p/verdin-am62p.c +11 -0
@@ -18,6 +18,7 @@#include <k3-ddrss.h> #include <spl.h> #include <linux/sizes.h> +#include <mach/k3-ddr.h> #include "../common/tdx-cfg-block.h"
@@ -57,6 +58,9 @@ static void read_hw_cfg(void)int dram_init (void ) { +if (!IS_ENABLED (CONFIG_CPU_V7R )) +return fdtdec_setup_mem_size_base (); + gd->ram_size =get_ram_size ((long *)CFG_SYS_SDRAM_BASE ,CFG_SYS_SDRAM_SIZE );if (gd->ram_size <SZ_1G )
@@ -132,6 +136,13 @@ int board_late_init(void)return 0 ; } +#if IS_ENABLED (CONFIG_XPL_BUILD ) +void spl_perform_board_fixups (struct spl_image_info *spl_image) +{ +fixup_memory_node (spl_image); +} +#endif +#define MCU_CTRL_LFXOSC_32K_BYPASS_VAL BIT(4)void spl_board_init (void )
Signature · 1 line
2.34.1
Re: [PATCH 1/1] board: toradex: Make A53 get RAM size from DT in K3 boards
Hello Suhaas,
Quoted 23 lines · Suhaas Joshi
dram_init()is called by R5 SPL and U-Boot, both. It starts by computing the size of the RAM. In verdin-am62(p), it does so by callingget_ram_size(). This function computes the size of the RAM by writing over the RAM.When R5 computes the size of the RAM, it does not update the DT with this size. As a result, when A53 invokes
dram_init()again, it has to compute the size throughget_ram_size()again.Commit
13c54cf588d82and0c3a6f748c9add firewall over ATF's and OPTEE's regions. This firewall is added during the R5 SPL stage of boot. So when A53 attempts to write over RAM inget_ram_size(), it writes over the protected region. Since A53 is a non-secure core, this is blocked by the firewall.To fix this, do the following:
* Implementspl_perform_board_fixups()function for verdin-am62 and verdin-am62p. Make this function callfixup_memory_node(), which updates the DT.
* Add an if-block indram_init(), to ensure that only R5 is able to callget_ram_size(), and that A53 reads this size from the DT.
Quoted 1 line
Signed-off-by Suhaas Joshi <[email protected]>
I was able to test it on a verdin am62, with 1GB of RAM, and it works as expected. I also agree that get_ram_size() should be called only on the R5 SPL.
There is a small change that I would do however, please see the inline comment in the code.
Quoted 10 lines
--- board/toradex/verdin-am62/verdin-am62.c | 10 ++++++++++ board/toradex/verdin-am62p/verdin-am62p.c | 11 +++++++++++ 2 files changed, 21 insertions(+)board/toradex/verdin-am62/verdin-am62.c +0
-0
board/toradex/verdin-am62/verdin-am62.c DECLARE_GLOBAL_DATA_PTR; · line 28
Quoted 5 lines
board/toradex/verdin-am62/verdin-am62.c +2
-0@@ -24,6 +24,9 @@ DECLARE_GLOBAL_DATA_PTR;int dram_init (void ) { +if (!IS_ENABLED (CONFIG_CPU_V7R )) +return fdtdec_setup_mem_size_base ();
change this to
if (!IS_ENABLED(CONFIG_TARGET_VERDIN_AM62_R5) || !IS_ENABLED(CONFIG_SPL_BUILD))
this way is clear that we want the get_ram_size() only on R5 SPL. It will make the code and the intention more clear, with no changes on the generated code.
Quoted 13 lines
board/toradex/verdin-am62p/verdin-am62p.c +1
-0@@ -18,6 +18,7 @@#include <k3-ddrss.h> #include <spl.h> #include <linux/sizes.h> +#include <mach/k3-ddr.h> #include "../common/tdx-cfg-block.h"
board/toradex/verdin-am62p/verdin-am62p.c static void read_hw_cfg(void) · line 62
Quoted 5 lines
board/toradex/verdin-am62p/verdin-am62p.c +2
-0@@ -57,6 +58,9 @@ static void read_hw_cfg(void)int dram_init (void ) { +if (!IS_ENABLED (CONFIG_CPU_V7R )) +return fdtdec_setup_mem_size_base ();
same comment here
if (!IS_ENABLED(CONFIG_TARGET_VERDIN_AM62P_R5) || !IS_ENABLED(CONFIG_SPL_BUILD))
with these 2 small changes also add
Thanks for the support on solving this regression.
Francesco
Re: [PATCH 1/1] board: toradex: Make A53 get RAM size from DT in K3 boards
Quoted 83 lines · Francesco Dolcini
Hello Suhaas,
Quoted 23 lines · Suhaas Joshi
dram_init()is called by R5 SPL and U-Boot, both. It starts by computing the size of the RAM. In verdin-am62(p), it does so by callingget_ram_size(). This function computes the size of the RAM by writing over the RAM.When R5 computes the size of the RAM, it does not update the DT with this size. As a result, when A53 invokes
dram_init()again, it has to compute the size throughget_ram_size()again.Commit
13c54cf588d82and0c3a6f748c9add firewall over ATF's and OPTEE's regions. This firewall is added during the R5 SPL stage of boot. So when A53 attempts to write over RAM inget_ram_size(), it writes over the protected region. Since A53 is a non-secure core, this is blocked by the firewall.To fix this, do the following:
* Implementspl_perform_board_fixups()function for verdin-am62 and verdin-am62p. Make this function callfixup_memory_node(), which updates the DT.
* Add an if-block indram_init(), to ensure that only R5 is able to callget_ram_size(), and that A53 reads this size from the DT.Quoted 1 line
Signed-off-by Suhaas Joshi <[email protected]>I was able to test it on a verdin am62, with 1GB of RAM, and it works as expected. I also agree that
get_ram_size()should be called only on the R5 SPL.There is a small change that I would do however, please see the inline comment in the code.
Quoted 10 lines
--- board/toradex/verdin-am62/verdin-am62.c | 10 ++++++++++ board/toradex/verdin-am62p/verdin-am62p.c | 11 +++++++++++ 2 files changed, 21 insertions(+)board/toradex/verdin-am62/verdin-am62.c +0
-0board/toradex/verdin-am62/verdin-am62.c DECLARE_GLOBAL_DATA_PTR; · line 28
Quoted 5 lines
board/toradex/verdin-am62/verdin-am62.c +2
-0@@ -24,6 +24,9 @@ DECLARE_GLOBAL_DATA_PTR;int dram_init (void ) { +if (!IS_ENABLED (CONFIG_CPU_V7R )) +return fdtdec_setup_mem_size_base ();change this to
if (!IS_ENABLED(CONFIG_TARGET_VERDIN_AM62_R5) || !IS_ENABLED(CONFIG_SPL_BUILD))
this way is clear that we want the
get_ram_size()only on R5 SPL. It will make the code and the intention more clear, with no changes on the generated code.Quoted 13 lines
board/toradex/verdin-am62p/verdin-am62p.c +1
-0@@ -18,6 +18,7 @@#include <k3-ddrss.h> #include <spl.h> #include <linux/sizes.h> +#include <mach/k3-ddr.h> #include "../common/tdx-cfg-block.h" board/toradex/verdin-am62p/verdin-am62p.c static void read_hw_cfg(void) · line 62
Quoted 5 lines
board/toradex/verdin-am62p/verdin-am62p.c +2
-0@@ -57,6 +58,9 @@ static void read_hw_cfg(void)int dram_init (void ) { +if (!IS_ENABLED (CONFIG_CPU_V7R )) +return fdtdec_setup_mem_size_base ();same comment here
Quoted 5 lines
if (!IS_ENABLED(CONFIG_TARGET_VERDIN_AM62P_R5) || !IS_ENABLED(CONFIG_SPL_BUILD))
with these 2 small changes also add
Reviewed-by Francesco Dolcini <[email protected]>
Done, I have sent the v2:
https://lore.kernel.org/u-boot/[email protected]/T/#t
Do let me know if there are any other issues in v2. Thanks for testing this out.
Regards
Suhaas
Quoted 5 lines
Thanks for the support on solving this regression.
Francesco