1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-01-18 20:11:20 +00:00

target/descriptor: Rework how parameter defaults are overridden.

Instead of supplying only the parameter name and value to be set as a
default, allow for replacing the entire parameter object as this allow
more control over what needs overriding for a particular platform.
This commit is contained in:
Marc Bonnici 2020-04-03 18:59:10 +01:00 committed by setrofim
parent a8abf24db0
commit 310bad3966

View File

@ -14,8 +14,6 @@
# #
import inspect import inspect
from collections import OrderedDict
from copy import copy
from devlib import (LinuxTarget, AndroidTarget, LocalLinuxTarget, from devlib import (LinuxTarget, AndroidTarget, LocalLinuxTarget,
ChromeOsTarget, Platform, Juno, TC2, Gem5SimulationPlatform, ChromeOsTarget, Platform, Juno, TC2, Gem5SimulationPlatform,
@ -506,30 +504,82 @@ ASSISTANTS = {
'chromeos': ChromeOsAssistant 'chromeos': ChromeOsAssistant
} }
# name --> ((platform_class, conn_class), params_list, defaults, target_defaults) # Platform specific parameter overrides.
JUNO_PLATFORM_OVERRIDES = [
Parameter('baudrate', kind=int, default=115200,
description='''
Baud rate for the serial connection.
'''),
Parameter('vemsd_mount', kind=str, default='/media/JUNO',
description='''
VExpress MicroSD card mount location. This is a MicroSD card in
the VExpress device that is mounted on the host via USB. The card
contains configuration files for the platform and firmware and
kernel images to be flashed.
'''),
Parameter('bootloader', kind=str, default='u-boot',
allowed_values=['uefi', 'uefi-shell', 'u-boot', 'bootmon'],
description='''
Selects the bootloader mechanism used by the board. Depending on
firmware version, a number of possible boot mechanisms may be use.
Please see ``devlib`` documentation for descriptions.
'''),
Parameter('hard_reset_method', kind=str, default='dtr',
allowed_values=['dtr', 'reboottxt'],
description='''
There are a couple of ways to reset VersatileExpress board if the
software running on the board becomes unresponsive. Both require
configuration to be enabled (please see ``devlib`` documentation).
``dtr``: toggle the DTR line on the serial connection
``reboottxt``: create ``reboot.txt`` in the root of the VEMSD mount.
'''),
]
TC2_PLATFORM_OVERRIDES = [
Parameter('baudrate', kind=int, default=38400,
description='''
Baud rate for the serial connection.
'''),
Parameter('vemsd_mount', kind=str, default='/media/VEMSD',
description='''
VExpress MicroSD card mount location. This is a MicroSD card in
the VExpress device that is mounted on the host via USB. The card
contains configuration files for the platform and firmware and
kernel images to be flashed.
'''),
Parameter('bootloader', kind=str, default='bootmon',
allowed_values=['uefi', 'uefi-shell', 'u-boot', 'bootmon'],
description='''
Selects the bootloader mechanism used by the board. Depending on
firmware version, a number of possible boot mechanisms may be use.
Please see ``devlib`` documentation for descriptions.
'''),
Parameter('hard_reset_method', kind=str, default='reboottxt',
allowed_values=['dtr', 'reboottxt'],
description='''
There are a couple of ways to reset VersatileExpress board if the
software running on the board becomes unresponsive. Both require
configuration to be enabled (please see ``devlib`` documentation).
``dtr``: toggle the DTR line on the serial connection
``reboottxt``: create ``reboot.txt`` in the root of the VEMSD mount.
'''),
]
# name --> ((platform_class, conn_class), params_list, defaults, target_overrides)
# Note: normally, connection is defined by the Target name, but # Note: normally, connection is defined by the Target name, but
# platforms may choose to override it # platforms may choose to override it
# Note: the target_defaults allows you to override common target_params for a # Note: the target_overrides allows you to override common target_params for a
# particular platform. Parameters you can override are in COMMON_TARGET_PARAMS # particular platform. Parameters you can override are in COMMON_TARGET_PARAMS
# Example of overriding one of the target parameters: Replace last None with: # Example of overriding one of the target parameters: Replace last `None` with
# {'shell_prompt': CUSTOM__SHELL_PROMPT} # a list of `Parameter` objects to be used instead.
PLATFORMS = { PLATFORMS = {
'generic': ((Platform, None), COMMON_PLATFORM_PARAMS, None, None), 'generic': ((Platform, None), COMMON_PLATFORM_PARAMS, None, None),
'juno': ((Juno, None), COMMON_PLATFORM_PARAMS + VEXPRESS_PLATFORM_PARAMS, 'juno': ((Juno, None), COMMON_PLATFORM_PARAMS + VEXPRESS_PLATFORM_PARAMS, JUNO_PLATFORM_OVERRIDES, None),
{
'vemsd_mount': '/media/JUNO',
'baudrate': 115200,
'bootloader': 'u-boot',
'hard_reset_method': 'dtr',
},
None),
'tc2': ((TC2, None), COMMON_PLATFORM_PARAMS + VEXPRESS_PLATFORM_PARAMS, 'tc2': ((TC2, None), COMMON_PLATFORM_PARAMS + VEXPRESS_PLATFORM_PARAMS,
{ TC2_PLATFORM_OVERRIDES, None),
'vemsd_mount': '/media/VEMSD',
'baudrate': 38400,
'bootloader': 'bootmon',
'hard_reset_method': 'reboottxt',
}, None),
'gem5': ((Gem5SimulationPlatform, Gem5Connection), GEM5_PLATFORM_PARAMS, None, None), 'gem5': ((Gem5SimulationPlatform, Gem5Connection), GEM5_PLATFORM_PARAMS, None, None),
} }
@ -560,8 +610,7 @@ class DefaultTargetDescriptor(TargetDescriptor):
if platform in unsupported_platforms: if platform in unsupported_platforms:
continue continue
# Add target defaults specified in the Platform tuple # Add target defaults specified in the Platform tuple
target_params = self._apply_param_defaults(target_params, target_params = self._override_params(target_params, platform_target_defaults)
platform_target_defaults)
name = '{}_{}'.format(platform_name, target_name) name = '{}_{}'.format(platform_name, target_name)
td = TargetDescription(name, self) td = TargetDescription(name, self)
td.target = target td.target = target
@ -581,22 +630,16 @@ class DefaultTargetDescriptor(TargetDescriptor):
result.append(td) result.append(td)
return result return result
def _apply_param_defaults(self, params, defaults): # pylint: disable=no-self-use def _override_params(self, params, overrides): # pylint: disable=no-self-use
'''Adds parameters in the defaults dict to params list. ''' Returns a new list of parameters replacing any parameter with the
Return updated params as a list (idempotent function).''' correesponding parameter in overrides'''
if not defaults: if not overrides:
return params return params
param_map = OrderedDict((p.name, copy(p)) for p in params) return [o if p.match(o.name) else p for o in overrides for p in params]
for name, value in defaults.items():
if name not in param_map:
raise ValueError('Unexpected default "{}"'.format(name))
param_map[name].default = value
# Convert the OrderedDict to a list to return the same type
return list(param_map.values())
def _get_item(self, item_tuple): def _get_item(self, item_tuple):
cls, params, defaults = item_tuple cls, params, defaults, = item_tuple
updated_params = self._apply_param_defaults(params, defaults) updated_params = self._override_params(params, defaults)
return cls, updated_params return cls, updated_params