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 \ |
| 40 | uboot-tools xz |
| 41 | |
| 42 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 43 | 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] | 44 | |
| 45 | USER ${USER} |
| 46 | ENV HOME ${HOME} |
| 47 | RUN /bin/bash |
| 48 | EOF |
| 49 | ) |
| 50 | |
| 51 | elif [[ "${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 |
| 57 | FROM ubuntu:latest |
| 58 | |
| 59 | ${PROXY} |
| 60 | |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 61 | ENV DEBIAN_FRONTEND noninteractive |
Chris Smart | fc730ff | 2016-03-09 20:17:19 +1100 | [diff] [blame] | 62 | RUN apt-get update && apt-get install -yy \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 63 | bc \ |
| 64 | build-essential \ |
| 65 | git \ |
Joel Stanley | 0c6ca41 | 2018-11-15 09:11:47 +1030 | [diff] [blame] | 66 | gcc-arm-linux-gnueabi \ |
| 67 | binutils-arm-linux-gnueabi \ |
| 68 | libssl-dev \ |
| 69 | bison \ |
| 70 | flex \ |
Chris Smart | 4593d4f | 2016-03-09 15:50:59 +1100 | [diff] [blame] | 71 | u-boot-tools |
| 72 | |
| 73 | RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER} |
| 74 | 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] | 75 | |
| 76 | USER ${USER} |
| 77 | ENV HOME ${HOME} |
| 78 | RUN /bin/bash |
| 79 | EOF |
| 80 | ) |
| 81 | fi |
| 82 | |
| 83 | # Build the docker container |
| 84 | docker build -t linux-aspeed/${distro} - <<< "${Dockerfile}" |
| 85 | if [[ "$?" -ne 0 ]]; then |
| 86 | echo "Failed to build docker container." |
| 87 | exit 1 |
| 88 | fi |
| 89 | |
| 90 | # Create the docker run script |
| 91 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 92 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 93 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 94 | |
| 95 | mkdir -p ${WORKSPACE} |
| 96 | |
| 97 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 98 | #!/bin/bash |
| 99 | |
| 100 | set -x |
| 101 | |
| 102 | cd ${WORKSPACE} |
| 103 | |
| 104 | # Go into the linux-aspeed directory (the script will put us in a build subdir) |
| 105 | cd linux-aspeed |
| 106 | |
| 107 | # Configure a build |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 108 | if [ "${distro}" == "fedora" ]; then |
| 109 | CROSS_COMPILER="arm-linux-gnu-" |
| 110 | else |
| 111 | CROSS_COMPILER="arm-none-eabi-" |
| 112 | fi |
| 113 | |
Joel Stanley | 50ab01d | 2015-11-19 09:53:25 +1030 | [diff] [blame] | 114 | # Record the version in the logs |
Joel Stanley | b97b530 | 2015-11-19 09:57:58 +1030 | [diff] [blame] | 115 | $\{CROSS_COMPILER}gcc --version |
Joel Stanley | 50ab01d | 2015-11-19 09:53:25 +1030 | [diff] [blame] | 116 | |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 117 | ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed_defconfig |
| 118 | ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make -j$(($(nproc) / 4)) |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 119 | |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 120 | # build palmetto image |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 121 | ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed-bmc-opp-palmetto.dtb |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 122 | 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] | 123 | ./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] | 124 | |
| 125 | EOF_SCRIPT |
| 126 | |
| 127 | chmod a+x ${WORKSPACE}/build.sh |
| 128 | |
| 129 | # Run the docker container, execute the build script we just built |
| 130 | docker 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 |
| 134 | echo "Build completed, $(date)" |
| 135 | |