Commit graph

466 commits

Author SHA1 Message Date
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
Alberto Escolar Piedras 76f7644118 arch: native: Run Zephyr natively in a POSIX OS
A new arch (posix) which relies on pthreads to emulate the context
switching
A new soc for it (inf_clock) which emulates a CPU running at an
infinely high clock (so when the CPU is awaken it runs till completion
in 0 time)
A new board, which provides a trivial system tick timer and
irq generation.

Origin: Original

Fixes #1891

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-27 14:16:08 -05:00
Anas Nashif 5146dbbc58 arch: architecture defines kernel entry
Make defining the kernel entry architecture specific and move it to the
architecture domain.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-27 14:16:08 -05:00
Sebastian Bøe ba0b2836e8 cmake: Fix the -Wl,--print-memory-usage compatibility test
-Wl,--print-memory-usage is a relatively new LD feature (2015) and is
not supported by the espressif toolchain. Unfortunately the toolchain
compatibility test was broken as it was not using the flag when
linking.

The root cause lies in how we test LD compatibility and this same fix
must be applied again in e.g. target_ld_options().

This patch fixes
https://github.com/zephyrproject-rtos/zephyr/issues/5458

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-21 11:06:56 -05:00
Sebastian Bøe dbdd722239 ld: Introduce --print-memory-usage
Pass the --print-memory-usage to the linker on the first link if the
toolchain supports it.

Don't use this option with the second link because seeing it twice
could confuse users and using it on the second link would suppress it
when the first link has a ram/flash-usage issue.

Note that the memory regions are symbolic concepts defined by the
linker scripts and do not necessarily map directly to the real
physical address space. Take also note that some platforms do two
passes of the linker so the results do not match exactly to the final
elf file. See also rom_report, ram_report and
https://sourceware.org/binutils/docs/ld/MEMORY.html

This is particularly useful when the linker fails due to excessive
flash/ram usage. When a section does not fit into a memory region the
linker will exit with an error code and will state how big the
overflow was. But it doesn't state what the memory region size is, or
what memory regions exist, which is good to know when debugging
overflow issues.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-19 16:57:11 -05:00
Sebastian Bøe 4ece94df6f cmake: Fail with an error message when empty libraries exist
A very annoying usability issue is that the error message is very
cryptic when you create a zephyr library that doesn't have any source
files. Creating such a library is very easy to do, so we should have a
good error message for it.

It was also considered to allow empty libraries to exist, but this was
decided against as they show up in the build output and can confuse
the end user.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-10 19:51:54 -05:00
Sebastian Bøe 89516fbc25 cmake: Change the zephyr_get_* API to be LANG-aware
When exporting flags to an external build system we need to deal with
the fact that we sometimes use generator expressions. Specifically, we
use generator expressions that look like this:

$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>

This patch replaces the old API with a new one where users can ask for
compile options for specific languages, like this:

zephyr_get_compile_options_for_lang_as_string(CXX x)

The existing API would have either crashed or silently omitted flags
when a COMPILE_LANG generator expression was present.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-05 10:08:40 -05:00
Gustavo Lima Chaves 4c4189242f cmake: honor again CONFIG_KERNEL_ENTRY
This was impacting Jailhouse port, at least.

Signed-off-by: Gustavo Lima Chaves <gustavo.lima.chaves@intel.com>
2017-12-04 21:02:06 -05:00
Sebastian Bøe 13a6840261 cmake: Re-organize syscall generation wrt. the build system
This commit fixes
https://github.com/zephyrproject-rtos/zephyr/issues/5008.

It does so by splitting up gen_syscalls.py into two scripts with a
json metadata file to communicate syscall metadata between them. The
parsing script parses header files from include/ and writes syscall
metadata to a file if the contents changed. The generation script
reads from the json file and generates syscall code.

The build system DAG now looks like this:

always_rebuild -> json -> syscalls -> offset.o

The script for generating json will do so only if the content changes,
this ensures that the entire DAG does not always do a full rebuild.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-12-04 10:51:07 -08:00
Sebastian Bøe 2ead15de8d cmake: Move syscall_macros.h generation into the build stage
This fixes https://github.com/zephyrproject-rtos/zephyr/issues/5186

The script that generates syscall_macros.h is moved from Configuration
time to build time. This allows us to express to the build system that
syscall_macros.h depends on the script that generates it.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-11-30 06:49:33 -05:00
Sebastian Bøe 703dc59baa kernel: stack: add -fstack-protector-all without checks
Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-11-29 09:51:55 -05:00
Sebastian Bøe 033fe7ed74 Revert "kernel: stack: add -fstack-protector-all without checks"
This reverts commit eb88bf2e62.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2017-11-29 09:51:55 -05:00
Anas Nashif eb88bf2e62 kernel: stack: add -fstack-protector-all without checks
Fixes #5019

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-11-28 16:48:41 -05:00
Anas Nashif 1f1143ac87 build: use kconfig to select generated artifacts
Not all boards require the various binary formats zephyr generates. So
be selective based on the arch, SoC or board and only geenrate the
binaries actually needed.

Fixes #5009

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-11-23 07:29:13 -05:00
Sebastian Bøe e51ce4d34d cmake: Generate POST_BUILD items based on KConfig
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-22 13:29:37 -05:00
Sebastian Bøe 9f59045546 cmake: Refactored EXTRA_FLAGS code into a dedicated script
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-15 19:47:44 -05:00
Sebastian Bøe 12f8f76165 Introduce cmake-based rewrite of KBuild
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.

This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.

For users that just want to continue their work with minimal
disruption the following should suffice:

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..

$ cd build
$ make

PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00