bulat-icon  Articles & Case Studies  
 
 

[+]  Articles

 
     
   

Booting Windows CE from Hard disk using PC BIOS

by Ashok Babu.K
 

Introduction

 
This document explains the build process for the Windows CE BIOS bootloader. The Windows CE image (NK.BIN) has to be loaded by the BIOS directly from the Hard disk, without any user intervention. The process should be like the way how a normal PC BIOS loads the OS from hard disk.

This BIOS boot loader component is responsible loading the Windows CE OS from the Hard disk and placing on the RAM and pass on control to it. This contains the Boot level file system support and reads the Windows CE image from the OS partition.

This document is derived out of Build instructions that are devised by e-con engineers during the development stage and also the compilation of mails MSDN Embedded newsgroups.
 

Scope

 
The scope of this document is limited to the steps involved in the building of the BIOS bootloader and the modifications done in the existing source code given by the Microsoft. The BIOS boot loader code is a standard X86 boot code and the changes done are very specific to the Buffer size.
 

Intended Audience

 
This document is intended for embedded engineers who are involved in the Windows CE development on PC platforms such as CEPC or any other PC-compliant platforms which has standard PC BIOS and hard disk.
 

Build Environment

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

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. Without this environment variables won’t be set and nothing can be built with the command line window.
     
    • For our case, we have a cepctest project of platform type CEPC.
    • Give the command as follows
      • wince.bat x86 cepctest CEPC
    • Please note that these arguments are case sensitive.
    • This will set up the environment variables for us to start the build process
  • Then go to PUBLIC\COMMON\OAK\CSP\X86\BIOSLOADER\LOADER directory.
  • Open the fat.h file and change the READ_BUFFER_LENGTH_MAX from 0x4000 to 0x3000
  • Then give build –c on the command line. This should build bldr file in the same directory. This should be of size 20kB
  • In case if the build fails, it might be because iniparse.lib is not built. If so go to PUBLIC\COMMON\OAK\CSP\X86\BIOSLOADER\INIPARSER directory and build that first. Then build the loader directory.
 

Making the Setup Disk

 
  • WE have to create the setup disk. This disk shall contain all the necessary stuff to make a hard disk partition bootable.
  • Go to the PUBLIC\COMMON\OAK\CSP\X86\BIOSLOADER\DISKIMAGES directory. Put a floppy on the A: drive and double click the SETUPDISK.144.
     
    • Before that you should have registered the .144 file. To do that, go to <INSTALL_PARTITION>:\Program Files\Windows CE Platform Builder\5.00\CEPB\UTILITIES. Run the file websetup.exe. This needs to be run only once. This will register the handler for the .144 files.
  • Once the setupdisk.144 runs successfully, you have your setup floppy disk ready. Open this floppy disk and replace BLDR with the BLDR that we had built with READ_BUFFER_LENGTH_MAX as 0x3000.
  • This floppy itself contains a file called boot.ini which specifies the some important parameters. Edit this file as given below:
     
    • Editing Boot.ini file
       
      • 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. The original one would be eboot.bix. Basically this states which OS image to use. We specify it as nk.bin and we keep a working WinCE OS image nk.bin in the hard disk.
      • Similarly set BakBinFile=eboot.bix
  • Copy this boot.ini file to setupdisk or keep it in another floppy. We have to copy this file also to the hard disk.
  • Now our setup disk is ready.
top-icon

