BSP之BootLoader开发(一)

此bootloader的开发是以ARM+CE5.0为基础的,参照PB帮助文档和相关前辈心得,我只是负责简单的思考和验证,得出一些自己的心得,都是简单英文,有些就不再翻译了

WinCE系统移植的重点是BSP 的移植。而BSP移植主要包括启动程序Bootloader、OEM适配层程序OAL、标准开发板(SDB)本地驱动程序以及一些文件配置的修改。

  修改Bootloader是移植Win CE系统第一步,也是关键的一步。只有得到一个稳定工作的启动程序,才能够进一步完成WinCE BSP的移植。Bootloader主要用来管理目标平台的启动过程,它是一段单独的程序代码,通过这段小程序可以初始化硬件设备、建立内存空间的映射图和下载操作系统的映像文件等,从而将系统的软硬件环境带到一个合适的状态,它一般存放于目标平台的非易失存储介质中,如ROM或Flash。
  一般来说,对于Bootloader的功能,不同的场合区别很大。比如,在桌面Windows版的PC硬件平台上,由于硬件启动根本就不通过Bootloader(而是通过BIOS),所以Bootloader就无需对CPU加电后的初始化做任何工作;而在嵌入式WinCE平台上,Bootloader是最先被执行的程序,所以就必须包括加电初始化程序,同时通常Bootloader必须包含下载WinCE映像文档的功能。由于Bootloader会涉及到基本的硬件操作,如CPU的结构、指令等,也会又涉及到以太网下载协议和映像文档格式。因此,从零开发实现的话会需要相当长的过程,通常的做法是利用微软为每种类型的CPU提供的某种标准研发板的Bootloader例程。

 

PB5.0 help文档中:

The boot loader is a utility that is an integral part of the OEM device development process. In some cases, it is also included in the final OEM product. The general purpose of the boot loader is to place the run-time image into memory, and then jump to the OS startup routine. The boot loader can obtain the run-time image in a number of different ways, including loading it over a cabled connection, such as Ethernet, a universal serial bus (USB), or serial connection. The boot loader also loads the OS from a local storage device, such as Compact Flash, or a hard disk. The boot loader might store the run-time image in RAM or in nonvolatile storage, such as flash memory, electrically erasable programmable read only memory (EEPROM), or some other storage device for later use.

BOOTLOADER的主要作用是将操作系统运行时映像加载到内存,并跳转到OS的启动程序处。BOOTLOADER获取运行时映像(一般对应的文件名为NK)一般有两种方法。它可以通过有线连接的方式象网络(Ethernet)、USB或串口从外部下载NK。它也可以从本地的存储器(Flash、Hard Disk)中加载NK。通常,BOOTLOADER通过Ethernet下载操作系统映像故将其称为EBOOT。在开发的过程中使用EBOOT,可以提高开发效率。通过使用EBOOT,你可以很快速的下载NK到目标设备中。而利用Flash编程工具或者是通过JTAG下载则很慢。在一些产品最终发布时,EBOOT是可以去掉的,但也有一些则必须包括BOOTLOADER,像X86的平台就是如此。

1、Create a directory for your new boot loader code.

The boot loader code directory is typically in a hardware platform directory.

所以我们可以在OS的安装目录,即我的是在C:\WINCE500\PLATFORM下建立如下目录结构。

“.\My2410\SRC\BOOTLOADER\EBOOT”。

You must include the directory in the hardware platform dirs file to build it as part of Platform Builder.

所以在C:\WINCE500\PLATFORM\My2410\SRC\BOOTLOADER目录下建立一个名为dirs的文件。

Dirs文件源代码:

DIRS= \

eboot

2. Set up a command-line build shell to create and build the boot loader.

一、这样做之前我们先要完成一步:建立BSP文件

启动PB5.0。依次选择菜单Platform—〉BSP Wizard…

建立一个新的BSP文件。

.cec文件名:My_2410。保存路径:C:\wince500\platform\My_2410。目录名:My_2410。平台目录:My_2410。Cpu类型:ARMV4I。

添加一个Bootloader到新的BSP中。

名称:Eboot。源代码路径:找到我们刚才建立好的dirs文件即可。

二,以新BSP为基础,建立操作系统。

1,PB5.0中菜单File—〉New Platform。

2,名称:MyPlatform。路径:保持默认。  

3,选择新BSP建立操作系统。

4,选一种你喜欢的配置,构成系统。

5,选择Sun2410 ARMV4I Debug编译系统。这时会报有三个错,不管他的。因为新的BSP还一个文件都没有,当然会错啦,不错就见鬼了。

3. Generate all static libraries required by the boot loader image.

1,PB5.0中菜单Build OS—〉Open Release Directory。这时已经进入到DOS状态下了。

2,改变目录到C:\WINCE500\public\common\oak\misc中。

3,输入命令wince。

4,输入命令sysgen。

5,改变目录到C:\WINCE500\PLATFORM\My_2410\SRC\BOOTLOADER中。

6,输入命令Build -c。如果无错,恭喜你。

4. Create a file for your boot loader's StartUp function, and then establish a function framework框架 as a starting point.

To create a file for the StartUp function

  1. Navigate to %_WINCEROOT%\Platform\MyPlatform\Src\Bootloader\Eboot.

到(我的)C:\wince500\platform\my_2410/src\bootloader\eboot目录下,创建一个文件StartUp.s.文件内容是一个框架式的,只能使用汇编语言描述;如下绿色字体,这是基于ARM硬件平台的,但你的代码可以不同于此

  1. Create a file called 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

 

STARTUPTEXT

LEAF_ENTRY StartUp

 nop               ; *** This routine will be filled in later ***

END

5. Create a sources file and makefile file in the boot loader directory.

Create a sources file.

The sources file must contain the following code. The code shows the macro variables for the sources file. 文件sources的内容如下:

TARGETNAME=EBOOT

TARGETTYPE=PROGRAM

RELEASETYPE=PLATFORM

EXEENTRY=StartUp

SOURCES=startup.s

 

The makefile file must contain the following code. 文件Makefile的内容如下:

!INCLUDE $(_MAKEENVROOT)\makefile.def

 

6. Build your first boot loader executable (.exe) file.

To build the boot loader source code

  1. At the command prompt, enter the following command:

build -c

For more information about the build tool and the parameters you can use, see Build Tool.

但是如果就这样编译是有错误的,一位前辈已经总结了

可是却又发生错误了。这是因为我们在汇编文件中include kxarm.h,但在我们所在的目录下并没有这个文件。建立一个Inc目录,在D:\WINCE500\PUBLIC\COMMON\SDK\INC目录下拷贝kxarm.h文件到这个目录。修改sources文件。

 

修改后的sources文件源代码如下:

TARGETNAME=EBOOT

TARGETTYPE=PROGRAM

RELEASETYPE=PLATFORM

EXEENTRY=StartUp

INCLUDES=.\Inc

SOURCES=startup.s

 

再次Build -c。

不过虽然有前辈帮忙,但我到这里还是有错误,如下:

不管了,吃饭先

参考:http://blog.csdn.net/xiaoxiangtian/archive/2008/09/22/2963034.aspx

原文地址:https://www.cnblogs.com/EmbeddedBoy/p/1718457.html