blob: a682f333aab726b430fdd515f698303322e2d8d5 [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"
47
48# Set before flag processing
49COMMAND=$(basename "$0")
50CMDARGS="$*"
Andrew McRae7c9655c2020-06-22 15:09:54 +100051
52# Parse command line
53FLAGS "$@" || exit 1
54eval set -- "${FLAGS_ARGV}"
55set -e
56
57# Script must be run inside the chroot.
58assert_inside_chroot
Andrew McRae0809eb52020-06-18 00:13:36 +100059#
60# Variables
61#
Andrew McRae7c9655c2020-06-22 15:09:54 +100062PATH="${PATH}:${GCLIENT_ROOT}/src/config/bin"
Andrew McRaeb46a3362020-07-16 12:12:18 +100063MAJOR_RE="[1-9][0-9]{4}"
64MINOR_RE="(0|[1-9][0-9]*)"
Andrew McRae0809eb52020-06-18 00:13:36 +100065BRANCH=""
Andrew McRae0809eb52020-06-18 00:13:36 +100066PROGRAM_CL=""
Andrew McRaeb46a3362020-07-16 12:12:18 +100067MAJOR_PREFIX="major_version = "
68MINOR_PREFIX="minor_version = "
69ANY_MAJOR="${MAJOR_PREFIX}${MAJOR_RE}"
70ANY_MINOR="${MINOR_PREFIX}${MINOR_RE}"
Andrew McRae0809eb52020-06-18 00:13:36 +100071#
72# Common functions
73#
74cleanup() {
Andrew McRae7c9655c2020-06-22 15:09:54 +100075 if [[ -d "${TEMPDIR}" ]]; then
76 rm -rf "${TEMPDIR}"
Andrew McRae0809eb52020-06-18 00:13:36 +100077 fi
Andrew McRae0809eb52020-06-18 00:13:36 +100078}
79#
80# Abort the update, and clean up branches and CLs
81#
82abort() {
Andrew McRae0809eb52020-06-18 00:13:36 +100083 CLS=$(gerrit -i --raw search "owner:me status:open hashtag:${BRANCH}")
84 if [[ -n "${CLS}" ]]; then
85 echo "Abandoning uploaded CLs"
Andrew McRaef96cd602020-06-23 23:06:19 +100086 for cl in ${CLS}; do
87 gerrit -i abandon "${cl}"
88 done
Andrew McRae0809eb52020-06-18 00:13:36 +100089 fi
Andrew McRae7c9655c2020-06-22 15:09:54 +100090 "cros_workon-${FLAGS_board}" stop "chromeos-base/chromeos-firmware-${FLAGS_board}"
91 "cros_workon-${FLAGS_board}" stop "chromeos-base/chromeos-config-bsp-${FLAGS_board}-private"
Andrew McRae0809eb52020-06-18 00:13:36 +100092 repo abandon "${BRANCH}"
Andrew McRae7c9655c2020-06-22 15:09:54 +100093 die "$*"
Andrew McRae0809eb52020-06-18 00:13:36 +100094}
95#
Andrew McRae88eda242020-06-26 12:35:55 +100096# Extract a CL number from the file containing the output of repo upload
Andrew McRae0809eb52020-06-18 00:13:36 +100097#
98getcl() {
99 CL=$(grep -o "https://chrome-internal-review.googlesource.com/c/chromeos/$1/+/[0-9][0-9]*" "$2")
100 if [[ -z "${CL}" ]]; then
101 cat "$2"
102 abort CL number not found in repo upload output
103 fi
104 echo "${CL}" | grep -o "[0-9][0-9]*"
105}
106#
107# If not on this branch, start a branch
108#
109branch() {
110 if ! (git branch --show-current | grep -q "${BRANCH}"); then
111 repo start "${BRANCH}"
112 else
113 echo "${BRANCH} already exists, skipping repo start"
114 fi
115}
116#
117# Return true if repo has changes.
Andrew McRae88eda242020-06-26 12:35:55 +1000118#
Andrew McRae0809eb52020-06-18 00:13:36 +1000119changed() {
120 [[ -n $(git status -s) ]]
121}
122#
123# Add a Cq-Depend line to a commit.
Andrew McRae0809eb52020-06-18 00:13:36 +1000124#
125amend() {
Andrew McRaef96cd602020-06-23 23:06:19 +1000126 git log -1 --pretty=%B > "${TEMPDIR}/amend-msg"
127 sed -i "/^Change-Id/ i ${1}" "${TEMPDIR}/amend-msg"
128 git commit -q --amend -F "${TEMPDIR}/amend-msg"
129}
130#
Andrew McRae88eda242020-06-26 12:35:55 +1000131# Confirm that $1 is a valid project
132#
133check_project() {
134 PDIR="${GCLIENT_ROOT}/src/project/${FLAGS_board}/${1}"
135 if [[ ! -d "${PDIR}" ]]; then
136 die "${P} is not a valid project (${PDIR} missing)"
137 fi
138}
139#
Andrew McRaef96cd602020-06-23 23:06:19 +1000140# Return true if $1 is in list $2
141#
142in_list() {
143 for S in ${2}; do
144 if [[ "$1" == "${S}" ]]; then
145 return 0
146 fi
147 done
148 return 1
Andrew McRae0809eb52020-06-18 00:13:36 +1000149}
150#
Andrew McRaeb46a3362020-07-16 12:12:18 +1000151# Return 0 if file has major or minor version in it.
Andrew McRae88eda242020-06-26 12:35:55 +1000152#
153has_version() {
Andrew McRaeb46a3362020-07-16 12:12:18 +1000154 (grep -E -q "(${ANY_MAJOR}|${ANY_MINOR})" "${1}")
Andrew McRae88eda242020-06-26 12:35:55 +1000155}
156#
Andrew McRaeb46a3362020-07-16 12:12:18 +1000157# Update the version in the file passed.
Andrew McRae88eda242020-06-26 12:35:55 +1000158# return 0 if version updated.
159# return 1 if version not in file, or unchanged.
160#
161update_version() {
Andrew McRaeb46a3362020-07-16 12:12:18 +1000162 # Check for major or minor version in file.
Andrew McRae88eda242020-06-26 12:35:55 +1000163 if ! (has_version "${1}") ;then
164 return 1
165 fi
166 local nf="${TEMPDIR}/new-${1}"
Andrew McRaeb46a3362020-07-16 12:12:18 +1000167 echo "Replace ${ANY_MAJOR} with ${NEW_MAJOR}"
168 echo "Replace ${ANY_MINOR} with ${NEW_MINOR}"
169 sed -E "s/${ANY_MAJOR}/${NEW_MAJOR}/" "${1}" > "${nf}"
170 sed -i -E "s/${ANY_MINOR}/${NEW_MINOR}/" "${nf}"
171 if cmp -s "${1}" "${nf}"; then
Andrew McRae88eda242020-06-26 12:35:55 +1000172 return 1
173 fi
174 cp "${nf}" "${1}"
175 return 0
176}
177#
Andrew McRae0809eb52020-06-18 00:13:36 +1000178# Validate arguments
179#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000180if [[ -z "${FLAGS_board}" ]]; then
181 die "-b or --board required."
182fi
183if [[ -z "${FLAGS_release}" ]]; then
184 die "-r or --release required."
Andrew McRae0809eb52020-06-18 00:13:36 +1000185fi
186#
187# Program must exist as a directory
188#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000189PROGDIR="${GCLIENT_ROOT}/src/program/${FLAGS_board}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000190if [[ ! -d "${PROGDIR}" ]]; then
Andrew McRae7c9655c2020-06-22 15:09:54 +1000191 die "${FLAGS_board} is not a valid program (${PROGDIR} missing)"
Andrew McRae0809eb52020-06-18 00:13:36 +1000192fi
Andrew McRaeb46a3362020-07-16 12:12:18 +1000193#
194# Validate release
195# Major must be a 5 digit number
196# Optional minor release must be a number.
197#
198if [[ "${FLAGS_release}" =~ ^${MAJOR_RE}$ ]]; then
199 MAJOR_VERSION=${FLAGS_release}
200 MINOR_VERSION="0"
201elif [[ "${FLAGS_release}" =~ ^${MAJOR_RE}\.${MINOR_RE}$ ]]; then
202 MAJOR_VERSION=$(echo "${FLAGS_release}" | cut -d. -f1)
203 MINOR_VERSION=$(echo "${FLAGS_release}" | cut -d. -f2)
204else
205 die "Unknown release format (must be NNNNN[.n])"
Andrew McRae0809eb52020-06-18 00:13:36 +1000206fi
Andrew McRaeb46a3362020-07-16 12:12:18 +1000207NEW_MAJOR="${MAJOR_PREFIX}${MAJOR_VERSION}"
208NEW_MINOR="${MINOR_PREFIX}${MINOR_VERSION}"
Andrew McRaef96cd602020-06-23 23:06:19 +1000209# Use a common git branch name.
Andrew McRaeb46a3362020-07-16 12:12:18 +1000210BRANCH="update_${FLAGS_board}_fw_${MAJOR_VERSION}_${MINOR_VERSION}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000211#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000212# Build the project list.
Andrew McRaef96cd602020-06-23 23:06:19 +1000213# If no projects are specified, use all in the programs directory.
Andrew McRae0809eb52020-06-18 00:13:36 +1000214#
Andrew McRaef96cd602020-06-23 23:06:19 +1000215if [[ -z "${FLAGS_project}" ]]; then
Andrew McRae7c9655c2020-06-22 15:09:54 +1000216 BDIR="${GCLIENT_ROOT}/src/project/${FLAGS_board}"
Andrew McRaef96cd602020-06-23 23:06:19 +1000217 cd "${BDIR}"
218 mapfile -t PROJLIST < <(ls)
219else
220 IFS=',' read -r -a PROJLIST <<< "${FLAGS_project}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000221fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000222#
Andrew McRaef96cd602020-06-23 23:06:19 +1000223# Filter out the projects that are to be skipped.
224#
225if [[ -n "${FLAGS_skip}" ]]; then
226 PROJECTS=()
227 IFS=',' read -r -a SKIP_ARRAY <<< "${FLAGS_skip}"
Andrew McRae88eda242020-06-26 12:35:55 +1000228 # Validate skipped projects
229 for S in "${SKIP_ARRAY[@]}"; do
230 check_project "${S}"
231 done
Andrew McRaef96cd602020-06-23 23:06:19 +1000232 SKIPPED="${SKIP_ARRAY[*]}"
233 for P in "${PROJLIST[@]}"; do
234 if ! (in_list "${P}" "${SKIPPED}"); then
235 PROJECTS+=("${P}")
236 fi
237 done
238else
239 PROJECTS=("${PROJLIST[@]}")
240fi
241#
Andrew McRae88eda242020-06-26 12:35:55 +1000242# Valid bug number (if any).
243# Must be of the form b:nnnnn or chromium:nnnnn
244#
245if [[ "${FLAGS_bug}" != "none" ]]; then
246 BG="b:[0-9]+|chromium:[0-9]+"
247 BGRE="^(${BG})(,(${BG}))*$"
248 if [[ ! "${FLAGS_bug}" =~ ${BGRE} ]]; then
249 echo "Bug must be of the form b:nnn or chromium:nnn"
250 die "A comma separated list is allowed"
251 fi
252fi
253#
Andrew McRaef96cd602020-06-23 23:06:19 +1000254# Validate project list and file locations.
Andrew McRae7c9655c2020-06-22 15:09:54 +1000255#
256for P in "${PROJECTS[@]}"; do
Andrew McRae88eda242020-06-26 12:35:55 +1000257 check_project "${P}"
Andrew McRae7c9655c2020-06-22 15:09:54 +1000258done
Andrew McRaef96cd602020-06-23 23:06:19 +1000259OVERLAY="${GCLIENT_ROOT}/src/private-overlays/overlay-${FLAGS_board}-private/chromeos-base/chromeos-firmware-${FLAGS_board}"
Andrew McRae88eda242020-06-26 12:35:55 +1000260# Validate project overlay and ebuild file
Andrew McRaef96cd602020-06-23 23:06:19 +1000261EB9999="chromeos-firmware-${FLAGS_board}-9999.ebuild"
262if [[ ! -f "${OVERLAY}/${EB9999}" ]]; then
Andrew McRae88eda242020-06-26 12:35:55 +1000263 die "${OVERLAY}/${EB9999}: overlay error"
Andrew McRaef96cd602020-06-23 23:06:19 +1000264fi
265# Make sure dev/contrib is accessible
266DEVCONTRIB="${GCLIENT_ROOT}/src/platform/dev/contrib"
267if [[ ! -d "${DEVCONTRIB}" ]]; then
268 die "${DEVCONTRIB}: invalid directory"
269fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000270#
Andrew McRae88eda242020-06-26 12:35:55 +1000271# If requesting dry run, dump arguments and exit.
272#
273if [[ "${FLAGS_dryrun}" -eq "${FLAGS_TRUE}" ]]; then
274 echo "Dry run requested, invoked as:"
275 echo "${COMMAND} ${CMDARGS}"
276 echo "Program (board) to be updated: ${FLAGS_board}"
277 echo -n "Projects to be updated are: "
278 for PROJ in "${PROJECTS[@]}"; do
279 echo -n " ${PROJ}"
280 done
281 if [[ -n "${SKIPPED}" ]]; then
282 echo -n " (skipped:"
283 for S in "${SKIPPED[@]}"; do
284 echo -n " ${S}"
285 done
286 echo -n ")"
287 fi
288 echo
289 echo "Release number of upgrade: ${FLAGS_release}"
Andrew McRaeb46a3362020-07-16 12:12:18 +1000290 echo "Major version of release: ${MAJOR_VERSION}"
291 echo "Minor version of release: ${MINOR_VERSION}"
Andrew McRae88eda242020-06-26 12:35:55 +1000292 echo "BUG string used in commit: ${FLAGS_bug}"
293 echo "TEST string used in commit: ${FLAGS_test}"
294 echo "Reviewer assigned to CLs: ${FLAGS_reviewer:-None}"
295 echo -n "Coreboot build enabled: "
296 if [[ "${FLAGS_build}" -eq "${FLAGS_FALSE}" ]]; then
297 echo "no"
298 else
299 echo "yes"
300 fi
301 echo "repo branch to be used is: ${BRANCH}"
302 exit 0
303fi
304if [[ "${FLAGS_build}" -eq "${FLAGS_FALSE}" ]]; then
305 echo
306 echo "******************************************"
307 echo "* You have elected not to build coreboot *"
308 echo "* This assumes coreboot is already built *"
309 echo "******************************************"
310 echo
311fi
312#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000313# Create a temp directory.
314TEMPDIR=$(mktemp -d -t fw-XXXXXXXXXX)
Andrew McRae7c9655c2020-06-22 15:09:54 +1000315
316trap "exit 1" HUP INT PIPE QUIT TERM
317trap 'cleanup' EXIT
318
Andrew McRae0809eb52020-06-18 00:13:36 +1000319#
Andrew McRae0809eb52020-06-18 00:13:36 +1000320# From now on, all errors should invoke 'abort'
Andrew McRae7c9655c2020-06-22 15:09:54 +1000321# so that the branches and CLs are cleaned up on exit.
Andrew McRae0809eb52020-06-18 00:13:36 +1000322#
Andrew McRae88eda242020-06-26 12:35:55 +1000323# If required, update the firmware version in the program's program.star file
Andrew McRae0809eb52020-06-18 00:13:36 +1000324#
Andrew McRae88eda242020-06-26 12:35:55 +1000325if [[ "${FLAGS_program}" -eq "${FLAGS_TRUE}" ]]; then
326 cd "${PROGDIR}"
327 echo "Updating program.star for board ${FLAGS_board}"
328 branch
329 if (update_version "program.star") ;then
330 #
331 # If config has changed, create a CL.
332 #
333 git add .
334 git commit -q -F - <<EOF
335${FLAGS_board}: Update program firmware to ${FLAGS_release}
Andrew McRae0809eb52020-06-18 00:13:36 +1000336
Andrew McRae88eda242020-06-26 12:35:55 +1000337Autogenerated by:
338${COMMAND} ${CMDARGS}
Andrew McRae3b94aaf2020-06-25 15:28:18 +1000339
340BUG=${FLAGS_bug}
Andrew McRae88eda242020-06-26 12:35:55 +1000341TEST=${FLAGS_test}
Andrew McRae0809eb52020-06-18 00:13:36 +1000342EOF
Andrew McRae88eda242020-06-26 12:35:55 +1000343 if ! repo upload -y "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.output" 2>&1 ;then
344 cat "${TEMPDIR}/upload.output"
345 abort "repo upload failed"
346 fi
347 PROGRAM_CL=$(getcl "program/${FLAGS_board}" "${TEMPDIR}/upload.output")
Andrew McRaef96cd602020-06-23 23:06:19 +1000348 fi
Andrew McRae0809eb52020-06-18 00:13:36 +1000349fi
350#
Andrew McRae88eda242020-06-26 12:35:55 +1000351# Now walk through the projects and update the version (if present)
352# and regenerate the configs.
Andrew McRae0809eb52020-06-18 00:13:36 +1000353# Create and upload a CL and capture the CL number and project directory
354# if the project has changed.
355#
356PROJ_CLS=()
357PROJ_DIRS=()
Andrew McRae7c9655c2020-06-22 15:09:54 +1000358for PROJ in "${PROJECTS[@]}"; do
359 echo "Updating configs for project ${PROJ}"
360 PDIR="${GCLIENT_ROOT}/src/project/${FLAGS_board}/${PROJ}"
Andrew McRaef96cd602020-06-23 23:06:19 +1000361 cd "${PDIR}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000362 branch
Andrew McRae88eda242020-06-26 12:35:55 +1000363 update_version "config.star" || true
Andrew McRae0809eb52020-06-18 00:13:36 +1000364 ./config.star || abort "Generate config failed for ${PROJ}"
365 check_config > "${TEMPDIR}/check_config-${PROJ}.output" || abort "check_config failed for ${PROJ}"
366 #
367 # Check if any files changed.
368 #
369 if changed; then
Andrew McRaef96cd602020-06-23 23:06:19 +1000370 echo "Creating CL for changes to project ${PROJ}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000371 git add .
Andrew McRaef96cd602020-06-23 23:06:19 +1000372 git commit -q -F - <<EOF
Andrew McRae7c9655c2020-06-22 15:09:54 +1000373${PROJ}: Update firmware to ${FLAGS_release}
Andrew McRaef96cd602020-06-23 23:06:19 +1000374
Andrew McRae88eda242020-06-26 12:35:55 +1000375Autogenerated by:
376${COMMAND} ${CMDARGS}
Andrew McRae3b94aaf2020-06-25 15:28:18 +1000377
378BUG=${FLAGS_bug}
Andrew McRae88eda242020-06-26 12:35:55 +1000379TEST=${FLAGS_test}
Andrew McRae0809eb52020-06-18 00:13:36 +1000380EOF
Andrew McRaef96cd602020-06-23 23:06:19 +1000381 if ! repo upload -y "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.${PROJ}.output" 2>&1 ;then
382 cat "${TEMPDIR}/upload.${PROJ}.output"
383 abort "repo upload failed"
384 fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000385 P_CL=$(getcl "project/${FLAGS_board}/${PROJ}" "${TEMPDIR}/upload.${PROJ}.output")
Andrew McRae0809eb52020-06-18 00:13:36 +1000386 PROJ_CLS+=("${P_CL}")
387 PROJ_DIRS+=("${PDIR}")
388 fi
389done
390#
391# Create a Cq-Depend line with all the project CLs
392#
393if [[ -n "${PROJ_CLS[*]}" ]];then
394 SEP=" "
395 PROG_CQD="Cq-Depend:"
396 for CL in "${PROJ_CLS[@]}"; do
397 PROG_CQD="${PROG_CQD}${SEP}chrome-internal:${CL}"
398 SEP=", "
399 done
400 #
Andrew McRaef96cd602020-06-23 23:06:19 +1000401 # If a program CL exists, add the Cq-Depend line to it.
Andrew McRae0809eb52020-06-18 00:13:36 +1000402 #
Andrew McRaef96cd602020-06-23 23:06:19 +1000403 if [[ -n "${PROGRAM_CL}" ]]; then
404 cd "${PROGDIR}"
405 amend "${PROG_CQD}"
406 if ! repo upload -y "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.amend.output" 2>&1 ;then
407 cat "${TEMPDIR}/upload.amend.output"
408 abort "repo upload failed"
409 fi
410 fi
Andrew McRae0809eb52020-06-18 00:13:36 +1000411fi
412#
413# All the boxster configs have been uploaded.
414# Now run the update script and update the firmware manifest.
415#
416# Build base coreboot files
Andrew McRae0809eb52020-06-18 00:13:36 +1000417#
Andrew McRae88eda242020-06-26 12:35:55 +1000418if [[ "${FLAGS_build}" -eq "${FLAGS_TRUE}" ]]; then
419 echo "Running coreboot build. This may take a while..."
420 #
421 # Attempt to customise the coreboot build depending on the platform.
422 #
423 case "${FLAGS_board}" in
424 "zork")
425 PACKAGES=(coreboot-zork chromeos-bootimage)
426 ;;
427 "puff")
428 PACKAGES=(chromeos-ec coreboot depthcharge vboot_reference libpayload chromeos-bootimage coreboot-private-files intel-cmlfsp coreboot-private-files-puff)
429 ;;
430 *)
431 # Use general packages
432 echo "Taking a guess at coreboot packages for ${FLAGS_board}"
433 echo "If the coreboot build fails, this script may have to be customized for this board"
434 PACKAGES=(coreboot depthcharge vboot_reference libpayload chromeos-bootimage)
435 ;;
436 esac
Andrew McRae94639642020-07-14 17:14:04 +1000437 if ! ("emerge-${FLAGS_board}" -j --quiet-build "${PACKAGES[@]}"); then
Andrew McRae88eda242020-06-26 12:35:55 +1000438 abort "coreboot build failed!"
439 fi
440 echo "coreboot build successful"
441else
442 echo "Coreboot build not attempted"
Andrew McRae0809eb52020-06-18 00:13:36 +1000443fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000444EB9999="chromeos-firmware-${FLAGS_board}-9999.ebuild"
Andrew McRae0809eb52020-06-18 00:13:36 +1000445#
446# Remove any previous attempts to build the firmware.
447#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000448"cros_workon-${FLAGS_board}" stop "chromeos-base/chromeos-firmware-${FLAGS_board}"
449"cros_workon-${FLAGS_board}" stop "chromeos-base/chromeos-config-bsp-${FLAGS_board}-private"
Andrew McRaef96cd602020-06-23 23:06:19 +1000450cd "${OVERLAY}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000451branch
Andrew McRaef96cd602020-06-23 23:06:19 +1000452cd "${DEVCONTRIB}"
Andrew McRae7c9655c2020-06-22 15:09:54 +1000453if ! (./cros_update_firmware -q "--board=${FLAGS_board}"); then
454 abort "cros_update_firmware failed for ${FLAGS_board}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000455fi
Andrew McRaef96cd602020-06-23 23:06:19 +1000456cd "${OVERLAY}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000457#
458# If files have been updated, then create a CL for the changes.
459#
460OVERLAY_CL=""
461if changed; then
462 #
463 # Bump the version in the ebuild file. Relies on the format
464 # of the version so that the last number is at the end of the line.
465 #
466 CURVERS=$(grep "VERSION=REVBUMP" "${EB9999}" | grep -o "[0-9][0-9]*$")
467 NEXTVERS=$((CURVERS + 1))
Andrew McRaef96cd602020-06-23 23:06:19 +1000468 sed -i "/VERSION=REVBUMP/s/${CURVERS}$/${NEXTVERS}/" "${EB9999}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000469 git add .
Andrew McRaef96cd602020-06-23 23:06:19 +1000470 git commit -q -F - <<EOF
Andrew McRae7c9655c2020-06-22 15:09:54 +1000471${FLAGS_board}: Update firmware to ${FLAGS_release}
Andrew McRae0809eb52020-06-18 00:13:36 +1000472
Andrew McRae88eda242020-06-26 12:35:55 +1000473Autogenerated by:
474${COMMAND} ${CMDARGS}
Andrew McRae3b94aaf2020-06-25 15:28:18 +1000475
476BUG=${FLAGS_bug}
Andrew McRae88eda242020-06-26 12:35:55 +1000477TEST=${FLAGS_test}
Andrew McRae0809eb52020-06-18 00:13:36 +1000478
Andrew McRaef96cd602020-06-23 23:06:19 +1000479${PROG_CQD}
Andrew McRae0809eb52020-06-18 00:13:36 +1000480EOF
481 #
482 # Upload with no-verify since the file lines are too long.
483 #
Andrew McRaef96cd602020-06-23 23:06:19 +1000484 if ! repo upload "--ht=${BRANCH}" -y --no-verify --cbr . > "${TEMPDIR}/overlay.output" 2>&1 ;then
485 cat "${TEMPDIR}/overlay.output"
486 abort "repo upload failed"
487 fi
Andrew McRae7c9655c2020-06-22 15:09:54 +1000488 OVERLAY_CL=$(getcl "overlays/overlay-${FLAGS_board}-private" "${TEMPDIR}/overlay.output")
Andrew McRae0809eb52020-06-18 00:13:36 +1000489 #
490 # Go back and amend all the project commit messages with a Cq-Depend on
491 # the program and overlay CLs.
492 #
493 CQD="Cq-Depend: chrome-internal:${OVERLAY_CL}"
494 if [[ -n "${PROGRAM_CL}" ]]; then
495 CQD="${CQD}, chrome-internal:${PROGRAM_CL}"
496 fi
497 for DIR in "${PROJ_DIRS[@]}"; do
Andrew McRaef96cd602020-06-23 23:06:19 +1000498 cd "${DIR}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000499 amend "${CQD}"
Andrew McRaef96cd602020-06-23 23:06:19 +1000500 if ! repo upload -y --cbr . > "${TEMPDIR}/cqd.output" 2>&1 ;then
501 cat "${TEMPDIR}/cqd.output"
502 abort "repo upload failed"
503 fi
Andrew McRae0809eb52020-06-18 00:13:36 +1000504 done
505fi
506#
507# Send all of the CLs to the CQ for a dry run.
508#
509ALL_CLS=$(gerrit -i --raw search "owner:me status:open hashtag:${BRANCH}")
510if [[ -z "${ALL_CLS}" ]]; then
Andrew McRae7c9655c2020-06-22 15:09:54 +1000511 echo "No changes required for program ${FLAGS_board}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000512 repo abandon "${BRANCH}"
513 exit 0
514fi
515for cl in ${ALL_CLS}; do
516 gerrit -i label-cq "${cl}" 1
517 gerrit -i label-v "${cl}" 1
518 gerrit -i label-as "${cl}" 1
519done
520#
521# If reviewer is set, then add them to the CLs
522#
Andrew McRae7c9655c2020-06-22 15:09:54 +1000523if [[ -n "${FLAGS_reviewer}" ]]; then
524 echo "Sending CLs ${ALL_CLS} to ${FLAGS_reviewer} for review"
Andrew McRae0809eb52020-06-18 00:13:36 +1000525 for cl in ${ALL_CLS}; do
Andrew McRae7c9655c2020-06-22 15:09:54 +1000526 gerrit -i reviewers "${cl}" "${FLAGS_reviewer}"
Andrew McRae0809eb52020-06-18 00:13:36 +1000527 done
528else
529 echo "Send CLs for review by running:"
530 echo " for cl in ${ALL_CLS}; do gerrit -i reviewers \$cl <reviewer>; done"
531fi
532#
533# Final instructions.
534#
535echo "Run:"
Andrew McRae7c9655c2020-06-22 15:09:54 +1000536echo " /build/${FLAGS_board}/usr/sbin/chromeos-firmwareupdate --manifest"
Andrew McRae0809eb52020-06-18 00:13:36 +1000537echo "to verify firmware update"
538echo "When submitted, cleanup by running:"
539echo "repo abandon ${BRANCH}"