Commit graph

466 commits

Author SHA1 Message Date
Torsten Rasmussen d38da9d386 cmake: runners dependencies cleanup
This commit renames `FLASH_DEPS` to `RUNNERS_DEPS`.
The current name `FLASH_DEPS` is misleading in the sense that this
depency is added to all runner targets, flash, debug, debugserver,
attach, and not only the flash runners.

Therefore this is now named `RUNNERS_DEPS` instead.

Similar, zephyr_property_target now contains the property
FLASH_DEPENDENCIES, DEBUG_DEPENDENCIES, and so on, so that additional
dependencies can be added for each runner.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-07-01 07:58:10 -04:00
Kumar Gala 9ca541a504 linker: Remove deprecated Kconfig options related to linker scripts
Remove Kconfig, linker script, and related bits associated with
CUSTOM_RODATA_LD, CUSTOM_RWDATA_LD, CUSTOM_SECTIONS_LD,
SOC_NOINIT_LD, SOC_RODATA_LD, and SOC_RWDATA_LD options that have been
deprecated since Zephyr 2.2.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-12 11:14:28 +02:00
Torsten Rasmussen 4df38c7916 cmake: remove direct call to cmake and use ${CMAKE_COMMAND} instead
This commit removes an occurence of `cmake` and instead uses the correct
form ${CMAKE_COMMAND}.

This fixes issues where CMake is invoked without being present in the
system PATH.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-06-11 08:24:14 -04:00
Andrew Boie fed960b94a net: tag net socket objects
Used for permission validation when accessing the associated file
descriptors from user mode.

There often get defined in implementation code, expand the search
to look in drivers/ and subsys/net/.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-06-03 22:33:32 +02:00
Andrew Boie 5960119f16 scripts: parse_syscalls: generalize struct tags
Now we can build up lists of data structures matching a list
of particular tags, with __subsystem being just one case.

Relax searches to also look inside C files, since struct
prototypes may be declared there as well.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-06-03 22:33:32 +02:00
Martí Bolívar 21c7d42a64 cmake: warn on dts_fixup.h files
These have been removed from the tree. Warn out of tree users about
support for them eventually being removed entirely.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
2020-05-13 18:21:18 +02:00
Rohit Gujarathi 35713f2ef6 cmake: Assembly listing containing all sections
Added support for creating an assembly listing containing all sections
like rodata, data and debug sections, not just those expected to
contain instructions.

Signed-off-by: Rohit Gujarathi <gujju.rohit@gmail.com>
2020-05-08 09:03:18 -04:00
Torsten Rasmussen 2da4550591 cmake: Set the ZEPHYR_<MODULE_NAME>_MODULE_DIR in parent scope
To allow samples to obtain `ZEPHYR_<MODULE_NAME>_MODULE_DIR` it is
necessary to also ensure the module variable is available in parent
scope.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-05-07 23:26:18 -05:00
Andy Ross cfeb07eded kernel/timeout: Enable 64 bit timeout precision
Add a CONFIG_TIMEOUT_64BIT kconfig that, when selected, makes the
k_ticks_t used in timeout computations pervasively 64 bit.  This will
allow much longer timeouts and much faster (i.e. more precise) tick
rates.  It also enables the use of absolute (not delta) timeouts in an
upcoming commit.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2020-03-31 19:40:47 -04:00
Sebastian Bøe 0d3d7251fc cmake: Fix syscall dependencies
Custom commands must depend on both the input files and the wrapper
targets for the input files.

See Sam Thursfield's blog post about "CMake: dependencies between
targets and files and custom commands" for why.

This fixes #23562

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2020-03-31 10:20:38 -04:00
Sebastian Bøe d9cca03036 cmake: Remove superflous dependency of obj_list
OBJ_LIST depends on ZEPHYR_PREBUILT_EXECUTABLE which again
transitively depends on PARSE_SYSCALLS_TARGET, so adding this
dependency is unnecessary.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2020-03-31 10:20:38 -04:00
Torsten Rasmussen d7862cf776 cmake: using ${ZEPHYR_BASE} instead of $ENV{ZEPHYR_BASE}
With the introduction of ZephyrConfig.cmake all parts of CMake code
should rely on the CMake ZEPHYR_BASE variable instead of the environment
setting.

This ensures that after the first CMake invocation, then all subsequent
invocation in same build folder will use same zephyr base.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-03-27 16:23:46 +01:00
Carles Cufi 1c79096559 ext: debug: Move ctf_map.h to subsys/tracing/ctf
To complete the removal of the ext/ folder, move the ctf_map.h file to
where it really belongs, which is subsys/tracing/ctf.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2020-03-20 22:56:19 -04:00
Andrew Boie 28be793cb6 kernel: delete separate logic for priv stacks
This never needed to be put in a separate gperf table.
Privilege mode stacks can be generated by the main
gen_kobject_list.py logic, which we do here.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-17 20:11:27 +02:00
Andrew Boie 2dc2ecfb60 kernel: rename struct _k_object
Private type, internal to the kernel, not directly associated
with any k_object_* APIs. Is the return value of z_object_find().
Rename to struct z_object.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-17 20:11:27 +02:00
Andrew Boie c1c54b13a6 build: prevent subsystems.json from being gen
Actual files make terrible dependency targets in CMake.
Wrap the generation of subsystems.json into a custom
target to get around this. Fixes a problem where
parse_syscalls.py was being called multiple times.

Fixes: #23504

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2020-03-17 18:07:54 +02:00
Corey Wharton ccd15df510 scripts: Dynamically add driver subsystems to subsystems list
This change extends the parse_syscalls.py script to scan for a
__subsystem sentinal added to driver api declarations. It thens
generates a list that is passed into gen_kobject_list.py to extend
the subsystems list. This allows subsystems to be declared in the
code instead of a separate python list and provides a mechanism for
defining out-of-tree subsystems.

Signed-off-by: Corey Wharton <coreyw7@fb.com>
2020-03-11 17:13:39 +02:00
Sebastian Bøe f17428a009 cmake: Have gperf be opt-out instead of mandatory
gperf is only used when CONFIG_USERSPACE is enabled. Users that use
arch's that don't support CONFIG_USERSPACE, or happen to not never
enable CONFIG_USERSPACE should not be artificially required to install
gperf.

This change makes gperf optional by moving it's presence-check to it's
usage.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2020-02-08 09:13:45 -05:00
Ulf Magnusson de42aea18f kconfig/cmake: Check that one of the CONFIG_<arch> symbols is set
All SoCs must now 'select' one of the CONFIG_<arch> symbols. Add an
ARCH_IS_SET helper symbol that's selected by the arch symbols and
checked in CMake, printing a warning otherwise.

Might save people some time until they're used to the new scheme.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2020-02-08 00:50:08 -06:00
Sebastian Bøe fdac7b3319 cmake: Add target for generating header files
Before C sources can be compiled any generated header that they
include must be generated. Currently, the target 'offsets_h' happens
to depend directly or indirectly on all generated headers.

This means that to compile safely, one can simply depend on
'offsets_h'. But this is coincidental and might not be true in the
future.

To be able to safely depend on a target that represents all generated
headers being ready we introduce the target
'zephyr_generated_headers'.

Any third-party build scripts can now safely depend on
'zephyr_generated_headers' and be protected from any internal changes
to the build system, like the removal of offsets_h.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2020-01-29 11:44:57 -06:00
Peter Bigot 235a5e5e4b cmake: remove include/drivers from include lists
Files that need something from this directory should be using the
prefix, e.g. <drivers/sensor.h> instead of just <sensor.h>.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
2020-01-26 17:52:12 +01:00
Sebastian Bøe d3a8fd40b9 cmake: Add option for exporting build metadata to Make
Add an opt-in feature that will generate a Makefile with build
variables like CC, and KBUILD_CFLAGS for consumption by third-party
Make-based build systems.

This emulates the 'outputexports' target that KBuild supported and is
supported for the same reasons that KBuild supported it. Easier
integration with third-party build systems.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2020-01-23 15:09:12 -05:00
Sebastian Bøe 56f6e35e47 cmake: Support passing syscall include directories through CMake
Introduce the CMake variable SYSCALL_INCLUDE_DIRS to support
out-of-tree syscall declarations.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2020-01-22 09:26:12 -05: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
Vincent Wan 180b4df229 soc: kconfig: add SOC_DEPRECATED_RELEASE
Adding a Kconfig parameter so that we can indicate an SoC is to be
deprecated, similar to what is being done for BOARD_DEPRECATED_RELEASE.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-01-13 10:21:12 -05:00
Vincent Wan a2bc514653 boards: Kconfig: rename BOARD_DEPRECATED to BOARD_DEPRECATED_RELEASE
Renaming this Kconfig option given it corresponds to a version string
for a particular release.

Signed-off-by: Vincent Wan <vincent.wan@linaro.org>
2020-01-13 10:21:12 -05:00
Torsten Rasmussen 4b68f959b5 cmake: locating zephyr modules in CMAKE_BINARY_DIR
This commit restores the old behaviour of locating Zephyr modules under
CMAKE_BINARY_DIR instead of CMAKE_CURRENT_BINARY_DIR during building of
Zephyr modules.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2020-01-09 14:33:36 -05:00
Håkon Øye Amundsen c9a2a5e7fb scripts: cmake: move print from python to cmake
Prior to this all hex files included in a merge would
be printed on every invokation of cmake.

Allow the user to explicitly require this information
by moving the print to a VERBOSE-only cmake message.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2020-01-03 08:20:08 -05:00
Jack Dähn e41bdcd545 cmake: Fix CMAKE_BUILD_TYPE and OPTIMIZATION_FLAG match check
The check introduced in #18777 uses incorrect CMake syntax.
IN_LIST requires the list variable name, not its content.

Signed-off-by: Jack Dähn <jack@jkdhn.me>
2019-12-20 20:26:20 -05:00
Sebastian Bøe fa8f9d423d cmake: assert: Reduce the verbosity of the assert warning
The warning about CONFIG_ASSERT being enabled is too loud. This patch
reduces it's verbosity and omits the explanation about performance as
this is believed to be obvious.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-12-18 17:11:02 +01:00
Torsten Rasmussen 5a703c8d58 cmake: use zephyr_library_app_memory for mem partition placement
This commit removes the hard coded mbed TLS library name
`lib..__modules__crypto__mbedtls.a` in top-level CMakeLists.txt file
and instead uses zephyr_library_app_memory function.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2019-12-17 13:05:36 -05:00
Torsten Rasmussen 08eabb83b2 cmake: Zephyr module processing set modules path
This commit introduces the variable:
ZEPHYR_${MODULE}_MODULE_DIR that can be used for modules to obtain
locations of other modules.

As example: a module which requires the knowledge of mcuboot con now
fetch this information using ZEPHYR_MCUBOOT_MODULE_DIR.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2019-12-10 17:43:55 +01:00
Andrew Boie c1863875b7 ztest: fix ztest_1cpu_user_unit_test()
The start/stop functions do a whole pile of supervisor-
only stuff; resolve this by making them ztest-specific
system calls.

Fixes: #20927

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-12-09 12:40:47 -05:00
Flavio Ceolin f4adf107f3 syscalls: Remove gen_syscall_header.py
gen_syscall_header.py is not longer necessary, it was just creating a
file including syscall.h. This header is now included directly by
gen_syscalls.py.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-12-09 16:08:50 +01:00
Ioannis Glaropoulos d58f8bee79 cmake: copy globals from libc_nano.a to z_libc_partition
When building with NEWLIB_LIBC_NANO we need to copy
the globals from libc_nano.a into application memory
partition z_libc_partition, exactly as we do for
libc.a globals. This is required so that these globals
are accessible by nPRIV code, when building with
user mode support.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-11-18 09:38:29 -06:00
Stephanos Ioannidis 2d7460482d headers: Refactor kernel and arch headers.
This commit refactors kernel and arch headers to establish a boundary
between private and public interface headers.

The refactoring strategy used in this commit is detailed in the issue

This commit introduces the following major changes:

1. Establish a clear boundary between private and public headers by
  removing "kernel/include" and "arch/*/include" from the global
  include paths. Ideally, only kernel/ and arch/*/ source files should
  reference the headers in these directories. If these headers must be
  used by a component, these include paths shall be manually added to
  the CMakeLists.txt file of the component. This is intended to
  discourage applications from including private kernel and arch
  headers either knowingly and unknowingly.

  - kernel/include/ (PRIVATE)
    This directory contains the private headers that provide private
   kernel definitions which should not be visible outside the kernel
   and arch source code. All public kernel definitions must be added
   to an appropriate header located under include/.

  - arch/*/include/ (PRIVATE)
    This directory contains the private headers that provide private
   architecture-specific definitions which should not be visible
   outside the arch and kernel source code. All public architecture-
   specific definitions must be added to an appropriate header located
   under include/arch/*/.

  - include/ AND include/sys/ (PUBLIC)
    This directory contains the public headers that provide public
   kernel definitions which can be referenced by both kernel and
   application code.

  - include/arch/*/ (PUBLIC)
    This directory contains the public headers that provide public
   architecture-specific definitions which can be referenced by both
   kernel and application code.

2. Split arch_interface.h into "kernel-to-arch interface" and "public
  arch interface" divisions.

  - kernel/include/kernel_arch_interface.h
    * provides private "kernel-to-arch interface" definition.
    * includes arch/*/include/kernel_arch_func.h to ensure that the
     interface function implementations are always available.
    * includes sys/arch_interface.h so that public arch interface
     definitions are automatically included when including this file.

  - arch/*/include/kernel_arch_func.h
    * provides architecture-specific "kernel-to-arch interface"
     implementation.
    * only the functions that will be used in kernel and arch source
     files are defined here.

  - include/sys/arch_interface.h
    * provides "public arch interface" definition.
    * includes include/arch/arch_inlines.h to ensure that the
     architecture-specific public inline interface function
     implementations are always available.

  - include/arch/arch_inlines.h
    * includes architecture-specific arch_inlines.h in
     include/arch/*/arch_inline.h.

  - include/arch/*/arch_inline.h
    * provides architecture-specific "public arch interface" inline
     function implementation.
    * supersedes include/sys/arch_inline.h.

