Skip to contentSkip to conversation

FDT fixes for running on native Open Firmware

PATCH In review Sascha Silbe 3 participants 6 messages May 13, 2017 – May 15, 2017 Device tree

lore
Share & tools
lore
#0 lore raw

cover FDT fixes for running on native Open Firmware

Two fixes for bugs in the FDT code I discovered while trying to get the mainline kernel to run on OLPC XO-1.75. XOs are running Open Firmware natively, not just passing down some blob.

Sascha Silbe (2):
fdt: correctly handle uncompressed node names
of: fdt: fix unflattening of FDTs containing uncompressed paths

 drivers/of/fdt.c            | 2 ++
 scripts/dtc/libfdt/fdt_ro.c | 3 +++
 2 files changed, 5 insertions(+)
Signature · 6 lines
2.11.0

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#1 lore raw

PATCH 1/2 fdt: correctly handle uncompressed node names

When handling uncompressed node names, we need to compare the last component rather than the entire string.

---
 scripts/dtc/libfdt/fdt_ro.c | 3 +++
 1 file changed, 3 insertions(+)
scripts/dtc/libfdt/fdt_ro.c +3 -0
index 3d00d2eee0e3..ca03ff87429c 100644
@@ -64,6 +64,9 @@ static int _fdt_nodename_eq(const void *fdt, int offset,
 		/* short match */
 		return 0;
 
+	if (*p == '/')
+		/* Uncompressed node name. Only compare the last part. */
+		p = strrchr(p, '/') + 1;
 	if (memcmp(p, s, len) != 0)
 		return 0;
 
Signature · 1 line
2.11.0
#2 lore raw

Re: [PATCH 1/2] fdt: correctly handle uncompressed node names

reproduce: wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross…

Hi Sascha,

[auto build test ERROR on robh/for-next]
[also build test ERROR on v4.11 next-20170512]
[cannot apply to glikely/devicetree/next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Sascha-Silbe/fdt-correctly-handle-uncompressed-node-names/20170513-184012
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
config: arm64-alldefconfig (attached as .config)
compiler: aarch64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705

reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm64

All errors (new ones prefixed by >>):

./drivers/firmware/efi/libstub/lib.a(lib-fdt_ro.stub.o): In function `__efistub_fdt_subnode_offset_namelen':

>> __efistub_fdt_ro.c:(.init.text+0x248): undefined reference to `__efistub_strrchr'

__efistub_fdt_ro.c:(.init.text+0x248): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `__efistub_strrchr'

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#3 lore raw

Re: [PATCH 1/2] fdt: correctly handle uncompressed node names

In reply to Sascha Silbe
reproduce: wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross…

Hi Sascha,

[auto build test ERROR on robh/for-next]
[also build test ERROR on v4.11 next-20170512]
[cannot apply to glikely/devicetree/next]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Sascha-Silbe/fdt-correctly-handle-uncompressed-node-names/20170513-184012
base:   https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next
config: arm-omap2plus_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 6.1.1-9) 6.1.1 20160705

reproduce:
wget https://raw.githubusercontent.com/01org/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm

All errors (new ones prefixed by >>):

arch/arm/boot/compressed/fdt_ro.o: In function `fdt_subnode_offset_namelen':

>> arch/arm/boot/compressed/fdt_ro.c:69: undefined reference to `strrchr'
>> arch/arm/boot/compressed/fdt_ro.o:(.debug_addr+0x364): undefined reference to `strrchr'

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#4 lore raw

Re: [PATCH 1/2] fdt: correctly handle uncompressed node names

In reply to Sascha Silbe
Quoted 7 lines · Sascha Silbe

When handling uncompressed node names, we need to compare the last component rather than the entire string.

---
 scripts/dtc/libfdt/fdt_ro.c | 3 +++
 1 file changed, 3 insertions(+)

This needs to be a patch against dtc, sent to devicetree-compiler list and accepted there, then I can pick it up.

scripts/dtc/libfdt/fdt_ro.c static int _fdt_nodename_eq(const void *fdt, int offset, · line 69

Quoted 12 lines
scripts/dtc/libfdt/fdt_ro.c +3 -0
index 3d00d2eee0e3..ca03ff87429c 100644
@@ -64,6 +64,9 @@ static int _fdt_nodename_eq(const void *fdt, int offset,
                /* short match */
                return 0;
 
+       if (*p == '/')
+               /* Uncompressed node name. Only compare the last part. */
+               p = strrchr(p, '/') + 1;

However, you are changing behavior here that I'd guess has existed for some time. This makes me suspicious that this is correct especially when it is non-FDT DT you are trying to fix.

Given that 0-day reports an error with EFI stub, you also have to consider if u-boot, barebox, grub, and all the other libfdt users provide strrchr.

Rob

#5 lore raw

PATCH 2/2 of: fdt: fix unflattening of FDTs containing uncompressed paths

In reply to Sascha Silbe

Probably since commit dfbd4c6eff35 ("drivers/of: Split unflatten_dt_node()"), unflattening an FDT containing uncompressed node names (e.g. "/gpio@d4019000/gpio@0") will abort after scanning the root node because fpsize wasn't updated to include the path len.

---
 drivers/of/fdt.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/of/fdt.c +2 -0
index e5ce4b59e162..2d5414e644b3 100644
@@ -309,6 +309,8 @@ static unsigned int populate_node(const void *blob,
 			fpsize += l;
 			allocl = fpsize;
 		}
+	} else {
+		fpsize += allocl;
 	}
 
 	np = unflatten_dt_alloc(mem, sizeof(struct device_node) + allocl,
Signature · 1 line
2.11.0