mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-02-11 09:25:20 +00:00
Add docker file to fix Zephy ESP32 linking issue (#2314)
- Provide a Dockerfile.old to fix issue of ESP32 custom linker scripts not working properly with the newer version of Zephyr, as reported in #2263 - Provide a Dockerfile with newer Zephyr for other boards - Update the corresponding document
This commit is contained in:
parent
25a1985413
commit
e495276646
|
@ -251,17 +251,7 @@ WAMR provides some features which can be easily configured by passing options to
|
|||
|
||||
## Zephyr
|
||||
|
||||
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
|
||||
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
|
||||
```
|
||||
|
||||
The [Zephyr SDK](https://github.com/zephyrproject-rtos/sdk-ng) provides toolchains for all supported targets. Follow the instructions in the [documentation](https://docs.zephyrproject.org/latest/develop/getting_started/index.html#install-zephyr-sdk) to ensure it is installed and configured correctly.
|
||||
Please refer to this [README](./platforms/zephyr/simple/README.md) under the Zephyr sample directory for details.
|
||||
|
||||
Note:
|
||||
WAMR provides some features which can be easily configured by passing options to cmake, please see [WAMR vmcore cmake building configurations](../doc/build_wamr.md#wamr-vmcore-cmake-building-configurations) for details. Currently in Zephyr, interpreter, AOT and builtin libc are enabled by default.
|
||||
|
|
60
product-mini/platforms/zephyr/simple/Dockerfile
Normal file
60
product-mini/platforms/zephyr/simple/Dockerfile
Normal file
|
@ -0,0 +1,60 @@
|
|||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
FROM ubuntu:20.04
|
||||
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
ENV TZ=Asian/Shanghai
|
||||
|
||||
# Install dependencies for Zephyr and ESPRESSIF
|
||||
# hadolint ignore=DL3008
|
||||
RUN apt-get update && apt-get install -y git wget flex bison gperf python3 python3-pip python3-venv\
|
||||
python3-dev python3-setuptools python3-tk python3-wheel xz-utils file libpython3.8-dev \
|
||||
ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0 device-tree-compiler \
|
||||
make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 qemu udev --no-install-recommends \
|
||||
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install recent CMake version
|
||||
WORKDIR /tmp
|
||||
RUN mkdir /opt/cmake \
|
||||
&& wget --progress=dot:giga 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"
|
||||
|
||||
# Install the Zephyr Software Development Kit (SDK)
|
||||
WORKDIR /opt
|
||||
# hadolint ignore=DL4006
|
||||
RUN wget --progress=dot:giga https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.1/zephyr-sdk-0.16.1_linux-x86_64.tar.xz \
|
||||
&& wget --progress=dot:giga -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.1/sha256.sum | shasum --check --ignore-missing \
|
||||
&& tar xvf zephyr-sdk-0.16.1_linux-x86_64.tar.xz && rm zephyr-sdk-0.16.1_linux-x86_64.tar.xz
|
||||
|
||||
WORKDIR /opt/zephyr-sdk-0.16.1
|
||||
# hadolint ignore=DL4006
|
||||
RUN yes | ./setup.sh
|
||||
|
||||
# Get ESP-IDF
|
||||
RUN ln -s /usr/bin/python3 /usr/bin/python && mkdir -p ~/esp
|
||||
WORKDIR /root/esp
|
||||
RUN git clone https://github.com/espressif/esp-idf.git
|
||||
WORKDIR /root/esp/esp-idf
|
||||
RUN git checkout 03d4fa28694ee15ccfd5a97447575de2d1655026 \
|
||||
&& git submodule update --init --recursive
|
||||
# Set up the sep-idf tools
|
||||
RUN ./install.sh esp32 esp32c3
|
||||
|
||||
# Get Zephyr
|
||||
# hadolint ignore=DL3013
|
||||
RUN pip3 install --no-cache-dir west && west init -m https://github.com/zephyrproject-rtos/zephyr --mr v3.4.0 /root/zephyrproject
|
||||
|
||||
WORKDIR /root/zephyrproject
|
||||
RUN west update
|
||||
|
||||
WORKDIR /root/zephyrproject/zephyr
|
||||
RUN west zephyr-export && pip install --no-cache-dir -r ~/zephyrproject/zephyr/scripts/requirements.txt
|
||||
|
||||
# Git clone wamr
|
||||
WORKDIR /root
|
||||
RUN git clone https://github.com/bytecodealliance/wasm-micro-runtime.git
|
||||
|
||||
WORKDIR /root/wasm-micro-runtime/product-mini/platforms/zephyr/simple
|
||||
|
||||
ENV ZEPHYR_BASE="/root/zephyrproject/zephyr"
|
58
product-mini/platforms/zephyr/simple/Dockerfile.old
Normal file
58
product-mini/platforms/zephyr/simple/Dockerfile.old
Normal file
|
@ -0,0 +1,58 @@
|
|||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
FROM ubuntu:20.04
|
||||
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
ENV TZ=Asian/Shanghai
|
||||
|
||||
# Install dependencies for Zephyr and ESPRESSIF
|
||||
# hadolint ignore=DL3008
|
||||
RUN apt-get update && apt-get install -y git wget flex bison gperf python3 python3-pip python3-venv\
|
||||
python3-dev python3-setuptools python3-tk python3-wheel xz-utils file libpython3.8-dev \
|
||||
ninja-build ccache libffi-dev libssl-dev dfu-util libusb-1.0-0 device-tree-compiler \
|
||||
make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 qemu udev --no-install-recommends \
|
||||
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
# Install recent CMake version
|
||||
WORKDIR /tmp
|
||||
RUN mkdir /opt/cmake \
|
||||
&& wget --progress=dot:giga 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"
|
||||
|
||||
# Install the Zephyr Software Development Kit (SDK)
|
||||
WORKDIR /opt
|
||||
# hadolint ignore=DL4006
|
||||
RUN wget --progress=dot:giga https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.11.3/zephyr-sdk-0.11.3-setup.run \
|
||||
&& chmod +x ./zephyr-sdk-0.11.3-setup.run \
|
||||
&& ./zephyr-sdk-0.11.3-setup.run -- -d /opt/zephyr-sdk-0.11.3
|
||||
ENV ZEPHYR_TOOLCHAIN_VARIANT=zephyr
|
||||
ENV ZEPHYR_SDK_INSTALL_DIR=/opt/zephyr-sdk-0.11.3
|
||||
|
||||
# Get ESP-IDF
|
||||
RUN ln -s /usr/bin/python3 /usr/bin/python && mkdir -p ~/esp
|
||||
WORKDIR /root/esp
|
||||
RUN git clone https://github.com/espressif/esp-idf.git
|
||||
WORKDIR /root/esp/esp-idf
|
||||
RUN git checkout v4.0 \
|
||||
&& pip install --no-cache-doir virtualenv==16.7.12 \
|
||||
&& git submodule update --init --recursive \
|
||||
&& ./install.sh esp32 esp32c3
|
||||
|
||||
# Get Zephyr
|
||||
# hadolint ignore=DL3013
|
||||
RUN pip3 install --no-cache-dir west && west init -m https://github.com/zephyrproject-rtos/zephyr --mr v2.3.0 /root/zephyrproject
|
||||
|
||||
WORKDIR /root/zephyrproject
|
||||
RUN west update
|
||||
|
||||
WORKDIR /root/zephyrproject/zephyr
|
||||
RUN west zephyr-export && pip install --no-cache-dir -r ~/zephyrproject/zephyr/scripts/requirements.txt
|
||||
|
||||
# Git clone wamr
|
||||
WORKDIR /root
|
||||
RUN git clone https://github.com/bytecodealliance/wasm-micro-runtime.git
|
||||
|
||||
WORKDIR /root/wasm-micro-runtime/product-mini/platforms/zephyr/simple
|
||||
|
||||
ENV ZEPHYR_BASE="/root/zephyrproject/zephyr"
|
106
product-mini/platforms/zephyr/simple/README.md
Normal file
106
product-mini/platforms/zephyr/simple/README.md
Normal file
|
@ -0,0 +1,106 @@
|
|||
# How to use WAMR with Zephyr
|
||||
|
||||
## Build with Docker(recommend approach)
|
||||
|
||||
To have a quicker start, a Docker container of the Zephyr setup can be generated. The current docker image would be considerably large(~15GB), it would take some time to build it and enough disk space to store it.
|
||||
|
||||
### Build Docker images
|
||||
|
||||
```shell
|
||||
docker build -t wamr-zephyr .
|
||||
```
|
||||
|
||||
> PS: currently, the esp32 custom linker script only works with a lower version of Zephyr, if you want to use an esp32 board, you can build the Dockerfile with a lower version of Zephyr, Zephyr SDE, ESP-IDF. The old version of Docker image can also build other targets, but probably it's a better choice to use the new Dockerfile for other boards
|
||||
|
||||
```shell
|
||||
# If you want to build on esp32 platform
|
||||
docker build -f Dockerfile.old -t wamr-zephyr .
|
||||
```
|
||||
|
||||
### Run Docker images
|
||||
|
||||
Adopt the device or remove if not needed.
|
||||
|
||||
```shell
|
||||
docker run -ti --device=/dev/ttyUSB0 wamr-zephyr
|
||||
```
|
||||
|
||||
And then inside the docker container:
|
||||
|
||||
```shell
|
||||
# copy the corresponding board conf file to current directory
|
||||
cp boards/qemu_x86_nommu.conf prj.conf
|
||||
# then build
|
||||
./build_and_run.sh x86
|
||||
```
|
||||
|
||||
> PS: for boards esp32, need to configure some environment first
|
||||
|
||||
```shell
|
||||
# configure zephyr with espressif
|
||||
export ZEPHYR_TOOLCHAIN_VARIANT="espressif"
|
||||
export ESPRESSIF_TOOLCHAIN_PATH="/root/.espressif/tools/xtensa-esp32-elf/esp-2019r2-8.2.0/xtensa-esp32-elf/"
|
||||
export ESP_IDF_PATH="/root/esp/esp-idf"
|
||||
# copy the corresponding board conf file to current directory
|
||||
cp boards/esp32.conf prj.conf
|
||||
# then build
|
||||
./build_and_run.sh esp32
|
||||
```
|
||||
|
||||
## Build on local environment
|
||||
|
||||
### Dependencies installation
|
||||
|
||||
Following the Zephyr and Espressif official document:
|
||||
|
||||
1. Zephyr installation:
|
||||
|
||||
<https://docs.zephyrproject.org/latest/develop/getting_started/index.html>
|
||||
|
||||
2. ESP32 installation:
|
||||
|
||||
<https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/linux-macos-setup.html>
|
||||
|
||||
And setup the Zephyr for esp32:
|
||||
|
||||
<https://wiki.amarulasolutions.com/zephyr/esp32/esp32-setup.html>
|
||||
|
||||
Then Installing QEMU, for example, on Linux:
|
||||
|
||||
```shell
|
||||
sudo apt-get install qemu
|
||||
```
|
||||
|
||||
### Run the build script
|
||||
|
||||
Make sure you have the environment variable ready, you can use the command `env` to check:
|
||||
|
||||
```shell
|
||||
env
|
||||
```
|
||||
|
||||
```shell
|
||||
# export ZEPHYR_BASE if it's not present
|
||||
export ZEPHYR_BASE=~/zephyrproject/zephyr
|
||||
# and if you install zephyr in virtual environment rather than global
|
||||
source ~/zephyrproject/.venv/bin/activate
|
||||
```
|
||||
|
||||
For boards esp32, need to configure some extra environment first, check the following env variable whether in the env list, if not, add them like:
|
||||
|
||||
> Noted: The esp32 custom linker script doesn't work with the recent version of Zephyr, if you want to use it in the local environment, please install Zephyr 2.3.0 with the corresponding SDK, and ESP-IDF 4.0
|
||||
|
||||
```shell
|
||||
export ZEPHYR_TOOLCHAIN_VARIANT="espressif"
|
||||
export ESPRESSIF_TOOLCHAIN_PATH="~/.espressif/tools/xtensa-esp32-elf/esp-{the version you installed}/xtensa-esp32-elf/"
|
||||
export ESP_IDF_PATH="~/esp/esp-idf"
|
||||
```
|
||||
|
||||
Then you can run the build script:
|
||||
|
||||
```shell
|
||||
# copy the corresponding board conf file to current directory
|
||||
cp boards/qemu_x86_nommu.conf prj.conf
|
||||
# then build
|
||||
./build_and_run.sh x86
|
||||
```
|
|
@ -1,25 +0,0 @@
|
|||
# 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
|
||||
```
|
Loading…
Reference in New Issue
Block a user