Skip to content

Commit

Permalink
initial support for building linux kernel with buildrump.sh
Browse files Browse the repository at this point in the history
This commit introduces a new options for buildrump.sh, which is '-l'
option to specify which rumpkernel (netbsd or linux) is used (default:
netbsd).  Linux kernel is based on Linux Kernel Library (LKL) with
non-upstreamed patches to implement with rump hypercall interfaces.

Since LKL is not yet upstreamed to Linus tree and development is still
ongoing, the commit tries to minimize future modifications to this
script (buildrump.sh) by specifying interfaces to build Linux kernel.

The new rumpkernel support involves the script structure refactor to
split each rumpkernel dependent commands into separate files (netbsd.sh
and linux.sh).

Currently, when '-l' option is specified, NetBSD rump kernel code will
be also built in addition to Linux kernel build since Linux part
requires headers files (i.e., include/rump) to build it.

A few more travis tests are also added though it's only build tests and
no execution tests for Linux at this moment though.  Plus, clang build
is marked as 'allow_failure' since Linux kernel isn't able to build with
clang so far.

There are still a couple of limitations:
- LKL_SRCDIR is hardcoded, which uses the current dir of the (root)
script.
- only build with standalone buildrump.sh.  standalone execution (i.e.,
without rumprun or frankenlibc) are not implemented since LKL itself has
to do it.
- thus, no standalone test are implemented either.

Signed-off-by: Hajime Tazaki <thehajime@gmail.com>
  • Loading branch information
thehajime committed Mar 30, 2017
1 parent 9c9b022 commit 238ed1f
Show file tree
Hide file tree
Showing 5 changed files with 361 additions and 177 deletions.
21 changes: 19 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
language: c
addons:
apt:
packages:
- bc
- libfuse-dev
- libarchive-dev
- xfsprogs
- btrfs-tools

compiler:
- gcc
Expand All @@ -7,17 +15,26 @@ compiler:
sudo: false

before_script:
- ./buildrump.sh checkout
- ./buildrump.sh ${RUMPKERNEL} checkout

env:
- NAME='static' LIBTYPE='MKPIC=no' BUILDTYPE='' TESTS='tests'
- NAME='dynamic' LIBTYPE='MKSTATICLIB=no' BUILDTYPE='' TESTS='tests'
- NAME='debug' LIBTYPE='MKSTATICLIB=no' BUILDTYPE='-DDD' TESTS='tests'
- NAME='release' LIBTYPE='MKSTATICLIB=no' BUILDTYPE='-r' TESTS='tests'
- NAME='fibers' LIBTYPE='MKSTATICLIB=no' BUILDTYPE='-V RUMPUSER_THREADS=fiber -V RUMP_CURLWP=hypercall' TESTS=''
- NAME='dynamic' LIBTYPE='MKSTATICLIB=no' BUILDTYPE='' TESTS='' RUMPKERNEL='-l linux'
- NAME='fibers' LIBTYPE='MKSTATICLIB=no' BUILDTYPE='-V RUMPUSER_THREADS=fiber -V RUMP_CURLWP=hypercall' TESTS='' RUMPKERNEL='-l linux'

matrix:
allow_failures:
- compiler: clang
env: NAME='dynamic' LIBTYPE='MKSTATICLIB=no' BUILDTYPE='' TESTS='' RUMPKERNEL='-l linux'
- compiler: clang
env: NAME='fibers' LIBTYPE='MKSTATICLIB=no' BUILDTYPE='-V RUMPUSER_THREADS=fiber -V RUMP_CURLWP=hypercall' TESTS='' RUMPKERNEL='-l linux'

script:
- ./buildrump.sh -o obj.${NAME} -d rump.${NAME} -qq -j16 -V ${LIBTYPE} ${BUILDTYPE} fullbuild ${TESTS}
- ./buildrump.sh ${RUMPKERNEL} -o obj.${NAME} -d rump.${NAME} -qq -j16 -V ${LIBTYPE} ${BUILDTYPE} fullbuild ${TESTS}

