Keil Logo

lpc1788 Cortex-m3 USB flash-fs micro sd, make it write protect for windows

Next Thread | Thread List | Previous Thread Start a Thread | Settings

Details Message
Read-Only
Author
Wouter Schol
Posted
4-Oct-2011 15:28 GMT
Toolset
ARM
New! lpc1788 Cortex-m3 USB flash-fs micro sd, make it write protect for windows

Hello All,

I get stuck on this one,

I have:

an Embedded Artists LPC1788 cortex-m3 developers board.
using TCP-net and Flash-fs and RTX kernel i've managed to use all TCP functions (in tasks, like TCP sockets, TFTP server, HTTP) and also using my microSD card (2 GB sandisk) with FAT etc.
I have USB mass storage class working that directly can access my microsd card.
so in windows i get a disk that has 2 GB size with my files. (yeah it works :D )

Now I want to make it write protect for windows, I want read access to the microSD in windows, but the user may not delete or manipulate the data.
At this time I made in mscuser.c that the functions MSC_MemoryWrite and MSC_MemoryVerify don't access the microSD.
In windows I can read the microSD now, but when I write/delete files it is only in the cache of windows. when I unplug and plug in my device, I see my original microSD again.

what do I want:
ok what I have can work.. but I want that windows knows that my microSD is an write protected device, so that you'll get an error if you try to write of delete files.

my device may access the microSD to store files by himself (logging) but only by USB mass storage it must be blocked.

Is there any way to set this? like in the function MSC_Inquiry, maybe some parameter of bulbuf?

I hope that someone can help me with this.

Greetings,

Wouter

Read-Only
Author
Hans-Bernhard Broeker
Posted
4-Oct-2011 20:03 GMT
Toolset
ARM
New! RE: lpc1788 Cortex-m3 USB flash-fs micro sd, make it write protect for windows

I suspect you're substantially underestimating the scope of the problem you've created there.

Even reading that file system from the Windows side won't work reliably while you're secretly also writing to it behind Windows' back. Windows strictly assumes itself to be the only system accessing those files. It may appear to work, but ultimately it won't.

Read-Only
Author
Wouter Schol
Posted
5-Oct-2011 07:55 GMT
Toolset
ARM
New! RE: lpc1788 Cortex-m3 USB flash-fs micro sd, make it write protect for windows

Dear Hans-Bernhard,

I know that you may not manipulate the microSD at the same time.
In my code I check if the USB is connected otherwise the ARM will not access the microSD by himself. Like your Android mobile phone. If you connect the phone to your pc and you want mass storage access, the microSD will be unmounted (MCU cannot access the microSD directly anymore).

your sdcard reader must check if the write protect is on (SD-card switch on the left side).
it must say in some way to windows that it is write protected.

my only question is: How can I say to windows that a USB mass storage device is write protected (read only)

regards,

Wouter

Read-Only
Author
Tamir Michael
Posted
5-Oct-2011 10:19 GMT
Toolset
ARM
New! RE: lpc1788 Cortex-m3 USB flash-fs micro sd, make it write protect for windows

Maybe there is a SCSI command for that - I don't know if that code is available anymore with the recent "let hide everything that we can make money with" move by Keil (oh, yeah). Either way, you can always power down USB while addressing the SD card from the microcontroller side, remounting later.

Read-Only
Author
servo controlled zeusti
Posted
5-Oct-2011 10:44 GMT
Toolset
ARM
New! 110%

<quote>"let hide everything that we can make money with" move by Keil (oh, yeah).</quote>

Tapeer,

yew are a cynic.

in case yoo donot understand plz check hear

http://dictionary.reference.com/browse/cynic

Always yo're freind.

Zeusti

Read-Only
Author
Wouter Schol
Posted
5-Oct-2011 12:23 GMT
Toolset
ARM
New! RE: lpc1788 Cortex-m3 USB flash-fs micro sd, make it write protect for windows

Hi,

I've got it working, my mass storage device is now write protected.
Searched for SCSI commands with write protection parameters, but this didn't work.

just comment out the SCSI_WRITE10 and SCSI_WRITE12 commands in function MSC_GetCBW in mscuser.c
if windows tries a write command, it will go to fail. Windows then responds that it is write protected!

regards,

Wouter

Read-Only
Author
Tamir Michael
Posted
5-Oct-2011 12:38 GMT
Toolset
ARM
New! RE: lpc1788 Cortex-m3 USB flash-fs micro sd, make it write protect for windows

Yes, I thought it would be something like that. Congratulations.

Read-Only
Author
servo controlled zeusti
Posted
5-Oct-2011 13:04 GMT
Toolset
ARM
New! off coarse yew did

<quote>Yes, I thought it would be something like that.</quote>

LMFAO

Always yo're freind.

Zeusti

Read-Only
Author
Wouter Schol
Posted
5-Oct-2011 13:06 GMT
Toolset
ARM
New! RE: lpc1788 Cortex-m3 USB flash-fs micro sd, make it write protect for windows

and to disable deleting (you can't write so delete would not work, but you'll get no message and file goes away) you must edit the MSC_ModeSense10 and MSC_ModeSense6 parameters with write protection for modesense10 it is byte 3 bit 8, for modesense6 it is byte 2 bit 8 (found on internet)

now you can uncomment the write functions too, because windows will see that the device is write protected, and when deleting it will give also a "write protected" error

Read-Only
Author
Tamir Michael
Posted
5-Oct-2011 13:19 GMT
Toolset
ARM
New! RE: lpc1788 Cortex-m3 USB flash-fs micro sd, make it write protect for windows

Wouter ,

I don't have time to check but I'm curious - is it possible to make a transaction "write only" ?

Read-Only
Author
Wouter Schol
Posted
5-Oct-2011 14:48 GMT
Toolset
ARM
New! RE: lpc1788 Cortex-m3 USB flash-fs micro sd, make it write protect for windows

Tamir,

Ehm, that would be strange, think that you won't be able to see the microSD FAT and files, but in windows you should can open the microSD and write something on the microSD which you can't see?

hope you understand me, but in my opinion that is strange.

I'll test a little thing but I don't think it's going to work.

Read-Only
Author
Tamir Michael
Posted
5-Oct-2011 14:56 GMT
Toolset
ARM
New! RE: lpc1788 Cortex-m3 USB flash-fs micro sd, make it write protect for windows

It seems then that the same SCSI commands are used to deliver file system image details as are used to deliver data. I thought there might be a way to coax a device to reveal its file system structure, but not to allow read access to the content of the file system.

Read-Only
Author
Wouter Schol
Posted
5-Oct-2011 15:03 GMT
Toolset
ARM
New! RE: lpc1788 Cortex-m3 USB flash-fs micro sd, make it write protect for windows

Then you should look at the USB bootloader examples with CRP.
when CRP is enabled, the mass storage device is loaded but you can't read the file (firmware), you can only update it.
looking at the code in the read function it returns 0x00 each byte if CRP 2 or 3 is enabled.
but the FAT system is static here, don't know how to do it on your sdcard which is dynamic.

Next Thread | Thread List | Previous Thread Start a Thread | Settings

  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.