BSP 之Bootloader開發(2)

轉自: http://www.cnblogs.com/EmbeddedBoy/archive/2010/04/23/1718490.html


接上……

 

錯誤顯示:不知道的操作碼??

應該是彙編文件的問題,但彙編語言沒什麼問題,那就是彙編格式有問題了。在每一句前面加上縮進(Tab鍵),再build –c

就沒錯了;恭喜通過了……

驗證 %_WINCEROOT\Platform\My_2410\target\ARMV4I\Debug\Eboot.exe 是否已被創建。

7. Implement the boot loader's StartUp function.

關於這裏,看英文很爽,不過我推薦去這個牛人寫的看看:http://blog.csdn.net/nanjianhui/archive/2008/10/12/3065291.aspx

已經分析得很好了

但是我們可以先不要這麼詳細實現先,這一步可以留着以後去實現:

於是我的StartUp.s是這樣的

代碼
複製代碼
OPT 2 ; Disable listing INCLUDE kxarm.h ; This defines the WinCE/ARM Calling Sequence Specification OPT 1 ; Reenable listing OPT 128 ; Disable listing of macro expansions TEXTAREA IMPORT main STARTUPTEXT LEAF_ENTRY StartUp b main nop ; *** This routine will be filled in later *** ENTRY_END END
複製代碼

  

8. Create a boot loader main function.

main函數由Startup函數調用,是函數的入口點;The main function turns around and calls BootloaderMain, which is defined in the BLCOMMON library.

BLCOMMON庫定義了boot loader的基本結構,爲boot loader開發過程提供很多具體的實現;具體請Google

To create a boot loader main function

  1. Create a file called Main.c.
  2. Add the implementation for the main routine in the Main.c file.

The following code example shows the implementation of the main routine for the hardware platform used in this boot loader example.

void main(void)

{

    // Common boot loader (blcommon) main routine.

    //

    BootloaderMain();

 

    // Should never get here.

    //

    SpinForever();

}

 

9. Create stub versions for a number of OEM functions, including generic hardware platform routines and flash memory operations.

Stubs are routines that do not contain executable code. They act as placeholders位置標誌符for functions that need to be fully implemented later. When implementing stubs, you can leave comments that describe what you eventually need to do to add functionality to your function.

You need to create stubs for some generic hardware platform routines and flash memory operations because BLCOMMON expects to call these functions, but they have not yet been implemented. You can revisit these functions and then fully implement them later.

簡單地講,Stubs就是一些BLCOMMON需要去調用的函數的聲明,你可以在其他的地方實現這些函數

The stub versions added to Main.c are for the following generic hardware platform routines:

也就是說,我們main函數中聲明它們,然後實現它們;

 

The stub versions added to Flash.c are for the following flash memory-related functions:

If the boot loader being developed does not need to erase or write to flash memory on your device, the flash memory routines can remain as stub versions and do not have to be fully implemented later.

flash.c中就具體的實現以上提到的函數,但如果你的設備不需要擦除或寫flash的話,有些函數是不需要實現的;

 

於是我main函數如下:main.c

代碼
複製代碼
#include <windows.h> #include <blcommon.h> BOOL OEMDebugInit(void){return(TRUE);} BOOL OEMPlatformInit(void){ return(TRUE);} DWORD OEMPreDownload(void){return(0);} //void OEMLaunch(DWORD dwImageStart,const ROMHDR *pRomHdr){} void OEMLaunch (DWORD dwImageStart, DWORD dwImageLength, DWORD dwLaunchAddr, const ROMHDR *pRomHdr) {} BOOL OEMReadData(DWORD cbData,LPBYTE pbData){return(TRUE);} void OEMShowProgress(DWORD dwPacketNum){} void OEMWriteDebugByte(unsigned char c){} static void SpinForever(void){ while(1); } void main(void) { BootloaderMain(); SpinForever(); }
複製代碼

 flash函數如下:

flash.c

