diff --git a/docs/boards/zephyr/native_sim.md b/docs/boards/zephyr/native_sim.md index fdf7ad4e..9b5d7ef8 100644 --- a/docs/boards/zephyr/native_sim.md +++ b/docs/boards/zephyr/native_sim.md @@ -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 @@ -50,6 +50,13 @@ 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. + ### Building with TAP Networking (Default) To build native_sim with TAP networking: @@ -57,6 +64,7 @@ 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 @@ -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 @@ -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 @@ -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 diff --git a/src/platform/zephyr/memory.c b/src/platform/zephyr/memory.c index 5b79f1d4..f768a90d 100644 --- a/src/platform/zephyr/memory.c +++ b/src/platform/zephyr/memory.c @@ -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) diff --git a/src/runtime/wamr-wasip1/wamr.c b/src/runtime/wamr-wasip1/wamr.c index 2758f036..3d0955ab 100644 --- a/src/runtime/wamr-wasip1/wamr.c +++ b/src/runtime/wamr-wasip1/wamr.c @@ -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) diff --git a/src/samples/demo/zephyr/boards/native_sim.conf b/src/samples/demo/zephyr/boards/native_sim.conf new file mode 100644 index 00000000..b5f9460c --- /dev/null +++ b/src/samples/demo/zephyr/boards/native_sim.conf @@ -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 diff --git a/src/samples/demo/zephyr/boards/native_sim.overlay b/src/samples/demo/zephyr/boards/native_sim.overlay new file mode 100644 index 00000000..848942a0 --- /dev/null +++ b/src/samples/demo/zephyr/boards/native_sim.overlay @@ -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) >; +}; diff --git a/src/samples/mini/zephyr/boards/native_sim.conf b/src/samples/mini/zephyr/boards/native_sim.conf new file mode 100644 index 00000000..b5f9460c --- /dev/null +++ b/src/samples/mini/zephyr/boards/native_sim.conf @@ -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 diff --git a/src/samples/mini/zephyr/boards/native_sim.overlay b/src/samples/mini/zephyr/boards/native_sim.overlay new file mode 100644 index 00000000..848942a0 --- /dev/null +++ b/src/samples/mini/zephyr/boards/native_sim.overlay @@ -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) >; +}; diff --git a/src/samples/supervisor/zephyr/boards/native_sim.conf b/src/samples/supervisor/zephyr/boards/native_sim.conf new file mode 100644 index 00000000..b5f9460c --- /dev/null +++ b/src/samples/supervisor/zephyr/boards/native_sim.conf @@ -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 diff --git a/src/samples/supervisor/zephyr/boards/native_sim.overlay b/src/samples/supervisor/zephyr/boards/native_sim.overlay new file mode 100644 index 00000000..848942a0 --- /dev/null +++ b/src/samples/supervisor/zephyr/boards/native_sim.overlay @@ -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) >; +}; diff --git a/tests_hw/groups/demo/clean.sh b/tests_hw/groups/demo/clean.sh index 6b895bf1..260799ee 100644 --- a/tests_hw/groups/demo/clean.sh +++ b/tests_hw/groups/demo/clean.sh @@ -1 +1,7 @@ -echo "Cleanup is complete" \ No newline at end of file +#!/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" diff --git a/tests_hw/groups/demo/setup.sh b/tests_hw/groups/demo/setup.sh index 78545bd9..9e29b854 100644 --- a/tests_hw/groups/demo/setup.sh +++ b/tests_hw/groups/demo/setup.sh @@ -1 +1,7 @@ -echo "Setup is complete" \ No newline at end of file +#!/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" diff --git a/tests_hw/groups/mini/clean.sh b/tests_hw/groups/mini/clean.sh index 6b895bf1..260799ee 100644 --- a/tests_hw/groups/mini/clean.sh +++ b/tests_hw/groups/mini/clean.sh @@ -1 +1,7 @@ -echo "Cleanup is complete" \ No newline at end of file +#!/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" diff --git a/tests_hw/groups/mini/setup.sh b/tests_hw/groups/mini/setup.sh index 78545bd9..9e29b854 100644 --- a/tests_hw/groups/mini/setup.sh +++ b/tests_hw/groups/mini/setup.sh @@ -1 +1,7 @@ -echo "Setup is complete" \ No newline at end of file +#!/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" diff --git a/zephyr/wamr.cmake b/zephyr/wamr.cmake index aa311b01..50d6ccf4 100644 --- a/zephyr/wamr.cmake +++ b/zephyr/wamr.cmake @@ -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 ()