kernel: make LOCALVERSION consistent between recipes

The initial fix for localversion setting in 6.3+ broke older
recipes and also broke recipes setting localversion in a kernel
recipe, as make-mod-scripts (and other locations) can trigger
a regeneration of files and don't have access to the variable.

Moving the setting of this variable to the global namespace
doesn't make sense, so we follow the example of the kernel-abiversion
and save a kernel-localversion to the build artifacts.

Recipes that may regenerate scripts/dynamic files, must
depend on the do_shared_workedir of the kernel and use the helper
function to read the file storing the localversion.

(From OE-Core rev: cca0971a7d92d823cc0c2b16cf14a7b2ed8ecb61)

Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>

cherry-picked from master b378eec156998eea55ba61e59103cb34fab0d07c

Signed-off-by: Andreas Helbech Kleist <andreaskleist@gmail.com>
Acked-by: Ryan Eatmon <reatmon@ti.com>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
This commit is contained in:
Bruce Ashfield 2024-02-22 11:35:45 +01:00 committed by Steve Sakoman
parent 2b7c113459
commit 26f23535ee
6 changed files with 30 additions and 8 deletions

View File

@ -65,11 +65,3 @@ KERNEL_CC = "${CCACHE}${HOST_PREFIX}gcc ${HOST_CC_KERNEL_ARCH} -fuse-ld=bfd ${DE
KERNEL_LD = "${CCACHE}${HOST_PREFIX}ld.bfd ${HOST_LD_KERNEL_ARCH}"
KERNEL_AR = "${CCACHE}${HOST_PREFIX}ar ${HOST_AR_KERNEL_ARCH}"
TOOLCHAIN ?= "gcc"
# 6.3+ requires the variable LOCALVERSION to be set to not get a "+" in
# the local version. Having it empty means nothing will be added, and any
# value will be appended to the local kernel version. This replaces the
# use of .scmversion file for setting a localversion without using
# the CONFIG_LOCALVERSION option.
KERNEL_LOCALVERSION ??= ""
export LOCALVERSION ?= "${KERNEL_LOCALVERSION}"

View File

@ -541,6 +541,7 @@ do_shared_workdir () {
#
echo "${KERNEL_VERSION}" > $kerneldir/${KERNEL_PACKAGE_NAME}-abiversion
echo "${KERNEL_LOCALVERSION}" > $kerneldir/${KERNEL_PACKAGE_NAME}-localversion
# Copy files required for module builds
cp System.map $kerneldir/System.map-${KERNEL_VERSION}
@ -630,6 +631,19 @@ python check_oldest_kernel() {
check_oldest_kernel[vardepsexclude] += "OLDEST_KERNEL KERNEL_VERSION"
do_configure[prefuncs] += "check_oldest_kernel"
KERNEL_LOCALVERSION ??= ""
# 6.3+ requires the variable LOCALVERSION to be set to not get a "+" in
# the local version. Having it empty means nothing will be added, and any
# value will be appended to the local kernel version. This replaces the
# use of .scmversion file for setting a localversion without using
# the CONFIG_LOCALVERSION option.
#
# Note: This class saves the value of localversion to a file
# so other recipes like make-mod-scripts can restore it via the
# helper function get_kernellocalversion_file
export LOCALVERSION="${KERNEL_LOCALVERSION}"
kernel_do_configure() {
# fixes extra + in /lib/modules/2.6.37+
# $ scripts/setlocalversion . => +

View File

@ -5,6 +5,7 @@ do_patch[depends] += "virtual/kernel:do_shared_workdir"
do_patch[noexec] = "1"
do_package[depends] += "virtual/kernel:do_populate_sysroot"
KERNEL_VERSION = "${@get_kernelversion_file("${STAGING_KERNEL_BUILDDIR}")}"
LOCAL_VERSION = "${@get_kernellocalversion_file("${STAGING_KERNEL_BUILDDIR}")}"
inherit linux-kernel-base

View File

@ -33,6 +33,17 @@ def get_kernelversion_file(p):
except IOError:
return None
def get_kernellocalversion_file(p):
fn = p + '/kernel-localversion'
try:
with open(fn, 'r') as f:
return f.readlines()[0].strip()
except IOError:
return ""
return ""
def linux_module_packages(s, d):
suffix = ""
return " ".join(map(lambda s: "kernel-module-%s%s" % (s.lower().replace('_', '-').replace('@', '+'), suffix), s.split()))

View File

@ -14,6 +14,7 @@ export CROSS_COMPILE = "${TARGET_PREFIX}"
export KBUILD_OUTPUT = "${STAGING_KERNEL_BUILDDIR}"
export KERNEL_VERSION = "${@oe.utils.read_file('${STAGING_KERNEL_BUILDDIR}/kernel-abiversion')}"
export LOCALVERSION = "${@oe.utils.read_file('${STAGING_KERNEL_BUILDDIR}/kernel-localversion')}"
KERNEL_OBJECT_SUFFIX = ".ko"
# kernel modules are generally machine specific

View File

@ -21,6 +21,9 @@ DEPENDS += "gmp-native"
EXTRA_OEMAKE = " HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}" HOSTCPP="${BUILD_CPP}""
EXTRA_OEMAKE += " HOSTCXX="${BUILD_CXX} ${BUILD_CXXFLAGS} ${BUILD_LDFLAGS}" CROSS_COMPILE=${TARGET_PREFIX}"
KERNEL_LOCALVERSION = "${@get_kernellocalversion_file("${STAGING_KERNEL_BUILDDIR}")}"
export LOCALVERSION="${KERNEL_LOCALVERSION}"
# Build some host tools under work-shared. CC, LD, and AR are probably
# not used, but this is the historical way of invoking "make scripts".
#