Bootloader Bringup



The Windows CE Bootloader

All devices running Windows CE require a small program - the bootloader - which loads the Windows CE kernel. The bootloader typically resides in flash, and loads CE from flash or a hard disk. ""OEMs"" are responsible for creating the bootloader, but Microsoft provides a rich set of libraries and sample code to make this task easier. Furthermore, you may write nearly all of your code in C. Only a very small portion is written in assembly language. In short: much of the heavy lifting is done for you. At a minimum, your bootloader should initialize enough hardware to launch the kernel (which is not much). But it doesn't end there: a bootloader usually supports many optional features:
* Download new CE images, which may be digitally signed
* Very basic device configuration
* Hardware diagnostics
If you want to get fancy, you can launch a 2nd-stage loader that is itself a bare-bones version of CE (a "Tiny Kernel" image). Because CE is fully componentized the 2nd stage can include whatever you want: support for removable media, filesystems, networking, and so on. At Microsoft the 2nd-stage loader is usually known as an IPL or Initial Program Loader. In this section we'll explain the architecture of a basic CE bootloader and provide detailed instructions for implementing one. We won't discuss the IPL; most devices don't need one.
We'll cover in detail:
* Hardware initialization
* Launching CE
* Downloading new images via Ethernet
* Digitally-signed images
* Sample code and libraries which do most of this for you

To keep it simple, we won't go into detail on:
* Downloading an image via USB (RNDIS)
* Compressed images
* Device configuration
* Hardware diagnostics
Adding those features is straight-forward if you want.


The Architecture of a CE bootloader

Microsoft does not dictate the design or feature set of your bootloader. However, we provide libraries and sample code which enable you to quickly implement a bootloader with the following features:
* Initialize basic hardware
* Launch CE image from flash or disk
* Download a new image via Ethernet or USB (RNDIS)
* Log debug messages (serial port or display)
* Bootloader configuration menu (serial port or display)
* Support for compressed images
* Support for digitally-signed images
You will need to fill in some device-specific code. Microsoft ships sample code for many common ""SoCs"" and peripherals. Examples of OEM-supplied code:
* Startup assembly - put CPU in Supervisor mode, enable MMU and caches, etc.

And if not supported by sample code:
* Functions to send and receive characters over a serial port
* Functions to send and receive packets over Ethernet or USB
* Functions to read and write flash memory

In turn Microsoft provides the following features:
* ""BLCommon"": a bootloader framework that supports signed and unsigned images
* ""BLMenu"": a text-based menu system to configure the bootloader
* TFTP: Trivial File Transfer Protocol for image download
* DHCP: obtain IP addresses automatically
* ""CECompress"": image compression/decompression
* ""LibC"": limitted support for the C Run-Time Library

@@Image("file://gadget/user/A-M/BBoBSP/Images/CEbootloaderdiagram.jpg", "Bootloader Overview")@@




BLCOMMON

BLCommon provides a complete bootloader framework, with support for downloading and launching signed and unsigned CE images. BLCommon calls OEM hooks to perform hardware-specific operations, such as reading data from Ethernet or writing it to flash.
Required OEM bootloader functions are listed in http://msdn2.microsoft.com/en-us/library/aa915114.aspx
Optional OEM bootloader functions are listed in http://msdn2.microsoft.com/en-us/library/aa909500.aspx
As the developer, you must write a bit of startup code in assembly. For example, you will put the CPU in Supervisor mode, disable interrupts, enable the caches, and create a stack. More about this later.
Once you've done that, you will call BootloaderMain(). BLCommon takes over from there; it will call OEM-supplied functions as needed. BLCommon is implemented in oalblcommon.lib and oalblcommon_secure.lib. The only difference between the two is support for downloading digitally-signed images. See the topic Secure Download Boot Loader for more information. For more on BLCommon refer to http://msdn2.microsoft.com/en-us/library/aa917240.aspx


BLMENU

BLMenu provides a simple text-based menu system for your bootloader. It can work over a serial port or the local display/keypad. In either case you must provide functions to read and write characters. BLMenu is typically used to cofigure bootloader options such as:
* Boot source (flash, Ethernet, hard disk, ...)
* Connection (DHCP or static IP address)
* Device ID (to connect to Platform Builder)

BLMenu is implemented in oal_blmenu.lib


SHARING INFORMATION WITH THE KERNEL

It's often useful for the bootloader to pass information to the operating system. This is normally done via a "Boot Arguments" structure, which is shared between the bootloader and OAL. Drivers and applications can query the OAL for this information via a variety of ""IOCTLs"", and you can add more if you want.
Examples of info passed in the Boot Arguments are:
* Hardware revision
* UUID (Universally-Unique Device ID)
* Device and settings to use for debugger and remote tools (KITL)
For more on Boot Arguments refer to http://msdn2.microsoft.com/en-us/library/aa915422.aspx
and BSP and OAL data structures



Implementing a Bootloader

We'll assume you want to leverage the BLCommon framework provided by Microsoft. Implementing a bootloader is best done (and tested) in stages. In general you will write code to:
* Initialize the CPU and memory controllers, disable interrupts, and create a stack
* Write and read characters over a serial port
* Send and receive data via Ethernet or USB (RNDIS)
* Read, erase, and write flash memory
The OEM functions to do this are clearly defined. BLCommon will invoke them to display a configuration menu, download images, and optionally save them to flash. If your device uses a CPU, UART, and Ethernet NIC supported by CE sample code, much of this may be done for you. You just need to piece it together. MSDN has detailed instructions for creating a bootloader using BLCommon. This information is loacted at http://msdn2.microsoft.com/en-us/library/aa908027.aspx"".""
Once you've completed the MSDN How-To, return here and learn how to add support for downloading digitally-signed images (Secure Download Bootloader).


Windows CE Secure Download Boot Loader

Once your bootloader is working and robust, it's time to add support for signed images.
<< TO DO: >>
* Why You Want Signed Images
* How Microsoft enables signed images
* Adding signed image support to your boot loader
* Signing images

For more information on Secure Download Boot Loaders, click here: http://msdn2.microsoft.com/en-us/library/bb202043.aspx
<< TO DO: >>



APPENDIX A: WINDOWS CE IMAGE FORMATS

* ""unsigned"".bin
* ""unsigned"".nb0
* ""signed"".bin
* ""signed"".nb0

APPENDIX B: SIGNING IMAGES

* ""ImageHash"".exe
* ""SDBLDump"".exe



Go up to BSP Introduction
Go up to BSP Bringup
Go up to Big Book of BSP

Thank you for contributing to this BSP Wiki. To ensure your comments and concerns receive proper exposure, include bspwiki""@""microsoft"".""com when providing feedback or topical suggestions.




Microsoft Communities