-
Notifications
You must be signed in to change notification settings - Fork 274
Application Build system
A new build system using python has been added recently. It will coexist with the system using make for some time and will replace it eventually. Currently the new build system works with the thumb2 target only. Il will be extended to the orther targets soon.
Using the new system is quite simple. Locate the BUILD object in the OS object of your OIL file. You should have something like that (example taken from examples/thumb2/cortex-m4/stf32f4-discovery/readbutton_isr
):
BUILD = TRUE {
TRAMPOLINE_BASE_PATH = "../../../../..";
APP_SRC = "readbutton_isr.c";
APP_NAME = "readbutton_isr_exe";
CFLAGS = "-g -O0 -Wall -Wno-unused-but-set-variable -Wformat";
CFLAGS = "-std=c99 -mcpu=cortex-m4 -Wmissing-field-initializers";
CFLAGS = "-mthumb -mfloat-abi=soft -mfpu=fpv4-sp-d16 -nostartfiles";
ASFLAGS = "-g -Wall -mcpu=cortex-m4 -mthumb --fatal-warnings";
ASFLAGS = "-mfloat-abi=soft -mfpu=fpv4-sp-d16";
LDFLAGS = "--fatal-warnings --warn-common --no-undefined";
LDFLAGS = "-L/usr/local/dev-arm/i386-Darwin-arm-gcc-4.9.2/arm-eabi/lib/thumb";
LDFLAGS = "-lc -L/usr/local/dev-arm/i386-Darwin-arm-gcc-4.9.2/lib/gcc/arm-eabi/4.9.2";
LDFLAGS = "-lgcc -Map=readbutton_isr.map";
COMPILER = "arm-eabi-gcc";
ASSEMBLER = "arm-eabi-as";
LINKER = "arm-eabi-ld";
COPIER = "arm-eabi-objcopy";
};
And add a SYSTEM = PYTHON;
inside the BUILD object.
Run goil on the OIL file: goil --target=thumb2/cortex-m4/STM32F4-Discovery --templates=../../../../../goil/templates readbutton_isr.oil
.
Two files related to the build system are generated: make.py
and build.py
. make.py
contains the rules and the build commands used to compile the OIL file itself. Dependencies are set on the OIL file and on all the included OIL files. build.py
contains the rules and the build commands used to compile the C files of the application, of the OS and those that have been generated by the OIL compilation. make.py
calls build.py
so it is not needed to launch build.py
directly, use only make.py
.
The application is now built by executing make.py
: ./make.py
. 2 build goals are provided by default: all
and clean
. Launching ./make.py
without any argument or with argument all
are equivalent. ./make.py clean
cleans up all the files.
On some target platform, additional build goals may be available. For instance on thumb2/cortex-m4/STM32F4-Discovery
the goal burn
allow to burn the flash with the application.
Adding a target to the build system consists in specifying the target specific files needed. When compiling for a target goil includes the config.oil
files, if available, along the target path starting at the goil/templates/config
directory. For instance for the thumb2/cortex-m4/STM32F4-Discovery
target, goil includes:
goil/templates/config/config.oil
goil/templates/config/thumb2/config.oil
goil/templates/config/thumb2/cortex-m4/config.oil
- and
goil/templates/config/thumb2/cortex-m4/STM32F4-Discovery/config.oil
For each depth in the hierarchy, the config.oil
file should define what files in the machines
corrresponding path should be compiled along with the operating system and application source files. This definition is done by using the PLATFORM_FILES
OIL object. Each PLATFORM_FILES
object has an attribute, PATH
, to give the relative path (from machines/
) where the files are located and as many as needed CFILE
(for C source file) and ASFILE
(for assembly source file) attributes. For instance, the following PLATFORM_FILES
object lists the files needed for the STM32F4-Discovery
target:
PLATFORM_FILES STM32F4_Discovery {
PATH = "thumb2/cortex-m4/STM32F4-Discovery";
CFILE = "stm32f4_discovery.c";
CFILE = "stm32f4xx_gpio.c";
CFILE = "stm32f4xx_rcc.c";
CFILE = "stm32f4xx_exti.c";
CFILE = "stm32f4xx_syscfg.c";
CFILE = "misc.c";
CFILE = "tp.c";
};
Additional files may be generated for a target: interrupt handlers, macros to acknowledge interrupts and so on. To have these files taken into account by the build system, they have to be listed in the config.oil
files by using the GENERATED_FILES
OIL object. For instance the following declaration lists the files generated for the cortex-m4
target:
GENERATED_FILES cortex_m4 {
CFILE = "tpl_first_stage_irq.S";
CFILE = "tpl_second_stage_irq.S";
CFILE = "tpl_vectors.c";
};
These files will be generated in the project directory.
Additional commands may be applied to a goal. For instance, after generating the executable, it has to be transformed to another format in order to be downloaded to the board. This is done by using the POSTBUILD
OIL object with the COMMAND
attribute. The name of the POSTBUILD
object is the goal where the command are added. The following sub-attributes of COMMAND
are available:
-
TYPE
gives the command. Predefined commands are available:-
COMPILER
uses the compiler defined in the application OIL file; -
ASSEMBLER
uses the assembler defined in the application OIL file; -
LINKER
uses the linker defined in the application OIL file; -
COPIER
uses the copier defined in the application OIL file; -
CUSTOM
uses a custom command. In this case, 2 sub-attributes must be provided:-
MESSAGE
: the message o be displayed when the command is run: -
NAME
: the name of the command.
-
-
-
INPUT
gives the input file of the command. Values are as follow:-
TARGET
: the input is the target of the goal. -
INTERMEDIATE
: the input is an arbitrary file. In this case a sub-attribute,SOURCE
gives the name of the file.
-
-
OUTPUT
gives the extension that will be added toINPUT
to build the output file name. It can be omitted. In this case the command is not supposed to output any file; -
PREOPTION
gives the options that will be put in the command line before the input and output file names; -
POSTOPTION
gives the options that will be put in the command line after the input and output file names.
For instance, the following declaration adds a post-build command to goal all
:
POSTBUILD all {
COMMAND buildbin {
TYPE = COPIER;
INPUT = TARGET;
OUTPUT = ".bin";
PREOPTION = "-O binary";
};
};
If COPIER
is defined as arm-eabi-objcopy
and the target of all
is readbutton_isr_exe
, this declaration will run command:
arm-eabi-objcopy -O binary readbutton_isr_exe readbutton_isr_exe.bin
Additional commands may be run at the end of the build process. Such a command is added by using the POSTCOMMAND
OIL object with the COMMAND
attribute. The name of the object defines the goal for which the post command should be run. If the name is not all
or clean
, a corresponding sub-goal of all
is defined. Using this sub-goal builds the goal all
and executes the post-commands. The following sub-attributes of COMMAND
are available:
-
MESSAGE
: unused at that moment; -
COMMAND
: name of the command -
INPUT
gives the input file of the command. Values are as follow:-
TARGET
: the input is the target of the goal. In this case a sub-attribute,EXT
gives a file extension. -
INTERMEDIATE
: the input is an arbitrary file. In this case a sub-attribute,SOURCE
gives the name of the file.
-
-
OUTPUT
gives the extension that will be added toINPUT
to build the output file name. It can be omitted. In this case the command is not supposed to output any file; -
PREOPTION
gives the options that will be put in the command line before the input and output file names; -
POSTOPTION
gives the options that will be put in the command line after the input and output file names.
For instance, the following declaration adds a post-command to goal all
:
POSTCOMMAND burn {
COMMAND flash {
MESSAGE = "Flashing";
COMMAND = "st-flash";
INPUT = TARGET { EXT = ".bin"; };
PREOPTION = "write";
POSTOPTION = "0x8000000";
};
};
This declaration adds a sub-goal burn
. Typing ./make.py burn
with target being readbutton_isr_exe
runs goal all
then apply the post-command:
st-flash write readbutton_isr_exe.bin 0x8000000
This command flashes the readbutton_isr_exe.bin using the stlink software.