Skip to content

Commit

Permalink
feat (build system): use SUIT_ENVELOPE_SEQUENCE_NUM to set version on…
Browse files Browse the repository at this point in the history
… the NCS templates

feat (build system): add BuildConfiguration to the build.py script
feat (build system): use KConfig values for templates generation

Signed-off-by: Robert Stypa <[email protected]>
  • Loading branch information
robertstypa committed Feb 27, 2024
1 parent 2c2ff23 commit b37829a
Show file tree
Hide file tree
Showing 14 changed files with 109 additions and 555 deletions.
22 changes: 6 additions & 16 deletions ncs/802154_rad_envelope.yaml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SUIT_Envelope_Tagged:
suit-digest-algorithm-id: cose-alg-sha-256
suit-manifest:
suit-manifest-version: 1
suit-manifest-sequence-number: {{ version }}
suit-manifest-sequence-number: {{ app['config']['SUIT_ENVELOPE_SEQUENCE_NUM'] }}
suit-common:
suit-components:
- - MEM
Expand All @@ -17,11 +17,11 @@ SUIT_Envelope_Tagged:
- suit-directive-set-component-index: 0
- suit-directive-override-parameters:
suit-parameter-vendor-identifier:
RFC4122_UUID: nordicsemi.com
RFC4122_UUID: {{ app['config']['CONFIG_SUIT_MPI_RAD_LOCAL_1_VENDOR_NAME']|default('nordicsemi.com') }}
suit-parameter-class-identifier:
RFC4122_UUID:
namespace: nordicsemi.com
name: nRF54H20_sample_rad
namespace: {{ app['config']['CONFIG_SUIT_MPI_RAD_LOCAL_1_VENDOR_NAME']|default('nordicsemi.com') }}
name: {{ app['config']['CONFIG_SUIT_MPI_RAD_LOCAL_1_CLASS_NAME']|default('nRF54H20_sample_rad') }}
suit-parameter-image-digest:
suit-digest-algorithm-id: cose-alg-sha-256
suit-digest-bytes:
Expand Down Expand Up @@ -76,20 +76,10 @@ SUIT_Envelope_Tagged:
- suit-send-record-failure
- suit-send-sysinfo-success
- suit-send-sysinfo-failure
suit-text:
suit-digest-algorithm-id: cose-alg-sha-256
suit-manifest-component-id:
- INSTLD_MFST
- RFC4122_UUID:
namespace: nordicsemi.com
name: nRF54H20_sample_rad
suit-text:
'["MEM", {{ _802154_rpmsg_subimage['dt'].label2node['cpu'].unit_addr }}, {{ get_absolute_address(_802154_rpmsg_subimage['dt'].chosen_nodes['zephyr,code-partition']) }}, {{ _802154_rpmsg_subimage['dt'].chosen_nodes['zephyr,code-partition'].regs[0].size }}]':
suit-text-vendor-name: Nordic Semiconductor ASA
suit-text-model-name: nRF54H20_cpurad
suit-text-vendor-domain: nordicsemi.com
suit-text-model-info: The nRF54H20 radio core
suit-text-component-description: Sample radio core FW
suit-text-component-version: v1.0.0
namespace: {{ app['config']['CONFIG_SUIT_MPI_RAD_LOCAL_1_VENDOR_NAME']|default('nordicsemi.com') }}
name: {{ app['config']['CONFIG_SUIT_MPI_RAD_LOCAL_1_CLASS_NAME']|default('nRF54H20_sample_rad') }}
suit-integrated-payloads:
'#{{ _802154_rpmsg_subimage['name'] }}': {{ _802154_rpmsg_subimage['binary'] }}
18 changes: 4 additions & 14 deletions ncs/app_envelope.yaml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SUIT_Envelope_Tagged:
suit-digest-algorithm-id: cose-alg-sha-256
suit-manifest:
suit-manifest-version: 1
suit-manifest-sequence-number: {{ version }}
suit-manifest-sequence-number: {{ app['config']['SUIT_ENVELOPE_SEQUENCE_NUM'] }}
suit-common:
suit-components:
- - MEM
Expand All @@ -23,11 +23,11 @@ SUIT_Envelope_Tagged:
- suit-directive-set-component-index: 0
- suit-directive-override-parameters:
suit-parameter-vendor-identifier:
RFC4122_UUID: nordicsemi.com
RFC4122_UUID: {{ app['config']['CONFIG_SUIT_MPI_APP_LOCAL_1_VENDOR_NAME']|default('nordicsemi.com') }}
suit-parameter-class-identifier:
RFC4122_UUID:
namespace: nordicsemi.com
name: nRF54H20_sample_app
namespace: {{ app['config']['CONFIG_SUIT_MPI_APP_LOCAL_1_VENDOR_NAME']|default('nordicsemi.com') }}
name: {{ app['config']['CONFIG_SUIT_MPI_APP_LOCAL_1_CLASS_NAME']|default('nRF54H20_sample_app') }}
suit-parameter-image-digest:
suit-digest-algorithm-id: cose-alg-sha-256
suit-digest-bytes:
Expand Down Expand Up @@ -122,21 +122,11 @@ SUIT_Envelope_Tagged:
- suit-send-record-failure
- suit-send-sysinfo-success
- suit-send-sysinfo-failure
suit-text:
suit-digest-algorithm-id: cose-alg-sha-256
suit-manifest-component-id:
- INSTLD_MFST
- RFC4122_UUID:
namespace: nordicsemi.com
name: nRF54H20_sample_app
suit-text:
'["MEM", {{ app['dt'].label2node['cpu'].unit_addr }}, {{ get_absolute_address(app['dt'].chosen_nodes['zephyr,code-partition']) }}, {{ app['dt'].chosen_nodes['zephyr,code-partition'].regs[0].size }}]':
suit-text-vendor-name: Nordic Semiconductor ASA
suit-text-model-name: nRF54H20_cpuapp
suit-text-vendor-domain: nordicsemi.com
suit-text-model-info: The nRF54H20 application core
suit-text-component-description: Sample application core FW
suit-text-component-version: v1.0.0
suit-integrated-payloads:
'#{{ app['name'] }}': {{ app['binary'] }}
{%- if flash_companion_subimage is defined %}
Expand Down
45 changes: 37 additions & 8 deletions ncs/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,56 @@
dir_path = pathlib.Path(__file__).parent.absolute()


