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 | 906df57 | 2018-08-17 09:16:47 +0800 | [diff] [blame] | 6 | # This script builds gpu drivers (mali-drivers[-bifrost], img-ddk) for a list |
| 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 |
| 18 | |
| 19 | # Parse command line. |
| 20 | FLAGS "$@" || exit 1 |
| 21 | eval set -- "${FLAGS_ARGV}" |
| 22 | |
| 23 | # Script must run inside the chroot. |
| 24 | assert_inside_chroot |
| 25 | |
| 26 | # List of supported drivers |
Nicolas Boichat | 906df57 | 2018-08-17 09:16:47 +0800 | [diff] [blame] | 27 | DRIVERS="mali-drivers mali-drivers-bifrost img-ddk" |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 28 | |
| 29 | # List of parameters to pass to build_board, for a given package $pn: |
| 30 | # - Build board names. |
| 31 | # - Suffixes for tarball name. |
| 32 | # - Board names for overlay with mali-drivers-bin.ebuild. |
| 33 | # - Overlay paths for each board. |
| 34 | # |
| 35 | # Variable name: "PARAMS_${pn//-/_}" |
| 36 | |
| 37 | PARAMS_mali_drivers=( |
| 38 | "daisy daisy daisy overlay-daisy" |
| 39 | "kevin gru gru baseboard-gru" |
| 40 | "peach_pit peach peach overlay-peach" |
| 41 | "veyron_jerry veyron veyron overlay-veyron" |
| 42 | ) |
| 43 | |
Nicolas Boichat | 906df57 | 2018-08-17 09:16:47 +0800 | [diff] [blame] | 44 | PARAMS_mali_drivers_bifrost=( |
| 45 | "kukui kukui kukui chipset-mt8183" |
| 46 | ) |
| 47 | |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 48 | PARAMS_img_ddk=( |
| 49 | "elm oak oak chipset-mt8173" |
| 50 | ) |
| 51 | |
| 52 | create_run_script() { |
| 53 | local script="$1" |
| 54 | local outputtarball="$2" |
| 55 | |
| 56 | cat > "${script}" <<\__HDREOF__ |
| 57 | #!/bin/sh |
| 58 | # |
| 59 | # Copyright 2015 The Chromium OS Authors. All rights reserved. |
| 60 | # |
| 61 | # Usage is subject to the enclosed license agreement. |
| 62 | # To be generated by Makeself 1.5.3 |
| 63 | skip=@HDRSZ@ |
| 64 | echo |
| 65 | echo The license for this software will now be displayed. |
| 66 | echo You must agree to this license before using this software. |
| 67 | echo |
| 68 | |
| 69 | more << __EOF__ |
| 70 | __HDREOF__ |
| 71 | |
| 72 | cat "${SRC_ROOT}/third_party/chromiumos-overlay/licenses/Google-TOS" >> "${script}" |
| 73 | echo __EOF__ >> "${script}" |
| 74 | cat >> "${script}" <<\__BODYEOF__ |
| 75 | if [ $? != 0 ]; then |
| 76 | echo "ERROR: Couldn't display license file" 1>&2 |
| 77 | exit 1 |
| 78 | fi |
| 79 | |
| 80 | echo |
| 81 | |
| 82 | printf 'Type "y" if you agree to the terms of the license: ' |
| 83 | read typed |
| 84 | |
| 85 | if [ "${typed}" != y ]; then |
| 86 | echo |
| 87 | echo "You didn't accept the license. Extraction aborted." |
| 88 | exit 2 |
| 89 | fi |
| 90 | |
| 91 | echo |
| 92 | |
| 93 | tail -n +${skip} "$0" | tar xjv 2>/dev/null |
| 94 | |
| 95 | if [ $? -ne 0 ]; then |
| 96 | echo |
| 97 | echo "ERROR: Couldn't extract files." 1>&2 |
| 98 | exit 3 |
| 99 | else |
| 100 | echo |
| 101 | echo "Files extracted successfully." |
| 102 | fi |
| 103 | exit 0 |
| 104 | __BODYEOF__ |
| 105 | |
| 106 | local hdrsize=$(wc -l < "${script}") |
| 107 | |
| 108 | sed -i "s/@HDRSZ@/$(( hdrsize + 1 ))/g" "${script}" |
| 109 | |
| 110 | cat "${outputtarball}" >> "${script}" |
| 111 | |
| 112 | chmod +x "${script}" |
| 113 | du -b "${script}" |
| 114 | } |
| 115 | |
| 116 | # arguments: |
| 117 | # $1 board name (Chrome OS board name to build) |
| 118 | # $2 binary package suffix (suffix added to tar package name) |
| 119 | # $3 overlay board name |
| 120 | # $4 overlay path |
| 121 | |
| 122 | build_board() { |
| 123 | local board=$1 |
| 124 | local suffix=$2 |
| 125 | local oboard=$3 |
| 126 | local opath=$4 |
| 127 | echo "Board is ${board}" |
| 128 | |
| 129 | if [[ "$oboard" != "X11" ]]; then |
| 130 | "${SRC_ROOT}/scripts/setup_board" --board="${oboard}" |
| 131 | fi |
| 132 | "${SRC_ROOT}/scripts/setup_board" --board="${board}" |
| 133 | if [[ $? != 0 ]]; then |
| 134 | die "Setting up board ${board} failed." |
| 135 | fi |
| 136 | |
| 137 | # Make sure we are not building -9999 ebuild. |
| 138 | # This could fail if cros_workon is already stopped so ignore return code. |
| 139 | cros_workon --board="${board}" stop ${pn} |
| 140 | |
| 141 | if [[ "$oboard" == "X11" ]]; then |
| 142 | echo "Building special X11 package" |
| 143 | USE=X emerge-${board} ${pn} |
| 144 | else |
| 145 | emerge-${board} ${pn} |
| 146 | fi |
| 147 | |
| 148 | if [[ $? != 0 ]]; then |
| 149 | die "Emerging ${pn} for ${board} failed." |
| 150 | fi |
| 151 | |
Nicolas Boichat | ec9dd2f | 2018-08-22 10:40:38 +0800 | [diff] [blame^] | 152 | # Source PVR (e.g. 13.0-r6) |
| 153 | local pvr="$("equery-${board}" -q list -p -o --format="\$fullversion" ${pn} | sort | head -n 1)" |
| 154 | # Binary PV (e.g. 13.0_p6) |
| 155 | local pv="${pvr/-r/_p}" |
| 156 | local category="$("equery-${board}" -q list -p -o --format="\$category" ${pn} | sort | head -n 1)" |
| 157 | local inputtarball="/build/${board}/packages/${category}/${pn}-${pvr}.tbz2" |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 158 | local outputtarball="${pn}-${suffix}-${pv}.tbz2" |
| 159 | local script="${pn}-${suffix}-${pv}.run" |
| 160 | local gspath="gs://chromeos-localmirror/distfiles" |
| 161 | |
Nicolas Boichat | ec9dd2f | 2018-08-22 10:40:38 +0800 | [diff] [blame^] | 162 | echo "Current version is ${pvr}" |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 163 | echo "Input tarball is ${inputtarball}" |
| 164 | echo "Output tarball is ${outputtarball}" |
| 165 | echo "Script is ${script}" |
| 166 | |
| 167 | local temp=$(mktemp -d) |
| 168 | echo "Temp dir is ${temp}" |
| 169 | pushd "${temp}" >& /dev/null |
| 170 | |
| 171 | mkdir work |
| 172 | if [[ $? != 0 ]]; then |
| 173 | die "Couldn't create work directory." |
| 174 | fi |
| 175 | |
| 176 | tar -C work -xpjvf "${inputtarball}" |
| 177 | if [[ $? != 0 ]]; then |
| 178 | die "Couldn't decompress package tarball ${inputtarball}." |
| 179 | fi |
| 180 | |
| 181 | tar -C work --exclude=usr/lib/debug -cpjvf "${outputtarball}" ./ |
| 182 | if [[ $? != 0 ]]; then |
| 183 | die "Couldn't create ${outputtarball}." |
| 184 | fi |
| 185 | |
| 186 | create_run_script "${script}" "${outputtarball}" |
| 187 | |
| 188 | echo "Uploading tarball to ${gspath}/${script}" |
| 189 | if [[ ${FLAGS_dryrun} -eq ${FLAGS_TRUE} ]]; then |
| 190 | echo "Would run: gsutil cp -a public-read \"${script}\" \"${gspath}/${script}\"" |
| 191 | else |
| 192 | gsutil cp -a public-read "${script}" "${gspath}/${script}" |
| 193 | if [[ $? != 0 ]]; then |
| 194 | die "Couldn't upload ${script} to ${gspath}/${script}." |
| 195 | fi |
| 196 | rm -rf "${temp}" |
| 197 | fi |
| 198 | |
| 199 | if [[ "${oboard}" != "X11" ]]; then |
| 200 | local pvbin=$("equery-${board}" -q list -p -o --format="\$fullversion" ${pnbin} | sort | head -n 1) |
Nicolas Boichat | ec9dd2f | 2018-08-22 10:40:38 +0800 | [diff] [blame^] | 201 | echo "New binary version: ${pv} (current binary version: ${pvbin})" |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 202 | # Uprev ebuild in git if it exists. |
| 203 | if [[ -d "${SRC_ROOT}/overlays/${opath}/${category}/${pnbin}" ]]; then |
| 204 | cd "${SRC_ROOT}/overlays/${opath}/${category}/${pnbin}" |
| 205 | |
| 206 | # following git commands may fail if they have been issued previously |
Nicolas Boichat | ec9dd2f | 2018-08-22 10:40:38 +0800 | [diff] [blame^] | 207 | git checkout -b "gpudriverbinupdate-${pv}" |
Mike Frysinger | edd6aab | 2018-08-16 15:06:28 -0400 | [diff] [blame] | 208 | git mv "${pnbin}-${pvbin}.ebuild" "${pnbin}-${pv}.ebuild" |
| 209 | |
| 210 | "ebuild-${oboard}" "${pnbin}-${pv}.ebuild" manifest |
| 211 | fi |
| 212 | fi |
| 213 | |
| 214 | popd >& /dev/null |
| 215 | } |
| 216 | |
| 217 | main() { |
| 218 | if [[ -z ${FLAGS_package} ]]; then |
| 219 | die "Please select a package using --package [${DRIVERS// /|}]" |
| 220 | fi |
| 221 | |
| 222 | local params |
| 223 | local typed |
| 224 | echo 'This script builds gpu drivers for a list of boards. It uploads the' |
| 225 | echo 'binaries to Google storage and makes them available in the public' |
| 226 | echo 'repository. It expects you have configured gsutil.' |
| 227 | echo |
| 228 | |
| 229 | printf 'Type "y" if you know what you are doing and want to go ahead: ' |
| 230 | read typed |
| 231 | |
| 232 | if [[ "${typed}" != y ]]; then |
| 233 | echo |
| 234 | echo "Good choice." |
| 235 | exit 2 |
| 236 | fi |
| 237 | |
| 238 | if [[ ! -f "${HOME}/.boto" ]]; then |
| 239 | die "You did not configure gsutil after all." |
| 240 | fi |
| 241 | |
| 242 | local pn="${FLAGS_package}" |
| 243 | local pnbin="${pn}-bin" |
| 244 | |
| 245 | local array="PARAMS_${pn//-/_}[@]" |
| 246 | |
| 247 | if [[ -z "${!array}" ]]; then |
| 248 | echo |
| 249 | echo "Nothing to do for ${pn}, you probably chose an incorrect package name." |
| 250 | echo "Supported packages: ${DRIVERS}" |
| 251 | exit 1 |
| 252 | fi |
| 253 | |
| 254 | for params in "${!array}"; do |
| 255 | build_board ${params} |
| 256 | done |
| 257 | } |
| 258 | |
| 259 | main "$@" |