Virtualization is a mature technology that lets several operating systems share the physical resources of a machine, such that that each thinks it has exclusive use of the resources. Emulation means that a program impersonates another—or, in this case, that a processor impersonates another. I proposed virtualization as a way to run an instance of a Linux host on a Windows machine; Cygwin is software that emulates a POSIX system on a Windows machine. In this article, I look at software for emulating a target board. If the target processor happens to be an x86, the virtualization software is perfect for the task. However, when you're emulating a processor different than the host, you have fewer options. Emulating a different processor requires software that, in effect, translates the op-codes of the emulated processor into the op-codes for the host processor. There are some additional complications, such as sharing devices like video and network, but this article's focus is on how to use these tools and not the details of their construction.
In a word: convenience, but in two respects. The first convenience is that the target board is likely being developed at the same time as the software that's supposed to run on the board. Second, running in an emulator greatly reduces the complications of communicating with a remote target. A common practice in embedded engineering is to write code that is compiled and tested on the development host. This makes sense, because the C language is portable enough to make this possible. Although large amounts of code can be written, compiled using the native tools, and tested without the benefit of an emulator, some things, such as the following, require testing using the target processor or emulator:
• Inline assembly: This is the most obvious. Code that has inline assembly for an ARM target won't compile on that nice new quad core Intel 64 bit host, no matter how much you want it to.
• Endiannesss: This describes the byte order used to store data. In a big-endian system, the high-order bytes precede the low-order bytes; little-endian is the reverse. The date 2009-01-31 is big endian, whereas 31-01-2009 is little-endian.1 If endianness isn't agreed on, imagine the confusion with a date like 02-05-2009, where the month and day aren't obvious. This is an example to make plain the notion that endianness, as the internal storage format for a date in a computer, is usually an integer.
• Floating point: The floating-point capacities aren't the same for all processors and the emulator. One processor's very large number is another processor's overflow. Not many embedded systems need high precision, but the ones that do should take these limitations into consideration.
• Optimization: The GCC compiler is smart enough to optimize not only by refactoring and re-ordering the code but also by selecting machine instructions that execute more quickly. This means the classic speed for time optimization may be very different on the host than the target. Optimization is also likely to find bugs in the code generated by GCC
QEMU is a growing emulation project started by Fabrice Bellard. It's available for Linux and Windows hosts and emulated PowerPC, ARM, MIPS, and SPARC targets. QEMU takes the approach of providing a minimal translation layer between the host and target processor. The host processor is the one running the emulator, and the target processor is what's being emulated. QEMU also provides support for USB, serial, graphics, and network devices by mapping them to a real device on the host machine. For an embedded board, this support makes it possible for QEMU to be a reasonable stand-in for kernel and application development. In addition to being a useful tool to emulate an entire system, QEMU can also execute programs compiled from the target machine on the host machine. This means you can test or debug a program without starting an entire emulated system, thus making it even easier to quickly debug and test programs. QEMU provides both virtualization software and emulation. This article looks at using QEMU as an emulator. If the target machine happens to be the same as the host machine, the software performs virtualization, but that's an implementation detail. QEMU has a kernel module for accelerating virtualization; unless your target machine is also a x86, this feature isn't that helpful.
QEMU is available in source form; the site has precompiled binaries as well. In spite of the binary distribution, this is open source software, so knowing how to compile it is important in case a patch becomes available—or just because it's open source, and compiling from source is the right thing to do. QEMU requires GCC 3.0 in order to build. To check what version of GCC is currently installed, do the following:
$ gcc –dump-version 4.2.3
If it does present you with a 4.0 or higher version number, install the GCC 3.4 package. Don't worry about multiple GCC installations on the system. GCC installs as gcc-<version> and creates a symlink gcc that points at the newest version. If you set the environment variable CC to gcc-3.4, that executable is used instead of the most recent gcc:
$ apt-get install gcc-3.4 $ export CC=gcc-3.4
QEMU's build also requires some additional development libraries in order to build. Fetch these by doing the following on an Ubuntu or a Debian system:
$ sudo apt-get install libsdl-gfx1.2-dev zlib1g-dev
Start compiling QEMU by getting the source code at Bellard. The current version is 0.9.1; you can download it using wget, like so:
$ cd ~ $ wget http://bellard.org/qemu/qemu-0.9.1.tar.gz
Then, untar:
$ tar zxf qemu-0.9.1.tar.gz
Start the build process by doing a configure:
$ cd qemu-0.9.1 $ ./configure
Does this message appear?
WARNING: "gcc" looks like gcc 4.x Looking for gcc 3.x gcc 3.x not found! QEMU is known to have problems when compiled with gcc 4.x It is recommended that you use gcc 3.x to build QEMU To use this compiler anyway, configure with --disable-gcc-check
This message means the GCC installed on the system isn't a 3.x version. Check that GCC 3.4 has been installed, and make sure the environment has the CC variable set to gcc-3.4. Running configure with the –disable-gcc-check flag results in the configure step working correctly, but the compilation fails. After the configure step, typing
$ make $ sudo make install
builds and installs QEMU. For Windows users, a precompiled package is available at Dion. It's recommended that QEMU users on Windows start with this precompiled package.
Our website is not responsible for the information contained by this article. Articleinput.com is a free articles resource thus practically any visitor can submit an article. However if you notice any copyrighted material, please contact us and we will remove the article(s) in discussion right away.
Note: This article was sent to us by: Reggie Lang at 01232010
1. Explanation of the Embedded Linux development process
All articles are property of their respective authors. Please read our Privacy Policy!
© 2009 ArticleInput.com.