blob: ee07400089c7ada08709580a305b0195ecf2e5e2 [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
18
19# Parse command line.
20FLAGS "$@" || exit 1
21eval set -- "${FLAGS_ARGV}"
22
23# Script must run inside the chroot.
24assert_inside_chroot
25
26# List of supported drivers
Nicolas Boichat906df572018-08-17 09:16:47 +080027DRIVERS="mali-drivers mali-drivers-bifrost img-ddk"
Mike Frysingeredd6aab2018-08-16 15:06:28 -040028
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
37PARAMS_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 Boichat906df572018-08-17 09:16:47 +080044PARAMS_mali_drivers_bifrost=(
45 "kukui kukui kukui chipset-mt8183"
46)
47
Mike Frysingeredd6aab2018-08-16 15:06:28 -040048PARAMS_img_ddk=(
49 "elm oak oak chipset-mt8173"
50)
51
52create_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
63skip=@HDRSZ@
64echo
65echo The license for this software will now be displayed.
66echo You must agree to this license before using this software.
67echo
68
69more << __EOF__
70__HDREOF__
71
72 cat "${SRC_ROOT}/third_party/chromiumos-overlay/licenses/Google-TOS" >> "${script}"
73 echo __EOF__ >> "${script}"
74 cat >> "${script}" <<\__BODYEOF__
75if [ $? != 0 ]; then
76 echo "ERROR: Couldn't display license file" 1>&2
77 exit 1
78fi
79
80echo
81
82printf 'Type "y" if you agree to the terms of the license: '
83read typed
84
85if [ "${typed}" != y ]; then
86 echo
87 echo "You didn't accept the license. Extraction aborted."
88 exit 2
89fi
90
91echo
92
93tail -n +${skip} "$0" | tar xjv 2>/dev/null
94
95if [ $? -ne 0 ]; then
96 echo
97 echo "ERROR: Couldn't extract files." 1>&2
98 exit 3
99else
100 echo
101 echo "Files extracted successfully."
102fi
103exit 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
122build_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 Boichatec9dd2f2018-08-22 10:40:38 +0800152 # 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 Frysingeredd6aab2018-08-16 15:06:28 -0400158 local outputtarball="${pn}-${suffix}-${pv}.tbz2"
159 local script="${pn}-${suffix}-${pv}.run"
160 local gspath="gs://chromeos-localmirror/distfiles"
161
Nicolas Boichatec9dd2f2018-08-22 10:40:38 +0800162 echo "Current version is ${pvr}"
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400163 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 Boichatec9dd2f2018-08-22 10:40:38 +0800201 echo "New binary version: ${pv} (current binary version: ${pvbin})"
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400202 # 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 Boichatec9dd2f2018-08-22 10:40:38 +0800207 git checkout -b "gpudriverbinupdate-${pv}"
Mike Frysingeredd6aab2018-08-16 15:06:28 -0400208 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
217main() {
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
259main "$@"