Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to format spi flash as vfat #10445

Closed
xiaotailang opened this issue Aug 30, 2023 · 10 comments
Closed

how to format spi flash as vfat #10445

xiaotailang opened this issue Aug 30, 2023 · 10 comments

Comments

@xiaotailang
Copy link

How can I format an SPI flash as a VFAT file system and manage it through the MTD interface? Are there any reference examples? Currently, I only see the method of formatting it as NXFFS and managing it through MTD.

@xiaoxiang781216
Copy link
Contributor

xiaoxiang781216 commented Aug 30, 2023

no, vfat can't work with mtd directly (mtd is totally different storage from the tradition block device). You can either:

  1. Use the flash friendly file system(e.g. littlefs, nxffs, smartfs)
  2. Utilize ftl(e.g. dhara: https://github.com/apache/nuttx/blob/master/drivers/mtd/dhara.c) which convert mtd interface to block interface

@xiaotailang
Copy link
Author

Thank you very much. Are there any reference examples for using other file systems on SPI flash, such as LittleFS or SmartFS? I have encountered some issues while using NXFFS.

@xiaoxiang781216
Copy link
Contributor

you can search the related config in nuttx/boards.

@xiaotailang
Copy link
Author

xiaotailang commented Sep 11, 2023

@xiaoxiang781216 Hello, when I was testing the file system, I tried using littlefs and it worked fine. However, when I attempted to use smartfs and referred to some boards, I encountered some issues. Here are the steps I followed:
CONFIG_FS_SMARTFS=y
CONFIG_SMARTFS_ERASEDSTATE=0xff
CONFIG_SMARTFS_MAXNAMLEN=16

CONFIG_MTD_SMART=y
CONFIG_MTD_SMART_SECTOR_SIZE=512
CONFIG_MTD_SMART_WEAR_LEVEL=y

Next, I added the following code:
smart_initialize(minor, mtd, "spiw25");

if (ret < 0)
{
finfo("smart_initialize failed, Trying to erase first...\n");
ret = mtd->ioctl(mtd, MTDIOC_BULKERASE, 0);
if (ret < 0)
{
ferr("ERROR: ioctl(BULKERASE) failed: %d\n", ret);
return ret;
}

finfo("Erase successful, initializing it again.\n");
smart_initialize(minor, mtd, "spiw25");
if (ret < 0)
  {
    ferr("ERROR: smart_initialize failed: %d\n", ret);
    return ret;
  }

}

When I entered "mksmartfs /dev/smart0," there was no error, but there was no "smart0" file generated in the "/dev/" directory. Consequently, the subsequent "mount" operation failed. Are there any additional configurations or steps that I may have overlooked?

It is working properly now. The bug in my code was causing the issue.

Sometimes there might be garbage files or incorrect content in the SPI flash, and in such cases, the "rm" command may fail to delete files. Is there any interface or command that can format the flash or erase the entire flash chip? I found a built-in command function and its corresponding command called "flash_eraseall" in the file system. Does this command also work for SPI flash?

@TimJTi
Copy link
Contributor

TimJTi commented Sep 11, 2023

I think you need something like (where mnt_name is your choice)?

ret = nx_mount("/dev/smart0", "/mnt/mnt_name", "smartfs", 0, autoformat);

@xiaotailang
Copy link
Author

@TimJTi

I think you need something like (where mnt_name is your choice)?

ret = nx_mount("/dev/smart0", "/mnt/mnt_name", "smartfs", 0, autoformat);

Yes, I have resolved the issue.。
I just tried the flash_eraseall command and am able to fully erase the SPI flash. Have you ever encountered a problem where writing to a SPI flash formatted with littlefs would get stuck when trying to write a file using the echo "12345" > 1.txt command during your previous development process? I am seeing this issue now while testing on top of littlefs, and I suspect it might be due to the echo command not interfacing correctly with littlefs.

@TimJTi
Copy link
Contributor

TimJTi commented Sep 11, 2023

Ok, away at moment so GitHub phone app sometimes slow to refresh. Sorry if I answered a question that didn't need answers!

I only ever tried things like "ls -l > /mnt/flash" and that always worked as long as the memory was properly formatted and mounted. I tried vfat, littlefs, smartfs and nxffs. Settled on littlefs in the end.

@xiaotailang
Copy link
Author

xiaotailang commented Sep 11, 2023

Ok, away at moment so GitHub phone app sometimes slow to refresh. Sorry if I answered a question that didn't need answers!

I only ever tried things like "ls -l > /mnt/flash" and that always worked as long as the memory was properly formatted and mounted. I tried vfat, littlefs, smartfs and nxffs. Settled on littlefs in the end.
ok ! thank you very much for your response.I also believe that littlefs is the best choice.

@TimJTi
Copy link
Contributor

TimJTi commented Sep 11, 2023

Should have been /mnt/flash/file.txt or similar of course. I think explicit paths may always be needed too? Or, at least, ./file.txt

@xiaotailang
Copy link
Author

Should have been /mnt/flash/file.txt or similar of course. I think explicit paths may always be needed too? Or, at least, ./file.txt

ok !Thank you once again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants