From 8a6bce7c76f142b3028495bdb54680b6f517ab12 Mon Sep 17 00:00:00 2001 From: Bertrand Marquis Date: Thu, 1 Dec 2022 14:25:30 +0000 Subject: [PATCH] automation: Create Yocto docker images Add containers suitable to run yocto kirkstone build based on ubuntu 22.04. It contains all packages required by Yocto and a checkout of the layers required to build Xen with Yocto. Add a generic docker image template to be used to automatically generate docker files for different configurations: - specific yocto version - different targets (qemu arm, arm64 and x86) - different host platforms (x86 or arm64) During a call to 'make all', only the images for the host platform we run it on in the CI is generated. If needed, images for an other host platform can be generated manually by calling the right make target (see make help). Add a build script to build and run xen on qemu using Yocto. The script supports arm32, arm64 and x86_64 and checks that dom0 is properly booting. At this stage this does not run any guest on top of dom0. The script is to be executed in one of the docker images to build and run a system using a Xen source tree. Add automation/build/yocto/*.dockerfile to gitignore as those files are generated. Signed-off-by: Bertrand Marquis Reviewed-by: Stefano Stabellini --- .gitignore | 1 + automation/build/Makefile | 16 +- automation/build/yocto/build-yocto.sh | 356 +++++++++++++++++++++ automation/build/yocto/yocto.dockerfile.in | 114 +++++++ automation/build/yocto/yocto.inc | 44 +++ 5 files changed, 528 insertions(+), 3 deletions(-) create mode 100755 automation/build/yocto/build-yocto.sh create mode 100644 automation/build/yocto/yocto.dockerfile.in create mode 100644 automation/build/yocto/yocto.inc diff --git a/.gitignore b/.gitignore index ea3243af9d..ce7caa56af 100644 --- a/.gitignore +++ b/.gitignore @@ -38,6 +38,7 @@ dist stubdom/*.tar.gz autom4te.cache/ +automation/build/yocto/*.dockerfile build-*/ config.log config.status diff --git a/automation/build/Makefile b/automation/build/Makefile index a4b2b85178..c4aaa747ff 100644 --- a/automation/build/Makefile +++ b/automation/build/Makefile @@ -1,20 +1,30 @@ # the base of where these containers will appear REGISTRY := registry.gitlab.com/xen-project/xen -CONTAINERS = $(subst .dockerfile,,$(wildcard */*.dockerfile)) +CONTAINERS := $(filter-out yocto/%,$(subst .dockerfile,,$(wildcard */*.dockerfile))) +CONTAINERS_EXTRA = DOCKER_CMD ?= docker help: @echo "Builds containers for building Xen based on different distros" @echo "To build one run 'make DISTRO/VERSION'. Available containers:" - @$(foreach file,$(sort $(CONTAINERS)),echo ${file};) + @$(foreach file,$(sort $(CONTAINERS)),echo $(file);) + @echo "Extra containers (not built using make all):" + @$(foreach file,$(sort $(CONTAINERS_EXTRA)),echo $(file);) @echo "To push container builds, set the env var PUSH" +include yocto/yocto.inc + %: %.dockerfile ## Builds containers $(DOCKER_CMD) build -t $(REGISTRY)/$(@D):$(@F) -f $< $( "${LOGDIR}/${task_log}.log" 2>&1 + else + "$@" 2>&1 | tee "${LOGDIR}/${task_log}.log" + fi + + if [ ${?} -ne 0 ]; then + echo "Error" + build_result=$((build_result+1)) + if [ "${do_dump}" = "y" ]; then + echo + echo "############ LOGS-START ############" + cat "${LOGDIR}/${task_log}.log" + echo "############ LOGS-END ############" + echo + fi + return 1 + else + echo "OK" + return 0 + fi +} + +function project_create() { + target="${1:?}" + destdir="${BUILDDIR}/${target}" + + ( + # init yocto project + source "${YOCTODIR}/poky/oe-init-build-env" "${destdir}" + + # add needed layers + for layer in ${build_layerlist}; do + bitbake-layers add-layer "${YOCTODIR}/${layer}" || exit 1 + done + ) || return 1 + + # Detect latest version available in Yocto and use it instead of default + # one. + XENVERS=$(grep -e "^XEN_REL" \ + "${YOCTODIR}"/meta-virtualization/recipes-extended/xen/xen_*.bb \ + 2> /dev/null | tr -d ' ' | tr -d '?' | tr -d '"' \ + | sed -e "s/.*=//" | sort -V | tail -n 1) + + # customize project configuration + cat <> "${destdir}/conf/local.conf" +# Yocto BSP +MACHINE = "${target}" + +# Use local cache to reuse previous builds results +SSTATE_DIR = "${CACHEDIR}/sstate-cache" +DL_DIR = "${CACHEDIR}/downloads" + +# Enable xen and virtualization +DISTRO_FEATURES = " virtualization xen ipv4" + +# Speed up run by not generating ssh host keys +IMAGE_INSTALL:append:pn-xen-image-minimal = " ssh-pregen-hostkeys" + +# Save some disk space +INHERIT += "rm_work" + +# Reduce number of jobs +BB_NUMBER_THREADS="${BUILDJOBS}" + +# Use latest Xen version +PREFERRED_VERSION:pn-xen = "${XENVERS}%" +PREFERRED_VERSION:pn-xen-tools = "${XENVERS}%" + +# Use autorev for now as Xen SHA used by latest yocto recipe for Xen does not +# include fixes required to build x86 on arm +SRCREV:pn-xen = "\${AUTOREV}" +SRCREV:pn-xen-tools = "\${AUTOREV}" + +# Disable all QA errors as the recipe is not up to date with changes in Xen +# when we use local sources +ERROR_QA:pn-xen = "arch" +ERROR_QA:pn-xen-tools = "arch" + +EOF + + if [ "${do_localsrc}" = "y" ]; then + XENBASE=$(dirname "$(realpath -m "${XENDIR}")") + XENSUB=$(basename "$(realpath -m "${XENDIR}")") + + cat <> "${destdir}/conf/local.conf" +# Use local sources for xen and xen-tools +FILESEXTRAPATHS:prepend:pn-xen := "${XENBASE}:" +FILESEXTRAPATHS:prepend:pn-xen-tools := "${XENBASE}:" + +SRC_URI:pn-xen = "file://${XENSUB}/;subdir=local-xen/" +SRC_URI:pn-xen-tools = "file://${XENSUB}/;subdir=local-xen/" + +S:pn-xen = "\${WORKDIR}/local-xen/${XENSUB}" +S:pn-xen-tools = "\${WORKDIR}/local-xen/${XENSUB}" + +SRCPV:pn-xen = "1" +SRCPV:pn-xen-tools = "1" + +EOF + fi +} + +function project_build() { + target="${1:?}" + destdir="${BUILDDIR}/${target}" + + ( + source "${YOCTODIR}/poky/oe-init-build-env" "${destdir}" + + bitbake "${build_image}" || exit 1 + ) || return 1 +} + +function project_clean() { + target="${1:?}" + destdir="${BUILDDIR}/${target}" + + rm -rf "${destdir}" +} + +function project_run() { + target="${1:?}" + destdir="${BUILDDIR}/${target}" + ( + source "${YOCTODIR}/poky/oe-init-build-env" "${destdir}" > /dev/null 2>&1 + + /usr/bin/expect < $$@ + +endef + +$(eval $(foreach version,$(YOCTO_VERSION),\ + $(foreach target,$(YOCTO_TARGETS),\ + $(foreach arch,$(YOCTO_ARCHS),\ + $(call GEN_DOCKER,$(version),$(target),$(arch),$(if $(filter amd64,$(arch)),,-$(arch)))))))