multiple board support


CHRISTIAN TOMAS TENLLADO VAN DER REIJDEN
 

Hello:

I am having some troubles compiling my project. I want to support
several boards and therefore I have a boards directory with a .conf
file for each board in which I can punt the CONFIG* entries specific
for that board. But then I also need to select specific compilation
flags that depend on the architecture of the SoC in each board.

I have tried using the flags from zephyr with
zephyr_get_compile_options_for_lang(C options), but it turns out that
the name of a file is included in the options variable and then I get
compiling errors from cmake.

I am thinking in using something like this:

if ( <check_board> EQUAL "qemu_x86")
set(EXTRA_CFLAGS <flags specific to qemu_x86>)
elseif (<check_board> EQUAL "disco_l475_iot1")
set(EXTRA_CFLAGS <flags specific to qemu_x86>)
endif()

<check_board> should be replaced by some variable check that contains
the name of the board selected in the west build command line. What is
that variable?

Is there a better way to approach this? I mean, having a project that
you want to be able to compile for several boards with different SoC
architectures for which you have to use specific compiler flags.

Thank you all in advance.

Regards,

Christian Tenllado


Jason Bens <jason.bens@...>
 

Hi Christian,

You may be able to simplify your conditional statement by instead testing for the presence of CONFIG_BOARD_QEMU_X86 or CONFIG_BOARD_DISCO_L475_IOT1. These should be set somewhere in a *_defconfig file in each SoC's board subdirectory, and so will only be set for the currently compiling board.

Unfortunately, I haven't had the need to set board-specific compilation flags, yet. Were I to try that, as a first attempt I would probably copy the relevant board subdirectories into my project and add these extra flags to the new boards' CMakeLists files. That way, the modified flags are tracked in my project while also being logically contained by the specific board they're relevant to. I rationalize this apparent duplication by figuring that my board is similar to the provided boards in the boards directory, but, as I need custom flags or configurations, it clearly isn't identical. Thus, we require a new board to be defined. Take this advice with a grain of salt, however, as I still consider myself an amateur when it comes to Zephyr's build system.

Hopefully, that helps get you started,

- Jason

-----Original Message-----
From: users@... <users@...> On Behalf Of CHRISTIAN TOMAS TENLLADO VAN DER REIJDEN
Sent: June 13, 2022 6:02 PM
To: users@...
Subject: [Zephyr-users] multiple board support

External Email:

Hello:

I am having some troubles compiling my project. I want to support several boards and therefore I have a boards directory with a .conf file for each board in which I can punt the CONFIG* entries specific for that board. But then I also need to select specific compilation flags that depend on the architecture of the SoC in each board.

I have tried using the flags from zephyr with zephyr_get_compile_options_for_lang(C options), but it turns out that the name of a file is included in the options variable and then I get compiling errors from cmake.

I am thinking in using something like this:

if ( <check_board> EQUAL "qemu_x86")
set(EXTRA_CFLAGS <flags specific to qemu_x86>) elseif (<check_board> EQUAL "disco_l475_iot1")
set(EXTRA_CFLAGS <flags specific to qemu_x86>)
endif()

<check_board> should be replaced by some variable check that contains the name of the board selected in the west build command line. What is that variable?

Is there a better way to approach this? I mean, having a project that you want to be able to compile for several boards with different SoC architectures for which you have to use specific compiler flags.

Thank you all in advance.

Regards,

Christian Tenllado


CHRISTIAN TOMAS TENLLADO VAN DER REIJDEN
 

Thank you very much Jason, it was indeed very helpful. Just for
reference, the piece of "code" in the CMakeLists.txt file can be:

if (${CONFIG_BOARD_QEMU_X86})
set(EXTRA_CFLAGS <flags for this board>)
elseif (${CONFIG_BOARD_DISCO_L475_IOT1})
set(EXTRA_CFLAGS <flags for this board>)
endif()

