Booting Windows CE from a hard drive through PC...

Introduction

This article explains the build process for the Windows CE BIOS bootloader and is derived from build instructions developed by engineers at e-con Systems together with a collection of postings on the MSDN Embedded newsgroups. It is intended for embedded engineers who are involved in the development of Windows CE using CEPC on PCs, or on other PC-compliant platforms that have a standard PC BIOS and hard disk.

The Windows CE image (NK.BIN) is loaded by the BIOS directly from the hard disk, without any user intervention, in a process similar to the way a normal PC BIOS loads the OS from hard disk. This BIOS boot loader component is responsible for loading the Windows CE OS from the OS partition on the hard disk into RAM, and passing control to it.

Scope

This article is limited to the steps involved in the building of the BIOS bootloader and the modifications done in the existing source code provided by Microsoft. The BIOS boot loader code is a standard x86 boot code and the changes made are very specific to the buffer size.

Build Environment

The build environment is Windows CE 5.0 Platform Builder. We have used both a normal PC as a CEPC platform and an x86-based PC-compliant target board from ICOP. The build instructions have been tested on both platforms.

Building the BIOS Bootloader (BLDR)
Start the Windows CE 5.0 Command Prompt

Go to Public\common\oak\misc

Run the WinCE.bat file with the target cpu type, project name and platform name:

wince.bat x86 cepctest CEPC
Note that the arguments are case sensitive. This sets up the environment variables for the build process.

Go to PUBLIC\COMMON\OAK\CSP\X86\BIOSLOADER\LOADER

Open the fat.h file and change the READ_BUFFER_LENGTH_MAX from 0x4000 to 0x3000

Then enter build –c on the command line. This should build the BLDR file in the same directory with a size of 20 KB

If the build fails, it might be because iniparse.lib is not built. If so go to PUBLIC\COMMON\OAK\CSP\X86\BIOSLOADER\INIPARSER and build that first. Then build the loader directory
Making the Setup Disk

It is necessary to create a setup diskette that contains all the necessary components to make a hard disk partition bootable. Before creating the setup diskette, the handler for ".144" files must be registered through the following one-time-only operation:
Go to lt.gifINSTALL_PARTITIONgt.gif:\Program Files\Windows CE Platform Builder\5.00\CEPB\UTILITIES

Execute websetup.exe
With that step out of the way, create the setup diskette as follows: Go to PUBLIC\COMMON\OAK\CSP\X86\BIOSLOADER\DISKIMAGES

Put a floppy in the A: drive and double click SETUPDISK.144.

After setupdisk.144 runs successfully, the setup diskette is ready. Open the diskette and replace BLDR with the BLDR built in the previous section with READ_BUFFER_LENGTH_MAX as 0x3000.
Editing the Boot.ini file

The setup diskette contains a file called boot.ini that specifies a number of important parameters. Edit this file as follows:
Change the DisplayWidth, DisplayHeight and DisplayDepth to suit your requirements. For our board we set them as 1024, 768, 16

Change the line BinFile=eboot.bix to BinFile=nk.bin. This specifies which OS image to boot. We specify it as nk.bin and keep a working Windows CE OS image nk.bin in the hard disk.

Set BakBinFile=eboot.bix

Copy this boot.ini file to the setup diskette or keep it in another floppy. It will also be copied to the hard disk.
Setting the Environment Start the target board or CEPC with the just created setup

Use fdisk to create a partition on the hard disk or CF or DiskOnChip from which Windows CE will boot automatically.

Ensure that the Primary partition is less than 512MB. There is much discussion in the newsgroups on this restriction. For our case, we keep the primary partition to 32MB, just enough to hold nk.bin and the registry. Set this primary partition as Active, again using fdisk. Let us call this primary partition C:

Create and configure other partitions as necessary. For our case we create one more partition from the remaining 220 MB.

The detailed fdisk steps are:
  • Delete the present C: partition by selecting 3 in the fdisk menu
  • Then select 1 to create a partition, select 1 again for primary partition and set the size to 32 MB
  • Make that partition active by selecting 2. This creates the C: drive
  • Create another extended partition for the remaining storage space. This becomes the D: drive
  • Format the C and D drives

Once partitioning is complete, run the mkdisk command with the argument C: i.e. mkdisk C: mkdisk copies the bootsect.img and the BLDR files from the diskette to the proper sectors of the hard disk. bootsect.img is placed in the first sector, i.e., track zero, head zero, sector one of the hard disk, also called the MBR (Master boot Record). BLDR is copied to contiguous sectors.

After running mkdisk, copy the boot.ini (that was edited above), splash.bmx and eboot.bix files from the setup diskette to C:

nk.bin

