From 2018c100adae6cadac49754a6c7c7115b0660b38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kope=C4=87?= Date: Fri, 25 Jul 2025 13:29:34 +0200 Subject: [PATCH] capsule_cabinet.sh: make it work independent of .config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Extract the coreboot config from the capsule itself, in order to be able to use the script on any coreboot capsules. Upstream-Status: Inappropriate [Dasharo downstream] Change-Id: I49f2fb91423b912d98d55ca5e0e008b483d1322c Signed-off-by: Michał Kopeć --- capsule_cabinet.sh | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/capsule_cabinet.sh b/capsule_cabinet.sh index a03851d2558..955886094f2 100755 --- a/capsule_cabinet.sh +++ b/capsule_cabinet.sh @@ -3,6 +3,9 @@ set -e +edk_workspace=${EDK_WORKSPACE:-payloads/external/edk2/workspace/Dasharo} +edk_tools=${edk_workspace}/BaseTools/BinWrappers/PosixLike + function die() { echo error: "$@" 1>&2 exit 1 @@ -24,17 +27,6 @@ if [ ! -f .config ]; then die "No '.config' file in current directory" fi -# import coreboot's config file replacing $(...) with ${...} -while read -r line; do - if ! eval "$line"; then - die "failed to source '.config'" - fi -done <<< "$(sed 's/\$(\([^)]\+\))/${\1}/g' .config)" - -if [ "$CONFIG_DRIVERS_EFI_UPDATE_CAPSULES" != y ]; then - die "Current board configuration lacks support of update capsules" -fi - capsule=$1 date=$(stat -c %w $capsule | cut -d ' ' -f 1) vendor=$(cat .config | grep -e "CONFIG_VENDOR_.*=y" | cut -d '=' -f 1 | cut -d '_' -f 3- | awk '{ print tolower($0) }') @@ -74,6 +66,25 @@ cat > "${archive_dir}/firmware.metainfo.xml" << EOF EOF +decode_dir=$(mktemp --tmpdir -d XXXXXXXX) +if ! "${edk_tools}/GenerateCapsule" --decode $capsule --output $decode_dir/capsule; then + die "GenerateCapsule --decode failed!" +fi +cbfstool $decode_dir/capsule.Payload.1.bin extract -r COREBOOT -n config -f $decode_dir/config + +# import coreboot's config file replacing $(...) with ${...} +while read -r line; do + if ! eval "$line"; then + die "failed to source 'config'" + fi +done <<< "$(sed 's/\$(\([^)]\+\))/${\1}/g' $decode_dir/config)" + +rm -r $decode_dir + +if [ "$CONFIG_DRIVERS_EFI_UPDATE_CAPSULES" != y ]; then + die "Current board configuration lacks support of update capsules" +fi + cp $capsule $archive_dir/firmware.bin pushd $archive_dir &> /dev/null