如何在启动输出或 /etc/issue 中包含镜像层的 git 修订版?

Ray*_*pew 4 git bitbake yocto

我正在为 SBC 创建 Poky 映像,并且希望用户能够查找用于创建映像的配方文件的 SHA1 ID。

菜谱内容如下:

SUMMARY = "Toradex Embedded Linux Console Sporian Yocto version"
DESCRIPTION = "A Yocto Poky build derived from core-image-minimal"

LICENSE = "MIT"

#start of the resulting deployable tarball name
export IMAGE_BASENAME = "Sporian-Console-Image-Yocto"
IMAGE_NAME_apalis-imx6 = "Apalis-iMX6_${IMAGE_BASENAME}"

require /home/rdepew/workspace/oe-core3/poky/meta/recipes-core/images/core-image-minimal.bb

IMAGE_INSTALL += " \
    packagegroup-core-ssh-openssh \
    sqlite3 \
    avro-c \
"
Run Code Online (Sandbox Code Playgroud)

以下是 SBC 启动时的控制台输出:

Poky (Yocto Project Reference Distro) 2.4.3 apalis-imx6 /dev/ttymxc0

apalis-imx6 login: root
root@apalis-imx6:~# uname -a
Linux apalis-imx6 4.1.44-2.7.4+gb1555bfbf388 #1 SMP Tue Oct 9 17:35:02 UTC 2018 armv7l GNU/Linux
root@apalis-imx6:~#
Run Code Online (Sandbox Code Playgroud)

以下是 /etc/issue 的内容。请注意,这些是默认内容:

Poky (Yocto Project Reference Distro) 2.4.3 \n \l
Run Code Online (Sandbox Code Playgroud)

假设包含配方的存储库的 SHA1 ID 为 ea4c5bb42e7542... 。我想在启动期间或响应用户命令时打印 SHA1 ID(类似于“uname”)。我怎样才能做到这一点?

我认为 ${SRCPV} 可能是解决我的问题的方法,但我不能屈服于我的意愿。

小智 5

聚会有点晚了,但我意识到falstaff 的答案实际上并没有保存配方层的 git 修订版,而是保存构建目录所在层的 git 修订版(如果构建目录不存在,则失败)在 git 存储库中)。

因此我最终使用了这样的东西git-revision-file.bb

LICENSE = "MIT"
SUMMARY = "Place a git revision file in the sysroot"

inherit image-buildinfo

REVISION_INFO_FILE = "build-layers-git-revisions"
S = "${WORKDIR}"


python do_configure() {
    full_path = d.expand("${S}/${REVISION_INFO_FILE}")

    with open(full_path, 'w') as file:
        file.writelines(get_layer_revs(d))
}

do_install() {
    install -d ${D}${sysconfdir}
    install -m 0644 ${S}/${REVISION_INFO_FILE} ${D}${sysconfdir}
}

FILES_${PN} = "${sysconfdir}"
Run Code Online (Sandbox Code Playgroud)

这会保存 git 分支和构建的每一层的修订版/etc/build-layers-git-revisions。如果您只想要您层的 git 版本,请base_get_metadata_git_revision(path, d)使用metadata_scm.bbclass. 但我认为上面的内容为您的构建提供了更完整的信息。