文章目录
- 官方文档
- 首先更新系统
- 安装依赖包
- 安装 cmake
- 安装 device-tree-compiler
- 更新 setuptools
- 忽略 SDK 的安装
- 忽略 west 的安装
- 安装 python 依赖包
- 配置编译器
- make 编译 hello world
- ninja 编译 hello world
mingdu.zheng at gmail dot com
官方文档
基本上参照官方文档就可以了,有几个依赖包的版本不一致,需要特别处理一下。
https://docs.zephyrproject.org/1.14.0/getting_started/index.html
首先更新系统
不清楚不更新会怎样,还是按照要求更新一下吧。
sudo apt-get update
sudo apt-get upgrade
安装依赖包
注意: 官方文档包含了 cmake 和 device-tree-compiler,但是 Ubuntu 16.04 默认安装的 cmake 和 device-tree-compiler 版本过低,这里要忽略 cmake 和 device-tree-compiler 的安装,后续补装。
sudo apt-get install --no-install-recommends git ninja-build gperf ccache dfu-util wget \
python3-pip python3-setuptools python3-wheel xz-utils file make gcc gcc-multilib
安装 cmake
pip3 install --user cmake
安装 device-tree-compiler
默认安装的 device-tree-compiler 版本是 1.4.0,但是 zephyr-1.14 需要 1.4.6 及以上版本。
wget https://mirrors.tuna.tsinghua.edu.cn/ubuntu/pool/main/d/device-tree-compiler/device-tree-compiler_1.4.7-3_amd64.deb
sudo dpkg -i device-tree-compiler_1.4.7-3_amd64.deb
更新 setuptools
zephyr-1.14 要求 setuptools 版本在 40.0 及以上,更新 setuptools。
pip3 install setuptools
忽略 SDK 的安装
下载 SDK 实在太慢,自己下载 ARM GCC 吧。
- GNU-RM Downloads
忽略 west 的安装
不要引入太多的自动化,自动化会隐藏一些细节,我希望把这些细节搞清楚,搞清楚了以后再自动化。
安装 python 依赖包
在这步之前,一定要把 setuptools 更新好,pyocd 需要 setuptools 在 40.0 及以上版本。
pip3 install --user -r zephyr/scripts/requirements.txt
配置编译器
echo "export ZEPHYR_TOOLCHAIN_VARIANT=gnuarmemb" > ~/.zephyrrc
echo "export GNUARMEMB_TOOLCHAIN_PATH=\"/home/user/gcc-arm-none-eabi-5_4-2016q3\"" >> ~/.zephyrrc
make 编译 hello world
首先配置一下环境,zephyr-env.sh 在 zephyr 源代码根目录下,注意路径问题。默认情况下,cmake 生成 makefile 。
source zephyr-env.sh
然后开始编译,采用 make 编译。
cd samples/hello_world
mkdir build && cd build
cmake -DBOARD=reel_board ..
make
ninja 编译 hello world
首先配置一下环境,zephyr-env.sh 在 zephyr 源代码根目录下,注意路径问题。通过参数 -GNinja 告知 cmake 生成 ninja 文件。
source zephyr-env.sh
然后开始编译,采用 make 编译。
cd samples/hello_world
mkdir build && cd build
cmake -GNinja -DBOARD=reel_board ..
ninja