blob: 207af55c2facc1c733bc5ab8438319c129797e07 [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 McRaeb46a3362020-07-16 12:12:18 +100012# ./update_program_fw --board=program --release=NNNNN.nn [ --reviewer=reviewer ]
Andrew McRae7c9655c2020-06-22 15:09:54 +100013# [ --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 McRae7c9655c2020-06-22 15:09:54 +100017CONTRIB_DIR=$(dirname "$(readlink -f "$0")")
18. "${CONTRIB_DIR}/common.sh" || exit 1
19
20FLAGS_HELP="
21Command to update the firmware version for a board.
22
Andrew McRae88eda242020-06-26 12:35:55 +100023Updates the firmware version configuration for a board's
Andrew McRae7c9655c2020-06-22 15:09:54 +100024master configuration (program.star) and for selected projects
25that include the master configuration.
26
27If no projects are specified, all projects for that board are selected.
Andrew McRaef96cd602020-06-23 23:06:19 +100028An optional skip list can be specified to skip selected boards.
Andrew McRae7c9655c2020-06-22 15:09:54 +100029
30The configurations for the selected projects are regenerated,
31and the firmware manifest are updated for the projects.
32
33The necessary CLs for these changes are created and uploaded for review.
34An optional reviewer can be specified to send all the CLs to.
35"
36# Flags
Andrew McRae88eda242020-06-26 12:35:55 +100037DEFINE_string board "${DEFAULT_BOARD}" "Which board (program) the firmware is for (e.g 'puff')" b
Andrew McRaeb46a3362020-07-16 12:12:18 +100038DEFINE_string release "${DEFAULT_RELEASE}" "The firmware release to update to (e.g 13310.3)" r
Andrew McRae88eda242020-06-26 12:35:55 +100039DEFINE_string project "${DEFAULT_PROJECT}" "Which projects this release is for (defaults to all), e.g 'duffy'" p
Andrew McRae3b94aaf2020-06-25 15:28:18 +100040DEFINE_string bug "none" "The bug to reference in the CL e.g b:12345"
Andrew McRae88eda242020-06-26 12:35:55 +100041DEFINE_string skip "${DEFAULT_SKIP}" "Skip these projects (comma separated list)" s
42DEFINE_boolean build "${FLAGS_TRUE}" "Attempt to build coreboot"
43DEFINE_boolean program "${FLAGS_TRUE}" "Update the version in the base program.star"
Andrew McRae7c9655c2020-06-22 15:09:54 +100044DEFINE_string reviewer "${DEFAULT_REVIEWER}" "The reviewer to send the CLs to (optional)"
Andrew McRae88eda242020-06-26 12:35:55 +100045DEFINE_string test "none" "The 'TEST=' string added to the commit message"
46DEFINE_boolean dryrun "${FLAGS_FALSE}" "Do not perform any actions, just validate and print arguments"
Andrew McRaea164ca62020-07-20 11:56:50 +100047DEFINE_boolean verify "${FLAGS_TRUE}" "Ask for verification before proceeding"
Andrew McRae88eda242020-06-26 12:35:55 +100048
49# Set before flag processing
50COMMAND=$(basename "$0")
51CMDARGS="$*"
Andrew McRae7c9655c2020-06-22 15:09:54 +100052
53# Parse command line
54FLAGS "$@" || exit 1
55eval set -- "${FLAGS_ARGV}"
56set -e
57
58# Script must be run inside the chroot.
59assert_inside_chroot
Andrew McRae0809eb52020-06-18 00:13:36 +100060#
61# Variables
62#
Andrew McRae7c9655c2020-06-22 15:09:54 +100063PATH="${PATH}:${GCLIENT_ROOT}/src/config/bin"
Andrew McRaeb46a3362020-07-16 12:12:18 +100064MAJOR_RE="[1-9][0-9]{4}"
65MINOR_RE="(0|[1-9][0-9]*)"
Andrew McRae0809eb52020-06-18 00:13:36 +100066BRANCH=""
Andrew McRae0809eb52020-06-18 00:13:36 +100067PROGRAM_CL=""
Andrew McRaeb46a3362020-07-16 12:12:18 +100068MAJOR_PREFIX="major_version = "
69MINOR_PREFIX="minor_version = "
70ANY_MAJOR="${MAJOR_PREFIX}${MAJOR_RE}"
71ANY_MINOR="${MINOR_PREFIX}${MINOR_RE}"
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#
Andrew McRaea164ca62020-07-20 11:56:50 +1000118# return 'yes' or 'no' for boolean true or false
119yes_no() {
120 if [[ "${1}" -eq "${FLAGS_FALSE}" ]]; then
121 echo -n "no"
122 else
123 echo -n "yes"
124 fi
125}
126#
Andrew McRae0809eb52020-06-18 00:13:36 +1000127# Return true if repo has changes.
Andrew McRae88eda242020-06-26 12:35:55 +1000128#
Andrew McRae0809eb52020-06-18 00:13:36 +1000129changed() {
130 [[ -n $(git status -s) ]]
131}
132#
133# Add a Cq-Depend line to a commit.
Andrew McRae0809eb52020-06-18 00:13:36 +1000134#
135amend() {
Andrew McRaef96cd602020-06-23 23:06:19 +1000136 git log -1 --pretty=%B > "${TEMPDIR}/amend-msg"
137 sed -i "/^Change-Id/ i ${1}" "${TEMPDIR}/amend-msg"
138 git commit -q --amend -F "${TEMPDIR}/amend-msg"
139}
140#
Andrew McRae88eda242020-06-26 12:35:55 +1000141# Confirm that $1 is a valid project
142#
143check_project() {
144 PDIR="${GCLIENT_ROOT}/src/project/${FLAGS_board}/${1}"
145 if [[ ! -d "${PDIR}" ]]; then
146 die "${P} is not a valid project (${PDIR} missing)"
147 fi
148}
149#
Andrew McRaef96cd602020-06-23 23:06:19 +1000150# Return true if $1 is in list $2
151#
152in_list() {
153 for S in ${2}; do
154 if [[ "$1" == "${S}" ]]; then
155 return 0
156 fi
157 done
158 return 1
Andrew McRae0809eb52020-06-18 00:13:36 +1000159}
160#
Andrew McRaeb46a3362020-07-16 12:12:18 +1000161# Return 0 if file has major or minor version in it.
Andrew McRae88eda242020-06-26 12:35:55 +1000162#
163has_version() {
Andrew McRaeb46a3362020-07-16 12:12:18 +1000164 (grep -E -q "(${ANY_MAJOR}|${ANY_MINOR})" "${1}")
Andrew McRae88eda242020-06-26 12:35:55 +1000165}
166#
Andrew McRaeb46a3362020-07-16 12:12:18 +1000167# Update the version in the file passed.
Andrew McRae88eda242020-06-26 12:35:55 +1000168# return 0 if version updated.
169# return 1 if version not in file, or unchanged.
170#
171update_version() {
Andrew McRaeb46a3362020-07-16 12:12:18 +1000172 # Check for major or minor version in file.
Andrew McRae88eda242020-06-26 12:35:55 +1000173 if ! (has_version "${1}") ;then
174 return 1
175 fi
176 local nf="${TEMPDIR}/new-${1}"
Andrew McRaeb46a3362020-07-16 12:12:18 +1000177 sed -E "s/${ANY_MAJOR}/${NEW_MAJOR}/" "${1}" > "${nf}"
178 sed -i -E "s/${ANY_MINOR}/${NEW_MINOR}/" "${nf}"
179 if cmp -s "${1}" "${nf}"; then
Andrew McRae88eda242020-06-26 12:35:55 +1000180 return 1
181 fi
182 cp "${nf}" "${1}"
183 return 0
184}
185#
Andrew McRae0809eb52020-06-18 00:13:36 +1000186# Validate arguments
187#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000188if [[ -z "${FLAGS_board}" ]]; then
189 die "-b or --board required."
190fi
191if [[ -z "${FLAGS_release}" ]]; then
192 die "-r or --release required."
Andrew McRae0809eb52020-06-18 00:13:36 +1000193fi
194#
195# Program must exist as a directory
196#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000197PROGDIR="${GCLIENT_ROOT}/src/program/${FLAGS_board}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000198if [[ ! -d "${PROGDIR}" ]]; then
Andrew McRae7c9655c2020-06-22 15:09:54 +1000199 die "${FLAGS_board} is not a valid program (${PROGDIR} missing)"
Andrew McRae0809eb52020-06-18 00:13:36 +1000200fi
Andrew McRaeb46a3362020-07-16 12:12:18 +1000201#
202# Validate release
203# Major must be a 5 digit number
204# Optional minor release must be a number.
205#
206if [[ "${FLAGS_release}" =~ ^${MAJOR_RE}$ ]]; then
207 MAJOR_VERSION=${FLAGS_release}
208 MINOR_VERSION="0"
209elif [[ "${FLAGS_release}" =~ ^${MAJOR_RE}\.${MINOR_RE}$ ]]; then
210 MAJOR_VERSION=$(echo "${FLAGS_release}" | cut -d. -f1)
211 MINOR_VERSION=$(echo "${FLAGS_release}" | cut -d. -f2)
212else
213 die "Unknown release format (must be NNNNN[.n])"
Andrew McRae0809eb52020-06-18 00:13:36 +1000214fi
Andrew McRaeb46a3362020-07-16 12:12:18 +1000215NEW_MAJOR="${MAJOR_PREFIX}${MAJOR_VERSION}"
216NEW_MINOR="${MINOR_PREFIX}${MINOR_VERSION}"
Andrew McRaef96cd602020-06-23 23:06:19 +1000217# Use a common git branch name.
Andrew McRaeb46a3362020-07-16 12:12:18 +1000218BRANCH="update_${FLAGS_board}_fw_${MAJOR_VERSION}_${MINOR_VERSION}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000219#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000220# Build the project list.
Andrew McRaef96cd602020-06-23 23:06:19 +1000221# If no projects are specified, use all in the programs directory.
Andrew McRae0809eb52020-06-18 00:13:36 +1000222#
Andrew McRaef96cd602020-06-23 23:06:19 +1000223if [[ -z "${FLAGS_project}" ]]; then
Andrew McRae7c9655c2020-06-22 15:09:54 +1000224 BDIR="${GCLIENT_ROOT}/src/project/${FLAGS_board}"
Andrew McRaef96cd602020-06-23 23:06:19 +1000225 cd "${BDIR}"
226 mapfile -t PROJLIST < <(ls)
227else
228 IFS=',' read -r -a PROJLIST <<< "${FLAGS_project}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000229fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000230#
Andrew McRaef96cd602020-06-23 23:06:19 +1000231# Filter out the projects that are to be skipped.
232#
233if [[ -n "${FLAGS_skip}" ]]; then
234 PROJECTS=()
235 IFS=',' read -r -a SKIP_ARRAY <<< "${FLAGS_skip}"
Andrew McRae88eda242020-06-26 12:35:55 +1000236 # Validate skipped projects
237 for S in "${SKIP_ARRAY[@]}"; do
238 check_project "${S}"
239 done
Andrew McRaef96cd602020-06-23 23:06:19 +1000240 SKIPPED="${SKIP_ARRAY[*]}"
241 for P in "${PROJLIST[@]}"; do
242 if ! (in_list "${P}" "${SKIPPED}"); then
243 PROJECTS+=("${P}")
244 fi
245 done
246else
247 PROJECTS=("${PROJLIST[@]}")
248fi
249#
Andrew McRae88eda242020-06-26 12:35:55 +1000250# Valid bug number (if any).
251# Must be of the form b:nnnnn or chromium:nnnnn
252#
253if [[ "${FLAGS_bug}" != "none" ]]; then
254 BG="b:[0-9]+|chromium:[0-9]+"
255 BGRE="^(${BG})(,(${BG}))*$"
256 if [[ ! "${FLAGS_bug}" =~ ${BGRE} ]]; then
257 echo "Bug must be of the form b:nnn or chromium:nnn"
258 die "A comma separated list is allowed"
259 fi
260fi
261#
Andrew McRaef96cd602020-06-23 23:06:19 +1000262# Validate project list and file locations.
Andrew McRae7c9655c2020-06-22 15:09:54 +1000263#
264for P in "${PROJECTS[@]}"; do
Andrew McRae88eda242020-06-26 12:35:55 +1000265 check_project "${P}"
Andrew McRae7c9655c2020-06-22 15:09:54 +1000266done
Andrew McRaef96cd602020-06-23 23:06:19 +1000267OVERLAY="${GCLIENT_ROOT}/src/private-overlays/overlay-${FLAGS_board}-private/chromeos-base/chromeos-firmware-${FLAGS_board}"
Andrew McRae88eda242020-06-26 12:35:55 +1000268# Validate project overlay and ebuild file
Andrew McRaef96cd602020-06-23 23:06:19 +1000269EB9999="chromeos-firmware-${FLAGS_board}-9999.ebuild"
270if [[ ! -f "${OVERLAY}/${EB9999}" ]]; then
Andrew McRae88eda242020-06-26 12:35:55 +1000271 die "${OVERLAY}/${EB9999}: overlay error"
Andrew McRaef96cd602020-06-23 23:06:19 +1000272fi
273# Make sure dev/contrib is accessible
274DEVCONTRIB="${GCLIENT_ROOT}/src/platform/dev/contrib"
275if [[ ! -d "${DEVCONTRIB}" ]]; then
276 die "${DEVCONTRIB}: invalid directory"
277fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000278#
Andrew McRaea164ca62020-07-20 11:56:50 +1000279# Display arguments.
280#
281echo "Invoked as:"
282echo "${COMMAND} ${CMDARGS}"
283echo "Program (board) to be updated: ${FLAGS_board}"
284echo -n "Projects to be updated are: "
285for PROJ in "${PROJECTS[@]}"; do
286 echo -n " ${PROJ}"
287done
288if [[ -n "${SKIPPED}" ]]; then
289 echo -n " (skipped:"
290 for S in "${SKIPPED[@]}"; do
291 echo -n " ${S}"
292 done
293 echo -n ")"
294fi
295echo
296echo "Release number of upgrade: ${FLAGS_release}"
297echo "Major version of release: ${MAJOR_VERSION}"
298echo "Minor version of release: ${MINOR_VERSION}"
299echo "BUG string used in commit: ${FLAGS_bug}"
300echo "TEST string used in commit: ${FLAGS_test}"
301echo "Reviewer assigned to CLs: ${FLAGS_reviewer:-None}"
302echo "repo branch to be used is: ${BRANCH}"
303echo "Update program.star version: $(yes_no ${FLAGS_program})"
304echo "Coreboot build enabled: $(yes_no ${FLAGS_build})"
305echo "Dry run requested: $(yes_no ${FLAGS_dryrun})"
306echo "Verify before proceeding: $(yes_no ${FLAGS_verify})"
Andrew McRae88eda242020-06-26 12:35:55 +1000307#
308if [[ "${FLAGS_dryrun}" -eq "${FLAGS_TRUE}" ]]; then
Andrew McRaea164ca62020-07-20 11:56:50 +1000309 echo "Dry run requested, exiting"
Andrew McRae88eda242020-06-26 12:35:55 +1000310 exit 0
311fi
Andrew McRaea164ca62020-07-20 11:56:50 +1000312read -p "Proceed with updating firmware (y/N)? " -r
313if [[ ! "${REPLY}" =~ ^[Yy]$ ]]; then
314 die "Not verified, exiting..."
315fi
Andrew McRae88eda242020-06-26 12:35:55 +1000316if [[ "${FLAGS_build}" -eq "${FLAGS_FALSE}" ]]; then
317 echo
318 echo "******************************************"
319 echo "* You have elected not to build coreboot *"
320 echo "* This assumes coreboot is already built *"
321 echo "******************************************"
322 echo
323fi
324#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000325# Create a temp directory.
326TEMPDIR=$(mktemp -d -t fw-XXXXXXXXXX)
Andrew McRae7c9655c2020-06-22 15:09:54 +1000327
328trap "exit 1" HUP INT PIPE QUIT TERM
329trap 'cleanup' EXIT
330
Andrew McRae0809eb52020-06-18 00:13:36 +1000331#
Andrew McRae0809eb52020-06-18 00:13:36 +1000332# From now on, all errors should invoke 'abort'
Andrew McRae7c9655c2020-06-22 15:09:54 +1000333# so that the branches and CLs are cleaned up on exit.
Andrew McRae0809eb52020-06-18 00:13:36 +1000334#
Andrew McRae88eda242020-06-26 12:35:55 +1000335# If required, update the firmware version in the program's program.star file
Andrew McRae0809eb52020-06-18 00:13:36 +1000336#
Andrew McRae88eda242020-06-26 12:35:55 +1000337if [[ "${FLAGS_program}" -eq "${FLAGS_TRUE}" ]]; then
338 cd "${PROGDIR}"
339 echo "Updating program.star for board ${FLAGS_board}"
340 branch
341 if (update_version "program.star") ;then
342 #
343 # If config has changed, create a CL.
344 #
345 git add .
346 git commit -q -F - <<EOF
347${FLAGS_board}: Update program firmware to ${FLAGS_release}
Andrew McRae0809eb52020-06-18 00:13:36 +1000348
Andrew McRae88eda242020-06-26 12:35:55 +1000349Autogenerated by:
350${COMMAND} ${CMDARGS}
Andrew McRae3b94aaf2020-06-25 15:28:18 +1000351
352BUG=${FLAGS_bug}
Andrew McRae88eda242020-06-26 12:35:55 +1000353TEST=${FLAGS_test}
Andrew McRae0809eb52020-06-18 00:13:36 +1000354EOF
Rob Barnesaafdcbd2020-07-21 07:42:37 -0600355 if ! repo upload -y --verify "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.output" 2>&1 ;then
Andrew McRae88eda242020-06-26 12:35:55 +1000356 cat "${TEMPDIR}/upload.output"
357 abort "repo upload failed"
358 fi
359 PROGRAM_CL=$(getcl "program/${FLAGS_board}" "${TEMPDIR}/upload.output")
Andrew McRaef96cd602020-06-23 23:06:19 +1000360 fi
Andrew McRae0809eb52020-06-18 00:13:36 +1000361fi
362#
Andrew McRae88eda242020-06-26 12:35:55 +1000363# Now walk through the projects and update the version (if present)
364# and regenerate the configs.
Andrew McRae0809eb52020-06-18 00:13:36 +1000365# Create and upload a CL and capture the CL number and project directory
366# if the project has changed.
367#
368PROJ_CLS=()
369PROJ_DIRS=()
Andrew McRae7c9655c2020-06-22 15:09:54 +1000370for PROJ in "${PROJECTS[@]}"; do
371 echo "Updating configs for project ${PROJ}"
372 PDIR="${GCLIENT_ROOT}/src/project/${FLAGS_board}/${PROJ}"
Andrew McRaef96cd602020-06-23 23:06:19 +1000373 cd "${PDIR}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000374 branch
Andrew McRae88eda242020-06-26 12:35:55 +1000375 update_version "config.star" || true
Andrew McRae0809eb52020-06-18 00:13:36 +1000376 ./config.star || abort "Generate config failed for ${PROJ}"
377 check_config > "${TEMPDIR}/check_config-${PROJ}.output" || abort "check_config failed for ${PROJ}"
378 #
379 # Check if any files changed.
380 #
381 if changed; then
Andrew McRaef96cd602020-06-23 23:06:19 +1000382 echo "Creating CL for changes to project ${PROJ}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000383 git add .
Andrew McRaef96cd602020-06-23 23:06:19 +1000384 git commit -q -F - <<EOF
Andrew McRae7c9655c2020-06-22 15:09:54 +1000385${PROJ}: Update firmware to ${FLAGS_release}
Andrew McRaef96cd602020-06-23 23:06:19 +1000386
Andrew McRae88eda242020-06-26 12:35:55 +1000387Autogenerated by:
388${COMMAND} ${CMDARGS}
Andrew McRae3b94aaf2020-06-25 15:28:18 +1000389
390BUG=${FLAGS_bug}
Andrew McRae88eda242020-06-26 12:35:55 +1000391TEST=${FLAGS_test}
Andrew McRae0809eb52020-06-18 00:13:36 +1000392EOF
Rob Barnesaafdcbd2020-07-21 07:42:37 -0600393 if ! repo upload -y --verify "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.${PROJ}.output" 2>&1 ;then
Andrew McRaef96cd602020-06-23 23:06:19 +1000394 cat "${TEMPDIR}/upload.${PROJ}.output"
395 abort "repo upload failed"
396 fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000397 P_CL=$(getcl "project/${FLAGS_board}/${PROJ}" "${TEMPDIR}/upload.${PROJ}.output")
Andrew McRae0809eb52020-06-18 00:13:36 +1000398 PROJ_CLS+=("${P_CL}")
399 PROJ_DIRS+=("${PDIR}")
400 fi
401done
402#
403# Create a Cq-Depend line with all the project CLs
404#
405if [[ -n "${PROJ_CLS[*]}" ]];then
406 SEP=" "
407 PROG_CQD="Cq-Depend:"
408 for CL in "${PROJ_CLS[@]}"; do
409 PROG_CQD="${PROG_CQD}${SEP}chrome-internal:${CL}"
410 SEP=", "
411 done
412 #
Andrew McRaef96cd602020-06-23 23:06:19 +1000413 # If a program CL exists, add the Cq-Depend line to it.
Andrew McRae0809eb52020-06-18 00:13:36 +1000414 #
Andrew McRaef96cd602020-06-23 23:06:19 +1000415 if [[ -n "${PROGRAM_CL}" ]]; then
416 cd "${PROGDIR}"
417 amend "${PROG_CQD}"
Rob Barnesaafdcbd2020-07-21 07:42:37 -0600418 if ! repo upload -y --verify "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.amend.output" 2>&1 ;then
Andrew McRaef96cd602020-06-23 23:06:19 +1000419 cat "${TEMPDIR}/upload.amend.output"
420 abort "repo upload failed"
421 fi
422 fi
Andrew McRae0809eb52020-06-18 00:13:36 +1000423fi
424#
425# All the boxster configs have been uploaded.
426# Now run the update script and update the firmware manifest.
427#
428# Build base coreboot files
Andrew McRae0809eb52020-06-18 00:13:36 +1000429#
Andrew McRae88eda242020-06-26 12:35:55 +1000430if [[ "${FLAGS_build}" -eq "${FLAGS_TRUE}" ]]; then
431 echo "Running coreboot build. This may take a while..."
432 #
433 # Attempt to customise the coreboot build depending on the platform.
434 #
435 case "${FLAGS_board}" in
436 "zork")
437 PACKAGES=(coreboot-zork chromeos-bootimage)
438 ;;
439 "puff")
440 PACKAGES=(chromeos-ec coreboot depthcharge vboot_reference libpayload chromeos-bootimage coreboot-private-files intel-cmlfsp coreboot-private-files-puff)
441 ;;
442 *)
443 # Use general packages
444 echo "Taking a guess at coreboot packages for ${FLAGS_board}"
445 echo "If the coreboot build fails, this script may have to be customized for this board"
446 PACKAGES=(coreboot depthcharge vboot_reference libpayload chromeos-bootimage)
447 ;;
448 esac
Andrew McRae94639642020-07-14 17:14:04 +1000449 if ! ("emerge-${FLAGS_board}" -j --quiet-build "${PACKAGES[@]}"); then
Andrew McRae88eda242020-06-26 12:35:55 +1000450 abort "coreboot build failed!"
451 fi
452 echo "coreboot build successful"
453else
454 echo "Coreboot build not attempted"
Andrew McRae0809eb52020-06-18 00:13:36 +1000455fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000456EB9999="chromeos-firmware-${FLAGS_board}-9999.ebuild"
Andrew McRae0809eb52020-06-18 00:13:36 +1000457#
458# Remove any previous attempts to build the firmware.
459#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000460"cros_workon-${FLAGS_board}" stop "chromeos-base/chromeos-firmware-${FLAGS_board}"
461"cros_workon-${FLAGS_board}" stop "chromeos-base/chromeos-config-bsp-${FLAGS_board}-private"
Andrew McRaef96cd602020-06-23 23:06:19 +1000462cd "${OVERLAY}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000463branch
Andrew McRaef96cd602020-06-23 23:06:19 +1000464cd "${DEVCONTRIB}"
Andrew McRae7c9655c2020-06-22 15:09:54 +1000465if ! (./cros_update_firmware -q "--board=${FLAGS_board}"); then
466 abort "cros_update_firmware failed for ${FLAGS_board}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000467fi
Andrew McRaef96cd602020-06-23 23:06:19 +1000468cd "${OVERLAY}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000469#
470# If files have been updated, then create a CL for the changes.
471#
472OVERLAY_CL=""
473if changed; then
474 #
475 # Bump the version in the ebuild file. Relies on the format
476 # of the version so that the last number is at the end of the line.
477 #
478 CURVERS=$(grep "VERSION=REVBUMP" "${EB9999}" | grep -o "[0-9][0-9]*$")
479 NEXTVERS=$((CURVERS + 1))
Andrew McRaef96cd602020-06-23 23:06:19 +1000480 sed -i "/VERSION=REVBUMP/s/${CURVERS}$/${NEXTVERS}/" "${EB9999}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000481 git add .
Andrew McRaef96cd602020-06-23 23:06:19 +1000482 git commit -q -F - <<EOF
Andrew McRae7c9655c2020-06-22 15:09:54 +1000483${FLAGS_board}: Update firmware to ${FLAGS_release}
Andrew McRae0809eb52020-06-18 00:13:36 +1000484
Andrew McRae88eda242020-06-26 12:35:55 +1000485Autogenerated by:
486${COMMAND} ${CMDARGS}
Andrew McRae3b94aaf2020-06-25 15:28:18 +1000487
488BUG=${FLAGS_bug}
Andrew McRae88eda242020-06-26 12:35:55 +1000489TEST=${FLAGS_test}
Andrew McRae0809eb52020-06-18 00:13:36 +1000490
Andrew McRaef96cd602020-06-23 23:06:19 +1000491${PROG_CQD}
Andrew McRae0809eb52020-06-18 00:13:36 +1000492EOF
493 #
494 # Upload with no-verify since the file lines are too long.
495 #
Andrew McRaef96cd602020-06-23 23:06:19 +1000496 if ! repo upload "--ht=${BRANCH}" -y --no-verify --cbr . > "${TEMPDIR}/overlay.output" 2>&1 ;then
497 cat "${TEMPDIR}/overlay.output"
498 abort "repo upload failed"
499 fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000500 OVERLAY_CL=$(getcl "overlays/overlay-${FLAGS_board}-private" "${TEMPDIR}/overlay.output")
Andrew McRae0809eb52020-06-18 00:13:36 +1000501 #
502 # Go back and amend all the project commit messages with a Cq-Depend on
503 # the program and overlay CLs.
504 #
505 CQD="Cq-Depend: chrome-internal:${OVERLAY_CL}"
506 if [[ -n "${PROGRAM_CL}" ]]; then
507 CQD="${CQD}, chrome-internal:${PROGRAM_CL}"
508 fi
509 for DIR in "${PROJ_DIRS[@]}"; do
Andrew McRaef96cd602020-06-23 23:06:19 +1000510 cd "${DIR}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000511 amend "${CQD}"
Rob Barnesaafdcbd2020-07-21 07:42:37 -0600512 if ! repo upload -y --verify --cbr . > "${TEMPDIR}/cqd.output" 2>&1 ;then
Andrew McRaef96cd602020-06-23 23:06:19 +1000513 cat "${TEMPDIR}/cqd.output"
514 abort "repo upload failed"
515 fi
Andrew McRae0809eb52020-06-18 00:13:36 +1000516 done
517fi
518#
519# Send all of the CLs to the CQ for a dry run.
520#
521ALL_CLS=$(gerrit -i --raw search "owner:me status:open hashtag:${BRANCH}")
522if [[ -z "${ALL_CLS}" ]]; then
Andrew McRae7c9655c2020-06-22 15:09:54 +1000523 echo "No changes required for program ${FLAGS_board}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000524 repo abandon "${BRANCH}"
525 exit 0
526fi
527for cl in ${ALL_CLS}; do
528 gerrit -i label-cq "${cl}" 1
529 gerrit -i label-v "${cl}" 1
530 gerrit -i label-as "${cl}" 1
531done
532#
533# If reviewer is set, then add them to the CLs
534#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000535if [[ -n "${FLAGS_reviewer}" ]]; then
536 echo "Sending CLs ${ALL_CLS} to ${FLAGS_reviewer} for review"
Andrew McRae0809eb52020-06-18 00:13:36 +1000537 for cl in ${ALL_CLS}; do
Andrew McRae7c9655c2020-06-22 15:09:54 +1000538 gerrit -i reviewers "${cl}" "${FLAGS_reviewer}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000539 done
540else
541 echo "Send CLs for review by running:"
542 echo " for cl in ${ALL_CLS}; do gerrit -i reviewers \$cl <reviewer>; done"
543fi
544#
545# Final instructions.
546#
547echo "Run:"
Andrew McRae7c9655c2020-06-22 15:09:54 +1000548echo " /build/${FLAGS_board}/usr/sbin/chromeos-firmwareupdate --manifest"
Andrew McRae0809eb52020-06-18 00:13:36 +1000549echo "to verify firmware update"
550echo "When submitted, cleanup by running:"
551echo "repo abandon ${BRANCH}"