3. Refactor kernel and the existing architecture implementations.

  - Remove circular dependency of kernel and arch headers. The
   following general rules should be observed:

    * Never include any private headers from public headers
    * Never include kernel_internal.h in kernel_arch_data.h
    * Always include kernel_arch_data.h from kernel_arch_func.h
    * Never include kernel.h from kernel_struct.h either directly or
     indirectly. Only add the kernel structures that must be referenced
     from public arch headers in this file.

  - Relocate syscall_handler.h to include/ so it can be used in the
   public code. This is necessary because many user-mode public codes
   reference the functions defined in this header.

  - Relocate kernel_arch_thread.h to include/arch/*/thread.h. This is
   necessary to provide architecture-specific thread definition for
   'struct k_thread' in kernel.h.

  - Remove any private header dependencies from public headers using
   the following methods:

    * If dependency is not required, simply omit
    * If dependency is required,
      - Relocate a portion of the required dependencies from the
       private header to an appropriate public header OR
      - Relocate the required private header to make it public.

This commit supersedes #20047, addresses #19666, and fixes #3056.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2019-11-06 16:07:32 -08:00
Sebastian Bøe e50e12d8d1 cmake: Check if match between CMAKE_BUILD_TYPE and OPTIMIZATION_FLAG
In CMake projects, 'CMAKE_BUILD_TYPE' usually determines the
optimization flag, but in Zephyr it is determined through Kconfig.

To avoid confusing users we now give a warning if there is a mismatch
between the CMAKE_BUILD_TYPE and the optimization flag.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-11-06 21:18:43 +01:00
Marc Herbert eddbf3c986 cmake: -fmacro-prefix-map=${WEST_TOPDIR}=WEST_TOPDIR
Commit 28a5657f1f and f67dcdbdf8 stopped ZEPHYR_BASE and
CMAKE_SOURCE_DIR from leaking into __FILE__ and other macros.
WEST_TOPDIR was still missing. Add it now that the new 'west topdir'
command has been implemented in
https://github.com/zephyrproject-rtos/west/pull/311

If the west version is too old then do nothing; same as before.

Any ASSERT in a zephyr module outside ZEPHYR_BASE is enough to test
this. One example:

$ZEPHYR_BASE/sanitycheck -T $ZEPHYR_BASE/tests/posix/fs/ -p qemu_x86 -v

readelf --string-dump=.rodata.disk_status.str1.1 {} \
  $(find sanity-out -name zfs_diskio.c.obj | head -n 1)

String dump of section '.rodata.disk_status.str1.1':

  [     0]  WEST_TOPDIR/modules/fs/fatfs/zfs_diskio.c
  [    2a]  pdrv < ((long) (((int) sizeof(char[1 - 2 * !(!__built....
  [    de]  ASSERTION FAIL [%s] @ %s:%d^J

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2019-11-06 21:17:56 +01:00
Andrew Boie 9ff64bb497 userspace: don't split args on 64-bit systems
None of the splitting logic is needed if 64-bit return
values or parameters fit inside a register.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-11-06 09:04:16 -08:00
Torsten Rasmussen 1f9723af19 cmake: app mem partion flexibility
This commit allows a more dynamic approach for specifying that a zephyr
library must be placed in a dedicated app memomory partition.
This is still done by defining the partition in code using
K_APPMEM_PARTITION_DEFINE, but now the zephyr library can be added to
the generation of partition table using zephyr_library_app_memory
instead of modifying the overall zephyr/CMakeLists.txt file.

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2019-11-05 08:44:26 -08:00
Torsten Rasmussen f0fa7b850c cmake: zephyr_library_amend feature
This commit introduces the cmake extension zephyr_library_amend.

This function allows for adding files in an out-of-tree Zephyr module
to a zephyr library created in zephyr repo CMake files.

As example:
drivers/entropy/CMakeLists.txt creates an zephyr library as:
zephyr_library()
only available to zephyr itself.

The amend function allows to amend to such a lib, by creating a
CMakeLists.txt file following identical folder structure in a Zephyr
Module:
<zephyr_module_oot>/drivers/entropy/CMakeLists.txt
zephyr_library_amend()
zephyr_library_sources() # Sources are amended to the original library

Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
2019-10-21 17:44:08 +02:00
Sebastian Bøe bb6a6e8fcc cmake: Move the invocation of 'project' earlier
The CMake documentation for 'project' states "Call the project()
command near the top of the top-level CMakeLists.txt". Meaning, it
should be run as early as possible.

An obscure internal error was observed when 'project' was located in
zephyr/CMakeLists.txt and was observed to be fixed after moving
'project' earlier, hence this patch that moves it earlier.

Invoking project depends on knowing information about the toolchain so
it is placed after target_toolchain.cmake.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-10-01 06:26:03 -05:00
Sebastian Bøe 6212ec9612 cmake: Cache the 'toolchain-is-ok' test as well
All compiler flag checks are cached for build-time performance reasons
except for the test that tests the toolchain itself.

It is believed that this test was left uncached because at the time,
there was not enough trust in the caching mechanism. But time has
shown that the caching mechanism is safe. So cache this test as well.

This improves build-time performance and also reduces noise in the
logs.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-09-07 10:25:12 -04:00
Sebastian Bøe 71281292fb cmake: Suppress west module logging
The log from CMake invocation's are now dominated by west
modules. This noise can hide important warnings.

To fix this we drop the logging.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-09-07 10:20:01 -04:00
Kumar Gala d541913fc5 cmake: Build HEX files if flash runner is openocd
The openocd flash runner now expects a hex file, so always build a HEX
image if the runner is set to openocd.

Fixes #18181

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-08-16 13:41:56 -05:00
Sebastian Bøe 5962aab42f cmake: Fix dependency between offset.c.obj and offsets.h
The command for generating offsets.h has only been depending on the
target for offsets.c.obj, and not the file offsets.c.obj itself. Both
are needed, as explained in "CMake: dependencies between targets and
files and custom commands"[0].

This patch adds the dependency and fixes #18301

[0] https://tinyurl.com/y2hgzjhx

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-08-15 17:47:21 +02:00
Paul Sokolovsky 1c6a7d78ef CMakeLists.txt: Call toolchain_cc_nostdinc() at the end
To let any other zephyr_system_include_directories() directives
act first and get these paths in an order allowing Zephyr's stuff
override compiler headers.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-08-08 14:31:35 +02:00
Danny Oerndrup 9336e3ee2c cmake: Toolchain abstraction: Abstraction of binary tool, strip.
This abstracts the interface for generation of the strip command
line, by naming the desired actions instead of directly setting the
command parameters, which then opens up for other binary tool sets
which may require different arguments to achieve the desired result.

The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.

No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
2019-08-02 13:05:59 +02:00
Danny Oerndrup 919df016f9 cmake: Toolchain abstraction: Abstraction of binary tool, readelf.
This abstracts the interface for generation of the readelf command
line, by naming the desired actions instead of directly setting the
command parameters, which then opens up for other binary tool sets
which may require different arguments to achieve the desired result.

The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.

No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
2019-08-02 13:05:59 +02:00
Danny Oerndrup 0760a53d2c cmake: Toolchain abstraction: Abstraction of binary tool, objdump.
This abstracts the interface for generation of the objdump command
line, by naming the desired actions instead of directly setting the
command parameters, which then opens up for other binary tool sets
which may require different arguments to achieve the desired result.

The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.

No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
2019-08-02 13:05:59 +02:00
Danny Oerndrup 51634cd661 cmake: Toolchain abstraction: Abstraction of binary tool, objcopy.
This abstracts the interface for generation of the objcopy command
line, by naming the desired actions instead of directly setting the
command parameters, which then opens up for other binary tool sets
which may require different arguments to achieve the desired result.

The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.

No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
2019-08-02 13:05:59 +02:00
Danny Oerndrup c41e712c6f cmake: Toolchain abstraction: Abstraction of print memory usage.
The method for getting a memory usage report printed during build, is
based on a GNU linker (ld) option flag, and thus is not necessarily
supported by other toolchain binary tools.
The introduced cmake macro allows for a given toolchain to specify how
the memory usage report is to be generated, and whether the command for
generation, if any, is to be added to the post_build_commands and the
post_build_byproducts lists of the top level CMakeLists.txt

The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.

No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
2019-07-31 11:09:35 +02:00
Danny Oerndrup e0569ac2dc cmake: Toolchain abstraction: Abstract compiler flag for add debug info
The macro, toolchain_cc_produce_debug_info, adds the compiler specific
flag for enabling the production of debugging information in the
toolchain native format.

The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.

No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
2019-07-29 16:59:09 +02:00
Carles Cufi 3ad1f27efc cmake: Encode and decode in UTF-8 in build system
In order to make sure that the build works in folders that require a UTF
encoding, make sure that both CMake and the various Python scripts that
interact with each other on files use the same encoding, in this case
UTF-8.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-07-18 16:50:08 +02:00
Andy Ross 50b78f08ea cmake: Remove check_link_map.py
This script is looking for a hyperspecific error (mismatched padding
when linking into two simultaneous output sections) that bit us once,
in an era where the linker scripts were less unified.  We haven't seen
it crop up since, and multiple platforms have changed the way they do
this anyway.

It's needless complexity.  Junk it.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-07-14 04:54:29 -07:00
Nicolas Pitre b86aa65723 CMakeLists.txt: parse zephyr_stdint.h after compiler specific flags
The zephyr_stdint.h file enforces Zephyr specific policies on the
compilation environment. Let's give compilers a chance to provide
definitions of their own via TOOLCHAIN_C_FLAGS prior the inclusion
of zephyr_stdint.h.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-07-03 06:09:16 -04:00
Nicolas Pitre f32330b22c stdint.h: streamline type definitions
Compilers (at least gcc and clang) already provide definitions to
create standard types and their range. For example, __INT16_TYPE__ is
normally defined as a short to be used with the int16_t typedef, and
__INT16_MAX__ is defined as 32767. So it makes sense to rely on them
rather than hardcoding our own, especially for the fast types where
the compiler itself knows what basic type is best.

Using compiler provided definitions makes even more sense when dealing
with 64-bit targets where some types such as intptr_t and size_t must
have a different size and range. Those definitions are then adjusted
by the compiler directly.

However there are two cases for which we should override those
definitions:

* The __INT32_TYPE__ definition on 32-bit targets vary between an int
  and a long int depending on the architecture and configuration.
  Notably, all compilers shipped with the Zephyr SDK, except for the
  i586-zephyr-elfiamcu variant, define __INT32_TYPE__ to a long int.
  Whereas, all Linux configurations for gcc, both 32-bit and 64-bit,
  always define __INT32_TYPE__ as an int. Having variability here is
  not welcome as pointers to a long int and to an int are not deemed
  compatible by the compiler, and printing an int32_t defined with a
  long using %d makes the compiler to complain, even if they're the
  same size on 32-bit targets. Given that an int is always 32 bits
  on all targets we might care about, and given that Zephyr hardcoded
  int32_t to an int before, then we just redefine __INT32_TYPE__ and
  derrivatives to an int to keep the peace in the code.

* The confusion also exists with __INTPTR_TYPE__. Looking again at the
  Zephyr SDK, it is defined as an int, even even when __INT32_TYPE__ is
  initially a long int. One notable exception is i586-zephyr-elf where
  __INTPTR_TYPE__ is a long int even when using -m32. On 64-bit targets
  this is always a long int. So let's redefine __INTPTR_TYPE__ to always
  be a long int on Zephyr which simplifies the code, works for both
  32-bit and 64-bit targets, and mimics what the Linux kernel does.
  Only a few print format strings needed adjustment.

In those two cases, there is a safeguard to ensure the type we're
enforcing has the right size and fail the build otherwise.

Signed-off-by: Nicolas Pitre <npitre@baylibre.com>
2019-06-25 23:29:22 -04:00
Anas Nashif f2cb20c772 docs: fix misspelling across the tree
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-19 15:34:13 -05:00
Marc Herbert 83723109be cmake: silence "WARNING: ASSERTs enabled" when CONFIG_TEST is true
TEST configurations don't need to be warned that they're using test
techniques with some side-effects.

On a typical sanitycheck invocation, this warning is one of the only two
that appears in most test runs. In other words this commit gets rid of
half of the entire grep -ri '[[:blank:]]warn' noise that obscures any
work-in-progress warnings or platform specific warnings in the
logs (typically: device tree warnings).

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2019-06-17 22:47:05 -04:00
Marc Herbert f67dcdbdf8 CMakeLists.txt: -fmacro-prefix-map=${CMAKE_SOURCE_DIR}=CMAKE_SOURCE_DIR
In commit 28a5657f1f we stopped ZEPHYR_BASE from leaking into
__FILE__ and other macros.  This works great for apps inside ZEPHYR_BASE
but does nothing for apps outside ZEPHYR_BASE.
-fmacro-prefix-map=${CMAKE_SOURCE_DIR}=CMAKE_SOURCE_DIR does it.

To avoid collisions and for consistency change:
  -fmacro-prefix-map=${ZEPHYR_BASE}=.
to:
  -fmacro-prefix-map=${ZEPHYR_BASE}=ZEPHYR_BASE

Quickest test/demo:

 - Copy samples/hello_word/ to ~/home_world/
 - Add "%s", __FILE__  to printf in ~/home_world/src/main.c

 cmake -B build  -S ~/home_world/  -DBOARD=qemu_x86
 make  -C build  run

Before:
     ~/home_world/src/main.c says Hello World! qemu_x86

After:
 CMAKE_SOURCE_DIR/src/main.c says Hello World! qemu_x86

objdump -h $(find build -name *.c.obj) | grep noinit

  9 .noinit."ZEPHYR_BASE/kernel/system_work_q.c".0 0000
 17 .noinit."ZEPHYR_BASE/kernel/init.c".2 00000100  000
 18 .noinit."ZEPHYR_BASE/kernel/init.c".1 00000400  000
 19 .noinit."ZEPHYR_BASE/kernel/init.c".3 00000800  000
 16 .noinit."ZEPHYR_BASE/kernel/mailbox.c".2 00000348
 18 .noinit."ZEPHYR_BASE/kernel/mailbox.c".1 00000028
 20 .noinit."ZEPHYR_BASE/kernel/pipes.c".2 00000280  00
 22 .noinit."ZEPHYR_BASE/kernel/pipes.c".1 00000028  00

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2019-06-17 16:21:51 -04:00
Marc Herbert 0370c9b76c cmake: stop destroying intermediate link maps like zephyr_prebuilt.map
The different linker steps are all hardcoded to the output filename
"zephyr.map" and only the last one survives.

Un-harcode.

This removes some confusion when trying to follow who builds
what/when/how and it stops destroying intermediate linking information
useful when tracing/debugging new features or issues in the build.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2019-06-17 12:02:12 -07:00
Danny Oerndrup 6331dae623 cmake: Toolchain abstraction: Introducing macro toolchain_cc_cstd_flag
The macro obtains the toolchain specific flag and value for
setting of the requested c standard.

The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.

No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
2019-06-14 10:25:28 +02:00
Mark Ruvald Pedersen 4052bac93f cmake: Introduce toolchain_ld_link_elf to abstract linker invocation
Final step of linker abstraction:
 * Abstract zephyr_lnk by including it in toolchain_ld_link_elf.
 * Abstract relevant uses of target_link_libraries.
 * Introduce toolchain_ld_force_undefined_symbols.

No functional change expected.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting non-intrusive porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-06-13 14:06:24 +02:00
Danny Oerndrup e34ed7c8e2 cmake: Toolchain abstraction: Introducing macro toolchain_cc_nocommon
The macro is intended to abstract the -fno-common compiler option
which controls the placement of uninitialized global variables. The
macro leaves it up to the toolchain to define the option.

The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.

No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
2019-06-13 13:08:11 +02:00
Danny Oerndrup 4ddbc0096a cmake: Toolchain abstraction: Introducing macro toolchain_cc_imacros
The macro is intended to abstract the -imacros compiler option for
inclusion of the autoconf.h header file. The abstraction allows for a
given toolchain to decide how the inclusion of the header file is to
be done.

The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.

No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
2019-06-12 13:05:40 +02:00
Danny Oerndrup faa72b7015 cmake: Toolchain abstraction: Introducing toolchain_cc_freestanding
The macro is intended to abstract the -ffreestanding compiler option
which tells the compiler that this is a bare metal env. The option is
compiler and thus toolchain specific, but this macro leaves it up to
the toolchain to decide the value of the option.

The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.

No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
2019-06-12 10:16:17 +02:00
Marc Herbert d3d3394893 cmake: warn if inconsistency between CMAKE_SOURCE_DIR and ZEPHYR_BASE
cmake has a number of issues dealing with symbolic links:

  https://gitlab.kitware.com/cmake/cmake/issues/16228

One of them can cause cmake to rewrite the -S input from the user and
CMAKE_SOURCE_DIR to unexpectedly include symbolic links:

  https://cmake.org/pipermail/cmake/2019-May/thread.html#69496

Catch this corner case and warn about subtle issues like breaking
-fmacro-prefix-map=${ZEPHYR_BASE}=

Sample warning message:

CMake Warning at ../../CMakeLists.txt:30 (message):
  ZEPHYR_BASE doesn't match CMAKE_CURRENT_SOURCE_DIR

    ZEPHYR_BASE              = ~/zephyrproject/zephyr
    PWD                      = ~/westsymlink/zephyr/samples/hello_world
    CMAKE_CURRENT_SOURCE_DIR = ~/westsymlink/zephyr

  You may be using a mix of symbolic links and real paths which causes
  subtle and hard to debug CMake issues.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2019-06-11 12:57:18 -04:00
Anas Nashif 6e27d6d3d1 mbedtls: move to external module
Use external module from https://github.com/zephyrproject-rtos/mbedtls

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-11 08:33:53 -04:00
Anas Nashif 3c2e43a19f cmake: build modules under /modules
As we start adding more modules, all of them end up in
${CMAKE_BINARY_DIR}/ and this is getting too busy. We have a module
directory created for each module and the interesting build data is
getting lost in the crowd.

Move all module into ${CMAKE_BINARY_DIR}/modules to and keep them under
one directory.

Future enhancement: maintain the same structure of the modules as
checked out by west.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-05-29 07:27:32 -04:00
Danny Oerndrup 025ffa2492 cmake: Toolchain abstraction: Abstraction of implicit-int error flag
Introducing the macro toolchain_cc_warning_error_implicit_int which,
abstracts the implicit_int error flag thus leaving it to the toolchain
to decide whether this flag is needed or not.

The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.

No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
2019-05-22 15:28:07 +02:00
Danny Oerndrup 8e5a95e4df cmake: Toolchain abstraction: Introduce macros for MISRA SANE flags
The macros are named toolchain_cc_warning_error_misra_sane and
toolchain_cc_cpp_warning_error_misra_sane

These macros provide toolchain specific flag(s) relating to the MISRA
SANE configuration option.
The macros will place the flag(s) in a variable provided by caller,
which can then add to zephyr compile options.

The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.

No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
2019-05-22 15:28:07 +02:00
Danny Oerndrup 8eaa906836 cmake: Toolchain abstraction: Added missing colon to some <at>Intent's
No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
2019-05-22 15:28:07 +02:00
Ulf Magnusson 9b6c2f4bf3 c++: kconfig: Fix choice dependencies and use 'menuconfig' symbol
- Make the 'C++ Standard' choice depend on CPLUSPLUS, so that it only
   shows up when C++ support is enabled.

   Also check that CPLUSPLUS is enabled before checking the standard in
   the top-level CMakeLists.txt, to avoid triggering an assert.

 - The 'C++ Options' menu now contains just CPLUSPLUS and its indented
   children. Remove one menu level by removing the menu and turning
   CPLUSPLUS into a 'menuconfig' symbol. Also change the prompt from
   "Enable C++ support for the application" to just "C++ support for the
   application", to make it consistent with e.g. "Logging".

 - Factor out the common CPLUSPLUS dependency with an 'if CPLUSPLUS'.

 - Order symbol properties more consistently with other Kconfig files,
   with the prompt at the top, etc.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2019-05-16 07:08:21 -05:00
Danny Oerndrup cbbbdeaae5 cmake: Toolchain abstraction: Introduce toolchain_cc_warning_extended
This is placeholder for extended warning flags, likely to change between
toolchains.

The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.

No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
2019-05-14 18:19:18 +02:00
Danny Oerndrup bdb229faff cmake: Toolchain abstraction: Introduce toolchain_cc_warning_base
This is placeholder for base warning flags, common to most toolchains.

The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.

No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
2019-05-14 18:19:18 +02:00
Danny Oerndrup 8650b150b9 cmake: Toolchain abstraction: Introduce toolchain_cc_warning_dw_[1-3]
The introduced macros are placeholders for the cmake parameter warning
level.

The intent here is to abstract Zephyr's dependence on toolchains,
thus allowing for easier porting to other, perhaps commercial,
toolchains and/or usecases.

No functional change expected.

Signed-off-by: Danny Oerndrup <daor@demant.com>
2019-05-14 18:19:18 +02:00
Mark Ruvald Pedersen 197197a579 cmake: Toolchain abstraction: Introduce toolchain_ld_configure_files
No functional change expected.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting non-intrusive porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-05-12 12:50:57 -04:00
Sebastian Bøe f483e5b527 cmake: Mark post_build files as BYPRODUCTS
Mark post_build files as BYPRODUCTS to allow custom commands to depend
on them.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-05-12 12:49:24 -04:00
Mark Ruvald Pedersen 37d494778e cmake: Rename kernel_elf to zephyr_final
* KERNEL_ELF was easily confused with KERNEL_ELF_NAME and KERNEL_NAME.
 * kernel_elf as the name of the binary indicates it somehow only
   contains the kernel, which is not correct.

Rename to zephyr_final as this is the reality: Zephyr elf has been
linked again (a number of times) due to generated kernel files.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-05-08 10:40:39 -04:00
Mark Ruvald Pedersen d7ee114106 cmake: Toolchain abstraction: move PROPERTY_LINKER_SCRIPT_DEFINES
Move PROPERTY_LINKER_SCRIPT_DEFINES to toolchain_ld_base.

No functional change expected.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting non-intrusive porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-05-07 22:17:29 -04:00
Mark Ruvald Pedersen 86a3e8ff40 cmake: Toolchain abstraction: Introduce toolchain_ld_relocation macro
No functional change expected.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting non-intrusive porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-05-04 08:59:53 -04:00
Mark Ruvald Pedersen 5f347eefe6 cmake: move configure_linker_script to ld/target.cmake
While configure_linker_script() may be useful for other linkers, it
currently only aimed at GNU ld. To really be useful among different
linkers, we would need to abstract its usage of the C preprocessor.
We can do this later, if needed.

No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-05-02 21:54:27 +02:00
Mark Ruvald Pedersen fbcea17c86 cmake: simplify configure_linker_script: avoid deriving define from name
Rather than associating defines within the function, let the call sites
themselves pick the appropriate define. Add new argument for this.
This also permits us to remove regex matching.

No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-05-02 21:54:27 +02:00
Mark Ruvald Pedersen 1073fbaa00 cmake: configure_linker_script: accept argument with file extension
Reduce the amount of {pre,post}fixing magic: I.e. let it be clearer at
call sites that "linker.cmd" is a file, rather than having to know that
"linker" will be postfixed with ".cmd" internally.

Change argument name to linker_script_gen, to better indicate that we
are producing a generated file.

No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-05-02 21:54:27 +02:00
Mark Ruvald Pedersen 4c811971f5 cmake: rename construct_add_custom_command_for_linker_pass macro
Now that we avoid the two-step procedure, we can simplify the name of
the construct_add_custom_command_for_linker_pass macro.

Move description comment up to head of definition, making the purpose
clearer.

No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-05-02 21:54:27 +02:00
Mark Ruvald Pedersen 11d6baea8c cmake: change construct_add_custom_command_for_linker_pass into macro
Change construct_add_custom_command_for_linker_pass from function into
macro. The purpose of the function was to set the output variable to a
string that would be fed to add_custom_command. This meant all use
required a two-step procedure and an intermediate
variable (custom_command).

The environmental leakage from a macro in this case is small, so let's
just simplify to a macro and avoid the two-step.

No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-05-02 21:54:27 +02:00
Mark Ruvald Pedersen 8c7c2d21e8 cmake: whitespace alignment of syscall_macros_h
No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-05-02 21:54:27 +02:00
Mark Ruvald Pedersen 85af28050e cmake: remove unused ALIGN_SIZING_DEP
Full grep reveal ALIGN_SIZING_DEP is only mentioned in cmake, where
it is never assigned a value.

No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-05-02 21:54:27 +02:00
Mark Ruvald Pedersen 3db09aa610 cmake: Toolchain abstraction: introduce toolchain_ld_cpp
No functional change expected.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting non-intrusive porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-05-02 15:19:02 +02:00
Mark Ruvald Pedersen b14b59c9e4 cmake: Toolchain abstraction: move symbol sorting into toolchain_ld_base
No functional change expected.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting non-intrusive porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-05-02 07:47:14 -04:00
Mark Ruvald Pedersen 173c953e9c cmake: Toolchain abstraction: orphan handling in toolchain_ld_baremetal
Move GNU ld linker specific flags related to orphan handling into
toolchain_ld_baremetal().

No functional change expected.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting non-intrusive porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-05-02 07:47:14 -04:00
Mark Ruvald Pedersen 69928beb36 cmake: Toolchain abstraction: build-id,gc-sections to toolchain_ld_base
Move --gc-sections flag to toolchain_ld_base()
Move --build-id=none flag to toolchain_ld_base()

No functional change expected.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting non-intrusive porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-05-02 07:47:14 -04:00
Mark Ruvald Pedersen 65f02c04d5 cmake: Toolchain abstraction: introduce toolchain_ld_baremetal()
The intent of toolchain_ld_baremetal() is to collect the flags belonging
to non-hosted (i.e. POSIX-based) targets.

No functional change expected.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting non-intrusive porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-04-30 10:13:41 -04:00
Mark Ruvald Pedersen 4080818300 cmake: Toolchain abstraction: move LINKERFLAGPREFIX under GNU ld
* LINKERFLAGPREFIX's value is GNU ld specific, and
* LINKERFLAGPREFIX is not a convention always honored by all linkers.

Thus we shall not set it from the common root CMakeList.txt.
So we move to linker/ld/target.cmake.

No functional change expected.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting non-intrusive porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-04-30 10:13:41 -04:00
Oleg Zhurakivskyy 2211935ed6 cmake: clang: Make clang pick -T option on linking
When linking, clang doesn't pick -T for some reason and complains,
while -Wl,-T works for both, gcc and clang.

Signed-off-by: Oleg Zhurakivskyy <oleg.zhurakivskyy@intel.com>
2019-04-30 09:33:54 -04:00
Mark Ruvald Pedersen 1f01325ee5 cmake: Toolchain abstraction: use LINKER, introduce toolchain_ld_base
toolchain_ld_base() represents flags that are fundamental to linking or
otherwise does not belong in any further specified linker flag category.

No functional change expected.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting non-intrusive porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-04-28 12:52:18 -04:00
Mark Ruvald Pedersen 3419efd552 cmake: fix intent description of toolchain_cc_nostdinc macro
toolchain_cc_nostdinc does not only obtain flags (to be placed in a
variable), it obtains and applies them.

No functional change expected.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-04-28 12:52:18 -04:00
Marc Herbert 4a10eea0eb gen_kobject_list.py: better comments and --help. Zero code change.
- The script can but does not always generate five files, in fact the
  current build invokes it at least three times requesting different
  outputs every time.

- --kobj-types-output produces a code fragment; not a standalone/usable
  header file. It outputs enum constants for a single enum type and not
  several enum types.

- Some outputs include driver instances and others not: clarify which.

- There's an entire and great section in the documentation that took
  me ages to find because it's not referenced anywhere in the --help
  or code. Fixed.

- Highlight the massive duplication in the CMakeLists.txt to save
  déjà vu confusion and minimize future divergence.

- Other minor tweaks.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2019-04-26 03:21:59 -07:00
Sebastian Bøe 3a0597f099 cmake: LD: Allow input sections to remain unsorted
We have users that have problems in their linker scripts where the
order of input sections matters.

To allow users to use the latest Zephyr while working on a fix to
their linker scripts we add an option to allow leaving the sections
unsorted.

See discussion here for more details
https://github.com/zephyrproject-rtos/zephyr/pull/14183

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-04-24 13:58:00 -07:00
Marc Herbert 498b49469a CMakeLists.txt: fix misleading logical_target_for_zephyr_elf comment
The comment for:

  set_target_properties(${logical_target_for_zephyr_elf} PROPERTIES
     OUTPUT_NAME ${KERNEL_NAME})

was completely off-topic and making something relatively simple
incredibly puzzling and time-consuming to understand.

Re-order the if(GKSF OR GKOF) clauses so the two initializations of
logical_target_for_zephyr_elf are close to each other and so the very
short clause is not buried at the bottom of the long one.

Other minor logical_target_for_zephyr_elf comment fixes.

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2019-04-19 09:26:23 -05:00
Marc Herbert 28a5657f1f cmake: zephyr_cc_option(-fmacro-prefix-map=${ZEPHYR_BASE}=.)
If the compiler supports it, strip the ${ZEPHYR_BASE} prefix from the
__FILE__ macro used in __ASSERT* macros, in the
.noinit."/home/joe/zephyr/fu/bar.c" section names and in any application
code. This saves some memory, stops leaking user locations in binaries,
makes failure logs more deterministic and most importantly makes builds
more deterministic.

- .noinit section names now look like this in objdump -h:

 17 .noinit."./kernel/init.c".2 00001100  00000000  ...

 18 .noinit."./kernel/init.c".1 00001200  00000000  ...

 19 .noinit."./kernel/init.c".3 00001800  00000000  ...

- The output of __ASSERT* macros now looks like this:

  ASSERTION FAIL [0] @ ./samples/hello_world/src/main.c:13
    The world comes crashing down
  ***** Kernel Panic! *****
  Current thread ID = 0x00400040

Signed-off-by: Marc Herbert <marc.herbert@intel.com>
2019-04-17 08:08:14 -04:00
Bradley Bolen 4198ba71f2 cmake: Fix missing dependency
DRV_VALIDATION should depend on any changes to the tool that generates
it, gen_kobject_list.py.

Signed-off-by: Bradley Bolen <bbolen@lexmark.com>
2019-04-16 22:53:49 -04: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
Daniel Leung 84b1bba8ee codecov: keep "inline" for ALWAYS_INLINE
Previous commit c31e659165 changed
the ALWAYS_INLINE macros to avoid functions being inlined for
the purpose of code coverage. This has a side effect of causing
the text sections of kobject_hash.c and priv_stacks_hash.c
to ballon more than 10 times in size. This is caused by
attaching the unused attribute, which results in all those
functions being in the text sections though they are never
used. So just keep the "inline" there.

This also removes -fno-inline from NO_COVERAGE_FLAGS so these
two files are not compiled with flags related to code coverage.

Fixes #15009

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-04-02 09:39:44 -04:00
Carles Cufi 766edd449d cmake: modules: Enclose name and path in quotes
Due to the fact that CMake only supports greedy regexes,
the ':' in a Windows path ('C:\...') was being matched leading
to an invalid split of the line. Quote both the name and the path
to avoid this issue.

Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2019-04-01 07:27:23 +08:00
Torsten Rasmussen bd7569f272 cmake: Extracted Zephyr module processing into python script
Fixes: #14513

This commit move the functionality of extracting zephyr modules into
generated CMake and Kconfig include files from CMake into python.

This allows other tools, especially CI to re-use the zephyr module
functionality.

Signed-off-by: Torsten Rasmussen <torsten.rasmussen@nordicsemi.no>
2019-03-29 23:10:59 -04:00
Kumar Gala 3713ea4761 cmake: Fix how we set include dirs for userspace
To ensure the proper flags are specified to the toolchain, we need to
keep system headers and non-system headers seperate and set the SYSTEM
flag to target_include_directories for system headers.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-15 06:42:41 -05:00
Andrew Boie a514898ee7 userspace: don't modify optimization options
The gperf hashtables and support functions are created
after the initial zephyr_prebuilt.elf is created, using
data found within it.

A fixed-sized amount of memory is reserved for the
program text of these support functions, as their true
size isn't possible to predict in advance and we don't
want memory addresses after them to shift. To minimize
the amount of space reserved, it seemed reasonable to
hard-code -Os.

However, on ARC, building with -Os can cause various
millicode functions from libgcc to be included in the
binary which would not be present in zephyr_prebuilt.elf
unless zephyr_prebuilt.elf was also built with -Os,
causing anything after them to be shifted, wreaking all
kinds of havoc.

Just build without hardcoding any optimization parameters.
We have checks in the linker scripts to let us know if
we have overflowed the region for the gperf support
functions anyway, so there is no danger of this failing
silently.

Fixes: #14139

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-03-14 22:22:31 -05:00
Daniel Leung af10d16a08 linker: sort sections by alignment
This turns on the linker flag to sort sections by alignment
in decreasing size of symbols. This helps to minimize
padding between symbols.

This also adds the linker options to sort common symbols by
alignment in descending to minimize the need for padding.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-13 15:54:29 -05:00
Daniel Leung 212ec9a29a linker: sort app shared mem partition by alignment
If CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT is enabled,
the app shared memory partition may cause waste of memory
due to the need for padding.

For example, tests/subsys/jwt and board mps2_an385:

  z_test_mem_partition: addr 0x20000000, size 52
  z_libc_partition    : addr 0x20000040, size 4
  k_mbedtls_partition : addr 0x20008000, size 32736

    ending at 0x2000ffff, taking up 65536 bytes

With power-of-two size and alignment requirement,
k_mbedtls_partition takes up 32KB memory and needs to be
aligned on 32KB boundary. If the above partitions are
ordered as shown, there needs to be a lot of padding
after z_libc_partition before k_mbedtls_partition can
start. In order to minimize padding, these partitions
need to be sort by size in descending order.

After the changes here,	the partitions are:

  k_mbedtls_partition : addr 0x20000000, size 32736
  z_test_mem_partition: addr 0x20008000, size 52
  z_libc_partition    : addr 0x20008040, size 4

    ending at 0x2000805f, taking up 32864 bytes

With the above example, sorting results in a saving
of 32672 bytes of saving.

Fixes #14121

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-13 18:26:51 +01:00
Daniel Leung e8a2348fac linker: move app_smem.ld into include/linker
The app_smem.ld is also being used by architectures other than ARM.
So move the linker script out of include/arch/arm and into
include/linker.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-13 18:26:51 +01:00
Kumar Gala 7aa8e43add libc: newlib: Cleanup/fix setting of system include paths
When we build with newlib we don't set -nostdinc.  In that case make
sure that we leave it to the toolchain to set the system include paths.

The one exception to leaving to the toolchain to set the system include
paths is the path to the newlib headers.  Since we build
with -ffreestanding we need to make sure the newlib header path is the
before the toolchain headers. Otherwise the toolchain's 'freestanding'
headers get picked up and that causes issues (for example getting PRI*64
defined properly from inttypes.h due to __STDC_HOSTED__ being '0').

For newlib we accomplish this by having the only system header specified
by zephyr_system_include_directories() being just the newlib headers.

Note: for minlibc we leave things alone as things just happen to work as
the -I include of the libc headers takes precedence over -isystem so we
get the libc headers over the toolchain ones.  For the newlib case it
appears that setting both -I and -isystem for the same dir causes the
-I to be ignored.

Fixes #14310

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-13 06:50:23 -05:00
Andrew Boie e686aefe09 mbedtls: provide user mode access
The mbedtls library has some globals which results in faults
when user mode tries to access them.

Instantiate a memory partition for mbedtls's globals.
The linker will place all globals found by building this
library into this partition.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-03-05 08:27:20 -05:00
Sebastian Bøe 8730854206 cmake: Don't assert when empty libraries are detected
The empty-library check was introduced because in earlier versions of
CMake the error message for empty libraries was very cryptic. But in
3.13.2 CMake now reports:

-- Configuring done
CMake Error at ../../cmake/extensions.cmake:357 (add_library):
  No SOURCES given to target: drivers__entropy
Call Stack (most recent call first):
  ../../cmake/extensions.cmake:334 (zephyr_library_named)
  ../../drivers/entropy/CMakeLists.txt:1 (zephyr_library)

which should be clear enough.

In addition to being redundant, our empty library check is run earlier
than CMake's check, so it will falsely report libraries to be empty,
when in fact, in an out-of-tree driver use-case, they will not
actually be empty at Generation time.

CMake runs it's check at generation time and is not affected by this
problem, so we remove the check.

This is a step, but not a complete solution, to resolving #8379.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-03-03 23:54:00 -05:00
Sebastian Bøe 244451b64f cmake: Rename CMake variable out of the reserved CONFIG_ namespace
Rename the poorly named CMake variable 'CONFIG_COMPILER_OPT_AS_LIST'
to 'COMPILER_OPT_AS_LIST' to take it out of the Kconfig-reserved
namespace 'CONFIG_*'.

This is a small step towards resolving #12144

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-03-03 23:52:29 -05:00
Torsten Rasmussen 605ae101eb cmake: remove debug message if no modules are included in build.
Fixes: #13245

Remove the printing of: 'Including module(s)' when no modules are
included into the CMake build.

Signed-off-by: Torsten Rasmussen <torsten.rasmussen@nordicsemi.no>
2019-03-03 17:43:47 -05:00
Andy Ross fe04adf99b lib/os: Conditionally eliminate alloca/VLA usage
MISRA rules (see #9892) forbid alloca() and family, even though those
features can be valuable performance and memory size optimizations
useful to Zephyr.

Introduce a MISRA_SANE kconfig, which when true enables a gcc error
condition whenever a variable length array is used.

When enabled, the mempool code will use a theoretical-maximum array
size on the stack instead of one tailored to the current pool
configuration.

The rbtree code will do similarly, but because the theoretical maximum
is quite a bit larger (236 bytes on 32 bit platforms) the array is
placed into struct rbtree instead so it can live in static data (and
also so I don't have to go and retune all the test stack sizes!).
Current code only uses at most two of these (one in the scheduler when
SCHED_SCALABLE is selected, and one for dynamic kernel objects when
USERSPACE and DYNAMIC_OBJECTS are set).

This tunable is false by default, but is selected in a single test (a
subcase of tests/kernel/common) for coverage.  Note that the I2C and
SPI subsystems contain uncorrected VLAs, so a few platforms need to be
blacklisted with a filter.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-02-28 10:06:35 -08:00
Anas Nashif 29f04767e9 arch: move common app_data_alignment.ld file
This file is being used by different architectures and is not ARC
specific.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-28 08:53:16 -08:00
Anas Nashif aa049e5d8f toolchain: abstract setting -nostdinc
- newlib needs c standard includes (so no -nostdinc)
- xcc needs toolchain headers (so no -nostdinc)
- with host gcc:
  - x86_64 should not build with standard includes (-nostdinc needed)
  - native_posix should build with standard include (no -nostdinc)
..
..

To simplify, abstract this and move it to compilers/toolchains and still
depend on what the application wants.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-24 17:48:10 -05:00
Andrew Boie 4ce652e4b2 userspace: remove APP_SHARED_MEM Kconfig
This is an integral part of userspace and cannot be used
on its own. Fold into the main userspace configuration.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-23 07:43:55 -05:00
Mark Ruvald Pedersen cb0fd451c2 cmake: Toolchain abstraction: Assembly
Introduce toolchain_cc_asm macro to capture toolchain specific flags
related to assembly.

-D_ASMLANGUAGE is kept common for all, assuming -D as define flag is
supported by all compilers (which is almost the case).

No functional change expected.

Clang's flags are compatible with gcc, and are thus inherited.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting easier porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-23 07:41:46 -05:00
Andrew Boie 17ce822ed9 app_shmem: create generic libc partition
We need a generic name for the partition containing
essential C library globals. We're going to need to
add the stack canary guard to this area so user mode
can read it.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-22 18:50:43 -05:00
Anas Nashif ccad9d0d09 tests: move testsuite and configs into subsys/
Move test related code and the testsuite away from tests/ and make it a
proper subsystem.
The way tests were integrate in the tree was not obvious and actual
tests were intermixed with the testsuite code.

This will allow us to have trees with the testcode and without the
samples by just remove the folders tests/ and samples, needed for
isolating actual code from test/sample code.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-22 08:58:40 -05:00
Kumar Gala 9c2ac77861 cmake: Fix setting of -nostdinc
We where defining the variable NOSTDINC_F after we tried to use it.
Move the definition before the first reference fixes things.  When
-nostdinc now enabled we need to explicitly add the compiler include
path for x86_64 based builds (x86_64 and ARCH_POSIX).

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-20 12:13:45 -06:00
Mark Ruvald Pedersen 63df409906 cmake: Toolchain abstraction: C++
Introduce toolchain_cc_cpp_*-family of macros.

Move the following into the toolchain_cc_cpp_* macros:
 * Common base set of flags
 * C++ standard version
 * RTTI
 * Exceptions

These macros must be implemented by every compiler port.
These macros set the respective flags, but leaves logic and control to
the root CMakeLists.txt file.

No functional change expected.

Clang's C++ flags are compatible with gcc, and are thus
inherited.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting easier porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-19 12:33:19 -05:00
Mark Ruvald Pedersen efb50e7af2 cmake: remove redundant compiler flags for C++
The compiler flags -ffunction-sections and -fdata-sections are already
universally set from arch/common/CMakeLists.txt, so we shall not set
them again for C++ only.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-19 12:33:19 -05:00
Mark Ruvald Pedersen 0b3c65feea cmake: Toolchain abstraction: optimizations
Introduce toolchain_cc_optimize_for_* family of macros.
Each macro represents a general optimization class.
Each macro is then responsible for setting an output variable to that
class-of-optimization's flag.
The names of these output variables are decided from the root
CMakeLists.txt.

No functional change expected.

Clang's optimization flags are compatible with gcc, and are thus
inherited.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting easier porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-02-18 08:22:42 -05:00
Andrew Boie 9af5089dee build: remove meltdown warning
Now addressed by KPTI.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-14 12:46:36 -05:00
Kumar Gala b16509f168 cmake: Remove dead Kconfig CONFIG_READABLE_ASM
CONFIG_READABLE_ASM hasn't existed as Kconfig option, so remove dead
references to it

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-11 22:29:58 -05:00
Torsten Rasmussen 7e9d1bdda4 CMake/Kconfig: CMake and Kconfig build integration
This commit allows for Zephyr modules to be natively integrated into
the build system with CMakeLists.txt and Kconfig files.

The sourcing of module files are done in following order:
- If <module>/zephyr/module.yml exists, use cmake and kconfig settings
  for sourcing of additional file
- Else if <module>/zephyr/CMakeLists.txt exists, source this file into
  CMake build tree and add <module>/zephyr/Kconfig as osource

If none of the above files are present, the project is considered to
not be a Zephyr module

Signed-off-by: Torsten Rasmussen <torsten.rasmussen@nordicsemi.no>
2019-02-08 22:47:02 -05:00
Sebastian Bøe 2a96312749 cmake: Fix dependencies for LD script generation
The dependencies relating to generating LD scripts are declared
incorrectly. This manifests itself as broken incremental builds as
shown in #13001.

This commit aligns the LD script generation with the Zephyr standard
for declaring custom commands.

For instance, custom commands should generate files that are wrapped
by targets. The custom commands should declare the dependencies, not
the targets.

Also, when using custom commands, the OUTPUT signature should be used,
not the TARGET signature, as app_smem was doing.

For details about how Zephyr uses custom commands see
https://samthursfield.wordpress.com/2015/11/21/cmake-dependencies-between-targets-and-files-and-custom-commands/

This fixes #13001.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-02-08 16:39:43 -06:00
Sebastian Bøe b43c6120ab cmake: Allow deps to be added to the preprocessing of LD scripts
To be able to correctly express that preprocessing a file will depend
on targets and files we enhance the LD script preprocessing function
by adding all trailing arguments to the DEPENDS section of the custom
command.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-02-08 16:39:43 -06:00
Sebastian Bøe 7a6afcdc04 cmake: Various refactorings and whitespace fixes
This commit applies various refactorings and whitespace fixes in
preparation for the patch that fixes #13001.

It includes changing indentation from tabs to spaces and splitting
tokens across more lines to increase readability and minimize patch
sizes.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-02-08 16:39:43 -06:00
Andrew Boie 41f6011c36 userspace: remove APPLICATION_MEMORY feature
This was never a long-term solution, more of a gross hack
to get test cases working until we could figure out a good
end-to-end solution for memory domains that generated
appropriate linker sections. Now that we have this with
the app shared memory feature, and have converted all tests
to remove it, delete this feature.

To date all userspace APIs have been tagged as 'experimental'
which sidesteps deprecation policies.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-08 07:04:30 -05:00
Andrew Boie 4b4f773484 libc: set up memory partitions
* Newlib now defines a special z_newlib_partition containing
  all globals relevant to newlib. Most of these are in libc.a
  with a heap tracking variable in newlib's hooks.

* Both C libraries now expose a k_mem_partition containing the
  bounds of the malloc heap arena. Threads that want to use
  libc malloc() will need to add this to their memory domain.

* z_newlib_get_heap_bounds has been removed, in favor of the
  memory partition for the heap arena

* ztest now includes the C library partitions in its memory
  domain.

* The mem_alloc test now runs in user mode to prove that this
  all works for both C libraries.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-08 07:04:30 -05:00
Adithya Baglody c12381793a CMakeLists: fix app_shmem dependency
This particular rule of cmake was causing problems when run in
multi-threaded environment. This change in the dependency will
resolve all such issues and ensures that this script is executed
correctly.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2019-02-08 07:04:30 -05:00
Adithya Baglody 50950eb2c9 app_shmem: use script for all arches
This patch will run the python scripts for all architectures
to determine the partitions available. This is needed for correct
operation of the app_shared_mem feature.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-08 07:04:30 -05:00
Klaus Petersen c66cb76fed Build: Added support for out-of-tree Arch
Introduces the ARCH_ROOT argument, similar to BOARD_ROOT and SOC_ROOT.
This enables support for out-of-tree architectures.

The ARCH_ROOT out-of-tree layout is expected to be the following:
 * ${ARCH_ROOT}/arch/${ARCH}/
 * ${ARCH_ROOT}/include/arch/${ARCH}/ (Optional)

Signed-off-by: Klaus Petersen <kape@oticon.com>
2019-02-07 17:00:43 -05:00
Klaus Petersen 62e55e5e4b Build: Offsets lib as OBJECT not STATIC
With the new cmake version, we are able to simplify the generation of
the offset object library without using absolute hardcoded paths.

Instead of the hardcoded paths, we now use the generator:
$<TARGET_OBJECTS:${OFFSETS_LIB}>

This is needed to eventually be able to have an arch-out-of-tree build

Signed-off-by: Klaus Petersen <kape@oticon.com>
2019-02-04 13:14:09 -05:00
Rajavardhan Gundi ecdea1c30c CMakeLists: Introduce extra post build commands
This patchset introduces support for building board specific custom
images. Any board which needs to build a custom image (a post-processed
zephyr.bin) should inject the post_build_command from a script in the
corresponding board directory.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2019-01-30 21:30:49 -05:00
Sebastian Bøe 40363399c9 cmake: Don't use non-existing include paths
Don't add non-existing include directories, it creates noise and even
warnings in some tooling, like Eclipse.

This fixes #12696

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-01-30 10:47:08 -05:00
Mark Ruvald Pedersen 01592071f1 cmake: Toolchain abstraction: security
Introduce the first of the toolchain_cc-family of macros:
toolchain_cc_security_fortify and toolchain_cc_security_canaries.

No functional change expected.

Fortify source is not supported by Clang, but this commit retains
current behavior.

This is motivated by the wish to abstract Zephyr's usage of toolchains,
permitting easier porting to other (commercial) toolchains.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2019-01-30 08:42:11 -05:00
Benoit Leforestier 04dad5954c C++: Suppress warning
The "register" keyword was deprecated since C++11.
Add -Wno-register flag for avoid warning, with recent version of C++.

Signed-off-by: Benoit Leforestier <benoit.leforestier@gmail.com>
2019-01-29 17:50:20 +01:00
Sebastian Bøe 5bd5e4e440 cmake: userspce: Always compile priv_stacks_hash.c as -Os
The gperf hash table 'kobject_hash.c' is always compiled as -Os to
resolve bug #5226, the same bug also affects the gperf hash table
'priv_stacks_hash.c'.

In this patch we copy over the fix from 'kobject_hash.c' to also fix
'priv_stacks_hash.c'.

See #5672 for more discussion on the original fix.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-01-28 14:16:50 -08:00
Sebastian Bøe 361fdaac1a cmake: Fix the generation of fixup files
A recent change in how the fixup mechanism works caused several
regressions. See
https://github.com/zephyrproject-rtos/zephyr/pull/12680 for more
details about the regressions.

The core of the matter is that using defines to pass on include paths
causes interopability issues when integrating with external build
systems.

To resolve this we re-write the fixup mechanism to instead generate an
aggregated fixup file that is ready to be included at build time. Then
no paths are passed through defines and we resolve the regressions
reported.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-01-28 12:18:38 -05: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
Sebastian Bøe fb3d201cae cmake: STACK_CANARIES: Re-write how compatibility is checked
This re-write fixes several issues with how we were checking for
compatibility with the canary flags:

If a compiler did not support any stack canaries, but a user had still
enabled them, this would silently result in no canaries being added
instead of error-ing out as it should have.

Compatiblity for '-mstack-protector-guard=global' was unnecessarily
being tested twice, once in 'check_c_compiler_flag' and once in
'zephyr_cc_option'.

Compatibility was being tested with 'check_c_compiler_flag' which is
slower than 'zephyr_check_compiler_flag' because it does not cache
it's results.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-01-23 09:44:09 +01:00
Anas Nashif b832a1e264 printk: move into lib/os
Last file under misc/. Put it alongside other support functions in
lib/os.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-22 07:45:22 -05:00
Anas Nashif 885aaf2734 cmake: fix assert message about misc/Kconfig
We have no Kconfig in misc/. Most options were moved to Kconfig.zephyr.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-22 07:45:22 -05:00
Sebastian Bøe 1b86fb9da3 cmake: Use variables for target names
There is an effort underway to make most of the Zephyr build script's
reentrant. Meaning, the build scripts can be executed multiple times
during the same CMake invocation.

Reentrancy enables several use-cases, the motivating one is the
ability to build several Zephyr executables, or images, for instance a
bootloader and an application.

For build scripts to be reentrant they cannot be directly referencing
global variables, like target names, but must instead reference
variables, which can vary from entry to entry.

Therefore, in this patch, we replace global targets with variables.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-01-19 07:21:55 -05:00
Sebastian Bøe 1526070082 cmake: Use a variable for 'zephyr_prebuilt'
There is an effort underway to make most of the Zephyr build script's
reentrant. Meaning, the build scripts can be executed multiple times
during the same CMake invocation.

Reentrancy enables several use-cases, the motivating one is the
ability to build several Zephyr executables, or images, for instance a
bootloader and an application.

For build scripts to be reentrant they cannot be directly referencing
global variables, like target names, but must instead reference
variables, which can vary from entry to entry.

Therefore, in this patch, we replace global targets with variables.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-01-19 07:21:55 -05:00
Adithya Baglody 4b3c7b3d17 cmake: Generated files are excluded from coverage.
When coverage option is enabled, all C files will have
coverage option enabled. When we enable it for generated files
it adds extra .bss info and other related information.
Since the bss has now increased the perfect hash that was
calculated by gperf is now incorrect. Which is a problem
for userspace enabled systems.

This patch will make sure that the generated C files will be
compiled without the coverage flags. The remaining functionality
remains unchanged.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2019-01-16 06:12:33 -05: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
Mark Ruvald Pedersen 59036db195 cmake: Move root CMakeLists.txt's comment-header to top
Inform user early on that ./CMakeLists.txt is not the top-level file.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-12-20 11:14:59 +01:00
Andrew Boie 95936e2b14 kernel: fix x86 stack protector with later GCC
Newer versions of GCC default to using thread-local storage ABI
for the canary value instead of a global. We don't implement TLS
in Zephyr like this (at least for now) so specify that we want
to use the global instead.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-12-07 19:34:29 -05:00
Adithya Baglody 3e784bc6b5 CMakeLists.txt: Enable -fno-common globally.
This is needed to force the .common type to .bss type.
This will force the .common variables to go into bss section
in the compiled object file.
As of now the movement to the .bss section was happening only
during the final linking stage.

The -fno-common option specifies that the compiler should place
uninitialized global variables in the data section of the object
file, rather than generating them as common blocks.  This has the
effect that if the same variable is declared (without "extern")
in two different compilations, you will get a multiple-definition
error when you link them.

e.g:
// file a.c
// file-scope

int b;

// file b.c
// file-scope

int b;

If there exist two non-extern declarations of the same variable
then no-common will cause a linker error.
This sequence would have compiled before, but will now cause a
linker error.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-12-07 10:32:41 -05:00
Adithya Baglody 62e152a8f0 cmake: Added rule and helper functions for code relocation.
This patch creates a rule in the cmake to trigger the generation
of linker_relocate.ld and code_relocation.c files.
The linker_relocate.ld will create appropriate sections and will
link the required functions or variables from all the selected
files.
The code_relocation.c will have code that is needed for
initializing data sections and copy of text sections(if XIP).
Also this will contain code that is needed for zeroing of bss.

The procedure to invoke this feature is:
1. Enable CONFIG_CODE_RELOCATION in the prj.conf

2. Inside CMakeList.txt in the project we need to mention
   all the files that needs to get relocated.

   zephyr_kernel_code_relocate(src/*.c SRAM2)

   Where the first argument is the file/files and the second
   argument is the memory where it has be placed.
   NOTE: The file argument supports glob expressions.

NOTE: Step 2 can be done as many times as required. And relative
paths can be given here.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-12-07 10:32:41 -05:00
Håkon Øye Amundsen 0da5d24c36 cmake: flash: Conditional dependency to 'mergehex'
This patch adds a dependency from the 'flash' target to
the 'mergehex' target IF files to be merged are configured.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2018-12-05 12:14:38 -05:00
Håkon Øye Amundsen 2a5a02e114 cmake: fix incorrect lower case variable
This patch fixes a bug where a incorrect lower case
variable 'MERGED_HEX_NAME' resulted in the 'flash'
target not getting the correct path to the hex file to flash.
This since cmake/flash/CMakeLists.txt uses the variable
${MERGED_HEX_NAME}.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2018-12-05 14:33:24 +01:00
Aurelien Jarno c6727d49b7 arch: ARM: set -mthumb, -mcpu, -mfpu and -mfloat-abi in linker flags
Some toolchains are built with multilib enabled in order to provide
multiple versions of the same library, optimized for different ABI
or architecture. They require the the ABI/architecture/CPU selection
options to be passed at linked time. This is important for example
when linking with newlib.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-12-04 19:40:39 -05:00
Håkon Øye Amundsen 81c6662d23 cmake: flash: scripts: Include externally built hex files
Allow user to add externally built hex files to the cmake property
HEX_FILES_TO_MERGE. The hex files in this list will be merged
with the hex file generated when building the zephyr application.

This allows users to leverage the application configuration
available in Kconfig and CMake to help decide what hex file
should be merged with the zephyr application.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2018-12-04 19:04:13 +01:00
Håkon Øye Amundsen 611b0d1e80 cmake: Move helper function up, inline variable.
This is done to make future modifications simpler,
as more variables and functions are available.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2018-12-04 08:33:04 -05:00
Håkon Øye Amundsen a449439504 cmake: Move check for TOTP property up.
This is done to make future modifications simpler,
as more variables and functions are available.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2018-12-04 08:33:04 -05:00
Håkon Øye Amundsen 2a3f43458b cmake: Move check for '-nostdinc' up.
This is done to make future modifications simpler,
as more variables and functions are available.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2018-12-04 08:33:04 -05:00
Håkon Øye Amundsen d6551b5dea cmake: Move MPU userspace declaration up.
This is done to make future modifications simpler,
as more variables and functions are available.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2018-12-04 08:33:04 -05:00
Ioannis Glaropoulos 0f6ad28c33 cmake: do not run app data section aligning post-script for ARM
Since the app_data_alignment.ld is not used anymore in ARM
builds, remove the need for running the script to auto-
generate it. The script now runs only for ARC builds.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-11-30 15:22:58 +01:00
Ioannis Glaropoulos c15c491199 cmake: move app_data_alignment.ld under ARC sub-directory
This commit moves the app_data_alignment.ld scripts
under arch/arc sub-directory, as it is not not used
at all in ARM builds. The script is still used for
ARC, whose v2 MPU also has the reuquirement for
power-of-two size alignment.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-11-30 15:22:58 +01:00
Håkon Øye Amundsen c086b935aa kconfig: cmake: Support for images without gaps.
Defines a Kconfig variable which allows the user to specify
that any generated hex/bin/s19 file should not have filled gaps.

This is done to support building in a multi image context,
where several image files will be merged together.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2018-11-26 06:41:05 -08:00
Kumar Gala 41e43111dc cmake: Remove global include of board dir
Remove having ${BOARD_DIR} in the global include path for Zephyr builds.
Needed to add this to the arch/posix because of how posix "boards"
define various things like interrupt handling.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-20 14:08:01 -05:00
Anas Nashif 644b31d2a4 Revert "Build: Offsets lib as OBJECT not STATIC"
This reverts commit 18f9bb04f7.

This breaks with cmake 3.8.2, the minimal required version we have in
all of our cmake files.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-17 22:28:33 -05:00
Klaus Petersen 18f9bb04f7 Build: Offsets lib as OBJECT not STATIC
Use cmake to get generated path of lib instead of predefined absolute
path.  This is needed to eventually be able to have an
architecture-out-of-tree build.  The path "OFFSETS_O_PATH" is not
generated for sources out-of-tree and therefore must be replaced by the
cmake generator $<TARGET_OBJECTS:offsets>.

The following lines are needed while we are using a Cmake version <
3.12.3:

target_include_directories(.....
target_compile_options(...
target_compile_definitions(....

This is due to the cmake feature "Linking Object Libraries" not
supported until 3.12:
https://cmake.org/cmake/help/v3.12/command/target_link_libraries.html#linking-object-libraries

Signed-off-by: Klaus Petersen <kape@oticon.com>
2018-11-16 08:34:30 -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
Benoit Leforestier 26e0f9a9e1 Build: Improve C++ support
Can choose the C++ standard (C++98/11/14/17/2a)
Can link with standard C++ library (libstdc++)
Add support of C++ exceptions
Add support of C++ RTTI
Add C++ options to subsys/cpp/Kconfig
Implements new and delete using k_malloc and k_free
if CONFIG_HEAP_MEM_POOL_SIZE is defined

Signed-off-by: Benoit Leforestier <benoit.leforestier@gmail.com>
2018-10-29 09:15:04 -04:00
Daniel Leung 6600c64331 linker: warn about orphan sections
(Previous patch set was reverted due to issue with priv_stack.
 Resubmitting after fixing the faults caused by priv_stack.noinit
 not at the end of RAM.)

This adds a linker flag and necessary changes to linker scripts
so that linker will warn about orphan sections.

Relates to #5534.

Fixes #10473, #10474, #10515.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-10-19 16:11:34 -04:00
Anas Nashif 951393f659 build: do not rename elf file, copy it
We break dependency if we rename the zephyr.elf file, we should keep it
as it is an essential dependency in the build system. Instead, copy the
file.

Fixes #10639

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-19 07:56:47 -04:00
Sebastian Bøe 0fc39343ff cmake: Export the target name of the final elf file to the app
For the 'app' build scripts to be able to do post-processing on the
elf file they need to know what the target name for the elf file is.

In zephyr this name varies depending on whether one does a single or
multiple link, so we export a variable with the name.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-10-16 15:58:56 -04:00
Anas Nashif 0d4b5daeaa Revert "linker: warn about orphan sections"
This reverts commit 8ce758a8ff.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-14 12:14:04 -04:00
Anas Nashif bb0e49c610 Revert "linker: use wildcards in rel-sections.ld"
This reverts commit 9ae3ea47b0.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-14 12:14:04 -04:00
Daniel Leung 9ae3ea47b0 linker: use wildcards in rel-sections.ld
Update rel-sections.ld to use wildcards instead of
spelling out those sections one by one.

Also, for POSIX, don't include this and turns off
the warnings. With different host toolchain across
different OS, it would be maintanence nightmare
to account for all those combinations. So this reverts
the POSIX linker script to before the first orphan
section changes.

Fixes #10493

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-10-12 13:21:52 -04:00
Yasushi SHOJI 6fc0d77432 arch: add big endian support
This patch adds Big Endian architecture support.  Even if a compiler
generating big endian object files is used, our linker script, or
include/linker/linker-tool-gcc.h to be precise, has default output
format as little endian.

This patch adds a hidden config CONFIG_BIG_ENDIAN, which should be set
by big endian architectures or a SoC's, and adds an condition to
switch OUTPUT_FORMAT in our linker.cmd.

Signed-off-by: Yasushi SHOJI <y-shoji@ispace-inc.com>
2018-10-10 09:28:05 -04:00
Daniel Leung 8ce758a8ff linker: warn about orphan sections
This adds a linker flag and necessary changes to linker scripts
so that linker will warn about orphan sections.

Relates to #5534.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-10-09 08:23:41 -04:00
Mark Ruvald Pedersen 28394cc44e portability: Warn at void* arithmetics which is a GNU C extension
Ensure future commits do not re-introduce use of this GNU C extension.

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-09-28 07:57:28 +05:30
Adithya Baglody c764e021d8 CMakeLists.txt: Updated the rule for shared memory alignment.
Due to the new changes for the subsys/app_memory we need to
have the script for smem run before any elf is created.
This is needed because the compiled code will have references to
certain linker variables that will be created by
gen_app_partitions.py.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-09-20 11:25:53 -04:00
Adithya Baglody d4b5ab6478 CMakeLists.txt: Set application shared memory dependency
The scripts for app_smem need to be ready before the script for
privilaged stack is run. This is needed because there is a small
possibility that the stacks get aligned (due to app_smem)
after privilaged stack script is run. This causes the gperf
to create an incorrect hash.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-09-18 22:45:14 -04:00
Erwan Gouriou ba31cb55cd cmake: Add zephyr base address when looking file into soc/
When checking availability of soc/${ARCH}/CMakeLists.txt,
we should use ${ZEPHYR_BASE} as path base.

Fixes #9956

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2018-09-13 10:11:57 -05:00
Anas Nashif 96455d5881 build: support out of tree SoC definition
Add the glue to make this work with SoC code outside of the tree.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-13 00:56:48 -04:00
Anas Nashif 3d1252ff2d soc: adapt Kconfig/CMake for soc in top /
Change build system to point to soc/ in the top directory rather than
under arch/

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-13 00:56:48 -04:00
Sebastian Bøe cbe7b4fb74 linker: Re-implement {APP,KERNEL}_INPUT_SECTION
This rewrites the implementation of the APP_INPUT_SECTION and
KERNEL_INPUT_SECTION macros such that an unbounded amount of
kernelspace libraries can be used.

This resolves #7703

The new implementation has a caveat/limitation; the linker script
developer must invoke APP_INPUT_SECTION before KERNEL_INPUT_SECTION.

All in-tree linker scripts happened to already be doing this so no
in-tree porting was necessary.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-08-16 20:15:52 -07:00
Adithya Baglody c69fb0d016 userspace: app_shared_mem: Fixed incorrect implementation.
This feature was failing on a default ARM core MPU. The linker
script that was getting created was not able to align the required
partitions at prebuilt time.

The old implementation relied on the prebuilt to finish then
extract the size information which was then used to align the regions.
This fails because the size of the alignment and the fill in the
linker needs to be available at prebuilt time else it cant manage
the final elf file generation. We cant have 2 different sizes of
prebuilt and final elf file.

This implementation will get the alignment requirements met at
prebuilt time.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-08-14 05:22:54 -07:00
Sebastian Bøe d46e2c7ec9 ld: Don't use --start-group and --end-group
Remove the usage of --start-group and --end-group. Perhaps it had a
function previously, but as it is used here it has no effect.

--start-group and --end-group is used to designate that a set of libs
should be searched repeatedly until all unresolved references among
them are resolved. From the documentation:

     --start-group archives --end-group
         The specified archives are searched repeatedly until no
         new undefined references are created.  Normally, an
         archive is searched only once in the order that it is
         specified on the command line.  If a symbol in that
         archive is needed to resolve an undefined symbol
         referred to by an object in an archive that appears
         later on the command line, the linker would not be able
         to resolve that reference.  By grouping the archives,
         they all be searched repeatedly until all possible
         references are resolved.

         Using this option has a significant performance cost.
         It is best to use it only when there are unavoidable
         circular references between two or more archives.

Currently it is used on the 'ZEPHYR_LIBS_PROPERTY' libs, but this has
no effect, because they are being --whole-archive'd anyway. It is also
used on 'kernel' and 'OFFSETS_O_PATH'. But these libraries have no
circular references, so this has no effect either.

Consequently, removing these two flags is expected to simplify the
link command line and have no adverse effects.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-08-09 12:15:07 +02:00
Andrew Boie 353acf4aae gen_syscalls.py: do not output data to stdout
There's no particularly good reason to have one kind of
output from this script to be sent to stdout instead of
a filename specified by parameter, and it makes it
annoying to add debug print() statements.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-26 00:53:45 -04:00
Shawn Mosley 573f32b6d2 userspace: compartmentalized app memory organization
Summary: revised attempt at addressing issue 6290.  The
following provides an alternative to using
CONFIG_APPLICATION_MEMORY by compartmentalizing data into
Memory Domains.  Dependent on MPU limitations, supports
compartmentalized Memory Domains for 1...N logical
applications.  This is considered an initial attempt at
designing flexible compartmentalized Memory Domains for
multiple logical applications and, with the provided python
script and edited CMakeLists.txt, provides support for power
of 2 aligned MPU architectures.

Overview: The current patch uses qualifiers to group data into
subsections.  The qualifier usage allows for dynamic subsection
creation and affords the developer a large amount of flexibility
in the grouping, naming, and size of the resulting partitions and
domains that are built on these subsections. By additional macro
calls, functions are created that help calculate the size,
address, and permissions for the subsections and enable the
developer to control application data in specified partitions and
memory domains.

Background: Initial attempts focused on creating a single
section in the linker script that then contained internally
grouped variables/data to allow MPU/MMU alignment and protection.
This did not provide additional functionality beyond
CONFIG_APPLICATION_MEMORY as we were unable to reliably group
data or determine their grouping via exported linker symbols.
Thus, the resulting decision was made to dynamically create
subsections using the current qualifier method. An attempt to
group the data by object file was tested, but found that this
broke applications such as ztest where two object files are
created: ztest and main.  This also creates an issue of grouping
the two object files together in the same memory domain while
also allowing for compartmenting other data among threads.

Because it is not possible to know a) the name of the partition
and thus the symbol in the linker, b) the size of all the data
in the subsection, nor c) the overall number of partitions
created by the developer, it was not feasible to align the
subsections at compile time without using dynamically generated
linker script for MPU architectures requiring power of 2
alignment.

In order to provide support for MPU architectures that require a
power of 2 alignment, a python script is run at build prior to
when linker_priv_stacks.cmd is generated.  This script scans the
built object files for all possible partitions and the names given
to them. It then generates a linker file (app_smem.ld) that is
included in the main linker.ld file.  This app_smem.ld allows the
compiler and linker to then create each subsection and align to
the next power of 2.

Usage:
 - Requires: app_memory/app_memdomain.h .
 - _app_dmem(id) marks a variable to be placed into a data
section for memory partition id.
 - _app_bmem(id) marks a variable to be placed into a bss
section for memory partition id.
 - These are seen in the linker.map as "data_smem_id" and
"data_smem_idb".
 - To create a k_mem_partition, call the macro
app_mem_partition(part0) where "part0" is the name then used to
refer to that partition. This macro only creates a function and
necessary data structures for the later "initialization".
 - To create a memory domain for the partition, the macro
app_mem_domain(dom0) is called where "dom0" is the name then
used for the memory domain.
 - To initialize the partition (effectively adding the partition
to a linked list), init_part_part0() is called. This is followed
by init_app_memory(), which walks all partitions in the linked
list and calculates the sizes for each partition.
 - Once the partition is initialized, the domain can be
initialized with init_domain_dom0(part0) which initializes the
domain with partition part0.
 - After the domain has been initialized, the current thread
can be added using add_thread_dom0(k_current_get()).
 - The code used in ztests ans kernel/init has been added under
a conditional #ifdef to isolate the code from other tests.
The userspace test CMakeLists.txt file has commands to insert
the CONFIG_APP_SHARED_MEM definition into the required build
targets.
  Example:
        /* create partition at top of file outside functions */
        app_mem_partition(part0);
        /* create domain */
        app_mem_domain(dom0);
        _app_dmem(dom0) int var1;
        _app_bmem(dom0) static volatile int var2;

        int main()
        {
                init_part_part0();
                init_app_memory();
                init_domain_dom0(part0);
                add_thread_dom0(k_current_get());
                ...
        }

 - If multiple partitions are being created, a variadic
preprocessor macro can be used as provided in
app_macro_support.h:

        FOR_EACH(app_mem_partition, part0, part1, part2);

or, for multiple domains, similarly:

        FOR_EACH(app_mem_domain, dom0, dom1);

Similarly, the init_part_* can also be used in the macro:

        FOR_EACH(init_part, part0, part1, part2);

Testing:
 - This has been successfully tested on qemu_x86 and the
ARM frdm_k64f board.  It compiles and builds power of 2
aligned subsections for the linker script on the 96b_carbon
boards.  These power of 2 alignments have been checked by
hand and are viewable in the zephyr.map file that is
produced during build. However, due to a shortage of
available MPU regions on the 96b_carbon board, we are unable
to test this.
 - When run on the 96b_carbon board, the test suite will
enter execution, but each individaul test will fail due to
an MPU FAULT.  This is expected as the required number of
MPU regions exceeds the number allowed due to the static
allocation. As the MPU driver does not detect this issue,
the fault occurs because the data being accessed has been
placed outside the active MPU region.
 - This now compiles successfully for the ARC boards
em_starterkit_em7d and em_starterkit_em7d_v22. However,
as we lack ARC hardware to run this build on, we are unable
to test this build.

Current known issues:
1) While the script and edited CMakeLists.txt creates the
ability to align to the next power of 2, this does not
address the shortage of available MPU regions on certain
devices (e.g. 96b_carbon).  In testing the APB and PPB
regions were commented out.
2) checkpatch.pl lists several issues regarding the
following:
a) Complex macros. The FOR_EACH macros as defined in
app_macro_support.h are listed as complex macros needing
parentheses.  Adding parentheses breaks their
functionality, and we have otherwise been unable to
resolve the reported error.
b) __aligned() preferred. The _app_dmem_pad() and
_app_bmem_pad() macros give warnings that __aligned()
is preferred. Prior iterations had this implementation,
which resulted in errors due to "complex macros".
c) Trailing semicolon. The macro init_part(name) has
a trailing semicolon as the semicolon is needed for the
inlined macro call that is generated when this macro
expands.

