Skip to contentSkip to conversation

fdt: Use phandle to distinguish DT nodes with same name

PATCH Superseded Aswath Govindraju 2 participants 3 messages Dec 2, 2020 – Dec 3, 2020 Library code

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fdt: Use phandle to distinguish DT nodes with same name

While assigning the sequence number to subsystem instances by reading the aliases property, only DT nodes names are compared and not the complete path. This causes a problem when there are two DT nodes with same name but have different paths.

In arch/arm/dts/k3-am65-main.dtsi there are two USB controllers with the same device tree node name but different path. When aliases are defined for these USB controllers then fdtdec_get_alias_seq() fails to pick the correct instance for a given index.

fdt_path_offset() function is slow and this would effect the uboot startup. To avert the time penalty on all boards, apply this extra check only when required by using a config option.

Fix it by comparing the phandles of DT nodes after the node names match, under a config option.

---

Changes since v1:
- Added a config option as fdt_path_offset() slows down the u-boot start up and would be better to be enabled only when required
- Added an example case in commit message where the following fix is required.

 lib/Kconfig  |  8 ++++++++
 lib/fdtdec.c | 11 +++++++++++
 2 files changed, 19 insertions(+)
lib/Kconfig +8 -0
index 8efb154f7344..9813a3a5e0ba 100644
@@ -685,3 +685,11 @@ config LIB_ELF
 	  This supports fir 32 bit and 64 bit versions.
 
 endmenu
+
+config PHANDLE_CHECK_SEQ
+	bool "Enable phandle check while getting sequence number"
+	default n
+	help
+	  When there are multiple device tree nodes with same name,
+         enable this config option to distinguish them using
+	  phandles in fdtdec_get_alias_seq() function.
lib/fdtdec.c +11 -0
index ee1bd41b0818..60aa1bd8cf1b 100644
@@ -500,6 +500,17 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
 		slash = strrchr(prop, '/');
 		if (strcmp(slash + 1, find_name))
 			continue;
