QEMU: Enabling a New Build Target/Option

If you happen to work on porting or adding new functionalities to QEMU. This post might be useful for you. Either you have a new architecture or a new feature in your brain. The first thing you have to do here is how to meld your new idea into it, so that the build system acknowledge your presence and work for you.

There are 3 files we have to work on in order to add new stuffs in QEMU.

  1. configure
  2. defaults-config/*.mak
  3. Makefile.objs

QEMU knows which files to be built by the following diagram.


configure

I just crop sections which relate to enabling here, so you can hop around configure file easily.

Add New Options’ Default Value

# default parameters 
source_path=`dirname "$0"` 
cpu="" iasl="iasl" 
interp_prefix="/usr/gnemul/qemu-%M" 
static="no" 
cross_prefix="" 
audio_drv_list=""

Add New Options

for opt do
 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
 case "$opt" in
 --cross-prefix=*) cross_prefix="$optarg"
 ;;
 --cc=*) CC="$optarg"
 ;;
 --cxx=*) CXX="$optarg"
 ;;
 --source-path=*) source_path="$optarg"
 ;;
 --cpu=*) cpu="$optarg"
 ;;

Add Help Text

Usage: configure [options]
Options: [defaults in brackets after descriptions]

Standard options:
 --help print this message
 --prefix=PREFIX install in PREFIX [$prefix]
 --interp-prefix=PREFIX where to find shared libraries, etc.
 use %M for cpu name [$interp_prefix]
 --target-list=LIST set target list (default: build everything)

Print out option variables

echo "Install prefix $prefix"
echo "BIOS directory `eval echo $qemu_datadir`"
echo "binary directory `eval echo $bindir`"
echo "library directory `eval echo $libdir`"
echo "module directory `eval echo $qemu_moddir`"

Use Big-Endian (if needed)

case "$target_name" in
 armeb|lm32|m68k|microblaze|mips|mipsn32|mips64|moxie|or32|ppc|ppcemb|ppc64|ppc64abi32|s390x|sh4eb|sparc|sparc64|sparc32plus|xtensaeb)
 target_bigendian=yes
 ;;
esac

Add Option Macro

if test "$linux" = "yes" ; then
 echo "CONFIG_LINUX=y" >> $config_host_mak
fi

if test "$darwin" = "yes" ; then
 echo "CONFIG_DARWIN=y" >> $config_host_mak
fi

if test "$aix" = "yes" ; then
 echo "CONFIG_AIX=y" >> $config_host_mak
fi

Define Architecture Specific Variables

TARGET_ARCH="$target_name"
TARGET_BASE_ARCH=""
TARGET_ABI_DIR=""

case "$target_name" in
 i386)
 ;;
 x86_64)
 TARGET_BASE_ARCH=i386
 ;;
 alpha)
 ;;
 arm|armeb)
 TARGET_ARCH=arm
 bflt="yes"
 gdb_xml_files="arm-core.xml arm-vfp.xml arm-vfp3.xml arm-neon.xml"
 ;;

Add Architecture Macro

for i in $ARCH $TARGET_BASE_ARCH ; do
 case "$i" in
 alpha)
 echo "CONFIG_ALPHA_DIS=y" >> $config_target_mak
 echo "CONFIG_ALPHA_DIS=y" >> config-all-disas.mak
 ;;
 aarch64)
 if test -n "${cxx}"; then
 echo "CONFIG_ARM_A64_DIS=y" >> $config_target_mak
 echo "CONFIG_ARM_A64_DIS=y" >> config-all-disas.mak
 fi
 ;;

 

default-configs/*.mak

This file contains default macros to be used in building for a specific target. Here are available targets for ARM

  1. arm-softmmu.mak
  2. arm-linux-user.mak
  3. armeb-linux-user.mak

Makefile.objs

You can find this file everywhere in QEMU source code. This file includes source code in its directory queued up for building.

Here is an example for ARM files.

// target-arm/Makefile.objs
obj-y += arm-semi.o
obj-$(CONFIG_SOFTMMU) += machine.o
obj-$(CONFIG_KVM) += kvm.o
obj-$(call land,$(CONFIG_KVM),$(call lnot,$(TARGET_AARCH64))) += kvm32.o
obj-$(call land,$(CONFIG_KVM),$(TARGET_AARCH64)) += kvm64.o
obj-$(call lnot,$(CONFIG_KVM)) += kvm-stub.o
obj-y += translate.o op_helper.o helper.o cpu.o
obj-y += neon_helper.o iwmmxt_helper.o
obj-y += gdbstub.o
obj-$(TARGET_AARCH64) += cpu64.o translate-a64.o helper-a64.o gdbstub64.o
obj-y += crypto_helper.o

What we have to do is adding a line as CONFIG_SOFTMMU with an option macro in configure. An object file to the right is obtained from the same source code name i.e. machine.o = machine.c

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s