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