/******************************************************************************* * Function Name : MAL_Read * Description : Read sectors * Input : None * Output : None * Return : Buffer pointer *******************************************************************************/ uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, uint32_t *Readbuff, uint16_t Transfer_Length) { switch (lun) { case 0: SD_ReadMultiBlocks((uint8_t*)Readbuff, Memory_Offset, Transfer_Length, 1); #if defined(USE_STM3210E_EVAL) || defined(USE_STM32L152D_EVAL) Status = SD_WaitReadOperation(); while(SD_GetStatus() != SD_TRANSFER_OK) { } if ( Status != SD_OK ) { return MAL_FAIL; } #endif /* USE_STM3210E_EVAL */ break; #ifdef USE_STM3210E_EVAL case 1: NAND_Read(Memory_Offset, Readbuff, Transfer_Length); ; break; #endif default: return MAL_FAIL; } return MAL_OK; }
/******************************************************************************* * Function Name : MAL_Read * Description : Read sectors * Input : None * Output : None * Return : Buffer pointer *******************************************************************************/ uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, uint32_t *Readbuff, uint16_t Transfer_Length) { switch (lun) { case 0: #ifdef USE_STM3210E_EVAL Status = SD_ReadBlock(Memory_Offset, Readbuff, Transfer_Length); if ( Status != SD_OK ) { return MAL_FAIL; } #else MSD_ReadBlock((uint8_t*)Readbuff, Memory_Offset, Transfer_Length); #endif break; #ifdef USE_FSMC_NAND case 1: NAND_Read(Memory_Offset, Readbuff, Transfer_Length); break; #endif default: return MAL_FAIL; } return MAL_OK; }
/******************************************************************************* * Function Name : MAL_Read * Description : Read sectors * Input : None * Output : None * Return : Buffer pointer *******************************************************************************/ uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, volatile uint8_t * Readbuff, uint32_t Transfer_Length) { switch (lun) { case 0: /* Physical drive number (0) */ Status = disk_read (0, (volatile uint8_t*)Readbuff, Memory_Offset/512, Transfer_Length/512); //Status = SD_ReadBlock((uint8_t*)Readbuff, Memory_Offset, Transfer_Length); #ifdef USE_STM3210E_EVAL if ( Status != SD_OK ) { return MAL_FAIL; } #endif /* USE_STM3210E_EVAL */ if(Status) return MAL_FAIL; break; #ifdef USE_STM3210E_EVAL case 1: NAND_Read(Memory_Offset, Readbuff, Transfer_Length); ; break; #endif default: return MAL_FAIL; } return MAL_OK; }
DRESULT disk_read ( BYTE drv, /* Physical drive nmuber (0..) */ BYTE *buff, /* Data buffer to store read data */ DWORD sector, /* Sector address (LBA) */ BYTE count /* Number of sectors to read (1..255) */ ) { if(NAND_Read((uint32_t )sector << 9, (uint32_t *)buff, (uint16_t)count << 9) == NAND_OK) return RES_OK; else return RES_ERROR; }
/******************************************************************************* * Function Name : MAL_Read * Description : Read sectors * Input : None * Output : None * Return : Buffer pointer *******************************************************************************/ uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, uint32_t *Readbuff, uint16_t Transfer_Length) { switch (lun) { case 0: break; case 1: NAND_Read(Memory_Offset, Readbuff, Transfer_Length); break; default: return MAL_FAIL; } return MAL_OK; }
/******************************************************************************* * Function Name : MAL_Read * Description : Read sectors * Input : None * Output : None * Return : Buffer pointer *******************************************************************************/ uint16_t MAL_Read(uint8_t lun, uint32_t Memory_Offset, uint32_t *Readbuff, uint16_t Transfer_Length) { switch (lun) { case 0: Status = SD_ReadBlock(Memory_Offset, Readbuff, Transfer_Length); if ( Status != SD_OK ) return MAL_FAIL; break; case 1: NAND_Read(Memory_Offset, Readbuff, Transfer_Length); printf("\r\nTransfer_Length_r = %d",Transfer_Length); break; default: return MAL_FAIL; } return MAL_OK; }
void NAND_Fatreadsects(uint32_t startsector,uint8_t* buf,uint32_t cnt) { uint32_t page,startpage,offset,i,j,i2,i3; uint8_t TempBuff[2048]; i = 0; for(j=0;j<cnt;j++){ startpage = ((startsector*2048)+(j*2048))/2048; offset = ((startsector*2048)+(j*2048))%2048; NAND_Read((startpage*2048), (uint32_t *)TempBuff, 2048); i2 = 0; for(i3=0;i3<2048;i3++){ buf[i++] = TempBuff[offset+(i2++)]; } } printf("\r\n startsector(%d) offset(%d) cnt(%d)\r\n",startsector,offset,cnt); }
void main(void) { register nPage; unsigned char *pBuf; unsigned char ucDID, ucHID; unsigned char nCnt; unsigned char uNumOfLoadPage = LOAD_PAGE_SIZE; BOOL b4KPage = FALSE; // Set up copy section (initialized globals). // // NOTE: after this call, globals become valid. // // SetupCopySection(pTOC); // Enable the ICache. // MMU_EnableICache(); // Set up all GPIO ports. Port_Init(); #ifdef DEBUGUART // UART initialize Uart_Init(); //Uart_SendString("\r\n\r\nWince 5.0 1st NAND Bootloader (NBL1) for SMDK2443\r\n"); // Initialize the NAND flash interface. Uart_SendString("NAND Initialize\r\n"); #endif NAND_Init(); Read_DeviceID(0, &ucDID, &ucHID); #ifdef DEBUGUART Uart_SendString("Device ID : 0x"); Uart_SendBYTE(ucDID, 1); Uart_SendString("Hidden ID : 0x"); Uart_SendBYTE(ucHID, 1); #endif if ( (ucDID == 0xd5 && ucHID == 0x14) || (ucDID == 0xd5 && ucHID == 0x94) || (ucDID == 0xd7 && ucHID == 0x55) || (ucDID == 0xd7 && ucHID == 0xD5) // for MLC || (ucDID == 0xd3 && ucHID == 0x10)) // for SLC { b4KPage = TRUE; uNumOfLoadPage = LOAD_PAGE_SIZE/2; } // Turn the LEDs off. Led_Display(0x0); pBuf = (unsigned char *)LOAD_ADDRESS_PHYSICAL; // MLC // Page 0, 1 : Steploader // Page 2 ~ 5 : empty page // Page 6 ~ PAGES_PER_BLOCK-3 : effective page // read pages with 0, 1 and 6 to PAGES_PER_BLOCK-3 nPage = 10; for (nCnt = 0; nCnt < uNumOfLoadPage; nCnt++) { #ifdef OMNIBOOK_VER Led_Display(0x1); #else //!OMNIBOOK_VER Led_Display(0x2); #endif OMNIBOOK_VER if (nPage >= (NAND_PAGE_PER_BLOCK-2) || (NAND_Read(0, nPage, pBuf, b4KPage) == FALSE)) { #ifdef DEBUGUART // Uncorrectable ECC Error Uart_SendString("ECC Error @ Page 0x"); Uart_SendBYTE(nPage, 1); #endif #ifdef OMNIBOOK_VER Led_Display(0x0); #else //!OMNIBOOK_VER Led_Display(0x9); #endif OMNIBOOK_VER while(1); } nPage++; if (b4KPage == TRUE) pBuf += NAND_BYTE_PER_PAGE*2; else pBuf += NAND_BYTE_PER_PAGE; #ifdef OMNIBOOK_VER Led_Display(0x2); #else //!OMNIBOOK_VER Led_Display(0x4); #endif OMNIBOOK_VER } //Uart_SendString("Jump to 2nd Bootloader...\r\n"); // Uart_SendDWORD(LOAD_ADDRESS_PHYSICAL, 1); // Turn the LEDs on. // #ifdef OMNIBOOK_VER Led_Display(0x3); #else //!OMNIBOOK_VER Led_Display(0x5); #endif OMNIBOOK_VER #ifdef DEBUGUART Uart_SendString("Jump to 2nd Bootloader...\r\n"); #endif ((PFN_IMAGE_LAUNCH)(LOAD_ADDRESS_PHYSICAL))(); }