def convert(edt_object):
"""Convert devicetree representation into simplified object."""
# TODO: returned data shall contain basic and the most important settings to simplify templates
data = edt_object.label2node
data["compat2vendor"] = edt_object.compat2vendor
return data
class BuildConfiguration(dict):
"""Represents a build system configuration, providing access to KConfig values.
This class reads configuration data from a specified file and parses it.
Configuration data is accessible as a dictionary.
"""

config_value_pattern = re.compile(r"(?P<kconfig_name>[A-Za-z0-9_]+)=(?P<kconfig_value>.*)")

def __init__(self, input_file: str = ".config") -> None:
"""Initialize a BuildConfiguration object."""
super().__init__()
with open(input_file, "r") as fh:
self._config_data = fh.readlines()
self._parse()

def _parse(self) -> None:
"""Parse input .config file and populate the configuration dictionary."""
for config_line in self._config_data:
if re_result := self.config_value_pattern.match(config_line):
kconfig_name = re_result.group("kconfig_name")
kconfig_value = re_result.group("kconfig_value")
if kconfig_value == "y":
# boolean value
kconfig_value = True
elif kconfig_value.startswith("0x"):
# hexadecimal value
kconfig_value = int(kconfig_value, base=16)
elif kconfig_value.startswith('"') and kconfig_value.endswith('"'):
# string value
kconfig_value = kconfig_value[1:-1]
elif kconfig_value.isdecimal():
# int value
kconfig_value = int(kconfig_value, base=10)
super().__setitem__(kconfig_name, kconfig_value)


def read_configurations(configurations):
"""Read configuration stored in the pickled devicetree."""
data = {}
for config in configurations:
name, binary, edt = config.split(",")
kconfig = pathlib.Path(edt).parent / ".config"
with open(edt, "rb") as edt_handler:
edt = pickle.load(edt_handler)
# add prefix _ to the names starting with digits, for example:
# 802154_rpmsg_subimage will be available in the templates as _802154_rpmsg_subimage
data[f"_{name}" if re.match("^[0-9].*]", name) else name] = {
"name": name,
"config": convert(edt),
"config": BuildConfiguration(kconfig),
"dt": edt,
"binary": binary,
}
Expand Down Expand Up @@ -133,7 +163,6 @@ def get_absolute_address(node, use_offset: bool = True):
configuration = read_configurations(arguments.core)

if arguments.command == TEMPLATE_CMD:
configuration["version"] = arguments.version
configuration["output_envelope"] = arguments.output_suit
output_suit_content = render_template(arguments.template_suit, configuration)
with open(arguments.output_suit, "w") as output_file:
Expand Down
161 changes: 0 additions & 161 deletions ncs/default_app_rad_cores_envelope.yaml.jinja2

This file was deleted.

Loading

0 comments on commit b37829a

Please sign in to comment.