Skip to content

MAX32690: filesystem won't mount initially unless a delay is added #91969

@dkouba-atym

Description

@dkouba-atym

Describe the bug

I have a MAX32690 dev kit from ADI and have it configured with a LittleFS filesystem located in the chip's flash. Here's the relevant excerpts from my overlay:

	fstab {
        compatible = "zephyr,fstab";

        lfs1: lfs1 {
            compatible = "zephyr,fstab,littlefs";
            partition = <&user_data_partition>;
            mount-point = "/lfs";
            
            read-size = <256>;      // Match 32690 flash controller
            prog-size = <256>;      // Match 32690 flash controller
            cache-size = <256>;     // Not sure what the max is
            lookahead-size = <32>;  // Default
            block-cycles = <512>;   // Default

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

...

        user_data_partition: partition@154000 {
			label = "user_data";
			reg = <0x154000 DT_SIZE_K(1024)>;
		};
        
	};
};

When the filesystem is fresh after a full chip erase, LittleFS cannot initialize:

D: fs register 1: 0
I: littlefs partition at /lfs
I: LittleFS version 2.10, disk version 2.1
D: FS area 0 at 0x154000 for 1048576 bytes
I: FS at flash_controller@40029000:0x154000 is 64 0x4000-byte blocks with 512 cycle
I: partition sizes: rd 256 ; pr 256 ; ca 256 ; la 32
E: WEST_TOPDIR/modules/fs/littlefs/lfs.c:1389: Corrupted dir pair at {0x0, 0x1}
W: can't mount (LFS -84); formatting
E: format failed (LFS -5)
E: fs mount error (-5)
E: Automount /lfs failed: -5
I: /lfs automounted

I had a suspicion this was because the flash device is not ready yet when we start using it, so I added a delay in the LittleFS init:

static int littlefs_init(void)
{
	static struct fs_mount_t *partitions[] = {
		DT_INST_FOREACH_STATUS_OKAY(REFERENCE_MOUNT)
	};

	int rc = fs_register(FS_LITTLEFS, &littlefs_fs);

	if (rc == 0) {
		struct fs_mount_t **mpi = partitions;
		k_sleep(K_MSEC(50));
		while (mpi < (partitions + ARRAY_SIZE(partitions))) {
			mount_init(*mpi++);
		}
	}

	return rc;
}

And the filesystem boots fine:

D: fs register 1: 0
I: littlefs partition at /lfs
I: LittleFS version 2.10, disk version 2.1
D: FS area 0 at 0x154000 for 1048576 bytes
I: FS at flash_controller@40029000:0x154000 is 64 0x4000-byte blocks with 512 cycle
I: partition sizes: rd 256 ; pr 256 ; ca 256 ; la 32
E: WEST_TOPDIR/modules/fs/littlefs/lfs.c:1389: Corrupted dir pair at {0x0, 0x1}
W: can't mount (LFS -84); formatting
I: /lfs mounted
D: fs mounted at /lfs
I: Automount /lfs succeeded
*** Booting Zephyr OS build v4.1.0-40-g34b526826adf ***
I: /lfs automounted

CONFIG_FILE_SYSTEM_INIT_PRIORITY and CONFIG_FLASH_INIT_PRIORITY are at their default values, 99 and 50 respectively.

Anyone have an idea of what could be going on?

Regression

  • This is a regression.

Steps to reproduce

No response

Relevant log output

Impact

Functional Limitation – Some features not working as expected, but system usable.

Environment

No response

Additional Context

No response

Metadata

Metadata

Labels

bugThe issue is a bug, or the PR is fixing a bugplatform: ADIAnalog Devices, Inc.priority: lowLow impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions