|
|
|
@ -32,14 +32,24 @@ An application in the simplest form has the following structure:
|
|
|
|
|
configuration option values are used; if no existing values are provided,
|
|
|
|
|
the kernel's default configuration values are used.
|
|
|
|
|
|
|
|
|
|
* **Makefile**: This file tells the build system where to find the files
|
|
|
|
|
* **CMakeLists.txt**: This file tells the build system where to find the files
|
|
|
|
|
mentioned above, as well as the desired target board configuration.
|
|
|
|
|
|
|
|
|
|
Once the application has been defined, it can be built with a single ``make``
|
|
|
|
|
call.
|
|
|
|
|
The results of the build process are located in a sub-directory called
|
|
|
|
|
:file:`outdir/BOARD`. This directory contains the files generated by the build
|
|
|
|
|
process, the most notable of which are listed below.
|
|
|
|
|
Once the application has been defined, project files for building it
|
|
|
|
|
can be generated by calling cmake. The project files will be written
|
|
|
|
|
to the directory where cmake was called, this directory is known as
|
|
|
|
|
the build directory.
|
|
|
|
|
|
|
|
|
|
The most notable files in the build directory are listed below.
|
|
|
|
|
|
|
|
|
|
* The :file:`Makefile` (or :file:`build.ninja`) project file that can
|
|
|
|
|
be invoked to build the application.
|
|
|
|
|
|
|
|
|
|
* The :file:`zephyr` directory is the working directory of the
|
|
|
|
|
generated build system and where most generated files are located.
|
|
|
|
|
|
|
|
|
|
After the underlying build tool has been invoked the build output will
|
|
|
|
|
be written to the :file:`zephyr` directory.
|
|
|
|
|
|
|
|
|
|
* The :file:`.config` file that contains the configuration settings
|
|
|
|
|
used to build the application.
|
|
|
|
@ -51,14 +61,13 @@ process, the most notable of which are listed below.
|
|
|
|
|
kernel binary.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Application Structure
|
|
|
|
|
*********************
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Create one directory for your application and a sub-directory for the
|
|
|
|
|
application's source code; this makes it easier to organize directories and
|
|
|
|
|
files in the structure that the kernel expects.
|
|
|
|
|
application's source code; this makes it easier to distinguish between
|
|
|
|
|
project files and source code.
|
|
|
|
|
|
|
|
|
|
#. Create an application directory structure outside of the kernel's
|
|
|
|
|
installation directory tree. Often this is your workspace directory.
|
|
|
|
@ -95,28 +104,22 @@ files in the structure that the kernel expects.
|
|
|
|
|
Application Definition
|
|
|
|
|
**********************
|
|
|
|
|
|
|
|
|
|
An application is integrated into the build system by including the Makefile.inc
|
|
|
|
|
file provided.
|
|
|
|
|
An application is integrated into the build system with two lines of
|
|
|
|
|
boilerplate code in it's :file:`CMakeLists.txt` file and by having the
|
|
|
|
|
environment variable :makevar:`ZEPHYR_BASE` set.
|
|
|
|
|
|
|
|
|
|
.. code-block:: make
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
include $(ZEPHYR_BASE)/Makefile.inc
|
|
|
|
|
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
|
|
|
|
project(NONE)
|
|
|
|
|
|
|
|
|
|
The following predefined variables configure the development project:
|
|
|
|
|
|
|
|
|
|
* :makevar:`ZEPHYR_BASE`: Sets the path to the kernel's base directory.
|
|
|
|
|
This variable is usually set by the :file:`zephyr_env.sh` script.
|
|
|
|
|
It can be used to get the kernel's base directory, as used in the
|
|
|
|
|
Makefile.inc inclusion above, or it can be overridden to select an
|
|
|
|
|
specific instance of the kernel.
|
|
|
|
|
|
|
|
|
|
* :makevar:`PROJECT_BASE`: Provides the developer's application project
|
|
|
|
|
directory path. It is set by the :file:`Makefile.inc` file.
|
|
|
|
|
|
|
|
|
|
* :makevar:`SOURCE_DIR`: Overrides the default value for the application's
|
|
|
|
|
source code directory. The developer source code directory is set to
|
|
|
|
|
:file:`$(PROJECT_BASE)/src/` by default. This directory name should end
|
|
|
|
|
with slash **'/'**.
|
|
|
|
|
* :makevar:`ZEPHYR_BASE`: Sets the path to the kernel's base
|
|
|
|
|
directory. This variable is usually set by the
|
|
|
|
|
:file:`zephyr_env.sh` script. It can be used to get the kernel's
|
|
|
|
|
base directory, as used in the boilerplate above, or it can be
|
|
|
|
|
overridden to select an specific instance of the kernel.
|
|
|
|
|
|
|
|
|
|
* :makevar:`BOARD`: Selects the board that the application's
|
|
|
|
|
build will use for the default configuration.
|
|
|
|
@ -125,155 +128,96 @@ The following predefined variables configure the development project:
|
|
|
|
|
This file includes the kconfig configuration values that override the
|
|
|
|
|
default configuration values.
|
|
|
|
|
|
|
|
|
|
* :makevar:`O`: Optional. Indicates the output directory that Kconfig uses.
|
|
|
|
|
The output directory stores all the files generated during the build
|
|
|
|
|
process. The default output directory is the :file:`$(PROJECT_BASE)/outdir`
|
|
|
|
|
directory.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Makefiles
|
|
|
|
|
CMake
|
|
|
|
|
*********
|
|
|
|
|
|
|
|
|
|
Overview
|
|
|
|
|
========
|
|
|
|
|
|
|
|
|
|
The build system defines a set of conventions for the correct use of Makefiles
|
|
|
|
|
in the kernel source directories. The correct use of Makefiles is driven by the
|
|
|
|
|
concept of recursion.
|
|
|
|
|
CMake is used to build Zephyr. A CMake build is done in two
|
|
|
|
|
stages. The first stage is called Configuration, during Configuration
|
|
|
|
|
the CMakeLists.txt build scripts are executed. At the end of
|
|
|
|
|
Configuration, CMake will have an internal model of the Zephyr build
|
|
|
|
|
and can generate build scripts that are native to the host platform.
|
|
|
|
|
|
|
|
|
|
In the recursion model, each Makefile within a directory includes the source
|
|
|
|
|
code and any subdirectories to the build process. Each subdirectory follows
|
|
|
|
|
the same principle. Developers can focus exclusively in their own work. They
|
|
|
|
|
integrate their module with the build system by adding a very simple Makefile
|
|
|
|
|
following the recursive model.
|
|
|
|
|
CMake supports generating several build systems, but only Ninja and
|
|
|
|
|
Make are tested and supported by Zephyr. After Configuration and
|
|
|
|
|
Generation the user can begin the Build stage by executing the
|
|
|
|
|
generated build system. The build system will for most code changes be
|
|
|
|
|
able to re-build the application without involving CMake. But for
|
|
|
|
|
certain configuration changes the Configuration step will need to be
|
|
|
|
|
executed again, either automatically by the build system, or even
|
|
|
|
|
manually in some cases.
|
|
|
|
|
|
|
|
|
|
.. _makefile_conventions:
|
|
|
|
|
Zephyr uses CMake's concept of a 'target' to organize the build. A
|
|
|
|
|
target can be an executable, a library, or a generated file. For
|
|
|
|
|
application developers, the library target is the most important to
|
|
|
|
|
understand. All source code that goes into a Zephyr build does so by
|
|
|
|
|
being included in a library target, even application code.
|
|
|
|
|
|
|
|
|
|
Makefile Conventions
|
|
|
|
|
====================
|
|
|
|
|
Library targets have source code, that is added through CMakeLists.txt
|
|
|
|
|
build scripts like this:
|
|
|
|
|
|
|
|
|
|
The following conventions restrict how to add modules and Makefiles to the
|
|
|
|
|
build system. These conventions ensure the correct implementation of the
|
|
|
|
|
recursive model.
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
* Each source code directory must contain a single Makefile. Directories
|
|
|
|
|
without a Makefile are not considered source code directories.
|
|
|
|
|
target_sources(app PRIVATE src/main.c)
|
|
|
|
|
|
|
|
|
|
* The scope of every Makefile is restricted to the contents of that directory.
|
|
|
|
|
A Makefile can only make a direct reference to files and subdirectories on the
|
|
|
|
|
same level or below.
|
|
|
|
|
In the above code an existing library target named 'app' is being
|
|
|
|
|
configured to have the source file src/main.c. The PRIVATE keyword
|
|
|
|
|
indicates that we are modifying the internals of how the library is
|
|
|
|
|
being built. Whereas using the keyword 'PUBLIC' would modify how other
|
|
|
|
|
libraries that link with app are built. In this case, using PUBLIC
|
|
|
|
|
here would cause libraries that link with app to also include the
|
|
|
|
|
source file src/main.c, behaviour that we surely do not want. The
|
|
|
|
|
'PUBLIC' keyword could however be useful when modifying the include
|
|
|
|
|
paths of a target library.
|
|
|
|
|
|
|
|
|
|
* Makefiles list the object files that are included in the link process. The
|
|
|
|
|
build system finds the source file that generates the object file by matching
|
|
|
|
|
the object file name to the source file.
|
|
|
|
|
Application CMakeLists.txt
|
|
|
|
|
**************************
|
|
|
|
|
|
|
|
|
|
* Parent directories add their child directories into the recursion model.
|
|
|
|
|
Every application must have a CMakeLists.txt file. The application
|
|
|
|
|
CMakeLists.txt file is the entry point, or toplevel of the build
|
|
|
|
|
system that builds the :file:`zephyr.elf` image. :file:`zephyr.elf`
|
|
|
|
|
contains both the application and the kernel libraries.
|
|
|
|
|
|
|
|
|
|
* The root Makefile adds the directories in the kernel base directory into the
|
|
|
|
|
recursion model.
|
|
|
|
|
#. Open the :file:`CMakeLists.txt` and add the following mandatory
|
|
|
|
|
entries using any text editor.
|
|
|
|
|
|
|
|
|
|
Adding Source Files
|
|
|
|
|
===================
|
|
|
|
|
|
|
|
|
|
The Makefile must refer the source build indirectly, specifying the object file
|
|
|
|
|
that results from the source file using the :literal:`obj-y` variable. For
|
|
|
|
|
example, if the file that we want to add is a C file named :file:`<file>.c` the
|
|
|
|
|
following line should be added in the Makefile:
|
|
|
|
|
|
|
|
|
|
.. code-block:: make
|
|
|
|
|
|
|
|
|
|
obj-y += <file>.o
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
The same method applies for assembly files with the .S extension.
|
|
|
|
|
|
|
|
|
|
Source files can be added conditionally using configuration options. For
|
|
|
|
|
example, if the option ``CONFIG_VAR`` is set and it implies that a source
|
|
|
|
|
file must be added in the compilation process, then the following line adds the
|
|
|
|
|
source code conditionally:
|
|
|
|
|
|
|
|
|
|
.. code-block:: none
|
|
|
|
|
|
|
|
|
|
obj-$(CONFIG_VAR) += <file>.o
|
|
|
|
|
|
|
|
|
|
Adding Directories
|
|
|
|
|
==================
|
|
|
|
|
|
|
|
|
|
Add a subdirectory to the build system by editing the Makefile in its
|
|
|
|
|
directory. The subdirectory is added using the :literal:`obj-y` variable. The
|
|
|
|
|
correct syntax to add a subdirectory into the build queue is:
|
|
|
|
|
|
|
|
|
|
.. code-block:: make
|
|
|
|
|
|
|
|
|
|
obj-y += <directory_name>/
|
|
|
|
|
|
|
|
|
|
The backslash at the end of the directory name signals the build system that a
|
|
|
|
|
directory, and not a file, is being added to the build queue.
|
|
|
|
|
|
|
|
|
|
The conventions require us to add only one directory per line and never to mix
|
|
|
|
|
source code with directory recursion in a single :literal:`obj-y` line. This
|
|
|
|
|
helps keep the readability of the Makefile by making it clear when an item adds
|
|
|
|
|
an additional lever of recursion.
|
|
|
|
|
|
|
|
|
|
Directories can also be conditionally added:
|
|
|
|
|
|
|
|
|
|
.. code-block:: none
|
|
|
|
|
|
|
|
|
|
obj-$(CONFIG_VAR) += <directory_name>/
|
|
|
|
|
|
|
|
|
|
The subdirectory must contain its own Makefile following the rules described in
|
|
|
|
|
:ref:`makefile_conventions`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Application Makefile
|
|
|
|
|
********************
|
|
|
|
|
|
|
|
|
|
Create an application Makefile to define basic information, such as the board
|
|
|
|
|
configuration used by the application. The build system uses the Makefile to
|
|
|
|
|
build a :file:`zephyr.elf` image that contains both the application and the
|
|
|
|
|
kernel libraries.
|
|
|
|
|
|
|
|
|
|
#. Open the :file:`Makefile` and add the following mandatory
|
|
|
|
|
entries using any standard text editor.
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
Ensure that there is a space before and after each ``=``.
|
|
|
|
|
|
|
|
|
|
#. Add the name of the default board configuration for your application on a
|
|
|
|
|
#. Add the name of the board configuration for your application on a
|
|
|
|
|
new line:
|
|
|
|
|
|
|
|
|
|
.. code-block:: make
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
BOARD = board_configuration_name
|
|
|
|
|
set(BOARD qemu_x86)
|
|
|
|
|
|
|
|
|
|
The supported boards can be found in :ref:`boards`.
|
|
|
|
|
|
|
|
|
|
#. Add the name of the default kernel configuration file for your
|
|
|
|
|
application on a new line:
|
|
|
|
|
#. Include the mandatory boilerplate that integrates the application
|
|
|
|
|
with the Zephyr build system on a new line:
|
|
|
|
|
|
|
|
|
|
.. code-block:: make
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
CONF_FILE ?= kernel_configuration_name
|
|
|
|
|
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
|
|
|
|
project(NONE)
|
|
|
|
|
|
|
|
|
|
#. Include the mandatory :file:`Makefile` on a new line:
|
|
|
|
|
#. Add any application source files to the 'app' target library:
|
|
|
|
|
|
|
|
|
|
.. code-block:: make
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
include ${ZEPHYR_BASE}/Makefile.inc
|
|
|
|
|
target_sources(app PRIVATE src/main.c)
|
|
|
|
|
|
|
|
|
|
#. Save and close the :file:`Makefile`.
|
|
|
|
|
#. Save and close the :file:`CMakeLists.txt`.
|
|
|
|
|
|
|
|
|
|
Below is an example CMakeList.txt:
|
|
|
|
|
|
|
|
|
|
Below is an example Makefile:
|
|
|
|
|
.. code-block:: cmake
|
|
|
|
|
|
|
|
|
|
.. code-block:: make
|
|
|
|
|
set(BOARD qemu_x86)
|
|
|
|
|
|
|
|
|
|
BOARD = qemu_x86
|
|
|
|
|
CONF_FILE = prj.conf
|
|
|
|
|
include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE)
|
|
|
|
|
project(NONE)
|
|
|
|
|
|
|
|
|
|
include ${ZEPHYR_BASE}/Makefile.inc
|
|
|
|
|
target_sources(app PRIVATE src/main.c)
|
|
|
|
|
|
|
|
|
|
.. _application_configuration:
|
|
|
|
|
|
|
|
|
@ -289,10 +233,10 @@ The available sources are (in order):
|
|
|
|
|
|
|
|
|
|
#. The application's current configuration. (i.e. The :file:`.config` file.)
|
|
|
|
|
|
|
|
|
|
#. The application's default configuration. (i.e. The :file:`.conf` file.)
|
|
|
|
|
#. The application's default configuration. (Specified by ``CONF_FILE``, i.e. :file:`prj.conf`.)
|
|
|
|
|
|
|
|
|
|
#. The board configuration used by the application.
|
|
|
|
|
(i.e. The board's :file:`.defconfig` file.)
|
|
|
|
|
(i.e. The board's :file:`_defconfig` file.)
|
|
|
|
|
|
|
|
|
|
#. The kernel's default configuration.
|
|
|
|
|
(i.e. One of the kernel's :file:`Kconfig` files.)
|
|
|
|
@ -322,8 +266,10 @@ in :file:`$ZEPHYR_BASE/boards/ARCHITECTURE/BOARD/BOARD_defconfig`.
|
|
|
|
|
|
|
|
|
|
$ vim prj.conf
|
|
|
|
|
|
|
|
|
|
The default name is :file:`prj.conf`. The filename must match the
|
|
|
|
|
``CONF_FILE`` entry in the application :file:`Makefile`.
|
|
|
|
|
The application's default configuration is specified by
|
|
|
|
|
``CONF_FILE``, ``CONF_FILE`` defaults to :file:`prj.conf` unless
|
|
|
|
|
configured otherwise in the application :file:`CMakeLists.txt`
|
|
|
|
|
file.
|
|
|
|
|
|
|
|
|
|
#. Edit the file and add the appropriate configuration entries.
|
|
|
|
|
|
|
|
|
@ -363,7 +309,7 @@ Configure the kernel options using a menu-driven interface. While you can add
|
|
|
|
|
entries manually, using the configuration menu is a preferred method.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#. Run the :command:`make menuconfig` rule to launch the menu-driven interface.
|
|
|
|
|
#. After generating project files run :command:`ninja menuconfig` to launch the menu-driven interface.
|
|
|
|
|
|
|
|
|
|
a) In a terminal session, navigate to the application directory
|
|
|
|
|
(:file:`~/app`).
|
|
|
|
@ -372,7 +318,8 @@ entries manually, using the configuration menu is a preferred method.
|
|
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
|
|
$ make [BOARD=<type>] menuconfig
|
|
|
|
|
$ cmake -Bbuild -H. -GNinja
|
|
|
|
|
$ ninja -C build menuconfig
|
|
|
|
|
|
|
|
|
|
A question-based menu opens that allows you to set individual configuration
|
|
|
|
|
options.
|
|
|
|
@ -427,9 +374,8 @@ entries manually, using the configuration menu is a preferred method.
|
|
|
|
|
Typically, you will save to the default file name unless you are
|
|
|
|
|
experimenting with various configuration scenarios.
|
|
|
|
|
|
|
|
|
|
An :file:`outdir` directory is created in the application directory. The
|
|
|
|
|
outdir directory contains symbolic links to files under
|
|
|
|
|
:file:`\$ZEPHYR_BASE`.
|
|
|
|
|
A :file:`zephyr` directory will have been created in the build
|
|
|
|
|
directory.
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
@ -439,7 +385,7 @@ entries manually, using the configuration menu is a preferred method.
|
|
|
|
|
:file:`.config`, rename it to something other than :file:`.config`.
|
|
|
|
|
|
|
|
|
|
Kernel configuration files, such as the :file:`.config` file, are saved
|
|
|
|
|
as hidden files in :file:`outdir`. To list all your kernel configuration
|
|
|
|
|
as hidden files in :file:`zephyr`. To list all your kernel configuration
|
|
|
|
|
files, enter :command:`ls -a` at the terminal prompt.
|
|
|
|
|
|
|
|
|
|
The following dialog opens, displaying the file name the configuration
|
|
|
|
@ -488,16 +434,10 @@ entries manually, using the configuration menu is a preferred method.
|
|
|
|
|
Application-Specific Code
|
|
|
|
|
*************************
|
|
|
|
|
|
|
|
|
|
Application-specific source code files are normally added to the application's
|
|
|
|
|
:file:`src` directory. If the application adds a large number of files the
|
|
|
|
|
developer can group them into sub-directories under :file:`src`, to whatever
|
|
|
|
|
depth is needed. The developer must supply a :file:`Makefile` for the
|
|
|
|
|
:file:`src` directory, as well as for each sub-directory under :file:`src`.
|
|
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
|
|
These Makefiles are distinct from the top-level application Makefile
|
|
|
|
|
that appears in :file:`~/app`.
|
|
|
|
|
Application-specific source code files are normally added to the
|
|
|
|
|
application's :file:`src` directory. If the application adds a large
|
|
|
|
|
number of files the developer can group them into sub-directories
|
|
|
|
|
under :file:`src`, to whatever depth is needed.
|
|
|
|
|
|
|
|
|
|
Application-specific source code should not use symbol name prefixes that have
|
|
|
|
|
been reserved by the kernel for its own use. For more information, see
|
|
|
|
@ -505,58 +445,6 @@ been reserved by the kernel for its own use. For more information, see
|
|
|
|
|
`Naming Conventions
|
|
|
|
|
<https://github.com/zephyrproject-rtos/zephyr/wiki/Naming-Conventions>`_.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The following requirements apply to all Makefiles in the :file:`src`
|
|
|
|
|
directory, including any sub-directories it may have.
|
|
|
|
|
|
|
|
|
|
* During the build process, Kbuild identifies the source files to compile
|
|
|
|
|
into object files by matching the file names identified in
|
|
|
|
|
the application's Makefile(s).
|
|
|
|
|
|
|
|
|
|
.. important::
|
|
|
|
|
|
|
|
|
|
A source file that is not referenced by any Makefile is not included
|
|
|
|
|
when the application is built.
|
|
|
|
|
|
|
|
|
|
* A Makefile cannot directly reference source code. It can only
|
|
|
|
|
reference object files (:file:`.o` files) produced from source code files.
|
|
|
|
|
|
|
|
|
|
* A Makefile can only reference files in its own directory or in the
|
|
|
|
|
sub-directories of that directory.
|
|
|
|
|
|
|
|
|
|
* A Makefile may reference multiple files from a single-line entry.
|
|
|
|
|
However, a separate line must be used to reference each directory.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#. Create a directory structure for your source code in :file:`src`
|
|
|
|
|
and add your source code files to it.
|
|
|
|
|
|
|
|
|
|
#. Create a :file:`Makefile` in the :file:`src` directory. Then create
|
|
|
|
|
an additional :file:`Makefile` in each of the sub-directories under
|
|
|
|
|
the :file:`src` directory, if any.
|
|
|
|
|
|
|
|
|
|
a) Use the following syntax to add file references:
|
|
|
|
|
|
|
|
|
|
.. code-block:: make
|
|
|
|
|
|
|
|
|
|
obj-y += file1.o file2.o
|
|
|
|
|
|
|
|
|
|
b) Use the following syntax to add directory references:
|
|
|
|
|
|
|
|
|
|
.. code-block:: make
|
|
|
|
|
|
|
|
|
|
obj-y += directory_name/**
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This example is taken from the :ref:`dining-philosophers-sample`. To examine this file in
|
|
|
|
|
context, navigate to: :file:`$ZEPHYR_BASE/samples/philosophers/src`.
|
|
|
|
|
|
|
|
|
|
.. code-block:: make
|
|
|
|
|
|
|
|
|
|
obj-y = main.o
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Support for building third-party library code
|
|
|
|
|
=============================================
|
|
|
|
|
|
|
|
|
@ -567,31 +455,22 @@ compiler flags that control the ABI targeted, making it important that both
|
|
|
|
|
libraries and applications have certain compiler flags in common. It may also
|
|
|
|
|
be useful for glue code to have access to Zephyr kernel header files.
|
|
|
|
|
|
|
|
|
|
To make it easier to integrate third-party components, the Zephyr build system
|
|
|
|
|
includes a special build target, ``outputexports``, that takes a number of
|
|
|
|
|
critical variables from the Zephyr build system and copies them into
|
|
|
|
|
:file:`Makefile.export`. This allows the critical variables to be included by
|
|
|
|
|
wrapper code for use in a third-party build system.
|
|
|
|
|
To make it easier to integrate third-party components, the Zephyr
|
|
|
|
|
build system has defined CMake functions that give application build
|
|
|
|
|
scripts access to the zephyr compiler options. The functions are
|
|
|
|
|
documented and defined in :file:`$ZEPHYR_BASE/cmake/extensions.cmake`
|
|
|
|
|
and follow the naming convention ``zephyr_get_<type>_<format>``.
|
|
|
|
|
|
|
|
|
|
The following variables are recommended for use within the third-party build
|
|
|
|
|
(see :file:`Makefile.export` for the complete list of exported variables):
|
|
|
|
|
The following variables will often need to be exported to the
|
|
|
|
|
third-party build system.
|
|
|
|
|
|
|
|
|
|
* ``CROSS_COMPILE``, together with related convenience variables to call the
|
|
|
|
|
cross-tools directly (including ``AR``, ``AS``, ``CC``, ``CXX``, ``CPP``
|
|
|
|
|
and ``LD``).
|
|
|
|
|
* ``CMAKE_C_COMPILER``, ``CMAKE_AR``.
|
|
|
|
|
|
|
|
|
|
* ``ARCH`` and ``BOARD``, together with several variables that identify the
|
|
|
|
|
Zephyr kernel version.
|
|
|
|
|
|
|
|
|
|
* ``KBUILD_CFLAGS``, ``NOSTDINC_FLAGS`` and ``ZEPHYRINCLUDE`` all of which
|
|
|
|
|
should normally be added, in that order, to ``CFLAGS`` (or
|
|
|
|
|
``CXXFLAGS``).
|
|
|
|
|
|
|
|
|
|
* All kconfig variables, allowing features of the library code to be
|
|
|
|
|
enabled/disabled automatically based on the Zephyr kernel configuration.
|
|
|
|
|
|
|
|
|
|
:file:`samples/application_development/static_lib` is a sample project that demonstrates
|
|
|
|
|
some of these features.
|
|
|
|
|
:file:`samples/application_development/external_lib` is a sample
|
|
|
|
|
project that demonstrates some of these features.
|
|
|
|
|
|
|
|
|
|
.. _build_an_application:
|
|
|
|
|
|
|
|
|
@ -605,13 +484,16 @@ hardware.
|
|
|
|
|
|
|
|
|
|
#. Navigate to the application directory :file:`~/app`.
|
|
|
|
|
|
|
|
|
|
#. Enter the following command to build the application's :file:`zephyr.elf`
|
|
|
|
|
image using the configuration settings for the board type specified
|
|
|
|
|
in the application's :file:`Makefile`.
|
|
|
|
|
#. Enter the following commands to build the application's
|
|
|
|
|
:file:`zephyr.elf` image using the configuration settings for the
|
|
|
|
|
board type specified in the application's :file:`CMakeLists.txt`.
|
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
|
|
$ make
|
|
|
|
|
$ mkdir build
|
|
|
|
|
$ cd build
|
|
|
|
|
$ cmake -GNinja ..
|
|
|
|
|
$ ninja
|
|
|
|
|
|
|
|
|
|
If desired, you can build the application using the configuration settings
|
|
|
|
|
specified in an alternate :file:`.conf` file using the :code:`CONF_FILE`
|
|
|
|
@ -620,15 +502,14 @@ hardware.
|
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
|
|
$ make CONF_FILE=prj.alternate.conf
|
|
|
|
|
|
|
|
|
|
If desired, you can build the application for a different board type than the
|
|
|
|
|
one specified in the application's :file:`Makefile` using the :code:`BOARD`
|
|
|
|
|
parameter. For example:
|
|
|
|
|
$ export CONF_FILE=prj.alternate.conf
|
|
|
|
|
$ cmake -GNinja ..
|
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
|
|
$ make BOARD=arduino_101
|
|
|
|
|
If desired, you can generate project files for a different board
|
|
|
|
|
type than the one specified in the application's
|
|
|
|
|
:file:`CMakeLists.txt` by defining the environment variable
|
|
|
|
|
:code:`BOARD`.
|
|
|
|
|
|
|
|
|
|
Both the :code:`CONF_FILE` and :code:`BOARD` parameters can be specified
|
|
|
|
|
when building the application.
|
|
|
|
@ -640,7 +521,7 @@ Application development is usually fastest when changes are continually tested.
|
|
|
|
|
Frequently rebuilding your application makes debugging less painful
|
|
|
|
|
as the application becomes more complex. It's usually a good idea to
|
|
|
|
|
rebuild and test after any major changes to the application's source files,
|
|
|
|
|
Makefiles, or configuration settings.
|
|
|
|
|
CMakeLists.txt files, or configuration settings.
|
|
|
|
|
|
|
|
|
|
.. important::
|
|
|
|
|
|
|
|
|
@ -654,23 +535,24 @@ the build system to rebuild the entire application from scratch with the
|
|
|
|
|
following procedure:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#. Navigate to the application directory :file:`~/app`.
|
|
|
|
|
#. Navigate to the build directory :file:`~/app/build`.
|
|
|
|
|
|
|
|
|
|
#. Enter the following command to delete the application's generated files
|
|
|
|
|
for the specified board type, except for the :file:`.config` file that
|
|
|
|
|
contains the application's current configuration information.
|
|
|
|
|
#. Enter the following command to delete the application's generated
|
|
|
|
|
files, except for the :file:`.config` file that contains the
|
|
|
|
|
application's current configuration information.
|
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
|
|
$ make [BOARD=<type>] clean
|
|
|
|
|
$ ninja clean
|
|
|
|
|
|
|
|
|
|
Alternatively, enter the following command to delete *all* generated files
|
|
|
|
|
for *all* board types, including the :file:`.config` files that contain
|
|
|
|
|
the application's current configuration information for those board types.
|
|
|
|
|
Alternatively, enter the following command to delete *all*
|
|
|
|
|
generated files, including the :file:`.config` files that contain
|
|
|
|
|
the application's current configuration information for those board
|
|
|
|
|
types.
|
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
|
|
$ make pristine
|
|
|
|
|
$ ninja pristine
|
|
|
|
|
|
|
|
|
|
#. Rebuild the application normally following the steps specified
|
|
|
|
|
in `Build an Application`_ above.
|
|
|
|
@ -721,13 +603,13 @@ run an application via QEMU:
|
|
|
|
|
#. Open a terminal console on your host computer, and navigate to the
|
|
|
|
|
application directory :file:`~/app`.
|
|
|
|
|
|
|
|
|
|
#. Enter the following command to build and run the application
|
|
|
|
|
using a QEMU-supported board configuration, such as qemu_cortex_m3 or
|
|
|
|
|
qemu_x86.
|
|
|
|
|
#. After generating project files for a QEMU-supported board
|
|
|
|
|
configuration, such as qemu_cortex_m3 or qemu_x86, enter the
|
|
|
|
|
following command to build and run the application.
|
|
|
|
|
|
|
|
|
|
.. code-block:: console
|
|
|
|
|
|
|
|
|
|
$ make [BOARD=<type> ...] run
|
|
|
|
|
$ ninja run
|
|
|
|
|
|
|
|
|
|
The Zephyr build system generates a :file:`zephyr.elf` image file
|
|
|
|
|
and then begins running it in the terminal console.
|
|
|
|
@ -758,7 +640,7 @@ The simplest way to debug an application running in QEMU is using the GNU
|
|
|
|
|
Debugger and setting a local GDB server in your development system through QEMU.
|
|
|
|
|
|
|
|
|
|
You will need an ELF binary image for debugging purposes. The build system
|
|
|
|
|
generates the image in the output directory. By default, the kernel binary name
|
|
|
|
|
generates the image in the build directory. By default, the kernel binary name
|
|
|
|
|
is :file:`zephyr.elf`. The name can be changed using a Kconfig option.
|
|
|
|
|
|
|
|
|
|
We will use the standard 1234 TCP port to open a :abbr:`GDB (GNU Debugger)`
|
|
|
|
@ -782,11 +664,11 @@ The options used above have the following meaning:
|
|
|
|
|
TCP port 1234.
|
|
|
|
|
|
|
|
|
|
To debug with QEMU and to start a GDB server and wait for a remote connect, run
|
|
|
|
|
the following inside an application:
|
|
|
|
|
the following inside the build directory of an application:
|
|
|
|
|
|
|
|
|
|
.. code-block:: bash
|
|
|
|
|
|
|
|
|
|
make BOARD=qemu_x86 debugserver
|
|
|
|
|
ninja debugserver
|
|
|
|
|
|
|
|
|
|
The build system will start a QEMU instance with the CPU halted at startup
|
|
|
|
|
and with a GDB server instance listening at the TCP port 1234.
|
|
|
|
|