notifications:
irc:
Expand Down
206 changes: 31 additions & 175 deletions buildrump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ helpme ()
printf "\t-r: release build (no -g, DIAGNOSTIC, etc.). default: no\n"
printf "\t-D: increase debugginess. default: -O2 -g\n"
printf "\t-k: only kernel (no POSIX hypercalls). default: all\n"
printf "\t-l: choose a rumpkernel: netbsd or linux. default: netbsd\n"
echo
printf "\t-H: ignore diagnostic checks (expert-only). default: no\n"
printf "\t-V: specify -V arguments to NetBSD build (expert-only)\n"
Expand Down Expand Up @@ -289,19 +290,6 @@ doesitcxx ()
-x c++ - -o /dev/null $* > /dev/null 2>&1
}

checkcheckout ()
{

[ -x "${SRCDIR}/build.sh" ] || die "Cannot find ${SRCDIR}/build.sh!"

[ ! -z "${TARBALLMODE}" ] && return

if ! ${BRDIR}/checkout.sh checkcheckout ${SRCDIR} \
&& ! ${TITANMODE}; then
die 'revision mismatch, run checkout (or -H to override)'
fi
}

checkcompiler ()
{

Expand Down Expand Up @@ -556,6 +544,7 @@ int main() {gzopen(NULL, NULL); return 0;}' -lz \
else
cppname=cpp
fi
# NB: we need rumpmake to build libbmk_*, but rumpmake needs --netbsd TOOLTUPLES
tname=${BRTOOLDIR}/bin/${MACHINE_GNU_ARCH}--netbsd${TOOLABI}-${cppname}
printf '#!/bin/sh\n\nexec %s -E -x c "${@}"\n' ${CC} > ${tname}
chmod 755 ${tname}
Expand Down Expand Up @@ -616,8 +605,8 @@ EOF
appendmkconf Cmd yes RUMPKERN_ONLY
fi

if ${KERNONLY} && ! cppdefines __NetBSD__; then
appendmkconf 'Cmd' '-D__NetBSD__' 'CPPFLAGS' +
if ${KERNONLY} && ! cppdefines ${RUMPKERN_CPPFLAGS}; then
appendmkconf 'Cmd' "${RUMPKERN_CPPFLAGS}" 'CPPFLAGS' +
appendmkconf 'Probe' "${RUMPKERN_UNDEF}" 'CPPFLAGS' +
else
appendmkconf 'Probe' "${RUMPKERN_UNDEF}" "RUMPKERN_UNDEF"
Expand Down Expand Up @@ -654,8 +643,8 @@ EOF
exec 3>&1 1>${BRTOOLDIR}/toolchain-conf.mk
printf 'BUILDRUMP_TOOL_CFLAGS=%s\n' "${EXTRA_CFLAGS}"
printf 'BUILDRUMP_TOOL_CXXFLAGS=%s\n' "${EXTRA_CFLAGS}"
printf 'BUILDRUMP_TOOL_CPPFLAGS=-D__NetBSD__ %s %s\n' \
"${EXTRA_CPPFLAGS}" "${RUMPKERN_UNDEF}"
printf 'BUILDRUMP_TOOL_CPPFLAGS=%s %s %s\n' \
"${RUMPKERN_CPPFLAGS}" "${EXTRA_CPPFLAGS}" "${RUMPKERN_UNDEF}"
exec 1>&3 3>&-

chkcrt begins
Expand Down Expand Up @@ -754,120 +743,6 @@ makemake ()
[ $? -ne 0 ] && die build.sh ${cmd} failed
}

