Author Topic: Mountable version of SD_CARD.bin  (Read 27456 times)

Offline schveiguy

  • Newbie
  • *
  • Posts: 19
    • View Profile
Mountable version of SD_CARD.bin
« on: August 31, 2012, 08:25:16 PM »
Hi,

I am just getting back into developing using uTasker, and I was hoping there was a way to mount the simulated SD_CARD.bin on my PC so I can examine the contents and ensure they are valid.

Alternatively, is there a way for the simulator to use a physical SD card inserted into the PC?

Thanks

-Steve

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3243
    • View Profile
    • uTasker
Re: Mountable version of SD_CARD.bin
« Reply #1 on: August 31, 2012, 09:20:51 PM »
Hi Steve

The simulator uses a special format for the SD_CARD.bin which only saves the contnet of sectors that are actually used (otherwies it may require a hugh file to simulate a large card).

Thsi means that the content of the file can not be used by the PC and also the simulator doesn't work with a real card - which would however be nice if it could. I don't know how to access the card at a low level though (rather than going through a standard file system interface which discuises the details). If it were possible to tell the PC to read physical sector of a real card and write it too then this would be very useful (but haven't found anything that allows it yet...).

This means that presently the only way to check the content of the simulated SD card is to use the "sect" commands in the utFAT command line interface.

Regards

Mark

Offline schveiguy

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Mountable version of SD_CARD.bin
« Reply #2 on: September 06, 2012, 05:26:00 PM »
OK, thanks.

I actually would not mind having a fully allocated SD card "image" on my PC, I certainly have 1GB to spare.  I actually am using a Windows VMWare image on a MAC, and I'm pretty sure my mac could mount a full filesystem as a file.

Is it difficult to do this?

-Steve

Offline schveiguy

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Mountable version of SD_CARD.bin
« Reply #3 on: September 06, 2012, 06:09:22 PM »
Further,

It would be fine if I had to take an actual SD card and copy the binary image of it to a file in order for this to work.  In other words, I don't care if the simulator creates the image, I just want to be able to use a mountable image with it.

-Steve

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3243
    • View Profile
    • uTasker
Re: Mountable version of SD_CARD.bin
« Reply #4 on: September 06, 2012, 06:43:27 PM »
Hi Steve

It would presumably be possible to use a large ram area for the simulation but to copy this to a card would then require a low level copy function so that each section is copied to the correct physical location of the SD card. A simple file copy from disk to a physical card would mean that the PC will use its own file system (on top) which would not be what is required.

If we could find a low level interface which can read and write sections on a physical card directly the simulator would be able to work in the perfect manner.

I did try some programs that I fount out there which said that they could manipulate cards but was always disappointed that they could only really do some forms of formatting which was not very helpful.

I wonder whether the required interface exists somewhere?

Regards

Mark

Offline schveiguy

  • Newbie
  • *
  • Posts: 19
    • View Profile
Re: Mountable version of SD_CARD.bin
« Reply #5 on: September 06, 2012, 06:54:17 PM »
I was thinking of simply using linux dd to copy the bits from a physical SD card to a file, then using that file as the simulated SD card.  Then, when I wanted to examine the contents on a PC, use linux dd to copy them back to the physical card (easy to do this with VMWare :)  Optionally, I could mount the file directly on Mac or Linux (there has to be a way to do this in Windows, but I'm not sure).

The simulator does not have to be aware of the filesystem layout of the file as far as I know, it just has to be able to seek within the file, right?

Yes, to use a physical SD card *directly*, we would need a way to access it as a file.  I wonder if using CreateFile using the low-level device file name would allow this?  I would guess not unless the SD card driver processes read and write system calls.

On Linux, this would be easy, just open /dev/sdx

-Steve

Offline creitzel

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Mountable version of SD_CARD.bin
« Reply #6 on: April 27, 2017, 07:27:37 PM »
Mark,

Have you looked into the IOCtl interface in Windows? 

When I was researching low level access to my usb drive on the Raspberry Pi (Linux), I ended up using to the IOCtl api to send SCSI commands directly to the device, which allows me to read/write sectors.   

I know Windows also supports the IOCtl api, so theoretically, you should be able to do the same thing to gain access to SD Card via USB on windows, and either copy the raw sectors to an image file, and mount that via your code, or talk directly to an SD Card mounted via usb.

Chris

Offline mark

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 3243
    • View Profile
    • uTasker
Re: Mountable version of SD_CARD.bin
« Reply #7 on: April 28, 2017, 10:58:17 PM »
Hi Chris

If it is possible to read and write sectors of the SD card it would be possible to perform utFAT directly on the card when the simulator runs.

Possibly the starting point is here (?)
https://msdn.microsoft.com/en-us/library/ff566970(v=vs.85).aspx

If via USB either a memory stick could be used, or an SD card in a USB reader. Otherwise maybe directly to the SD card in its reader (?)

At first glance I can't say that I understood much about what routines would be used though....or about how to get started on it.

Regards

Mark


Offline creitzel

  • Newbie
  • *
  • Posts: 29
    • View Profile
Re: Mountable version of SD_CARD.bin
« Reply #8 on: May 01, 2017, 05:08:46 PM »
Mark,

Quote
If it is possible to read and write sectors of the SD card it would be possible to perform utFAT directly on the card when the simulator runs.

Yes, I believe it is possible to read and write the sectors of the card directly using IoCtl. 

Quote
If via USB either a memory stick could be used, or an SD card in a USB reader. Otherwise maybe directly to the SD card in its reader (?)

When I was writing and testing my code, I was using a USB SD card reader, connected to a debian linux virtual machine, running on my Windows 7 desktop box.  I'm not sure how you would go about connecting directly to an SD Card reader, because I've never worked with them.  But, USB card readers seem to work fine.

Quote
At first glance I can't say that I understood much about what routines would be used though....or about how to get started on it.

Possibly the starting point is here (?)
https://msdn.microsoft.com/en-us/library/ff566970(v=vs.85).aspx


On Linux (where I was writing my code), the calls go through the generic SCSI driver, and to the device.  I'm not sure what layers are involved on Windows, but that link you posted definitely seems like the right place to start. 

I looked up one of the calls that I implemented (a ReadCapacity call), there, and it appears to be doing the exact same thing I was on Linux.  I believe, on windows, the DeviceIOControl function is the key to it.  On Linux, the function is called IoCtl, but they both take similar parameter lists, and I think they do the same thing.  Here's a link to the MSDN docs on the windows version:  https://msdn.microsoft.com/en-us/library/windows/desktop/aa363216(v=vs.85).aspx

The IoCtl function can be used to interact directly with the driver layer of a device, and it allows you to pass device specific commands to the device, and get back the results.  For mass storage type devices, I believe the underlying commands are just the SCSI commands that the device supports (at least this seemed to prove true on Linux, because that was what I used when writing my code).

I can post my code for you, if it would help ya.  It's written in Free Pascal, but it only wraps 2 of the function calls right now, one to read the device's capacity (i.e. total sectors, and sector size), and one to read a raw sector from the device.

it basically boils down to something like the following:

Code: [Select]
   // Open a file handle to the device
   fd := fpOpen('/dev/sdb1', O_RDOnly);  // here, /dev/sdb1 is the device Linux mapped to my SD Card reader

   // Send IoCtl codes to the device to perform the functions you want
   // this is actually a bit more involved when you add in appropriate error handling etc.
   fpIoCtl(fd, ...);  // The parameters here vary based on what command you want to send.  The first parameter is a
   fpIoCtl(fd, ...);  // a single byte code that represents the command, and the other parameters are for passing data
                           // in and out of the command.

   // Close the device when done
   fpClose(fd);


Here's a link to one of the documents I found, documenting the SCSI commands that can be sent via the IoCtl function:

http://www.seagate.com/staticfiles/support/disc/manuals/scsi/100293068a.pdf

Sorry it took so long to respond, My birthday was Saturday, and my family had all kinds of activities planned for me, so I wasn't able to get online much.  :-)

Hope this helps,

Chris