Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

suit: Decompression stream filter #20582

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nordic-mik7
Copy link
Contributor

This PR provides implementation of decompression stream filter module.
For this filter, support for Flash sink and RAM sink was added by implementing required sink
readback interfaces.

Additionally, fixes to lzma.c were introduced as results of testing the filter (cache behavior and
ending the decompression stream).

@nordic-mik7 nordic-mik7 requested review from a team and nordicjm as code owners February 24, 2025 15:44
@github-actions github-actions bot added the changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. label Feb 24, 2025
Copy link

github-actions bot commented Feb 24, 2025

After documentation is built, you will find the preview for this PR here.

@NordicBuilder
Copy link
Contributor

NordicBuilder commented Feb 24, 2025

CI Information

To view the history of this post, clich the 'edited' button above
Build number: 6

Inputs:

Sources:

sdk-nrf: PR head: 642138ef4c5b66dcbdede23733286b7c8d2e505d
suit-processor: PR head: 54817f8648566721389114a10d8f3c3fe6362d9c

more details

sdk-nrf:

PR head: 642138ef4c5b66dcbdede23733286b7c8d2e505d
merge base: f79bb54aa27859dc46886f75d8afa760096d794a
target head (main): f79bb54aa27859dc46886f75d8afa760096d794a
Diff

suit-processor:

PR head: 54817f8648566721389114a10d8f3c3fe6362d9c
merge base: 4f1652126dcfc4cf669a6796ef3ef664b299cc35
target head (main): 4f1652126dcfc4cf669a6796ef3ef664b299cc35
Diff

Github labels

Enabled Name Description
ci-disabled Disable the ci execution
ci-all-test Run all of ci, no test spec filtering will be done
ci-force-downstream Force execution of downstream even if twister fails
ci-run-twister Force run twister
ci-run-zephyr-twister Force run zephyr twister
List of changed files detected by CI (21)
modules
│  ├── lib
│  │  ├── suit-processor
│  │  │  ├── include
│  │  │  │  │ suit_types.h
subsys
│  ├── nrf_compress
│  │  ├── src
│  │  │  │ lzma.c
│  ├── suit
│  │  ├── platform
│  │  │  ├── CMakeLists.txt
│  │  │  ├── sdfw
│  │  │  │  │ CMakeLists.txt
│  │  ├── stream
│  │  │  ├── Kconfig
│  │  │  ├── stream_filters
│  │  │  │  ├── CMakeLists.txt
│  │  │  │  ├── include
│  │  │  │  │  │ suit_decompress_filter.h
│  │  │  │  ├── src
│  │  │  │  │  │ suit_decompress_filter.c
│  │  │  ├── stream_sinks
│  │  │  │  ├── include
│  │  │  │  │  ├── suit_flash_sink.h
│  │  │  │  │  │ suit_ram_sink.h
│  │  │  │  ├── src
│  │  │  │  │  ├── suit_flash_sink.c
│  │  │  │  │  │ suit_ram_sink.c
tests
│  ├── subsys
│  │  ├── suit
│  │  │  ├── decompress_filter
│  │  │  │  ├── CMakeLists.txt
│  │  │  │  ├── boards
│  │  │  │  │  ├── native_sim.conf
│  │  │  │  │  ├── native_sim.overlay
│  │  │  │  │  ├── native_sim_64.conf
│  │  │  │  │  │ native_sim_64.overlay
│  │  │  │  ├── prj.conf
│  │  │  │  ├── src
│  │  │  │  │  │ main.c
│  │  │  │  │ testcase.yaml
west.yml

Outputs:

Toolchain

Version: aedb4c0245
Build docker image: docker-dtr.nordicsemi.no/sw-production/ncs-build:aedb4c0245_bece0367df

Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped; ⚠️ Quarantine

  • ◻️ Toolchain - Skipped: existing toolchain is used
  • ✅ Build twister
    • sdk-nrf test count: 132
  • ✅ Integration tests
    • ✅ test-fw-nrfconnect-boot
    • ✅ test-sdk-mcuboot
    • ✅ test-sdk-dfu
    • ⚠️ test-sdk-dfu
Disabled integration tests
    • desktop52_verification
    • doc-internal
    • test_ble_nrf_config
    • test-fw-nrfconnect-apps
    • test-fw-nrfconnect-ble_mesh
    • test-fw-nrfconnect-ble_samples
    • test-fw-nrfconnect-chip
    • test-fw-nrfconnect-fem
    • test-fw-nrfconnect-nfc
    • test-fw-nrfconnect-nrf-iot_cloud
    • test-fw-nrfconnect-nrf-iot_libmodem-nrf
    • test-fw-nrfconnect-nrf-iot_lwm2m
    • test-fw-nrfconnect-nrf-iot_mosh
    • test-fw-nrfconnect-nrf-iot_positioning
    • test-fw-nrfconnect-nrf-iot_samples
    • test-fw-nrfconnect-nrf-iot_serial_lte_modem
    • test-fw-nrfconnect-nrf-iot_thingy91
    • test-fw-nrfconnect-nrf-iot_zephyr_lwm2m
    • test-fw-nrfconnect-nrf_crypto
    • test-fw-nrfconnect-proprietary_esb
    • test-fw-nrfconnect-ps
    • test-fw-nrfconnect-rpc
    • test-fw-nrfconnect-rs
    • test-fw-nrfconnect-tfm
    • test-fw-nrfconnect-thread
    • test-fw-nrfconnect-zigbee
    • test-low-level
    • test-sdk-audio
    • test-sdk-find-my
    • test-sdk-pmic-samples
    • test-sdk-sidewalk
    • test-sdk-wifi
    • test-secdom-samples-public

Note: This message is automatically posted and updated by the CI

@nordic-mik7 nordic-mik7 force-pushed the dev/decompress_filter_rebase branch from 01d2ca8 to c3d8fb7 Compare February 24, 2025 16:03
@nordic-mik7 nordic-mik7 requested review from a team as code owners February 24, 2025 16:03
@NordicBuilder
Copy link
Contributor

NordicBuilder commented Feb 24, 2025

The following west manifest projects have changed revision in this Pull Request:

Name Old Revision New Revision Diff
suit-processor nrfconnect/suit-processor@4f16521 (main) nrfconnect/suit-processor#106 nrfconnect/suit-processor#106/files

DNM label due to: 1 project with PR revision

Note: This message is automatically posted and updated by the Manifest GitHub Action.

@nordic-mik7 nordic-mik7 force-pushed the dev/decompress_filter_rebase branch 2 times, most recently from 9105b76 to e10e118 Compare February 24, 2025 16:14
Copy link
Contributor

@nordicjm nordicjm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bit confused with the check for output size not equalling 0 but assuming I'm just missing a part of the picture. Apply comments throughout whole PR, not all instances have been commented on

* @param[in] size Size of @a buf; data read size
*/
typedef suit_plat_err_t (*out_sink_readback_func)(void *sink_ctx,
size_t offset, uint8_t *buf, size_t size);
Copy link
Contributor

@nordicjm nordicjm Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alignment is off here and below, and line length is 100, sink_ctx, offset and buf can all be on the top line and is under limit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/**
* @brief Interface function type for output sink readback, passed to
* suit_decompress_filter_get() as a callback. Decompression process needs
* an access to unaltered destination component memory (see WARNING below).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* an access to unaltered destination component memory (see WARNING below).
* access to unaltered destination component memory (see WARNING below).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 46 to 49
const struct suit_compression_info *compress_info,
const suit_manifest_class_id_t *class_id,
const struct stream_sink *out_sink,
out_sink_readback_func out_sink_readback);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* @param[in] offset Offset of output sink area to start reading from
* @param[out] buf Buffer to read into
* @param[in] size Size of @a buf; data read size
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no details on retval

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* @param[in] out_sink Pointer to output stream_sink to be filled with decompressed data
* @param[in] out_sink_readback Output sink readback function
*
* @return SUIT_PLAT_SUCCESS if success otherwise error code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be @retval and have multiple lines e.g.:

 * @retval 0 on success.
 * @retval -ENOMEM if LwM2M engine couldn't allocate its objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

/* Make sure we buffer CHUNK_BUFFER_SIZE bytes
* in ctx.last_chunk for the flush operation.
*/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

return SUIT_PLAT_ERR_INVAL;
}

enum nrf_compress_types compress_type = NRF_COMPRESS_TYPE_COUNT;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

declare variables at top of scope

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* of the stream_sink API. User that holds the flash_sink can readback the data during
* streaming, as flash_sink has the access to data destination in memory.
*
* @param[in] ctx context of the flash_sink
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sink_ctx

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* of the stream_sink API. User that holds the ram_sink can readback the data during
* streaming, as ram_sink has the access to data destination in memory.
*
* @param[in] ctx Context of the ram_sink
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as above

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

if (ctx_found == false) {
LOG_ERR("readback with invalid sink_ctx called.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

capital first letters for messages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@nordic-mik7 nordic-mik7 force-pushed the dev/decompress_filter_rebase branch from e10e118 to e5db0be Compare February 25, 2025 11:57
rc = Lzma2Dec_DecodeToDic(&lzma_decoder, decoder->dicHandle->dicBufSize,
input, &chunk_size,
(last_part ? LZMA_FINISH_END : LZMA_FINISH_ANY), &status);
rc = Lzma2Dec_DecodeToDic(&lzma_decoder, decoder->dicHandle->dicBufSize, input, &chunk_size,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nordicjm Please take a look at changes to lzma_decompress() function logic. I implemented them for the 'external dictionary' version but I believe they should be applied for all configurations.

LZMA_FINISH_END flag configures lzma decompression behavior to lookup for the 'end mark' if 'dicLimit' is reached during LzmaDec_DecodeToDic() call. If it is not found, LzmaDec_DecodeToDic() will return error.
If we set LZMA_FINISH_END when we deliver 'last_part', this means we must fit with the output of decompression of this last part in dictionary buffer that is currently available (lzma_decoder.dicBufSize - lzma_decoder.dicPos). As we can provide 'last_part' at any given point, we may exceed 'dicLimit' with decompression output. I believe we should not return an error here, just let the user provide the rest of the 'last_part' in the next call.

Also check on the line 553 is faulthy then - if we fit with our decompression output in dictionary buffer, we should always have chunk_size == input_size. If not, then we should not override offset but just signal that more processing is needed.

This commit provides implementation of
decompression stream filter module.
For this filter, support for Flash sink and RAM
sink was added by implementing required sink
readback interfaces.

Additionally, fixes to lzma.c were introduced as
results of testing the filter (cache behavior and
ending the decompression stream).

Signed-off-by: Michal Kozikowski <[email protected]>
@nordic-mik7 nordic-mik7 force-pushed the dev/decompress_filter_rebase branch from e5db0be to 642138e Compare February 25, 2025 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-entry-required Update changelog before merge. Remove label if entry is not needed or already added. DNM manifest manifest-suit-processor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants