This commit introduces devicetree API in CMake so that devicetree
properties and register block can be used in the CMake build system.
The script scripts/dts/gen_dts_cmake.py processes the edt.pickle and
generates a corresponding devicetree property map in a devicetree_target
that is then used in CMake.
The following devicetree API has been made available in Zephyr CMake:
- dt_nodelabel(<var> NODELABEL <label>)
- dt_node_exists(<var> PATH <path>)
- dt_node_has_status(<var> PATH <path> STATUS <status>)
- dt_prop(<var> PATH <path> PROPERTY <prop>)
- dt_prop(<var> PATH <path> INDEX <idx> PROPERTY <prop>)
- dt_num_regs(<var> PATH <path>)
- dt_reg_addr(<var> PATH <path> [INDEX <idx>])
- dt_reg_size(<var> PATH <path> [INDEX <idx>])
- dt_has_chosen(<var> PROPERTY <prop>)
- dt_chosen(<var> PROPERTY <prop>)
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Now that the infrastructure we need is in place, we can allow every
element of DTS_ROOT to have its own dts/bindings/vendor-prefixes.txt
file instead of just special-casing ZEPHYR_BASE (which is always in
DTS_ROOT).
This treats all modules equally and eases out of tree management of
downstream-specific vendor prefixes.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
It's a bit weird to loop over the same list twice like this.
Just unify the two loops into one.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
The file <board>.dts_compiled was made obsolete in 8d8b06978c.
<board>.dts_compiled contains only a reference to zephyr.dts.
Users interested in devicetree should be familiar with zephyr.dts,
therefore it's time to remove the unused <board>.dts_compiled.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Make sure the flags in EXTRA_DTC_FLAGS are valid for the version of dtc
we have and only invoke dtc with flags it supports.
Fixes#32644
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Treat shield directories containing a dts subdirectory as a DTS root
directory.
This allows shield specific devicetree include files and bindings to be
stored under the shield dts subdirectory.
Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
Since EXTRA_DTC_FLAGS will be ';' seperated if we pass that as is if
there are multiple items in the list we'll get an error. Sanitize
EXTRA_DTC_FLAGS by replacing ';' with ' ' before we call gen_defines.py
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Generate a header (device_extern.h) that handles extern of possible
device structs that would come from devicetree. This removes the need
for DEVICE_DT_DECLARE and DEVICE_DT_INST_DECLARE which we can remove.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
We're well past Zephyr v1.16 (which turned out to be v2.1,
since v1.14 was followed by v2.0), so remove a message about a
variable that's been obsolete for two versions before that.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit introduces support for versioning of boards.
The existing board handling is limited in such a way that it is not
possible to support a specific board in multiple variants.
This commit introduces versioning of board revisions so that it is
possible to support minor variations to a board without having to
defining a completely new board.
This can be done by adding a revision.cmake file in the board folder:
boards/<arch>/<board-dir>/revision.cmake
Depending on the revision format chosen, additional configuration files
for each revision available must also be added, those have the form:
boards/<arch>/<board-dir>/<board>_<revision>.conf
Examples:
boards/<arch>/<board-dir>/<board>_defconfig: Common board settings
Revision format: MAJOR.MINOR.PATCH
boards/<arch>/<board-dir>/<board>_0_5_0.conf: Revision 0.5.0
boards/<arch>/<board-dir>/<board>_1_0_0.conf: Revision 1.0.0
boards/<arch>/<board-dir>/<board>_1_5_0.conf: Revision 1.5.0
Revision format: LETTER
boards/<arch>/<board-dir>/<board>_A.conf: Revision A
boards/<arch>/<board-dir>/<board>_B.conf: Revision B
The `board_check_revision` function is available in `extensions.cmake`
to facilitate board revision handling in `revision.cmake`.
User select the board revision using: `-DBOARD=<board>@<revision>`, as
example `-DBOARD=plank@0.5.0`.
If a shield, test, sample, or application needs to specify DTS overlay
or Kconfig fragments, this can be done by adding revision specific
configuration files in the sample/test/shield folder, like this:
<shield/sample-path>/boards/<board>.conf
<shield/sample-path>/boards/<board>_<revision>.conf
or if there is there is only a need for adjusting on a given board
revision:
<shield/sample-path>/boards/<board>_<revision>.conf
Similar for DTS overlay files:
<shield-path>/boards/<board>.overlay
<shield-path>/boards/<board>_<revision>.overlay
or:
<shield-path>/boards/<board>_<revision>.conf
For test/samples/apps:
<sample-path>/<board>.overlay
<sample-path>/<board>_<revision>.overlay
or:
<sample-path>/<board>_<revision>.overlay
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Fixes: #28893
Now using get_filename_component(REALPATH) to ensure full path with
symlinks and `..` resolved.
Having `..` in path causes the gcc generated dependency file to contain
`\` in path on windows. This confuses ninja.
The result is that ninja consider the file missing, and thus invokes a
CMake run to create the file, resulting in endless loop.
By ensuring that full path (containing `/` which is already ensured)
when calling gcc, then all paths will be posix style, making ninja
happy.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
This commit fixes an issue where providing a list of overlay files for
dts was not handled correctly.
The means that using `-DDTC_OVERLAY_FILE="file1.overlay;file2.overlay"`
would fail as those two file names would be concatenated into a single
file name.
This is fixed by properly quote the `DTC_OVERLAY_FILE` variable.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
The legacy macros were first deprecated in Zephyr v2.3. Now that
Zephyr v2.4 has been released, that makes two releases where these
macros have been deprecated, so it's OK to remove them.
This leaves support for legacy binding syntax in place. Removing that
is left to future work.
We need to update various pieces of documentation related to flash
partitions that never got updated when the new API was introduced.
Consolidate this information in the flash_map.h API reference page,
since that's really where users will run into it. This also gives us
the opportunity to improve this documentation.
Adjust a couple of kconfigfunctions.py and sanitycheck bits to use
non-legacy edtlib APIs.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Fixes: #23825
Today, BOARD, SOC, ARCH, DTS, KCONFIG, and TOOLCHAIN_ROOT can be
specified by users or through other CMake files.
It is not clear if relative paths are permitted and/or from where a
relative path is constructed.
Inside CMake, it is very easy to specify `${ZEPHYR_BASE}`,
`${CMAKE_CURRENT_SOURCE_DIR}`, or similar, thus there is no reason to
use relative path inside CMake, as it easy can lead to discussion on
relative to what.
For users manually invoking CMake using, `cmake ... <app-dir>` it is
nice to have to possibility to specify a relative path.
For this purpose, relative path are considered relative to the
`APPLICATION_SOURCE_DIR`.
This commit updates:
- BOARD_ROOT
- SOC_ROOT
- ARCH_ROOT
- DTS_ROOT
- KCONFIG_ROOT
- TOOLCHAIN_ROOT
to allow paths relative to `APPLICATION_SOURCE_DIR` when specified with
`-D<type>_ROOT=<relative-path>`
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
MWDT CCAC compiler can't handle the dts file as gcc does, so
allow to specify compliler for DTS preprocessing which is differ
from ${CMAKE_C_COMPILER}.
Use ARC GNU compiler for DTS preprocessing in case of MWDT
toolchain.
Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Fixes: #26112
All file paths provided on the list of overlay files are converted to
CMake style paths.
This ensures that even paths with mixed style `\` and `/` on Windows are
treated correctly. This fixes the issue where the deps file created
would cause ninja to re-invoke CMake in an endless loop on windows.
Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
In some cases it is useful to use the C preprocessor to control the
content of a devicetree file. A specific use case is in testing,
where different combinations of node properties must be checked.
Provide a mechanism to allow arbitrary preprocessor flags to be passed
through CMake to affect the devicetree content.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Consolidate creation of edtlib.EDT objects from a build directory's
devicetree into one place by loading it from build/zephyr/edt.pickle
everywhere. A previous commit creates edt.pickle from gen_defines.py.
In addition to probably speeding things up slightly by not reparsing
the devicetree, the main benefit of this approach is creating a single
point of truth for the bindings directories and warnings
configuration, meaning we don't have to worry about them getting out
of sync while being passed around between devicetree creation and
usage time.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
We need to save and restore the devicetree data to generate optimized
dependency information later on in the build, in particular during the
final application link.
Make this happen by pickling the EDT object in BUILD_DIR/edt.pickle.
The existence of this file is an implementation detail, so do not add
it to the documentation.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Since gen_defines.py is run using execute_process() at CMake time, the
entire build system must be regenerated if it changes. Add the
dependency tracking to make this possible.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
The last user of the .conf file format DTS data has been removed. We
can now remove the generation and associated support for the .conf file.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This is joint work with Kumar Gala (see signed-off-by).
This supports a new devicetree macro syntax coming. It's not really
worth mixing up the old and the new generation scripts into one file,
because:
- we aim to remove support for the old macros at some point, so it
will be cleaner to start fresh with a new script based on the old one
that only generates the new syntax
- it will avoid regressions to leave the existing code alone while
we're moving users to the new names
Keep the existing script by moving it to gen_legacy_defines.py and
changing a few comments and strings around. It's responsible for
generating:
- devicetree.conf: only needed by deprecated kconfigfunctions
- devicetree_legacy_unfixed.h: "old" devicetree_unfixed.h macros
Put a new gen_defines.py in its place. It generates:
- zephyr.dts
- devicetree_unfixed.h in the new syntax
Include devicetree_legacy_unfixed.h from devicetree.h so no DT users
are affected by this change.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This rename is mostly to easy git managment and review so any changes or
the addition of the new gen_defines.py doesn't look like a diff against
the old code if you look at just that commit.
We keep changes to a minimum to just keep things building with the
renamed gen_legacy_defines.py.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Pass arguments as command line from cmake to python. Extra DTC flags are
used later on to check errors in python.
Signed-off-by: Andrei Gansari <andrei.gansari@nxp.com>
Add a '--dts-out <file>' flag to gen_defines.py that saves the final
devicetree to <file>, in DTS format, using the new EDT.dts_source
attribute.
Handy to have available as a debugging aid. Unused otherwise.
Also write a dummy <BOARD>.dts_compiled file that tells people to look
at zephyr.dts, for people that might be used to that file. It was
removed in commit 8d8b06978c ("dts: Remove generation of
<BOARD>.dts_compiled").
Fixes: #22272
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
dtc is only used for static analysis (producing warnings) of the
DeviceTree sources. This means that valid Zephyr firmware can sanely
be built without it.
For some users, for instance Windows users that are not permitted to
use Chocolatey, installing dtc is problematic and installing it is not
worth the DT warnings that it provides.
To make using Zephyr easier for these users we make using DTC
recommended and opt-out, instead of mandatory.
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
generated_dts_board.h is pretty redundant and confusing as a name. Call
it devicetree.h instead.
dts.h would be another option, but DTS stands for "devicetree source"
and is the source code format, so it's a bit confusing too.
The replacement was done by grepping for 'generated_dts_board' and
'GENERATED_DTS_BOARD'.
Two build diagram and input-output SVG files were updated as well, along
with misc. documentation.
hal_ti, mcuboot, and ci-tools updates are included too, in the west.yml
update.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Unused after the old devicescript were removed in commit c8c35f76ab
("scripts: dts: Remove deprecated extract_dts_includes.py script"). The
old scripts relied on parsing the output of 'dts -Odts', which replaces
e.g. phandle references. The new scripts parse the DTS files directly.
Keep running the dtc compiler just to catch any warnings/errors from it.
The edit to doc/guides/build/build-config-phase.svg is to remove the box
with '*.dts_compiled' in it (and the arrows to/from it). https://draw.io
can be used to edit it.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Change the DTS preprocessor working directory from the binary
directory to the application directory.
This is done so that the user can specify
-DDTC_OVERLAY_FILE=overlay.dts with a relative path from the
application directory as is possible for CONF_FILE, and as is
reasonably expected to be possible by users.
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
We now use EDTS and gen_defines.py to generate DTS defines. We
deprecated the old script and defines several releases ago, so lets now
remove them.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
When generating the dependency file for DTS (${BOARD}.dts.pre.d),
some toolchains would use the source file for the file name stem.
So, the resulting dependency file is empty_file.d instead of one
with the board name. Fix this by passing -MF to explicitly tell
the compiler the name of the dependency file.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
We need this information in the cache now that we're not allowed to
parse generated_dts_board.conf from Python code after build time.
Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
If duplicates gets passed to scripts/dts/gen_defines.py, the bindings in
those directories will be loaded twice and actually get in conflict with
itself.
Signed-off-by: Tobias Svehagen <tobias.svehagen@gmail.com>
Remove the common.dts file which has been used for a year.
common.dts at one point allowed us to conditionally add an MCUBoot
overlay based on Kconfig.
but since DT lost access to Kconfig options it has been unused.
The overridable variable DTS_COMMON_OVERLAYS, which by default points
to common.dts, is also unused in-tree, and any out-of-tree usage can
be ported over to use DTC_OVERLAY_FILE instead, so we remove the
variable as well.
This simplifies the configuration system.
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
When DT sources change CMake must be run again. CMake is currently
detecting changes to DT source files that we manually specify, but not
sources that are included through use of the preprocessor.
This patch makes the preprocessor output the includes used and adds
them to the 'CMAKE_CONFIGURE_DEPENDS' property.
This fixes#16791.
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Should be --bindings-dirs, not --bindings-dir, but the 'argparse' module
supports shortening flags, so it worked anyway.
Broke my grepping though.
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
Add a new DTS/binding parser to scripts/dts/ for generating
generated_dts_board.conf and generated_dts_board_unfixed.h.
The old code is kept to generate some deprecated defines, using the
--deprecated-only flag. It will be removed later.
The new parser is implemented in three files in scripts/dts/:
dtlib.py:
A low-level .dts parsing library. This is similar to devicetree.py in
the old code, but is a general robust DTS parser that doesn't rely on
preprocessing.
edtlib.py (e for extended):
A library built on top of dtlib.py that brings together data from DTS
files and bindings and creates Device instances with all the data for
a device.
gen_defines.py:
A script that uses edtlib.py to generate generated_dts_board.conf and
generated_dts_board_unfixed.h. Corresponds to extract_dts_includes.py
and the files in extract/ in the old code.
testdtlib.py:
Test suite for dtlib.py. Can be run directly as a script.
testedtlib.py (uses test.dts and test-bindings/):
Test suite for edtlib.py. Can be run directly as a script.
The test suites will be run automatically in CI.
The new code turns some things that were warnings (or not checked) in
the old code into errors, like missing properties that are specified
with 'category: required' in the binding for the node.
The code includes lots of documentation and tries to give helpful error
messages instead of Python errors.
Co-authored-by: Kumar Gala <kumar.gala@linaro.org>
Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
We don't generate any CONFIG_ prefixed symbols from dts files so we
don't need to try and import them in anymore.
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
The Particle mesh feather boards provide device-tree overlays that
allow individual applications to select the SPI peripheral to be
used for the pins associated with a specific labelled SPI device.
This is necessary because different peripheral instances have slightly
different properties.
Add BOARD_DIR to DTS_ROOTS so these shared files can be located when
included from application-specific overlays.
Signed-off-by: Peter A. Bigot <pab@pabigot.com>
Just like board's can be placed in out-of-tree BOARD_ROOT's, we now
support DeviceTree sources and bindings being placed in out-of-tree
DTS_ROOT's.
This required for out-of-tree drivers that use DeviceTree.
To implement this we get rid of various user-settable CMake variables
like DTS_APP_BINDINGS, DTS_APP_INCLUDE, and instead have ZEPHYR_BASE,
APPLICATION_SOURCE_DIR and out-of-tree directories conform to using
the same DTS_ROOT concept and directory structure.
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
All DT include directories are system directories, except for
dts/common. There is no reason for dts/common to diverge, so we align
it with the other directories to be consistent.
Also, we move it closer to the other include directories.
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Update the files which contain no license information with the
'Apache-2.0' SPDX license identifier. Many source files in the tree are
missing licensing information, which makes it harder for compliance
tools to determine the correct license.
By default all files without license information are under the default
license of Zephyr, which is Apache version 2.
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Based on work from Sebastian Bøe and updated to current tree.
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
Ensure that changes to DeviceTree sources cause CMake to be re-run
when make/ninja is invoked.
Note that this is not perfect, as it does not cover files that are
\#included, but it will cover most DT changes.
This fixes#12692
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>