MFS filesystem library does not work with SD cards larger than 2GB.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MFS filesystem library does not work with SD cards larger than 2GB.

Jump to solution
2,128 Views
MattJCole
Contributor V

I am using.

  • KSDK Version: 1.3.0,
  • MFS library 0x04020000
  • Processor: MK65FN2M0xxx18

The Version of MFS filesystem library does not seem to be able to access files after the 2GB mark. It seems to be a bug in the library. Does anyone know how to fix it?

MattJCole_0-1623849171530.png

 

0 Kudos
1 Solution
2,072 Views
MattJCole
Contributor V

The bug is in the MFS library. The function MFS_Write_device_sectors and MFS_Read_device_sectors define seek_loc as a signed 32 bit and use the function lseek witch takes a signed 32 bit value for location. When I updated both functions to define seek_loc as a signed 64 bit variable and used the function _nio_lseek instead of lseek the problem went away.

View solution in original post

14 Replies
2,073 Views
MattJCole
Contributor V

The bug is in the MFS library. The function MFS_Write_device_sectors and MFS_Read_device_sectors define seek_loc as a signed 32 bit and use the function lseek witch takes a signed 32 bit value for location. When I updated both functions to define seek_loc as a signed 64 bit variable and used the function _nio_lseek instead of lseek the problem went away.

2,030 Views
MattJCole
Contributor V

No that didn't fix the problem. I still have the 2GB size issue. I am starting to think the MFS library should not be used do to this bug. Is there an alternative MFS library that works?

0 Kudos
2,026 Views
myke_predko
Senior Contributor III

Hey @MattJCole 

I've had quite good success with FatFS - it's a bit of work to implement but it sounds like you have the IO functions working so it should be fairly straightforward to install FatFS over them.  

As I indicated previously, don't expect FatFS to work for *everything*.  You will probably find that it's a bit cranky with older SD cards as well as the latest. 

In your testing (as well as any other time), I recommend that you don't use Kingston SD cards as the company really is a chip broker rather than an SD card manufacturer - they have no problem slapping their name on whatever cheapest SD cards from wherever they can find them which often means discontinued or literally floor sweepings.  Two Kingston cards which are in identical packaging and bought at the same time, from the same store, together on the same display peg could be completely different and behave differently.  I'm pointing this out because Kingston SD cards are available everywhere and they're generally pretty cheap for a "brandname", but in my application development and testing they caused all kind of confusion and many of the SD cards we bought ended up being good examples of the worst case.  

SanDisk seems to be the current best.  

Good luck and let us know how it works out for you.

myke

0 Kudos
2,019 Views
bobpaddock
Senior Contributor III

Also get them from a known source, not Amazon.
I've gotten 'fake' cards and USB sticks there.
Fortunately these were just for my personal use, not production.

"Standards are great.  Everyone has one."


 

0 Kudos
2,012 Views
myke_predko
Senior Contributor III

Hey @bobpaddock 

At the time, becasue of the weirdness we had with Kingston SD cards (and they were originally bought from Staples) we ordered some directly from Kingston (it doesn't look like you can do that any more - I just checked their website) and we found the same thing.  

Actually we bought quite a few SD cards from Amazon as well AliExpress, Digi-Key, Canada Computers and local dollar stores to get a good range of manufacturers' cards and we found that Kingston SD card operations was just as unpredicatable as the cheapest we could buy. 

I'm not exaggerating when I say we have a shoebox full of SD cards - in different zip lock bags depending on how they worked with different hardware. 

The bag below is the collection of 19 SD Cards that worked everywhere we tested (PCs, Macs, Linux, Canon Camera, 3D printers, HP Printers, Android tablets):

workingEverywhereSDCards.jpg

In case you're interested in the brands of the SD Cards that work everywhere:

  • 5x Centon (2G, 4G, 8G, 16G, 32G)
  • 4x Sandisk (4G, 8G, 16G, 32G)
  • 3x Lexar (2G, 16G, 32G)
  • 2x Kingston (2G, 4G)
  • 2x Hipstreet (8G, 16G)
  • 1x Canon (512MB)
  • 1x Transcend (8G)
  • 1x Nexxotek (4G)

That's not representative of the total number of each manufacturer's cards we bought.  I know we bought at least 30 Kingstons SD cards and I don't think we had any Centon cards which had problems anywhere.  We do have 64GB and 128GB SD cards in the group, but they only worked in the cameras and Macs and some PCs (depending on the SD Card port).  

I can't find the tracking spreadsheet and I don't feel like going through any more bags.  

0 Kudos
2,009 Views
bobpaddock
Senior Contributor III

Thank you for the list of working cards, very useful.

It is very annoying that nothing above 32G really works in most devices.

 

0 Kudos
2,002 Views
myke_predko
Senior Contributor III

Hi @bobpaddock 

Just curious; what applications are you looking that requires more than 32 GB?  

SD HD cards are very available and quite inexpensive.  32 GB really is a lot of storage (eight DVD movies for all intents and purposes).  

0 Kudos
1,980 Views
MattJCole
Contributor V

The software runs on an ocean buoy that generates power. The software records data about the buoy every 100 MS. This will generate a lot of data. Since the buoy can be in the middle of no where with very spotty internet connection that data on the buoy might go a while before it can be downloaded, so it must be stored on the device until it can be downloaded. 

0 Kudos
1,974 Views
myke_predko
Senior Contributor III

@MattJCole 

That sounds really cool.  

I would recommend that you reach out to SD card manufacturers to get them to explain their products along with design/manufacturing - as this is (I believe) an environmental product they should be willing to give some time to you so that you can ensure that you will get consistently working SD cards which should minimize problems down the road.  

0 Kudos
1,981 Views
MattJCole
Contributor V
 
0 Kudos
1,988 Views
bobpaddock
Senior Contributor III

It is more that off the shelf devices like my Canon camera and my DashCam won't work with any card larger than 32G.  Whom ever is developing devices like these, run into the same problems we do.

 

 

2,003 Views
MattJCole
Contributor V

Found the culprit. It relates to the lseek again. The functions _io_part_mgr_read and _io_part_mgr_write use lseek instead of _nio_lseek. I will look into FatFS for a potential long term solution but for now I do not have time to get a new file system library to work with the KSDK OS.

2,079 Views
myke_predko
Senior Contributor III

@MattJCole 

You're going to have to understand whether or not the library you are using was written for the "SD" or "SDHC" (or later) standards.  The "SD" standard is for cards up to 2GB which is where you seem to be.  "SDHC" works for up to 32GB, SDXC is good for up to 2TB, etc.  

Along with the high level standards there are a plethora of lower level application specific standards meaning that it's a very non-trivial exercise coming up with code (as well as hardware wiring) that can work with "any" SD card.  

@danielchen sounds like he's accessing a library that can access at least an SDHC card.  

I'm not aware of any single project that provides "universal" SD card access along with a FatFS ability to access all the files on "every" SD card.  You are probably going to have to bound what your application can work with.  

Sorry, I wish I had better news, but this was something a spent a few months on three years ago.  I have literally a shoebox with different type, size, vintage, standard SD cards that I was able to access with varying levels of success.  

2,086 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi MattJCole:

I tested the demo under folder

\KSDK_1.3.0\middleware\filesystem\mfs\examples\sdcard\build\iar\sdcard_frdmk64f

with my sd card.  I had 6 files in my sd card,  the total size is more than 2.8G .

danielchen_0-1627967059821.png

I can access the file.  could you please let me know how to reproduce your issue on my side?

 

Regards

Daniel

0 Kudos