Implement XAP 'secure' core requirements (#16843)
Co-authored-by: Drashna Jaelre <drashna@live.com> Co-authored-by: Stefan Kerkmann <karlk90@pm.me>
This commit is contained in:
parent
ae4d518352
commit
92a61aa0cd
15 changed files with 312 additions and 13 deletions
|
@ -94,7 +94,12 @@ def generate_config_items(kb_info_json, config_h_lines):
|
|||
except KeyError:
|
||||
continue
|
||||
|
||||
if key_type.startswith('array'):
|
||||
if key_type.startswith('array.array'):
|
||||
config_h_lines.append('')
|
||||
config_h_lines.append(f'#ifndef {config_key}')
|
||||
config_h_lines.append(f'# define {config_key} {{ {", ".join(["{" + ",".join(list(map(str, x))) + "}" for x in config_value])} }}')
|
||||
config_h_lines.append(f'#endif // {config_key}')
|
||||
elif key_type.startswith('array'):
|
||||
config_h_lines.append('')
|
||||
config_h_lines.append(f'#ifndef {config_key}')
|
||||
config_h_lines.append(f'# define {config_key} {{ {", ".join(map(str, config_value))} }}')
|
||||
|
|
|
@ -168,28 +168,46 @@ def _extract_pins(pins):
|
|||
return [_pin_name(pin) for pin in pins.split(',')]
|
||||
|
||||
|
||||
def _extract_direct_matrix(direct_pins):
|
||||
def _extract_2d_array(raw):
|
||||
"""Return a 2d array of strings
|
||||
"""
|
||||
"""
|
||||
direct_pin_array = []
|
||||
out_array = []
|
||||
|
||||
while direct_pins[-1] != '}':
|
||||
direct_pins = direct_pins[:-1]
|
||||
while raw[-1] != '}':
|
||||
raw = raw[:-1]
|
||||
|
||||
for row in direct_pins.split('},{'):
|
||||
for row in raw.split('},{'):
|
||||
if row.startswith('{'):
|
||||
row = row[1:]
|
||||
|
||||
if row.endswith('}'):
|
||||
row = row[:-1]
|
||||
|
||||
direct_pin_array.append([])
|
||||
out_array.append([])
|
||||
|
||||
for pin in row.split(','):
|
||||
if pin == 'NO_PIN':
|
||||
pin = None
|
||||
for val in row.split(','):
|
||||
out_array[-1].append(val)
|
||||
|
||||
direct_pin_array[-1].append(pin)
|
||||
return out_array
|
||||
|
||||
|
||||
def _extract_2d_int_array(raw):
|
||||
"""Return a 2d array of ints
|
||||
"""
|
||||
ret = _extract_2d_array(raw)
|
||||
|
||||
return [list(map(int, x)) for x in ret]
|
||||
|
||||
|
||||
def _extract_direct_matrix(direct_pins):
|
||||
"""extract direct_matrix
|
||||
"""
|
||||
direct_pin_array = _extract_2d_array(direct_pins)
|
||||
|
||||
for i in range(len(direct_pin_array)):
|
||||
for j in range(len(direct_pin_array[i])):
|
||||
if direct_pin_array[i][j] == 'NO_PIN':
|
||||
direct_pin_array[i][j] = None
|
||||
|
||||
return direct_pin_array
|
||||
|
||||
|
@ -207,6 +225,21 @@ def _extract_audio(info_data, config_c):
|
|||
info_data['audio'] = {'pins': audio_pins}
|
||||
|
||||
|
||||
def _extract_secure_unlock(info_data, config_c):
|
||||
"""Populate data about the secure unlock sequence
|
||||
"""
|
||||
unlock = config_c.get('SECURE_UNLOCK_SEQUENCE', '').replace(' ', '')[1:-1]
|
||||
if unlock:
|
||||
unlock_array = _extract_2d_int_array(unlock)
|
||||
if 'secure' not in info_data:
|
||||
info_data['secure'] = {}
|
||||
|
||||
if 'unlock_sequence' in info_data['secure']:
|
||||
_log_warning(info_data, 'Secure unlock sequence is specified in both config.h (SECURE_UNLOCK_SEQUENCE) and info.json (secure.unlock_sequence) (Value: %s), the config.h value wins.' % info_data['secure']['unlock_sequence'])
|
||||
|
||||
info_data['secure']['unlock_sequence'] = unlock_array
|
||||
|
||||
|
||||
def _extract_split_main(info_data, config_c):
|
||||
"""Populate data about the split configuration
|
||||
"""
|
||||
|
@ -466,6 +499,7 @@ def _extract_config_h(info_data, config_c):
|
|||
# Pull data that easily can't be mapped in json
|
||||
_extract_matrix_info(info_data, config_c)
|
||||
_extract_audio(info_data, config_c)
|
||||
_extract_secure_unlock(info_data, config_c)
|
||||
_extract_split_main(info_data, config_c)
|
||||
_extract_split_transport(info_data, config_c)
|
||||
_extract_split_right_pins(info_data, config_c)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue