Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 1 | #!/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 McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 6 | # 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 McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 12 | # ./update_program_fw --board=program --release=NNNNN [ --reviewer=reviewer ] |
| 13 | # [ --project=proj... ] |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 14 | # E.g: |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 15 | # ./update_program_fw --board=puff --release=13291 --reviewer=amcrae@google.com |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 16 | # |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 17 | # TODO: |
| 18 | # - Handle minor version |
| 19 | # |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 20 | CONTRIB_DIR=$(dirname "$(readlink -f "$0")") |
| 21 | . "${CONTRIB_DIR}/common.sh" || exit 1 |
| 22 | |
| 23 | FLAGS_HELP=" |
| 24 | Command to update the firmware version for a board. |
| 25 | |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 26 | Updates the firmware version configuration for a board's |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 27 | master configuration (program.star) and for selected projects |
| 28 | that include the master configuration. |
| 29 | |
| 30 | If no projects are specified, all projects for that board are selected. |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 31 | An optional skip list can be specified to skip selected boards. |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 32 | |
| 33 | The configurations for the selected projects are regenerated, |
| 34 | and the firmware manifest are updated for the projects. |
| 35 | |
| 36 | The necessary CLs for these changes are created and uploaded for review. |
| 37 | An optional reviewer can be specified to send all the CLs to. |
| 38 | " |
| 39 | # Flags |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 40 | DEFINE_string board "${DEFAULT_BOARD}" "Which board (program) the firmware is for (e.g 'puff')" b |
| 41 | DEFINE_integer release 0 "The firmware release to update to (e.g 13310)" r |
| 42 | DEFINE_string project "${DEFAULT_PROJECT}" "Which projects this release is for (defaults to all), e.g 'duffy'" p |
Andrew McRae | 3b94aaf | 2020-06-25 15:28:18 +1000 | [diff] [blame] | 43 | DEFINE_string bug "none" "The bug to reference in the CL e.g b:12345" |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 44 | DEFINE_string skip "${DEFAULT_SKIP}" "Skip these projects (comma separated list)" s |
| 45 | DEFINE_boolean build "${FLAGS_TRUE}" "Attempt to build coreboot" |
| 46 | DEFINE_boolean program "${FLAGS_TRUE}" "Update the version in the base program.star" |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 47 | DEFINE_string reviewer "${DEFAULT_REVIEWER}" "The reviewer to send the CLs to (optional)" |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 48 | DEFINE_string test "none" "The 'TEST=' string added to the commit message" |
| 49 | DEFINE_boolean dryrun "${FLAGS_FALSE}" "Do not perform any actions, just validate and print arguments" |
| 50 | |
| 51 | # Set before flag processing |
| 52 | COMMAND=$(basename "$0") |
| 53 | CMDARGS="$*" |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 54 | |
| 55 | # Parse command line |
| 56 | FLAGS "$@" || exit 1 |
| 57 | eval set -- "${FLAGS_ARGV}" |
| 58 | set -e |
| 59 | |
| 60 | # Script must be run inside the chroot. |
| 61 | assert_inside_chroot |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 62 | # |
| 63 | # Variables |
| 64 | # |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 65 | PATH="${PATH}:${GCLIENT_ROOT}/src/config/bin" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 66 | DIGITS="[1-9][0-9][0-9][0-9][0-9]" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 67 | BRANCH="" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 68 | PROGRAM_CL="" |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 69 | MAJORV=" major_version = " |
| 70 | ANY_MV="${MAJORV}${DIGITS}" |
| 71 | NEW_MV="${MAJORV}${FLAGS_release}" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 72 | # |
| 73 | # Common functions |
| 74 | # |
| 75 | cleanup() { |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 76 | if [[ -d "${TEMPDIR}" ]]; then |
| 77 | rm -rf "${TEMPDIR}" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 78 | fi |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 79 | } |
| 80 | # |
| 81 | # Abort the update, and clean up branches and CLs |
| 82 | # |
| 83 | abort() { |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 84 | CLS=$(gerrit -i --raw search "owner:me status:open hashtag:${BRANCH}") |
| 85 | if [[ -n "${CLS}" ]]; then |
| 86 | echo "Abandoning uploaded CLs" |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 87 | for cl in ${CLS}; do |
| 88 | gerrit -i abandon "${cl}" |
| 89 | done |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 90 | fi |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 91 | "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 McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 93 | repo abandon "${BRANCH}" |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 94 | die "$*" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 95 | } |
| 96 | # |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 97 | # Extract a CL number from the file containing the output of repo upload |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 98 | # |
| 99 | getcl() { |
| 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 | # |
| 110 | branch() { |
| 111 | if ! (git branch --show-current | grep -q "${BRANCH}"); then |
| 112 | repo start "${BRANCH}" |
| 113 | else |
| 114 | echo "${BRANCH} already exists, skipping repo start" |
| 115 | fi |
| 116 | } |
| 117 | # |
| 118 | # Return true if repo has changes. |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 119 | # |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 120 | changed() { |
| 121 | [[ -n $(git status -s) ]] |
| 122 | } |
| 123 | # |
| 124 | # Add a Cq-Depend line to a commit. |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 125 | # |
| 126 | amend() { |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 127 | git log -1 --pretty=%B > "${TEMPDIR}/amend-msg" |
| 128 | sed -i "/^Change-Id/ i ${1}" "${TEMPDIR}/amend-msg" |
| 129 | git commit -q --amend -F "${TEMPDIR}/amend-msg" |
| 130 | } |
| 131 | # |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 132 | # Confirm that $1 is a valid project |
| 133 | # |
| 134 | check_project() { |
| 135 | PDIR="${GCLIENT_ROOT}/src/project/${FLAGS_board}/${1}" |
| 136 | if [[ ! -d "${PDIR}" ]]; then |
| 137 | die "${P} is not a valid project (${PDIR} missing)" |
| 138 | fi |
| 139 | } |
| 140 | # |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 141 | # Return true if $1 is in list $2 |
| 142 | # |
| 143 | in_list() { |
| 144 | for S in ${2}; do |
| 145 | if [[ "$1" == "${S}" ]]; then |
| 146 | return 0 |
| 147 | fi |
| 148 | done |
| 149 | return 1 |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 150 | } |
| 151 | # |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 152 | # Return 0 if file has version in it. |
| 153 | # |
| 154 | has_version() { |
| 155 | (grep -q "${ANY_MV}" "${1}") |
| 156 | } |
| 157 | # |
| 158 | # Update the major version in the file passed. |
| 159 | # return 0 if version updated. |
| 160 | # return 1 if version not in file, or unchanged. |
| 161 | # |
| 162 | update_version() { |
| 163 | # Check for major_version in file. |
| 164 | if ! (has_version "${1}") ;then |
| 165 | return 1 |
| 166 | fi |
| 167 | local nf="${TEMPDIR}/new-${1}" |
| 168 | sed "/${ANY_MV}/s/${ANY_MV}/${NEW_MV}/" "${1}" > "${nf}" |
| 169 | # |
| 170 | # Verify that only 1-5 characters have changed. |
| 171 | # |
| 172 | DIFF=$(cmp -l "${1}" "${nf}" | wc -l) |
| 173 | if [[ "${DIFF}" -gt 5 ]]; then |
| 174 | diff "${1}" "{nf}}" |
| 175 | abort "${1} update error" |
| 176 | fi |
| 177 | if [[ "${DIFF}" == 0 ]]; then |
| 178 | return 1 |
| 179 | fi |
| 180 | cp "${nf}" "${1}" |
| 181 | return 0 |
| 182 | } |
| 183 | # |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 184 | # Validate arguments |
| 185 | # |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 186 | if [[ -z "${FLAGS_board}" ]]; then |
| 187 | die "-b or --board required." |
| 188 | fi |
| 189 | if [[ -z "${FLAGS_release}" ]]; then |
| 190 | die "-r or --release required." |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 191 | fi |
| 192 | # |
| 193 | # Program must exist as a directory |
| 194 | # |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 195 | PROGDIR="${GCLIENT_ROOT}/src/program/${FLAGS_board}" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 196 | if [[ ! -d "${PROGDIR}" ]]; then |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 197 | die "${FLAGS_board} is not a valid program (${PROGDIR} missing)" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 198 | fi |
| 199 | # Release must be a 5 digit number |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 200 | if [[ ! "${FLAGS_release}" =~ ^${DIGITS}$ ]]; then |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 201 | die "release must be a 5 digit number" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 202 | fi |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 203 | # Use a common git branch name. |
| 204 | BRANCH="update_${FLAGS_board}_fw_${FLAGS_release}" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 205 | # |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 206 | # Build the project list. |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 207 | # If no projects are specified, use all in the programs directory. |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 208 | # |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 209 | if [[ -z "${FLAGS_project}" ]]; then |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 210 | BDIR="${GCLIENT_ROOT}/src/project/${FLAGS_board}" |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 211 | cd "${BDIR}" |
| 212 | mapfile -t PROJLIST < <(ls) |
| 213 | else |
| 214 | IFS=',' read -r -a PROJLIST <<< "${FLAGS_project}" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 215 | fi |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 216 | # |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 217 | # Filter out the projects that are to be skipped. |
| 218 | # |
| 219 | if [[ -n "${FLAGS_skip}" ]]; then |
| 220 | PROJECTS=() |
| 221 | IFS=',' read -r -a SKIP_ARRAY <<< "${FLAGS_skip}" |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 222 | # Validate skipped projects |
| 223 | for S in "${SKIP_ARRAY[@]}"; do |
| 224 | check_project "${S}" |
| 225 | done |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 226 | SKIPPED="${SKIP_ARRAY[*]}" |
| 227 | for P in "${PROJLIST[@]}"; do |
| 228 | if ! (in_list "${P}" "${SKIPPED}"); then |
| 229 | PROJECTS+=("${P}") |
| 230 | fi |
| 231 | done |
| 232 | else |
| 233 | PROJECTS=("${PROJLIST[@]}") |
| 234 | fi |
| 235 | # |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 236 | # Valid bug number (if any). |
| 237 | # Must be of the form b:nnnnn or chromium:nnnnn |
| 238 | # |
| 239 | if [[ "${FLAGS_bug}" != "none" ]]; then |
| 240 | BG="b:[0-9]+|chromium:[0-9]+" |
| 241 | BGRE="^(${BG})(,(${BG}))*$" |
| 242 | if [[ ! "${FLAGS_bug}" =~ ${BGRE} ]]; then |
| 243 | echo "Bug must be of the form b:nnn or chromium:nnn" |
| 244 | die "A comma separated list is allowed" |
| 245 | fi |
| 246 | fi |
| 247 | # |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 248 | # Validate project list and file locations. |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 249 | # |
| 250 | for P in "${PROJECTS[@]}"; do |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 251 | check_project "${P}" |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 252 | done |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 253 | OVERLAY="${GCLIENT_ROOT}/src/private-overlays/overlay-${FLAGS_board}-private/chromeos-base/chromeos-firmware-${FLAGS_board}" |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 254 | # Validate project overlay and ebuild file |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 255 | EB9999="chromeos-firmware-${FLAGS_board}-9999.ebuild" |
| 256 | if [[ ! -f "${OVERLAY}/${EB9999}" ]]; then |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 257 | die "${OVERLAY}/${EB9999}: overlay error" |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 258 | fi |
| 259 | # Make sure dev/contrib is accessible |
| 260 | DEVCONTRIB="${GCLIENT_ROOT}/src/platform/dev/contrib" |
| 261 | if [[ ! -d "${DEVCONTRIB}" ]]; then |
| 262 | die "${DEVCONTRIB}: invalid directory" |
| 263 | fi |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 264 | # |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 265 | # If requesting dry run, dump arguments and exit. |
| 266 | # |
| 267 | if [[ "${FLAGS_dryrun}" -eq "${FLAGS_TRUE}" ]]; then |
| 268 | echo "Dry run requested, invoked as:" |
| 269 | echo "${COMMAND} ${CMDARGS}" |
| 270 | echo "Program (board) to be updated: ${FLAGS_board}" |
| 271 | echo -n "Projects to be updated are: " |
| 272 | for PROJ in "${PROJECTS[@]}"; do |
| 273 | echo -n " ${PROJ}" |
| 274 | done |
| 275 | if [[ -n "${SKIPPED}" ]]; then |
| 276 | echo -n " (skipped:" |
| 277 | for S in "${SKIPPED[@]}"; do |
| 278 | echo -n " ${S}" |
| 279 | done |
| 280 | echo -n ")" |
| 281 | fi |
| 282 | echo |
| 283 | echo "Release number of upgrade: ${FLAGS_release}" |
| 284 | echo "BUG string used in commit: ${FLAGS_bug}" |
| 285 | echo "TEST string used in commit: ${FLAGS_test}" |
| 286 | echo "Reviewer assigned to CLs: ${FLAGS_reviewer:-None}" |
| 287 | echo -n "Coreboot build enabled: " |
| 288 | if [[ "${FLAGS_build}" -eq "${FLAGS_FALSE}" ]]; then |
| 289 | echo "no" |
| 290 | else |
| 291 | echo "yes" |
| 292 | fi |
| 293 | echo "repo branch to be used is: ${BRANCH}" |
| 294 | exit 0 |
| 295 | fi |
| 296 | if [[ "${FLAGS_build}" -eq "${FLAGS_FALSE}" ]]; then |
| 297 | echo |
| 298 | echo "******************************************" |
| 299 | echo "* You have elected not to build coreboot *" |
| 300 | echo "* This assumes coreboot is already built *" |
| 301 | echo "******************************************" |
| 302 | echo |
| 303 | fi |
| 304 | # |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 305 | # Create a temp directory. |
| 306 | TEMPDIR=$(mktemp -d -t fw-XXXXXXXXXX) |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 307 | |
| 308 | trap "exit 1" HUP INT PIPE QUIT TERM |
| 309 | trap 'cleanup' EXIT |
| 310 | |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 311 | # |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 312 | # From now on, all errors should invoke 'abort' |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 313 | # so that the branches and CLs are cleaned up on exit. |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 314 | # |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 315 | # If required, update the firmware version in the program's program.star file |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 316 | # |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 317 | if [[ "${FLAGS_program}" -eq "${FLAGS_TRUE}" ]]; then |
| 318 | cd "${PROGDIR}" |
| 319 | echo "Updating program.star for board ${FLAGS_board}" |
| 320 | branch |
| 321 | if (update_version "program.star") ;then |
| 322 | # |
| 323 | # If config has changed, create a CL. |
| 324 | # |
| 325 | git add . |
| 326 | git commit -q -F - <<EOF |
| 327 | ${FLAGS_board}: Update program firmware to ${FLAGS_release} |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 328 | |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 329 | Autogenerated by: |
| 330 | ${COMMAND} ${CMDARGS} |
Andrew McRae | 3b94aaf | 2020-06-25 15:28:18 +1000 | [diff] [blame] | 331 | |
| 332 | BUG=${FLAGS_bug} |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 333 | TEST=${FLAGS_test} |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 334 | EOF |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 335 | if ! repo upload -y "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.output" 2>&1 ;then |
| 336 | cat "${TEMPDIR}/upload.output" |
| 337 | abort "repo upload failed" |
| 338 | fi |
| 339 | PROGRAM_CL=$(getcl "program/${FLAGS_board}" "${TEMPDIR}/upload.output") |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 340 | fi |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 341 | fi |
| 342 | # |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 343 | # Now walk through the projects and update the version (if present) |
| 344 | # and regenerate the configs. |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 345 | # Create and upload a CL and capture the CL number and project directory |
| 346 | # if the project has changed. |
| 347 | # |
| 348 | PROJ_CLS=() |
| 349 | PROJ_DIRS=() |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 350 | for PROJ in "${PROJECTS[@]}"; do |
| 351 | echo "Updating configs for project ${PROJ}" |
| 352 | PDIR="${GCLIENT_ROOT}/src/project/${FLAGS_board}/${PROJ}" |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 353 | cd "${PDIR}" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 354 | branch |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 355 | update_version "config.star" || true |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 356 | ./config.star || abort "Generate config failed for ${PROJ}" |
| 357 | check_config > "${TEMPDIR}/check_config-${PROJ}.output" || abort "check_config failed for ${PROJ}" |
| 358 | # |
| 359 | # Check if any files changed. |
| 360 | # |
| 361 | if changed; then |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 362 | echo "Creating CL for changes to project ${PROJ}" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 363 | git add . |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 364 | git commit -q -F - <<EOF |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 365 | ${PROJ}: Update firmware to ${FLAGS_release} |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 366 | |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 367 | Autogenerated by: |
| 368 | ${COMMAND} ${CMDARGS} |
Andrew McRae | 3b94aaf | 2020-06-25 15:28:18 +1000 | [diff] [blame] | 369 | |
| 370 | BUG=${FLAGS_bug} |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 371 | TEST=${FLAGS_test} |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 372 | EOF |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 373 | if ! repo upload -y "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.${PROJ}.output" 2>&1 ;then |
| 374 | cat "${TEMPDIR}/upload.${PROJ}.output" |
| 375 | abort "repo upload failed" |
| 376 | fi |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 377 | P_CL=$(getcl "project/${FLAGS_board}/${PROJ}" "${TEMPDIR}/upload.${PROJ}.output") |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 378 | PROJ_CLS+=("${P_CL}") |
| 379 | PROJ_DIRS+=("${PDIR}") |
| 380 | fi |
| 381 | done |
| 382 | # |
| 383 | # Create a Cq-Depend line with all the project CLs |
| 384 | # |
| 385 | if [[ -n "${PROJ_CLS[*]}" ]];then |
| 386 | SEP=" " |
| 387 | PROG_CQD="Cq-Depend:" |
| 388 | for CL in "${PROJ_CLS[@]}"; do |
| 389 | PROG_CQD="${PROG_CQD}${SEP}chrome-internal:${CL}" |
| 390 | SEP=", " |
| 391 | done |
| 392 | # |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 393 | # If a program CL exists, add the Cq-Depend line to it. |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 394 | # |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 395 | if [[ -n "${PROGRAM_CL}" ]]; then |
| 396 | cd "${PROGDIR}" |
| 397 | amend "${PROG_CQD}" |
| 398 | if ! repo upload -y "--ht=${BRANCH}" --cbr . > "${TEMPDIR}/upload.amend.output" 2>&1 ;then |
| 399 | cat "${TEMPDIR}/upload.amend.output" |
| 400 | abort "repo upload failed" |
| 401 | fi |
| 402 | fi |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 403 | fi |
| 404 | # |
| 405 | # All the boxster configs have been uploaded. |
| 406 | # Now run the update script and update the firmware manifest. |
| 407 | # |
| 408 | # Build base coreboot files |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 409 | # |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 410 | if [[ "${FLAGS_build}" -eq "${FLAGS_TRUE}" ]]; then |
| 411 | echo "Running coreboot build. This may take a while..." |
| 412 | # |
| 413 | # Attempt to customise the coreboot build depending on the platform. |
| 414 | # |
| 415 | case "${FLAGS_board}" in |
| 416 | "zork") |
| 417 | PACKAGES=(coreboot-zork chromeos-bootimage) |
| 418 | ;; |
| 419 | "puff") |
| 420 | PACKAGES=(chromeos-ec coreboot depthcharge vboot_reference libpayload chromeos-bootimage coreboot-private-files intel-cmlfsp coreboot-private-files-puff) |
| 421 | ;; |
| 422 | *) |
| 423 | # Use general packages |
| 424 | echo "Taking a guess at coreboot packages for ${FLAGS_board}" |
| 425 | echo "If the coreboot build fails, this script may have to be customized for this board" |
| 426 | PACKAGES=(coreboot depthcharge vboot_reference libpayload chromeos-bootimage) |
| 427 | ;; |
| 428 | esac |
Andrew McRae | 9463964 | 2020-07-14 17:14:04 +1000 | [diff] [blame] | 429 | if ! ("emerge-${FLAGS_board}" -j --quiet-build "${PACKAGES[@]}"); then |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 430 | abort "coreboot build failed!" |
| 431 | fi |
| 432 | echo "coreboot build successful" |
| 433 | else |
| 434 | echo "Coreboot build not attempted" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 435 | fi |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 436 | EB9999="chromeos-firmware-${FLAGS_board}-9999.ebuild" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 437 | # |
| 438 | # Remove any previous attempts to build the firmware. |
| 439 | # |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 440 | "cros_workon-${FLAGS_board}" stop "chromeos-base/chromeos-firmware-${FLAGS_board}" |
| 441 | "cros_workon-${FLAGS_board}" stop "chromeos-base/chromeos-config-bsp-${FLAGS_board}-private" |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 442 | cd "${OVERLAY}" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 443 | branch |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 444 | cd "${DEVCONTRIB}" |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 445 | if ! (./cros_update_firmware -q "--board=${FLAGS_board}"); then |
| 446 | abort "cros_update_firmware failed for ${FLAGS_board}" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 447 | fi |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 448 | cd "${OVERLAY}" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 449 | # |
| 450 | # If files have been updated, then create a CL for the changes. |
| 451 | # |
| 452 | OVERLAY_CL="" |
| 453 | if changed; then |
| 454 | # |
| 455 | # Bump the version in the ebuild file. Relies on the format |
| 456 | # of the version so that the last number is at the end of the line. |
| 457 | # |
| 458 | CURVERS=$(grep "VERSION=REVBUMP" "${EB9999}" | grep -o "[0-9][0-9]*$") |
| 459 | NEXTVERS=$((CURVERS + 1)) |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 460 | sed -i "/VERSION=REVBUMP/s/${CURVERS}$/${NEXTVERS}/" "${EB9999}" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 461 | git add . |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 462 | git commit -q -F - <<EOF |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 463 | ${FLAGS_board}: Update firmware to ${FLAGS_release} |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 464 | |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 465 | Autogenerated by: |
| 466 | ${COMMAND} ${CMDARGS} |
Andrew McRae | 3b94aaf | 2020-06-25 15:28:18 +1000 | [diff] [blame] | 467 | |
| 468 | BUG=${FLAGS_bug} |
Andrew McRae | 88eda24 | 2020-06-26 12:35:55 +1000 | [diff] [blame] | 469 | TEST=${FLAGS_test} |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 470 | |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 471 | ${PROG_CQD} |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 472 | EOF |
| 473 | # |
| 474 | # Upload with no-verify since the file lines are too long. |
| 475 | # |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 476 | if ! repo upload "--ht=${BRANCH}" -y --no-verify --cbr . > "${TEMPDIR}/overlay.output" 2>&1 ;then |
| 477 | cat "${TEMPDIR}/overlay.output" |
| 478 | abort "repo upload failed" |
| 479 | fi |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 480 | OVERLAY_CL=$(getcl "overlays/overlay-${FLAGS_board}-private" "${TEMPDIR}/overlay.output") |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 481 | # |
| 482 | # Go back and amend all the project commit messages with a Cq-Depend on |
| 483 | # the program and overlay CLs. |
| 484 | # |
| 485 | CQD="Cq-Depend: chrome-internal:${OVERLAY_CL}" |
| 486 | if [[ -n "${PROGRAM_CL}" ]]; then |
| 487 | CQD="${CQD}, chrome-internal:${PROGRAM_CL}" |
| 488 | fi |
| 489 | for DIR in "${PROJ_DIRS[@]}"; do |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 490 | cd "${DIR}" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 491 | amend "${CQD}" |
Andrew McRae | f96cd60 | 2020-06-23 23:06:19 +1000 | [diff] [blame] | 492 | if ! repo upload -y --cbr . > "${TEMPDIR}/cqd.output" 2>&1 ;then |
| 493 | cat "${TEMPDIR}/cqd.output" |
| 494 | abort "repo upload failed" |
| 495 | fi |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 496 | done |
| 497 | fi |
| 498 | # |
| 499 | # Send all of the CLs to the CQ for a dry run. |
| 500 | # |
| 501 | ALL_CLS=$(gerrit -i --raw search "owner:me status:open hashtag:${BRANCH}") |
| 502 | if [[ -z "${ALL_CLS}" ]]; then |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 503 | echo "No changes required for program ${FLAGS_board}" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 504 | repo abandon "${BRANCH}" |
| 505 | exit 0 |
| 506 | fi |
| 507 | for cl in ${ALL_CLS}; do |
| 508 | gerrit -i label-cq "${cl}" 1 |
| 509 | gerrit -i label-v "${cl}" 1 |
| 510 | gerrit -i label-as "${cl}" 1 |
| 511 | done |
| 512 | # |
| 513 | # If reviewer is set, then add them to the CLs |
| 514 | # |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 515 | if [[ -n "${FLAGS_reviewer}" ]]; then |
| 516 | echo "Sending CLs ${ALL_CLS} to ${FLAGS_reviewer} for review" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 517 | for cl in ${ALL_CLS}; do |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 518 | gerrit -i reviewers "${cl}" "${FLAGS_reviewer}" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 519 | done |
| 520 | else |
| 521 | echo "Send CLs for review by running:" |
| 522 | echo " for cl in ${ALL_CLS}; do gerrit -i reviewers \$cl <reviewer>; done" |
| 523 | fi |
| 524 | # |
| 525 | # Final instructions. |
| 526 | # |
| 527 | echo "Run:" |
Andrew McRae | 7c9655c | 2020-06-22 15:09:54 +1000 | [diff] [blame] | 528 | echo " /build/${FLAGS_board}/usr/sbin/chromeos-firmwareupdate --manifest" |
Andrew McRae | 0809eb5 | 2020-06-18 00:13:36 +1000 | [diff] [blame] | 529 | echo "to verify firmware update" |
| 530 | echo "When submitted, cleanup by running:" |
| 531 | echo "repo abandon ${BRANCH}" |