blob: c7ae48d2f8d46d09ff76e1a1f910faef1275cfa5 [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 Boichat2ac05a92020-06-29 11:27:33 +08006# This script builds gpu drivers (mali-drivers[-*], img-ddk) for a list
Nicolas Boichat906df572018-08-17 09:16:47 +08007# 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 Boichat2ac05a92020-06-29 11:27:33 +080034DRIVERS="mali-drivers mali-drivers-bifrost mali-drivers-valhall 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
Nicolas Boichat2ac05a92020-06-29 11:27:33 +080054PARAMS_mali_drivers_valhall=(
55 "asurada asurada chipset-mt8192"
56)
57
Mike Frysingeredd6aab2018-08-16 15:06:28 -040058PARAMS_img_ddk=(
Nicolas Boichatc7140be2018-11-24 10:49:02 +080059 "elm oak chipset-mt8173"
Mike Frysingeredd6aab2018-08-16 15:06:28 -040060)
61
62create_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
73skip=@HDRSZ@
74echo
75echo The license for this software will now be displayed.
76echo You must agree to this license before using this software.
77echo
78
79more << __EOF__
80__HDREOF__
81
82 cat "${SRC_ROOT}/third_party/chromiumos-overlay/licenses/Google-TOS" >> "${script}"
83 echo __EOF__ >> "${script}"
84 cat >> "${script}" <<\__BODYEOF__
85if [ $? != 0 ]; then
86 echo "ERROR: Couldn't display license file" 1>&2
87 exit 1
88fi
89
90echo
91
92printf 'Type "y" if you agree to the terms of the license: '
93read typed
94
95if [ "${typed}" != y ]; then
96 echo
97 echo "You didn't accept the license. Extraction aborted."
98 exit 2
99fi
100
101echo
102
103tail -n +${skip} "$0" | tar xjv 2>/dev/null
104
105if [ $? -ne 0 ]; then
106 echo
107 echo "ERROR: Couldn't extract files." 1>&2
108 exit 3
109else
110 echo
111 echo "Files extracted successfully."
112fi
113exit 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 Boichatc7140be2018-11-24 10:49:02 +0800129# $3 overlay path
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400130
131build_board() {
132 local board=$1
133 local suffix=$2
Nicolas Boichatc7140be2018-11-24 10:49:02 +0800134 local opath=$3
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400135 echo "Board is ${board}"
136
Nicolas Boichatec9dd2f2018-08-22 10:40:38 +0800137 # Source PVR (e.g. 13.0-r6)
Nicolas Boichat7f94c0d2018-11-24 17:25:38 +0800138 local pvr
139 local inputtarball
140
Nicolas Boichatb375dbf2018-11-28 10:36:58 +0800141 local temp="${TEMP_DIR}/${suffix}"
142 mkdir "${temp}"
Nicolas Boichat7f94c0d2018-11-24 17:25:38 +0800143 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 Boichatba3d6ae2019-10-31 18:20:41 +0800152 "m/master:chromeos/binhost/target/${board}-POSTSUBMIT_BINHOST.conf" | \
153 sed -nE 's/POSTSUBMIT_BINHOST=\"(.*)\"/\1/p')"
Nicolas Boichat7f94c0d2018-11-24 17:25:38 +0800154
155 # Parse Packages file to find GS path of the latest ${pn} prebuilt.
Nicolas Boichatba3d6ae2019-10-31 18:20:41 +0800156 local prebuilt_path="$(gsutil cat "${binhost_gs}/Packages" | \
Nicolas Boichat7f94c0d2018-11-24 17:25:38 +0800157 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 Klein97ed37f2019-01-11 14:19:14 -0700171 setup_board --board="${board}"
Nicolas Boichat7f94c0d2018-11-24 17:25:38 +0800172 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 Boichatec9dd2f2018-08-22 10:40:38 +0800191 # Binary PV (e.g. 13.0_p6)
192 local pv="${pvr/-r/_p}"
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400193 local outputtarball="${pn}-${suffix}-${pv}.tbz2"
194 local script="${pn}-${suffix}-${pv}.run"
195 local gspath="gs://chromeos-localmirror/distfiles"
196
Nicolas Boichatec9dd2f2018-08-22 10:40:38 +0800197 echo "Current version is ${pvr}"
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400198 echo "Input tarball is ${inputtarball}"
199 echo "Output tarball is ${outputtarball}"
200 echo "Script is ${script}"
201
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400202 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 Frysingeredd6aab2018-08-16 15:06:28 -0400227 fi
228
Nicolas Boichatc7140be2018-11-24 10:49:02 +0800229 # Uprev ebuild in git if it exists.
Nicolas Boichatf88b0f82018-11-24 11:33:44 +0800230 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 Frysingeredd6aab2018-08-16 15:06:28 -0400238
Nicolas Boichatc7140be2018-11-24 10:49:02 +0800239 # following git commands may fail if they have been issued previously
Nicolas Boichatf88b0f82018-11-24 11:33:44 +0800240 git checkout -b "gpudriverbinupdate-${pnbin}-${pv}"
Nicolas Boichatc7140be2018-11-24 10:49:02 +0800241 git mv "${pnbin}-${pvbin}.ebuild" "${pnbin}-${pv}.ebuild"
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400242
Nicolas Boichatf88b0f82018-11-24 11:33:44 +0800243 ebuild "${pnbin}-${pv}.ebuild" manifest
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400244 fi
245
Nicolas Boichat7f94c0d2018-11-24 17:25:38 +0800246 popd > /dev/null
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400247}
248
Nicolas Boichatb375dbf2018-11-28 10:36:58 +0800249cleanup() {
250 trap - INT TERM ERR EXIT
251
252 rm -rf "${TEMP_DIR}"
253}
254
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400255main() {
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 Boichatb375dbf2018-11-28 10:36:58 +0800262
263 trap cleanup INT TERM ERR EXIT
264
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400265 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 Boichatb375dbf2018-11-28 10:36:58 +0800270 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 Frysingeredd6aab2018-08-16 15:06:28 -0400275
Nicolas Boichatb375dbf2018-11-28 10:36:58 +0800276 if [[ "${typed}" != y ]]; then
277 echo
278 echo "Good choice."
279 exit 2
280 fi
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400281 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 Boichatb375dbf2018-11-28 10:36:58 +0800299 TEMP_DIR="$(mktemp -d)"
300 echo "Temp dir is ${TEMP_DIR}"
301
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400302 for params in "${!array}"; do
303 build_board ${params}
304 done
305}
306
307main "$@"