|
| 1 | +# Zephyr Board: `native_sim` |
| 2 | + |
| 3 | +The **native_sim** board is a simulated Zephyr target that runs on your host Linux machine. It allows you to develop and test Zephyr applications without needing physical hardware. The native_sim board is particularly useful for rapid iteration, testing, and debugging. |
| 4 | + |
| 5 | +For detailed information, see the [Zephyr Native Simulator Documentation](https://docs.zephyrproject.org/latest/boards/native/native_sim/doc/index.html). |
| 6 | + |
| 7 | +## Architecture Support |
| 8 | + |
| 9 | +The **native_sim/native/64** (64-bit variant) is supported for the following Ocre samples: |
| 10 | + |
| 11 | +- **mini** |
| 12 | +- **demo** |
| 13 | +- **supervisor** |
| 14 | + |
| 15 | +**Note:** native_sim on 32-bit is not currently supported. |
| 16 | + |
| 17 | +## Networking |
| 18 | + |
| 19 | +For **supervisor** sample, native_sim board supports two distinct networking modes, configurable at build time: |
| 20 | + |
| 21 | +### 1. TAP Network Interface (Default) |
| 22 | + |
| 23 | +The TAP (TAP Virtual Network Interface) mode creates a virtual Ethernet network interface on your host machine, allowing the simulated board to communicate with the actual network. |
| 24 | + |
| 25 | +**Configuration:** |
| 26 | + |
| 27 | +- Uses `CONFIG_ETH_NATIVE_TAP=y` (enabled by default) |
| 28 | +- No additional configuration file needed |
| 29 | + |
| 30 | +### 2. NSOS (Native Sockets) Mode |
| 31 | + |
| 32 | +The NSOS (Native Sockets) mode uses the host machine's native socket implementation, allowing the simulated board to use the host's network stack directly. |
| 33 | + |
| 34 | +**Characteristics:** |
| 35 | + |
| 36 | +- Uses host native sockets API |
| 37 | +- Based on `CONFIG_NET_SOCKETS` and `CONFIG_NET_SOCKETS_OFFLOAD` |
| 38 | +- Uses separate `overlay-nsos.conf` configuration |
| 39 | + |
| 40 | +**Configuration File:** |
| 41 | +The NSOS mode uses board overlay configuration at: |
| 42 | + |
| 43 | +``` |
| 44 | +boards/overlay-nsos.conf |
| 45 | +``` |
| 46 | + |
| 47 | +## Build Instructions |
| 48 | + |
| 49 | +### Prerequisites |
| 50 | + |
| 51 | +Start with [Getting Started with Zephyr](../../GetStartedZephyr.md) to get a working build environment. |
| 52 | + |
| 53 | +### Building with TAP Networking (Default) |
| 54 | + |
| 55 | +To build native_sim with TAP networking: |
| 56 | + |
| 57 | +```bash |
| 58 | +west build -p always -b native_sim/native/64 src/samples/supervisor/zephyr/ |
| 59 | +``` |
| 60 | + |
| 61 | +### Building with NSOS Networking |
| 62 | + |
| 63 | +To build native_sim with Native Sockets (NSOS): |
| 64 | + |
| 65 | +```bash |
| 66 | +west build -p always -b native_sim/native/64 src/samples/supervisor/zephyr/ -- -DEXTRA_CONF_FILE=boards/overlay-nsos.conf |
| 67 | +``` |
| 68 | + |
| 69 | +## Running the Simulation |
| 70 | + |
| 71 | +After building, regardless of which network method was used, run the native_sim application with the following command: |
| 72 | + |
| 73 | +```bash |
| 74 | +west build -t run |
| 75 | +``` |
| 76 | + |
| 77 | +## Serial Console |
| 78 | + |
| 79 | +Unlike physical boards, native_sim outputs to your terminal directly. You will see output similar to: |
| 80 | + |
| 81 | +``` |
| 82 | +*** Booting Zephyr OS build <version> *** |
| 83 | +
|
| 84 | +ocre:~$ |
| 85 | +``` |
| 86 | + |
| 87 | +To interact with the Ocre shell, type commands directly in the same terminal. |
| 88 | + |
| 89 | +## Test Network Connectivity |
| 90 | + |
| 91 | +Once running, check network configuration with: |
| 92 | + |
| 93 | +```bash |
| 94 | +ocre:~$ net iface |
| 95 | +``` |
| 96 | + |
| 97 | +**Example TAP mode output:** |
| 98 | + |
| 99 | +```bash |
| 100 | +Interface eth0 (0x4ba390) (Ethernet) [1] |
| 101 | +=================================== |
| 102 | +Link addr : 02:00:5E:00:53:31 |
| 103 | +MTU : 1500 |
| 104 | +Flags : AUTO_START,IPv4,IPv6 |
| 105 | +Device : zeth0 (0x4b8b50) |
| 106 | +Status : oper=UP, admin=UP, carrier=ON |
| 107 | +``` |
| 108 | + |
| 109 | +**Example NSOS mode output:** |
| 110 | + |
| 111 | +```bash |
| 112 | +Interface net0 (0x4c1988) (<unknown type>) [1] |
| 113 | +========================================= |
| 114 | +MTU : 1500 |
| 115 | +Flags : AUTO_START,IPv4,IPv6 |
| 116 | +Device : nsos_socket (0x4c0008) |
| 117 | +Status : oper=UP, admin=UP, carrier=ON |
| 118 | +IPv4 unicast addresses (max 1): |
| 119 | + 192.0.2.1/255.255.255.0 overridable preferred infinite |
| 120 | +``` |
| 121 | + |
| 122 | +## Memory Configuration |
| 123 | + |
| 124 | +The native_sim/native/64 variant includes enhanced memory configuration: |
| 125 | + |
| 126 | +``` |
| 127 | +CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=10485760 # 10 MB malloc arena |
| 128 | +``` |
| 129 | + |
| 130 | +Flash and storage partitions are sized appropriately for simulation: |
| 131 | + |
| 132 | +``` |
| 133 | +flash0: 32 MB (simulated) |
| 134 | +storage: 16 MB (for container images) |
| 135 | +``` |
| 136 | + |
| 137 | +## Advantages for Development |
| 138 | + |
| 139 | +- **Fast iteration**: No hardware flashing required |
| 140 | +- **Easy debugging**: Direct terminal access and debugging tools |
| 141 | +- **Network simulation**: Test networking without physical network setup |
| 142 | +- **CI/CD compatible**: Can run in automated testing pipelines |
| 143 | + |
| 144 | +## Limitations |
| 145 | + |
| 146 | +- **64-bit only**: 32-bit native_sim is not supported |
| 147 | +- **Hardware peripherals**: No hardware-specific peripherals available (GPIO, sensors, etc.) |
| 148 | + |
| 149 | +## References |
| 150 | + |
| 151 | +- [Zephyr Native Simulator Documentation](https://docs.zephyrproject.org/latest/boards/native/native_sim/doc/index.html) |
| 152 | +- [Zephyr Networking Documentation](https://docs.zephyrproject.org/latest/connectivity/networking/index.html) |
| 153 | +- [Supervisor Sample Documentation](../../samples/supervisor.md) |
| 154 | + |
| 155 | +See the main documentation for: |
| 156 | + |
| 157 | +- [Zephyr Build System](../../BuildSystemZephyr.md) |
| 158 | +- [Get started Zephyr](../../GetStartedZephyr.md) |
0 commit comments