• BSP之BootLoader开发(二)


    接上……

    错误显示:不知道的操作码??

    应该是汇编文件的问题,但汇编语言没什么问题,那就是汇编格式有问题了。在每一句前面加上缩进(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中就有了吧

     

     

     到这步是最基础的,没完待续……

  • 相关阅读:
    简直不敢相信...
    halcon 保存Region [原创]
    VS2015 下载链接
    C#【数据转换】十进制yte[]相互转换
    C# 复制窗体问题完美解决办法
    TextBox 保持固定长度,添加新行滚动到最后,跨线程。
    mysql isnull
    C#跨线程访问控件[我的记录]
    C# 常用类-IO-ClassExcelExport
    C# 常用类-IO-ClassXML
  • 原文地址:https://www.cnblogs.com/EmbeddedBoy/p/1718490.html
Copyright © 2020-2023  润新知