Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # Copyright 2017 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 | |
| 6 | # Loads script libraries. |
| 7 | CONTRIB_DIR=$(dirname "$(readlink -f "$0")") |
| 8 | . "${CONTRIB_DIR}/common.sh" || exit 1 |
| 9 | |
| 10 | FLAGS_HELP=" |
| 11 | Command to rebuild firmware after a config change. |
| 12 | |
| 13 | After you make a change to the firmware version in the master configuration, |
| 14 | run this script to test it. It will rebuild the master configuration, update |
| 15 | the Manifest and build the new firmware. You can then submit your CL to update |
| 16 | the master configuration, safe in the knowledge that you have tested it. |
| 17 | |
| 18 | Usage: |
YH Lin | 7050ce7 | 2020-03-18 16:54:51 -0700 | [diff] [blame] | 19 | cros_update_firmware <board> [project] |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 20 | |
| 21 | where <board> is the board whose firmware needs updating (e.g. 'coral'). |
YH Lin | 7050ce7 | 2020-03-18 16:54:51 -0700 | [diff] [blame] | 22 | [project] is the project the board belongs to. |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 23 | " |
| 24 | |
| 25 | # Flags |
| 26 | DEFINE_string board "${DEFAULT_BOARD}" "Which board the firmware is for" b |
YH Lin | 7050ce7 | 2020-03-18 16:54:51 -0700 | [diff] [blame] | 27 | DEFINE_string project "${DEFAULT_PROJECT}" "Which project this board is for" p |
Andrew McRae | 3fccc99 | 2020-06-18 14:49:33 +1000 | [diff] [blame] | 28 | DEFINE_boolean quiet "${FLAGS_FALSE}" "Reduce emerge build output" q |
Andrew Lamb | feacb4c | 2020-09-23 15:00:09 -0600 | [diff] [blame] | 29 | DEFINE_boolean append_srcuris "${FLAGS_TRUE}" "Only applicable when the project |
| 30 | flag is set. Append firmware uris to srcuris instead of overwriting. This is |
| 31 | usually needed if you have limited access to project config repos, so |
| 32 | overwriting would delete some uris." |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 33 | |
| 34 | # Parse command line. |
| 35 | FLAGS "$@" || exit 1 |
| 36 | eval set -- "${FLAGS_ARGV}" |
| 37 | set -e |
| 38 | |
| 39 | # Script must be run inside the chroot. |
| 40 | assert_inside_chroot |
| 41 | |
| 42 | start_workon() { |
| 43 | local board="$1" |
| 44 | local pkg item |
| 45 | if [[ -z "$2" ]]; then |
| 46 | echo "Empty package. Skipping..." |
| 47 | return 1 |
| 48 | fi |
Andrew McRae | d26b279 | 2020-08-06 23:28:26 +1000 | [diff] [blame] | 49 | pkg=$(cros workon --board="${board}" info "$2" | cut -d ' ' -f 1) |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 50 | shift 2 |
| 51 | for item in "$@"; do |
| 52 | if [[ "${pkg}" == "${item}" ]]; then |
| 53 | echo "Already workon ${pkg}. Skipping..." |
| 54 | return 1 |
| 55 | fi |
| 56 | done |
Andrew McRae | d26b279 | 2020-08-06 23:28:26 +1000 | [diff] [blame] | 57 | cros workon --board="${board}" start "${pkg}" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 58 | return $? |
| 59 | } |
| 60 | |
| 61 | stop_workon() { |
Andrew McRae | d26b279 | 2020-08-06 23:28:26 +1000 | [diff] [blame] | 62 | cros workon --board="$1" stop "$2" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | update_firmware() { |
| 66 | local board="$1" |
YH Lin | 7050ce7 | 2020-03-18 16:54:51 -0700 | [diff] [blame] | 67 | local project="$2" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 68 | local base ebuild srcuris cfg_bsp_pkg cfg_bsp_baseboard_pkg |
Andrew McRae | 3fccc99 | 2020-06-18 14:49:33 +1000 | [diff] [blame] | 69 | local current_workon_pkg_list start_pkg result i quiet |
| 70 | [[ "$3" == "${FLAGS_TRUE}" ]] && quiet="--quiet-build" |
Andrew Lamb | feacb4c | 2020-09-23 15:00:09 -0600 | [diff] [blame] | 71 | local append_srcuris="$4" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 72 | |
| 73 | set -e |
| 74 | |
| 75 | # query the current working package |
Andrew McRae | d26b279 | 2020-08-06 23:28:26 +1000 | [diff] [blame] | 76 | mapfile -t current_workon_pkg_list < <(cros workon --board="${board}" list) |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 77 | |
| 78 | # check if chromeos-config-bsp is a virtual package |
| 79 | cfg_bsp_pkg="chromeos-config-bsp" |
| 80 | equery-"${board}" w chromeos-base/chromeos-config-bsp > /dev/null 2>&1 \ |
| 81 | || cfg_bsp_pkg="chromeos-config-bsp-${board}-private" |
| 82 | # check if chromeos-config-bsp-baseboard is in use |
| 83 | cfg_bsp_baseboard_pkg="chromeos-config-bsp-baseboard" |
| 84 | equery-"${board}" w chromeos-base/chromeos-config-bsp-baseboard \ |
| 85 | > /dev/null 2>&1 || cfg_bsp_baseboard_pkg= |
| 86 | |
| 87 | start_pkg=("${cfg_bsp_pkg}") |
| 88 | start_pkg+=("chromeos-firmware-${board}") |
| 89 | start_pkg+=("${cfg_bsp_baseboard_pkg}") |
| 90 | |
| 91 | for i in "${!start_pkg[@]}"; do |
| 92 | result[i]=0 |
| 93 | start_workon "${board}" "${start_pkg[i]}" "${current_workon_pkg_list[@]}" \ |
| 94 | || result[i]=$? |
| 95 | done |
| 96 | |
Ned Nguyen | 6d6cd60 | 2019-01-22 17:17:13 -0700 | [diff] [blame] | 97 | overlay="${GCLIENT_ROOT}/src/private-overlays/overlay-${board}-private" |
| 98 | metadata="${overlay}/metadata" |
Ned Nguyen | fc67e1f | 2019-01-31 16:06:53 -0700 | [diff] [blame] | 99 | edb_cache="/var/cache/edb/dep/mnt/host/source/src/private-overlays/overlay-${board}-private" |
Ned Nguyen | 6d6cd60 | 2019-01-22 17:17:13 -0700 | [diff] [blame] | 100 | base="${overlay}/chromeos-base" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 101 | ebuild="${base}/chromeos-firmware-${board}/chromeos-firmware-${board}-9999.ebuild" |
| 102 | srcuris="${base}/chromeos-firmware-${board}/files/srcuris" |
| 103 | yaml_config="/build/${board}/usr/share/chromeos-config/yaml/config.yaml" |
| 104 | |
YH Lin | 7050ce7 | 2020-03-18 16:54:51 -0700 | [diff] [blame] | 105 | # Check project config repo exists -- if so generate the config first. |
YH Lin | 3f600de | 2020-04-13 10:55:06 -0700 | [diff] [blame] | 106 | if [[ -d "${GCLIENT_ROOT}/src/project/${project}" ]]; then |
| 107 | pushd "${GCLIENT_ROOT}/src/project/${project}" > /dev/null |
| 108 | for brd in *; do |
| 109 | if [[ -d "${brd}" && -x "${brd}/config/bin/gen_config" && -f "${brd}/config.star" ]]; then |
| 110 | pushd "${brd}" > /dev/null |
| 111 | ./config/bin/gen_config config.star |
| 112 | popd > /dev/null |
| 113 | fi |
| 114 | done |
YH Lin | 7050ce7 | 2020-03-18 16:54:51 -0700 | [diff] [blame] | 115 | popd > /dev/null |
| 116 | fi |
| 117 | |
Yu-Ping Wu | b4b2fe8 | 2020-11-30 17:31:51 +0800 | [diff] [blame] | 118 | "emerge-${board}" -j ${quiet} ${cfg_bsp_baseboard_pkg} "${cfg_bsp_pkg}" |
| 119 | "emerge-${board}" ${quiet} chromeos-config |
Andrew Lamb | feacb4c | 2020-09-23 15:00:09 -0600 | [diff] [blame] | 120 | |
| 121 | # If the append_srcuris and project flags are set, append uris that aren't |
| 122 | # already in srcuris. Otherwise, overwrite srcuris. |
| 123 | if [[ -n "${project}" && "${append_srcuris}" == "${FLAGS_TRUE}" ]]; then |
| 124 | for uri in $(cros_config_host -c "${yaml_config}" get-firmware-uris); do |
| 125 | if ! grep -q "${uri}" "${srcuris}"; then |
| 126 | # Append uri to the last line of srcuris (srcuris should be a file with |
Andrew Lamb | bc1c80a | 2020-10-23 12:21:49 -0600 | [diff] [blame] | 127 | # one line per-uri). |
| 128 | echo "${uri}" >> "${srcuris}" |
Andrew Lamb | feacb4c | 2020-09-23 15:00:09 -0600 | [diff] [blame] | 129 | fi |
| 130 | done |
| 131 | else |
Andrew Lamb | bc1c80a | 2020-10-23 12:21:49 -0600 | [diff] [blame] | 132 | # Put each uri on its own line for easier merging in git. |
| 133 | cros_config_host -c "${yaml_config}" get-firmware-uris | tr ' ' '\n' > "${srcuris}" |
Andrew Lamb | feacb4c | 2020-09-23 15:00:09 -0600 | [diff] [blame] | 134 | fi |
| 135 | |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 136 | touch "${ebuild}" |
YH Lin | 7050ce7 | 2020-03-18 16:54:51 -0700 | [diff] [blame] | 137 | |
Ned Nguyen | fc67e1f | 2019-01-31 16:06:53 -0700 | [diff] [blame] | 138 | # Clean metadata cache to make sure SRC_URI is fetched from ${srcuris} |
| 139 | # instead from portage cache which maybe out of sync. |
Ned Nguyen | 6d6cd60 | 2019-01-22 17:17:13 -0700 | [diff] [blame] | 140 | # Note: this workaround is needed because we break the SRC_URI API contract |
| 141 | # which is supposed to be a static (see |
Ned Nguyen | fc67e1f | 2019-01-31 16:06:53 -0700 | [diff] [blame] | 142 | # https://devmanual.gentoo.org/general-concepts/portage-cache/index.html). |
| 143 | # TODO(crbug.com/927917): find a different way to generate SRC_URI and remove |
| 144 | # these cache cleanup code. |
| 145 | rm -rf "${metadata}/cache" "${metadata}/md5-cache" "${edb_cache}" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 146 | "ebuild-${board}" "${ebuild}" manifest |
Andrew McRae | bf31263 | 2020-07-14 17:44:28 +1000 | [diff] [blame] | 147 | "emerge-${board}" -j ${quiet} "chromeos-firmware-${board}" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 148 | |
| 149 | for i in "${!result[@]}"; do |
| 150 | if [[ "${result[i]}" -eq "0" ]]; then |
| 151 | stop_workon "${board}" "${start_pkg[i]}" |
| 152 | fi |
| 153 | done |
| 154 | } |
| 155 | |
| 156 | main() { |
| 157 | if [[ -z "${FLAGS_board}" ]]; then |
| 158 | die "-b or --board required." |
| 159 | fi |
| 160 | |
Andrew Lamb | feacb4c | 2020-09-23 15:00:09 -0600 | [diff] [blame] | 161 | update_firmware "${FLAGS_board}" "${FLAGS_project}" "${FLAGS_quiet}" "${FLAGS_append_srcuris}" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | main "$@" |