Index: firmware/target/arm/as3525/ata_sd_as3525.c
===================================================================
--- firmware/target/arm/as3525/ata_sd_as3525.c	(Revision 19773)
+++ firmware/target/arm/as3525/ata_sd_as3525.c	(Arbeitskopie)
@@ -110,7 +110,7 @@
 #endif

 static struct wakeup transfer_completion_signal;
-bool retry;
+static volatile bool retry;

 static inline void mci_delay(void) { int i = 0xffff; while(i--) ; }

@@ -383,9 +383,10 @@
             {
                 sd_enable(true);
                 init_pl180_controller(SD_SLOT_AS3525);
-                disk_mount(1);
+                sd_init_card(SD_SLOT_AS3525);
+                disk_mount(SD_SLOT_AS3525);
             }
-
+            
             queue_broadcast(SYS_FS_CHANGED, 0);

             /* Access is now safe */
@@ -427,6 +428,11 @@

 static void init_pl180_controller(const int drive)
 {
+#ifdef HAVE_MULTIVOLUME
+    if (drive == SD_SLOT_AS3525)
+    {
+    }
+#endif
     MCI_COMMAND(drive) = MCI_DATA_CTRL(drive) = 0;
     MCI_CLEAR(drive) = 0x7ff;

@@ -445,6 +451,7 @@
     GPIOA_IS &= ~(1<<2);
     /* detect both raising and falling edges */
     GPIOA_IBE |= (1<<2);
+
 #endif

 #else
@@ -470,37 +477,19 @@
 int sd_init(void)
 {
     int ret;
-
-    CGU_IDE =   (1<<7)  /* AHB interface enable */  |
-                (1<<6)  /* interface enable */      |
-                ((CLK_DIV(AS3525_PLLA_FREQ, AS3525_IDE_FREQ) - 1) << 2) |
+    sd_enable(true);
+    CGU_IDE |= ((CLK_DIV(AS3525_PLLA_FREQ, AS3525_IDE_FREQ) - 1) << 2) |
                 1       /* clock source = PLLA */;

-    CGU_PERI |= CGU_NAF_CLOCK_ENABLE;
-#ifdef HAVE_MULTIVOLUME
-    CGU_PERI |= CGU_MCI_CLOCK_ENABLE;
-#endif
-
     wakeup_init(&transfer_completion_signal);

     init_pl180_controller(INTERNAL_AS3525);
+    init_pl180_controller(SD_SLOT_AS3525);
     ret = sd_init_card(INTERNAL_AS3525);
     if(ret < 0)
         return ret;

-#ifdef HAVE_MULTIVOLUME
-    CCU_IO &= ~8;           /* bits 3:2 = 01, xpd is SD interface */
-    CCU_IO |= 4;
-
-    init_pl180_controller(SD_SLOT_AS3525);
-    sd_init_card(SD_SLOT_AS3525);
-#endif
     /* init mutex */
-
-#ifndef BOOTLOADER
-    sd_enable(false);
-#endif
-
     mutex_init(&sd_mtx);

     queue_init(&sd_queue, true);
@@ -603,10 +592,10 @@

     if (card_info[drive].initialized <= 0)
     {
-        sd_init_card(drive);
+        ret = sd_init_card(drive);
         if (!(card_info[drive].initialized))
         {
-            panicf("card not initialised");
+            panicf("card not initialised (%d)", ret);
             goto sd_transfer_error;
         }
     }
@@ -623,6 +612,8 @@

     while(count)
     {
+        /* Interrupt handler might set this to true during transfer */
+        retry = false;
         /* 128 * 512 = 2^16, and doesn't fit in the 16 bits of DATA_LENGTH
          * register, so we have to transfer maximum 127 sectors at a time. */
         unsigned int transfer = (count >= 128) ? 127 : count; /* sectors */
@@ -636,10 +627,7 @@
                     MCI_ARG, NULL);

         if (ret < 0)
-        {
-            panicf("transfer multiple blocks failed");
-            goto sd_transfer_error;
-        }
+            panicf("transfer multiple blocks failed (%d)", ret);

         if(write)
             dma_enable_channel(0, buf, MCI_FIFO(drive),
@@ -657,7 +645,7 @@
                                 (1<<3) /* DMA */                        |
                                 (9<<4) /* 2^9 = 512 */ ;

-        retry = false;
+
         wakeup_wait(&transfer_completion_signal, TIMEOUT_BLOCK);
         if(!retry)
         {
@@ -678,26 +666,23 @@
         ret = sd_wait_for_state(drive, SD_TRAN);
         if (ret < 0)
         {
-            panicf(" wait for state TRAN failed");
+            panicf(" wait for state TRAN failed (%d)", ret);
             goto sd_transfer_error;
         }
     }

-    while (1)
-    {
-        dma_release();
+    dma_release();

 #ifndef BOOTLOADER
-        sd_enable(false);
+    sd_enable(false);
 #endif
-        mutex_unlock(&sd_mtx);
+    mutex_unlock(&sd_mtx);
+    return 0;

-        return ret;
-
 sd_transfer_error:
-        panicf("transfer error : %d",ret);
-        card_info[drive].initialized = 0;
-    }
+    panicf("transfer error : %d",ret);
+    card_info[drive].initialized = 0;
+    return ret;
 }

 int sd_read_sectors(IF_MV2(int drive,) unsigned long start, int count,
@@ -748,6 +733,8 @@
         return; /* nothing to do */
     if(on)
     {
+        CCU_IO &= ~(1<<3);           /* bits 3:2 = 01, xpd is SD interface */
+        CCU_IO |= (1<<2);
         CGU_PERI |= CGU_NAF_CLOCK_ENABLE;
 #ifdef HAVE_MULTIVOLUME
         CGU_PERI |= CGU_MCI_CLOCK_ENABLE;
@@ -758,6 +745,7 @@
     }
     else
     {
+        CCU_IO &= ~(1<<2|1<<3);
         CGU_PERI &= ~CGU_NAF_CLOCK_ENABLE;
 #ifdef HAVE_MULTIVOLUME
         CGU_PERI &= ~CGU_MCI_CLOCK_ENABLE;