[PATCH v2] xilinx: board: Add support to pick bootscr address from DT

From: Algapally Santosh Sagar santoshsagar.algapally@amd.com
The bootscript is expected at a default address specific to each platform. When high speed memory like Programmable Logic Double Data Rate RAM (PL DDR RAM) or Higher Bandwidth Memory RAM (HBM) is used the boot.scr may be loaded at a different offset. The offset needs to be set through setenv. Due to the default values in some cases the boot.scr is falling in between the kernel partition.
The bootscript address or the bootscript offset is fetched directly from the DT and updated in the environment making it easier for automated flows.
Signed-off-by: Algapally Santosh Sagar santoshsagar.algapally@amd.com Signed-off-by: Michal Simek michal.simek@amd.com ---
Changes in v2: - s/bootscr-offset-from-ram-start/bootscr-ram-offset/ - Aligned with https://github.com/devicetree-org/dt-schema/pull/105
board/xilinx/common/board.c | 43 ++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-)
diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c index 0328d68e7512..53c4264e794c 100644 --- a/board/xilinx/common/board.c +++ b/board/xilinx/common/board.c @@ -405,6 +405,31 @@ static int env_set_by_index(const char *name, int index, char *data) return env_set(var, data); }
+static int get_bootscript_address(u64 *bootscr_address, u64 *bootscr_offset) +{ + int ret; + ofnode uboot; + + *bootscr_address = 0; + *bootscr_offset = 0; + + uboot = ofnode_path("/options/u-boot"); + if (!ofnode_valid(uboot)) { + printf("%s: Missing /u-boot node\n", __func__); + return -EINVAL; + } + + ret = ofnode_read_u64(uboot, "bootscr-address", bootscr_address); + if (ret) { + ret = ofnode_read_u64(uboot, "bootscr-ram-offset", + bootscr_offset); + if (ret) + return -EINVAL; + } + + return 0; +} + int board_late_init_xilinx(void) { u32 ret = 0; @@ -414,9 +439,21 @@ int board_late_init_xilinx(void)
if (!IS_ENABLED(CONFIG_MICROBLAZE)) { ulong scriptaddr; - - scriptaddr = env_get_hex("scriptaddr", 0); - ret |= env_set_hex("scriptaddr", gd->ram_base + scriptaddr); + u64 bootscr_address; + u64 bootscr_offset; + + /* Fetch bootscr_address/bootscr_offset from DT and update */ + if (!get_bootscript_address(&bootscr_address, &bootscr_offset)) { + if (bootscr_offset) + ret |= env_set_hex("scriptaddr", + gd->ram_base + bootscr_offset); + else + ret |= env_set_hex("scriptaddr", bootscr_address); + } else { + /* Update scriptaddr(bootscr offset) from env */ + scriptaddr = env_get_hex("scriptaddr", 0); + ret |= env_set_hex("scriptaddr", gd->ram_base + scriptaddr); + } }
if (IS_ENABLED(CONFIG_ARCH_ZYNQ) || IS_ENABLED(CONFIG_MICROBLAZE))

Hi Michal,
On Thu, 13 Jul 2023 at 06:54, Michal Simek michal.simek@amd.com wrote:
From: Algapally Santosh Sagar santoshsagar.algapally@amd.com
The bootscript is expected at a default address specific to each platform. When high speed memory like Programmable Logic Double Data Rate RAM (PL DDR RAM) or Higher Bandwidth Memory RAM (HBM) is used the boot.scr may be loaded at a different offset. The offset needs to be set through setenv. Due to the default values in some cases the boot.scr is falling in between the kernel partition.
The bootscript address or the bootscript offset is fetched directly from the DT and updated in the environment making it easier for automated flows.
Signed-off-by: Algapally Santosh Sagar santoshsagar.algapally@amd.com Signed-off-by: Michal Simek michal.simek@amd.com
Changes in v2:
- s/bootscr-offset-from-ram-start/bootscr-ram-offset/
- Aligned with https://github.com/devicetree-org/dt-schema/pull/105
board/xilinx/common/board.c | 43 ++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-)
How about we start a new 'options' API in /common to read things from /options? You could have opt_bootscript_addr() as the first member?
diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c index 0328d68e7512..53c4264e794c 100644 --- a/board/xilinx/common/board.c +++ b/board/xilinx/common/board.c @@ -405,6 +405,31 @@ static int env_set_by_index(const char *name, int index, char *data) return env_set(var, data); }
+static int get_bootscript_address(u64 *bootscr_address, u64 *bootscr_offset) +{
int ret;
ofnode uboot;
*bootscr_address = 0;
*bootscr_offset = 0;
uboot = ofnode_path("/options/u-boot");
if (!ofnode_valid(uboot)) {
printf("%s: Missing /u-boot node\n", __func__);
return -EINVAL;
}
ret = ofnode_read_u64(uboot, "bootscr-address", bootscr_address);
if (ret) {
ret = ofnode_read_u64(uboot, "bootscr-ram-offset",
bootscr_offset);
if (ret)
return -EINVAL;
}
return 0;
+}
int board_late_init_xilinx(void) { u32 ret = 0; @@ -414,9 +439,21 @@ int board_late_init_xilinx(void)
if (!IS_ENABLED(CONFIG_MICROBLAZE)) { ulong scriptaddr;
scriptaddr = env_get_hex("scriptaddr", 0);
ret |= env_set_hex("scriptaddr", gd->ram_base + scriptaddr);
u64 bootscr_address;
u64 bootscr_offset;
/* Fetch bootscr_address/bootscr_offset from DT and update */
if (!get_bootscript_address(&bootscr_address, &bootscr_offset)) {
if (bootscr_offset)
ret |= env_set_hex("scriptaddr",
gd->ram_base + bootscr_offset);
else
ret |= env_set_hex("scriptaddr", bootscr_address);
} else {
/* Update scriptaddr(bootscr offset) from env */
scriptaddr = env_get_hex("scriptaddr", 0);
ret |= env_set_hex("scriptaddr", gd->ram_base + scriptaddr);
} } if (IS_ENABLED(CONFIG_ARCH_ZYNQ) || IS_ENABLED(CONFIG_MICROBLAZE))
-- 2.36.1
Regards, Simon

On 7/13/23 22:51, Simon Glass wrote:
Hi Michal,
On Thu, 13 Jul 2023 at 06:54, Michal Simek michal.simek@amd.com wrote:
From: Algapally Santosh Sagar santoshsagar.algapally@amd.com
The bootscript is expected at a default address specific to each platform. When high speed memory like Programmable Logic Double Data Rate RAM (PL DDR RAM) or Higher Bandwidth Memory RAM (HBM) is used the boot.scr may be loaded at a different offset. The offset needs to be set through setenv. Due to the default values in some cases the boot.scr is falling in between the kernel partition.
The bootscript address or the bootscript offset is fetched directly from the DT and updated in the environment making it easier for automated flows.
Signed-off-by: Algapally Santosh Sagar santoshsagar.algapally@amd.com Signed-off-by: Michal Simek michal.simek@amd.com
Changes in v2:
s/bootscr-offset-from-ram-start/bootscr-ram-offset/
Aligned with https://github.com/devicetree-org/dt-schema/pull/105
board/xilinx/common/board.c | 43 ++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-)
How about we start a new 'options' API in /common to read things from /options? You could have opt_bootscript_addr() as the first member?
Actually I was thinking if make sense to pretty much move this code to generic common location that it can be reused by others. Not sure if make sense to create new functions for all DT options properties because they should be read only once not multiple times. Or do you see the reason to call them multiple times?
Thanks, Michal

