1.. _native_sim: 2 3Native simulator - native_sim 4############################# 5 6.. contents:: 7 :depth: 1 8 :backlinks: entry 9 :local: 10 11Overview 12******** 13 14The ``native_sim`` board is a :ref:`POSIX architecture<Posix arch>` based board. 15With it, a Zephyr application can be compiled together with 16the Zephyr kernel, and libraries, creating a normal Linux executable. 17 18``native_sim`` is based on the 19`native simulator <https://github.com/BabbleSim/native_simulator/>`_ 20and the :ref:`POSIX architecture<Posix arch>`. 21 22This board does not intend to simulate any particular HW, but it provides 23a few peripherals such as an Ethernet driver, display, UART, etc., to enable 24developing and testing application code which would require them. 25See `Peripherals`_ for more information. 26 27.. note:: 28 29 | ``native_sim`` is an evolution of its predecessor ``native_posix``. 30 | Some components, code, options names, and documentation will still use the old native_posix 31 names. But all components which worked with native_posix will work with native_sim. 32 33Host system dependencies 34************************ 35 36Please check the 37:ref:`Posix Arch Dependencies<posix_arch_deps>` 38 39.. _nativesim_important_limitations: 40 41Important limitations and unsupported features 42********************************************** 43 44``native_sim`` is based on the :ref:`POSIX architecture<Posix arch>`, and therefore 45:ref:`its limitations <posix_arch_limitations>` and considerations apply to it. 46 47Similarly, it inherits the POSIX architecture 48:ref:`unsupported features set <posix_arch_unsupported>`. 49 50Note that some drivers may have limitations, or may not support their whole driver API optional 51functionality. 52 53.. _native_sim_how_to_use: 54 55How to use it 56************* 57 58Compiling 59========= 60 61To build, simply specify the ``native_sim`` board as target: 62 63.. zephyr-app-commands:: 64 :zephyr-app: samples/hello_world 65 :host-os: unix 66 :board: native_sim 67 :goals: build 68 :compact: 69 70Running 71======= 72 73The result of the compilation is an executable (``zephyr.exe``) placed in the 74``zephyr/`` subdirectory of the ``build`` folder. 75Run the ``zephyr.exe`` executable as you would any other Linux console application. 76 77.. code-block:: console 78 79 $ ./build/zephyr/zephyr.exe 80 # Press Ctrl+C to exit 81 82This executable accepts several command line options depending on the 83compilation configuration. 84You can run it with the ``--help`` command line switch to get a list of 85available options. 86 87.. code-block:: console 88 89 $ ./build/zephyr/zephyr.exe --help 90 91Note that the Zephyr kernel does not actually exit once the application is 92finished. It simply goes into the idle loop forever. 93Therefore you must stop the application manually (Ctrl+C in Linux). 94 95Application tests using the :ref:`ztest framework<test-framework>` will exit after all 96tests have completed. 97 98If you want your application to gracefully finish when it reaches some point, 99you may add a conditionally compiled (:kconfig:option:`CONFIG_ARCH_POSIX`) call to 100``nsi_exit(int status)`` at that point. 101 102.. _native_sim_debug: 103 104Debugging 105========= 106 107Since the Zephyr executable is a native application, it can be debugged and 108instrumented as any other native program. The program is compiled with debug 109information, so it can be run directly in, for example, ``gdb`` or instrumented 110with ``valgrind``. 111 112Because the execution of your Zephyr application is normally deterministic 113(there are no asynchronous or random components), you can execute the 114code multiple times and get the exact same result. Instrumenting the 115code does not affect its execution. 116 117To ease debugging you may want to compile your code without optimizations 118(e.g., ``-O0``) by setting :kconfig:option:`CONFIG_NO_OPTIMIZATIONS`. 119 120For ease of debugging consider using an IDE as GUI for your debugger. 121 122.. _native_sim_asan: 123 124Address Sanitizer (ASan) 125======================== 126 127You can also build Zephyr with the `Address Sanitizer`_. To do this, set 128:kconfig:option:`CONFIG_ASAN`, for example, in the application project file, or in the 129``west build`` or ``cmake`` command line invocation. 130 131Note that you will need the ASan library installed in your system. 132In Debian/Ubuntu this is ``libasan1``. 133 134.. _Address Sanitizer: 135 https://github.com/google/sanitizers/wiki/AddressSanitizer 136 137Undefined Behavior Sanitizer (UBSan) 138==================================== 139 140You can also build Zephyr with the `Undefined Behavior Sanitizer`_. To do this, set 141:kconfig:option:`CONFIG_UBSAN`, for example, in the application project file, or in the 142``west build`` or ``cmake`` command line invocation. 143 144.. _Undefined Behavior Sanitizer: 145 https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html 146 147Coverage reports 148================ 149 150See 151:ref:`coverage reports using the POSIX architecture<coverage_posix>`. 152 153 154.. _native_sim32_64: 155 15632 and 64bit versions 157===================== 158 159native_sim comes with two targets: A 32 bit and 64 bit version. 160The 32 bit version, ``native_sim``, is the default target, which will compile 161your code for the ILP32 ABI (i386 in a x86 or x86_64 system) where pointers 162and longs are 32 bits. 163This mimics the ABI of most embedded systems Zephyr targets, 164and is therefore normally best to test and debug your code, as some bugs are 165dependent on the size of pointers and longs. 166This target requires either a 64 bit system with multilib support installed or 167one with a 32bit userspace. 168 169The 64 bit version, ``native_sim/native/64``, compiles your code targeting the 170LP64 ABI (x86-64 in x86 systems), where pointers and longs are 64 bits. 171You can use this target if you cannot compile or run 32 bit binaries. 172 173.. _native_sim_Clib_choice: 174 175C library choice 176**************** 177 178native_sim may be compiled with a choice of C libraries. 179By default it will be compiled with the host C library (:kconfig:option:`CONFIG_EXTERNAL_LIBC`), 180but you can also select to build it with :kconfig:option:`CONFIG_MINIMAL_LIBC` or with 181:kconfig:option:`CONFIG_PICOLIBC`. 182If you select some feature which are not compatible with the host C library, 183:ref:`Picolibc <c_library_picolibc>` will be selected by default instead. 184 185When building with either :ref:`minimal <c_library_minimal>` or :ref:`Picolibc<c_library_picolibc>` 186you will build your code in a more similar way as when building for the embedded target, 187you will be able to test your code interacting with that C library, 188and there will be no conflicts with the :ref:`POSIX OS abstraction<posix_support>` shim, 189but, accessing the host for test purposes from your embedded code will be more 190difficult, and you will have a limited choice of 191:ref:`drivers and backends to chose from<native_sim_peripherals_c_compat>`. 192 193Rationale for this port and comparison with other options 194********************************************************* 195 196The native_sim board shares the overall 197:ref:`intent of the POSIX architecture<posix_arch_rationale>`, 198while being a HW agnostic test platform which in some cases utilizes the host 199OS peripherals. 200It does not intend to model any particular HW, and as such can only be used 201to develop and test application code which is far decoupled from the HW. 202 203For developing and testing SW which requires specific HW, while retaining the 204benefits of the POSIX architecture other solutions like the 205:ref:`bsim boards<bsim boards>` 206should be considered. 207 208Check the :ref:`POSIX architecture comparison <posix_arch_compare>` 209with other development and test options for more insights. 210 211.. _native_sim_architecture: 212 213Architecture 214************ 215 216This board is based on the POSIX architecture port of Zephyr and shares 217:ref:`its basic architecture<posix_arch_architecture>` regarding threading 218and CPU/HW scheduling. 219 220If you are interested on the inner workings of the native simulator itself, you can check 221`its documentation <https://github.com/BabbleSim/native_simulator/blob/main/docs/README.md>`_. 222 223This board does not try to emulate any particular embedded CPU or SOC. 224The code is compiled natively for the host system (typically x86). 225 226About time in native_sim 227======================== 228 229Normally simulated time runs fully decoupled from the real host time 230and as fast as the host compute power would allow. 231This is desirable when running in a debugger or testing in batch, but not if 232interacting with external interfaces based on the real host time. 233 234The Zephyr kernel is only aware of the simulated time as provided by the 235HW models. Therefore any normal Zephyr thread will also know only about 236simulated time. 237 238The only link between the simulated time and the real/host time, if any, 239is created by the clock and timer model. 240 241This model can be configured to slow down the execution of native_sim to 242real time. 243You can do this with the ``--rt`` and ``--no-rt`` options from the command line. 244The default behavior is set with 245:kconfig:option:`CONFIG_NATIVE_SIM_SLOWDOWN_TO_REAL_TIME`. 246 247Note that all this model does is wait before raising the 248next system tick interrupt until the corresponding real/host time. 249If, for some reason, native_sim runs slower than real time, all this 250model can do is "catch up" as soon as possible by not delaying the 251following ticks. 252So if the host load is too high, or you are running in a debugger, you will 253see simulated time lagging behind the real host time. 254This solution ensures that normal runs are still deterministic while 255providing an illusion of real timeness to the observer. 256 257When locked to real time, simulated time can also be set to run faster or 258slower than real time. 259This can be controlled with the ``--rt-ratio=<ratio>`` and ``-rt-drift=<drift>`` 260command line options. Note that both of these options control the same 261underlying mechanism, and that ``drift`` is by definition equal to 262``ratio - 1``. 263It is also possible to adjust this clock speed on the fly with 264:c:func:`native_rtc_adjust_clock()`. 265 266In this way if, for example, ``--rt-ratio=2`` is given, the simulated time 267will advance at twice the real time speed. 268Similarly if ``--rt-drift=-100e-6`` is given, the simulated time will progress 269100ppm slower than real time. 270Note that these 2 options have no meaning when running in non real-time 271mode. 272 273How simulated time and real time relate to each other 274----------------------------------------------------- 275 276Simulated time (``st``) can be calculated from real time (``rt``) as 277 278.. math:: 279 st = (rt - last\_rt) \times ratio + last\_st 280 281And vice-versa: 282 283.. math:: 284 rt = (st - last\_st) / ratio + last\_rt 285 286Where ``last_rt`` and ``last_st`` are respectively the real time and the 287simulated time when the last clock ratio adjustment took place. 288 289All times are kept in microseconds. 290 291.. _native_sim_peripherals: 292 293Peripherals 294*********** 295 296The following peripherals are currently provided with this board: 297 298**Interrupt controller** 299 A simple yet generic interrupt controller is provided. It can nest interrupts 300 and provides interrupt priorities. Interrupts can be individually masked or 301 unmasked. SW interrupts are also supported. 302 303**Clock, timer and system tick model** 304 This model provides the system tick timer. By default 305 :kconfig:option:`CONFIG_SYS_CLOCK_TICKS_PER_SEC` configures it to tick every 10ms. 306 307 Please refer to the section `About time in native_sim`_ for more 308 information. 309 310**UART/Serial** 311 Two optional native UART drivers are available: 312 313 **PTY driver (UART_NATIVE_PTY)** 314 With this driver, Zephyr UART devices can be created. These 315 can be connected to the Linux process stdin/stdout or a newly created 316 pseudo-tty. For more information refer to the section `PTY UART`_. 317 318 **TTY driver (UART_NATIVE_TTY)** 319 An UART driver for interacting with host-attached serial port devices 320 (eg. USB to UART dongles). For more information refer to the section 321 `TTY UART`_. 322 323**Real time clock** 324 The real time clock model provides a model of a constantly powered clock. 325 By default this is initialized to the host time at boot. 326 327 This RTC can also be set to start from time 0 with the ``--rtc-reset`` command 328 line option. 329 330 It is possible to offset the RTC clock value at boot with the 331 ``--rtc-offset=<offset>`` option, 332 or to adjust it dynamically with the function :c:func:`native_rtc_offset`. 333 334 After start, this RTC advances with the simulated time, and is therefore 335 affected by the simulated time speed ratio. 336 See `About time in native_sim`_ for more information. 337 338 The time can be queried with the functions :c:func:`native_rtc_gettime_us` 339 and :c:func:`native_rtc_gettime`. Both accept as parameter the clock source: 340 341 - ``RTC_CLOCK_BOOT``: It counts the simulated time passed since boot. 342 It is not subject to offset adjustments 343 - ``RTC_CLOCK_REALTIME``: RTC persistent time. It is affected by 344 offset adjustments. 345 - ``RTC_CLOCK_PSEUDOHOSTREALTIME``: A version of the real host time, 346 as if the host was also affected by the clock speed ratio and offset 347 adjustments performed to the simulated clock and this RTC. Normally 348 this value will be a couple of hundredths of microseconds ahead of the 349 simulated time, depending on the host execution speed. 350 This clock source should be used with care, as depending on the actual 351 execution speed of native_sim and the host load, 352 it may return a value considerably ahead of the simulated time. 353 354 Note this device does not yet have an :ref:`RTC API compatible driver <rtc_api>`. 355 356.. _nsim_per_entr: 357 358**Entropy device** 359 An entropy device based on the host :c:func:`random` API. 360 This device will generate the same sequence of random numbers if initialized 361 with the same random seed. 362 You can change this random seed value by using the command line option: 363 :samp:`--seed={<random_seed>}` where the value specified is a 32-bit integer 364 such as 97229 (decimal), 0x17BCD (hex), or 0275715 (octal). 365 366.. _nsim_per_ethe: 367 368**Ethernet driver** 369 A simple TAP based ethernet driver is provided. The driver expects that the 370 **zeth** network interface already exists in the host system. The **zeth** 371 network interface can be created by the ``net-setup.sh`` script found in 372 the `net-tools`_ zephyr project repository. User can communicate with the 373 Zephyr instance via the **zeth** network interface. Multiple TAP based 374 network interfaces can be created if needed. The IP address configuration 375 can be specified for each network interface instance. 376 377 Note that this device can only be used with Linux hosts. 378 379.. _`net-tools`: https://github.com/zephyrproject-rtos/net-tools 380 381.. _nsim_per_offloaded_sockets: 382 383**Offloaded sockets driver** 384 This driver is an alternative to the :ref:`TAP based ethernet driver 385 <nsim_per_ethe>`. Instead of using a virtual network in the Linux side, this 386 driver utilizes Linux's standard BSD socket API. With this, multiple Zephyr 387 applications can communicate over the Linux loopback interface. 388 The benefit of this approach is that root privileges are not required and 389 that the process is connected to the same interface as other Linux processes 390 instead of a virtual network, facilitating testing without the need for extra 391 setup in the host. The drawback is that the L2 layer of Zephyr's networking 392 stack is not exercised. 393 394.. _nsim_bt_host_cont: 395 396**Bluetooth controller** 397 It's possible to use the host's Bluetooth adapter as a Bluetooth 398 controller for Zephyr. To do this the HCI device needs to be passed as 399 a command line option to ``zephyr.exe``. For example, to use ``hci0``, 400 use ``sudo zephyr.exe --bt-dev=hci0``. Using the device requires root 401 privileges (or the CAP_NET_ADMIN POSIX capability, to be exact) so 402 ``zephyr.exe`` needs to be run through ``sudo``. The chosen HCI device 403 must be powered down and support Bluetooth Low Energy (i.e. support the 404 Bluetooth specification version 4.0 or greater). 405 406 Another possibility is to use a HCI TCP server which acts as a 407 :ref:`virtual Bluetooth controller<bluetooth_virtual_posix>` over TCP. 408 To connect to a HCI TCP server its IP address and port number must 409 be specified. For example, to connect to a HCI TCP server with IP 410 address 127.0.0.0 and port number 1020 use ``zephyr.exe --bt-dev=127.0.0.1:1020``. 411 This alternative option is mainly aimed for testing Bluetooth connectivity over 412 a virtual Bluetooth controller that does not depend on the Linux Bluetooth 413 stack and its HCI interface. 414 415.. _nsim_per_usb: 416 417**USB controller** 418 It's possible to use the Virtual USB controller working over USB/IP 419 protocol. More information can be found in 420 :ref:`Testing USB over USP/IP in native_sim <testing_USB_native_sim>`. 421 422.. _nsim_per_disp_sdl: 423 424**Display driver** 425 A display driver is provided that creates a window on the host machine to 426 render display content. 427 428 When building for the default 32bit ``native_sim`` target this driver requires a 32-bit version of 429 the `SDL2`_ development library on the host machine. For 430 :ref:`64bit native_sim<native_sim32_64>` builds you need to have the 64bit version installed. 431 You may also need to set ``pkg-config`` to correctly pickup the SDL2 install path. 432 433 On Ubuntu the package is ``libsdl2-dev`` whose 64bit version is likely installed by default. 434 On an Ubuntu 18.04 host system, you can install the ``pkg-config`` and the 32bit 435 ``libsdl2-dev:i386`` packages, and configure the pkg-config search path with these commands: 436 437 .. code-block:: console 438 439 $ sudo dpkg --add-architecture i386 440 $ sudo apt update 441 $ sudo apt-get install pkg-config libsdl2-dev:i386 442 $ export PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig 443 444.. _SDL2: 445 https://www.libsdl.org 446 447.. _nsim_per_flash_simu: 448 449**EEPROM simulator** 450 The EEPROM simulator can also be used in the native targets. In these, you have the added feature 451 of keeping the EEPROM content on a file on the host filesystem. 452 By default this is kept in the file :file:`eeprom.bin` in the current working directory, but you 453 can select the location of this file and its name with the command line parameter ``--eeprom``. 454 Some more information can be found in :ref:`the emulators page <emul_eeprom_simu_brief>`. 455 456**Flash simulator** 457 The flash simulator can also be used in the native targets. In this you have the option to keep 458 the flash content in a binary file on the host file system or in RAM. The behavior of the flash 459 device can be configured through the native_sim board devicetree or Kconfig settings under 460 :kconfig:option:`CONFIG_FLASH_SIMULATOR`. 461 462 By default the binary data is located in the file :file:`flash.bin` in the current 463 working directory. The location of this file can be changed through the 464 command line parameter ``--flash``. The flash data will be stored in raw format 465 and the file will be truncated to match the size specified in the devicetree 466 configuration. In case the file does not exists the driver will take care of 467 creating the file, else the existing file is used. 468 469 Some more information can be found in :ref:`the emulators page <emul_flash_simu_brief>`. 470 471 The flash content can be accessed from the host system, as explained in the 472 `Host (FUSE) filesystem access`_ section. 473 474**Input events** 475 Two optional native input drivers are available: 476 477 **evdev driver** 478 A driver is provided to read input events from a Linux evdev input device and 479 inject them back into the Zephyr input subsystem. 480 481 The driver is automatically enabled when :kconfig:option:`CONFIG_INPUT` is 482 enabled and the devicetree contains a node such as: 483 484 .. code-block:: dts 485 486 evdev { 487 compatible = "zephyr,native-linux-evdev"; 488 }; 489 490 The application then has to be run with a command line option to specify 491 which evdev device node has to be used, for example 492 ``zephyr.exe --evdev=/dev/input/event0``. 493 494 **Input SDL touch** 495 This driver emulates a touch panel input using the SDL library. It can be enabled with 496 :kconfig:option:`CONFIG_INPUT_SDL_TOUCH` and configured with the device tree binding 497 :dtcompatible:`zephyr,input-sdl-touch`. 498 499 More information on using SDL and the Display driver can be found in 500 :ref:`its section <nsim_per_disp_sdl>`. 501 502**CAN controller** 503 It is possible to use a host CAN controller with the native SocketCAN Linux driver. It can be 504 enabled with :kconfig:option:`CONFIG_CAN_NATIVE_LINUX` and configured with the device tree binding 505 :dtcompatible:`zephyr,native-linux-can`. 506 507 It is possible to specify which CAN interface will be used by the app using the ``--can-if`` 508 command-line option. This option overrides **every** Linux SocketCAN driver instance to use the specified 509 interface. 510 511.. _native_ptty_uart: 512 513PTY UART 514========= 515 516This driver is automatically enabled when devicetree contains nodes with the 517``"zephyr,native-pty-uart"`` compatible property and ``okay`` status and 518:kconfig:option:`CONFIG_SERIAL` is set. 519By default one ready UART of this type is setup in DTS, but any number can be enabled as desired. 520 521Normally these UARTs are connected to new pseudoterminals PTYs, i.e. :file:`/dev/pts{<nbr>}`, 522but it is also possible to map one of them to the executable's ``stdin`` and ``stdout``. 523This can be done in two ways, either with the command line option ``--<uart_name>_stdinout`` 524(where ``<uart_name>`` is the UART DTS node name), or, for the first PTY UART instance by chosing 525:kconfig:option:`CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT` instead of the default 526:kconfig:option:`CONFIG_UART_NATIVE_PTY_0_ON_OWN_PTY`. 527For interactive use with the :ref:`shell_api`, it is recommended to choose the PTY option. 528The ``STDINOUT`` option can be used for automated testing, such as when piping other processes' 529output to control it. This is because the shell subsystem expects access to a raw terminal, 530which (by default) a normal Linux terminal is not. 531 532When a UART is connected to a new PTY, the name of the newly created UART pseudo-terminal will be 533displayed in the console. 534If you want to interact with it manually, you should attach a terminal emulator to it. 535This can be done, for example with the command: 536 537.. code-block:: console 538 539 $ xterm -e screen /dev/<ptyn> & 540 # Or if you prefer gnome-terminal: 541 $ gnome-terminal -- screen /dev/<ptyn> & 542 543where :file:`/dev/{<ptyn>}` should be replaced with the actual PTY device. 544 545You may also chose to automatically attach a terminal emulator to any of these UARTs. 546To automatically attach one to all these UARTs, pass the command line option ``-attach_uart`` to the 547executable. To automatically attach one to a single UART use ``-<uart_name>_attach_uart`` 548The command used for attaching to the new shell can be set for all UARTs with the command line 549option ``-attach_uart_cmd=<"cmd">``, or for each individual UART with 550``-<uart_name>_attach_uart_cmd``. Where the default command is given by 551:kconfig:option:`CONFIG_UART_NATIVE_PTY_AUTOATTACH_DEFAULT_CMD`. 552Note that the default command assumes both ``xterm`` and ``screen`` are installed in the system. 553 554This driver only supports poll mode. Interrupt and async mode are not supported. 555Neither runtime configuration or line control are supported. 556 557.. _native_tty_uart: 558 559TTY UART 560======== 561 562With this driver an application can use the polling and interrupt based UART APIs to write and read 563characters to and from a connected serial port device. 564 565This driver is automatically enabled when a devicetree contains a node 566with ``"zephyr,native-tty-uart"`` compatible property and ``okay`` status, such 567as one below. 568 569.. code-block:: dts 570 571 uart { 572 status = "okay"; 573 compatible = "zephyr,native-tty-uart"; 574 serial-port = "/dev/ttyUSB0"; 575 current-speed = <115200>; 576 }; 577 578Interaction with serial ports can be configured in several different ways: 579 580* The default serial port and baud rate can be set via the device tree 581 properties ``serial-port`` and ``current-speed`` respectively. The 582 ``serial-port`` property is optional. 583* Serial port and baud rate can also be set via command line options ``X_port`` 584 and ``X_baud`` respectively, where ``X`` is a name of a node. Command line 585 options override values from the devicetree. 586* The rest of the configuration options such as number of data and stop bits, 587 parity, as well as baud rate can be set at runtime with ``uart_configure``. 588* This driver can emulate an interrupt-driven UART by enabling 589 :kconfig:option:`CONFIG_UART_INTERRUPT_DRIVEN`. 590 591Multiple instances of such uart drivers are supported. 592 593The :zephyr:code-sample:`uart-native-tty` sample app provides a working example of the 594driver. 595 596This driver only supports poll mode and interrupt mode. Async mode is not 597supported. 598It has runtime configuration support, but no line control support. 599 600.. _native_sim_backends: 601 602Subsystems backends 603******************* 604 605Apart from its own peripherals, the native_sim board also has some dedicated 606backends for some of Zephyr's subsystems. These backends are designed to ease 607development by integrating more seamlessly with the host operating system: 608 609.. _nsim_back_console: 610 611**Console backend**: 612 A console backend which by default is configured to 613 redirect any :c:func:`printk` write to the native host application's 614 ``stdout``. 615 616 This driver is selected by default if no UART driver is compiled in. 617 Otherwise :kconfig:option:`CONFIG_UART_CONSOLE` will be set to select the UART as 618 console backend. 619 620.. _nsim_back_logger: 621 622**Logger backend**: 623 A backend which prints all logger output to the process ``stdout``. 624 It supports timestamping, which can be enabled with 625 :kconfig:option:`CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP`; and colored output which can 626 be enabled with :kconfig:option:`CONFIG_LOG_BACKEND_SHOW_COLOR` and controlled 627 with the command line options ``--color``, ``--no-color`` and 628 ``--force-color``. 629 630 In native_sim, by default, the logger is configured with 631 :kconfig:option:`CONFIG_LOG_MODE_IMMEDIATE`. 632 633 This backend can be selected with :kconfig:option:`CONFIG_LOG_BACKEND_NATIVE_POSIX` 634 and is enabled by default. 635 636.. _nsim_back_trace: 637 638**Tracing**: 639 A backend/"bottom" for Zephyr's CTF tracing subsystem which writes the tracing 640 data to a file in the host filesystem. 641 More information can be found in :ref:`Common Tracing Format <ctf>` 642 643Emulators 644********* 645 646All :ref:`available HW emulators <emulators>` can be used with native_sim. 647 648.. _native_fuse_flash: 649 650Host (FUSE) filesystem access 651***************************** 652 653When building Zephyr with a filesystem, the device partitions can be exposed through the host file 654system by enabling :kconfig:option:`CONFIG_FUSE_FS_ACCESS`. This option enables a FUSE 655(File system in User space) layer that mounts the simulated embedded filesystem in the host 656filesystem, maps the Zephyr file system calls to the required UNIX file system calls, and provides 657access to its partitions with normal operating system commands such as ``cd``, ``ls`` and ``mkdir``. 658 659By default the partitions are exposed through the directory :file:`flash/` in the 660current working directory. This directory can be changed via the command line 661option ``--flash-mount``. 662 663On exit, the native_sim board application will take care of unmounting the 664directory. In the unfortunate case that the native_sim board application 665crashes, you can cleanup the stale mount point by using the program 666``fusermount``: 667 668.. code-block:: console 669 670 $ fusermount -u flash 671 672Note that this feature requires a 32-bit version of the FUSE library, with a 673minimal version of 2.6, on the host system and ``pkg-config`` settings to 674correctly pickup the FUSE install path and compiler flags. 675 676On a Ubuntu 22.04 host system, for example, install the ``pkg-config`` and 677``libfuse-dev:i386`` packages, and configure the pkg-config search path with 678these commands: 679 680.. code-block:: console 681 682 $ sudo dpkg --add-architecture i386 683 $ sudo apt update 684 $ sudo apt-get install pkg-config libfuse-dev:i386 685 $ export PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig 686 687.. _native_sim_peripherals_c_compat: 688 689Peripherals and backends C library compatibility 690************************************************ 691 692Today, some native_sim peripherals and backends are, so far, only available when compiling with the 693host libC (:kconfig:option:`CONFIG_EXTERNAL_LIBC`): 694 695.. csv-table:: Drivers/backends vs libC choice 696 :header: Driver class, driver name, driver kconfig, libC choices 697 698 ADC, ADC emul, :kconfig:option:`CONFIG_ADC_EMUL`, All 699 Bluetooth, :ref:`Userchan <nsim_bt_host_cont>`, :kconfig:option:`CONFIG_BT_USERCHAN`, Host and pico libC 700 CAN, CAN native Linux, :kconfig:option:`CONFIG_CAN_NATIVE_LINUX`, All 701 Console backend, :ref:`POSIX arch console <nsim_back_console>`, :kconfig:option:`CONFIG_POSIX_ARCH_CONSOLE`, All 702 Display, :ref:`Display SDL <nsim_per_disp_sdl>`, :kconfig:option:`CONFIG_SDL_DISPLAY`, All 703 Entropy, :ref:`Native simulator entropy <nsim_per_entr>`, :kconfig:option:`CONFIG_FAKE_ENTROPY_NATIVE_SIM`, All 704 EEPROM, EEPROM simulator, :kconfig:option:`CONFIG_EEPROM_SIMULATOR`, All 705 EEPROM, EEPROM emulator, :kconfig:option:`CONFIG_EEPROM_EMULATOR`, All 706 Ethernet, :ref:`Eth native_tap <nsim_per_ethe>`, :kconfig:option:`CONFIG_ETH_NATIVE_TAP`, All 707 Flash, :ref:`Flash simulator <nsim_per_flash_simu>`, :kconfig:option:`CONFIG_FLASH_SIMULATOR`, All 708 FUSE, :ref:`Host based filesystem access <native_fuse_flash>`, :kconfig:option:`CONFIG_FUSE_FS_ACCESS`, All 709 GPIO, GPIO emulator, :kconfig:option:`CONFIG_GPIO_EMUL`, All 710 GPIO, SDL GPIO emulator, :kconfig:option:`CONFIG_GPIO_EMUL_SDL`, All 711 I2C, I2C emulator, :kconfig:option:`CONFIG_I2C_EMUL`, All 712 Input, Input SDL touch, :kconfig:option:`CONFIG_INPUT_SDL_TOUCH`, All 713 Input, Linux evdev, :kconfig:option:`CONFIG_NATIVE_LINUX_EVDEV`, All 714 Logger backend, :ref:`Native backend <nsim_back_logger>`, :kconfig:option:`CONFIG_LOG_BACKEND_NATIVE_POSIX`, All 715 Offloaded sockets, :ref:`nsim_per_offloaded_sockets`, :kconfig:option:`CONFIG_NET_NATIVE_OFFLOADED_SOCKETS`, All 716 RTC, RTC emul, :kconfig:option:`CONFIG_RTC_EMUL`, All 717 Serial, :ref:`UART native PTY <native_ptty_uart>`, :kconfig:option:`CONFIG_UART_NATIVE_PTY`, All 718 Serial, :ref:`UART native TTY <native_tty_uart>`, :kconfig:option:`CONFIG_UART_NATIVE_TTY`, All 719 SPI, SPI emul, :kconfig:option:`CONFIG_SPI_EMUL`, All 720 System tick, Native_sim timer, :kconfig:option:`CONFIG_NATIVE_SIM_TIMER`, All 721 Tracing, :ref:`Posix tracing backend <nsim_back_trace>`, :kconfig:option:`CONFIG_TRACING_BACKEND_POSIX`, All 722 USB, :ref:`USB native posix <nsim_per_usb>`, :kconfig:option:`CONFIG_USB_NATIVE_POSIX`, Host libC 723