Yocto Linux /lib/modules/ directory differs per root filesystem build due to kgit-s2q

I am using Yocto Kirkstone to create a Linux image for a i.MX8 device. It successfully builds the Linux kernel version 5.15.71.

I have also integrated RAUC (https://github.com/rauc/rauc) for firmware updates. This method creates an A/B partitioning scheme for firmware updates where the root file system is updated on the device.

I have created a bbappend in my own custom layer and locked the SRCREV of the kernel.

SRCREV = "50ade09d822cbf0f49af4c2cac250edb4003c7ef"

The problem I am facing is that after a RAUC update of the root filesystem, the secondary partition is successfully updated and activated, however the /lib/modules/ directory has the incorrect version. This results in error messsages such as the following:

Aug 27 13:29:02 device python3[754]: modprobe: FATAL: Module ip_tables not found in directory /lib/modules/5.15.71-1.0+ge1cb7633db6d
Aug 27 13:29:02 device python3[753]: iptables v1.8.7 (legacy): can't initialize iptables table `filter': Table does not exist (do you need to insmod?)
Aug 27 13:29:02 device python3[753]: Perhaps iptables or your kernel needs to be upgraded.
Aug 27 13:29:02 device python3[748]: 2024-08-27 13:29:02,425:ERROR:Error: Failed to set firewall commands: None

The actual directory that does exist on disk is now:

/lib/modules/2018 5.15.71-1.0+g885f034ad83a

When I check the Yocto tmp/work/*/linux-complab build directory, I can see that the git repository is successfully checked out to my specified version. If I symlink this new directory to the expected directory version, the kernel successfully finds the modules it is looking for.

Why is the root filesystem image produced by Yocto containing this directory by a changing name? How can I lock it down to one dependable name?

UPDATE:

After digging more, I think the issue is that the script in the work directory “recipe-sysroot-native/usr/bin/kgit-s2q” is missing some information. This section adds the ‘invalid_git config’:

#  Parse the author information
GIT_AUTHOR_NAME=$(sed -ne 's/Author: //p' "$tmp_info")
GIT_AUTHOR_EMAIL=$(sed -ne 's/Email: //p' "$tmp_info")
export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL
while test -z "$GIT_AUTHOR_EMAIL" && test -z "$GIT_AUTHOR_NAME" ; do
    if [ -n "$quilt_author" ] ; then
        GIT_AUTHOR_NAME="$quilt_author_name";
        GIT_AUTHOR_EMAIL="$quilt_author_email";
    else
        if [ -z "$INTERACTIVE" ]; then
            GIT_AUTHOR_NAME="invalid_git config"
            GIT_AUTHOR_EMAIL="<unknown@unknown>"
        else
            echo "No author found in $patch_name" >&2;
            echo "---"
            cat $tmp_msg
            printf "Author: ";
            read patch_author

            echo "$patch_author"

            patch_author_name=$(expr "z$patch_author" : 'z(.*[^ ]) *<.*') &&
            patch_author_email=$(expr "z$patch_author" : '.*<([^>]*)') &&
            test '' != "$patch_author_name" &&
            test '' != "$patch_author_email" &&
            GIT_AUTHOR_NAME="$patch_author_name" &&
            GIT_AUTHOR_EMAIL="$patch_author_email"
        fi
    fi
done

It looks like it sets the invalid git config if “INTERACTIVE” is null:

if [ -z "$INTERACTIVE" ]; then
    GIT_AUTHOR_NAME="invalid_git config"
    GIT_AUTHOR_EMAIL="<unknown@unknown>"

This in turn causes the top of the git log to include this bogus commit that is different each time I use bitbake to clean and build the kernel:

commit 84e2651775ca2bdb4fdfbc081f314ec61451b3de (HEAD -> linux-compulab_v5.15.71)
Author: invalid_git config <unknown@unknown>
Date:   Tue Aug 27 22:55:34 2024 +0000

commit 50ade09d822cbf0f49af4c2cac250edb4003c7ef (origin/linux-compulab_v5.15.71, origin/HEAD)
Author: vraevsky <valentin@compulab.co.il>
Date:   Fri Feb 16 13:13:45 2024 +0200

    Update README.md

The temp folder logs show this kgit-s2q script getting called only in these few locations:

>>/5.15.71-r0/temp$ grep -R "kgit-s2q" *
run.do_patch:           kgit-s2q --gen -v $kgit_extra_args --patches .kernel-meta/
run.do_patch.2351048:           kgit-s2q --gen -v $kgit_extra_args --patches .kernel-meta/
run.do_validate_branches:                       # We've checked out HEAD, make sure we cleanup kgit-s2q fence post check
run.do_validate_branches:                       kgit-s2q --clean
run.do_validate_branches.2350365:                       # We've checked out HEAD, make sure we cleanup kgit-s2q fence post check
run.do_validate_branches.2350365:                       kgit-s2q --clean

This causes the git checkout to match the built kernel modules:

linux-compulab/5.15.71-r0/image/lib/modules$ ls
5.15.71-1.0+g84e2651775ca

It looks like the kernel-yocto.bbclass file is what sets the extra args:

developer@machine:~/compulab-nxp-bsp/sources$ grep -R "kgit_extra_args" *
poky/meta/classes/kernel-yocto.bbclass:         kgit_extra_args=""
poky/meta/classes/kernel-yocto.bbclass:             kgit_extra_args="--commit-sha author"
poky/meta/classes/kernel-yocto.bbclass:         kgit-s2q --gen -v $kgit_extra_args --patches .kernel-meta/

How do I fix the kgit-s2q script so this bogus checkout is not created?