From: Christian Storm <[email protected]>

Adapt the build system to also support aarch64 builds of EFI Boot
Guard without the (x86-specific) watchdog arming part, leaving the
switching logics part only on this platform.
The watchdog arming part on aarch64 has to be provided externally
for now, e.g, by U-Boot (also providing EFI on aarch64).

Signed-off-by: Christian Storm <[email protected]>
---
 Makefile.am  | 32 +++++++++++++++++++++++++++-----
 configure.ac |  4 ++++
 2 files changed, 31 insertions(+), 5 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 91bcf46..d27272d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -124,7 +124,7 @@ efi_loadername = efibootguard$(MACHINE_TYPE_NAME).efi
 
 # NOTE: wdat.c is placed first so it is tried before any other drivers
 # NOTE: ipc4x7e_wdt.c must be *before* itco.c
-efi_sources = \
+efi_sources_watchdogs = \
        drivers/watchdog/init_array_start.S \
        drivers/watchdog/wdat.c \
        drivers/watchdog/amdfch_wdt.c \
@@ -133,7 +133,9 @@ efi_sources = \
        drivers/watchdog/ipc4x7e_wdt.c \
        drivers/watchdog/itco.c \
        drivers/watchdog/init_array_end.S \
-       watchdog.c \
+       watchdog.c
+
+efi_sources_main = \
        env/syspart.c \
        env/fatvars.c \
        utils.c \
@@ -160,12 +162,12 @@ efi_cflags = \
        -fno-strict-aliasing \
        -fno-stack-protector \
        -Wsign-compare \
-       -mno-sse \
-       -mno-mmx \
        $(CFLAGS)
 
 if ARCH_X86_64
 efi_cflags += \
+       -mno-sse \
+       -mno-mmx \
        -DEFI_FUNCTION_WRAPPER \
        -DWATCHDOG_DRIVERS \
        -mno-red-zone
@@ -183,6 +185,26 @@ efi_ldflags = \
        -L $(GNUEFI_LIB_DIR) \
        $(GNUEFI_LIB_DIR)/crt0-efi-$(ARCH).o
 
+if ARCH_AARCH64
+# aarch64's objcopy doesn't understand --target efi-[app|bsdrv|rtdrv],
+# hence set subsystem 0xa (EFI application) and binary format.
+objcopy_format = -O binary
+efi_ldflags += --defsym=EFI_SUBSYSTEM=0xa
+else
+objcopy_format = --target=efi-app-$(ARCH)
+endif
+
+# Don't build EFI Boot Guard's watchdog drivers for non-x86 systems.
+if ARCH_X86_64
+efi_sources = \
+       $(efi_sources_watchdogs) \
+       $(efi_sources_main)
+efi_cflags += -DWATCHDOG_DRIVERS
+else
+efi_sources = \
+       $(efi_sources_main)
+endif
+
 efi_objects_pre1 = $(efi_sources:.c=.o)
 efi_objects_pre2 = $(efi_objects_pre1:.S=.o)
 efi_objects = $(addprefix $(top_builddir)/,$(efi_objects_pre2))
@@ -219,7 +241,7 @@ $(efi_solib): $(efi_objects)
 $(efi_loadername): $(efi_solib)
        $(AM_V_GEN) $(OBJCOPY) -j .text -j .sdata -j .data -j .dynamic \
          -j .dynsym -j .rel -j .rela -j .reloc -j .init_array \
-         --target=efi-app-$(ARCH) $< $@
+         -j .rela.got -j .rela.data $(objcopy_format) $< $@
 
 $(top_builddir)/tools/bg_setenv-bg_setenv.o: $(GEN_VERSION_H)
 
diff --git a/configure.ac b/configure.ac
index b8d2b1c..d7a7451 100644
--- a/configure.ac
+++ b/configure.ac
@@ -82,6 +82,7 @@ SET_ARCH(I586, i586*)
 SET_ARCH(I686, i686*)
 SET_ARCH(X86_64, x86_64*)
 SET_ARCH(IA64, ia64*)
+SET_ARCH(AARCH64, aarch64*)
 
 ARCH=$(echo $host | sed "s/\(-\).*$//")
 
@@ -96,6 +97,9 @@ AM_COND_IF(ARCH_I586, [
 AM_COND_IF(ARCH_X86_64, [
           MACHINE_TYPE_NAME=x64])
 
+AM_COND_IF(ARCH_AARCH64, [
+          MACHINE_TYPE_NAME=aarch64])
+
 AC_SUBST([ARCH])
 AC_SUBST([MACHINE_TYPE_NAME])
 
-- 
2.32.0

-- 
You received this message because you are subscribed to the Google Groups "EFI 
Boot Guard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/efibootguard-dev/20210818140427.133612-2-christian.storm%40siemens.com.

Reply via email to