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 the older :ref:`native_posix<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 **PTTY driver (UART_NATIVE_POSIX)** 314 With this driver, one or two 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 `PTTY 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: 380 https://github.com/zephyrproject-rtos/net-tools 381 382.. _nsim_per_offloaded_sockets: 383 384**Offloaded sockets driver** 385 This driver is an alternative to the :ref:`TAP based ethernet driver 386 <nsim_per_ethe>`. Instead of using a virtual network in the Linux side, this 387 driver utilizes Linux's standard BSD socket API. With this, multiple Zephyr 388 applications can communicate over the Linux loopback interface. 389 The benefit of this approach is that root privileges are not required and 390 that the process is connected to the same interface as other Linux processes 391 instead of a virtual network, facilitating testing without the need for extra 392 setup in the host. The drawback is that the L2 layer of Zephyr's networking 393 stack is not exercised. 394 395.. _nsim_bt_host_cont: 396 397**Bluetooth controller** 398 It's possible to use the host's Bluetooth adapter as a Bluetooth 399 controller for Zephyr. To do this the HCI device needs to be passed as 400 a command line option to ``zephyr.exe``. For example, to use ``hci0``, 401 use ``sudo zephyr.exe --bt-dev=hci0``. Using the device requires root 402 privileges (or the CAP_NET_ADMIN POSIX capability, to be exact) so 403 ``zephyr.exe`` needs to be run through ``sudo``. The chosen HCI device 404 must be powered down and support Bluetooth Low Energy (i.e. support the 405 Bluetooth specification version 4.0 or greater). 406 407 Another possibility is to use a HCI TCP server which acts as a 408 :ref:`virtual Bluetooth controller<bluetooth_virtual_posix>` over TCP. 409 To connect to a HCI TCP server its IP address and port number must 410 be specified. For example, to connect to a HCI TCP server with IP 411 address 127.0.0.0 and port number 1020 use ``zephyr.exe --bt-dev=127.0.0.1:1020``. 412 This alternative option is mainly aimed for testing Bluetooth connectivity over 413 a virtual Bluetooth controller that does not depend on the Linux Bluetooth 414 stack and its HCI interface. 415 416.. _nsim_per_usb: 417 418**USB controller** 419 It's possible to use the Virtual USB controller working over USB/IP 420 protocol. More information can be found in 421 :ref:`Testing USB over USP/IP in native_sim <testing_USB_native_sim>`. 422 423.. _nsim_per_disp_sdl: 424 425**Display driver** 426 A display driver is provided that creates a window on the host machine to 427 render display content. 428 429 This driver requires a 32-bit version of the `SDL2`_ library on the host 430 machine and ``pkg-config`` settings to correctly pickup the SDL2 install path 431 and compiler flags. 432 433 On a Ubuntu 22.04 host system, for example, install the ``pkg-config`` and 434 ``libsdl2-dev:i386`` packages, and configure the pkg-config search path with 435 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/download-2.0.php 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 based flash 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 513PTTY UART 514========= 515 516This driver can be configured with :kconfig:option:`CONFIG_UART_NATIVE_POSIX` 517to instantiate up to two UARTs. By default only one UART is enabled. 518With :kconfig:option:`CONFIG_UART_NATIVE_POSIX_PORT_1_ENABLE` 519you can enable the second one. 520 521For the first UART, it can link it to a new 522pseudoterminal (i.e. :file:`/dev/pts{<nbr>}`), or map the UART input and 523output to the executable's ``stdin`` and ``stdout``. 524This is chosen by selecting either 525:kconfig:option:`CONFIG_NATIVE_UART_0_ON_OWN_PTY` or 526:kconfig:option:`CONFIG_NATIVE_UART_0_ON_STDINOUT` 527For interactive use with the :ref:`shell_api`, choose the first (OWN_PTY) option. 528The second (STDINOUT) option can be used with the shell for automated 529testing, such as when piping other processes' output to control it. 530This is because the shell subsystem expects access to a raw terminal, 531which (by default) a normal Linux terminal is not. 532 533When :kconfig:option:`CONFIG_NATIVE_UART_0_ON_OWN_PTY` is chosen, the name of the 534newly created UART pseudo-terminal will be displayed in the console. 535If you want to interact with it manually, you should attach a terminal emulator 536to it. This can be done, for example with the command: 537 538.. code-block:: console 539 540 $ xterm -e screen /dev/<ttyn> & 541 542where :file:`/dev/tty{<n>}` should be replaced with the actual TTY device. 543 544You may also chose to automatically attach a terminal emulator to the first UART 545by passing the command line option ``-attach_uart`` to the executable. 546The command used for attaching to the new shell can be set with the command line 547option ``-attach_uart_cmd=<"cmd">``. Where the default command is given by 548:kconfig:option:`CONFIG_NATIVE_UART_AUTOATTACH_DEFAULT_CMD`. 549Note that the default command assumes both ``xterm`` and ``screen`` are 550installed in the system. 551 552This driver only supports poll mode. Interrupt and async mode are not supported. 553Neither runtime configuration or line control are supported. 554 555.. _native_tty_uart: 556 557TTY UART 558======== 559 560With this driver an application can use the polling UART API (``uart_poll_out``, 561``uart_poll_in``) to write and read characters to and from a connected serial 562port device. 563 564This driver is automatically enabled when a devicetree contains a node 565with ``"zephyr,native-tty-uart"`` compatible property and ``okay`` status, such 566as one below. 567 568.. code-block:: dts 569 570 uart { 571 status = "okay"; 572 compatible = "zephyr,native-tty-uart"; 573 serial-port = "/dev/ttyUSB0"; 574 current-speed = <115200>; 575 }; 576 577Interaction with serial ports can be configured in several different ways: 578 579* The default serial port and baud rate can be set via the device tree 580 properties ``serial-port`` and ``current-speed`` respectively. The 581 ``serial-port`` property is optional. 582* Serial port and baud rate can also be set via command line options ``X_port`` 583 and ``X_baud`` respectively, where ``X`` is a name of a node. Command line 584 options override values from the devicetree. 585* The rest of the configuration options such as number of data and stop bits, 586 parity, as well as baud rate can be set at runtime with ``uart_configure``. 587* This driver can emulate an interrupt-driven UART by enabling 588 :kconfig:option:`CONFIG_UART_INTERRUPT_DRIVEN`. 589 590Multiple instances of such uart drivers are supported. 591 592The :zephyr:code-sample:`uart-native-tty` sample app provides a working example of the 593driver. 594 595This driver only supports poll mode and interrupt mode. Async mode is not 596supported. 597It has runtime configuration support, but no line control support. 598 599.. _native_sim_backends: 600 601Subsystems backends 602******************* 603 604Apart from its own peripherals, the native_sim board also has some dedicated 605backends for some of Zephyr's subsystems. These backends are designed to ease 606development by integrating more seamlessly with the host operating system: 607 608.. _nsim_back_console: 609 610**Console backend**: 611 A console backend which by default is configured to 612 redirect any :c:func:`printk` write to the native host application's 613 ``stdout``. 614 615 This driver is selected by default if the `PTTY UART`_ is not compiled in. 616 Otherwise :kconfig:option:`CONFIG_UART_CONSOLE` will be set to select the UART as 617 console backend. 618 619.. _nsim_back_logger: 620 621**Logger backend**: 622 A backend which prints all logger output to the process ``stdout``. 623 It supports timestamping, which can be enabled with 624 :kconfig:option:`CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP`; and colored output which can 625 be enabled with :kconfig:option:`CONFIG_LOG_BACKEND_SHOW_COLOR` and controlled 626 with the command line options ``--color``, ``--no-color`` and 627 ``--force-color``. 628 629 In native_sim, by default, the logger is configured with 630 :kconfig:option:`CONFIG_LOG_MODE_IMMEDIATE`. 631 632 This backend can be selected with :kconfig:option:`CONFIG_LOG_BACKEND_NATIVE_POSIX` 633 and is enabled by default. 634 635.. _nsim_back_trace: 636 637**Tracing**: 638 A backend/"bottom" for Zephyr's CTF tracing subsystem which writes the tracing 639 data to a file in the host filesystem. 640 More information can be found in :ref:`Common Tracing Format <ctf>` 641 642Emulators 643********* 644 645All :ref:`available HW emulators <emulators>` can be used with native_sim. 646 647.. _native_fuse_flash: 648 649Host based flash access 650*********************** 651 652If a flash device is present, the file system partitions on the flash 653device can be exposed through the host file system by enabling 654:kconfig:option:`CONFIG_FUSE_FS_ACCESS`. This option enables a FUSE 655(File system in User space) layer that maps the Zephyr file system calls to 656the required UNIX file system calls, and provides access to the flash file 657system partitions with normal operating system commands such as ``cd``, 658``ls`` and ``mkdir``. 659 660By default the partitions are exposed through the directory :file:`flash/` in the 661current working directory. This directory can be changed via the command line 662option ``--flash-mount``. As this directory operates as a mount point for FUSE 663you have to ensure that it exists before starting the native_sim board. 664 665On exit, the native_sim board application will take care of unmounting the 666directory. In the unfortunate case that the native_sim board application 667crashes, you can cleanup the stale mount point by using the program 668``fusermount``: 669 670.. code-block:: console 671 672 $ fusermount -u flash 673 674Note that this feature requires a 32-bit version of the FUSE library, with a 675minimal version of 2.6, on the host system and ``pkg-config`` settings to 676correctly pickup the FUSE install path and compiler flags. 677 678On a Ubuntu 22.04 host system, for example, install the ``pkg-config`` and 679``libfuse-dev:i386`` packages, and configure the pkg-config search path with 680these commands: 681 682.. code-block:: console 683 684 $ sudo dpkg --add-architecture i386 685 $ sudo apt update 686 $ sudo apt-get install pkg-config libfuse-dev:i386 687 $ export PKG_CONFIG_PATH=/usr/lib/i386-linux-gnu/pkgconfig 688 689.. _native_sim_peripherals_c_compat: 690 691Peripherals and backends C library compatibility 692************************************************ 693 694Today, some native_sim peripherals and backends are, so far, only available when compiling with the 695host libC (:kconfig:option:`CONFIG_EXTERNAL_LIBC`): 696 697.. csv-table:: Drivers/backends vs libC choice 698 :header: Driver class, driver name, driver kconfig, libC choices 699 700 ADC, ADC emul, :kconfig:option:`CONFIG_ADC_EMUL`, All 701 Bluetooth, :ref:`Userchan <nsim_bt_host_cont>`, :kconfig:option:`CONFIG_BT_USERCHAN`, Host libC 702 CAN, CAN native Linux, :kconfig:option:`CONFIG_CAN_NATIVE_LINUX`, All 703 Console backend, :ref:`POSIX arch console <nsim_back_console>`, :kconfig:option:`CONFIG_POSIX_ARCH_CONSOLE`, All 704 Display, :ref:`Display SDL <nsim_per_disp_sdl>`, :kconfig:option:`CONFIG_SDL_DISPLAY`, All 705 Entropy, :ref:`Native posix entropy <nsim_per_entr>`, :kconfig:option:`CONFIG_FAKE_ENTROPY_NATIVE_POSIX`, All 706 EEPROM, EEPROM simulator, :kconfig:option:`CONFIG_EEPROM_SIMULATOR`, Host libC 707 EEPROM, EEPROM emulator, :kconfig:option:`CONFIG_EEPROM_EMULATOR`, All 708 Ethernet, :ref:`Eth native_posix <nsim_per_ethe>`, :kconfig:option:`CONFIG_ETH_NATIVE_POSIX`, All 709 Flash, :ref:`Flash simulator <nsim_per_flash_simu>`, :kconfig:option:`CONFIG_FLASH_SIMULATOR`, All 710 Flash, :ref:`Host based flash access <native_fuse_flash>`, :kconfig:option:`CONFIG_FUSE_FS_ACCESS`, Host libC 711 GPIO, GPIO emulator, :kconfig:option:`CONFIG_GPIO_EMUL`, All 712 GPIO, SDL GPIO emulator, :kconfig:option:`CONFIG_GPIO_EMUL_SDL`, All 713 I2C, I2C emulator, :kconfig:option:`CONFIG_I2C_EMUL`, All 714 Input, Input SDL touch, :kconfig:option:`CONFIG_INPUT_SDL_TOUCH`, All 715 Input, Linux evdev, :kconfig:option:`CONFIG_NATIVE_LINUX_EVDEV`, All 716 Logger backend, :ref:`Native backend <nsim_back_logger>`, :kconfig:option:`CONFIG_LOG_BACKEND_NATIVE_POSIX`, All 717 Offloaded sockets, :ref:`nsim_per_offloaded_sockets`, :kconfig:option:`CONFIG_NET_NATIVE_OFFLOADED_SOCKETS`, All 718 RTC, RTC emul, :kconfig:option:`CONFIG_RTC_EMUL`, All 719 Serial, :ref:`UART native posix/PTTY <native_ptty_uart>`, :kconfig:option:`CONFIG_UART_NATIVE_POSIX`, All 720 Serial, :ref:`UART native TTY <native_tty_uart>`, :kconfig:option:`CONFIG_UART_NATIVE_TTY`, All 721 SPI, SPI emul, :kconfig:option:`CONFIG_SPI_EMUL`, All 722 System tick, Native_posix timer, :kconfig:option:`CONFIG_NATIVE_POSIX_TIMER`, All 723 Tracing, :ref:`Posix tracing backend <nsim_back_trace>`, :kconfig:option:`CONFIG_TRACING_BACKEND_POSIX`, All 724 USB, :ref:`USB native posix <nsim_per_usb>`, :kconfig:option:`CONFIG_USB_NATIVE_POSIX`, Host libC 725