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
15 changes: 12 additions & 3 deletions doc/build_wamr.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,25 @@ WAMR provides some features which can be easily configured by passing options to

Zephyr
-------------------------
You need to download the Zephyr source code first and embed WAMR into it.
You need to prepare Zephyr first as described here https://docs.zephyrproject.org/latest/getting_started/index.html#get-zephyr-and-install-python-dependencies).

After that you need to point the `ZEPHYR_BASE` variable to e.g. `~/zephyrproject/zephyr`. Also, it is important that you have `west` available for subsequent actions.

``` Bash
git clone https://github.com/zephyrproject-rtos/zephyr.git
source zephyr/zephyr-env.sh
cd <wamr_root_dir>/product-mini/platforms/zephyr/simple
# Execute the ./build_and_run.sh script with board name as parameter. Here take x86 as example:
./build_and_run.sh x86
```

If you want to use the Espressif toolchain (esp32 or esp32c3), you can most conveniently install it with `west`:

``` Bash
cd $ZEPHYR_BASE
west espressif install
```

After that set `ESPRESSIF_TOOLCHAIN_PATH` according to the output, for example `~/.espressif/tools/zephyr`.

Note:
WAMR provides some features which can be easily configured by passing options to cmake, please see [WAMR vmcore cmake building configurations](./build_wamr.md#wamr-vmcore-cmake-building-configurations) for details. Currently in Zephyr, interpreter, AoT and builtin libc are enabled by default.

Expand Down
34 changes: 34 additions & 0 deletions product-mini/platforms/zephyr/simple/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
FROM ubuntu:20.04

ARG DOCKER_UID=1000

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get -qq update && apt-get -qq dist-upgrade && apt install -qq -y python3-pip git wget ninja-build

WORKDIR /tmp

RUN mkdir /opt/cmake && wget -q https://github.com/Kitware/CMake/releases/download/v3.22.1/cmake-3.22.1-linux-x86_64.sh && sh cmake-3.22.1-linux-x86_64.sh --skip-license --prefix=/opt/cmake && rm cmake-3.22.1-linux-x86_64.sh

ENV PATH="/opt/cmake/bin:$PATH"

RUN useradd -m wamr -u ${DOCKER_UID} -G dialout

USER wamr

ENV PATH="/home/wamr/.local/bin:$PATH"

RUN pip3 install --user west

RUN west init ~/zephyrproject && cd ~/zephyrproject && west update && west zephyr-export

RUN pip3 install --user -r ~/zephyrproject/zephyr/scripts/requirements.txt

WORKDIR /home/wamr/zephyrproject

RUN west espressif install

ENV ZEPHYR_BASE=/home/wamr/zephyrproject/zephyr
ENV ESPRESSIF_TOOLCHAIN_PATH=/home/wamr/.espressif/tools/zephyr

WORKDIR /home/wamr/source/product-mini/platforms/zephyr/simple
25 changes: 25 additions & 0 deletions product-mini/platforms/zephyr/simple/README_docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Build with Docker

To have a quicker start, a Docker container of the Zephyr setup can be generated.

## Build Docker container

``` Bash
docker build --build-arg DOCKER_UID=$(id -u) . -t wamr-zephyr
```

## Run Docker container to build images

Enter the docker container (maps the toplevel wasm-micro-runtime repo as volume):

``` Bash
docker run -ti -v $PWD/../../../..:/home/wamr/source --device=/dev/ttyUSB0 wamr-zephyr
```

Adopt the device or remove if not needed.

And then in the docker container:

``` Bash
./build_and_run.sh esp32c3
```
39 changes: 32 additions & 7 deletions product-mini/platforms/zephyr/simple/build_and_run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
X86_TARGET="x86"
STM32_TARGET="stm32"
ESP32_TARGET="esp32"
ESP32C3_TARGET="esp32c3"
PARTICLE_ARGON_TARGET="particle_argon"
QEMU_CORTEX_A53="qemu_cortex_a53"
QEMU_XTENSA_TARGET="qemu_xtensa"
QEMU_RISCV64_TARGET="qemu_riscv64"
Expand All @@ -15,11 +17,13 @@ QEMU_ARC_TARGET="qemu_arc"
usage ()
{
echo "USAGE:"
echo "$0 $X86_TARGET|$STM32_TARGET|$ESP32_TARGET|$QEMU_CORTEX_A53|$QEMU_XTENSA_TARGET|$QEMU_RISCV64_TARGET|$QEMU_RISCV32_TARGET|$QEMU_ARC_TARGET"
echo "$0 $X86_TARGET|$STM32_TARGET|$ESP32_TARGET|$ESP32C3_TARGET|$PARTICLE_ARGON_TARGET|$QEMU_CORTEX_A53|$QEMU_XTENSA_TARGET|$QEMU_RISCV64_TARGET|$QEMU_RISCV32_TARGET|$QEMU_ARC_TARGET"
echo "Example:"
echo " $0 $X86_TARGET"
echo " $0 $STM32_TARGET"
echo " $0 $ESP32_TARGET"
echo " $0 $ESP32C3_TARGET"
echo " $0 $PARTICLE_ARGON_TARGET"
echo " $0 $QEMU_CORTEX_A53"
echo " $0 $QEMU_XTENSA_TARGET"
echo " $0 $QEMU_RISCV64_TARGET"
Expand Down Expand Up @@ -47,14 +51,35 @@ case $TARGET in
west flash
;;
$ESP32_TARGET)
# suppose you have set environment variable ESP_IDF_PATH
export ZEPHYR_TOOLCHAIN_VARIANT="espressif"
if [[ -z "${ESPRESSIF_TOOLCHAIN_PATH}" ]]; then
echo "Set ESPRESSIF_TOOLCHAIN_PATH to your espressif toolchain"
exit 1
fi
west build -b esp32 \
. -p always -- \
-DESP_IDF_PATH=$ESP_IDF_PATH \
-DWAMR_BUILD_TARGET=XTENSA
# suppose the serial port is /dev/ttyUSB1 and you should change to
# the real name accordingly
west flash --esp-device /dev/ttyUSB1
-DWAMR_BUILD_TARGET=XTENSA
# west flash will discover the device
west flash
;;
$ESP32C3_TARGET)
export ZEPHYR_TOOLCHAIN_VARIANT="espressif"
if [[ -z "${ESPRESSIF_TOOLCHAIN_PATH}" ]]; then
echo "Set ESPRESSIF_TOOLCHAIN_PATH to your espressif toolchain"
exit 1
fi
west build -b esp32c3_devkitm \
. -p always -- \
-DWAMR_BUILD_TARGET=RISCV32_ILP32
# west flash will discover the device
west flash
;;
$PARTICLE_ARGON_TARGET)
west build -b particle_argon \
. -p always -- \
-DWAMR_BUILD_TARGET=THUMBV7
# west flash will discover the device
west flash
;;
$QEMU_XTENSA_TARGET)
west build -b qemu_xtensa \
Expand Down