makebuild ()
{

checkcheckout

# ensure we're in SRCDIR, in case "tools" wasn't run
cd ${SRCDIR}

targets="obj includes dependall install"

#
# Building takes 4 passes, just like when
# building NetBSD the regular way. The passes are:
# 1) obj
# 2) includes
# 3) dependall
# 4) install
#

DIRS_first='lib/librumpuser'
DIRS_second='lib/librump'
DIRS_third="lib/librumpdev lib/librumpnet lib/librumpvfs
sys/rump/dev sys/rump/fs sys/rump/kern sys/rump/net
sys/rump/include ${BRDIR}/brlib"

# sys/rump/share was added to ${SRCDIR} 11/2014
[ -d ${SRCDIR}/sys/rump/share ] \
&& appendvar DIRS_second ${SRCDIR}/sys/rump/share

if [ ${MACHINE} = "i386" -o ${MACHINE} = "amd64" \
-o ${MACHINE#evbearm} != ${MACHINE} \
-o ${MACHINE#evbppc} != ${MACHINE} ]; then
DIRS_emul=sys/rump/kern/lib/libsys_linux
fi
${SYS_SUNOS} && appendvar DIRS_emul sys/rump/kern/lib/libsys_sunos
if ${HIJACK}; then
DIRS_final="lib/librumphijack"
else
DIRS_final=
fi

DIRS_third="${DIRS_third} ${DIRS_emul}"

if ${KERNONLY}; then
mkmakefile ${OBJDIR}/Makefile.all \
sys/rump ${DIRS_emul} ${BRDIR}/brlib
else
DIRS_third="lib/librumpclient ${DIRS_third}"

mkmakefile ${OBJDIR}/Makefile.first ${DIRS_first}
mkmakefile ${OBJDIR}/Makefile.second ${DIRS_second}
mkmakefile ${OBJDIR}/Makefile.third ${DIRS_third}
mkmakefile ${OBJDIR}/Makefile.final ${DIRS_final}
mkmakefile ${OBJDIR}/Makefile.all \
${DIRS_first} ${DIRS_second} ${DIRS_third} ${DIRS_final}
fi

# try to minimize the amount of domake invocations. this makes a
# difference especially on systems with a large number of slow cores
for target in ${targets}; do
if [ ${target} = "dependall" ] && ! ${KERNONLY}; then
domake ${OBJDIR}/Makefile.first ${target}
domake ${OBJDIR}/Makefile.second ${target}
domake ${OBJDIR}/Makefile.third ${target}
domake ${OBJDIR}/Makefile.final ${target}
else
domake ${OBJDIR}/Makefile.all ${target}
fi
done

if ! ${KERNONLY}; then
mkmakefile ${OBJDIR}/Makefile.utils \
usr.bin/rump_server usr.bin/rump_allserver \
usr.bin/rump_wmd
for target in ${targets}; do
domake ${OBJDIR}/Makefile.utils ${target}
done
fi
}

makeinstall ()
{

# ensure we run this in a directory that does not have a
# Makefile that could confuse rumpmake
stage=$(cd ${BRTOOLDIR} && ${RUMPMAKE} -V '${BUILDRUMP_STAGE}')
(cd ${stage}/usr ; tar -cf - .) | (cd ${DESTDIR} ; tar -xf -)
}

#
# install kernel headers.
# Note: Do _NOT_ do this unless you want to install a
# full rump kernel application stack
#
makekernelheaders ()
{

dodirs=$(cd ${SRCDIR}/sys && \
${RUMPMAKE} -V '${SUBDIR:Narch:Nmodules:Ncompat:Nnetnatm}' includes)
# missing some architectures
appendvar dodirs arch/amd64/include arch/i386/include arch/x86/include
appendvar dodirs arch/arm/include arch/arm/include/arm32
appendvar dodirs arch/evbarm64/include arch/aarch64/include
appendvar dodirs arch/evbppc/include arch/powerpc/include
appendvar dodirs arch/evbmips/include arch/mips/include
appendvar dodirs arch/riscv/include
for dir in ${dodirs}; do
(cd ${SRCDIR}/sys/${dir} && ${RUMPMAKE} obj)
(cd ${SRCDIR}/sys/${dir} && ${RUMPMAKE} includes)
done
# create machine symlink
(cd ${SRCDIR}/sys/arch && ${RUMPMAKE} NOSUBDIR=1 includes)
}

settool ()
{

Expand Down Expand Up @@ -1036,7 +911,9 @@ evaltoolchain ()

case ${CC_TARGET} in
*-linux*)
RUMPKERN_UNDEF='-Ulinux -U__linux -U__linux__ -U__gnu_linux__'
if [ ${RUMPKERNEL} != "linux" ]; then
RUMPKERN_UNDEF='-Ulinux -U__linux -U__linux__ -U__gnu_linux__'
fi
cppdefines _BIG_ENDIAN \
&& appendvar RUMPKERN_UNDEF -U_BIG_ENDIAN
cppdefines _LITTLE_ENDIAN \
Expand Down Expand Up @@ -1353,12 +1230,14 @@ parseargs ()
NOISE=2
debugginess=0
KERNONLY=false
RUMPKERNEL=netbsd
OBJDIR=./obj
DESTDIR=./rump
SRCDIR=./src
LKL_SRCDIR=./linux
JNUM=4

while getopts 'd:DhHj:ko:qrs:T:V:F:' opt; do
while getopts 'd:DhHj:kl:o:qrs:T:V:F:' opt; do
case "$opt" in
d)
DESTDIR=${OPTARG}
Expand Down Expand Up @@ -1419,6 +1298,9 @@ parseargs ()
k)
KERNONLY=true
;;
l)
RUMPKERNEL=${OPTARG}
;;
o)
OBJDIR=${OPTARG}
;;
Expand Down Expand Up @@ -1451,6 +1333,14 @@ parseargs ()
done
shift $((${OPTIND} - 1))

