Forcing USB mass storage device to look like CDROM

Discussion around product based on ARM Cortex M3 core.

Moderators: nferre, ncollot

hennesa
Posts: 8
Joined: Tue Feb 15, 2011 10:17 am

Forcing USB mass storage device to look like CDROM

Tue Feb 15, 2011 10:26 am

dear All,

I am using the ATSAM3U-EK. I've managed to run the mass storage device example.
Now I want the device o appear to windows as a CDROM. How can I do that?

I've changed the media settings (media->protected) to 1 but still it looks as normal USB stick.

Any idea?
CptTitanic
Posts: 871
Joined: Sat Oct 30, 2010 6:04 pm

Re: Forcing USB mass storage device to look like CDROM

Tue Feb 15, 2011 6:01 pm

>>Any idea?

The SCSI Inquiry command needs to return a device type of 5, and your reads need to return 2048 byte sectors. You'd probably also need to implement Read TOC and other CD/DVD specific commands with the responses Windows expects.
hennesa
Posts: 8
Joined: Tue Feb 15, 2011 10:17 am

Re: Forcing USB mass storage device to look like CDROM

Wed Feb 16, 2011 12:03 pm

What is the code for the SCSI Inquiry command?

Where can I get more info about the SCSI Inquiry command and all other commands that I must handle?
CptTitanic
Posts: 871
Joined: Sat Oct 30, 2010 6:04 pm

Re: Forcing USB mass storage device to look like CDROM

Wed Feb 16, 2011 7:13 pm

Top result for a Google of "SCSI Inquiry Command"
http://en.wikipedia.org/wiki/SCSI_Inquiry_Command

Maybe if you want to implement a CDROM look-alike device for Windows, you should download a copy of the IDE/ATAPI specs, looks at CDROM *MANDATORY* commands, decide which of those are used by looking at some Windows DDK driver source examples, and perhaps invest in a software or hardware USB bus analyzer. It always helps to understand how the device you want to emulate actually works, and how the subsystem you attach it to uses it. Try T10.ORG

Off the top of my head, you'd at least need to look at

TEST UNIT READY
REQUEST SENSE
INQUIRY
MODE SENSE
MODE SELECT
READ CAPACITY
READ TOC
READ (6/10/12)
hennesa
Posts: 8
Joined: Tue Feb 15, 2011 10:17 am

Re: Forcing USB mass storage device to look like CDROM

Thu Feb 17, 2011 10:03 am

thank you for your valuable information.

I'll try to implement those commands and feed you back asap :)
hennesa
Posts: 8
Joined: Tue Feb 15, 2011 10:17 am

Re: Forcing USB mass storage device to look like CDROM

Mon Feb 21, 2011 12:52 pm

Forcing the SCSI Inquiry command to return a device type of 5 just made the trick ;)

know after being viewed as CDROM windows sends some commands which I am trying to handle right know.

The un-handled commands are:

0x23, 0x1A, 0x46, 0x4A, 0x1E, 0x43, 0x5A, 0x42.

and of course the eject command 0x1B.

Thanks for the help
Tsuneo
Posts: 6
Joined: Wed Sep 24, 2014 11:23 am

Re: Forcing USB mass storage device to look like CDROM

Wed Sep 24, 2014 2:03 pm

I know this thread is an old one,
but as this question (USB CD-ROM emulation) has occasionally (once every year?) poped up in MCU communities,
and I don't yet see any elaborate answer, which leads to smooth implementation.
So, I try it here.


The required protocol (ie. SCSI spec) of CD-ROM over USB Mass-Storage Class is described in this chapter of SCSI MMC-6 (mmc6r02g.pdf)
5.4.4 CD-ROM Profile (0008h)
  • Table 207 — Mandatory Features for CD-ROM
    0000h Profile List A list of all Profiles supported by the device
    0001h Core Basic Functionality
    0002h Morphing The device changes its operational behavior due to external events
    0003h Removable Medium The medium may be removed from the device
    0010h Random Readable, PP=1 Read ability for storage devices with random addressing.
    001Eh CD Read The ability to read CD specific structures
    0100h Power Management Host and device directed power management
    0105h Timeout Ability to respond to all commands within a specific time
Above features require these SCSI commands

00h* TEST UNIT READY
03h* REQUEST SENSE
12h* INQUIRY
1Bh* START STOP UNIT
1Eh* PREVENT ALLOW MEDIUM REMOVAL
25h* READ CAPACITY
28h* READ (10)
43h* READ TOC/PMA/ATIP
46h* GET CONFIGURATION
4Ah* GET EVENT STATUS NOTIFICATION
55h MODE SELECT (10)
5Ah MODE SENSE (10)
BDh MECHANISM STATUS
B9h READ CD MSF
BEh READ CD

For the usual usage of CD-ROM on major OS (Windows, Linux, MacOSX), implementation of commnads with (*) are enough (by my experience)
- If you would like to see complete implementation, ask it here, though READ CD implementation requires additional 20Kbytes code space for EDC/ECC tables ;-)

Here, I show you a working example
AT91SAM7EX256_USB_CDROM.zip
Emulation of USB CD-ROM drive on AT91SAM7X
(48.48 KiB) Downloaded 189 times
- Based upon Keil MDK-ARM v4 example
\Keil\ARM\Boards\Atmel\AT91SAM7X-EK\USB\Memory

- Ported to Olimex SAM7-EX256

- Tested on Windows7 (x64/x32), MacOSX 10.9.4, Ubuntu 14.04.1 LTS

This example emulates USB CD-ROM on AT91SAM7X
which has single ReadMe.txt file.


a) Customization
To make up your own CD-ROM on this firmware,
1) Using ISO Workshop, drop in your files into an ISO image.
http://www.glorylogic.com/iso-workshop/
- Applying ISO9660 Level1 option

2) Convert the .iso image file into C code file, using SRecord
http://srecord.sourceforge.net

> srec_cat DiskImg.iso -binary -o DiskImg.c -C-Array

3) Replace DiskImg.c of this example with yours.
- touch MSC_ImageSize value in memory.h, so that it holds the size of your .iso image


b) Porting to other target
To port this example to your target MCU,
0) Start with a USB Mass-Storage example of your target.
- Identify the file in the example, which implements process of SCSI commands

1) Referring to mscuser.c in above example, modify/add SCSI command process in your target.
A brief explanation of modifications,

- INQUIRY
Change the first byte (PDT:Peripheral Device Type) of INQUIRY response from 0x00 (Direct-Access device) to 0x05 (CD/DVD)

- READ CAPACITY
LBA: (your ISO image size)/2048 - 1
sector size: 2048

- READ (10)
Return the part of your ISO image (on code FLASH or other medium), starting with the specified sector and size by this command.

- READ TOC/PMA/ATIP
- GET CONFIGURATION
- GET EVENT STATUS NOTIFICATION
The process of these routines return a fixed response (data block), specified by their parameter.
Drag in the routines (MSC_ReadTOC(), MSC_GetConfiguration() and MSC_GetEventStatusNotification()) in mscuser.c, with related arrays, to your target. And modify the routines, so that they refer to the right parameter on the CB (Command Block), and so that they return the specified data block.


c) Suggestions for improvement
- The first 16 sectors of ISO image are reserved one, always filled with 0. You may easily generate these sectors on RAM at READ(10) process, without holding these sectors on your media. This idea saves 32 KBytes of your media.
- Also, the follwing four sectors (Primary Volume Descriptor, Volume Descriptor Set Terminator, Path Table (Type L) and Path Table (Type M)) have just a couple of "effective" bytes on each sector. You may suppress these sectors, too.


[Related discussions]
http://www.keil.com/forum/21411/rl-arm- ... nd-cd-rom/
http://www.keil.com/forum/58452/usb-msc ... -subclass/

Tsuneo

Return to “SAM3 Cortex-M3 MCU”

Who is online

Users browsing this forum: No registered users and 2 guests