blob: 31376a732c9adf9149d88bf0310557a14cfd91dc [file] [log] [blame]
Mike Frysinger39bf51f2018-08-16 14:48:40 -04001#!/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.
7CONTRIB_DIR=$(dirname "$(readlink -f "$0")")
8. "${CONTRIB_DIR}/common.sh" || exit 1
9
10FLAGS_HELP="
11Command to rebuild firmware after a config change.
12
13After you make a change to the firmware version in the master configuration,
14run this script to test it. It will rebuild the master configuration, update
15the Manifest and build the new firmware. You can then submit your CL to update
16the master configuration, safe in the knowledge that you have tested it.
17
18Usage:
19 cros_update_firmware <board>
20
21where <board> is the board whose firmware needs updating (e.g. 'coral').
22"
23
24# Flags
25DEFINE_string board "${DEFAULT_BOARD}" "Which board the firmware is for" b
26
27# Parse command line.
28FLAGS "$@" || exit 1
29eval set -- "${FLAGS_ARGV}"
30set -e
31
32# Script must be run inside the chroot.
33assert_inside_chroot
34
35start_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
54stop_workon() {
55 cros_workon --board="$1" stop "$2"
56}
57
58update_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 Nguyen6d6cd602019-01-22 17:17:13 -070087 overlay="${GCLIENT_ROOT}/src/private-overlays/overlay-${board}-private"
88 metadata="${overlay}/metadata"
Ned Nguyenfc67e1f2019-01-31 16:06:53 -070089 edb_cache="/var/cache/edb/dep/mnt/host/source/src/private-overlays/overlay-${board}-private"
Ned Nguyen6d6cd602019-01-22 17:17:13 -070090 base="${overlay}/chromeos-base"
Mike Frysinger39bf51f2018-08-16 14:48:40 -040091 ebuild="${base}/chromeos-firmware-${board}/chromeos-firmware-${board}-9999.ebuild"
92 srcuris="${base}/chromeos-firmware-${board}/files/srcuris"
93 yaml_config="/build/${board}/usr/share/chromeos-config/yaml/config.yaml"
94
95 "emerge-${board}" ${cfg_bsp_baseboard_pkg} "${cfg_bsp_pkg}" chromeos-config
C Shapiro15ecf7a2018-11-06 12:04:38 -070096 cros_config_host -c "${yaml_config}" get-firmware-uris > "${srcuris}"
Mike Frysinger39bf51f2018-08-16 14:48:40 -040097 touch "${ebuild}"
Ned Nguyenfc67e1f2019-01-31 16:06:53 -070098 # Clean metadata cache to make sure SRC_URI is fetched from ${srcuris}
99 # instead from portage cache which maybe out of sync.
Ned Nguyen6d6cd602019-01-22 17:17:13 -0700100 # Note: this workaround is needed because we break the SRC_URI API contract
101 # which is supposed to be a static (see
Ned Nguyenfc67e1f2019-01-31 16:06:53 -0700102 # https://devmanual.gentoo.org/general-concepts/portage-cache/index.html).
103 # TODO(crbug.com/927917): find a different way to generate SRC_URI and remove
104 # these cache cleanup code.
105 rm -rf "${metadata}/cache" "${metadata}/md5-cache" "${edb_cache}"
Mike Frysinger39bf51f2018-08-16 14:48:40 -0400106 "ebuild-${board}" "${ebuild}" manifest
107 "emerge-${board}" "chromeos-firmware-${board}"
108
109 for i in "${!result[@]}"; do
110 if [[ "${result[i]}" -eq "0" ]]; then
111 stop_workon "${board}" "${start_pkg[i]}"
112 fi
113 done
114}
115
116main() {
117 if [[ -z "${FLAGS_board}" ]]; then
118 die "-b or --board required."
119 fi
120
121 update_firmware "${FLAGS_board}"
122}
123
124main "$@"