blob: b08e61973476f4872a40fdadb93c97b565d8ad83 [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"
Michael Shepos10afbb22019-02-06 13:33:07 -060044# xtrct_small_copy_dir
45# Directory within build_dir that should be copied to
46# xtrct_path. The directory and all parents up to, but not
47# including, build_dir will be copied. For example, if
48# build_dir is set to "/tmp/openbmc" and this is set to
49# "build/tmp", the directory at xtrct_path will have the
50# following directory structure:
51# xtrct_path
52# | - build
53# | - tmp
54# ...
55# Can also be set to the empty string to copy the entire
56# contents of build_dir to xtrct_path.
57# Default: "deploy/images".
Alanny Lopezb0a12dd2017-04-24 16:21:47 -050058#
59###############################################################################
Joel Stanley4b8b2392016-02-12 15:44:57 +103060# Trace bash processing. Set -e so when a step fails, we fail the build
Joel Stanley38c9d142016-02-16 12:31:55 +103061set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +110062
Alanny Lopez46967702018-02-25 00:29:14 -060063# Script Variables:
64build_scripts_dir=${build_scripts_dir:-"$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"}
65http_proxy=${http_proxy:-}
66WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
Andrew Geisslerdc1e7022018-03-26 07:54:48 -070067num_cpu=${num_cpu:-$(nproc)}
Alanny Lopez46967702018-02-25 00:29:14 -060068
69# Docker Image Build Variables:
70build_dir=${build_dir:-/tmp/openbmc}
Chris Smart02651712015-11-11 11:09:00 +110071distro=${distro:-ubuntu}
Alanny Lopez1246b032018-02-24 23:34:55 -060072img_tag=${img_tag:-latest}
Alanny Lopez46967702018-02-25 00:29:14 -060073target=${target:-qemu}
74
75# Deployment variables
Alanny Lopez46967702018-02-25 00:29:14 -060076obmc_dir=${obmc_dir:-${WORKSPACE}/openbmc}
Michael Shepos3939e952019-01-16 16:00:35 -060077ssc_dir=${HOME}
Michael Shepos10afbb22019-02-06 13:33:07 -060078xtrct_small_copy_dir=${xtrct_small_copy_dir:-deploy/images}
Michael Shepos3939e952019-01-16 16:00:35 -060079xtrct_path="${obmc_dir}/build/tmp"
80xtrct_copy_timeout="300"
Alanny Lopez46967702018-02-25 00:29:14 -060081
Chris Smartc3522542016-02-16 11:59:36 +110082PROXY=""
Chris Smart02651712015-11-11 11:09:00 +110083
Alanny Lopezccc650e2017-04-24 15:14:20 -050084# Determine the architecture
85ARCH=$(uname -m)
86
87# Determine the prefix of the Dockerfile's base image
88case ${ARCH} in
89 "ppc64le")
90 DOCKER_BASE="ppc64le/"
91 ;;
92 "x86_64")
93 DOCKER_BASE=""
94 ;;
95 *)
96 echo "Unsupported system architecture(${ARCH}) found for docker image"
97 exit 1
98esac
Andrew Geissler11abbbe2016-08-14 19:39:47 -050099
Chris Smart02651712015-11-11 11:09:00 +1100100# Timestamp for job
101echo "Build started, $(date)"
102
Alanny Lopez1246b032018-02-24 23:34:55 -0600103# If the obmc_dir directory doesn't exist clone it in
104if [ ! -d ${obmc_dir} ]; then
105 echo "Clone in openbmc master to ${obmc_dir}"
106 git clone https://github.com/openbmc/openbmc ${obmc_dir}
Andrew Geisslerc3c35202016-08-16 08:47:50 -0500107fi
108
Alanny Lopez1246b032018-02-24 23:34:55 -0600109# Make and chown the xtrct_path directory to avoid permission errors
110if [ ! -d ${xtrct_path} ]; then
111 mkdir -p ${xtrct_path}
Alanny Lopez723fea62017-09-12 11:22:17 -0500112fi
Alanny Lopez1246b032018-02-24 23:34:55 -0600113chown ${UID}:${GROUPS} ${xtrct_path}
Alanny Lopez723fea62017-09-12 11:22:17 -0500114
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500115# Work out what build target we should be running and set BitBake command
Michael Shepos2de03e92018-11-07 15:54:56 -0600116MACHINE=""
Chris Smart02651712015-11-11 11:09:00 +1100117case ${target} in
Chris Smart02651712015-11-11 11:09:00 +1100118 palmetto)
Brad Bishop7161a172018-10-05 16:48:06 -0400119 LAYER_DIR="meta-ibm/meta-palmetto"
Chris Smart02651712015-11-11 11:09:00 +1100120 ;;
Joel Stanley0e077202016-06-28 16:42:45 +0930121 witherspoon)
Brad Bishop7161a172018-10-05 16:48:06 -0400122 LAYER_DIR="meta-ibm/meta-witherspoon"
Joel Stanley0e077202016-06-28 16:42:45 +0930123 ;;
Joel Stanley0e077202016-06-28 16:42:45 +0930124 evb-ast2500)
Brad Bishop7161a172018-10-05 16:48:06 -0400125 LAYER_DIR="meta-evb/meta-evb-aspeed/meta-evb-ast2500"
Joel Stanley0e077202016-06-28 16:42:45 +0930126 ;;
Ed Tanous6dc40d92018-07-30 11:13:36 -0700127 s2600wf)
Brad Bishop7161a172018-10-05 16:48:06 -0400128 LAYER_DIR="meta-intel/meta-s2600wf"
Ed Tanous6dc40d92018-07-30 11:13:36 -0700129 ;;
Joel Stanley915381f2016-11-01 16:58:59 +1030130 zaius)
Brad Bishop7161a172018-10-05 16:48:06 -0400131 LAYER_DIR="meta-ingrasys/meta-zaius"
Joel Stanley915381f2016-11-01 16:58:59 +1030132 ;;
133 romulus)
Brad Bishop7161a172018-10-05 16:48:06 -0400134 LAYER_DIR="meta-ibm/meta-romulus"
Joel Stanley915381f2016-11-01 16:58:59 +1030135 ;;
Chris Smart02651712015-11-11 11:09:00 +1100136 qemu)
Brad Bishop7161a172018-10-05 16:48:06 -0400137 LAYER_DIR="meta-phosphor"
Michael Shepos2de03e92018-11-07 15:54:56 -0600138 # MACHINE defaults to `qemuarm` in this layer, no change necessary
Chris Smart02651712015-11-11 11:09:00 +1100139 ;;
Andrew Geisslerdd820722018-02-20 13:42:58 -0600140 qemux86-64)
Michael Shepos2de03e92018-11-07 15:54:56 -0600141 LAYER_DIR="meta-phosphor"
142 # MACHINE defaults to `qemuarm` in this layer, change to `qemux86-64`
143 MACHINE="qemux86-64"
Andrew Geisslerdd820722018-02-20 13:42:58 -0600144 ;;
Vijay Khemka4c5b12e2019-01-23 14:50:09 -0800145 tiogapass)
146 LAYER_DIR="meta-facebook/meta-tiogapass"
147 ;;
Chris Smart02651712015-11-11 11:09:00 +1100148 *)
149 exit 1
150 ;;
151esac
152
Brad Bishop7161a172018-10-05 16:48:06 -0400153BITBAKE_CMD="TEMPLATECONF=${LAYER_DIR}/conf source oe-init-build-env"
154
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500155# Configure Docker build
Chris Smart02651712015-11-11 11:09:00 +1100156if [[ "${distro}" == fedora ]];then
157
158 if [[ -n "${http_proxy}" ]]; then
159 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
160 fi
161
162 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600163 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100164
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500165 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100166
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500167 # Set the locale
168 RUN locale-gen en_US.UTF-8
169 ENV LANG en_US.UTF-8
170 ENV LANGUAGE en_US:en
171 ENV LC_ALL en_US.UTF-8
Saqib Khan75635122017-03-23 10:57:34 -0500172
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500173 RUN dnf --refresh install -y \
174 bzip2 \
175 chrpath \
176 cpio \
177 diffstat \
178 findutils \
179 gcc \
180 gcc-c++ \
181 git \
182 make \
183 patch \
184 perl-bignum \
185 perl-Data-Dumper \
186 perl-Thread-Queue \
187 python-devel \
188 python3-devel \
189 SDL-devel \
190 socat \
191 subversion \
192 tar \
193 texinfo \
194 wget \
Saqib Khan5158a322017-10-23 11:31:24 -0500195 which \
196 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100197
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500198 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
199 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smart02651712015-11-11 11:09:00 +1100200
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500201 USER ${USER}
202 ENV HOME ${HOME}
203 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100204EOF
205)
206
Alanny Lopezccc650e2017-04-24 15:14:20 -0500207elif [[ "${distro}" == ubuntu ]]; then
208
Chris Smart02651712015-11-11 11:09:00 +1100209 if [[ -n "${http_proxy}" ]]; then
210 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
211 fi
212
213 Dockerfile=$(cat << EOF
Alanny Lopez1246b032018-02-24 23:34:55 -0600214 FROM ${DOCKER_BASE}${distro}:${img_tag}
Chris Smart02651712015-11-11 11:09:00 +1100215
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500216 ${PROXY}
Chris Smart02651712015-11-11 11:09:00 +1100217
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500218 ENV DEBIAN_FRONTEND noninteractive
Saqib Khan75635122017-03-23 10:57:34 -0500219
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500220 RUN apt-get update && apt-get install -yy \
221 build-essential \
222 chrpath \
223 debianutils \
224 diffstat \
225 gawk \
226 git \
227 libdata-dumper-simple-perl \
228 libsdl1.2-dev \
229 libthread-queue-any-perl \
Alanny Lopez27af3a02017-05-26 10:49:06 -0500230 locales \
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500231 python \
232 python3 \
233 socat \
234 subversion \
235 texinfo \
236 cpio \
Saqib Khan5158a322017-10-23 11:31:24 -0500237 wget \
238 iputils-ping
Chris Smart02651712015-11-11 11:09:00 +1100239
Alanny Lopez27af3a02017-05-26 10:49:06 -0500240 # Set the locale
241 RUN locale-gen en_US.UTF-8
242 ENV LANG en_US.UTF-8
243 ENV LANGUAGE en_US:en
244 ENV LC_ALL en_US.UTF-8
245
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500246 RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
247 RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Chris Smartd30c5902016-03-01 15:00:54 +1100248
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500249 USER ${USER}
250 ENV HOME ${HOME}
251 RUN /bin/bash
Chris Smart02651712015-11-11 11:09:00 +1100252EOF
253)
254fi
255
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500256# Create the Docker run script
Chris Smart02651712015-11-11 11:09:00 +1100257export PROXY_HOST=${http_proxy/#http*:\/\/}
258export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
259export PROXY_PORT=${http_proxy/#http*:\/\/*:}
260
Chris Smart01d2b962015-11-11 18:05:30 +1100261mkdir -p ${WORKSPACE}
Chris Smart02651712015-11-11 11:09:00 +1100262
Chris Smart01d2b962015-11-11 18:05:30 +1100263cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
Chris Smart02651712015-11-11 11:09:00 +1100264#!/bin/bash
265
Joel Stanley38c9d142016-02-16 12:31:55 +1030266set -xeo pipefail
Chris Smart02651712015-11-11 11:09:00 +1100267
Alanny Lopez723fea62017-09-12 11:22:17 -0500268# Go into the OpenBMC directory, the build will handle changing directories
Alanny Lopez1246b032018-02-24 23:34:55 -0600269cd ${obmc_dir}
Chris Smart02651712015-11-11 11:09:00 +1100270
271# Set up proxies
272export ftp_proxy=${http_proxy}
273export http_proxy=${http_proxy}
274export https_proxy=${http_proxy}
275
Chris Smart01d2b962015-11-11 18:05:30 +1100276mkdir -p ${WORKSPACE}/bin
Chris Smart02651712015-11-11 11:09:00 +1100277
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500278# Configure proxies for BitBake
Chris Smart02651712015-11-11 11:09:00 +1100279if [[ -n "${http_proxy}" ]]; then
280
Chris Smartd30c5902016-03-01 15:00:54 +1100281 cat > ${WORKSPACE}/bin/git-proxy << \EOF_GIT
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500282 #!/bin/bash
283 # \$1 = hostname, \$2 = port
284 PROXY=${PROXY_HOST}
285 PROXY_PORT=${PROXY_PORT}
286 exec socat STDIO PROXY:\${PROXY}:\${1}:\${2},proxyport=\${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100287EOF_GIT
288
Chris Smart01d2b962015-11-11 18:05:30 +1100289 chmod a+x ${WORKSPACE}/bin/git-proxy
290 export PATH=${WORKSPACE}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${PATH}
Chris Smart02651712015-11-11 11:09:00 +1100291 git config core.gitProxy git-proxy
292
293 mkdir -p ~/.subversion
294
295 cat > ~/.subversion/servers << EOF_SVN
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500296 [global]
297 http-proxy-host = ${PROXY_HOST}
298 http-proxy-port = ${PROXY_PORT}
Chris Smart02651712015-11-11 11:09:00 +1100299EOF_SVN
300fi
301
302# Source our build env
303${BITBAKE_CMD}
304
Michael Shepos2de03e92018-11-07 15:54:56 -0600305# Change MACHINE name when given for build target
306if [[ -n "${MACHINE}" ]]; then
307 sed "s/^MACHINE\ ??=.*/MACHINE\ ??=\ \"${MACHINE}\"/" -i conf/local.conf
308fi
309
Alanny Lopezeaa2eae2017-04-24 14:55:07 -0500310# Custom BitBake config settings
Chris Smart02651712015-11-11 11:09:00 +1100311cat >> conf/local.conf << EOF_CONF
Chris Smartc650c202015-11-25 15:58:53 +1100312BB_NUMBER_THREADS = "$(nproc)"
313PARALLEL_MAKE = "-j$(nproc)"
Chris Smart02651712015-11-11 11:09:00 +1100314INHERIT += "rm_work"
315BB_GENERATE_MIRROR_TARBALLS = "1"
Alanny Lopez1246b032018-02-24 23:34:55 -0600316DL_DIR="${ssc_dir}/bitbake_downloads"
317SSTATE_DIR="${ssc_dir}/bitbake_sharedstatecache"
Chris Smart02651712015-11-11 11:09:00 +1100318USER_CLASSES += "buildstats"
Andrew Geissler931ec672016-08-11 13:10:05 -0500319INHERIT_remove = "uninative"
Alanny Lopez1246b032018-02-24 23:34:55 -0600320TMPDIR="${build_dir}"
Chris Smart02651712015-11-11 11:09:00 +1100321EOF_CONF
322
323# Kick off a build
Andrew Geissler496a6b02016-10-03 10:04:49 -0500324bitbake ${BITBAKE_OPTS} obmc-phosphor-image
Chris Smart02651712015-11-11 11:09:00 +1100325
Alanny Lopez1246b032018-02-24 23:34:55 -0600326# Copy internal build directory into xtrct_path directory
Charles Paul Hoferb249c2c2018-09-12 12:15:13 -0500327if [[ ${xtrct_small_copy_dir} ]]; then
328 mkdir -p ${xtrct_path}/${xtrct_small_copy_dir}
329 timeout ${xtrct_copy_timeout} cp -r ${build_dir}/${xtrct_small_copy_dir}/* ${xtrct_path}/${xtrct_small_copy_dir}
330else
331 timeout ${xtrct_copy_timeout} cp -r ${build_dir}/* ${xtrct_path}
332fi
Charles Paul Hoferbe8700e2018-09-05 09:28:08 -0500333
334if [[ 0 -ne $? ]]; then
335 echo "Received a non-zero exit code from timeout"
336 exit 1
337fi
338
Chris Smart02651712015-11-11 11:09:00 +1100339EOF_SCRIPT
340
341chmod a+x ${WORKSPACE}/build.sh
342
Alanny Lopez51186882017-08-01 16:14:41 -0500343# Give the Docker image a name based on the distro,tag,arch,and target
Alanny Lopez1246b032018-02-24 23:34:55 -0600344img_name=${img_name:-openbmc/${distro}:${img_tag}-${target}-${ARCH}}
Alanny Lopez51186882017-08-01 16:14:41 -0500345
346# Build the Docker image
Alanny Lopez1246b032018-02-24 23:34:55 -0600347docker build -t ${img_name} - <<< "${Dockerfile}"
Alanny Lopez51186882017-08-01 16:14:41 -0500348
Michael Shepos3939e952019-01-16 16:00:35 -0600349# If obmc_dir or ssc_dir are ${HOME} or a subdirectory they will not be mounted
350mount_obmc_dir="-v ""${obmc_dir}"":""${obmc_dir}"" "
351mount_ssc_dir="-v ""${ssc_dir}"":""${ssc_dir}"" "
352if [[ "${obmc_dir}" = "${HOME}/"* || "${obmc_dir}" = "${HOME}" ]];then
353mount_obmc_dir=""
Alanny Lopez3fbaa512017-04-24 15:46:52 -0500354fi
Michael Shepos3939e952019-01-16 16:00:35 -0600355if [[ "${ssc_dir}" = "${HOME}/"* || "${ssc_dir}" = "${HOME}" ]];then
356mount_ssc_dir=""
357fi
358
359# Run the Docker container, execute the build.sh script
360docker run \
361--cap-add=sys_admin \
362--net=host \
363--rm=true \
364-e WORKSPACE=${WORKSPACE} \
365-w "${HOME}" \
366-v "${HOME}":"${HOME}" \
367${mount_obmc_dir} \
368${mount_ssc_dir} \
369--cpus="$num_cpu" \
370-t ${img_name} \
371${WORKSPACE}/build.sh
Chris Smart02651712015-11-11 11:09:00 +1100372
Alanny Lopezd32d3322017-07-18 15:21:39 -0500373# To maintain function of resources that used an older path, add a link
Alanny Lopez1246b032018-02-24 23:34:55 -0600374ln -sf ${xtrct_path}/deploy ${WORKSPACE}/deploy
Alanny Lopezd32d3322017-07-18 15:21:39 -0500375
Chris Smart02651712015-11-11 11:09:00 +1100376# Timestamp for build
Alanny Lopez0e8ad992017-06-19 15:45:23 -0500377echo "Build completed, $(date)"