External flash partitions (LittleFS) not detected with nRF5340

Hi,

I have a firmware project that was originally developed for an nRF52833. It successfully mounts LittleFS on 3 partitions in external flash. For the nRF52833 I was simply able to define these partitions in my DTS without using the Partition Manager. This firmware has been rigorously tested for the nRF52833 and LittleFS is successfully configured on external flash. Files can be written and read.

&spi2 {
	compatible = "nordic,nrf-spim";
	status = "okay";
	pinctrl-0 = <&spi2_default>;
	pinctrl-1 = <&spi2_sleep>;
	pinctrl-names = "default", "sleep";
	cs-gpios = <&gpio0 18 GPIO_ACTIVE_LOW>;
	mx25u64: mx25u6432f@0 {
		compatible = "jedec,spi-nor";
		reg = <0>;
		spi-max-frequency = <32000000>;
		jedec-id = [ c2 25 37  ];
		size = <67108864>;
		wp-gpios = <&gpio0 15 GPIO_ACTIVE_LOW>;
		hold-gpios = <&gpio1 9 GPIO_ACTIVE_LOW>;
		sfdp-bfp = [ e5 20 f1 ff ff ff ff 03 44 eb 08 6b 08 3b 04 bb ee ff ff ff ff ff 00 ff ff ff 00 ff 0c 20 0f 52 10 d8 00 ff 23 72 f5 00 82 ed 04 cc 44 83 68 44 30 b0 30 b0 f7 c4 d5 5c 00 be 29 ff f0 d0 ff ff  ];
		has-dpd;
		t-enter-dpd = <10000>;
		t-exit-dpd = <35000>;
	};
};

&mx25u64 {
	partitions {
		compatible = "fixed-partitions";
		#address-cells = <1>;
		#size-cells = <1>;

		user_partition: partition@0 {
			label = "user_partition";
			reg = <0x00000000 0x00370000>;
		};

		display_partition: partition@370000 {
			label = "display_partition";
			reg = <0x00370000 0x0048C000>;
		};

		log_partition: partition@7FC000 {
			label = "log_partition";
			reg = <0x007FC000 0x00004000>;
		};
	};
};

/ {
	fstab {
		compatible = "zephyr,fstab";
		user_lfs: user_lfs {
			compatible = "zephyr,fstab,littlefs";
			mount-point = "/user";
			partition = <&user_partition>;
			read-size = <16>;
			prog-size = <16>;
			cache-size = <64>;
			lookahead-size = <32>;
			block-cycles = <512>;
		};
		display_lfs: display_lfs {
			compatible = "zephyr,fstab,littlefs";
			mount-point = "/display";
			partition = <&display_partition>;
			read-size = <16>;
			prog-size = <16>;
			cache-size = <64>;
			lookahead-size = <32>;
			block-cycles = <512>;
		};
		log_lfs: log_lfs {
			compatible = "zephyr,fstab,littlefs";
			mount-point = "/log";
			partition = <&log_partition>;
			read-size = <16>;
			prog-size = <16>;
			cache-size = <64>;
			lookahead-size = <32>;
			block-cycles = <512>;
		};
	};
};

After porting this project to the nRF5340, it appears the Partition Manager is permanently enabled and my partition definitions in my DTS are ignored. So I created a pm_static.yml file:


littlefs_storage:
  address: 0x00000000  # Start of the combined storage area in external flash
  region: external_flash
  size: 0x00800000  # Total size covering all three partitions
  placement:
    before: end

user_partition:
  address: 0x00000000
  region: external_flash
  size: 0x00370000
  placement:
    within: littlefs_storage  # Explicitly part of littlefs_storage

display_partition:
  address: 0x00370000
  region: external_flash
  size: 0x0048C000
  placement:
    after: user_partition
    within: littlefs_storage

log_partition:
  address: 0x007FC000
  region: external_flash
  size: 0x00004000
  placement:
    after: display_partition
    within: littlefs_storage

and updated my DTS:

	chosen {
		nordic,pm-ext-flash = &mx25u64;
	};

In my logs I can see that there are attempts to read the external flash, but it is never able to access the individual partitions, even though it was able to for the nRF53833 with the same application code. It always just sees the external flash as one giant partition:

[00:00:03.550,109] <inf> littlefs: FS at mx25u6432f@0:0x0 is 2048 0x1000-byte blocks with 512 cycle

Is this a known issue? Is there a proper way to configure LittleFS partitions on external flash? Any help is appreciated.

Parker

  • Hi

    I'm looking into your issue. If you enable mcumgr then you need to use partition manager as it will ignore any changes you have done in the devicetree. 

    Have you remembered to add the including flash config to the childimage for mcuboot?

    Regards

    Runar

  • Hi Runar,

    Thanks for your response.

    I have not explicitly enabled mcumgr. I have attached my prj.conf to this reply. I suspect some other config is enabling the Partition Manager without me knowing.

    7455.prj.conf

    After building the application for the nRF5340, I can see it identifying the partitions in the build files.

    Here is my partitions.yml

    EMPTY_0:
      address: 0xfe000
      end_address: 0x100000
      placement:
        after:
        - settings_storage
      region: flash_primary
      size: 0x2000
    app:
      address: 0x0
      end_address: 0xfc000
      region: flash_primary
      size: 0xfc000
    display_partition:
      address: 0x370000
      end_address: 0x7fc000
      placement:
        after: user_partition
        within: littlefs_storage
      region: external_flash
      size: 0x48c000
    external_flash:
      address: 0x1000000
      end_address: 0x800000
      region: external_flash
      size: -0x800000
    littlefs_storage:
      address: 0x0
      end_address: 0x800000
      placement:
        before: end
      region: external_flash
      size: 0x800000
    log_partition:
      address: 0x7fc000
      end_address: 0x800000
      placement:
        after: display_partition
        within: littlefs_storage
      region: external_flash
      size: 0x4000
    otp:
      address: 0xff8100
      end_address: 0xff83fc
      region: otp
      size: 0x2fc
    rpmsg_nrf53_sram:
      address: 0x20070000
      end_address: 0x20080000
      placement:
        before:
        - end
      region: sram_primary
      size: 0x10000
    settings_storage:
      address: 0xfc000
      end_address: 0xfe000
      placement:
        align:
          start: 0x4000
        before:
        - end
      region: flash_primary
      size: 0x2000
    sram_primary:
      address: 0x20000000
      end_address: 0x20070000
      region: sram_primary
      size: 0x70000
    user_partition:
      address: 0x0
      end_address: 0x370000
      placement:
        within: littlefs_storage
      region: external_flash
      size: 0x370000
    

    Here is my regions.yml

    external_flash:
      base_address: 0x0
      default_driver_kconfig: CONFIG_PM_EXTERNAL_FLASH_HAS_DRIVER
      device: DT_CHOSEN(nordic_pm_ext_flash)
      dynamic_partition: null
      name: external_flash
      placement_strategy: start_to_end
      size: 0x800000
    flash_primary:
      base_address: 0x0
      default_driver_kconfig: CONFIG_SOC_FLASH_NRF
      device: flash_controller
      dynamic_partition: null
      name: flash_primary
      placement_strategy: complex
      size: 0x100000
    otp:
      base_address: 0xff8100
      default_driver_kconfig: ''
      device: ''
      dynamic_partition: null
      name: otp
      placement_strategy: start_to_end
      size: 0x2fc
    sram_primary:
      base_address: 0x20000000
      default_driver_kconfig: ''
      device: ''
      dynamic_partition: sram_primary
      name: sram_primary
      placement_strategy: complex
      size: 0x80000
    

    My partitions.yml seems to indicate that the partitions are indeed contained within littlefs_storage for the build. I suspect I may need to change my application code to properly access the partitions. My original code for the nRF52833 relied on the DTS partition nodes to access the partitions:

    #define USER_PARTITION_NODE    DT_NODELABEL( user_lfs )
    
    FS_FSTAB_DECLARE_ENTRY( USER_PARTITION_NODE );
    
    static struct fs_mount_t *user_mp    = &FS_FSTAB_ENTRY( USER_PARTITION_NODE );
    

    I am still using this code for the nRF5340. Does this need to change?

    I am unsure what you mean by this:
    Have you remembered to add the including flash config to the childimage for mcuboot?

    Does Nordic have a simple example project that shows how to configure LittleFS partitions on external flash while using the Partition Manager?

    Parker

  • I would recommend you to take a look at the demo Vidar posted here  nRF5340-DK: Partition Manager for external flash 
    I think it is exactly what you need 

    Regards

    Runar 

Related