嵌入式Linux之我行,主要講述和總結(jié)了本人在學習嵌入式linux中的每個步驟。一為總結(jié)經(jīng)驗,二希望能給想入門嵌入式Linux的朋友提供方便。如有錯誤之處,謝請指正。
共享資源,歡迎轉(zhuǎn)載:http://hbhuanggang.cublog.cn
一、移植環(huán)境
主 機:VMWare--Fedora 9
開發(fā)板:Mini2440--64MB Nand,Kernel:2.6.30.4
編譯器:arm-linux-gcc-4.3.2.tgz
u-boot:u-boot-2009.08.tar.bz2
二、移植步驟
上接:u-boot-2009.08在2440上的移植詳解(一)
4)準備進入u-boot的第二階段(在u-boot中添加對我們開發(fā)板上Nor Flash的支持)。
通 常,在嵌入式bootloader中,有兩種方式來引導啟動內(nèi)核:從Nor Flash啟動和從Nand Flash啟動。u-boot中默認是從Nor Flash啟動,再從上一節(jié)這個運行結(jié)果圖中看,還發(fā)現(xiàn)幾個問題:第一,我開發(fā)板的Nor Flash是2M的,而這里顯示的是512kB;第二,出現(xiàn)Warning - bad CRC, using default environment的警告信息。不是u-boot默認是從Nor Flash啟動的嗎?為什么會有這些錯誤信息呢?這是因為我們還沒有添加對我們自己的Nor Flash的支持,u-boot默認的是其他型號的Nor Flash,而我們的Nor Flash的型號是SST39VF1601。另外怎樣將命令行提示符前面的SMDK2410變成我自己定義的呢?
下面我們一一來解決這些問題,讓u-boot完全對我們Nor Flash的支持。首先我們修改頭文件代碼如下:
#geditinclude/configs/my2440.h//修改命令行前的名字和Nor Flash參數(shù)部分的定義
#defineCONFIG_SYS_PROMPT"[MY2440]#"http://將命令行前的名字改成[MY2440]
/*-----------------------------------------------------------------------
* FLASH and environment organization
*/
#if0//注釋掉下面兩個類型的Nor Flash設(shè)置,因為不是我們所使用的型號
#defineCONFIG_AMD_LV4001/* uncomment this if you have a LV400 flash */
#defineCONFIG_AMD_LV8001/* uncomment this if you have a LV800 flash */
#endif
#defineCONFIG_SYS_MAX_FLASH_BANKS1/* max number of memory banks */
#ifdefCONFIG_AMD_LV800
#definePHYS_FLASH_SIZE0x00100000/* 1MB */
#defineCONFIG_SYS_MAX_FLASH_SECT(19)/* max number of sectors on one chip */
#defineCONFIG_ENV_ADDR(CONFIG_SYS_FLASH_BASE+0x0F0000)/* addr of environment */
#endif
#ifdefCONFIG_AMD_LV400
#definePHYS_FLASH_SIZE0x00080000/* 512KB */
#defineCONFIG_SYS_MAX_FLASH_SECT(11)/* max number of sectors on one chip */
#defineCONFIG_ENV_ADDR(CONFIG_SYS_FLASH_BASE+0x070000)/* addr of environment */
#endif
#defineCONFIG_SST_39VF16011//添加mini2440開發(fā)板Nor Flash設(shè)置
#definePHYS_FLASH_SIZE0x200000//我們開發(fā)板的Nor Flash是2M
#defineCONFIG_SYS_MAX_FLASH_SECT(512)//根據(jù)SST39VF1601的芯片手冊描述,對其進行操作有兩種方式:塊方式和扇區(qū)方式?,F(xiàn)采用扇區(qū)方式(sector),1 sector = 2Kword = 4Kbyte,所以2M的Nor Flash共有512個sector
#defineCONFIG_ENV_ADDR(CONFIG_SYS_FLASH_BASE+0x040000)//暫設(shè)置環(huán)境變量的首地址為0x040000(即:256Kb)
然后添加對我們mini2440開發(fā)板上2M的Nor Flash(型號為SST39VF1601)的支持。在u-boot中對Nor Flash的操作分別有初始化、擦除和寫入,所以我們主要修改與硬件密切相關(guān)的三個函數(shù)flash_init、flash_erase、 write_hword,修改代碼如下:
#geditboard/samsung/my2440/flash.c
//修改定義部分如下:
//#define MAIN_SECT_SIZE0x10000
#defineMAIN_SECT_SIZE0x1000//定義為4k,剛好是一個扇區(qū)的大小
//#define MEM_FLASH_ADDR1 (*(volatile u16 *)(CONFIG_SYS_FLASH_BASE + (0x00000555 << 1)))
//#define MEM_FLASH_ADDR2(*(volatile u16 *)(CONFIG_SYS_FLASH_BASE + (0x000002AA << 1)))
#defineMEM_FLASH_ADDR1(*(volatileu16*)(CONFIG_SYS_FLASH_BASE+(0x00005555<<1)))//這兩個參數(shù)看SST39VF1601手冊
#defineMEM_FLASH_ADDR2(*(volatileu16*)(CONFIG_SYS_FLASH_BASE+(0x00002AAA<<1)))
//修改flash_init函數(shù)如下:
#elifdefined(CONFIG_AMD_LV800)
(AMD_MANUFACT&FLASH_VENDMASK)|
(AMD_ID_LV800B&FLASH_TYPEMASK);
#elifdefined(CONFIG_SST_39VF1601)//在CONFIG_AMD_LV800后面添加CONFIG_SST_39VF1601
(SST_MANUFACT&FLASH_VENDMASK)|
(SST_ID_xF1601&FLASH_TYPEMASK);
for(j=0;j
// /* 1st one is 16 KB */
//if (j == 0) {
//flash_info[i].start[j] =flashbase + 0;
//}
///* 2nd and 3rd are both 8 KB */
//if ((j == 1) || (j == 2)) {
//flash_info[i].start[j] =flashbase + 0x4000 + (j -1) *0x2000;
//}
///* 4th 32 KB */
//if (j == 3) {
//flash_info[i].start[j] =flashbase + 0x8000;
//}
//} else {
//flash_info[i].start[j] =flashbase + (j - 3) * MAIN_SECT_SIZE;
//}
flash_info[i].start[j]=flashbase+j*MAIN_SECT_SIZE;
}
//修改flash_print_info函數(shù)如下:
case(AMD_MANUFACT&FLASH_VENDMASK):
printf("AMD: ");
break;
case(SST_MANUFACT&FLASH_VENDMASK)://添加SST39VF1601的
printf("SST:");
break;
case(AMD_ID_LV800B&FLASH_TYPEMASK):
printf("1x Amd29LV800BB (8Mbit)n");
break;
case(SST_ID_xF1601&FLASH_TYPEMASK)://添加SST39VF1601的
printf("1x SST39VF1610 (16Mbit)n");
break;
//修改flash_erase函數(shù)如下:
//if ((info->flash_id & FLASH_VENDMASK) !=
// (AMD_MANUFACT & FLASH_VENDMASK)) {
//return ERR_UNKNOWN_FLASH_VENDOR;
//}
if((info->flash_id&FLASH_VENDMASK)!=
(SST_MANUFACT&FLASH_VENDMASK)){
returnERR_UNKNOWN_FLASH_VENDOR;
}
///* wait until flash is ready */
//chip = 0;
//do {
//result = *addr;
///* check timeout */
//if (get_timer_masked () >
// CONFIG_SYS_FLASH_ERASE_TOUT) {
//MEM_FLASH_ADDR1 = CMD_READ_ARRAY;
//chip = TMO;
//break;
//}
//if (!chip
// && (result & 0xFFFF) & BIT_ERASE_DONE)
//chip = READY;
//if (!chip
// && (result & 0xFFFF) & BIT_PROGRAM_ERROR)
//chip = ERR;
//} while (!chip);
//MEM_FLASH_ADDR1 = CMD_READ_ARRAY;
//if (chip == ERR) {
//rc = ERR_PROG_ERROR;
//goto outahere;
//}
//if (chip == TMO) {
//rc = ERR_TIMOUT;
//goto outahere;
//}
while(1)
{
if((*addr&0x40)!=(*addr&0x40))
continue;
if(*addr&0x80)
{
rc=ERR_OK;
break;
}
}
//修改write_hword函數(shù)如下:
MEM_FLASH_ADDR1=CMD_UNLOCK1;
MEM_FLASH_ADDR2=CMD_UNLOCK2;
//MEM_FLASH_ADDR1 = CMD_UNLOCK_BYPASS;
MEM_FLASH_ADDR1=CMD_PROGRAM;
//*addr = CMD_PROGRAM;
*addr=data;
///* wait until flash is ready */
//chip = 0;
//do {
//result = *addr;
///* check timeout */
//if (get_timer_masked () > CONFIG_SYS_FLASH_ERASE_TOUT) {
//chip = ERR | TMO;
//break;
//}
//if (!chip && ((result & 0x80) == (data & 0x80)))
//chip = READY;
//if (!chip && ((result & 0xFFFF) & BIT_PROGRAM_ERROR)) {
//result = *addr;
//if ((result & 0x80) == (data & 0x80))
//chip = READY;
//else
//chip = ERR;
//}
//} while (!chip);
//*addr = CMD_READ_ARRAY;
//if (chip == ERR || *addr != data)
//rc = ERR_PROG_ERROR;
while(1)
{
if((*addr&0x40)!=(*addr&0x40))
continue;
if((*addr&0x80)==(data&0x80))
{
rc=ERR_OK;
break;
}
}