Update: updated to alternative CONFIG_APPLCATION_MEMORY.
Added config option CONFIG_APP_SHARED_MEM to enable a new section
app_smem to contain the shared memory component.  This commit
seperates the Kconfig definition from the definition used for the
conditional code.  The change is in response to changes in the
way the build system treats definitions.  The python script used
to generate a linker script for app_smem was also midified to
simplify the alignment directives.  A default linker script
app_smem.ld was added to remove the conditional includes dependency
on CONFIG_APP_SHARED_MEM.  By addining the default linker script
the prebuild stages link properly prior to the python script running

Signed-off-by: Joshua Domagalski <jedomag@tycho.nsa.gov>
Signed-off-by: Shawn Mosley <smmosle@tycho.nsa.gov>
2018-07-25 12:02:01 -07:00
Thomas Ebert Hansen 15bc615b5b cmake: Use _FORTIFY_SOURCE only with optimizations enabled
When compiling for native, some glibc versions has a check on the
use of _FORTIFY_SOURCE without optimizations enabled and gives a
preprocessor warning.

Signed-off-by: Thomas Ebert Hansen <thoh@oticon.com>
2018-07-12 23:13:01 -04:00
Walter Xie 6b836d6e6d cmake: Add "gap-fill 0xFF" option for CMAKE_OBJCOPY command.
Add "gap-fill 0xFF" option for the CMAKE_OBJCOPY command,
in order to reduce the flash programming time for some boards,
such as cc2650.

