📄 sanosclib.c
字号:
// file: SanOSclib.c
// by : Sanicle
// ver : 2005.03.20
// from: http://3mn.net
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "2410lib.h"
#include "SanOSlib.h"
DWORD ReadNandOS()
{
// This fuction load OS from NandFlash to SDRAM
DWORD dwSector, dwLength; // Start Sector & Length
DWORD dwRAM; // This value is SanOS' Base Address in SDRAM
rNFCONF = 0xF830; // Init NandFlash
dwRAM=0x30000000;
dwSector=0x00000040;
// if 4096 blocks, 0x40 here is block 2 (start from 0)
// cause 512B*0x40=0x20kB
dwLength=0x00000100;
// 0x00000100 is 128k
while (dwLength)
{
DWORD i, r = 0; // for loop
BYTE ecc0,ecc1,ecc2; // ecc check
BOOL rc = TRUE;
ECCRegVal eccRegVal;
_again:
// Initialize ECC register
rNFCONF |= (1<<12);
// Enable the chip
rNFCONF &= ~(1<<11);
// Issue Read command
rNFCMD = 0x00;
// Set up address
rNFADDR = 0x00;
rNFADDR = ((dwSector) & 0xff);
rNFADDR = ((dwSector >> 8) & 0xff);
rNFADDR = ((dwSector >> 16) & 0xff);
for (i = 0; i < 5; i++); // wait tWB(100ns)
while(!(rNFSTAT&(1<<0))); // wait tR(max 12us)
// read data in nandFlash
__SanReadFlash512((LPBYTE)dwRAM);
// Read the ECC from ECC Register
eccRegVal.dwECCVal = rNFECC;
// Skip first 8 bytes
for(i=0; i<8; i++)
{
ecc0 = rNFDATA;
}
ecc0 = rNFDATA;
ecc1 = rNFDATA;
ecc2 = rNFDATA;
rNFCONF |= (1<<11);
if ( !rc && r++ < 10 )
{
//Uart_SendString("Read Sector: ");
//Uart_SendDWORD(dwSector, TRUE);
// NandFlash Reset
rNFCONF &= ~(1<<11);
rNFCMD = 0xff;
while(!(rNFSTAT&(1<<0)));
rNFCONF |= (1<<11);
for (i = 0; i < 5; i++); // delay
rc = TRUE;
goto _again;
}
if( ecc0 != eccRegVal.bECCBuf[0] ||
ecc0 != eccRegVal.bECCBuf[0] ||
ecc0 != eccRegVal.bECCBuf[0] )
{
//Uart_SendString("ECC mismatch for Sector: ");
//Uart_SendDWORD(dwSector, TRUE);
rc = FALSE;
}
dwSector++;
dwLength--;
dwRAM += SECTOR_SIZE;
}
return 0x30000000; // dwRAW init value, SanOS launch address
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -