PERFORCE change 99448 for review
Warner Losh
imp at FreeBSD.org
Sat Jun 17 19:22:04 UTC 2006
http://perforce.freebsd.org/chv.cgi?CH=99448
Change 99448 by imp at imp_lighthouse on 2006/06/17 19:21:02
checkpoint my attempts to boot off the sd card. I can read up
to address 0x14000 (81920) on the card, then it dies. No clue why
this is happening.
Affected files ...
.. //depot/projects/arm/src/sys/boot/arm/at91/bootsd/main.c#4 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/bootspi/main.c#11 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/bootspi/mci_device.c#3 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/bootspi/mci_device.h#2 edit
.. //depot/projects/arm/src/sys/boot/arm/at91/bootspi/sd-card.c#4 edit
Differences ...
==== //depot/projects/arm/src/sys/boot/arm/at91/bootsd/main.c#4 (text+ko) ====
@@ -76,7 +76,7 @@
unsigned char mac[6] = { 0x42, 0x53, 0x44, 0, 0, 1 };
-#define REAL
+// #define REAL
int
main(void)
{
@@ -103,13 +103,12 @@
SetMACAddress(low_addr, high_addr);
printf("Reading from card...");
#ifdef REAL
- for (i = 0; i < 7; i++)
- {
- MCI_read((char *)0x20000000 + ((i + 1) << 20), i << 20, 1 << 20);
- printf("*");
+ for (i = 0x80; i < 10 * 2048; i++) {
+ MCI_read((char *)0x20000000, i << 9, 1 << 9);
+ printf("*");
}
printf("\r\nStarting...\r\n");
- ((void(*)())(0x20000000 + (1 << 20)))();
+ ((void(*)())(0x20000000))();
#else
MCI_read((char *)0x20000000, 0, 1 << 20);
printf("Found %s\r\n", (char *)0x20000000);
==== //depot/projects/arm/src/sys/boot/arm/at91/bootspi/main.c#11 (text+ko) ====
==== //depot/projects/arm/src/sys/boot/arm/at91/bootspi/mci_device.c#3 (text+ko) ====
@@ -17,6 +17,8 @@
#include "mci_device.h"
+#include "lib.h"
+
//*----------------------------------------------------------------------------
//* \fn AT91F_MCI_SendCommand
//* \brief Generic function to send a command to the MMC or SDCard
@@ -44,10 +46,8 @@
// if the command is SEND_OP_COND the CRC error flag is always present (cf : R3 response)
if ( (Cmd != AT91C_SDCARD_APP_OP_COND_CMD) && (Cmd != AT91C_MMC_SEND_OP_COND_CMD) )
return ((AT91C_BASE_MCI->MCI_SR) & AT91C_MCI_SR_ERROR);
- else {
- if (error != AT91C_MCI_RCRCE)
- return ((AT91C_BASE_MCI->MCI_SR) & AT91C_MCI_SR_ERROR);
- }
+ if (error != AT91C_MCI_RCRCE)
+ return ((AT91C_BASE_MCI->MCI_SR) & AT91C_MCI_SR_ERROR);
}
return AT91C_CMD_SEND_OK;
}
@@ -109,20 +109,18 @@
unsigned int status)
{
// If End of Tx Buffer Empty interrupt occurred
- if ( status & AT91C_MCI_TXBUFE ) {
+ if (pMCI_Device->pMCI_DeviceDesc->state == AT91C_MCI_TX_SINGLE_BLOCK && status & AT91C_MCI_TXBUFE) {
AT91C_BASE_MCI->MCI_IDR = AT91C_MCI_TXBUFE;
AT91C_BASE_PDC_MCI->PDC_PTCR = AT91C_PDC_TXTDIS;
-
pMCI_Device->pMCI_DeviceDesc->state = AT91C_MCI_IDLE;
- } // End of if AT91C_MCI_TXBUFF
-
+ } // End of if AT91C_MCI_TXBUFF
+
// If End of Rx Buffer Full interrupt occurred
- if ( status & AT91C_MCI_RXBUFF ) {
+ if (pMCI_Device->pMCI_DeviceDesc->state == AT91C_MCI_RX_SINGLE_BLOCK && status & AT91C_MCI_RXBUFF) {
AT91C_BASE_MCI->MCI_IDR = AT91C_MCI_RXBUFF;
AT91C_BASE_PDC_MCI->PDC_PTCR = AT91C_PDC_RXTDIS;
pMCI_Device->pMCI_DeviceDesc->state = AT91C_MCI_IDLE;
} // End of if AT91C_MCI_RXBUFF
-
}
//*----------------------------------------------------------------------------
@@ -137,29 +135,42 @@
int sizeToRead)
{
////////////////////////////////////////////////////////////////////////////////////////////
- if (pMCI_Device->pMCI_DeviceDesc->state != AT91C_MCI_IDLE)
- return AT91C_READ_ERROR;
+ if (pMCI_Device->pMCI_DeviceDesc->state != AT91C_MCI_IDLE) {
+ printf("1 state is 0x%x\r\n", pMCI_Device->pMCI_DeviceDesc->state);
+ return AT91C_READ_ERROR;
+ }
+
if ((AT91F_MCI_GetStatus(pMCI_Device,
pMCI_Device->pMCI_DeviceFeatures->Relative_Card_Address) & AT91C_SR_READY_FOR_DATA) !=
- AT91C_SR_READY_FOR_DATA)
- return AT91C_READ_ERROR;
+ AT91C_SR_READY_FOR_DATA) {
+ printf("2\r\n");
+ return AT91C_READ_ERROR;
+ }
- if ( (src + sizeToRead) > pMCI_Device->pMCI_DeviceFeatures->Memory_Capacity )
- return AT91C_READ_ERROR;
+ if ( (src + sizeToRead) > pMCI_Device->pMCI_DeviceFeatures->Memory_Capacity ) {
+ printf("3\r\n");
+ return AT91C_READ_ERROR;
+ }
// If source does not fit a begin of a block
- if ( (src % pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length) != 0 )
- return AT91C_READ_ERROR;
+ if ( (src % pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length) != 0 ) {
+ printf("4\r\n");
+ return AT91C_READ_ERROR;
+ }
// Test if the MMC supports Partial Read Block
// ALWAYS SUPPORTED IN SD Memory Card
if( (sizeToRead < pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length)
- && (pMCI_Device->pMCI_DeviceFeatures->Read_Partial == 0x00) )
- return AT91C_READ_ERROR;
+ && (pMCI_Device->pMCI_DeviceFeatures->Read_Partial == 0x00) ) {
+ printf("5\r\n");
+ return AT91C_READ_ERROR;
+ }
- if( sizeToRead > pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length)
- return AT91C_READ_ERROR;
+ if( sizeToRead > pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length) {
+ printf("6\r\n");
+ return AT91C_READ_ERROR;
+ }
////////////////////////////////////////////////////////////////////////////////////////////
// Init Mode Register
@@ -512,7 +523,7 @@
AT91F_MCI_SendCommand(pMCI_Device, AT91C_GO_IDLE_STATE_CMD, AT91C_NO_ARGUMENT);
- if(AT91F_MCI_SDCard_GetOCR(pMCI_Device) == AT91C_INIT_ERROR)
+ if (AT91F_MCI_SDCard_GetOCR(pMCI_Device) == AT91C_INIT_ERROR)
return AT91C_INIT_ERROR;
if (AT91F_MCI_SDCard_GetCID(pMCI_Device,tab_response) == AT91C_CMD_SEND_OK) {
@@ -530,23 +541,22 @@
pMCI_Device->pMCI_DeviceFeatures->Write_Block_Misalignment = (tab_response[1] >> AT91C_CSD_WR_B_MIS_S) & AT91C_CSD_WR_B_MIS_M;
//// Compute Memory Capacity
- // compute MULT
- mult = 1 << ( ((tab_response[2] >> AT91C_CSD_C_SIZE_M_S) & AT91C_CSD_C_SIZE_M_M) + 2 );
- // compute MSB of C_SIZE
- blocknr = ((tab_response[1] >> AT91C_CSD_CSIZE_H_S) & AT91C_CSD_CSIZE_H_M) << 2;
- // compute MULT * (LSB of C-SIZE + MSB already computed + 1) = BLOCKNR
- blocknr = mult * ( ( blocknr + ( (tab_response[2] >> AT91C_CSD_CSIZE_L_S) & AT91C_CSD_CSIZE_L_M) ) + 1 );
+ // compute MULT
+ mult = 1 << ( ((tab_response[2] >> AT91C_CSD_C_SIZE_M_S) & AT91C_CSD_C_SIZE_M_M) + 2 );
+ // compute MSB of C_SIZE
+ blocknr = ((tab_response[1] >> AT91C_CSD_CSIZE_H_S) & AT91C_CSD_CSIZE_H_M) << 2;
+ // compute MULT * (LSB of C-SIZE + MSB already computed + 1) = BLOCKNR
+ blocknr = mult * ( ( blocknr + ( (tab_response[2] >> AT91C_CSD_CSIZE_L_S) & AT91C_CSD_CSIZE_L_M) ) + 1 );
- pMCI_Device->pMCI_DeviceFeatures->Memory_Capacity = pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length * blocknr;
+ pMCI_Device->pMCI_DeviceFeatures->Memory_Capacity = pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length * blocknr;
//// End of Compute Memory Capacity
- if( AT91F_MCI_SDCard_SetBusWidth(pMCI_Device) == AT91C_CMD_SEND_OK )
- {
+ if (AT91F_MCI_SDCard_SetBusWidth(pMCI_Device) == AT91C_CMD_SEND_OK) {
if (AT91F_MCI_SetBlocklength(pMCI_Device,pMCI_Device->pMCI_DeviceFeatures->Max_Read_DataBlock_Length) == AT91C_CMD_SEND_OK)
- return AT91C_INIT_OK;
+ return AT91C_INIT_OK;
}
}
}
}
- return AT91C_INIT_ERROR;
+ return AT91C_INIT_ERROR;
}
==== //depot/projects/arm/src/sys/boot/arm/at91/bootspi/mci_device.h#2 (text+ko) ====
==== //depot/projects/arm/src/sys/boot/arm/at91/bootspi/sd-card.c#4 (text+ko) ====
@@ -57,6 +57,9 @@
}
while( !(status & AT91C_MCI_NOTBUSY) && (timeout>0) );
+ if (timeout == 0)
+ printf("Timeout, status is 0x%x\r\n", status);
+
//TODO: Make interrupts work!
AT91F_MCI_Handler();
}
@@ -134,7 +137,7 @@
}
int
-MCI_read (char* dest, unsigned source, unsigned length)
+MCI_read(char* dest, unsigned source, unsigned length)
{
unsigned sectorLength = MCI_Device.pMCI_DeviceFeatures->Max_Read_DataBlock_Length;
// unsigned sector = (unsigned)source / sectorLength;
@@ -143,6 +146,10 @@
int sizeToRead;
unsigned int *walker;
+ printf("Reading 0x%x bytes into ARM Addr 0x%x from card offset 0x%x\r\n",
+ length, dest, source);
+
+
//See if we are requested to read partial sectors, and have the capability to do so
if ((length % sectorLength) && !(MCI_Device_Features.Read_Partial))
//Return error if appropriat
@@ -155,8 +162,7 @@
return MCI_UNSUPP_OFFSET_ERROR;
//If the address we're trying to read != sector boundary
- if (offset)
- {
+ if (offset) {
//* Wait MCI Device Ready
AT91F_MCIDeviceWaitReady(AT91C_MCI_TIMEOUT);
@@ -165,8 +171,10 @@
//Do the writing
status = AT91F_MCI_ReadBlock(&MCI_Device, source, (unsigned int*)dest, sizeToRead);
//TODO:Status checking
- if (status != AT91C_READ_OK)
- return -1;
+ if (status != AT91C_READ_OK) {
+ printf("STATUS is 0x%x\r\n", status);
+ return -1;
+ }
//* Wait MCI Device Ready
AT91F_MCIDeviceWaitReady(AT91C_MCI_TIMEOUT);
@@ -185,7 +193,7 @@
while (length)
{
//See if we've got at least a sector to read
- if (length > sectorLength)
+ if (length > sectorLength)
sizeToRead = sectorLength;
//Else just write the remainder
else
@@ -194,9 +202,14 @@
AT91F_MCIDeviceWaitReady(AT91C_MCI_TIMEOUT);
//Do the writing
status = AT91F_MCI_ReadBlock(&MCI_Device, source, (unsigned int*)dest, sizeToRead);
+ printf("Reading 0x%x Addr 0x%x card 0x%x\r\n",
+ sizeToRead, dest, source);
+
//TODO:Status checking
- if (status != AT91C_READ_OK)
+ if (status != AT91C_READ_OK) {
+ printf("STATUS is 0x%x\r\n", status);
return -1;
+ }
//* Wait MCI Device Ready
AT91F_MCIDeviceWaitReady(AT91C_MCI_TIMEOUT);
@@ -371,7 +384,8 @@
{
int status;
- status = ( AT91C_BASE_MCI->MCI_SR & AT91C_BASE_MCI->MCI_IMR );
+// status = ( AT91C_BASE_MCI->MCI_SR & AT91C_BASE_MCI->MCI_IMR );
+ status = AT91C_BASE_MCI->MCI_SR;
AT91F_MCI_Device_Handler(&MCI_Device,status);
}
More information about the p4-projects
mailing list