David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # -*- coding: utf-8 -*- |
| 3 | # Copyright 2020 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | """Transforms config from /config/proto/api proto format to platform JSON.""" |
| 7 | |
| 8 | import argparse |
| 9 | import json |
| 10 | import pprint |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 11 | import os |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 12 | import sys |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 13 | import re |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 14 | import xml.etree.ElementTree as etree |
C Shapiro | 9a3ac8c | 2020-04-25 07:49:21 -0500 | [diff] [blame] | 15 | import xml.dom.minidom as minidom |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 16 | |
Andrew Lamb | 319cc92 | 2020-06-15 10:45:46 -0600 | [diff] [blame] | 17 | from typing import List |
| 18 | |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 19 | from collections import namedtuple |
| 20 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 21 | from google.protobuf import json_format |
| 22 | |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 23 | from chromiumos.config.api import device_brand_pb2 |
David Burger | 92609a3 | 2020-04-23 10:38:50 -0600 | [diff] [blame] | 24 | from chromiumos.config.api import topology_pb2 |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 25 | from chromiumos.config.payload import config_bundle_pb2 |
Prathmesh Prabhu | 72f8a00 | 2020-04-10 09:57:53 -0700 | [diff] [blame] | 26 | from chromiumos.config.api.software import brand_config_pb2 |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 27 | |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 28 | Config = namedtuple('Config', [ |
| 29 | 'program', 'hw_design', 'odm', 'hw_design_config', 'device_brand', |
| 30 | 'device_signer_config', 'oem', 'sw_config', 'brand_config', 'build_target' |
| 31 | ]) |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 32 | |
David Burger | 2f0d952 | 2020-07-30 10:52:28 -0600 | [diff] [blame] | 33 | ConfigFiles = namedtuple('ConfigFiles', [ |
| 34 | 'bluetooth', 'arc_hw_features', 'touch_fw', 'dptf_map', 'camera_map', |
| 35 | 'arc_camera_map' |
| 36 | ]) |
| 37 | |
| 38 | ARC_CONFIG_PATH = 'sw_build_config/platform/chromeos-config/arc' |
| 39 | ARC_CAMERA_CHARACTERISTICS_FILE = 'camera_characteristics.conf' |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 40 | |
| 41 | CAMERA_CONFIG_DEST_PATH_TEMPLATE = '/etc/camera/camera_config_{}.json' |
| 42 | CAMERA_CONFIG_SOURCE_PATH_TEMPLATE = ( |
| 43 | 'sw_build_config/platform/chromeos-config/camera/camera_config_{}.json') |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 44 | |
David Burger | 52c9d32 | 2020-06-09 07:16:18 -0600 | [diff] [blame] | 45 | DPTF_PATH = 'sw_build_config/platform/chromeos-config/thermal' |
| 46 | DPTF_FILE = 'dptf.dv' |
David Burger | 2f0d952 | 2020-07-30 10:52:28 -0600 | [diff] [blame] | 47 | |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 48 | TOUCH_PATH = 'sw_build_config/platform/chromeos-config/touch' |
Andrew Lamb | 6c42efc | 2020-06-16 10:40:43 -0600 | [diff] [blame] | 49 | WALLPAPER_BASE_PATH = '/usr/share/chromeos-assets/wallpaper' |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 50 | |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 51 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 52 | def parse_args(argv): |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 53 | """Parse the available arguments. |
| 54 | |
| 55 | Invalid arguments or -h cause this function to print a message and exit. |
| 56 | |
| 57 | Args: |
| 58 | argv: List of string arguments (excluding program name / argv[0]) |
| 59 | |
| 60 | Returns: |
| 61 | argparse.Namespace object containing the attributes. |
| 62 | """ |
| 63 | parser = argparse.ArgumentParser( |
| 64 | description='Converts source proto config into platform JSON config.') |
| 65 | parser.add_argument( |
| 66 | '-c', |
| 67 | '--project_configs', |
| 68 | nargs='+', |
| 69 | type=str, |
| 70 | help='Space delimited list of source protobinary project config files.') |
| 71 | parser.add_argument( |
| 72 | '-p', |
| 73 | '--program_config', |
| 74 | type=str, |
| 75 | help='Path to the source program-level protobinary file') |
| 76 | parser.add_argument( |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 77 | '-o', '--output', type=str, help='Output file that will be generated') |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 78 | return parser.parse_args(argv) |
| 79 | |
| 80 | |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 81 | def _upsert(field, target, target_name): |
| 82 | """Updates or inserts `field` within `target`. |
| 83 | |
| 84 | If `target_name` already exists within `target` an update is performed, |
| 85 | otherwise, an insert is performed. |
| 86 | """ |
Sam McNally | 9a873f7 | 2020-06-05 19:47:22 +1000 | [diff] [blame] | 87 | if field or field == 0: |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 88 | if target_name in target: |
| 89 | target[target_name].update(field) |
| 90 | else: |
| 91 | target[target_name] = field |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 92 | |
| 93 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 94 | def _build_arc(config, config_files): |
| 95 | if not config.build_target.arc: |
| 96 | return None |
| 97 | |
| 98 | build_properties = { |
| 99 | 'device': config.build_target.arc.device, |
| 100 | 'first-api-level': config.build_target.arc.first_api_level, |
| 101 | 'marketing-name': config.device_brand.brand_name, |
| 102 | 'metrics-tag': config.hw_design.name.lower(), |
| 103 | 'product': config.build_target.id.value, |
| 104 | } |
| 105 | if config.oem: |
| 106 | build_properties['oem'] = config.oem.name |
| 107 | result = {'build-properties': build_properties} |
| 108 | feature_id = _arc_hardware_feature_id(config.hw_design_config) |
| 109 | if feature_id in config_files.arc_hw_features: |
| 110 | result['hardware-features'] = config_files.arc_hw_features[feature_id] |
| 111 | topology = config.hw_design_config.hardware_topology |
| 112 | ppi = topology.screen.hardware_feature.screen.panel_properties.pixels_per_in |
| 113 | # Only set for high resolution displays |
| 114 | if ppi and ppi > 250: |
| 115 | result['scale'] = ppi |
David Burger | 2f0d952 | 2020-07-30 10:52:28 -0600 | [diff] [blame] | 116 | |
| 117 | if config_files.arc_camera_map: |
| 118 | # Prefer design specific if found, if not fall back to project wide config |
| 119 | # mapped under the empty string. |
| 120 | if config.hw_design.name in config_files.arc_camera_map: |
| 121 | camera_characteristics = config_files.arc_camera_map[ |
| 122 | config.hw_design.name] |
| 123 | else: |
| 124 | camera_characteristics = config_files.arc_camera_map.get('') |
| 125 | result['camera-characteristics'] = camera_characteristics |
| 126 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 127 | return result |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 128 | |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 129 | |
Andrew Lamb | 319cc92 | 2020-06-15 10:45:46 -0600 | [diff] [blame] | 130 | def _build_ash_flags(config: Config) -> List[str]: |
| 131 | """Returns a list of Ash flags for config. |
| 132 | |
| 133 | Ash is the window manager and system UI for ChromeOS, see |
| 134 | https://chromium.googlesource.com/chromium/src/+/refs/heads/master/ash/. |
| 135 | """ |
| 136 | # A map from flag name -> value. Value may be None for boolean flags. |
| 137 | flags = {} |
| 138 | |
| 139 | hw_features = config.hw_design_config.hardware_features |
| 140 | if hw_features.stylus.stylus == topology_pb2.HardwareFeatures.Stylus.INTERNAL: |
Andrew Lamb | 2e641e2 | 2020-06-15 12:30:41 -0600 | [diff] [blame] | 141 | flags['has-internal-stylus'] = None |
Andrew Lamb | 319cc92 | 2020-06-15 10:45:46 -0600 | [diff] [blame] | 142 | |
Andrew Lamb | 2e641e2 | 2020-06-15 12:30:41 -0600 | [diff] [blame] | 143 | fp_loc = hw_features.fingerprint.location |
| 144 | if fp_loc and fp_loc != topology_pb2.HardwareFeatures.Fingerprint.NOT_PRESENT: |
| 145 | loc_name = topology_pb2.HardwareFeatures.Fingerprint.Location.Name(fp_loc) |
| 146 | flags['fingerprint-sensor-location'] = loc_name.lower().replace('_', '-') |
| 147 | |
Andrew Lamb | 6c42efc | 2020-06-16 10:40:43 -0600 | [diff] [blame] | 148 | wallpaper = config.brand_config.wallpaper |
| 149 | # If a wallpaper is set, the 'default-wallpaper-is-oem' flag needs to be set. |
| 150 | # If a wallpaper is not set, the 'default_[large|small].jpg' wallpapers |
| 151 | # should still be set. |
| 152 | if wallpaper: |
| 153 | flags['default-wallpaper-is-oem'] = None |
| 154 | else: |
| 155 | wallpaper = 'default' |
| 156 | |
| 157 | for size in ('small', 'large'): |
| 158 | flags[f'default-wallpaper-{size}'] = ( |
| 159 | f'{WALLPAPER_BASE_PATH}/{wallpaper}_{size}.jpg') |
| 160 | |
| 161 | # For each size, also install 'guest' and 'child' wallpapers. |
| 162 | for wallpaper_type in ('guest', 'child'): |
| 163 | flags[f'{wallpaper_type}-wallpaper-{size}'] = ( |
| 164 | f'{WALLPAPER_BASE_PATH}/{wallpaper_type}_{size}.jpg') |
| 165 | |
Andrew Lamb | 72d4136 | 2020-06-17 09:19:02 -0600 | [diff] [blame] | 166 | flags['arc-build-properties'] = json_format.MessageToDict( |
| 167 | config.build_target.arc) |
| 168 | |
Andrew Lamb | 90b168c | 2020-06-22 10:42:30 -0600 | [diff] [blame] | 169 | power_button = hw_features.power_button |
| 170 | if power_button.edge: |
| 171 | flags['ash-power-button-position'] = json.dumps({ |
| 172 | 'edge': |
| 173 | topology_pb2.HardwareFeatures.Button.Edge.Name(power_button.edge |
| 174 | ).lower(), |
| 175 | # Starlark sometimes represents float literals strangely, e.g. changing |
| 176 | # 0.9 to 0.899999. Round to two digits here. |
| 177 | 'position': |
| 178 | round(power_button.position, 2) |
| 179 | }) |
| 180 | |
| 181 | volume_button = hw_features.volume_button |
| 182 | if volume_button.edge: |
| 183 | flags['ash-side-volume-button-position'] = json.dumps({ |
| 184 | 'region': |
| 185 | topology_pb2.HardwareFeatures.Button.Region.Name( |
| 186 | volume_button.region).lower(), |
| 187 | 'edge': |
| 188 | topology_pb2.HardwareFeatures.Button.Edge.Name(volume_button.edge |
| 189 | ).lower(), |
| 190 | }) |
| 191 | |
Andrew Lamb | 2e641e2 | 2020-06-15 12:30:41 -0600 | [diff] [blame] | 192 | return sorted([f'--{k}={v}' if v else f'--{k}' for k, v in flags.items()]) |
Andrew Lamb | 319cc92 | 2020-06-15 10:45:46 -0600 | [diff] [blame] | 193 | |
| 194 | |
| 195 | def _build_ui(config: Config) -> dict: |
| 196 | """Builds the 'ui' property from cros_config_schema.""" |
| 197 | return {'extra-ash-flags': _build_ash_flags(config)} |
| 198 | |
| 199 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 200 | def _build_bluetooth(config, bluetooth_files): |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 201 | bt_flags = config.sw_config.bluetooth_config.flags |
| 202 | # Convert to native map (from proto wrapper) |
| 203 | bt_flags_map = dict(bt_flags) |
| 204 | result = {} |
| 205 | if bt_flags_map: |
| 206 | result['flags'] = bt_flags_map |
C Shapiro | 74da76e | 2020-05-04 13:02:20 -0500 | [diff] [blame] | 207 | bt_comp = config.hw_design_config.hardware_features.bluetooth.component.usb |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 208 | if bt_comp.vendor_id: |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 209 | bt_id = _bluetooth_id(config.hw_design.name.lower(), bt_comp) |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 210 | if bt_id in bluetooth_files: |
| 211 | result['config'] = bluetooth_files[bt_id] |
| 212 | return result |
| 213 | |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 214 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 215 | def _build_fingerprint(hw_topology): |
| 216 | if not hw_topology.HasField('fingerprint'): |
| 217 | return None |
| 218 | |
| 219 | fp = hw_topology.fingerprint.hardware_feature.fingerprint |
| 220 | result = {} |
| 221 | if fp.location != topology_pb2.HardwareFeatures.Fingerprint.NOT_PRESENT: |
| 222 | location = fp.Location.DESCRIPTOR.values_by_number[fp.location].name |
| 223 | result['sensor-location'] = location.lower().replace('_', '-') |
| 224 | if fp.board: |
| 225 | result['board'] = fp.board |
Tom Hughes | dfc3540 | 2020-06-29 16:02:09 -0700 | [diff] [blame] | 226 | if fp.ro_version: |
| 227 | result['ro-version'] = fp.ro_version |
| 228 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 229 | return result |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 230 | |
| 231 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 232 | def _fw_bcs_path(payload): |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 233 | if payload and payload.firmware_image_name: |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 234 | return 'bcs://%s.%d.%d.0.tbz2' % (payload.firmware_image_name, |
| 235 | payload.version.major, |
| 236 | payload.version.minor) |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 237 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 238 | return None |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 239 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 240 | |
| 241 | def _fw_build_target(payload): |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 242 | if payload: |
| 243 | return payload.build_target_name |
| 244 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 245 | return None |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 246 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 247 | |
| 248 | def _build_firmware(config): |
David Burger | b70b676 | 2020-05-21 12:14:59 -0600 | [diff] [blame] | 249 | """Returns firmware config, or None if no build targets.""" |
Andrew Lamb | 3da156d | 2020-04-16 16:00:56 -0600 | [diff] [blame] | 250 | fw_payload_config = config.sw_config.firmware |
| 251 | fw_build_config = config.sw_config.firmware_build_config |
| 252 | main_ro = fw_payload_config.main_ro_payload |
| 253 | main_rw = fw_payload_config.main_rw_payload |
| 254 | ec_ro = fw_payload_config.ec_ro_payload |
| 255 | pd_ro = fw_payload_config.pd_ro_payload |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 256 | |
| 257 | build_targets = {} |
Andrew Lamb | 3da156d | 2020-04-16 16:00:56 -0600 | [diff] [blame] | 258 | |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 259 | _upsert(fw_build_config.build_targets.depthcharge, build_targets, |
| 260 | 'depthcharge') |
| 261 | _upsert(fw_build_config.build_targets.coreboot, build_targets, 'coreboot') |
| 262 | _upsert(fw_build_config.build_targets.ec, build_targets, 'ec') |
| 263 | _upsert( |
Andrew Lamb | f8954ee | 2020-04-21 10:24:40 -0600 | [diff] [blame] | 264 | list(fw_build_config.build_targets.ec_extras), build_targets, 'ec_extras') |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 265 | _upsert(fw_build_config.build_targets.libpayload, build_targets, 'libpayload') |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 266 | |
David Burger | b70b676 | 2020-05-21 12:14:59 -0600 | [diff] [blame] | 267 | if not build_targets: |
| 268 | return None |
| 269 | |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 270 | result = { |
| 271 | 'bcs-overlay': config.build_target.overlay_name, |
| 272 | 'build-targets': build_targets, |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 273 | } |
Andrew Lamb | 883fa04 | 2020-04-06 11:37:22 -0600 | [diff] [blame] | 274 | |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 275 | _upsert(main_ro.firmware_image_name.lower(), result, 'image-name') |
Andrew Lamb | 883fa04 | 2020-04-06 11:37:22 -0600 | [diff] [blame] | 276 | |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 277 | _upsert(_fw_bcs_path(main_ro), result, 'main-ro-image') |
| 278 | _upsert(_fw_bcs_path(main_rw), result, 'main-rw-image') |
| 279 | _upsert(_fw_bcs_path(ec_ro), result, 'ec-ro-image') |
| 280 | _upsert(_fw_bcs_path(pd_ro), result, 'pd-ro-image') |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 281 | |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 282 | _upsert( |
Andrew Lamb | f39fbe8 | 2020-04-13 16:14:33 -0600 | [diff] [blame] | 283 | config.hw_design_config.hardware_features.fw_config.value, |
| 284 | result, |
| 285 | 'firmware-config', |
| 286 | ) |
| 287 | |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 288 | return result |
| 289 | |
| 290 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 291 | def _build_fw_signing(config): |
C Shapiro | 2f0bb5d | 2020-04-14 10:07:47 -0500 | [diff] [blame] | 292 | if config.sw_config.firmware and config.device_signer_config: |
David Burger | 68e0d14 | 2020-05-15 17:29:33 -0600 | [diff] [blame] | 293 | hw_design = config.hw_design.name.lower() |
Sam McNally | 2fc807f | 2020-07-16 18:13:53 +1000 | [diff] [blame] | 294 | brand_scan_config = config.brand_config.scan_config |
| 295 | if brand_scan_config and brand_scan_config.whitelabel_tag: |
| 296 | signature_id = '%s-%s' % (hw_design, brand_scan_config.whitelabel_tag) |
| 297 | else: |
| 298 | signature_id = hw_design |
| 299 | |
C Shapiro | 2f0bb5d | 2020-04-14 10:07:47 -0500 | [diff] [blame] | 300 | return { |
| 301 | 'key-id': config.device_signer_config.key_id, |
Sam McNally | 2fc807f | 2020-07-16 18:13:53 +1000 | [diff] [blame] | 302 | 'signature-id': signature_id, |
C Shapiro | 2f0bb5d | 2020-04-14 10:07:47 -0500 | [diff] [blame] | 303 | } |
| 304 | return {} |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 305 | |
| 306 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 307 | def _file(source, destination): |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 308 | return {'destination': destination, 'source': source} |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 309 | |
| 310 | |
David Burger | 40dfe3a | 2020-06-18 17:09:13 -0600 | [diff] [blame] | 311 | def _file_v2(build_path, system_path): |
| 312 | return {'build-path': build_path, 'system-path': system_path} |
| 313 | |
| 314 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 315 | def _build_audio(config): |
David Burger | 178f3ef | 2020-06-26 12:11:57 -0600 | [diff] [blame] | 316 | if not config.sw_config.audio_configs: |
| 317 | return {} |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 318 | alsa_path = '/usr/share/alsa/ucm' |
| 319 | cras_path = '/etc/cras' |
| 320 | project_name = config.hw_design.name.lower() |
David Burger | 4325066 | 2020-05-07 11:21:50 -0600 | [diff] [blame] | 321 | program_name = config.program.name.lower() |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 322 | files = [] |
David Burger | 178f3ef | 2020-06-26 12:11:57 -0600 | [diff] [blame] | 323 | ucm_suffix = None |
| 324 | for audio in config.sw_config.audio_configs: |
| 325 | card = audio.card_name |
| 326 | card_with_suffix = audio.card_name |
| 327 | if audio.ucm_suffix: |
| 328 | # TODO: last ucm_suffix wins. |
| 329 | ucm_suffix = audio.ucm_suffix |
| 330 | card_with_suffix += '.' + audio.ucm_suffix |
| 331 | if audio.ucm_file: |
| 332 | files.append( |
| 333 | _file(audio.ucm_file, |
| 334 | '%s/%s/HiFi.conf' % (alsa_path, card_with_suffix))) |
| 335 | if audio.ucm_master_file: |
| 336 | files.append( |
| 337 | _file( |
| 338 | audio.ucm_master_file, '%s/%s/%s.conf' % |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 339 | (alsa_path, card_with_suffix, card_with_suffix))) |
David Burger | 178f3ef | 2020-06-26 12:11:57 -0600 | [diff] [blame] | 340 | if audio.card_config_file: |
| 341 | files.append( |
| 342 | _file(audio.card_config_file, |
| 343 | '%s/%s/%s' % (cras_path, project_name, card))) |
| 344 | if audio.dsp_file: |
| 345 | files.append( |
| 346 | _file(audio.dsp_file, '%s/%s/dsp.ini' % (cras_path, project_name))) |
| 347 | if audio.module_file: |
| 348 | files.append( |
| 349 | _file(audio.module_file, |
| 350 | '/etc/modprobe.d/alsa-%s.conf' % program_name)) |
| 351 | if audio.board_file: |
| 352 | files.append( |
| 353 | _file(audio.board_file, |
| 354 | '%s/%s/board.ini' % (cras_path, project_name))) |
David Burger | 599ff7b | 2020-04-06 16:29:31 -0600 | [diff] [blame] | 355 | |
| 356 | result = { |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 357 | 'main': { |
| 358 | 'cras-config-dir': project_name, |
| 359 | 'files': files, |
| 360 | } |
| 361 | } |
David Burger | 178f3ef | 2020-06-26 12:11:57 -0600 | [diff] [blame] | 362 | |
| 363 | if ucm_suffix: |
| 364 | result['main']['ucm-suffix'] = ucm_suffix |
David Burger | 599ff7b | 2020-04-06 16:29:31 -0600 | [diff] [blame] | 365 | |
| 366 | return result |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 367 | |
| 368 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 369 | def _build_camera(hw_topology): |
David Burger | 8aa8fa3 | 2020-04-14 08:30:34 -0600 | [diff] [blame] | 370 | if hw_topology.HasField('camera'): |
| 371 | camera = hw_topology.camera.hardware_feature.camera |
| 372 | result = {} |
| 373 | if camera.count.value: |
| 374 | result['count'] = camera.count.value |
| 375 | return result |
| 376 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 377 | return None |
David Burger | 8aa8fa3 | 2020-04-14 08:30:34 -0600 | [diff] [blame] | 378 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 379 | |
| 380 | def _build_identity(hw_scan_config, program, brand_scan_config=None): |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 381 | identity = {} |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 382 | _upsert(hw_scan_config.firmware_sku, identity, 'sku-id') |
| 383 | _upsert(hw_scan_config.smbios_name_match, identity, 'smbios-name-match') |
Andrew Lamb | 7806ce9 | 2020-04-07 10:22:17 -0600 | [diff] [blame] | 384 | # 'platform-name' is needed to support 'mosys platform name'. Clients should |
| 385 | # longer require platform name, but set it here for backwards compatibility. |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 386 | _upsert(program.name, identity, 'platform-name') |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 387 | # ARM architecture |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 388 | _upsert(hw_scan_config.device_tree_compatible_match, identity, |
| 389 | 'device-tree-compatible-match') |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 390 | |
| 391 | if brand_scan_config: |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 392 | _upsert(brand_scan_config.whitelabel_tag, identity, 'whitelabel-tag') |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 393 | |
| 394 | return identity |
| 395 | |
| 396 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 397 | def _lookup(id_value, id_map): |
| 398 | if not id_value.value: |
| 399 | return None |
| 400 | |
| 401 | key = id_value.value |
| 402 | if key in id_map: |
| 403 | return id_map[id_value.value] |
| 404 | error = 'Failed to lookup %s with value: %s' % ( |
| 405 | id_value.__class__.__name__.replace('Id', ''), key) |
| 406 | print(error) |
| 407 | print('Check the config contents provided:') |
| 408 | printer = pprint.PrettyPrinter(indent=4) |
| 409 | printer.pprint(id_map) |
| 410 | raise Exception(error) |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 411 | |
| 412 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 413 | def _build_touch_file_config(config, project_name): |
Sean McAllister | eaf10b7 | 2020-08-03 13:41:06 -0600 | [diff] [blame] | 414 | partners = {x.id.value: x for x in config.partner_list} |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 415 | files = [] |
| 416 | for comp in config.components: |
C Shapiro | 4813be6 | 2020-05-13 17:31:58 -0500 | [diff] [blame] | 417 | touch = comp.touchscreen |
| 418 | # Everything is the same for Touch screen/pad, except different fields |
| 419 | if comp.HasField('touchpad'): |
| 420 | touch = comp.touchpad |
| 421 | if touch.product_id: |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 422 | vendor = _lookup(comp.manufacturer_id, partners) |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 423 | if not vendor: |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 424 | raise Exception("Manufacturer must be set for touch device %s" % |
| 425 | comp.id.value) |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 426 | |
C Shapiro | 4813be6 | 2020-05-13 17:31:58 -0500 | [diff] [blame] | 427 | product_id = touch.product_id |
| 428 | fw_version = touch.fw_version |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 429 | |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 430 | file_name = "%s_%s.bin" % (product_id, fw_version) |
| 431 | fw_file_path = os.path.join(TOUCH_PATH, vendor.name, file_name) |
| 432 | |
| 433 | if not os.path.exists(fw_file_path): |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 434 | raise Exception("Touchscreen fw bin file doesn't exist at: %s" % |
| 435 | fw_file_path) |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 436 | |
C Shapiro | 303cece | 2020-07-22 07:15:21 -0500 | [diff] [blame] | 437 | touch_vendor = vendor.touch_vendor |
| 438 | sym_link = touch_vendor.symlink_file_format.format( |
| 439 | vendor_name=vendor.name, |
| 440 | vendor_id=touch_vendor.vendor_id, |
| 441 | product_id=product_id, |
| 442 | fw_version=fw_version, |
| 443 | product_series=touch.product_series) |
| 444 | |
| 445 | dest = "%s_%s" % (vendor.name, file_name) |
| 446 | if touch_vendor.destination_file_format: |
| 447 | dest = touch_vendor.destination_file_format.format( |
| 448 | vendor_name=vendor.name, |
| 449 | vendor_id=touch_vendor.vendor_id, |
| 450 | product_id=product_id, |
| 451 | fw_version=fw_version, |
| 452 | product_series=touch.product_series) |
| 453 | |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 454 | files.append({ |
C Shapiro | 303cece | 2020-07-22 07:15:21 -0500 | [diff] [blame] | 455 | "destination": os.path.join("/opt/google/touch/firmware", dest), |
YH Lin | 9160fc5 | 2020-07-22 16:35:28 -0700 | [diff] [blame] | 456 | "source": os.path.join(project_name, fw_file_path), |
| 457 | "symlink": os.path.join("/lib/firmware", sym_link), |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 458 | }) |
| 459 | |
| 460 | result = {} |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 461 | _upsert(files, result, 'files') |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 462 | return result |
| 463 | |
| 464 | |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 465 | def _transform_build_configs(config, |
David Burger | 2f0d952 | 2020-07-30 10:52:28 -0600 | [diff] [blame] | 466 | config_files=ConfigFiles({}, {}, {}, {}, {}, {})): |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 467 | # pylint: disable=too-many-locals,too-many-branches |
Sean McAllister | eaf10b7 | 2020-08-03 13:41:06 -0600 | [diff] [blame] | 468 | partners = {x.id.value: x for x in config.partner_list} |
Sean McAllister | f38d1e9 | 2020-08-03 13:57:53 -0600 | [diff] [blame] | 469 | programs = {x.id.value: x for x in config.program_list} |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 470 | sw_configs = list(config.software_configs) |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 471 | brand_configs = {x.brand_id.value: x for x in config.brand_configs} |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 472 | |
C Shapiro | a0b766c | 2020-03-31 08:35:28 -0500 | [diff] [blame] | 473 | if len(config.build_targets) != 1: |
| 474 | # Artifact of sharing the config_bundle for analysis and transforms. |
| 475 | # Integrated analysis of multiple programs/projects it the only time |
| 476 | # having multiple build targets would be valid. |
| 477 | raise Exception('Single build_target required for transform') |
| 478 | |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 479 | results = {} |
Sean McAllister | f66887b | 2020-08-03 14:00:51 -0600 | [diff] [blame] | 480 | for hw_design in config.design_list: |
Sean McAllister | 6cbb0ec | 2020-08-03 14:03:37 -0600 | [diff] [blame] | 481 | if config.device_brand_list: |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 482 | device_brands = [ |
Sean McAllister | 6cbb0ec | 2020-08-03 14:03:37 -0600 | [diff] [blame] | 483 | x for x in config.device_brand_list |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 484 | if x.design_id.value == hw_design.id.value |
| 485 | ] |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 486 | else: |
| 487 | device_brands = [device_brand_pb2.DeviceBrand()] |
| 488 | |
| 489 | for device_brand in device_brands: |
| 490 | # Brand config can be empty since platform JSON config allows it |
| 491 | brand_config = brand_config_pb2.BrandConfig() |
| 492 | if device_brand.id.value in brand_configs: |
| 493 | brand_config = brand_configs[device_brand.id.value] |
| 494 | |
| 495 | for hw_design_config in hw_design.configs: |
| 496 | design_id = hw_design_config.id.value |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 497 | sw_config_matches = [ |
| 498 | x for x in sw_configs if x.design_config_id.value == design_id |
| 499 | ] |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 500 | if len(sw_config_matches) == 1: |
| 501 | sw_config = sw_config_matches[0] |
| 502 | elif len(sw_config_matches) > 1: |
| 503 | raise Exception('Multiple software configs found for: %s' % design_id) |
| 504 | else: |
| 505 | raise Exception('Software config is required for: %s' % design_id) |
| 506 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 507 | program = _lookup(hw_design.program_id, programs) |
C Shapiro | adefd7c | 2020-05-19 16:37:21 -0500 | [diff] [blame] | 508 | signer_configs_by_design = {} |
| 509 | signer_configs_by_brand = {} |
| 510 | for signer_config in program.device_signer_configs: |
| 511 | design_id = signer_config.design_id.value |
| 512 | brand_id = signer_config.brand_id.value |
| 513 | if design_id: |
| 514 | signer_configs_by_design[design_id] = signer_config |
| 515 | elif brand_id: |
| 516 | signer_configs_by_brand[brand_id] = signer_config |
| 517 | else: |
| 518 | raise Exception('No ID found for signer config: %s' % signer_config) |
| 519 | |
C Shapiro | 2f0bb5d | 2020-04-14 10:07:47 -0500 | [diff] [blame] | 520 | device_signer_config = None |
C Shapiro | adefd7c | 2020-05-19 16:37:21 -0500 | [diff] [blame] | 521 | if signer_configs_by_design or signer_configs_by_brand: |
| 522 | design_id = hw_design.id.value |
| 523 | brand_id = device_brand.id.value |
| 524 | if design_id in signer_configs_by_design: |
| 525 | device_signer_config = signer_configs_by_design[design_id] |
| 526 | elif brand_id in signer_configs_by_brand: |
| 527 | device_signer_config = signer_configs_by_brand[brand_id] |
| 528 | else: |
| 529 | # Assume that if signer configs are set, every config is setup |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 530 | raise Exception('Signer config missing for design: %s, brand: %s' % |
| 531 | (design_id, brand_id)) |
C Shapiro | 2f0bb5d | 2020-04-14 10:07:47 -0500 | [diff] [blame] | 532 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 533 | transformed_config = _transform_build_config( |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 534 | Config( |
| 535 | program=program, |
| 536 | hw_design=hw_design, |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 537 | odm=_lookup(hw_design.odm_id, partners), |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 538 | hw_design_config=hw_design_config, |
| 539 | device_brand=device_brand, |
| 540 | device_signer_config=device_signer_config, |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 541 | oem=_lookup(device_brand.oem_id, partners), |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 542 | sw_config=sw_config, |
| 543 | brand_config=brand_config, |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 544 | build_target=config.build_targets[0]), config_files) |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 545 | |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 546 | config_json = json.dumps( |
| 547 | transformed_config, |
| 548 | sort_keys=True, |
| 549 | indent=2, |
| 550 | separators=(',', ': ')) |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 551 | |
| 552 | if config_json not in results: |
| 553 | results[config_json] = transformed_config |
| 554 | |
| 555 | return list(results.values()) |
| 556 | |
| 557 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 558 | def _transform_build_config(config, config_files): |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 559 | """Transforms Config instance into target platform JSON schema. |
| 560 | |
| 561 | Args: |
| 562 | config: Config namedtuple |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 563 | config_files: Map to look up the generated config files. |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 564 | |
| 565 | Returns: |
| 566 | Unique config payload based on the platform JSON schema. |
| 567 | """ |
| 568 | result = { |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 569 | 'identity': |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 570 | _build_identity(config.sw_config.id_scan_config, config.program, |
| 571 | config.brand_config.scan_config), |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 572 | 'name': |
| 573 | config.hw_design.name.lower(), |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 574 | } |
| 575 | |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 576 | _upsert(_build_arc(config, config_files), result, 'arc') |
| 577 | _upsert(_build_audio(config), result, 'audio') |
| 578 | _upsert(_build_bluetooth(config, config_files.bluetooth), result, 'bluetooth') |
| 579 | _upsert(config.device_brand.brand_code, result, 'brand-code') |
| 580 | _upsert( |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 581 | _build_camera(config.hw_design_config.hardware_topology), result, |
| 582 | 'camera') |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 583 | _upsert(_build_firmware(config), result, 'firmware') |
| 584 | _upsert(_build_fw_signing(config), result, 'firmware-signing') |
| 585 | _upsert( |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 586 | _build_fingerprint(config.hw_design_config.hardware_topology), result, |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 587 | 'fingerprint') |
Andrew Lamb | 0d236ab | 2020-06-30 12:30:20 -0600 | [diff] [blame] | 588 | _upsert(_build_ui(config), result, 'ui') |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 589 | power_prefs = config.sw_config.power_config.preferences |
| 590 | power_prefs_map = dict( |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 591 | (x.replace('_', '-'), power_prefs[x]) for x in power_prefs) |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 592 | _upsert(power_prefs_map, result, 'power') |
| 593 | if config_files.camera_map: |
| 594 | camera_file = config_files.camera_map.get(config.hw_design.name, {}) |
| 595 | _upsert(camera_file, result, 'camera') |
David Burger | 52c9d32 | 2020-06-09 07:16:18 -0600 | [diff] [blame] | 596 | if config_files.dptf_map: |
| 597 | # Prefer design specific if found, if not fall back to project wide config |
| 598 | # mapped under the empty string. |
| 599 | if config_files.dptf_map.get(config.hw_design.name): |
| 600 | dptf_file = config_files.dptf_map[config.hw_design.name] |
| 601 | else: |
| 602 | dptf_file = config_files.dptf_map.get('') |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 603 | _upsert(dptf_file, result, 'thermal') |
| 604 | _upsert(config_files.touch_fw, result, 'touch') |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 605 | |
| 606 | return result |
| 607 | |
| 608 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 609 | def write_output(configs, output=None): |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 610 | """Writes a list of configs to platform JSON format. |
| 611 | |
| 612 | Args: |
| 613 | configs: List of config dicts defined in cros_config_schema.yaml |
| 614 | output: Target file output (if None, prints to stdout) |
| 615 | """ |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 616 | json_output = json.dumps({'chromeos': { |
| 617 | 'configs': configs, |
| 618 | }}, |
| 619 | sort_keys=True, |
| 620 | indent=2, |
| 621 | separators=(',', ': ')) |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 622 | if output: |
| 623 | with open(output, 'w') as output_stream: |
| 624 | # Using print function adds proper trailing newline. |
| 625 | print(json_output, file=output_stream) |
| 626 | else: |
| 627 | print(json_output) |
| 628 | |
| 629 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 630 | def _bluetooth_id(project_name, bt_comp): |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 631 | return '_'.join( |
| 632 | [project_name, bt_comp.vendor_id, bt_comp.product_id, bt_comp.bcd_device]) |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 633 | |
| 634 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 635 | def _feature(name, present): |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 636 | attrib = {'name': name} |
| 637 | if present: |
| 638 | return etree.Element('feature', attrib=attrib) |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 639 | |
| 640 | return etree.Element('unavailable-feature', attrib=attrib) |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 641 | |
| 642 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 643 | def _any_present(features): |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 644 | return topology_pb2.HardwareFeatures.PRESENT in features |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 645 | |
| 646 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 647 | def _arc_hardware_feature_id(design_config): |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 648 | return design_config.id.value.lower().replace(':', '_') |
| 649 | |
| 650 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 651 | def _write_arc_hardware_feature_file(output_dir, file_name, config_content): |
David Burger | 77a1d31 | 2020-05-23 16:05:45 -0600 | [diff] [blame] | 652 | output_dir += '/arc' |
| 653 | os.makedirs(output_dir, exist_ok=True) |
| 654 | output = '%s/%s' % (output_dir, file_name) |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 655 | file_content = minidom.parseString(config_content).toprettyxml( |
| 656 | indent=' ', encoding='utf-8') |
C Shapiro | ea33cff | 2020-05-11 13:32:05 -0500 | [diff] [blame] | 657 | |
| 658 | with open(output, 'wb') as f: |
| 659 | f.write(file_content) |
| 660 | |
| 661 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 662 | def _write_arc_hardware_feature_files(config, output_dir, build_root_dir): |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 663 | """Writes ARC hardware_feature.xml files for each config |
| 664 | |
| 665 | Args: |
| 666 | config: Source ConfigBundle to process. |
| 667 | output_dir: Path to the generated output. |
C Shapiro | 5c87799 | 2020-04-29 12:11:28 -0500 | [diff] [blame] | 668 | build_root_path: Path to the config file from portage's perspective. |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 669 | Returns: |
| 670 | dict that maps the design_config_id onto the correct file. |
| 671 | """ |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 672 | # pylint: disable=too-many-locals |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 673 | result = {} |
C Shapiro | ea33cff | 2020-05-11 13:32:05 -0500 | [diff] [blame] | 674 | configs_by_design = {} |
Sean McAllister | f66887b | 2020-08-03 14:00:51 -0600 | [diff] [blame] | 675 | for hw_design in config.design_list: |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 676 | for design_config in hw_design.configs: |
| 677 | hw_features = design_config.hardware_features |
Kazuhiro Inaba | 76d8bb5 | 2020-06-26 10:34:07 +0900 | [diff] [blame] | 678 | any_camera = hw_features.camera.count.value > 0 |
Josie Nordrum | adc27a7 | 2020-07-08 11:05:26 -0600 | [diff] [blame] | 679 | multi_camera = hw_features.camera.count.value > 1 |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 680 | touchscreen = _any_present([hw_features.screen.touch_support]) |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 681 | acc = hw_features.accelerometer |
| 682 | gyro = hw_features.gyroscope |
| 683 | compass = hw_features.magnetometer |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 684 | light_sensor = hw_features.light_sensor |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 685 | root = etree.Element('permissions') |
| 686 | root.extend([ |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 687 | _feature('android.hardware.camera', multi_camera), |
| 688 | _feature('android.hardware.camera.autofocus', multi_camera), |
Kazuhiro Inaba | 76d8bb5 | 2020-06-26 10:34:07 +0900 | [diff] [blame] | 689 | _feature('android.hardware.camera.any', any_camera), |
| 690 | _feature('android.hardware.camera.front', any_camera), |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 691 | _feature( |
| 692 | 'android.hardware.sensor.accelerometer', |
| 693 | _any_present([acc.lid_accelerometer, acc.base_accelerometer])), |
| 694 | _feature('android.hardware.sensor.gyroscope', |
| 695 | _any_present([gyro.lid_gyroscope, gyro.base_gyroscope])), |
| 696 | _feature( |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 697 | 'android.hardware.sensor.compass', |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 698 | _any_present( |
| 699 | [compass.lid_magnetometer, compass.base_magnetometer])), |
| 700 | _feature( |
| 701 | 'android.hardware.sensor.light', |
| 702 | _any_present( |
| 703 | [light_sensor.lid_lightsensor, |
| 704 | light_sensor.base_lightsensor])), |
| 705 | _feature('android.hardware.touchscreen', touchscreen), |
| 706 | _feature('android.hardware.touchscreen.multitouch', touchscreen), |
| 707 | _feature('android.hardware.touchscreen.multitouch.distinct', |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 708 | touchscreen), |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 709 | _feature('android.hardware.touchscreen.multitouch.jazzhand', |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 710 | touchscreen), |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 711 | ]) |
| 712 | |
C Shapiro | ea33cff | 2020-05-11 13:32:05 -0500 | [diff] [blame] | 713 | design_name = hw_design.name.lower() |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 714 | |
C Shapiro | ea33cff | 2020-05-11 13:32:05 -0500 | [diff] [blame] | 715 | # Constructs the following map: |
| 716 | # design_name -> config -> design_configs |
| 717 | # This allows any of the following file naming schemes: |
| 718 | # - All configs within a design share config (design_name prefix only) |
| 719 | # - Nobody shares (full design_name and config id prefix needed) |
| 720 | # |
| 721 | # Having shared configs when possible makes code reviews easier around |
| 722 | # the configs and makes debugging easier on the platform side. |
| 723 | config_content = etree.tostring(root) |
| 724 | arc_configs = configs_by_design.get(design_name, {}) |
| 725 | design_configs = arc_configs.get(config_content, []) |
| 726 | design_configs.append(design_config) |
| 727 | arc_configs[config_content] = design_configs |
| 728 | configs_by_design[design_name] = arc_configs |
C Shapiro | 9a3ac8c | 2020-04-25 07:49:21 -0500 | [diff] [blame] | 729 | |
C Shapiro | ea33cff | 2020-05-11 13:32:05 -0500 | [diff] [blame] | 730 | for design_name, unique_configs in configs_by_design.items(): |
| 731 | for file_content, design_configs in unique_configs.items(): |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 732 | file_name = 'hardware_features_%s.xml' % design_name |
| 733 | if len(unique_configs) == 1: |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 734 | _write_arc_hardware_feature_file(output_dir, file_name, file_content) |
C Shapiro | 9a3ac8c | 2020-04-25 07:49:21 -0500 | [diff] [blame] | 735 | |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 736 | for design_config in design_configs: |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 737 | feature_id = _arc_hardware_feature_id(design_config) |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 738 | if len(unique_configs) > 1: |
| 739 | file_name = 'hardware_features_%s.xml' % feature_id |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 740 | _write_arc_hardware_feature_file(output_dir, file_name, file_content) |
David Burger | 40dfe3a | 2020-06-18 17:09:13 -0600 | [diff] [blame] | 741 | result[feature_id] = _file_v2('%s/arc/%s' % (build_root_dir, file_name), |
| 742 | '/etc/%s' % file_name) |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 743 | return result |
| 744 | |
| 745 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 746 | def _write_bluetooth_config_files(config, output_dir, build_root_path): |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 747 | """Writes bluetooth conf files for every unique bluetooth chip. |
| 748 | |
| 749 | Args: |
| 750 | config: Source ConfigBundle to process. |
| 751 | output_dir: Path to the generated output. |
C Shapiro | 5c87799 | 2020-04-29 12:11:28 -0500 | [diff] [blame] | 752 | build_root_path: Path to the config file from portage's perspective. |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 753 | Returns: |
| 754 | dict that maps the bluetooth component id onto the file config. |
| 755 | """ |
David Burger | 77a1d31 | 2020-05-23 16:05:45 -0600 | [diff] [blame] | 756 | output_dir += '/bluetooth' |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 757 | result = {} |
Sean McAllister | f66887b | 2020-08-03 14:00:51 -0600 | [diff] [blame] | 758 | for hw_design in config.design_list: |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 759 | project_name = hw_design.name.lower() |
| 760 | for design_config in hw_design.configs: |
C Shapiro | 74da76e | 2020-05-04 13:02:20 -0500 | [diff] [blame] | 761 | bt_comp = design_config.hardware_features.bluetooth.component.usb |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 762 | if bt_comp.vendor_id: |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 763 | bt_id = _bluetooth_id(project_name, bt_comp) |
David Burger | 40dfe3a | 2020-06-18 17:09:13 -0600 | [diff] [blame] | 764 | result[bt_id] = _file_v2( |
| 765 | '%s/bluetooth/%s.conf' % (build_root_path, bt_id), |
| 766 | '/etc/bluetooth/%s/main.conf' % bt_id) |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 767 | bt_content = '''[General] |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 768 | DeviceID = bluetooth:%s:%s:%s''' % (bt_comp.vendor_id, bt_comp.product_id, |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 769 | bt_comp.bcd_device) |
| 770 | |
David Burger | 77a1d31 | 2020-05-23 16:05:45 -0600 | [diff] [blame] | 771 | os.makedirs(output_dir, exist_ok=True) |
| 772 | output = '%s/%s.conf' % (output_dir, bt_id) |
C Shapiro | 90fda25 | 2020-04-17 14:34:57 -0500 | [diff] [blame] | 773 | with open(output, 'w') as output_stream: |
| 774 | # Using print function adds proper trailing newline. |
| 775 | print(bt_content, file=output_stream) |
| 776 | return result |
| 777 | |
| 778 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 779 | def _read_config(path): |
David Burger | d4f3296 | 2020-05-02 12:07:40 -0600 | [diff] [blame] | 780 | """Reads a ConfigBundle proto from a json pb file. |
David Burger | e6f7622 | 2020-04-27 11:08:01 -0600 | [diff] [blame] | 781 | |
| 782 | Args: |
David Burger | d4f3296 | 2020-05-02 12:07:40 -0600 | [diff] [blame] | 783 | path: Path to the file encoding the json pb proto. |
David Burger | e6f7622 | 2020-04-27 11:08:01 -0600 | [diff] [blame] | 784 | """ |
| 785 | config = config_bundle_pb2.ConfigBundle() |
| 786 | with open(path, 'r') as f: |
| 787 | return json_format.Parse(f.read(), config) |
| 788 | |
| 789 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 790 | def _merge_configs(configs): |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 791 | result = config_bundle_pb2.ConfigBundle() |
| 792 | for config in configs: |
| 793 | result.MergeFrom(config) |
| 794 | |
| 795 | return result |
| 796 | |
| 797 | |
David Burger | 1ba78a2 | 2020-06-18 18:42:47 -0600 | [diff] [blame] | 798 | def _camera_map(configs, project_name): |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 799 | """Produces a camera config map for the given configs. |
| 800 | |
| 801 | Produces a map that maps from the design name to the camera config for that |
| 802 | design. |
| 803 | |
| 804 | Args: |
| 805 | configs: Source ConfigBundle to process. |
David Burger | 1ba78a2 | 2020-06-18 18:42:47 -0600 | [diff] [blame] | 806 | project_name: Name of project processing for. |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 807 | |
| 808 | Returns: |
| 809 | map from design name to camera config. |
| 810 | """ |
| 811 | result = {} |
Sean McAllister | f66887b | 2020-08-03 14:00:51 -0600 | [diff] [blame] | 812 | for design in configs.design_list: |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 813 | design_name = design.name |
David Burger | 0d9e846 | 2020-06-19 14:12:37 -0600 | [diff] [blame] | 814 | config_path = CAMERA_CONFIG_SOURCE_PATH_TEMPLATE.format(design_name.lower()) |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 815 | if os.path.exists(config_path): |
David Burger | 0d9e846 | 2020-06-19 14:12:37 -0600 | [diff] [blame] | 816 | destination = CAMERA_CONFIG_DEST_PATH_TEMPLATE.format(design_name.lower()) |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 817 | result[design_name] = { |
David Burger | 1ba78a2 | 2020-06-18 18:42:47 -0600 | [diff] [blame] | 818 | 'config-path': |
| 819 | destination, |
| 820 | 'config-file': |
| 821 | _file_v2(os.path.join(project_name, config_path), destination), |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 822 | } |
| 823 | return result |
| 824 | |
| 825 | |
David Burger | 2f0d952 | 2020-07-30 10:52:28 -0600 | [diff] [blame] | 826 | def _config_map(configs, config_dir, config_file, system_dir): |
| 827 | """Produces a config map for the given configs. |
| 828 | |
| 829 | Produces a map that maps from design name to the config file for that |
| 830 | design. It looks for the config files at: |
| 831 | config_dir + '/' + config_file |
| 832 | for a project wide config, that it maps under the empty string, and at: |
| 833 | config_dir + '/' + design_name + '/' + config_file |
| 834 | for design specific configs that it maps under the design name. |
| 835 | |
| 836 | Args: |
| 837 | configs: Source ConfigBundle to process. |
| 838 | config_dir: Path to the directory containing configuration files. |
| 839 | config_file: Name of the configuration files. |
| 840 | system_dir: Base directory for the output system path. |
| 841 | |
| 842 | Returns: |
| 843 | map from design name or empty string (project wide), to config. |
| 844 | """ |
| 845 | result = {} |
| 846 | # Looking at top level for project wide, and then for each design name |
| 847 | # for design specific. |
| 848 | dirs = [""] + [d.name for d in configs.designs.value] |
| 849 | for directory in dirs: |
| 850 | design = directory.lower() |
| 851 | build_path = os.path.join(config_dir, design, config_file) |
| 852 | if os.path.exists(build_path): |
| 853 | if design: |
| 854 | system_file = config_file.replace('.', '_{}.'.format(design)) |
| 855 | else: |
| 856 | system_file = config_file |
| 857 | system_path = os.path.join(system_dir, system_file) |
| 858 | result[directory] = _file_v2(build_path, system_path) |
| 859 | return result |
| 860 | |
| 861 | |
David Burger | 52c9d32 | 2020-06-09 07:16:18 -0600 | [diff] [blame] | 862 | def _dptf_map(configs, project_name): |
| 863 | """Produces a dptf map for the given configs. |
| 864 | |
| 865 | Produces a map that maps from design name to the dptf file config for that |
| 866 | design. It looks for the dptf files at: |
David Burger | 2f0d952 | 2020-07-30 10:52:28 -0600 | [diff] [blame] | 867 | DPTF_PATH + '/' + DPTF_FILE |
David Burger | 52c9d32 | 2020-06-09 07:16:18 -0600 | [diff] [blame] | 868 | for a project wide config, that it maps under the empty string, and at: |
David Burger | 2f0d952 | 2020-07-30 10:52:28 -0600 | [diff] [blame] | 869 | DPTF_PATH + '/' + design_name + '/' + DPTF_FILE |
David Burger | 52c9d32 | 2020-06-09 07:16:18 -0600 | [diff] [blame] | 870 | for design specific configs that it maps under the design name. |
| 871 | |
| 872 | Args: |
| 873 | configs: Source ConfigBundle to process. |
| 874 | project_name: Name of project processing for. |
| 875 | |
| 876 | Returns: |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 877 | map from design name or empty string (project wide), to dptf config. |
David Burger | 52c9d32 | 2020-06-09 07:16:18 -0600 | [diff] [blame] | 878 | """ |
| 879 | result = {} |
David Burger | 52c9d32 | 2020-06-09 07:16:18 -0600 | [diff] [blame] | 880 | # Looking at top level for project wide, and then for each design name |
| 881 | # for design specific. |
Sean McAllister | f66887b | 2020-08-03 14:00:51 -0600 | [diff] [blame] | 882 | dirs = [""] + [d.name for d in configs.design_list] |
David Burger | 52c9d32 | 2020-06-09 07:16:18 -0600 | [diff] [blame] | 883 | for directory in dirs: |
David Burger | a225276 | 2020-07-09 15:09:49 -0600 | [diff] [blame] | 884 | design = directory.lower() |
| 885 | if os.path.exists(os.path.join(DPTF_PATH, design, DPTF_FILE)): |
David Burger | 2f0d952 | 2020-07-30 10:52:28 -0600 | [diff] [blame] | 886 | project_dptf_path = os.path.join(project_name, design, DPTF_FILE) |
David Burger | 52c9d32 | 2020-06-09 07:16:18 -0600 | [diff] [blame] | 887 | dptf_file = { |
| 888 | 'dptf-dv': |
| 889 | project_dptf_path, |
| 890 | 'files': [ |
| 891 | _file( |
David Burger | a225276 | 2020-07-09 15:09:49 -0600 | [diff] [blame] | 892 | os.path.join(project_name, DPTF_PATH, design, DPTF_FILE), |
David Burger | 52c9d32 | 2020-06-09 07:16:18 -0600 | [diff] [blame] | 893 | os.path.join('/etc/dptf', project_dptf_path)) |
| 894 | ] |
| 895 | } |
| 896 | result[directory] = dptf_file |
| 897 | return result |
| 898 | |
| 899 | |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 900 | def Main(project_configs, program_config, output): # pylint: disable=invalid-name |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 901 | """Transforms source proto config into platform JSON. |
| 902 | |
| 903 | Args: |
| 904 | project_configs: List of source project configs to transform. |
| 905 | program_config: Program config for the given set of projects. |
| 906 | output: Output file that will be generated by the transform. |
| 907 | """ |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 908 | configs = _merge_configs([_read_config(program_config)] + |
| 909 | [_read_config(config) for config in project_configs]) |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 910 | bluetooth_files = {} |
| 911 | arc_hw_feature_files = {} |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 912 | touch_fw = {} |
David Burger | 2f0d952 | 2020-07-30 10:52:28 -0600 | [diff] [blame] | 913 | arc_camera_map = {} |
David Burger | 52c9d32 | 2020-06-09 07:16:18 -0600 | [diff] [blame] | 914 | dptf_map = {} |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 915 | camera_map = {} |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 916 | output_dir = os.path.dirname(output) |
C Shapiro | 5c87799 | 2020-04-29 12:11:28 -0500 | [diff] [blame] | 917 | build_root_dir = output_dir |
C Shapiro | 5c87799 | 2020-04-29 12:11:28 -0500 | [diff] [blame] | 918 | if 'sw_build_config' in output_dir: |
| 919 | full_path = os.path.realpath(output) |
Andrew Lamb | 2413c98 | 2020-05-29 12:15:36 -0600 | [diff] [blame] | 920 | project_name = re.match(r'.*/(\w*)/sw_build_config/.*', |
| 921 | full_path).groups(1)[0] |
C Shapiro | 5c87799 | 2020-04-29 12:11:28 -0500 | [diff] [blame] | 922 | # Projects don't know about each other until they are integrated into the |
| 923 | # build system. When this happens, the files need to be able to co-exist |
| 924 | # without any collisions. This prefixes the project name (which is how |
| 925 | # portage maps in the project), so project files co-exist and can be |
| 926 | # installed together. |
| 927 | # This is necessary to allow projects to share files at the program level |
| 928 | # without having portage file installation collisions. |
| 929 | build_root_dir = os.path.join(project_name, output_dir) |
C Shapiro | 6830e6c | 2020-04-29 13:29:56 -0500 | [diff] [blame] | 930 | |
David Burger | 2f0d952 | 2020-07-30 10:52:28 -0600 | [diff] [blame] | 931 | arc_camera_map = _config_map(configs, ARC_CONFIG_PATH, |
| 932 | ARC_CAMERA_CHARACTERISTICS_FILE, '/etc/arc') |
David Burger | 1ba78a2 | 2020-06-18 18:42:47 -0600 | [diff] [blame] | 933 | camera_map = _camera_map(configs, project_name) |
David Burger | 52c9d32 | 2020-06-09 07:16:18 -0600 | [diff] [blame] | 934 | dptf_map = _dptf_map(configs, project_name) |
| 935 | |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 936 | if os.path.exists(TOUCH_PATH): |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 937 | touch_fw = _build_touch_file_config(configs, project_name) |
| 938 | bluetooth_files = _write_bluetooth_config_files(configs, output_dir, |
| 939 | build_root_dir) |
| 940 | arc_hw_feature_files = _write_arc_hardware_feature_files( |
| 941 | configs, output_dir, build_root_dir) |
C Shapiro | 5bf23a7 | 2020-04-24 11:40:17 -0500 | [diff] [blame] | 942 | config_files = ConfigFiles( |
| 943 | bluetooth=bluetooth_files, |
| 944 | arc_hw_features=arc_hw_feature_files, |
C Shapiro | 2b6d533 | 2020-05-06 17:51:35 -0500 | [diff] [blame] | 945 | touch_fw=touch_fw, |
David Burger | 8ee9b4d | 2020-06-16 17:40:21 -0600 | [diff] [blame] | 946 | dptf_map=dptf_map, |
David Burger | 2f0d952 | 2020-07-30 10:52:28 -0600 | [diff] [blame] | 947 | camera_map=camera_map, |
| 948 | arc_camera_map=arc_camera_map) |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 949 | write_output(_transform_build_configs(configs, config_files), output) |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 950 | |
| 951 | |
| 952 | def main(argv=None): |
| 953 | """Main program which parses args and runs |
| 954 | |
| 955 | Args: |
| 956 | argv: List of command line arguments, if None uses sys.argv. |
| 957 | """ |
| 958 | if argv is None: |
| 959 | argv = sys.argv[1:] |
Andrew Lamb | cd33f70 | 2020-06-11 10:45:16 -0600 | [diff] [blame] | 960 | opts = parse_args(argv) |
David Burger | 7fd1dbe | 2020-03-26 09:26:55 -0600 | [diff] [blame] | 961 | Main(opts.project_configs, opts.program_config, opts.output) |
| 962 | |
| 963 | |
| 964 | if __name__ == '__main__': |
| 965 | sys.exit(main(sys.argv[1:])) |