2012-06-23 20:08:56 +02:00
|
|
|
#include "diskio.h"
|
|
|
|
#include "string.h"
|
|
|
|
#include "memory.h"
|
|
|
|
|
|
|
|
extern u32 IsInit;
|
|
|
|
|
|
|
|
DSTATUS disk_initialize( BYTE drv )
|
|
|
|
{
|
2012-06-24 00:07:03 +02:00
|
|
|
s32 r, s_cnt;
|
|
|
|
u32 s_size;
|
|
|
|
|
|
|
|
while( 1 )
|
|
|
|
{
|
|
|
|
udelay( 50000 );
|
2012-06-23 20:08:56 +02:00
|
|
|
|
2012-06-24 00:07:03 +02:00
|
|
|
tiny_ehci_init();
|
2012-06-23 20:08:56 +02:00
|
|
|
|
2012-06-24 00:07:03 +02:00
|
|
|
int ret = -ENODEV;
|
2012-06-23 20:08:56 +02:00
|
|
|
|
2012-06-24 00:07:03 +02:00
|
|
|
do {
|
2012-06-23 20:08:56 +02:00
|
|
|
|
2012-06-24 00:07:03 +02:00
|
|
|
udelay( 4000 );
|
|
|
|
ret = ehci_discover();
|
2012-06-23 20:08:56 +02:00
|
|
|
|
2012-06-24 00:07:03 +02:00
|
|
|
} while( ret == -ENODEV );
|
2012-06-23 20:08:56 +02:00
|
|
|
|
2012-06-24 00:07:03 +02:00
|
|
|
dbgprintf("ehci_discover():%d\n", ret );
|
2012-06-23 20:08:56 +02:00
|
|
|
|
2012-06-24 00:07:03 +02:00
|
|
|
r = USBStorage_Init();
|
2012-06-23 20:08:56 +02:00
|
|
|
|
2012-06-24 00:07:03 +02:00
|
|
|
if( r == 0 )
|
|
|
|
break;
|
|
|
|
}
|
2012-06-23 20:08:56 +02:00
|
|
|
|
2012-06-24 00:07:03 +02:00
|
|
|
s_cnt = USBStorage_Get_Capacity( &s_size );
|
|
|
|
|
2012-06-23 20:08:56 +02:00
|
|
|
dbgprintf( "DIP: Drive size: %dMB SectorSize:%d\n", s_cnt / 1024 * s_size / 1024, s_size);
|
|
|
|
|
|
|
|
return r;
|
2012-06-24 00:07:03 +02:00
|
|
|
|
2012-06-23 20:08:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DSTATUS disk_status( BYTE drv )
|
|
|
|
{
|
|
|
|
(void)drv;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
DRESULT disk_read( BYTE drv, BYTE *buff, DWORD sector, BYTE count )
|
|
|
|
{
|
|
|
|
u8 *buffer = (u8*)buff;
|
|
|
|
//dbgprintf("disk_read( %d, %d, %p, %p)\n", sector, count, buff, buffer );
|
|
|
|
|
|
|
|
if( (u32)buff & 0xF0000000 )
|
|
|
|
{
|
|
|
|
buffer = (u8*)0x1000;
|
|
|
|
u32 i=0;
|
|
|
|
u32 Blocks = 3;
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
if( (count-i) < Blocks )
|
|
|
|
Blocks = (count-i);
|
|
|
|
|
|
|
|
USBStorage_Read_Sectors( sector + i, Blocks, buffer );
|
|
|
|
memcpy( buff + i * 512, buffer, Blocks * 512 );
|
|
|
|
|
|
|
|
i+=Blocks;
|
|
|
|
|
|
|
|
if( i >= count )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
USBStorage_Read_Sectors( sector, count, buffer );
|
|
|
|
dc_flushrange( buffer, count*512 );
|
|
|
|
ahb_flush_from( AHB_SDHC );
|
|
|
|
}
|
|
|
|
|
|
|
|
return RES_OK;
|
|
|
|
}
|
|
|
|
// Write Sector(s)
|
|
|
|
DRESULT disk_write( BYTE drv, const BYTE *buff, DWORD sector, BYTE count )
|
|
|
|
{
|
|
|
|
u8 *buffer = (u8*)buff;
|
|
|
|
|
|
|
|
if( (u32)buff & 0xF0000000 )
|
|
|
|
{
|
|
|
|
buffer = (u8*)0x1000;
|
|
|
|
u32 i;
|
|
|
|
for( i=0; i < count; ++i )
|
|
|
|
{
|
|
|
|
memcpy( buffer, (void*)buff + i * 512, 512 );
|
|
|
|
USBStorage_Write_Sectors( sector + i, 1, buffer );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
|
|
|
|
ahb_flush_to( AHB_SDHC );
|
|
|
|
USBStorage_Write_Sectors( sector, count, buffer );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return RES_OK;
|
|
|
|
}
|