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 | |
| 32 | RUN dnf --refresh upgrade -y |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 33 | RUN dnf install -y bc findutils git gcc gcc-arm-linux-gnu hostname make uboot-tools xz |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 34 | RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 35 | |
| 36 | USER ${USER} |
| 37 | ENV HOME ${HOME} |
| 38 | RUN /bin/bash |
| 39 | EOF |
| 40 | ) |
| 41 | |
| 42 | elif [[ "${distro}" == ubuntu ]]; then |
| 43 | if [[ -n "${http_proxy}" ]]; then |
| 44 | PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy" |
| 45 | fi |
| 46 | |
| 47 | Dockerfile=$(cat << EOF |
| 48 | FROM ubuntu:latest |
| 49 | |
| 50 | ${PROXY} |
| 51 | |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 52 | RUN apt-get update |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 53 | RUN DEBIAN_FRONTEND=noninteractive apt-get upgrade -yy |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 54 | RUN DEBIAN_FRONTEND=noninteractive apt-get install -yy bc build-essential git gcc-arm-none-eabi u-boot-tools |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 55 | RUN groupadd -g ${GROUPS} ${USER} && useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER} |
| 56 | |
| 57 | USER ${USER} |
| 58 | ENV HOME ${HOME} |
| 59 | RUN /bin/bash |
| 60 | EOF |
| 61 | ) |
| 62 | fi |
| 63 | |
| 64 | # Build the docker container |
| 65 | docker build -t linux-aspeed/${distro} - <<< "${Dockerfile}" |
| 66 | if [[ "$?" -ne 0 ]]; then |
| 67 | echo "Failed to build docker container." |
| 68 | exit 1 |
| 69 | fi |
| 70 | |
| 71 | # Create the docker run script |
| 72 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 73 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 74 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 75 | |
| 76 | mkdir -p ${WORKSPACE} |
| 77 | |
| 78 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 79 | #!/bin/bash |
| 80 | |
| 81 | set -x |
| 82 | |
| 83 | cd ${WORKSPACE} |
| 84 | |
| 85 | # Go into the linux-aspeed directory (the script will put us in a build subdir) |
| 86 | cd linux-aspeed |
| 87 | |
| 88 | # Configure a build |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 89 | if [ "${distro}" == "fedora" ]; then |
| 90 | CROSS_COMPILER="arm-linux-gnu-" |
| 91 | else |
| 92 | CROSS_COMPILER="arm-none-eabi-" |
| 93 | fi |
| 94 | |
Joel Stanley | 50ab01d | 2015-11-19 09:53:25 +1030 | [diff] [blame] | 95 | # Record the version in the logs |
Joel Stanley | b97b530 | 2015-11-19 09:57:58 +1030 | [diff] [blame] | 96 | $\{CROSS_COMPILER}gcc --version |
Joel Stanley | 50ab01d | 2015-11-19 09:53:25 +1030 | [diff] [blame] | 97 | |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 98 | ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed_defconfig |
| 99 | ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make -j$(($(nproc) / 4)) |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 100 | |
| 101 | # Build barreleye image |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 102 | ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed-bmc-opp-barreleye.dtb |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 103 | 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] | 104 | ./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] | 105 | |
| 106 | # build palmetto image |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 107 | ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed-bmc-opp-palmetto.dtb |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 108 | 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] | 109 | ./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] | 110 | |
| 111 | EOF_SCRIPT |
| 112 | |
| 113 | chmod a+x ${WORKSPACE}/build.sh |
| 114 | |
| 115 | # Run the docker container, execute the build script we just built |
| 116 | docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \ |
| 117 | -w "${HOME}" -v "${HOME}":"${HOME}" -t linux-aspeed/${distro} ${WORKSPACE}/build.sh |
| 118 | |
| 119 | # Timestamp for build |
| 120 | echo "Build completed, $(date)" |
| 121 | |