Signed-off-by: Walter Xie <41377148@qq.com>
2018-07-11 23:04:32 -04:00
Adithya Baglody e67720bbf2 syscalls: Scan multiple folders to build complete syscall list
Previously the syscall list was generated only from the include
folder. This is a limitation when the application tries to create
system calls. This patch create a simple way to include these
new syscalls without the application touching the kernel.

This can be enabled by a Kconfig CONFIG_APPLICATION_DEFINED_SYSCALL.
Once enabled the application source directory will be scanned to
find all application defined syscalls.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-07-10 10:22:04 -07:00
Alberto Escolar Piedras c2882410ed cmake: Allow C standard version to be overriden
Allow archs/boards/apps to override the C standard version.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-07-05 12:55:07 -04:00
Sebastian Bøe 347f9a0a2d cmake: LD: Specify the entry point in the linker scripts
The entry point can and therefore should be set by linker
scripts. Whenever possible one should express things in the source
language, be it .c or .ld, and not in code generators or in the build
system.

This patch removes the flag -eCONFIG_KERNEL_ENTRY from the linker's
command line and replaces it with the linker script command

ENTRY(CONFIG_KERNEL_ENTRY)

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-07-03 17:18:14 -04:00
Anas Nashif 72edc4e15f clang/llvm: add initial configuration file for clang
Add an LLVM backend and a clang toolchain variant to support building
with llvm coming with popular Linux distributions.

