of: Add unit tests for applying overlays
Subsystems (2)
v4 cover of: Add unit tests for applying overlays
From: Frank Rowand <[email protected]>
Existing overlay unit tests examine individual pieces of the overlay code. The new tests target the entire process of applying an overlay.
Changes from v3:
- make subject line of patch 1 more generic
Changes from v2:
- of_private.h: move __unflatten_device_tree() outside
#ifdef CONFIG_OF_UNITTEST
- unittest.c: move overlay declaration macros outside
#ifdef CONFIG_OF_OVERLAY - unittest.c: make overlay_info overlays[] static
- unittest.c: remove extra blank line
Changes from v1:
- Move overlay base dtb unflattening into unittest.c. Call from fdt.c.
- Clarify file and variable names, 'overlay_test_' instead of 'ot_'
- Use proper naming convention for node names.
- A few added comments.
- Improve error messages in the new tests.
Frank Rowand (2):
of: support dtc compiler flags for overlays
of: Add unit tests for applying overlays
drivers/of/fdt.c | 14 +- drivers/of/of_private.h | 12 + drivers/of/unittest-data/Makefile | 17 +- drivers/of/unittest-data/overlay.dts | 53 ++++ drivers/of/unittest-data/overlay_bad_phandle.dts | 20 ++ drivers/of/unittest-data/overlay_base.dts | 80 ++++++ drivers/of/unittest.c | 317 +++++++++++++++++++++++ scripts/Makefile.lib | 2 + 8 files changed, 507 insertions(+), 8 deletions(-) create mode 100644 drivers/of/unittest-data/overlay.dts create mode 100644 drivers/of/unittest-data/overlay_bad_phandle.dts create mode 100644 drivers/of/unittest-data/overlay_base.dts
Signature · 1 line
Frank Rowand <[email protected]>
PATCH v4 1/2 of: per-file dtc compiler flags
From: Frank Rowand <frank.rowand-7U/[email protected]>
The dtc compiler version that adds initial support was available in 4.11-rc1. Add the ability to set an additional dtc compiler flag is needed by overlays.
--- scripts/Makefile.lib | 2 ++ 1 file changed, 2 insertions(+)
scripts/Makefile.lib +2 -0
@@ -283,6 +283,8 @@ ifeq ($(KBUILD_ENABLE_EXTRA_GCC_CHECKS),) DTC_FLAGS += -Wno-unit_address_vs_reg endif +DTC_FLAGS += $(DTC_FLAGS_$(basetarget)) + # Generate an assembly file to wrap the output of the device tree compiler quiet_cmd_dt_S_dtb= DTB $@ cmd_dt_S_dtb= \
Signature · 6 lines
Frank Rowand <frank.rowand-7U/[email protected]> -- 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
Re: [PATCH v4 1/2] of: per-file dtc compiler flags
2017-04-26 9:09 GMT+09:00 <[email protected]>:
Quoted 8 lines
From: Frank Rowand <frank.rowand-7U/[email protected]>
The dtc compiler version that adds initial support was available in 4.11-rc1. Add the ability to set an additional dtc compiler flag is needed by overlays.
Signed-off-by Frank Rowand <frank.rowand-7U/[email protected]>---
Signature · 6 lines
Best Regards Masahiro Yamada -- 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
Re: [PATCH v4 1/2] of: per-file dtc compiler flags
In reply to [email protected]Quoted 10 lines · On Tue, Apr 25, 2017 at 05:09:53PM -0700, [email protected] wrote:
From: Frank Rowand <[email protected]>
The dtc compiler version that adds initial support was available in 4.11-rc1. Add the ability to set an additional dtc compiler flag is needed by overlays.
Signed-off-by Frank Rowand <[email protected]>--- scripts/Makefile.lib | 2 ++ 1 file changed, 2 insertions(+)
Applied.
PATCH v4 2/2 of: Add unit tests for applying overlays
In reply to [email protected]From: Frank Rowand <[email protected]>
Existing overlay unit tests examine individual pieces of the overlay code. The new tests target the entire process of applying an overlay.
---
There are checkpatch warnings. I have reviewed them and feel they can be ignored.
drivers/of/fdt.c | 14 +- drivers/of/of_private.h | 12 + drivers/of/unittest-data/Makefile | 17 +- drivers/of/unittest-data/overlay.dts | 53 ++++ drivers/of/unittest-data/overlay_bad_phandle.dts | 20 ++ drivers/of/unittest-data/overlay_base.dts | 80 ++++++ drivers/of/unittest.c | 317 +++++++++++++++++++++++ 7 files changed, 505 insertions(+), 8 deletions(-) create mode 100644 drivers/of/unittest-data/overlay.dts create mode 100644 drivers/of/unittest-data/overlay_bad_phandle.dts create mode 100644 drivers/of/unittest-data/overlay_base.dts
drivers/of/fdt.c +9 -5
@@ -31,6 +31,8 @@#include <asm/setup.h> /* for COMMAND_LINE_SIZE */ #include <asm/page.h> +#include "of_private.h" +/* * of_fdt_limit_memory - limit the number of regions in the /memory node * @limit: maximum entries
@@ -469,11 +471,11 @@ static int unflatten_dt_nodes(const void *blob,* Returns NULL on failure or the memory chunk containing the unflattened * device tree on success. */ -static void *__unflatten_device_tree (const void *blob, -struct device_node *dad, -struct device_node **mynodes, -void *(*dt_alloc)(u64 size,u64 align), -bool detached) +void *__unflatten_device_tree (const void *blob, +struct device_node *dad, +struct device_node **mynodes, +void *(*dt_alloc)(u64 size,u64 align), +bool detached) {int size;void *mem;
@@ -1261,6 +1263,8 @@ void __init unflatten_device_tree(void)/* Get pointer to "/chosen" and "/aliases" nodes for use everywhere */ of_alias_scan (early_init_dt_alloc_memory_arch); + +unittest_unflatten_overlay_base (); }/**
drivers/of/of_private.h +12 -0
@@ -55,6 +55,18 @@ static inline int of_property_notify(int action, struct device_node *np, }#endif /* CONFIG_OF_DYNAMIC */ +#ifdef CONFIG_OF_UNITTEST +extern void __init unittest_unflatten_overlay_base (void ); +#else +static inline void unittest_unflatten_overlay_base (void ) {}; +#endif + +extern void *__unflatten_device_tree (const void *blob, +struct device_node *dad, +struct device_node **mynodes, +void *(*dt_alloc)(u64 size,u64 align), +bool detached); +/** * General utilities for working with live trees. *
drivers/of/unittest-data/Makefile +14 -3
@@ -1,7 +1,18 @@ obj-y += testcases.dtb.o +obj-y += overlay.dtb.o +obj-y += overlay_bad_phandle.dtb.o +obj-y += overlay_base.dtb.o targets += testcases.dtb testcases.dtb.S +targets += overlay.dtb overlay.dtb.S +targets += overlay_bad_phandle.dtb overlay_bad_phandle.dtb.S +targets += overlay_base.dtb overlay_base.dtb.S -.SECONDARY: \ - $(obj)/testcases.dtb.S \ - $(obj)/testcases.dtb +.PRECIOUS: \ + $(obj)/%.dtb.S \ + $(obj)/%.dtb + +# enable creation of __symbols__ node +DTC_FLAGS_overlay := -@ +DTC_FLAGS_overlay_bad_phandle := -@ +DTC_FLAGS_overlay_base := -@
drivers/of/unittest-data/overlay.dts new file +53 -0
53 lines not on this page · raw message
drivers/of/unittest-data/overlay_bad_phandle.dts new file +20 -0
@@ -0,0 +1,20 @@ +/dts-v1/; +/plugin/; + +/ { + + fragment@0 { + target = <&electric_1>; + + __overlay__ { + + // This label should cause an error when the overlay + // is applied. There is already a phandle value + // in the base tree for motor-1. + spin_ctrl_1_conflict: motor-1 { + accelerate = < 3 >; + decelerate = < 5 >; + }; + }; + }; +};
drivers/of/unittest-data/overlay_base.dts new file +80 -0
80 lines not on this page · raw message
drivers/of/unittest.c +317 -0
335 lines not on this page · raw message
Signature · 1 line
Frank Rowand <[email protected]>
Quoted 11 lines · On Tue, Apr 25, 2017 at 05:09:54PM -0700, [email protected] wrote:
From: Frank Rowand <[email protected]>
Existing overlay unit tests examine individual pieces of the overlay code. The new tests target the entire process of applying an overlay.
Signed-off-by Frank Rowand <[email protected]>---
There are checkpatch warnings. I have reviewed them and feel they can be ignored.
Quoted 11 lines
drivers/of/fdt.c | 14 +- drivers/of/of_private.h | 12 + drivers/of/unittest-data/Makefile | 17 +- drivers/of/unittest-data/overlay.dts | 53 ++++ drivers/of/unittest-data/overlay_bad_phandle.dts | 20 ++ drivers/of/unittest-data/overlay_base.dts | 80 ++++++ drivers/of/unittest.c | 317 +++++++++++++++++++++++ 7 files changed, 505 insertions(+), 8 deletions(-) create mode 100644 drivers/of/unittest-data/overlay.dts create mode 100644 drivers/of/unittest-data/overlay_bad_phandle.dts create mode 100644 drivers/of/unittest-data/overlay_base.dts
Applied.
Rob
Hi Frank,
Quoted 20 lines · On Wed, Apr 26, 2017 at 2:09 AM, <[email protected]> wrote:
From: Frank Rowand <[email protected]>
Existing overlay unit tests examine individual pieces of the overlay code. The new tests target the entire process of applying an overlay.
Signed-off-by Frank Rowand <[email protected]>---
There are checkpatch warnings. I have reviewed them and feel they can be ignored.
drivers/of/fdt.c | 14 +- drivers/of/of_private.h | 12 + drivers/of/unittest-data/Makefile | 17 +- drivers/of/unittest-data/overlay.dts | 53 ++++ drivers/of/unittest-data/overlay_bad_phandle.dts | 20 ++ drivers/of/unittest-data/overlay_base.dts | 80 ++++++ drivers/of/unittest.c | 317 +++++++++++++++++++++++ 7 files changed, 505 insertions(+), 8 deletions(-)
Quoted 3 lines
create mode 100644 drivers/of/unittest-data/overlay.dts create mode 100644 drivers/of/unittest-data/overlay_bad_phandle.dts create mode 100644 drivers/of/unittest-data/overlay_base.dts
Shouldn't these be called .dtso instead of .dts?
drivers/of/unittest-data/Makefile line 18
Quoted 7 lines
drivers/of/unittest-data/Makefile +4
-0+# enable creation of __symbols__ node +DTC_FLAGS_overlay := -@ +DTC_FLAGS_overlay_bad_phandle := -@ +DTC_FLAGS_overlay_base := -@
This flag is needed for all DTs that will be involved with overlays.
Hence what about enabling this globally instead, cfr. "Enable DT symbols when" CONFIG_OF_OVERLAY is used ("http://www.spinics.net/lists/devicetree/msg103363.html")?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Quoted 23 lines · Geert Uytterhoeven
Hi Frank,
Quoted 20 lines · On Wed, Apr 26, 2017 at 2:09 AM, <[email protected]…
From: Frank Rowand <frank.rowand-7U/[email protected]>
Existing overlay unit tests examine individual pieces of the overlay code. The new tests target the entire process of applying an overlay.
Signed-off-by Frank Rowand <frank.rowand-7U/[email protected]>---
There are checkpatch warnings. I have reviewed them and feel they can be ignored.
drivers/of/fdt.c | 14 +- drivers/of/of_private.h | 12 + drivers/of/unittest-data/Makefile | 17 +- drivers/of/unittest-data/overlay.dts | 53 ++++ drivers/of/unittest-data/overlay_bad_phandle.dts | 20 ++ drivers/of/unittest-data/overlay_base.dts | 80 ++++++ drivers/of/unittest.c | 317 +++++++++++++++++++++++ 7 files changed, 505 insertions(+), 8 deletions(-)
Quoted 5 lines
Quoted 3 lines
create mode 100644 drivers/of/unittest-data/overlay.dts create mode 100644 drivers/of/unittest-data/overlay_bad_phandle.dts create mode 100644 drivers/of/unittest-data/overlay_base.dtsShouldn't these be called .dtso instead of .dts?
That is a good question. I'm not worried about solving it this week for this patch, because this could turn into a bikeshed and I can always fix it with a patch if we decide to change. But if we do want to change the naming, I would like to make the decision in the next couple of months. I would like to see more progress on overlays in general this summer, and plan to be working on them myself.
I _think_ there has been some discussion about source file naming on the devicetree-compiler or devicetree list in the far distant past. Or I may just be mis-remembering.
As far as I know, the current dtc does not know any suffixes other than .dts for source files. Not that the compiler has to know, we can always specify '-I dts'.
Quoted 11 lines
drivers/of/unittest-data/Makefile line 18
Quoted 8 lines
drivers/of/unittest-data/Makefile +4
-0+# enable creation of __symbols__ node +DTC_FLAGS_overlay := -@ +DTC_FLAGS_overlay_bad_phandle := -@ +DTC_FLAGS_overlay_base := -@This flag is needed for all DTs that will be involved with overlays.
Quoted 3 lines
Hence what about enabling this globally instead, cfr. "Enable DT symbols when"
CONFIG_OF_OVERLAYis used ("http://www.spinics.net/lists/devicetree/msg103363.html")?
And another really good question.
There are some issues. I have thought about it enough to know there are issues, but do not have a solution and do not think I know all the issues. Some possible issues (or perceived issues) are:
- The size of __symbols__ in an FDT (akd compile .dtb image) in either a kernel image or a bootloader if overlays are not actually needed on a given system (even if the system is physically capable of using overlays).
- The size of __symbols__ in kernel memory if overlays are not actually needed on a given system (even if the system is physically capable of using overlays.) This could be possibly be enabled/disabled by a boot command, even if __symbols__ is in the FDT.
- A base FDT might want to have __symbols__ included with the expectation that overlays will be used in the future. (The FDT might be built for the boot loader, then be stable for many kernel releases.)
- Should the creation of __symbols__ be a global switch, or should it be controlled on a per dtb basis? Or a combination of both?
Again, I'm not worried about an immediate, this week solution, but I would like to make good progress on this in the next couple of months.
-Frank
Quoted 12 lines
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
--
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
Hi Frank,
Quoted 15 lines · Frank Rowand
Quoted 6 lines · Geert Uytterhoeven
Quoted 3 lines · On Wed, Apr 26, 2017 at 2:09 AM, <[email protected]> wrote:
create mode 100644 drivers/of/unittest-data/overlay.dts create mode 100644 drivers/of/unittest-data/overlay_bad_phandle.dts create mode 100644 drivers/of/unittest-data/overlay_base.dtsShouldn't these be called .dtso instead of .dts?
That is a good question. I'm not worried about solving it this week for this patch, because this could turn into a bikeshed and I can always fix it with a patch if we decide to change. But if we do want to change the naming, I would like to make the decision in the next couple of months. I would like to see more progress on overlays in general this summer, and plan to be working on them myself.
Quoted 7 lines
I _think_ there has been some discussion about source file naming on the devicetree-compiler or devicetree list in the far distant past. Or I may just be mis-remembering.
As far as I know, the current dtc does not know any suffixes other than .dts for source files. Not that the compiler has to know, we can always specify '-I dts'.
That's not an obstacle, though. I've been compiling .dtso files into .dtbo files for several years, cfr.
https://git.kernel.org/pub/scm/linux/kernel/git/geert/renesas-drivers.git/log/?h=topic/renesas-overlays
According to "make V=1", the kernel build system basically uses
./scripts/dtc/dtc -O dtb -o <file>.dtbo <file>.dtbo.dts.tmp
with <file>.dtbo.dts.tmp the preprocessed .dtso files. And dtc copes fine with that.
Quoted 16 lines
Quoted 10 lines
drivers/of/unittest-data/Makefile line 18
Quoted 7 lines
drivers/of/unittest-data/Makefile +4
-0+# enable creation of __symbols__ node +DTC_FLAGS_overlay := -@ +DTC_FLAGS_overlay_bad_phandle := -@ +DTC_FLAGS_overlay_base := -@This flag is needed for all DTs that will be involved with overlays.
Quoted 3 lines
Hence what about enabling this globally instead, cfr. "Enable DT symbols when"
CONFIG_OF_OVERLAYis used ("http://www.spinics.net/lists/devicetree/msg103363.html")?And another really good question.
Quoted 7 lines
There are some issues. I have thought about it enough to know there are issues, but do not have a solution and do not think I know all the issues. Some possible issues (or perceived issues) are:
- The size of
__symbols__in an FDT (akd compile .dtb image) in either a kernel image or a bootloader if overlays are not actually needed on a given system (even if the system is physically capable of using overlays).
What do you mean with "physically capable of using overlays"?
The presence of expansion connectors, like Raspberry Pi and BeagleBone Black?
Even lacking such connectors, an overlay could add hardware description that was just missing (forgotten, or lack of DT bindings) when the main DTB was built.
I agree about the size, but you never know in advance if an overlay will be used or needed later.
Quoted 4 lines
- The size of
__symbols__in kernel memory if overlays are not actually needed on a given system (even if the system is physically capable of using overlays.) This could be possibly be enabled/disabled by a boot command, even if__symbols__is in the FDT.
Agreed. Not allowing overlays is akin to not allowing to load (more) kernel modules, and may increase security.
Quoted 6 lines
- A base FDT might want to have
__symbols__included with the expectation that overlays will be used in the future. (The FDT might be built for the boot loader, then be stable for many kernel releases.)- Should the creation of
__symbols__be a global switch, or should it be controlled on a per dtb basis? Or a combination of both?
So you want to decouple OF overlay support in the Linux kernel from __symbols__ present in the DTBs built?
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Quoted 7 lines · On Tue, Apr 25, 2017 at 7:09 PM, <[email protected]> wrote:
From: Frank Rowand <[email protected]>
Existing overlay unit tests examine individual pieces of the overlay code. The new tests target the entire process of applying an overlay.
Signed-off-by Frank Rowand <[email protected]>---
[...]
drivers/of/fdt.c void __init unflatten_device_tree(void) · line 1267
Quoted 6 lines
drivers/of/fdt.c +2
-0@@ -1261,6 +1263,8 @@ void __init unflatten_device_tree(void)/* Get pointer to "/chosen" and "/aliases" nodes for use everywhere */ of_alias_scan (early_init_dt_alloc_memory_arch); + +unittest_unflatten_overlay_base ();
This breaks on systems that don't boot with FDT and call unflatten_device_tree, namely x86 and UML (UML needs a few hacks to work) which was a feature of the unittest. Considering applying overlays on x86 is something we'll want to support, the unittest should support that case.
Rob
Quoted 24 lines · Rob Herring
Quoted 7 lines · On Tue, Apr 25, 2017 at 7:09 PM, <[email protected]> wrote:
From: Frank Rowand <[email protected]>
Existing overlay unit tests examine individual pieces of the overlay code. The new tests target the entire process of applying an overlay.
Signed-off-by Frank Rowand <[email protected]>---
[...]
drivers/of/fdt.c void __init unflatten_device_tree(void) · line 1267
Quoted 6 lines
drivers/of/fdt.c +2
-0@@ -1261,6 +1263,8 @@ void __init unflatten_device_tree(void)/* Get pointer to "/chosen" and "/aliases" nodes for use everywhere */ of_alias_scan (early_init_dt_alloc_memory_arch); + +unittest_unflatten_overlay_base ();This breaks on systems that don't boot with FDT and call
unflatten_device_tree, namely x86 and UML (UML needs a few hacks to work) which was a feature of the unittest. Considering applying overlays on x86 is something we'll want to support, the unittest should support that case.
Quoted 2 lines
Rob
I meant to reply when I read this...
I'll look at this, probably next week. Thanks for pointing out the issue.
-Frank
Hi Rob,
Quoted 24 lines · Rob Herring
Quoted 7 lines · On Tue, Apr 25, 2017 at 7:09 PM, <[email protected]…
From: Frank Rowand <frank.rowand-7U/[email protected]>
Existing overlay unit tests examine individual pieces of the overlay code. The new tests target the entire process of applying an overlay.
Signed-off-by Frank Rowand <frank.rowand-7U/[email protected]>---
[...]
drivers/of/fdt.c void __init unflatten_device_tree(void) · line 1267
Quoted 6 lines
drivers/of/fdt.c +2
-0@@ -1261,6 +1263,8 @@ void __init unflatten_device_tree(void)/* Get pointer to "/chosen" and "/aliases" nodes for use everywhere */ of_alias_scan (early_init_dt_alloc_memory_arch); + +unittest_unflatten_overlay_base ();This breaks on systems that don't boot with FDT and call
unflatten_device_tree, namely x86 and UML (UML needs a few hacks to work) which was a feature of the unittest. Considering applying overlays on x86 is something we'll want to support, the unittest should support that case.
Quoted 1 line
Rob
What is the symptom of the breakage? Or what is causing breakage?
-Frank
--
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