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: |
| 19 | cros_update_firmware <board> |
| 20 | |
| 21 | where <board> is the board whose firmware needs updating (e.g. 'coral'). |
| 22 | " |
| 23 | |
| 24 | # Flags |
| 25 | DEFINE_string board "${DEFAULT_BOARD}" "Which board the firmware is for" b |
| 26 | |
| 27 | # Parse command line. |
| 28 | FLAGS "$@" || exit 1 |
| 29 | eval set -- "${FLAGS_ARGV}" |
| 30 | set -e |
| 31 | |
| 32 | # Script must be run inside the chroot. |
| 33 | assert_inside_chroot |
| 34 | |
| 35 | start_workon() { |
| 36 | local board="$1" |
| 37 | local pkg item |
| 38 | if [[ -z "$2" ]]; then |
| 39 | echo "Empty package. Skipping..." |
| 40 | return 1 |
| 41 | fi |
| 42 | pkg=$(cros_workon --board="${board}" info "$2" | cut -d ' ' -f 1) |
| 43 | shift 2 |
| 44 | for item in "$@"; do |
| 45 | if [[ "${pkg}" == "${item}" ]]; then |
| 46 | echo "Already workon ${pkg}. Skipping..." |
| 47 | return 1 |
| 48 | fi |
| 49 | done |
| 50 | cros_workon --board="${board}" start "${pkg}" |
| 51 | return $? |
| 52 | } |
| 53 | |
| 54 | stop_workon() { |
| 55 | cros_workon --board="$1" stop "$2" |
| 56 | } |
| 57 | |
| 58 | update_firmware() { |
| 59 | local board="$1" |
| 60 | local base ebuild srcuris cfg_bsp_pkg cfg_bsp_baseboard_pkg |
| 61 | local current_workon_pkg_list start_pkg result i |
| 62 | |
| 63 | set -e |
| 64 | |
| 65 | # query the current working package |
| 66 | mapfile -t current_workon_pkg_list < <(cros_workon --board="${board}" list) |
| 67 | |
| 68 | # check if chromeos-config-bsp is a virtual package |
| 69 | cfg_bsp_pkg="chromeos-config-bsp" |
| 70 | equery-"${board}" w chromeos-base/chromeos-config-bsp > /dev/null 2>&1 \ |
| 71 | || cfg_bsp_pkg="chromeos-config-bsp-${board}-private" |
| 72 | # check if chromeos-config-bsp-baseboard is in use |
| 73 | cfg_bsp_baseboard_pkg="chromeos-config-bsp-baseboard" |
| 74 | equery-"${board}" w chromeos-base/chromeos-config-bsp-baseboard \ |
| 75 | > /dev/null 2>&1 || cfg_bsp_baseboard_pkg= |
| 76 | |
| 77 | start_pkg=("${cfg_bsp_pkg}") |
| 78 | start_pkg+=("chromeos-firmware-${board}") |
| 79 | start_pkg+=("${cfg_bsp_baseboard_pkg}") |
| 80 | |
| 81 | for i in "${!start_pkg[@]}"; do |
| 82 | result[i]=0 |
| 83 | start_workon "${board}" "${start_pkg[i]}" "${current_workon_pkg_list[@]}" \ |
| 84 | || result[i]=$? |
| 85 | done |
| 86 | |
Ned Nguyen | 6d6cd60 | 2019-01-22 17:17:13 -0700 | [diff] [blame^] | 87 | overlay="${GCLIENT_ROOT}/src/private-overlays/overlay-${board}-private" |
| 88 | metadata="${overlay}/metadata" |
| 89 | base="${overlay}/chromeos-base" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 90 | ebuild="${base}/chromeos-firmware-${board}/chromeos-firmware-${board}-9999.ebuild" |
| 91 | srcuris="${base}/chromeos-firmware-${board}/files/srcuris" |
| 92 | yaml_config="/build/${board}/usr/share/chromeos-config/yaml/config.yaml" |
| 93 | |
| 94 | "emerge-${board}" ${cfg_bsp_baseboard_pkg} "${cfg_bsp_pkg}" chromeos-config |
C Shapiro | 15ecf7a | 2018-11-06 12:04:38 -0700 | [diff] [blame] | 95 | cros_config_host -c "${yaml_config}" get-firmware-uris > "${srcuris}" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 96 | touch "${ebuild}" |
Ned Nguyen | 6d6cd60 | 2019-01-22 17:17:13 -0700 | [diff] [blame^] | 97 | # clean metadata cache to make sure SRC_URI is fetched from ${srcuris} |
| 98 | # instead from portage cache which maybe out of sync |
| 99 | # Note: this workaround is needed because we break the SRC_URI API contract |
| 100 | # which is supposed to be a static (see |
| 101 | # https://devmanual.gentoo.org/general-concepts/portage-cache/index.html) |
| 102 | rm -rf "${metadata}/cache" "${metadata}/md5-cache" |
Mike Frysinger | 39bf51f | 2018-08-16 14:48:40 -0400 | [diff] [blame] | 103 | "ebuild-${board}" "${ebuild}" manifest |
| 104 | "emerge-${board}" "chromeos-firmware-${board}" |
| 105 | |
| 106 | for i in "${!result[@]}"; do |
| 107 | if [[ "${result[i]}" -eq "0" ]]; then |
| 108 | stop_workon "${board}" "${start_pkg[i]}" |
| 109 | fi |
| 110 | done |
| 111 | } |
| 112 | |
| 113 | main() { |
| 114 | if [[ -z "${FLAGS_board}" ]]; then |
| 115 | die "-b or --board required." |
| 116 | fi |
| 117 | |
| 118 | update_firmware "${FLAGS_board}" |
| 119 | } |
| 120 | |
| 121 | main "$@" |