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