runx: introduce xen OCI container recipe

This is the initial version of the runX OCI wrapper to allow Xen based virtual
machines to be launched and managed as containers via an OCI interface.

In this first version, runx consists of the following components:

  - runX binary/wrapper (/usr/bin/)
  - state control wrappers (/usr/share/runX)
  - runx kernel
  - initrd

Once built and installed these allow the launching of Xen virtual machines
in an OCI compliant manner.

Dependencies of this recipe include:

  - kernel: must be a specific version, currently 4.15. This is done as
            a nested build and not as a multiconfig (by design).
  - static target busybox: used for the initrd
  - initrd: constructed from the kernel + busybox

The configuration of the system to build the dependencies in the right
mode for use in runX is controlled via the DISTRO_FEATURE "vmsep". If
this feature is missing, and runx is bitbaked, an error is thrown.

Installing the "runx" package to a rootfs will install all the required
support components (and dependencies).

Signed-off-by: Bruce Ashfield <bruce.ashfield@xilinx.com>
This commit is contained in:
Bruce Ashfield 2019-12-17 17:25:31 -08:00 committed by Bruce Ashfield
parent 7a8ee8e986
commit 4ff05c1bc7
3 changed files with 282 additions and 0 deletions

View File

@ -0,0 +1,42 @@
From d8bd5749e6fc6e0c86a8720044ec78167bab3569 Mon Sep 17 00:00:00 2001
From: Bruce Ashfield <bruce.ashfield@xilinx.com>
Date: Mon, 16 Dec 2019 22:03:14 -0800
Subject: [PATCH] make-initrd: cross install tweaks
Signed-off-by: Bruce Ashfield <bruce.ashfield@xilinx.com>
---
kernel/make-initrd | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/kernel/make-initrd b/kernel/make-initrd
index 4c299dc..9ef386f 100755
--- a/kernel/make-initrd
+++ b/kernel/make-initrd
@@ -16,8 +16,22 @@ mkdir -p $tmpdir/sys
mkdir -p $tmpdir/lib
mkdir -p $tmpdir/var
mkdir -p $tmpdir/mnt
-cp `which busybox` $tmpdir/bin
-$tmpdir/bin/busybox --install $tmpdir/bin
+
+
+if [ -z "$BUSYBOX" ]; then
+ BUSYBOX=`which busybox`
+fi
+cp $BUSYBOX $tmpdir/bin
+if [ -n "$CROSS_COMPILE" ]; then
+ echo "cross compiling, busybox --install emulation"
+ if [ -n "$QEMU_USER" ]; then
+ $QEMU_USER $tmpdir/bin/busybox --install $tmpdir/bin
+ else
+ echo "QEMU_USER is not defined, no binary symlinks will be available"
+ fi
+else
+ $tmpdir/bin/busybox --install $tmpdir/bin
+fi
cp $init $tmpdir/init
chmod +x $tmpdir/init
--
2.17.1

View File

@ -0,0 +1,86 @@
From 7e3498ab7c375bd545de501920acffa77eb24120 Mon Sep 17 00:00:00 2001
From: Bruce Ashfield <bruce.ashfield@xilinx.com>
Date: Mon, 16 Dec 2019 20:42:04 -0800
Subject: [PATCH] make-kernel: cross-compilation tweaks
Signed-off-by: Bruce Ashfield <bruce.ashfield@xilinx.com>
---
kernel/make-kernel | 41 +++++++++++++++++++++++++++++++++--------
1 file changed, 33 insertions(+), 8 deletions(-)
diff --git a/kernel/make-kernel b/kernel/make-kernel
index 33b7150..c684669 100755
--- a/kernel/make-kernel
+++ b/kernel/make-kernel
@@ -13,6 +13,7 @@ fi
kernel_stuffdir=`readlink -f kernel`
kernel_outpath=$kernel_stuffdir/out
+kernel_srcdir=$kernel_stuffdir/src
kernel_builddir=$kernel_stuffdir/build
kernel_out=$kernel_outpath/kernel
@@ -22,28 +23,52 @@ kernel_tarball="$kernel_name".tar.xz
kernel_url=https://www.kernel.org/pub/linux/kernel/v4.x/"$kernel_tarball"
kernel_src_config="$kernel_stuffdir"/cutdown-config.$ARCH
kernel_patchesdir="$kernel_stuffdir"/patches
-kernel_image="$kernel_builddir"/"$kernel_name"/arch/"$ARCH"/boot/"$image"
+kernel_image="$kernel_builddir"/arch/"$ARCH"/boot/"$image"
+echo "#########################"
+echo "kernel build summary:"
+echo " version: $kernel_version"
+echo " url: $kernel_url"
+echo " src dir: $kernel_srcdir"
+echo " out dir: $kernel_builddir"
+echo " artifacts: $kernel_out"
+echo " image: $image"
+echo " build vars: $build_vars"
+echo "#########################"
-rm -rf $kernel_outpath
+if [ ! -e "$kernel_builddir/.config" ];
+then
+ rm -rf $kernel_buildir
+fi
mkdir -p $kernel_outpath
mkdir -p $kernel_builddir
+mkdir -p $kernel_srcdir
if [[ ! -f $kernel_builddir/$kernel_tarball ]]
then
+ echo "fetching the kernel .."
wget -O $kernel_builddir/$kernel_tarball --tries=20 $kernel_url
fi
-if [[ ! -d $kernel_builddir/$kernel_name ]]
+
+if [[ ! -d $kernel_srcdir/$kernel_name ]]
then
- tar --extract --xz --touch --file="$kernel_builddir/$kernel_tarball" --directory="$kernel_builddir"
- cd $kernel_builddir/$kernel_name
+ echo "extracting the kernel ..."
+ echo " tar --extract --xz --touch --file=\"$kernel_builddir/$kernel_tarball\" --directory=\"$kernel_srcdir\""
+ tar --extract --xz --touch --file="$kernel_builddir/$kernel_tarball" --directory="$kernel_srcdir"
+ cd $kernel_srcdir/$kernel_name
for i in $kernel_patchesdir/*
do
patch -p1 < $i
done
- cp $kernel_src_config .config
fi
-cd $kernel_builddir/$kernel_name
-make -j4 $image
+if [[ ! -f $kernel_builddir/.config ]]
+then
+ cp $kernel_src_config $kernel_builddir/.config
+fi
+cd $kernel_srcdir/$kernel_name
+
+echo "building the kernel ..."
+eval make O=$kernel_builddir $build_vars oldconfig
+eval make -j4 O=$kernel_builddir $build_vars $image
cp $kernel_image $kernel_out
--
2.17.1

View File

@ -0,0 +1,154 @@
HOMEPAGE = "https://github.com/lf-edge/runx"
SUMMARY = "runx stuff"
DESCRIPTION = "Xen Runtime for OCI"
SRCREV_runx = "a6fe5ca3081f44e9085972d424c74707d4f0fc71"
SRC_URI = "\
git://github.com/lf-edge/runx;nobranch=1;name=runx \
https://www.kernel.org/pub/linux/kernel/v4.x/linux-4.15.tar.xz;destsuffix=git/kernel/build \
file://0001-make-kernel-cross-compilation-tweaks.patch \
file://0001-make-initrd-cross-install-tweaks.patch \
"
SRC_URI[md5sum] = "0d701ac1e2a67d47ce7127432df2c32b"
SRC_URI[sha256sum] = "5a26478906d5005f4f809402e981518d2b8844949199f60c4b6e1f986ca2a769"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://LICENSE;md5=945fc9aa694796a6337395cc291ddd8c"
S = "${WORKDIR}/git"
PV = "0.1-git${SRCREV_runx}"
inherit distro_features_check
REQUIRED_DISTRO_FEATURES = "vmsep"
# TODO: for if we need a go shim
# GO_IMPORT = "import"
# inherit go
# inherit goarch
inherit pkgconfig
# for the kernel build
inherit kernel-arch
# we have a busybox bbappend that makes /bin available to the
# sysroot, and hence gets us the target binary that we need
DEPENDS = "busybox"
# for the kernel build phase
DEPENDS += "openssl-native coreutils-native util-linux-native xz-native bc-native"
DEPENDS += "qemu-native"
RDEPENDS_${PN} += " jq bash"
RDEPENDS_${PN} += " xen-xl"
do_compile() {
# we'll need this for the initrd later, so lets error if it isn't what
# we expect (statically linked)
file ${STAGING_DIR_HOST}/bin/busybox.nosuid
# prep steps to short circuit some of make-kernel's fetching and
# building.
mkdir -p ${S}/kernel/build
mkdir -p ${S}/kernel/src
cp ${DL_DIR}/linux-4.15.tar.xz ${S}/kernel/build/
# In the future, we might want to link the extracted kernel source (if
# we move patches to recipe space, but for now, we need make-kernel to
# extract a copy and possibly patch it.
# ln -sf ${WORKDIR}/linux-4.15 ${S}/kernel/src/
# build the kernel
echo "[INFO]: runx: building the kernel"
export KERNEL_CC="${KERNEL_CC}"
export KERNEL_LD="${KERNEL_LD}"
export ARCH="${ARCH}"
export HOSTCC="${BUILD_CC} ${BUILD_CFLAGS} ${BUILD_LDFLAGS}"
export HOSTCPP="${BUILD_CPP}"
export CROSS_COMPILE="${CROSS_COMPILE}"
export build_vars="HOSTCC='$HOSTCC' STRIP='$STRIP' OBJCOPY='$OBJCOPY' ARCH=$ARCH CC='$KERNEL_CC' LD='$KERNEL_LD'"
unset CFLAGS CPPFLAGS CXXFLAGS LDFLAGS MACHINE
# We want make-kernel, to have the following build lines:
# make O=$kernel_builddir HOSTCC="${HOSTCC}" ARCH=$ARCH oldconfig
# make -j4 O=$kernel_builddir HOSTCC="${HOSTCC}" STRIP="$STRIP" OBJCOPY="$OBJCOPY" ARCH=$ARCH CC="$KERNEL_CC" LD="$KERNEL_LD" $image
${S}/kernel/make-kernel
# construct the initrd
echo "[INFO]: runx: constructing the initrd"
cp ${STAGING_DIR_HOST}/bin/busybox.nosuid ${WORKDIR}/busybox
export QEMU_USER=`which qemu-${HOST_ARCH}`
export BUSYBOX="${WORKDIR}/busybox"
export CROSS_COMPILE="t"
${S}/kernel/make-initrd
}
do_build_go_shim() {
# placeholder for any go shim code we may need, i.e. console
# export GOARCH="${TARGET_GOARCH}"
# export GOROOT="${STAGING_LIBDIR_NATIVE}/${TARGET_SYS}/go"
# export GOPATH="${S}/src/import:${S}/src/import/vendor"
# # Pass the needed cflags/ldflags so that cgo
# # can find the needed headers files and libraries
# export CGO_ENABLED="1"
# export CFLAGS=""
# export LDFLAGS=""
# export CGO_CFLAGS="${BUILDSDK_CFLAGS} --sysroot=${STAGING_DIR_TARGET}"
# export CGO_LDFLAGS="${BUILDSDK_LDFLAGS} --sysroot=${STAGING_DIR_TARGET}"
# # link fixups for compilation
# rm -f ${S}/src/import/vendor/src
# ln -sf ./ ${S}/src/import/vendor/src
# mkdir -p ${S}/src/import/vendor/github.com/hyperhq/runv
# ln -sf src/import/cli
# ln -sf ../../../../api ${S}/src/import/vendor/github.com/hyperhq/runv/api
# ln -sf ../../../../cli ${S}/src/import/vendor/github.com/hyperhq/runv/cli
# ln -sf ../../../../lib ${S}/src/import/vendor/github.com/hyperhq/runv/lib
# ln -sf ../../../../driverloader ${S}/src/import/vendor/github.com/hyperhq/runv/driverloader
# ln -sf ../../../../factory ${S}/src/import/vendor/github.com/hyperhq/runv/factory
# ln -sf ../../../../hyperstart ${S}/src/import/vendor/github.com/hyperhq/runv/hyperstart
# ln -sf ../../../../hypervisor ${S}/src/import/vendor/github.com/hyperhq/runv/hypervisor
# ln -sf ../../../../template ${S}/src/import/vendor/github.com/hyperhq/runv/template
# export GOPATH="${S}/src/import/.gopath:${S}/src/import/vendor:${STAGING_DIR_TARGET}/${prefix}/local/go"
# export GOROOT="${STAGING_DIR_NATIVE}/${nonarch_libdir}/${HOST_SYS}/go"
# # Pass the needed cflags/ldflags so that cgo
# # can find the needed headers files and libraries
# export CGO_ENABLED="1"
# export CGO_CFLAGS="${CFLAGS} --sysroot=${STAGING_DIR_TARGET}"
# export CGO_LDFLAGS="${LDFLAGS} --sysroot=${STAGING_DIR_TARGET}"
# oe_runmake build-shim
true
}
do_install() {
install -d ${D}${bindir}
install -m 755 ${S}/runX ${D}${bindir}
install -d ${D}${datadir}/runX
install -m 755 ${S}/kernel/out/kernel ${D}/${datadir}/runX
install -m 755 ${S}/kernel/out/initrd ${D}/${datadir}/runX
install -m 755 ${S}/files/start ${D}/${datadir}/runX
install -m 755 ${S}/files/state ${D}/${datadir}/runX
install -m 755 ${S}/files/delete ${D}/${datadir}/runX
}
deltask compile_ptest_base
FILES_${PN} += "${bindir}/* ${datadir}/runX/*"
INHIBIT_PACKAGE_STRIP = "1"
INSANE_SKIP_${PN} += "ldflags already-stripped"