1#!/bin/bash 2############################################################################### 3# 4# This build script is for running the QEMU build in a container 5# 6# It expects to be run in with the qemu source present in the directory called 7# '$WORKSPACE/qemu', where WORKSPACE is an environment variable. 8# 9# In Jenkins configure the git SCM 'Additional Behaviours', 'check-out to a sub 10# directory' called 'qemu'. 11# 12# When building locally set WORKSPACE to be the directory above the qemu 13# checkout: 14# git clone https://github.com/qemu/qemu 15# WORKSPACE=$PWD/qemu ~/openbmc-build-scripts/qemu-build.sh 16# 17############################################################################### 18# 19# Script Variables: 20# http_proxy The HTTP address of the proxy server to connect to. 21# Default: "", proxy is not setup if this is not set 22# WORKSPACE Path of the workspace directory where the build will 23# occur, and output artifacts will be produced. 24# 25############################################################################### 26# Trace bash processing 27#set -x 28 29# Script Variables: 30http_proxy=${http_proxy:-} 31 32if [ -z ${WORKSPACE+x} ]; then 33 echo "Please set WORKSPACE variable" 34 exit 1 35fi 36 37# Determine the architecture 38ARCH=$(uname -m) 39 40# Docker Image Build Variables: 41img_name=qemu-build 42 43# Timestamp for job 44echo "Build started, $(date)" 45 46# Setup Proxy 47if [[ -n "${http_proxy}" ]]; then 48 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" 49fi 50 51# Determine the prefix of the Dockerfile's base image 52case ${ARCH} in 53 "ppc64le") 54 DOCKER_BASE="ppc64le/" 55 ;; 56 "x86_64") 57 DOCKER_BASE="" 58 ;; 59 "aarch64") 60 DOCKER_BASE="arm64v8/" 61 ;; 62 *) 63 echo "Unsupported system architecture(${ARCH}) found for docker image" 64 exit 1 65esac 66 67# Create the docker run script 68export PROXY_HOST=${http_proxy/#http*:\/\/} 69export PROXY_HOST=${PROXY_HOST/%:[0-9]*} 70export PROXY_PORT=${http_proxy/#http*:\/\/*:} 71 72cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT 73#!/bin/bash 74 75set -x 76 77# Go into the build directory 78cd ${WORKSPACE}/qemu 79 80gcc --version 81git submodule update --init dtc 82# disable anything that requires us to pull in X 83./configure \ 84 --target-list=arm-softmmu \ 85 --disable-spice \ 86 --disable-docs \ 87 --disable-gtk \ 88 --disable-smartcard \ 89 --disable-usb-redir \ 90 --disable-libusb \ 91 --disable-sdl \ 92 --disable-gnutls \ 93 --disable-vte \ 94 --disable-vnc \ 95 --disable-werror \ 96 --disable-vnc-png 97make clean 98make -j4 99 100EOF_SCRIPT 101 102chmod a+x "${WORKSPACE}"/build.sh 103 104# Configure docker build 105 106# !!! 107# Keep the base docker image in sync with the image under which we run the 108# resulting qemu binary. 109# !!! 110 111Dockerfile=$(cat << EOF 112FROM ${DOCKER_BASE}ubuntu:bionic 113 114${PROXY} 115 116ENV DEBIAN_FRONTEND noninteractive 117RUN apt-get update && apt-get install -yy --no-install-recommends \ 118 bison \ 119 bzip2 \ 120 ca-certificates \ 121 flex \ 122 gcc \ 123 git \ 124 libc6-dev \ 125 libfdt-dev \ 126 libglib2.0-dev \ 127 libpixman-1-dev \ 128 make \ 129 ninja-build \ 130 python3-yaml \ 131 iputils-ping 132 133RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} 134RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER} 135USER ${USER} 136ENV HOME ${HOME} 137EOF 138) 139 140if ! docker build -t ${img_name} - <<< "${Dockerfile}" ; then 141 echo "Failed to build docker container." 142 exit 1 143fi 144 145docker run \ 146 --rm=true \ 147 -e WORKSPACE="${WORKSPACE}" \ 148 -w "${HOME}" \ 149 --user="${USER}" \ 150 -v "${HOME}":"${HOME}" \ 151 -t ${img_name} \ 152 "${WORKSPACE}"/build.sh 153