Skip to content

Conversation

@desowin
Copy link

@desowin desowin commented Sep 30, 2022

USB mass storage sample, when configured to use flash-based disk do not work in Zephyr 3.2 release due to removed label property. The naive fix is to change the "MX25R64" to "mx25r6435f@0" and "GD25Q16" to "gd25q16@0" in samples/subsys/usb/mass/Kconfig. During the review, the naive fix was deemed inappropriate.

The PR addresses the issue by introducing "zephyr,flash-disk" compatible property. That way, any number of flashdisks can be specified in devicetree. While this fixes the USB Mass Storage sample, the actual Mass Storage class support for multiple LUNs is out of scope of this PR.

@zephyrbot zephyrbot added platform: nRF Nordic nRFx area: USB Universal Serial Bus labels Sep 30, 2022
@zephyrbot zephyrbot requested a review from anangl September 30, 2022 13:06
@jfischer-no jfischer-no added bug The issue is a bug, or the PR is fixing a bug area: Samples Samples labels Sep 30, 2022
jfischer-no
jfischer-no previously approved these changes Sep 30, 2022
Copy link
Contributor

@mbolivar-nordic mbolivar-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Second patch is the wrong approach. Kconfig option should be removed entirely and DEVICE_DT_GET used instead. See devicetree release notes for v3.2 for extended discussion

@jfischer-no
Copy link
Contributor

jfischer-no commented Sep 30, 2022

Second patch is the wrong approach. Kconfig option should be removed entirely and DEVICE_DT_GET used instead. See devicetree release notes for v3.2 for extended discussion

No, that is not the intention of this patch. See also changes in tests/subsys/fs/fat_fs_api, 418d601.

@desowin
Copy link
Author

desowin commented Oct 3, 2022

Second patch is the wrong approach. Kconfig option should be removed entirely and DEVICE_DT_GET used instead. See devicetree release notes for v3.2 for extended discussion

I can achieve this by modifying

flash_dev = device_get_binding(CONFIG_DISK_FLASH_DEV_NAME);
to

#if DT_NODE_HAS_STATUS(DT_NODELABEL(mx25r64), okay)
	flash_dev = DEVICE_DT_GET(DT_NODELABEL(mx25r64));
#elif DT_NODE_HAS_STATUS(DT_NODELABEL(gd25q16), okay)
	flash_dev = DEVICE_DT_GET(DT_NODELABEL(gd25q16));
#elif DT_NODE_HAS_STATUS(DT_NODELABEL(flashcontroller0), okay)
	flash_dev = DEVICE_DT_GET(DT_NODELABEL(flashcontroller0));
#endif

but doing so doesn't really seem right.

@mbolivar-nordic Is above what you want? How to handle the device selection, is the ifdef chain appropriate?

@de-nordic
Copy link
Contributor

de-nordic commented Oct 5, 2022

#if DT_NODE_HAS_STATUS(DT_NODELABEL(mx25r64), okay)
	flash_dev = DEVICE_DT_GET(DT_NODELABEL(mx25r64));
#elif DT_NODE_HAS_STATUS(DT_NODELABEL(gd25q16), okay)
	flash_dev = DEVICE_DT_GET(DT_NODELABEL(gd25q16));
#elif DT_NODE_HAS_STATUS(DT_NODELABEL(flashcontroller0), okay)
	flash_dev = DEVICE_DT_GET(DT_NODELABEL(flashcontroller0));
#endif

but doing so doesn't really seem right.

Is there an option to use chosen zephyr,flash-disk for that purpose? For example

chosen {
    zephyr,flash-disk = &mx25r64;
};

This would allow code like this

    flash_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_flash_disk));

This is flexible and easily allows to set default value in DTS or board overlay, while at the same time easily allowing to replace it in app overlay by doing /delete-property/ zephyr,flash-disk on the chosen node.

There is also an option, less nice and flexible, to use specific label, for example

zephyr_flash_disk_0: &mx25r64 : { };

and in code:

   flash_dev = DEVICE_DT_GET(DT_NODELABEL(zephyr_flash_disk_0));   

In both cases Kconfigs are no longer there and there is no need for if sequence, as flash disk selection is done in DTS.

