zephyr编译环境搭建
本文记录了在Ubuntu 16.04 64bit下安装配置zephy编译环境并编译esp32的过程
Zephyr环境安装 链接到标题
下载代码到~/work/project/zephyr/ 链接到标题
cd ~/work/project/
git clone https://github.com/zephyrproject-rtos/zephyr.git
设置环境 链接到标题
安装软件包 链接到标题
sudo apt-get install --no-install-recommends git cmake ninja-build gperf \
ccache doxygen dfu-util device-tree-compiler \
python3-ply python3-pip python3-setuptools xz-utils file make gcc-multilib \
autoconf automake libtool
安装Zephyr依赖包 链接到标题
cd ~/work/project/zephyr
pip3 install --user -r scripts/requirements.txt
如果安装的是python2需要使用下面命令
pip2 install --user -r scripts/py2-requirements.txt
用“cmake –version”确认cmake版本是3.8.2以上,如果不是安装3.8.2
mkdir $HOME/cmake && cd $HOME/cmake
wget https://cmake.org/files/v3.8/cmake-3.8.2-Linux-x86_64.sh
yes | sh cmake-3.8.2-Linux-x86_64.sh | cat
echo "export PATH=$PWD/cmake-3.8.2-Linux-x86_64/bin:\$PATH" >> $HOME/.zephyrrc
安装Zephyr SDK 链接到标题
- 下载SDK 在https://github.com/zephyrproject-rtos/meta-zephyr-sdk/releases 选择最新的SDK下载,目前是zephyr-sdk-0.9.2-setup.run
- 安装SDK
sh zephyr-sdk-0.9.2-setup.run
安装时将SDK安装在~/zephyr-sdk/,编辑~/.zephyrrc将加入环境变量
#export ZEPHYR_GCC_VARIANT=zephyr -->这个环境变量不能设置,会导致esp32编译时使用xtensa模拟器的toolchain,详见https://github.com/zephyrproject-rtos/zephyr/issues/6439
export ZEPHYR_SDK_INSTALL_DIR=/home/frank/zephyr-sdk
ESP32 环境安装 链接到标题
安装ESP32 toolchain 链接到标题
安装依赖包 链接到标题
sudo apt-get install git wget make libncurses-dev flex bison gperf python python-serial
下载&安装tool chain 链接到标题
通过https://dl.espressif.com/dl/xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz 下载toolchain,并安装在~/opt/esp/下
mkdir -p ~/opt/esp
cd ~/opt/esp
tar -xzf ~/Downloads/xtensa-esp32-elf-linux64-1.22.0-80-g6c4433a-5.2.0.tar.gz
安装ESP32 SDK 链接到标题
cd ~/opt/esp
git clone --recursive https://github.com/espressif/esp-idf.git
cd ~/opt/esp/esp-idf
git checkout dc8c33892e0 #esp SDK最新的版本可能会删除zephyr的依赖文件,因此checkout到指定版本
配置ESP32环境 链接到标题
建立文件~/opt/esp/zephyr-esp-setup.sh来配置ESP32用的环境变量
export ZEPHYR_TOOLCHAIN_VARIANT="espressif"
export ESP_IDF_PATH="/home/frank/opt/esp/esp-idf"
export ESPRESSIF_TOOLCHAIN_PATH="/home/frank/opt/esp/xtensa-esp32-elf/"
编译Zephyr for ESP32 链接到标题
设置环境变量 链接到标题
cd ~/work/project/zephyr
source ./zephyr-env.sh
source ~/opt/esp/zephyr-esp-setup.sh
编译hello world 链接到标题
cd samples/hello_world/
mkdir esp32_build
cmake -GNinja -DBOARD=esp32 ..
ninja
最后产出的文件在esp32_build/zephyr下
-rwxrwxr-x 1 frank frank 862741 3月 11 22:05 zephyr.bin
-rwxrwxr-x 1 frank frank 253960 3月 11 22:05 zephyr.elf
-rw-rw-r-- 1 frank frank 276611 3月 11 22:05 zephyr.lst
-rw-rw-r-- 1 frank frank 140256 3月 11 22:05 zephyr.map
-rwxrwxr-x 1 frank frank 20905792 3月 11 22:05 zephyr_prebuilt.elf
-rw-rw-r-- 1 frank frank 3527 3月 11 22:05 zephyr.stat
参考 链接到标题
http://docs.zephyrproject.org/getting_started/getting_started.html http://docs.zephyrproject.org/boards/xtensa/esp32/doc/esp32.html https://esp-idf.readthedocs.io/en/latest/get-started/linux-setup.html https://esp-idf.readthedocs.io/en/latest/get-started/index.html#get-started-get-esp-idf