Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dts: gen_defines.py: Support generating static initializers for nodes #21393

Closed

Conversation

ulfalizer
Copy link
Collaborator

Documentation (from the updated dts/binding-template.yaml):

If 'generate-child-initializer: true' appears in the binding for a node, then
static initializers will be generated for the child nodes of the node, along
with a static initializer for an array with the child nodes.

As an example, take the following devicetree. Assume that the binding for
'foos' contains 'generate-child-initializer: true', and that it gives the
foo_0 and foo_1 nodes a binding via 'child-binding:' (see below).

    / {
            foos@0 {
                    compatible = "foos";
                    foo_0 {
                            int = <0>;
                            string = "foo";
                    };
                    foo_1 {
                            int = <1>;
                            array = <2 3>;
                    };
            };
    };

These additional static initializers will then be generated, along with
aliases. The order of the properties in the initializer matches the order in
the devicetree.

    /* Initializer for foo_0 */
    #define DT_FOOS_0_FOO_0_INIT   {DT_FOOS_0_FOO_0_INT, DT_FOOS_0_FOO_0_STRING}
    /* Initializer for foo_1 */
    #define DT_FOOS_0_FOO_1_INIT   {DT_FOOS_0_FOO_1_INT, DT_FOOS_0_FOO_1_ARRAY}
    /* Initializer for the children of foos@0 */
    #define DT_FOOS_0_INIT         {DT_FOOS_0_FOO_0_INIT, DT_FOOS_0_FOO_1_INIT}

The referenced macros initialize each property (note that these are always
generated):

    #define DT_FOOS_0_FOO_0_INT    0
    #define DT_FOOS_0_FOO_0_STRING "foo"
    #define DT_FOOS_0_FOO_1_INT    1
    #define DT_FOOS_0_FOO_1_ARRAY  {2, 3}

Main commit:

dts: gen_defines.py: Support generating static initializers for nodes

Add a new 'generate-child-initializer' flag to bindings. When 'true',
static initializers will be generated for all child nodes of the node,
along with an initializer for an array that includes all the child
nodes.

This can be used to statically initialize structures and arrays derived
from devicetree data, e.g. for a list of LEDs.

See the updated documentation in doc/binding-template.yaml for more
information.

Fixes: #21239

Misc. refactoring:

dts: gen_defines.py: Add should_write() helper for properties

should_write() returns False for properties that are skipped in
write_properties().

Helps shorten write_properties() a bit. Want to keep it manageable when
adding some new stuff.
dts: gen_defines.py: Add helper for outputting {} initializers

The

    "{" + ", ".join(...) + "}"

pattern is in a bunch of places now. Add an out_dev_init() helper for
it, with the same parameters as out_dev().

@ulfalizer
Copy link
Collaborator Author

ulfalizer commented Dec 14, 2019

@KAGA164
Try it out when you have the time and tell me what you think.

Might make sense to have it ignore compatible = ... in the child nodes if it shows up, but it's not a problem for child-binding: at least. I kept it small.

Copy link
Collaborator

@pabigot pabigot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Block until we come to agreement in #21369 about how devicetree paths are to be mapped to symbols that won't conflict.

Also the implicit dependency on the order that properties are listed in the binding is not maintainable.

@KAGA164
Copy link
Collaborator

KAGA164 commented Dec 16, 2019

@ulfalizer Thanks for this feature. This is exactly what I need.

should_write() returns False for properties that are skipped in
write_properties().

Helps shorten write_properties() a bit. Want to keep it manageable when
adding some new stuff.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Add a new 'generate-child-initializer' flag to bindings. When 'true',
static initializers will be generated for all child nodes of the node,
along with an initializer for an array that includes all the child
nodes.

This can be used to statically initialize structures and arrays derived
from devicetree data, e.g. for a list of LEDs.

See the updated documentation in doc/binding-template.yaml for more
information.

Fixes: zephyrproject-rtos#21239

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
The

    "{" + ", ".join(...) + "}"

pattern is in a bunch of places now. Add an out_dev_init() helper for
it, with the same parameters as out_dev().

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
@galak
Copy link
Collaborator

galak commented Apr 17, 2020

Closing this as we are moving to the new generator / dt macro's

@galak galak closed this Apr 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Tooling PR modifies or adds a Device Tree tooling
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants