Commit graph

81 commits

Author SHA1 Message Date
Patrick Boettcher 55109ae5fb cmake: give an assert a useful message
When the ZEPHYR_GCC_VARIANT-variable is not set properly no
message is printed, whereas this small change will help users
to easier understand why things are not working. Here: they forgot
to set an ENV-variable.

Signed-off-by: Patrick Boettcher <patrick.boettcher@posteo.de>
2018-01-29 14:32:01 +01:00
Anas Nashif de311407bd scripts: fix ram_reports and generate bin file if missing
Some boards do not generate .bin files by default, this file is however
needed when generating ram/rom reports, so in case it is not present,
create it.

Fixes #5784

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-29 05:16:52 +05:30
Jimmy Huang 4a243ffce9 arch: arc: use default optimization flag
The work-around previously setting ARC builds to use -O2 to fix an
ADC bug #3797 is no longer needed, we should this patch and revert
to the default -Os flag to optimize for smaller size.

Signed-off-by: Jimmy Huang <jimmy.huang@intel.com>
2018-01-25 07:56:58 +05:30
Ding Tao d187da4922 cmake: Fix missing braces around interface
Error occurred when using target_link_libraries in CMakeLists.txt:

Cannot specify link libraries for target "interface" which is not built
by this project.

Replace "interface" with "${interface}".

Signed-off-by: Ding Tao <miyatsu@qq.com>
2018-01-23 17:42:05 +05:30
Sebastian Bøe 690bea3a3c cmake: Fix "make usage" regression from the ZEPHYR_BASE change
$ENV{ZEPHYR_BASE} was recently search-replaced with ${ZEPHYR_BASE},
but some CMake code, like usage.cmake, is run by a seperate CMake
build system that does not have access to the CMake variable
ZEPHYR_BASE.

This patch reverts the usage of ${ZEPHYR_BASE} back to use
$ENV{ZEPHYR_BASE} in usage.cmake.

This has been proven to work on both Windows and Linux.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-18 10:44:19 -05:00
Sebastian Bøe 2c8aa87138 kconfig: Revert back to old behaviour pre-kconfiglib.py
Run Kconfig on every reconfigure but with different fragments
depending on the situation.

When .config is missing or when a file from merge_config_file has been
modified use the merge_config_file's as input, otherwise use .config
as input.

This should match the behaviour before kconfiglib.py was introduced
and fixes #5673.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-17 07:39:28 -05:00
Sebastian Bøe db31de5df6 Revert "cmake: kconfig: Run Kconfig on every reconfiguration"
This reverts commit a8b361b176.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-17 07:39:28 -05:00
Anas Nashif 54bdccc5bc cmake: do not error on missing 'config'
'conf' is part of the zephyr SDK or need to be built and installed in
the path. We now using python for Kconfig processing, so this is not a
strict requirement and we should be able to build without it. If the
binary is not found, just go on with our business.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-16 17:03:48 -05:00
Marti Bolivar 70a40813df cmake: add optional app_set_runner_args()
Due to a chicken-and-egg problem, it's not possible to call
board_runner_args() directly from an application CMakeLists.txt and
have it take effect:

  - if the board_runner_args() call appears before including the
    boilerplate file, then the function is undefined and an error
    occurs.

  - if the call appears after including the boilerplate file, then
    board_finalize_runner_args() has already been called by the
    relevant runner.board.cmake file, so it won't take effect.

Similarly to the way set_conf_file() works, allow applications to
declare additional runner args by checking if they have provided a
macro named app_set_runner_args(), which contains calls to
board_runner_args(). Using a macro means that we can invoke it with
the definition of board_runner_args() in scope.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2018-01-15 16:21:28 -05:00
Sebastian Bøe 8b6d3ad69b cmake: Improve error messages for detecting libgcc
Use two different variables for the distinct values LIBGCC_FILE_NAME
and LIBGCC_DIR and assert that each of them exists.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-12 08:37:41 -05:00
Sebastian Bøe 15ca6da4c8 cmake: Re-introduce support for CROSS_COMPILE
CROSS_COMPILE is a KBuild feature that was dropped during the CMake
migration. It is now re-introduced. Documentation for it is still
lacking, but at least it now behaves as expected.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-12 08:37:41 -05:00
Sebastian Bøe a896be1192 cmake: toolchain: Misc. comment cleanups
Sync the outdated comments with the code. E.g. there is no
toolchain-clang.cmake, but there is a toolchain-host-gcc.cmake.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-12 08:37:41 -05:00
Sebastian Bøe 4b61bd1b7a kconfig: Prune kconfig files that don't match the ARCH or BOARD
When Kconfiglib was introduced it caused a significant performance
issue. This patch uses pruning to mitigate the performance issue.

The pruning exploits the fact that before the Kconfig database is
parsed we already know what ARCH and BOARD has been selected. So in
theory we could prune away all Kconfig sources that are not related to
the current ARCH or BOARD. In practice, it is only the Kconfig sources
in zephyr/arch/$ARCH and zephyr/board/$ARCH/ that are easy to prune.

Still, that is quite a few Kconfig sources. For qemu_x86 this patch
reduced the number of parsed Kconfig source files from 632 to
272. This pruning resulted in a incremental reconfiguration (time
cmake ..) speedup of 21% (0.56s to 0.46) and a clean build speedup of
4% (Using board qemu_x86 and sample hello_world).

Furthermore, it should be easier to maintain ARCH's and BOARD's
out-of-tree since the user now has a mechanism to redirect where
Kconfig sources are found. But this has not been explored.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-12 07:29:05 -05:00
Sebastian Bøe a8b361b176 cmake: kconfig: Run Kconfig on every reconfiguration
Kconfiglib does not support merging fragments without parsing the
entire Kconfig "database". For Zephyr this means we no longer get a
performance gain from splitting up the fragment-merging and the
.config generation.

This patch removes the seperated merge step and it's associated
caching mechanism. Now we do a full Kconfig execution on every
reconfiguration.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-12 07:29:05 -05:00
Carles Cufi d92769b849 scripts: kconfig: Replace Kconfig exectuables with Python
We have been using a fork of the Linux kernel's Kconfig system to
configure the Zephyr tree. The issue is that this is a native tool
written in C that is not easy to compile for Windows. This patch
replaces the use of the conf executable with kconfig.py, a script that
uses Kconfiglib to generate the .config and autoconf.h files required to
compile Zephyr.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-01-12 07:29:05 -05:00
Carles Cufi 07a64f19ed cmake: Use find_program() to locate the toolchain
Instead of hard-coding the path use find_program(), since that allows
CMake to sort out platform-specific details such as .exe extensions on
Windows.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-01-11 16:05:05 -05:00
Carles Cufi 7d764b35f3 cmake: Use path-corrected version of ZEPHYR_BASE
Instead of accessing the environment variable ZEPHYR_BASE every time we
require accessing the source code root, use an intermediate variable
that has OS path separators correctly set to '/' to avoid issues on
Windows.

Note: This removes the ZEPHYR_SOURCE_DIR CMake variable. External
applications using that will need to change to use the new ZEPHYR_BASE
variable.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-01-11 14:59:03 -05:00
Sebastian Bøe daa39867b8 cmake: sdk: Improve error message when INSTALL_DIR is wrong
Add an assertion that verifies the user has not misconfigured
ZEPHYR_SDK_INSTALL_DIR.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-11 06:39:12 -05:00
Sebastian Bøe c6f367d251 cmake: Give descriptive error to user when cloned with core.autocrlf
Windows users have on multiple occasions cloned Zephyr using a Windows
git client. It seems that the windows git client defaults to
converting line endings from LF to CRLF when cloning repo's. This
breaks at least one of Zephyr's tools (Kconfig).

This patch introduces a sanity check of the environment for MSYS
users.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-10 22:12:27 -05:00
Carles Cufi e29744c0cd cmake: Require 3.8.2 on all platforms, including MSYS2
Now that MSYS2 ships with CMake 3.9.6 there's no need anymore to
downgrade the minimum required CMake version for it.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2018-01-08 11:01:47 -05:00
Anas Nashif 33592e8aa8 cmake: remove IS_TEST handling
Depending on a path inside the Zephyr tree to determine if we are a test
does not scale. Also some samples were marked as TEST while they are
not, just to get some options defined for tests.

Idenitfying a test will be addressed in another patch introducing
CONFIG_TEST.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-08 10:03:57 -05:00
Anas Nashif f746cb3aeb version: fix version handling without extra_version set
Without extra_version, we had an extra - at the end of the version
string.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-08 08:08:45 -05:00
Sebastian Bøe 5d25497f90 cmake: zephyr_get_*: Add support for SKIP_PREFIX
Usually the zephyr_get_* API returns values prefixed with tokens like
-I -system, -D. But sometimes we need the values without these
prefixes, so we introduce the optional SKIP_PREFIX argument.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-04 00:03:25 -05:00
Sebastian Bøe 3c8331d390 cmake: Introduce Zephyr interface libraries
Introduce Zephyr interface libraries to fix #5351.

From the documentation:

A Zephyr interface library is a thin wrapper over a CMake INTERFACE
library. The most important responsibility of this abstraction is to
ensure that when a user KConfig-enables a library then the header
files of this library will be accessible to the 'app' library.

This is done because when a user uses Kconfig to enable a library he
expects to be able to include it's header files and call it's
functions out-of-the box.

A Zephyr interface library should be used when there exists some
build information (include directories, defines, compiler flags,
etc.) that should be applied to a set of Zephyr libraries and 'app'
might be one of these libraries.

Zephyr libraries must explicitly call
zephyr_library_link_libraries(<interface_library>) to use this build
information. 'app' is treated as a special case for usability
reasons; a Kconfig option (CONFIG_APP_LINK_WITH_<interface_library>)
should exist for each interface_library and will determine if 'app'
links with the interface_library.

This API has a constructor like the zephyr_library API has, but it

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-02 22:09:01 -05:00
Sebastian Bøe d5fe808a09 cmake: net: qemu: Don't pass "-serial none" to qemu
I don't know why we have been passing "-serial none" to qemu but it
does not seem to be doing anything useful. So I propose we remove it.

According to the qemu documenation it should be disabling all serial
ports;

"-serial dev
Redirect the virtual serial port to host character device dev. The
default device is vc in graphical mode and stdio in non graphical
mode.

This option can be used several times to simulate up to 4 serial
ports.

Use -serial none to disable all serial ports."

But when we use "-serial none", we always combine it with "-serial
pipe", or "-serial unix", to redirect the serial port, so clearly it
is not disabling all serial ports as it attempting to do.

"-serial none" was first introduced to Zephyr in this commit:
0b54f984b8

As far I can tell, pinging an echo_server works fine without it, so I
suspect that our second -serial flag is overriding it and that it has
no effect.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-02 09:41:54 -05:00
Sebastian Bøe dfe5cb731c cmake: qemu: Don't use the '\$' hack with Ninja
Using the '\$' technique to accept make variables corrupts Ninja build
systems, so avoid using it when generating Ninja files. Not using it
with Ninja means we need to come up with some other mechanism to
support build-time configuration of the QEMU CLI with Ninja.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-30 11:29:24 -05:00
Sebastian Bøe c14013ca2d cmake: generate_inc: Change how the target name is constructed
The generate_inc_file_for_target() extension is a useful wrapper
around the more low-level generate_inc_file(). It takes care of
ensuring that the generated file correctly depends on it's source.

To do so it needs to name and define a custom_target, the name must be
unique, so it was constructed based on the path to the generated file,
but this caused multiple issues.

The intention was that the path of the file would help identify the
target, in hindsight, identifying the target has proven to not be
important.

This patch fixes #5466 by using a random string to construct the
target name instead of the path to the generated file.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-28 18:23:19 -05:00
Sebastian Bøe 5fb5adb34f cmake: Fix target_ld_options()
target_ld_options() was only testing whether a flag could be passed to
the compiler driver when it was compiling an object file. Not whether
a flag could be passed to the compiler driver when it was linking an
elf file.

For most flags, these tests would have the same result, but it does
not for flags like -Wl,--print-memory-usage or -Wl,notaflag.

This patch fixes #5488 by re-using the method from #5459.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-28 11:37:09 -05:00
Sebastian Bøe 4b77b4ad92 cmake: usage: Added posix to list of arch's with boards
Added posix to the list of arch's with boards. Usage will now show
native_posix as one of the available boards.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-28 11:24:21 -05:00
Anas Nashif 4592ff2d5a native: build zephyr.exe for posix arch
To indicate the generated binary is executable on the host, add .exe
extension to the generated ELF file.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-27 14:16:08 -05:00
Anas Nashif fd276aeb42 cmake: cleanup qemu runner configuration
All runner logic was implemented in qemu.cmake, remove the generic stuff
and make qemu.cmake qemu specific.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-27 14:16:08 -05:00
Anas Nashif e32a656962 posix: native: support native runner
This adds support of 'make run' to the native port allowing us to run
applications natively on the host instead of qemu.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-27 14:16:08 -05:00
Anas Nashif c15d3c9126 cmake: support other emulation platforms/runners
Right now we are hardcoded to only qemu, with the native port, we make
this more generic and support this in a plugin mode where a running has
its own cmake definitons implementing the various targets.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2017-12-27 14:16:08 -05:00
Alberto Escolar Piedras 76f7644118 arch: native: Run Zephyr natively in a POSIX OS
A new arch (posix) which relies on pthreads to emulate the context
switching
A new soc for it (inf_clock) which emulates a CPU running at an
infinely high clock (so when the CPU is awaken it runs till completion
in 0 time)
A new board, which provides a trivial system tick timer and
irq generation.

Origin: Original

Fixes #1891

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-27 14:16:08 -05:00
Anas Nashif 2bbe6af07c cmake: add zephyr_link_libraries_ifdef
Link libraries only when config is defined.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-27 14:16:08 -05:00
Anas Nashif 2e9064b7d6 cmake: replace @ in path with _
To avoid warnings from cmake such as:

  'path' is reserved or not valid for certain CMake features, such as
  generator expressions, and may result in undefined behavior.

This can be seen in Jenkins for example where @ is used when multiple
jobs are run on the same machine.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-23 09:13:44 -05:00
Sebastian Bøe fa53e89419 cmake: boilerplate: Define properties earlier
The properties definitions were not doing much because they were
defined after they were used. They were actually overriding the true
properties with "".

Moving them earlier ensures that the properties behave as expected, as
documented global mutable variables.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-19 17:01:47 -05:00
Marti Bolivar 8447b5ea2e cmake: flash: support verbose output toggle
If CMAKE_VERBOSE_MAKEFILE is defined, make flashing and debugging more
verbose.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar 7a3462de7a scripts: runner: use arguments, not environment vars
The various runners (flash/debug scripts) use environment variables to
take arguments. This is legacy behavior which is not desirable.

Use command line arguments instead.

Note: this leaves more general environment variables with publicly
      documented behavior in place for now, for compatibility, e.g.:

      ZEPHYR_FLASH_OVER_DFU, OPENSDA_FW, ESP_IDF_PATH, PYOCD_DAPARG

For example, when using dfu-util to flash arduino_101, instead of
setting DFUUTIL_PID, DFUUTIL_ALT, and DFUUTIL_IMG environment
variables, have the script invocation look like this:

  python3 .../zephyr_flash_debug.py dfu-util flash \
          [common arguments omitted] \
          --pid=8087:0aba --alt=x86_app \
          --img=.../build/zephyr/zephyr.bin

Make similar changes for other runners (openocd, etc.) and
targets (debug, debugserver).

To implement this in the scripts:

  - have the individual scripts/support/runner/some-runner.py files
    register their own command line arguments

  - teach them to construct instances from arguments, not the
    environment

  - have zephyr_flash_debug.py request runners to register command
    line argument parsers, and handle arguments

In the build system:

  - add a new board_runner_args() extension function that board.cmake
    files can use to add to the zephyr_flash_debug.py command line

  - adjust cmake/flash/CMakeLists.txt to invoke with arguments

  - add new helper include files for each runner (like
    boards/common/dfu-util.board.cmake, etc.), which add default
    options as needed and then add on overrides from
    board_runner_args() calls

  - update board.cmake files to use the new includes and extension

This implied some tweaking when using openocd to make the CMake string
escaping and unescaping work properly.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar 94290ee189 cmake: extensions: support list arguments to set_ifndef()
I keep tripping over not being able to use set_ifndef to set a value
to a list, like this:

set_ifndef(VARIABLE value1 value2 value3...)

Allow that to work without changing its existing behavior when called
with one argument.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar e33ec242fd scripts: refactor flash/debug scripts to remove "shell"
The Python-based runners have replaced the old shell scripts. Refactor
the build system accordingly:

- FLASH_SCRIPT is now BOARD_FLASH_RUNNER
- DEBUG_SCRIPT is now BOARD_DEBUG_RUNNER

The values, rather than being the names of files, are now the names of
runners in scripts/support/runner. They are still short, descriptive
names like "openocd", "jlink", "em-starterkit", etc.

Adjust the zephyr_flash_debug.py call and runner internals
accordingly. Have each runner class report a name and the commands it
can handle. This lets us move some boilerplate from each do_run()
method into the common run() routine, and enables further improvements
in future patches.

The handles_command() method is temporary, and will be replaced by a
more general mechanism for describing runner capabilities in a
subsequent patch. The initial use case for extending this is to add
device tree awareness to the runners.

To try to avoid user confusion, abort the configuration if an
xxx_SCRIPT is defined.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Marti Bolivar f8e0a0c519 cmake: extensions: add assert_not()
To be used in a later patch.

Signed-off-by: Marti Bolivar <marti@opensourcefoundries.com>
2017-12-15 09:57:30 -05:00
Sebastian Bøe 11c020ebf7 cmake: Support installing toolchains in "Program Files"
Support installing toolchains in "Program Files", or more generally,
in paths that contain whitespace. This is a common bug for new users
to discover.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-12 11:53:45 -06:00
Sebastian Bøe c87d262295 size_report: Use the CMake-discovered toolchain instead of ENV vars
size_report was using the environment variables NM and OBJDUMP to find
it's toolchain dependencies. It is not clear how well this will work
on different platforms; OSX, Windows. So we now pass the paths of
these dependencies from the build system to the script.

PS: This ensures that size_report uses the cross-compiler's GNU bin
tool instead of the host GNU bin tools. This is presumably beneficial
as it has been required for other GNU bin tools like GDB.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-12 11:42:05 -05:00
Sebastian Bøe 6a2a94b124 cmake: qemu: Allow -kernel to be overridden
This is needed by platforms like jailhouse.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
Signed-off-by: Gustavo Lima Chaves <gustavo.lima.chaves@intel.com>
2017-12-12 09:31:31 -05:00
Sebastian Bøe e0e7a7d852 cmake: Reorganize how qemu is found
We don't want to pollute core-infrastructure with board-specific code,
so we move the qemu discovery to after board.cmake has been executed,
and we introduce the overridable QEMU_binary_suffix CMake variable.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-12 09:31:31 -05:00
Gustavo Lima Chaves fb7f914cc7 cmake: call the right QEMU binary on Jailhouse's make run target
In that case, QEMU is emulating the base (root system) that will be
partitioned to receive Zephyr as one of the cells/guests, not the direct
system Zephyr will run on. We need this one more level of indirection,
otherwise it's impossible to attest Zephyr is running in a virtualized
environment in QEMU.

Fix QEMU binary to point to the x86_64 version, then, once Jailhouse is
targeted at that architecture.

Finally, don't pass QEMU the -kernel flag in this case, since Zephyr has
to loaded manually, from inside QEMU, for Jailhouse's make run target.

Signed-off-by: Gustavo Lima Chaves <gustavo.lima.chaves@intel.com>
2017-12-12 09:31:31 -05:00
Sebastian Bøe b0c4316190 cmake: Show usage when an invalid board is given
Print the usage when an invalid board is given, this somewhat
allievates the catch-22 where you need to run CMake to know what
boards exist, but you need a board to run CMake.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-10 19:51:21 -05:00
Sebastian Bøe 6c8ebab183 cmake: Added assert that will show usage
There is a catch-22 in that you need to run CMake to get a build
system that can show you usage, but you need to know the usage to be
able to get a build system.

This assert could be used to improve the usability somewhat. When
invalid usage is detected it can be used to print the usage.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-10 19:51:21 -05:00
Sebastian Bøe 6a61d5f82c cmake: Fix the dependency between qemu and the elf file
I can't explain why "make run" worked before, but after this patch it
should definitely work.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-07 08:09:12 -06:00