Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 1 | #!/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 |
| 10 | set -x |
| 11 | |
| 12 | # Default variables |
| 13 | distro=${distro:-ubuntu} |
| 14 | WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}} |
| 15 | http_proxy=${http_proxy:-} |
| 16 | |
| 17 | # Timestamp for job |
| 18 | echo "Build started, $(date)" |
| 19 | |
| 20 | # Configure docker build |
| 21 | if [[ "${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 |
| 28 | FROM fedora:latest |
| 29 | |
| 30 | ${PROXY} |
| 31 | |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 32 | RUN dnf --refresh install -y \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 33 | bc \ |
| 34 | findutils \ |
| 35 | git \ |
| 36 | gcc \ |
| 37 | gcc-arm-linux-gnu \ |
| 38 | hostname \ |
| 39 | make \ |
Saqib Khan | 5158a32 | 2017-10-23 11:31:24 -0500 | [diff] [blame^] | 40 | iputils-ping \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 41 | uboot-tools xz |
| 42 | |
| 43 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 44 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 45 | |
| 46 | USER ${USER} |
| 47 | ENV HOME ${HOME} |
| 48 | RUN /bin/bash |
| 49 | EOF |
| 50 | ) |
| 51 | |
| 52 | elif [[ "${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 |
| 58 | FROM ubuntu:latest |
| 59 | |
| 60 | ${PROXY} |
| 61 | |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 62 | ENV DEBIAN_FRONTEND noninteractive |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 63 | RUN apt-get update && apt-get install -yy \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 64 | bc \ |
| 65 | build-essential \ |
| 66 | git \ |
| 67 | gcc-arm-none-eabi \ |
| 68 | u-boot-tools |
| 69 | |
| 70 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 71 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 72 | |
| 73 | USER ${USER} |
| 74 | ENV HOME ${HOME} |
| 75 | RUN /bin/bash |
| 76 | EOF |
| 77 | ) |
| 78 | fi |
| 79 | |
| 80 | # Build the docker container |
| 81 | docker build -t linux-aspeed/${distro} - <<< "${Dockerfile}" |
| 82 | if [[ "$?" -ne 0 ]]; then |
| 83 | echo "Failed to build docker container." |
| 84 | exit 1 |
| 85 | fi |
| 86 | |
| 87 | # Create the docker run script |
| 88 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 89 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 90 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 91 | |
| 92 | mkdir -p ${WORKSPACE} |
| 93 | |
| 94 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 95 | #!/bin/bash |
| 96 | |
| 97 | set -x |
| 98 | |
| 99 | cd ${WORKSPACE} |
| 100 | |
| 101 | # Go into the linux-aspeed directory (the script will put us in a build subdir) |
| 102 | cd linux-aspeed |
| 103 | |
| 104 | # Configure a build |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 105 | if [ "${distro}" == "fedora" ]; then |
| 106 | CROSS_COMPILER="arm-linux-gnu-" |
| 107 | else |
| 108 | CROSS_COMPILER="arm-none-eabi-" |
| 109 | fi |
| 110 | |
Joel Stanley | 50ab01d | 2015-11-19 09:53:25 +1030 | [diff] [blame] | 111 | # Record the version in the logs |
Joel Stanley | b97b530 | 2015-11-19 09:57:58 +1030 | [diff] [blame] | 112 | $\{CROSS_COMPILER}gcc --version |
Joel Stanley | 50ab01d | 2015-11-19 09:53:25 +1030 | [diff] [blame] | 113 | |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 114 | ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed_defconfig |
| 115 | ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make -j$(($(nproc) / 4)) |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 116 | |
| 117 | # Build barreleye image |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 118 | ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed-bmc-opp-barreleye.dtb |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 119 | cat arch/arm/boot/zImage arch/arm/boot/dts/aspeed-bmc-opp-barreleye.dtb > barreleye-zimage |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 120 | ./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 Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 121 | |
| 122 | # build palmetto image |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 123 | ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed-bmc-opp-palmetto.dtb |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 124 | cat arch/arm/boot/zImage arch/arm/boot/dts/aspeed-bmc-opp-palmetto.dtb > palmetto-zimage |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 125 | ./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 Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 126 | |
| 127 | EOF_SCRIPT |
| 128 | |
| 129 | chmod a+x ${WORKSPACE}/build.sh |
| 130 | |
| 131 | # Run the docker container, execute the build script we just built |
| 132 | docker 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 |
| 136 | echo "Build completed, $(date)" |
| 137 | |