代碼
複製代碼
#include <windows.h> #include <blcommon.h> BOOL OEMStartEraseFlash (DWORD dwStartAddr, DWORD dwLength) { return(FALSE); } void OEMContinueEraseFlash (void) {} BOOL OEMFinishEraseFlash (void) {return(FALSE); } BOOL OEMIsFlashAddr (DWORD dwAddr) { return(FALSE); } BOOL OEMWriteFlash(DWORD dwStartAddr, DWORD dwLength) { return(FALSE); } LPBYTE OEMMapMemAddr (DWORD dwImageStart, DWORD dwAddr) { return((LPBYTE)dwAddr); }
複製代碼

 

 

10. Add the new source files, Main.c. and Flash.c, created in the previous step to the SOURCES line in the sources file.  

在sourcefile文件中的sources行添加main.c 、flash.c

然後就要解決鏈接依賴的問題:在sources文件中添加TARGETLIBS(定義要鏈接的庫文件) ,比如:

TARGETLIBS=$(_COMMONOAKROOT)\lib\$(_CPUDEPPATH)\blcommon.lib \

           $(_COMMONOAKROOT)\lib\$(_CPUDEPPATH)\fulllibc.lib

它就解決了main函數中BootloaderMain調用的鏈接依賴;

所以總的sources文件內容如下:

 

代碼
複製代碼
TARGETNAME=EBOOT TARGETTYPE=PROGRAM RELEASETYPE=PLATFORM EXEENTRY=StartUp INCLUDES=.\Inc;$(_COMMONSDKROOT)\inc;$(_COMMONOAKROOT)\inc TARGETLIBS=$(_COMMONOAKROOT)\lib\$(_CPUDEPPATH)\blcommon.lib \ $(_COMMONOAKROOT)\lib\$(_CPUDEPPATH)\fulllibc.lib SOURCES=startup.s \ main.c \ flash.c \ WINCETARGETFILES=BootImage
複製代碼

 

 

11. Create the .bib file, which will be used by Romimage.exe to convert the boot loader .exe file into .bin and .nb0 files.

 

哈,我們若要產生.bin和.nb0文件就要用到這個.bib文件了

bib文件介紹請看:http://www.cnblogs.com/EmbeddedBoy/articles/1718835.html

創建一個Boot.bib文件,內容如下:

代碼
複製代碼
; Eboot is built to run out of RAM, though initially the location of the ; image may be in flash. This .bib file will create two different Eboot ; images of interest: ; ; Eboot.nb0 - Can be used to flash an initial Eboot image using JTAG. ; Eboot.bin - Can be downloaded by existing Eboot image and flashed. ; ; Note: The .nb0 file is a raw未經處理的 binary image. The .bin file is a recordized ; image with header. ; MEMORY ; Name Start Size Type ; ------- -------- -------- ---- ; Reserve some RAM before Eboot. ; This memory will be used later. FILLER A0000000 00030000 RESERVED ; Replaced with data later. EBOOT A0030000 00020000 RAMIMAGE ; Set aside 128 KB for loader; finalize later. RAM A0050000 00010000 RAM ; Free RAM; finalize later. CONFIG COMPRESSION=OFF PROFILE=OFF KERNELFIXUPS=ON ; These configuration options cause the .nb0 file to be created. ; An .nb0 file may be directly written to flash memory and then ; booted. Because the loader is linked to execute from RAM, ; the following configuration options ; must match the RAMIMAGE section. ROMSTART=A0030000 ROMWIDTH=32 ROMSIZE=20000 MODULES ; Name Path Memory Type ; ----------- --------------------------------------------- ----------- nk.exe $(_TARGETPLATROOT)\target\$(_TGTCPU)\$(WINCEDEBUG)\EBOOT.exe EBOOT
複製代碼

接着創建一個Makefile.inc文件,內容如下:

BootImage:

     romimage  boot.bib

 

接着把WINCETARGETFILES=BootImage加到sources文件中(已經加了)。

 

12. Rebuild the boot loader.

 再次編譯:build -c

看%_WINCEROOT%\Platform\My2410\Target\ARMV4I\Debug中就有了吧

 

 

 到這步是最基礎的,沒完待續……


發佈了6 篇原創文章 · 獲贊 3 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章