4)準備進入u-boot的第二階段(在u-boot中添加對咱們開發板上Nor Flash的支持)。java
一般,在嵌入式bootloader中,有兩種方式來引導啓動內核:從Nor Flash啓動和從Nand Flash啓動。u-boot中默認是從Nor Flash啓動,再從上一節這個運行結果圖中看,還發現幾個問題:第一,我開發板的Nor Flash是2M的,而這裏顯示的是512kB;第二,出現Warning - bad CRC, using default environment的警告信息。不是u-boot默認是從Nor Flash啓動的嗎?爲何會有這些錯誤信息呢?這是由於咱們尚未添加對咱們本身的Nor Flash的支持,u-boot默認的是其餘型號的Nor Flash,而咱們的Nor Flash的型號是SST39VF1601。另外怎樣將命令行提示符前面的SMDK2410變成我本身定義的呢?函數
下面咱們一一來解決這些問題,讓u-boot徹底對咱們Nor Flash的支持。首先咱們修改頭文件代碼以下:this
#gedit include/configs/my2440.h //修改命令行前的名字和Nor Flash參數部分的定義
#define CONFIG_SYS_PROMPT "[MY2440]#" //將命令行前的名字改爲[MY2440] /*----------------------------------------------------------------------- * FLASH and environment organization */ #if 0 //註釋掉下面兩個類型的Nor Flash設置,由於不是咱們所使用的型號 #define CONFIG_AMD_LV400 1 /* uncomment this if you have a LV400 flash */ #define CONFIG_AMD_LV800 1 /* uncomment this if you have a LV800 flash */ #endif #define CONFIG_SYS_MAX_FLASH_BANKS 1 /* max number of memory banks */ #ifdef CONFIG_AMD_LV800 #define PHYS_FLASH_SIZE 0x00100000 /* 1MB */ #define CONFIG_SYS_MAX_FLASH_SECT (19) /* max number of sectors on one chip */ #define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x0F0000) /* addr of environment */ #endif #ifdef CONFIG_AMD_LV400 #define PHYS_FLASH_SIZE 0x00080000 /* 512KB */ #define CONFIG_SYS_MAX_FLASH_SECT (11) /* max number of sectors on one chip */ #define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x070000) /* addr of environment */ #endif #define CONFIG_SST_39VF1601 1 //添加mini2440開發板Nor Flash設置 #define PHYS_FLASH_SIZE 0x200000 //咱們開發板的Nor Flash是2M #define CONFIG_SYS_MAX_FLASH_SECT (512) //根據SST39VF1601的芯片手冊描述,對其進行操做有兩種方式:塊方式和扇區方式。現採用扇區方式(sector),1 sector = 2Kword = 4Kbyte,因此2M的Nor Flash共有512個sector #define CONFIG_ENV_ADDR (CONFIG_SYS_FLASH_BASE + 0x040000) //暫設置環境變量的首地址爲0x040000(即:256Kb)
而後添加對咱們mini2440開發板上2M的Nor Flash(型號爲SST39VF1601,注:本人的mini2440板上是:s29al016j70tfi02,容量一樣是:2M)的支持。在u-boot中對Nor Flash的操做分別有初始化、擦除和寫入,因此咱們主要修改與硬件密切相關的三個函數flash_init、flash_erase、write_hword,修改代碼以下:spa
#gedit board/samsung/my2440/flash.c
//修改定義部分以下: //#define MAIN_SECT_SIZE 0x10000 #define MAIN_SECT_SIZE 0x1000 //定義爲4k,恰好是一個扇區的大小 //#define MEM_FLASH_ADDR1 (*(volatile u16 *)(CONFIG_SYS_FLASH_BASE + (0x00000555 << 1))) //#define MEM_FLASH_ADDR2 (*(volatile u16 *)(CONFIG_SYS_FLASH_BASE + (0x000002AA << 1))) #define MEM_FLASH_ADDR1 (*(volatile u16 *)(CONFIG_SYS_FLASH_BASE +(0x00005555 << 1))) //這兩個參數看SST39VF1601手冊 #define MEM_FLASH_ADDR2 (*(volatile u16 *)(CONFIG_SYS_FLASH_BASE +(0x00002AAA << 1))) //修改flash_init函數以下: #elif defined(CONFIG_AMD_LV800) (AMD_MANUFACT & FLASH_VENDMASK) | (AMD_ID_LV800B & FLASH_TYPEMASK); #elif defined(CONFIG_SST_39VF1601) //在CONFIG_AMD_LV800後面添加CONFIG_SST_39VF1601 (SST_MANUFACT & FLASH_VENDMASK) | (SST_ID_xF1601 & FLASH_TYPEMASK); for (j = 0; j < flash_info[i].sector_count; j++) { //if (j <= 3) { // /* 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函數以下: 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函數以下: //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)) { return ERR_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函數以下: 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; } }
修改完後從新編譯u-boot,下載到RAM中運行結果以下圖:命令行
# make my2440_config # make
本人是直接燒寫到 NOR FLASH 中的,運行結果(大體)以下:(注:本人並沒用supervivi)code
從運行結果圖看,Nor Flash的大小能夠正確檢測到了,命令行前面的名字也由原來的SMDK2410改爲我本身定義的[MY2440]了,可是還會出現bad CRC的警告信息,其實這並非什麼問題,只是尚未將環境變量設置到Nor Flash中,咱們執行一下u-boot的:saveenv命令就能夠了。以下圖:orm
從新從NOR FLASH啓動開發板,能夠觀察到不會出現警告信息了,這時候u-boot已經對咱們開發板上的Nor Flash徹底支持了。以下:ip
OK,到此爲止, 移植的u-boot已支持從NOR FLASH啓動了,並能正確識別 2M的NOR FLASH了。開發