MMC card with spi-sd-card.c

Gene Smith gds at chartertn.net
Tue Jan 6 04:25:30 UTC 2009


Gene Smith wrote, On 12/24/2008 04:03 AM:
> Sebastian Huber wrote, On 12/23/2008 03:15 AM:
>> Sebastian Huber wrote:
>>> Gene Smith wrote:
>>>> I have been trying to use an MMC with the "spi/sd" drivers in RTEMS. I 
>>>> worked until it tries to send two commands in a loop waiting for idle 
>>>> conditon in an init routine:
>>>>
>>>> rv = sd_card_send_command( e, SD_CARD_CMD_APP_CMD, 0);
>>>> CLEANUP_RVSC( rv, sc, sd_card_driver_init_cleanup, "Send: 
>>>> SD_CARD_CMD_APP_CMD");
>>>> rv = sd_card_send_command( e, SD_CARD_ACMD_SD_SEND_OP_COND, 0);
>>>> CLEANUP_RVSC( rv, sc, sd_card_driver_init_cleanup, "Send: 
>>>> SD_CARD_ACMD_SD_SEND_OP_COND");
>>> These commands set the SD Card into SPI mode.
>> [...]
>>
>> Oh, I guess I misunderstood you.  You want to use a MMC in SPI mode? There are
>> several ways to switch from MMC mode to SPI mode.  This one worked for all
>> cards I worked with.  We may use the alternatives if one approach fails.
>>
> 
> I try to mount using the shell:
> 
> mkdir /mnt
> mount -t mddos /dev/sd-card-a /mnt
> mount: mount failed: Invalid argument

My problem here is I need to mount a partition and not a device. I 
should do:
mount -t msdos /dev/sd-card-a1 /mnt
(the mddos above is a typo).

However, to make a partition on the MMC you have to call
sc = rtems_ide_part_table_initialize(e->disk_device_name);
	CLEANUP_SC( sc, sd_card_driver_init_cleanup, "Initialize IDE partition 
table");

Seem like this should be in spi-sd-card.c in sd-card-init() right after 
the disk is created but before stop since you almost always need a 
partition when creating a disk.

> 
> I see no card errors printed with syslog() and see none stepping with 
> debugger. Blocks are read with no errors detected.
> 
> But error occurs in fat.c when checking the boot record. The bytes per 
> sector does not match any in the list and fails here:
> 
> 381:
>      /* Evaluate boot record */
>      vol->bps = FAT_GET_BR_BYTES_PER_SECTOR(boot_rec);
> 
>      if ( (vol->bps != 512)  &&
>           (vol->bps != 1024) &&
>           (vol->bps != 2048) &&
>           (vol->bps != 4096))
>      {
>          rtems_disk_release(vol->dd);
>          rtems_set_errno_and_return_minus_one( EINVAL );  <---fails here
>      }
> 
> Also, when I try to format it seems to work:
> [/] # msdosfmt -t 16 /dev/sd-card-a
> msdos format: /dev/sd-card-a
> msdos format successful
>

tried msdosfmt -t 16 /dev/sd-card-a1

This still seems to be a no-op. Have not tried to see what is happening 
when I do msdosfmt. It is not documented in the shell manual I think.

> But I still can't mount it and when I take the card out and put it on a 
> "real" system the files are all still there.
> 
> Card was originally fat32 formatted by a camera. Reformated with gparted 
>   to fat16 and have same errors.
> 
> Haven't tried doing the mount with my own code yet like Bob G did. I 
> think shell commands should do the same thing, right?
> 




More information about the users mailing list