There is however something that was not clear in my OP. I do not need
the extra flags for the zephyr part, but for a library I am trying to
add to my project. For instance some boards may not support floating
point instructions and you have to compile with the -msoft-float flag
and others may have other flags needed.

The problem is that the flags selected by zephyr are not used by
default for my own code. That is why my first attempt was to get and
use the compiler flags selected by zephyr, but it turns out that using
the zephyr_get_compile_options_for_lang(C options) includes the name
of a .h file in the flags list and that breaks the compilation of the
library.

I am probably doing something wrong here, but I cannot find the
"correct way to do it". Something that could also be very useful for
me is an example project that includes support for several boards with
different architectures, but I could not find one.

Again, thank you very much, I am struggling with the compilation
system of zephyr and your answer was of great help.

Regards,

Christian.

On Tue, Jun 14, 2022 at 9:29 AM Jason Bens <Jason.Bens@...> wrote:

Hi Christian,

You may be able to simplify your conditional statement by instead testing for the presence of CONFIG_BOARD_QEMU_X86 or CONFIG_BOARD_DISCO_L475_IOT1. These should be set somewhere in a *_defconfig file in each SoC's board subdirectory, and so will only be set for the currently compiling board.

Unfortunately, I haven't had the need to set board-specific compilation flags, yet. Were I to try that, as a first attempt I would probably copy the relevant board subdirectories into my project and add these extra flags to the new boards' CMakeLists files. That way, the modified flags are tracked in my project while also being logically contained by the specific board they're relevant to. I rationalize this apparent duplication by figuring that my board is similar to the provided boards in the boards directory, but, as I need custom flags or configurations, it clearly isn't identical. Thus, we require a new board to be defined. Take this advice with a grain of salt, however, as I still consider myself an amateur when it comes to Zephyr's build system.

Hopefully, that helps get you started,

- Jason


-----Original Message-----
From: users@... <users@...> On Behalf Of CHRISTIAN TOMAS TENLLADO VAN DER REIJDEN
Sent: June 13, 2022 6:02 PM
To: users@...
Subject: [Zephyr-users] multiple board support

External Email:

Hello:

I am having some troubles compiling my project. I want to support several boards and therefore I have a boards directory with a .conf file for each board in which I can punt the CONFIG* entries specific for that board. But then I also need to select specific compilation flags that depend on the architecture of the SoC in each board.

I have tried using the flags from zephyr with zephyr_get_compile_options_for_lang(C options), but it turns out that the name of a file is included in the options variable and then I get compiling errors from cmake.

I am thinking in using something like this:

if ( <check_board> EQUAL "qemu_x86")
set(EXTRA_CFLAGS <flags specific to qemu_x86>) elseif (<check_board> EQUAL "disco_l475_iot1")
set(EXTRA_CFLAGS <flags specific to qemu_x86>)
endif()

<check_board> should be replaced by some variable check that contains the name of the board selected in the west build command line. What is that variable?

Is there a better way to approach this? I mean, having a project that you want to be able to compile for several boards with different SoC architectures for which you have to use specific compiler flags.

Thank you all in advance.

Regards,

Christian Tenllado





CHRISTIAN TOMAS TENLLADO VAN DER REIJDEN
 

Just for future reference. The previous code can be rewritten as:

if (CONFIG_BOARD_QEMU_X86)
set(EXTRA_CFLAGS <flags for this board>)
elseif (CONFIG_BOARD_DISCO_L475_IOT1)
set(EXTRA_CFLAGS <flags for this board>)
endif()

and then the EXTRA_CFLAGS can be used to tune the compile flags
depending on the target board.

As a side note, my original problem was that the library I am trying
to compile with cmake was giving me errors when the first function of
the library was called, and tuning the compile flags did solve the
problem. However I discovered that I need not to specify the compile
flags if the library is linked with zephyr_interface, adding:

target_link_libraries(<library-name> zephyr_interface)

