]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: core: ofnode: Add ofnode_read_bootscript_flash()
authorMichal Simek <michal.simek@amd.com>
Thu, 31 Aug 2023 07:04:27 +0000 (09:04 +0200)
committerMichal Simek <michal.simek@amd.com>
Thu, 21 Sep 2023 11:20:11 +0000 (13:20 +0200)
ofnode_read_bootscript_flash() reads bootscript address from
/options/u-boot DT node. bootscr-flash-offset and bootscr-flash-size
properties are read and values are filled. When bootscr-flash-size is not
defined, bootscr-flash-offset property is unusable that's why cleaned.
Both of these properties should be defined to function properly.

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/08a3e6c09cce13287c69ad370e409e7f1766b406.1693465465.git.michal.simek@amd.com
arch/sandbox/dts/test.dts
drivers/core/ofnode.c
include/dm/ofnode.h
test/dm/ofnode.c

index d93c010bc5b41d359d2543763c227fd19a68aa14..9a863ea732ffdc728cbff6914e61776d978f89a6 100644 (file)
@@ -85,6 +85,8 @@
                u-boot {
                        compatible = "u-boot,config";
                        bootscr-ram-offset = /bits/ 64 <0x12345678>;
+                       bootscr-flash-offset = /bits/ 64 <0>;
+                       bootscr-flash-size = /bits/ 64 <0x2000>;
                };
        };
 
index 5076054acd688ba5e5c48001bab9caeca4dbb349..fb4447c84b7008829ec3bf09f22565c45602d10b 100644 (file)
@@ -1618,6 +1618,40 @@ int ofnode_read_bootscript_address(u64 *bootscr_address, u64 *bootscr_offset)
        return 0;
 }
 
+int ofnode_read_bootscript_flash(u64 *bootscr_flash_offset,
+                                u64 *bootscr_flash_size)
+{
+       int ret;
+       ofnode uboot;
+
+       *bootscr_flash_offset = 0;
+       *bootscr_flash_size = 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-flash-offset",
+                             bootscr_flash_offset);
+       if (ret)
+               return -EINVAL;
+
+       ret = ofnode_read_u64(uboot, "bootscr-flash-size",
+                             bootscr_flash_size);
+       if (ret)
+               return -EINVAL;
+
+       if (!bootscr_flash_size) {
+               debug("bootscr-flash-size is zero. Ignoring properties!\n");
+               *bootscr_flash_offset = 0;
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 ofnode ofnode_get_phy_node(ofnode node)
 {
        /* DT node properties that reference a PHY node */
index c38596acbd057c04f7ab4bcbc30de05cb0d5fc3a..06ea68e81c57142db211b1e24c2384b6045a35e6 100644 (file)
@@ -1533,6 +1533,27 @@ const char *ofnode_conf_read_str(const char *prop_name);
  */
 int ofnode_read_bootscript_address(u64 *bootscr_address, u64 *bootscr_offset);
 
+/**
+ * ofnode_read_bootscript_flash() - Read bootscr-flash-offset/size
+ *
+ * @bootscr_flash_offset: pointer to 64bit offset where bootscr-flash-offset
+ * property value is stored
+ * @bootscr_flash_size: pointer to 64bit size where bootscr-flash-size property
+ * value is stored
+ *
+ * This reads a bootscr-flash-offset and bootscr-flash-size properties from
+ * the /options/u-boot/ node of the devicetree. bootscr-flash-offset holds
+ * the offset of the boot script file from start of flash. bootscr-flash-size
+ * holds the boot script size in flash. When bootscr-flash-size is not defined,
+ * bootscr-flash-offset property is cleaned.
+ *
+ * This only works with the control FDT.
+ *
+ * Return: 0 if OK, -EINVAL if property is not found or incorrect.
+ */
+int ofnode_read_bootscript_flash(u64 *bootscr_flash_offset,
+                                u64 *bootscr_flash_size);
+
 #else /* CONFIG_DM */
 static inline bool ofnode_conf_read_bool(const char *prop_name)
 {
@@ -1554,6 +1575,12 @@ static inline int ofnode_read_bootscript_address(u64 *bootscr_address, u64 *boot
        return -EINVAL;
 }
 
+static inline int ofnode_read_bootscript_flash(u64 *bootscr_flash_offset,
+                                              u64 *bootscr_flash_size)
+{
+       return -EINVAL;
+}
+
 #endif /* CONFIG_DM */
 
 /**
index 621a4b4fa3cf2e15ff3a6deeac8036e008785d55..d71faac0ee4381532e561c1f47d0465dc70bc20a 100644 (file)
@@ -585,14 +585,19 @@ DM_TEST(dm_test_ofnode_conf, 0);
 
 static int dm_test_ofnode_options(struct unit_test_state *uts)
 {
-       u64 bootscr_address;
-       u64 bootscr_offset;
+       u64 bootscr_address, bootscr_offset;
+       u64 bootscr_flash_offset, bootscr_flash_size;
 
        ut_assertok(ofnode_read_bootscript_address(&bootscr_address,
                                                   &bootscr_offset));
        ut_asserteq_64(0, bootscr_address);
        ut_asserteq_64(0x12345678, bootscr_offset);
 
+       ut_assertok(ofnode_read_bootscript_flash(&bootscr_flash_offset,
+                                                &bootscr_flash_size));
+       ut_asserteq_64(0, bootscr_flash_offset);
+       ut_asserteq_64(0x2000, bootscr_flash_size);
+
        return 0;
 }
 DM_TEST(dm_test_ofnode_options, 0);