blob: 8eff5f58681ca74f1473be9daa05bbb1751ce894 [file] [log] [blame]
Alanny Lopez56fc36a2017-07-27 13:55:44 -05001#!/bin/bash
Alanny Lopezb0a12dd2017-04-24 16:21:47 -05002###############################################################################
Chris Smart02651712015-11-11 11:09:00 +11003#
Michael Shepos3939e952019-01-16 16:00:35 -06004# This build script is for running the OpenBMC builds as Docker containers.
Alanny Lopez3fbaa512017-04-24 15:46:52 -05005#
Alanny Lopezb0a12dd2017-04-24 16:21:47 -05006###############################################################################
7#
Alanny Lopeze08e8702018-02-24 18:07:13 -06008# Script Variables:
9# build_scripts_dir The path of the openbmc-build-scripts directory.
10# Default: The directory containing this script
11# http_proxy The HTTP address of the proxy server to connect to.
12# Default: "", proxy is not setup if this is not set
13# WORKSPACE Path of the workspace directory where some intermediate
14# files and the images will be saved to.
15# Default: "~/{RandomNumber}"
Andrew Geisslerdc1e7022018-03-26 07:54:48 -070016# num_cpu Number of cpu's to give bitbake, default is total amount
17# in system
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050018#
Alanny Lopeze08e8702018-02-24 18:07:13 -060019# Docker Image Build Variables:
Alanny Lopez1246b032018-02-24 23:34:55 -060020# BITBAKE_OPTS Set to "-c populate_sdk" or whatever other BitBake options
Alanny Lopeze08e8702018-02-24 18:07:13 -060021# you'd like to pass into the build.
22# Default: "", no options set
Alanny Lopez1246b032018-02-24 23:34:55 -060023# build_dir Path where the actual BitBake build occurs inside the
Alanny Lopeze08e8702018-02-24 18:07:13 -060024# container, path cannot be located on network storage.
25# Default: "/tmp/openbmc"
26# distro The distro used as the base image for the build image:
27# fedora|ubuntu
28# Default: "ubuntu"
Alanny Lopez1246b032018-02-24 23:34:55 -060029# img_name The name given to the target build's docker image.
Alanny Lopeze08e8702018-02-24 18:07:13 -060030# Default: "openbmc/${distro}:${imgtag}-${target}-${ARCH}"
Alanny Lopez1246b032018-02-24 23:34:55 -060031# img_tag The base docker image distro tag:
Alanny Lopeze08e8702018-02-24 18:07:13 -060032# ubuntu: latest|16.04|14.04|trusty|xenial
33# fedora: 23|24|25
34# Default: "latest"
35# target The target we aim to build:
Andrew Geisslerdd820722018-02-20 13:42:58 -060036# evb-ast2500|palmetto|qemu|qemux86-64
Vijay Khemka4c5b12e2019-01-23 14:50:09 -080037# romulus|s2600wf|witherspoon|zaius|tiogapass
Alanny Lopeze08e8702018-02-24 18:07:13 -060038# Default: "qemu"
Alanny Lopez723fea62017-09-12 11:22:17 -050039#
Alanny Lopeze08e8702018-02-24 18:07:13 -060040# Deployment Variables:
Alanny Lopez1246b032018-02-24 23:34:55 -060041# obmc_dir Path of the OpenBMC repo directory used as a reference
Alanny Lopeze08e8702018-02-24 18:07:13 -060042# for the build inside the container.
43# Default: "${WORKSPACE}/openbmc"
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050044#
45###############################################################################
Joel Stanley4b8b2392016-02-12 15:44:57 +103046# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103047set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110048
Alanny Lopez46967702018-02-25 00:29:14 -060049# Script Variables:
50build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"}
51http_proxy=${http_proxy:-}
52WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Andrew Geisslerdc1e7022018-03-26 07:54:48 -070053num_cpu=${num_cpu:-$(nproc)}
Alanny Lopez46967702018-02-25 00:29:14 -060054
55# Docker Image Build Variables:
56build_dir=${build_dir:-/tmp/openbmc}
Chris Smart02651712015-11-11 11:09:00 +110057distro=${distro:-ubuntu}
Alanny Lopez1246b032018-02-24 23:34:55 -060058img_tag=${img_tag:-latest}
Alanny Lopez46967702018-02-25 00:29:14 -060059target=${target:-qemu}
60
61# Deployment variables
Alanny Lopez46967702018-02-25 00:29:14 -060062obmc_dir=${obmc_dir:-${WORKSPACE}/openbmc}
Michael Shepos3939e952019-01-16 16:00:35 -060063ssc_dir=${HOME}
64xtrct_small_copy_dir="deploy/images"
65xtrct_path="${obmc_dir}/build/tmp"
66xtrct_copy_timeout="300"
Alanny Lopez46967702018-02-25 00:29:14 -060067
Chris Smartc3522542016-02-16 11:59:36 +110068PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110069
Alanny Lopezccc650e2017-04-24 15:14:20 -050070# Determine the architecture
71ARCH=$(uname -m)
72
73# Determine the prefix of the Dockerfile's base image
74case ${ARCH} in
75 "ppc64le")
76 DOCKER_BASE="ppc64le/"
77 ;;
78 "x86_64")
79 DOCKER_BASE=""
80 ;;
81 *)
82 echo "Unsupported system architecture(${ARCH}) found for docker image"
83 exit 1
84esac
Andrew Geissler11abbbe2016-08-14 19:39:47 -050085
Chris Smart02651712015-11-11 11:09:00 +110086# Timestamp for job
87echo "Build started, $(date)"
88
Alanny Lopez1246b032018-02-24 23:34:55 -060089# If the obmc_dir directory doesn't exist clone it in
90if [ ! -d ${obmc_dir} ]; then
91 echo "Clone in openbmc master to ${obmc_dir}"
92 git clone https://github.com/openbmc/openbmc ${obmc_dir}
Andrew Geisslerc3c35202016-08-16 08:47:50 -050093fi
94
Alanny Lopez1246b032018-02-24 23:34:55 -060095# Make and chown the xtrct_path directory to avoid permission errors
96if [ ! -d ${xtrct_path} ]; then
97 mkdir -p ${xtrct_path}
Alanny Lopez723fea62017-09-12 11:22:17 -050098fi
Alanny Lopez1246b032018-02-24 23:34:55 -060099chown ${UID}:${GROUPS} ${xtrct_path}
Alanny Lopez723fea62017-09-12 11:22:17 -0500100
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500101# Work out what build target we should be running and set BitBake command
Michael Shepos2de03e92018-11-07 15:54:56 -0600102MACHINE=""
Chris Smart02651712015-11-11 11:09:00 +1100103case ${target} in
Chris Smart02651712015-11-11 11:09:00 +1100104 palmetto)
Brad Bishop7161a172018-10-05 16:48:06 -0400105 LAYER_DIR="meta-ibm/meta-palmetto"
Chris Smart02651712015-11-11 11:09:00 +1100106 ;;
Joel Stanley0e077202016-06-28 16:42:45 +0930107 witherspoon)
Brad Bishop7161a172018-10-05 16:48:06 -0400108 LAYER_DIR="meta-ibm/meta-witherspoon"
Joel Stanley0e077202016-06-28 16:42:45 +0930109 ;;
Joel Stanley0e077202016-06-28 16:42:45 +0930110 evb-ast2500)
Brad Bishop7161a172018-10-05 16:48:06 -0400111 LAYER_DIR="meta-evb/meta-evb-aspeed/meta-evb-ast2500"
Joel Stanley0e077202016-06-28 16:42:45 +0930112 ;;
Ed Tanous6dc40d92018-07-30 11:13:36 -0700113 s2600wf)
Brad Bishop7161a172018-10-05 16:48:06 -0400114 LAYER_DIR="meta-intel/meta-s2600wf"
Ed Tanous6dc40d92018-07-30 11:13:36 -0700115 ;;
Joel Stanley915381f2016-11-01 16:58:59 +1030116 zaius)
Brad Bishop7161a172018-10-05 16:48:06 -0400117 LAYER_DIR="meta-ingrasys/meta-zaius"
Joel Stanley915381f2016-11-01 16:58:59 +1030118 ;;
119 romulus)
Brad Bishop7161a172018-10-05 16:48:06 -0400120 LAYER_DIR="meta-ibm/meta-romulus"
Joel Stanley915381f2016-11-01 16:58:59 +1030121 ;;
Chris Smart02651712015-11-11 11:09:00 +1100122 qemu)
Brad Bishop7161a172018-10-05 16:48:06 -0400123 LAYER_DIR="meta-phosphor"
Michael Shepos2de03e92018-11-07 15:54:56 -0600124 # MACHINE defaults to `qemuarm` in this layer, no change necessary
Chris Smart02651712015-11-11 11:09:00 +1100125 ;;
Andrew Geisslerdd820722018-02-20 13:42:58 -0600126 qemux86-64)
Michael Shepos2de03e92018-11-07 15:54:56 -0600127 LAYER_DIR="meta-phosphor"
128 # MACHINE defaults to `qemuarm` in this layer, change to `qemux86-64`
129 MACHINE="qemux86-64"
Andrew Geisslerdd820722018-02-20 13:42:58 -0600130 ;;
Vijay Khemka4c5b12e2019-01-23 14:50:09 -0800131 tiogapass)
132 LAYER_DIR="meta-facebook/meta-tiogapass"
133 ;;
Chris Smart02651712015-11-11 11:09:00 +1100134 *)
135 exit 1
136 ;;
137esac
138
Brad Bishop7161a172018-10-05 16:48:06 -0400139BITBAKE_CMD="TEMPLATECONF=${LAYER_DIR}/conf source oe-init-build-env"
140
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500141# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +1100142if [[ "${distro}" == fedora ]];then
143
144 if [[ -n "${http_proxy}" ]]; then
145 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
146 fi
147
148 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600149 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100150
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500151 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100152
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500153 # Set the locale
154 RUN locale-gen en_US.UTF-8
155 ENV LANG en_US.UTF-8
156 ENV LANGUAGE en_US:en
157 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -0500158
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500159 RUN dnf --refresh install -y \
160 bzip2 \
161 chrpath \
162 cpio \
163 diffstat \
164 findutils \
165 gcc \
166 gcc-c++ \
167 git \
168 make \
169 patch \
170 perl-bignum \
171 perl-Data-Dumper \
172 perl-Thread-Queue \
173 python-devel \
174 python3-devel \
175 SDL-devel \
176 socat \
177 subversion \
178 tar \
179 texinfo \
180 wget \
Saqib Khan5158a322017-10-23 11:31:24 -0500181 which \
182 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100183
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500184 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
185 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100186
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500187 USER ${USER}
188 ENV HOME ${HOME}
189 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100190EOF
191)
192
Alanny Lopezccc650e2017-04-24 15:14:20 -0500193elif [[ "${distro}" == ubuntu ]]; then
194
Chris Smart02651712015-11-11 11:09:00 +1100195 if [[ -n "${http_proxy}" ]]; then
196 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
197 fi
198
199 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600200 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100201
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500202 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100203
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500204 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500205
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500206 RUN apt-get update && apt-get install -yy \
207 build-essential \
208 chrpath \
209 debianutils \
210 diffstat \
211 gawk \
212 git \
213 libdata-dumper-simple-perl \
214 libsdl1.2-dev \
215 libthread-queue-any-perl \
Alanny Lopez27af3a02017-05-26 10:49:06 -0500216 locales \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500217 python \
218 python3 \
219 socat \
220 subversion \
221 texinfo \
222 cpio \
Saqib Khan5158a322017-10-23 11:31:24 -0500223 wget \
224 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100225
Alanny Lopez27af3a02017-05-26 10:49:06 -0500226 # Set the locale
227 RUN locale-gen en_US.UTF-8
228 ENV LANG en_US.UTF-8
229 ENV LANGUAGE en_US:en
230 ENV LC_ALL en_US.UTF-8
231
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500232 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
233 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100234
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500235 USER ${USER}
236 ENV HOME ${HOME}
237 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100238EOF
239)
240fi
241
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500242# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100243export PROXY_HOST=${http_proxy/#http*:\/\/}
244export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
245export PROXY_PORT=${http_proxy/#http*:\/\/*:}
246
Chris Smart01d2b962015-11-11 18:05:30 +1100247mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100248
Chris Smart01d2b962015-11-11 18:05:30 +1100249cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100250#!/bin/bash
251
Joel Stanley38c9d142016-02-16 12:31:55 +1030252set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100253
Alanny Lopez723fea62017-09-12 11:22:17 -0500254# Go into the OpenBMC directory, the build will handle changing directories
Alanny Lopez1246b032018-02-24 23:34:55 -0600255cd ${obmc_dir}
Chris Smart02651712015-11-11 11:09:00 +1100256
257# Set up proxies
258export ftp_proxy=${http_proxy}
259export http_proxy=${http_proxy}
260export https_proxy=${http_proxy}
261
Chris Smart01d2b962015-11-11 18:05:30 +1100262mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100263
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500264# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100265if [[ -n "${http_proxy}" ]]; then
266
Chris Smartd30c5902016-03-01 15:00:54 +1100267 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500268 #!/bin/bash
269 # \$1 = hostname, \$2 = port
270 PROXY=${PROXY_HOST}
271 PROXY_PORT=${PROXY_PORT}
272 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100273EOF_GIT
274
Chris Smart01d2b962015-11-11 18:05:30 +1100275 chmod a+x ${WORKSPACE}/bin/git-proxy
276 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100277 git config core.gitProxy git-proxy
278
279 mkdir -p ~/.subversion
280
281 cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500282 [global]
283 http-proxy-host = ${PROXY_HOST}
284 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100285EOF_SVN
286fi
287
288# Source our build env
289${BITBAKE_CMD}
290
Michael Shepos2de03e92018-11-07 15:54:56 -0600291# Change MACHINE name when given for build target
292if [[ -n "${MACHINE}" ]]; then
293 sed "s/^MACHINE\ ??=.*/MACHINE\ ??=\ \"${MACHINE}\"/" -i conf/local.conf
294fi
295
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500296# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100297cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100298BB_NUMBER_THREADS = "$(nproc)"
299PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100300INHERIT += "rm_work"
301BB_GENERATE_MIRROR_TARBALLS = "1"
Alanny Lopez1246b032018-02-24 23:34:55 -0600302DL_DIR="${ssc_dir}/bitbake_downloads"
303SSTATE_DIR="${ssc_dir}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100304USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500305INHERIT_remove = "uninative"
Alanny Lopez1246b032018-02-24 23:34:55 -0600306TMPDIR="${build_dir}"
Chris Smart02651712015-11-11 11:09:00 +1100307EOF_CONF
308
309# Kick off a build
Andrew Geissler496a6b02016-10-03 10:04:49 -0500310bitbake ${BITBAKE_OPTS} obmc-phosphor-image
Chris Smart02651712015-11-11 11:09:00 +1100311
Alanny Lopez1246b032018-02-24 23:34:55 -0600312# Copy internal build directory into xtrct_path directory
Charles Paul Hoferb249c2c2018-09-12 12:15:13 -0500313if [[ ${xtrct_small_copy_dir} ]]; then
314 mkdir -p ${xtrct_path}/${xtrct_small_copy_dir}
315 timeout ${xtrct_copy_timeout} cp -r ${build_dir}/${xtrct_small_copy_dir}/* ${xtrct_path}/${xtrct_small_copy_dir}
316else
317 timeout ${xtrct_copy_timeout} cp -r ${build_dir}/* ${xtrct_path}
318fi
Charles Paul Hoferbe8700e2018-09-05 09:28:08 -0500319
320if [[ 0 -ne $? ]]; then
321 echo "Received a non-zero exit code from timeout"
322 exit 1
323fi
324
Chris Smart02651712015-11-11 11:09:00 +1100325EOF_SCRIPT
326
327chmod a+x ${WORKSPACE}/build.sh
328
Alanny Lopez51186882017-08-01 16:14:41 -0500329# Give the Docker image a name based on the distro,tag,arch,and target
Alanny Lopez1246b032018-02-24 23:34:55 -0600330img_name=${img_name:-openbmc/${distro}:${img_tag}-${target}-${ARCH}}
Alanny Lopez51186882017-08-01 16:14:41 -0500331
332# Build the Docker image
Alanny Lopez1246b032018-02-24 23:34:55 -0600333docker build -t ${img_name} - <<< "${Dockerfile}"
Alanny Lopez51186882017-08-01 16:14:41 -0500334
Michael Shepos3939e952019-01-16 16:00:35 -0600335# If obmc_dir or ssc_dir are ${HOME} or a subdirectory they will not be mounted
336mount_obmc_dir="-v ""${obmc_dir}"":""${obmc_dir}"" "
337mount_ssc_dir="-v ""${ssc_dir}"":""${ssc_dir}"" "
338if [[ "${obmc_dir}" = "${HOME}/"* || "${obmc_dir}" = "${HOME}" ]];then
339mount_obmc_dir=""
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500340fi
Michael Shepos3939e952019-01-16 16:00:35 -0600341if [[ "${ssc_dir}" = "${HOME}/"* || "${ssc_dir}" = "${HOME}" ]];then
342mount_ssc_dir=""
343fi
344
345# Run the Docker container, execute the build.sh script
346docker run \
347--cap-add=sys_admin \
348--net=host \
349--rm=true \
350-e WORKSPACE=${WORKSPACE} \
351-w "${HOME}" \
352-v "${HOME}":"${HOME}" \
353${mount_obmc_dir} \
354${mount_ssc_dir} \
355--cpus="$num_cpu" \
356-t ${img_name} \
357${WORKSPACE}/build.sh
Chris Smart02651712015-11-11 11:09:00 +1100358
Alanny Lopezd32d3322017-07-18 15:21:39 -0500359# To maintain function of resources that used an older path, add a link
Alanny Lopez1246b032018-02-24 23:34:55 -0600360ln -sf ${xtrct_path}/deploy ${WORKSPACE}/deploy
Alanny Lopezd32d3322017-07-18 15:21:39 -0500361
Chris Smart02651712015-11-11 11:09:00 +1100362# Timestamp for build
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500363echo "Build completed, $(date)"