f7add51c39
Raise an error if the host is using an older kernel than the target. Since qemu-user passes emulated system calls to the host kernel, this prevents usage of qemu-user in situations where those system calls will fail. This is based on an original patch from Frank Hunleth <fhunleth@troodon-software.com>, but completely rewritten in a different way: * Instead of using shell based testing, we use pure make tests, which allows to detect the problem not when host-qemu starts to build, but at the very beginning of the entire Buildroot build. * Instead of looking at $(STAGING_DIR)/usr/include/linux/version.h (which requires having a dependency on the 'toolchain' package, which is a bit unusual for a host package), we use the BR2_TOOLCHAIN_HEADERS_AT_LEAST Config.in option which tells us the version of the kernel headers used in the toolchain. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Tested-by: Frank Hunleth <fhunleth@troodon-software.com>
222 lines
7.1 KiB
Makefile
222 lines
7.1 KiB
Makefile
################################################################################
|
||
#
|
||
# qemu
|
||
#
|
||
################################################################################
|
||
|
||
QEMU_VERSION = 2.1.2
|
||
QEMU_SOURCE = qemu-$(QEMU_VERSION).tar.bz2
|
||
QEMU_SITE = http://wiki.qemu.org/download
|
||
QEMU_LICENSE = GPLv2 LGPLv2.1 MIT BSD-3c BSD-2c Others/BSD-1c
|
||
QEMU_LICENSE_FILES = COPYING COPYING.LIB
|
||
# NOTE: there is no top-level license file for non-(L)GPL licenses;
|
||
# the non-(L)GPL license texts are specified in the affected
|
||
# individual source files.
|
||
|
||
#-------------------------------------------------------------
|
||
# Host-qemu
|
||
|
||
HOST_QEMU_DEPENDENCIES = host-pkgconf host-zlib host-libglib2 host-pixman
|
||
|
||
# BR ARCH qemu
|
||
# ------- ----
|
||
# arm arm
|
||
# armeb armeb
|
||
# avr32 not supported
|
||
# bfin not supported
|
||
# i386 i386
|
||
# i486 i386
|
||
# i586 i386
|
||
# i686 i386
|
||
# x86_64 x86_64
|
||
# m68k m68k
|
||
# microblaze microblaze
|
||
# mips mips
|
||
# mipsel mipsel
|
||
# mips64 ?
|
||
# mips64el ?
|
||
# powerpc ppc
|
||
# sh2a not supported
|
||
# sh4 sh4
|
||
# sh4eb sh4eb
|
||
# sh4a ?
|
||
# sh4aeb ?
|
||
# sh64 not supported
|
||
# sparc sparc
|
||
|
||
HOST_QEMU_ARCH = $(ARCH)
|
||
ifeq ($(HOST_QEMU_ARCH),i486)
|
||
HOST_QEMU_ARCH = i386
|
||
endif
|
||
ifeq ($(HOST_QEMU_ARCH),i586)
|
||
HOST_QEMU_ARCH = i386
|
||
endif
|
||
ifeq ($(HOST_QEMU_ARCH),i686)
|
||
HOST_QEMU_ARCH = i386
|
||
endif
|
||
ifeq ($(HOST_QEMU_ARCH),powerpc)
|
||
HOST_QEMU_ARCH = ppc
|
||
endif
|
||
HOST_QEMU_TARGETS = $(HOST_QEMU_ARCH)-linux-user
|
||
|
||
ifeq ($(BR2_PACKAGE_HOST_QEMU),y)
|
||
HOST_QEMU_HOST_SYSTEM_TYPE = $(shell uname -s)
|
||
ifneq ($(HOST_QEMU_HOST_SYSTEM_TYPE),Linux)
|
||
$(error "qemu-user can only be used on Linux hosts")
|
||
endif
|
||
|
||
HOST_QEMU_HOST_SYSTEM_VERSION_MAJOR = $(shell uname -r | cut -f1 -d'.')
|
||
HOST_QEMU_HOST_SYSTEM_VERSION_MINOR = $(shell uname -r | cut -f2 -d'.')
|
||
HOST_QEMU_TARGET_SYSTEM_VERSION_MAJOR = $(shell echo $(BR2_TOOLCHAIN_HEADERS_AT_LEAST) | cut -f1 -d'.')
|
||
HOST_QEMU_TARGET_SYSTEM_VERSION_MINOR = $(shell echo $(BR2_TOOLCHAIN_HEADERS_AT_LEAST) | cut -f2 -d'.')
|
||
HOST_QEMU_COMPARE_VERSION_MAJOR = $(shell test $(HOST_QEMU_HOST_SYSTEM_VERSION_MAJOR) -ge $(HOST_QEMU_TARGET_SYSTEM_VERSION_MAJOR) && echo OK)
|
||
HOST_QEMU_COMPARE_VERSION_MINOR = $(shell test $(HOST_QEMU_HOST_SYSTEM_VERSION_MINOR) -ge $(HOST_QEMU_TARGET_SYSTEM_VERSION_MINOR) && echo OK)
|
||
|
||
#
|
||
# The principle of qemu-user is that it emulates the instructions of
|
||
# the target architecture when running the binary, and then when this
|
||
# binary does a system call, it converts this system call into a
|
||
# system call on the host machine. This mechanism makes an assumption:
|
||
# that the target binary will not do system calls that do not exist on
|
||
# the host. This basically requires that the target binary should be
|
||
# built with kernel headers that are older or the same as the kernel
|
||
# version running on the host machine.
|
||
#
|
||
ifneq ($(HOST_QEMU_COMPARE_VERSION_MAJOR)$(HOST_QEMU_COMPARE_VERSION_MINOR),OKOK)
|
||
$(error "Refusing to build qemu-user: target Linux version newer than host's.")
|
||
endif
|
||
endif
|
||
|
||
define HOST_QEMU_CONFIGURE_CMDS
|
||
cd $(@D); $(HOST_CONFIGURE_OPTS) ./configure \
|
||
--target-list="$(HOST_QEMU_TARGETS)" \
|
||
--prefix="$(HOST_DIR)/usr" \
|
||
--interp-prefix=$(STAGING_DIR) \
|
||
--cc="$(HOSTCC)" \
|
||
--host-cc="$(HOSTCC)" \
|
||
--extra-cflags="$(HOST_CFLAGS)" \
|
||
--extra-ldflags="$(HOST_LDFLAGS)"
|
||
endef
|
||
|
||
define HOST_QEMU_BUILD_CMDS
|
||
$(HOST_MAKE_ENV) $(MAKE) -C $(@D)
|
||
endef
|
||
|
||
define HOST_QEMU_INSTALL_CMDS
|
||
$(HOST_MAKE_ENV) $(MAKE) -C $(@D) install
|
||
endef
|
||
|
||
$(eval $(host-generic-package))
|
||
|
||
# variable used by other packages
|
||
QEMU_USER = $(HOST_DIR)/usr/bin/qemu-$(HOST_QEMU_ARCH)
|
||
|
||
#-------------------------------------------------------------
|
||
# Target-qemu
|
||
|
||
QEMU_DEPENDENCIES = host-pkgconf host-python libglib2 zlib pixman
|
||
|
||
# Need the LIBS variable because librt and libm are
|
||
# not automatically pulled. :-(
|
||
QEMU_LIBS = -lrt -lm
|
||
|
||
QEMU_OPTS =
|
||
|
||
QEMU_VARS = \
|
||
LIBTOOL=$(HOST_DIR)/usr/bin/libtool \
|
||
PYTHON=$(HOST_DIR)/usr/bin/python2 \
|
||
PYTHONPATH=$(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/site-packages
|
||
|
||
# If we want to specify only a subset of targets, we must still enable all
|
||
# of them, so that QEMU properly builds its list of default targets, from
|
||
# which it then checks if the specified sub-set is valid. That's what we
|
||
# do in the first part of the if-clause.
|
||
# Otherwise, if we do not want to pass a sub-set of targets, we then need
|
||
# to either enable or disable -user and/or -system emulation appropriately.
|
||
# That's what we do in the else-clause.
|
||
ifneq ($(call qstrip,$(BR2_PACKAGE_QEMU_CUSTOM_TARGETS)),)
|
||
QEMU_OPTS += --enable-system --enable-linux-user
|
||
QEMU_OPTS += --target-list="$(call qstrip,$(BR2_PACKAGE_QEMU_CUSTOM_TARGETS))"
|
||
else
|
||
|
||
ifeq ($(BR2_PACKAGE_QEMU_SYSTEM),y)
|
||
QEMU_OPTS += --enable-system
|
||
else
|
||
QEMU_OPTS += --disable-system
|
||
endif
|
||
|
||
ifeq ($(BR2_PACKAGE_QEMU_LINUX_USER),y)
|
||
QEMU_OPTS += --enable-linux-user
|
||
else
|
||
QEMU_OPTS += --disable-linux-user
|
||
endif
|
||
|
||
endif
|
||
|
||
ifeq ($(BR2_PACKAGE_QEMU_SDL),y)
|
||
QEMU_OPTS += --enable-sdl
|
||
QEMU_DEPENDENCIES += sdl
|
||
QEMU_VARS += SDL_CONFIG=$(BR2_STAGING_DIR)/usr/bin/sdl-config
|
||
else
|
||
QEMU_OPTS += --disable-sdl
|
||
endif
|
||
|
||
ifeq ($(BR2_PACKAGE_QEMU_FDT),y)
|
||
QEMU_OPTS += --enable-fdt
|
||
QEMU_DEPENDENCIES += dtc
|
||
else
|
||
QEMU_OPTS += --disable-fdt
|
||
endif
|
||
|
||
define QEMU_CONFIGURE_CMDS
|
||
( cd $(@D); \
|
||
LIBS='$(QEMU_LIBS)' \
|
||
$(TARGET_CONFIGURE_OPTS) \
|
||
$(TARGET_CONFIGURE_ARGS) \
|
||
$(QEMU_VARS) \
|
||
./configure \
|
||
--prefix=/usr \
|
||
--cross-prefix=$(TARGET_CROSS) \
|
||
--with-system-pixman \
|
||
--audio-drv-list= \
|
||
--enable-kvm \
|
||
--enable-attr \
|
||
--enable-vhost-net \
|
||
--disable-bsd-user \
|
||
--disable-xen \
|
||
--disable-slirp \
|
||
--disable-vnc \
|
||
--disable-virtfs \
|
||
--disable-brlapi \
|
||
--disable-curses \
|
||
--disable-curl \
|
||
--disable-bluez \
|
||
--disable-guest-base \
|
||
--disable-uuid \
|
||
--disable-vde \
|
||
--disable-linux-aio \
|
||
--disable-cap-ng \
|
||
--disable-docs \
|
||
--disable-spice \
|
||
--disable-rbd \
|
||
--disable-libiscsi \
|
||
--disable-usb-redir \
|
||
--disable-smartcard-nss \
|
||
--disable-strip \
|
||
--disable-seccomp \
|
||
--disable-sparse \
|
||
--disable-tools \
|
||
$(QEMU_OPTS) \
|
||
)
|
||
endef
|
||
|
||
define QEMU_BUILD_CMDS
|
||
$(TARGET_MAKE_ENV) $(MAKE) -C $(@D)
|
||
endef
|
||
|
||
define QEMU_INSTALL_TARGET_CMDS
|
||
$(TARGET_MAKE_ENV) $(MAKE) -C $(@D) $(QEMU_MAKE_ENV) DESTDIR=$(TARGET_DIR) install
|
||
endef
|
||
|
||
$(eval $(generic-package))
|