dtc: Resync fdt_check_full function
cover dtc: Resync fdt_check_full function
Hey all,
As part of the resync to dtc version v1.7.2-35-g52f07dcca47c from the Linux Kernel, we missed updating the fdt_check_full function because it exists in its own file in upstream dtc and the kernel doesn't import it, as reported by Anton Ivanov. This short series brings in the upstream fdt_check.c file and then implements our size-saving option, but in the modern way.
The size-saving portion will be upstreamed and I'll update this series if needed based on upstream feedback.
Signature · 1 line
Tom
PATCH 1/2 dtc: Resync fdt_check_full() with upstream version v1.7.2-35-g52f07dcca47c
In the upstream project, the function fdt_check_full has been moved from fdt_ro.c to its own file, fdt_check.c. This file is not included in the Linux kernel copy and so has not been synced over. As we do need and use the fdt_check_full function, bring that file over as of the current upstream we are synced to. Remove our copy of this function from fdt_ro.c and add fdt_check.o and 1-liner fdt_check.c where needed. Note that for now, this will increase size in some cases as upstream does not have a size reduction method here.
--- lib/libfdt/Makefile | 1 + lib/libfdt/fdt_check.c | 2 + scripts/dtc/Makefile | 2 +- scripts/dtc/libfdt/Makefile.libfdt | 2 +- scripts/dtc/libfdt/fdt_check.c | 96 ++++++++++++++++++++++++++++++ scripts/dtc/libfdt/fdt_ro.c | 88 --------------------------- scripts/dtc/update-dtc-source.sh | 2 +- tools/Makefile | 3 +- tools/libfdt/fdt_check.c | 2 + 9 files changed, 106 insertions(+), 92 deletions(-) create mode 100644 lib/libfdt/fdt_check.c create mode 100644 scripts/dtc/libfdt/fdt_check.c create mode 100644 tools/libfdt/fdt_check.c
lib/libfdt/Makefile +1 -0
@@ -5,6 +5,7 @@ obj-y += \ fdt.o \ + fdt_check.o \ fdt_ro.o \ fdt_wip.o \ fdt_strerror.o \
lib/libfdt/fdt_check.c new file +2 -0
@@ -0,0 +1,2 @@ +#include <linux/libfdt_env.h> +#include "../../scripts/dtc/libfdt/fdt_check.c"
scripts/dtc/Makefile +1 -1
@@ -10,7 +10,7 @@ dtc-objs += dtc-lexer.lex.o dtc-parser.tab.o # The upstream project builds libfdt as a separate library. We are choosing to # instead directly link the libfdt object files into fdtoverlay. -libfdt-objs := fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o fdt_strerror.o fdt_empty_tree.o fdt_addresses.o fdt_overlay.o +libfdt-objs := fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o fdt_strerror.o fdt_empty_tree.o fdt_addresses.o fdt_overlay.o fdt_check.o libfdt = $(addprefix libfdt/,$(libfdt-objs)) fdtoverlay-objs := $(libfdt) fdtoverlay.o util.o
scripts/dtc/libfdt/Makefile.libfdt +1 -1
@@ -8,7 +8,7 @@ LIBFDT_soname = libfdt.$(SHAREDLIB_EXT).1 LIBFDT_INCLUDES = fdt.h libfdt.h libfdt_env.h LIBFDT_VERSION = version.lds LIBFDT_SRCS = fdt.c fdt_ro.c fdt_wip.c fdt_sw.c fdt_rw.c fdt_strerror.c fdt_empty_tree.c \ - fdt_addresses.c fdt_overlay.c + fdt_addresses.c fdt_overlay.c fdt_check.c LIBFDT_OBJS = $(LIBFDT_SRCS:%.c=%.o) LIBFDT_LIB = libfdt-$(DTC_VERSION).$(SHAREDLIB_EXT)
scripts/dtc/libfdt/fdt_check.c new file +96 -0
96 lines not on this page · raw message
scripts/dtc/libfdt/fdt_ro.c +0 -88
91 lines not on this page · raw message
scripts/dtc/update-dtc-source.sh +1 -1
@@ -34,7 +34,7 @@ DTC_LINUX_PATH=`pwd`/scripts/dtc DTC_SOURCE="checks.c data.c dtc.c dtc.h flattree.c fstree.c livetree.c srcpos.c \ srcpos.h treesource.c util.c util.h version_gen.h \ dtc-lexer.l dtc-parser.y" -LIBFDT_SOURCE="fdt.c fdt.h fdt_addresses.c fdt_empty_tree.c \ +LIBFDT_SOURCE="fdt.c fdt.h fdt_addresses.c fdt_empty_tree.c fdt_check.c \ fdt_overlay.c fdt_ro.c fdt_rw.c fdt_strerror.c fdt_sw.c \ fdt_wip.c libfdt.h libfdt_env.h libfdt_internal.h" FDTOVERLAY_SOURCE=fdtoverlay.c
tools/Makefile +2 -1
@@ -82,7 +82,8 @@ HOSTCFLAGS_image-host.o += \ # The following files are synced with upstream DTC. # Use synced versions from scripts/dtc/libfdt/. LIBFDT_OBJS := $(addprefix libfdt/, fdt.o fdt_ro.o fdt_wip.o fdt_sw.o fdt_rw.o \ - fdt_strerror.o fdt_empty_tree.o fdt_addresses.o fdt_overlay.o) + fdt_strerror.o fdt_empty_tree.o fdt_addresses.o fdt_overlay.o \ + fdt_check.o) RSA_OBJS-$(CONFIG_TOOLS_LIBCRYPTO) := $(addprefix generated/lib/rsa/, \ rsa-sign.o rsa-verify.o \
tools/libfdt/fdt_check.c new file +2 -0
@@ -0,0 +1,2 @@ +#include "fdt_host.h" +#include "../scripts/dtc/libfdt/fdt_check.c"
Signature · 1 line
2.43.0
Re: [PATCH 1/2] dtc: Resync fdt_check_full() with upstream version v1.7.2-35-g52f07dcca47c
Quoted 14 lines · Tom Rini
dtc: Resync
fdt_check_full()with upstream version v1.7.2-35-g52f07dcca47cIn the upstream project, the function
fdt_check_fullhas been moved fromfdt_ro.cto its own file,fdt_check.c. This file is not included in the Linux kernel copy and so has not been synced over. As we do need and use thefdt_check_fullfunction, bring that file over as of the current upstream we are synced to. Remove our copy of this function fromfdt_ro.cand add fdt_check.o and 1-linerfdt_check.cwhere needed. Note that for now, this will increase size in some cases as upstream does not have a size reduction method here.Signed-off-by Tom Rini <[email protected]>
lib/libfdt/Makefile| 1 +
Quoted 9 lines
lib/libfdt/fdt_check.c | 2 + scripts/dtc/Makefile | 2 +- scripts/dtc/libfdt/Makefile.libfdt | 2 +- scripts/dtc/libfdt/fdt_check.c | 96 ++++++++++++++++++++++++++++++++++++++ scripts/dtc/libfdt/fdt_ro.c | 88 ---------------------------------- scripts/dtc/update-dtc-source.sh | 2 +- tools/Makefile | 3 +- tools/libfdt/fdt_check.c | 2 + 9 files changed, 106 insertions(+), 92 deletions(-)
PATCH 2/2 dtc: libfdt: Introduce a can_assume check in fdt_check_full
In reply to Tom RiniThe current upstream method of having a function omit various tests is to use the can_assume macro. Take the logic we had previously been using and instead make it a can_assume(PERFECT) check within fdt_check_full itself.
---
I will be submitting this change upstream and will follow up if needed here.
--- scripts/dtc/libfdt/fdt_check.c | 2 ++ 1 file changed, 2 insertions(+)
scripts/dtc/libfdt/fdt_check.c +2 -0
@@ -21,6 +21,8 @@ int fdt_check_full(const void *fdt, size_t bufsize)const char *propname;bool expect_end = false; +if (can_assume (PERFECT )) +return 0 ;if (bufsize <FDT_V1_SIZE )return -FDT_ERR_TRUNCATED ;if (bufsize <fdt_header_size (fdt))
Signature · 1 line
2.43.0
Re: [PATCH 2/2] dtc: libfdt: Introduce a can_assume check in fdt_check_full
Hi Tom,
Quoted 14 lines · Tom Rini
dtc: libfdt: Introduce a
can_assumecheck infdt_check_fullThe current upstream method of having a function omit various tests is to use the
can_assumemacro. Take the logic we had previously been using and instead make it acan_assume(PERFECT)check withinfdt_check_fullitself.Signed-off-by Tom Rini <[email protected]>
scripts/dtc/libfdt/fdt_check.c| 2 ++1 file changed, 2 insertions(+)
scripts/dtc/libfdt/fdt_check.c int fdt_check_full(const void *fdt, size_t bufsize) · line 25
Quoted 5 lines
scripts/dtc/libfdt/fdt_check.c +2
-0@@ -21,6 +21,8 @@ int fdt_check_full(const void *fdt, size_t bufsize)const char *propname;bool expect_end = false; +if (can_assume (PERFECT )) +return 0 ;
Just to note that this of course affects image-fit.c too, so FITs are no-longer validated if used in SPL. People can change the mask though.
I suggest stronger wording in the commit message since 'Take the logic we had previously been using' reads as a no-op refactor to me. I'm assuming that the motivation here is code size so you could mention too.
Regards,
Simon
Re: [PATCH 2/2] dtc: libfdt: Introduce a can_assume check in fdt_check_full
Quoted 20 lines · Simon Glass
Hi Tom,
Quoted 17 lines · Tom Rini
dtc: libfdt: Introduce a
can_assumecheck infdt_check_fullThe current upstream method of having a function omit various tests is to use the
can_assumemacro. Take the logic we had previously been using and instead make it acan_assume(PERFECT)check withinfdt_check_fullitself.Signed-off-by Tom Rini <[email protected]>
scripts/dtc/libfdt/fdt_check.c| 2 ++1 file changed, 2 insertions(+)scripts/dtc/libfdt/fdt_check.c +0
-0@@ -21,6 +21,8 @@ int fdt_check_full(const void *fdt, size_t bufsize)const char *propname;bool expect_end = false;
Quoted 5 lines
scripts/dtc/libfdt/fdt_check.c int fdt_check_full(const void *fdt, size_t bufsize) · line 25
Quoted 2 lines
scripts/dtc/libfdt/fdt_check.c +2
-0+if (can_assume (PERFECT )) +return 0 ;Just to note that this of course affects
image-fit.ctoo, so FITs are no-longer validated if used in SPL. People can change the mask though.
There's no functional change to what we have today, actually, really.
Signature · 1 line
Tom
Re: [PATCH 2/2] dtc: libfdt: Introduce a can_assume check in fdt_check_full
In reply to Tom RiniQuoted 18 lines · Tom Rini
The current upstream method of having a function omit various tests is to use the
can_assumemacro. Take the logic we had previously been using and instead make it acan_assume(PERFECT)check withinfdt_check_fullitself.Signed-off-by Tom Rini <[email protected]>---
I will be submitting this change upstream and will follow up if needed here.--- scripts/dtc/libfdt/fdt_check.c | 2 ++ 1 file changed, 2 insertions(+)scripts/dtc/libfdt/fdt_check.c +0
-0
scripts/dtc/libfdt/fdt_check.c int fdt_check_full(const void *fdt, size_t bufsize) · line 25
Quoted 5 lines
scripts/dtc/libfdt/fdt_check.c +2
-0@@ -21,6 +21,8 @@ int fdt_check_full(const void *fdt, size_t bufsize)const char *propname;bool expect_end = false; +if (can_assume (PERFECT )) +return 0 ;
Is this right? I think that would require changing can_assume() to test if the given mask is a subset of FDT_ASSUME_MASK, not merely intersects it. When called with a single-bit mask, those are of course the same thing.
Because as-is, can_assume(PERFECT) is true if FDT_ASSUME_MASK has any non-zero value, but I don't think FDT_ASSUME_MASK=ASSUME_LATEST, for example, should imply "perfect".
Rasmus
Re: [PATCH 2/2] dtc: libfdt: Introduce a can_assume check in fdt_check_full
Quoted 31 lines · Rasmus Villemoes
Quoted 18 lines · Tom Rini
The current upstream method of having a function omit various tests is to use the
can_assumemacro. Take the logic we had previously been using and instead make it acan_assume(PERFECT)check withinfdt_check_fullitself.Signed-off-by Tom Rini <[email protected]>---
I will be submitting this change upstream and will follow up if needed here.--- scripts/dtc/libfdt/fdt_check.c | 2 ++ 1 file changed, 2 insertions(+)scripts/dtc/libfdt/fdt_check.c +0
-0scripts/dtc/libfdt/fdt_check.c int fdt_check_full(const void *fdt, size_t bufsize) · line 25
Quoted 5 lines
scripts/dtc/libfdt/fdt_check.c +2
-0@@ -21,6 +21,8 @@ int fdt_check_full(const void *fdt, size_t bufsize)const char *propname;bool expect_end = false; +if (can_assume (PERFECT )) +return 0 ;Is this right? I think that would require changing
can_assume()to test if the given mask is a subset ofFDT_ASSUME_MASK, not merely intersects it. When called with a single-bit mask, those are of course the same thing.
Quoted 3 lines
Because as-is,
can_assume(PERFECT)is true ifFDT_ASSUME_MASKhas any non-zero value, but I don't think FDT_ASSUME_MASK=ASSUME_LATEST, for example, should imply "perfect".
Honestly (and I mentioned this to David in his reply on the devicetree-compiler list) the usage of the mask today is either 0xff or 0x0 and nothing in between. Which means yes, I wonder a little about the can_assume macro as opposed to how the mask was used originally.
Signature · 1 line
Tom
Quoted 10 lines · Tom Rini
Hey all,
As part of the resync to dtc version v1.7.2-35-g52f07dcca47c from the Linux Kernel, we missed updating the
fdt_check_fullfunction because it exists in its own file in upstream dtc and the kernel doesn't import it, as reported by Anton Ivanov. This short series brings in the upstreamfdt_check.cfile and then implements our size-saving option, but in the modern way.[...]
Applied to u-boot/next, thanks!
[1/2] dtc: Resync fdt_check_full() with upstream version v1.7.2-35-g52f07dcca47c
commit: 37fef5ab88d1134fd6b8b53090e0bfa442732e24
[2/2] dtc: libfdt: Introduce a can_assume check in fdt_check_full
commit: 487994d65cf305e943e4fd4efb56283f214f0611Signature · 1 line
Tom