blob: 84eb6f5cc53b009e213e8c931f651f8875c92d5c [file] [log] [blame]
Joel Stanley0d3597f2015-11-18 14:09:54 +10301#!/bin/bash
2
3# This build script is for running the Jenkins builds using docker.
4#
5# It expects a variable as part of Jenkins build job matrix:
6# distro = fedora|ubuntu
7# WORKSPACE =
8
9# Trace bash processing
10set -x
11
12# Default variables
13distro=${distro:-ubuntu}
14WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
15http_proxy=${http_proxy:-}
16
17# Timestamp for job
18echo "Build started, $(date)"
19
20# Configure docker build
21if [[ "${distro}" == fedora ]];then
22
23 if [[ -n "${http_proxy}" ]]; then
24 PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf"
25 fi
26
27 Dockerfile=$(cat << EOF
28FROM fedora:latest
29
30${PROXY}
31
Chris Smartfc730ff2016-03-09 20:17:19 +110032RUN dnf --refresh install -y \
Chris Smart4593d4f2016-03-09 15:50:59 +110033 bc \
34 findutils \
35 git \
36 gcc \
37 gcc-arm-linux-gnu \
38 hostname \
39 make \
Saqib Khan5158a322017-10-23 11:31:24 -050040 iputils-ping \
Chris Smart4593d4f2016-03-09 15:50:59 +110041 uboot-tools xz
42
43RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
44RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley0d3597f2015-11-18 14:09:54 +103045
46USER ${USER}
47ENV HOME ${HOME}
48RUN /bin/bash
49EOF
50)
51
52elif [[ "${distro}" == ubuntu ]]; then
53 if [[ -n "${http_proxy}" ]]; then
54 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
55 fi
56
57 Dockerfile=$(cat << EOF
58FROM ubuntu:latest
59
60${PROXY}
61
Chris Smart4593d4f2016-03-09 15:50:59 +110062ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +110063RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +110064 bc \
65 build-essential \
66 git \
67 gcc-arm-none-eabi \
68 u-boot-tools
69
70RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
71RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley0d3597f2015-11-18 14:09:54 +103072
73USER ${USER}
74ENV HOME ${HOME}
75RUN /bin/bash
76EOF
77)
78fi
79
80# Build the docker container
81docker build -t linux-aspeed/${distro} - <<< "${Dockerfile}"
82if [[ "$?" -ne 0 ]]; then
83 echo "Failed to build docker container."
84 exit 1
85fi
86
87# Create the docker run script
88export PROXY_HOST=${http_proxy/#http*:\/\/}
89export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
90export PROXY_PORT=${http_proxy/#http*:\/\/*:}
91
92mkdir -p ${WORKSPACE}
93
94cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
95#!/bin/bash
96
97set -x
98
99cd ${WORKSPACE}
100
101# Go into the linux-aspeed directory (the script will put us in a build subdir)
102cd linux-aspeed
103
104# Configure a build
Chris Smart72ed8022015-11-18 17:06:47 +1100105if [ "${distro}" == "fedora" ]; then
106 CROSS_COMPILER="arm-linux-gnu-"
107else
108 CROSS_COMPILER="arm-none-eabi-"
109fi
110
Joel Stanley50ab01d2015-11-19 09:53:25 +1030111# Record the version in the logs
Joel Stanleyb97b5302015-11-19 09:57:58 +1030112$\{CROSS_COMPILER}gcc --version
Joel Stanley50ab01d2015-11-19 09:53:25 +1030113
Chris Smart72ed8022015-11-18 17:06:47 +1100114ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed_defconfig
115ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make -j$(($(nproc) / 4))
Joel Stanley0d3597f2015-11-18 14:09:54 +1030116
117# Build barreleye image
Chris Smart72ed8022015-11-18 17:06:47 +1100118ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed-bmc-opp-barreleye.dtb
Joel Stanley0d3597f2015-11-18 14:09:54 +1030119cat arch/arm/boot/zImage arch/arm/boot/dts/aspeed-bmc-opp-barreleye.dtb > barreleye-zimage
Chris Smart72ed8022015-11-18 17:06:47 +1100120./scripts/mkuboot.sh -A arm -O linux -C none -T kernel -a 0x40008000 -e 0x40008000 -d-e 0x40008000 -n obmc-beye-\$(date +%Y%m%d%H%M) -d barreleye-zimage uImage.barreleye
Joel Stanley0d3597f2015-11-18 14:09:54 +1030121
122# build palmetto image
Chris Smart72ed8022015-11-18 17:06:47 +1100123ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed-bmc-opp-palmetto.dtb
Joel Stanley0d3597f2015-11-18 14:09:54 +1030124cat arch/arm/boot/zImage arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dtb > palmetto-zimage
Chris Smart72ed8022015-11-18 17:06:47 +1100125./scripts/mkuboot.sh -A arm -O linux -C none -T kernel -a 0x40008000 -e 0x40008000 -d-e 0x40008000 -n obmc-palm-\$(date +%Y%m%d%H%M) -d palmetto-zimage uImage.palmetto
Joel Stanley0d3597f2015-11-18 14:09:54 +1030126
127EOF_SCRIPT
128
129chmod a+x ${WORKSPACE}/build.sh
130
131# Run the docker container, execute the build script we just built
132docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
133 -w "${HOME}" -v "${HOME}":"${HOME}" -t linux-aspeed/${distro} ${WORKSPACE}/build.sh
134
135# Timestamp for build
136echo "Build completed, $(date)"
137