blob: 0cf9b1e4df6bb37574861e5240a78f8c4d9128b6 [file] [log] [blame]
David Burger7fd1dbe2020-03-26 09:26:55 -06001#!/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
8import argparse
9import json
10import pprint
C Shapiro90fda252020-04-17 14:34:57 -050011import os
David Burger7fd1dbe2020-03-26 09:26:55 -060012import sys
C Shapiro90fda252020-04-17 14:34:57 -050013import re
C Shapiro5bf23a72020-04-24 11:40:17 -050014import xml.etree.ElementTree as etree
C Shapiro9a3ac8c2020-04-25 07:49:21 -050015import xml.dom.minidom as minidom
David Burger7fd1dbe2020-03-26 09:26:55 -060016
Andrew Lamb319cc922020-06-15 10:45:46 -060017from typing import List
18
David Burger7fd1dbe2020-03-26 09:26:55 -060019from collections import namedtuple
20
Andrew Lambcd33f702020-06-11 10:45:16 -060021from google.protobuf import json_format
22
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070023from chromiumos.config.api import device_brand_pb2
David Burger92609a32020-04-23 10:38:50 -060024from chromiumos.config.api import topology_pb2
C Shapiro5bf23a72020-04-24 11:40:17 -050025from chromiumos.config.payload import config_bundle_pb2
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070026from chromiumos.config.api.software import brand_config_pb2
David Burger7fd1dbe2020-03-26 09:26:55 -060027
Andrew Lamb2413c982020-05-29 12:15:36 -060028Config = 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 Burger7fd1dbe2020-03-26 09:26:55 -060032
Andrew Lamb2413c982020-05-29 12:15:36 -060033ConfigFiles = namedtuple(
David Burger8ee9b4d2020-06-16 17:40:21 -060034 'ConfigFiles',
35 ['bluetooth', 'arc_hw_features', 'touch_fw', 'dptf_map', 'camera_map'])
36
37CAMERA_CONFIG_DEST_PATH_TEMPLATE = '/etc/camera/camera_config_{}.json'
38CAMERA_CONFIG_SOURCE_PATH_TEMPLATE = (
39 'sw_build_config/platform/chromeos-config/camera/camera_config_{}.json')
C Shapiro5bf23a72020-04-24 11:40:17 -050040
David Burger52c9d322020-06-09 07:16:18 -060041DPTF_PATH = 'sw_build_config/platform/chromeos-config/thermal'
42DPTF_FILE = 'dptf.dv'
C Shapiro2b6d5332020-05-06 17:51:35 -050043TOUCH_PATH = 'sw_build_config/platform/chromeos-config/touch'
Andrew Lamb6c42efc2020-06-16 10:40:43 -060044WALLPAPER_BASE_PATH = '/usr/share/chromeos-assets/wallpaper'
David Burger7fd1dbe2020-03-26 09:26:55 -060045
Andrew Lamb2413c982020-05-29 12:15:36 -060046
Andrew Lambcd33f702020-06-11 10:45:16 -060047def parse_args(argv):
David Burger7fd1dbe2020-03-26 09:26:55 -060048 """Parse the available arguments.
49
50 Invalid arguments or -h cause this function to print a message and exit.
51
52 Args:
53 argv: List of string arguments (excluding program name / argv[0])
54
55 Returns:
56 argparse.Namespace object containing the attributes.
57 """
58 parser = argparse.ArgumentParser(
59 description='Converts source proto config into platform JSON config.')
60 parser.add_argument(
61 '-c',
62 '--project_configs',
63 nargs='+',
64 type=str,
65 help='Space delimited list of source protobinary project config files.')
66 parser.add_argument(
67 '-p',
68 '--program_config',
69 type=str,
70 help='Path to the source program-level protobinary file')
71 parser.add_argument(
Andrew Lamb2413c982020-05-29 12:15:36 -060072 '-o', '--output', type=str, help='Output file that will be generated')
David Burger7fd1dbe2020-03-26 09:26:55 -060073 return parser.parse_args(argv)
74
75
David Burger8ee9b4d2020-06-16 17:40:21 -060076def _upsert(field, target, target_name):
77 """Updates or inserts `field` within `target`.
78
79 If `target_name` already exists within `target` an update is performed,
80 otherwise, an insert is performed.
81 """
Sam McNally9a873f72020-06-05 19:47:22 +100082 if field or field == 0:
David Burger8ee9b4d2020-06-16 17:40:21 -060083 if target_name in target:
84 target[target_name].update(field)
85 else:
86 target[target_name] = field
David Burger7fd1dbe2020-03-26 09:26:55 -060087
88
Andrew Lambcd33f702020-06-11 10:45:16 -060089def _build_arc(config, config_files):
90 if not config.build_target.arc:
91 return None
92
93 build_properties = {
94 'device': config.build_target.arc.device,
95 'first-api-level': config.build_target.arc.first_api_level,
96 'marketing-name': config.device_brand.brand_name,
97 'metrics-tag': config.hw_design.name.lower(),
98 'product': config.build_target.id.value,
99 }
100 if config.oem:
101 build_properties['oem'] = config.oem.name
102 result = {'build-properties': build_properties}
103 feature_id = _arc_hardware_feature_id(config.hw_design_config)
104 if feature_id in config_files.arc_hw_features:
105 result['hardware-features'] = config_files.arc_hw_features[feature_id]
106 topology = config.hw_design_config.hardware_topology
107 ppi = topology.screen.hardware_feature.screen.panel_properties.pixels_per_in
108 # Only set for high resolution displays
109 if ppi and ppi > 250:
110 result['scale'] = ppi
111 return result
David Burger7fd1dbe2020-03-26 09:26:55 -0600112
Andrew Lamb2413c982020-05-29 12:15:36 -0600113
Andrew Lamb319cc922020-06-15 10:45:46 -0600114def _build_ash_flags(config: Config) -> List[str]:
115 """Returns a list of Ash flags for config.
116
117 Ash is the window manager and system UI for ChromeOS, see
118 https://chromium.googlesource.com/chromium/src/+/refs/heads/master/ash/.
119 """
120 # A map from flag name -> value. Value may be None for boolean flags.
121 flags = {}
122
123 hw_features = config.hw_design_config.hardware_features
124 if hw_features.stylus.stylus == topology_pb2.HardwareFeatures.Stylus.INTERNAL:
Andrew Lamb2e641e22020-06-15 12:30:41 -0600125 flags['has-internal-stylus'] = None
Andrew Lamb319cc922020-06-15 10:45:46 -0600126
Andrew Lamb2e641e22020-06-15 12:30:41 -0600127 fp_loc = hw_features.fingerprint.location
128 if fp_loc and fp_loc != topology_pb2.HardwareFeatures.Fingerprint.NOT_PRESENT:
129 loc_name = topology_pb2.HardwareFeatures.Fingerprint.Location.Name(fp_loc)
130 flags['fingerprint-sensor-location'] = loc_name.lower().replace('_', '-')
131
Andrew Lamb6c42efc2020-06-16 10:40:43 -0600132 wallpaper = config.brand_config.wallpaper
133 # If a wallpaper is set, the 'default-wallpaper-is-oem' flag needs to be set.
134 # If a wallpaper is not set, the 'default_[large|small].jpg' wallpapers
135 # should still be set.
136 if wallpaper:
137 flags['default-wallpaper-is-oem'] = None
138 else:
139 wallpaper = 'default'
140
141 for size in ('small', 'large'):
142 flags[f'default-wallpaper-{size}'] = (
143 f'{WALLPAPER_BASE_PATH}/{wallpaper}_{size}.jpg')
144
145 # For each size, also install 'guest' and 'child' wallpapers.
146 for wallpaper_type in ('guest', 'child'):
147 flags[f'{wallpaper_type}-wallpaper-{size}'] = (
148 f'{WALLPAPER_BASE_PATH}/{wallpaper_type}_{size}.jpg')
149
Andrew Lamb72d41362020-06-17 09:19:02 -0600150 flags['arc-build-properties'] = json_format.MessageToDict(
151 config.build_target.arc)
152
Andrew Lamb2e641e22020-06-15 12:30:41 -0600153 return sorted([f'--{k}={v}' if v else f'--{k}' for k, v in flags.items()])
Andrew Lamb319cc922020-06-15 10:45:46 -0600154
155
156def _build_ui(config: Config) -> dict:
157 """Builds the 'ui' property from cros_config_schema."""
158 return {'extra-ash-flags': _build_ash_flags(config)}
159
160
Andrew Lambcd33f702020-06-11 10:45:16 -0600161def _build_bluetooth(config, bluetooth_files):
C Shapiro90fda252020-04-17 14:34:57 -0500162 bt_flags = config.sw_config.bluetooth_config.flags
163 # Convert to native map (from proto wrapper)
164 bt_flags_map = dict(bt_flags)
165 result = {}
166 if bt_flags_map:
167 result['flags'] = bt_flags_map
C Shapiro74da76e2020-05-04 13:02:20 -0500168 bt_comp = config.hw_design_config.hardware_features.bluetooth.component.usb
C Shapiro90fda252020-04-17 14:34:57 -0500169 if bt_comp.vendor_id:
Andrew Lambcd33f702020-06-11 10:45:16 -0600170 bt_id = _bluetooth_id(config.hw_design.name.lower(), bt_comp)
C Shapiro90fda252020-04-17 14:34:57 -0500171 if bt_id in bluetooth_files:
172 result['config'] = bluetooth_files[bt_id]
173 return result
174
David Burger7fd1dbe2020-03-26 09:26:55 -0600175
Andrew Lambcd33f702020-06-11 10:45:16 -0600176def _build_fingerprint(hw_topology):
177 if not hw_topology.HasField('fingerprint'):
178 return None
179
180 fp = hw_topology.fingerprint.hardware_feature.fingerprint
181 result = {}
182 if fp.location != topology_pb2.HardwareFeatures.Fingerprint.NOT_PRESENT:
183 location = fp.Location.DESCRIPTOR.values_by_number[fp.location].name
184 result['sensor-location'] = location.lower().replace('_', '-')
185 if fp.board:
186 result['board'] = fp.board
187 return result
David Burger7fd1dbe2020-03-26 09:26:55 -0600188
189
Andrew Lambcd33f702020-06-11 10:45:16 -0600190def _fw_bcs_path(payload):
David Burger7fd1dbe2020-03-26 09:26:55 -0600191 if payload and payload.firmware_image_name:
Andrew Lamb2413c982020-05-29 12:15:36 -0600192 return 'bcs://%s.%d.%d.0.tbz2' % (payload.firmware_image_name,
193 payload.version.major,
194 payload.version.minor)
David Burger7fd1dbe2020-03-26 09:26:55 -0600195
Andrew Lambcd33f702020-06-11 10:45:16 -0600196 return None
David Burger7fd1dbe2020-03-26 09:26:55 -0600197
Andrew Lambcd33f702020-06-11 10:45:16 -0600198
199def _fw_build_target(payload):
David Burger7fd1dbe2020-03-26 09:26:55 -0600200 if payload:
201 return payload.build_target_name
202
Andrew Lambcd33f702020-06-11 10:45:16 -0600203 return None
David Burger7fd1dbe2020-03-26 09:26:55 -0600204
Andrew Lambcd33f702020-06-11 10:45:16 -0600205
206def _build_firmware(config):
David Burgerb70b6762020-05-21 12:14:59 -0600207 """Returns firmware config, or None if no build targets."""
Andrew Lamb3da156d2020-04-16 16:00:56 -0600208 fw_payload_config = config.sw_config.firmware
209 fw_build_config = config.sw_config.firmware_build_config
210 main_ro = fw_payload_config.main_ro_payload
211 main_rw = fw_payload_config.main_rw_payload
212 ec_ro = fw_payload_config.ec_ro_payload
213 pd_ro = fw_payload_config.pd_ro_payload
David Burger7fd1dbe2020-03-26 09:26:55 -0600214
215 build_targets = {}
Andrew Lamb3da156d2020-04-16 16:00:56 -0600216
David Burger8ee9b4d2020-06-16 17:40:21 -0600217 _upsert(fw_build_config.build_targets.depthcharge, build_targets,
218 'depthcharge')
219 _upsert(fw_build_config.build_targets.coreboot, build_targets, 'coreboot')
220 _upsert(fw_build_config.build_targets.ec, build_targets, 'ec')
221 _upsert(
Andrew Lambf8954ee2020-04-21 10:24:40 -0600222 list(fw_build_config.build_targets.ec_extras), build_targets, 'ec_extras')
David Burger8ee9b4d2020-06-16 17:40:21 -0600223 _upsert(fw_build_config.build_targets.libpayload, build_targets, 'libpayload')
David Burger7fd1dbe2020-03-26 09:26:55 -0600224
David Burgerb70b6762020-05-21 12:14:59 -0600225 if not build_targets:
226 return None
227
David Burger7fd1dbe2020-03-26 09:26:55 -0600228 result = {
229 'bcs-overlay': config.build_target.overlay_name,
230 'build-targets': build_targets,
David Burger7fd1dbe2020-03-26 09:26:55 -0600231 }
Andrew Lamb883fa042020-04-06 11:37:22 -0600232
David Burger8ee9b4d2020-06-16 17:40:21 -0600233 _upsert(main_ro.firmware_image_name.lower(), result, 'image-name')
Andrew Lamb883fa042020-04-06 11:37:22 -0600234
David Burger8ee9b4d2020-06-16 17:40:21 -0600235 _upsert(_fw_bcs_path(main_ro), result, 'main-ro-image')
236 _upsert(_fw_bcs_path(main_rw), result, 'main-rw-image')
237 _upsert(_fw_bcs_path(ec_ro), result, 'ec-ro-image')
238 _upsert(_fw_bcs_path(pd_ro), result, 'pd-ro-image')
David Burger7fd1dbe2020-03-26 09:26:55 -0600239
David Burger8ee9b4d2020-06-16 17:40:21 -0600240 _upsert(
Andrew Lambf39fbe82020-04-13 16:14:33 -0600241 config.hw_design_config.hardware_features.fw_config.value,
242 result,
243 'firmware-config',
244 )
245
David Burger7fd1dbe2020-03-26 09:26:55 -0600246 return result
247
248
Andrew Lambcd33f702020-06-11 10:45:16 -0600249def _build_fw_signing(config):
C Shapiro2f0bb5d2020-04-14 10:07:47 -0500250 if config.sw_config.firmware and config.device_signer_config:
David Burger68e0d142020-05-15 17:29:33 -0600251 hw_design = config.hw_design.name.lower()
C Shapiro2f0bb5d2020-04-14 10:07:47 -0500252 return {
253 'key-id': config.device_signer_config.key_id,
C Shapiro10e9a612020-05-19 17:06:43 -0500254 # TODO(shapiroc): Need to fix for whitelabel.
255 # Whitelabel will collide on unique signature-id values.
David Burger68e0d142020-05-15 17:29:33 -0600256 'signature-id': hw_design,
C Shapiro2f0bb5d2020-04-14 10:07:47 -0500257 }
258 return {}
David Burger7fd1dbe2020-03-26 09:26:55 -0600259
260
Andrew Lambcd33f702020-06-11 10:45:16 -0600261def _file(source, destination):
Andrew Lamb2413c982020-05-29 12:15:36 -0600262 return {'destination': destination, 'source': source}
David Burger7fd1dbe2020-03-26 09:26:55 -0600263
264
Andrew Lambcd33f702020-06-11 10:45:16 -0600265def _build_audio(config):
David Burger7fd1dbe2020-03-26 09:26:55 -0600266 alsa_path = '/usr/share/alsa/ucm'
267 cras_path = '/etc/cras'
268 project_name = config.hw_design.name.lower()
David Burger43250662020-05-07 11:21:50 -0600269 program_name = config.program.name.lower()
Andrew Lamb7d536782020-04-07 10:23:55 -0600270 if not config.sw_config.HasField('audio_config'):
David Burger7fd1dbe2020-03-26 09:26:55 -0600271 return {}
272 audio = config.sw_config.audio_config
273 card = audio.card_name
David Burger599ff7b2020-04-06 16:29:31 -0600274 card_with_suffix = audio.card_name
275 if audio.ucm_suffix:
276 card_with_suffix += '.' + audio.ucm_suffix
David Burger7fd1dbe2020-03-26 09:26:55 -0600277 files = []
278 if audio.ucm_file:
Andrew Lamb2413c982020-05-29 12:15:36 -0600279 files.append(
Andrew Lambcd33f702020-06-11 10:45:16 -0600280 _file(audio.ucm_file,
Andrew Lamb2413c982020-05-29 12:15:36 -0600281 '%s/%s/HiFi.conf' % (alsa_path, card_with_suffix)))
David Burger7fd1dbe2020-03-26 09:26:55 -0600282 if audio.ucm_master_file:
Andrew Lamb2413c982020-05-29 12:15:36 -0600283 files.append(
Andrew Lambcd33f702020-06-11 10:45:16 -0600284 _file(audio.ucm_master_file, '%s/%s/%s.conf' %
Andrew Lamb2413c982020-05-29 12:15:36 -0600285 (alsa_path, card_with_suffix, card_with_suffix)))
David Burger7fd1dbe2020-03-26 09:26:55 -0600286 if audio.card_config_file:
Andrew Lamb2413c982020-05-29 12:15:36 -0600287 files.append(
Andrew Lambcd33f702020-06-11 10:45:16 -0600288 _file(audio.card_config_file,
Andrew Lamb2413c982020-05-29 12:15:36 -0600289 '%s/%s/%s' % (cras_path, project_name, card)))
David Burger7fd1dbe2020-03-26 09:26:55 -0600290 if audio.dsp_file:
291 files.append(
Andrew Lambcd33f702020-06-11 10:45:16 -0600292 _file(audio.dsp_file, '%s/%s/dsp.ini' % (cras_path, project_name)))
David Burgere1a37492020-05-06 09:29:24 -0600293 if audio.module_file:
294 files.append(
Andrew Lambcd33f702020-06-11 10:45:16 -0600295 _file(audio.module_file, '/etc/modprobe.d/alsa-%s.conf' % program_name))
David Burgere1a37492020-05-06 09:29:24 -0600296 if audio.board_file:
297 files.append(
Andrew Lambcd33f702020-06-11 10:45:16 -0600298 _file(audio.board_file, '%s/%s/board.ini' % (cras_path, project_name)))
David Burger599ff7b2020-04-06 16:29:31 -0600299
300 result = {
David Burger7fd1dbe2020-03-26 09:26:55 -0600301 'main': {
302 'cras-config-dir': project_name,
303 'files': files,
304 }
305 }
David Burger599ff7b2020-04-06 16:29:31 -0600306 if audio.ucm_suffix:
David Burger03cdcbd2020-04-13 13:54:48 -0600307 result['main']['ucm-suffix'] = audio.ucm_suffix
David Burger599ff7b2020-04-06 16:29:31 -0600308
309 return result
David Burger7fd1dbe2020-03-26 09:26:55 -0600310
311
Andrew Lambcd33f702020-06-11 10:45:16 -0600312def _build_camera(hw_topology):
David Burger8aa8fa32020-04-14 08:30:34 -0600313 if hw_topology.HasField('camera'):
314 camera = hw_topology.camera.hardware_feature.camera
315 result = {}
316 if camera.count.value:
317 result['count'] = camera.count.value
318 return result
319
Andrew Lambcd33f702020-06-11 10:45:16 -0600320 return None
David Burger8aa8fa32020-04-14 08:30:34 -0600321
Andrew Lambcd33f702020-06-11 10:45:16 -0600322
323def _build_identity(hw_scan_config, program, brand_scan_config=None):
David Burger7fd1dbe2020-03-26 09:26:55 -0600324 identity = {}
David Burger8ee9b4d2020-06-16 17:40:21 -0600325 _upsert(hw_scan_config.firmware_sku, identity, 'sku-id')
326 _upsert(hw_scan_config.smbios_name_match, identity, 'smbios-name-match')
Andrew Lamb7806ce92020-04-07 10:22:17 -0600327 # 'platform-name' is needed to support 'mosys platform name'. Clients should
328 # longer require platform name, but set it here for backwards compatibility.
David Burger8ee9b4d2020-06-16 17:40:21 -0600329 _upsert(program.name, identity, 'platform-name')
David Burger7fd1dbe2020-03-26 09:26:55 -0600330 # ARM architecture
David Burger8ee9b4d2020-06-16 17:40:21 -0600331 _upsert(hw_scan_config.device_tree_compatible_match, identity,
332 'device-tree-compatible-match')
David Burger7fd1dbe2020-03-26 09:26:55 -0600333
334 if brand_scan_config:
David Burger8ee9b4d2020-06-16 17:40:21 -0600335 _upsert(brand_scan_config.whitelabel_tag, identity, 'whitelabel-tag')
David Burger7fd1dbe2020-03-26 09:26:55 -0600336
337 return identity
338
339
Andrew Lambcd33f702020-06-11 10:45:16 -0600340def _lookup(id_value, id_map):
341 if not id_value.value:
342 return None
343
344 key = id_value.value
345 if key in id_map:
346 return id_map[id_value.value]
347 error = 'Failed to lookup %s with value: %s' % (
348 id_value.__class__.__name__.replace('Id', ''), key)
349 print(error)
350 print('Check the config contents provided:')
351 printer = pprint.PrettyPrinter(indent=4)
352 printer.pprint(id_map)
353 raise Exception(error)
David Burger7fd1dbe2020-03-26 09:26:55 -0600354
355
Andrew Lambcd33f702020-06-11 10:45:16 -0600356def _build_touch_file_config(config, project_name):
357 partners = {x.id.value: x for x in config.partners.value}
C Shapiro2b6d5332020-05-06 17:51:35 -0500358 files = []
359 for comp in config.components:
C Shapiro4813be62020-05-13 17:31:58 -0500360 touch = comp.touchscreen
361 # Everything is the same for Touch screen/pad, except different fields
362 if comp.HasField('touchpad'):
363 touch = comp.touchpad
364 if touch.product_id:
Andrew Lambcd33f702020-06-11 10:45:16 -0600365 vendor = _lookup(comp.manufacturer_id, partners)
C Shapiro2b6d5332020-05-06 17:51:35 -0500366 if not vendor:
Andrew Lamb2413c982020-05-29 12:15:36 -0600367 raise Exception("Manufacturer must be set for touch device %s" %
368 comp.id.value)
C Shapiro2b6d5332020-05-06 17:51:35 -0500369
C Shapiro4813be62020-05-13 17:31:58 -0500370 product_id = touch.product_id
371 fw_version = touch.fw_version
C Shapiro2b6d5332020-05-06 17:51:35 -0500372
C Shapiro5c6fc212020-05-13 16:32:09 -0500373 touch_vendor = vendor.touch_vendor
374 sym_link = touch_vendor.fw_file_format.format(
Andrew Lamb2413c982020-05-29 12:15:36 -0600375 vendor_name=vendor.name,
376 vendor_id=touch_vendor.vendor_id,
377 product_id=product_id,
378 fw_version=fw_version,
379 product_series=touch.product_series)
C Shapiro2b6d5332020-05-06 17:51:35 -0500380
381 file_name = "%s_%s.bin" % (product_id, fw_version)
382 fw_file_path = os.path.join(TOUCH_PATH, vendor.name, file_name)
383
384 if not os.path.exists(fw_file_path):
Andrew Lamb2413c982020-05-29 12:15:36 -0600385 raise Exception("Touchscreen fw bin file doesn't exist at: %s" %
386 fw_file_path)
C Shapiro2b6d5332020-05-06 17:51:35 -0500387
388 files.append({
Andrew Lamb2413c982020-05-29 12:15:36 -0600389 "destination":
390 "/opt/google/touch/firmware/%s_%s" % (vendor.name, file_name),
391 "source":
392 os.path.join(project_name, fw_file_path),
393 "symlink":
394 os.path.join("/lib/firmware", sym_link),
C Shapiro2b6d5332020-05-06 17:51:35 -0500395 })
396
397 result = {}
David Burger8ee9b4d2020-06-16 17:40:21 -0600398 _upsert(files, result, 'files')
C Shapiro2b6d5332020-05-06 17:51:35 -0500399 return result
400
401
David Burger8ee9b4d2020-06-16 17:40:21 -0600402def _transform_build_configs(config,
403 config_files=ConfigFiles({}, {}, {}, {}, {})):
Andrew Lambcd33f702020-06-11 10:45:16 -0600404 # pylint: disable=too-many-locals,too-many-branches
405 partners = {x.id.value: x for x in config.partners.value}
406 programs = {x.id.value: x for x in config.programs.value}
David Burger7fd1dbe2020-03-26 09:26:55 -0600407 sw_configs = list(config.software_configs)
Andrew Lambcd33f702020-06-11 10:45:16 -0600408 brand_configs = {x.brand_id.value: x for x in config.brand_configs}
David Burger7fd1dbe2020-03-26 09:26:55 -0600409
C Shapiroa0b766c2020-03-31 08:35:28 -0500410 if len(config.build_targets) != 1:
411 # Artifact of sharing the config_bundle for analysis and transforms.
412 # Integrated analysis of multiple programs/projects it the only time
413 # having multiple build targets would be valid.
414 raise Exception('Single build_target required for transform')
415
David Burger7fd1dbe2020-03-26 09:26:55 -0600416 results = {}
417 for hw_design in config.designs.value:
418 if config.device_brands.value:
Andrew Lamb2413c982020-05-29 12:15:36 -0600419 device_brands = [
420 x for x in config.device_brands.value
421 if x.design_id.value == hw_design.id.value
422 ]
David Burger7fd1dbe2020-03-26 09:26:55 -0600423 else:
424 device_brands = [device_brand_pb2.DeviceBrand()]
425
426 for device_brand in device_brands:
427 # Brand config can be empty since platform JSON config allows it
428 brand_config = brand_config_pb2.BrandConfig()
429 if device_brand.id.value in brand_configs:
430 brand_config = brand_configs[device_brand.id.value]
431
432 for hw_design_config in hw_design.configs:
433 design_id = hw_design_config.id.value
Andrew Lamb2413c982020-05-29 12:15:36 -0600434 sw_config_matches = [
435 x for x in sw_configs if x.design_config_id.value == design_id
436 ]
David Burger7fd1dbe2020-03-26 09:26:55 -0600437 if len(sw_config_matches) == 1:
438 sw_config = sw_config_matches[0]
439 elif len(sw_config_matches) > 1:
440 raise Exception('Multiple software configs found for: %s' % design_id)
441 else:
442 raise Exception('Software config is required for: %s' % design_id)
443
Andrew Lambcd33f702020-06-11 10:45:16 -0600444 program = _lookup(hw_design.program_id, programs)
C Shapiroadefd7c2020-05-19 16:37:21 -0500445 signer_configs_by_design = {}
446 signer_configs_by_brand = {}
447 for signer_config in program.device_signer_configs:
448 design_id = signer_config.design_id.value
449 brand_id = signer_config.brand_id.value
450 if design_id:
451 signer_configs_by_design[design_id] = signer_config
452 elif brand_id:
453 signer_configs_by_brand[brand_id] = signer_config
454 else:
455 raise Exception('No ID found for signer config: %s' % signer_config)
456
C Shapiro2f0bb5d2020-04-14 10:07:47 -0500457 device_signer_config = None
C Shapiroadefd7c2020-05-19 16:37:21 -0500458 if signer_configs_by_design or signer_configs_by_brand:
459 design_id = hw_design.id.value
460 brand_id = device_brand.id.value
461 if design_id in signer_configs_by_design:
462 device_signer_config = signer_configs_by_design[design_id]
463 elif brand_id in signer_configs_by_brand:
464 device_signer_config = signer_configs_by_brand[brand_id]
465 else:
466 # Assume that if signer configs are set, every config is setup
Andrew Lamb2413c982020-05-29 12:15:36 -0600467 raise Exception('Signer config missing for design: %s, brand: %s' %
468 (design_id, brand_id))
C Shapiro2f0bb5d2020-04-14 10:07:47 -0500469
Andrew Lambcd33f702020-06-11 10:45:16 -0600470 transformed_config = _transform_build_config(
C Shapiro90fda252020-04-17 14:34:57 -0500471 Config(
472 program=program,
473 hw_design=hw_design,
Andrew Lambcd33f702020-06-11 10:45:16 -0600474 odm=_lookup(hw_design.odm_id, partners),
C Shapiro90fda252020-04-17 14:34:57 -0500475 hw_design_config=hw_design_config,
476 device_brand=device_brand,
477 device_signer_config=device_signer_config,
Andrew Lambcd33f702020-06-11 10:45:16 -0600478 oem=_lookup(device_brand.oem_id, partners),
C Shapiro90fda252020-04-17 14:34:57 -0500479 sw_config=sw_config,
480 brand_config=brand_config,
Andrew Lamb2413c982020-05-29 12:15:36 -0600481 build_target=config.build_targets[0]), config_files)
David Burger7fd1dbe2020-03-26 09:26:55 -0600482
Andrew Lamb2413c982020-05-29 12:15:36 -0600483 config_json = json.dumps(
484 transformed_config,
485 sort_keys=True,
486 indent=2,
487 separators=(',', ': '))
David Burger7fd1dbe2020-03-26 09:26:55 -0600488
489 if config_json not in results:
490 results[config_json] = transformed_config
491
492 return list(results.values())
493
494
Andrew Lambcd33f702020-06-11 10:45:16 -0600495def _transform_build_config(config, config_files):
David Burger7fd1dbe2020-03-26 09:26:55 -0600496 """Transforms Config instance into target platform JSON schema.
497
498 Args:
499 config: Config namedtuple
C Shapiro5bf23a72020-04-24 11:40:17 -0500500 config_files: Map to look up the generated config files.
David Burger7fd1dbe2020-03-26 09:26:55 -0600501
502 Returns:
503 Unique config payload based on the platform JSON schema.
504 """
505 result = {
Andrew Lamb2413c982020-05-29 12:15:36 -0600506 'identity':
Andrew Lambcd33f702020-06-11 10:45:16 -0600507 _build_identity(config.sw_config.id_scan_config, config.program,
508 config.brand_config.scan_config),
Andrew Lamb2413c982020-05-29 12:15:36 -0600509 'name':
510 config.hw_design.name.lower(),
David Burger7fd1dbe2020-03-26 09:26:55 -0600511 }
512
David Burger8ee9b4d2020-06-16 17:40:21 -0600513 _upsert(_build_arc(config, config_files), result, 'arc')
514 _upsert(_build_audio(config), result, 'audio')
515 _upsert(_build_bluetooth(config, config_files.bluetooth), result, 'bluetooth')
516 _upsert(config.device_brand.brand_code, result, 'brand-code')
517 _upsert(
Andrew Lambcd33f702020-06-11 10:45:16 -0600518 _build_camera(config.hw_design_config.hardware_topology), result,
519 'camera')
David Burger8ee9b4d2020-06-16 17:40:21 -0600520 _upsert(_build_firmware(config), result, 'firmware')
521 _upsert(_build_fw_signing(config), result, 'firmware-signing')
522 _upsert(
Andrew Lambcd33f702020-06-11 10:45:16 -0600523 _build_fingerprint(config.hw_design_config.hardware_topology), result,
Andrew Lamb2413c982020-05-29 12:15:36 -0600524 'fingerprint')
Andrew Lamb319cc922020-06-15 10:45:46 -0600525
526 # TODO(crbug.com/1093837): Enable _build_ui for real programs once ready.
527 if config.program.id.value == "FAKE_PROGRAM":
David Burger8ee9b4d2020-06-16 17:40:21 -0600528 _upsert(_build_ui(config), result, 'ui')
David Burger7fd1dbe2020-03-26 09:26:55 -0600529 power_prefs = config.sw_config.power_config.preferences
530 power_prefs_map = dict(
Andrew Lamb2413c982020-05-29 12:15:36 -0600531 (x.replace('_', '-'), power_prefs[x]) for x in power_prefs)
David Burger8ee9b4d2020-06-16 17:40:21 -0600532 _upsert(power_prefs_map, result, 'power')
533 if config_files.camera_map:
534 camera_file = config_files.camera_map.get(config.hw_design.name, {})
535 _upsert(camera_file, result, 'camera')
David Burger52c9d322020-06-09 07:16:18 -0600536 if config_files.dptf_map:
537 # Prefer design specific if found, if not fall back to project wide config
538 # mapped under the empty string.
539 if config_files.dptf_map.get(config.hw_design.name):
540 dptf_file = config_files.dptf_map[config.hw_design.name]
541 else:
542 dptf_file = config_files.dptf_map.get('')
David Burger8ee9b4d2020-06-16 17:40:21 -0600543 _upsert(dptf_file, result, 'thermal')
544 _upsert(config_files.touch_fw, result, 'touch')
David Burger7fd1dbe2020-03-26 09:26:55 -0600545
546 return result
547
548
Andrew Lambcd33f702020-06-11 10:45:16 -0600549def write_output(configs, output=None):
David Burger7fd1dbe2020-03-26 09:26:55 -0600550 """Writes a list of configs to platform JSON format.
551
552 Args:
553 configs: List of config dicts defined in cros_config_schema.yaml
554 output: Target file output (if None, prints to stdout)
555 """
Andrew Lamb2413c982020-05-29 12:15:36 -0600556 json_output = json.dumps({'chromeos': {
557 'configs': configs,
558 }},
559 sort_keys=True,
560 indent=2,
561 separators=(',', ': '))
David Burger7fd1dbe2020-03-26 09:26:55 -0600562 if output:
563 with open(output, 'w') as output_stream:
564 # Using print function adds proper trailing newline.
565 print(json_output, file=output_stream)
566 else:
567 print(json_output)
568
569
Andrew Lambcd33f702020-06-11 10:45:16 -0600570def _bluetooth_id(project_name, bt_comp):
Andrew Lamb2413c982020-05-29 12:15:36 -0600571 return '_'.join(
572 [project_name, bt_comp.vendor_id, bt_comp.product_id, bt_comp.bcd_device])
C Shapiro90fda252020-04-17 14:34:57 -0500573
574
Andrew Lambcd33f702020-06-11 10:45:16 -0600575def _feature(name, present):
C Shapiro5bf23a72020-04-24 11:40:17 -0500576 attrib = {'name': name}
577 if present:
578 return etree.Element('feature', attrib=attrib)
Andrew Lambcd33f702020-06-11 10:45:16 -0600579
580 return etree.Element('unavailable-feature', attrib=attrib)
C Shapiro5bf23a72020-04-24 11:40:17 -0500581
582
Andrew Lambcd33f702020-06-11 10:45:16 -0600583def _any_present(features):
Andrew Lamb2413c982020-05-29 12:15:36 -0600584 return topology_pb2.HardwareFeatures.PRESENT in features
C Shapiro5bf23a72020-04-24 11:40:17 -0500585
586
Andrew Lambcd33f702020-06-11 10:45:16 -0600587def _arc_hardware_feature_id(design_config):
C Shapiro5bf23a72020-04-24 11:40:17 -0500588 return design_config.id.value.lower().replace(':', '_')
589
590
Andrew Lambcd33f702020-06-11 10:45:16 -0600591def _write_arc_hardware_feature_file(output_dir, file_name, config_content):
David Burger77a1d312020-05-23 16:05:45 -0600592 output_dir += '/arc'
593 os.makedirs(output_dir, exist_ok=True)
594 output = '%s/%s' % (output_dir, file_name)
Andrew Lamb2413c982020-05-29 12:15:36 -0600595 file_content = minidom.parseString(config_content).toprettyxml(
596 indent=' ', encoding='utf-8')
C Shapiroea33cff2020-05-11 13:32:05 -0500597
598 with open(output, 'wb') as f:
599 f.write(file_content)
600
601
Andrew Lambcd33f702020-06-11 10:45:16 -0600602def _write_arc_hardware_feature_files(config, output_dir, build_root_dir):
C Shapiro5bf23a72020-04-24 11:40:17 -0500603 """Writes ARC hardware_feature.xml files for each config
604
605 Args:
606 config: Source ConfigBundle to process.
607 output_dir: Path to the generated output.
C Shapiro5c877992020-04-29 12:11:28 -0500608 build_root_path: Path to the config file from portage's perspective.
C Shapiro5bf23a72020-04-24 11:40:17 -0500609 Returns:
610 dict that maps the design_config_id onto the correct file.
611 """
Andrew Lambcd33f702020-06-11 10:45:16 -0600612 # pylint: disable=too-many-locals
C Shapiro5bf23a72020-04-24 11:40:17 -0500613 result = {}
C Shapiroea33cff2020-05-11 13:32:05 -0500614 configs_by_design = {}
C Shapiro5bf23a72020-04-24 11:40:17 -0500615 for hw_design in config.designs.value:
616 for design_config in hw_design.configs:
617 hw_features = design_config.hardware_features
618 multi_camera = hw_features.camera.count == 2
Andrew Lambcd33f702020-06-11 10:45:16 -0600619 touchscreen = _any_present([hw_features.screen.touch_support])
C Shapiro5bf23a72020-04-24 11:40:17 -0500620 acc = hw_features.accelerometer
621 gyro = hw_features.gyroscope
622 compass = hw_features.magnetometer
Andrew Lambcd33f702020-06-11 10:45:16 -0600623 light_sensor = hw_features.light_sensor
C Shapiro5bf23a72020-04-24 11:40:17 -0500624 root = etree.Element('permissions')
625 root.extend([
Andrew Lambcd33f702020-06-11 10:45:16 -0600626 _feature('android.hardware.camera', multi_camera),
627 _feature('android.hardware.camera.autofocus', multi_camera),
628 _feature(
629 'android.hardware.sensor.accelerometer',
630 _any_present([acc.lid_accelerometer, acc.base_accelerometer])),
631 _feature('android.hardware.sensor.gyroscope',
632 _any_present([gyro.lid_gyroscope, gyro.base_gyroscope])),
633 _feature(
Andrew Lamb2413c982020-05-29 12:15:36 -0600634 'android.hardware.sensor.compass',
Andrew Lambcd33f702020-06-11 10:45:16 -0600635 _any_present(
636 [compass.lid_magnetometer, compass.base_magnetometer])),
637 _feature(
638 'android.hardware.sensor.light',
639 _any_present(
640 [light_sensor.lid_lightsensor,
641 light_sensor.base_lightsensor])),
642 _feature('android.hardware.touchscreen', touchscreen),
643 _feature('android.hardware.touchscreen.multitouch', touchscreen),
644 _feature('android.hardware.touchscreen.multitouch.distinct',
Andrew Lamb2413c982020-05-29 12:15:36 -0600645 touchscreen),
Andrew Lambcd33f702020-06-11 10:45:16 -0600646 _feature('android.hardware.touchscreen.multitouch.jazzhand',
Andrew Lamb2413c982020-05-29 12:15:36 -0600647 touchscreen),
C Shapiro5bf23a72020-04-24 11:40:17 -0500648 ])
649
C Shapiroea33cff2020-05-11 13:32:05 -0500650 design_name = hw_design.name.lower()
C Shapiro5bf23a72020-04-24 11:40:17 -0500651
C Shapiroea33cff2020-05-11 13:32:05 -0500652 # Constructs the following map:
653 # design_name -> config -> design_configs
654 # This allows any of the following file naming schemes:
655 # - All configs within a design share config (design_name prefix only)
656 # - Nobody shares (full design_name and config id prefix needed)
657 #
658 # Having shared configs when possible makes code reviews easier around
659 # the configs and makes debugging easier on the platform side.
660 config_content = etree.tostring(root)
661 arc_configs = configs_by_design.get(design_name, {})
662 design_configs = arc_configs.get(config_content, [])
663 design_configs.append(design_config)
664 arc_configs[config_content] = design_configs
665 configs_by_design[design_name] = arc_configs
C Shapiro9a3ac8c2020-04-25 07:49:21 -0500666
C Shapiroea33cff2020-05-11 13:32:05 -0500667 for design_name, unique_configs in configs_by_design.items():
668 for file_content, design_configs in unique_configs.items():
Andrew Lamb2413c982020-05-29 12:15:36 -0600669 file_name = 'hardware_features_%s.xml' % design_name
670 if len(unique_configs) == 1:
Andrew Lambcd33f702020-06-11 10:45:16 -0600671 _write_arc_hardware_feature_file(output_dir, file_name, file_content)
C Shapiro9a3ac8c2020-04-25 07:49:21 -0500672
Andrew Lamb2413c982020-05-29 12:15:36 -0600673 for design_config in design_configs:
Andrew Lambcd33f702020-06-11 10:45:16 -0600674 feature_id = _arc_hardware_feature_id(design_config)
Andrew Lamb2413c982020-05-29 12:15:36 -0600675 if len(unique_configs) > 1:
676 file_name = 'hardware_features_%s.xml' % feature_id
Andrew Lambcd33f702020-06-11 10:45:16 -0600677 _write_arc_hardware_feature_file(output_dir, file_name, file_content)
Andrew Lamb2413c982020-05-29 12:15:36 -0600678 result[feature_id] = {
679 'build-path': '%s/arc/%s' % (build_root_dir, file_name),
680 'system-path': '/etc/%s' % file_name,
681 }
C Shapiro5bf23a72020-04-24 11:40:17 -0500682 return result
683
684
Andrew Lambcd33f702020-06-11 10:45:16 -0600685def _write_bluetooth_config_files(config, output_dir, build_root_path):
C Shapiro90fda252020-04-17 14:34:57 -0500686 """Writes bluetooth conf files for every unique bluetooth chip.
687
688 Args:
689 config: Source ConfigBundle to process.
690 output_dir: Path to the generated output.
C Shapiro5c877992020-04-29 12:11:28 -0500691 build_root_path: Path to the config file from portage's perspective.
C Shapiro90fda252020-04-17 14:34:57 -0500692 Returns:
693 dict that maps the bluetooth component id onto the file config.
694 """
David Burger77a1d312020-05-23 16:05:45 -0600695 output_dir += '/bluetooth'
C Shapiro90fda252020-04-17 14:34:57 -0500696 result = {}
697 for hw_design in config.designs.value:
698 project_name = hw_design.name.lower()
699 for design_config in hw_design.configs:
C Shapiro74da76e2020-05-04 13:02:20 -0500700 bt_comp = design_config.hardware_features.bluetooth.component.usb
C Shapiro90fda252020-04-17 14:34:57 -0500701 if bt_comp.vendor_id:
Andrew Lambcd33f702020-06-11 10:45:16 -0600702 bt_id = _bluetooth_id(project_name, bt_comp)
C Shapiro90fda252020-04-17 14:34:57 -0500703 result[bt_id] = {
C Shapiro5c877992020-04-29 12:11:28 -0500704 'build-path': '%s/bluetooth/%s.conf' % (build_root_path, bt_id),
C Shapiro90fda252020-04-17 14:34:57 -0500705 'system-path': '/etc/bluetooth/%s/main.conf' % bt_id,
706 }
707 bt_content = '''[General]
Andrew Lamb2413c982020-05-29 12:15:36 -0600708DeviceID = bluetooth:%s:%s:%s''' % (bt_comp.vendor_id, bt_comp.product_id,
C Shapiro90fda252020-04-17 14:34:57 -0500709 bt_comp.bcd_device)
710
David Burger77a1d312020-05-23 16:05:45 -0600711 os.makedirs(output_dir, exist_ok=True)
712 output = '%s/%s.conf' % (output_dir, bt_id)
C Shapiro90fda252020-04-17 14:34:57 -0500713 with open(output, 'w') as output_stream:
714 # Using print function adds proper trailing newline.
715 print(bt_content, file=output_stream)
716 return result
717
718
Andrew Lambcd33f702020-06-11 10:45:16 -0600719def _read_config(path):
David Burgerd4f32962020-05-02 12:07:40 -0600720 """Reads a ConfigBundle proto from a json pb file.
David Burgere6f76222020-04-27 11:08:01 -0600721
722 Args:
David Burgerd4f32962020-05-02 12:07:40 -0600723 path: Path to the file encoding the json pb proto.
David Burgere6f76222020-04-27 11:08:01 -0600724 """
725 config = config_bundle_pb2.ConfigBundle()
726 with open(path, 'r') as f:
727 return json_format.Parse(f.read(), config)
728
729
Andrew Lambcd33f702020-06-11 10:45:16 -0600730def _merge_configs(configs):
David Burger7fd1dbe2020-03-26 09:26:55 -0600731 result = config_bundle_pb2.ConfigBundle()
732 for config in configs:
733 result.MergeFrom(config)
734
735 return result
736
737
David Burger8ee9b4d2020-06-16 17:40:21 -0600738def _camera_map(configs):
739 """Produces a camera config map for the given configs.
740
741 Produces a map that maps from the design name to the camera config for that
742 design.
743
744 Args:
745 configs: Source ConfigBundle to process.
746
747 Returns:
748 map from design name to camera config.
749 """
750 result = {}
751 for design in configs.designs.value:
752 design_name = design.name
753 config_path = CAMERA_CONFIG_SOURCE_PATH_TEMPLATE.format(design_name)
754 if os.path.exists(config_path):
755 destination = CAMERA_CONFIG_DEST_PATH_TEMPLATE.format(design_name)
756 result[design_name] = {
757 'config-path': destination,
758 'config-file': _file(config_path, destination),
759 }
760 return result
761
762
David Burger52c9d322020-06-09 07:16:18 -0600763def _dptf_map(configs, project_name):
764 """Produces a dptf map for the given configs.
765
766 Produces a map that maps from design name to the dptf file config for that
767 design. It looks for the dptf files at:
768 DPTF_PATH + DPTF_FILE
769 for a project wide config, that it maps under the empty string, and at:
770 DPTF_PATH + design_name + DPTF_FILE
771 for design specific configs that it maps under the design name.
772
773 Args:
774 configs: Source ConfigBundle to process.
775 project_name: Name of project processing for.
776
777 Returns:
David Burger8ee9b4d2020-06-16 17:40:21 -0600778 map from design name or empty string (project wide), to dptf config.
David Burger52c9d322020-06-09 07:16:18 -0600779 """
780 result = {}
781 project_dptf_path = os.path.join(project_name, 'dptf.dv')
782 # Looking at top level for project wide, and then for each design name
783 # for design specific.
784 dirs = [""] + [d.name for d in configs.designs.value]
785 for directory in dirs:
786 if os.path.exists(os.path.join(DPTF_PATH, directory, DPTF_FILE)):
787 dptf_file = {
788 'dptf-dv':
789 project_dptf_path,
790 'files': [
791 _file(
792 os.path.join(project_name, DPTF_PATH, directory, DPTF_FILE),
793 os.path.join('/etc/dptf', project_dptf_path))
794 ]
795 }
796 result[directory] = dptf_file
797 return result
798
799
Andrew Lambcd33f702020-06-11 10:45:16 -0600800def Main(project_configs, program_config, output): # pylint: disable=invalid-name
David Burger7fd1dbe2020-03-26 09:26:55 -0600801 """Transforms source proto config into platform JSON.
802
803 Args:
804 project_configs: List of source project configs to transform.
805 program_config: Program config for the given set of projects.
806 output: Output file that will be generated by the transform.
807 """
Andrew Lambcd33f702020-06-11 10:45:16 -0600808 configs = _merge_configs([_read_config(program_config)] +
809 [_read_config(config) for config in project_configs])
C Shapiro5bf23a72020-04-24 11:40:17 -0500810 bluetooth_files = {}
811 arc_hw_feature_files = {}
C Shapiro2b6d5332020-05-06 17:51:35 -0500812 touch_fw = {}
David Burger52c9d322020-06-09 07:16:18 -0600813 dptf_map = {}
David Burger8ee9b4d2020-06-16 17:40:21 -0600814 camera_map = {}
C Shapiro5bf23a72020-04-24 11:40:17 -0500815 output_dir = os.path.dirname(output)
C Shapiro5c877992020-04-29 12:11:28 -0500816 build_root_dir = output_dir
C Shapiro5c877992020-04-29 12:11:28 -0500817 if 'sw_build_config' in output_dir:
818 full_path = os.path.realpath(output)
Andrew Lamb2413c982020-05-29 12:15:36 -0600819 project_name = re.match(r'.*/(\w*)/sw_build_config/.*',
820 full_path).groups(1)[0]
C Shapiro5c877992020-04-29 12:11:28 -0500821 # Projects don't know about each other until they are integrated into the
822 # build system. When this happens, the files need to be able to co-exist
823 # without any collisions. This prefixes the project name (which is how
824 # portage maps in the project), so project files co-exist and can be
825 # installed together.
826 # This is necessary to allow projects to share files at the program level
827 # without having portage file installation collisions.
828 build_root_dir = os.path.join(project_name, output_dir)
C Shapiro6830e6c2020-04-29 13:29:56 -0500829
David Burger8ee9b4d2020-06-16 17:40:21 -0600830 camera_map = _camera_map(configs)
David Burger52c9d322020-06-09 07:16:18 -0600831 dptf_map = _dptf_map(configs, project_name)
832
C Shapiro2b6d5332020-05-06 17:51:35 -0500833 if os.path.exists(TOUCH_PATH):
Andrew Lambcd33f702020-06-11 10:45:16 -0600834 touch_fw = _build_touch_file_config(configs, project_name)
835 bluetooth_files = _write_bluetooth_config_files(configs, output_dir,
836 build_root_dir)
837 arc_hw_feature_files = _write_arc_hardware_feature_files(
838 configs, output_dir, build_root_dir)
C Shapiro5bf23a72020-04-24 11:40:17 -0500839 config_files = ConfigFiles(
840 bluetooth=bluetooth_files,
841 arc_hw_features=arc_hw_feature_files,
C Shapiro2b6d5332020-05-06 17:51:35 -0500842 touch_fw=touch_fw,
David Burger8ee9b4d2020-06-16 17:40:21 -0600843 dptf_map=dptf_map,
844 camera_map=camera_map)
Andrew Lambcd33f702020-06-11 10:45:16 -0600845 write_output(_transform_build_configs(configs, config_files), output)
David Burger7fd1dbe2020-03-26 09:26:55 -0600846
847
848def main(argv=None):
849 """Main program which parses args and runs
850
851 Args:
852 argv: List of command line arguments, if None uses sys.argv.
853 """
854 if argv is None:
855 argv = sys.argv[1:]
Andrew Lambcd33f702020-06-11 10:45:16 -0600856 opts = parse_args(argv)
David Burger7fd1dbe2020-03-26 09:26:55 -0600857 Main(opts.project_configs, opts.program_config, opts.output)
858
859
860if __name__ == '__main__':
861 sys.exit(main(sys.argv[1:]))