IMHO using Kconfig to select flash disk is not best approach, because the Kconfig will require updates every time when new flash devices or boards with such devices are added; when the DTS is designated for selecting flash disk, and you add new board with new flash, all you have to do is to point to it with chosen or label, and you do not have to touch Kconfig, or the flash disk driver code.

@desowin
Copy link
Author

desowin commented Oct 5, 2022

Is there an option to use chosen zephyr,flash-disk for that purpose? For example

chosen {
    zephyr,flash-disk = &mx25r64;
};

This seems better than the #ifdef ladder but how to set the defaults? Should the zephyr,flash-disk (or equivalent) be specified in mass storage boards overlay? Should there be a native_posix.overlay specifying zephyr,flash-disk added to tests/subsys/fs/fat_fs_api?

Another option instead of overlays would be putting it by default in board dts, but it raises an issue what to do with targets that actually use the mx25r64 flash for some partitions? Going with the overlays in samples/test direction avoids this issue.

@de-nordic
Copy link
Contributor

Should the zephyr,flash-disk (or equivalent) be specified in mass storage boards overlay? Should there be a native_posix.overlay specifying zephyr,flash-disk added to tests/subsys/fs/fat_fs_api?

Every sample and test, either generic or board specific, that uses mass storage needs to have overlay which elects the flash disk; the same way it does this with Kconfig now, just the place will be different.

Another option instead of overlays would be putting it by default in board dts, but it raises an issue what to do with targets that actually use the mx25r64 flash for some partitions? Going with the overlays in samples/test direction avoids this issue.

Not really fan of this, but it wouldn't break anything unless you enable all subsystems that use that specific flash at the same time.

@mbolivar-nordic mbolivar-nordic requested a review from galak October 5, 2022 12:05
@galak
Copy link
Contributor

galak commented Oct 5, 2022

I agree with the approach of zephyr,flash-disk and removal of Kconfig DISK_FLASH_DEV_NAME and replacing device_get_binding with DEVICE_DT_GET.

tmon-nordic and others added 7 commits October 28, 2022 09:42
Add bindings to describe a block storage device based on flash map
partition.

Co-authored-by: Johann Fischer <johann.fischer@nordicsemi.no>
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Add flash disk description to overlays. Specify custom flashdisk
partition for fat fs api test to match the Kconfig values, because
native posix storage partition is too small for FatFS filesystem.

Co-authored-by: Johann Fischer <johann.fischer@nordicsemi.no>
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Use devicetree to obtain information for all zephyr flash disks.

Co-authored-by: Johann Fischer <johann.fischer@nordicsemi.no>
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Allocate cache buffer for every flashdisk instance instead of using one
globally shared buffer.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Remove all obsolete DISK_FLASH* Kconfig options.

Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Include zephyr,flash-disk devicetree sample in disk documentation.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Mention removal of flashdisk Kconfig options in favor of new
zephyr,flash-disk devicetree binding.

Signed-off-by: Tomasz Moń <tomasz.mon@nordicsemi.no>
Laczen
Laczen previously approved these changes Oct 28, 2022
jfischer-no
jfischer-no previously approved these changes Oct 28, 2022
Comment on lines 80 to 100
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks ability to have RO FAT FS on non page uniform devices.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just remove the constraints check commit then. The write on non-uniform partitions never worked before and this PR won't change it, but removing the constraint check will make the RO continue to work.

@desowin desowin dismissed stale reviews from jfischer-no and Laczen via 1def895 October 28, 2022 09:41
@desowin desowin requested a review from de-nordic October 28, 2022 09:41
Copy link
Contributor

@de-nordic de-nordic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK. Thanks for commits and your patience.

@carlescufi carlescufi merged commit 7cfc553 into zephyrproject-rtos:main Oct 28, 2022
@Laczen
Copy link
Contributor

Laczen commented Oct 28, 2022

@desowin, Thank you for the excellent work and the perseverance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Build System area: Devicetree Binding PR modifies or adds a Device Tree binding area: Devicetree area: Disk Access area: Documentation area: File System area: Samples Samples area: USB Universal Serial Bus bug The issue is a bug, or the PR is fixing a bug platform: nRF Nordic nRFx Release Notes To be mentioned in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.