blob: 42810e654421264f96e2dbeb8b997421eddfb61d [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
Ren-Pei Zengce869dd2020-08-18 01:29:37 +08008# pylint: disable=too-many-lines
9
David Burger7fd1dbe2020-03-26 09:26:55 -060010import argparse
11import json
12import pprint
C Shapiro90fda252020-04-17 14:34:57 -050013import os
David Burger7fd1dbe2020-03-26 09:26:55 -060014import sys
C Shapiro90fda252020-04-17 14:34:57 -050015import re
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
Ren-Pei Zengacf03be2020-11-11 13:56:51 +080022from lxml import etree
Andrew Lambcd33f702020-06-11 10:45:16 -060023
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070024from chromiumos.config.api import device_brand_pb2
David Burger92609a32020-04-23 10:38:50 -060025from chromiumos.config.api import topology_pb2
C Shapiro5bf23a72020-04-24 11:40:17 -050026from chromiumos.config.payload import config_bundle_pb2
Prathmesh Prabhu72f8a002020-04-10 09:57:53 -070027from chromiumos.config.api.software import brand_config_pb2
David Burger7fd1dbe2020-03-26 09:26:55 -060028
Andrew Lamb2413c982020-05-29 12:15:36 -060029Config = namedtuple('Config', [
30 'program', 'hw_design', 'odm', 'hw_design_config', 'device_brand',
C Shapirod5545f12020-11-30 16:37:04 -060031 'device_signer_config', 'oem', 'sw_config', 'brand_config'
Andrew Lamb2413c982020-05-29 12:15:36 -060032])
David Burger7fd1dbe2020-03-26 09:26:55 -060033
Ren-Pei Zengacf03be2020-11-11 13:56:51 +080034ConfigFiles = namedtuple('ConfigFiles', [
35 'arc_hw_features', 'arc_media_profiles', 'touch_fw', 'dptf_map',
36 'camera_map', 'wifi_sar_map'
37])
David Burger8ee9b4d2020-06-16 17:40:21 -060038
39CAMERA_CONFIG_DEST_PATH_TEMPLATE = '/etc/camera/camera_config_{}.json'
40CAMERA_CONFIG_SOURCE_PATH_TEMPLATE = (
41 'sw_build_config/platform/chromeos-config/camera/camera_config_{}.json')
C Shapiro5bf23a72020-04-24 11:40:17 -050042
David Burger52c9d322020-06-09 07:16:18 -060043DPTF_PATH = 'sw_build_config/platform/chromeos-config/thermal'
44DPTF_FILE = 'dptf.dv'
David Burger2f0d9522020-07-30 10:52:28 -060045
C Shapiro2b6d5332020-05-06 17:51:35 -050046TOUCH_PATH = 'sw_build_config/platform/chromeos-config/touch'
Andrew Lamb6c42efc2020-06-16 10:40:43 -060047WALLPAPER_BASE_PATH = '/usr/share/chromeos-assets/wallpaper'
David Burger7fd1dbe2020-03-26 09:26:55 -060048
Ren-Pei Zengacf03be2020-11-11 13:56:51 +080049XML_DECLARATION = b'<?xml version="1.0" encoding="utf-8"?>\n'
50
Andrew Lamb2413c982020-05-29 12:15:36 -060051
Andrew Lambcd33f702020-06-11 10:45:16 -060052def parse_args(argv):
David Burger7fd1dbe2020-03-26 09:26:55 -060053 """Parse the available arguments.
54
55 Invalid arguments or -h cause this function to print a message and exit.
56
57 Args:
58 argv: List of string arguments (excluding program name / argv[0])
59
60 Returns:
61 argparse.Namespace object containing the attributes.
62 """
63 parser = argparse.ArgumentParser(
64 description='Converts source proto config into platform JSON config.')
65 parser.add_argument(
66 '-c',
67 '--project_configs',
68 nargs='+',
69 type=str,
70 help='Space delimited list of source protobinary project config files.')
71 parser.add_argument(
72 '-p',
73 '--program_config',
74 type=str,
75 help='Path to the source program-level protobinary file')
76 parser.add_argument(
Andrew Lamb2413c982020-05-29 12:15:36 -060077 '-o', '--output', type=str, help='Output file that will be generated')
David Burger7fd1dbe2020-03-26 09:26:55 -060078 return parser.parse_args(argv)
79
80
David Burger8ee9b4d2020-06-16 17:40:21 -060081def _upsert(field, target, target_name):
82 """Updates or inserts `field` within `target`.
83
84 If `target_name` already exists within `target` an update is performed,
85 otherwise, an insert is performed.
86 """
Sam McNally9a873f72020-06-05 19:47:22 +100087 if field or field == 0:
David Burger8ee9b4d2020-06-16 17:40:21 -060088 if target_name in target:
89 target[target_name].update(field)
90 else:
91 target[target_name] = field
David Burger7fd1dbe2020-03-26 09:26:55 -060092
93
Andrew Lambcd33f702020-06-11 10:45:16 -060094def _build_arc(config, config_files):
Andrew Lambcd33f702020-06-11 10:45:16 -060095 build_properties = {
C Shapirod5545f12020-11-30 16:37:04 -060096 # TODO(chromium:1126527) - Push this into the overlay itself.
97 # This isn't/can't be device specific and shouldn't be configured as such.
98 'device': "%s_cheets" % config.program.name.lower(),
99 'first-api-level': '28',
Andrew Lambcd33f702020-06-11 10:45:16 -0600100 'marketing-name': config.device_brand.brand_name,
101 'metrics-tag': config.hw_design.name.lower(),
C Shapirod5545f12020-11-30 16:37:04 -0600102 'product': config.program.name.lower(),
Andrew Lambcd33f702020-06-11 10:45:16 -0600103 }
104 if config.oem:
105 build_properties['oem'] = config.oem.name
106 result = {'build-properties': build_properties}
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +0800107 config_id = _get_formatted_config_id(config.hw_design_config)
108 if config_id in config_files.arc_hw_features:
109 result['hardware-features'] = config_files.arc_hw_features[config_id]
Ren-Pei Zengacf03be2020-11-11 13:56:51 +0800110 if config_id in config_files.arc_media_profiles:
111 result['media-profiles'] = config_files.arc_media_profiles[config_id]
Andrew Lambcd33f702020-06-11 10:45:16 -0600112 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 Burger2f0d9522020-07-30 10:52:28 -0600117
Andrew Lambcd33f702020-06-11 10:45:16 -0600118 return result
David Burger7fd1dbe2020-03-26 09:26:55 -0600119
Andrew Lamb2413c982020-05-29 12:15:36 -0600120
Andrew Lamb319cc922020-06-15 10:45:46 -0600121def _build_ash_flags(config: Config) -> List[str]:
122 """Returns a list of Ash flags for config.
123
124 Ash is the window manager and system UI for ChromeOS, see
125 https://chromium.googlesource.com/chromium/src/+/refs/heads/master/ash/.
126 """
127 # A map from flag name -> value. Value may be None for boolean flags.
128 flags = {}
129
130 hw_features = config.hw_design_config.hardware_features
131 if hw_features.stylus.stylus == topology_pb2.HardwareFeatures.Stylus.INTERNAL:
Andrew Lamb2e641e22020-06-15 12:30:41 -0600132 flags['has-internal-stylus'] = None
Andrew Lamb319cc922020-06-15 10:45:46 -0600133
Andrew Lamb2e641e22020-06-15 12:30:41 -0600134 fp_loc = hw_features.fingerprint.location
135 if fp_loc and fp_loc != topology_pb2.HardwareFeatures.Fingerprint.NOT_PRESENT:
136 loc_name = topology_pb2.HardwareFeatures.Fingerprint.Location.Name(fp_loc)
137 flags['fingerprint-sensor-location'] = loc_name.lower().replace('_', '-')
138
Andrew Lamb6c42efc2020-06-16 10:40:43 -0600139 wallpaper = config.brand_config.wallpaper
140 # If a wallpaper is set, the 'default-wallpaper-is-oem' flag needs to be set.
141 # If a wallpaper is not set, the 'default_[large|small].jpg' wallpapers
142 # should still be set.
143 if wallpaper:
144 flags['default-wallpaper-is-oem'] = None
145 else:
146 wallpaper = 'default'
147
148 for size in ('small', 'large'):
149 flags[f'default-wallpaper-{size}'] = (
150 f'{WALLPAPER_BASE_PATH}/{wallpaper}_{size}.jpg')
151
152 # For each size, also install 'guest' and 'child' wallpapers.
153 for wallpaper_type in ('guest', 'child'):
154 flags[f'{wallpaper_type}-wallpaper-{size}'] = (
155 f'{WALLPAPER_BASE_PATH}/{wallpaper_type}_{size}.jpg')
156
C Shapiro2e97aad2020-11-16 11:58:10 -0600157 regulatory_label = config.brand_config.regulatory_label
158 if regulatory_label:
159 flags['regulatory-label-dir'] = (regulatory_label)
160
C Shapirod5545f12020-11-30 16:37:04 -0600161 flags['arc-build-properties'] = {
162 'device': "%s_cheets" % config.program.name.lower(),
163 'firstApiLevel': '28',
164 }
Andrew Lamb72d41362020-06-17 09:19:02 -0600165
Andrew Lamb90b168c2020-06-22 10:42:30 -0600166 power_button = hw_features.power_button
167 if power_button.edge:
168 flags['ash-power-button-position'] = json.dumps({
169 'edge':
170 topology_pb2.HardwareFeatures.Button.Edge.Name(power_button.edge
171 ).lower(),
172 # Starlark sometimes represents float literals strangely, e.g. changing
173 # 0.9 to 0.899999. Round to two digits here.
174 'position':
175 round(power_button.position, 2)
176 })
177
178 volume_button = hw_features.volume_button
179 if volume_button.edge:
180 flags['ash-side-volume-button-position'] = json.dumps({
181 'region':
182 topology_pb2.HardwareFeatures.Button.Region.Name(
183 volume_button.region).lower(),
184 'edge':
185 topology_pb2.HardwareFeatures.Button.Edge.Name(volume_button.edge
186 ).lower(),
187 })
188
Nikolai Artemievda87d992020-12-04 15:09:00 +1100189 form_factor = hw_features.form_factor.form_factor
190 lid_accel = hw_features.accelerometer.lid_accelerometer
191 if (form_factor == topology_pb2.HardwareFeatures.FormFactor.CHROMEBASE and
192 lid_accel == topology_pb2.HardwareFeatures.PRESENT):
193 flags['force-in-tablet-physical-state'] = None
194
Andrew Lamb2e641e22020-06-15 12:30:41 -0600195 return sorted([f'--{k}={v}' if v else f'--{k}' for k, v in flags.items()])
Andrew Lamb319cc922020-06-15 10:45:46 -0600196
197
198def _build_ui(config: Config) -> dict:
199 """Builds the 'ui' property from cros_config_schema."""
200 return {'extra-ash-flags': _build_ash_flags(config)}
201
202
David Burger07af5242020-08-11 11:08:25 -0600203def _build_bluetooth(config):
C Shapiro90fda252020-04-17 14:34:57 -0500204 bt_flags = config.sw_config.bluetooth_config.flags
205 # Convert to native map (from proto wrapper)
206 bt_flags_map = dict(bt_flags)
207 result = {}
208 if bt_flags_map:
209 result['flags'] = bt_flags_map
C Shapiro90fda252020-04-17 14:34:57 -0500210 return result
211
David Burger7fd1dbe2020-03-26 09:26:55 -0600212
David Burgerceeb68a2020-09-03 11:31:10 -0600213def _build_ath10k_config(ath10k_config):
214 """Builds the wifi configuration for the ath10k driver.
215
216 Args:
217 ath10k_config: Ath10kConfig config.
218
219 Returns:
220 wifi configuration for the ath10k driver.
221 """
David Burgerec753912020-08-10 12:59:11 -0600222 result = {}
David Burgerec753912020-08-10 12:59:11 -0600223
David Burgerceeb68a2020-09-03 11:31:10 -0600224 def power_chain(power):
225 return {
226 'limit-2g': power.limit_2g,
227 'limit-5g': power.limit_5g,
228 }
David Burgerec753912020-08-10 12:59:11 -0600229
David Burgerceeb68a2020-09-03 11:31:10 -0600230 result['tablet-mode-power-table-ath10k'] = power_chain(
231 ath10k_config.tablet_mode_power_table)
232 result['non-tablet-mode-power-table-ath10k'] = power_chain(
233 ath10k_config.non_tablet_mode_power_table)
David Burgerec753912020-08-10 12:59:11 -0600234 return result
235
236
David Burgerceeb68a2020-09-03 11:31:10 -0600237def _build_rtw88_config(rtw88_config):
238 """Builds the wifi configuration for the rtw88 driver.
239
240 Args:
241 rtw88_config: Rtw88Config config.
242
243 Returns:
244 wifi configuration for the rtw88 driver.
245 """
246 result = {}
247
248 def power_chain(power):
249 return {
250 'limit-2g': power.limit_2g,
251 'limit-5g-1': power.limit_5g_1,
252 'limit-5g-3': power.limit_5g_3,
253 'limit-5g-4': power.limit_5g_4,
254 }
255
256 result['tablet-mode-power-table-rtw'] = power_chain(
257 rtw88_config.tablet_mode_power_table)
258 result['non-tablet-mode-power-table-rtw'] = power_chain(
259 rtw88_config.non_tablet_mode_power_table)
260
261 def offsets(offset):
262 return {
263 'offset-2g': offset.offset_2g,
264 'offset-5g': offset.offset_5g,
265 }
266
267 result['geo-offsets-fcc'] = offsets(rtw88_config.offset_fcc)
268 result['geo-offsets-eu'] = offsets(rtw88_config.offset_eu)
269 result['geo-offsets-rest-of-world'] = offsets(rtw88_config.offset_other)
270 return result
271
272
273def _build_intel_config(config, config_files):
274 """Builds the wifi configuration for the intel driver.
275
276 Args:
277 config: Config namedtuple
278 config_files: Map to look up the generated config files.
279
280 Returns:
281 wifi configuration for the intel driver.
282 """
283 design_name = config.hw_design.name.lower()
284 return config_files.wifi_sar_map.get(design_name)
285
286
287def _build_wifi(config, config_files):
288 """Builds the wifi configuration.
289
290 Args:
291 config: Config namedtuple
292 config_files: Map to look up the generated config files.
293
294 Returns:
295 wifi configuration.
296 """
297 config_field = config.sw_config.wifi_config.WhichOneof('wifi_config')
298 if config_field == 'ath10k_config':
299 return _build_ath10k_config(config.sw_config.wifi_config.ath10k_config)
300 if config_field == 'rtw88_config':
301 return _build_rtw88_config(config.sw_config.wifi_config.rtw88_config)
302 if config_field == 'intel_config':
303 return _build_intel_config(config, config_files)
304 return {}
305
306
Andrew Lambcd33f702020-06-11 10:45:16 -0600307def _build_fingerprint(hw_topology):
308 if not hw_topology.HasField('fingerprint'):
309 return None
310
311 fp = hw_topology.fingerprint.hardware_feature.fingerprint
312 result = {}
313 if fp.location != topology_pb2.HardwareFeatures.Fingerprint.NOT_PRESENT:
314 location = fp.Location.DESCRIPTOR.values_by_number[fp.location].name
315 result['sensor-location'] = location.lower().replace('_', '-')
316 if fp.board:
317 result['board'] = fp.board
Tom Hughesdfc35402020-06-29 16:02:09 -0700318 if fp.ro_version:
319 result['ro-version'] = fp.ro_version
320
Andrew Lambcd33f702020-06-11 10:45:16 -0600321 return result
David Burger7fd1dbe2020-03-26 09:26:55 -0600322
323
Trent Beginf067ccb2020-08-12 12:33:53 -0600324def _build_hardware_properties(hw_topology):
325 if not hw_topology.HasField('form_factor'):
326 return None
327
328 form_factor = hw_topology.form_factor.hardware_feature.form_factor.form_factor
329 result = {}
330 if form_factor in [
331 topology_pb2.HardwareFeatures.FormFactor.CHROMEBIT,
332 topology_pb2.HardwareFeatures.FormFactor.CHROMEBASE,
333 topology_pb2.HardwareFeatures.FormFactor.CHROMEBOX
334 ]:
335 result['psu-type'] = "AC_only"
336 else:
337 result['psu-type'] = "battery"
338
339 result['has-backlight'] = form_factor not in [
340 topology_pb2.HardwareFeatures.FormFactor.CHROMEBIT,
341 topology_pb2.HardwareFeatures.FormFactor.CHROMEBOX
342 ]
343
Nikolai Artemiev1be27ef2021-01-11 17:32:17 +1100344 form_factor_names = {
345 topology_pb2.HardwareFeatures.FormFactor.CHROMEBASE: "CHROMEBASE",
346 }
347 if form_factor in form_factor_names:
348 result['form-factor'] = form_factor_names[form_factor]
349
Trent Beginf067ccb2020-08-12 12:33:53 -0600350 return result
351
352
Andrew Lambcd33f702020-06-11 10:45:16 -0600353def _fw_bcs_path(payload):
David Burger7fd1dbe2020-03-26 09:26:55 -0600354 if payload and payload.firmware_image_name:
Andrew Lamb2413c982020-05-29 12:15:36 -0600355 return 'bcs://%s.%d.%d.0.tbz2' % (payload.firmware_image_name,
356 payload.version.major,
357 payload.version.minor)
David Burger7fd1dbe2020-03-26 09:26:55 -0600358
Andrew Lambcd33f702020-06-11 10:45:16 -0600359 return None
David Burger7fd1dbe2020-03-26 09:26:55 -0600360
Andrew Lambcd33f702020-06-11 10:45:16 -0600361
362def _fw_build_target(payload):
David Burger7fd1dbe2020-03-26 09:26:55 -0600363 if payload:
364 return payload.build_target_name
365
Andrew Lambcd33f702020-06-11 10:45:16 -0600366 return None
David Burger7fd1dbe2020-03-26 09:26:55 -0600367
Andrew Lambcd33f702020-06-11 10:45:16 -0600368
369def _build_firmware(config):
David Burgerb70b6762020-05-21 12:14:59 -0600370 """Returns firmware config, or None if no build targets."""
Andrew Lamb3da156d2020-04-16 16:00:56 -0600371 fw_payload_config = config.sw_config.firmware
372 fw_build_config = config.sw_config.firmware_build_config
373 main_ro = fw_payload_config.main_ro_payload
374 main_rw = fw_payload_config.main_rw_payload
375 ec_ro = fw_payload_config.ec_ro_payload
376 pd_ro = fw_payload_config.pd_ro_payload
David Burger7fd1dbe2020-03-26 09:26:55 -0600377
378 build_targets = {}
Andrew Lamb3da156d2020-04-16 16:00:56 -0600379
David Burger8ee9b4d2020-06-16 17:40:21 -0600380 _upsert(fw_build_config.build_targets.depthcharge, build_targets,
381 'depthcharge')
382 _upsert(fw_build_config.build_targets.coreboot, build_targets, 'coreboot')
383 _upsert(fw_build_config.build_targets.ec, build_targets, 'ec')
384 _upsert(
Andrew Lambf8954ee2020-04-21 10:24:40 -0600385 list(fw_build_config.build_targets.ec_extras), build_targets, 'ec_extras')
David Burger8ee9b4d2020-06-16 17:40:21 -0600386 _upsert(fw_build_config.build_targets.libpayload, build_targets, 'libpayload')
David Burger7fd1dbe2020-03-26 09:26:55 -0600387
David Burgerb70b6762020-05-21 12:14:59 -0600388 if not build_targets:
389 return None
390
David Burger7fd1dbe2020-03-26 09:26:55 -0600391 result = {
C Shapirod5545f12020-11-30 16:37:04 -0600392 'bcs-overlay': 'overlay-%s-private' % config.program.name.lower(),
David Burger7fd1dbe2020-03-26 09:26:55 -0600393 'build-targets': build_targets,
David Burger7fd1dbe2020-03-26 09:26:55 -0600394 }
Andrew Lamb883fa042020-04-06 11:37:22 -0600395
David Burger8ee9b4d2020-06-16 17:40:21 -0600396 _upsert(main_ro.firmware_image_name.lower(), result, 'image-name')
Andrew Lamb883fa042020-04-06 11:37:22 -0600397
David Burger8ee9b4d2020-06-16 17:40:21 -0600398 _upsert(_fw_bcs_path(main_ro), result, 'main-ro-image')
399 _upsert(_fw_bcs_path(main_rw), result, 'main-rw-image')
400 _upsert(_fw_bcs_path(ec_ro), result, 'ec-ro-image')
401 _upsert(_fw_bcs_path(pd_ro), result, 'pd-ro-image')
David Burger7fd1dbe2020-03-26 09:26:55 -0600402
David Burger8ee9b4d2020-06-16 17:40:21 -0600403 _upsert(
Andrew Lambf39fbe82020-04-13 16:14:33 -0600404 config.hw_design_config.hardware_features.fw_config.value,
405 result,
406 'firmware-config',
407 )
408
David Burger7fd1dbe2020-03-26 09:26:55 -0600409 return result
410
411
Sam McNallyfd14e4b2020-09-12 10:26:35 +1000412def _build_fw_signing(config, whitelabel):
C Shapiro2f0bb5d2020-04-14 10:07:47 -0500413 if config.sw_config.firmware and config.device_signer_config:
David Burger68e0d142020-05-15 17:29:33 -0600414 hw_design = config.hw_design.name.lower()
Sam McNally2fc807f2020-07-16 18:13:53 +1000415 brand_scan_config = config.brand_config.scan_config
416 if brand_scan_config and brand_scan_config.whitelabel_tag:
417 signature_id = '%s-%s' % (hw_design, brand_scan_config.whitelabel_tag)
418 else:
419 signature_id = hw_design
420
Sam McNallyfd14e4b2020-09-12 10:26:35 +1000421 result = {
C Shapiro2f0bb5d2020-04-14 10:07:47 -0500422 'key-id': config.device_signer_config.key_id,
Sam McNally2fc807f2020-07-16 18:13:53 +1000423 'signature-id': signature_id,
C Shapiro2f0bb5d2020-04-14 10:07:47 -0500424 }
Sam McNallyfd14e4b2020-09-12 10:26:35 +1000425 if whitelabel:
426 result['sig-id-in-customization-id'] = True
427 return result
C Shapiro2f0bb5d2020-04-14 10:07:47 -0500428 return {}
David Burger7fd1dbe2020-03-26 09:26:55 -0600429
430
Andrew Lambcd33f702020-06-11 10:45:16 -0600431def _file(source, destination):
Andrew Lamb2413c982020-05-29 12:15:36 -0600432 return {'destination': destination, 'source': source}
David Burger7fd1dbe2020-03-26 09:26:55 -0600433
434
David Burger40dfe3a2020-06-18 17:09:13 -0600435def _file_v2(build_path, system_path):
436 return {'build-path': build_path, 'system-path': system_path}
437
438
Andrew Lambcd33f702020-06-11 10:45:16 -0600439def _build_audio(config):
David Burger178f3ef2020-06-26 12:11:57 -0600440 if not config.sw_config.audio_configs:
441 return {}
David Burger7fd1dbe2020-03-26 09:26:55 -0600442 alsa_path = '/usr/share/alsa/ucm'
443 cras_path = '/etc/cras'
444 project_name = config.hw_design.name.lower()
David Burger43250662020-05-07 11:21:50 -0600445 program_name = config.program.name.lower()
David Burger7fd1dbe2020-03-26 09:26:55 -0600446 files = []
David Burger178f3ef2020-06-26 12:11:57 -0600447 ucm_suffix = None
448 for audio in config.sw_config.audio_configs:
449 card = audio.card_name
450 card_with_suffix = audio.card_name
451 if audio.ucm_suffix:
452 # TODO: last ucm_suffix wins.
453 ucm_suffix = audio.ucm_suffix
454 card_with_suffix += '.' + audio.ucm_suffix
455 if audio.ucm_file:
456 files.append(
457 _file(audio.ucm_file,
458 '%s/%s/HiFi.conf' % (alsa_path, card_with_suffix)))
459 if audio.ucm_master_file:
460 files.append(
461 _file(
462 audio.ucm_master_file, '%s/%s/%s.conf' %
Andrew Lamb2413c982020-05-29 12:15:36 -0600463 (alsa_path, card_with_suffix, card_with_suffix)))
David Burger178f3ef2020-06-26 12:11:57 -0600464 if audio.card_config_file:
465 files.append(
466 _file(audio.card_config_file,
467 '%s/%s/%s' % (cras_path, project_name, card)))
468 if audio.dsp_file:
469 files.append(
470 _file(audio.dsp_file, '%s/%s/dsp.ini' % (cras_path, project_name)))
471 if audio.module_file:
472 files.append(
473 _file(audio.module_file,
474 '/etc/modprobe.d/alsa-%s.conf' % program_name))
475 if audio.board_file:
476 files.append(
477 _file(audio.board_file,
478 '%s/%s/board.ini' % (cras_path, project_name)))
David Burger599ff7b2020-04-06 16:29:31 -0600479
480 result = {
David Burger7fd1dbe2020-03-26 09:26:55 -0600481 'main': {
482 'cras-config-dir': project_name,
483 'files': files,
484 }
485 }
David Burger178f3ef2020-06-26 12:11:57 -0600486
487 if ucm_suffix:
488 result['main']['ucm-suffix'] = ucm_suffix
David Burger599ff7b2020-04-06 16:29:31 -0600489
490 return result
David Burger7fd1dbe2020-03-26 09:26:55 -0600491
492
Andrew Lambcd33f702020-06-11 10:45:16 -0600493def _build_camera(hw_topology):
Ren-Pei Zeng573d6332020-11-12 14:55:22 +0800494 camera_pb = topology_pb2.HardwareFeatures.Camera
495 camera = hw_topology.camera.hardware_feature.camera
496 result = {'count': len(camera.devices)}
497 if camera.devices:
498 result['devices'] = []
499 for device in camera.devices:
500 interface = {
501 camera_pb.INTERFACE_USB: 'usb',
502 camera_pb.INTERFACE_MIPI: 'mipi',
503 }[device.interface]
504 facing = {
505 camera_pb.FACING_FRONT: 'front',
506 camera_pb.FACING_BACK: 'back',
507 }[device.facing]
508 orientation = {
509 camera_pb.ORIENTATION_0: 0,
510 camera_pb.ORIENTATION_90: 90,
511 camera_pb.ORIENTATION_180: 180,
512 camera_pb.ORIENTATION_270: 270,
513 }[device.orientation]
514 flags = {
515 'support-1080p':
516 bool(device.flags & camera_pb.FLAGS_SUPPORT_1080P),
517 'support-autofocus':
518 bool(device.flags & camera_pb.FLAGS_SUPPORT_AUTOFOCUS),
519 }
Ricardo Ribaldab9b17b32021-01-13 17:10:20 +0100520 dev = {
Ren-Pei Zeng573d6332020-11-12 14:55:22 +0800521 'interface': interface,
522 'facing': facing,
523 'orientation': orientation,
524 'flags': flags,
525 'ids': list(device.ids),
Ricardo Ribaldab9b17b32021-01-13 17:10:20 +0100526 }
527 if device.privacy_switch != topology_pb2.HardwareFeatures.PRESENT_UNKNOWN:
528 dev['has-privacy-switch'] = device.privacy_switch == topology_pb2.HardwareFeatures.PRESENT
529 result['devices'].append(dev)
Ren-Pei Zeng573d6332020-11-12 14:55:22 +0800530 return result
David Burger8aa8fa32020-04-14 08:30:34 -0600531
Andrew Lambcd33f702020-06-11 10:45:16 -0600532
533def _build_identity(hw_scan_config, program, brand_scan_config=None):
David Burger7fd1dbe2020-03-26 09:26:55 -0600534 identity = {}
David Burger8ee9b4d2020-06-16 17:40:21 -0600535 _upsert(hw_scan_config.firmware_sku, identity, 'sku-id')
536 _upsert(hw_scan_config.smbios_name_match, identity, 'smbios-name-match')
Andrew Lamb7806ce92020-04-07 10:22:17 -0600537 # 'platform-name' is needed to support 'mosys platform name'. Clients should
Sean McAllister0b757772020-11-13 12:22:36 -0700538 # no longer require platform name, but set it here for backwards compatibility.
539 if program.mosys_platform_name:
540 _upsert(program.mosys_platform_name, identity, 'platform-name')
541 else:
542 _upsert(program.name, identity, 'platform-name')
543
David Burger7fd1dbe2020-03-26 09:26:55 -0600544 # ARM architecture
David Burger8ee9b4d2020-06-16 17:40:21 -0600545 _upsert(hw_scan_config.device_tree_compatible_match, identity,
546 'device-tree-compatible-match')
David Burger7fd1dbe2020-03-26 09:26:55 -0600547
548 if brand_scan_config:
David Burger8ee9b4d2020-06-16 17:40:21 -0600549 _upsert(brand_scan_config.whitelabel_tag, identity, 'whitelabel-tag')
David Burger7fd1dbe2020-03-26 09:26:55 -0600550
551 return identity
552
553
Andrew Lambcd33f702020-06-11 10:45:16 -0600554def _lookup(id_value, id_map):
555 if not id_value.value:
556 return None
557
558 key = id_value.value
559 if key in id_map:
560 return id_map[id_value.value]
561 error = 'Failed to lookup %s with value: %s' % (
562 id_value.__class__.__name__.replace('Id', ''), key)
563 print(error)
564 print('Check the config contents provided:')
565 printer = pprint.PrettyPrinter(indent=4)
566 printer.pprint(id_map)
567 raise Exception(error)
David Burger7fd1dbe2020-03-26 09:26:55 -0600568
569
Andrew Lambcd33f702020-06-11 10:45:16 -0600570def _build_touch_file_config(config, project_name):
Sean McAllistereaf10b72020-08-03 13:41:06 -0600571 partners = {x.id.value: x for x in config.partner_list}
C Shapiro2b6d5332020-05-06 17:51:35 -0500572 files = []
573 for comp in config.components:
C Shapiro4813be62020-05-13 17:31:58 -0500574 touch = comp.touchscreen
575 # Everything is the same for Touch screen/pad, except different fields
576 if comp.HasField('touchpad'):
577 touch = comp.touchpad
578 if touch.product_id:
Andrew Lambcd33f702020-06-11 10:45:16 -0600579 vendor = _lookup(comp.manufacturer_id, partners)
C Shapiro2b6d5332020-05-06 17:51:35 -0500580 if not vendor:
Andrew Lamb2413c982020-05-29 12:15:36 -0600581 raise Exception("Manufacturer must be set for touch device %s" %
582 comp.id.value)
C Shapiro2b6d5332020-05-06 17:51:35 -0500583
C Shapiro4813be62020-05-13 17:31:58 -0500584 product_id = touch.product_id
585 fw_version = touch.fw_version
C Shapiro2b6d5332020-05-06 17:51:35 -0500586
C Shapiro2b6d5332020-05-06 17:51:35 -0500587 file_name = "%s_%s.bin" % (product_id, fw_version)
588 fw_file_path = os.path.join(TOUCH_PATH, vendor.name, file_name)
589
590 if not os.path.exists(fw_file_path):
Andrew Lamb2413c982020-05-29 12:15:36 -0600591 raise Exception("Touchscreen fw bin file doesn't exist at: %s" %
592 fw_file_path)
C Shapiro2b6d5332020-05-06 17:51:35 -0500593
C Shapiro303cece2020-07-22 07:15:21 -0500594 touch_vendor = vendor.touch_vendor
595 sym_link = touch_vendor.symlink_file_format.format(
596 vendor_name=vendor.name,
597 vendor_id=touch_vendor.vendor_id,
598 product_id=product_id,
599 fw_version=fw_version,
600 product_series=touch.product_series)
601
602 dest = "%s_%s" % (vendor.name, file_name)
603 if touch_vendor.destination_file_format:
604 dest = touch_vendor.destination_file_format.format(
605 vendor_name=vendor.name,
606 vendor_id=touch_vendor.vendor_id,
607 product_id=product_id,
608 fw_version=fw_version,
609 product_series=touch.product_series)
610
C Shapiro2b6d5332020-05-06 17:51:35 -0500611 files.append({
C Shapiro303cece2020-07-22 07:15:21 -0500612 "destination": os.path.join("/opt/google/touch/firmware", dest),
YH Lin9160fc52020-07-22 16:35:28 -0700613 "source": os.path.join(project_name, fw_file_path),
614 "symlink": os.path.join("/lib/firmware", sym_link),
C Shapiro2b6d5332020-05-06 17:51:35 -0500615 })
616
617 result = {}
David Burger8ee9b4d2020-06-16 17:40:21 -0600618 _upsert(files, result, 'files')
C Shapiro2b6d5332020-05-06 17:51:35 -0500619 return result
620
621
Vincent Palatin2ef6bd62021-01-04 14:47:31 +0000622def _build_modem(config):
623 """Returns the cellular modem configuration, or None if absent."""
624 hw_features = config.hw_design_config.hardware_features
625 lte_support = _any_present([hw_features.lte.present])
626 if not lte_support:
627 return None
628 return {'firmware-variant': config.hw_design.name.lower()}
629
630
David Burgerceeb68a2020-09-03 11:31:10 -0600631def _sw_config(sw_configs, design_config_id):
632 """Returns the correct software config for `design_config_id`.
633
634 Returns the correct software config match for `design_config_id`. If no such
635 config or multiple such configs are found an exception is raised.
636 """
637 sw_config_matches = [
638 x for x in sw_configs if x.design_config_id.value == design_config_id
639 ]
640 if len(sw_config_matches) == 1:
641 return sw_config_matches[0]
642 if len(sw_config_matches) > 1:
643 raise ValueError('Multiple software configs found for: %s' %
644 design_config_id)
645 raise ValueError('Software config is required for: %s' % design_config_id)
646
647
Sam McNallyfd14e4b2020-09-12 10:26:35 +1000648def _is_whitelabel(brand_configs, device_brands):
649 for device_brand in device_brands:
650 if device_brand.id.value in brand_configs:
651 brand_scan_config = brand_configs[device_brand.id.value].scan_config
652 if brand_scan_config and brand_scan_config.whitelabel_tag:
653 return True
654 return False
655
656
David Burgerceeb68a2020-09-03 11:31:10 -0600657def _transform_build_configs(config,
Ren-Pei Zengacf03be2020-11-11 13:56:51 +0800658 config_files=ConfigFiles({}, {}, {}, {}, {}, {})):
Andrew Lambcd33f702020-06-11 10:45:16 -0600659 # pylint: disable=too-many-locals,too-many-branches
Sean McAllistereaf10b72020-08-03 13:41:06 -0600660 partners = {x.id.value: x for x in config.partner_list}
Sean McAllisterf38d1e92020-08-03 13:57:53 -0600661 programs = {x.id.value: x for x in config.program_list}
David Burger7fd1dbe2020-03-26 09:26:55 -0600662 sw_configs = list(config.software_configs)
Andrew Lambcd33f702020-06-11 10:45:16 -0600663 brand_configs = {x.brand_id.value: x for x in config.brand_configs}
David Burger7fd1dbe2020-03-26 09:26:55 -0600664
665 results = {}
Sean McAllisterf66887b2020-08-03 14:00:51 -0600666 for hw_design in config.design_list:
Sean McAllister6cbb0ec2020-08-03 14:03:37 -0600667 if config.device_brand_list:
Andrew Lamb2413c982020-05-29 12:15:36 -0600668 device_brands = [
Sean McAllister6cbb0ec2020-08-03 14:03:37 -0600669 x for x in config.device_brand_list
Andrew Lamb2413c982020-05-29 12:15:36 -0600670 if x.design_id.value == hw_design.id.value
671 ]
David Burger7fd1dbe2020-03-26 09:26:55 -0600672 else:
673 device_brands = [device_brand_pb2.DeviceBrand()]
674
Sam McNallyfd14e4b2020-09-12 10:26:35 +1000675 whitelabel = _is_whitelabel(brand_configs, device_brands)
676
David Burger7fd1dbe2020-03-26 09:26:55 -0600677 for device_brand in device_brands:
678 # Brand config can be empty since platform JSON config allows it
679 brand_config = brand_config_pb2.BrandConfig()
680 if device_brand.id.value in brand_configs:
681 brand_config = brand_configs[device_brand.id.value]
682
683 for hw_design_config in hw_design.configs:
David Burgerceeb68a2020-09-03 11:31:10 -0600684 sw_config = _sw_config(sw_configs, hw_design_config.id.value)
Andrew Lambcd33f702020-06-11 10:45:16 -0600685 program = _lookup(hw_design.program_id, programs)
C Shapiroadefd7c2020-05-19 16:37:21 -0500686 signer_configs_by_design = {}
687 signer_configs_by_brand = {}
688 for signer_config in program.device_signer_configs:
689 design_id = signer_config.design_id.value
690 brand_id = signer_config.brand_id.value
691 if design_id:
692 signer_configs_by_design[design_id] = signer_config
693 elif brand_id:
694 signer_configs_by_brand[brand_id] = signer_config
695 else:
696 raise Exception('No ID found for signer config: %s' % signer_config)
697
C Shapiro2f0bb5d2020-04-14 10:07:47 -0500698 device_signer_config = None
C Shapiroadefd7c2020-05-19 16:37:21 -0500699 if signer_configs_by_design or signer_configs_by_brand:
700 design_id = hw_design.id.value
701 brand_id = device_brand.id.value
702 if design_id in signer_configs_by_design:
703 device_signer_config = signer_configs_by_design[design_id]
704 elif brand_id in signer_configs_by_brand:
705 device_signer_config = signer_configs_by_brand[brand_id]
706 else:
707 # Assume that if signer configs are set, every config is setup
Andrew Lamb2413c982020-05-29 12:15:36 -0600708 raise Exception('Signer config missing for design: %s, brand: %s' %
709 (design_id, brand_id))
C Shapiro2f0bb5d2020-04-14 10:07:47 -0500710
Andrew Lambcd33f702020-06-11 10:45:16 -0600711 transformed_config = _transform_build_config(
C Shapiro90fda252020-04-17 14:34:57 -0500712 Config(
713 program=program,
714 hw_design=hw_design,
Andrew Lambcd33f702020-06-11 10:45:16 -0600715 odm=_lookup(hw_design.odm_id, partners),
C Shapiro90fda252020-04-17 14:34:57 -0500716 hw_design_config=hw_design_config,
717 device_brand=device_brand,
718 device_signer_config=device_signer_config,
Andrew Lambcd33f702020-06-11 10:45:16 -0600719 oem=_lookup(device_brand.oem_id, partners),
C Shapiro90fda252020-04-17 14:34:57 -0500720 sw_config=sw_config,
C Shapirod5545f12020-11-30 16:37:04 -0600721 brand_config=brand_config), config_files, whitelabel)
David Burger7fd1dbe2020-03-26 09:26:55 -0600722
Andrew Lamb2413c982020-05-29 12:15:36 -0600723 config_json = json.dumps(
724 transformed_config,
725 sort_keys=True,
726 indent=2,
727 separators=(',', ': '))
David Burger7fd1dbe2020-03-26 09:26:55 -0600728
729 if config_json not in results:
730 results[config_json] = transformed_config
731
732 return list(results.values())
733
734
Sam McNallyfd14e4b2020-09-12 10:26:35 +1000735def _transform_build_config(config, config_files, whitelabel):
David Burger7fd1dbe2020-03-26 09:26:55 -0600736 """Transforms Config instance into target platform JSON schema.
737
738 Args:
739 config: Config namedtuple
C Shapiro5bf23a72020-04-24 11:40:17 -0500740 config_files: Map to look up the generated config files.
Sam McNallyfd14e4b2020-09-12 10:26:35 +1000741 whitelabel: Whether the config is for a whitelabel design
David Burger7fd1dbe2020-03-26 09:26:55 -0600742
743 Returns:
744 Unique config payload based on the platform JSON schema.
745 """
746 result = {
Andrew Lamb2413c982020-05-29 12:15:36 -0600747 'identity':
Andrew Lambcd33f702020-06-11 10:45:16 -0600748 _build_identity(config.sw_config.id_scan_config, config.program,
749 config.brand_config.scan_config),
Andrew Lamb2413c982020-05-29 12:15:36 -0600750 'name':
751 config.hw_design.name.lower(),
David Burger7fd1dbe2020-03-26 09:26:55 -0600752 }
753
David Burger8ee9b4d2020-06-16 17:40:21 -0600754 _upsert(_build_arc(config, config_files), result, 'arc')
755 _upsert(_build_audio(config), result, 'audio')
David Burger07af5242020-08-11 11:08:25 -0600756 _upsert(_build_bluetooth(config), result, 'bluetooth')
David Burgerceeb68a2020-09-03 11:31:10 -0600757 _upsert(_build_wifi(config, config_files), result, 'wifi')
Andrew Lambca279902020-08-06 10:13:42 -0600758 _upsert(config.brand_config.wallpaper, result, 'wallpaper')
C Shapiro2e97aad2020-11-16 11:58:10 -0600759 _upsert(config.brand_config.regulatory_label, result, 'regulatory-label')
David Burger8ee9b4d2020-06-16 17:40:21 -0600760 _upsert(config.device_brand.brand_code, result, 'brand-code')
761 _upsert(
Andrew Lambcd33f702020-06-11 10:45:16 -0600762 _build_camera(config.hw_design_config.hardware_topology), result,
763 'camera')
David Burger8ee9b4d2020-06-16 17:40:21 -0600764 _upsert(_build_firmware(config), result, 'firmware')
Sam McNallyfd14e4b2020-09-12 10:26:35 +1000765 _upsert(_build_fw_signing(config, whitelabel), result, 'firmware-signing')
David Burger8ee9b4d2020-06-16 17:40:21 -0600766 _upsert(
Andrew Lambcd33f702020-06-11 10:45:16 -0600767 _build_fingerprint(config.hw_design_config.hardware_topology), result,
Andrew Lamb2413c982020-05-29 12:15:36 -0600768 'fingerprint')
Andrew Lamb0d236ab2020-06-30 12:30:20 -0600769 _upsert(_build_ui(config), result, 'ui')
David Burger7fd1dbe2020-03-26 09:26:55 -0600770 power_prefs = config.sw_config.power_config.preferences
771 power_prefs_map = dict(
Andrew Lamb2413c982020-05-29 12:15:36 -0600772 (x.replace('_', '-'), power_prefs[x]) for x in power_prefs)
David Burger8ee9b4d2020-06-16 17:40:21 -0600773 _upsert(power_prefs_map, result, 'power')
774 if config_files.camera_map:
775 camera_file = config_files.camera_map.get(config.hw_design.name, {})
776 _upsert(camera_file, result, 'camera')
David Burger52c9d322020-06-09 07:16:18 -0600777 if config_files.dptf_map:
778 # Prefer design specific if found, if not fall back to project wide config
779 # mapped under the empty string.
780 if config_files.dptf_map.get(config.hw_design.name):
781 dptf_file = config_files.dptf_map[config.hw_design.name]
782 else:
783 dptf_file = config_files.dptf_map.get('')
David Burger8ee9b4d2020-06-16 17:40:21 -0600784 _upsert(dptf_file, result, 'thermal')
785 _upsert(config_files.touch_fw, result, 'touch')
Trent Beginf067ccb2020-08-12 12:33:53 -0600786 _upsert(
787 _build_hardware_properties(config.hw_design_config.hardware_topology),
788 result, 'hardware-properties')
Vincent Palatin2ef6bd62021-01-04 14:47:31 +0000789 _upsert(_build_modem(config), result, 'modem')
David Burger7fd1dbe2020-03-26 09:26:55 -0600790
791 return result
792
793
Andrew Lambcd33f702020-06-11 10:45:16 -0600794def write_output(configs, output=None):
David Burger7fd1dbe2020-03-26 09:26:55 -0600795 """Writes a list of configs to platform JSON format.
796
797 Args:
798 configs: List of config dicts defined in cros_config_schema.yaml
799 output: Target file output (if None, prints to stdout)
800 """
Andrew Lamb2413c982020-05-29 12:15:36 -0600801 json_output = json.dumps({'chromeos': {
802 'configs': configs,
803 }},
804 sort_keys=True,
805 indent=2,
806 separators=(',', ': '))
David Burger7fd1dbe2020-03-26 09:26:55 -0600807 if output:
808 with open(output, 'w') as output_stream:
809 # Using print function adds proper trailing newline.
810 print(json_output, file=output_stream)
811 else:
812 print(json_output)
813
814
Andrew Lambcd33f702020-06-11 10:45:16 -0600815def _feature(name, present):
C Shapiro5bf23a72020-04-24 11:40:17 -0500816 attrib = {'name': name}
817 if present:
818 return etree.Element('feature', attrib=attrib)
Andrew Lambcd33f702020-06-11 10:45:16 -0600819
820 return etree.Element('unavailable-feature', attrib=attrib)
C Shapiro5bf23a72020-04-24 11:40:17 -0500821
822
Andrew Lambcd33f702020-06-11 10:45:16 -0600823def _any_present(features):
Andrew Lamb2413c982020-05-29 12:15:36 -0600824 return topology_pb2.HardwareFeatures.PRESENT in features
C Shapiro5bf23a72020-04-24 11:40:17 -0500825
826
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +0800827def _get_formatted_config_id(design_config):
C Shapiro5bf23a72020-04-24 11:40:17 -0500828 return design_config.id.value.lower().replace(':', '_')
829
830
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +0800831def _write_file(output_dir, file_name, file_content):
David Burger77a1d312020-05-23 16:05:45 -0600832 os.makedirs(output_dir, exist_ok=True)
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +0800833 output = '{}/{}'.format(output_dir, file_name)
C Shapiroea33cff2020-05-11 13:32:05 -0500834 with open(output, 'wb') as f:
835 f.write(file_content)
836
837
Ren-Pei Zengf22b5382020-09-02 13:31:22 +0800838def _get_arc_camera_features(camera):
839 """Gets camera related features for ARC hardware_features.xml from camera
840 topology. Check
841 https://developer.android.com/reference/android/content/pm/PackageManager#FEATURE_CAMERA
842 and CTS android.app.cts.SystemFeaturesTest#testCameraFeatures for the correct
843 settings.
844
845 Args:
846 camera: A HardwareFeatures.Camera proto message.
847 Returns:
848 list of camera related ARC features as XML elements.
849 """
850 camera_pb = topology_pb2.HardwareFeatures.Camera
851
Ren-Pei Zeng9b5682d2020-10-14 17:37:30 +0800852 count = len(camera.devices)
853 has_front_camera = any(
854 (d.facing == camera_pb.FACING_FRONT for d in camera.devices))
855 has_back_camera = any(
856 (d.facing == camera_pb.FACING_BACK for d in camera.devices))
857 has_autofocus_back_camera = any((d.facing == camera_pb.FACING_BACK and
858 d.flags & camera_pb.FLAGS_SUPPORT_AUTOFOCUS
859 for d in camera.devices))
860 # Assumes MIPI cameras support FULL-level.
861 # TODO(kamesan): Setting this in project configs when there's an exception.
862 has_level_full_camera = any(
863 (d.interface == camera_pb.INTERFACE_MIPI for d in camera.devices))
Ren-Pei Zengf22b5382020-09-02 13:31:22 +0800864
Ren-Pei Zengf22b5382020-09-02 13:31:22 +0800865 return [
866 _feature('android.hardware.camera', has_back_camera),
867 _feature('android.hardware.camera.any', count > 0),
868 _feature('android.hardware.camera.autofocus', has_autofocus_back_camera),
869 _feature('android.hardware.camera.capability.manual_post_processing',
870 has_level_full_camera),
871 _feature('android.hardware.camera.capability.manual_sensor',
872 has_level_full_camera),
873 _feature('android.hardware.camera.front', has_front_camera),
874 _feature('android.hardware.camera.level.full', has_level_full_camera),
875 ]
876
877
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +0800878def _generate_arc_hardware_features(hw_features):
879 """Generates ARC hardware_features.xml file content.
C Shapiro5bf23a72020-04-24 11:40:17 -0500880
881 Args:
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +0800882 hw_features: HardwareFeatures proto message.
C Shapiro5bf23a72020-04-24 11:40:17 -0500883 Returns:
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +0800884 bytes of the hardware_features.xml content.
C Shapiro5bf23a72020-04-24 11:40:17 -0500885 """
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +0800886 touchscreen = _any_present([hw_features.screen.touch_support])
887 acc = hw_features.accelerometer
888 gyro = hw_features.gyroscope
889 compass = hw_features.magnetometer
890 light_sensor = hw_features.light_sensor
891 root = etree.Element('permissions')
892 root.extend(
893 _get_arc_camera_features(hw_features.camera) + [
894 _feature(
895 'android.hardware.sensor.accelerometer',
896 _any_present([acc.lid_accelerometer, acc.base_accelerometer])),
897 _feature('android.hardware.sensor.gyroscope',
898 _any_present([gyro.lid_gyroscope, gyro.base_gyroscope])),
899 _feature(
900 'android.hardware.sensor.compass',
901 _any_present(
902 [compass.lid_magnetometer, compass.base_magnetometer])),
903 _feature(
904 'android.hardware.sensor.light',
905 _any_present([
906 light_sensor.lid_lightsensor, light_sensor.base_lightsensor
907 ])),
908 _feature('android.hardware.touchscreen', touchscreen),
909 _feature('android.hardware.touchscreen.multitouch', touchscreen),
910 _feature('android.hardware.touchscreen.multitouch.distinct',
911 touchscreen),
912 _feature('android.hardware.touchscreen.multitouch.jazzhand',
913 touchscreen),
914 ])
Ren-Pei Zengacf03be2020-11-11 13:56:51 +0800915 return XML_DECLARATION + etree.tostring(root, pretty_print=True)
916
917
918def _generate_arc_media_profiles(hw_features, sw_config):
919 """Generates ARC media_profiles.xml file content.
920
921 Args:
922 hw_features: HardwareFeatures proto message.
923 sw_config: SoftwareConfig proto message.
924 Returns:
925 bytes of the media_profiles.xml content, or None if |sw_config| disables the
Ren-Pei Zengb55e4312020-11-18 17:03:01 +0800926 generation or there's no camera.
Ren-Pei Zengacf03be2020-11-11 13:56:51 +0800927 """
928
929 def _gen_camcorder_profiles(camera_id, resolutions):
930 elem = etree.Element(
931 'CamcorderProfiles', attrib={'cameraId': str(camera_id)})
932 for width, height in resolutions:
933 elem.extend([
934 _gen_encoder_profile(width, height, False),
935 _gen_encoder_profile(width, height, True),
936 ])
937 elem.extend([
938 etree.Element('ImageEncoding', attrib={'quality': '90'}),
939 etree.Element('ImageEncoding', attrib={'quality': '80'}),
940 etree.Element('ImageEncoding', attrib={'quality': '70'}),
941 etree.Element('ImageDecoding', attrib={'memCap': '20000000'}),
942 ])
943 return elem
944
945 def _gen_encoder_profile(width, height, timelapse):
946 elem = etree.Element(
947 'EncoderProfile',
948 attrib={
949 'quality': ('timelapse' if timelapse else '') + str(height) + 'p',
950 'fileFormat': 'mp4',
951 'duration': '60',
952 })
953 elem.append(
954 etree.Element(
955 'Video',
956 attrib={
957 'codec': 'h264',
958 'bitRate': '8000000',
959 'width': str(width),
960 'height': str(height),
961 'frameRate': '30',
962 }))
963 elem.append(
964 etree.Element(
965 'Audio',
966 attrib={
967 'codec': 'aac',
968 'bitRate': '96000',
969 'sampleRate': '44100',
970 'channels': '1',
971 }))
972 return elem
973
974 def _gen_video_encoder_cap(name, min_bit_rate, max_bit_rate):
975 return etree.Element(
976 'VideoEncoderCap',
977 attrib={
978 'name': name,
979 'enabled': 'true',
980 'minBitRate': str(min_bit_rate),
981 'maxBitRate': str(max_bit_rate),
982 'minFrameWidth': '320',
983 'maxFrameWidth': '1920',
984 'minFrameHeight': '240',
985 'maxFrameHeight': '1080',
986 'minFrameRate': '15',
987 'maxFrameRate': '30',
988 })
989
990 def _gen_audio_encoder_cap(name, min_bit_rate, max_bit_rate, min_sample_rate,
991 max_sample_rate):
992 return etree.Element(
993 'AudioEncoderCap',
994 attrib={
995 'name': name,
996 'enabled': 'true',
997 'minBitRate': str(min_bit_rate),
998 'maxBitRate': str(max_bit_rate),
999 'minSampleRate': str(min_sample_rate),
1000 'maxSampleRate': str(max_sample_rate),
1001 'minChannels': '1',
1002 'maxChannels': '1',
1003 })
1004
1005 camera_config = sw_config.camera_config
1006 if not camera_config.generate_media_profiles:
1007 return None
1008
1009 camera_pb = topology_pb2.HardwareFeatures.Camera
1010 root = etree.Element('MediaSettings')
1011 camera_id = 0
1012 for facing in [camera_pb.FACING_BACK, camera_pb.FACING_FRONT]:
1013 camera_device = next(
1014 (d for d in hw_features.camera.devices if d.facing == facing), None)
1015 if camera_device is None:
1016 continue
1017 if camera_config.camcorder_resolutions:
1018 resolutions = [
1019 (r.width, r.height) for r in camera_config.camcorder_resolutions
1020 ]
1021 else:
1022 resolutions = [(1280, 720)]
1023 if camera_device.flags & camera_pb.FLAGS_SUPPORT_1080P:
1024 resolutions.append((1920, 1080))
1025 root.append(_gen_camcorder_profiles(camera_id, resolutions))
1026 camera_id += 1
Ren-Pei Zengb55e4312020-11-18 17:03:01 +08001027 # media_profiles.xml should have at least one CamcorderProfiles.
1028 if camera_id == 0:
1029 return None
Ren-Pei Zengacf03be2020-11-11 13:56:51 +08001030
1031 root.extend([
1032 etree.Element('EncoderOutputFileFormat', attrib={'name': '3gp'}),
1033 etree.Element('EncoderOutputFileFormat', attrib={'name': 'mp4'}),
1034 _gen_video_encoder_cap('h264', 64000, 17000000),
1035 _gen_video_encoder_cap('h263', 64000, 1000000),
1036 _gen_video_encoder_cap('m4v', 64000, 2000000),
1037 _gen_audio_encoder_cap('aac', 758, 288000, 8000, 48000),
1038 _gen_audio_encoder_cap('heaac', 8000, 64000, 16000, 48000),
1039 _gen_audio_encoder_cap('aaceld', 16000, 192000, 16000, 48000),
1040 _gen_audio_encoder_cap('amrwb', 6600, 23050, 16000, 16000),
1041 _gen_audio_encoder_cap('amrnb', 5525, 12200, 8000, 8000),
1042 etree.Element(
1043 'VideoDecoderCap', attrib={
1044 'name': 'wmv',
1045 'enabled': 'false'
1046 }),
1047 etree.Element(
1048 'AudioDecoderCap', attrib={
1049 'name': 'wma',
1050 'enabled': 'false'
1051 }),
1052 ])
Ren-Pei Zeng21708cc2020-11-17 11:14:07 +08001053
1054 dtd_path = os.path.dirname(__file__)
1055 dtd = etree.DTD(os.path.join(dtd_path, 'media_profiles.dtd'))
1056 if not dtd.validate(root):
1057 raise etree.DTDValidateError(
1058 'Invalid media_profiles.xml generated:\n{}'.format(dtd.error_log))
1059
Ren-Pei Zengacf03be2020-11-11 13:56:51 +08001060 return XML_DECLARATION + etree.tostring(root, pretty_print=True)
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +08001061
1062
1063def _write_files_by_design_config(configs, output_dir, build_dir, system_dir,
1064 file_name_template, generate_file_content):
1065 """Writes generated files for each design config.
1066
1067 Args:
1068 configs: Source ConfigBundle to process.
1069 output_dir: Path to the generated output.
1070 build_dir: Path to the config file from portage's perspective.
1071 system_dir: Path to the config file in the target device.
1072 file_name_template: Template string of the config file name including one
1073 format()-style replacement field for the config id, e.g. 'config_{}.xml'.
1074 generate_file_content: Function to generate config file content from
Ren-Pei Zengacf03be2020-11-11 13:56:51 +08001075 HardwareFeatures and SoftwareConfig proto.
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +08001076 Returns:
1077 dict that maps the formatted config id to the correct file.
1078 """
1079 # pylint: disable=too-many-arguments,too-many-locals
C Shapiro5bf23a72020-04-24 11:40:17 -05001080 result = {}
C Shapiroea33cff2020-05-11 13:32:05 -05001081 configs_by_design = {}
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +08001082 for hw_design in configs.design_list:
C Shapiro5bf23a72020-04-24 11:40:17 -05001083 for design_config in hw_design.configs:
Ren-Pei Zengacf03be2020-11-11 13:56:51 +08001084 sw_config = _sw_config(configs.software_configs, design_config.id.value)
1085 config_content = generate_file_content(design_config.hardware_features,
1086 sw_config)
1087 if not config_content:
1088 continue
C Shapiroea33cff2020-05-11 13:32:05 -05001089 design_name = hw_design.name.lower()
C Shapiro5bf23a72020-04-24 11:40:17 -05001090
C Shapiroea33cff2020-05-11 13:32:05 -05001091 # Constructs the following map:
1092 # design_name -> config -> design_configs
1093 # This allows any of the following file naming schemes:
1094 # - All configs within a design share config (design_name prefix only)
1095 # - Nobody shares (full design_name and config id prefix needed)
1096 #
1097 # Having shared configs when possible makes code reviews easier around
1098 # the configs and makes debugging easier on the platform side.
C Shapiroea33cff2020-05-11 13:32:05 -05001099 arc_configs = configs_by_design.get(design_name, {})
1100 design_configs = arc_configs.get(config_content, [])
1101 design_configs.append(design_config)
1102 arc_configs[config_content] = design_configs
1103 configs_by_design[design_name] = arc_configs
C Shapiro9a3ac8c2020-04-25 07:49:21 -05001104
C Shapiroea33cff2020-05-11 13:32:05 -05001105 for design_name, unique_configs in configs_by_design.items():
1106 for file_content, design_configs in unique_configs.items():
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +08001107 file_name = file_name_template.format(design_name)
Andrew Lamb2413c982020-05-29 12:15:36 -06001108 if len(unique_configs) == 1:
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +08001109 _write_file(output_dir, file_name, file_content)
C Shapiro9a3ac8c2020-04-25 07:49:21 -05001110
Andrew Lamb2413c982020-05-29 12:15:36 -06001111 for design_config in design_configs:
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +08001112 config_id = _get_formatted_config_id(design_config)
Andrew Lamb2413c982020-05-29 12:15:36 -06001113 if len(unique_configs) > 1:
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +08001114 file_name = file_name_template.format(config_id)
1115 _write_file(output_dir, file_name, file_content)
1116 result[config_id] = _file_v2('{}/{}'.format(build_dir, file_name),
1117 '{}/{}'.format(system_dir, file_name))
C Shapiro5bf23a72020-04-24 11:40:17 -05001118 return result
1119
1120
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +08001121def _write_arc_hardware_feature_files(configs, output_root_dir, build_root_dir):
Ren-Pei Zengacf03be2020-11-11 13:56:51 +08001122 return _write_files_by_design_config(
1123 configs, output_root_dir + '/arc', build_root_dir + '/arc', '/etc',
1124 'hardware_features_{}.xml',
1125 lambda hw_features, _: _generate_arc_hardware_features(hw_features))
1126
1127
1128def _write_arc_media_profile_files(configs, output_root_dir, build_root_dir):
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +08001129 return _write_files_by_design_config(configs, output_root_dir + '/arc',
1130 build_root_dir + '/arc', '/etc',
Ren-Pei Zengacf03be2020-11-11 13:56:51 +08001131 'media_profiles_{}.xml',
1132 _generate_arc_media_profiles)
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +08001133
1134
Andrew Lambcd33f702020-06-11 10:45:16 -06001135def _read_config(path):
David Burgerd4f32962020-05-02 12:07:40 -06001136 """Reads a ConfigBundle proto from a json pb file.
David Burgere6f76222020-04-27 11:08:01 -06001137
1138 Args:
David Burgerd4f32962020-05-02 12:07:40 -06001139 path: Path to the file encoding the json pb proto.
David Burgere6f76222020-04-27 11:08:01 -06001140 """
1141 config = config_bundle_pb2.ConfigBundle()
1142 with open(path, 'r') as f:
1143 return json_format.Parse(f.read(), config)
1144
1145
Andrew Lambcd33f702020-06-11 10:45:16 -06001146def _merge_configs(configs):
David Burger7fd1dbe2020-03-26 09:26:55 -06001147 result = config_bundle_pb2.ConfigBundle()
1148 for config in configs:
1149 result.MergeFrom(config)
1150
1151 return result
1152
1153
David Burger1ba78a22020-06-18 18:42:47 -06001154def _camera_map(configs, project_name):
David Burger8ee9b4d2020-06-16 17:40:21 -06001155 """Produces a camera config map for the given configs.
1156
1157 Produces a map that maps from the design name to the camera config for that
1158 design.
1159
1160 Args:
1161 configs: Source ConfigBundle to process.
David Burger1ba78a22020-06-18 18:42:47 -06001162 project_name: Name of project processing for.
David Burger8ee9b4d2020-06-16 17:40:21 -06001163
1164 Returns:
1165 map from design name to camera config.
1166 """
1167 result = {}
Sean McAllisterf66887b2020-08-03 14:00:51 -06001168 for design in configs.design_list:
David Burger8ee9b4d2020-06-16 17:40:21 -06001169 design_name = design.name
David Burger0d9e8462020-06-19 14:12:37 -06001170 config_path = CAMERA_CONFIG_SOURCE_PATH_TEMPLATE.format(design_name.lower())
David Burger8ee9b4d2020-06-16 17:40:21 -06001171 if os.path.exists(config_path):
David Burger0d9e8462020-06-19 14:12:37 -06001172 destination = CAMERA_CONFIG_DEST_PATH_TEMPLATE.format(design_name.lower())
David Burger8ee9b4d2020-06-16 17:40:21 -06001173 result[design_name] = {
David Burger1ba78a22020-06-18 18:42:47 -06001174 'config-file':
1175 _file_v2(os.path.join(project_name, config_path), destination),
David Burger8ee9b4d2020-06-16 17:40:21 -06001176 }
1177 return result
1178
1179
David Burger52c9d322020-06-09 07:16:18 -06001180def _dptf_map(configs, project_name):
1181 """Produces a dptf map for the given configs.
1182
1183 Produces a map that maps from design name to the dptf file config for that
1184 design. It looks for the dptf files at:
David Burger2f0d9522020-07-30 10:52:28 -06001185 DPTF_PATH + '/' + DPTF_FILE
David Burger52c9d322020-06-09 07:16:18 -06001186 for a project wide config, that it maps under the empty string, and at:
David Burger2f0d9522020-07-30 10:52:28 -06001187 DPTF_PATH + '/' + design_name + '/' + DPTF_FILE
David Burger52c9d322020-06-09 07:16:18 -06001188 for design specific configs that it maps under the design name.
1189
1190 Args:
1191 configs: Source ConfigBundle to process.
1192 project_name: Name of project processing for.
1193
1194 Returns:
David Burger8ee9b4d2020-06-16 17:40:21 -06001195 map from design name or empty string (project wide), to dptf config.
David Burger52c9d322020-06-09 07:16:18 -06001196 """
1197 result = {}
David Burger52c9d322020-06-09 07:16:18 -06001198 # Looking at top level for project wide, and then for each design name
1199 # for design specific.
Sean McAllisterf66887b2020-08-03 14:00:51 -06001200 dirs = [""] + [d.name for d in configs.design_list]
David Burger52c9d322020-06-09 07:16:18 -06001201 for directory in dirs:
David Burgera2252762020-07-09 15:09:49 -06001202 design = directory.lower()
1203 if os.path.exists(os.path.join(DPTF_PATH, design, DPTF_FILE)):
David Burger2f0d9522020-07-30 10:52:28 -06001204 project_dptf_path = os.path.join(project_name, design, DPTF_FILE)
David Burger52c9d322020-06-09 07:16:18 -06001205 dptf_file = {
1206 'dptf-dv':
1207 project_dptf_path,
1208 'files': [
1209 _file(
David Burgera2252762020-07-09 15:09:49 -06001210 os.path.join(project_name, DPTF_PATH, design, DPTF_FILE),
David Burger52c9d322020-06-09 07:16:18 -06001211 os.path.join('/etc/dptf', project_dptf_path))
1212 ]
1213 }
1214 result[directory] = dptf_file
1215 return result
1216
1217
David Burgerceeb68a2020-09-03 11:31:10 -06001218def _wifi_sar_map(configs, project_name, output_dir, build_root_dir):
1219 """Constructs a map from design name to wifi sar config for that design.
1220
1221 Constructs a map from design name to the wifi sar config for that design.
1222 In the process a wifi sar hex file is generated that the config points at.
1223 This mapping is only made for the intel wifi where the generated file is
1224 provided when building coreboot.
1225
1226 Args:
1227 configs: Source ConfigBundle to process.
1228 project_name: Name of project processing for.
1229 output_dir: Path to the generated output.
Ren-Pei Zengc6ba15c2020-10-17 00:51:25 +08001230 build_root_dir: Path to the config file from portage's perspective.
David Burgerceeb68a2020-09-03 11:31:10 -06001231
1232 Returns:
1233 dict that maps the design name onto the wifi config for that design.
1234 """
1235 # pylint: disable=too-many-locals
1236 result = {}
1237 programs = {p.id.value: p for p in configs.program_list}
1238 sw_configs = list(configs.software_configs)
1239 for hw_design in configs.design_list:
1240 for hw_design_config in hw_design.configs:
1241 sw_config = _sw_config(sw_configs, hw_design_config.id.value)
1242 if sw_config.wifi_config.HasField('intel_config'):
1243 sar_file_content = _create_intel_sar_file_content(
1244 sw_config.wifi_config.intel_config)
1245 design_name = hw_design.name.lower()
1246 program = _lookup(hw_design.program_id, programs)
1247 wifi_sar_id = _extract_fw_config_value(hw_design_config, program,
1248 'Intel wifi sar id')
1249 output_path = os.path.join(output_dir, 'wifi')
1250 os.makedirs(output_path, exist_ok=True)
1251 filename = 'wifi_sar_{}.hex'.format(wifi_sar_id)
1252 output_path = os.path.join(output_path, filename)
1253 build_path = os.path.join(build_root_dir, 'wifi', filename)
1254 if os.path.exists(output_path):
1255 with open(output_path, 'r') as f:
1256 if f.read() != sar_file_content:
1257 raise Exception(
1258 'Project {} has conflicting wifi sar file content under '
1259 'wifi sar id {}.'.format(project_name, wifi_sar_id))
1260 else:
1261 with open(output_path, 'w') as f:
1262 f.write(sar_file_content)
1263 system_path = '/firmware/cbfs-rw-raw/{}/{}'.format(
1264 project_name, filename)
David Burger89e7cae2020-09-15 17:04:12 -06001265 result[design_name] = {'sar-file': _file_v2(build_path, system_path)}
David Burgerceeb68a2020-09-03 11:31:10 -06001266 return result
1267
1268
1269def _extract_fw_config_value(hw_design_config, program, name):
1270 """Extracts the firwmare config value with the given name.
1271
1272 Args:
1273 hw_design_config: Design extracting value from.
1274 program: Program the `hw_design_config` belongs to.
1275 name: Name of firmware config segment to extract.
1276
1277 Returns: the extracted value or raises a ValueError if no firmware
1278 configuration segment with `name` is found.
1279 """
1280 fw_config = hw_design_config.hardware_features.fw_config.value
1281 for fcs in program.firmware_configuration_segments:
1282 if fcs.name == name:
1283 value = fw_config & fcs.mask
1284 lsb_bit_set = (~fcs.mask + 1) & fcs.mask
1285 return value // lsb_bit_set
1286 raise ValueError(
1287 'No firmware configuration segment with name {} found'.format(name))
1288
1289
1290def _create_intel_sar_file_content(intel_config):
1291 """Creates and returns the intel sar file content for the given config.
1292
1293 Creates and returns the sar file content that is used with intel drivers
1294 only.
1295
1296 Args:
1297 intel_config: IntelConfig config.
1298
1299 Returns:
1300 sar file content for the given config, see:
1301 https://chromeos.google.com/partner/dlm/docs/connectivity/wifidyntxpower.html
1302 """
1303
1304 def to_hex(val):
1305 if val > 255 or val < 0:
1306 raise Exception('Sar file value %s out of range' % val)
1307 return '{0:0{1}X}'.format(val, 2)
1308
1309 def power_table(tpc):
1310 return (to_hex(tpc.limit_2g) + to_hex(tpc.limit_5g_1) +
1311 to_hex(tpc.limit_5g_2) + to_hex(tpc.limit_5g_3) +
1312 to_hex(tpc.limit_5g_4))
1313
1314 def wgds_value(wgds):
1315 return to_hex(wgds)
1316
1317 def offset_table(offsets):
1318 return (to_hex(offsets.max_2g) + to_hex(offsets.offset_2g_a) +
1319 to_hex(offsets.offset_2g_b) + to_hex(offsets.max_5g) +
1320 to_hex(offsets.offset_5g_a) + to_hex(offsets.offset_5g_b))
1321
1322 # See https://chromeos.google.com/partner/dlm/docs/connectivity/wifidyntxpower.html
1323 return (power_table(intel_config.tablet_mode_power_table_a) +
1324 power_table(intel_config.tablet_mode_power_table_b) +
1325 power_table(intel_config.non_tablet_mode_power_table_a) +
1326 power_table(intel_config.non_tablet_mode_power_table_b) +
1327 '00000000000000000000' + '00000000000000000000' +
1328 wgds_value(intel_config.wgds_version) +
1329 offset_table(intel_config.offset_fcc) +
1330 offset_table(intel_config.offset_eu) +
1331 offset_table(intel_config.offset_other))
1332
1333
Andrew Lambcd33f702020-06-11 10:45:16 -06001334def Main(project_configs, program_config, output): # pylint: disable=invalid-name
David Burger7fd1dbe2020-03-26 09:26:55 -06001335 """Transforms source proto config into platform JSON.
1336
1337 Args:
1338 project_configs: List of source project configs to transform.
1339 program_config: Program config for the given set of projects.
1340 output: Output file that will be generated by the transform.
1341 """
Andrew Lambcd33f702020-06-11 10:45:16 -06001342 configs = _merge_configs([_read_config(program_config)] +
1343 [_read_config(config) for config in project_configs])
C Shapiro2b6d5332020-05-06 17:51:35 -05001344 touch_fw = {}
David Burger8ee9b4d2020-06-16 17:40:21 -06001345 camera_map = {}
David Burgerceeb68a2020-09-03 11:31:10 -06001346 dptf_map = {}
1347 wifi_sar_map = {}
C Shapiro5bf23a72020-04-24 11:40:17 -05001348 output_dir = os.path.dirname(output)
C Shapiro5c877992020-04-29 12:11:28 -05001349 build_root_dir = output_dir
C Shapiro5c877992020-04-29 12:11:28 -05001350 if 'sw_build_config' in output_dir:
1351 full_path = os.path.realpath(output)
Andrew Lamb6b607732020-08-24 15:52:46 -06001352 project_name = re.match(r'.*/(\w*)/(public_)?sw_build_config/.*',
Andrew Lamb2413c982020-05-29 12:15:36 -06001353 full_path).groups(1)[0]
C Shapiro5c877992020-04-29 12:11:28 -05001354 # Projects don't know about each other until they are integrated into the
1355 # build system. When this happens, the files need to be able to co-exist
1356 # without any collisions. This prefixes the project name (which is how
1357 # portage maps in the project), so project files co-exist and can be
1358 # installed together.
1359 # This is necessary to allow projects to share files at the program level
1360 # without having portage file installation collisions.
1361 build_root_dir = os.path.join(project_name, output_dir)
C Shapiro6830e6c2020-04-29 13:29:56 -05001362
David Burger1ba78a22020-06-18 18:42:47 -06001363 camera_map = _camera_map(configs, project_name)
David Burger52c9d322020-06-09 07:16:18 -06001364 dptf_map = _dptf_map(configs, project_name)
David Burgerceeb68a2020-09-03 11:31:10 -06001365 wifi_sar_map = _wifi_sar_map(configs, project_name, output_dir,
1366 build_root_dir)
David Burger52c9d322020-06-09 07:16:18 -06001367
C Shapiro2b6d5332020-05-06 17:51:35 -05001368 if os.path.exists(TOUCH_PATH):
Andrew Lambcd33f702020-06-11 10:45:16 -06001369 touch_fw = _build_touch_file_config(configs, project_name)
Andrew Lambcd33f702020-06-11 10:45:16 -06001370 arc_hw_feature_files = _write_arc_hardware_feature_files(
1371 configs, output_dir, build_root_dir)
Ren-Pei Zengacf03be2020-11-11 13:56:51 +08001372 arc_media_profile_files = _write_arc_media_profile_files(
1373 configs, output_dir, build_root_dir)
C Shapiro5bf23a72020-04-24 11:40:17 -05001374 config_files = ConfigFiles(
C Shapiro5bf23a72020-04-24 11:40:17 -05001375 arc_hw_features=arc_hw_feature_files,
Ren-Pei Zengacf03be2020-11-11 13:56:51 +08001376 arc_media_profiles=arc_media_profile_files,
C Shapiro2b6d5332020-05-06 17:51:35 -05001377 touch_fw=touch_fw,
David Burger8ee9b4d2020-06-16 17:40:21 -06001378 dptf_map=dptf_map,
David Burgerceeb68a2020-09-03 11:31:10 -06001379 camera_map=camera_map,
1380 wifi_sar_map=wifi_sar_map)
Andrew Lambcd33f702020-06-11 10:45:16 -06001381 write_output(_transform_build_configs(configs, config_files), output)
David Burger7fd1dbe2020-03-26 09:26:55 -06001382
1383
1384def main(argv=None):
1385 """Main program which parses args and runs
1386
1387 Args:
1388 argv: List of command line arguments, if None uses sys.argv.
1389 """
1390 if argv is None:
1391 argv = sys.argv[1:]
Andrew Lambcd33f702020-06-11 10:45:16 -06001392 opts = parse_args(argv)
David Burger7fd1dbe2020-03-26 09:26:55 -06001393 Main(opts.project_configs, opts.program_config, opts.output)
1394
1395
1396if __name__ == '__main__':
1397 sys.exit(main(sys.argv[1:]))