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