From d7a92e9cb22497562b1632aebc0d625b17bbfd51 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 26 Jul 2023 09:59:52 +0300 Subject: fdt: off by one in ofnode_lookup_fdt() The "oftree_count" is the number of entries which have been set in the oftree_list[] array. If all the entries have been initialized then this off by one would result in reading one element beyond the end of the array. Signed-off-by: Dan Carpenter Reviewed-by: Simon Glass --- drivers/core/ofnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/core/ofnode.c') diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 8df16e56af5..a4dc9bde085 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -103,7 +103,7 @@ void *ofnode_lookup_fdt(ofnode node) if (gd->flags & GD_FLG_RELOC) { uint i = OFTREE_TREE_ID(node.of_offset); - if (i > oftree_count) { + if (i >= oftree_count) { log_debug("Invalid tree ID %x\n", i); return NULL; } -- cgit v1.2.3 From fa12dfa08a7bdc7d67e3758f10461468a663ce2e Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Fri, 25 Aug 2023 11:37:46 +0200 Subject: dm: core: support reading a single indexed u64 value Add helper function to allow reading a single indexed u64 value from a device-tree property containing multiple u64 values, that is an array of u64's. Co-developed-by: Ashok Reddy Soma Signed-off-by: Ashok Reddy Soma Reviewed-by: Simon Glass Signed-off-by: Michal Simek Link: https://lore.kernel.org/r/08043c8d204d0068f04c27de86afe78c75c50b69.1692956263.git.michal.simek@amd.com --- drivers/core/ofnode.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'drivers/core/ofnode.c') diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index a4dc9bde085..8311282abf6 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -344,6 +344,36 @@ int ofnode_read_u32_index(ofnode node, const char *propname, int index, return 0; } +int ofnode_read_u64_index(ofnode node, const char *propname, int index, + u64 *outp) +{ + const fdt64_t *cell; + int len; + + assert(ofnode_valid(node)); + + if (ofnode_is_np(node)) + return of_read_u64_index(ofnode_to_np(node), propname, index, + outp); + + cell = fdt_getprop(ofnode_to_fdt(node), ofnode_to_offset(node), + propname, &len); + if (!cell) { + debug("(not found)\n"); + return -EINVAL; + } + + if (len < (sizeof(u64) * (index + 1))) { + debug("(not large enough)\n"); + return -EOVERFLOW; + } + + *outp = fdt64_to_cpu(cell[index]); + debug("%#llx (%lld)\n", *outp, *outp); + + return 0; +} + u32 ofnode_read_u32_index_default(ofnode node, const char *propname, int index, u32 def) { -- cgit v1.2.3 From db5e349d3ddfc75953b2364e94b111ea1795f3c8 Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Thu, 31 Aug 2023 08:59:05 +0200 Subject: 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 Signed-off-by: Michal Simek Link: https://lore.kernel.org/r/23be3838502efef61803c90ef6e8b32bbd6ede41.1693465140.git.michal.simek@amd.com --- drivers/core/ofnode.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'drivers/core/ofnode.c') diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 8311282abf6..5076054acd6 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -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 */ -- cgit v1.2.3 From 44f35e1aca706e7625aa2989911b4bc938681158 Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Thu, 31 Aug 2023 09:04:27 +0200 Subject: dm: core: ofnode: Add ofnode_read_bootscript_flash() 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 Signed-off-by: Michal Simek Link: https://lore.kernel.org/r/08a3e6c09cce13287c69ad370e409e7f1766b406.1693465465.git.michal.simek@amd.com --- drivers/core/ofnode.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'drivers/core/ofnode.c') diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 5076054acd6..fb4447c84b7 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -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 */ -- cgit v1.2.3 From a5d2721bb2697306c7534e6c9f7c84c6bdc6a4d1 Mon Sep 17 00:00:00 2001 From: Michal Simek Date: Mon, 11 Sep 2023 15:30:01 +0200 Subject: dm: core: ofnode: Fix error message in ofnode_read_bootscript_address/flash() Missing u-boot node shouldn't be visible in bootlog without debug enabled that's why change message from printf to debug. Signed-off-by: Michal Simek Link: https://lore.kernel.org/r/ff62e980237ab271cf05facfbc306e85914a8c6e.1694438999.git.michal.simek@amd.com --- drivers/core/ofnode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/core/ofnode.c') diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index fb4447c84b7..ff0a5b5164f 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -1603,7 +1603,7 @@ int ofnode_read_bootscript_address(u64 *bootscr_address, u64 *bootscr_offset) uboot = ofnode_path("/options/u-boot"); if (!ofnode_valid(uboot)) { - printf("%s: Missing /u-boot node\n", __func__); + debug("%s: Missing /u-boot node\n", __func__); return -EINVAL; } @@ -1629,7 +1629,7 @@ int ofnode_read_bootscript_flash(u64 *bootscr_flash_offset, uboot = ofnode_path("/options/u-boot"); if (!ofnode_valid(uboot)) { - printf("%s: Missing /u-boot node\n", __func__); + debug("%s: Missing /u-boot node\n", __func__); return -EINVAL; } -- cgit v1.2.3 From 9e644284ab812f2db23f6185af77c0e771b0be73 Mon Sep 17 00:00:00 2001 From: Jonas Karlman Date: Sun, 20 Aug 2023 22:03:18 +0000 Subject: dm: core: Report bootph-pre-ram/sram node as pre-reloc after relocation Nodes with bootph-pre-sram/ram props are bound in multiple phases: 1. At TPL (bootph-pre-sram) or SPL (bootph-pre-ram) phase 2. At U-Boot proper pre-relocation phase 3. At U-Boot proper normal phase However the binding and U-Boot Driver Model documentation indicate that only nodes marked with bootph-all or bootph-some-ram should be bound in the U-Boot proper pre-relocation phase. Change ofnode_pre_reloc to report a node with bootph-pre-ram/sram prop with a pre-reloc status only after U-Boot proper pre-relocation phase. Also update the ofnode_pre_reloc documentation to closer reflect the binding and driver model documentation. This changes behavior of what nodes are bound in the U-Boot proper pre-relocation phase. Change to bootph-all or add bootph-some-ram prop to restore prior behavior. Signed-off-by: Jonas Karlman Reviewed-by: Simon Glass --- drivers/core/ofnode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/core/ofnode.c') diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index ff0a5b5164f..2cafa7bca5b 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -1383,7 +1383,7 @@ bool ofnode_pre_reloc(ofnode node) */ if (ofnode_read_bool(node, "bootph-pre-ram") || ofnode_read_bool(node, "bootph-pre-sram")) - return true; + return gd->flags & GD_FLG_RELOC; if (IS_ENABLED(CONFIG_OF_TAG_MIGRATE)) { /* detect and handle old tags */ -- cgit v1.2.3