blob: 955120cd86c1aa72b42d4980a2cae7fcbba70cc8 [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 P8_PORE_TOOLCHAIN --enable HOST_P8_PORE_BINUTILS \
112 --enable PPE42_TOOLCHAIN --enable HOST_PPE42_GCC --enable HOST_PPE42_BINUTILS
113
Klaus Heinrich Kiwie6116742020-05-12 14:42:44 -0300114 HASH_PROPERTIES="$HASH_PROPERTIES $(sha1sum_dir openpower/package/p8-pore-binutils/)"
Klaus Heinrich Kiwib64ca282020-05-12 14:42:44 -0300115 HASH_PROPERTIES="$HASH_PROPERTIES $(sha1sum_dir openpower/package/ppe42-gcc/)"
116 HASH_PROPERTIES="$HASH_PROPERTIES $(sha1sum_dir openpower/package/ppe42-binutils/)"
Klaus Heinrich Kiwie6116742020-05-12 14:42:44 -0300117
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300118 # As we are disabling BR2_LINUX_KERNEL, capture Kernel version if any
119 # to prevent it from defaulting to the last on olddefconfig
120 KERNEL_VER=$(buildroot/utils/config --file $SDK_BUILD_DIR/.config --state LINUX_KERNEL_CUSTOM_VERSION_VALUE)
121 if [ "$KERNEL_VER" != "undef" ]; then
122 KERNEL="KERNEL_HEADERS_$(get_major_minor_release $KERNEL_VER)"
123 buildroot/utils/config --file $SDK_BUILD_DIR/.config --enable "$KERNEL"
124 fi
125
126 # Disable packages we won't pull into the SDK to speed it's build
127 buildroot/utils/config --file $SDK_BUILD_DIR/.config --package \
128 --disable BUSYBOX \
129 --disable KEXEC_LITE \
130 --disable LINUX_FIRMWARE \
131 --disable CRYPTSETUP \
132 --disable IPMITOOL \
133 --disable LVM2 \
134 --disable MDADM \
135 --disable NVME \
136 --disable PCIUTILS \
137 --disable ZLIB \
138 --disable LIBZLIB \
139 --disable DTC \
140 --disable LIBAIO \
141 --disable JSON_C \
142 --disable ELFUTILS \
143 --disable NCURSES \
144 --disable POPT \
145 --disable DROPBEAR --disable DROPBEAR_CLIENT \
146 --disable ETHTOOL \
147 --disable IFUPDOWN_SCRIPTS \
148 --disable LRZSZ \
149 --disable NETCAT \
150 --disable RSYNC \
151 --disable SUDO \
152 --disable KMOD \
153 --disable POWERPC_UTILS \
154 --disable UTIL_LINUX \
155 --disable IPRUTILS
156
157 # Additionally, disable ROOTFS stuff that we won't need
158 # Including the OpenPower Packages
159 buildroot/utils/config --file $SDK_BUILD_DIR/.config --undefine ROOTFS_USERS_TABLES \
160 --undefine ROOTFS_OVERLAY \
161 --undefine ROOTFS_POST_BUILD_SCRIPT \
162 --undefine ROOTFS_POST_FAKEROOT_SCRIPT \
163 --undefine ROOTFS_POST_IMAGE_SCRIPT \
164 --undefine ROOTFS_POST_SCRIPT_ARGS \
165 --undefine OPENPOWER_PLATFORM \
166 --undefine BR2_OPENPOWER_POWER8 \
167 --undefine BR2_OPENPOWER_POWER9
168
169 # Enable CCACHE
170 buildroot/utils/config --file $SDK_BUILD_DIR/.config --enable CCACHE \
171 --set-str CCACHE_DIR $CCACHE_DIR
172
173 op-build O=$SDK_BUILD_DIR olddefconfig
174
175 # Ideally this woulnd't matter, but to be safe, include Kernel
176 # Headers and GCC version as part of the SDK Hash, so that we
177 # don't have Full builds and SDK builds potentially diverging
178 # on the headers/compiler versions each uses
179 KERNEL_VER=$(buildroot/utils/config --file $SDK_BUILD_DIR/.config --state DEFAULT_KERNEL_HEADERS)
180 HASH_PROPERTIES="$HASH_PROPERTIES $KERNEL_VER"
181 echo "SDK KERNEL Version: $KERNEL_VER"
182 GCC_VER=$(buildroot/utils/config --file $SDK_BUILD_DIR/.config --state GCC_VERSION)
183 echo "SDK GCC Version: $GCC_VER"
184 HASH_PROPERTIES="$HASH_PROPERTIES $GCC_VER"
185
186 # sha1sum our properties and check if a matching sdk exists
187 # A potential caveat he is if op-build is patching any of the
188 # HASH_PROPERTIES content at build time
189 HASH_VAL=$(echo -n "$HASH_PROPERTIES" | sha1sum | sed -e 's/ .*//')
190
191 SDK_DIR="$2/toolchain-${HASH_VAL}"
192
193 if [ -e "$SDK_DIR" ]; then
194 echo "Acceptable SDK for $i exists in $SDK_DIR - skipping build"
195 else
196 op-build O=$SDK_BUILD_DIR sdk
197 if [ $? -ne 0 ]; then
198 rm -rf $SDK_DIR
199 return 1
200 fi
201
202 # Move sdk to resting location and adjust paths
203 mv $SDK_BUILD_DIR $SDK_DIR
204 $SDK_DIR/host/relocate-sdk.sh
205 fi
206 export SDK_DIR
207}
208
Klaus Heinrich Kiwi63c28632020-05-05 18:44:20 -0300209if [ -z "${PLATFORM_LIST-}" ]; then
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +0530210 echo "Using all the defconfigs for all the platforms"
211 DEFCONFIGS=`(cd openpower/configs; ls -1 *_defconfig)`
212else
213 IFS=', '
Samuel Mendoza-Jonas8d102aa2018-08-10 13:47:48 +1000214 for p in ${PLATFORM_LIST};
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +0530215 do
216 DEFCONFIGS+=($p$CONFIGTAG)
217 done
218fi
Stewart Smith098d03e2016-03-01 13:59:42 +1100219
Klaus Heinrich Kiwi63c28632020-05-05 18:44:20 -0300220if [ -z "${CCACHE_DIR-}" ]; then
Stewart Smith098d03e2016-03-01 13:59:42 +1100221 CCACHE_DIR=`pwd`/.op-build_ccache
222fi
223
224shopt -s expand_aliases
225source op-build-env
226
Klaus Heinrich Kiwi63c28632020-05-05 18:44:20 -0300227if [ -n "${DL_DIR-}" ]; then
Samuel Mendoza-Jonas94ec86a2018-08-06 15:18:26 +1000228 unset BR2_DL_DIR
229 export BR2_DL_DIR=${DL_DIR}
230fi
231
Klaus Heinrich Kiwi04ce68e2020-04-16 15:17:50 -0300232if [ -f "$(ldconfig -p | grep libeatmydata.so | tr ' ' '\n' | grep /|head -n1)" ]; then
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000233 export LD_PRELOAD=${LD_PRELOAD:+"$LD_PRELOAD "}libeatmydata.so
Klaus Heinrich Kiwib0cfd8e2020-04-20 23:18:30 -0300234elif [ -f "/usr/lib64/nosync/nosync.so" ]; then
235 export LD_PRELOAD=${LD_PRELOAD:+"$LD_PRELOAD "}/usr/lib64/nosync/nosync.so
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000236fi
237
Pridhiviraj Paidipeddi24d94a22016-08-15 16:51:31 +0530238for i in ${DEFCONFIGS[@]}; do
Klaus Heinrich Kiwia1f404a2020-04-16 14:24:30 -0300239 export O=${OUTDIR}/$i
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000240 rm -rf $O
Joel Stanleya81c1242018-11-01 13:19:58 +1030241
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300242 SDK_DIR=""
243 build_sdk $i $SDK_CACHE
244 if [ $? -ne 0 ]; then
245 echo "Error building SDK"
246 exit 1
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000247 fi
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300248
249 if [ $SDK_ONLY -ne 0 ]; then
250 continue
251 fi
252
253 op-build O=$O $i
254 buildroot/utils/config --file $O/.config --enable CCACHE \
255 --set-str CCACHE_DIR $CCACHE_DIR
256 buildroot/utils/config --file $O/.config --enable TOOLCHAIN_EXTERNAL \
257 --set-str TOOLCHAIN_EXTERNAL_PATH $SDK_DIR/host \
258 --enable TOOLCHAIN_EXTERNAL_CUSTOM_GLIBC
259
260 # Our SDK will always have CPP enabled, but avoid potentially
261 # diverging with the Full build by only enabling it
262 # conditionally
263 CPP_REQUIRED=$(buildroot/utils/config --file $O/.config --state INSTALL_LIBSTDCPP)
264 if [ "$CPP_REQUIRED" = "y" ]; then
265 buildroot/utils/config --file $O/.config --enable TOOLCHAIN_EXTERNAL_CXX
266 fi
267
Klaus Heinrich Kiwie6116742020-05-12 14:42:44 -0300268 # Our SDK will always have p8-pore-toolchain enabled, but
269 # only use it if we require it
270 P8_PORE_REQUIRED=$(buildroot/utils/config --file $O/.config --package --state P8_PORE_TOOLCHAIN)
271 if [ "$P8_PORE_REQUIRED" = "y" ]; then
272 buildroot/utils/config --file $O/.config --enable PACKAGE_P8_PORE_TOOLCHAIN_EXTERNAL \
273 --set-str P8_PORE_TOOLCHAIN_EXTERNAL_PATH $SDK_DIR/host
274 fi
275
Klaus Heinrich Kiwib64ca282020-05-12 14:42:44 -0300276 # Our SDK will always have ppe42-toolchain enabled, but
277 # only use it if we require it
278 PPE42_REQUIRED=$(buildroot/utils/config --file $O/.config --package --state PPE42_TOOLCHAIN)
279 if [ "$PPE42_REQUIRED" = "y" ]; then
280 buildroot/utils/config --file $O/.config --enable PACKAGE_PPE42_TOOLCHAIN_EXTERNAL \
281 --set-str PPE42_TOOLCHAIN_EXTERNAL_PATH $SDK_DIR/host
282 fi
283
Klaus Heinrich Kiwie6116742020-05-12 14:42:44 -0300284
285
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300286 # The Kernel Headers requested MUST be the same as the one
287 # provided by the SDK (i.e., it's part of the hash)
288 HEADERS_VER=$(buildroot/utils/config --file $O/.config --state TOOLCHAIN_HEADERS_AT_LEAST)
289 echo "Toolchain Headers Version Requested: $HEADERS_VER"
290 HEADERS="TOOLCHAIN_EXTERNAL_HEADERS_$(get_major_minor_release $HEADERS_VER)"
291 buildroot/utils/config --file $O/.config --enable "$HEADERS"
292
293 # Same for the GCC version
294 EXTERNAL_GCC_VER=$(buildroot/utils/config --file $O/.config --state GCC_VERSION)
295 echo "GCC Version Requested: $EXTERNAL_GCC_VER"
296 EXTERNAL_GCC="TOOLCHAIN_EXTERNAL_GCC_$(get_major_release $EXTERNAL_GCC_VER)"
297 buildroot/utils/config --file $O/.config --enable "$EXTERNAL_GCC"
298
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000299 op-build O=$O olddefconfig
300 op-build O=$O
Stewart Smith098d03e2016-03-01 13:59:42 +1100301 r=$?
Klaus Heinrich Kiwi5a6c1252020-04-25 14:40:13 -0300302 if [ ${BUILD_INFO} -eq 1 ] && [ $r -eq 0 ]; then
Stewart Smithc4b9bf62018-08-24 13:30:15 +1000303 op-build O=$O legal-info
304 op-build O=$O graph-build
305 op-build O=$O graph-size
306 op-build O=$O graph-depends
307 fi
308 lsb_release -a > $O/lsb_release
Stewart Smith098d03e2016-03-01 13:59:42 +1100309 if [ $r -ne 0 ]; then
310 exit $r
311 fi
312done
313