OpenBMC devtool
devtool 是 OpenBMC 提供的一个工具,可以用于辅助本地的开发验证工作。

devtool

在使用 devtool 之前同样需要设置环境变量:

source setup romulus
Machine romulus found in meta-ibm/meta-romulus
Common targets are:
     obmc-phosphor-image

devtool modify 会新建一个分支进行代码管理:

❯ devtool modify bmcweb

❯ devtool status
bmcweb: /home/runsisi/working/bmc/openbmc/build/romulus/workspace/sources/bmcweb

cd /home/runsisi/working/bmc/openbmc/build/romulus/workspace/sources/bmcweb
❯ git br
* devtool
  master

同时会修改 build/romulus/conf/bblayers.conf 配置文件,并增加 build/romulus/workspace 一层:

❯ cat build/romulus/conf/bblayers.conf
# LAYER_CONF_VERSION is increased each time build/conf/bblayers.conf
# changes incompatibly
LCONF_VERSION = "8"

BBPATH = "${TOPDIR}"
BBFILES ?= ""

BBLAYERS ?= " \
  /home/runsisi/working/bmc/openbmc/meta \
  /home/runsisi/working/bmc/openbmc/meta-openembedded/meta-oe \
  /home/runsisi/working/bmc/openbmc/meta-openembedded/meta-networking \
  /home/runsisi/working/bmc/openbmc/meta-openembedded/meta-perl \
  /home/runsisi/working/bmc/openbmc/meta-openembedded/meta-python \
  /home/runsisi/working/bmc/openbmc/meta-phosphor \
  /home/runsisi/working/bmc/openbmc/meta-aspeed \
  /home/runsisi/working/bmc/openbmc/meta-openpower \
  /home/runsisi/working/bmc/openbmc/meta-ibm/meta-romulus \
  /home/runsisi/working/bmc/openbmc/build/romulus/workspace \
  "

如果需要修改构建选项,可以修改 build/romulus/workspace/appends 下的 bbappend 文件,如:

❯ vi build/romulus/workspace/appends/bmcweb_git.bbappend
EXTRA_OEMESON:append = " -Dinsecure-disable-xss=enabled -Dinsecure-disable-ssl=disabled"

devtool 的子命令除了 create-workspace 都是通过插件注册的,各插件的实现请参考 scripts/lib/devtool 目录下的文件。

export EDITOR=vim

❯ devtool edit-recipe bmcweb

❯ devtool build bmcweb
NOTE: bmcweb: compiling from external source tree /home/runsisi/working/bmc/openbmc/build/romulus/workspace/sources/bmcweb

此时使用 devtool build 进行构建与使用 bitbake 并无差异。

构建操作将在 build/romulus/workspace/sources/bmcweb/oe-workdir 下的 bmcweb-1.0+git 目录进行,oe-workdir 是指向 build/romulus/tmp/work/arm1176jzs-openbmc-linux-gnueabi/bmcweb/1.0+git 目录的符号链接,这个目录本来就是 bitbake 的构建目录(严格来说应该是 devtool modify 之前的构建),因此 devtool 只是在这个目录下新建了一个 bmcweb-1.0+git 子目录用于构建(严格来说应该是 devtool modify 之后的构建,因为 devtool modify 之后再使用 bitbake 也是在新目录进行构建):

❯ ls -ld build/romulus/workspace/sources/bmcweb/oe-logs
lrwxrwxrwx 1 runsisi runsisi 109 Dec 19 16:41 build/romulus/workspace/sources/bmcweb/oe-logs -> /home/runsisi/working/bmc/openbmc/build/romulus/tmp/work/arm1176jzs-openbmc-linux-gnueabi/bmcweb/1.0+git/temp

❯ ls -ld build/romulus/workspace/sources/bmcweb/oe-workdir
lrwxrwxrwx 1 runsisi runsisi 104 Nov  3 21:40 build/romulus/workspace/sources/bmcweb/oe-workdir -> /home/runsisi/working/bmc/openbmc/build/romulus/tmp/work/arm1176jzs-openbmc-linux-gnueabi/bmcweb/1.0+git

cd build/romulus/tmp/work/arm1176jzs-openbmc-linux-gnueabi/bmcweb
❯ tree -L 2
.
└── 1.0+git                // oe-workdir soft link dir
    ├── bmcweb-1.0+git     // devtool build dir
    ├── build              // bitbake build dir
    ├── debugsources.list
    ├── deploy-ipks
    ├── deploy-source-date-epoch
    ├── git                // bitbake src dir
    ├── image
    ├── license-destdir
    ├── meson.cross
    ├── meson.native
    ├── meson-qemuwrapper
    ├── package
    ├── packages-split
    ├── pkgdata
    ├── pkgdata-pdata-input
    ├── pkgdata-sysroot
    ├── pseudo
    ├── recipe-sysroot
    ├── recipe-sysroot-native
    ├── run-ptest
    ├── source-date-epoch
    ├── spdx
    ├── sysroot-destdir
    └── temp               // build log

❯ ls build/romulus/workspace/sources/bmcweb/oe-workdir/image/usr/bin
bmcweb
❯ file build/romulus/workspace/sources/bmcweb/oe-workdir/image/usr/bin/bmcweb
build/romulus/workspace/sources/bmcweb/oe-workdir/image/usr/bin/bmcweb: ELF 32-bit LSB pie executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /usr/lib/ld-linux.so.3, BuildID[sha1]=e831f5e55bc980de9ee85806ad5b1fda2d6cac94, for GNU/Linux 5.15.0, with debug_info, not stripped

