blob: 667a6bde3e4b5d23cccb8a846b4265a4c35018e8 [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
Fei Shao075ed552021-01-05 16:53:34 +080020DEFINE_boolean clobber ${FLAGS_FALSE} \
21 "overwrites the existing binaries when uploading" c
Mike Frysingeredd6aab2018-08-16 15:06:28 -040022
23# Parse command line.
24FLAGS "$@" || exit 1
25eval set -- "${FLAGS_ARGV}"
26
27# Script must run inside the chroot.
28assert_inside_chroot
29
Nicolas Boichatb375dbf2018-11-28 10:36:58 +080030# The temp dir to use for scratch space.
31TEMP_DIR=""
32
Nicolas Boichatf88b0f82018-11-24 11:33:44 +080033# All drivers are in media-libs/ portage category.
34CATEGORY="media-libs"
Mike Frysingeredd6aab2018-08-16 15:06:28 -040035# List of supported drivers
Fei Shaobd9ce852021-05-07 23:35:16 +080036DRIVERS="arc-mali-drivers-bifrost arc-mali-drivers-valhall mali-drivers mali-drivers-bifrost mali-drivers-valhall img-ddk"
Mike Frysingeredd6aab2018-08-16 15:06:28 -040037
38# List of parameters to pass to build_board, for a given package $pn:
39# - Build board names.
40# - Suffixes for tarball name.
Mike Frysingeredd6aab2018-08-16 15:06:28 -040041# - Overlay paths for each board.
42#
43# Variable name: "PARAMS_${pn//-/_}"
44
Fei Shao553075a2021-04-21 18:47:20 +080045PARAMS_arc_mali_drivers_bifrost=(
46 "kukui kukui chipset-mt8183"
47)
48
49PARAMS_arc_mali_drivers_valhall=(
50 "asurada asurada chipset-mt8192"
Fei Shao97173b22021-04-23 11:08:51 +080051 "cherry cherry chipset-mt8195"
Fei Shao553075a2021-04-21 18:47:20 +080052)
53
Mike Frysingeredd6aab2018-08-16 15:06:28 -040054PARAMS_mali_drivers=(
Nicolas Boichatc7140be2018-11-24 10:49:02 +080055 "daisy daisy overlay-daisy"
56 "kevin gru baseboard-gru"
57 "peach_pit peach overlay-peach"
58 "veyron_jerry veyron overlay-veyron"
Mike Frysingeredd6aab2018-08-16 15:06:28 -040059)
60
Nicolas Boichat906df572018-08-17 09:16:47 +080061PARAMS_mali_drivers_bifrost=(
Nicolas Boichatc7140be2018-11-24 10:49:02 +080062 "kukui kukui chipset-mt8183"
Nicolas Boichat906df572018-08-17 09:16:47 +080063)
64
Nicolas Boichat2ac05a92020-06-29 11:27:33 +080065PARAMS_mali_drivers_valhall=(
66 "asurada asurada chipset-mt8192"
Fei Shao97173b22021-04-23 11:08:51 +080067 "cherry cherry chipset-mt8195"
Nicolas Boichat2ac05a92020-06-29 11:27:33 +080068)
69
Mike Frysingeredd6aab2018-08-16 15:06:28 -040070PARAMS_img_ddk=(
Nicolas Boichatc7140be2018-11-24 10:49:02 +080071 "elm oak chipset-mt8173"
Mike Frysingeredd6aab2018-08-16 15:06:28 -040072)
73
74create_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
85skip=@HDRSZ@
86echo
87echo The license for this software will now be displayed.
88echo You must agree to this license before using this software.
89echo
90
91more << __EOF__
92__HDREOF__
93
94 cat "${SRC_ROOT}/third_party/chromiumos-overlay/licenses/Google-TOS" >> "${script}"
95 echo __EOF__ >> "${script}"
96 cat >> "${script}" <<\__BODYEOF__
97if [ $? != 0 ]; then
98 echo "ERROR: Couldn't display license file" 1>&2
99 exit 1
100fi
101
102echo
103
104printf 'Type "y" if you agree to the terms of the license: '
105read typed
106
107if [ "${typed}" != y ]; then
108 echo
109 echo "You didn't accept the license. Extraction aborted."
110 exit 2
111fi
112
113echo
114
115tail -n +${skip} "$0" | tar xjv 2>/dev/null
116
117if [ $? -ne 0 ]; then
118 echo
119 echo "ERROR: Couldn't extract files." 1>&2
120 exit 3
121else
122 echo
123 echo "Files extracted successfully."
124fi
125exit 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 Boichatc7140be2018-11-24 10:49:02 +0800141# $3 overlay path
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400142
143build_board() {
144 local board=$1
145 local suffix=$2
Nicolas Boichatc7140be2018-11-24 10:49:02 +0800146 local opath=$3
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400147 echo "Board is ${board}"
148
Nicolas Boichatec9dd2f2018-08-22 10:40:38 +0800149 # Source PVR (e.g. 13.0-r6)
Nicolas Boichat7f94c0d2018-11-24 17:25:38 +0800150 local pvr
151 local inputtarball
152
Nicolas Boichatb375dbf2018-11-28 10:36:58 +0800153 local temp="${TEMP_DIR}/${suffix}"
154 mkdir "${temp}"
Nicolas Boichat7f94c0d2018-11-24 17:25:38 +0800155 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 Boichatba3d6ae2019-10-31 18:20:41 +0800164 "m/master:chromeos/binhost/target/${board}-POSTSUBMIT_BINHOST.conf" | \
165 sed -nE 's/POSTSUBMIT_BINHOST=\"(.*)\"/\1/p')"
Nicolas Boichat7f94c0d2018-11-24 17:25:38 +0800166
167 # Parse Packages file to find GS path of the latest ${pn} prebuilt.
Nicolas Boichatba3d6ae2019-10-31 18:20:41 +0800168 local prebuilt_path="$(gsutil cat "${binhost_gs}/Packages" | \
Nicolas Boichat7f94c0d2018-11-24 17:25:38 +0800169 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 Klein97ed37f2019-01-11 14:19:14 -0700183 setup_board --board="${board}"
Nicolas Boichat7f94c0d2018-11-24 17:25:38 +0800184 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 Boichatec9dd2f2018-08-22 10:40:38 +0800203 # Binary PV (e.g. 13.0_p6)
204 local pv="${pvr/-r/_p}"
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400205 local outputtarball="${pn}-${suffix}-${pv}.tbz2"
206 local script="${pn}-${suffix}-${pv}.run"
207 local gspath="gs://chromeos-localmirror/distfiles"
208
Nicolas Boichatec9dd2f2018-08-22 10:40:38 +0800209 echo "Current version is ${pvr}"
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400210 echo "Input tarball is ${inputtarball}"
211 echo "Output tarball is ${outputtarball}"
212 echo "Script is ${script}"
213
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400214 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 Shao075ed552021-01-05 16:53:34 +0800233 echo "Would run: gsutil cp -n -a public-read \"${script}\" \"${gspath}/${script}\""
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400234 else
Fei Shao075ed552021-01-05 16:53:34 +0800235 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 Frysingeredd6aab2018-08-16 15:06:28 -0400247 if [[ $? != 0 ]]; then
248 die "Couldn't upload ${script} to ${gspath}/${script}."
249 fi
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400250 fi
251
Nicolas Boichatc7140be2018-11-24 10:49:02 +0800252 # Uprev ebuild in git if it exists.
Nicolas Boichatf88b0f82018-11-24 11:33:44 +0800253 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 Frysingeredd6aab2018-08-16 15:06:28 -0400261
Nicolas Boichatc7140be2018-11-24 10:49:02 +0800262 # following git commands may fail if they have been issued previously
Nicolas Boichatf88b0f82018-11-24 11:33:44 +0800263 git checkout -b "gpudriverbinupdate-${pnbin}-${pv}"
Nicolas Boichatc7140be2018-11-24 10:49:02 +0800264 git mv "${pnbin}-${pvbin}.ebuild" "${pnbin}-${pv}.ebuild"
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400265
Nicolas Boichatf88b0f82018-11-24 11:33:44 +0800266 ebuild "${pnbin}-${pv}.ebuild" manifest
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400267 fi
268
Nicolas Boichat7f94c0d2018-11-24 17:25:38 +0800269 popd > /dev/null
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400270}
271
Nicolas Boichatb375dbf2018-11-28 10:36:58 +0800272cleanup() {
273 trap - INT TERM ERR EXIT
274
275 rm -rf "${TEMP_DIR}"
276}
277
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400278main() {
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 Boichatb375dbf2018-11-28 10:36:58 +0800285
286 trap cleanup INT TERM ERR EXIT
287
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400288 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 Boichatb375dbf2018-11-28 10:36:58 +0800293 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 Frysingeredd6aab2018-08-16 15:06:28 -0400298
Nicolas Boichatb375dbf2018-11-28 10:36:58 +0800299 if [[ "${typed}" != y ]]; then
300 echo
301 echo "Good choice."
302 exit 2
303 fi
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400304 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 Boichatb375dbf2018-11-28 10:36:58 +0800322 TEMP_DIR="$(mktemp -d)"
323 echo "Temp dir is ${TEMP_DIR}"
324
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400325 for params in "${!array}"; do
326 build_board ${params}
327 done
328}
329
330main "$@"