Hi Alan, I have figured out the cause...it was because of a very *small* error in my rawwrite method which was confusing littlefs (which I think commits CRC, flushes it and rechecks the written data for consistency at one point in the forceformat operation).
Right now, mount() works as intended. However there is a floating point exception that occurs if I try to cd or ls the mounted directory, and I'll be looking into it tomorrow (most probably a division by 0 error). Here are the logs and stats just after a mount: https://pastebin.com/QxJ4qMRd (it's a bit long....has stats about each of 4096 pages in a 2MB virtual device). PS: I had to use vi to view the logs in nsh in a sane manner, though a tool like less would be godsend in such cases. BR, SP On Sat, Feb 24, 2024 at 9:23 PM Saurav Pal <resyfer....@gmail.com> wrote: > Hi Xiang and Alan, > > Thanks for the info Xiang. > > Alan, the first error returns ENOTTY as littlefs sends a BIOC_FLUSH > command in IOCTL which isn't supported in NAND, and Xiang has provided the > explanation on why that is fine. > > As for the -ENOSPC, I'm looking into it currently. It *should *have > enough space, considering I have the virtual device with a size of 2MB + > (some bytes for the respective spare areas in blocks) and that is way more > than theoretical requirement of littlefs, so I'll need to debug it further. > > PS: I was also having a problem with the "vi" utility in the sim, any > movement keys (or anything I typed in general) that I typed were echoed out > the the terminal as well, so I fixed that using termios to disable echo > (and enable back on quitting vi). > > BR, > SP > > On Sat, 24 Feb, 2024, 20:18 Alan C. Assis, <acas...@gmail.com> wrote: > >> Hi Saurav, >> >> I suggest you to verifyr these errors first: >> >> *Command: 1293 | BIOC_FLUSH: 1293* >> Error Upper! ioctl | -25 >> >> #define ENOTTY 25 /* Not a typewriter */ >> >> So, you can search where this ENOTTY is returned. >> >> Some to: >> >> nx_mount: ERROR: Bind method failed: -28 >> nsh: mount: mount failed: 28 >> >> #define ENOSPC 28 /* No space left on device */ >> >> BR, >> >> Alan >> >> On Sat, Feb 24, 2024 at 9:28 AM Saurav Pal <resyfer....@gmail.com> wrote: >> >> > Hi all, >> > >> > I've been trying to develop a device simulator for the NAND flash (in >> the >> > sim). >> > >> > A short note on what this does is create a virtual NAND flash (from RAM) >> > and provide a driver, as well as a wrapper around the upper half (which >> for >> > now, does nothing extra). This helps in creating records of >> > reads/writes/erases (in a separate file) for testing and statistics >> > purposes. >> > >> > Since littlefs is one of the supported filesystems on MTD devices, I >> tried >> > to use it to test mount but it tries to use an ioctl with BIOC_FLUSH in >> the >> > format process, which is not supported as far as code in >> > drivers/mtd/mtd_nand.c go. >> > >> > *Should that be something that the NAND driver should support?* >> > >> > Here are the logs of that process, the first ioctl is for >> MTDIOC_GEOMETRY >> > (which is supported), and second for BIOC_FLUSH (in *bold*): >> > >> > nuttx ➤ make && ./nuttx >> > LD: nuttx >> > login: admin >> > password: >> > User Logged-in! >> > nsh> ls /dev >> > /dev: >> > console >> > gpio0 >> > gpio1 >> > gpio2 >> > gpio3 >> > loop >> > null >> > oneshot >> > ram0 >> > ram1 >> > ram2 >> > zero >> > nsh> mtddev >> > Size: 2097152 B >> > >> > Pages: 4096 >> > Blocks: 33 >> > Writing...Done >> > Driver running >> > nsh> ls /dev >> > /dev: >> > console >> > gpio0 >> > gpio1 >> > gpio2 >> > gpio3 >> > loop >> > mtd >> > null >> > oneshot >> > ram0 >> > ram1 >> > ram2 >> > zero >> > nsh> mount -t littlefs -o forceformat /dev/mtd /hi >> > Upper! ioctl >> > Command: 1537 | BIOC_FLUSH: 1293 >> > Upper! bread >> > Page 128 >> > Lower! rawread : Page 128 >> > Lower! rawread : Page 129 >> > Lower! rawread : Page 130 >> > Lower! rawread : Page 131 >> > Upper! erase >> > Lower! eraseblock : Block 0 >> > Upper! bread >> > Page 0 >> > Lower! rawread : Page 0 >> > Lower! rawread : Page 1 >> > Lower! rawread : Page 2 >> > Lower! rawread : Page 3 >> > Upper! bread >> > Page 4 >> > Lower! rawread : Page 4 >> > Lower! rawread : Page 5 >> > Lower! rawread : Page 6 >> > Lower! rawread : Page 7 >> > Upper! bwrite >> > Lower! rawwrite : Page 0 >> > Lower! rawwrite : Page 1 >> > Lower! rawwrite : Page 2 >> > Lower! rawwrite : Page 3 >> > Upper! ioctl >> > *Command: 1293 | BIOC_FLUSH: 1293* >> > Error Upper! ioctl | -25 >> > Upper! bread >> > Page 0 >> > Lower! rawread : Page 0 >> > Lower! rawread : Page 1 >> > Lower! rawread : Page 2 >> > Lower! rawread : Page 3 >> > nx_mount: ERROR: Bind method failed: -28 >> > nsh: mount: mount failed: 28 >> > nsh> >> > >> > The logs with "Upper!" refer to the upper half of the driver being >> > executed, and same for the lower, and the pages are numbered from the >> start >> > of the device (ie. (block << LOG_N_BLOCKS_PER_PAGE) + page_in_block)). >> > >> > Regards, >> > SP >> > >> >