]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: core: ofnode: Add ofnode_read_bootscript_address()
authorMichal Simek <michal.simek@amd.com>
Thu, 31 Aug 2023 06:59:05 +0000 (08:59 +0200)
committerMichal Simek <michal.simek@amd.com>
Thu, 21 Sep 2023 11:20:11 +0000 (13:20 +0200)
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>
Link: https://lore.kernel.org/r/23be3838502efef61803c90ef6e8b32bbd6ede41.1693465140.git.michal.simek@amd.com
arch/sandbox/dts/test.dts
drivers/core/ofnode.c
include/dm/ofnode.h
test/dm/ofnode.c

index e6a471e40d99723b433296c8a1f7f7001f499d02..d93c010bc5b41d359d2543763c227fd19a68aa14 100644 (file)
                };
        };
 
+       options {
+               u-boot {
+                       compatible = "u-boot,config";
+                       bootscr-ram-offset = /bits/ 64 <0x12345678>;
+               };
+       };
+
        bootstd {
                bootph-verify;
                compatible = "u-boot,boot-std";
index 8311282abf69331964d0891a4f291a71db6092de..5076054acd688ba5e5c48001bab9caeca4dbb349 100644 (file)
@@ -1593,6 +1593,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 */
index 0a85db31f3604ccbe608656768a6957eb346e5e1..c38596acbd057c04f7ab4bcbc30de05cb0d5fc3a 100644 (file)
@@ -20,6 +20,7 @@
 struct resource;
 
 #include <dm/ofnode_decl.h>
+#include <linux/errno.h>
 
 struct ofnode_phandle_args {
        ofnode node;
@@ -1512,6 +1513,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)
 {
@@ -1528,6 +1549,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 */
 
 /**
index b74f5c2ebcff3e91b5b3620bd01bf16a4a616e38..621a4b4fa3cf2e15ff3a6deeac8036e008785d55 100644 (file)
@@ -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";