Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | set -ex |
| 4 | set -eo pipefail |
| 5 | |
Samuel Mendoza-Jonas | 8d102aa | 2018-08-10 13:47:48 +1000 | [diff] [blame] | 6 | BUILD_INFO=0 |
Klaus Heinrich Kiwi | 5a6c125 | 2020-04-25 14:40:13 -0300 | [diff] [blame] | 7 | SDK_ONLY=0 |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 8 | CONFIGTAG="_defconfig" |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 9 | DEFCONFIGS=(); |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 10 | SDK_DIR="" |
| 11 | |
Klaus Heinrich Kiwi | 5a6c125 | 2020-04-25 14:40:13 -0300 | [diff] [blame] | 12 | opt=$(getopt -o 'o:Ss:p:r' -- "$@") |
| 13 | if [ $? -ne 0 ] ; then |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 14 | echo "Invalid arguments" |
| 15 | exit 1 |
| 16 | fi |
| 17 | |
| 18 | eval set -- "$opt" |
| 19 | unset opt |
| 20 | |
| 21 | while true; do |
| 22 | case "$1" in |
| 23 | '-o') |
| 24 | shift |
| 25 | echo "Output directory: $1" |
| 26 | OUTDIR="$1" |
Samuel Mendoza-Jonas | 8d102aa | 2018-08-10 13:47:48 +1000 | [diff] [blame] | 27 | ;; |
Klaus Heinrich Kiwi | 5a6c125 | 2020-04-25 14:40:13 -0300 | [diff] [blame] | 28 | '-S') |
| 29 | echo "Build SDK Only" |
| 30 | SDK_ONLY=1 |
| 31 | ;; |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 32 | '-s') |
| 33 | shift |
Klaus Heinrich Kiwi | 5a6c125 | 2020-04-25 14:40:13 -0300 | [diff] [blame] | 34 | echo "SDK cache dir is in: $1" |
| 35 | SDK_CACHE=$1 |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 36 | ;; |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 37 | '-p') |
| 38 | shift |
| 39 | echo "Platforms to build: $1" |
| 40 | PLATFORM_LIST="$1" |
Samuel Mendoza-Jonas | 8d102aa | 2018-08-10 13:47:48 +1000 | [diff] [blame] | 41 | ;; |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 42 | '-r') |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 43 | echo "Build legal-info etc for release" |
Samuel Mendoza-Jonas | 8d102aa | 2018-08-10 13:47:48 +1000 | [diff] [blame] | 44 | BUILD_INFO=1 |
| 45 | ;; |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 46 | '--') |
| 47 | shift |
| 48 | break |
Samuel Mendoza-Jonas | 8d102aa | 2018-08-10 13:47:48 +1000 | [diff] [blame] | 49 | ;; |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 50 | *) |
| 51 | echo "Internal error!" |
Samuel Mendoza-Jonas | 8d102aa | 2018-08-10 13:47:48 +1000 | [diff] [blame] | 52 | exit 1 |
| 53 | ;; |
| 54 | esac |
Klaus Heinrich Kiwi | 220aeba | 2020-04-20 17:28:18 -0300 | [diff] [blame] | 55 | shift |
Samuel Mendoza-Jonas | 8d102aa | 2018-08-10 13:47:48 +1000 | [diff] [blame] | 56 | done |
| 57 | |
Klaus Heinrich Kiwi | 5a6c125 | 2020-04-25 14:40:13 -0300 | [diff] [blame] | 58 | function get_major_minor_release |
Joel Stanley | a81c124 | 2018-11-01 13:19:58 +1030 | [diff] [blame] | 59 | { |
| 60 | IFS=. read major minor macro <<<"$1" |
| 61 | echo -n "${major}_${minor}" |
| 62 | } |
| 63 | |
Klaus Heinrich Kiwi | 5a6c125 | 2020-04-25 14:40:13 -0300 | [diff] [blame] | 64 | function get_major_release |
| 65 | { |
| 66 | IFS=. read major minor macro <<<"$1" |
| 67 | echo -n "${major}" |
| 68 | } |
| 69 | |
Klaus Heinrich Kiwi | e611674 | 2020-05-12 14:42:44 -0300 | [diff] [blame] | 70 | function 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 Kiwi | 5a6c125 | 2020-04-25 14:40:13 -0300 | [diff] [blame] | 75 | function 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 Kiwi | 1c7da10 | 2020-05-04 20:50:33 -0300 | [diff] [blame] | 90 | HASH_PROPERTIES="$HASH_PROPERTIES $(lsb_release -as | tr -d '[:space:]')" |
Klaus Heinrich Kiwi | 5a6c125 | 2020-04-25 14:40:13 -0300 | [diff] [blame] | 91 | |
| 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 Kiwi | e611674 | 2020-05-12 14:42:44 -0300 | [diff] [blame] | 108 | # 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 Kiwi | b64ca28 | 2020-05-12 14:42:44 -0300 | [diff] [blame] | 111 | --enable PPE42_TOOLCHAIN --enable HOST_PPE42_GCC --enable HOST_PPE42_BINUTILS |
| 112 | |
Klaus Heinrich Kiwi | b64ca28 | 2020-05-12 14:42:44 -0300 | [diff] [blame] | 113 | HASH_PROPERTIES="$HASH_PROPERTIES $(sha1sum_dir openpower/package/ppe42-gcc/)" |
| 114 | HASH_PROPERTIES="$HASH_PROPERTIES $(sha1sum_dir openpower/package/ppe42-binutils/)" |
Klaus Heinrich Kiwi | e611674 | 2020-05-12 14:42:44 -0300 | [diff] [blame] | 115 | |
Klaus Heinrich Kiwi | 5a6c125 | 2020-04-25 14:40:13 -0300 | [diff] [blame] | 116 | # 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 Kiwi | 63c2863 | 2020-05-05 18:44:20 -0300 | [diff] [blame] | 207 | if [ -z "${PLATFORM_LIST-}" ]; then |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 208 | echo "Using all the defconfigs for all the platforms" |
| 209 | DEFCONFIGS=`(cd openpower/configs; ls -1 *_defconfig)` |
| 210 | else |
| 211 | IFS=', ' |
Samuel Mendoza-Jonas | 8d102aa | 2018-08-10 13:47:48 +1000 | [diff] [blame] | 212 | for p in ${PLATFORM_LIST}; |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 213 | do |
| 214 | DEFCONFIGS+=($p$CONFIGTAG) |
| 215 | done |
| 216 | fi |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 217 | |
Klaus Heinrich Kiwi | 63c2863 | 2020-05-05 18:44:20 -0300 | [diff] [blame] | 218 | if [ -z "${CCACHE_DIR-}" ]; then |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 219 | CCACHE_DIR=`pwd`/.op-build_ccache |
| 220 | fi |
| 221 | |
| 222 | shopt -s expand_aliases |
| 223 | source op-build-env |
| 224 | |
Klaus Heinrich Kiwi | 63c2863 | 2020-05-05 18:44:20 -0300 | [diff] [blame] | 225 | if [ -n "${DL_DIR-}" ]; then |
Samuel Mendoza-Jonas | 94ec86a | 2018-08-06 15:18:26 +1000 | [diff] [blame] | 226 | unset BR2_DL_DIR |
| 227 | export BR2_DL_DIR=${DL_DIR} |
| 228 | fi |
| 229 | |
Klaus Heinrich Kiwi | 04ce68e | 2020-04-16 15:17:50 -0300 | [diff] [blame] | 230 | if [ -f "$(ldconfig -p | grep libeatmydata.so | tr ' ' '\n' | grep /|head -n1)" ]; then |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 231 | export LD_PRELOAD=${LD_PRELOAD:+"$LD_PRELOAD "}libeatmydata.so |
Klaus Heinrich Kiwi | b0cfd8e | 2020-04-20 23:18:30 -0300 | [diff] [blame] | 232 | elif [ -f "/usr/lib64/nosync/nosync.so" ]; then |
| 233 | export LD_PRELOAD=${LD_PRELOAD:+"$LD_PRELOAD "}/usr/lib64/nosync/nosync.so |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 234 | fi |
| 235 | |
Pridhiviraj Paidipeddi | 24d94a2 | 2016-08-15 16:51:31 +0530 | [diff] [blame] | 236 | for i in ${DEFCONFIGS[@]}; do |
Klaus Heinrich Kiwi | a1f404a | 2020-04-16 14:24:30 -0300 | [diff] [blame] | 237 | export O=${OUTDIR}/$i |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 238 | rm -rf $O |
Joel Stanley | a81c124 | 2018-11-01 13:19:58 +1030 | [diff] [blame] | 239 | |
Klaus Heinrich Kiwi | 5a6c125 | 2020-04-25 14:40:13 -0300 | [diff] [blame] | 240 | SDK_DIR="" |
| 241 | build_sdk $i $SDK_CACHE |
| 242 | if [ $? -ne 0 ]; then |
| 243 | echo "Error building SDK" |
| 244 | exit 1 |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 245 | fi |
Klaus Heinrich Kiwi | 5a6c125 | 2020-04-25 14:40:13 -0300 | [diff] [blame] | 246 | |
| 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 Kiwi | b64ca28 | 2020-05-12 14:42:44 -0300 | [diff] [blame] | 266 | # 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 Kiwi | e611674 | 2020-05-12 14:42:44 -0300 | [diff] [blame] | 274 | |
| 275 | |
Klaus Heinrich Kiwi | 5a6c125 | 2020-04-25 14:40:13 -0300 | [diff] [blame] | 276 | # 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 Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 289 | op-build O=$O olddefconfig |
| 290 | op-build O=$O |
Stewart Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 291 | r=$? |
Klaus Heinrich Kiwi | 5a6c125 | 2020-04-25 14:40:13 -0300 | [diff] [blame] | 292 | if [ ${BUILD_INFO} -eq 1 ] && [ $r -eq 0 ]; then |
Stewart Smith | c4b9bf6 | 2018-08-24 13:30:15 +1000 | [diff] [blame] | 293 | 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 Smith | 098d03e | 2016-03-01 13:59:42 +1100 | [diff] [blame] | 299 | if [ $r -ne 0 ]; then |
| 300 | exit $r |
| 301 | fi |
| 302 | done |
| 303 | |