blob: b61b6c966681649986be23a2046b2e88f6c58ee8 [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 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
Andrew McRaed0aee432020-07-22 15:40:55 +1000119#
Andrew McRaea164ca62020-07-20 11:56:50 +1000120yes_no() {
121 if [[ "${1}" -eq "${FLAGS_FALSE}" ]]; then
122 echo -n "no"
123 else
124 echo -n "yes"
125 fi
126}
127#
Andrew McRaed0aee432020-07-22 15:40:55 +1000128# Normalise a comma or space separated argument or arguments to
129# a single set of space separated arguments.
130#
131rd_list() {
132 local l=()
133 for arg in "$@"; do
134 IFS=', ' read -r -a la <<< "${arg}"
135 l+=("${la[@]}")
136 done
137 echo "${l[@]}"
138}
139#
Andrew McRae0809eb52020-06-18 00:13:36 +1000140# Return true if repo has changes.
Andrew McRae88eda242020-06-26 12:35:55 +1000141#
Andrew McRae0809eb52020-06-18 00:13:36 +1000142changed() {
143 [[ -n $(git status -s) ]]
144}
145#
146# Add a Cq-Depend line to a commit.
Andrew McRae0809eb52020-06-18 00:13:36 +1000147#
148amend() {
Andrew McRaef96cd602020-06-23 23:06:19 +1000149 git log -1 --pretty=%B > "${TEMPDIR}/amend-msg"
150 sed -i "/^Change-Id/ i ${1}" "${TEMPDIR}/amend-msg"
151 git commit -q --amend -F "${TEMPDIR}/amend-msg"
152}
153#
Andrew McRae88eda242020-06-26 12:35:55 +1000154# Confirm that $1 is a valid project
155#
156check_project() {
157 PDIR="${GCLIENT_ROOT}/src/project/${FLAGS_board}/${1}"
158 if [[ ! -d "${PDIR}" ]]; then
159 die "${P} is not a valid project (${PDIR} missing)"
160 fi
161}
162#
Andrew McRaef96cd602020-06-23 23:06:19 +1000163# Return true if $1 is in list $2
164#
165in_list() {
166 for S in ${2}; do
167 if [[ "$1" == "${S}" ]]; then
168 return 0
169 fi
170 done
171 return 1
Andrew McRae0809eb52020-06-18 00:13:36 +1000172}
173#
Andrew McRaeb46a3362020-07-16 12:12:18 +1000174# Return 0 if file has major or minor version in it.
Andrew McRae88eda242020-06-26 12:35:55 +1000175#
176has_version() {
Andrew McRaeb46a3362020-07-16 12:12:18 +1000177 (grep -E -q "(${ANY_MAJOR}|${ANY_MINOR})" "${1}")
Andrew McRae88eda242020-06-26 12:35:55 +1000178}
179#
Andrew McRaeb46a3362020-07-16 12:12:18 +1000180# Update the version in the file passed.
Andrew McRae88eda242020-06-26 12:35:55 +1000181# return 0 if version updated.
182# return 1 if version not in file, or unchanged.
183#
184update_version() {
Andrew McRaeb46a3362020-07-16 12:12:18 +1000185 # Check for major or minor version in file.
Andrew McRae88eda242020-06-26 12:35:55 +1000186 if ! (has_version "${1}") ;then
187 return 1
188 fi
189 local nf="${TEMPDIR}/new-${1}"
Andrew McRaeb46a3362020-07-16 12:12:18 +1000190 sed -E "s/${ANY_MAJOR}/${NEW_MAJOR}/" "${1}" > "${nf}"
191 sed -i -E "s/${ANY_MINOR}/${NEW_MINOR}/" "${nf}"
192 if cmp -s "${1}" "${nf}"; then
Andrew McRae88eda242020-06-26 12:35:55 +1000193 return 1
194 fi
195 cp "${nf}" "${1}"
196 return 0
197}
198#
Andrew McRae0809eb52020-06-18 00:13:36 +1000199# Validate arguments
200#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000201if [[ -z "${FLAGS_board}" ]]; then
202 die "-b or --board required."
203fi
204if [[ -z "${FLAGS_release}" ]]; then
205 die "-r or --release required."
Andrew McRae0809eb52020-06-18 00:13:36 +1000206fi
207#
208# Program must exist as a directory
209#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000210PROGDIR="${GCLIENT_ROOT}/src/program/${FLAGS_board}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000211if [[ ! -d "${PROGDIR}" ]]; then
Andrew McRae7c9655c2020-06-22 15:09:54 +1000212 die "${FLAGS_board} is not a valid program (${PROGDIR} missing)"
Andrew McRae0809eb52020-06-18 00:13:36 +1000213fi
Andrew McRaeb46a3362020-07-16 12:12:18 +1000214#
215# Validate release
216# Major must be a 5 digit number
217# Optional minor release must be a number.
218#
219if [[ "${FLAGS_release}" =~ ^${MAJOR_RE}$ ]]; then
220 MAJOR_VERSION=${FLAGS_release}
221 MINOR_VERSION="0"
222elif [[ "${FLAGS_release}" =~ ^${MAJOR_RE}\.${MINOR_RE}$ ]]; then
223 MAJOR_VERSION=$(echo "${FLAGS_release}" | cut -d. -f1)
224 MINOR_VERSION=$(echo "${FLAGS_release}" | cut -d. -f2)
225else
226 die "Unknown release format (must be NNNNN[.n])"
Andrew McRae0809eb52020-06-18 00:13:36 +1000227fi
Andrew McRaeb46a3362020-07-16 12:12:18 +1000228NEW_MAJOR="${MAJOR_PREFIX}${MAJOR_VERSION}"
229NEW_MINOR="${MINOR_PREFIX}${MINOR_VERSION}"
Andrew McRaef96cd602020-06-23 23:06:19 +1000230# Use a common git branch name.
Andrew McRaeb46a3362020-07-16 12:12:18 +1000231BRANCH="update_${FLAGS_board}_fw_${MAJOR_VERSION}_${MINOR_VERSION}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000232#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000233# Build the project list.
Andrew McRaef96cd602020-06-23 23:06:19 +1000234# If no projects are specified, use all in the programs directory.
Andrew McRae0809eb52020-06-18 00:13:36 +1000235#
Andrew McRaef96cd602020-06-23 23:06:19 +1000236if [[ -z "${FLAGS_project}" ]]; then
Andrew McRae7c9655c2020-06-22 15:09:54 +1000237 BDIR="${GCLIENT_ROOT}/src/project/${FLAGS_board}"
Andrew McRaef96cd602020-06-23 23:06:19 +1000238 cd "${BDIR}"
239 mapfile -t PROJLIST < <(ls)
240else
Andrew McRaed0aee432020-07-22 15:40:55 +1000241 read -r -a PROJLIST <<< "$(rd_list "${FLAGS_project}")"
Andrew McRae0809eb52020-06-18 00:13:36 +1000242fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000243#
Andrew McRaed0aee432020-07-22 15:40:55 +1000244# Get list of reviewers (if any)
245#
246read -r -a REVIEWERS <<< "$(rd_list "${FLAGS_reviewer}")"
247#
Andrew McRaef96cd602020-06-23 23:06:19 +1000248# Filter out the projects that are to be skipped.
249#
250if [[ -n "${FLAGS_skip}" ]]; then
251 PROJECTS=()
Andrew McRaed0aee432020-07-22 15:40:55 +1000252 read -r -a SKIP_ARRAY <<< "$(rd_list "${FLAGS_skip}")"
Andrew McRae88eda242020-06-26 12:35:55 +1000253 # Validate skipped projects
254 for S in "${SKIP_ARRAY[@]}"; do
255 check_project "${S}"
256 done
Andrew McRaef96cd602020-06-23 23:06:19 +1000257 SKIPPED="${SKIP_ARRAY[*]}"
258 for P in "${PROJLIST[@]}"; do
259 if ! (in_list "${P}" "${SKIPPED}"); then
260 PROJECTS+=("${P}")
261 fi
262 done
263else
264 PROJECTS=("${PROJLIST[@]}")
265fi
266#
Andrew McRaed0aee432020-07-22 15:40:55 +1000267# Validate bug number (if any).
Andrew McRae88eda242020-06-26 12:35:55 +1000268# Must be of the form b:nnnnn or chromium:nnnnn
269#
270if [[ "${FLAGS_bug}" != "none" ]]; then
271 BG="b:[0-9]+|chromium:[0-9]+"
272 BGRE="^(${BG})(,(${BG}))*$"
273 if [[ ! "${FLAGS_bug}" =~ ${BGRE} ]]; then
274 echo "Bug must be of the form b:nnn or chromium:nnn"
275 die "A comma separated list is allowed"
276 fi
277fi
278#
Andrew McRaef96cd602020-06-23 23:06:19 +1000279# Validate project list and file locations.
Andrew McRae7c9655c2020-06-22 15:09:54 +1000280#
281for P in "${PROJECTS[@]}"; do
Andrew McRae88eda242020-06-26 12:35:55 +1000282 check_project "${P}"
Andrew McRae7c9655c2020-06-22 15:09:54 +1000283done
Andrew McRaef96cd602020-06-23 23:06:19 +1000284OVERLAY="${GCLIENT_ROOT}/src/private-overlays/overlay-${FLAGS_board}-private/chromeos-base/chromeos-firmware-${FLAGS_board}"
Andrew McRae88eda242020-06-26 12:35:55 +1000285# Validate project overlay and ebuild file
Andrew McRaef96cd602020-06-23 23:06:19 +1000286EB9999="chromeos-firmware-${FLAGS_board}-9999.ebuild"
287if [[ ! -f "${OVERLAY}/${EB9999}" ]]; then
Andrew McRae88eda242020-06-26 12:35:55 +1000288 die "${OVERLAY}/${EB9999}: overlay error"
Andrew McRaef96cd602020-06-23 23:06:19 +1000289fi
290# Make sure dev/contrib is accessible
291DEVCONTRIB="${GCLIENT_ROOT}/src/platform/dev/contrib"
292if [[ ! -d "${DEVCONTRIB}" ]]; then
293 die "${DEVCONTRIB}: invalid directory"
294fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000295#
Andrew McRaea164ca62020-07-20 11:56:50 +1000296# Display arguments.
297#
298echo "Invoked as:"
299echo "${COMMAND} ${CMDARGS}"
300echo "Program (board) to be updated: ${FLAGS_board}"
301echo -n "Projects to be updated are: "
302for PROJ in "${PROJECTS[@]}"; do
303 echo -n " ${PROJ}"
304done
305if [[ -n "${SKIPPED}" ]]; then
306 echo -n " (skipped:"
307 for S in "${SKIPPED[@]}"; do
308 echo -n " ${S}"
309 done
310 echo -n ")"
311fi
312echo
313echo "Release number of upgrade: ${FLAGS_release}"
314echo "Major version of release: ${MAJOR_VERSION}"
315echo "Minor version of release: ${MINOR_VERSION}"
316echo "BUG string used in commit: ${FLAGS_bug}"
317echo "TEST string used in commit: ${FLAGS_test}"
Andrew McRaed0aee432020-07-22 15:40:55 +1000318echo "Reviewer(s) assigned to CLs: ${REVIEWERS[*]}"
Andrew McRaea164ca62020-07-20 11:56:50 +1000319echo "repo branch to be used is: ${BRANCH}"
Andrew McRaed0aee432020-07-22 15:40:55 +1000320echo "Update program.star version: $(yes_no "${FLAGS_program}")"
321echo "Coreboot build enabled: $(yes_no "${FLAGS_build}")"
322echo "Dry run requested: $(yes_no "${FLAGS_dryrun}")"
323echo "Verify before proceeding: $(yes_no "${FLAGS_verify}")"
Andrew McRae88eda242020-06-26 12:35:55 +1000324#
325if [[ "${FLAGS_dryrun}" -eq "${FLAGS_TRUE}" ]]; then
Andrew McRaea164ca62020-07-20 11:56:50 +1000326 echo "Dry run requested, exiting"
Andrew McRae88eda242020-06-26 12:35:55 +1000327 exit 0
328fi
Andrew McRaea164ca62020-07-20 11:56:50 +1000329read -p "Proceed with updating firmware (y/N)? " -r
330if [[ ! "${REPLY}" =~ ^[Yy]$ ]]; then
331 die "Not verified, exiting..."
332fi
Andrew McRae88eda242020-06-26 12:35:55 +1000333if [[ "${FLAGS_build}" -eq "${FLAGS_FALSE}" ]]; then
334 echo
335 echo "******************************************"
336 echo "* You have elected not to build coreboot *"
337 echo "* This assumes coreboot is already built *"
338 echo "******************************************"
339 echo
340fi
341#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000342# Create a temp directory.
343TEMPDIR=$(mktemp -d -t fw-XXXXXXXXXX)
Andrew McRae7c9655c2020-06-22 15:09:54 +1000344
345trap "exit 1" HUP INT PIPE QUIT TERM
346trap 'cleanup' EXIT
347
Andrew McRae0809eb52020-06-18 00:13:36 +1000348#
Andrew McRae0809eb52020-06-18 00:13:36 +1000349# From now on, all errors should invoke 'abort'
Andrew McRae7c9655c2020-06-22 15:09:54 +1000350# so that the branches and CLs are cleaned up on exit.
Andrew McRae0809eb52020-06-18 00:13:36 +1000351#
Andrew McRae88eda242020-06-26 12:35:55 +1000352# If required, update the firmware version in the program's program.star file
Andrew McRae0809eb52020-06-18 00:13:36 +1000353#
Andrew McRae88eda242020-06-26 12:35:55 +1000354if [[ "${FLAGS_program}" -eq "${FLAGS_TRUE}" ]]; then
355 cd "${PROGDIR}"
356 echo "Updating program.star for board ${FLAGS_board}"
357 branch
358 if (update_version "program.star") ;then
359 #
360 # If config has changed, create a CL.
361 #
362 git add .
363 git commit -q -F - <<EOF
364${FLAGS_board}: Update program firmware to ${FLAGS_release}
Andrew McRae0809eb52020-06-18 00:13:36 +1000365
Andrew McRae88eda242020-06-26 12:35:55 +1000366Autogenerated by:
Andrew McRaed0aee432020-07-22 15:40:55 +1000367$(echo "${COMMAND} ${CMDARGS}" | fold -s -w 70 | sed '2,$s/^/ /')
Andrew McRae3b94aaf2020-06-25 15:28:18 +1000368
369BUG=${FLAGS_bug}
Andrew McRae88eda242020-06-26 12:35:55 +1000370TEST=${FLAGS_test}
Andrew McRae0809eb52020-06-18 00:13:36 +1000371EOF
Rob Barnesaafdcbd2020-07-21 07:42:37 -0600372 if ! repo upload -y --verify "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.output" 2>&1 ;then
Andrew McRae88eda242020-06-26 12:35:55 +1000373 cat "${TEMPDIR}/upload.output"
374 abort "repo upload failed"
375 fi
376 PROGRAM_CL=$(getcl "program/${FLAGS_board}" "${TEMPDIR}/upload.output")
Andrew McRaef96cd602020-06-23 23:06:19 +1000377 fi
Andrew McRae0809eb52020-06-18 00:13:36 +1000378fi
379#
Andrew McRae88eda242020-06-26 12:35:55 +1000380# Now walk through the projects and update the version (if present)
381# and regenerate the configs.
Andrew McRae0809eb52020-06-18 00:13:36 +1000382# Create and upload a CL and capture the CL number and project directory
383# if the project has changed.
384#
385PROJ_CLS=()
386PROJ_DIRS=()
Andrew McRae7c9655c2020-06-22 15:09:54 +1000387for PROJ in "${PROJECTS[@]}"; do
388 echo "Updating configs for project ${PROJ}"
389 PDIR="${GCLIENT_ROOT}/src/project/${FLAGS_board}/${PROJ}"
Andrew McRaef96cd602020-06-23 23:06:19 +1000390 cd "${PDIR}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000391 branch
Andrew McRae88eda242020-06-26 12:35:55 +1000392 update_version "config.star" || true
Andrew McRae0809eb52020-06-18 00:13:36 +1000393 ./config.star || abort "Generate config failed for ${PROJ}"
394 check_config > "${TEMPDIR}/check_config-${PROJ}.output" || abort "check_config failed for ${PROJ}"
395 #
396 # Check if any files changed.
397 #
398 if changed; then
Andrew McRaef96cd602020-06-23 23:06:19 +1000399 echo "Creating CL for changes to project ${PROJ}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000400 git add .
Andrew McRaef96cd602020-06-23 23:06:19 +1000401 git commit -q -F - <<EOF
Andrew McRae7c9655c2020-06-22 15:09:54 +1000402${PROJ}: Update firmware to ${FLAGS_release}
Andrew McRaef96cd602020-06-23 23:06:19 +1000403
Andrew McRae88eda242020-06-26 12:35:55 +1000404Autogenerated by:
405${COMMAND} ${CMDARGS}
Andrew McRae3b94aaf2020-06-25 15:28:18 +1000406
407BUG=${FLAGS_bug}
Andrew McRae88eda242020-06-26 12:35:55 +1000408TEST=${FLAGS_test}
Andrew McRae0809eb52020-06-18 00:13:36 +1000409EOF
Rob Barnesaafdcbd2020-07-21 07:42:37 -0600410 if ! repo upload -y --verify "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.${PROJ}.output" 2>&1 ;then
Andrew McRaef96cd602020-06-23 23:06:19 +1000411 cat "${TEMPDIR}/upload.${PROJ}.output"
412 abort "repo upload failed"
413 fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000414 P_CL=$(getcl "project/${FLAGS_board}/${PROJ}" "${TEMPDIR}/upload.${PROJ}.output")
Andrew McRae0809eb52020-06-18 00:13:36 +1000415 PROJ_CLS+=("${P_CL}")
416 PROJ_DIRS+=("${PDIR}")
417 fi
418done
419#
420# Create a Cq-Depend line with all the project CLs
421#
422if [[ -n "${PROJ_CLS[*]}" ]];then
423 SEP=" "
424 PROG_CQD="Cq-Depend:"
425 for CL in "${PROJ_CLS[@]}"; do
426 PROG_CQD="${PROG_CQD}${SEP}chrome-internal:${CL}"
427 SEP=", "
428 done
429 #
Andrew McRaef96cd602020-06-23 23:06:19 +1000430 # If a program CL exists, add the Cq-Depend line to it.
Andrew McRae0809eb52020-06-18 00:13:36 +1000431 #
Andrew McRaef96cd602020-06-23 23:06:19 +1000432 if [[ -n "${PROGRAM_CL}" ]]; then
433 cd "${PROGDIR}"
434 amend "${PROG_CQD}"
Rob Barnesaafdcbd2020-07-21 07:42:37 -0600435 if ! repo upload -y --verify "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.amend.output" 2>&1 ;then
Andrew McRaef96cd602020-06-23 23:06:19 +1000436 cat "${TEMPDIR}/upload.amend.output"
437 abort "repo upload failed"
438 fi
439 fi
Andrew McRae0809eb52020-06-18 00:13:36 +1000440fi
441#
442# All the boxster configs have been uploaded.
443# Now run the update script and update the firmware manifest.
444#
445# Build base coreboot files
Andrew McRae0809eb52020-06-18 00:13:36 +1000446#
Andrew McRae88eda242020-06-26 12:35:55 +1000447if [[ "${FLAGS_build}" -eq "${FLAGS_TRUE}" ]]; then
448 echo "Running coreboot build. This may take a while..."
449 #
450 # Attempt to customise the coreboot build depending on the platform.
451 #
452 case "${FLAGS_board}" in
453 "zork")
454 PACKAGES=(coreboot-zork chromeos-bootimage)
455 ;;
456 "puff")
457 PACKAGES=(chromeos-ec coreboot depthcharge vboot_reference libpayload chromeos-bootimage coreboot-private-files intel-cmlfsp coreboot-private-files-puff)
458 ;;
459 *)
460 # Use general packages
461 echo "Taking a guess at coreboot packages for ${FLAGS_board}"
462 echo "If the coreboot build fails, this script may have to be customized for this board"
463 PACKAGES=(coreboot depthcharge vboot_reference libpayload chromeos-bootimage)
464 ;;
465 esac
Andrew McRae94639642020-07-14 17:14:04 +1000466 if ! ("emerge-${FLAGS_board}" -j --quiet-build "${PACKAGES[@]}"); then
Andrew McRae88eda242020-06-26 12:35:55 +1000467 abort "coreboot build failed!"
468 fi
469 echo "coreboot build successful"
470else
471 echo "Coreboot build not attempted"
Andrew McRae0809eb52020-06-18 00:13:36 +1000472fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000473EB9999="chromeos-firmware-${FLAGS_board}-9999.ebuild"
Andrew McRae0809eb52020-06-18 00:13:36 +1000474#
475# Remove any previous attempts to build the firmware.
476#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000477"cros_workon-${FLAGS_board}" stop "chromeos-base/chromeos-firmware-${FLAGS_board}"
478"cros_workon-${FLAGS_board}" stop "chromeos-base/chromeos-config-bsp-${FLAGS_board}-private"
Andrew McRaef96cd602020-06-23 23:06:19 +1000479cd "${OVERLAY}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000480branch
Andrew McRaef96cd602020-06-23 23:06:19 +1000481cd "${DEVCONTRIB}"
Andrew McRae7c9655c2020-06-22 15:09:54 +1000482if ! (./cros_update_firmware -q "--board=${FLAGS_board}"); then
483 abort "cros_update_firmware failed for ${FLAGS_board}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000484fi
Andrew McRaef96cd602020-06-23 23:06:19 +1000485cd "${OVERLAY}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000486#
487# If files have been updated, then create a CL for the changes.
488#
489OVERLAY_CL=""
490if changed; then
491 #
492 # Bump the version in the ebuild file. Relies on the format
493 # of the version so that the last number is at the end of the line.
494 #
495 CURVERS=$(grep "VERSION=REVBUMP" "${EB9999}" | grep -o "[0-9][0-9]*$")
496 NEXTVERS=$((CURVERS + 1))
Andrew McRaef96cd602020-06-23 23:06:19 +1000497 sed -i "/VERSION=REVBUMP/s/${CURVERS}$/${NEXTVERS}/" "${EB9999}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000498 git add .
Andrew McRaef96cd602020-06-23 23:06:19 +1000499 git commit -q -F - <<EOF
Andrew McRae7c9655c2020-06-22 15:09:54 +1000500${FLAGS_board}: Update firmware to ${FLAGS_release}
Andrew McRae0809eb52020-06-18 00:13:36 +1000501
Andrew McRae88eda242020-06-26 12:35:55 +1000502Autogenerated by:
503${COMMAND} ${CMDARGS}
Andrew McRae3b94aaf2020-06-25 15:28:18 +1000504
505BUG=${FLAGS_bug}
Andrew McRae88eda242020-06-26 12:35:55 +1000506TEST=${FLAGS_test}
Andrew McRae0809eb52020-06-18 00:13:36 +1000507
Andrew McRaef96cd602020-06-23 23:06:19 +1000508${PROG_CQD}
Andrew McRae0809eb52020-06-18 00:13:36 +1000509EOF
510 #
511 # Upload with no-verify since the file lines are too long.
512 #
Andrew McRaef96cd602020-06-23 23:06:19 +1000513 if ! repo upload "--ht=${BRANCH}" -y --no-verify --cbr . > "${TEMPDIR}/overlay.output" 2>&1 ;then
514 cat "${TEMPDIR}/overlay.output"
515 abort "repo upload failed"
516 fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000517 OVERLAY_CL=$(getcl "overlays/overlay-${FLAGS_board}-private" "${TEMPDIR}/overlay.output")
Andrew McRae0809eb52020-06-18 00:13:36 +1000518 #
519 # Go back and amend all the project commit messages with a Cq-Depend on
520 # the program and overlay CLs.
521 #
522 CQD="Cq-Depend: chrome-internal:${OVERLAY_CL}"
523 if [[ -n "${PROGRAM_CL}" ]]; then
524 CQD="${CQD}, chrome-internal:${PROGRAM_CL}"
525 fi
526 for DIR in "${PROJ_DIRS[@]}"; do
Andrew McRaef96cd602020-06-23 23:06:19 +1000527 cd "${DIR}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000528 amend "${CQD}"
Rob Barnesaafdcbd2020-07-21 07:42:37 -0600529 if ! repo upload -y --verify --cbr . > "${TEMPDIR}/cqd.output" 2>&1 ;then
Andrew McRaef96cd602020-06-23 23:06:19 +1000530 cat "${TEMPDIR}/cqd.output"
531 abort "repo upload failed"
532 fi
Andrew McRae0809eb52020-06-18 00:13:36 +1000533 done
534fi
535#
536# Send all of the CLs to the CQ for a dry run.
537#
538ALL_CLS=$(gerrit -i --raw search "owner:me status:open hashtag:${BRANCH}")
539if [[ -z "${ALL_CLS}" ]]; then
Andrew McRae7c9655c2020-06-22 15:09:54 +1000540 echo "No changes required for program ${FLAGS_board}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000541 repo abandon "${BRANCH}"
542 exit 0
543fi
544for cl in ${ALL_CLS}; do
545 gerrit -i label-cq "${cl}" 1
546 gerrit -i label-v "${cl}" 1
547 gerrit -i label-as "${cl}" 1
548done
549#
550# If reviewer is set, then add them to the CLs
551#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000552if [[ -n "${FLAGS_reviewer}" ]]; then
Andrew McRaed0aee432020-07-22 15:40:55 +1000553 echo "Sending CLs ${ALL_CLS} to ${REVIEWERS[*]} for review"
Andrew McRae0809eb52020-06-18 00:13:36 +1000554 for cl in ${ALL_CLS}; do
Andrew McRaed0aee432020-07-22 15:40:55 +1000555 gerrit -i reviewers "${cl}" "${REVIEWERS[@]}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000556 done
557else
558 echo "Send CLs for review by running:"
559 echo " for cl in ${ALL_CLS}; do gerrit -i reviewers \$cl <reviewer>; done"
560fi
561#
562# Final instructions.
563#
564echo "Run:"
Andrew McRae7c9655c2020-06-22 15:09:54 +1000565echo " /build/${FLAGS_board}/usr/sbin/chromeos-firmwareupdate --manifest"
Andrew McRae0809eb52020-06-18 00:13:36 +1000566echo "to verify firmware update"
567echo "When submitted, cleanup by running:"
568echo "repo abandon ${BRANCH}"