mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-02-11 09:25:20 +00:00
Update Zephyr support to v3.5.0 and make instructions generic to boards (#2805)
Includes a number of updates to the Zephyr example, including removing a fair amount of stale configuration. This is part of moving towards supporting WAMR as a Zephyr module as described in #2782. Some functionality is removed as part of this diff (e.g. AOT XTENSA support), but it had become stale while not being actively maintained. It is anticipated that it (and AOT support for other platforms) will be added back, along with CI support for ensuring they do not become stale again. Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
This commit is contained in:
parent
f9e8b9535e
commit
2175910bac
|
@ -1,49 +1,32 @@
|
|||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
FROM ubuntu:20.04
|
||||
FROM ubuntu:22.04
|
||||
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
ENV TZ=Asian/Shanghai
|
||||
|
||||
# Install dependencies for Zephyr and ESPRESSIF
|
||||
# Install dependencies for Zephyr
|
||||
# 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 \
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends git cmake ninja-build gperf \
|
||||
ccache dfu-util device-tree-compiler wget \
|
||||
python3-dev python3-pip python3-setuptools python3-tk python3-wheel xz-utils file \
|
||||
make gcc gcc-multilib g++-multilib libsdl2-dev libmagic1 \
|
||||
&& 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
|
||||
RUN wget --progress=dot:giga https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.3/zephyr-sdk-0.16.3_linux-x86_64.tar.xz \
|
||||
&& wget --progress=dot:giga -O - https://github.com/zephyrproject-rtos/sdk-ng/releases/download/v0.16.3/sha256.sum | shasum --check --ignore-missing \
|
||||
&& tar xvf zephyr-sdk-0.16.3_linux-x86_64.tar.xz && rm zephyr-sdk-0.16.3_linux-x86_64.tar.xz
|
||||
|
||||
WORKDIR /opt/zephyr-sdk-0.16.1
|
||||
WORKDIR /opt/zephyr-sdk-0.16.3
|
||||
# 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
|
||||
RUN pip3 install --no-cache-dir west && west init -m https://github.com/zephyrproject-rtos/zephyr --mr v3.5.0 /root/zephyrproject
|
||||
|
||||
WORKDIR /root/zephyrproject
|
||||
RUN west update
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
# 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-dir 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"
|
|
@ -1,106 +1,108 @@
|
|||
# How to use WAMR with Zephyr
|
||||
|
||||
## Build with Docker(recommend approach)
|
||||
[Zephyr](https://www.zephyrproject.org/) is an open source real-time operating
|
||||
system (RTOS) with a focus on security and broad hardware support. WAMR is
|
||||
compatible with Zephyr via the [Zephyr WAMR
|
||||
port](../../../../core/shared/platform/zephyr).
|
||||
|
||||
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.
|
||||
## Setup
|
||||
|
||||
### Build Docker images
|
||||
Using WAMR with Zephyr can be accomplished by either using the provided Docker
|
||||
image, or by installing Zephyr locally. Both approaches are described below.
|
||||
|
||||
### Docker
|
||||
|
||||
The provided Docker image sets up Zephyr and its dependencies for all
|
||||
architectures, meaning that you are ready to build for any [supported
|
||||
board](https://docs.zephyrproject.org/latest/boards/index.html). This comes at
|
||||
the expense of building a rather large image, which both can take a long time to
|
||||
build and uses up a large amount of storage (~15 GB).
|
||||
|
||||
Execute the following command to build the Docker image. This may take an
|
||||
extended period of time to complete.
|
||||
|
||||
```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
|
||||
Execute the following command to run the image built in the previous step. If
|
||||
you are planning to flash a device after building, make sure to specify it with
|
||||
[`--device`](https://docs.docker.com/engine/reference/run/#runtime-privilege-and-linux-capabilities).
|
||||
|
||||
```shell
|
||||
# If you want to build on esp32 platform
|
||||
docker build -f Dockerfile.old -t wamr-zephyr .
|
||||
docker run -it --rm --device=/dev/ttyUSB0 wamr-zephyr
|
||||
```
|
||||
|
||||
### Run Docker images
|
||||
### Local Environment
|
||||
|
||||
Adopt the device or remove if not needed.
|
||||
Zephyr can also be setup locally to enable building this sample application.
|
||||
This allows you have have more control over what modules and tools are
|
||||
installed, which can drastically reduce the storage required compared to the
|
||||
Docker image.
|
||||
|
||||
Follow the steps provided in the [Zephyr Getting Started
|
||||
guide](https://docs.zephyrproject.org/latest/develop/getting_started/index.html)
|
||||
to setup for local development.
|
||||
|
||||
## Building for a Specific Board
|
||||
|
||||
With an environment setup either locally or in a Docker container, you can build
|
||||
for a Zephyr suppported board using
|
||||
[`west`](https://docs.zephyrproject.org/latest/develop/west/index.html). There
|
||||
are already [configuaration files](./boards) for a few boards in this sample.
|
||||
However, if you are using a new board, you will need to add your own file for
|
||||
the board, or define configuration in the [`prj.conf](./prj.conf). After doing
|
||||
so, use the following command with your board identifier to build the sample
|
||||
application.
|
||||
|
||||
```shell
|
||||
docker run -ti --device=/dev/ttyUSB0 wamr-zephyr
|
||||
west build . -b <board-identifier> --pristine -- -DWAMR_BUILD_TARGET=<wamr-arch>
|
||||
```
|
||||
|
||||
And then inside the docker container:
|
||||
The `<board-identifier>` can be found in the Zephyr supported boards
|
||||
documentation. It must also be used as the name of the board configuration file.
|
||||
You must define the architecture for WAMR to target with `WAMR_BUILD_TARGET`.
|
||||
The list of supported architectures can be found in the main project
|
||||
[README.md](../../../../README.md#supported-architectures-and-platforms).
|
||||
|
||||
It may be necessary to define additional symbols for some boards. For example,
|
||||
WAMR AOT execution may not be supported on all architectures. It and other
|
||||
options can be disabled by modifying the [CMakeLists.txt](./CMakeLists.txt)
|
||||
file, or by passing additional arguments at build (e.g. `-DWAMR_BUILD_AOT=0`).
|
||||
|
||||
### Example Targets
|
||||
|
||||
[ESP32-C3](https://docs.zephyrproject.org/latest/boards/riscv/esp32c3_devkitm/doc/index.html)
|
||||
is a 32-bit RISC-V target that does not currently support AOT.
|
||||
|
||||
```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
|
||||
west build . -b esp32c3_devkitm -p always -- -DWAMR_BUILD_TARGET=RISCV32_ILP32 -DWAMR_BUILD_AOT=0
|
||||
```
|
||||
|
||||
> PS: for boards esp32, need to configure some environment first
|
||||
[ARM Cortex-A53 QEMU
|
||||
(ARM)](https://docs.zephyrproject.org/latest/boards/arm64/qemu_cortex_a53/doc/index.html)
|
||||
is a 64-bit ARM target for emulating the Cortex-A53 platform.
|
||||
|
||||
```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
|
||||
west build . -b qemu_cortex_a53 -p always -- -DWAMR_BUILD_TARGET=AARCH64
|
||||
```
|
||||
|
||||
## Build on local environment
|
||||
|
||||
### Dependencies installation
|
||||
## Flashing or Running Image
|
||||
|
||||
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:
|
||||
The board can be flashed with the built image with the following command.
|
||||
|
||||
```shell
|
||||
sudo apt-get install qemu
|
||||
west flash
|
||||
```
|
||||
|
||||
### Run the build script
|
||||
`west` will automatically identify the board if it is connected to the host
|
||||
machine.
|
||||
|
||||
Make sure you have the environment variable ready, you can use the command `env` to check:
|
||||
When using emulated targets, such as those that utilize QEMU, there is no
|
||||
physical device to flash, but `west` can be used to run the image under
|
||||
emulation.
|
||||
|
||||
```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
|
||||
west build -t run
|
||||
```
|
||||
|
|
|
@ -1,8 +0,0 @@
|
|||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
CONFIG_STACK_SENTINEL=y
|
||||
CONFIG_PRINTK=y
|
||||
CONFIG_LOG=y
|
||||
CONFIG_HAVE_CUSTOM_LINKER_SCRIPT=y
|
||||
CONFIG_CUSTOM_LINKER_SCRIPT="esp32_custom_linker.ld"
|
|
@ -2,6 +2,3 @@
|
|||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
CONFIG_ARM_MPU=y
|
||||
CONFIG_STACK_SENTINEL=y
|
||||
CONFIG_PRINTK=y
|
||||
CONFIG_LOG=y
|
|
@ -2,6 +2,3 @@
|
|||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
CONFIG_ARM_MMU=n
|
||||
CONFIG_STACK_SENTINEL=y
|
||||
CONFIG_PRINTK=y
|
||||
CONFIG_LOG=y
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
CONFIG_STACK_SENTINEL=y
|
||||
CONFIG_PRINTK=y
|
||||
CONFIG_LOG=n
|
|
@ -1,6 +0,0 @@
|
|||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
CONFIG_STACK_SENTINEL=y
|
||||
CONFIG_PRINTK=y
|
||||
CONFIG_LOG=n
|
|
@ -1,6 +0,0 @@
|
|||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
CONFIG_STACK_SENTINEL=y
|
||||
CONFIG_PRINTK=y
|
||||
CONFIG_LOG=y
|
|
@ -1,6 +0,0 @@
|
|||
# Copyright (C) 2019 Intel Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
|
||||
CONFIG_STACK_SENTINEL=y
|
||||
CONFIG_PRINTK=y
|
||||
CONFIG_LOG=y
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
X86_TARGET="x86"
|
||||
STM32_TARGET="stm32"
|
||||
ESP32_TARGET="esp32"
|
||||
ESP32C3_TARGET="esp32c3"
|
||||
PARTICLE_ARGON_TARGET="particle_argon"
|
||||
QEMU_CORTEX_A53="qemu_cortex_a53"
|
||||
|
@ -17,11 +16,10 @@ QEMU_ARC_TARGET="qemu_arc"
|
|||
usage ()
|
||||
{
|
||||
echo "USAGE:"
|
||||
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 "$0 $X86_TARGET|$STM32_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"
|
||||
|
@ -51,27 +49,11 @@ case $TARGET in
|
|||
-DWAMR_BUILD_TARGET=THUMBV7
|
||||
west flash
|
||||
;;
|
||||
$ESP32_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 esp32 \
|
||||
. -p always -- \
|
||||
-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
|
||||
-DWAMR_BUILD_TARGET=RISCV32_ILP32 \
|
||||
-DWAMR_BUILD_AOT=0
|
||||
# west flash will discover the device
|
||||
west flash
|
||||
;;
|
||||
|
|
|
@ -1,274 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2016 Cadence Design Systems, Inc.
|
||||
* Copyright (c) 2017 Intel Corporation
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Linker command/script file
|
||||
*
|
||||
* Linker script for the Xtensa platform.
|
||||
*/
|
||||
|
||||
#include <devicetree.h>
|
||||
#include <autoconf.h>
|
||||
#include <linker/sections.h>
|
||||
#include <linker/linker-defs.h>
|
||||
#include <linker/linker-tool.h>
|
||||
|
||||
#define RAMABLE_REGION dram0_0_seg :dram0_0_phdr
|
||||
#define RAMABLE_REGION1 dram0_1_seg :dram0_0_phdr
|
||||
#define ROMABLE_REGION iram0_0_seg :iram0_0_phdr
|
||||
|
||||
PROVIDE ( __stack = 0x3ffe3f20 );
|
||||
|
||||
PROVIDE ( esp32_rom_uart_tx_one_char = 0x40009200 );
|
||||
PROVIDE ( esp32_rom_uart_rx_one_char = 0x400092d0 );
|
||||
PROVIDE ( esp32_rom_uart_attach = 0x40008fd0 );
|
||||
PROVIDE ( esp32_rom_intr_matrix_set = 0x4000681c );
|
||||
PROVIDE ( esp32_rom_gpio_matrix_in = 0x40009edc );
|
||||
PROVIDE ( esp32_rom_gpio_matrix_out = 0x40009f0c );
|
||||
PROVIDE ( esp32_rom_Cache_Flush = 0x40009a14 );
|
||||
PROVIDE ( esp32_rom_Cache_Read_Enable = 0x40009a84 );
|
||||
PROVIDE ( esp32_rom_ets_set_appcpu_boot_addr = 0x4000689c );
|
||||
|
||||
MEMORY
|
||||
{
|
||||
iram0_0_seg(RX): org = 0x40080000, len = 0x20000
|
||||
iram0_2_seg(RX): org = 0x400D0018, len = 0x330000
|
||||
dram0_0_seg(RW): org = 0x3FFB0000, len = 0x30000
|
||||
dram0_1_seg(RWX):org = 0x400A0000, len = 0x20000
|
||||
drom0_0_seg(R): org = 0x3F400010, len = 0x800000
|
||||
rtc_iram_seg(RWX): org = 0x400C0000, len = 0x2000
|
||||
rtc_slow_seg(RW): org = 0x50000000, len = 0x1000
|
||||
#ifdef CONFIG_GEN_ISR_TABLES
|
||||
IDT_LIST(RW): org = 0x3ebfe010, len = 0x2000
|
||||
#endif
|
||||
}
|
||||
|
||||
PHDRS
|
||||
{
|
||||
iram0_0_phdr PT_LOAD;
|
||||
dram0_0_phdr PT_LOAD;
|
||||
}
|
||||
|
||||
/* Default entry point: */
|
||||
PROVIDE ( _ResetVector = 0x40000400 );
|
||||
ENTRY(CONFIG_KERNEL_ENTRY)
|
||||
|
||||
_rom_store_table = 0;
|
||||
|
||||
PROVIDE(_memmap_vecbase_reset = 0x40000450);
|
||||
PROVIDE(_memmap_reset_vector = 0x40000400);
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
|
||||
#include <linker/rel-sections.ld>
|
||||
|
||||
/* RTC fast memory holds RTC wake stub code,
|
||||
including from any source file named rtc_wake_stub*.c
|
||||
*/
|
||||
.rtc.text :
|
||||
{
|
||||
. = ALIGN(4);
|
||||
*(.rtc.literal .rtc.text)
|
||||
*rtc_wake_stub*.o(.literal .text .literal.* .text.*)
|
||||
} >rtc_iram_seg
|
||||
|
||||
/* RTC slow memory holds RTC wake stub
|
||||
data/rodata, including from any source file
|
||||
named rtc_wake_stub*.c
|
||||
*/
|
||||
.rtc.data :
|
||||
{
|
||||
_rtc_data_start = ABSOLUTE(.);
|
||||
*(.rtc.data)
|
||||
*(.rtc.rodata)
|
||||
*rtc_wake_stub*.o(.data .rodata .data.* .rodata.* .bss .bss.*)
|
||||
_rtc_data_end = ABSOLUTE(.);
|
||||
} > rtc_slow_seg
|
||||
|
||||
/* RTC bss, from any source file named rtc_wake_stub*.c */
|
||||
.rtc.bss (NOLOAD) :
|
||||
{
|
||||
_rtc_bss_start = ABSOLUTE(.);
|
||||
*rtc_wake_stub*.o(.bss .bss.*)
|
||||
*rtc_wake_stub*.o(COMMON)
|
||||
_rtc_bss_end = ABSOLUTE(.);
|
||||
} > rtc_slow_seg
|
||||
|
||||
/* Send .iram0 code to iram */
|
||||
.iram0.vectors : ALIGN(4)
|
||||
{
|
||||
/* Vectors go to IRAM */
|
||||
_init_start = ABSOLUTE(.);
|
||||
/* Vectors according to builds/RF-2015.2-win32/esp108_v1_2_s5_512int_2/config.html */
|
||||
. = 0x0;
|
||||
KEEP(*(.WindowVectors.text));
|
||||
. = 0x180;
|
||||
KEEP(*(.Level2InterruptVector.text));
|
||||
. = 0x1c0;
|
||||
KEEP(*(.Level3InterruptVector.text));
|
||||
. = 0x200;
|
||||
KEEP(*(.Level4InterruptVector.text));
|
||||
. = 0x240;
|
||||
KEEP(*(.Level5InterruptVector.text));
|
||||
. = 0x280;
|
||||
KEEP(*(.DebugExceptionVector.text));
|
||||
. = 0x2c0;
|
||||
KEEP(*(.NMIExceptionVector.text));
|
||||
. = 0x300;
|
||||
KEEP(*(.KernelExceptionVector.text));
|
||||
. = 0x340;
|
||||
KEEP(*(.UserExceptionVector.text));
|
||||
. = 0x3C0;
|
||||
KEEP(*(.DoubleExceptionVector.text));
|
||||
. = 0x400;
|
||||
*(.*Vector.literal)
|
||||
|
||||
*(.UserEnter.literal);
|
||||
*(.UserEnter.text);
|
||||
. = ALIGN (16);
|
||||
*(.entry.text)
|
||||
*(.init.literal)
|
||||
*(.init)
|
||||
_init_end = ABSOLUTE(.);
|
||||
|
||||
/* This goes here, not at top of linker script, so addr2line finds it last,
|
||||
and uses it in preference to the first symbol in IRAM */
|
||||
_iram_start = ABSOLUTE(0);
|
||||
} GROUP_LINK_IN(ROMABLE_REGION)
|
||||
|
||||
#include <linker/common-ram.ld>
|
||||
#include <linker/common-rom.ld>
|
||||
|
||||
SECTION_PROLOGUE(_TEXT_SECTION_NAME, , ALIGN(4))
|
||||
{
|
||||
/* Code marked as running out of IRAM */
|
||||
_iram_text_start = ABSOLUTE(.);
|
||||
*(.iram1 .iram1.*)
|
||||
*(.iram0.literal .iram.literal .iram.text.literal .iram0.text .iram.text)
|
||||
*(.literal .text .literal.* .text.*)
|
||||
_iram_text_end = ABSOLUTE(.);
|
||||
} GROUP_LINK_IN(ROMABLE_REGION)
|
||||
|
||||
.dram0.text :
|
||||
{
|
||||
_data_start = ABSOLUTE(.);
|
||||
*(.aot_code_buf)
|
||||
_data_end = ABSOLUTE(.);
|
||||
. = ALIGN(4);
|
||||
} GROUP_LINK_IN(RAMABLE_REGION1)
|
||||
|
||||
|
||||
.dram0.data :
|
||||
{
|
||||
_data_start = ABSOLUTE(.);
|
||||
*(.data)
|
||||
*(.data.*)
|
||||
*(.gnu.linkonce.d.*)
|
||||
*(.data1)
|
||||
*(.sdata)
|
||||
*(.sdata.*)
|
||||
*(.gnu.linkonce.s.*)
|
||||
*(.sdata2)
|
||||
*(.sdata2.*)
|
||||
*(.gnu.linkonce.s2.*)
|
||||
KEEP(*(.jcr))
|
||||
*(.dram1 .dram1.*)
|
||||
_data_end = ABSOLUTE(.);
|
||||
. = ALIGN(4);
|
||||
} GROUP_LINK_IN(RAMABLE_REGION)
|
||||
|
||||
SECTION_PROLOGUE(_RODATA_SECTION_NAME,,ALIGN(4))
|
||||
{
|
||||
_rodata_start = ABSOLUTE(.);
|
||||
*(.rodata)
|
||||
*(.rodata.*)
|
||||
*(.gnu.linkonce.r.*)
|
||||
*(.rodata1)
|
||||
__XT_EXCEPTION_TABLE__ = ABSOLUTE(.);
|
||||
KEEP (*(.xt_except_table))
|
||||
KEEP (*(.gcc_except_table .gcc_except_table.*))
|
||||
*(.gnu.linkonce.e.*)
|
||||
*(.gnu.version_r)
|
||||
KEEP (*(.eh_frame))
|
||||
/* C++ constructor and destructor tables, properly ordered: */
|
||||
KEEP (*crtbegin.o(.ctors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors))
|
||||
KEEP (*(SORT(.ctors.*)))
|
||||
KEEP (*(.ctors))
|
||||
KEEP (*crtbegin.o(.dtors))
|
||||
KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors))
|
||||
KEEP (*(SORT(.dtors.*)))
|
||||
KEEP (*(.dtors))
|
||||
/* C++ exception handlers table: */
|
||||
__XT_EXCEPTION_DESCS__ = ABSOLUTE(.);
|
||||
*(.xt_except_desc)
|
||||
*(.gnu.linkonce.h.*)
|
||||
__XT_EXCEPTION_DESCS_END__ = ABSOLUTE(.);
|
||||
*(.xt_except_desc_end)
|
||||
*(.dynamic)
|
||||
*(.gnu.version_d)
|
||||
. = ALIGN(4); /* this table MUST be 4-byte aligned */
|
||||
_rodata_end = ABSOLUTE(.);
|
||||
} GROUP_LINK_IN(RAMABLE_REGION)
|
||||
|
||||
|
||||
/* Shared RAM */
|
||||
SECTION_DATA_PROLOGUE(_BSS_SECTION_NAME,(NOLOAD),)
|
||||
{
|
||||
. = ALIGN (8);
|
||||
_bss_start = ABSOLUTE(.);
|
||||
*(.dynsbss)
|
||||
*(.sbss)
|
||||
*(.sbss.*)
|
||||
*(.gnu.linkonce.sb.*)
|
||||
*(.scommon)
|
||||
*(.sbss2)
|
||||
*(.sbss2.*)
|
||||
*(.gnu.linkonce.sb2.*)
|
||||
*(.dynbss)
|
||||
*(.bss)
|
||||
*(.bss.*)
|
||||
*(.share.mem)
|
||||
*(.gnu.linkonce.b.*)
|
||||
*(COMMON)
|
||||
. = ALIGN (8);
|
||||
_bss_end = ABSOLUTE(.);
|
||||
} GROUP_LINK_IN(RAMABLE_REGION)
|
||||
|
||||
|
||||
SECTION_DATA_PROLOGUE(_APP_NOINIT_SECTION_NAME, (NOLOAD),)
|
||||
{
|
||||
. = ALIGN (8);
|
||||
*(.app_noinit)
|
||||
*("app_noinit.*")
|
||||
. = ALIGN (8);
|
||||
_app_end = ABSOLUTE(.);
|
||||
} GROUP_LINK_IN(RAMABLE_REGION)
|
||||
|
||||
|
||||
SECTION_DATA_PROLOGUE(_NOINIT_SECTION_NAME, (NOLOAD),)
|
||||
{
|
||||
. = ALIGN (8);
|
||||
*(.noinit)
|
||||
*(".noinit.*")
|
||||
. = ALIGN (8);
|
||||
_heap_start = ABSOLUTE(.);
|
||||
} GROUP_LINK_IN(RAMABLE_REGION)
|
||||
|
||||
#ifdef CONFIG_GEN_ISR_TABLES
|
||||
#include <linker/intlist.ld>
|
||||
#endif
|
||||
|
||||
#include <linker/debug-sections.ld>
|
||||
|
||||
SECTION_PROLOGUE(.xtensa.info, 0,)
|
||||
{
|
||||
*(.xtensa.info)
|
||||
}
|
||||
|
||||
}
|
|
@ -104,56 +104,6 @@ app_instance_main(wasm_module_inst_t module_inst)
|
|||
static char global_heap_buf[CONFIG_GLOBAL_HEAP_BUF_SIZE] = { 0 };
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_BOARD_ESP32
|
||||
#include "mem_alloc.h"
|
||||
/*
|
||||
esp32_technical_reference_manual:
|
||||
"
|
||||
The capacity of Internal SRAM 1 is 128 KB. Either CPU can read and write this
|
||||
memory at addresses 0x3FFE_0000 ~ 0x3FFF_FFFF of the data bus, and also at
|
||||
addresses 0x400A_0000 ~ 0x400B_FFFF of the instruction bus.
|
||||
"
|
||||
|
||||
The custom linker script defines dram0_1_seg and map it to 0x400A_0000 ~
|
||||
0x400B_FFFF for instruction bus access. Here we define the buffer that will be
|
||||
placed to dram0_1_seg.
|
||||
*/
|
||||
static char esp32_executable_memory_buf[100 * 1024]
|
||||
__attribute__((section(".aot_code_buf"))) = { 0 };
|
||||
|
||||
/* the poll allocator for executable memory */
|
||||
static mem_allocator_t esp32_exec_mem_pool_allocator;
|
||||
|
||||
static int
|
||||
esp32_exec_mem_init()
|
||||
{
|
||||
if (!(esp32_exec_mem_pool_allocator =
|
||||
mem_allocator_create(esp32_executable_memory_buf,
|
||||
sizeof(esp32_executable_memory_buf))))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
esp32_exec_mem_destroy()
|
||||
{
|
||||
mem_allocator_destroy(esp32_exec_mem_pool_allocator);
|
||||
}
|
||||
|
||||
static void *
|
||||
esp32_exec_mem_alloc(unsigned int size)
|
||||
{
|
||||
return mem_allocator_malloc(esp32_exec_mem_pool_allocator, size);
|
||||
}
|
||||
|
||||
static void
|
||||
esp32_exec_mem_free(void *addr)
|
||||
{
|
||||
mem_allocator_free(esp32_exec_mem_pool_allocator, addr);
|
||||
}
|
||||
#endif /* end of #ifdef CONFIG_BOARD_ESP32 */
|
||||
|
||||
void
|
||||
iwasm_main(void *arg1, void *arg2, void *arg3)
|
||||
{
|
||||
|
@ -189,16 +139,6 @@ iwasm_main(void *arg1, void *arg2, void *arg3)
|
|||
return;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BOARD_ESP32
|
||||
/* Initialize executable memory */
|
||||
if (esp32_exec_mem_init() != 0) {
|
||||
printf("Init executable memory failed.\n");
|
||||
goto fail1;
|
||||
}
|
||||
/* Set hook functions for executable memory management */
|
||||
set_exec_mem_alloc_func(esp32_exec_mem_alloc, esp32_exec_mem_free);
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_LOG != 0
|
||||
bh_log_set_verbose_level(log_verbose_level);
|
||||
#endif
|
||||
|
@ -211,11 +151,7 @@ iwasm_main(void *arg1, void *arg2, void *arg3)
|
|||
if (!(wasm_module = wasm_runtime_load(wasm_file_buf, wasm_file_size,
|
||||
error_buf, sizeof(error_buf)))) {
|
||||
printf("%s\n", error_buf);
|
||||
#ifdef CONFIG_BOARD_ESP32
|
||||
goto fail1_1;
|
||||
#else
|
||||
goto fail1;
|
||||
#endif
|
||||
}
|
||||
|
||||
/* instantiate the module */
|
||||
|
@ -236,12 +172,6 @@ fail2:
|
|||
/* unload the module */
|
||||
wasm_runtime_unload(wasm_module);
|
||||
|
||||
#ifdef CONFIG_BOARD_ESP32
|
||||
fail1_1:
|
||||
/* destroy executable memory */
|
||||
esp32_exec_mem_destroy();
|
||||
#endif
|
||||
|
||||
fail1:
|
||||
/* destroy runtime environment */
|
||||
wasm_runtime_destroy();
|
||||
|
|
Loading…
Reference in New Issue
Block a user