Rapid Prototyping with Windows XP Embedded
Microsoft® Windows® XP Embedded
Microsoft Virtual PC 2004
Windows Preinstallation Environment (Windows PE)
Summary: Rapid prototyping is an essential part of the planning and design stage of an embedded project. By providing early sample configurations to the customer, features and requirements can be adjusted according to the customer's environment. In many cases, prototypes also help coordinate the hardware development and software development in a project. The result is a significant and beneficial impact on time to market. This article describes how to set up a virtual build environment with minimal effort by using Microsoft Virtual PC and Windows PE on a development computer.
The initial phase of any software or embedded project includes many discussions and meetings with the customer's subject matter experts, developers, and project managers to establish the requirements of the application or the device. It is essential to incorporate into the product the different points of view that the members of the project team bring from their differing backgrounds.
A very helpful asset in incorporating customer feedback into the product is the use of prototypes, which serve as milestones and as a common ground for all the different specialists. A prototype enables the specialists to judge the look and functionality of the product and guides further progress. Using a prototype also helps the project team avoid heading in the wrong direction and improve ergonomics at an early stage. In addition, a prototype can be a convincing sales tool to alleviate the customer's concerns about the feasibility of a certain feature or to highlight the speed of the development process that the Microsoft® Windows® XP Embedded tools provide.
On mobile devices, developers can use the Microsoft Windows CE .NET emulation technology built into Platform Designer (the Windows CE .NET system development tool), which generates an operating system image ready to run in a virtual environment. This custom emulation can then easily be installed into Microsoft Visual Studio® .NET or be sent to the customer, expediting application development or enabling further design discussions.
This article shows how to achieve rapid prototyping for Windows XP Embedded by using Microsoft Virtual PC 2004 together with Windows Preinstallation Environment on CD 1 of Target Designer .
Because prototypes provide benefits at the early stages of a project, they must be:
- Not hardware dependent, because the hardware design may not be finished.
- Portable and easy to install for the customer or for the application development team.
- Realistic in how closely they will match the final product.
These requirements imply that you need a kind of generic hardware that can be distributed easily and that provides the flexibility to run the Windows XP Embedded image along with the applications needed in your project. The solution is Virtual PC 2004, which is the commercially available version of the technology also used for Windows CE .NET emulation.
Virtual PC emulates a complete x86-based computer running on your development computer that is equipped, for example, with Windows XP Professional as a host operating system. The guest system uses its own virtual processor, hard disks, and memory, while still having access to many important peripheral devices, such as CD-ROM, serial and parallel ports, video and sound devices, and (most important) the network card. The type of access to the peripheral devices is not a direct one; the emulation bridges between the dedicated physical device of the host system and, for example, the emulated network or video card of the guest operating system. For this reason, the drivers of the virtual hardware—not the drivers of the host operating system—must be used in the guest image. The virtual image hardware is then independent of the host system.
Note: Virtual PC has limitations regarding universal serial bus (USB) support (only USB keyboard and mouse are supported through PS/2 emulation) and does not support small computer system interface (SCSI). You can download a 45-day trial version from the Microsoft Virtual PC 2004 Web site.
To decrease development time, you need to have, in addition to Virtual PC, a simple and straightforward deployment mechanism to bring the Windows XP Embedded image onto your virtual device. Windows Preinstallation Environment is a good choice to fill this need. It is much more than a replacement for the outdated Microsoft MS-DOS® startup disk; it is a comprehensive toolkit that helps prepare the environmental conditions for Windows operating systems on your hardware. It provides El Torito support to start from CD, automatically enables networking, provides tools to create partitions and format the virtual drives, is scriptable, and even runs compiled HTML (.htc) applications to provide a user interface (if needed).
Windows PE is free on CD 1 of Target Designer, which automatically starts Windows PE if CD startup is enabled.
Building a Virtual PC prototype entails creating a virtual machine, using Windows PE to prepare the virtual machine, and building the Windows XP Embedded image. The following sections describe how to perform these tasks.
Creating a Virtual Machine
After you install a Microsoft Virtual PC 2004 setup routine, you need to configure a new virtual machine. Virtual PC offers support through a configuration wizard that takes you through the different steps.
To create a virtual machine:
- Specify the name of the virtual machine—for example, as "XPe_Prototype_MSDN."
- The wizard asks if it should guide you or generate a default virtual machine. For the current scenario, choose to follow the wizard.
- Select the guest operating system. Because there is no Windows XP Embedded entry in this list, just select Windows XP. This selection will work because Windows XP and Windows XP Embedded are binary compatible.
- Provide the amount of available random access memory (RAM). It is a good approach to choose a value that comes close to the actual situation on the device. If you provide too much memory, you may experience fast prototypes but, ultimately, a slow device. This situation is most likely to occur if your device is not as well equipped with memory as your development station is.
- Create a new virtual disk, specify the location of the related .vhd file, and finish the wizard. The overall result may look like the following figure.
Now you have the basic virtual hardware with an empty 16-gigabyte (GB) hard disk and 351 megabytes (MB) of RAM. The result of the wizard is a generic base configuration that can be used by anybody who uses Virtual PC. Thus, the configuration provides the exchangeability and mobility of the prototype set as a requirement at the beginning of this article.
Note: The amount of RAM has been chosen randomly for the prototype. You should use a RAM size comparable to the hardware configuration of the embedded device.
Preparing the Virtual Machine by Using Windows PE
After you configure the prototype device, you should insert CD 1 of Target Designer—which contains Windows PE—into the CD-ROM drive of the host computer. Additionally, check in the CD command that Virtual PC has captured the host CD drive, and when requested, press any key during startup to start from CD.
The virtual machine then starts in a Windows XP mini kernel, which starts the additional functionality of the Windows PE environment. Figure 2 shows the Windows PE command shell running on the virtual machine.
Figure 2. Windows PE command shell running on the virtual machine (click picture to see larger image)
To prepare the virtual machine for Windows XP Embedded, and to satisfy project requirements, you may need to create partitions on the empty hard disk and format the hard disk through a file system. In Windows PE, you use the Diskpart and Format tools to accomplish these tasks.
The usage of Diskpart is similar to a command-prompt-based File Transfer Protocol (FTP) client. After you start the Diskpart application, you can issue commands to manipulate the disk environment. Typing a question mark (?) or help gives an overview of the commands available. You can also script the tool through command-prompt parameters to help automate certain recurring processes.
To check partition information, you can use Diskpart commands as follows:
- To get a current list of the installed virtual disks in Diskpart, use the list disk command, as shown previously in Figure 2.
- To request the details of the disk object, type select disk 0 and then use the detail disk command. You should see that disk 0 has a size of 16 GB, is using the FAT32 file system, and is mapped to drive C.
- To ensure that the first partition is activated, type select partition 1 and then use the detail partition command. This step is important because Windows XP Embedded starts from the active partition only. The partition normally is activated, but if it is not, use the activate command to activate it.
If required in your project specification, you can use Diskpart to create additional partitions. In this sample case, you do not need additional partitions (or disks, which you can also configure if required), so you move on to the next task, formatting partition C through the NTFS file system.
To format the partition:
- Exit Diskpart by using the exit command.
- Type format c: /fs:ntfs /q at the command prompt. The options /fs:ntfs and /q specify the NTFS file system and format the partition quickly.
- Cross-check with Diskpart to prove that the partition has been formatted through NTFS.
This task completes the efforts to prepare the virtual machine, and you are now ready to create the operating system image for the prototype.
Building the Image
To ensure that the operating system is ready to use the virtual hardware, you must determine the hardware configuration for Target Designer by using the 32-bit Target Analyzer probe tool. There are two ways to get a valid hardware description file (.pmq) from Target Analyzer. One is to install Windows XP Professional on the virtual machine and run the tool. This approach will give you the most complete hardware information regarding Virtual PC. The other way is to start in Windows PE and then run Tap.exe on the virtual machine from a network share on your development computer. The hardware information returned by the second approach will not be as sophisticated as the information returned by the first approach, and it may include some Windows PE settings. However, the second approach is sufficient to run Windows XP Embedded on the virtual machine.
To start in Windows PE and run Tap.exe:
- Share the \Windows Embedded\Utilities folder in which Tap.exe resides.
- To increase security on your development computer, restrict the permissions by revoking permissions from the Everyone group and granting access to you only.
- Change back to the virtual machine and map the network share by using the net use command: net use s: \\name_of_your_virtual_machine\utilities
- Enter your user credentials when you are prompted, and then map the share to drive S on the virtual machine. Note that you must have a DHCP infrastructure to perform this step, because Windows PE gets the Internet Protocol (IP) address dynamically. If you do not have a DHCP server available, see the Tips and Tricks section later in this article.
- Change to drive S and run Tap.exe from there, generating on the share a Devices.pmq file, which contains the hardware information for the virtual machine.
With the help of the hardware information, you now can proceed to building the Windows XP Embedded image, as you would do for any real hardware device.
To build the image:
- Configure the image in Target Designer, adding the hardware information to the build environment either directly or through a component.
- Run all dependency checks and resolve the arising issues.
- Fine-tune the system according to the project requirements, and then build the Windows XP Embedded image.
Note: Be sure that the Target Designer project settings for the startup partition and disk match the virtual environment.
- Move the files locally from the local build directory to the network share, which is already mapped by Virtual PC in a subfolder (for example, a subfolder called Image). From this subfolder, use the xcopy command in Windows PE, as follows, to transport all the files of the image onto the virtual hard disk:
xcopy s:\Image\*.* c:\ /q /e /r /y /h
The xcopy options are as follows:
- /q Do not display the copied files.
- /e Copy files, folders, and subfolders, including empty ones.
- /r Overwrite read-only files.
- /y Suppress confirmations to overwrite a file.
- /h Copy hidden and system files. (This option is important; Windows XP Embedded will not start if system files are missing.)
- After all the files have been copied, reset the virtual machine and do not start from CD.
You should see Windows XP Embedded and First Boot Agent (FBA) start. FBA prepares the embedded operating system to be fully functional and restarts the operating system one time. When FBA has completed, the prototype is ready to be used to demonstrate certain Windows XP Embedded features, such as Enhanced Write Filter and custom shells. If the application developers have Virtual PC 2004, you can pass the complete virtual image to the developers so that they can test their applications on an operating system image that is very similar to the final one. This testing is especially helpful in determining missing components in the image that the application requires.
Figure 3 shows an example of a Windows XP Embedded prototype running on a virtual machine.
Figure 3. Windows XP Embedded prototype running on a virtual machine (click picture to see larger image)
If your device is equipped with custom hardware, you can even write and install driver stubs on the virtual machine to emulate the behavior of the custom hardware. This task requires additional effort, but the effort might be worthwhile if the hardware is not ready to use and if you are not able to wait to start application development.
Tips and Tricks
The build and deployment scenario described previously works well if you are in a network environment that supports DHCP. Windows PE, when starting from CD 1 of Target Designer, requires a DHCP server to acquire an IP address. In addition, you need a valid IP connection to the share that contains the Windows XP Embedded tools and that serves as the source of the Windows XP Embedded image for copying onto the embedded device. The drawback here is that at the customer's site you rarely have this infrastructure available, so the demonstrated scenario will not work. In addition, the built-in network card on your laptop will not work, because you will not have a network cable in combination with a network hub. You can bring a small hub and a cable to the customer's site, but DHCP will still be missing.
To solve these problems, you need to do two things: install Microsoft Loopback Adapter and configure Windows XP to offer a DHCP service.
Installing Loopback Adapter
Loopback Adapter is a software network card that reroutes network traffic to Windows Redirector for simulating a fully functional network. Loopback Adapter is part of any Windows XP Professional standard installation; you just have to install it by using the Add Hardware tool in Control Panel.
To install Loopback Adapter:
- In Control Panel, double-click Add Hardware.
- Click Next.
- In the Is the hardware connected box, click Yes, I have already connected the hardware, and then click Next.
- In the list of installed hardware, click Add a new hardware device, and then click Next.
- In the next dialog box, click Install the hardware that I manually select from a list (Advanced), and then click Next.
- In the Common hardware types list, click Network adapters, and then click Next.
- In the Manufacturer list, click Microsoft, click Microsoft Loopback Adapter in the Network Adapter list, and then click Next.
- Click Next again.
- To complete the Add Hardware Wizard, click Finish.
After you install Loopback Adapter, you do not need to bring a hub and a cable with you.
Configuring Windows XP to offer a DHCP service
To configure Windows XP to offer a DHCP service, you can apply a trick that Windows CE .NET developers use. Windows CE .NET needs a DHCP server to download the Windows CE image on the custom hardware. If there is no DHCP sever available, the following special configuration of Windows XP can provide this functionality:
- In the Network Connections item in Control Panel, create a new modem connection (this works even if no modem is installed on your computer).
- In the MSN Modem Properties dialog box for the connection, on the Advanced tab, set up a shared modem connection as shown in Figure 4.
Figure 4. Sharing a modem connection to get a DHCP server on the development computer
- At the moment you share this connection, Windows XP automatically offers a DHCP server for the local subnet. Make sure that you share Loopback Adapter under Home networking connection, as shown in Figure 4. This action automatically sets the IP address of the adapter to 192.168.0.1 (with a subnet mask of 255.255.255.0) to serve as the standard gateway for all local traffic.
- Configure Virtual PC to use Loopback Adapter for all external traffic. You can perform this step in the main application of Virtual PC by clicking File, and then clicking Preferences, as shown in Figure 5.
Figure 5. The Preferences command
- The Virtual PC Preferences dialog box appears. In this dialog box, you can configure Loopback Adapter for all traffic external to the virtual machine, as shown in Figure 6.
Figure 6. Configuring Loopback Adapter for all traffic external to the virtual machine (click picture to see larger image)
After this minor system reconfiguration, you are able to work in your own subnet on your laptop at customer demonstrations or presentations with DHCP and as many virtual machines on your laptop as you want.
Note: To avoid disturbing the DHCP infrastructure in your organization, disable the DHCP server when you return to your organization's network by clearing the sharing options of the modem connection.
As shown in this article, rapid prototyping is available for Windows XP Embedded with minimal effort through Virtual PC 2004 and Windows Preinstallation Environment. The benefits of prototypes include holding convincing technology presentations at the customer's site and expediting the development process by coordinating the hardware development and software development tasks.
In developing your project, you must eventually use a real hardware configuration file or component to generate a hardware-specific Windows XP Embedded image. Even if everything runs well in the emulation, deploying an image on the final hardware will likely cause some problems to arise. However, if you carefully set up the environment for the prototypes, any problems should be minor.
For more information about Windows XP Embedded, see the Windows Embedded Web site.
For online documentation and context-sensitive Help included with Windows XP Embedded, see the Windows XP Embedded product documentation.