- while(1);\r
- }\r
- \r
-+#define AT91C_MCI_TIMEOUT 1000000\r
-+\r
-+extern AT91S_MciDevice MCI_Device;\r
-+\r
-+extern void AT91F_MCIDeviceWaitReady(unsigned int);\r
-+extern int AT91F_MCI_ReadBlockSwab(AT91PS_MciDevice, int, unsigned int *, int);\r
-+\r
-+\r
-+int Program_From_MCI(void)\r
-+{\r
-+ int i;\r
-+ unsigned int Max_Read_DataBlock_Length;\r
-+ int block = 0;\r
-+ int buffer = AT91C_DOWNLOAD_BASE_ADDRESS;\r
-+ int bufpos = AT91C_DOWNLOAD_BASE_ADDRESS;\r
-+ int NbPage = 0;\r
-+ struct trx_header *p;\r
-+ unsigned int data;\r
-+\r
-+ p = (struct trx_header *)bufpos;\r
-+\r
-+ Max_Read_DataBlock_Length = MCI_Device.pMCI_DeviceFeatures->Max_Read_DataBlock_Length;\r
-+\r
-+ AT91F_MCIDeviceWaitReady(AT91C_MCI_TIMEOUT);\r
-+\r
-+ AT91F_MCI_ReadBlockSwab(&MCI_Device, block*Max_Read_DataBlock_Length, (unsigned int *)bufpos, Max_Read_DataBlock_Length);\r
-+\r
-+ if (p->magic != TRX_MAGIC)\r
-+ return FALSE;\r
-+\r
-+ printf("Read SD-Card\n\r");\r
-+ AT91C_BASE_PIOC->PIO_CODR = AT91C_PIO_PC7 | AT91C_PIO_PC15 | AT91C_PIO_PC8 | AT91C_PIO_PC14;\r
-+ for (i=0; i<(p->len/512); i++) {\r
-+ AT91F_MCI_ReadBlockSwab(&MCI_Device, block*Max_Read_DataBlock_Length, (unsigned int *)bufpos, Max_Read_DataBlock_Length);\r
-+ block++;\r
-+ bufpos += Max_Read_DataBlock_Length;\r
-+ }\r
-+\r
-+ NbPage = 0;\r
-+ i = dataflash_info[0].Device.pages_number;\r
-+ while(i >>= 1)\r
-+ NbPage++;\r
-+ i = ((p->offsets[1] - p->offsets[0])/ 512) + 1 + (NbPage << 13) + (dataflash_info[0].Device.pages_size << 17);\r
-+ *(int *)(buffer + p->offsets[0] + AT91C_OFFSET_VECT6) = i;\r
-+\r
-+ printf("Write romboot\n\r");\r
-+ AT91C_BASE_PIOC->PIO_CODR = AT91C_PIO_PC7 | AT91C_PIO_PC15 | AT91C_PIO_PC14;\r
-+ AT91C_BASE_PIOC->PIO_SODR = AT91C_PIO_PC8;\r
-+ write_dataflash(0xc0000000, buffer + p->offsets[0], p->offsets[1] - p->offsets[0]);\r
-+ printf("Write u-boot\n\r");\r
-+ AT91C_BASE_PIOC->PIO_CODR = AT91C_PIO_PC7 | AT91C_PIO_PC15;\r
-+ AT91C_BASE_PIOC->PIO_SODR = AT91C_PIO_PC8 | AT91C_PIO_PC14;\r
-+ write_dataflash(0xc0008000, buffer + p->offsets[1], p->offsets[2] - p->offsets[1]);\r
-+ printf("Write knl/root\n\r");\r
-+ AT91C_BASE_PIOC->PIO_CODR = AT91C_PIO_PC8 | AT91C_PIO_PC15;\r
-+ AT91C_BASE_PIOC->PIO_SODR = AT91C_PIO_PC7 | AT91C_PIO_PC14;\r
-+ write_dataflash(0xc0042000, buffer + p->offsets[2], p->len - p->offsets[2]);\r
-+ AT91C_BASE_PIOC->PIO_CODR = AT91C_PIO_PC8 | AT91C_PIO_PC14;\r
-+ AT91C_BASE_PIOC->PIO_SODR = AT91C_PIO_PC7 | AT91C_PIO_PC15;\r
-+ return TRUE;\r
-+ }\r
- \r
- //*----------------------------------------------------------------------------\r
- //* Function Name : main\r
+ while(1);
+ }
+
++#define AT91C_MCI_TIMEOUT 1000000
++
++extern AT91S_MciDevice MCI_Device;
++
++extern void AT91F_MCIDeviceWaitReady(unsigned int);
++extern int AT91F_MCI_ReadBlockSwab(AT91PS_MciDevice, int, unsigned int *, int);
++
++
++int Program_From_MCI(void)
++{
++ int i;
++ unsigned int Max_Read_DataBlock_Length;
++ int block = 0;
++ int buffer = AT91C_DOWNLOAD_BASE_ADDRESS;
++ int bufpos = AT91C_DOWNLOAD_BASE_ADDRESS;
++ int NbPage = 0;
++ struct trx_header *p;
++ unsigned int data;
++
++ p = (struct trx_header *)bufpos;
++
++ Max_Read_DataBlock_Length = MCI_Device.pMCI_DeviceFeatures->Max_Read_DataBlock_Length;
++
++ AT91F_MCIDeviceWaitReady(AT91C_MCI_TIMEOUT);
++
++ AT91F_MCI_ReadBlockSwab(&MCI_Device, block*Max_Read_DataBlock_Length, (unsigned int *)bufpos, Max_Read_DataBlock_Length);
++
++ if (p->magic != TRX_MAGIC)
++ return FALSE;
++
++ printf("Read SD-Card\n\r");
++ AT91C_BASE_PIOC->PIO_CODR = AT91C_PIO_PC7 | AT91C_PIO_PC15 | AT91C_PIO_PC8 | AT91C_PIO_PC14;
++ for (i=0; i<(p->len/512); i++) {
++ AT91F_MCI_ReadBlockSwab(&MCI_Device, block*Max_Read_DataBlock_Length, (unsigned int *)bufpos, Max_Read_DataBlock_Length);
++ block++;
++ bufpos += Max_Read_DataBlock_Length;
++ }
++
++ NbPage = 0;
++ i = dataflash_info[0].Device.pages_number;
++ while(i >>= 1)
++ NbPage++;
++ i = ((p->offsets[1] - p->offsets[0])/ 512) + 1 + (NbPage << 13) + (dataflash_info[0].Device.pages_size << 17);
++ *(int *)(buffer + p->offsets[0] + AT91C_OFFSET_VECT6) = i;
++
++ printf("Write romboot\n\r");
++ AT91C_BASE_PIOC->PIO_CODR = AT91C_PIO_PC7 | AT91C_PIO_PC15 | AT91C_PIO_PC14;
++ AT91C_BASE_PIOC->PIO_SODR = AT91C_PIO_PC8;
++ write_dataflash(0xc0000000, buffer + p->offsets[0], p->offsets[1] - p->offsets[0]);
++ printf("Write u-boot\n\r");
++ AT91C_BASE_PIOC->PIO_CODR = AT91C_PIO_PC7 | AT91C_PIO_PC15;
++ AT91C_BASE_PIOC->PIO_SODR = AT91C_PIO_PC8 | AT91C_PIO_PC14;
++ write_dataflash(0xc0008000, buffer + p->offsets[1], p->offsets[2] - p->offsets[1]);
++ printf("Write knl/root\n\r");
++ AT91C_BASE_PIOC->PIO_CODR = AT91C_PIO_PC8 | AT91C_PIO_PC15;
++ AT91C_BASE_PIOC->PIO_SODR = AT91C_PIO_PC7 | AT91C_PIO_PC14;
++ write_dataflash(0xc0042000, buffer + p->offsets[2], p->len - p->offsets[2]);
++ AT91C_BASE_PIOC->PIO_CODR = AT91C_PIO_PC8 | AT91C_PIO_PC14;
++ AT91C_BASE_PIOC->PIO_SODR = AT91C_PIO_PC7 | AT91C_PIO_PC15;
++ return TRUE;
++ }
+
+ //*----------------------------------------------------------------------------
+ //* Function Name : main