blob: a8eaa444cdae2a772e85965028d782520032e248 [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
87 base="${GCLIENT_ROOT}/src/private-overlays/overlay-${board}-private/chromeos-base"
88 ebuild="${base}/chromeos-firmware-${board}/chromeos-firmware-${board}-9999.ebuild"
89 srcuris="${base}/chromeos-firmware-${board}/files/srcuris"
90 yaml_config="/build/${board}/usr/share/chromeos-config/yaml/config.yaml"
91
92 "emerge-${board}" ${cfg_bsp_baseboard_pkg} "${cfg_bsp_pkg}" chromeos-config
C Shapiro15ecf7a2018-11-06 12:04:38 -070093 cros_config_host -c "${yaml_config}" get-firmware-uris > "${srcuris}"
Mike Frysinger39bf51f2018-08-16 14:48:40 -040094 touch "${ebuild}"
95 "ebuild-${board}" "${ebuild}" manifest
96 "emerge-${board}" "chromeos-firmware-${board}"
97
98 for i in "${!result[@]}"; do
99 if [[ "${result[i]}" -eq "0" ]]; then
100 stop_workon "${board}" "${start_pkg[i]}"
101 fi
102 done
103}
104
105main() {
106 if [[ -z "${FLAGS_board}" ]]; then
107 die "-b or --board required."
108 fi
109
110 update_firmware "${FLAGS_board}"
111}
112
113main "$@"