Skip to content

Projects with empty devicetree files may fail to compile #63808

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

Closed
gmarull opened this issue Oct 11, 2023 · 0 comments · Fixed by #63799
Closed

Projects with empty devicetree files may fail to compile #63808

gmarull opened this issue Oct 11, 2023 · 0 comments · Fixed by #63799
Assignees
Labels
bug The issue is a bug, or the PR is fixing a bug

Comments

@gmarull
Copy link
Member

gmarull commented Oct 11, 2023

Describe the bug

When we have an empty Devicetree, ie,

/dts-v1/;

/ {

};

The node's dep_ordinal is never initialized because the node graph is empty. This ends up with invalid ordinal tokens (-1) in devicetree_generated.h which in turn produce some cryptic compiler errors, see e.g.

error: pasting "dts_ord_" and "-" does not give a valid preprocessing
token
   95 | #define Z_DEVICE_DT_DEV_ID(node_id) _CONCAT(dts_ord_,
      DT_DEP_ORD(node_id))

...

include/zephyr/devicetree.h:2498:41:
note: in expansion of macro 'DT_FOREACH_OKAY_HELPER'
 2498 | #define DT_FOREACH_STATUS_OKAY_NODE(fn)
      DT_FOREACH_OKAY_HELPER(fn)
            |
	    ^~~~~~~~~~~~~~~~~~~~~~
include/zephyr/device.h:1022:1:
note: in expansion of macro 'DT_FOREACH_STATUS_OKAY_NODE'
     1022 |
	  DT_FOREACH_STATUS_OKAY_NODE(Z_MAYBE_DEVICE_DECLARE_INTERNAL)

(devicetree_generated.h)

...
 #define DT_N_ORD -1
 #define DT_N_ORD_STR_SORTABLE 000-1
...

To Reproduce

Delete board.dts file, try to compile and observe the errors shown above.

Expected behavior

Failure is not due to missing internal Devicetree macros.

Impact

Certain DT paths need to be guarded with HAS_DTS. Blocker for #63696

Logs and console output

See above.

Environment (please complete the following information):

  • OS: Linux
  • Toolchain Zephyr SDK 0.16
  • Commit SHA or Version used 4d59868

Additional context
N/A

@gmarull gmarull added the bug The issue is a bug, or the PR is fixing a bug label Oct 11, 2023
@gmarull gmarull self-assigned this Oct 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug The issue is a bug, or the PR is fixing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant