Skip to content

Commit b41f0e4

Browse files
committed
suit: Ensure that cache IPUCs have no copies
It is required to make ensure that all cache ops use the same device driver to erase/setup/write data into IPUC. It is not required for image/component IPUCs because they are created temporarily, just for the scope of a single operation. Ref: NCSDK-32779 Signed-off-by: Tomasz Chyrowicz <[email protected]>
1 parent a50d127 commit b41f0e4

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

drivers/flash/flash_ipuc/flash_ipuc.c

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -636,6 +636,35 @@ bool flash_component_ipuc_check(struct zcbor_string *component_id)
636636
return false;
637637
}
638638

639+
static struct device *replace_if_duplicate(struct device *ipuc_dev)
640+
{
641+
struct ipuc_context *ipuc_ctx = NULL;
642+
struct ipuc_context *ctx = NULL;
643+
struct device *dev = NULL;
644+
645+
ipuc_ctx = (struct ipuc_context *)ipuc_dev->data;
646+
647+
for (size_t i = 0; i < ARRAY_SIZE(ipuc_devs); i++) {
648+
dev = (struct device *)ipuc_devs[i];
649+
ctx = (struct ipuc_context *)dev->data;
650+
if ((ctx->component_id.value == NULL) || (dev == ipuc_dev)) {
651+
continue;
652+
}
653+
654+
if ((ctx->component_id.len == ipuc_ctx->component_id.len) &&
655+
(memcmp(ctx->component_id.value, ipuc_ctx->component_id.value,
656+
ctx->component_id.len) == 0) &&
657+
(ctx->read_access == ipuc_ctx->read_access)) {
658+
LOG_DBG("Remove duplicate for IPUC (0x%lx, 0x%x)", ctx->address,
659+
ctx->size);
660+
flash_ipuc_release(ipuc_dev);
661+
return dev;
662+
}
663+
}
664+
665+
return ipuc_dev;
666+
}
667+
639668
static struct device *flash_cache_ipuc(uintptr_t min_address, uintptr_t *ipuc_address,
640669
size_t *ipuc_size, bool dry_run)
641670
{
@@ -724,8 +753,10 @@ static struct device *flash_cache_ipuc(uintptr_t min_address, uintptr_t *ipuc_ad
724753
}
725754

726755
if (!dry_run) {
727-
LOG_INF("Cache IPUC at idx %d for address range (0x%lx, 0x%x) created", i_max,
728-
ctx->address, ctx->size);
756+
dev = replace_if_duplicate(dev);
757+
ctx = (struct ipuc_context *)dev->data;
758+
LOG_INF("Cache IPUC for 0x%lx at idx %d for address range (0x%lx, 0x%x) created",
759+
min_address, i_max, ctx->address, ctx->size);
729760
}
730761

731762
ctx->setup_pending = true;

0 commit comments

Comments
 (0)