The final problem is to get an appropriate Windows CE image, nk.bin, onto the hard disk. This nk.bin will be placed in the boot partition to be loaded by BLDR. It should be a thoroughly tested release version with no debugging support.

To make this, go to Platform->Settings menu on the Windows CE Platform Builder (with your platform workspace loaded). Go to the Build Options tab and uncheck all the check boxes. Build the image, which is a release version of nk.bin.

This nk.bin must somehow be copied to the boot partition on C:. Here's how we do it:
Create a test platform with hard disk, Ethernet, and FTP enabled. We build the platform to get a Windows CE image that we'll call nkloader.bin

Use the CEPCBoot diskette to boot the target machine (or CEPC) and use Ethernet to load and run nkloader.bin

Connect the test platform to the target machine and use FTP to copy the release version of nk.bin from the FTP home directory (by default /Temp) to the boot partition, C:, of the hard disk

Remove the diskette

Configure the BIOS to use the hard disk as the default boot device and reboot the target (or CEPC)
The boot process

At power-on, the BIOS loads the master boot record into RAM at 0000:7C00 (Real mode) and jumps to it. Typical MBR code reads the available operating systems and displays them to the user. It then loads the corresponding loader for the OS that the user selects. This is known as a "two-stage bootloader," an example being GRUB.

In our case, the MBR code simply looks for BLDR, loads it into RAM, and passes control to it. There is no interaction with the user, the boot code just displays the string "Microsoft Windows CE BIOS Bootloader" on the screen. If BLDR is not found, it displays the error message "Unable to load BLDR!"

Next, BLDR takes over and configures the screen, initiates the OS loading process, and configures the debug serial port. It then locates and loads nk.bin and gives the control to it. This finally brings up the Windows CE desktop, and we're done.

Troubleshooting the BIOS loader

If the loader is not able to load the OS, or configure the display, for example, it will output appropriate error messages on serial port COM1. COM1 is configured for 38.4 kbaud, 8 data bits, 1 stop bit, no parity and no flow control. The loader outputs error, warning, and info codes only unless it is built in debug mode with FULLMESSAGES defined.

The full text corresponding to the error codes is found in the file debug.h located at WINCE500\PUBLIC\COMMON\OAK\CSP\X86\BIOSLOADER\LOADER. When FULLMESSAGES is defined the text in debug.h is built into the loader binary.

If the loader reports that it can't load the bootloader it may be useful to format the partition again to be sure the BLDR file is stored on contiguous sectors. Also note that the loader size is fixed and defined by the symbol READ_LENGTH. If you add code to the loader it may be necessary to update this setting.

A search of groups.google.com using the error message can often yield helpful hints.

The next step is to have a custom boot logo and our own boot progress bar.

转载于:https://my.oschina.net/panzerwl/blog/14140

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实验目标: 本实验的目标是完成一个可以在QEMU仿真器上运行的x86操作系统。具体地说,我们将编写引导扇区代码和内核代码,并将它们组合成一个可引导的磁盘映像。最后,我们将使用QEMU仿真器启动我们的操作系统。 实验步骤: 1. 准备工作 准备工作包括安装必要的软件和工具、下载实验代码和文档等。 2. 编写引导扇区代码 引导扇区是操作系统的第一个扇区,它需要被放置在磁盘的第一个扇区。引导扇区必须包含一个512字节的主引导记录(MBR),其中包括一个引导程序和分区表。我们需要编写一个能够在引导扇区中运行的汇编代码,它将加载内核并将控制权转交给内核。 3. 编写内核代码 内核是操作系统的核心部分,它负责管理计算机的硬件资源、提供系统调用接口等。我们需要编写一个简单的内核,该内核将输出“Hello, world!”并进入无限循环。我们可以使用C语言编写内核代码,并使用GCC编译器将其编译成汇编代码。 4. 构建磁盘映像 我们需要将引导扇区和内核代码组合成一个可引导的磁盘映像。为此,我们可以使用dd命令将引导扇区和内核代码写入一个空白磁盘映像中。 5. 启动操作系统 最后,我们需要使用QEMU仿真器启动我们的操作系统。我们可以使用以下命令启动QEMU并加载磁盘映像: ``` qemu-system-i386 -hda os.img ``` 实验结果: 经过以上步骤,我们成功地编写了一个简单的操作系统,并使用QEMU仿真器进行了测试。当我们启动操作系统时,它将输出“Hello, world!”并进入无限循环。 实验总结: 本实验让我了解了操作系统的基本概念和架构,并学会了如何编写一个简单的操作系统。通过实验,我更深入地理解了计算机系统的底层原理,对操作系统的工作原理有了更深入的了解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值