efitools: Fix cross-compilation

Failing to build in a cross-compiled setup. these changes address that.

(cherry picked from commit c7d0f5d110)
This commit is contained in:
Brian McGillion 2026-02-02 11:40:09 +04:00 committed by github-actions[bot]
commit 7feb3143a6
2 changed files with 121 additions and 1 deletions

View file

@ -0,0 +1,89 @@
--- a/Make.rules
+++ b/Make.rules
@@ -68,35 +68,35 @@ endif
%.h: %.auth
./xxdi.pl $< > $@
-%.hash: %.efi hash-to-efi-sig-list
- ./hash-to-efi-sig-list $< $@
+%.hash: %.efi
+ hash-to-efi-sig-list $< $@
-%-blacklist.esl: %.crt cert-to-efi-hash-list
- ./cert-to-efi-sig-list $< $@
+%-blacklist.esl: %.crt
+ cert-to-efi-sig-list $< $@
-%-hash-blacklist.esl: %.crt cert-to-efi-hash-list
- ./cert-to-efi-hash-list $< $@
+%-hash-blacklist.esl: %.crt
+ cert-to-efi-hash-list $< $@
-%.esl: %.crt cert-to-efi-sig-list
- ./cert-to-efi-sig-list -g $(MYGUID) $< $@
+%.esl: %.crt
+ cert-to-efi-sig-list -g $(MYGUID) $< $@
getcert = $(shell if [ "$(1)" = "PK" -o "$(1)" = "KEK" ]; then echo "-c PK.crt -k PK.key"; else echo "-c KEK.crt -k KEK.key"; fi)
getvar = $(shell if [ "$(1)" = "PK" -o "$(1)" = "KEK" ]; then echo $(1); else echo db; fi)
-%.auth: %.esl PK.crt KEK.crt sign-efi-sig-list
- ./sign-efi-sig-list $(call getcert,$*) $(call getvar,$*) $< $@
+%.auth: %.esl PK.crt KEK.crt
+ sign-efi-sig-list $(call getcert,$*) $(call getvar,$*) $< $@
-%-update.auth: %.esl PK.crt KEK.crt sign-efi-sig-list
- ./sign-efi-sig-list -a $(call getcert,$*) $(call getvar,$*) $< $@
+%-update.auth: %.esl PK.crt KEK.crt
+ sign-efi-sig-list -a $(call getcert,$*) $(call getvar,$*) $< $@
-%-pkupdate.auth: %.esl PK.crt sign-efi-sig-list
- ./sign-efi-sig-list -a -c PK.crt -k PK.key $(call getvar,$*) $< $@
+%-pkupdate.auth: %.esl PK.crt
+ sign-efi-sig-list -a -c PK.crt -k PK.key $(call getvar,$*) $< $@
-%-blacklist.auth: %-blacklist.esl KEK.crt sign-efi-sig-list
- ./sign-efi-sig-list -a -c KEK.crt -k KEK.key dbx $< $@
+%-blacklist.auth: %-blacklist.esl KEK.crt
+ sign-efi-sig-list -a -c KEK.crt -k KEK.key dbx $< $@
-%-pkblacklist.auth: %-blacklist.esl PK.crt sign-efi-sig-list
- ./sign-efi-sig-list -a -c PK.crt -k PK.key dbx $< $@
+%-pkblacklist.auth: %-blacklist.esl PK.crt
+ sign-efi-sig-list -a -c PK.crt -k PK.key dbx $< $@
%.o: %.c
$(CC) $(INCDIR) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
--- a/Makefile
+++ b/Makefile
@@ -27,13 +27,11 @@ include Make.rules
EFISIGNED = $(patsubst %.efi,%-signed.efi,$(EFIFILES))
-all: $(EFISIGNED) $(BINARIES) $(MANPAGES) noPK.auth $(KEYAUTH) \
+all: $(EFISIGNED) $(BINARIES) noPK.auth $(KEYAUTH) \
$(KEYUPDATEAUTH) $(KEYBLACKLISTAUTH) $(KEYHASHBLACKLISTAUTH)
install: all
- $(INSTALL) -m 755 -d $(MANDIR)
- $(INSTALL) -m 644 $(MANPAGES) $(MANDIR)
$(INSTALL) -m 755 -d $(EFIDIR)
$(INSTALL) -m 755 $(EFIFILES) $(EFIDIR)
$(INSTALL) -m 755 -d $(BINDIR)
@@ -65,11 +63,11 @@ DB.h: DB.auth
noPK.esl:
> noPK.esl
-noPK.auth: noPK.esl PK.crt sign-efi-sig-list
- ./sign-efi-sig-list -t "$(shell date --date='1 second' +'%Y-%m-%d %H:%M:%S')" -c PK.crt -k PK.key PK $< $@
+noPK.auth: noPK.esl PK.crt
+ sign-efi-sig-list -t "$(shell date --date='1 second' +'%Y-%m-%d %H:%M:%S')" -c PK.crt -k PK.key PK $< $@
-ms-%.esl: ms-%.crt cert-to-efi-sig-list
- ./cert-to-efi-sig-list -g $(MSGUID) $< $@
+ms-%.esl: ms-%.crt
+ cert-to-efi-sig-list -g $(MSGUID) $< $@
hashlist.h: HashTool.hash
cat $^ > /tmp/tmp.hash

View file

@ -8,7 +8,13 @@
perlPackages,
help2man,
fetchzip,
pkgsCross,
efitools,
buildPackages,
}:
let
isCross = !(stdenv.buildPlatform.canExecute stdenv.hostPlatform);
in
stdenv.mkDerivation (finalAttrs: {
pname = "efitools";
version = "1.9.2";
@ -16,13 +22,17 @@ stdenv.mkDerivation (finalAttrs: {
buildInputs = [
gnu-efi
openssl
sbsigntool
];
nativeBuildInputs = [
perl
perlPackages.FileSlurp
help2man
openssl
sbsigntool
]
++ lib.optionals isCross [
efitools
];
src = fetchzip {
@ -39,6 +49,10 @@ stdenv.mkDerivation (finalAttrs: {
# https://bugs.debian.org/1122408
./objcopy-output-target.patch
]
++ lib.optionals isCross [
# Use builder's efitools to create sig lists for host
./cross.patch
];
postPatch = ''
@ -47,9 +61,26 @@ stdenv.mkDerivation (finalAttrs: {
sed -i -e 's#$(DESTDIR)/usr#$(out)#g' Make.rules
sed -i '$asign-efi-sig-list.o flash-var.o: CFLAGS += -D_GNU_SOURCE' Makefile
substituteInPlace lib/console.c --replace "EFI_WARN_UNKOWN_GLYPH" "EFI_WARN_UNKNOWN_GLYPH"
# Fix cross-compilation: use $(AR) and $(NM) variables instead of hardcoded commands
substituteInPlace Make.rules --replace-fail 'ar rcv' '$(AR) rcv'
substituteInPlace Make.rules --replace-fail 'nm -D' '$(NM) -D'
patchShebangs .
'';
makeFlags = [
"ARCH=${stdenv.hostPlatform.parsed.cpu.name}"
"AR=${stdenv.cc.targetPrefix}ar"
"NM=${stdenv.cc.targetPrefix}nm"
"OBJCOPY=${stdenv.cc.targetPrefix}objcopy"
]
++ lib.optionals isCross [
"MANPAGES="
];
passthru.tests = {
cross-aarch64 = pkgsCross.aarch64-multiplatform.efitools;
};
meta = {
description = "Tools for manipulating UEFI secure boot platforms";
homepage = "https://git.kernel.org/pub/scm/linux/kernel/git/jejb/efitools.git";