+
+		/*
+		 * Adding an extra check to distinguish DT nodes with
+		 * same name
+		 */
+		#ifdef CONFIG_PHANDLE_CHECK_SEQ
+		if (fdt_get_phandle(blob, offset) !=
+		    fdt_get_phandle(blob, fdt_path_offset(blob, prop)))
+			continue;
+		#endif
+
 		val = trailing_strtol(name);
 		if (val != -1) {
 			*seqp = val;
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/1 fdt: Use phandle to distinguish DT nodes with same name

Hi Aswath,

Quoted 6 lines · Aswath Govindraju

While assigning the sequence number to subsystem instances by reading the aliases property, only DT nodes names are compared and not the complete path. This causes a problem when there are two DT nodes with same name but have different paths.

Quoted 6 lines

In arch/arm/dts/k3-am65-main.dtsi there are two USB controllers with the same device tree node name but different path. When aliases are defined for these USB controllers then fdtdec_get_alias_seq() fails to pick the correct instance for a given index.

fdt_path_offset() function is slow and this would effect the uboot startup.

U-Boot

Quoted 40 lines

To avert the time penalty on all boards, apply this extra check only when required by using a config option.

Fix it by comparing the phandles of DT nodes after the node names match, under a config option.

---

Changes since v1:
- Added a config option as fdt_path_offset() slows down the u-boot start up and would be better to be enabled only when required
- Added an example case in commit message where the following fix is required.

 lib/Kconfig  |  8 ++++++++
 lib/fdtdec.c | 11 +++++++++++
 2 files changed, 19 insertions(+)
lib/Kconfig +8 -0
index 8efb154f7344..9813a3a5e0ba 100644
@@ -685,3 +685,11 @@ config LIB_ELF
          This supports fir 32 bit and 64 bit versions.
 
 endmenu
+
+config PHANDLE_CHECK_SEQ
+       bool "Enable phandle check while getting sequence number"
+       default n
+       help
+         When there are multiple device tree nodes with same name,
+         enable this config option to distinguish them using
+         phandles in fdtdec_get_alias_seq() function.
lib/fdtdec.c +0 -0
index ee1bd41b0818..60aa1bd8cf1b 100644

lib/fdtdec.c int fdtdec_get_alias_seq(const void *blob, const char *base, int offset, · line 508

Quoted 9 lines
lib/fdtdec.c +6 -0
@@ -500,6 +500,17 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
                slash = strrchr(prop, '/');
                if (strcmp(slash + 1, find_name))
                        continue;
+
+               /*
+                * Adding an extra check to distinguish DT nodes with
+                * same name
+                */
+               #ifdef CONFIG_PHANDLE_CHECK_SEQ

if (IS_ENABLED(CONFIG...

(did you not get a warning from patman on that?)

Quoted 11 lines
lib/fdtdec.c +5 -1
+               if (fdt_get_phandle(blob, offset) !=
+                   fdt_get_phandle(blob, fdt_path_offset(blob, prop)))
+                       continue;
+               #endif
+
                val = trailing_strtol(name);
                if (val != -1) {
                        *seqp = val;
--

2.17.1

Regards,
SImon

#2 lore raw

PATCH v2 1/1 fdt: Use phandle to distinguish DT nodes with same name

Hi Simon,

Quoted 9 lines · Simon Glass

Hi Aswath,

Quoted 6 lines · Aswath Govindraju

While assigning the sequence number to subsystem instances by reading the aliases property, only DT nodes names are compared and not the complete path. This causes a problem when there are two DT nodes with same name but have different paths.

Quoted 9 lines
Quoted 6 lines

In arch/arm/dts/k3-am65-main.dtsi there are two USB controllers with the same device tree node name but different path. When aliases are defined for these USB controllers then fdtdec_get_alias_seq() fails to pick the correct instance for a given index.

fdt_path_offset() function is slow and this would effect the uboot startup.

U-Boot

Corrected this.

Quoted 43 lines
Quoted 43 lines

To avert the time penalty on all boards, apply this extra check only when required by using a config option.

Fix it by comparing the phandles of DT nodes after the node names match, under a config option.

---

Changes since v1:
- Added a config option as fdt_path_offset() slows down the u-boot start up and would be better to be enabled only when required
- Added an example case in commit message where the following fix is required.

 lib/Kconfig  |  8 ++++++++
 lib/fdtdec.c | 11 +++++++++++
 2 files changed, 19 insertions(+)
lib/Kconfig +8 -0
index 8efb154f7344..9813a3a5e0ba 100644
@@ -685,3 +685,11 @@ config LIB_ELF
          This supports fir 32 bit and 64 bit versions.
 
 endmenu
+
+config PHANDLE_CHECK_SEQ
+       bool "Enable phandle check while getting sequence number"
+       default n
+       help
+         When there are multiple device tree nodes with same name,
+         enable this config option to distinguish them using
+         phandles in fdtdec_get_alias_seq() function.
lib/fdtdec.c +0 -0
index ee1bd41b0818..60aa1bd8cf1b 100644
@@ -500,6 +500,17 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
                slash = strrchr(prop, '/');
                if (strcmp(slash + 1, find_name))
                        continue;
Quoted 9 lines

lib/fdtdec.c int fdtdec_get_alias_seq(const void *blob, const char *base, int offset, · line 508

Quoted 6 lines
lib/fdtdec.c +6 -0
+
+               /*
+                * Adding an extra check to distinguish DT nodes with
+                * same name
+                */
+               #ifdef CONFIG_PHANDLE_CHECK_SEQ

if (IS_ENABLED(CONFIG...

Corrected this.

Quoted 1 line

(did you not get a warning from patman on that?)

No, I am not getting it.

Thank you for the comments. I made the changes that you suggested and I posted a respin.

Thanks,
Aswath

Quoted 16 lines
Quoted 10 lines
lib/fdtdec.c +5 -1
+               if (fdt_get_phandle(blob, offset) !=
+                   fdt_get_phandle(blob, fdt_path_offset(blob, prop)))
+                       continue;
+               #endif
+
                val = trailing_strtol(name);
                if (val != -1) {
                        *seqp = val;
--
Quoted 2 lines

2.17.1

Regards,
SImon