当前位置: 首页 > 工具软件 > OpenBMC > 使用案例 >

OpenBmc(一)——编译工程

姬昊焱
2023-12-01

环境准备

1.准备一台安装有ubuntu18.04系统的主机,当然可以在虚拟机上安装ubuntu18.04,。

2.配置虚拟机,让ubuntu18.04系统至少保证有12G内存可用,并保证硬盘大小不少于100G。

3.启动ubuntu系统,配置软件源。

备份原有源

sudo cp /etc/apt/sources.list /etc/apt/sources.list_back

修改源

sudo gedit /etc/apt/sources.list

内容填入以下

# 清华源
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

#  中科大源
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.ustc.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

更新源

sudo apt-get update

更新软件(请谨慎更新,ADM主机更新可能导致登录图形界面无法显示)

sudo apt-get upgrade

4.安装必备软件

openbmc工程编译需要依赖很多工具

sudo apt-get install -y gawk wget git-core git diffstat unzip texinfo gcc-multilib build-essential chrpath socat cpio python python3 python3-pip python3-pexpect xz-utils debianutils iputils-ping python3-git python3-jinja2 libegl1-mesa libsdl1.2-dev pylint3 xterm sed cvs subversion help2man make gcc g++ desktop-file-utils libgl1-mesa-dev libglu1-mesa-dev mercurial autoconf automake groff curl lzop asciidoc npm meson ninja tree

5.git配置

openbmc工程包中并没有源码,源码需要在编译过程中下载,所以需要配置Git,详细配置方法请自行百度。

正式开始

1.下载openbmc工程

找一个空目录,比如/work

​git clone https://github.com/openbmc/openbmc.git

2.配置编译平台

进入openbmc目录,配置需要编译的平台,根据README.md文档,配置romulus示例平台。

export TEMPLATECONF=meta-ibm/meta-romulus/conf
. openbmc-env

如果后续再次编译其他平台,则需要先删除配置,再配置平台:

rm -rf build/conf
export TEMPLATECONF=XXX
. openbmc-env

3.配置同时编译任务个数,一般为实际cpu核个数的两倍(本机为4物理核)

vi conf/local.conf

填入

BB_NUMBER_THREADS = '8'
PARALLEL_MAKE     = '-j 8'

BB_NUMBER_THREADS表示同时执行8个任务,PARALLEL_MAKE表示每个任务最多使用8个线程

4.先只执行下载任务

bitbake obmc-phosphor-image --runall=fetch

所有包下载完成之后,再执行bitbake obmc-phosphor-image命令编译固件,这样的好处是可以尽快检出会下载出错的包,进而修改协议或手动下载包放进去,后续编译过程就不需要人值守。

github下载出错

正常情况下,会有很多下载出错,可以使用以下协议转换配置

git config --global url."https://".insteadOf git://
git config --global url."http://".insteadOf git://

git config --global url."git@github.com:".insteadOf git://github.com/
git config --global url."git@github.com:".insteadOf git://git@github.com/

注意:上面后面两个 git@github.com: 替换需要轮流配置,一次只能配置一种,每次配置完之后执行下载,多次下载均报错后更换另一种。

另外,也可以手动下载,比如linux内核出现下载报错如下:

ERROR: linux-aspeed-5.15.10+gitAUTOINC+dd1e40cecc-r0 do_fetch: Fetcher failure: Fetch command export PSEUDO_DISABLED=1; export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/1000/bus"; export SSH_AGENT_PID="3078"; export SSH_AUTH_SOCK="/run/user/1000/keyring/ssh"; export PATH="/work/openbmc/scripts:/work/openbmc/build/tmp/work/romulus-openbmc-linux-gnueabi/linux-aspeed/5.15.10+gitAUTOINC+dd1e40cecc-r0/recipe-sysroot-native/usr/bin/arm-openbmc-linux-gnueabi:/work/openbmc/build/tmp/work/romulus-openbmc-linux-gnueabi/linux-aspeed/5.15.10+gitAUTOINC+dd1e40cecc-r0/recipe-sysroot/usr/bin/crossscripts:/work/openbmc/build/tmp/work/romulus-openbmc-linux-gnueabi/linux-aspeed/5.15.10+gitAUTOINC+dd1e40cecc-r0/recipe-sysroot-native/usr/sbin:/work/openbmc/build/tmp/work/romulus-openbmc-linux-gnueabi/linux-aspeed/5.15.10+gitAUTOINC+dd1e40cecc-r0/recipe-sysroot-native/usr/bin:/work/openbmc/build/tmp/work/romulus-openbmc-linux-gnueabi/linux-aspeed/5.15.10+gitAUTOINC+dd1e40cecc-r0/recipe-sysroot-native/sbin:/work/openbmc/build/tmp/work/romulus-openbmc-linux-gnueabi/linux-aspeed/5.15.10+gitAUTOINC+dd1e40cecc-r0/recipe-sysroot-native/bin:/work/openbmc/poky/bitbake/bin:/work/openbmc/build/tmp/hosttools"; export HOME="/home/cdw"; LANG=C git -c core.fsyncobjectfiles=0 -c gc.autoDetach=false clone --bare --mirror git://github.com/openbmc/linux /work/openbmc/build/downloads/git2/github.com.openbmc.linux --progress failed with exit code 128, no output

ERROR: linux-aspeed-5.15.10+gitAUTOINC+dd1e40cecc-r0 do_fetch: Fetcher failure for URL: 'git://github.com/openbmc/linux;protocol=git;branch=dev-5.15'. Unable to fetch URL from any source.

ERROR: Logfile of failure stored in: /work/openbmc/build/tmp/work/romulus-openbmc-linux-gnueabi/linux-aspeed/5.15.10+gitAUTOINC+dd1e40cecc-r0/temp/log.do_fetch.118487

ERROR: Task (/work/openbmc/meta-aspeed/recipes-kernel/linux/linux-aspeed_git.bb:do_fetch) failed with exit code '1'

可以看到上面已经提示了需要下载的版本、需要存放到哪个目录、存放的名字

处理方法:

git clone -b dev-5.15 git@github.com:openbmc/linux.git  work/openbmc/build/downloads/git2/github.com.openbmc.linux

下载完成之后,随意复制/work/openbmc/build/downloads/git2/目录下一个*.done文件,命名为github.com.openbmc.linux.done,这样yocto便知道github.com.openbmc.linux已下载完成。

cp github.com.openbmc.phosphor-objmgr.done  github.com.openbmc.linux.done

又比如u-boot:

git clone -b v2016.07-aspeed-openbmc git@github.com:openbmc/u-boot.git /work/openbmc/build/downloads/git2/github.com.openbmc.u-boot.git

#进入/work/openbmc/build/downloads/git2/目录下
cp github.com.openbmc.phosphor-objmgr.done  github.com.openbmc.u-boot.git.done

又比如ipmid:

git clone  git@github.com:openbmc/phosphor-host-ipmid.git /work/openbmc/build/downloads/git2/github.com.openbmc.phosphor-host-ipmid

#进入/work/openbmc/build/downloads/git2/目录下
cp github.com.openbmc.phosphor-objmgr.done  github.com.openbmc.phosphor-host-ipmid.done

其他下载报错:

如果看到这样的下载地址:https://github.com/liberationfonts/liberation-fonts/files/6418984/liberation-fonts-ttf-2.1.4.tar.gz 出错,可以用wget命令下载,下载完成后复制到downloads文件夹下,即/work/openbmc/build/downloads目录,再次执行编译命令即可。

​
wget https://github.com/liberationfonts/liberation-fonts/files/6418984/liberation-fonts-ttf-2.1.4.tar.gz

cp  liberation-fonts-ttf-2.1.4.tar.gz  /work/openbmc/build/romulus/downloads/

#进入/work/openbmc/build/downloads/目录下(注意,不是git2下)
cp XXX.done liberation-fonts-ttf-2.1.4.tar.gz.done
​

如果使用wget命令也无法下载,那就只能去网上找一样的软件包,比如liberation-fonts-ttf-2.1.4.tar.gz,将其下载后放入/work/openbmc/build/downloads目录即可(也需要.done文件)。

注意:一般软件压缩包是放入/work/openbmc/build/romulus/downloads目录,而github下载的则直接解压放入/work/openbmc/build/downloads/git2/,在这两个目录中的每个包均有对应的*.done文件,yocto通过该文件是否存在来判断这个包是否下载完成。

5.编译

执行

bitbake obmc-phosphor-image

可能会出现以下错误:

fatal error: Killed signal terminated program cc1plus
compilation terminated.
ninja: build stopped: subcommand failed.
WARNING: exit code 1 from a shell command.

g++:internal compiler error:Killed (program cc1plus)

这是因为ubuntu内存太小,至少保证ubuntu共有12G内存大小。

6.编译完成之后配置

vi conf/local.conf

添加以下变量:

BB_NO_NETWORK = "1"

表示以后编译为断网环境,这样以后将直接从/work/openbmc/build/downloads取包,而不需要网络下载。

7.查看编译成果

编译输出位于/work/openbmc/build/tmp/deploy/images/romulus/目录下。

 类似资料: