From b2422a2a5edb1fe227cca4769dfac28e2b31d1e7 Mon Sep 17 00:00:00 2001 From: Artur Hadasz Date: Tue, 27 Aug 2024 14:53:43 +0200 Subject: [PATCH] suit: Changes in build system for extracting images to caches This commit introduces several changes which allow to severe firmware images from SUIT envelopes and extract them to raw cache files, which can then be flashed separately to the device. Signed-off-by: Artur Hadasz --- cmake/sysbuild/suit.cmake | 32 +++++++++++++++++++ cmake/sysbuild/suit_utilities.cmake | 10 ++++++ .../default/v1/app_envelope.yaml.jinja2 | 10 ++++++ .../default/v1/rad_envelope.yaml.jinja2 | 11 +++++++ .../matter/v1/app_envelope.yaml.jinja2 | 6 ++++ .../matter/v1/rad_envelope.yaml.jinja2 | 6 ++++ west.yml | 2 +- 7 files changed, 76 insertions(+), 1 deletion(-) diff --git a/cmake/sysbuild/suit.cmake b/cmake/sysbuild/suit.cmake index 124d5123a90f..5a85788b2545 100644 --- a/cmake/sysbuild/suit.cmake +++ b/cmake/sysbuild/suit.cmake @@ -261,6 +261,38 @@ function(suit_create_package) ) endforeach() + # First parse which images should be extracted to which cache partition + set(DFU_CACHE_PARTITIONS_USED "") + foreach(image ${IMAGES}) + sysbuild_get(EXTRACT_TO_CACHE IMAGE ${image} VAR CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE KCONFIG) + if(EXTRACT_TO_CACHE) + sysbuild_get(CACHE_PARTITION_NUM IMAGE ${image} VAR CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_PARTITION KCONFIG) + list(APPEND DFU_CACHE_PARTITIONS_USED ${CACHE_PARTITION_NUM}) + list(APPEND SUIT_CACHE_PARTITION_${CACHE_PARTITION_NUM} ${image}) + endif() + endforeach() + list(REMOVE_DUPLICATES DFU_CACHE_PARTITIONS_USED) + + # Then create the cache partitions + foreach(CACHE_PARTITION_NUM ${DFU_CACHE_PARTITIONS_USED}) + set(CACHE_CREATE_ARGS "") + foreach(image ${SUIT_CACHE_PARTITION_${CACHE_PARTITION_NUM}}) + sysbuild_get(BINARY_DIR IMAGE ${image} VAR APPLICATION_BINARY_DIR CACHE) + sysbuild_get(BINARY_FILE IMAGE ${image} VAR CONFIG_KERNEL_BIN_NAME KCONFIG) + sysbuild_get(IMAGE_CACHE_URI IMAGE ${image} VAR CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI KCONFIG) + list(APPEND CACHE_CREATE_ARGS + "--input" "\"${IMAGE_CACHE_URI},${BINARY_DIR}/zephyr/${BINARY_FILE}.bin\"" + ) + endforeach() + list(APPEND CACHE_CREATE_ARGS "--output-file" "${SUIT_ROOT_DIRECTORY}dfu_cache_partition_${CACHE_PARTITION_NUM}.bin") + + if(SUIT_DFU_CACHE_PARTITION_${CACHE_PARTITION_NUM}_EB_SIZE) + list(APPEND CACHE_CREATE_ARGS "--eb-size" "${SUIT_DFU_CACHE_PARTITION_${CACHE_PARTITION_NUM}_EB_SIZE}") + endif() + + suit_create_cache_partition("${CACHE_CREATE_ARGS}") + endforeach() + suit_get_manifest(${SB_CONFIG_SUIT_ENVELOPE_ROOT_TEMPLATE_FILENAME} INPUT_ROOT_ENVELOPE_JINJA_FILE) message(STATUS "Found root manifest template: ${INPUT_ROOT_ENVELOPE_JINJA_FILE}") diff --git a/cmake/sysbuild/suit_utilities.cmake b/cmake/sysbuild/suit_utilities.cmake index 531915558c6f..53d7e38193e6 100644 --- a/cmake/sysbuild/suit_utilities.cmake +++ b/cmake/sysbuild/suit_utilities.cmake @@ -87,3 +87,13 @@ function(suit_create_envelope input_file output_file create_signature) suit_sign_envelope(${output_file} ${output_file}) endif() endfunction() + +function(suit_create_cache_partition args) + set_property( + GLOBAL APPEND PROPERTY SUIT_POST_BUILD_COMMANDS + COMMAND ${PYTHON_EXECUTABLE} ${SUIT_GENERATOR_CLI_SCRIPT} + cache_create + ${args} + BYPRODUCTS ${output_file} + ) +endfunction() diff --git a/config/suit/templates/nrf54h20/default/v1/app_envelope.yaml.jinja2 b/config/suit/templates/nrf54h20/default/v1/app_envelope.yaml.jinja2 index 700aa1740bc6..a543fd490b49 100644 --- a/config/suit/templates/nrf54h20/default/v1/app_envelope.yaml.jinja2 +++ b/config/suit/templates/nrf54h20/default/v1/app_envelope.yaml.jinja2 @@ -77,7 +77,11 @@ SUIT_Envelope_Tagged: suit-install: - suit-directive-set-component-index: 1 - suit-directive-override-parameters: +{%- if 'CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI' in application['config'] and application['config']['CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI'] != '' %} + suit-parameter-uri: '{{ application['config']['CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI'] }}' +{%- else %} suit-parameter-uri: '#{{ application['name'] }}' +{%- endif %} suit-parameter-image-digest: suit-digest-algorithm-id: cose-alg-sha-256 suit-digest-bytes: @@ -125,7 +129,11 @@ SUIT_Envelope_Tagged: suit-candidate-verification: - suit-directive-set-component-index: 1 - suit-directive-override-parameters: +{%- if 'CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI' in application['config'] and application['config']['CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI'] != '' %} + suit-parameter-uri: '{{ application['config']['CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI'] }}' +{%- else %} suit-parameter-uri: '#{{ application['name'] }}' +{%- endif %} suit-parameter-image-digest: suit-digest-algorithm-id: cose-alg-sha-256 suit-digest-bytes: @@ -158,5 +166,7 @@ SUIT_Envelope_Tagged: suit-text-model-info: The nRF54H20 application core suit-text-component-description: Sample application core FW suit-text-component-version: v1.0.0 +{%- if 'CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE' not in application['config'] or application['config']['CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE'] == '' %} suit-integrated-payloads: '#{{ application['name'] }}': {{ application['binary'] }} +{%- endif %} diff --git a/config/suit/templates/nrf54h20/default/v1/rad_envelope.yaml.jinja2 b/config/suit/templates/nrf54h20/default/v1/rad_envelope.yaml.jinja2 index 026cd632f3fc..63f88053a61c 100644 --- a/config/suit/templates/nrf54h20/default/v1/rad_envelope.yaml.jinja2 +++ b/config/suit/templates/nrf54h20/default/v1/rad_envelope.yaml.jinja2 @@ -82,7 +82,11 @@ SUIT_Envelope_Tagged: suit-install: - suit-directive-set-component-index: 1 - suit-directive-override-parameters: +{%- if 'CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI' in radio['config'] and radio['config']['CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI'] != '' %} + suit-parameter-uri: '{{ radio['config']['CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI'] }}' +{%- else %} suit-parameter-uri: '#{{ radio['name'] }}' +{%- endif %} suit-parameter-image-digest: suit-digest-algorithm-id: cose-alg-sha-256 suit-digest-bytes: @@ -130,7 +134,11 @@ SUIT_Envelope_Tagged: suit-candidate-verification: - suit-directive-set-component-index: 1 - suit-directive-override-parameters: +{%- if 'CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI' in radio['config'] and radio['config']['CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI'] != '' %} + suit-parameter-uri: '{{ radio['config']['CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI'] }}' +{%- else %} suit-parameter-uri: '#{{ radio['name'] }}' +{%- endif %} suit-parameter-image-digest: suit-digest-algorithm-id: cose-alg-sha-256 suit-digest-bytes: @@ -163,5 +171,8 @@ SUIT_Envelope_Tagged: suit-text-model-info: The nRF54H20 radio core suit-text-component-description: Sample radio core FW suit-text-component-version: v1.0.0 + +{%- if 'CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE' not in radio['config'] or radio['config']['CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE'] == '' %} suit-integrated-payloads: '#{{ radio['name'] }}': {{ radio['binary'] }} +{%- endif %} diff --git a/config/suit/templates/nrf54h20/matter/v1/app_envelope.yaml.jinja2 b/config/suit/templates/nrf54h20/matter/v1/app_envelope.yaml.jinja2 index 941da9fd28f1..c9e3a09c4ac0 100644 --- a/config/suit/templates/nrf54h20/matter/v1/app_envelope.yaml.jinja2 +++ b/config/suit/templates/nrf54h20/matter/v1/app_envelope.yaml.jinja2 @@ -115,7 +115,11 @@ SUIT_Envelope_Tagged: {%- endif %} - suit-directive-set-component-index: 1 - suit-directive-override-parameters: +{%- if 'CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI' in application['config'] and application['config']['CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI'] != '' %} + suit-parameter-uri: '{{ application['config']['CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI'] }}' +{%- else %} suit-parameter-uri: '#{{ application['name'] }}' +{%- endif %} suit-parameter-image-digest: suit-digest-algorithm-id: cose-alg-sha-256 suit-digest-bytes: @@ -154,7 +158,9 @@ SUIT_Envelope_Tagged: suit-text-component-description: Sample application core FW suit-text-component-version: v1.0.0 suit-integrated-payloads: +{%- if 'CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE' not in application['config'] or application['config']['CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE'] == '' %} '#{{ application['name'] }}': {{ application['binary'] }} +{%- endif %} {%- if flash_companion is defined %} '#{{ flash_companion['name'] }}': {{ flash_companion['binary'] }} {%- endif %} diff --git a/config/suit/templates/nrf54h20/matter/v1/rad_envelope.yaml.jinja2 b/config/suit/templates/nrf54h20/matter/v1/rad_envelope.yaml.jinja2 index 58a7777d4df4..25cedfa872dd 100644 --- a/config/suit/templates/nrf54h20/matter/v1/rad_envelope.yaml.jinja2 +++ b/config/suit/templates/nrf54h20/matter/v1/rad_envelope.yaml.jinja2 @@ -78,7 +78,11 @@ SUIT_Envelope_Tagged: suit-install: - suit-directive-set-component-index: 1 - suit-directive-override-parameters: +{%- if 'CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI' in radio['config'] and radio['config']['CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI'] != '' %} + suit-parameter-uri: '{{ radio['config']['CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE_URI'] }}' +{%- else %} suit-parameter-uri: '#{{ radio['name'] }}' +{%- endif %} - suit-directive-fetch: - suit-send-record-failure - suit-condition-image-match: @@ -112,5 +116,7 @@ SUIT_Envelope_Tagged: suit-text-model-info: The nRF54H20 radio core suit-text-component-description: Sample radio core FW suit-text-component-version: v1.0.0 +{%- if 'CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE' not in radio['config'] or radio['config']['CONFIG_SUIT_DFU_CACHE_EXTRACT_IMAGE'] == '' %} suit-integrated-payloads: '#{{ radio['name'] }}': {{ radio['binary'] }} +{%- endif %} diff --git a/west.yml b/west.yml index 606b6b3ab9b0..a4a531df349f 100644 --- a/west.yml +++ b/west.yml @@ -254,7 +254,7 @@ manifest: upstream-sha: c6eaeda5a1c1c5dbb24dce7e027340cb8893a77b compare-by-default: false - name: suit-generator - revision: 97ef5bdd41716aa7fa21a0f0c149a66d1f91ab8d + revision: pull/139/head path: modules/lib/suit-generator - name: suit-processor revision: ee58d543994256d545c692e14badf3efa9830237