1. 开发环境搭建
本次使用官方FUSDK(GitHub:sifive/freedom-u-sdk: Freedom Unleashed Software Development Kit (github.com))进行开发,我们希望能重新编译包括bootloader、kernel在内的各个模块,并将其移植到开发板上运行。
基本配置:建议使用Ubuntu18.04以上系统作为Host,并拥有基本的ssh网络通路
Tips:可以尝试如下命令检查网络连接状况:
# 检查github的ssh连接状态 ssh -T git@github.com # 检查一些远程代码仓库的ssh连接状态 git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
如果存在Timeout的情况,请优先处理网络状况问题,由于各企业、学校、单位的网络环境、代理设置和防火墙配置不同,可能存在某些仓库无法自动下载的问题。
由于我司设置了外网代理,所以这里先进行代理的设置。
# 设置全局代理环境变量
export http_proxy=[公司代理:端口]
export https_proxy=[公司代理:端口]
# 下载包转发工具和代理连接工具
sudo apt-get install connect-proxy socat
# 编辑 ~/.ssh/config
# 增添一条新规则到ssh配置 (.ssh/config):
host !*.[公司内网].com
ProxyCommand connect-proxy -s %h %p
# 编辑一个新脚本用来执行ssh代理
# 脚本位置可自定
vim /usr/bin/git_proxy_command
# 复制如下代码到脚本:
#!/bin/sh
# This setting is for git using proxy
_proxy=[公司代理].com
_proxyport=[端口号]
exec socat stdio SOCKS:$_proxy:$1:$2
# Change mode of this script:
sudo chmod +x /usr/bin/git_proxy_command
# 设置gitconfig
git config –global core.gitproxy “/usr/bin/git_proxy_command”
# 或编辑 ~/.gitconfig:
# 增加以下项
[core]
gitproxy = /usr/bin/git_proxy_command
下面我们按照README.md来进行接下来的配置
1. 安装repo
mkdir ~/bin
export PATH=~/bin:$PATH
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
2. 创建工作区
mkdir riscv-sifive && cd riscv-sifive
repo init -u git://github.com/sifive/meta-sifive -b 2021.08 -m tools/manifests/sifive.xml
repo sync
Tips: 此处如果git://无法下载可以改为https://重试,由于网络环境不同,有些环境ssh协议使用github并不方便
repo sync成功后,我们可以看到OpenEmbedded的各种仓库:
3. 创建构造
需要利用bitbake去构造我们需要的build文件夹
bitbake是python开发的自动化构建脚本,可执行程序位于
我们首先把它和它的依赖库加入到环境变量中
export PATH=~/riscv-sifive/openembedded-core/bitbake/bin:$PATH
export PYTHONPATH=~/riscv-sifive/openembedded-core/bitbake/lib
然后构建sifive build文件夹:
./meta-sifive/setup.sh
进入build文件夹
执行:
PARALLEL_MAKE="-j 4" BB_NUMBER_THREADS=4 MACHINE=unmatched bitbake demo-coreip-xfce4
即开始构建我们所需要的一切。
其中我们可以指定PARALLEL_MAKE和BB_NUMBER_THREADS来确定构建时创建的任务和线程数,根据机器的性能自行确定。这些参数也可以写入conf/local.conf来设置。
我们可以在bitbake后加 -vD 参数来获取编译过程的DEBUG信息,-vDDD可以获取更多信息:)
关于bitbake,可参考:
A practical guide to BitBake (a4z.gitlab.io)
4. 一些小坑
下面是我遇到的一些问题,在此做个记录。
(1) 无法连接www.example.com
bitbake 在构建开始的时候会通过连接www.example.com来进行网络测试,但是有些网络限制的环境无法通过此过程,导致Timeout,可以通过在conf/local.conf里加入如下变量:
CONNECTIVITY_CHECK_URIS = "www.baidu.com" 或直接
CONNECTIVITY_CHECK_URIS = "" 来跳过检查
(2) 无法构建python3-tensorflow-lite
在这个recipe中,会独立执行一个bash脚本,其中需要利用wget/curl去下载依赖代码,但是bash有可能无法获得系统的代理配置,可以在~/.wgetrc 中添加:
use_proxy = on
http_proxy = [proxy:port]
https_proxy = [proxy:port]
使wget能正确连接代理服务器下载代码