Full name: Zephyr Software Development Kit.
Definition
The Zephyr SDK (software development kit) is a bundle of compilers and tools that the Zephyr §6.33 project, maker of an operating system for small devices, publishes for building Zephyr programs. It holds one toolchain §12.2 per processor family that Zephyr supports: a compiler, assembler, linker §12.4, debugger and C libraries that together turn source code into programs for that family. Each toolchain is a cross-compiler §12.1: it runs on the developer’s computer, the host, and produces code for the device. Host tools, such as an emulator and a debug server, come with it.
The idea
Building a Zephyr program for an Arm Cortex-M4 §6.3 microcontroller §6.1, a small computer on one chip, needs a compiler that emits Arm instructions, a C library precompiled for that processor, and versions of both that Zephyr’s build has been tested with. The compiler that a desktop Linux distribution installs produces programs for the desktop computer, not for the device. A team could collect a toolchain for each processor family from different vendors, but then each developer might hold a different compiler version and different library code, and the Toolchain entry shows that such differences change the program. The SDK replaces the collection with one tested set. One SDK version number covers the toolchains of every processor family and the host tools, and the Zephyr documentation names the SDK version it recommends for each Zephyr release. SDK versions are numbered separately from Zephyr’s.
The picture is a toolbox with one drawer per processor family; the Zephyr build opens the drawer that matches the board. The picture leaves out the step that causes most confusion. A computer may hold several toolboxes, and the build, not the developer, decides which one to open. That choice follows fixed rules and is recorded in the build directory, so it can be checked.
How it works
Contents. Current releases come in three variants: gnu, with toolchains of the GNU project, whose name stands for GNU’s Not Unix (GCC §12.17, the GNU Compiler Collection; the binary utilities; and GDB §6.28, the GNU Debugger), for every supported processor family; llvm, with toolchains built on the LLVM §12.18 compiler project (a name that began as Low Level Virtual Machine) and its C compiler Clang; and minimal, with host tools only, whose setup script downloads the toolchains the user picks. The host tools include builds of QEMU (Quick Emulator), which runs programs for another processor on the host, and OpenOCD §6.29 (Open On-Chip Debugger), which controls a chip through a debug probe.
Target tuple. Each GNU toolchain sits in a directory named by its target tuple, also called a target triple: a short name of the form processor-vendor-system that states which code the toolchain produces. arm-zephyr-eabi is the toolchain for 32-bit Arm processors: processor family arm, vendor zephyr, and eabi in the system position, meaning no operating system and the Arm embedded ABI §12.47 (application binary interface), the rules for calls and data layout. aarch64-zephyr-elf produces code for 64-bit Arm processors in object files of the ELF §12.6 (Executable and Linking Format) kind. Every program of a toolchain carries the tuple as a prefix, as in arm-zephyr-eabi-gcc, and a GCC compiler prints its own tuple when run with the option -dumpmachine.
Installation. The user extracts the bundle, for example into the home directory, and runs its script setup.sh once. The script installs the chosen toolchains and the host tools and registers the SDK in the CMake §12.12 package registry, a per-user list of installed packages that CMake (cross-platform make), the tool that configures Zephyr builds, searches. After the SDK directory is moved, the script must be run again.
Selection. When CMake configures a Zephyr build directory, it chooses a toolchain in this order.
Kind of toolchain. The variable
ZEPHYR_TOOLCHAIN_VARIANT, from the environment or the CMake command line, names it. The valuezephyr, or no value at all, means the Zephyr SDK; another value, such asgnuarmembfor the Arm GNU Toolchain, selects another toolchain.Which SDK. If the variable
ZEPHYR_SDK_INSTALL_DIRis set, current Zephyr looks only in that directory, which may hold one SDK or several, and stops with an error if no SDK there is compatible. Otherwise it collects every SDK in the CMake package registry and in the standard locations/usr,/usr/local,/opt, the home directory and its subdirectories.local,.local/optandbin, and takes the highest version that is compatible. An SDK is compatible when its version is not lower than the lowest version the Zephyr source tree accepts, and not higher than the highest, if the tree states one.Toolchain for the board. The board’s processor family picks the tuple, for example
arm-zephyr-eabifor a Cortex-M4 board, and so the compilerarm-zephyr-eabi-gccin the SDK’s directoryarm-zephyr-eabi/bin.Processor options. Zephyr’s configuration of the chip adds compiler options §12.3 such as
-mcpu=cortex-m4 -mthumb, and floating-point options such as-mfpu=fpv4-sp-d16when the floating-point hardware is enabled. These options, not the tuple, decide the exact instructions and which precompiled variant of each library the linker uses.
Record. The CMake step prints two lines that name the SDK’s version and directory:
Found host-tools: zephyr 0.17.0 (/home/dev/zephyr-sdk-0.17.0)
Found toolchain: zephyr 0.17.0 (/home/dev/zephyr-sdk-0.17.0)
The build directory’s file CMakeCache.txt stores the SDK directory as ZEPHYR_SDK_INSTALL_DIR and the full path of the C compiler as CMAKE_C_COMPILER. west -v build prints every compiler command with its options.
Worked example
A developer’s computer holds two SDKs in the home directory /home/dev: zephyr-sdk-0.16.8 and zephyr-sdk-0.17.0. Both are in a standard location. Suppose the Zephyr tree being built accepts SDK version 0.16.5 or higher and states no highest version. Versions are compared number by number from the left: in against the first numbers are equal, and the second numbers give , so 0.17.0 is the higher version.
Case 1: the variable ZEPHYR_SDK_INSTALL_DIR is not set. The build sorts the candidates from highest to lowest, 0.17.0 then 0.16.8, and takes the first one that is at least 0.16.5. It uses 0.17.0 and prints Found toolchain: zephyr 0.17.0 with the directory /home/dev/zephyr-sdk-0.17.0.
Case 2: a shell start-up file left from an older project still contains the line
export ZEPHYR_SDK_INSTALL_DIR=/home/dev/zephyr-sdk-0.16.8
The build looks only in that directory. Version 0.16.8 is at least 0.16.5, so the build uses 0.16.8, although the developer meant 0.17.0 to be used. The printed line and CMakeCache.txt both show 0.16.8.
Case 3: the same variable is set, but the Zephyr tree requires at least 0.17.0. Version 0.16.8 is lower, so configuration stops with an error. Current Zephyr does not fall back to the 0.17.0 SDK in the home directory.
In cases 1 and 2 the board has a Cortex-M4 processor, whose family is 32-bit Arm, so the tuple is arm-zephyr-eabi. In case 1 the compiler is:
/home/dev/zephyr-sdk-0.17.0/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
Run with -dumpmachine, it prints arm-zephyr-eabi. The same compiler prints the same tuple for a board with a Cortex-M0 processor; only the option -mcpu differs. The tuple names the processor family, not the processor.
Stated precisely
Let be the lowest SDK version that the Zephyr tree accepts, and write for the version of an installed SDK , with versions compared number by number from the left. In current Zephyr the build selects:
if
ZEPHYR_SDK_INSTALL_DIRis set to a directory : the SDK in with the highest among those with and within the highest version the tree accepts, if it states one; if there is none, configuration fails;otherwise: the SDK with the highest satisfying the same conditions among the SDKs in the CMake package registry and in the standard locations.
For a board whose processor family has the tuple , the GNU variant then uses the compiler named followed by -gcc, in the directory of the selected SDK. The exact processor, floating-point use and ABI follow from the compiler options, not from .
The guarantee behind the choice is a compatibility statement by the Zephyr project: the recommended SDK version is the one tested with that Zephyr release, and an SDK below the stated lowest version is refused. It is not a statement that the compiler has no bugs, and it says nothing about an SDK that the build did not select.
Limits and common mistakes
An installed SDK is not a used SDK, as cases 2 and 3 of the worked example show. The build’s printed lines and CMakeCache.txt name the SDK actually selected for that build directory.
The SDK version is not the compiler version. arm-zephyr-eabi-gcc --version prints the version of the GCC inside the SDK, a different number. A newer SDK can bring a newer GCC with different warnings and different code.
The tuple does not identify the processor. Code built with -mcpu=cortex-m4 and hardware floating point uses instructions that a Cortex-M0 does not have, and fails on it, although both boards use arm-zephyr-eabi.
The SDK does not contain Zephyr itself, the Python §12.23 packages that west §12.15 and the build scripts need, or vendors’ programming software such as the J-Link §6.27 tools.
QEMU emulates a processor and a few devices on the host. Timing and peripherals differ from the real board, so a program that runs under QEMU can still fail on hardware.
If ZEPHYR_TOOLCHAIN_VARIANT names another toolchain, the build compiles with that toolchain. The SDK on the same computer then supplies at most some host tools, and its version says nothing about the compiler used.
Questions answered
Which SDK version and target tuple are selected?
The selected SDK version is the one that the Zephyr build’s CMake configuration step chose by its search rules for that build directory, and the selected target tuple is that SDK’s toolchain name for the board’s processor family, such as arm-zephyr-eabi for 32-bit Arm. The SDK (software development kit) is the Zephyr project’s bundle of cross-compilers and host tools; a target tuple, also called a target triple, is a name of the form processor-vendor-system that states which code a toolchain produces. To read both from a real build:
the configuration output prints
Found toolchain: zephyrfollowed by the SDK version and its directory;a file in the build directory,
CMakeCache.txt, records the SDK directory under the nameZEPHYR_SDK_INSTALL_DIRand the compiler’s full path under the nameCMAKE_C_COMPILER; the compiler’s directory and file name carry the tuple;that compiler, run with
-dumpmachine, prints the tuple, and with--versionprints its own GCC version;west -v buildprints the compile commands with options such as-mcpu, which choose the exact processor that the tuple leaves open.
To predict the choice before building: if ZEPHYR_SDK_INSTALL_DIR is set, current Zephyr uses the highest compatible SDK in that directory or fails; otherwise it uses the highest compatible SDK in the CMake package registry and the standard locations. An SDK that is merely installed, or named in a request, has not been shown to be the one used.
Related entries: Cross-compilation (§12.1), Toolchain (§12.2), Newlib and Picolibc (§12.19), West (§12.15), CMake (§12.12), Zephyr RTOS (§6.33), Native application binary interface (ABI) (§12.47). Further reading: [119].