blob: 9c5f7cbbc08f8756c071ecda18c627dc928330d8 [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 \
40 uboot-tools xz
41
42RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
43RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley0d3597f2015-11-18 14:09:54 +103044
45USER ${USER}
46ENV HOME ${HOME}
47RUN /bin/bash
48EOF
49)
50
51elif [[ "${distro}" == ubuntu ]]; then
52 if [[ -n "${http_proxy}" ]]; then
53 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
54 fi
55
56 Dockerfile=$(cat << EOF
57FROM ubuntu:latest
58
59${PROXY}
60
Chris Smart4593d4f2016-03-09 15:50:59 +110061ENV DEBIAN_FRONTEND noninteractive
Chris Smartfc730ff2016-03-09 20:17:19 +110062RUN apt-get update && apt-get install -yy \
Chris Smart4593d4f2016-03-09 15:50:59 +110063 bc \
64 build-essential \
65 git \
Joel Stanley0c6ca412018-11-15 09:11:47 +103066 gcc-arm-linux-gnueabi \
67 binutils-arm-linux-gnueabi \
68 libssl-dev \
69 bison \
70 flex \
Chris Smart4593d4f2016-03-09 15:50:59 +110071 u-boot-tools
72
73RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
74RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
Joel Stanley0d3597f2015-11-18 14:09:54 +103075
76USER ${USER}
77ENV HOME ${HOME}
78RUN /bin/bash
79EOF
80)
81fi
82
83# Build the docker container
84docker build -t linux-aspeed/${distro} - <<< "${Dockerfile}"
85if [[ "$?" -ne 0 ]]; then
86 echo "Failed to build docker container."
87 exit 1
88fi
89
90# Create the docker run script
91export PROXY_HOST=${http_proxy/#http*:\/\/}
92export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
93export PROXY_PORT=${http_proxy/#http*:\/\/*:}
94
95mkdir -p ${WORKSPACE}
96
97cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
98#!/bin/bash
99
100set -x
101
102cd ${WORKSPACE}
103
104# Go into the linux-aspeed directory (the script will put us in a build subdir)
105cd linux-aspeed
106
107# Configure a build
Chris Smart72ed8022015-11-18 17:06:47 +1100108if [ "${distro}" == "fedora" ]; then
109 CROSS_COMPILER="arm-linux-gnu-"
110else
Joel Stanleyc822ed42019-04-04 13:15:23 +1030111 CROSS_COMPILER="arm-linux-gnueabi-"
Chris Smart72ed8022015-11-18 17:06:47 +1100112fi
113
Joel Stanley50ab01d2015-11-19 09:53:25 +1030114# Record the version in the logs
Joel Stanleyb97b5302015-11-19 09:57:58 +1030115$\{CROSS_COMPILER}gcc --version
Joel Stanley50ab01d2015-11-19 09:53:25 +1030116
Chris Smart72ed8022015-11-18 17:06:47 +1100117ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed_defconfig
118ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make -j$(($(nproc) / 4))
Joel Stanley0d3597f2015-11-18 14:09:54 +1030119
Joel Stanley0d3597f2015-11-18 14:09:54 +1030120# build palmetto image
Chris Smart72ed8022015-11-18 17:06:47 +1100121ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed-bmc-opp-palmetto.dtb
Joel Stanley0d3597f2015-11-18 14:09:54 +1030122cat arch/arm/boot/zImage arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dtb > palmetto-zimage
Chris Smart72ed8022015-11-18 17:06:47 +1100123./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 +1030124
125EOF_SCRIPT
126
127chmod a+x ${WORKSPACE}/build.sh
128
129# Run the docker container, execute the build script we just built
130docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
131 -w "${HOME}" -v "${HOME}":"${HOME}" -t linux-aspeed/${distro} ${WORKSPACE}/build.sh
132
133# Timestamp for build
134echo "Build completed, $(date)"
135