Skip to content

Commit

Permalink
suit: platform: DFU Cache refactoring
Browse files Browse the repository at this point in the history
Ref: NCSDK-28335

Signed-off-by: Sylwester Konczyk <sylwester.konczyk@nordicsemi.no>
  • Loading branch information
SylwesterKonczyk authored and nordicjm committed Aug 15, 2024
1 parent 86662b8 commit 5d3c406
Show file tree
Hide file tree
Showing 31 changed files with 474 additions and 547 deletions.
3 changes: 3 additions & 0 deletions samples/suit/smp_transfer/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ CONFIG_ZCBOR_CANONICAL=y
CONFIG_MCUMGR=y
CONFIG_MCUMGR_SMP_LEGACY_RC_BEHAVIOUR=y
CONFIG_CRC=y
CONFIG_MCUMGR_TRANSPORT_NETBUF_SIZE=1040

# Enable the serial mcumgr transport
CONFIG_SERIAL=y
CONFIG_CONSOLE=y
CONFIG_BASE64=y
CONFIG_MCUMGR_TRANSPORT_UART=y
CONFIG_UART_MCUMGR_RX_BUF_SIZE=1040
CONFIG_MCUMGR_TRANSPORT_UART_MTU=1024

# Enable SUIT services
CONFIG_SUIT=y
Expand Down
4 changes: 2 additions & 2 deletions samples/suit/smp_transfer/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ int main(void)
printk("Cannot init LEDs (err: %d)\r\n", ret);
}

printk("Hello world from %s version: %d\r\n", CONFIG_BOARD,
CONFIG_SUIT_ENVELOPE_SEQUENCE_NUM);
printk("Hello world from %s version: %d, BUILD: %s %s\r\n", CONFIG_BOARD,
CONFIG_SUIT_ENVELOPE_SEQUENCE_NUM, __DATE__, __TIME__);

#if (CONFIG_SSF_SUIT_SERVICE_ENABLED) && (CONFIG_SUIT_ENVELOPE_SEQUENCE_NUM == 1) && \
(!CONFIG_MGMT_SUITFU)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

CONFIG_SUIT_DFU_CANDIDATE_PROCESSING_FULL=y
CONFIG_SUIT_STREAM_SOURCE_FLASH=y
CONFIG_SUIT_CACHEX_ERASE_ON_INIT=y
CONFIG_SUIT_ENVELOPE_TEMPLATE="templates/extflash/app_envelope.yaml.jinja2"
1 change: 1 addition & 0 deletions subsys/suit/cache/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ zephyr_library_sources_ifdef(CONFIG_SUIT_CACHE_RW src/suit_dfu_cache_rw.c)
zephyr_library_link_libraries(suit_cache_interface)

zephyr_library_link_libraries_ifdef(CONFIG_SUIT_CACHE_RW suit_utils)
zephyr_library_link_libraries_ifdef(CONFIG_SUIT_CACHE_RW suit_envelope_info)

zephyr_library_link_libraries(suit_stream_sources_interface)
zephyr_library_link_libraries(suit_source_selector_interface)
Expand Down
26 changes: 0 additions & 26 deletions subsys/suit/cache/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,4 @@ config SUIT_CACHE_RW
depends on SUIT_UTILS
depends on !SUIT_PLATFORM_VARIANT_SDFW

config SUIT_CACHE0_ERASE_ON_ENVELOPE_STORED
bool "Always erase the DFU cache partition 0 after the envelope is stored"
help
If this option is set then after the SUIT envelope is stored (more
precisely: when calling the suit_dfu_cache_rw_initialize function)
then Cache0 will be erased and reinitialized regardless of its previous
state. If this option is not set, the SUIT subsystem will check the
partition and only erase it if its broken and needs recovery.
If this option is not set it is up to the user to ensure that the
contents of cache0 are appropriate after the envelope is stored.
depends on SUIT_CACHE_RW
default y

config SUIT_CACHEX_ERASE_ON_INIT
bool "Always erase the DFU cache partition 1 .. n on initialization"
help
If this option is set the SUIT caches with ID 1 .. n will be erased
during cache initialization, if the cache partition is not already erased.

config SUIT_CACHEX_ERASE_BLOCK_SIZE
int "Erase block size"
default 4096
help
Erase block size of cache partitions 1 .. n.
This configuration does not affect cache partition 0.

endif # SUIT_CACHE
69 changes: 36 additions & 33 deletions subsys/suit/cache/include/suit_dfu_cache_rw.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <zcbor_decode.h>
#include <zephyr/storage/flash_map.h>
#include <suit_dfu_cache.h>
#include <suit_memory_layout.h>

#ifdef __cplusplus
extern "C" {
Expand All @@ -30,71 +31,73 @@ struct suit_cache_slot {
};

/**
* @brief Initialize cache in R/W mode for APP context
*
* @note dfu_cache structure is initialized based on dfu_partitions_ext which in turn is
* initialized using SUIT cache partitions information from Device Tree.
* @brief Function tries to allocate slot in cache pointed by ID
*
* @param addr Address of the envelope in DFU partition
* @param size Size of the envelope
* @param cache_partition_id ID of the cache partition in which slot should be allocated
* @param slot Pointer to structure that will be filled with allocated slot info
* @param uri URI that will be used as a key in cache cbor map
* @param uri_size URI size
*
* @return SUIT_PLAT_SUCCESS in case of success, otherwise error code
*/
suit_plat_err_t suit_dfu_cache_rw_initialize(void *addr, size_t size);
suit_plat_err_t suit_dfu_cache_rw_slot_create(uint8_t cache_partition_id,
struct suit_cache_slot *slot, const uint8_t *uri,
size_t uri_size);

/**
* @brief Deinitialize SUIT cache. This will also erase all the cache partitions.
* @brief Commits changes written to slot by updating cbor header for the cache slot
*
* @param slot Pointer to opened cache slot
* @param size_used Number of bytes written
*
* @return SUIT_PLAT_SUCCESS in case of success, otherwise error code
*/
suit_plat_err_t suit_dfu_cache_rw_deinitialize(void);
suit_plat_err_t suit_dfu_cache_rw_slot_close(struct suit_cache_slot *slot, size_t size_used);

/**
* @brief Retrieve information about the address and size of a given cache
* partition.
* @brief Drop data written to slot and revert slot allocation
*
* @param cache_partition_id ID of the cache partition
* @param address address of the cache partition
* @param size size of the cache partition
* @param slot Pointer to slot that should be dropped
*
* @return SUIT_PLAT_SUCCESS in case of success
* @return SUIT_PLAT_ERR_NOT_FOUND if the given partition does not exist
* @return SUIT_PLAT_SUCCESS in case of success, otherwise error code
*/
suit_plat_err_t suit_dfu_cache_rw_partition_info_get(uint8_t cache_partition_id,
const uint8_t **address, size_t *size);
suit_plat_err_t suit_dfu_cache_rw_slot_drop(struct suit_cache_slot *slot);

/**
* @brief Function tries to allocate slot in cache pointed by ID
* @brief Adjust cache partition 0 location and size based on characteristics of
* update candidate envelope
*
* @param cache_partition_id ID of the cache partition in which slot should be allocated
* @param slot Pointer to structure that will be filled with allocated slot info
* @param uri URI that will be used as a key in cache cbor map
* @param uri_size URI size
* To be executed each time new envelope is stored in the dfu partition
*
* @return SUIT_PLAT_SUCCESS in case of success, otherwise error code
*/
suit_plat_err_t suit_dfu_cache_rw_slot_create(uint8_t cache_partition_id,
struct suit_cache_slot *slot,
const uint8_t *uri, size_t uri_size);
suit_plat_err_t suit_dfu_cache_0_resize(void);

/**
* @brief Commits changes written to slot by updating cbor header for the cache slot
* @brief Validates content of cache partitions
*
* @param slot Pointer to opened cache slot
* @param size_used Number of bytes written
* Validates content of cache partitions and erases nvm partition in case of content incoherency
*
* @return SUIT_PLAT_SUCCESS in case of success, otherwise error code
*/
suit_plat_err_t suit_dfu_cache_rw_slot_close(struct suit_cache_slot *slot, size_t size_used);
suit_plat_err_t suit_dfu_cache_validate_content(void);

/**
* @brief Drop data written to slot and revert slot allocation
* @brief Drops content of all cache partitions
*
* @param slot Pointer to slot that should be dropped
* Erases nvm partitions belonging to all cache partitions
*
* @return SUIT_PLAT_SUCCESS in case of success, otherwise error code
*/
suit_plat_err_t suit_dfu_cache_rw_slot_drop(struct suit_cache_slot *slot);
suit_plat_err_t suit_dfu_cache_drop_content(void);

/**
* @brief Gets information about characteristics of cache partition
*
* @return suit_plat_success on success, error code otherwise.
*/
suit_plat_err_t suit_dfu_cache_rw_device_info_get(uint8_t cache_partition_id,
struct suit_nvm_device_info *device_info);

#ifdef __cplusplus
}
Expand Down
2 changes: 1 addition & 1 deletion subsys/suit/cache/src/suit_dfu_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
LOG_MODULE_REGISTER(dfu_cache, CONFIG_SUIT_LOG_LEVEL);

static bool init_done;
struct dfu_cache dfu_cache;
static struct dfu_cache dfu_cache;

/**
* @brief Check if current_key is same as uri
Expand Down
1 change: 1 addition & 0 deletions subsys/suit/cache/src/suit_dfu_cache_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ suit_plat_err_t suit_dfu_cache_partition_is_empty(struct dfu_cache_pool *cache_p
}
}

address += read_size;
remaining -= read_size;
}

Expand Down
Loading

0 comments on commit 5d3c406

Please sign in to comment.