Skip to content

Commit

Permalink
[build] Add support for building as an AArch64 (ARM64) binary
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Brown <[email protected]>
  • Loading branch information
mcb30 committed Dec 5, 2023
1 parent 5509dce commit 20a4a49
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ jobs:
run: |
sudo apt update
sudo apt install -y -o Acquire::Retries=50 \
pesign gcab
pesign gcab gcc-aarch64-linux-gnu
- name: Build
working-directory: src
run: |
make
make CROSS_arm64=aarch64-linux-gnu-
5 changes: 3 additions & 2 deletions .github/workflows/coverity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
run: |
sudo apt update
sudo apt install -y -o Acquire::Retries=50 \
pesign gcab
pesign gcab gcc-aarch64-linux-gnu
- name: Download Coverity Scan
run: |
curl --form token=${{ secrets.COVERITY_SCAN_TOKEN }} \
Expand All @@ -28,7 +28,8 @@ jobs:
- name: Build via Coverity Scan
working-directory: src
run: |
/opt/coverity/bin/cov-build --dir cov-int make
/opt/coverity/bin/cov-build --dir cov-int \
make CROSS_arm64=aarch64-linux-gnu-
- name: Create submission
working-directory: src
run : |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ jobs:
run: |
sudo apt update
sudo apt install -y -o Acquire::Retries=50 \
pesign gcab \
pesign gcab gcc-aarch64-linux-gnu \
qemu-system-x86 ovmf \
python3-libvirt python3-lxml python3-pil \
python3-qrcode python3-yaml python3-zbar
- name: Build
working-directory: src
run: |
make
make CROSS_arm64=aarch64-linux-gnu-
- name: Fetch images
uses: actions/cache@v3
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Changelog

## [Unreleased]

- Add support for building as an AArch64 (ARM64) binary.

- Update to latest EDK2 headers.

## [v2.7.6] 2023-08-16
Expand Down
43 changes: 39 additions & 4 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ OBJECTS += paging.o memmap.o
OBJECTS_i386 := $(patsubst %.o,%.i386.o,$(OBJECTS))
OBJECTS_x86_64 := $(patsubst %.o,%.x86_64.o,$(OBJECTS))
OBJECTS_i386_x86_64 := $(patsubst %.o,%.i386.x86_64.o,$(OBJECTS))
OBJECTS_arm64 := $(patsubst %.o,%.arm64.o,$(OBJECTS))

# Header files
#
Expand Down Expand Up @@ -54,6 +55,15 @@ AR_x86_64 = $(CROSS_x86_64)ar
RANLIB_x86_64 = $(CROSS_x86_64)ranlib
OBJCOPY_x86_64 = $(CROSS_x86_64)objcopy

# Build tools for arm64 target
#
CC_arm64 = $(CROSS_arm64)gcc
AS_arm64 = $(CROSS_arm64)as
LD_arm64 = $(CROSS_arm64)ld
AR_arm64 = $(CROSS_arm64)ar
RANLIB_arm64 = $(CROSS_arm64)ranlib
OBJCOPY_arm64 = $(CROSS_arm64)objcopy

# Build flags for host binaries
#
HOST_CFLAGS += -Wall -W -Werror
Expand Down Expand Up @@ -82,6 +92,11 @@ CFLAGS_x86_64 := -m64 -mno-red-zone -fpie
ASFLAGS_x86_64 := --64
LDFLAGS_x86_64 := -m elf_x86_64

# Build flags for arm64 target
#
CFLAGS_arm64 := -mlittle-endian -mcmodel=small
ASFLAGS_arm64 := -mabi=lp64 -EL

# Run a test compilation and discard any output
#
CC_TEST = $(CC_$(1)) $(CFLAGS) $(CFLAGS_$(1)) \
Expand Down Expand Up @@ -132,12 +147,13 @@ CFLAGS_COND = $(CFLAGS_SPG) $(CFLAGS_CFI) $(CFLAGS_WNAPM) $(CFLAGS_WNAB) \
$(CFLAGS_NLTO) $(CFLAGS_MS_ABI)
CFLAGS_i386 += $(call CFLAGS_COND,i386)
CFLAGS_x86_64 += $(call CFLAGS_COND,x86_64)
CFLAGS_arm64 += $(call CFLAGS_COND,arm64)

###############################################################################
#
# Final targets

all : wimboot wimboot.i386 wimboot.x86_64 wimboot.cab
all : wimboot wimboot.i386 wimboot.x86_64 wimboot.arm64 wimboot.cab

wimboot : wimboot.x86_64 Makefile
$(CP) $< $@
Expand All @@ -152,7 +168,7 @@ wimboot.%.unsigned : wimboot.%.elf elf2efi32 Makefile
$(OBJCOPY_$*) -Obinary $< $@
./elf2efi32 --hybrid $< $@

wimboot.x86_64.unsigned : \
wimboot.x86_64.unsigned wimboot.arm64.unsigned : \
wimboot.%.unsigned : wimboot.%.elf elf2efi64 Makefile
$(OBJCOPY_$*) -Obinary $< $@
./elf2efi64 --hybrid $< $@
Expand All @@ -170,8 +186,8 @@ wimboot.% : wimboot.%.efi wimboot.%.efi.hash wimboot.%.unsigned.hash Makefile
$(DIFF) wimboot.$*.efi.hash wimboot.$*.unsigned.hash
$(CP) $< $@

wimboot.cab : wimboot.i386.efi wimboot.x86_64.efi Makefile
$(GCAB) -n -c $@ wimboot.i386.efi wimboot.x86_64.efi
wimboot.cab : wimboot.i386.efi wimboot.x86_64.efi wimboot.arm64.efi Makefile
$(GCAB) -n -c $@ wimboot.i386.efi wimboot.x86_64.efi wimboot.arm64.efi

###############################################################################
#
Expand Down Expand Up @@ -219,6 +235,24 @@ lib.x86_64.a : $(OBJECTS_x86_64) $(OBJECTS_i386_x86_64) Makefile
$(AR_x86_64) r $@ $(OBJECTS_x86_64) $(OBJECTS_i386_x86_64)
$(RANLIB_x86_64) $@

###############################################################################
#
# arm64 objects

%.arm64.s : %.S $(HEADERS) Makefile
$(CC_arm64) $(CFLAGS) $(CFLAGS_arm64) -DASSEMBLY -E $< -o $@

%.arm64.s : %.c $(HEADERS) Makefile
$(CC_arm64) $(CFLAGS) $(CFLAGS_arm64) -S $< -o $@

%.arm64.o : %.arm64.s Makefile
$(AS_arm64) $(ASFLAGS) $(ASFLAGS_arm64) $< -o $@

lib.arm64.a : $(OBJECTS_arm64) Makefile
$(RM) -f $@
$(AR_arm64) r $@ $(OBJECTS_arm64)
$(RANLIB_arm64) $@

###############################################################################
#
# EFI relocator
Expand All @@ -238,6 +272,7 @@ clean :
$(RM) -f elf2efi32 elf2efi64
$(RM) -f wimboot.i386 wimboot.i386.*
$(RM) -f wimboot.x86_64 wimboot.x86_64.*
$(RM) -f wimboot.arm64 wimboot.arm64.*
$(RM) -f wimboot wimboot.cab

.DELETE_ON_ERROR :

0 comments on commit 20a4a49

Please sign in to comment.