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 | |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 23 | if [[ -n "${http_proxy}" ]]; then |
| 24 | PROXY="RUN echo \"proxy=${http_proxy}\" >> /etc/dnf/dnf.conf" |
| 25 | fi |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 26 | |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 27 | Dockerfile=$(cat << EOF |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 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 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 42 | RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} |
| 43 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${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 |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 49 | ) |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 50 | |
| 51 | elif [[ "${distro}" == ubuntu ]]; then |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 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 |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 55 | |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 56 | Dockerfile=$(cat << EOF |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 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 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 73 | RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER} |
| 74 | RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${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 |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 80 | ) |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 81 | fi |
| 82 | |
| 83 | # Build the docker container |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 84 | if ! docker build -t "linux-aspeed/${distro}" - <<< "${Dockerfile}" ; then |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 85 | echo "Failed to build docker container." |
| 86 | exit 1 |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 87 | fi |
| 88 | |
| 89 | # Create the docker run script |
| 90 | export PROXY_HOST=${http_proxy/#http*:\/\/} |
| 91 | export PROXY_HOST=${PROXY_HOST/%:[0-9]*} |
| 92 | export PROXY_PORT=${http_proxy/#http*:\/\/*:} |
| 93 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 94 | mkdir -p "${WORKSPACE}" |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 95 | |
| 96 | cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT |
| 97 | #!/bin/bash |
| 98 | |
| 99 | set -x |
| 100 | |
| 101 | cd ${WORKSPACE} |
| 102 | |
| 103 | # Go into the linux-aspeed directory (the script will put us in a build subdir) |
| 104 | cd linux-aspeed |
| 105 | |
| 106 | # Configure a build |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 107 | if [ "${distro}" == "fedora" ]; then |
| 108 | CROSS_COMPILER="arm-linux-gnu-" |
| 109 | else |
Joel Stanley | c822ed4 | 2019-04-04 13:15:23 +1030 | [diff] [blame] | 110 | CROSS_COMPILER="arm-linux-gnueabi-" |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 111 | fi |
| 112 | |
Joel Stanley | 50ab01d | 2015-11-19 09:53:25 +1030 | [diff] [blame] | 113 | # Record the version in the logs |
Joel Stanley | b97b530 | 2015-11-19 09:57:58 +1030 | [diff] [blame] | 114 | $\{CROSS_COMPILER}gcc --version |
Joel Stanley | 50ab01d | 2015-11-19 09:53:25 +1030 | [diff] [blame] | 115 | |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 116 | ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed_defconfig |
| 117 | ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make -j$(($(nproc) / 4)) |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 118 | |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 119 | # build palmetto image |
Chris Smart | 72ed802 | 2015-11-18 17:06:47 +1100 | [diff] [blame] | 120 | ARCH=arm CROSS_COMPILE=\${CROSS_COMPILER} make aspeed-bmc-opp-palmetto.dtb |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 121 | 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] | 122 | ./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] | 123 | |
| 124 | EOF_SCRIPT |
| 125 | |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 126 | chmod a+x "${WORKSPACE}"/build.sh |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 127 | |
| 128 | # Run the docker container, execute the build script we just built |
Patrick Williams | 384d741 | 2020-11-06 16:15:41 -0600 | [diff] [blame] | 129 | docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE="${WORKSPACE}" --user="${USER}" \ |
Patrick Williams | 476a7e9 | 2022-12-06 09:52:53 -0600 | [diff] [blame] | 130 | -w "${HOME}" -v "${HOME}":"${HOME}" -t linux-aspeed/"${distro}" "${WORKSPACE}"/build.sh |
Joel Stanley | 0d3597f | 2015-11-18 14:09:54 +1030 | [diff] [blame] | 131 | |
| 132 | # Timestamp for build |
| 133 | echo "Build completed, $(date)" |
| 134 | |