I'm creating a Poky image for an SBC, and I want to have a way for a user to look up the SHA1 ID of the recipe file used to create the image.
Recipe contents are as follows:
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 \
"
Here's the console output when the SBC boots:
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:~#
Here are the contents of /etc/issue. Note that these are the default contents:
Poky (Yocto Project Reference Distro) 2.4.3 \n \l
Suppose the SHA1 ID of the repository containing the recipe is ea4c5bb42e7542... . I want to print the SHA1 ID during bootup or in response to a user command (similar to 'uname'). How can I do that?
I thought that ${SRCPV} might be the solution to my problem, but I can't bend it to my will.
A bit late to the party, but I realized that falstaff's answer actually does not save the git revision of the layer of the recipe, but instead the git revision of the layer where the build directory is located (or fails if the build directory is not in a git repository).
Hence I ended up using something like this 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}"
This saves the git branch and revision of each layer of your build in /etc/build-layers-git-revisions.
If you instead want only the git revision of you layer use base_get_metadata_git_revision(path, d) of the metadata_scm.bbclass. But I think the above provides more complete information for your build.
Linux and U-Boot git hashes are the ones from the Linux/U-Boot git repository. This is how it is commonly done with OpenEmbedded. There is certainly a way to pass the git hash from OE to the U-Boot/Kernel build system, but I would not recommend doing that since it is not how it is commonly done.
As for the /etc/issue file, this typically gets generated in the meta/recipes-core/base-files/base-files_3.0.14.bb recipe. It should be fairly straight forward to add a bbappend to your layer and extend the task, e.g. something like this:
def get_layer_rev(d):
return bb.process.run('git rev-parse HEAD')
LAYER_REV="${@get_layer_rev(d)}"
do_install_basefilesissue_append() {
# Overwrite /etc/issue with a custom version of it
printf "${DISTRO_NAME} " > ${D}${sysconfdir}/issue
printf "${LAYER_REV}" >> ${D}${sysconfdir}/issue
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With