Commit graph

61 commits

Author SHA1 Message Date
Martí Bolívar 9c92baa73f devicetree: use edt.pickle more
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>
2020-07-23 09:19:45 -05:00
Martí Bolívar 533f451e7e dts: marshal the EDT object for later use
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>
2020-07-08 14:02:44 -05:00
Martí Bolívar ee955c28c4 cmake: re-run if gen_defines changes
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>
2020-04-13 08:22:46 -05:00
Kumar Gala 86887dafde dts: Remove conf file generation support
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>
2020-04-12 09:49:16 -05:00
Martí Bolívar dc85edd2e9 scripts: dts: write new gen_defines.py
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>
2020-03-24 10:11:20 -05:00
Kumar Gala c7f2c89783 gen_defines.py: rename gen_defines.py to gen_legacy_defines.py
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>
2020-03-24 10:11:20 -05:00
Andrei Gansari 77b125a8b3 cmake: pass extra dtc flags to python scripts
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>
2020-02-05 13:04:44 -06:00
Ulf Magnusson edfe5a653e dts: gen_defines.py: Save final devicetree to zephyr/zephyr.dts
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>
2020-01-30 04:27:39 -06:00
Sebastian Bøe 23df708aa3 dtc: Support opting-out of installing dtc
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>
2020-01-28 12:47:54 -06:00
Ulf Magnusson 4e85006ba4 dts: Rename generated_dts_board*.{h,conf} to devicetree*.{h,conf}
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>
2020-01-17 17:57:59 +01:00
Ulf Magnusson 8d8b06978c dts: Remove generation of <BOARD>.dts_compiled
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>
2020-01-14 16:53:12 -05:00
Robert Lubos cb3670c1b5 cmake: dts fixups
Trivial dts.cmake cleanups.

Signed-off-by: Robert Lubos <robert.lubos@nordicsemi.no>
2019-12-18 21:42:43 +01:00
Sebastian Bøe 3a4d547c5a cmake: Change the DTS preprocessing work directory
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>
2019-12-09 16:34:55 -05:00
Kumar Gala c8c35f76ab scripts: dts: Remove deprecated extract_dts_includes.py script
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>
2019-12-09 16:31:42 -05:00
Daniel Leung 68729ad3f8 dts: tell compiler the name of dependency file for output
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>
2019-11-25 07:43:52 -05:00
Martí Bolívar 258b71f8fe cmake: cache DTS bindings directory
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>
2019-11-15 07:53:25 -06:00
Kumar Gala 7573e048ca cmake: dts: Drop loading symbols from generated_dts_board.conf
Now that DT symbols from generated_dts_board.conf are deprecated remove
loading symbols from it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-11-07 08:43:16 -06:00
Tobias Svehagen 4fc6a04eb1 cmake: dts: Remove duplicates from DTS_ROOT
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>
2019-11-06 20:56:16 +01:00
Sebastian Bøe e79768c2df dtc: Remove support for common.dts
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>
2019-10-24 11:01:08 -05:00
Sebastian Bøe 5c57abcc48 cmake: dt: Reconfigure when DTS dependencies change
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>
2019-10-23 17:54:41 +02:00
Ulf Magnusson f15ad9d886 cmake: dts: Fix (harmless) --bindings-dirs typo
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>
2019-09-25 06:11:26 -04:00
Kumar Gala 5735397b9b kconfig: Add new functions to kconfigfunctions to use EDT
Add a new set of functions that utilize EDT so we can move away from the
generated .conf file.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-09-13 11:42:34 -05:00
Ulf Magnusson 62d5741476 dts: Add new DTS/binding parser
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>
2019-07-29 16:22:17 -04:00
Kumar Gala 7f94e71102 cmake/dts: Remove import of CONFIG_ prefixed symbols from dts
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>
2019-07-24 09:33:10 -04:00
Peter A. Bigot 8437ab10eb cmake: DT: Add support for overlays that reference board-provided dtsi
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>
2019-07-11 07:06:35 -04:00
Sebastian Bøe 397abd41c8 cmake: DT: Add support for out-of-tree binding root directories
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>
2019-04-17 16:25:41 -05:00
Sebastian Bøe 9472299226 cmake: DT: Change from -Idts/common to -isystem dts/common
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>
2019-04-17 16:25:41 -05:00
Anas Nashif 3ae52624ff license: cleanup: add SPDX Apache-2.0 license identifier
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>
2019-04-07 08:45:22 -04:00
Kumar Gala 4b4b9bc49b cmake: Run dts before kconfig
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>
2019-02-01 10:16:06 -06:00
Sebastian Bøe 04857d0d59 cmake: Rebuild when DTS sources are modified
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>
2019-01-25 03:02:58 -06:00
Sebastian Bøe c23cc26c73 DeviceTree: Convert 'generated_dts_board.h' into a source file
extract_dts_includes.py has been generating DT output and then
concatenating it with fixup header files to create
'generated_dts_board.h'.

In this patch we instead introduce a source file named
'generated_dts_board.h' and have it \#include the appropriate DT
output and fixup files.

This results in a simpler system because users can now read
'generated_dts_board.h' as C source code to see how fixup files and
generated DT output relate to each other. Whereas before they would
have to either read documentation or python code to gain the same
understanding.

Also, it reduces the scope and complexity of one of our most bloated
python scripts, extract_dts_includes.py.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-01-25 03:02:33 -06:00
Kumar Gala 67e098ab3e cmake: dts: Fix building with dtc 1.4.6
dtc 1.4.6 doesn't support the -Wno-unique_unit_address flag.  We need to
check that the flag is supported before using it on pre dtc-1.4.7
versions.

Fixes #12685

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-01-24 19:13:32 -05:00
Kumar Gala 717aa9cea7 cmake: dts: Tweak warning flags for unit_address check
In Zephyr we have dts in which multiple peripherals can be at the same
MMIO address.  So we want to disable the `unique_unit_address` check via
(-Wno-unique_unit_address).  However, newer dtc support a check that
makes sure if we have duplicate unit-address devices that only one is
enabled.  So if the dtc flag is supported we enable
(-Wunique_unit_address_if_enabled).

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-01-23 09:43:53 -06:00
Erwan Gouriou 0115c47b69 cmake: dts: move to specifying shield on the command line
Rather than specifying SHIELD via Kconfig, we move it to being
specified via the command line, similar to board.

So we can do:

  -DSHIELD=x_nucleo_iks01a1

or, for multiple shields:

  -DSHIELD="x_nucleo_iks01a1 frdm_kw41z"

Following cmake change, update x_nucleo_iks01a1 sample in order
not to enable CONFIG option anymore but set SHIELD cmake option.

Last, update documentation to reflect this change.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-01-18 13:20:59 -06:00
Mark Ruvald Pedersen 0efad5f7fd cmake: Whitespace and commentary fixes
Cosmetics, no functional change expected.
Fixed leading space alignment.
Replaced tabs with spaces.
Emulation error message output is now aligned.

To locate tabs in cmake, the following bash is useful:
grep -PRil "\t" * | grep -i cmake | grep -v ^sanity

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-12-20 12:23:50 +01:00
Sebastian Bøe 2192302c04 cmake: DT: Introduce 'DT_' symbols into the CMake namespace
CMake parses the Kconfig output for 'CONFIG_*' symbols and adds them
to the CMake namespace.

It does the same for DT, but has only been including 'CONFIG_' symbols
and been ignoring the 'DT_' symbols.

For DeviceTree to be useful, it's information needs to be accessible
from CMake, just like Kconfig is.

To this end we also introduce the 'DT_' symbols into the CMake
namespace.

This resolves #11109

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-12-13 07:33:08 -06:00
Sebastian Bøe c842fb88d7 cmake: import_kconfig: Generalize 'import_kconfig' to support DT
Generalize 'import_kconfig' to support parsing symbols with other
prefixes than 'CONFIG_'. This will eventually allow us to also import
'DT_' symbols into the CMake namespace.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-12-13 07:33:08 -06:00
Sebastian Bøe 8037c89606 cmake: Align the DT build logs with Kconfig
Align how DT and Kconfig print log output to be more consistent.

For instance, Kconfig does not state which header file it generates,
so we remove this from DT.

Also, Kconfig states which sources it uses, which is useful to know
when there is a build failure, so we align with Kconfig by printing
the DT source and overlay files.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-11-21 09:43:21 -05:00
Bobby Noelte 098dbfd185 dts: scan application dir for files included by dts
In addition to zephyr/include and zephyr/dts also scan
the dts directory within the application source directory
for files included by the DTS.

Allows to have application specific DTS includes. This
is especially useful for out of tree drivers.

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
2018-11-19 11:41:42 -05:00
Marti Bolivar c9a4058605 cmake: fix dts fixup file location for external SOC
The board is done correctly, but there's a missing SOC_DIR.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-11-14 23:32:23 +01:00
Andrzej Głąbek a7c430f36f scripts: dts: Use DT_ prefix in generated labels
Almost all labels generated by the extracting script are now prefixed
with DT_. The only exceptions are:
- stuff with 'base_label' specified in yaml bindings
- items specified by 'regs_config' and 'name_config' dictionaries
  in globals.py module
- FLASH related labels generated by flash.extract() called separately
  from generate_node_definitions(), e.g. FLASH_WRITE_BLOCK_SIZE -
  these are used directly, not through fixups, from existing code
  so I didn't want to touch them now

Labels generated for aliases are additionally prefixed with information
from the 'compatible' property, e.g. DT_GPIO_LEDS_LED0_* is generated
instead of LED0_*. To provide backward compatibility for code that uses
LEDx_* and SWx_* labels in their previous forms, a command line option
named 'old-alias-names' is added to the extraction script. This option
causes that the labels for aliases are generated in both old and new
forms. Currently this option is always enabled in dts.cmake.

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-11-13 10:44:42 -06:00
Sebastian Bøe 075525cfe7 cmake: Add support for out-of-tree shields
Add support for out-of-tree shields. Out-of-tree shields can now be
stored in out-of-tree board directories.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-11-06 16:16:01 -05:00
Daniel Leung 3829cb5c41 cmake: parameterized flags to not include standard defines/files
Not all compiles/linkers support the GCC flags to not include standard
defines, include files and libraries. So make these parameters such
that the toolchain can define them when supported.

Also, according to documentation, -nostdlib does the same for both
-nostartfiles and -nodefaultlibs. So remove the redundant ones.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-11-01 16:30:02 -04:00
Sebastian Bøe d0fc988e9f cmake: Error-out when dts.fixup files are detected
The filename dts.fixup is deprecated, dts_fixup.h should be used
instead. This commit detects when fixup files have not been renamed
and errors out with a warning.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-10-08 11:38:56 -04:00
Sebastian Bøe 8eb734cd82 DT: Rename from dts.fixup to dts_fixup.h
The Zephyr configuration system uses many different files in many
different formats. It makes it a lot easier for users to understand
what these files do if when we use the correct file extensions.

To this end we rename the dts.fixup files to the correct file
extension '.h'.

This is a breaking change for out-of-tree fixup files. Such files will
be detected and given an appropriate error message.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-10-08 11:38:56 -04:00
Kumar Gala c361405e90 dts: Reduce include paths for building dts
Drop a few paths from when we preprocess the dts.  This is to reduce
creep of where #defines might get resolved from.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-10-04 07:48:05 -05:00
Sebastian Bøe f612c3c167 dts: Allow users to pass extra flags to DTC
Allow application build scripts to pass extra flags to DTC, this could
for instance be done to enable/disable warnings.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-10-03 08:22:44 -05:00
Sebastian Bøe e8b501976c dts: Treat a missing 'reg property warning' as an error
As far as testing can tell, all occurences of the "Node has a unit
name, but no reg property" warnings have been fixed. To prevent them
from re-appearing we turn the warning into an error.

This is a breaking change for out-of-tree boards that are affected by
the warning.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-10-03 08:22:44 -05:00
Sebastian Bøe fd8022ae16 cmake: Misc. cleanups of how BOARD_ROOT and BOARD_DIR are used
Misc. refactorings that clean up how BOARD_ROOT and BOARD_DIR are
used.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-10-01 09:46:46 -04:00
Sebastian Bøe 350c3d7734 dts: Simplify overlay build scripts
Miscellaneous refactorings to simplify the overlay build scripts.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-09-21 18:51:26 -04:00