Skip to content

Commit

Permalink
add eve efi application
Browse files Browse the repository at this point in the history
Signed-off-by: Shahriyar Jalayeri <shahriyar@zededa.com>
  • Loading branch information
shjala committed Oct 4, 2024
1 parent e7bb230 commit d396edd
Show file tree
Hide file tree
Showing 5 changed files with 764 additions and 1 deletion.
22 changes: 21 additions & 1 deletion pkg/dom0-ztools/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# syntax=docker/dockerfile-upstream:1.5.0-rc2-labs
FROM lfedge/eve-alpine:82df60e43ab9f8c935584b8c7b4d0a4b0271d608 as zfs
ENV BUILD_PKGS git patch ca-certificates util-linux build-base gettext-dev libtirpc-dev automake autoconf \
libtool linux-headers attr-dev e2fsprogs-dev glib-dev openssl-dev util-linux-dev coreutils
libtool linux-headers attr-dev e2fsprogs-dev glib-dev openssl-dev util-linux-dev coreutils gnu-efi gnu-efi-dev mtools
ENV PKGS ca-certificates util-linux libintl libuuid libtirpc libblkid libcrypto1.1 zlib
RUN eve-alpine-deploy.sh

Expand Down Expand Up @@ -42,6 +42,26 @@ RUN cp -r /tmp/zfs-out/* /out
# Add directory for CDI files
RUN mkdir -p /out/etc/cdi

# build dosfstools, the one that is in alpine (busybox) is too old
# and doesn't support creating small FAT filesystems.
WORKDIR /mkfs
ADD https://github.com/dosfstools/dosfstools.git#v4.2 dosfstools
RUN cd dosfstools && \
./autogen.sh && \
./configure --prefix=/mkfs/dosfstools/bin && \
make && \
make install
WORKDIR /efi
COPY efi/ .
RUN make all && \
mkdir -p /out/etc/ovmf && \
cp efi_run.sh /out/etc/ovmf/ && \
chmod +x /out/etc/ovmf/efi_run.sh && \
dd if=/dev/zero of=/out/etc/ovmf/eve_efi.img bs=1M count=1 && \
/mkfs/dosfstools/bin/sbin/mkfs.fat /out/etc/ovmf/eve_efi.img && \
mcopy -i /out/etc/ovmf/eve_efi.img startup.nsh :: && \
mcopy -i /out/etc/ovmf/eve_efi.img efi_eveutil.efi ::

FROM scratch
COPY --from=zfs /out/ /
# hadolint ignore=DL3020
Expand Down
32 changes: 32 additions & 0 deletions pkg/dom0-ztools/efi/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
ARCH = $(shell uname -m | sed s,i[3456789]86,ia32,)
OBJS = main.o
TARGE_SO = efi_eveutil.so
TARGET_EFI = efi_eveutil.efi
EFIINC = /usr/include/efi
EFIINCS = -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol
LIB = /usr/lib
EFILIB = /usr/lib
EFI_CRT_OBJS = $(EFILIB)/crt0-efi-$(ARCH).o
EFI_LDS = $(EFILIB)/elf_$(ARCH)_efi.lds

CFLAGS = $(EFIINCS) -fno-stack-protector -fpic \
-fshort-wchar -mno-red-zone -Wall -Werror
ifeq ($(ARCH),x86_64)
CFLAGS += -DEFI_FUNCTION_WRAPPER
endif

LDFLAGS = -nostdlib -znocombreloc -T $(EFI_LDS) -shared \
-Bsymbolic -L $(EFILIB) -L $(LIB) $(EFI_CRT_OBJS)

all: $(TARGET_EFI)

$(TARGE_SO): $(OBJS)
ld $(LDFLAGS) $(OBJS) -o $@ -lefi -lgnuefi

clean:
rm -f $(OBJS) $(TARGE_EFI) $(TARGE_SO)

%.efi: %.so
objcopy -j .text -j .sdata -j .data -j .dynamic \
-j .dynsym -j .rel -j .rela -j .reloc \
--target=efi-app-$(ARCH) $^ $@
11 changes: 11 additions & 0 deletions pkg/dom0-ztools/efi/efi_run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh
mkdir -p /run/kvm
cp /hostfs/etc/ovmf/eve_efi.img /run/kvm/eve_efi.img
/usr/lib/xen/bin/qemu-system-x86_64 \
-machine "type=pc-q35-3.1" \
-drive "if=pflash,unit=0,format=raw,readonly=on,file=/usr/lib/xen/boot/OVMF_CODE.fd" \
-drive "if=pflash,unit=1,format=raw,readonly=off,file=${1}" \
-drive "file=/run/kvm/eve_efi.img,format=raw" \
-smbios "type=11,value=${2}" \
-net none \
-nographic
Loading

0 comments on commit d396edd

Please sign in to comment.