Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright 2015 The Chromium OS Authors. All rights reserved. |
| 3 | # Use of this source code is governed by a BSD-style license that can be |
| 4 | # found in the LICENSE file. |
| 5 | |
Nicolas Boichat | 2ac05a9 | 2020-06-29 11:27:33 +0800 | [diff] [blame^] | 6 | # This script builds gpu drivers (mali-drivers[-*], img-ddk) for a list |
Nicolas Boichat | 906df57 | 2018-08-17 09:16:47 +0800 | [diff] [blame] | 7 | # of boards. It uploads the binaries to Google storage and makes them available |
| 8 | # in the public repository. |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 9 | |
| 10 | # Loads script libraries. |
| 11 | CONTRIB_DIR=$(dirname "$(readlink -f "$0")") |
| 12 | . "${CONTRIB_DIR}/common.sh" || exit 1 |
| 13 | |
| 14 | DEFINE_string package "" \ |
| 15 | "selects which gpu drivers package to build" |
| 16 | DEFINE_boolean dryrun ${FLAGS_FALSE} \ |
| 17 | "dry run, don't upload anything and don't delete temporary dirs" n |
Nicolas Boichat | 7f94c0d | 2018-11-24 17:25:38 +0800 | [diff] [blame] | 18 | DEFINE_boolean usebinpkg ${FLAGS_TRUE} \ |
| 19 | "use prebuilt binaries, instead of building driver locally" b |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 20 | |
| 21 | # Parse command line. |
| 22 | FLAGS "$@" || exit 1 |
| 23 | eval set -- "${FLAGS_ARGV}" |
| 24 | |
| 25 | # Script must run inside the chroot. |
| 26 | assert_inside_chroot |
| 27 | |
Nicolas Boichat | b375dbf | 2018-11-28 10:36:58 +0800 | [diff] [blame] | 28 | # The temp dir to use for scratch space. |
| 29 | TEMP_DIR="" |
| 30 | |
Nicolas Boichat | f88b0f8 | 2018-11-24 11:33:44 +0800 | [diff] [blame] | 31 | # All drivers are in media-libs/ portage category. |
| 32 | CATEGORY="media-libs" |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 33 | # List of supported drivers |
Nicolas Boichat | 2ac05a9 | 2020-06-29 11:27:33 +0800 | [diff] [blame^] | 34 | DRIVERS="mali-drivers mali-drivers-bifrost mali-drivers-valhall img-ddk" |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 35 | |
| 36 | # List of parameters to pass to build_board, for a given package $pn: |
| 37 | # - Build board names. |
| 38 | # - Suffixes for tarball name. |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 39 | # - Overlay paths for each board. |
| 40 | # |
| 41 | # Variable name: "PARAMS_${pn//-/_}" |
| 42 | |
| 43 | PARAMS_mali_drivers=( |
Nicolas Boichat | c7140be | 2018-11-24 10:49:02 +0800 | [diff] [blame] | 44 | "daisy daisy overlay-daisy" |
| 45 | "kevin gru baseboard-gru" |
| 46 | "peach_pit peach overlay-peach" |
| 47 | "veyron_jerry veyron overlay-veyron" |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 48 | ) |
| 49 | |
Nicolas Boichat | 906df57 | 2018-08-17 09:16:47 +0800 | [diff] [blame] | 50 | PARAMS_mali_drivers_bifrost=( |
Nicolas Boichat | c7140be | 2018-11-24 10:49:02 +0800 | [diff] [blame] | 51 | "kukui kukui chipset-mt8183" |
Nicolas Boichat | 906df57 | 2018-08-17 09:16:47 +0800 | [diff] [blame] | 52 | ) |
| 53 | |
Nicolas Boichat | 2ac05a9 | 2020-06-29 11:27:33 +0800 | [diff] [blame^] | 54 | PARAMS_mali_drivers_valhall=( |
| 55 | "asurada asurada chipset-mt8192" |
| 56 | ) |
| 57 | |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 58 | PARAMS_img_ddk=( |
Nicolas Boichat | c7140be | 2018-11-24 10:49:02 +0800 | [diff] [blame] | 59 | "elm oak chipset-mt8173" |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 60 | ) |
| 61 | |
| 62 | create_run_script() { |
| 63 | local script="$1" |
| 64 | local outputtarball="$2" |
| 65 | |
| 66 | cat > "${script}" <<\__HDREOF__ |
| 67 | #!/bin/sh |
| 68 | # |
| 69 | # Copyright 2015 The Chromium OS Authors. All rights reserved. |
| 70 | # |
| 71 | # Usage is subject to the enclosed license agreement. |
| 72 | # To be generated by Makeself 1.5.3 |
| 73 | skip=@HDRSZ@ |
| 74 | echo |
| 75 | echo The license for this software will now be displayed. |
| 76 | echo You must agree to this license before using this software. |
| 77 | echo |
| 78 | |
| 79 | more << __EOF__ |
| 80 | __HDREOF__ |
| 81 | |
| 82 | cat "${SRC_ROOT}/third_party/chromiumos-overlay/licenses/Google-TOS" >> "${script}" |
| 83 | echo __EOF__ >> "${script}" |
| 84 | cat >> "${script}" <<\__BODYEOF__ |
| 85 | if [ $? != 0 ]; then |
| 86 | echo "ERROR: Couldn't display license file" 1>&2 |
| 87 | exit 1 |
| 88 | fi |
| 89 | |
| 90 | echo |
| 91 | |
| 92 | printf 'Type "y" if you agree to the terms of the license: ' |
| 93 | read typed |
| 94 | |
| 95 | if [ "${typed}" != y ]; then |
| 96 | echo |
| 97 | echo "You didn't accept the license. Extraction aborted." |
| 98 | exit 2 |
| 99 | fi |
| 100 | |
| 101 | echo |
| 102 | |
| 103 | tail -n +${skip} "$0" | tar xjv 2>/dev/null |
| 104 | |
| 105 | if [ $? -ne 0 ]; then |
| 106 | echo |
| 107 | echo "ERROR: Couldn't extract files." 1>&2 |
| 108 | exit 3 |
| 109 | else |
| 110 | echo |
| 111 | echo "Files extracted successfully." |
| 112 | fi |
| 113 | exit 0 |
| 114 | __BODYEOF__ |
| 115 | |
| 116 | local hdrsize=$(wc -l < "${script}") |
| 117 | |
| 118 | sed -i "s/@HDRSZ@/$(( hdrsize + 1 ))/g" "${script}" |
| 119 | |
| 120 | cat "${outputtarball}" >> "${script}" |
| 121 | |
| 122 | chmod +x "${script}" |
| 123 | du -b "${script}" |
| 124 | } |
| 125 | |
| 126 | # arguments: |
| 127 | # $1 board name (Chrome OS board name to build) |
| 128 | # $2 binary package suffix (suffix added to tar package name) |
Nicolas Boichat | c7140be | 2018-11-24 10:49:02 +0800 | [diff] [blame] | 129 | # $3 overlay path |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 130 | |
| 131 | build_board() { |
| 132 | local board=$1 |
| 133 | local suffix=$2 |
Nicolas Boichat | c7140be | 2018-11-24 10:49:02 +0800 | [diff] [blame] | 134 | local opath=$3 |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 135 | echo "Board is ${board}" |
| 136 | |
Nicolas Boichat | ec9dd2f | 2018-08-22 10:40:38 +0800 | [diff] [blame] | 137 | # Source PVR (e.g. 13.0-r6) |
Nicolas Boichat | 7f94c0d | 2018-11-24 17:25:38 +0800 | [diff] [blame] | 138 | local pvr |
| 139 | local inputtarball |
| 140 | |
Nicolas Boichat | b375dbf | 2018-11-28 10:36:58 +0800 | [diff] [blame] | 141 | local temp="${TEMP_DIR}/${suffix}" |
| 142 | mkdir "${temp}" |
Nicolas Boichat | 7f94c0d | 2018-11-24 17:25:38 +0800 | [diff] [blame] | 143 | pushd "${temp}" > /dev/null |
| 144 | |
| 145 | if [[ ${FLAGS_usebinpkg} -eq ${FLAGS_TRUE} ]]; then |
| 146 | # Fetch binary package from Google Storage. |
| 147 | local partner_overlay="${SRC_ROOT}/private-overlays/chromeos-partner-overlay" |
| 148 | |
| 149 | # Fetch latest preflight prebuilt version. |
| 150 | git --git-dir "${partner_overlay}/.git" fetch --all |
| 151 | local binhost_gs="$(git --git-dir "${partner_overlay}/.git" show \ |
Nicolas Boichat | ba3d6ae | 2019-10-31 18:20:41 +0800 | [diff] [blame] | 152 | "m/master:chromeos/binhost/target/${board}-POSTSUBMIT_BINHOST.conf" | \ |
| 153 | sed -nE 's/POSTSUBMIT_BINHOST=\"(.*)\"/\1/p')" |
Nicolas Boichat | 7f94c0d | 2018-11-24 17:25:38 +0800 | [diff] [blame] | 154 | |
| 155 | # Parse Packages file to find GS path of the latest ${pn} prebuilt. |
Nicolas Boichat | ba3d6ae | 2019-10-31 18:20:41 +0800 | [diff] [blame] | 156 | local prebuilt_path="$(gsutil cat "${binhost_gs}/Packages" | \ |
Nicolas Boichat | 7f94c0d | 2018-11-24 17:25:38 +0800 | [diff] [blame] | 157 | awk ' |
| 158 | $1 == "CPV:" && $2 ~ /'"${CATEGORY}"'\/'"${pn}"'-[0-9]/ { m = 1 } |
| 159 | m && $1 == "PATH:" { print $2 } |
| 160 | m && $1 == "" { exit } |
| 161 | ')" |
| 162 | local package_gs="gs://chromeos-prebuilt/${prebuilt_path}" |
| 163 | |
| 164 | gsutil cp "${package_gs}" . |
| 165 | |
| 166 | inputtarball="${temp}/${package_gs##*/}" |
| 167 | pvr="${package_gs%.*}" |
| 168 | pvr="${pvr##*${pn}-}" |
| 169 | else |
| 170 | # Build from source. |
Alex Klein | 97ed37f | 2019-01-11 14:19:14 -0700 | [diff] [blame] | 171 | setup_board --board="${board}" |
Nicolas Boichat | 7f94c0d | 2018-11-24 17:25:38 +0800 | [diff] [blame] | 172 | if [[ $? != 0 ]]; then |
| 173 | die "Setting up board ${board} failed." |
| 174 | fi |
| 175 | |
| 176 | # Make sure we are not building -9999 ebuild. |
| 177 | # This could fail if cros_workon is already stopped so ignore return code. |
| 178 | cros_workon --board="${board}" stop "${pn}" |
| 179 | |
| 180 | "emerge-${board}" "${pn}" |
| 181 | |
| 182 | if [[ $? != 0 ]]; then |
| 183 | die "Emerging ${pn} for ${board} failed." |
| 184 | fi |
| 185 | |
| 186 | pvr="$("equery-${board}" -q list -p -o --format="\$fullversion" "${pn}" | \ |
| 187 | sort -V | head -n 1)" |
| 188 | inputtarball="/build/${board}/packages/${CATEGORY}/${pn}-${pvr}.tbz2" |
| 189 | fi |
| 190 | |
Nicolas Boichat | ec9dd2f | 2018-08-22 10:40:38 +0800 | [diff] [blame] | 191 | # Binary PV (e.g. 13.0_p6) |
| 192 | local pv="${pvr/-r/_p}" |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 193 | local outputtarball="${pn}-${suffix}-${pv}.tbz2" |
| 194 | local script="${pn}-${suffix}-${pv}.run" |
| 195 | local gspath="gs://chromeos-localmirror/distfiles" |
| 196 | |
Nicolas Boichat | ec9dd2f | 2018-08-22 10:40:38 +0800 | [diff] [blame] | 197 | echo "Current version is ${pvr}" |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 198 | echo "Input tarball is ${inputtarball}" |
| 199 | echo "Output tarball is ${outputtarball}" |
| 200 | echo "Script is ${script}" |
| 201 | |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 202 | mkdir work |
| 203 | if [[ $? != 0 ]]; then |
| 204 | die "Couldn't create work directory." |
| 205 | fi |
| 206 | |
| 207 | tar -C work -xpjvf "${inputtarball}" |
| 208 | if [[ $? != 0 ]]; then |
| 209 | die "Couldn't decompress package tarball ${inputtarball}." |
| 210 | fi |
| 211 | |
| 212 | tar -C work --exclude=usr/lib/debug -cpjvf "${outputtarball}" ./ |
| 213 | if [[ $? != 0 ]]; then |
| 214 | die "Couldn't create ${outputtarball}." |
| 215 | fi |
| 216 | |
| 217 | create_run_script "${script}" "${outputtarball}" |
| 218 | |
| 219 | echo "Uploading tarball to ${gspath}/${script}" |
| 220 | if [[ ${FLAGS_dryrun} -eq ${FLAGS_TRUE} ]]; then |
| 221 | echo "Would run: gsutil cp -a public-read \"${script}\" \"${gspath}/${script}\"" |
| 222 | else |
| 223 | gsutil cp -a public-read "${script}" "${gspath}/${script}" |
| 224 | if [[ $? != 0 ]]; then |
| 225 | die "Couldn't upload ${script} to ${gspath}/${script}." |
| 226 | fi |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 227 | fi |
| 228 | |
Nicolas Boichat | c7140be | 2018-11-24 10:49:02 +0800 | [diff] [blame] | 229 | # Uprev ebuild in git if it exists. |
Nicolas Boichat | f88b0f8 | 2018-11-24 11:33:44 +0800 | [diff] [blame] | 230 | if [[ -d "${SRC_ROOT}/overlays/${opath}/${CATEGORY}/${pnbin}" ]]; then |
| 231 | cd "${SRC_ROOT}/overlays/${opath}/${CATEGORY}/${pnbin}" |
| 232 | |
| 233 | # Grab the version of the current release of the binary package. |
| 234 | local pvbin="$(printf '%s\n' *.ebuild | \ |
| 235 | sed -nE "s/^${pnbin}-(.*)\.ebuild\$/\1/p" | \ |
| 236 | sort -V | tail -n 1)" |
| 237 | echo "New binary version: ${pv} (current binary version: ${pvbin})" |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 238 | |
Nicolas Boichat | c7140be | 2018-11-24 10:49:02 +0800 | [diff] [blame] | 239 | # following git commands may fail if they have been issued previously |
Nicolas Boichat | f88b0f8 | 2018-11-24 11:33:44 +0800 | [diff] [blame] | 240 | git checkout -b "gpudriverbinupdate-${pnbin}-${pv}" |
Nicolas Boichat | c7140be | 2018-11-24 10:49:02 +0800 | [diff] [blame] | 241 | git mv "${pnbin}-${pvbin}.ebuild" "${pnbin}-${pv}.ebuild" |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 242 | |
Nicolas Boichat | f88b0f8 | 2018-11-24 11:33:44 +0800 | [diff] [blame] | 243 | ebuild "${pnbin}-${pv}.ebuild" manifest |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 244 | fi |
| 245 | |
Nicolas Boichat | 7f94c0d | 2018-11-24 17:25:38 +0800 | [diff] [blame] | 246 | popd > /dev/null |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 247 | } |
| 248 | |
Nicolas Boichat | b375dbf | 2018-11-28 10:36:58 +0800 | [diff] [blame] | 249 | cleanup() { |
| 250 | trap - INT TERM ERR EXIT |
| 251 | |
| 252 | rm -rf "${TEMP_DIR}" |
| 253 | } |
| 254 | |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 255 | main() { |
| 256 | if [[ -z ${FLAGS_package} ]]; then |
| 257 | die "Please select a package using --package [${DRIVERS// /|}]" |
| 258 | fi |
| 259 | |
| 260 | local params |
| 261 | local typed |
Nicolas Boichat | b375dbf | 2018-11-28 10:36:58 +0800 | [diff] [blame] | 262 | |
| 263 | trap cleanup INT TERM ERR EXIT |
| 264 | |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 265 | echo 'This script builds gpu drivers for a list of boards. It uploads the' |
| 266 | echo 'binaries to Google storage and makes them available in the public' |
| 267 | echo 'repository. It expects you have configured gsutil.' |
| 268 | echo |
| 269 | |
Nicolas Boichat | b375dbf | 2018-11-28 10:36:58 +0800 | [diff] [blame] | 270 | if [[ ${FLAGS_dryrun} -eq ${FLAGS_TRUE} ]]; then |
| 271 | echo "Running with --dryrun, moving forward." |
| 272 | else |
| 273 | printf 'Type "y" if you know what you are doing and want to go ahead: ' |
| 274 | read typed |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 275 | |
Nicolas Boichat | b375dbf | 2018-11-28 10:36:58 +0800 | [diff] [blame] | 276 | if [[ "${typed}" != y ]]; then |
| 277 | echo |
| 278 | echo "Good choice." |
| 279 | exit 2 |
| 280 | fi |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 281 | fi |
| 282 | |
| 283 | if [[ ! -f "${HOME}/.boto" ]]; then |
| 284 | die "You did not configure gsutil after all." |
| 285 | fi |
| 286 | |
| 287 | local pn="${FLAGS_package}" |
| 288 | local pnbin="${pn}-bin" |
| 289 | |
| 290 | local array="PARAMS_${pn//-/_}[@]" |
| 291 | |
| 292 | if [[ -z "${!array}" ]]; then |
| 293 | echo |
| 294 | echo "Nothing to do for ${pn}, you probably chose an incorrect package name." |
| 295 | echo "Supported packages: ${DRIVERS}" |
| 296 | exit 1 |
| 297 | fi |
| 298 | |
Nicolas Boichat | b375dbf | 2018-11-28 10:36:58 +0800 | [diff] [blame] | 299 | TEMP_DIR="$(mktemp -d)" |
| 300 | echo "Temp dir is ${TEMP_DIR}" |
| 301 | |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 302 | for params in "${!array}"; do |
| 303 | build_board ${params} |
| 304 | done |
| 305 | } |
| 306 | |
| 307 | main "$@" |