Skip to content

Commit 9cad422

Browse files
sigvartmhSebastianBoe
authored andcommitted
[nrf noup] soc: flash: Add tfm read service to nRF SoC Flash driver
This adds the functionality to read memory which are residing in the secure part of flash from a non-secure application when building with TF-M. Currently we check if the address space is not inside the non-secure applapplication address space. If the address space is outside we do a request to TF-M so that the secure application can either return success or fail if the address space is not allowed to be read. Ref. NCSDK-13085 Signed-off-by: Sigvart Hovland <sigvart.hovland@nordicsemi.no>
1 parent f295fb7 commit 9cad422

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

drivers/flash/soc_flash_nrf.c

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,17 @@ LOG_MODULE_REGISTER(flash_nrf);
3737

3838
#define SOC_NV_FLASH_NODE DT_INST(0, soc_nv_flash)
3939

40-
#if CONFIG_ARM_NONSECURE_FIRMWARE && CONFIG_SPM
40+
#if CONFIG_ARM_NONSECURE_FIRMWARE
41+
#if CONFIG_SPM
4142
#include <secure_services.h>
43+
#elif CONFIG_BUILD_WITH_TFM
44+
#include <tfm_ns_interface.h>
45+
#include <tfm/tfm_ioctl_api.h>
46+
#endif /* CONFIG_SPM */
4247
#if USE_PARTITION_MANAGER
4348
#include <pm_config.h>
4449
#endif /* USE_PARTITION_MANAGER */
45-
#endif /* CONFIG_ARM_NONSECURE_FIRMWARE && CONFIG_SPM */
50+
#endif /* CONFIG_ARM_NONSECURE_FIRMWARE */
4651

4752
#ifndef CONFIG_SOC_FLASH_NRF_RADIO_SYNC_NONE
4853
#define FLASH_SLOT_WRITE 7500
@@ -153,10 +158,22 @@ static int flash_nrf_read(const struct device *dev, off_t addr,
153158
return 0;
154159
}
155160

156-
#if CONFIG_ARM_NONSECURE_FIRMWARE && CONFIG_SPM && USE_PARTITION_MANAGER \
157-
&& CONFIG_SPM_SECURE_SERVICES
158-
if (addr < PM_APP_ADDRESS) {
161+
#if CONFIG_ARM_NONSECURE_FIRMWARE && USE_PARTITION_MANAGER
162+
if ((addr < PM_APP_ADDRESS) || (addr > (PM_APP_ADDRESS + PM_APP_SIZE))) {
163+
#if CONFIG_SPM && CONFIG_SPM_SECURE_SERVICES
159164
return spm_request_read(data, addr, len);
165+
#elif CONFIG_BUILD_WITH_TFM
166+
uint32_t err = 0;
167+
enum tfm_platform_err_t plt_err;
168+
169+
plt_err = tfm_platform_mem_read(&data, addr, len, &err);
170+
if (plt_err != TFM_PLATFORM_ERR_SUCCESS || err != 0) {
171+
LOG_ERR("tfm_..._mem_read failed: plt_err: 0x%x,"
172+
"err: 0x%x\n", plt_err, err);
173+
return -EINVAL;
174+
}
175+
return 0;
176+
#endif
160177
}
161178
#endif
162179

0 commit comments

Comments
 (0)