The SPL board_init_r() of these boards points its gd parameter, which
shadows the global gd, at CONFIG_VAL(GD_ADDR), clears that area and
stores bd, the full malloc flag and, in the NAND TPLs, the location of
the loaded environment there. The SPL keeps running on the global data
that cpu_init_early_f() set up in the initial RAM, so nothing reads
this copy.

The next patch makes gd LTO safe, and gd can then no longer be the name
of a parameter. Drop the copy and the stores to it instead of moving
the global data to CONFIG_VAL(GD_ADDR): on the P1/P2 RDB SD card SPLs
that address is 4 KiB below the stack top, and the 8 KiB environment
buffer of env_mmc_load_singular() would overwrite it.

No functional change: the SPLs and TPLs lose only the stores to the
copy.

Tested on CZ.NIC Turris 1.1 (SD boot, with the LTO build of this
series).

Signed-off-by: Josef Schlehofer <[email protected]>
Reviewed-by: Marek Mojík <[email protected]>
Cc: Priyanka Jain <[email protected]>
Cc: Qiang Zhao <[email protected]>
Cc: Peng Fan <[email protected]>
Cc: Marek Behún <[email protected]>
Cc: Marek Mojík <[email protected]>
---
(no changes since v1)
---
 board/nxp/p1010rdb/spl.c     | 9 +--------
 board/nxp/p1_p2_rdb_pc/spl.c | 9 +--------
 2 files changed, 2 insertions(+), 16 deletions(-)

diff --git a/board/nxp/p1010rdb/spl.c b/board/nxp/p1010rdb/spl.c
index fc26cef2cc8..7c36026a55a 100644
--- a/board/nxp/p1010rdb/spl.c
+++ b/board/nxp/p1010rdb/spl.c
@@ -60,22 +60,17 @@ void board_init_f(ulong bootflag)
        relocate_code(CONFIG_VAL(RELOC_STACK), 0, CONFIG_SPL_RELOC_TEXT_BASE);
 }
 
-void board_init_r(gd_t *gd, ulong dest_addr)
+void board_init_r(gd_t *dummy, ulong dest_addr)
 {
-       /* Pointer is writable since we allocated a register for it */
-       gd = (gd_t *)CONFIG_VAL(GD_ADDR);
        struct bd_info *bd;
 
-       memset(gd, 0, sizeof(gd_t));
        bd = (struct bd_info *)(CONFIG_VAL(GD_ADDR) + sizeof(gd_t));
        memset(bd, 0, sizeof(struct bd_info));
-       gd->bd = bd;
 
        arch_cpu_init();
        get_clocks();
        mem_malloc_init(CONFIG_VAL(RELOC_MALLOC_ADDR),
                        CONFIG_VAL(RELOC_MALLOC_SIZE));
-       gd->flags |= GD_FLG_FULL_MALLOC_INIT;
 
 #ifndef CONFIG_SPL_NAND_BOOT
        env_init();
@@ -88,8 +83,6 @@ void board_init_r(gd_t *gd, ulong dest_addr)
 #ifdef CONFIG_SPL_NAND_BOOT
        nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
                            (uchar *)SPL_ENV_ADDR);
-                           gd->env_addr  = (ulong)(SPL_ENV_ADDR);
-       gd->env_valid = ENV_VALID;
 #else
        env_relocate();
 #endif
diff --git a/board/nxp/p1_p2_rdb_pc/spl.c b/board/nxp/p1_p2_rdb_pc/spl.c
index b07f481fbf9..6db77682e3c 100644
--- a/board/nxp/p1_p2_rdb_pc/spl.c
+++ b/board/nxp/p1_p2_rdb_pc/spl.c
@@ -72,22 +72,17 @@ void board_init_f(ulong bootflag)
        relocate_code(CONFIG_VAL(RELOC_STACK), 0, CONFIG_SPL_RELOC_TEXT_BASE);
 }
 
-void board_init_r(gd_t *gd, ulong dest_addr)
+void board_init_r(gd_t *dummy, ulong dest_addr)
 {
-       /* Pointer is writable since we allocated a register for it */
-       gd = (gd_t *)CONFIG_VAL(GD_ADDR);
        struct bd_info *bd;
 
-       memset(gd, 0, sizeof(gd_t));
        bd = (struct bd_info *)(CONFIG_VAL(GD_ADDR) + sizeof(gd_t));
        memset(bd, 0, sizeof(struct bd_info));
-       gd->bd = bd;
 
        arch_cpu_init();
        get_clocks();
        mem_malloc_init(CONFIG_VAL(RELOC_MALLOC_ADDR),
                        CONFIG_VAL(RELOC_MALLOC_SIZE));
-       gd->flags |= GD_FLG_FULL_MALLOC_INIT;
 
 #ifdef CONFIG_SPL_ENV_SUPPORT
 #ifndef CONFIG_SPL_NAND_BOOT
@@ -102,8 +97,6 @@ void board_init_r(gd_t *gd, ulong dest_addr)
 #ifdef CONFIG_SPL_NAND_BOOT
        nand_spl_load_image(CONFIG_ENV_OFFSET, CONFIG_ENV_SIZE,
                            (uchar *)SPL_ENV_ADDR);
-       gd->env_addr  = (ulong)(SPL_ENV_ADDR);
-       gd->env_valid = ENV_VALID;
 #else
        env_relocate();
 #endif
-- 
2.54.0 (Apple Git-157)

Reply via email to