blob: bc8a7fa1275ae5384fdef6cd6fdfb07bb38760fb [file] [log] [blame]
Andrew McRae0809eb52020-06-18 00:13:36 +10001#!/bin/bash
2# Copyright 2020 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#
Andrew McRae0809eb52020-06-18 00:13:36 +10006# Script to update base firmware in a program's config, and then
7# regenerate the configs of projects that are part of the program.
8# Also updates the firmware manifest, and uploads all of the changes
9# for review.
10#
11# Usage:
Andrew McRae7c9655c2020-06-22 15:09:54 +100012# ./update_program_fw --board=program --release=NNNNN [ --reviewer=reviewer ]
13# [ --project=proj... ]
Andrew McRae0809eb52020-06-18 00:13:36 +100014# E.g:
Andrew McRae7c9655c2020-06-22 15:09:54 +100015# ./update_program_fw --board=puff --release=13291 --reviewer=amcrae@google.com
Andrew McRae0809eb52020-06-18 00:13:36 +100016#
Andrew McRae88eda242020-06-26 12:35:55 +100017# TODO:
18# - Handle minor version
19#
Andrew McRae7c9655c2020-06-22 15:09:54 +100020CONTRIB_DIR=$(dirname "$(readlink -f "$0")")
21. "${CONTRIB_DIR}/common.sh" || exit 1
22
23FLAGS_HELP="
24Command to update the firmware version for a board.
25
Andrew McRae88eda242020-06-26 12:35:55 +100026Updates the firmware version configuration for a board's
Andrew McRae7c9655c2020-06-22 15:09:54 +100027master configuration (program.star) and for selected projects
28that include the master configuration.
29
30If no projects are specified, all projects for that board are selected.
Andrew McRaef96cd602020-06-23 23:06:19 +100031An optional skip list can be specified to skip selected boards.
Andrew McRae7c9655c2020-06-22 15:09:54 +100032
33The configurations for the selected projects are regenerated,
34and the firmware manifest are updated for the projects.
35
36The necessary CLs for these changes are created and uploaded for review.
37An optional reviewer can be specified to send all the CLs to.
38"
39# Flags
Andrew McRae88eda242020-06-26 12:35:55 +100040DEFINE_string board "${DEFAULT_BOARD}" "Which board (program) the firmware is for (e.g 'puff')" b
41DEFINE_integer release 0 "The firmware release to update to (e.g 13310)" r
42DEFINE_string project "${DEFAULT_PROJECT}" "Which projects this release is for (defaults to all), e.g 'duffy'" p
Andrew McRae3b94aaf2020-06-25 15:28:18 +100043DEFINE_string bug "none" "The bug to reference in the CL e.g b:12345"
Andrew McRae88eda242020-06-26 12:35:55 +100044DEFINE_string skip "${DEFAULT_SKIP}" "Skip these projects (comma separated list)" s
45DEFINE_boolean build "${FLAGS_TRUE}" "Attempt to build coreboot"
46DEFINE_boolean program "${FLAGS_TRUE}" "Update the version in the base program.star"
Andrew McRae7c9655c2020-06-22 15:09:54 +100047DEFINE_string reviewer "${DEFAULT_REVIEWER}" "The reviewer to send the CLs to (optional)"
Andrew McRae88eda242020-06-26 12:35:55 +100048DEFINE_string test "none" "The 'TEST=' string added to the commit message"
49DEFINE_boolean dryrun "${FLAGS_FALSE}" "Do not perform any actions, just validate and print arguments"
50
51# Set before flag processing
52COMMAND=$(basename "$0")
53CMDARGS="$*"
Andrew McRae7c9655c2020-06-22 15:09:54 +100054
55# Parse command line
56FLAGS "$@" || exit 1
57eval set -- "${FLAGS_ARGV}"
58set -e
59
60# Script must be run inside the chroot.
61assert_inside_chroot
Andrew McRae0809eb52020-06-18 00:13:36 +100062#
63# Variables
64#
Andrew McRae7c9655c2020-06-22 15:09:54 +100065PATH="${PATH}:${GCLIENT_ROOT}/src/config/bin"
Andrew McRae0809eb52020-06-18 00:13:36 +100066DIGITS="[1-9][0-9][0-9][0-9][0-9]"
Andrew McRae0809eb52020-06-18 00:13:36 +100067BRANCH=""
Andrew McRae0809eb52020-06-18 00:13:36 +100068PROGRAM_CL=""
Andrew McRae88eda242020-06-26 12:35:55 +100069MAJORV=" major_version = "
70ANY_MV="${MAJORV}${DIGITS}"
71NEW_MV="${MAJORV}${FLAGS_release}"
Andrew McRae0809eb52020-06-18 00:13:36 +100072#
73# Common functions
74#
75cleanup() {
Andrew McRae7c9655c2020-06-22 15:09:54 +100076 if [[ -d "${TEMPDIR}" ]]; then
77 rm -rf "${TEMPDIR}"
Andrew McRae0809eb52020-06-18 00:13:36 +100078 fi
Andrew McRae0809eb52020-06-18 00:13:36 +100079}
80#
81# Abort the update, and clean up branches and CLs
82#
83abort() {
Andrew McRae0809eb52020-06-18 00:13:36 +100084 CLS=$(gerrit -i --raw search "owner:me status:open hashtag:${BRANCH}")
85 if [[ -n "${CLS}" ]]; then
86 echo "Abandoning uploaded CLs"
Andrew McRaef96cd602020-06-23 23:06:19 +100087 for cl in ${CLS}; do
88 gerrit -i abandon "${cl}"
89 done
Andrew McRae0809eb52020-06-18 00:13:36 +100090 fi
Andrew McRae7c9655c2020-06-22 15:09:54 +100091 "cros_workon-${FLAGS_board}" stop "chromeos-base/chromeos-firmware-${FLAGS_board}"
92 "cros_workon-${FLAGS_board}" stop "chromeos-base/chromeos-config-bsp-${FLAGS_board}-private"
Andrew McRae0809eb52020-06-18 00:13:36 +100093 repo abandon "${BRANCH}"
Andrew McRae7c9655c2020-06-22 15:09:54 +100094 die "$*"
Andrew McRae0809eb52020-06-18 00:13:36 +100095}
96#
Andrew McRae88eda242020-06-26 12:35:55 +100097# Extract a CL number from the file containing the output of repo upload
Andrew McRae0809eb52020-06-18 00:13:36 +100098#
99getcl() {
100 CL=$(grep -o "https://chrome-internal-review.googlesource.com/c/chromeos/$1/+/[0-9][0-9]*" "$2")
101 if [[ -z "${CL}" ]]; then
102 cat "$2"
103 abort CL number not found in repo upload output
104 fi
105 echo "${CL}" | grep -o "[0-9][0-9]*"
106}
107#
108# If not on this branch, start a branch
109#
110branch() {
111 if ! (git branch --show-current | grep -q "${BRANCH}"); then
112 repo start "${BRANCH}"
113 else
114 echo "${BRANCH} already exists, skipping repo start"
115 fi
116}
117#
118# Return true if repo has changes.
Andrew McRae88eda242020-06-26 12:35:55 +1000119#
Andrew McRae0809eb52020-06-18 00:13:36 +1000120changed() {
121 [[ -n $(git status -s) ]]
122}
123#
124# Add a Cq-Depend line to a commit.
Andrew McRae0809eb52020-06-18 00:13:36 +1000125#
126amend() {
Andrew McRaef96cd602020-06-23 23:06:19 +1000127 git log -1 --pretty=%B > "${TEMPDIR}/amend-msg"
128 sed -i "/^Change-Id/ i ${1}" "${TEMPDIR}/amend-msg"
129 git commit -q --amend -F "${TEMPDIR}/amend-msg"
130}
131#
Andrew McRae88eda242020-06-26 12:35:55 +1000132# Confirm that $1 is a valid project
133#
134check_project() {
135 PDIR="${GCLIENT_ROOT}/src/project/${FLAGS_board}/${1}"
136 if [[ ! -d "${PDIR}" ]]; then
137 die "${P} is not a valid project (${PDIR} missing)"
138 fi
139}
140#
Andrew McRaef96cd602020-06-23 23:06:19 +1000141# Return true if $1 is in list $2
142#
143in_list() {
144 for S in ${2}; do
145 if [[ "$1" == "${S}" ]]; then
146 return 0
147 fi
148 done
149 return 1
Andrew McRae0809eb52020-06-18 00:13:36 +1000150}
151#
Andrew McRae88eda242020-06-26 12:35:55 +1000152# Return 0 if file has version in it.
153#
154has_version() {
155 (grep -q "${ANY_MV}" "${1}")
156}
157#
158# Update the major version in the file passed.
159# return 0 if version updated.
160# return 1 if version not in file, or unchanged.
161#
162update_version() {
163 # Check for major_version in file.
164 if ! (has_version "${1}") ;then
165 return 1
166 fi
167 local nf="${TEMPDIR}/new-${1}"
168 sed "/${ANY_MV}/s/${ANY_MV}/${NEW_MV}/" "${1}" > "${nf}"
169 #
170 # Verify that only 1-5 characters have changed.
171 #
172 DIFF=$(cmp -l "${1}" "${nf}" | wc -l)
173 if [[ "${DIFF}" -gt 5 ]]; then
174 diff "${1}" "{nf}}"
175 abort "${1} update error"
176 fi
177 if [[ "${DIFF}" == 0 ]]; then
178 return 1
179 fi
180 cp "${nf}" "${1}"
181 return 0
182}
183#
Andrew McRae0809eb52020-06-18 00:13:36 +1000184# Validate arguments
185#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000186if [[ -z "${FLAGS_board}" ]]; then
187 die "-b or --board required."
188fi
189if [[ -z "${FLAGS_release}" ]]; then
190 die "-r or --release required."
Andrew McRae0809eb52020-06-18 00:13:36 +1000191fi
192#
193# Program must exist as a directory
194#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000195PROGDIR="${GCLIENT_ROOT}/src/program/${FLAGS_board}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000196if [[ ! -d "${PROGDIR}" ]]; then
Andrew McRae7c9655c2020-06-22 15:09:54 +1000197 die "${FLAGS_board} is not a valid program (${PROGDIR} missing)"
Andrew McRae0809eb52020-06-18 00:13:36 +1000198fi
199# Release must be a 5 digit number
Andrew McRae7c9655c2020-06-22 15:09:54 +1000200if [[ ! "${FLAGS_release}" =~ ^${DIGITS}$ ]]; then
Andrew McRaef96cd602020-06-23 23:06:19 +1000201 die "release must be a 5 digit number"
Andrew McRae0809eb52020-06-18 00:13:36 +1000202fi
Andrew McRaef96cd602020-06-23 23:06:19 +1000203# Use a common git branch name.
204BRANCH="update_${FLAGS_board}_fw_${FLAGS_release}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000205#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000206# Build the project list.
Andrew McRaef96cd602020-06-23 23:06:19 +1000207# If no projects are specified, use all in the programs directory.
Andrew McRae0809eb52020-06-18 00:13:36 +1000208#
Andrew McRaef96cd602020-06-23 23:06:19 +1000209if [[ -z "${FLAGS_project}" ]]; then
Andrew McRae7c9655c2020-06-22 15:09:54 +1000210 BDIR="${GCLIENT_ROOT}/src/project/${FLAGS_board}"
Andrew McRaef96cd602020-06-23 23:06:19 +1000211 cd "${BDIR}"
212 mapfile -t PROJLIST < <(ls)
213else
214 IFS=',' read -r -a PROJLIST <<< "${FLAGS_project}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000215fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000216#
Andrew McRaef96cd602020-06-23 23:06:19 +1000217# Filter out the projects that are to be skipped.
218#
219if [[ -n "${FLAGS_skip}" ]]; then
220 PROJECTS=()
221 IFS=',' read -r -a SKIP_ARRAY <<< "${FLAGS_skip}"
Andrew McRae88eda242020-06-26 12:35:55 +1000222 # Validate skipped projects
223 for S in "${SKIP_ARRAY[@]}"; do
224 check_project "${S}"
225 done
Andrew McRaef96cd602020-06-23 23:06:19 +1000226 SKIPPED="${SKIP_ARRAY[*]}"
227 for P in "${PROJLIST[@]}"; do
228 if ! (in_list "${P}" "${SKIPPED}"); then
229 PROJECTS+=("${P}")
230 fi
231 done
232else
233 PROJECTS=("${PROJLIST[@]}")
234fi
235#
Andrew McRae88eda242020-06-26 12:35:55 +1000236# Valid bug number (if any).
237# Must be of the form b:nnnnn or chromium:nnnnn
238#
239if [[ "${FLAGS_bug}" != "none" ]]; then
240 BG="b:[0-9]+|chromium:[0-9]+"
241 BGRE="^(${BG})(,(${BG}))*$"
242 if [[ ! "${FLAGS_bug}" =~ ${BGRE} ]]; then
243 echo "Bug must be of the form b:nnn or chromium:nnn"
244 die "A comma separated list is allowed"
245 fi
246fi
247#
Andrew McRaef96cd602020-06-23 23:06:19 +1000248# Validate project list and file locations.
Andrew McRae7c9655c2020-06-22 15:09:54 +1000249#
250for P in "${PROJECTS[@]}"; do
Andrew McRae88eda242020-06-26 12:35:55 +1000251 check_project "${P}"
Andrew McRae7c9655c2020-06-22 15:09:54 +1000252done
Andrew McRaef96cd602020-06-23 23:06:19 +1000253OVERLAY="${GCLIENT_ROOT}/src/private-overlays/overlay-${FLAGS_board}-private/chromeos-base/chromeos-firmware-${FLAGS_board}"
Andrew McRae88eda242020-06-26 12:35:55 +1000254# Validate project overlay and ebuild file
Andrew McRaef96cd602020-06-23 23:06:19 +1000255EB9999="chromeos-firmware-${FLAGS_board}-9999.ebuild"
256if [[ ! -f "${OVERLAY}/${EB9999}" ]]; then
Andrew McRae88eda242020-06-26 12:35:55 +1000257 die "${OVERLAY}/${EB9999}: overlay error"
Andrew McRaef96cd602020-06-23 23:06:19 +1000258fi
259# Make sure dev/contrib is accessible
260DEVCONTRIB="${GCLIENT_ROOT}/src/platform/dev/contrib"
261if [[ ! -d "${DEVCONTRIB}" ]]; then
262 die "${DEVCONTRIB}: invalid directory"
263fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000264#
Andrew McRae88eda242020-06-26 12:35:55 +1000265# If requesting dry run, dump arguments and exit.
266#
267if [[ "${FLAGS_dryrun}" -eq "${FLAGS_TRUE}" ]]; then
268 echo "Dry run requested, invoked as:"
269 echo "${COMMAND} ${CMDARGS}"
270 echo "Program (board) to be updated: ${FLAGS_board}"
271 echo -n "Projects to be updated are: "
272 for PROJ in "${PROJECTS[@]}"; do
273 echo -n " ${PROJ}"
274 done
275 if [[ -n "${SKIPPED}" ]]; then
276 echo -n " (skipped:"
277 for S in "${SKIPPED[@]}"; do
278 echo -n " ${S}"
279 done
280 echo -n ")"
281 fi
282 echo
283 echo "Release number of upgrade: ${FLAGS_release}"
284 echo "BUG string used in commit: ${FLAGS_bug}"
285 echo "TEST string used in commit: ${FLAGS_test}"
286 echo "Reviewer assigned to CLs: ${FLAGS_reviewer:-None}"
287 echo -n "Coreboot build enabled: "
288 if [[ "${FLAGS_build}" -eq "${FLAGS_FALSE}" ]]; then
289 echo "no"
290 else
291 echo "yes"
292 fi
293 echo "repo branch to be used is: ${BRANCH}"
294 exit 0
295fi
296if [[ "${FLAGS_build}" -eq "${FLAGS_FALSE}" ]]; then
297 echo
298 echo "******************************************"
299 echo "* You have elected not to build coreboot *"
300 echo "* This assumes coreboot is already built *"
301 echo "******************************************"
302 echo
303fi
304#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000305# Create a temp directory.
306TEMPDIR=$(mktemp -d -t fw-XXXXXXXXXX)
Andrew McRae7c9655c2020-06-22 15:09:54 +1000307
308trap "exit 1" HUP INT PIPE QUIT TERM
309trap 'cleanup' EXIT
310
Andrew McRae0809eb52020-06-18 00:13:36 +1000311#
Andrew McRae0809eb52020-06-18 00:13:36 +1000312# From now on, all errors should invoke 'abort'
Andrew McRae7c9655c2020-06-22 15:09:54 +1000313# so that the branches and CLs are cleaned up on exit.
Andrew McRae0809eb52020-06-18 00:13:36 +1000314#
Andrew McRae88eda242020-06-26 12:35:55 +1000315# If required, update the firmware version in the program's program.star file
Andrew McRae0809eb52020-06-18 00:13:36 +1000316#
Andrew McRae88eda242020-06-26 12:35:55 +1000317if [[ "${FLAGS_program}" -eq "${FLAGS_TRUE}" ]]; then
318 cd "${PROGDIR}"
319 echo "Updating program.star for board ${FLAGS_board}"
320 branch
321 if (update_version "program.star") ;then
322 #
323 # If config has changed, create a CL.
324 #
325 git add .
326 git commit -q -F - <<EOF
327${FLAGS_board}: Update program firmware to ${FLAGS_release}
Andrew McRae0809eb52020-06-18 00:13:36 +1000328
Andrew McRae88eda242020-06-26 12:35:55 +1000329Autogenerated by:
330${COMMAND} ${CMDARGS}
Andrew McRae3b94aaf2020-06-25 15:28:18 +1000331
332BUG=${FLAGS_bug}
Andrew McRae88eda242020-06-26 12:35:55 +1000333TEST=${FLAGS_test}
Andrew McRae0809eb52020-06-18 00:13:36 +1000334EOF
Andrew McRae88eda242020-06-26 12:35:55 +1000335 if ! repo upload -y "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.output" 2>&1 ;then
336 cat "${TEMPDIR}/upload.output"
337 abort "repo upload failed"
338 fi
339 PROGRAM_CL=$(getcl "program/${FLAGS_board}" "${TEMPDIR}/upload.output")
Andrew McRaef96cd602020-06-23 23:06:19 +1000340 fi
Andrew McRae0809eb52020-06-18 00:13:36 +1000341fi
342#
Andrew McRae88eda242020-06-26 12:35:55 +1000343# Now walk through the projects and update the version (if present)
344# and regenerate the configs.
Andrew McRae0809eb52020-06-18 00:13:36 +1000345# Create and upload a CL and capture the CL number and project directory
346# if the project has changed.
347#
348PROJ_CLS=()
349PROJ_DIRS=()
Andrew McRae7c9655c2020-06-22 15:09:54 +1000350for PROJ in "${PROJECTS[@]}"; do
351 echo "Updating configs for project ${PROJ}"
352 PDIR="${GCLIENT_ROOT}/src/project/${FLAGS_board}/${PROJ}"
Andrew McRaef96cd602020-06-23 23:06:19 +1000353 cd "${PDIR}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000354 branch
Andrew McRae88eda242020-06-26 12:35:55 +1000355 update_version "config.star" || true
Andrew McRae0809eb52020-06-18 00:13:36 +1000356 ./config.star || abort "Generate config failed for ${PROJ}"
357 check_config > "${TEMPDIR}/check_config-${PROJ}.output" || abort "check_config failed for ${PROJ}"
358 #
359 # Check if any files changed.
360 #
361 if changed; then
Andrew McRaef96cd602020-06-23 23:06:19 +1000362 echo "Creating CL for changes to project ${PROJ}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000363 git add .
Andrew McRaef96cd602020-06-23 23:06:19 +1000364 git commit -q -F - <<EOF
Andrew McRae7c9655c2020-06-22 15:09:54 +1000365${PROJ}: Update firmware to ${FLAGS_release}
Andrew McRaef96cd602020-06-23 23:06:19 +1000366
Andrew McRae88eda242020-06-26 12:35:55 +1000367Autogenerated by:
368${COMMAND} ${CMDARGS}
Andrew McRae3b94aaf2020-06-25 15:28:18 +1000369
370BUG=${FLAGS_bug}
Andrew McRae88eda242020-06-26 12:35:55 +1000371TEST=${FLAGS_test}
Andrew McRae0809eb52020-06-18 00:13:36 +1000372EOF
Andrew McRaef96cd602020-06-23 23:06:19 +1000373 if ! repo upload -y "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.${PROJ}.output" 2>&1 ;then
374 cat "${TEMPDIR}/upload.${PROJ}.output"
375 abort "repo upload failed"
376 fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000377 P_CL=$(getcl "project/${FLAGS_board}/${PROJ}" "${TEMPDIR}/upload.${PROJ}.output")
Andrew McRae0809eb52020-06-18 00:13:36 +1000378 PROJ_CLS+=("${P_CL}")
379 PROJ_DIRS+=("${PDIR}")
380 fi
381done
382#
383# Create a Cq-Depend line with all the project CLs
384#
385if [[ -n "${PROJ_CLS[*]}" ]];then
386 SEP=" "
387 PROG_CQD="Cq-Depend:"
388 for CL in "${PROJ_CLS[@]}"; do
389 PROG_CQD="${PROG_CQD}${SEP}chrome-internal:${CL}"
390 SEP=", "
391 done
392 #
Andrew McRaef96cd602020-06-23 23:06:19 +1000393 # If a program CL exists, add the Cq-Depend line to it.
Andrew McRae0809eb52020-06-18 00:13:36 +1000394 #
Andrew McRaef96cd602020-06-23 23:06:19 +1000395 if [[ -n "${PROGRAM_CL}" ]]; then
396 cd "${PROGDIR}"
397 amend "${PROG_CQD}"
398 if ! repo upload -y "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.amend.output" 2>&1 ;then
399 cat "${TEMPDIR}/upload.amend.output"
400 abort "repo upload failed"
401 fi
402 fi
Andrew McRae0809eb52020-06-18 00:13:36 +1000403fi
404#
405# All the boxster configs have been uploaded.
406# Now run the update script and update the firmware manifest.
407#
408# Build base coreboot files
Andrew McRae0809eb52020-06-18 00:13:36 +1000409#
Andrew McRae88eda242020-06-26 12:35:55 +1000410if [[ "${FLAGS_build}" -eq "${FLAGS_TRUE}" ]]; then
411 echo "Running coreboot build. This may take a while..."
412 #
413 # Attempt to customise the coreboot build depending on the platform.
414 #
415 case "${FLAGS_board}" in
416 "zork")
417 PACKAGES=(coreboot-zork chromeos-bootimage)
418 ;;
419 "puff")
420 PACKAGES=(chromeos-ec coreboot depthcharge vboot_reference libpayload chromeos-bootimage coreboot-private-files intel-cmlfsp coreboot-private-files-puff)
421 ;;
422 *)
423 # Use general packages
424 echo "Taking a guess at coreboot packages for ${FLAGS_board}"
425 echo "If the coreboot build fails, this script may have to be customized for this board"
426 PACKAGES=(coreboot depthcharge vboot_reference libpayload chromeos-bootimage)
427 ;;
428 esac
429 if ! ("emerge-${FLAGS_board}" --quiet-build "${PACKAGES[@]}"); then
430 abort "coreboot build failed!"
431 fi
432 echo "coreboot build successful"
433else
434 echo "Coreboot build not attempted"
Andrew McRae0809eb52020-06-18 00:13:36 +1000435fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000436EB9999="chromeos-firmware-${FLAGS_board}-9999.ebuild"
Andrew McRae0809eb52020-06-18 00:13:36 +1000437#
438# Remove any previous attempts to build the firmware.
439#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000440"cros_workon-${FLAGS_board}" stop "chromeos-base/chromeos-firmware-${FLAGS_board}"
441"cros_workon-${FLAGS_board}" stop "chromeos-base/chromeos-config-bsp-${FLAGS_board}-private"
Andrew McRaef96cd602020-06-23 23:06:19 +1000442cd "${OVERLAY}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000443branch
Andrew McRaef96cd602020-06-23 23:06:19 +1000444cd "${DEVCONTRIB}"
Andrew McRae7c9655c2020-06-22 15:09:54 +1000445if ! (./cros_update_firmware -q "--board=${FLAGS_board}"); then
446 abort "cros_update_firmware failed for ${FLAGS_board}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000447fi
Andrew McRaef96cd602020-06-23 23:06:19 +1000448cd "${OVERLAY}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000449#
450# If files have been updated, then create a CL for the changes.
451#
452OVERLAY_CL=""
453if changed; then
454 #
455 # Bump the version in the ebuild file. Relies on the format
456 # of the version so that the last number is at the end of the line.
457 #
458 CURVERS=$(grep "VERSION=REVBUMP" "${EB9999}" | grep -o "[0-9][0-9]*$")
459 NEXTVERS=$((CURVERS + 1))
Andrew McRaef96cd602020-06-23 23:06:19 +1000460 sed -i "/VERSION=REVBUMP/s/${CURVERS}$/${NEXTVERS}/" "${EB9999}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000461 git add .
Andrew McRaef96cd602020-06-23 23:06:19 +1000462 git commit -q -F - <<EOF
Andrew McRae7c9655c2020-06-22 15:09:54 +1000463${FLAGS_board}: Update firmware to ${FLAGS_release}
Andrew McRae0809eb52020-06-18 00:13:36 +1000464
Andrew McRae88eda242020-06-26 12:35:55 +1000465Autogenerated by:
466${COMMAND} ${CMDARGS}
Andrew McRae3b94aaf2020-06-25 15:28:18 +1000467
468BUG=${FLAGS_bug}
Andrew McRae88eda242020-06-26 12:35:55 +1000469TEST=${FLAGS_test}
Andrew McRae0809eb52020-06-18 00:13:36 +1000470
Andrew McRaef96cd602020-06-23 23:06:19 +1000471${PROG_CQD}
Andrew McRae0809eb52020-06-18 00:13:36 +1000472EOF
473 #
474 # Upload with no-verify since the file lines are too long.
475 #
Andrew McRaef96cd602020-06-23 23:06:19 +1000476 if ! repo upload "--ht=${BRANCH}" -y --no-verify --cbr . > "${TEMPDIR}/overlay.output" 2>&1 ;then
477 cat "${TEMPDIR}/overlay.output"
478 abort "repo upload failed"
479 fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000480 OVERLAY_CL=$(getcl "overlays/overlay-${FLAGS_board}-private" "${TEMPDIR}/overlay.output")
Andrew McRae0809eb52020-06-18 00:13:36 +1000481 #
482 # Go back and amend all the project commit messages with a Cq-Depend on
483 # the program and overlay CLs.
484 #
485 CQD="Cq-Depend: chrome-internal:${OVERLAY_CL}"
486 if [[ -n "${PROGRAM_CL}" ]]; then
487 CQD="${CQD}, chrome-internal:${PROGRAM_CL}"
488 fi
489 for DIR in "${PROJ_DIRS[@]}"; do
Andrew McRaef96cd602020-06-23 23:06:19 +1000490 cd "${DIR}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000491 amend "${CQD}"
Andrew McRaef96cd602020-06-23 23:06:19 +1000492 if ! repo upload -y --cbr . > "${TEMPDIR}/cqd.output" 2>&1 ;then
493 cat "${TEMPDIR}/cqd.output"
494 abort "repo upload failed"
495 fi
Andrew McRae0809eb52020-06-18 00:13:36 +1000496 done
497fi
498#
499# Send all of the CLs to the CQ for a dry run.
500#
501ALL_CLS=$(gerrit -i --raw search "owner:me status:open hashtag:${BRANCH}")
502if [[ -z "${ALL_CLS}" ]]; then
Andrew McRae7c9655c2020-06-22 15:09:54 +1000503 echo "No changes required for program ${FLAGS_board}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000504 repo abandon "${BRANCH}"
505 exit 0
506fi
507for cl in ${ALL_CLS}; do
508 gerrit -i label-cq "${cl}" 1
509 gerrit -i label-v "${cl}" 1
510 gerrit -i label-as "${cl}" 1
511done
512#
513# If reviewer is set, then add them to the CLs
514#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000515if [[ -n "${FLAGS_reviewer}" ]]; then
516 echo "Sending CLs ${ALL_CLS} to ${FLAGS_reviewer} for review"
Andrew McRae0809eb52020-06-18 00:13:36 +1000517 for cl in ${ALL_CLS}; do
Andrew McRae7c9655c2020-06-22 15:09:54 +1000518 gerrit -i reviewers "${cl}" "${FLAGS_reviewer}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000519 done
520else
521 echo "Send CLs for review by running:"
522 echo " for cl in ${ALL_CLS}; do gerrit -i reviewers \$cl <reviewer>; done"
523fi
524#
525# Final instructions.
526#
527echo "Run:"
Andrew McRae7c9655c2020-06-22 15:09:54 +1000528echo " /build/${FLAGS_board}/usr/sbin/chromeos-firmwareupdate --manifest"
Andrew McRae0809eb52020-06-18 00:13:36 +1000529echo "to verify firmware update"
530echo "When submitted, cleanup by running:"
531echo "repo abandon ${BRANCH}"