# load rump kernel specific scripts
if [ ${RUMPKERNEL} != "netbsd" -a ${RUMPKERNEL} != "linux" ]; then
echo '>> ERROR:'
echo '>> -l option (RUMPKERNEL) must be netbsd or linux'
exit 1
fi
. ${BRDIR}/${RUMPKERNEL}.sh

DBG="${F_DBG:-${DBG}}"

BEQUIET="-N${NOISE}"
Expand Down Expand Up @@ -1508,6 +1398,10 @@ parseargs ()
docheckout=true
checkoutstyle=cvs
fi
if ${docheckout} && [ ${RUMPKERNEL} = "linux" ] ; then
docheckout=true
checkoutstyle=linux-git
fi

# sanity checks
if [ ! -z "${TARBALLMODE}" ]; then
Expand Down Expand Up @@ -1542,6 +1436,7 @@ resolvepaths ()

abspath BRTOOLDIR
abspath SRCDIR
[ "${RUMPKERNEL}" = "linux" ] && abspath LKL_SRCDIR

RUMPMAKE="${BRTOOLDIR}/bin/brrumpmake"
BRIMACROS="${BRTOOLDIR}/include/opt_buildrump.h"
Expand Down Expand Up @@ -1572,40 +1467,7 @@ resolvepaths ()
done
}

# create the makefiles used for building
mkmakefile ()
{

makefile=$1
shift
exec 3>&1 1>${makefile}
printf '# GENERATED FILE, MIGHT I SUGGEST NOT EDITING?\n'
printf 'SUBDIR='
for dir in $*; do
case ${dir} in
/*)
printf ' %s' ${dir}
;;
*)
printf ' %s' ${SRCDIR}/${dir}
;;
esac
done

printf '\n.include <bsd.subdir.mk>\n'
exec 1>&3 3>&-
}

domake ()
{

mkfile=${1}; shift
mktarget=${1}; shift

[ ! -x ${RUMPMAKE} ] && die "No rumpmake (${RUMPMAKE}). Forgot tools?"
${RUMPMAKE} $* -j ${JNUM} -f ${mkfile} ${mktarget}
[ $? -eq 0 ] || die "make $mkfile $mktarget"
}

###
###
Expand All @@ -1624,7 +1486,7 @@ done

parseargs "$@"

${docheckout} && { ${BRDIR}/checkout.sh ${checkoutstyle} ${SRCDIR} || exit 1; }
${docheckout} && { ${BRDIR}/checkout.sh ${checkoutstyle} ${SRCDIR} ${LKL_SRCDIR} || exit 1; }

if ${doprobe} || ${dotools} || ${dobuild} || ${dokernelheaders} \
|| ${doinstall} || ${dotests}; then
Expand All @@ -1635,20 +1497,14 @@ if ${doprobe} || ${dotools} || ${dobuild} || ${dokernelheaders} \

${KERNONLY} || evalplatform

export RUMPKERNEL
${doprobe} && writeproberes
${dotools} && maketools
${dobuild} && makebuild
${dokernelheaders} && makekernelheaders
${doinstall} && makeinstall

if ${dotests}; then
if ${KERNONLY}; then
diagout 'Kernel-only; skipping tests (no hypervisor)'
else
. ${BRDIR}/tests/testrump.sh
alltests
fi
fi
${dotests} && maketests
fi

diagout buildrump.sh ran successfully
Expand Down

0 comments on commit 238ed1f

Please sign in to comment.