[PATCH v3 08/17] board_f: Introduce board_setup_bdinfo_mem initcall

Ovidiu Panait ovidiu.panait at windriver.com
Mon Jul 20 16:13:58 CEST 2020


In most cases (arc, ppc, mips, sh, m68k) gd->bd->bi_memsize and
gd->bd->bi_memstart are populated in a similar fashion:

    bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
    bd->bi_memsize = gd->ram_size;

However, there is a special case in board/cadence/xtfpga/xtfpga.c that
populates those fields in a board specific manner:

    gd->bd->bi_memstart = PHYSADDR(CONFIG_SYS_SDRAM_BASE);
    gd->bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;

Due to this fact, a weak board-specific routine is introduced to take care
of this scenario. Also, move all assignments to bi_mem* fields to
setup_bdinfo initcall.

Use gd->ram_base to populate bi_memstart to avoid an ifdef.

Signed-off-by: Ovidiu Panait <ovidiu.panait at windriver.com>
---

 arch/arc/lib/cpu.c            |  2 --
 board/cadence/xtfpga/xtfpga.c |  7 ++++++-
 common/board_f.c              | 21 +++++++++++++++------
 include/init.h                | 12 ++++++++++++
 4 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/arch/arc/lib/cpu.c b/arch/arc/lib/cpu.c
index 27b5832a0c..ccb7e1b265 100644
--- a/arch/arc/lib/cpu.c
+++ b/arch/arc/lib/cpu.c
@@ -27,8 +27,6 @@ int arch_cpu_init(void)
 
 int arch_early_init_r(void)
 {
-	gd->bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;
-	gd->bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
 	return 0;
 }
 
diff --git a/board/cadence/xtfpga/xtfpga.c b/board/cadence/xtfpga/xtfpga.c
index 2869e5cf68..6f168f3f9f 100644
--- a/board/cadence/xtfpga/xtfpga.c
+++ b/board/cadence/xtfpga/xtfpga.c
@@ -49,7 +49,7 @@ int checkboard(void)
 	return 0;
 }
 
-int dram_init_banksize(void)
+int board_setup_bdinfo_mem(void)
 {
 	gd->bd->bi_memstart = PHYSADDR(CONFIG_SYS_SDRAM_BASE);
 	gd->bd->bi_memsize = CONFIG_SYS_SDRAM_SIZE;
@@ -57,6 +57,11 @@ int dram_init_banksize(void)
 	return 0;
 }
 
+int dram_init_banksize(void)
+{
+	return 0;
+}
+
 int board_postclk_init(void)
 {
 	/*
diff --git a/common/board_f.c b/common/board_f.c
index 4356431488..ac72096e3a 100644
--- a/common/board_f.c
+++ b/common/board_f.c
@@ -598,6 +598,19 @@ static int display_new_sp(void)
 	return 0;
 }
 
+__weak int board_setup_bdinfo_mem(void)
+{
+	struct bd_info *bd = gd->bd;
+
+	/*
+	 * Save local variables to board info struct
+	 */
+	bd->bi_memstart = gd->ram_base;  /* start of memory */
+	bd->bi_memsize = gd->ram_size;   /* size in bytes */
+
+	return 0;
+}
+
 __weak int arch_setup_bdinfo(void)
 {
 	return 0;
@@ -605,6 +618,8 @@ __weak int arch_setup_bdinfo(void)
 
 int setup_bdinfo(void)
 {
+	board_setup_bdinfo_mem();
+
 	return arch_setup_bdinfo();
 }
 
@@ -614,12 +629,6 @@ static int setup_board_part1(void)
 {
 	struct bd_info *bd = gd->bd;
 
-	/*
-	 * Save local variables to board info struct
-	 */
-	bd->bi_memstart = CONFIG_SYS_SDRAM_BASE;	/* start of memory */
-	bd->bi_memsize = gd->ram_size;			/* size in bytes */
-
 #ifdef CONFIG_SYS_SRAM_BASE
 	bd->bi_sramstart = CONFIG_SYS_SRAM_BASE;	/* start of SRAM */
 	bd->bi_sramsize = CONFIG_SYS_SRAM_SIZE;		/* size  of SRAM */
diff --git a/include/init.h b/include/init.h
index e9354e8fca..85c8f49095 100644
--- a/include/init.h
+++ b/include/init.h
@@ -141,6 +141,18 @@ int arch_reserve_stacks(void);
  */
 int arch_reserve_mmu(void);
 
+/**
+ * board_setup_bdinfo_mem() - Populate gd->bd->bi_mem* fields
+ *
+ * Board-specific routine for populating gd->bd->bi_mem* fields.
+ * It is called during the generic board init sequence in setup_bdinfo.
+ *
+ * If an implementation is not provided, the generic one will be used.
+ *
+ * Return: 0 if OK
+ */
+int board_setup_bdinfo_mem(void);
+
 /**
  * arch_setup_bdinfo() - Architecture dependent boardinfo setup
  *
-- 
2.17.1



More information about the U-Boot mailing list