blob: 7d932119479e01076195ba26b0bc1814cf8377ee [file] [log] [blame]
Stewart Smith098d03e2016-03-01 13:59:42 +11001#!/bin/bash
2
3set -ex
4set -eo pipefail
5
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +10006BUILD_INFO=0
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -03007SDK_ONLY=0
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +05308CONFIGTAG="_defconfig"
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +05309DEFCONFIGS=();
Stewart Smithc4b9bf62018-08-24 13:30:15 +100010SDK_DIR=""
11
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030012opt=$(getopt -o 'o:Ss:p:r' -- "$@")
13if [ $? -ne 0 ] ; then
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030014 echo "Invalid arguments"
15 exit 1
16fi
17
18eval set -- "$opt"
19unset opt
20
21while true; do
22 case "$1" in
23 '-o')
24 shift
25 echo "Output directory: $1"
26 OUTDIR="$1"
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100027 ;;
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030028 '-S')
29 echo "Build SDK Only"
30 SDK_ONLY=1
31 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030032 '-s')
33 shift
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030034 echo "SDK cache dir is in: $1"
35 SDK_CACHE=$1
Stewart Smithc4b9bf62018-08-24 13:30:15 +100036 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030037 '-p')
38 shift
39 echo "Platforms to build: $1"
40 PLATFORM_LIST="$1"
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100041 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030042 '-r')
Stewart Smithc4b9bf62018-08-24 13:30:15 +100043 echo "Build legal-info etc for release"
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100044 BUILD_INFO=1
45 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030046 '--')
47 shift
48 break
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100049 ;;
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030050 *)
51 echo "Internal error!"
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100052 exit 1
53 ;;
54 esac
Klaus Heinrich Kiwi220aeba2020-04-20 17:28:18 -030055 shift
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +100056done
57
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030058function get_major_minor_release
Joel Stanleya81c1242018-11-01 13:19:58 +103059{
60 IFS=. read major minor macro <<<"$1"
61 echo -n "${major}_${minor}"
62}
63
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030064function get_major_release
65{
66 IFS=. read major minor macro <<<"$1"
67 echo -n "${major}"
68}
69
Klaus Heinrich Kiwie6116742020-05-12 14:42:44 -030070function sha1sum_dir
71{
72 echo -n "$(find $1 -type f -print0 | sort -z | xargs -0 sha1sum | sed -e 's/ .*//' | tr -d '[:space:]' | sha1sum | sed -e 's/ .*//')"
73}
74
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030075function build_sdk
76{
77# $1 is the defconfig
78# $2 is the SDK output directory
79# writes the output SDK pathname in global $SDK_DIR
80# also considers global var $CCACHE_DIR
81 SDK_BUILD_DIR=`mktemp -d`
82 op-build O=$SDK_BUILD_DIR $1
83
84 # Accumulate the SDK properties we want to hash to make it unique, but
85 # just so. Start with the buildroot version and machine/OS
86 HASH_PROPERTIES="$(git submodule) $(uname -mo)"
87
88 # Even if they should be interchangeable, we want to force the sdk
89 # build on every supported OS variations
Klaus Heinrich Kiwi1c7da102020-05-04 20:50:33 -030090 HASH_PROPERTIES="$HASH_PROPERTIES $(lsb_release -as | tr -d '[:space:]')"
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -030091
92 # Disable things not necessary for the sdk
93 # (Buildroot manual section 6.1.3 plus a few more things)
94 buildroot/utils/config --file $SDK_BUILD_DIR/.config --disable INIT_BUSYBOX \
95 --enable INIT_NONE \
96 --disable SYSTEM_BIN_SH_BUSYBOX \
97 --disable TARGET_ROOTFS_TAR \
98 --disable SYSTEM_BIN_SH_DASH \
99 --enable SYSTEM_BIN_SH_NONE
100
101 # We don't need the Linux Kernel or eudev (they'll be rebuilt anyway), but we need
102 # to preserve the custom kernel version (if defined) for headers consistency, and
103 # since we're at it, enabling CPP won't hurt and will make the SDK more general
104 buildroot/utils/config --file $SDK_BUILD_DIR/.config --disable LINUX_KERNEL \
105 --disable ROOTFS_DEVICE_CREATION_DYNAMIC_EUDEV \
106 --enable INSTALL_LIBSTDCPP
107
Klaus Heinrich Kiwie6116742020-05-12 14:42:44 -0300108 # Enable toolchains we'll need to be built as part of the SDK, and make sure we
109 # consider them to make the sdk unique
110 buildroot/utils/config --file $SDK_BUILD_DIR/.config --package \
Klaus Heinrich Kiwib64ca282020-05-12 14:42:44 -0300111 --enable PPE42_TOOLCHAIN --enable HOST_PPE42_GCC --enable HOST_PPE42_BINUTILS
112
Klaus Heinrich Kiwib64ca282020-05-12 14:42:44 -0300113 HASH_PROPERTIES="$HASH_PROPERTIES $(sha1sum_dir openpower/package/ppe42-gcc/)"
114 HASH_PROPERTIES="$HASH_PROPERTIES $(sha1sum_dir openpower/package/ppe42-binutils/)"
Klaus Heinrich Kiwie6116742020-05-12 14:42:44 -0300115
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300116 # As we are disabling BR2_LINUX_KERNEL, capture Kernel version if any
117 # to prevent it from defaulting to the last on olddefconfig
118 KERNEL_VER=$(buildroot/utils/config --file $SDK_BUILD_DIR/.config --state LINUX_KERNEL_CUSTOM_VERSION_VALUE)
119 if [ "$KERNEL_VER" != "undef" ]; then
120 KERNEL="KERNEL_HEADERS_$(get_major_minor_release $KERNEL_VER)"
121 buildroot/utils/config --file $SDK_BUILD_DIR/.config --enable "$KERNEL"
122 fi
123
124 # Disable packages we won't pull into the SDK to speed it's build
125 buildroot/utils/config --file $SDK_BUILD_DIR/.config --package \
126 --disable BUSYBOX \
127 --disable KEXEC_LITE \
128 --disable LINUX_FIRMWARE \
129 --disable CRYPTSETUP \
130 --disable IPMITOOL \
131 --disable LVM2 \
132 --disable MDADM \
133 --disable NVME \
134 --disable PCIUTILS \
135 --disable ZLIB \
136 --disable LIBZLIB \
137 --disable DTC \
138 --disable LIBAIO \
139 --disable JSON_C \
140 --disable ELFUTILS \
141 --disable NCURSES \
142 --disable POPT \
143 --disable DROPBEAR --disable DROPBEAR_CLIENT \
144 --disable ETHTOOL \
145 --disable IFUPDOWN_SCRIPTS \
146 --disable LRZSZ \
147 --disable NETCAT \
148 --disable RSYNC \
149 --disable SUDO \
150 --disable KMOD \
151 --disable POWERPC_UTILS \
152 --disable UTIL_LINUX \
153 --disable IPRUTILS
154
155 # Additionally, disable ROOTFS stuff that we won't need
156 # Including the OpenPower Packages
157 buildroot/utils/config --file $SDK_BUILD_DIR/.config --undefine ROOTFS_USERS_TABLES \
158 --undefine ROOTFS_OVERLAY \
159 --undefine ROOTFS_POST_BUILD_SCRIPT \
160 --undefine ROOTFS_POST_FAKEROOT_SCRIPT \
161 --undefine ROOTFS_POST_IMAGE_SCRIPT \
162 --undefine ROOTFS_POST_SCRIPT_ARGS \
163 --undefine OPENPOWER_PLATFORM \
164 --undefine BR2_OPENPOWER_POWER8 \
165 --undefine BR2_OPENPOWER_POWER9
166
167 # Enable CCACHE
168 buildroot/utils/config --file $SDK_BUILD_DIR/.config --enable CCACHE \
169 --set-str CCACHE_DIR $CCACHE_DIR
170
171 op-build O=$SDK_BUILD_DIR olddefconfig
172
173 # Ideally this woulnd't matter, but to be safe, include Kernel
174 # Headers and GCC version as part of the SDK Hash, so that we
175 # don't have Full builds and SDK builds potentially diverging
176 # on the headers/compiler versions each uses
177 KERNEL_VER=$(buildroot/utils/config --file $SDK_BUILD_DIR/.config --state DEFAULT_KERNEL_HEADERS)
178 HASH_PROPERTIES="$HASH_PROPERTIES $KERNEL_VER"
179 echo "SDK KERNEL Version: $KERNEL_VER"
180 GCC_VER=$(buildroot/utils/config --file $SDK_BUILD_DIR/.config --state GCC_VERSION)
181 echo "SDK GCC Version: $GCC_VER"
182 HASH_PROPERTIES="$HASH_PROPERTIES $GCC_VER"
183
184 # sha1sum our properties and check if a matching sdk exists
185 # A potential caveat he is if op-build is patching any of the
186 # HASH_PROPERTIES content at build time
187 HASH_VAL=$(echo -n "$HASH_PROPERTIES" | sha1sum | sed -e 's/ .*//')
188
189 SDK_DIR="$2/toolchain-${HASH_VAL}"
190
191 if [ -e "$SDK_DIR" ]; then
192 echo "Acceptable SDK for $i exists in $SDK_DIR - skipping build"
193 else
194 op-build O=$SDK_BUILD_DIR sdk
195 if [ $? -ne 0 ]; then
196 rm -rf $SDK_DIR
197 return 1
198 fi
199
200 # Move sdk to resting location and adjust paths
201 mv $SDK_BUILD_DIR $SDK_DIR
202 $SDK_DIR/host/relocate-sdk.sh
203 fi
204 export SDK_DIR
205}
206
Klaus Heinrich Kiwi63c28632020-05-05 18:44:20 -0300207if [ -z "${PLATFORM_LIST-}" ]; then
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +0530208 echo "Using all the defconfigs for all the platforms"
209 DEFCONFIGS=`(cd openpower/configs; ls -1 *_defconfig)`
210else
211 IFS=', '
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +1000212 for p in ${PLATFORM_LIST};
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +0530213 do
214 DEFCONFIGS+=($p$CONFIGTAG)
215 done
216fi
Stewart Smith098d03e2016-03-01 13:59:42 +1100217
Klaus Heinrich Kiwi63c28632020-05-05 18:44:20 -0300218if [ -z "${CCACHE_DIR-}" ]; then
Stewart Smith098d03e2016-03-01 13:59:42 +1100219 CCACHE_DIR=`pwd`/.op-build_ccache
220fi
221
222shopt -s expand_aliases
223source op-build-env
224
Klaus Heinrich Kiwi63c28632020-05-05 18:44:20 -0300225if [ -n "${DL_DIR-}" ]; then
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +1000226 unset BR2_DL_DIR
227 export BR2_DL_DIR=${DL_DIR}
228fi
229
Klaus Heinrich Kiwi04ce68e2020-04-16 15:17:50 -0300230if [ -f "$(ldconfig -p | grep libeatmydata.so | tr ' ' '\n' | grep /|head -n1)" ]; then
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000231 export LD_PRELOAD=${LD_PRELOAD:+"$LD_PRELOAD "}libeatmydata.so
Klaus Heinrich Kiwib0cfd8e2020-04-20 23:18:30 -0300232elif [ -f "/usr/lib64/nosync/nosync.so" ]; then
233 export LD_PRELOAD=${LD_PRELOAD:+"$LD_PRELOAD "}/usr/lib64/nosync/nosync.so
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000234fi
235
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +0530236for i in ${DEFCONFIGS[@]}; do
Klaus Heinrich Kiwia1f404a2020-04-16 14:24:30 -0300237 export O=${OUTDIR}/$i
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000238 rm -rf $O
Joel Stanleya81c1242018-11-01 13:19:58 +1030239
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300240 SDK_DIR=""
241 build_sdk $i $SDK_CACHE
242 if [ $? -ne 0 ]; then
243 echo "Error building SDK"
244 exit 1
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000245 fi
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300246
247 if [ $SDK_ONLY -ne 0 ]; then
248 continue
249 fi
250
251 op-build O=$O $i
252 buildroot/utils/config --file $O/.config --enable CCACHE \
253 --set-str CCACHE_DIR $CCACHE_DIR
254 buildroot/utils/config --file $O/.config --enable TOOLCHAIN_EXTERNAL \
255 --set-str TOOLCHAIN_EXTERNAL_PATH $SDK_DIR/host \
256 --enable TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC
257
258 # Our SDK will always have CPP enabled, but avoid potentially
259 # diverging with the Full build by only enabling it
260 # conditionally
261 CPP_REQUIRED=$(buildroot/utils/config --file $O/.config --state INSTALL_LIBSTDCPP)
262 if [ "$CPP_REQUIRED" = "y" ]; then
263 buildroot/utils/config --file $O/.config --enable TOOLCHAIN_EXTERNAL_CXX
264 fi
265
Klaus Heinrich Kiwib64ca282020-05-12 14:42:44 -0300266 # Our SDK will always have ppe42-toolchain enabled, but
267 # only use it if we require it
268 PPE42_REQUIRED=$(buildroot/utils/config --file $O/.config --package --state PPE42_TOOLCHAIN)
269 if [ "$PPE42_REQUIRED" = "y" ]; then
270 buildroot/utils/config --file $O/.config --enable PACKAGE_PPE42_TOOLCHAIN_EXTERNAL \
271 --set-str PPE42_TOOLCHAIN_EXTERNAL_PATH $SDK_DIR/host
272 fi
273
Klaus Heinrich Kiwie6116742020-05-12 14:42:44 -0300274
275
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300276 # The Kernel Headers requested MUST be the same as the one
277 # provided by the SDK (i.e., it's part of the hash)
278 HEADERS_VER=$(buildroot/utils/config --file $O/.config --state TOOLCHAIN_HEADERS_AT_LEAST)
279 echo "Toolchain Headers Version Requested: $HEADERS_VER"
280 HEADERS="TOOLCHAIN_EXTERNAL_HEADERS_$(get_major_minor_release $HEADERS_VER)"
281 buildroot/utils/config --file $O/.config --enable "$HEADERS"
282
283 # Same for the GCC version
284 EXTERNAL_GCC_VER=$(buildroot/utils/config --file $O/.config --state GCC_VERSION)
285 echo "GCC Version Requested: $EXTERNAL_GCC_VER"
286 EXTERNAL_GCC="TOOLCHAIN_EXTERNAL_GCC_$(get_major_release $EXTERNAL_GCC_VER)"
287 buildroot/utils/config --file $O/.config --enable "$EXTERNAL_GCC"
288
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000289 op-build O=$O olddefconfig
290 op-build O=$O
Stewart Smith098d03e2016-03-01 13:59:42 +1100291 r=$?
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300292 if [ ${BUILD_INFO} -eq 1 ] && [ $r -eq 0 ]; then
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000293 op-build O=$O legal-info
294 op-build O=$O graph-build
295 op-build O=$O graph-size
296 op-build O=$O graph-depends
297 fi
298 lsb_release -a > $O/lsb_release
Stewart Smith098d03e2016-03-01 13:59:42 +1100299 if [ $r -ne 0 ]; then
300 exit $r
301 fi
302done
303