10b851182SJoel Stanley#!/bin/bash 2cce369b6SAlanny Lopez############################################################################### 3cce369b6SAlanny Lopez# 4b23c4cc4SJoel Stanley# This build script is for running the QEMU build in a container 5b23c4cc4SJoel Stanley# 6b23c4cc4SJoel Stanley# It expects to be run in with the qemu source present in the directory called 7b23c4cc4SJoel Stanley# '$WORKSPACE/qemu', where WORKSPACE is an environment variable. 8b23c4cc4SJoel Stanley# 9b23c4cc4SJoel Stanley# In Jenkins configure the git SCM 'Additional Behaviours', 'check-out to a sub 10b23c4cc4SJoel Stanley# directory' called 'qemu'. 11b23c4cc4SJoel Stanley# 12b23c4cc4SJoel Stanley# When building locally set WORKSPACE to be the directory above the qemu 13b23c4cc4SJoel Stanley# checkout: 14b23c4cc4SJoel Stanley# git clone https://github.com/qemu/qemu 15b23c4cc4SJoel Stanley# WORKSPACE=$PWD/qemu ~/openbmc-build-scripts/qemu-build.sh 16cce369b6SAlanny Lopez# 17cce369b6SAlanny Lopez############################################################################### 18cce369b6SAlanny Lopez# 19e08e8702SAlanny Lopez# Script Variables: 20e08e8702SAlanny Lopez# http_proxy The HTTP address of the proxy server to connect to. 21e08e8702SAlanny Lopez# Default: "", proxy is not setup if this is not set 22b23c4cc4SJoel Stanley# WORKSPACE Path of the workspace directory where the build will 23b23c4cc4SJoel Stanley# occur, and output artifacts will be produced. 24cce369b6SAlanny Lopez# 25cce369b6SAlanny Lopez############################################################################### 260b851182SJoel Stanley# Trace bash processing 27b23c4cc4SJoel Stanley#set -x 280b851182SJoel Stanley 294696770cSAlanny Lopez# Script Variables: 300b851182SJoel Stanleyhttp_proxy=${http_proxy:-} 31b23c4cc4SJoel Stanley 32b23c4cc4SJoel Stanleyif [ -z ${WORKSPACE+x} ]; then 33b23c4cc4SJoel Stanley echo "Please set WORKSPACE variable" 34b23c4cc4SJoel Stanley exit 1 35b23c4cc4SJoel Stanleyfi 364696770cSAlanny Lopez 3762d18027SJoel Stanley# Determine the architecture 3862d18027SJoel StanleyARCH=$(uname -m) 3962d18027SJoel Stanley 404696770cSAlanny Lopez# Docker Image Build Variables: 41b23c4cc4SJoel Stanleyimg_name=qemu-build 424696770cSAlanny Lopez 430b851182SJoel Stanley# Timestamp for job 440b851182SJoel Stanleyecho "Build started, $(date)" 450b851182SJoel Stanley 4641e2ada2SAlanny Lopez# Setup Proxy 470b851182SJoel Stanleyif [[ -n "${http_proxy}" ]]; then 480b851182SJoel Stanley PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" 490b851182SJoel Stanleyfi 500b851182SJoel Stanley 5141e2ada2SAlanny Lopez# Determine the prefix of the Dockerfile's base image 5241e2ada2SAlanny Lopezcase ${ARCH} in 5341e2ada2SAlanny Lopez "ppc64le") 5441e2ada2SAlanny Lopez DOCKER_BASE="ppc64le/" 5541e2ada2SAlanny Lopez ;; 5641e2ada2SAlanny Lopez "x86_64") 5741e2ada2SAlanny Lopez DOCKER_BASE="" 5841e2ada2SAlanny Lopez ;; 59051b05b7SThang Q. Nguyen "aarch64") 60f98f1a8dSThang Q. Nguyen DOCKER_BASE="arm64v8/" 61051b05b7SThang Q. Nguyen ;; 6241e2ada2SAlanny Lopez *) 6341e2ada2SAlanny Lopez echo "Unsupported system architecture(${ARCH}) found for docker image" 640b851182SJoel Stanley exit 1 6541e2ada2SAlanny Lopezesac 660b851182SJoel Stanley 670b851182SJoel Stanley# Create the docker run script 680b851182SJoel Stanleyexport PROXY_HOST=${http_proxy/#http*:\/\/} 690b851182SJoel Stanleyexport PROXY_HOST=${PROXY_HOST/%:[0-9]*} 700b851182SJoel Stanleyexport PROXY_PORT=${http_proxy/#http*:\/\/*:} 710b851182SJoel Stanley 720b851182SJoel Stanleycat > "${WORKSPACE}"/build.sh << EOF_SCRIPT 730b851182SJoel Stanley#!/bin/bash 740b851182SJoel Stanley 750b851182SJoel Stanleyset -x 760b851182SJoel Stanley 77a61e99abSAlanny Lopez# Go into the build directory 78b23c4cc4SJoel Stanleycd ${WORKSPACE}/qemu 790b851182SJoel Stanley 800b851182SJoel Stanleygcc --version 8141e2ada2SAlanny Lopezgit submodule update --init dtc 820b851182SJoel Stanley# disable anything that requires us to pull in X 83e30237caSAlanny Lopez./configure \ 84e30237caSAlanny Lopez --target-list=arm-softmmu \ 85e30237caSAlanny Lopez --disable-spice \ 86e30237caSAlanny Lopez --disable-docs \ 87e30237caSAlanny Lopez --disable-gtk \ 88e30237caSAlanny Lopez --disable-smartcard \ 89e30237caSAlanny Lopez --disable-usb-redir \ 90e30237caSAlanny Lopez --disable-libusb \ 91e30237caSAlanny Lopez --disable-sdl \ 92e30237caSAlanny Lopez --disable-gnutls \ 93e30237caSAlanny Lopez --disable-vte \ 94e30237caSAlanny Lopez --disable-vnc \ 954a015826SAndrew Geissler --disable-werror 96b23c4cc4SJoel Stanleymake clean 970b851182SJoel Stanleymake -j4 980b851182SJoel Stanley 990b851182SJoel StanleyEOF_SCRIPT 1000b851182SJoel Stanley 101384d741bSPatrick Williamschmod a+x "${WORKSPACE}"/build.sh 1020b851182SJoel Stanley 10341e2ada2SAlanny Lopez# Configure docker build 104a311abc5SAndrew Jeffery 105a311abc5SAndrew Jeffery# !!! 106a311abc5SAndrew Jeffery# Keep the base docker image in sync with the image under which we run the 107a311abc5SAndrew Jeffery# resulting qemu binary. 108a311abc5SAndrew Jeffery# !!! 109a311abc5SAndrew Jeffery 11041e2ada2SAlanny LopezDockerfile=$(cat << EOF 111851eaff9SAndrew GeisslerFROM ${DOCKER_BASE}ubuntu:jammy 11241e2ada2SAlanny Lopez 11341e2ada2SAlanny Lopez${PROXY} 11441e2ada2SAlanny Lopez 11541e2ada2SAlanny LopezENV DEBIAN_FRONTEND noninteractive 11641e2ada2SAlanny LopezRUN apt-get update && apt-get install -yy --no-install-recommends \ 11741e2ada2SAlanny Lopez bison \ 11841826806SAndrew Jeffery bzip2 \ 119a3f390e1SJoel Stanley ca-certificates \ 12041e2ada2SAlanny Lopez flex \ 12141e2ada2SAlanny Lopez gcc \ 12241e2ada2SAlanny Lopez git \ 12341e2ada2SAlanny Lopez libc6-dev \ 12441e2ada2SAlanny Lopez libfdt-dev \ 12541e2ada2SAlanny Lopez libglib2.0-dev \ 12641e2ada2SAlanny Lopez libpixman-1-dev \ 1274a015826SAndrew Geissler libslirp-dev \ 12841e2ada2SAlanny Lopez make \ 12941826806SAndrew Jeffery ninja-build \ 130*4b4c8ec0SAndrew Geissler python3-venv \ 1315158a324SSaqib Khan python3-yaml \ 1325158a324SSaqib Khan iputils-ping 13341e2ada2SAlanny Lopez 134384d741bSPatrick WilliamsRUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} 135384d741bSPatrick WilliamsRUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER} 13641e2ada2SAlanny LopezUSER ${USER} 13741e2ada2SAlanny LopezENV HOME ${HOME} 13841e2ada2SAlanny LopezEOF 13941e2ada2SAlanny Lopez) 14041e2ada2SAlanny Lopez 141384d741bSPatrick Williamsif ! docker build -t ${img_name} - <<< "${Dockerfile}" ; then 14241e2ada2SAlanny Lopez echo "Failed to build docker container." 14341e2ada2SAlanny Lopez exit 1 14441e2ada2SAlanny Lopezfi 145b23c4cc4SJoel Stanley 146e30237caSAlanny Lopezdocker run \ 147e30237caSAlanny Lopez --rm=true \ 148384d741bSPatrick Williams -e WORKSPACE="${WORKSPACE}" \ 149e30237caSAlanny Lopez -w "${HOME}" \ 150b23c4cc4SJoel Stanley --user="${USER}" \ 151e30237caSAlanny Lopez -v "${HOME}":"${HOME}" \ 1521246b038SAlanny Lopez -t ${img_name} \ 153384d741bSPatrick Williams "${WORKSPACE}"/build.sh 154