This has been tested with X86 boards:
- quark_d2000_crb
- quark_se_c1000_devboard/Arduino 101

Use:

export ZEPHYR_TOOLCHAIN_VARIANT=clang

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-07-01 22:58:09 +02:00
Sebastian Bøe 1b6007067d cmake: Invoke 'python' instead of py scripts directly
Python scripts should be executed indirectly by the python
interpreter, not directly in a CMake COMMAND. This is for portability
reasons.

Directly executing a python script depends on non-portable shebang
logic and/or "default application" behaviour.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-06-22 12:28:31 -04:00
Torsten Rasmussen 080e32efc5 cmake: Using symlinks on unix like os'es for dependencies
Fixes: #8380

This commit fixes the side-effect of PR #8211 where a 'ninja clean'
would try to remove dependency folders.
Changes:
- Symlinks are created during build and CMake targets now depends on
  the symlinks. Thus, same behavior is achived with regards to
  dependency handling, while at the same time, the output can be
  cleaned as the dependencies are now attached to the symlinks.
- Dependencies have been changed so that generation of json files
  depends on the trigger file and CMake depends upon the subdir txt
  file. This prevents additional CMake runs after a clean.

Signed-off-by: Torsten Rasmussen <torsten.rasmussen@nordicsemi.no>
2018-06-19 17:00:27 +02:00
Alex Tereschenko 3c1a78ea0d cmake: replace PROJECT_SOURCE_DIR with ZEPHYR_BASE
Both variables were used (with the same value) interchangeably
throughout CMake files and per the discussion in GH issue,
ZEPHYR_BASE is preferred.

Also add a comment with explanation of one vs. the other.

Tested by building hello_world for several boards ensuring no errors.

Fixes #7173.

Signed-off-by: Alex Tereschenko <alext.mkrs@gmail.com>
2018-06-18 15:25:55 -04:00
Aurelien Jarno e8413d18f5 kconfig: add a compiler speed optimization
Zephyr currently allows users to choose a compiler optimization
between -O0, -Og and -Os, the default being the latter as it offers a
good compromise between speed and flash usage. In cases the speed
matters and/or the flash usage doesn't, optimizing for speed with -O2
is another alternative. For example in case of a simple application
doing cryptographic signature validation with mbedtls, the flash size
increase by about 15% compared to -Os, while it provides a 15% speed
boost for a RSA signature and 30% speed boost for a ECC signature.

This patches therefore adds a new option CONFIG_SPEED_OPTIMIZATIONS
corresponding to the -O2 flag, but keep the default set to
CONFIG_SIZE_OPTIMIZATIONS.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-06-18 09:05:02 -04:00
Aurelien Jarno 92a6898bd2 cmake: allow multiple compiler options
It is currently not possible to define multiple compiler options using
the CONFIG_COMPILER_OPT Kconfig option. The string is interpreted as a
single quoted option, for example "-opt1 -opt2".

This patch fixes that by splitting the CONFIG_COMPILER_OPT string into
multiple options using the separate_arguments cmake function.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-06-18 09:05:02 -04:00
Torsten Rasmussen f38e388ad1 cmake: Update to dependency handling for syscalls.json
Fixes: #8210

Following changes has been made to ensure correct behavior on different
system:
- Python script to detect changes to directories, including empty ones.
  When files are modified the list is updated
  If sub-directories are added / removed a trigger file is touched to
  notify cmake to re-run
- Windows: To detect changes to header files in include for
           parse_syscalls.py all files must be individual monitored.
           Hence all headers are globbed added to dependencies.
           CMake configure depends on the folders so the added /
           removed files are picked up.
- Other:   Folders are monitored through the python list file so that
           added / remove / modified
           Added / removed sub-directories are detected through trigger
           file in order to re-run cmake.

Signed-off-by: Torsten Rasmussen <torsten.rasmussen@nordicsemi.no>
2018-06-13 13:22:46 +02:00
Torsten Rasmussen a74e80fa5f cmake: Removing the need for always rebuild
Fixes: #8210

This commit removes the need for always rebuild when generating the
syscalls.json.

It find the files and subfolders of the include directory and makes
syscalls depends on those.
To find added files / subfolders on all platforms CMake configure
is also depending on the folders found.
This ensures that added files / folders will also be detected at later
stages.

Signed-off-by: Torsten Rasmussen <torsten.rasmussen@nordicsemi.no>
2018-06-13 13:22:46 +02:00
Sebastian Bøe ee9af86f4c cmake: Improve user error feedback when -H$ZEPHYR_BASE is specified
Users are sometimes mistakenly invoking cmake with $ZEPHYR_BASE set as
the source directory.

This user-error can occur if the user believes that the toplevel
CMakeLists.txt file is at the root of the repo, or if the user uses
the wrong path when invoking cmake.

The error given when this user-error occurs is cryptic and undefined,
so we replace it with what should be an easy-to-understand error
message.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-06-11 17:32:50 -04:00
Ioannis Glaropoulos f90416c680 cmake: fix warning message
This commit provides a minor fix to a CMake output text which
warns the user that ASSERT() statements are enabled.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-05-31 07:04:09 -04:00
Andrew Boie 411686f02b build: suppress asserts warning if forced off
This was being incorrectly printed.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-05-24 15:12:56 -07:00
Kumar Gala 59b2c74312 cmake: Remove dead logic related to CONFIG_DEBUG_SECTION_MISMATCH
We haven't ever really had a Kconfig symbol to enable the support
related to DEBUG_SECTION_MISMATCH.  Thus this isn't really used by
anyone and we will remove it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-05-23 17:57:06 -04:00
Andy Gross 878f39c18e makefile: Fix dependencies for privileged stacks
This patch fixes the dependency chain for priviliged stack
generation.  This fixes a problem when compiling after making
significant changes that would shift the privileged stack area.

Signed-off-by: Andy Gross <andy.gross@linaro.org>
2018-05-02 10:59:40 -04:00
Rajavardhan Gundi 08172cdf83 xtensa: provide XCC compiler support for Xtensa
This patchset provides Xtensa's xcc compiler support for Xtensa
projects in Cmake. This requires the below environment variables
to be defined aptly. The appropriate xcc license information also
need to be supplied.

ZEPHYR_GCC_VARIANT=xcc
TOOLCHAIN_VER=RF-2015.3-linux
XTENSA_CORE=cavs21_LX6HiFi3_RF3_WB16
XTENSA_SYSTEM=/opt/xtensa/XtDevTools/install/tools/
		RF-2015.3-linux/XtensaTools/config/
XTENSA_BUILD_PATHS=/opt/xtensa/XtDevTools/install/builds/

Change-Id: Ib3c10e8095439b0e32276ff37c00eca8420773ec
Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-05-01 16:46:41 -04:00
Rajavardhan Gundi 7db4d5699e Revert "warnings: Disable "unused-local-typedefs" compiler warning"
This reverts commit d9ac1d4b4a.

This option can be compiler specific and is not required anymore.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-04-30 16:46:14 -04:00
Sebastian Bøe 71b849f18c cmake: Port Zephyr to use zephyr_check_compiler_flag
This commit ports nearly all usage of check_c_compiler_flag,
check_cxx_compiler_flag, and check_compiler_flag to use
zephyr_check_compiler_flag instead.

This has a significant CMake configure-time performance impact.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-04-27 12:06:02 +02:00
Leandro Pereira 39dc7d03f7 scripts: gen_kobject_list: Generate enums and case statements
Adding a new kernel object type or driver subsystem requires changes
in various different places.  This patch makes it easier to create
those devices by generating as much as possible in compile time.

No behavior change.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-04-26 02:57:12 +05:30
Leandro Pereira c200367b68 drivers: Perform a runtime check if a driver is capable of an operation
Driver APIs might not implement all operations, making it possible for
a user thread to get the kernel to execute a function at 0x00000000.

Perform runtime checks in all the driver handlers, checking if they're
capable of performing the requested operation.

Fixes #6907.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-04-26 02:57:12 +05:30
Leandro Pereira d9ac1d4b4a warnings: Disable "unused-local-typedefs" compiler warning
This is required to have BUILD_ASSERT() from toolchain/common.h to
work without issuing a warning.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-04-24 04:04:36 +05:30
Sebastian Bøe c1aa9d16e9 cmake: Fix CONFIG_CUSTOM_LINKER_SCRIPT
Specifying a custom linker script is supposed to be supported through
Kconfig, but evidently this has been unused and 100% broken at least
since the CMake migration.

This commit fixes
https://github.com/zephyrproject-rtos/zephyr/issues/6983

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-04-12 18:31:33 -04:00
Anas Nashif daf7716ddd build: use git version and hash for boot banner
This uses the version and hash (git describe) and replaces the timestamp
currently used in the boot banner. This works much better than using
timestamps. It lets us point to the exact commit being used to run a
certain application or test.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-04-10 10:57:50 -04:00
Sebastian Bøe 87031e3cf9 cmake: Find out earlier whether ccache is to be used or not
Moving the ccache build script earlier in allows us to export ccache
to external projects. Using ccache with external projects, such as
OpenThread, can significantly speed up the build time.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-03-02 07:13:21 +01:00
Kumar Gala 440cc18d1b cmake: Move SOC_* var defines to cmake/app/boilerplate.cmake
We need access to SOC_PATH in dts.cmake so we need to move the
definitions of SOC_NAME, SOC_SERIES, SOC_FAMILY, and SOC_PATH out of the
toplevel CMakeLists.txt and into cmake/app/boilerplate.cmake.  We place
them before we include cmake/dts.cmake so they will be available to use
in it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-02-22 10:14:02 -06:00
Wayne Ren 5a0ba2faa5 cmake: disable privilege stack generation for arc
Currently, ARC will not use privilege stack generation.

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-02-16 12:20:16 +01:00
Andy Gross e1fc5c21fc cmake: Add CONFIG_APPLICATION_MEMORY constraint
This patch adds an additional constraint to make sure that we only
do the application memory sizing if it is really necessary.

Signed-off-by: Andy Gross <andy.gross@linaro.org>
2018-02-15 08:37:20 -06:00
Anas Nashif 7ee8bb9677 build: deprecate ZEPHYR_GCC_VARIANT
We want to support other toolchain not based on GCC, so the variable is
confusing, use ZEPHYR_TOOLCHAIN_VARIANT instead.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-02-13 07:44:45 -08:00
Kristian Klomsten Skordal 0225e952ff cmake: ld: add application source dir to linker script cpp command
To enable using application-defined sections in linker scripts, the
application source directory must be included in the search path when
running the preprocessor to generate linker scripts.

This prevents build failures when using any of the configuration options
CONFIG_CUSTOM_RODATA_LD, CONFIG_CUSTOM_RWDATA_LD and
CONFIG_CUSTOM_SECTIONS_LD.

Signed-off-by: Kristian Klomsten Skordal <kristian.skordal@nordicsemi.no>
2018-02-08 15:57:32 -08:00
Rajavardhan Gundi 1e6adba9ef drivers/interrupt_controller: Introduce multi-level interrupt support
In a scenario where a platform harbours multiple interrupts to the
extent the core cannot support it, an interrupt controller is added
as an additional level of interrupt. It typically combines several
sources of interrupt into one line that is then routed to the parent
controller.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-02-06 22:39:05 -05:00
Chunlin Han 18560a01a4 arm: Generate privileged stacks
This patch adds the generation and incorporation of privileged stack
regions that are used by ARM user mode threads.  This patch adds the
infrastructure for privileged stacks.  Later patches will utilize the
generated stacks and helper functions.

Signed-off-by: Chunlin Han <chunlin.han@linaro.org>
Signed-off-by: Andy Gross <andy.gross@linaro.org>
2018-02-06 15:31:16 -08:00
Andy Gross e8860fe8be arm: Add app data section alignment constraints
This patch adds application data section alignment constraints
to match the region definition requirements for ARM MPUs.  Most MPUs
require a minimum of 32 bytes of alignment for any regions, but some
require power of two alignment to the size of a region.

This requires that the linker align the application data section to
the size of the section.  This requires a linker pass to determine the
size.  Once this is accomplished the correct value is added to a linker
include file that is utilized in subsequent linker operations.

Signed-off-by: Andy Gross <andy.gross@linaro.org>
2018-02-06 15:31:16 -08:00
Andy Gross 1f0ff06e38 makefile: Convert linker function to use names
This patch changes the way the custom linker function works.  It uses
names instead of numbers to denote the name of the file and applies
the correct LINKER_PASS variable for the final linker pass.

Signed-off-by: Andy Gross <andy.gross@linaro.org>
2018-02-06 15:31:16 -08:00
Adithya Baglody ce9a5a2354 cmake: kobject: Fixed kobject text area overflow for optimization 0
We need to allocate extra memory region for the hash function
that the gperf generates. The linker will need to maintain
the same location counter between multiple linker stages. Reserving
memory will help in maintaing correct location counters between
multiple stages. The required memory varies with optimization level.
In order to keep the size of the compiled object consistent,
the kobject_hash.c is always compiled with -Os.

fixes #5226

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-02-05 07:52:42 -08:00
Sebastian Bøe 600c8f7d85 kconfig: Change how optimization level is set
This patch does several things, most notably it changes the semantics
of CONFIG_DEBUG. CONFIG_DEBUG continues to behave as a vaguely defined
"debug mode" that enables printf's, -Og, etc. but now the user may
choose to be in "debug mode" while using a different optimization
level than -Og.

Tp support this a new config is defined to enable -Og;
CONFIG_DEBUG_OPTIMIZATIONS.

Additionally CONFIG_SIZE_OPTIMIZATIONS is introduced to allow the user
to explicitly request optimizing for size instead of relying on
defaulting to it.

The three config's {NO,SIZE,DEBUG}_OPTIMIZATIONS are now organized in
a Kconfig choice to ensure that at most one can be enabled at a time.

Finally, selected users of CONFIG_DEBUG have been ported to use one of
the optimizations configs when it was clear from usage that the
intention was to behave differently when using a different
optimization level and not when in "debug mode".

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-02-05 06:23:20 -08:00
Alberto Escolar Piedras f60527a138 build: Added CONFIG_NO_OPTIMIZATIONS
Added a new config option which lowers the compiler
optimizations to -O0 independently of other flags.

CONFIG_COVERAGE uses it now instead of having its own
choice in CMakeLists.txt

Fixes #5720

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-02-05 06:23:20 -08:00
Sebastian Bøe f5758b5d97 cmake: Fix dependencies between kobject_hash files
CMake's custom_command support is not great. It is technically
supported, but it is not easy to get it right.

As explained in "5. File-level dependencies of custom targets are not
propagated" from http://bit.ly/2GvwwEy. When a custom_command uses a
custom_target as input, the custom_command must DEPEND on both the
custom_target and the underlying file.

Longterm we need to do something more sofisticated to prevent these
issues from popping up. Like add some static analysis to detect badly
written CMake code or introduce an abstraction for custom commands
that is not affect by this issue.

This fixes #5881

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-31 05:54:19 -05:00
Patrick Boettcher 840953271d cmake: do not set CMAKE_SKIP_INSTALL_RULES to ON
This CMakeLists.txt is added via add_subdirectory() to the app's
CMakeLists.txt. If the app-CMakeLists.txt has install() rules and
wants to use them, setting CMAKE_SKIP_INSTALL_RULES to ON breaks
the 'make install' call.

Not setting this variable does not harm zephyr because zephyr does
not use install().

Signed-off-by: Patrick Boettcher <patrick.boettcher@posteo.de>
2018-01-29 15:12:03 -05:00
Andrew Boie df48e11d98 build: warn user about Meltdown vulnerability
A fix for this issue is in progress, meanwhile warn the user that
they may be susceptible to this problem if they enable user mode on
an x86-based target that is not known to be immune.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-01-12 15:12:32 -08:00
Sebastian Bøe 6f946e20b6 cmake: Execute arch/CMakeLists.txt before subsys/CMakeList.txt
Re-order the execution of the arch/ and subsys/ CMakeLists.txt code to
work around a manifestation of issue #6505. When OpenThread created an
External project in subsys, it did not have access to important
toolchain flags added in arch/.

Intuitively, subsystems might depends on how the ARCH is configured,
but the ARCH shouldn't depend on any subsystem.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-11 16:06:55 -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 64edbaf64c cmake: Don't assert that imported zephyr libraries have source files
A Zephyr library not having source files is usually due to a
misconfiguration and will lead to an obscure error message. But
imported Zephyr libraries don't have source files so we need to skip
the source file when a library is imported.

An imported Zephyr library is normally used to reference externally
built code, either prebuilt or recursively built through an external
build system.

This fixes #5497

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-09 11:46:40 -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
Sebastian Bøe a55279ac90 cmake: gen_isr_tables: Reduce verbosity of non-verbose builds.
gen_isr_tables.py's --debug flag causes it to spit out a verbose
log. Normal builds don't need to see this information.

This patch will remove this from the build log:

gen_isr_tables.py: (4041, 4477, 46, 0, 7)
gen_isr_tables.py: spurious handler: 0xfc9
gen_isr_tables.py: Configured interrupt routing
gen_isr_tables.py: handler    irq flags param
gen_isr_tables.py: --------------------------
gen_isr_tables.py: 0x14bd     0   0     0x0
gen_isr_tables.py: 0x16a1     6   0     0x20002bac
gen_isr_tables.py: 0x1975     17  0     0x0
gen_isr_tables.py: 0x7e5b     13  0     0x0
gen_isr_tables.py: 0x7e55     24  0     0x0
gen_isr_tables.py: 0x7e21     11  0     0x0
gen_isr_tables.py: 0x7e5f     1   1     0x0

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-04 08:55:26 -05:00
Sebastian Bøe b1ab5018ba cmake: ld: Ensure that a linker script change triggers a rebuild
This fixes
https://github.com/zephyrproject-rtos/zephyr/issues/5010. CMake has a
simple parser that can parse C-like files to find header
dependencies. But the parser needs to know what the include
directories are to be able to follow #include pragmas.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-04 00:03:25 -05:00
Sebastian Bøe 8062a88e82 cmake: LD: Add comment explaining the -P flag
Add a comment that explains what the -P flag does. The explanatory
comment is useful when you want to find the flag so you can comment it
out while debugging the link stage.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-03 13:19:59 -05:00
Sebastian Bøe 1c2de10c06 cmake: ninja: Change how CMake names the kernelspace archives
The linker script places kernelspace and userspace archives in
different sections. But the linker script itself does not determine
what archives are in what space, that is done by CMake.

CMake passes the list of kernelspace archives to the linker script
through defines, like this:

-DNUM_KERNEL_OBJECT_FILES=3
-DKERNEL_OBJECT_FILE_0=path/to/archive_a.a
-DKERNEL_OBJECT_FILE_1=path/to/archive_b.a
-DKERNEL_OBJECT_FILE_2=path/to/archive_c.a

These paths are relative, and since Ninja and Make invoke the linker
with different "working directories"[0], the relative paths need to be
different. This patch rectifies the relative path when using Ninja.

This fixes #5343

[0] https://gitlab.kitware.com/cmake/cmake/issues/17448

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-03 13:19:59 -05:00
Sebastian Bøe a0b9129e85 cmake: Ninja: ld: Use the correct depfile in the second pass
When building for Ninja we were accidentally using the wrong depfile
in the second pass. This commit moves the LINKER_SCRIPT_DEP logic into
the custom command function so that it can be linker-pass-aware and
set the depfile appropriately.

This should fix an issue where Ninja reported:

ninja: error: expected depfile 'zephyr/linker.cmd.dep' to mention
'zephyr/linker_pass2.cmd', got 'zephyr/linker.cmd'

But this has not been reproduced. It has however been confirmed that a
dependency issue with linker_pass2.cmd has been fixed because ninja no
longer regenerates linker_pass2.cmd on every build like this:

$ ninja
[1/79] Generating always_rebuild
Building for board qemu_x86
[2/3] Generating linker_pass2.cmd
[3/3] Linking C executable zephyr/zephyr.elf

Now:

$ ninja
[1/78] Generating always_rebuild
Building for board qemu_x86

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-03 13:19:59 -05:00
Sebastian Bøe b85dd3c238 cmake: ld: Refactor the linker script's cpp command construction
Construct the custom command for preprocessing the linker script with
a function to avoid copy-paste errors between linker passes.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-03 13:19:59 -05:00
Anas Nashif 34aebad4b1 coverage: build with -O0 to get more information
per the gcov man page:

 You should compile your code without optimization if you plan to use
 gcov because the optimization, by combining some lines of code into one
 function, may not give you as much information .

Fixes #5548

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-01-03 13:12:03 -05:00
Sebastian Bøe c34b7a3f65 cmake: Fix CMAKE_REQUIRED_FLAGS corruption
The --print-memory-usage check was accidentally corrupting the
CMAKE_REQUIRED_FLAGS variable due to a variable de-referencing bug.

This was affecting app CMakeLists.txt code that was using
CMAKE_REQUIRED_FLAGS.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-28 11:37:09 -05:00
Anas Nashif 72fe097bc0 testing: add option to generate coverage reports
With the native port we are able to generate coverage reports, add the
needed options to the compliler and add a kconfig option to enable this
on the supported architectures.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-27 14:16:08 -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 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