u-boot 移植 --->三、S5PV210啓動序列

           經過三星官方的資料S5PV210_iROM_ApplicationNote_Preliminary_20091126.pdf,瞭解到S5PVS10這款芯片的復位過程啓動序列。芯片在出廠時就在內部固化了一段程序internal ROM簡稱iROM,這段代碼在芯片復位一後會自動運行,他主要負責初始化系統的時鐘等具體以下:安全

1. Disable the Watch-Dog Timer \\關閉看門狗
2. Initialize the instruction cache \\關閉指定cache
3. Initialize the stack region (see 「memory map」 on chap 2.5) \\設置不一樣模式的棧指針
4. Initialize the heap region. (see 「memory map」 on chap 2.5) \\設置堆
5. Initialize the Block Device Copy Function. (see 「Device Copy Function」 on chap 2.7) \\初始化塊設備拷貝的函數這些函數對用戶開放
6. Initialize the PLL and Set system clock. (see 「clock configuration」 on chap 2.11) \\系統時鐘配置
7. Copy the BL1 to the internal SRAM region (see 「Device Copy Function」 on chap 2.7) \\自動拷貝啓動介質指定的地方指定長度的代碼到IRAM中
8. Verify the checksum of BL1.
If checksum fails, iROM will try the second boot up. (SD/MMC channel 2)\\校驗拷貝的代碼,格式和拷貝過程校驗,失敗的話會嘗試其餘的啓動方式
9. Check if it is secure-boot mode or not. 
If the security key value is written in S5PV210, It’s secure-boot mode. \\檢查是不是安全啓動,進而進行更嚴格的驗證。
If it is secure-boot mode, verify the integrity of BL1.
10. Jump to the start address of BL1 \\跳轉到指定的地址0xD002_0010開始執行。此時就開始把執行權交給用戶了。

 

三星原廠的資料中有一個流程圖可更加詳細形象的展現內嵌的IROM程序的操做詳細。不用安全模式則只須要將可執行程序的頭上按照其手冊添加指定的hearer info 就能夠了,這裏借鑑網上的代碼,參也能夠考手冊字節寫,比較簡單源碼以下:函數

/* 在BL0階段,Irom內固化的代碼讀取nandflash或SD卡前16K的內容, * 並比對前16字節中的校驗和是否正確,正確則繼續,錯誤則中止。 */ #include <stdio.h> #include <string.h> #include <stdlib.h>

#define BUFSIZE (16*1024)
#define IMG_SIZE (16*1024)
#define SPL_HEADER_SIZE 16
#define SPL_HEADER "S5PC110 HEADER "

int main (int argc, char *argv[]) { FILE *fp; char    *Buf, *a; int BufLen; int nbytes, fileLen; unsigned int checksum, count; int i; // 1. 3個參數
if (argc != 3) { printf("Usage: mkbl1 <source file> <destination file>\n"); return -1; } // 2. 分配16K的buffer
BufLen = BUFSIZE; Buf = (char *)malloc(BufLen); if (!Buf) { printf("Alloc buffer failed!\n"); return -1; } memset(Buf, 0x00, BufLen); // 3. 讀源bin到buffer // 3.1 打開源bin
fp = fopen(argv[1], "rb"); if( fp == NULL) { printf("source file open error\n"); free(Buf); return -1; } // 3.2 獲取源bin長度
fseek(fp, 0L, SEEK_END); fileLen = ftell(fp); fseek(fp, 0L, SEEK_SET); // 3.3 源bin長度不得超過16K-16byte
count = (fileLen < (IMG_SIZE - SPL_HEADER_SIZE)) ? fileLen : (IMG_SIZE - SPL_HEADER_SIZE); // 3.4 buffer[0~15]存放"S5PC110 HEADER "
memcpy(&Buf[0], SPL_HEADER, SPL_HEADER_SIZE); // 3.5 讀源bin到buffer[16]
nbytes = fread(Buf + SPL_HEADER_SIZE, 1, count, fp); if ( nbytes != count ) { printf("source file read error\n"); free(Buf); fclose(fp); return -1; } fclose(fp); // 4. 計算校驗和 // 4.1 從第16byte開始統計buffer中共有幾個1
a = Buf + SPL_HEADER_SIZE; for(i = 0, checksum = 0; i < IMG_SIZE - SPL_HEADER_SIZE; i++) checksum += (0x000000FF) & *a++; // 4.2 將校驗和保存在buffer[8~15]
a = Buf + 8; *( (unsigned int *)a ) = checksum; // 5. 拷貝buffer中的內容到目的bin // 5.1 打開目的bin
fp = fopen(argv[2], "wb"); if (fp == NULL) { printf("destination file open error\n"); free(Buf); return -1; } // 5.2 將16k的buffer拷貝到目的bin中
a = Buf; nbytes = fwrite( a, 1, BufLen, fp); if ( nbytes != BufLen ) { printf("destination file write error\n"); free(Buf); fclose(fp); return -1; } free(Buf); fclose(fp); return 0; }

編譯生成可執行文件 這裏爲imagemeker最後可使用 ./imagemeker u-boot.bin outputfilename 提取U-boot的前16K代碼生成BL1代碼,進而燒寫到SD卡中選擇好SD啓動後就能夠運行了,BL1這一段代碼的任務就是初始化DRAM而後將後續剩餘的u-boot或其餘代碼拷貝到DRAM中去,由於內部IRAM 的空間過小。spa

第一啓動方案是按外部OM腳的配置狀況來決定啓動方式的若是啓動方式失敗了(非安全模式,安全模式啓動失敗芯片將中止任何動做),則會執行第二啓動方案其中包括UART和USB啓動。第二啓動方案會再次嘗試OM選擇的啓動介質,若是仍是失敗則會執行默認的第二個啓動介質引導啓動這個過程成功後同上面的啓動方式相同會執行BL1,不然將嘗試UART啓動,成功後也將執行BL1,不然嘗試USB啓動,行爲同上面的UART啓動,這裏將額BL1指用戶代碼的前16K-16字節+16字節的header info。指針

相關文章
相關標籤/搜索