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 |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 29 | |
| 30 | # Parse command line. |
| 31 | FLAGS "$@" || exit 1 |
| 32 | eval set -- "${FLAGS_ARGV}" |
| 33 | set -e |
| 34 | |
| 35 | # Script must be run inside the chroot. |
| 36 | assert_inside_chroot |
| 37 | |
| 38 | start_workon() { |
| 39 | local board="$1" |
| 40 | local pkg item |
| 41 | if [[ -z "$2" ]]; then |
| 42 | echo "Empty package. Skipping..." |
| 43 | return 1 |
| 44 | fi |
Andrew McRae | d26b279 | 2020-08-06 23:28:26 +1000 | [diff] [blame^] | 45 | pkg=$(cros workon --board="${board}" info "$2" | cut -d ' ' -f 1) |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 46 | shift 2 |
| 47 | for item in "$@"; do |
| 48 | if [[ "${pkg}" == "${item}" ]]; then |
| 49 | echo "Already workon ${pkg}. Skipping..." |
| 50 | return 1 |
| 51 | fi |
| 52 | done |
Andrew McRae | d26b279 | 2020-08-06 23:28:26 +1000 | [diff] [blame^] | 53 | cros workon --board="${board}" start "${pkg}" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 54 | return $? |
| 55 | } |
| 56 | |
| 57 | stop_workon() { |
Andrew McRae | d26b279 | 2020-08-06 23:28:26 +1000 | [diff] [blame^] | 58 | cros workon --board="$1" stop "$2" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | update_firmware() { |
| 62 | local board="$1" |
YH Lin | 7050ce7 | 2020-03-18 16:54:51 -0700 | [diff] [blame] | 63 | local project="$2" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 64 | local base ebuild srcuris cfg_bsp_pkg cfg_bsp_baseboard_pkg |
Andrew McRae | 3fccc99 | 2020-06-18 14:49:33 +1000 | [diff] [blame] | 65 | local current_workon_pkg_list start_pkg result i quiet |
| 66 | [[ "$3" == "${FLAGS_TRUE}" ]] && quiet="--quiet-build" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 67 | |
| 68 | set -e |
| 69 | |
| 70 | # query the current working package |
Andrew McRae | d26b279 | 2020-08-06 23:28:26 +1000 | [diff] [blame^] | 71 | mapfile -t current_workon_pkg_list < <(cros workon --board="${board}" list) |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 72 | |
| 73 | # check if chromeos-config-bsp is a virtual package |
| 74 | cfg_bsp_pkg="chromeos-config-bsp" |
| 75 | equery-"${board}" w chromeos-base/chromeos-config-bsp > /dev/null 2>&1 \ |
| 76 | || cfg_bsp_pkg="chromeos-config-bsp-${board}-private" |
| 77 | # check if chromeos-config-bsp-baseboard is in use |
| 78 | cfg_bsp_baseboard_pkg="chromeos-config-bsp-baseboard" |
| 79 | equery-"${board}" w chromeos-base/chromeos-config-bsp-baseboard \ |
| 80 | > /dev/null 2>&1 || cfg_bsp_baseboard_pkg= |
| 81 | |
| 82 | start_pkg=("${cfg_bsp_pkg}") |
| 83 | start_pkg+=("chromeos-firmware-${board}") |
| 84 | start_pkg+=("${cfg_bsp_baseboard_pkg}") |
| 85 | |
| 86 | for i in "${!start_pkg[@]}"; do |
| 87 | result[i]=0 |
| 88 | start_workon "${board}" "${start_pkg[i]}" "${current_workon_pkg_list[@]}" \ |
| 89 | || result[i]=$? |
| 90 | done |
| 91 | |
Ned Nguyen | 6d6cd60 | 2019-01-22 17:17:13 -0700 | [diff] [blame] | 92 | overlay="${GCLIENT_ROOT}/src/private-overlays/overlay-${board}-private" |
| 93 | metadata="${overlay}/metadata" |
Ned Nguyen | fc67e1f | 2019-01-31 16:06:53 -0700 | [diff] [blame] | 94 | 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] | 95 | base="${overlay}/chromeos-base" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 96 | ebuild="${base}/chromeos-firmware-${board}/chromeos-firmware-${board}-9999.ebuild" |
| 97 | srcuris="${base}/chromeos-firmware-${board}/files/srcuris" |
| 98 | yaml_config="/build/${board}/usr/share/chromeos-config/yaml/config.yaml" |
| 99 | |
YH Lin | 7050ce7 | 2020-03-18 16:54:51 -0700 | [diff] [blame] | 100 | # Check project config repo exists -- if so generate the config first. |
YH Lin | 3f600de | 2020-04-13 10:55:06 -0700 | [diff] [blame] | 101 | if [[ -d "${GCLIENT_ROOT}/src/project/${project}" ]]; then |
| 102 | pushd "${GCLIENT_ROOT}/src/project/${project}" > /dev/null |
| 103 | for brd in *; do |
| 104 | if [[ -d "${brd}" && -x "${brd}/config/bin/gen_config" && -f "${brd}/config.star" ]]; then |
| 105 | pushd "${brd}" > /dev/null |
| 106 | ./config/bin/gen_config config.star |
| 107 | popd > /dev/null |
| 108 | fi |
| 109 | done |
YH Lin | 7050ce7 | 2020-03-18 16:54:51 -0700 | [diff] [blame] | 110 | popd > /dev/null |
| 111 | fi |
| 112 | |
Andrew McRae | bf31263 | 2020-07-14 17:44:28 +1000 | [diff] [blame] | 113 | "emerge-${board}" -j ${quiet} ${cfg_bsp_baseboard_pkg} "${cfg_bsp_pkg}" chromeos-config |
C Shapiro | 15ecf7a | 2018-11-06 12:04:38 -0700 | [diff] [blame] | 114 | cros_config_host -c "${yaml_config}" get-firmware-uris > "${srcuris}" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 115 | touch "${ebuild}" |
YH Lin | 7050ce7 | 2020-03-18 16:54:51 -0700 | [diff] [blame] | 116 | |
Ned Nguyen | fc67e1f | 2019-01-31 16:06:53 -0700 | [diff] [blame] | 117 | # Clean metadata cache to make sure SRC_URI is fetched from ${srcuris} |
| 118 | # instead from portage cache which maybe out of sync. |
Ned Nguyen | 6d6cd60 | 2019-01-22 17:17:13 -0700 | [diff] [blame] | 119 | # Note: this workaround is needed because we break the SRC_URI API contract |
| 120 | # which is supposed to be a static (see |
Ned Nguyen | fc67e1f | 2019-01-31 16:06:53 -0700 | [diff] [blame] | 121 | # https://devmanual.gentoo.org/general-concepts/portage-cache/index.html). |
| 122 | # TODO(crbug.com/927917): find a different way to generate SRC_URI and remove |
| 123 | # these cache cleanup code. |
| 124 | rm -rf "${metadata}/cache" "${metadata}/md5-cache" "${edb_cache}" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 125 | "ebuild-${board}" "${ebuild}" manifest |
Andrew McRae | bf31263 | 2020-07-14 17:44:28 +1000 | [diff] [blame] | 126 | "emerge-${board}" -j ${quiet} "chromeos-firmware-${board}" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 127 | |
| 128 | for i in "${!result[@]}"; do |
| 129 | if [[ "${result[i]}" -eq "0" ]]; then |
| 130 | stop_workon "${board}" "${start_pkg[i]}" |
| 131 | fi |
| 132 | done |
| 133 | } |
| 134 | |
| 135 | main() { |
| 136 | if [[ -z "${FLAGS_board}" ]]; then |
| 137 | die "-b or --board required." |
| 138 | fi |
| 139 | |
Andrew McRae | 3fccc99 | 2020-06-18 14:49:33 +1000 | [diff] [blame] | 140 | update_firmware "${FLAGS_board}" "${FLAGS_project}" "${FLAGS_quiet}" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | main "$@" |