Skip to content

Commit

Permalink
Incorporate AMD SEV support in the main branch
Browse files Browse the repository at this point in the history
So far we kept AMD SEV support in a separate branch. In this commit
we incorporate it to the main branch and extend the build system
to be able to either build the regular kernel or the SEV one (if the
SEV=1 option is passed to make).

Signed-off-by: Sergio Lopez <[email protected]>
  • Loading branch information
slp committed Jun 7, 2022
1 parent 4cacd64 commit d11100f
Show file tree
Hide file tree
Showing 8 changed files with 2,559 additions and 7 deletions.
36 changes: 29 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ KERNEL_C_BUNDLE = kernel.c
ABI_VERSION=2
FULL_VERSION=2.1.1

ifeq ($(SEV),1)
VARIANT = -sev
KERNEL_PATCHES += $(shell find patches-sev/ -name "0*.patch" | sort)
endif

ARCH = $(shell uname -m)
OS = $(shell uname -s)

Expand All @@ -17,9 +22,9 @@ BUNDLE_SCRIPT_aarch64 = Image_to_bundle.py
KERNEL_BINARY_x86_64 = $(KERNEL_SOURCES)/vmlinux
KERNEL_BINARY_aarch64 = $(KERNEL_SOURCES)/arch/arm64/boot/Image

KRUNFW_BINARY_Linux = libkrunfw.so.$(FULL_VERSION)
KRUNFW_SONAME_Linux = libkrunfw.so.$(ABI_VERSION)
KRUNFW_BASE_Linux = libkrunfw.so
KRUNFW_BINARY_Linux = libkrunfw$(VARIANT).so.$(FULL_VERSION)
KRUNFW_SONAME_Linux = libkrunfw$(VARIANT).so.$(ABI_VERSION)
KRUNFW_BASE_Linux = libkrunfw$(VARIANT).so
SONAME_Linux = -Wl,-soname,$(KRUNFW_SONAME_Linux)

KRUNFW_BINARY_Darwin = libkrunfw.$(FULL_VERSION).dylib
Expand All @@ -34,6 +39,13 @@ ifeq ($(PREFIX),)
PREFIX := /usr/local
endif

ifeq ($(SEV),1)
QBOOT_BINARY = qboot/bios.bin
QBOOT_C_BUNDLE = qboot.c
INITRD_BINARY = initrd/initrd.gz
INITRD_C_BUNDLE = initrd.c
endif

.PHONY: all install clean

all: $(KRUNFW_BINARY_$(OS))
Expand All @@ -45,7 +57,7 @@ $(KERNEL_TARBALL):
$(KERNEL_SOURCES): $(KERNEL_TARBALL)
tar xf $(KERNEL_TARBALL)
for patch in $(KERNEL_PATCHES); do patch -p1 -d $(KERNEL_SOURCES) < "$$patch"; done
cp config-libkrunfw_$(ARCH) $(KERNEL_SOURCES)/.config
cp config-libkrunfw$(VARIANT)_$(ARCH) $(KERNEL_SOURCES)/.config
cd $(KERNEL_SOURCES) ; $(MAKE) olddefconfig

$(KERNEL_BINARY_$(ARCH)): $(KERNEL_SOURCES)
Expand All @@ -55,8 +67,18 @@ $(KERNEL_C_BUNDLE): $(KERNEL_BINARY_$(ARCH))
@echo "Generating $(KERNEL_C_BUNDLE) from $(KERNEL_BINARY_$(ARCH))..."
@python3 $(BUNDLE_SCRIPT_$(ARCH)) $(KERNEL_BINARY_$(ARCH))

$(KRUNFW_BINARY_$(OS)): $(KERNEL_C_BUNDLE)
gcc -fPIC -shared $(SONAME_$(OS)) -o $@ $(KERNEL_C_BUNDLE)
ifeq ($(SEV),1)
$(QBOOT_C_BUNDLE): $(QBOOT_BINARY)
@echo "Generating $(QBOOT_C_BUNDLE) from $(QBOOT_BINARY)..."
@python3 qboot_to_bundle.py $(QBOOT_BINARY)

$(INITRD_C_BUNDLE): $(INITRD_BINARY)
@echo "Generating $(INITRD_C_BUNDLE) from $(INITRD_BINARY)..."
@python3 initrd_to_bundle.py $(INITRD_BINARY)
endif

$(KRUNFW_BINARY_$(OS)): $(KERNEL_C_BUNDLE) $(QBOOT_C_BUNDLE) $(INITRD_C_BUNDLE)
gcc -fPIC -shared $(SONAME_$(OS)) -o $@ $(KERNEL_C_BUNDLE) $(QBOOT_C_BUNDLE) $(INITRD_C_BUNDLE)
ifeq ($(OS),Linux)
strip $(KRUNFW_BINARY_$(OS))
endif
Expand All @@ -67,4 +89,4 @@ install: $(KRUNFW_BINARY_$(OS))
cd $(DESTDIR)$(PREFIX)/$(LIBDIR_$(OS))/ ; ln -s $(KRUNFW_BINARY_$(OS)) $(KRUNFW_SONAME_$(OS)) ; ln -s $(KRUNFW_SONAME_$(OS)) $(KRUNFW_BASE_$(OS))

clean:
rm -fr $(KERNEL_SOURCES) $(KERNEL_C_BUNDLE) $(KRUNFW_BINARY_$(OS))
rm -fr $(KERNEL_SOURCES) $(KERNEL_C_BUNDLE) $(QBOOT_C_BUNDLE) $(INITRD_C_BUNDLE) $(KRUNFW_BINARY_$(OS))
Loading

0 comments on commit d11100f

Please sign in to comment.