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