Setting the Environment and Making the bootable hard disk

 
 
  • Now start your target board or CEPC with the setupdisk floppy that we had created just now.
  • Use fdisk to create partition the hard disk or CF or DiskOnChip from which you want to boot your Windows CE automatically.
  • Ensure that the Primary partition is less than 512MB. There are lots of discussions on the Newsgroups on this restriction. For our case, we keep the primary partition to 32MB, just to hold the nk.bin and registry. And set this primary partition as Active, again using fdisk. Let us call this primary partition as C:
  • Create and configure other partitions for your usage. For our case we create one more partition of remaining 220 MB.
  • During FORMAT steps to follow
     
    • Delete the present C: promt by selecting 3 in the choice given after u run fdisk
    • Then select 1 to create partition in that select I for primary and for 32MB
    • Make that one active by selecting 2 choice this will be u r C drive
    • Then create another extended partition for remaining memory in extended memory and that will be stored as D drive after that make that one by selecting choice 3
    • Then format the C and D drive .Otherwise u will get error if u run mkdisk
  • Once partitioning is done, run the mkdisk command with the argument C: i.e. as mkdisk C:
  • This will copy the bootsect.img and the bldr files from the floppy to the hard disk, in the proper sectors of the hard disk. Basically it is not simply copy, but a different operation. The bootsect.img is placed in the first sector, i.e., track zero, head zero, sector one of the hard disk or called as MBR. And another restriction is that BLDR is placed in contiguous sectors.
     
    • A small digression here. At power-on, the BIOS code performs POST.
    • The BIOS seeks out the boot disk and on a fixed disk, loads the first sector (the master boot record - MBR) on to RAM at 0000:7C00 (Real mode) and jumps to it A typical MBR code reads the available Operating systems and displays them to the user. It will load the corresponding loader for the OS selected by the user. This is known as two-stage bootloader. An example of that is GRUB.
    • In our case, we don’t have special MBR code that reads the available Operating Systems and displays to the user so that he can select any one. Our bootsect.img just looks for the bldr and loads the bldr to RAM and passes the control to it. In this process, so many transfer of code inside the RAM locations will take place.
    • This boot sector code is the first filesystem-specific bit of code and it's job is to locate, load, and bootstrap the OS (or in our case, the bldr).
    • This bootsector code only displays the string “Microsoft Windows CE BIOS Bootloader” on the screen.
    • If the bldr is not found, then it displays the error message “Unable to load BLDR!”
  • After this bldr code takes over and configures the screen, initiates the OS loading process. It also configures the debug serial port and sends out the debug messages at 38400 baud, no parity, 8bits of data and one stop bit. It then locates the nk.bin and loads the nk.bin and gives the control to it… and we get our Windows CE desktop!!! Before that we should have our working nk.bin on the boot partition. That is described next.
  • Once mkdisk is done, if you run dir /ash C: you can see the bldr on the C: drive
  • Now copy the boot.ini (which is edited by us), splash.bmx and eboot.bix files from the setupdisk floppy to C:
  • Now we are all set except the actual Windows CE image nk.bin
top-icon

Finally putting it all together

 
 
  • Now we are done with all the necessary stuff. We need to have a working nk.bin to boot from.
  • Another small digression here. This nk.bin will be placed in the boot partition and will be loaded by the bldr. This nk.bin should already have been tested. The important thing to note here is that this nk.bin should be shipping version. That is, this should be a 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 and this image is a shipping version of nk.bin
  • Now somehow copy this nk.bin to the C drive. In our environment we use the following technique
     
    • Copying the nk.bin
    • We create a test platform with hard disk, Ethernet and FTP enabled. We build the platform and we get the WinCE image. Let us call this as nkloader.bin
    • We use the CEPCBoot floppy and boot the target machine (or CEPC) and using Ethernet, we load our nkloader.bin and run it
    • Now we connect to the target machine and copy our shipping version of nk.bin through FTP
    • We copy this actual shipping version of nk.bin from the FTP home directory (by default it is in /Temp) to the boot partition of the hard disk (i.e. C: in our Windows CE, this will “My Device/Hard disk”). And we are done with that. Our nk.bin is on the boot partition
  • Now we are complete. Remove the floppy. Configure the BIOS to use the hard disk as the default boot device and reboot the target (or CEPC)
  • You should see you nk.bin loading and enjoy your Windows CE on your target board booting out of hard disk directly!!!
 

Action Item and Conclusions

 
The above instructions are tested on a fresh installation of Windows CE Platform Builder. The next step is to have the custom boot logo and our own boot progress bar. e-con Systems is specialized in Windows CE based solution, For Windows CE Driver development, please write to sales@e-consystems.com with the subject Windows CE driver Development. For Windows CE BSP Development, Please write to sales@e-consystems.com with the subject Window CE BSP Development.
 
 
top-icon