Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions docs/boards/zephyr/native_sim.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ For detailed information, see the [Zephyr Native Simulator Documentation](https:

## Architecture Support

The **native_sim/native/64** (64-bit variant) is supported for the following Ocre samples:
Both **native_sim/native/64** (64-bit) and **native_sim** (32-bit) variants are supported for the following Ocre samples:

- **mini**
- **demo**
- **supervisor**

**Note:** native_sim on 32-bit is not currently supported.
**Note:** The 32-bit variant requires `gcc-multilib` to be installed on your host machine (see [Prerequisites](#prerequisites)) if you are running on a 64-bit system.

## Networking

Expand Down Expand Up @@ -50,13 +50,21 @@ boards/overlay-nsos.conf

Start with [Getting Started with Zephyr](../../GetStartedZephyr.md) to get a working build environment.

To build for the 32-bit `native_sim` variant on a 64-bit system, install `gcc-multilib` on your host machine:

```bash
sudo apt install gcc-multilib
```
**Note:** this is not required for 32-bit systems.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Note: this is not required for 32-bit systems.

### Building with TAP Networking (Default)

To build native_sim with TAP networking:

```bash
west build -p always -b native_sim/native/64 src/samples/supervisor/zephyr/
```
Alternatively, the `native_sim` board could be used for supported 32-bit platforms.

### Building with NSOS Networking

Expand All @@ -65,6 +73,7 @@ To build native_sim with Native Sockets (NSOS):
```bash
west build -p always -b native_sim/native/64 src/samples/supervisor/zephyr/ -- -DEXTRA_CONF_FILE=boards/overlay-nsos.conf
```
Alternatively, the `native_sim` board could be used for supported 32-bit platforms.

## Running the Simulation

Expand Down Expand Up @@ -121,7 +130,7 @@ IPv4 unicast addresses (max 1):

## Memory Configuration

The native_sim/native/64 variant includes enhanced memory configuration:
Both `native_sim/native/64` and `native_sim` variant includes enhanced memory configuration:

```
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=10485760 # 10 MB malloc arena
Expand All @@ -143,7 +152,7 @@ storage: 16 MB (for container images)

## Limitations

- **64-bit only**: 32-bit native_sim is not supported
- **32-bit requires gcc-multilib on 64-bit systems**: Install `gcc-multilib` on your machine before building the 32-bit variant
- **Hardware peripherals**: No hardware-specific peripherals available (GPIO, sensors, etc.)

## References
Expand Down
6 changes: 5 additions & 1 deletion src/platform/zephyr/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ void *user_realloc(void *ptr, size_t size)

void *user_malloc(size_t size)
{
return malloc(size);
/* Note that Zephyr does not use the C11 aligned_alloc(). The aligned_alloc
implementation here is just a wrapper around sys_heap_aligned_alloc which does not
have the `the size be an integral multiple of alignment` requirement and so can be used
without any checks. */
return aligned_alloc(8, size);
}

void user_free(void *ptr)
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/wamr-wasip1/wamr.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ static int runtime_init(void)

/* Allocate memory for the shared heap */

shared_heap_buf = user_malloc(CONFIG_OCRE_SHARED_HEAP_BUF_VIRTUAL);
shared_heap_buf = user_malloc(CONFIG_OCRE_SHARED_HEAP_BUF_SIZE);
if (!shared_heap_buf) {
LOG_ERR("Failed to allocate memory for the shared heap of size %zu",
(size_t)CONFIG_OCRE_SHARED_HEAP_BUF_VIRTUAL);
(size_t)CONFIG_OCRE_SHARED_HEAP_BUF_SIZE);
return -1;
}
#elif defined(CONFIG_OCRE_SHARED_HEAP_BUF_PHYSICAL)
Expand Down
9 changes: 9 additions & 0 deletions src/samples/demo/zephyr/boards/native_sim.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# @copyright Copyright (c) contributors to Project Ocre,
# which has been established as Project Ocre a Series of LF Projects, LLC
#
# SPDX-License-Identifier: Apache-2.0

CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=10485760
CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
CONFIG_UART_NATIVE_PTY=y
CONFIG_SYS_HEAP_AUTO=y
14 changes: 14 additions & 0 deletions src/samples/demo/zephyr/boards/native_sim.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @copyright Copyright (c) contributors to Project Ocre,
* which has been established as Project Ocre a Series of LF Projects, LLC
*
* SPDX-License-Identifier: Apache-2.0
*/

&flash0 {
reg = < 0x0 DT_SIZE_M(32) >;
};

&storage_partition {
reg = < 0xfc000 DT_SIZE_M(16) >;
};
9 changes: 9 additions & 0 deletions src/samples/mini/zephyr/boards/native_sim.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# @copyright Copyright (c) contributors to Project Ocre,
# which has been established as Project Ocre a Series of LF Projects, LLC
#
# SPDX-License-Identifier: Apache-2.0

CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=10485760
CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
CONFIG_UART_NATIVE_PTY=y
CONFIG_SYS_HEAP_AUTO=y
14 changes: 14 additions & 0 deletions src/samples/mini/zephyr/boards/native_sim.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @copyright Copyright (c) contributors to Project Ocre,
* which has been established as Project Ocre a Series of LF Projects, LLC
*
* SPDX-License-Identifier: Apache-2.0
*/

&flash0 {
reg = < 0x0 DT_SIZE_M(32) >;
};

&storage_partition {
reg = < 0xfc000 DT_SIZE_M(16) >;
};
9 changes: 9 additions & 0 deletions src/samples/supervisor/zephyr/boards/native_sim.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# @copyright Copyright (c) contributors to Project Ocre,
# which has been established as Project Ocre a Series of LF Projects, LLC
#
# SPDX-License-Identifier: Apache-2.0

CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=10485760
CONFIG_UART_NATIVE_PTY_0_ON_STDINOUT=y
CONFIG_UART_NATIVE_PTY=y
CONFIG_SYS_HEAP_AUTO=y
14 changes: 14 additions & 0 deletions src/samples/supervisor/zephyr/boards/native_sim.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* @copyright Copyright (c) contributors to Project Ocre,
* which has been established as Project Ocre a Series of LF Projects, LLC
*
* SPDX-License-Identifier: Apache-2.0
*/

&flash0 {
reg = < 0x0 DT_SIZE_M(32) >;
};

&storage_partition {
reg = < 0xfc000 DT_SIZE_M(16) >;
};
8 changes: 7 additions & 1 deletion tests_hw/groups/demo/clean.sh
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
echo "Cleanup is complete"
#!/bin/sh
# @copyright Copyright (c) contributors to Project Ocre,
# which has been established as Project Ocre a Series of LF Projects, LLC
#
# SPDX-License-Identifier: Apache-2.0

echo "Cleanup is complete"
8 changes: 7 additions & 1 deletion tests_hw/groups/demo/setup.sh
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
echo "Setup is complete"
#!/bin/sh
# @copyright Copyright (c) contributors to Project Ocre,
# which has been established as Project Ocre a Series of LF Projects, LLC
#
# SPDX-License-Identifier: Apache-2.0

echo "Setup is complete"
8 changes: 7 additions & 1 deletion tests_hw/groups/mini/clean.sh
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
echo "Cleanup is complete"
#!/bin/sh
# @copyright Copyright (c) contributors to Project Ocre,
# which has been established as Project Ocre a Series of LF Projects, LLC
#
# SPDX-License-Identifier: Apache-2.0

echo "Cleanup is complete"
8 changes: 7 additions & 1 deletion tests_hw/groups/mini/setup.sh
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
echo "Setup is complete"
#!/bin/sh
# @copyright Copyright (c) contributors to Project Ocre,
# which has been established as Project Ocre a Series of LF Projects, LLC
#
# SPDX-License-Identifier: Apache-2.0

echo "Setup is complete"
7 changes: 6 additions & 1 deletion zephyr/wamr.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ elseif (DEFINED CONFIG_ARCH_POSIX)
elseif (UNAME_M STREQUAL "i686")
set (TARGET_ISA "X86_32")
elseif (UNAME_M STREQUAL "x86_64")
set (TARGET_ISA "X86_64")
# For x86_64, check if building 32-bit or 64-bit
if (DEFINED CONFIG_64BIT)
set (TARGET_ISA "X86_64")
else ()
set (TARGET_ISA "X86_32")
endif ()
else ()
message(SEND_ERROR "Unsupported build target platform!")
endif ()
Expand Down
Loading