aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2017-09-01 15:48:52 +0200
committerGerd Hoffmann <kraxel@redhat.com>2017-11-14 16:03:18 +0100
commit1761de60f0468d93a0f218f021e6e0e309ba0007 (patch)
treece806373ed9ecc739e0f497d95edcd734caefa39
parentd80f44e011942eff4c97e98ace8e4219ef96a5ce (diff)
downloadqemu-firmware-1761de60f0468d93a0f218f021e6e0e309ba0007.tar.gz
Add Makefile, add build rules for edk2
Based on roms/Makefile in qemu repo. Paths have been adapted to qemu-firmware repo layout. "make install" target has been added. "make help" text is more verbose. edk2 build rules and helper script added. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
-rw-r--r--Makefile82
-rwxr-xr-xscripts/compile-edk2.sh61
2 files changed, 143 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..a6a4e1a
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,82 @@
+# directories
+DESTDIR ?=
+prefix ?= /usr/local
+datadir := $(DESTDIR)$(prefix)/share/qemu-firmware
+
+
+#############################################################################
+# cross compiler auto detection
+
+path := $(subst :, ,$(PATH))
+system := $(shell uname -s | tr "A-Z" "a-z")
+
+# first find cross binutils in path
+find-cross-ld = $(firstword $(wildcard $(patsubst %,%/$(1)-*$(system)*-ld,$(path))))
+# then check we have cross gcc too
+find-cross-gcc = $(firstword $(wildcard $(patsubst %ld,%gcc,$(call find-cross-ld,$(1)))))
+# finally strip off path + toolname so we get the prefix
+find-cross-prefix = $(subst gcc,,$(notdir $(call find-cross-gcc,$(1))))
+
+powerpc64_cross_prefix := $(call find-cross-prefix,powerpc64)
+powerpc_cross_prefix := $(call find-cross-prefix,powerpc)
+x86_64_cross_prefix := $(call find-cross-prefix,x86_64)
+arm_cross_prefix := $(call find-cross-prefix,arm)
+aarch64_cross_prefix := $(call find-cross-prefix,aarch64)
+
+
+#############################################################################
+# help text, common rules and targets
+
+default help:
+ @echo
+ @echo "nothing is done by default"
+ @echo
+ @echo "build targets:"
+ @echo " edk2 -- build UEFI firmware"
+ @echo
+ @echo "other targets:"
+ @echo " clean -- cleanup"
+ @echo " install -- install blobs to $(datadir)"
+ @echo
+ @echo "You can set DESTDIR and prefix on the command line to"
+ @echo "to change the install target directory, for example:"
+ @echo "$ make prefix=/usr install"
+ @echo
+
+install:
+ mkdir -p $(datadir)
+ cp -avr blobs/edk2-* $(datadir)
+
+clean: edk2-clean
+
+submodule-%:
+ git submodule update --init repos/$*
+
+
+#############################################################################
+# edk2 build rules
+
+edk2 uefi: edk2-i386 edk2-x86_64 edk2-arm edk2-aarch64
+
+edk2-i386: submodule-edk2
+ sh scripts/compile-edk2.sh i386 $(x86_64_cross_prefix)
+
+edk2-x86_64: submodule-edk2
+ sh scripts/compile-edk2.sh x86_64 $(x86_64_cross_prefix)
+
+edk2-arm: submodule-edk2
+ sh scripts/compile-edk2.sh arm $(arm_cross_prefix)
+
+edk2-aarch64: submodule-edk2
+ sh scripts/compile-edk2.sh aarch64 $(aarch64_cross_prefix)
+
+edk2-tools: submodule-edk2
+ make -C repos/edk2/BaseTools
+
+edk2-clean:
+ make -C repos/edk2/BaseTools clean
+ rm -rf repos/edk2/Build
+ rm -rf repos/edk2/Conf/BuildEnv.sh
+ rm -rf repos/edk2/Conf/build_rule.txt
+ rm -rf repos/edk2/Conf/target.txt
+ rm -rf repos/edk2/Conf/tools_def.txt
diff --git a/scripts/compile-edk2.sh b/scripts/compile-edk2.sh
new file mode 100755
index 0000000..d940381
--- /dev/null
+++ b/scripts/compile-edk2.sh
@@ -0,0 +1,61 @@
+#!/bin/sh
+
+# args
+arch="$1"
+cross="$2"
+
+# figure gcc version, set cross build prefix vars
+gccver=$(${cross}gcc --version \
+ | awk '{ print $3; exit}' \
+ | cut -d. -f1,2 \
+ | tr -d ".")
+case "$gccver" in
+4*) # nothing, keep "4x"
+ ;;
+5* | 6* | 7*)
+ gccver=5
+ ;;
+esac
+toolchain="GCC$gccver"
+
+eval "export GCC${gccver}_IA32_PREFIX=${cross}"
+eval "export GCC${gccver}_X64_PREFIX=${cross}"
+eval "export GCC${gccver}_ARM_PREFIX=${cross}"
+eval "export GCC${gccver}_AARCH64_PREFIX=${cross}"
+
+# what we are going to build?
+case "$arch" in
+i386)
+ efiarch="IA32"
+ project="OvmfPkg/OvmfPkgIa32.dsc"
+ match="OvmfIa32/*/FV/OVMF*.fd"
+ ;;
+x86_64)
+ efiarch="X64"
+ project="OvmfPkg/OvmfPkgX64.dsc"
+ match="OvmfX64/*/FV/OVMF*.fd"
+ ;;
+arm | aarch64)
+ efiarch="$(echo $arch | tr 'a-z' 'A-Z')"
+ project="ArmVirtPkg/ArmVirtQemu.dsc"
+ match="ArmVirtQemu-${efiarch}/*/FV/QEMU_*.fd"
+ ;;
+esac
+
+# setup edk2 build environment
+cd repos/edk2
+source ./edksetup.sh --reconfig
+bopts=""
+bopts="$bopts -t $toolchain"
+bopts="$bopts -D HTTP_BOOT_ENABLE"
+bopts="$bopts -a $efiarch"
+bopts="$bopts -p $project"
+
+# go build everything
+make -C BaseTools || exit 1
+build $bopts || exit 1
+
+# copy over results
+dest="../../blobs/edk2-${arch}"
+mkdir -p "$dest"
+cp -v Build/${match} "$dest"