1#!/bin/bash 2############################################################################### 3# 4# This build script is for running the QEMU build as a container with the 5# option of launching the container with Docker or Kubernetes. 6# 7############################################################################### 8# 9# Variables used for in the build: 10# WORKSPACE = Path of the workspace directory where some intermediate files 11# and the images will be saved to. 12# qemudir = Path of the QEMU directory where the build will be done, if 13# none exists will clone in the OpenBMC/QEMU repo to WORKSPACE. 14# 15# Optional Variables: 16# launch = job|pod 17# Can be left blank to launch via Docker if not using 18# Kubernetes to launch the container. 19# Job lets you keep a copy of job and container logs on the 20# api, can be useful if not using Jenkins as you can run the 21# job again via the api without needing this script. 22# Pod launches a container which runs to completion without 23# saving anything to the api when it completes. 24# imgname = Defaults to qemu-build with the arch as its tag, can be 25# changed or passed to give a specific name to created image. 26# http_proxy = The HTTP address for the proxy server you wish to connect to. 27# 28############################################################################### 29 30# Trace bash processing 31set -x 32 33# Default variables 34WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} 35http_proxy=${http_proxy:-} 36launch=${launch:-} 37qemudir=${qemudir:-${WORKSPACE}/qemu} 38ARCH=$(uname -m) 39imgname=${imgname:-qemu-build:${ARCH}} 40 41# Timestamp for job 42echo "Build started, $(date)" 43 44# Setup Proxy 45if [[ -n "${http_proxy}" ]]; then 46PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" 47fi 48 49# Determine the prefix of the Dockerfile's base image 50case ${ARCH} in 51 "ppc64le") 52 DOCKER_BASE="ppc64le/" 53 ;; 54 "x86_64") 55 DOCKER_BASE="" 56 ;; 57 *) 58 echo "Unsupported system architecture(${ARCH}) found for docker image" 59 exit 1 60esac 61 62# If there is no qemu directory, git clone in the openbmc mirror 63if [ ! -d ${qemudir} ]; then 64 echo "Clone in openbmc master to ${qemudir}" 65 git clone https://github.com/openbmc/qemu ${qemudir} 66fi 67 68# Create the docker run script 69export PROXY_HOST=${http_proxy/#http*:\/\/} 70export PROXY_HOST=${PROXY_HOST/%:[0-9]*} 71export PROXY_PORT=${http_proxy/#http*:\/\/*:} 72 73mkdir -p ${WORKSPACE} 74 75cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT 76#!/bin/bash 77 78set -x 79 80# Go into the source directory (the script will put us in a build subdir) 81cd ${qemudir} 82 83gcc --version 84git submodule update --init dtc 85# disable anything that requires us to pull in X 86./configure \ 87 --target-list=arm-softmmu \ 88 --disable-spice \ 89 --disable-docs \ 90 --disable-gtk \ 91 --disable-smartcard \ 92 --disable-usb-redir \ 93 --disable-libusb \ 94 --disable-sdl \ 95 --disable-gnutls \ 96 --disable-vte \ 97 --disable-vnc \ 98 --disable-vnc-png 99make -j4 100 101EOF_SCRIPT 102 103chmod a+x ${WORKSPACE}/build.sh 104 105# Configure docker build 106Dockerfile=$(cat << EOF 107FROM ${DOCKER_BASE}ubuntu:16.04 108 109${PROXY} 110 111ENV DEBIAN_FRONTEND noninteractive 112RUN apt-get update && apt-get install -yy --no-install-recommends \ 113 bison \ 114 flex \ 115 gcc \ 116 git \ 117 libc6-dev \ 118 libfdt-dev \ 119 libglib2.0-dev \ 120 libpixman-1-dev \ 121 make \ 122 python-yaml \ 123 python3-yaml 124 125RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} 126RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} 127USER ${USER} 128ENV HOME ${HOME} 129EOF 130) 131 132# If Launch is left empty will create a docker container 133if [[ "${launch}" == "" ]]; then 134 135 docker build -t ${imgname} - <<< "${Dockerfile}" 136 if [[ "$?" -ne 0 ]]; then 137 echo "Failed to build docker container." 138 exit 1 139 fi 140 mountqemu="-v ""${qemudir}"":""${qemudir}"" " 141 if [[ "${qemudir}" = "${HOME}/"* || "${qemudir}" = "${HOME}" ]];then 142 mountqemu="" 143 fi 144 docker run \ 145 --rm=true \ 146 -e WORKSPACE=${WORKSPACE} \ 147 -w "${HOME}" \ 148 -v "${HOME}":"${HOME}" \ 149 ${mountqemu} \ 150 -t ${imgname} \ 151 ${WORKSPACE}/build.sh 152 153else 154 echo "Launch Parameter is invalid" 155fi 156 157 158