Still, architecture specific flags are not being used to compile the
individual files of the library, which is strange. I do not understand
why the compile flags derived from the zephyr configuration are not
being used for the user code. But in my case, the library seems to
work.

Thank you all for your help.

Christian

On Tue, Jun 14, 2022 at 10:20 AM CHRISTIAN TOMAS TENLLADO VAN DER
REIJDEN via lists.zephyrproject.org
<tenllado=ucm.es@...> wrote:


Thank you very much Jason, it was indeed very helpful. Just for
reference, the piece of "code" in the CMakeLists.txt file can be:

if (${CONFIG_BOARD_QEMU_X86})
set(EXTRA_CFLAGS <flags for this board>)
elseif (${CONFIG_BOARD_DISCO_L475_IOT1})
set(EXTRA_CFLAGS <flags for this board>)
endif()

There is however something that was not clear in my OP. I do not need
the extra flags for the zephyr part, but for a library I am trying to
add to my project. For instance some boards may not support floating
point instructions and you have to compile with the -msoft-float flag
and others may have other flags needed.

The problem is that the flags selected by zephyr are not used by
default for my own code. That is why my first attempt was to get and
use the compiler flags selected by zephyr, but it turns out that using
the zephyr_get_compile_options_for_lang(C options) includes the name
of a .h file in the flags list and that breaks the compilation of the
library.

I am probably doing something wrong here, but I cannot find the
"correct way to do it". Something that could also be very useful for
me is an example project that includes support for several boards with
different architectures, but I could not find one.

Again, thank you very much, I am struggling with the compilation
system of zephyr and your answer was of great help.

Regards,

Christian.

On Tue, Jun 14, 2022 at 9:29 AM Jason Bens <Jason.Bens@...> wrote:

Hi Christian,

You may be able to simplify your conditional statement by instead testing for the presence of CONFIG_BOARD_QEMU_X86 or CONFIG_BOARD_DISCO_L475_IOT1. These should be set somewhere in a *_defconfig file in each SoC's board subdirectory, and so will only be set for the currently compiling board.

Unfortunately, I haven't had the need to set board-specific compilation flags, yet. Were I to try that, as a first attempt I would probably copy the relevant board subdirectories into my project and add these extra flags to the new boards' CMakeLists files. That way, the modified flags are tracked in my project while also being logically contained by the specific board they're relevant to. I rationalize this apparent duplication by figuring that my board is similar to the provided boards in the boards directory, but, as I need custom flags or configurations, it clearly isn't identical. Thus, we require a new board to be defined. Take this advice with a grain of salt, however, as I still consider myself an amateur when it comes to Zephyr's build system.

Hopefully, that helps get you started,

- Jason


-----Original Message-----
From: users@... <users@...> On Behalf Of CHRISTIAN TOMAS TENLLADO VAN DER REIJDEN
Sent: June 13, 2022 6:02 PM
To: users@...
Subject: [Zephyr-users] multiple board support

External Email:

Hello:

I am having some troubles compiling my project. I want to support several boards and therefore I have a boards directory with a .conf file for each board in which I can punt the CONFIG* entries specific for that board. But then I also need to select specific compilation flags that depend on the architecture of the SoC in each board.

I have tried using the flags from zephyr with zephyr_get_compile_options_for_lang(C options), but it turns out that the name of a file is included in the options variable and then I get compiling errors from cmake.

I am thinking in using something like this:

if ( <check_board> EQUAL "qemu_x86")
set(EXTRA_CFLAGS <flags specific to qemu_x86>) elseif (<check_board> EQUAL "disco_l475_iot1")
set(EXTRA_CFLAGS <flags specific to qemu_x86>)
endif()

<check_board> should be replaced by some variable check that contains the name of the board selected in the west build command line. What is that variable?

Is there a better way to approach this? I mean, having a project that you want to be able to compile for several boards with different SoC architectures for which you have to use specific compiler flags.

Thank you all in advance.

Regards,

Christian Tenllado