新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > uboot如何檢測(cè)s3c2440是從Nand Flash還是Nor Flash啟動(dòng)

uboot如何檢測(cè)s3c2440是從Nand Flash還是Nor Flash啟動(dòng)

作者: 時(shí)間:2016-11-27 來(lái)源:網(wǎng)絡(luò) 收藏
nand啟動(dòng)時(shí),地址0x00000000為SRAM映射的地址;nor啟動(dòng)時(shí),地址0x00000000為norflash的實(shí)際起始地址。向norflash中寫(xiě)數(shù)據(jù)需要特定的命令時(shí)序,而向內(nèi)存中寫(xiě)數(shù)據(jù)可以直接向內(nèi)存地址賦值。
根據(jù)這兩個(gè)特性,我們可以這樣檢測(cè),代碼如下
int check_flashboot_mode(void)
{
volatile unsigned int *pdw = (volatile unsigned int *)0;
unsigned int dwVal;
dwVal = *pdw;
*pdw = 0x12345678;
if (*pdw != 0x12345678)
{
return 1; //boot from norflash
}
else //boot from nandflash
{
*pdw = dwVal; //數(shù)據(jù)還原
return 0;
}
}

用volatile聲明一個(gè)寄存器變量*pdw指向的是0地址。向0地址處寫(xiě)一串?dāng)?shù)據(jù),比如0x12345678,*pdw = 0x12345678,接著再?gòu)?地址中把數(shù)據(jù)讀回來(lái)。
因?yàn)閚or啟動(dòng)時(shí),0地址是norflash的起始址,而向norflash寫(xiě)數(shù)據(jù)需要特定的命令時(shí)序,所以直接給地址賦值是不起做用的,所以讀回來(lái)的數(shù)據(jù)還是norflash中原有的數(shù)據(jù),這樣通過(guò)*pdw != 0x12345678判斷,此時(shí)為nor啟動(dòng)。
而在nand啟動(dòng)時(shí),0地址是內(nèi)存的地址映射,可以用直接賦值的方法向內(nèi)存中寫(xiě)入數(shù)據(jù),接著從0地址讀回來(lái)的數(shù)據(jù)變?yōu)?x12345678,和之前寫(xiě)入的數(shù)據(jù)相等,此時(shí)就為nand啟動(dòng),在操作完后,要將數(shù)據(jù)還原 *pdw = dwVal

參考:

本文引用地址:http://www.2s4d.com/article/201611/322381.htm

http://blog.chinaunix.net/uid-22030783-id-3347621.html



關(guān)鍵詞: uboots3c2440NandFlashNo

評(píng)論


技術(shù)專(zhuān)區(qū)

關(guān)閉