❯ ls build/romulus/workspace/sources/bmcweb/oe-workdir/package/usr/bin
bmcweb
❯ file build/romulus/workspace/sources/bmcweb/oe-workdir/package/usr/bin/bmcweb
build/romulus/workspace/sources/bmcweb/oe-workdir/package/usr/bin/bmcweb: ELF 32-bit LSB pie executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /usr/lib/ld-linux.so.3, BuildID[sha1]=e831f5e55bc980de9ee85806ad5b1fda2d6cac94, for GNU/Linux 5.15.0, stripped

输出物可以通过 oe-logs 目录( 实际指向 oe-workdir/temp 目录)下的日志文件进行了解。

可以通过 devtool modify 同时修改多个项目:

❯ devtool modify webui-vue

❯ devtool status
bmcweb: /home/runsisi/working/bmc/openbmc/build/romulus/workspace/sources/bmcweb
webui-vue: /home/runsisi/working/bmc/openbmc/build/romulus/workspace/sources/webui-vue

devtool
https://github.com/openbmc/docs/blob/master/cheatsheet.md#devtool

% 符号

The use of the “ % “ character is limited in that it only works directly in front of the .bbappend portion of the append file’s name. You cannot use the wildcard character in any other location of the name.

Append Files
https://docs.yoctoproject.org/bitbake/bitbake-user-manual/bitbake-user-manual-intro.html#append-files

so it actually truncates the expression at the first % and ignores
anything after the first one. That is there to chop the bbappend off
but can obviously chop off more.

meta-security/recipes-kernel/linux/linux-%_5.%.bbappend
may as well be:
meta-security/recipes-kernel/linux/linux-%.bbappend

so matches a bit more than expected and

meta-anaconda/recipes-gnome/gtk+/gtk+3_%.%.%.bbappend
is effectively
meta-anaconda/recipes-gnome/gtk+/gtk+3_%.bbappend

still confused about valid wildcarding for bbappend files
https://lists.openembedded.org/g/bitbake-devel/topic/81850298

externalsrc

需要注意的是,使用 devtool build 的情况下不能以补丁的方式修改代码,也就是说下面 SRC_URI:append 的方法行不通:

vi workspace/appends/bmcweb_git.bbappend
FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"
FILESPATH:prepend := "/home/runsisi/working/bmc/openbmc/build/romulus/workspace/sources/bmcweb/oe-local-files:"
# srctreebase: /home/runsisi/working/bmc/openbmc/build/romulus/workspace/sources/bmcweb

inherit externalsrc
# NOTE: We use pn- overrides here to avoid affecting multiple variants in the case where the recipe uses BBCLASSEXTEND
EXTERNALSRC:pn-bmcweb = "/home/runsisi/working/bmc/openbmc/build/romulus/workspace/sources/bmcweb"

# initial_rev .: 75e8e218cbf9539144ee8f6aea01e158d0a9e190

SRC_URI:append = "file://0001-static.patch"

修改需要直接应用到 EXTERNALSRC:pn-bmcweb 定义的源代码目录:

❯ bitbake bmcweb -e | grep ^EXTERNALSRC
EXTERNALSRC="/home/runsisi/working/bmc/openbmc/build/romulus/workspace/sources/bmcweb"
EXTERNALSRC:pn-bmcweb="/home/runsisi/working/bmc/openbmc/build/romulus/workspace/sources/bmcweb"
EXTERNALSRC_SYMLINKS="oe-workdir:/home/runsisi/working/bmc/openbmc/build/romulus/tmp/work/arm1176jzs-openbmc-linux-gnueabi/bmcweb/1.0+git oe-logs:/home/runsisi/working/bmc/openbmc/build/romulus/tmp/work/arm1176jzs-openbmc-linux-gnueabi/bmcweb/1.0+git/temp"

跳过 do_patch 的处理请阅读 externalsrc.bbclass 的实现:

// meta/classes/externalsrc.bbclass

SRCTREECOVEREDTASKS ?= "do_patch do_unpack do_fetch"

if EXTERNALSRC variable is set for your package, you would not get do_patch task when listing or executing tasks.

Bitbake recipe is missing do_patch task
https://stackoverflow.com/questions/67183912/bitbake-recipe-is-missing-do-patch-task

externalsrc
https://docs.yoctoproject.org/ref-manual/classes.html#ref-classes-externalsrc

可以通过在 bbapend 文件中注释掉 inherit externalsrc 或者注释掉 EXTERNALSRC:pn-bmcweb 的方法进行规避,这样的话补丁直接应用到原始的源代码目录,而不是 EXTERNALSRC 指向的目录(不管是 bitbake 还是 devtool 行为都一样)。

但是,对于 devtool build 而言有些特殊,在 bbapend 文件中注释掉 EXTERNALSRC:pn-bmcweb 的定义不可行,因为 EXTERNALSRC 必须定义:

❯ devtool build bmcweb
ERROR: Found *.bbappend in /home/runsisi/working/bmc/openbmc/build/romulus/workspace, but could not determine EXTERNALSRC:pn-*. Maybe still using old syntax?

该错误请参考如下代码:

# openembedded-core/srcripts/devtool

externalsrc_re = re.compile(r'^EXTERNALSRC(:pn-([^ =]+))? *= *"([^"]*)"$')

devtool / read_workspace
https://github.com/openembedded/openembedded-core/blob/yocto-4.3.1/scripts/devtool#L103


最后修改于 2024-01-03