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                         | 28 ++++++++++++++++++++++------
 configure.ac                        |  4 ++++
 drivers/watchdog/init_array_start.S |  6 +++++-
 3 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 8347749..121c7ed 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -122,16 +122,23 @@ install-exec-hook:
 #
 efi_loadername = efibootguard$(MACHINE_TYPE_NAME).efi
 
+if ARCH_AARCH64
+efi_sources_watchdogs = 
+else
 # 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 = \
-       drivers/watchdog/init_array_start.S \
+efi_sources_watchdogs = \
        drivers/watchdog/wdat.c \
        drivers/watchdog/amdfch_wdt.c \
        drivers/watchdog/i6300esb.c \
        drivers/watchdog/atom-quark.c \
        drivers/watchdog/ipc4x7e_wdt.c \
-       drivers/watchdog/itco.c \
+       drivers/watchdog/itco.c
+endif
+
+efi_sources = \
+       drivers/watchdog/init_array_start.S \
+       $(efi_sources_watchdogs) \
        drivers/watchdog/init_array_end.S \
        env/syspart.c \
        env/fatvars.c \
@@ -159,12 +166,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 \
        -mno-red-zone
 endif
@@ -181,6 +188,15 @@ 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
+
 efi_objects_pre1 = $(efi_sources:.c=.o)
 efi_objects_pre2 = $(efi_objects_pre1:.S=.o)
 efi_objects = $(addprefix $(top_builddir)/,$(efi_objects_pre2))
@@ -217,7 +233,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])
 
diff --git a/drivers/watchdog/init_array_start.S 
b/drivers/watchdog/init_array_start.S
index 61a6780..6d4b7cd 100644
--- a/drivers/watchdog/init_array_start.S
+++ b/drivers/watchdog/init_array_start.S
@@ -13,7 +13,11 @@
  */
 
 .section .init_array
+/* Dummy value to avoid zero-size .init_array section linker error on
+ * architectures having no watchdog drivers */
+.word 0x5343
 /* align to 4K so that signing tools will not stumble over this section */
-.align 0x1000
+/* Note: Explicitly use .b(yte-)align as .align takes power of 2 on ARM */
+.balign 0x1000
 .global init_array_start
 init_array_start:
-- 
2.33.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/20210823103218.140510-1-christian.storm%40siemens.com.

Reply via email to