This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

NRF9160 LittleFS build non-secure target

Hi,

I'm trying to incorporate LittleFS into our development. We are relying on services provided by TF-M. 

To recreate: build /zephyr/samples/fs/littleFS and set target nrf9160dk_nrf9160_ns

It works perfectly fine when I don't select the non-secure target. 

It fails to mount. I suspect that the fs is accessing a part of flash that has been configured for secure access only. The "memcpy(data, (void *)addr, len);" triggers a security fault and the device locks up. (zephyr/drivers/flash/soc_flash_nrf.c:163)

Any way to configure regions of the flash so it wont trigger the security exception? Should the FS be moved to a different location on flash? Is there a way to see what regions on the flash are reserved for the trusted execution environment? 

First part of the example works and it detects the flash area: "Area 5 at 0xfa000 on NRF_FLASH_DRV_NAME for 24576 bytes" 

It is pretty clear that it has been handled when using SPM as the spm_request_read(data, addr, len); is invoked in some cases. 

Cheers! 

static int flash_nrf_read(const struct device *dev, off_t addr,
			    void *data, size_t len)
{
	if (is_regular_addr_valid(addr, len)) {
		addr += DT_REG_ADDR(SOC_NV_FLASH_NODE);
	} else if (!is_uicr_addr_valid(addr, len)) {
		LOG_ERR("invalid address: 0x%08lx:%zu",
				(unsigned long)addr, len);
		return -EINVAL;
	}

	if (!len) {
		return 0;
	}

#if CONFIG_ARM_NONSECURE_FIRMWARE && CONFIG_SPM && USE_PARTITION_MANAGER \
	&& CONFIG_SPM_SECURE_SERVICES
	if (addr < PM_APP_ADDRESS) {
		return spm_request_read(data, addr, len);
	}
#endif

	memcpy(data, (void *)addr, len);

	return 0;
}

Parents
  • Hi,

     

    Which version of ncs are you using?

    Do you have any changes to the local dts/kconfig options?

    Could you share the log output from your end?

    Here's the output from ncs v1.9.1 when building zephyr/samples/subsys/fs/littlefs for board nrf9160dk_nrf9160_ns:

    SPM: NS image at 0x10000
    SPM: NS MSP at 0x2000e8e8
    SPM: NS reset vector at 0x12d0d
    SPM: prepare to jump to Non-Secure image.
    *** Booting Zephyr OS build v2.7.99-ncs1-1  ***
    Area 2 at 0xfa000 on NRF_FLASH_DRV_NAME for 24576 bytes
    /lfs mount: 0
    /lfs: bsize = 16 ; frsize = 4096 ; blocks = 6 ; bfree = 4
    /lfs/boot_count stat: 0
            fn 'boot_count' size 4
    /lfs/boot_count read count 1: 4
    /lfs/boot_count seek start: 0
    /lfs/boot_count write new boot count 2: 4
    /lfs/boot_count close: 0
    /lfs opendir: 0
      F 4 boot_count
    End of files
    /lfs unmount: 0
    [00:00:00.518,493] <inf> littlefs: LittleFS version 2.4, disk version 2.0
    [00:00:00.518,707] <inf> littlefs: FS at NRF_FLASH_DRV_NAME:0xfa000 is 6 0x1000-byte blocks with 512 cycle
    [00:00:00.518,707] <inf> littlefs: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    [00:00:00.519,165] <inf> littlefs: /lfs mounted
    [00:00:00.549,652] <inf> littlefs: /lfs unmounted
    

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    Which version of ncs are you using?

    Do you have any changes to the local dts/kconfig options?

    Could you share the log output from your end?

    Here's the output from ncs v1.9.1 when building zephyr/samples/subsys/fs/littlefs for board nrf9160dk_nrf9160_ns:

    SPM: NS image at 0x10000
    SPM: NS MSP at 0x2000e8e8
    SPM: NS reset vector at 0x12d0d
    SPM: prepare to jump to Non-Secure image.
    *** Booting Zephyr OS build v2.7.99-ncs1-1  ***
    Area 2 at 0xfa000 on NRF_FLASH_DRV_NAME for 24576 bytes
    /lfs mount: 0
    /lfs: bsize = 16 ; frsize = 4096 ; blocks = 6 ; bfree = 4
    /lfs/boot_count stat: 0
            fn 'boot_count' size 4
    /lfs/boot_count read count 1: 4
    /lfs/boot_count seek start: 0
    /lfs/boot_count write new boot count 2: 4
    /lfs/boot_count close: 0
    /lfs opendir: 0
      F 4 boot_count
    End of files
    /lfs unmount: 0
    [00:00:00.518,493] <inf> littlefs: LittleFS version 2.4, disk version 2.0
    [00:00:00.518,707] <inf> littlefs: FS at NRF_FLASH_DRV_NAME:0xfa000 is 6 0x1000-byte blocks with 512 cycle
    [00:00:00.518,707] <inf> littlefs: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    [00:00:00.519,165] <inf> littlefs: /lfs mounted
    [00:00:00.549,652] <inf> littlefs: /lfs unmounted
    

     

    Kind regards,

    Håkon

Children
No Data
Related