diff --git a/subsys/ipc/ipc_service/backends/Kconfig.rpmsg b/subsys/ipc/ipc_service/backends/Kconfig.rpmsg index b5104ca45a7..7bff068fd49 100644 --- a/subsys/ipc/ipc_service/backends/Kconfig.rpmsg +++ b/subsys/ipc/ipc_service/backends/Kconfig.rpmsg @@ -12,4 +12,13 @@ config IPC_SERVICE_BACKEND_RPMSG_WQ_STACK_SIZE prevent notifying service users about received data from the system work queue. Size is the same for all instances. +config IPC_SERVICE_BACKEND_RPMSG_SHMEM_RESET + bool "Reset shared memory state" + help + Some platforms retain the memory content upon reset. This is + problematic because the backend expects a zero-ed memory to be + able to correctly setup instances and endpoints at init time. + When this parameter is set to 'y' the status region of the shared + memory is reset on kernel initialization. + endif # IP_SERVICE_BACKEND_RPMSG diff --git a/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c b/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c index 0ef7e8bf73d..16f46ddddaf 100644 --- a/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c +++ b/subsys/ipc/ipc_service/backends/ipc_rpmsg_static_vrings.c @@ -508,3 +508,24 @@ static int backend_init(const struct device *instance) &backend_ops); DT_INST_FOREACH_STATUS_OKAY(DEFINE_BACKEND_DEVICE) + +#define BACKEND_CONFIG_INIT(n) &backend_config_##n, + +#if defined(CONFIG_IPC_SERVICE_BACKEND_RPMSG_SHMEM_RESET) +static int shared_memory_prepare(const struct device *arg) +{ + static const struct backend_config_t *config[] = { + DT_INST_FOREACH_STATUS_OKAY(BACKEND_CONFIG_INIT) + }; + + for (int i = 0; i < DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT); i++) { + if (config[i]->role == ROLE_HOST) { + memset((void *) config[i]->shm_addr, 0, VDEV_STATUS_SIZE); + } + } + + return 0; +} + +SYS_INIT(shared_memory_prepare, PRE_KERNEL_1, 1); +#endif /* CONFIG_IPC_SERVICE_BACKEND_RPMSG_SHMEM_RESET */