Skip to content

Commit

Permalink
suit: Changes in build system for extracting images to caches
Browse files Browse the repository at this point in the history
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 <artur.hadasz@nordicsemi.no>
  • Loading branch information
ahasztag committed Sep 3, 2024
1 parent 944e4d4 commit b2422a2
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 1 deletion.
32 changes: 32 additions & 0 deletions cmake/sysbuild/suit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down
10 changes: 10 additions & 0 deletions cmake/sysbuild/suit_utilities.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
10 changes: 10 additions & 0 deletions config/suit/templates/nrf54h20/default/v1/app_envelope.yaml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 %}
11 changes: 11 additions & 0 deletions config/suit/templates/nrf54h20/default/v1/rad_envelope.yaml.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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 %}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 %}
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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 %}
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b2422a2

Please sign in to comment.