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# DOCKER_REG: <optional, the URL of a docker registry to utilize 25# instead of our default (public.ecr.aws/ubuntu) 26# (ex. docker.io) 27# 28############################################################################### 29# Trace bash processing 30#set -x 31 32# Script Variables: 33http_proxy=${http_proxy:-} 34 35if [ -z ${WORKSPACE+x} ]; then 36 echo "Please set WORKSPACE variable" 37 exit 1 38fi 39 40docker_reg=${DOCKER_REG:-"public.ecr.aws/ubuntu"} 41 42# Docker Image Build Variables: 43img_name=qemu-build 44 45# Timestamp for job 46echo "Build started, $(date)" 47 48# Setup Proxy 49if [[ -n "${http_proxy}" ]]; then 50 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" 51fi 52 53# Create the docker run script 54export PROXY_HOST=${http_proxy/#http*:\/\/} 55export PROXY_HOST=${PROXY_HOST/%:[0-9]*} 56export PROXY_PORT=${http_proxy/#http*:\/\/*:} 57 58cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT 59#!/bin/bash 60 61set -x 62 63# Go into the build directory 64cd ${WORKSPACE}/qemu 65 66gcc --version 67git submodule update --init dtc 68# disable anything that requires us to pull in X 69./configure \ 70 --target-list=arm-softmmu \ 71 --disable-spice \ 72 --disable-docs \ 73 --disable-gtk \ 74 --disable-smartcard \ 75 --disable-usb-redir \ 76 --disable-libusb \ 77 --disable-sdl \ 78 --disable-gnutls \ 79 --disable-vte \ 80 --disable-vnc \ 81 --disable-werror 82make clean 83make -j4 84 85EOF_SCRIPT 86 87chmod a+x "${WORKSPACE}"/build.sh 88 89# Configure docker build 90 91# !!! 92# Keep the base docker image in sync with the image under which we run the 93# resulting qemu binary. 94# !!! 95 96Dockerfile=$(cat << EOF 97FROM ${docker_reg}/ubuntu:jammy 98 99${PROXY} 100 101ENV DEBIAN_FRONTEND noninteractive 102RUN apt-get update && apt-get install -yy --no-install-recommends \ 103 bison \ 104 bzip2 \ 105 ca-certificates \ 106 flex \ 107 gcc \ 108 git \ 109 libc6-dev \ 110 libfdt-dev \ 111 libglib2.0-dev \ 112 libpixman-1-dev \ 113 libslirp-dev \ 114 make \ 115 ninja-build \ 116 python3-tomli \ 117 python3-venv \ 118 python3-yaml \ 119 iputils-ping 120 121RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} 122RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER} 123USER ${USER} 124ENV HOME ${HOME} 125EOF 126) 127 128if ! docker build -t ${img_name} - <<< "${Dockerfile}" ; then 129 echo "Failed to build docker container." 130 exit 1 131fi 132 133docker run \ 134 --rm=true \ 135 -e WORKSPACE="${WORKSPACE}" \ 136 -w "${HOME}" \ 137 --user="${USER}" \ 138 -v "${HOME}":"${HOME}" \ 139 -t ${img_name} \ 140 "${WORKSPACE}"/build.sh 141