linux/linux.mk: add kernel commit hash
cover linux/linux.mk: add kernel commit hash
Working with embedded platforms I found very useful having the buildroot commit hash part of the kernel version string. Building different images and I could always trace back to any change made to buildroot in between different builds.
In the same way I also found very useful to know exactly which commit hash was used to build the Linux kernel during development, so I can check specific commits that could introduce later an issue. With the default buildroot configuration, this patch adds the kernel commit hash to the kernel version string, in case LINUX_DIR contains a valid git repo.
Flaviu Nistor (1):
linux/linux.mk: add kernel commit hash
linux/linux.mk | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Signature · 6 lines
2.43.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
PATCH 1/1 linux/linux.mk: add kernel commit hash
Add also the kernel commit hash to the kernel release string in case LINUX_DIR is a valid git repo. Using uname, this allows easy identification of the commit hash used to build the kernel.
--- linux/linux.mk | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
linux/linux.mk +7 -1
@@ -12,6 +12,11 @@ LINUX_CPE_ID_VENDOR = linux LINUX_CPE_ID_PRODUCT = linux_kernel LINUX_CPE_ID_PREFIX = cpe:2.3:o +# Get git commit hash if LINUX_DIR is a valid git repo or +# an empty string which will be passed via LINUX_MAKE_FLAGS +LINUX_GIT_COMMIT_HASH = $(shell cd $(LINUX_DIR) 2>/dev/null && git rev-parse --short HEAD 2>/dev/null) +LINUX_LOCALVERSION = $(if $(LINUX_GIT_COMMIT_HASH),-g$(LINUX_GIT_COMMIT_HASH),) + # Compute LINUX_SOURCE and LINUX_SITE from the configuration ifeq ($(BR2_LINUX_KERNEL_CUSTOM_TARBALL),y) LINUX_TARBALL = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION))
@@ -164,7 +169,8 @@ LINUX_MAKE_FLAGS = \ CROSS_COMPILE="$(TARGET_CROSS)" \ WERROR=0 \ REGENERATE_PARSERS=1 \ - DEPMOD=$(HOST_DIR)/sbin/depmod + DEPMOD=$(HOST_DIR)/sbin/depmod \ + LOCALVERSION="$(LINUX_LOCALVERSION)" ifeq ($(BR2_REPRODUCIBLE),y) LINUX_MAKE_ENV += \
Signature · 6 lines
2.43.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Hi Flaviu!
Am 09.02.26 um 08:07 schrieb Flaviu Nistor:
Quoted 26 lines
Add also the kernel commit hash to the kernel release string in case
LINUX_DIRis a valid git repo. Using uname, this allows easy identification of the commit hash used to build the kernel.Signed-off-by Flaviu Nistor <[email protected]>--- linux/linux.mk | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)linux/linux.mk +5
-0@@ -12,6 +12,11 @@ LINUX_CPE_ID_VENDOR = linux LINUX_CPE_ID_PRODUCT = linux_kernel LINUX_CPE_ID_PREFIX = cpe:2.3:o +# Get git commit hash if LINUX_DIR is a valid git repo or +# an empty string which will be passed via LINUX_MAKE_FLAGS +LINUX_GIT_COMMIT_HASH = $(shell cd $(LINUX_DIR) 2>/dev/null && git rev-parse --short HEAD 2>/dev/null) +LINUX_LOCALVERSION = $(if $(LINUX_GIT_COMMIT_HASH),-g$(LINUX_GIT_COMMIT_HASH),) + # Compute LINUX_SOURCE and LINUX_SITE from the configuration ifeq ($(BR2_LINUX_KERNEL_CUSTOM_TARBALL),y) LINUX_TARBALL = $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCATION))
linux/linux.mk LINUX_MAKE_FLAGS = \ · line 173
Quoted 6 lines
linux/linux.mk +2
-1@@ -164,7 +169,8 @@ LINUX_MAKE_FLAGS = \ CROSS_COMPILE="$(TARGET_CROSS)" \ WERROR=0 \ REGENERATE_PARSERS=1 \ - DEPMOD=$(HOST_DIR)/sbin/depmod + DEPMOD=$(HOST_DIR)/sbin/depmod \ + LOCALVERSION="$(LINUX_LOCALVERSION)"
Wouldn't setting CONFIG_LOCALVERSION_AUTO=y in your kernel config achieve pretty much the same thing, without adding to localversion for everyone's builds?
Best regards,
Fiona
linux/linux.mk LINUX_MAKE_FLAGS = \ · line 176
Quoted 2 lines
linux/linux.mk +0
-0ifeq ($(BR2_REPRODUCIBLE),y) LINUX_MAKE_ENV += \
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Hello Fiona!
Quoted 15 lines · Fiona Klute
Hi Flaviu!
Am 09.02.26 um 08:07 schrieb Flaviu Nistor:
Quoted 12 lines
Add also the kernel commit hash to the kernel release string in case
LINUX_DIRis a valid git repo. Using uname, this allows easy identification of the commit hash used to build the kernel. =20Signed-off-by Flaviu Nistor <[email protected]>--- linux/linux.mk | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)=20
linux/linux.mk +0
-1--- a/linux/linux.mk
Quoted 8 lines
linux/linux.mk LINUX_CPE_ID_VENDOR =3D linux · line 17
Quoted 8 lines
+++
b/linux/linux.mklinux/linux.mk +3
-0@@ -12,6 +12,11 @@ LINUX_CPE_ID_VENDOR =3D linux LINUX_CPE_ID_PRODUCT =3D linux_kernel LINUX_CPE_ID_PREFIX =3D cpe:2.3:o =20 +# Get git commit hash if LINUX_DIR is a valid git repo or +# an empty string which will be passed via LINUX_MAKE_FLAGS +LINUX_GIT_COMMIT_HASH =3D $(shell cd $(LINUX_DIR) 2>/dev/null && git rev=
-parse --short HEAD 2>/dev/null)
Quoted 1 line
linux/linux.mk LINUX_CPE_ID_VENDOR =3D linux · line 18
Quoted 1 line
linux/linux.mk +1
-0+LINUX_LOCALVERSION =3D $(if $(LINUX_GIT_COMMIT_HASH),-g$(LINUX_GIT_COMMI=
T_HASH),)
Quoted 4 lines
linux/linux.mk LINUX_CPE_ID_VENDOR = linux
Quoted 4 lines
linux/linux.mk +1
-0+ # Compute LINUX_SOURCE and LINUX_SITE from the configuration ifeq ($(BR2_LINUX_KERNEL_CUSTOM_TARBALL),y) LINUX_TARBALL =3D $(call qstrip,$(BR2_LINUX_KERNEL_CUSTOM_TARBALL_LOCAT=
ION))
Quoted 12 lines
linux/linux.mk LINUX_MAKE_FLAGS =3D \ · line 173
Quoted 7 lines
linux/linux.mk +2
-1@@ -164,7 +169,8 @@ LINUX_MAKE_FLAGS =3D \ =09CROSS_COMPILE=3D"$(TARGET_CROSS)" \ =09WERROR=3D0 \ =09REGENERATE_PARSERS=3D1 \ -=09DEPMOD=3D$(HOST_DIR)/sbin/depmod +=09DEPMOD=3D$(HOST_DIR)/sbin/depmod \ +=09LOCALVERSION=3D"$(LINUX_LOCALVERSION)"Wouldn't setting
CONFIG_LOCALVERSION_AUTO=3Dyin your kernel config=20 achieve pretty much the same thing, without adding to localversion for=20 everyone's builds?
You are right, making sure to set this in the kernel config file would end in the same result. Thanks for the reply and pointing this out.
Best regards,
Flaviu
Quoted 5 lines
Best regards,
FionaQuoted 2 lines
linux/linux.mk +0
-0ifeq ($(BR2_REPRODUCIBLE),y) LINUX_MAKE_ENV +=3D \
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot