This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RL-ARM mass storage sample and CD-ROM

Hi my friends!

I've used RL-ARM mass storage code from sample codes of KEIL 4.03 on AT91SAM7S256.
when I attach it to PC , the system recognizes it as a flash disk, correctly;

now I want to change it to apear as a CD-ROM in windows.

I want to know any changes in code.

can anyone help me?

thanks for your help!

Parents
  • Hi my friend again!

    I thought that monitoring device with a application like device monitoring studio can help us, so the result is :

    command level

    START

    000027: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:16.282 +0.0
    Opcode:  0x12
    
    Name: INQUIRY
    Enable Vital Product Data: FALSE
    Command Support Data: FALSE
    Page or OPCODE: 0x0
    Allocation Length: 0x24
    Control: 0x0
    000030: Expected Data Received (UP), 09.09.2012 15:46:16.286 +0.002
    Size: 0x24
    
    
    000032: Command Status Wrapper (UP), 09.09.2012 15:46:16.288 +0.002
    
    
    000033: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:16.288 +0.0
    Opcode:  0x12
    
    Name: INQUIRY
    Enable Vital Product Data: FALSE
    Command Support Data: FALSE
    Page or OPCODE: 0x0
    Allocation Length: 0x24
    Control: 0x0
    000036: Expected Data Received (UP), 09.09.2012 15:46:16.292 +0.002
    Size: 0x24
    
    
    000038: Command Status Wrapper (UP), 09.09.2012 15:46:16.294 +0.002
    
    
    000039: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:16.294 +0.0
    Opcode:  0x12
    
    Name: INQUIRY
    Enable Vital Product Data: TRUE
    Command Support Data: FALSE
    Page or OPCODE: 0x80
    Allocation Length: 0xff
    Control: 0x0
    000042: Expected Data Received (UP), 09.09.2012 15:46:16.298 +0.002
    Size: 0x24
    
    
    000044: Command Status Wrapper (UP), 09.09.2012 15:46:16.299 +0.001
    
    
    000047: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:16.303 +0.004
    Opcode:  0x12
    
    Name: INQUIRY
    Enable Vital Product Data: FALSE
    Command Support Data: FALSE
    Page or OPCODE: 0x0
    Allocation Length: 0x24
    Control: 0x0
    000050: Expected Data Received (UP), 09.09.2012 15:46:16.306 +0.002
    Size: 0x24
    
    
    000052: Command Status Wrapper (UP), 09.09.2012 15:46:16.308 +0.002
    
    
    000053: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:16.308 +0.0
    Opcode:  0x12
    
    Name: INQUIRY
    Enable Vital Product Data: FALSE
    Command Support Data: FALSE
    Page or OPCODE: 0x0
    Allocation Length: 0x25
    Control: 0x0
    000056: Expected Data Received (UP), 09.09.2012 15:46:16.312 +0.002
    Size: 0x24
    
    
    000058: Command Status Wrapper (UP), 09.09.2012 15:46:16.313 +0.001
    
    
    000059: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:16.313 +0.0
    Opcode:  0x12
    
    Name: INQUIRY
    Enable Vital Product Data: FALSE
    Command Support Data: FALSE
    Page or OPCODE: 0x0
    Allocation Length: 0x24
    Control: 0x0
    000062: Expected Data Received (UP), 09.09.2012 15:46:16.317 +0.002
    Size: 0x24
    
    
    000064: Command Status Wrapper (UP), 09.09.2012 15:46:16.319 +0.002
    
    
    000065: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:16.320 +0.001
    Opcode:  0x4a
    
    Name: GET EVENT/STATUS
    IMMED: TRUE
    Notification Class Request:0x0
    Allocation Length:0x8
    Control: 0x0
    
    
    000069: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:16.476 +0.153
    Opcode:  0x46
    
    Name: GET CONFIGURATION (MMC)
    Request Type: LU shall return Feature Header and all Feature Descriptors
    Starting Feature Number:0x0
    Allocation Length:0x8
    Control: 0x0
    
    
    000073: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:16.633 +0.153
    Opcode:  0x46
    
    Name: GET CONFIGURATION (MMC)
    Request Type: LU shall return Feature Header and all Feature Descriptors
    Starting Feature Number:0x0
    Allocation Length:0x8
    Control: 0x0
    
    
    000077: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:16.790 +0.153
    Opcode:  0x46
    
    Name: GET CONFIGURATION (MMC)
    Request Type: LU shall return Feature Header and all Feature Descriptors
    Starting Feature Number:0x0
    Allocation Length:0x8
    Control: 0x0
    
    
    000081: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:16.947 +0.153
    Opcode:  0x46
    
    Name: GET CONFIGURATION (MMC)
    Request Type: LU shall return Feature Header and all Feature Descriptors
    Starting Feature Number:0x0
    Allocation Length:0x8
    Control: 0x0
    
    
    000085: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:17.104 +0.153
    Opcode:  0x46
    
    Name: GET CONFIGURATION (MMC)
    Request Type: LU shall return Feature Header and all Feature Descriptors
    Starting Feature Number:0x0
    Allocation Length:0x8
    Control: 0x0
    
    
    000089: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:17.261 +0.153
    Opcode:  0x46
    
    Name: GET CONFIGURATION (MMC)
    Request Type: LU shall return Feature Header and all Feature Descriptors
    Starting Feature Number:0x0
    Allocation Length:0x8
    Control: 0x0
    
    
    000093: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:17.418 +0.153
    Opcode:  0x25
    
    Name: READ CAPACITY (MMC)
    Logical Block Address:0x0
    Control: 0x0
    
    
    
    
    000097: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:17.575 +0.153
    Opcode:  0x25
    
    Name: READ CAPACITY (MMC)
    Logical Block Address:0x0
    Control: 0x0
    
    
    
    
    000101: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:17.732 +0.153
    Opcode:  0x25
    
    Name: READ CAPACITY (MMC)
    Logical Block Address:0x0
    Control: 0x0
    
    
    
    
    000105: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:17.889 +0.153
    
    Name: TEST UNIT READY
    Control: 0x0
    
    
    
    000108: Command Status Wrapper (UP), 09.09.2012 15:46:17.893 +0.002
    
    
    000109: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:18.046 +0.153
    
    Name: TEST UNIT READY
    Control: 0x0
    
    
    
    000112: Command Status Wrapper (UP), 09.09.2012 15:46:18.050 +0.002
    
    
    000113: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:18.050 +0.0
    
    Name: TEST UNIT READY
    Control: 0x0
    
    
    
    000116: Command Status Wrapper (UP), 09.09.2012 15:46:18.054 +0.002
    
    
    000117: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:18.054 +0.0
    
    Name: TEST UNIT READY
    Control: 0x0
    
    
    
    000120: Command Status Wrapper (UP), 09.09.2012 15:46:18.058 +0.002
    
    
    000121: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:18.058 +0.0
    Opcode:  0x43
    
    Name: READ TOC/PMA/ATIP (MMC)
    MSF: TRUE
    SUBQ: FALSE
    Track Number: 0x0
    Allocation Length:0x324
    Control: 0x0
    


    END
    After this command , no other command transferred.
    I will post mass storage level in next post.

    Thank you for your help!

Reply
  • Hi my friend again!

    I thought that monitoring device with a application like device monitoring studio can help us, so the result is :

    command level

    START

    000027: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:16.282 +0.0
    Opcode:  0x12
    
    Name: INQUIRY
    Enable Vital Product Data: FALSE
    Command Support Data: FALSE
    Page or OPCODE: 0x0
    Allocation Length: 0x24
    Control: 0x0
    000030: Expected Data Received (UP), 09.09.2012 15:46:16.286 +0.002
    Size: 0x24
    
    
    000032: Command Status Wrapper (UP), 09.09.2012 15:46:16.288 +0.002
    
    
    000033: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:16.288 +0.0
    Opcode:  0x12
    
    Name: INQUIRY
    Enable Vital Product Data: FALSE
    Command Support Data: FALSE
    Page or OPCODE: 0x0
    Allocation Length: 0x24
    Control: 0x0
    000036: Expected Data Received (UP), 09.09.2012 15:46:16.292 +0.002
    Size: 0x24
    
    
    000038: Command Status Wrapper (UP), 09.09.2012 15:46:16.294 +0.002
    
    
    000039: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:16.294 +0.0
    Opcode:  0x12
    
    Name: INQUIRY
    Enable Vital Product Data: TRUE
    Command Support Data: FALSE
    Page or OPCODE: 0x80
    Allocation Length: 0xff
    Control: 0x0
    000042: Expected Data Received (UP), 09.09.2012 15:46:16.298 +0.002
    Size: 0x24
    
    
    000044: Command Status Wrapper (UP), 09.09.2012 15:46:16.299 +0.001
    
    
    000047: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:16.303 +0.004
    Opcode:  0x12
    
    Name: INQUIRY
    Enable Vital Product Data: FALSE
    Command Support Data: FALSE
    Page or OPCODE: 0x0
    Allocation Length: 0x24
    Control: 0x0
    000050: Expected Data Received (UP), 09.09.2012 15:46:16.306 +0.002
    Size: 0x24
    
    
    000052: Command Status Wrapper (UP), 09.09.2012 15:46:16.308 +0.002
    
    
    000053: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:16.308 +0.0
    Opcode:  0x12
    
    Name: INQUIRY
    Enable Vital Product Data: FALSE
    Command Support Data: FALSE
    Page or OPCODE: 0x0
    Allocation Length: 0x25
    Control: 0x0
    000056: Expected Data Received (UP), 09.09.2012 15:46:16.312 +0.002
    Size: 0x24
    
    
    000058: Command Status Wrapper (UP), 09.09.2012 15:46:16.313 +0.001
    
    
    000059: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:16.313 +0.0
    Opcode:  0x12
    
    Name: INQUIRY
    Enable Vital Product Data: FALSE
    Command Support Data: FALSE
    Page or OPCODE: 0x0
    Allocation Length: 0x24
    Control: 0x0
    000062: Expected Data Received (UP), 09.09.2012 15:46:16.317 +0.002
    Size: 0x24
    
    
    000064: Command Status Wrapper (UP), 09.09.2012 15:46:16.319 +0.002
    
    
    000065: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:16.320 +0.001
    Opcode:  0x4a
    
    Name: GET EVENT/STATUS
    IMMED: TRUE
    Notification Class Request:0x0
    Allocation Length:0x8
    Control: 0x0
    
    
    000069: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:16.476 +0.153
    Opcode:  0x46
    
    Name: GET CONFIGURATION (MMC)
    Request Type: LU shall return Feature Header and all Feature Descriptors
    Starting Feature Number:0x0
    Allocation Length:0x8
    Control: 0x0
    
    
    000073: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:16.633 +0.153
    Opcode:  0x46
    
    Name: GET CONFIGURATION (MMC)
    Request Type: LU shall return Feature Header and all Feature Descriptors
    Starting Feature Number:0x0
    Allocation Length:0x8
    Control: 0x0
    
    
    000077: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:16.790 +0.153
    Opcode:  0x46
    
    Name: GET CONFIGURATION (MMC)
    Request Type: LU shall return Feature Header and all Feature Descriptors
    Starting Feature Number:0x0
    Allocation Length:0x8
    Control: 0x0
    
    
    000081: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:16.947 +0.153
    Opcode:  0x46
    
    Name: GET CONFIGURATION (MMC)
    Request Type: LU shall return Feature Header and all Feature Descriptors
    Starting Feature Number:0x0
    Allocation Length:0x8
    Control: 0x0
    
    
    000085: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:17.104 +0.153
    Opcode:  0x46
    
    Name: GET CONFIGURATION (MMC)
    Request Type: LU shall return Feature Header and all Feature Descriptors
    Starting Feature Number:0x0
    Allocation Length:0x8
    Control: 0x0
    
    
    000089: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:17.261 +0.153
    Opcode:  0x46
    
    Name: GET CONFIGURATION (MMC)
    Request Type: LU shall return Feature Header and all Feature Descriptors
    Starting Feature Number:0x0
    Allocation Length:0x8
    Control: 0x0
    
    
    000093: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:17.418 +0.153
    Opcode:  0x25
    
    Name: READ CAPACITY (MMC)
    Logical Block Address:0x0
    Control: 0x0
    
    
    
    
    000097: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:17.575 +0.153
    Opcode:  0x25
    
    Name: READ CAPACITY (MMC)
    Logical Block Address:0x0
    Control: 0x0
    
    
    
    
    000101: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:17.732 +0.153
    Opcode:  0x25
    
    Name: READ CAPACITY (MMC)
    Logical Block Address:0x0
    Control: 0x0
    
    
    
    
    000105: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:17.889 +0.153
    
    Name: TEST UNIT READY
    Control: 0x0
    
    
    
    000108: Command Status Wrapper (UP), 09.09.2012 15:46:17.893 +0.002
    
    
    000109: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:18.046 +0.153
    
    Name: TEST UNIT READY
    Control: 0x0
    
    
    
    000112: Command Status Wrapper (UP), 09.09.2012 15:46:18.050 +0.002
    
    
    000113: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:18.050 +0.0
    
    Name: TEST UNIT READY
    Control: 0x0
    
    
    
    000116: Command Status Wrapper (UP), 09.09.2012 15:46:18.054 +0.002
    
    
    000117: SCSI Primary Command Set 2 (DOWN), 09.09.2012 15:46:18.054 +0.0
    
    Name: TEST UNIT READY
    Control: 0x0
    
    
    
    000120: Command Status Wrapper (UP), 09.09.2012 15:46:18.058 +0.002
    
    
    000121: SFF-8020i, MMC2 (ATAPI) command set (DOWN), 09.09.2012 15:46:18.058 +0.0
    Opcode:  0x43
    
    Name: READ TOC/PMA/ATIP (MMC)
    MSF: TRUE
    SUBQ: FALSE
    Track Number: 0x0
    Allocation Length:0x324
    Control: 0x0
    


    END
    After this command , no other command transferred.
    I will post mass storage level in next post.

    Thank you for your help!

Children
  • > I think that there are some wrong parameter that are sent in previous commands before MSC-ReadTOC that make the wrong received command from pc in this point.

    Windows put both of READ_TOC(MSF:0) and READ_TOC(MSF:1)
    In above implementation, just READ_TOC(MSF:0) is supported.
    To support both, MSC_ReadTOC() changes as follows,

    const BYTE SCSI_TOC_MSF0[] = {
           // TOC response header
      0x00, 0x0A,             // Data Length
      0x01,                   // First Track
      0x01,                   // Last Track
            // track descriptor
      0x00,                   // Reserved
      0x14,                   // ADR/CONTROL
      0x01,                   // Track Number
      0x00,                   // Reserved
      0x00, 0x00, 0x00, 0x00  // Track Start Address
    };
    
    const BYTE SCSI_TOC_MSF1[] = {
           // TOC response header
      0x00, 0x12,             // Data Length
      0x01,                   // First Track
      0x01,                   // Last Track
           // track descriptor 1
      0x00,                   // Reserved
      0x14,                   // ADR/CONTROL
      0x01,                   // Track Number
      0x00,                   // Reserved
      0x00, 0x00, 0x02, 0x00, // start address in MSF format (fixed)
           // track descriptor 2
      0x00,                   // Reserved
      0x14,                   // ADR/CONTROL
      0xAA,                   // Track Number: Lead-out area
      0x00,                   // Reserved
      0x00, 0x39, 0x06, 0x06  // Lead-out start address in MSF format
                              // (variable, depending on the size of track 1)
    };
    
    void MSC_ReadTOC (void) {
      if (  ((CBW.CB[1] & 0x02) == 0)     // MSF field
         && ((CBW.CB[2] & 0x0F) == 0)     // Format field
         )
      {
        memcpy( BulkBuf, SCSI_TOC_MSF0, sizeof(SCSI_TOC_MSF0) );
        BulkLen = sizeof(SCSI_TOC_MSF0);
        DataInTransfer();
      }
    
      if (  ((CBW.CB[1] & 0x02) == 1)     // MSF field
         && ((CBW.CB[2] & 0x0F) == 0)     // Format field
         )
      {
        memcpy( BulkBuf, SCSI_TOC_MSF1, sizeof(SCSI_TOC_MSF1) );
        BulkLen = sizeof(SCSI_TOC_MSF1);
        DataInTransfer();
      }
    }
    

    Tsuneo

  • > Now we change the code to CD-ROM state , must we see it in cd-rom as before or cd-rom can't show it because of CD IMAGE concepts or other reason?

    KEIL original example gives disk image in DiskImage[] ROM array (DiskImg.c).
    This disk image consists of FAT file system
    - MBR (Master Boot Record)
    - Boot sector
    - FAT
    - Root directory
    - File sectors

    For CD implementation, you have to replace the contents of the disk image into CD one, which is formatted following to ISO9660 (ECMA-119) spec (see my first post). You may easily make it using a CD-R writer utility, which has a function to make ISO9660 image file.

    At the entry of main() (memory.c), the contents of DiskImage[] is copied to Memory[] RAM array. READ10 and WRITE10 access to Memory[] array. For read-only CD, READ10 may directly access to DiskImage[] ROM array, instead of the RAM array.

    Tsuneo

  • Hi my friend Tsuneo!

    I do what you post for me but , that didn't work .
    I changed what you said and I made an iso file and fetch the byte stream of it and changed the code according that (disk Image , size , . . . ) , but when I attach device to computer , my computer (explorer) goes to a wait sate and can't work with the device.

    thank my friend!

  • Hi Mr Chinzei.

    Me and my friend Meysam were working around your solution to make our USB Mass storage device a CD-ROM.

    BUt As we started the work, lots of problems poped out.

    we changed the PDT and Sector size as you guided. We also implemented the following commands as you said: * Read12 * Write12 * Start/Stop unit * Read TOC

    Then we loaded an image of a sample CD into device memory.

    But it seams we can't get it to work, So I think we have to check it out with the standard specifications.

    We searced for some guides or references about this matter and this is what we found:

    SCSI Multimedia commands from T10.org.

    What i see in here is 6 different versions of MMC commands. I looked in MMC-4 and there's alot of commands for CD-ROM devices in it which I can't get why and how you only choosed a subset of these commands for us to implement.

    I am wondering now, whether you know an implementation guidance or a book in which the essential steps for making a CD-ROM device is explained or you use the T10 references too.

    Do you know any useful book or guide for my problem?

  • We could get our CD-ROM to work!

    I post the modifications we made to your soluton in order to help others who might read this thread later.

    First:
    I changed the Read TOC function so that it respond to all other read TOC formats too.
    It is a shame! but I responded all Formats with the same data, Like another USB CD-ROM I was monitoring its commands.

    well, my analisys is that we had to make a proper response to any Read TOC which this code do not.

    Also the '1' at second if is a logical error.

    void MSC_ReadTOC (void) {
      if (  ((CBW.CB[1] & 0x02) == 0)     // MSF field
         && ((CBW.CB[2] & 0x0F) == 0)     // Format field
         )
      {
        memcpy( BulkBuf, SCSI_TOC_MSF0, sizeof(SCSI_TOC_MSF0) );
        BulkLen = sizeof(SCSI_TOC_MSF0);
        DataInTransfer();
      }
    
      if (  ((CBW.CB[1] & 0x02) == 1)     // MSF field <-----===== Change '1' to '2'
         && ((CBW.CB[2] & 0x0F) == 0)     // Format field
         )
      {
        memcpy( BulkBuf, SCSI_TOC_MSF1, sizeof(SCSI_TOC_MSF1) );
        BulkLen = sizeof(SCSI_TOC_MSF1);
        DataInTransfer();
      }
    
    //<-----===== Put the code to handle other formats here, even if you going to fail it(i did not test the fail myself)
    
    }
    

    After this the CD can be succecfully recognized in windows, but it has two halts(1 min each).
    These halts happen after failing "Read Disc Information" and "Get Configuration Commands" which was removed after implementing these commads based on MMC commands reffrence from T10.org