From 2739c4b77396651282bcf6b4b101d013ec910a17 Mon Sep 17 00:00:00 2001 From: Martin Roth Date: Sat, 28 Jun 2025 10:14:16 -0600 Subject: [PATCH] SBOM: Change makefile to get versions from build.h Builds using SBOM were failing in the release because we don't have a git tree to get information from. We can't assume that the coreboot source will always be in a git tree, so it needs to be updated. This updates build.h to contain all the data that the SBOM wants and changes the SBOM makefile to get its information from build.h which can generate the required data in a number of different ways. Change-Id: I59fba349d95cb0dcff7a31d335f4acb4f11c89c7 Signed-off-by: Martin Roth Reviewed-on: https://review.coreboot.org/c/coreboot/+/88236 Reviewed-by: Angel Pons Reviewed-by: Matt DeVillier Tested-by: build bot (Jenkins) Reviewed-by: Alicja Michalska --- src/sbom/Makefile.mk | 6 +++--- util/genbuild_h/genbuild_h.sh | 4 ++++ util/release/build-release | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/sbom/Makefile.mk b/src/sbom/Makefile.mk index 4e3adc27d1..26f48dc3e8 100644 --- a/src/sbom/Makefile.mk +++ b/src/sbom/Makefile.mk @@ -110,10 +110,10 @@ $(build-dir)/compiler-%.json: $(src-dir)/compiler-%.json | $(build-dir)/goswid $(build-dir)/goswid add-payload-file -o $@ -i $@ --name $$(basename $$tool) --version $$version; \ done -$(build-dir)/coreboot.json: $(src-dir)/coreboot.json .git/HEAD | $(build-dir)/goswid +$(build-dir)/coreboot.json: $(src-dir)/coreboot.json $(obj)/build.h | $(build-dir)/goswid cp $< $@ - git_tree_hash=$$(git log -n 1 --format=%T);\ - git_comm_hash=$$(git log -n 1 --format=%H);\ + git_tree_hash=$$(grep 'COREBOOT_ORIGIN_TREE_REVISION' $(obj)/build.h | sed 's/.*"\(.*\)".*/\1/');\ + git_comm_hash=$$(grep 'COREBOOT_ORIGIN_GIT_REVISION' $(obj)/build.h | sed 's/.*"\(.*\)".*/\1/');\ sed -i -e "s//$$git_tree_hash/" -e "s//$$git_comm_hash/" $@;\ $(build-dir)/goswid add-license -o $@ -i $@ $(coreboot-licenses) diff --git a/util/genbuild_h/genbuild_h.sh b/util/genbuild_h/genbuild_h.sh index b381ab2776..e83d4e177f 100755 --- a/util/genbuild_h/genbuild_h.sh +++ b/util/genbuild_h/genbuild_h.sh @@ -33,6 +33,7 @@ if [ "${BUILD_TIMELESS}" = "1" ]; then DATE=0 elif [ "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = "true" ]; then GITREV="$(get_git_head_data %h)" + TREE_REV="$(get_git_head_data %t)" TIMESOURCE=git DATE="$(get_git_head_data %ct)" VERSION="$(git describe)" @@ -45,6 +46,8 @@ else if [ -f "${COREBOOT_VERSION_FILE}" ]; then MAJOR_VER="$(sed -n 's/^0*\([0-9]*\)\.0*\([0-9]*\).*/\1/p' "${COREBOOT_VERSION_FILE}")" MINOR_VER="$(sed -n 's/^0*\([0-9]*\)\.0*\([0-9]*\).*/\2/p' "${COREBOOT_VERSION_FILE}")" + GITREV="Based_on_$(sed -n 's/^[^-]*-\([^-]*\)-.*/\1/p' "${COREBOOT_VERSION_FILE}")" + TREE_REV="Based_on_$(sed -n 's/^[^-]*-[^-]*-\(.*\)/\1/p' "${COREBOOT_VERSION_FILE}")" fi fi @@ -78,6 +81,7 @@ printf "#define COREBOOT_VERSION %s\n" "\"${KERNELVERSION}\"" printf "/* timesource: %s */\n" "${TIMESOURCE}" printf "#define COREBOOT_VERSION_TIMESTAMP %s\n" "${DATE}" printf "#define COREBOOT_ORIGIN_GIT_REVISION \"%s\"\n" "${GITREV}" +printf "#define COREBOOT_ORIGIN_TREE_REVISION \"%s\"\n" "${TREE_REV:-0}" printf "#define COREBOOT_EXTRA_VERSION \"%s\"\n" "${COREBOOT_EXTRA_VERSION}" printf "#define COREBOOT_MAJOR_VERSION %s\n" "${MAJOR_VER:-0}" diff --git a/util/release/build-release b/util/release/build-release index c8e939b4bb..7c4aeb597f 100755 --- a/util/release/build-release +++ b/util/release/build-release @@ -89,7 +89,7 @@ fi git submodule update --init --checkout - printf "%s-%s\n" "$VERSION_NAME" "$(git log --pretty=%h -1)" > .coreboot-version + printf "%s-%s-%s\n" "$VERSION_NAME" "$(git log --pretty=%h -1)" "$(git log --pretty=%t -1)" > .coreboot-version printf "%s\n" "$(git log --pretty=format:%ci -1)" > "${TIME_FILE}" ) tstamp=$(cat "${TIME_FILE}" | sed 's/ +0000//')