FS#2475 - better USB mode handling if MMC plugged at startup

Attached to Project: Rockbox
Opened by Jörg Hohensohn (hohensoh) - Friday, 18 March 2005, 22:23 GMT
Last edited by Jens Arnold (amiconn) - Tuesday, 17 May 2005, 23:35 GMT
Task Type Patches
Status Closed
Assigned To Jens Arnold (amiconn)
Operating System
Severity Low
Priority Normal
Reported Version Unstable (example)
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 0
Private No


This patch avoids the prompt for MMC removal if plugged
right at the start. USB mode is handled before the
mounting, which else causes the first MMC access.

I have some issues with it, sometimes it gets confused
after leaving USB mode. Like, duplicating the MMC
content into the root (confusing cards, perhaps), or not
showing any content. Very strange, perhaps uncovering
an older bug.
This task depends upon

Closed by  Jens Arnold (amiconn)
Tuesday, 17 May 2005, 23:35 GMT
Reason for closing:  Accepted
Comment by Jens Arnold (amiconn) - Saturday, 30 April 2005, 08:02 GMT

I tried the patch on my Ondio SP and didn't have any issues
with it (this was after the MMC driver got updated to handle
blocksizes != 512 byte).

I fixed the marked issues in main.c (glitch protection,
timeout), and also some others.

@Jörg: Please test the new patch.
Comment by Jens Arnold (amiconn) - Saturday, 30 April 2005, 10:20 GMT

The 'break' was unnecessary, it only increased code size.
Comment by Jens Arnold (amiconn) - Tuesday, 03 May 2005, 00:54 GMT

Some research remarks:

(1) I updated the patch again, using a better place for
setting the 'MMC touched' flag.

I do have another idea for determining the state on boot.
Instead of simply 'guessing' (!coldstart meaning MMC was
probably touched, which is incorrect when booting a
non-flashed box, or left-booting), we can actually probe the
card without switching it. This is possible because the card
only switches to SPI mode when it receives a CMD0 and /CS is
low. So if we send another command instead (e.g. CMD1), the
card won't switch to SPI mode just because of that. If we
receive an answer, it already is in SPI mode, otherwise it's

(2) I also observed the described behaviour (MMC contents
both as root volume and under /<MMC1>) now, but it seems
this is unrelated o the early USB handling. I found a way to
quite reliably reproduce it:

a) Ondio switched off, MMC in slot, but standing out ~8 mm
so it doesn't get detected

b) Switch on the Ondio, and after approx. one second
(rockbox logo still displayed), push in the card. => message
"No .rockbox directory...", and 2x card contents

This looks like a mount race to me. Both the main mount and
the MMC thread try to mount at the same time...

Awaiting comments....
Comment by Jens Arnold (amiconn) - Monday, 16 May 2005, 17:07 GMT

Patch updated to current cvs.

- Removed the extra USB check and the start of dirbrowse()
as it is no longer necessary with early USB detection and
may even cause deadlocks (there's a bug report)
- Try to detect correct MMC state when in doubt as described
- Small fix for player (no double height)

Awaiting comments/ test results, not only from Ondio owners...