Application Development Directory Structure
Each application resides in a uniquely-named application
directory created by the developer, typically, in the developer’s
workspace directory. The application developer also creates a
src
directory for the application’s source code.
Note
The Zephyr Kernel either supplies or generates all other application directories.
Procedures
Creating an Application and Source Code Directory using the CLI
Create one directory for your application and another for the application’s source code; this makes it easier to organize directories and files in the structure that the kernel expects.
Before You Begin
- The environment variable must be set for each console terminal using Setting Environment Variables.
Steps
- Create an application directory structure outside of the kernel’s installation directory tree. Often this is your workspace directory.
- In a Linux console, navigate to a location where you want your applications to reside.
- Create the application’s directory, enter:
$ mkdir application_name
Note
This directory and the path to it, are referred to in the documentation as
~/appDir
.
Create a source code directory in your
~/appDir
, enter:$ mkdir src
The source code directory
~/appDir/src
is created.-- appDir |-- src
Creating an Application Makefile
Create an application Makefile to define basic information such as the kernel
type, microkernel or nanokernel, and the board configuration used by the
application. The build system uses the Makefile to build an image with both
the application and the kernel libraries called either
microkernel.elf
or nanokernel.elf
.
Before You Begin
- Be familiar with the standard GNU Make language.
- Be familiar with the board configuration used for your application and, if it is a custom board configuration, where it is located.
- Set the environment variable for each console terminal using Setting Environment Variables.
Steps
In the
appDir
directory, create a Makefile. Enter:$ touch Makefile
Open the
Makefile
and add the following mandatory entries using any standard text editor.Note
Ensure that there is a space after each
=
.Add the kernel type on a new line:
KERNEL_TYPE = micro|nano
Either micro or nano, short for microkernel or nanokernel respectively.
Add the name of the board configuration for your application on a new line:
BOARD ?= board_configuration_name
The supported boards can be found in Supported Boards.
Add the name of the default kernel configuration file for your application on a new line:
CONF_FILE = prj.conf
The default name is
prj.conf
. If you are not using the default name, this entry must match the filename of the.conf
file you are using.For microkernel applications, add the name of the MDEF for your application:
MDEF_FILE = prj.mdef
The default name is
prj.mdef
. If you are not using the default name, this entry must match the filename of the.mdef
file you are using.Include the mandatory
Makefile
fragments on a new line:include ${ZEPHYR_BASE}/Makefile.inc
Save and close the
Makefile
.
Example Makefile
KERNEL_TYPE = micro
BOARD ?= qemu_x86
CONF_FILE = prj.conf
MDEF_FILE = prj.mdef
include ${ZEPHYR_BASE}/Makefile.inc