summaryrefslogtreecommitdiffhomepage
path: root/src/tests/qemu
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-04-12 18:29:38 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2017-04-14 14:28:43 +0200
commitc865218afdf03e3b6305dbfe2dd3c4d2df67bfa7 (patch)
treee9f37016936be10fffda7a17532f98db7061e472 /src/tests/qemu
parentec6816a206cc20b42909932324ba6f6505e8c767 (diff)
qemu: work on ARM64
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/tests/qemu')
-rw-r--r--src/tests/qemu/Makefile20
-rw-r--r--src/tests/qemu/init.c4
-rw-r--r--src/tests/qemu/kernel.config2
3 files changed, 21 insertions, 5 deletions
diff --git a/src/tests/qemu/Makefile b/src/tests/qemu/Makefile
index a9ce0a6..7c63eb9 100644
--- a/src/tests/qemu/Makefile
+++ b/src/tests/qemu/Makefile
@@ -13,7 +13,8 @@ DOWNLOAD := wget -O
MIRROR := https://download.wireguard.io/qemu-test/distfiles/
-CHOST := x86_64-pc-linux-gnu
+CHOST := $(shell gcc -dumpmachine)
+ARCH := $(shell uname -m)
WIREGUARD_SOURCES := $(wildcard ../../*.c ../../*.h ../../selftest/*.h ../../crypto/*.c ../../crypto/*.h ../../crypto/*.S ../../compat/*.h)
TOOLS_SOURCES := $(wildcard ../../tools/*.c ../../tools*.h ../../uapi.h)
@@ -41,7 +42,6 @@ KERNEL_URL_DIRECTORY := https://cdn.kernel.org/pub/linux/kernel/v$(firstword $(s
endif
$(eval $(call tar_download,KERNEL,linux,$(KERNEL_VERSION),.tar.xz,$(KERNEL_URL_DIRECTORY)))
-KERNEL_BZIMAGE := $(KERNEL_PATH)/arch/x86/boot/bzImage
$(eval $(call tar_download,MUSL,musl,1.1.15,.tar.gz,https://www.musl-libc.org/releases/))
$(eval $(call tar_download,LIBMNL,libmnl,1.0.4,.tar.bz2,http://ftp.netfilter.org/pub/libmnl/))
$(eval $(call tar_download,IPERF,iperf,3.1.3,.tar.gz,http://downloads.es.net/pub/iperf/))
@@ -50,6 +50,16 @@ $(eval $(call tar_download,IPROUTE2,iproute2,4.3.0,.tar.gz,http://www.kernel.org
$(eval $(call tar_download,IPTABLES,iptables,1.6.0,.tar.bz2,http://ftp.netfilter.org/pub/iptables/))
$(eval $(call tar_download,NMAP,nmap,7.25BETA1,.tar.bz2,http://nmap.org/dist/))
+ifeq ($(ARCH),aarch64)
+KERNEL_ARCH := arm64
+KERNEL_BZIMAGE := $(KERNEL_PATH)/arch/arm64/boot/Image
+QEMU_MACHINE := -machine virt,accel=kvm,gic_version=host
+else
+KERNEL_ARCH := $(ARCH)
+KERNEL_BZIMAGE := $(KERNEL_PATH)/arch/x86/boot/bzImage
+QEMU_MACHINE := -machine q35,accel=kvm
+endif
+
IPUTILS_VERSION := s20160308
IPUTILS_TAR := $(DISTFILES_PATH)/$(IPUTILS_VERSION).tar.gz
IPUTILS_PATH := $(BUILD_PATH)/iputils-$(IPUTILS_VERSION)
@@ -62,10 +72,10 @@ MUSL_CC := $(BUILD_PATH)/musl-gcc
qemu: $(KERNEL_BZIMAGE)
rm -f $(BUILD_PATH)/result
- qemu-system-x86_64 \
+ qemu-system-$(ARCH) \
-nodefaults \
-nographic \
- -machine q35,accel=kvm \
+ $(QEMU_MACHINE) \
-cpu host \
-smp $(NR_CPUS) \
-m 96M \
@@ -113,7 +123,7 @@ $(KERNEL_PATH)/.installed: $(KERNEL_TAR)
$(KERNEL_PATH)/.config: kernel.config | $(KERNEL_PATH)/.installed
cp kernel.config $(KERNEL_PATH)/minimal.config
printf 'CONFIG_NR_CPUS=$(NR_CPUS)\nCONFIG_INITRAMFS_SOURCE="$(BUILD_PATH)/init-cpio-spec.txt"\n' >> $(KERNEL_PATH)/minimal.config
- $(MAKE) -C $(KERNEL_PATH) ARCH=x86_64 allnoconfig
+ $(MAKE) -C $(KERNEL_PATH) ARCH=$(KERNEL_ARCH) allnoconfig
cd $(KERNEL_PATH) && scripts/kconfig/merge_config.sh -n .config minimal.config
-[ "$(DEBUG_KERNEL)" = "yes" ] && ( cd $(KERNEL_PATH) && scripts/kconfig/merge_config.sh -n .config $(PWD)/debug.config )
diff --git a/src/tests/qemu/init.c b/src/tests/qemu/init.c
index f65b132..38df1aa 100644
--- a/src/tests/qemu/init.c
+++ b/src/tests/qemu/init.c
@@ -24,8 +24,12 @@
{
fflush(stdout);
fflush(stderr);
+#if defined(__x86_64__) || defined(__i386__)
ioperm(0x604, 2, 1);
outw(1 << 13, 0x604);
+#else
+ reboot(RB_POWER_OFF);
+#endif
sleep(30);
fprintf(stderr, "\x1b[37m\x1b[41m\x1b[1mFailed to power off!!!\x1b[0m\n");
exit(1);
diff --git a/src/tests/qemu/kernel.config b/src/tests/qemu/kernel.config
index c6cc5c9..4e4f573 100644
--- a/src/tests/qemu/kernel.config
+++ b/src/tests/qemu/kernel.config
@@ -22,6 +22,8 @@ CONFIG_BINFMT_ELF=y
CONFIG_BINFMT_SCRIPT=y
CONFIG_PCI=y
CONFIG_PCI_MSI=y
+CONFIG_PCI_HOST_COMMON=y
+CONFIG_PCI_HOST_GENERIC=y
CONFIG_VIRTUALIZATION=y
CONFIG_HYPERVISOR_GUEST=y
CONFIG_PARAVIRT=y