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 INSTALL_PARTITION:\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.

你可能感兴趣的:(Booting Windows CE from a hard drive through PC...)