Skip to content

Commit

Permalink
[efi] Switch from efireloc to elf2efi
Browse files Browse the repository at this point in the history
Import elf2efi.c from the iPXE repository and use it to perform the
conversion from ELF to PE format.

This removes the build dependency on libbfd, and opens up the
possibility of using cross-compiled ELF objects.

Signed-off-by: Michael Brown <[email protected]>
  • Loading branch information
mcb30 committed Nov 27, 2023
1 parent afd9f9e commit a49b707
Show file tree
Hide file tree
Showing 9 changed files with 1,301 additions and 747 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
run: |
sudo apt update
sudo apt install -y -o Acquire::Retries=50 \
binutils-dev libiberty-dev pesign gcab
pesign gcab
- name: Build
working-directory: src
run: |
Expand Down
2 changes: 1 addition & 1 deletion .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 \
binutils-dev libiberty-dev pesign gcab
pesign gcab
- name: Download Coverity Scan
run: |
curl --form token=${{ secrets.COVERITY_SCAN_TOKEN }} \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ jobs:
run: |
sudo apt update
sudo apt install -y -o Acquire::Retries=50 \
binutils-dev libiberty-dev pesign gcab \
pesign gcab \
qemu-system-x86 ovmf \
python3-libvirt python3-lxml python3-pil \
python3-qrcode python3-yaml python3-zbar
Expand Down
3 changes: 2 additions & 1 deletion src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ wimboot
*.unsigned
*.efi
*.cab
efireloc
elf2efi32
elf2efi64
23 changes: 11 additions & 12 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ PESIGN := pesign
DIFF := diff
GREP := grep
XARGS := xargs
BINUTILS_DIR := /usr
BFD_DIR := $(BINUTILS_DIR)
ZLIB_DIR := /usr

HOST_CFLAGS += -Wall -W -Werror

Expand Down Expand Up @@ -107,9 +104,13 @@ wimboot.%.elf : prefix.%.o lib.%.a script.lds Makefile
$(LD) -m elf_$* -T script.lds -o $@ -q -Map wimboot.$*.map \
prefix.$*.o lib.$*.a

wimboot.%.unsigned : wimboot.%.elf efireloc Makefile
wimboot.i386.unsigned : wimboot.i386.elf elf2efi32 Makefile
$(OBJCOPY) -Obinary $< $@
./efireloc $< $@
./elf2efi32 --hybrid $< $@

wimboot.x86_64.unsigned : wimboot.x86_64.elf elf2efi64 Makefile
$(OBJCOPY) -Obinary $< $@
./elf2efi64 --hybrid $< $@

wimboot.%.unsigned.hash : wimboot.%.unsigned Makefile
$(PESIGN) -h -i $< | $(XARGS) -n 1 $(ECHO) | $(GREP) -x '[0-9a-f]*' > $@
Expand Down Expand Up @@ -177,21 +178,19 @@ lib.x86_64.a : $(OBJECTS_x86_64) $(OBJECTS_i386_x86_64) Makefile
#
# EFI relocator

EFIRELOC_CFLAGS := -I$(BINUTILS_DIR)/include -I$(BFD_DIR)/include \
-I$(ZLIB_DIR)/include -idirafter . -DEFI_HOSTONLY
EFIRELOC_LDFLAGS := -L$(BINUTILS_DIR)/lib -L$(BFD_DIR)/lib -L$(ZLIB_DIR)/lib \
-lbfd -ldl -liberty -lz -Wl,--no-warn-search-mismatch
elf2efi32 : elf2efi.c Makefile
$(CC) $(HOST_CFLAGS) -idirafter . -DEFI_TARGET32 $< -o $@

efireloc : efireloc.c Makefile
$(CC) $(HOST_CFLAGS) $(EFIRELOC_CFLAGS) $< $(EFIRELOC_LDFLAGS) -o $@
elf2efi64 : elf2efi.c Makefile
$(CC) $(HOST_CFLAGS) -idirafter . -DEFI_TARGET64 $< -o $@

###############################################################################
#
# Cleanup

clean :
$(RM) -f *.s *.o *.a *.elf *.map
$(RM) -f efireloc
$(RM) -f elf2efi32 elf2efi64
$(RM) -f wimboot wimboot.i386 wimboot.x86_64 ../wimboot
$(RM) -f wimboot.i386.unsigned wimboot.x86_64.unsigned
$(RM) -f wimboot.i386.efi wimboot.x86_64.efi wimboot.cab
Loading

0 comments on commit a49b707

Please sign in to comment.