[PATCH v5 1/2] dm: core: ofnode: Add ofnode_read_bootscript_address()

ofnode_read_bootscript_address() reads bootscript address from /options/u-boot DT node. bootscr-address or bootscr-ram-offset properties are read and values are filled. bootscr-address has higher priority than bootscr-ram-offset and the only one should be described in DT.
Also add test to cover this new function.
Reviewed-by: Simon Glass sjg@chromium.org Signed-off-by: Michal Simek michal.simek@amd.com ---
Changes in v5: - CI loop found some issues. Missing errno.h, multiple ofnode_read_bootscript_address() because of missing static inline for !DM cases
Changes in v4: - Update ofnode test based on review from Simon
Changes in v3: - new patch in this series
arch/sandbox/dts/test.dts | 7 +++++++ drivers/core/ofnode.c | 25 +++++++++++++++++++++++++ include/dm/ofnode.h | 26 ++++++++++++++++++++++++++ test/dm/ofnode.c | 14 ++++++++++++++ 4 files changed, 72 insertions(+)
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index f351d5cb84b0..84879cc31ac0 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -79,6 +79,13 @@ }; };
+ options { + u-boot { + compatible = "u-boot,config"; + bootscr-ram-offset = /bits/ 64 <0x12345678>; + }; + }; + bootstd { bootph-verify; compatible = "u-boot,boot-std"; diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 8df16e56af5c..d94f0300c30a 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -1563,6 +1563,31 @@ const char *ofnode_conf_read_str(const char *prop_name) return ofnode_read_string(node, prop_name); }
+int ofnode_read_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; +} + ofnode ofnode_get_phy_node(ofnode node) { /* DT node properties that reference a PHY node */ diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 0f38b3e736de..c1afa69e1c56 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -20,6 +20,7 @@ struct resource;
#include <dm/ofnode_decl.h> +#include <linux/errno.h>
struct ofnode_phandle_args { ofnode node; @@ -1500,6 +1501,26 @@ int ofnode_conf_read_int(const char *prop_name, int default_val); */ const char *ofnode_conf_read_str(const char *prop_name);
+/** + * ofnode_read_bootscript_address() - Read bootscr-address or bootscr-ram-offset + * + * @bootscr_address: pointer to 64bit address where bootscr-address property value + * is stored + * @bootscr_offset: pointer to 64bit offset address where bootscr-ram-offset + * property value is stored + * + * This reads a bootscr-address or bootscr-ram-offset property from + * the /options/u-boot/ node of the devicetree. bootscr-address holds the full + * address of the boot script file. bootscr-ram-offset holds the boot script + * file offset from the start of the ram base address. When bootscr-address is + * defined, bootscr-ram-offset property is ignored. + * + * This only works with the control FDT. + * + * Return: 0 if OK, -EINVAL if property is not found. + */ +int ofnode_read_bootscript_address(u64 *bootscr_address, u64 *bootscr_offset); + #else /* CONFIG_DM */ static inline bool ofnode_conf_read_bool(const char *prop_name) { @@ -1516,6 +1537,11 @@ static inline const char *ofnode_conf_read_str(const char *prop_name) return NULL; }
+static inline int ofnode_read_bootscript_address(u64 *bootscr_address, u64 *bootscr_offset) +{ + return -EINVAL; +} + #endif /* CONFIG_DM */
/** diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 6fbebc7da085..a4e04f23784f 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -583,6 +583,20 @@ static int dm_test_ofnode_conf(struct unit_test_state *uts) } DM_TEST(dm_test_ofnode_conf, 0);
+static int dm_test_ofnode_options(struct unit_test_state *uts) +{ + u64 bootscr_address; + u64 bootscr_offset; + + ut_assertok(ofnode_read_bootscript_address(&bootscr_address, + &bootscr_offset)); + ut_asserteq_64(0, bootscr_address); + ut_asserteq_64(0x12345678, bootscr_offset); + + return 0; +} +DM_TEST(dm_test_ofnode_options, 0); + static int dm_test_ofnode_for_each_compatible_node(struct unit_test_state *uts) { const char compatible[] = "denx,u-boot-fdt-test";

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 ---
(no changes since v3)
Changes in v3: - Rename get_bootscript_address() to ofnode_read_bootscript_address() and move it to common location - Fix alignments
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 | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/board/xilinx/common/board.c b/board/xilinx/common/board.c index 906d5e3c2d7c..b3fb6acc25a3 100644 --- a/board/xilinx/common/board.c +++ b/board/xilinx/common/board.c @@ -414,9 +414,25 @@ 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 (!ofnode_read_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))

On 8/31/23 08:59, Michal Simek wrote:
ofnode_read_bootscript_address() reads bootscript address from /options/u-boot DT node. bootscr-address or bootscr-ram-offset properties are read and values are filled. bootscr-address has higher priority than bootscr-ram-offset and the only one should be described in DT.
Also add test to cover this new function.
Reviewed-by: Simon Glass sjg@chromium.org Signed-off-by: Michal Simek michal.simek@amd.com
Changes in v5:
- CI loop found some issues. Missing errno.h, multiple ofnode_read_bootscript_address() because of missing static inline for !DM cases
Changes in v4:
- Update ofnode test based on review from Simon
Changes in v3:
new patch in this series
arch/sandbox/dts/test.dts | 7 +++++++ drivers/core/ofnode.c | 25 +++++++++++++++++++++++++ include/dm/ofnode.h | 26 ++++++++++++++++++++++++++ test/dm/ofnode.c | 14 ++++++++++++++ 4 files changed, 72 insertions(+)
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index f351d5cb84b0..84879cc31ac0 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -79,6 +79,13 @@ }; };
- options {
u-boot {
compatible = "u-boot,config";
bootscr-ram-offset = /bits/ 64 <0x12345678>;
};
- };
- bootstd { bootph-verify; compatible = "u-boot,boot-std";
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 8df16e56af5c..d94f0300c30a 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -1563,6 +1563,31 @@ const char *ofnode_conf_read_str(const char *prop_name) return ofnode_read_string(node, prop_name); }
+int ofnode_read_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;
+}
- ofnode ofnode_get_phy_node(ofnode node) { /* DT node properties that reference a PHY node */
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 0f38b3e736de..c1afa69e1c56 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -20,6 +20,7 @@ struct resource;
#include <dm/ofnode_decl.h> +#include <linux/errno.h>
struct ofnode_phandle_args { ofnode node; @@ -1500,6 +1501,26 @@ int ofnode_conf_read_int(const char *prop_name, int default_val); */ const char *ofnode_conf_read_str(const char *prop_name);
+/**
- ofnode_read_bootscript_address() - Read bootscr-address or bootscr-ram-offset
- @bootscr_address: pointer to 64bit address where bootscr-address property value
- is stored
- @bootscr_offset: pointer to 64bit offset address where bootscr-ram-offset
- property value is stored
- This reads a bootscr-address or bootscr-ram-offset property from
- the /options/u-boot/ node of the devicetree. bootscr-address holds the full
- address of the boot script file. bootscr-ram-offset holds the boot script
- file offset from the start of the ram base address. When bootscr-address is
- defined, bootscr-ram-offset property is ignored.
- This only works with the control FDT.
- Return: 0 if OK, -EINVAL if property is not found.
- */
+int ofnode_read_bootscript_address(u64 *bootscr_address, u64 *bootscr_offset);
- #else /* CONFIG_DM */ static inline bool ofnode_conf_read_bool(const char *prop_name) {
@@ -1516,6 +1537,11 @@ static inline const char *ofnode_conf_read_str(const char *prop_name) return NULL; }
+static inline int ofnode_read_bootscript_address(u64 *bootscr_address, u64 *bootscr_offset) +{
- return -EINVAL;
+}
#endif /* CONFIG_DM */
/**
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c index 6fbebc7da085..a4e04f23784f 100644 --- a/test/dm/ofnode.c +++ b/test/dm/ofnode.c @@ -583,6 +583,20 @@ static int dm_test_ofnode_conf(struct unit_test_state *uts) } DM_TEST(dm_test_ofnode_conf, 0);
+static int dm_test_ofnode_options(struct unit_test_state *uts) +{
- u64 bootscr_address;
- u64 bootscr_offset;
- ut_assertok(ofnode_read_bootscript_address(&bootscr_address,
&bootscr_offset));
- ut_asserteq_64(0, bootscr_address);
- ut_asserteq_64(0x12345678, bootscr_offset);
- return 0;
+} +DM_TEST(dm_test_ofnode_options, 0);
- static int dm_test_ofnode_for_each_compatible_node(struct unit_test_state *uts) { const char compatible[] = "denx,u-boot-fdt-test";
Applied. M
participants (1)
-
Michal Simek