blob: ff9edfdce94ee2686af368ee89953aa546d1e59b [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 McRaed0aee432020-07-22 15:40:55 +100012# ./update_program_fw --board=program --release=NNNNN.nn [ --reviewer=reviewers ]
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 McRaed0aee432020-07-22 15:40:55 +100044DEFINE_string reviewer "${DEFAULT_REVIEWER}" "The reviewer(s) 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 McRaed26b2792020-08-06 23:28:26 +100091 cros workon "--board=${FLAGS_board}" stop "chromeos-base/chromeos-firmware-${FLAGS_board}"
92 cros workon "--board=${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 McRae802326f2020-07-23 13:48:16 +100097# Return 0 if file has major or minor version in it.
98#
99has_version() {
100 (grep -E -q "(${ANY_MAJOR}|${ANY_MINOR})" "${1}")
101}
102#
103# Return 0 if file has major version in it.
104#
105has_major_version() {
106 (grep -E -q "${ANY_MAJOR}" "${1}")
107}
108#
109# Return 0 if file has minor version in it.
110#
111has_minor_version() {
112 (grep -E -q "${ANY_MINOR}" "${1}")
113}
114#
Andrew McRae88eda242020-06-26 12:35:55 +1000115# Extract a CL number from the file containing the output of repo upload
Andrew McRae0809eb52020-06-18 00:13:36 +1000116#
117getcl() {
118 CL=$(grep -o "https://chrome-internal-review.googlesource.com/c/chromeos/$1/+/[0-9][0-9]*" "$2")
119 if [[ -z "${CL}" ]]; then
120 cat "$2"
121 abort CL number not found in repo upload output
122 fi
123 echo "${CL}" | grep -o "[0-9][0-9]*"
124}
125#
126# If not on this branch, start a branch
127#
128branch() {
129 if ! (git branch --show-current | grep -q "${BRANCH}"); then
130 repo start "${BRANCH}"
131 else
132 echo "${BRANCH} already exists, skipping repo start"
133 fi
134}
135#
Andrew McRaea164ca62020-07-20 11:56:50 +1000136# return 'yes' or 'no' for boolean true or false
Andrew McRaed0aee432020-07-22 15:40:55 +1000137#
Andrew McRaea164ca62020-07-20 11:56:50 +1000138yes_no() {
139 if [[ "${1}" -eq "${FLAGS_FALSE}" ]]; then
140 echo -n "no"
141 else
142 echo -n "yes"
143 fi
144}
145#
Andrew McRaed0aee432020-07-22 15:40:55 +1000146# Normalise a comma or space separated argument or arguments to
147# a single set of space separated arguments.
148#
149rd_list() {
150 local l=()
151 for arg in "$@"; do
152 IFS=', ' read -r -a la <<< "${arg}"
153 l+=("${la[@]}")
154 done
155 echo "${l[@]}"
156}
157#
Andrew McRae0809eb52020-06-18 00:13:36 +1000158# Return true if repo has changes.
Andrew McRae88eda242020-06-26 12:35:55 +1000159#
Andrew McRae0809eb52020-06-18 00:13:36 +1000160changed() {
161 [[ -n $(git status -s) ]]
162}
163#
164# Add a Cq-Depend line to a commit.
Andrew McRae0809eb52020-06-18 00:13:36 +1000165#
166amend() {
Andrew McRaef96cd602020-06-23 23:06:19 +1000167 git log -1 --pretty=%B > "${TEMPDIR}/amend-msg"
168 sed -i "/^Change-Id/ i ${1}" "${TEMPDIR}/amend-msg"
169 git commit -q --amend -F "${TEMPDIR}/amend-msg"
170}
171#
Andrew McRae88eda242020-06-26 12:35:55 +1000172# Confirm that $1 is a valid project
173#
174check_project() {
Andrew McRae802326f2020-07-23 13:48:16 +1000175 PFILE="${GCLIENT_ROOT}/src/project/${FLAGS_board}/${1}/config.star"
176 if [[ ! -f "${PFILE}" ]]; then
177 die "${P} is not a valid project (${PFILE} missing)"
178 fi
179 #
180 # If the board's program.star is not being updated, check that the
181 # project has the right config lines to update.
182 #
183 if [[ "${FLAGS_program}" -eq "${FLAGS_FALSE}" ]]; then
184 if ! (has_major_version "${PFILE}") ;then
185 version_error "${PFILE} requires major_version"
186 fi
187 if [[ "${MINOR_VERSION}" -ne "0" ]] && ! (has_minor_version "${PFILE}"); then
188 version_error "${PFILE} requires minor_version"
189 fi
Andrew McRae88eda242020-06-26 12:35:55 +1000190 fi
191}
192#
Andrew McRaef96cd602020-06-23 23:06:19 +1000193# Return true if $1 is in list $2
194#
195in_list() {
196 for S in ${2}; do
197 if [[ "$1" == "${S}" ]]; then
198 return 0
199 fi
200 done
201 return 1
Andrew McRae0809eb52020-06-18 00:13:36 +1000202}
203#
Andrew McRae802326f2020-07-23 13:48:16 +1000204# Dump a message about the version expectations and quit.
Andrew McRae88eda242020-06-26 12:35:55 +1000205#
Andrew McRae802326f2020-07-23 13:48:16 +1000206version_error() {
207echo "ERROR: ${1}"
208cat << EOF
209
210To correctly update the version, the config files must have existing version
211configuration lines in them that the script can find and replace.
212These lines are in the form of (e.g):
213
214...
215 major_version = 12345,
216 minor_version = 10
217...
218
219The regular expressions used to find and replace these configuration lines are
220"/${ANY_MAJOR}/" and "/${ANY_MINOR}/".
221The version configuration lines must match these regular expressions.
222
223These configuration lines may appear in the board's base program.star file, or in
224the projects' config.star file. If the minor version is not 0, a 'minor_version' line
225must exist in the files to be updated.
226
227If the board's program.star file is updated (the default --program option), then carefully
228check that the inherited project configs are correct, especially if projects are skipped.
229
230If the --noprogram option is selected, then a config line of 'major_version' (and
231'minor_version' if the minor version is not 0) must exist in the project config.star files.
232
233Since the project's config is inherited from the board's program.star file, and can override
234the version of the config, ensure that selectively updating either the program.star or
235the project versions will not leave projects in an inconsistent state.
236EOF
237exit 1
Andrew McRae88eda242020-06-26 12:35:55 +1000238}
239#
Andrew McRaeb46a3362020-07-16 12:12:18 +1000240# Update the version in the file passed.
Andrew McRae88eda242020-06-26 12:35:55 +1000241# return 0 if version updated.
242# return 1 if version not in file, or unchanged.
243#
244update_version() {
Andrew McRaeb46a3362020-07-16 12:12:18 +1000245 # Check for major or minor version in file.
Andrew McRae88eda242020-06-26 12:35:55 +1000246 if ! (has_version "${1}") ;then
247 return 1
248 fi
249 local nf="${TEMPDIR}/new-${1}"
Andrew McRaeb46a3362020-07-16 12:12:18 +1000250 sed -E "s/${ANY_MAJOR}/${NEW_MAJOR}/" "${1}" > "${nf}"
251 sed -i -E "s/${ANY_MINOR}/${NEW_MINOR}/" "${nf}"
252 if cmp -s "${1}" "${nf}"; then
Andrew McRae88eda242020-06-26 12:35:55 +1000253 return 1
254 fi
255 cp "${nf}" "${1}"
256 return 0
257}
258#
Andrew McRae0809eb52020-06-18 00:13:36 +1000259# Validate arguments
260#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000261if [[ -z "${FLAGS_board}" ]]; then
262 die "-b or --board required."
263fi
264if [[ -z "${FLAGS_release}" ]]; then
265 die "-r or --release required."
Andrew McRae0809eb52020-06-18 00:13:36 +1000266fi
267#
268# Program must exist as a directory
269#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000270PROGDIR="${GCLIENT_ROOT}/src/program/${FLAGS_board}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000271if [[ ! -d "${PROGDIR}" ]]; then
Andrew McRae7c9655c2020-06-22 15:09:54 +1000272 die "${FLAGS_board} is not a valid program (${PROGDIR} missing)"
Andrew McRae0809eb52020-06-18 00:13:36 +1000273fi
Andrew McRae802326f2020-07-23 13:48:16 +1000274PROGFILE="${PROGDIR}/program.star"
Andrew McRaeb46a3362020-07-16 12:12:18 +1000275#
276# Validate release
277# Major must be a 5 digit number
278# Optional minor release must be a number.
279#
280if [[ "${FLAGS_release}" =~ ^${MAJOR_RE}$ ]]; then
281 MAJOR_VERSION=${FLAGS_release}
282 MINOR_VERSION="0"
283elif [[ "${FLAGS_release}" =~ ^${MAJOR_RE}\.${MINOR_RE}$ ]]; then
284 MAJOR_VERSION=$(echo "${FLAGS_release}" | cut -d. -f1)
285 MINOR_VERSION=$(echo "${FLAGS_release}" | cut -d. -f2)
286else
287 die "Unknown release format (must be NNNNN[.n])"
Andrew McRae0809eb52020-06-18 00:13:36 +1000288fi
Andrew McRaeb46a3362020-07-16 12:12:18 +1000289NEW_MAJOR="${MAJOR_PREFIX}${MAJOR_VERSION}"
290NEW_MINOR="${MINOR_PREFIX}${MINOR_VERSION}"
Andrew McRae802326f2020-07-23 13:48:16 +1000291#
292# If updating the board config, check for program.star
293# and for version strings.
294#
295if [[ "${FLAGS_program}" -eq "${FLAGS_TRUE}" ]]; then
296 if [[ ! -f "${PROGFILE}" ]]; then
297 die "${FLAGS_board} is not a valid program (${PROGFILE} missing)"
298 fi
299 if ! (has_major_version "${PROGFILE}") ;then
300 version_error "${PROGFILE} requires major_version"
301 fi
302 if [[ "${MINOR_VERSION}" -ne "0" ]] && ! (has_minor_version "${PROGFILE}"); then
303 version_error "${PROGFILE} requires minor_version"
304 fi
305fi
Andrew McRaef96cd602020-06-23 23:06:19 +1000306# Use a common git branch name.
Andrew McRaeb46a3362020-07-16 12:12:18 +1000307BRANCH="update_${FLAGS_board}_fw_${MAJOR_VERSION}_${MINOR_VERSION}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000308#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000309# Build the project list.
Andrew McRaef96cd602020-06-23 23:06:19 +1000310# If no projects are specified, use all in the programs directory.
Andrew McRae0809eb52020-06-18 00:13:36 +1000311#
Andrew McRaef96cd602020-06-23 23:06:19 +1000312if [[ -z "${FLAGS_project}" ]]; then
Andrew McRae7c9655c2020-06-22 15:09:54 +1000313 BDIR="${GCLIENT_ROOT}/src/project/${FLAGS_board}"
Andrew McRaef96cd602020-06-23 23:06:19 +1000314 cd "${BDIR}"
315 mapfile -t PROJLIST < <(ls)
316else
Andrew McRaed0aee432020-07-22 15:40:55 +1000317 read -r -a PROJLIST <<< "$(rd_list "${FLAGS_project}")"
Andrew McRae0809eb52020-06-18 00:13:36 +1000318fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000319#
Andrew McRaed0aee432020-07-22 15:40:55 +1000320# Get list of reviewers (if any)
321#
322read -r -a REVIEWERS <<< "$(rd_list "${FLAGS_reviewer}")"
323#
Andrew McRaef96cd602020-06-23 23:06:19 +1000324# Filter out the projects that are to be skipped.
325#
326if [[ -n "${FLAGS_skip}" ]]; then
327 PROJECTS=()
Andrew McRaed0aee432020-07-22 15:40:55 +1000328 read -r -a SKIP_ARRAY <<< "$(rd_list "${FLAGS_skip}")"
Andrew McRae88eda242020-06-26 12:35:55 +1000329 # Validate skipped projects
330 for S in "${SKIP_ARRAY[@]}"; do
331 check_project "${S}"
332 done
Andrew McRaef96cd602020-06-23 23:06:19 +1000333 SKIPPED="${SKIP_ARRAY[*]}"
334 for P in "${PROJLIST[@]}"; do
335 if ! (in_list "${P}" "${SKIPPED}"); then
336 PROJECTS+=("${P}")
337 fi
338 done
339else
340 PROJECTS=("${PROJLIST[@]}")
341fi
342#
Andrew McRaed0aee432020-07-22 15:40:55 +1000343# Validate bug number (if any).
Andrew McRae88eda242020-06-26 12:35:55 +1000344# Must be of the form b:nnnnn or chromium:nnnnn
345#
346if [[ "${FLAGS_bug}" != "none" ]]; then
347 BG="b:[0-9]+|chromium:[0-9]+"
348 BGRE="^(${BG})(,(${BG}))*$"
349 if [[ ! "${FLAGS_bug}" =~ ${BGRE} ]]; then
350 echo "Bug must be of the form b:nnn or chromium:nnn"
351 die "A comma separated list is allowed"
352 fi
353fi
354#
Andrew McRaef96cd602020-06-23 23:06:19 +1000355# Validate project list and file locations.
Andrew McRae7c9655c2020-06-22 15:09:54 +1000356#
357for P in "${PROJECTS[@]}"; do
Andrew McRae88eda242020-06-26 12:35:55 +1000358 check_project "${P}"
Andrew McRae7c9655c2020-06-22 15:09:54 +1000359done
Andrew McRaef96cd602020-06-23 23:06:19 +1000360OVERLAY="${GCLIENT_ROOT}/src/private-overlays/overlay-${FLAGS_board}-private/chromeos-base/chromeos-firmware-${FLAGS_board}"
Andrew McRae88eda242020-06-26 12:35:55 +1000361# Validate project overlay and ebuild file
Andrew McRaef96cd602020-06-23 23:06:19 +1000362EB9999="chromeos-firmware-${FLAGS_board}-9999.ebuild"
363if [[ ! -f "${OVERLAY}/${EB9999}" ]]; then
Andrew McRae88eda242020-06-26 12:35:55 +1000364 die "${OVERLAY}/${EB9999}: overlay error"
Andrew McRaef96cd602020-06-23 23:06:19 +1000365fi
366# Make sure dev/contrib is accessible
367DEVCONTRIB="${GCLIENT_ROOT}/src/platform/dev/contrib"
368if [[ ! -d "${DEVCONTRIB}" ]]; then
369 die "${DEVCONTRIB}: invalid directory"
370fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000371#
Andrew McRaea164ca62020-07-20 11:56:50 +1000372# Display arguments.
373#
374echo "Invoked as:"
375echo "${COMMAND} ${CMDARGS}"
376echo "Program (board) to be updated: ${FLAGS_board}"
377echo -n "Projects to be updated are: "
378for PROJ in "${PROJECTS[@]}"; do
379 echo -n " ${PROJ}"
380done
381if [[ -n "${SKIPPED}" ]]; then
382 echo -n " (skipped:"
383 for S in "${SKIPPED[@]}"; do
384 echo -n " ${S}"
385 done
386 echo -n ")"
387fi
388echo
389echo "Release number of upgrade: ${FLAGS_release}"
390echo "Major version of release: ${MAJOR_VERSION}"
391echo "Minor version of release: ${MINOR_VERSION}"
392echo "BUG string used in commit: ${FLAGS_bug}"
393echo "TEST string used in commit: ${FLAGS_test}"
Andrew McRaed0aee432020-07-22 15:40:55 +1000394echo "Reviewer(s) assigned to CLs: ${REVIEWERS[*]}"
Andrew McRaea164ca62020-07-20 11:56:50 +1000395echo "repo branch to be used is: ${BRANCH}"
Andrew McRaed0aee432020-07-22 15:40:55 +1000396echo "Update program.star version: $(yes_no "${FLAGS_program}")"
397echo "Coreboot build enabled: $(yes_no "${FLAGS_build}")"
398echo "Dry run requested: $(yes_no "${FLAGS_dryrun}")"
399echo "Verify before proceeding: $(yes_no "${FLAGS_verify}")"
Andrew McRae88eda242020-06-26 12:35:55 +1000400#
401if [[ "${FLAGS_dryrun}" -eq "${FLAGS_TRUE}" ]]; then
Andrew McRaea164ca62020-07-20 11:56:50 +1000402 echo "Dry run requested, exiting"
Andrew McRae88eda242020-06-26 12:35:55 +1000403 exit 0
404fi
Andrew McRaea164ca62020-07-20 11:56:50 +1000405read -p "Proceed with updating firmware (y/N)? " -r
406if [[ ! "${REPLY}" =~ ^[Yy]$ ]]; then
407 die "Not verified, exiting..."
408fi
Andrew McRae88eda242020-06-26 12:35:55 +1000409if [[ "${FLAGS_build}" -eq "${FLAGS_FALSE}" ]]; then
410 echo
411 echo "******************************************"
412 echo "* You have elected not to build coreboot *"
413 echo "* This assumes coreboot is already built *"
414 echo "******************************************"
415 echo
416fi
417#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000418# Create a temp directory.
419TEMPDIR=$(mktemp -d -t fw-XXXXXXXXXX)
Andrew McRae7c9655c2020-06-22 15:09:54 +1000420
421trap "exit 1" HUP INT PIPE QUIT TERM
422trap 'cleanup' EXIT
423
Andrew McRae0809eb52020-06-18 00:13:36 +1000424#
Andrew McRae0809eb52020-06-18 00:13:36 +1000425# From now on, all errors should invoke 'abort'
Andrew McRae7c9655c2020-06-22 15:09:54 +1000426# so that the branches and CLs are cleaned up on exit.
Andrew McRae0809eb52020-06-18 00:13:36 +1000427#
Andrew McRae88eda242020-06-26 12:35:55 +1000428# If required, update the firmware version in the program's program.star file
Andrew McRae0809eb52020-06-18 00:13:36 +1000429#
Andrew McRae88eda242020-06-26 12:35:55 +1000430if [[ "${FLAGS_program}" -eq "${FLAGS_TRUE}" ]]; then
431 cd "${PROGDIR}"
432 echo "Updating program.star for board ${FLAGS_board}"
433 branch
434 if (update_version "program.star") ;then
435 #
436 # If config has changed, create a CL.
437 #
438 git add .
439 git commit -q -F - <<EOF
440${FLAGS_board}: Update program firmware to ${FLAGS_release}
Andrew McRae0809eb52020-06-18 00:13:36 +1000441
Andrew McRae88eda242020-06-26 12:35:55 +1000442Autogenerated by:
Andrew McRaed0aee432020-07-22 15:40:55 +1000443$(echo "${COMMAND} ${CMDARGS}" | fold -s -w 70 | sed '2,$s/^/ /')
Andrew McRae3b94aaf2020-06-25 15:28:18 +1000444
445BUG=${FLAGS_bug}
Andrew McRae88eda242020-06-26 12:35:55 +1000446TEST=${FLAGS_test}
Andrew McRae0809eb52020-06-18 00:13:36 +1000447EOF
Rob Barnesaafdcbd2020-07-21 07:42:37 -0600448 if ! repo upload -y --verify "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.output" 2>&1 ;then
Andrew McRae88eda242020-06-26 12:35:55 +1000449 cat "${TEMPDIR}/upload.output"
450 abort "repo upload failed"
451 fi
452 PROGRAM_CL=$(getcl "program/${FLAGS_board}" "${TEMPDIR}/upload.output")
Andrew McRaef96cd602020-06-23 23:06:19 +1000453 fi
Andrew McRae0809eb52020-06-18 00:13:36 +1000454fi
455#
Andrew McRae88eda242020-06-26 12:35:55 +1000456# Now walk through the projects and update the version (if present)
457# and regenerate the configs.
Andrew McRae0809eb52020-06-18 00:13:36 +1000458# Create and upload a CL and capture the CL number and project directory
459# if the project has changed.
460#
461PROJ_CLS=()
462PROJ_DIRS=()
Andrew McRae7c9655c2020-06-22 15:09:54 +1000463for PROJ in "${PROJECTS[@]}"; do
464 echo "Updating configs for project ${PROJ}"
465 PDIR="${GCLIENT_ROOT}/src/project/${FLAGS_board}/${PROJ}"
Andrew McRaef96cd602020-06-23 23:06:19 +1000466 cd "${PDIR}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000467 branch
Andrew McRae88eda242020-06-26 12:35:55 +1000468 update_version "config.star" || true
Andrew McRae0809eb52020-06-18 00:13:36 +1000469 ./config.star || abort "Generate config failed for ${PROJ}"
470 check_config > "${TEMPDIR}/check_config-${PROJ}.output" || abort "check_config failed for ${PROJ}"
471 #
472 # Check if any files changed.
473 #
474 if changed; then
Andrew McRaef96cd602020-06-23 23:06:19 +1000475 echo "Creating CL for changes to project ${PROJ}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000476 git add .
Andrew McRaef96cd602020-06-23 23:06:19 +1000477 git commit -q -F - <<EOF
Andrew McRae7c9655c2020-06-22 15:09:54 +1000478${PROJ}: Update firmware to ${FLAGS_release}
Andrew McRaef96cd602020-06-23 23:06:19 +1000479
Andrew McRae88eda242020-06-26 12:35:55 +1000480Autogenerated by:
481${COMMAND} ${CMDARGS}
Andrew McRae3b94aaf2020-06-25 15:28:18 +1000482
483BUG=${FLAGS_bug}
Andrew McRae88eda242020-06-26 12:35:55 +1000484TEST=${FLAGS_test}
Andrew McRae0809eb52020-06-18 00:13:36 +1000485EOF
Rob Barnesaafdcbd2020-07-21 07:42:37 -0600486 if ! repo upload -y --verify "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.${PROJ}.output" 2>&1 ;then
Andrew McRaef96cd602020-06-23 23:06:19 +1000487 cat "${TEMPDIR}/upload.${PROJ}.output"
488 abort "repo upload failed"
489 fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000490 P_CL=$(getcl "project/${FLAGS_board}/${PROJ}" "${TEMPDIR}/upload.${PROJ}.output")
Andrew McRae0809eb52020-06-18 00:13:36 +1000491 PROJ_CLS+=("${P_CL}")
492 PROJ_DIRS+=("${PDIR}")
493 fi
494done
495#
496# Create a Cq-Depend line with all the project CLs
497#
498if [[ -n "${PROJ_CLS[*]}" ]];then
499 SEP=" "
500 PROG_CQD="Cq-Depend:"
501 for CL in "${PROJ_CLS[@]}"; do
502 PROG_CQD="${PROG_CQD}${SEP}chrome-internal:${CL}"
503 SEP=", "
504 done
505 #
Andrew McRaef96cd602020-06-23 23:06:19 +1000506 # If a program CL exists, add the Cq-Depend line to it.
Andrew McRae0809eb52020-06-18 00:13:36 +1000507 #
Andrew McRaef96cd602020-06-23 23:06:19 +1000508 if [[ -n "${PROGRAM_CL}" ]]; then
509 cd "${PROGDIR}"
510 amend "${PROG_CQD}"
Rob Barnesaafdcbd2020-07-21 07:42:37 -0600511 if ! repo upload -y --verify "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.amend.output" 2>&1 ;then
Andrew McRaef96cd602020-06-23 23:06:19 +1000512 cat "${TEMPDIR}/upload.amend.output"
513 abort "repo upload failed"
514 fi
515 fi
Andrew McRae0809eb52020-06-18 00:13:36 +1000516fi
517#
518# All the boxster configs have been uploaded.
519# Now run the update script and update the firmware manifest.
520#
521# Build base coreboot files
Andrew McRae0809eb52020-06-18 00:13:36 +1000522#
Andrew McRae88eda242020-06-26 12:35:55 +1000523if [[ "${FLAGS_build}" -eq "${FLAGS_TRUE}" ]]; then
524 echo "Running coreboot build. This may take a while..."
525 #
526 # Attempt to customise the coreboot build depending on the platform.
527 #
528 case "${FLAGS_board}" in
529 "zork")
530 PACKAGES=(coreboot-zork chromeos-bootimage)
531 ;;
532 "puff")
533 PACKAGES=(chromeos-ec coreboot depthcharge vboot_reference libpayload chromeos-bootimage coreboot-private-files intel-cmlfsp coreboot-private-files-puff)
534 ;;
535 *)
536 # Use general packages
537 echo "Taking a guess at coreboot packages for ${FLAGS_board}"
538 echo "If the coreboot build fails, this script may have to be customized for this board"
539 PACKAGES=(coreboot depthcharge vboot_reference libpayload chromeos-bootimage)
540 ;;
541 esac
Andrew McRae94639642020-07-14 17:14:04 +1000542 if ! ("emerge-${FLAGS_board}" -j --quiet-build "${PACKAGES[@]}"); then
Andrew McRae88eda242020-06-26 12:35:55 +1000543 abort "coreboot build failed!"
544 fi
545 echo "coreboot build successful"
546else
547 echo "Coreboot build not attempted"
Andrew McRae0809eb52020-06-18 00:13:36 +1000548fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000549EB9999="chromeos-firmware-${FLAGS_board}-9999.ebuild"
Andrew McRae0809eb52020-06-18 00:13:36 +1000550#
551# Remove any previous attempts to build the firmware.
552#
Andrew McRaed26b2792020-08-06 23:28:26 +1000553cros workon "--board=${FLAGS_board}" stop "chromeos-base/chromeos-firmware-${FLAGS_board}"
554cros workon "--board=${FLAGS_board}" stop "chromeos-base/chromeos-config-bsp-${FLAGS_board}-private"
Andrew McRaef96cd602020-06-23 23:06:19 +1000555cd "${OVERLAY}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000556branch
Andrew McRaef96cd602020-06-23 23:06:19 +1000557cd "${DEVCONTRIB}"
Andrew McRae7c9655c2020-06-22 15:09:54 +1000558if ! (./cros_update_firmware -q "--board=${FLAGS_board}"); then
559 abort "cros_update_firmware failed for ${FLAGS_board}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000560fi
Andrew McRaef96cd602020-06-23 23:06:19 +1000561cd "${OVERLAY}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000562#
563# If files have been updated, then create a CL for the changes.
564#
565OVERLAY_CL=""
566if changed; then
567 #
568 # Bump the version in the ebuild file. Relies on the format
569 # of the version so that the last number is at the end of the line.
570 #
571 CURVERS=$(grep "VERSION=REVBUMP" "${EB9999}" | grep -o "[0-9][0-9]*$")
572 NEXTVERS=$((CURVERS + 1))
Andrew McRaef96cd602020-06-23 23:06:19 +1000573 sed -i "/VERSION=REVBUMP/s/${CURVERS}$/${NEXTVERS}/" "${EB9999}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000574 git add .
Andrew McRaef96cd602020-06-23 23:06:19 +1000575 git commit -q -F - <<EOF
Andrew McRae7c9655c2020-06-22 15:09:54 +1000576${FLAGS_board}: Update firmware to ${FLAGS_release}
Andrew McRae0809eb52020-06-18 00:13:36 +1000577
Andrew McRae88eda242020-06-26 12:35:55 +1000578Autogenerated by:
579${COMMAND} ${CMDARGS}
Andrew McRae3b94aaf2020-06-25 15:28:18 +1000580
581BUG=${FLAGS_bug}
Andrew McRae88eda242020-06-26 12:35:55 +1000582TEST=${FLAGS_test}
Andrew McRae0809eb52020-06-18 00:13:36 +1000583
Andrew McRaef96cd602020-06-23 23:06:19 +1000584${PROG_CQD}
Andrew McRae0809eb52020-06-18 00:13:36 +1000585EOF
586 #
587 # Upload with no-verify since the file lines are too long.
588 #
Andrew McRaef96cd602020-06-23 23:06:19 +1000589 if ! repo upload "--ht=${BRANCH}" -y --no-verify --cbr . > "${TEMPDIR}/overlay.output" 2>&1 ;then
590 cat "${TEMPDIR}/overlay.output"
591 abort "repo upload failed"
592 fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000593 OVERLAY_CL=$(getcl "overlays/overlay-${FLAGS_board}-private" "${TEMPDIR}/overlay.output")
Andrew McRae0809eb52020-06-18 00:13:36 +1000594 #
595 # Go back and amend all the project commit messages with a Cq-Depend on
596 # the program and overlay CLs.
597 #
598 CQD="Cq-Depend: chrome-internal:${OVERLAY_CL}"
599 if [[ -n "${PROGRAM_CL}" ]]; then
600 CQD="${CQD}, chrome-internal:${PROGRAM_CL}"
601 fi
602 for DIR in "${PROJ_DIRS[@]}"; do
Andrew McRaef96cd602020-06-23 23:06:19 +1000603 cd "${DIR}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000604 amend "${CQD}"
Rob Barnesaafdcbd2020-07-21 07:42:37 -0600605 if ! repo upload -y --verify --cbr . > "${TEMPDIR}/cqd.output" 2>&1 ;then
Andrew McRaef96cd602020-06-23 23:06:19 +1000606 cat "${TEMPDIR}/cqd.output"
607 abort "repo upload failed"
608 fi
Andrew McRae0809eb52020-06-18 00:13:36 +1000609 done
610fi
611#
612# Send all of the CLs to the CQ for a dry run.
613#
614ALL_CLS=$(gerrit -i --raw search "owner:me status:open hashtag:${BRANCH}")
615if [[ -z "${ALL_CLS}" ]]; then
Andrew McRae7c9655c2020-06-22 15:09:54 +1000616 echo "No changes required for program ${FLAGS_board}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000617 repo abandon "${BRANCH}"
618 exit 0
619fi
620for cl in ${ALL_CLS}; do
621 gerrit -i label-cq "${cl}" 1
622 gerrit -i label-v "${cl}" 1
623 gerrit -i label-as "${cl}" 1
624done
625#
626# If reviewer is set, then add them to the CLs
627#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000628if [[ -n "${FLAGS_reviewer}" ]]; then
Andrew McRaed0aee432020-07-22 15:40:55 +1000629 echo "Sending CLs ${ALL_CLS} to ${REVIEWERS[*]} for review"
Andrew McRae0809eb52020-06-18 00:13:36 +1000630 for cl in ${ALL_CLS}; do
Andrew McRaed0aee432020-07-22 15:40:55 +1000631 gerrit -i reviewers "${cl}" "${REVIEWERS[@]}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000632 done
633else
634 echo "Send CLs for review by running:"
635 echo " for cl in ${ALL_CLS}; do gerrit -i reviewers \$cl <reviewer>; done"
636fi
637#
638# Final instructions.
639#
640echo "Run:"
Andrew McRae7c9655c2020-06-22 15:09:54 +1000641echo " /build/${FLAGS_board}/usr/sbin/chromeos-firmwareupdate --manifest"
Andrew McRae0809eb52020-06-18 00:13:36 +1000642echo "to verify firmware update"
643echo "When submitted, cleanup by running:"
644echo "repo abandon ${BRANCH}"