With nRF5340 : How to use internal and external flash both as Littlefs to store data

Hi All,

In nRF5340DK board, with ncs SDK(v1.9.1), we can use internal flash partition as Littlefs and store data into it. we are able to find sample demo for external flash as littlefs.

Now we want to add external Flash(MX25R64) and internal flash both as littlefs and use both to store data into it for different purpose.

Question:

1) Can we use both internal flash storage partition and external flash as littlefs to store data ?

2) Is there any demo sample which describes to configure and use internal and external flash both as littlefs ?

  • Hi

    1. I think this should be possible, although I'm not aware of anyone who has tested this in the past. It will be necessary with two instances of littlefs though, as I don't think you can seamlessly move between internal and external storage like that.

    2. Unfortunately, there are no demos available doing this in the official nRF Connect SDK, but if there is one, I would think it is available somewhere on Github. Feel free to search for a Zephyr project doing this there.

    Best regards,

    Simon

  • 1) For External flash support with Littlefs, we used ncs\v1.9.1\zephyr\samples\subsys\fs\littlefs demos for nRF5340 board. We are able to successfully run internal and external flash both as littlefs with few changes.

    With enabling both internal and external flash as littlefs, when we enable MCUBOOT(CONFIG_BOOTLOADER_MCUBOOT=y) then it stopped compiling. It gives PM ID related error. Any idea for this ?

    2) We didn't find any demos on Github related to littlefs. Could you please share a link of it ?

  • Hi

    1. Glad to hear you got it up and running. Can you show me the exact error you're seeing. My initial guess would be that your internal flash storage and the bootloader addresses overlap at some point which causes the error when configuring the bootloader for your application.

    2. Sorry, I think you misunderstood. I don't know of any demoes doing littlefs for both internal and external flash, but I would imagine that if there was an example project available somewhere, it would be somewhere on GitHub. I don't have a specific link, just a suggestion as to where you could look.

    Best regards,

    Simon

  • Hi,

    In the example below, the littlefs storage is placed inside the internal and  external flash with 1st stage mcuboot bootloader, and this sample is working fine.

    littlefs_int_ext_1st_stage_mcuboot.zip

    it works successfully, you should get the following output when you run above share code with nrf5340dk :

    *** Booting Zephyr OS build v2.7.99-ncs1-1  ***
    Starting Bootloader bootloader_mcuboot_boot_zephyr FW: v1.0.0
    
    I: Starting bootloader
    I: Primary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Secondary image: magic=unset, swap_type=0x1, copy_done=0x3, image_ok=0x3
    I: Boot source: none
    I: Swap type: none
    I: Bootloader chainload address offset: 0xc000
    I: Jumping to the first image slot
    *** Booting Zephyr OS build v2.7.99-ncs1-1  ***
    Area 9 at 0xf8000 on NRF_FLASH_DRV_NAME for 24576 bytes
    /lfs mount: 0
    /lfs: bsize = 16 ; frsize = 4096 ; blocks = 6 ; bfree = 4
    /lfs/boot_count_int stat: -2
    /lfs/boot_count_int read count 0: 0
    /lfs/boot_count_int seek start: 0
    /lfs/boot_count_int write new boot count 1: 4
    /lfs/boot_count_int close: 0
    /lfs opendir: 0
      F 4 boot_count_int
    End of files
    /lfs unmount: 0
    #######################
    
    
    
    
    
    Area 2 at 0x0 on MX25R64 for 122880 bytes
    [00:00:00.009,704] <inf> littlef/lfs_ext_flash mount: 0
    s: LittleFS version 2.4, di/lfs_ext_flash: bsize = 16 ; frsize = 4096 ; blocks = 30 ; bfree = 26
    sk version 2.0fs_ext_flash/boot_count_ext stat: -2
    0m
    [00:00:00.009,857]/lfs_ext_flash/boot_count_ext read count 0: 0
    /lfs_ext_flash/boot_count_ext seek start: 0
    /lfs_ext_flash/boot_count_ext write new boot count 1: 4
     fs_ext_flash/boot_count_ext close: 0
    m<inf> littlefs: F/lfs_ext_flash opendir: 0
    S at NRF_FLASH  F 4 boot_count_ext
    _DRV_NAME:0  F 5000 boot_count
    End of files
    /lfs_ext_flash unmount: 0
    xf8000 is 6 0x1000-byte blocks with 512 cycle
    [00:00:00.009,857] <inf> littlefs: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    [00:00:00.009,948] <err> littlefs: WEST_TOPDIR/modules/fs/littlefs/lfs.c:1077: Corrupted dir pair at {0x0, 0x1}
    [00:00:00.009,948] <wrn> littlefs: can't mount (LFS -84); formatting
    [00:00:00.186,370] <inf> littlefs: /lfs mounted
    [00:00:00.214,874] <inf> littlefs: /lfs unmounted
    [00:00:00.223,144] <inf> littlefs: LittleFS version 2.4, disk version 2.0
    [00:00:00.223,205] <inf> littlefs: FS at MX25R64:0x0 is 30 0x1000-byte blocks with 512 cycle
    [00:00:00.223,205] <inf> littlefs: sizes: rd 16 ; pr 16 ; ca 64 ; la 32
    [00:00:00.228,057] <inf> littlefs: /lfs_ext_flash mounted
    [00:00:00.278,045] <inf> littlefs: /lfs_ext_flash unmounted

    Now, when we enable Dual Stage MCUBoot Support (CONFIG_SECURE_BOOT=y) in above shared example code then it stopped compiling.

    It gives below error. Any idea for this ?

    C:/Users/ncs/v1.9.1/nrf/modules/mcuboot/hooks/nrf53_hooks.c: In function 'boot_read_image_header_hook':
    C:\Users\ncs\v1.9.1\nrf\modules\mcuboot\hooks\nrf53_hooks.c:27:28: error: 'PM_MCUBOOT_PRIMARY_1_ADDRESS' undeclared (first use in this function); did you mean 'PM_MCUBOOT_PRIMARY_ADDRESS'?
       27 |   img_head->ih_load_addr = PM_MCUBOOT_PRIMARY_1_ADDRESS;
          |                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
          |                            PM_MCUBOOT_PRIMARY_ADDRESS
    C:\Users\ncs\v1.9.1\nrf\modules\mcuboot\hooks\nrf53_hooks.c:27:28: note: each undeclared identifier is reported only once for each function it appears in
    C:\Users\ncs\v1.9.1\nrf\modules\mcuboot\hooks\nrf53_hooks.c:28:27: error: 'PM_CPUNET_APP_SIZE' undeclared (first use in this function); did you mean 'PM_SPM_APP_SIZE'?
       28 |   img_head->ih_img_size = PM_CPUNET_APP_SIZE;
          |                           ^~~~~~~~~~~~~~~~~~
          |                           PM_SPM_APP_SIZE
    C:/Users/ncs/v1.9.1/nrf/modules/mcuboot/hooks/nrf53_hooks.c: In function 'network_core_update':
    C:\Users\ncs\v1.9.1\nrf\modules\mcuboot\hooks\nrf53_hooks.c:84:38: error: 'PM_MCUBOOT_PRIMARY_1_DEV_NAME' undeclared (first use in this function); did you mean 'PM_MCUBOOT_PRIMARY_DEV_NAME'?
       84 |  mock_flash_dev = device_get_binding(PM_MCUBOOT_PRIMARY_1_DEV_NAME);
          |                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          |                                      PM_MCUBOOT_PRIMARY_DEV_NAME
    C:\Users\ncs\v1.9.1\nrf\modules\mcuboot\hooks\nrf53_hooks.c:97:20: error: 'PM_CPUNET_B0N_ADDRESS' undeclared (first use in this function)
       97 |   if (reset_addr > PM_CPUNET_B0N_ADDRESS) {

Related