Hi Michal,
On Fri, 14 Jul 2023 at 00:19, Michal Simek michal.simek@amd.com wrote:
On 7/13/23 22:51, Simon Glass wrote:
Hi Michal,
On Thu, 13 Jul 2023 at 06:54, Michal Simek michal.simek@amd.com wrote:
From: Algapally Santosh Sagar santoshsagar.algapally@amd.com
The bootscript is expected at a default address specific to each platform. When high speed memory like Programmable Logic Double Data Rate RAM (PL DDR RAM) or Higher Bandwidth Memory RAM (HBM) is used the boot.scr may be loaded at a different offset. The offset needs to be set through setenv. Due to the default values in some cases the boot.scr is falling in between the kernel partition.
The bootscript address or the bootscript offset is fetched directly from the DT and updated in the environment making it easier for automated flows.
Signed-off-by: Algapally Santosh Sagar santoshsagar.algapally@amd.com Signed-off-by: Michal Simek michal.simek@amd.com
Changes in v2:
s/bootscr-offset-from-ram-start/bootscr-ram-offset/
Aligned with https://github.com/devicetree-org/dt-schema/pull/105
board/xilinx/common/board.c | 43 ++++++++++++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 3 deletions(-)
How about we start a new 'options' API in /common to read things from /options? You could have opt_bootscript_addr() as the first member?
Actually I was thinking if make sense to pretty much move this code to generic common location that it can be reused by others. Not sure if make sense to create new functions for all DT options properties because they should be read only once not multiple times. Or do you see the reason to call them multiple times?
Well they will appear in the source code in different places, I suspect, since different boards will call them, from different places. Also that makes it easier to add a test to test/dm/opt.c or whatever.
Regards, Simon
participants (2)
-
Michal Simek
-
Simon Glass