The latest development version of this page may be more current than this released 3.5.0 version.

Native simulator - native_sim

Overview

The native_sim board is an evolution of native_posix. Just like with native_posix you can build your Zephyr application with the Zephyr kernel, creating a normal Linux executable with your host tooling, and can debug and instrument it like any other Linux program.

native_sim is based on the native simulator and the POSIX architecture.

Host system dependencies

Please check the Posix Arch Dependencies

Important limitations

Native_sim is based on the POSIX architecture, and therefore its limitations and considerations apply to it.

How to use it

To build, simply specify the native_sim board as target:

west build -b native_sim samples/hello_world

Now you have a Linux executable, ./build/zephyr/zephyr.exe, you can use just like any other Linux program.

You can run, debug, build it with sanitizers or with coverage just like with native_posix. Please check native_posix’s how to for more info.

32 and 64bit versions

Just like native_posix, native_sim comes with two targets: A 32 bit and 64 bit version. The 32 bit version, native_sim, is the default target, which will compile your code for the ILP32 ABI (i386 in a x86 or x86_64 system) where pointers and longs are 32 bits. This mimics the ABI of most embedded systems Zephyr targets, and is therefore normally best to test and debug your code, as some bugs are dependent on the size of pointers and longs. This target requires either a 64 bit system with multilib support installed or one with a 32bit userspace.

The 64 bit version, native_sim_64, compiles your code targeting the LP64 ABI (x86-64 in x86 systems), where pointers and longs are 64 bits. You can use this target if you cannot compile or run 32 bit binaries.

C library choice

Unlike native_posix, native_sim may be compiled with a choice of C libraries. By default it will be compiled with the host C library (CONFIG_EXTERNAL_LIBC), but you can also select to build it with CONFIG_MINIMAL_LIBC or with CONFIG_PICOLIBC.

When building with either MINIMAL or PICO libC you will build your code in a more similar way as when building for the embedded target, you will be able to test your code interacting with that C library, and there will be no conflicts with the POSIX OS abstraction shim, but, accessing the host for test purposes from your embedded code will be more difficult, and you will have a limited choice of drivers and backends to chose from.

Architecture

native_posix’s architecture description as well as the POSIX architecture description are directly applicable to native_sim.

If you are interested on the inner workigns of the native simulator itself, you can check its documentation.

Peripherals, subsystems backends and host based flash access

Today, native_sim supports the exact same peripherals and backends as native_posix, with the only caveat that some of these are, so far, only available when compiling with the host libC (CONFIG_EXTERNAL_LIBC).

Drivers/backends vs libC choice

Driver class

driver name

driver kconfig

libC choices

adc

ADC emul

CONFIG_ADC_EMUL

all

bluetooth

userchan

CONFIG_BT_USERCHAN

host libC

can

can native posix

CONFIG_CAN_NATIVE_POSIX_LINUX

host libC

console backend

POSIX arch console

CONFIG_POSIX_ARCH_CONSOLE

all

display

display SDL

CONFIG_SDL_DISPLAY

all

entropy

native posix entropy

CONFIG_FAKE_ENTROPY_NATIVE_POSIX

all

eprom

eprom emulator

CONFIG_EEPROM_EMULATOR

host libC

ethernet

eth native_posix

CONFIG_ETH_NATIVE_POSIX

host libC

flash

flash simulator

CONFIG_FLASH_SIMULATOR

all

flash

host based flash access

CONFIG_FUSE_FS_ACCESS

host libC

gpio

GPIO emulator

CONFIG_GPIO_EMUL

all

gpio

SDL GPIO emulator

CONFIG_GPIO_EMUL_SDL

all

i2c

I2C emulator

CONFIG_I2C_EMUL

all

input

input SDL touch

CONFIG_INPUT_SDL_TOUCH

all

log backend

native backend

CONFIG_LOG_BACKEND_NATIVE_POSIX

all

rtc

RTC emul

CONFIG_RTC_EMUL

all

serial

uart native posix/PTTY

CONFIG_UART_NATIVE_POSIX

all

serial

uart native TTY

CONFIG_UART_NATIVE_TTY

all

spi

SPI emul

CONFIG_SPI_EMUL

all

system tick

native_posix timer

CONFIG_NATIVE_POSIX_TIMER

all

tracing

Posix tracing backend

CONFIG_TRACING_BACKEND_POSIX

all

usb

USB native posix

CONFIG_USB_NATIVE_POSIX

host libC