Embedded Java with GCJ
Getting and Unpacking Crosstool
Crosstool is the creation of Dan Kegel. You can find out everything you want to know about crosstool by visiting kegel.com/crosstool. The page has a great quick start guide as well as complete documentation. This article used version 0.38 available at kegel.com/crosstool/crosstool-0.38.tar.gz.
On the crosstool home page, check out the buildlogs link (kegel.com/crosstool/crosstool-0.38/buildlogs) to see what combinations of glibc/gcc successfully build for your target architecture.
The first thing to compile with your newly minted cross compiler is the root filesystem. The root filesystem, in this case, is compliments of BusyBox. For the uninitiated, BusyBox is a single binary that encapsulates mini versions of the most popular UNIX utilities in a surpassingly small executable. Built for people that count bytes, BusyBox has hundreds of knobs to turn to create a filesystem with the utilities you need within your desired space constraints. For the purpose of this article, we change the BusyBox configuration so that it cross compiles, leaving size optimization as an exercise for the reader.
BusyBox is a mainstay of the embedded Linux world and is maintained by Erik Anderson. One way to get BusyBox is to download it at www.busybox.net/downloads/busybox-1.01.tar.bz2.
To create a BusyBox root filesystem, you need to invoke make menuconfig in the directory where BusyBox was untarred. The menuconfig program works just like the 2.4/2.6 menuconfig kernel configuration interface. Here's what you'll need to do to build the root filesystem.
First, select the build options. Check the Do you want to build BusyBox with a Cross Compiler? box. Fill in the prefix of the cross compiler in the input control that appears when you click this option, in this case, powerpc-750-linux-gnu-. The BusyBox build scripts concatenate the necessary tool name during compilation (gcc, ld and so on). Make sure that the compiler is on your $PATH.
Next, run make and install:
make make install
BusyBox puts the newly minted root filesystem at ./_install. You'll notice that BusyBox compiles in much less time than GCC.
Almost there! The root filesystem BusyBox creates does not contain any libraries. GCJ programs require some libraries and so does BusyBox, shown in Table 1.
Table 1. Libraries Required by GCJ and BusyBox
|ld.so.1||Dynamically linked file loader. Invoked when the program is run, loads required libraries and performs dynamic linking.|
|libdl.so.2||Helper functions for manipulating dynamic libraries.|
|libgcc_s.so.1||Defines interfaces for handling exceptions.|
|libgcj.so.6||The GCJ run-time library. Contains implementations of the standard Java library.|
|libm.so.6||Library of math functions.|
|libpthread.so.0||POSIX threads library.|
These libraries match those used by the cross compiler. In this case, the files are stored in the $RESULT_TOP/gcc-4.0.1-glibc-2.2.2/powerpc-750-linux-gnu/powerpc-750-linux-gnu/lib (not a typo!) directory. The easiest way to get them into the root filesystem is simply to copy them:
for f in ld.so.1 lib libdl.so.2 libgcc_s.so.1libgcj.so.6 libm.so.6 libpthread.so.0 ; do cp $RESULT_TOP/gcc-4.0.1-glibc-2.2.2/powerpc-750-linux-gnu/powerpc-750-linux-gnu/lib/$f <busybox install directory>/lib $RESULT_TOP/gcc-4.0.1-glibc-2.2.2/powerpc-750-linux-gnu/bin/power pc-750-linux-gnu-strip <busybox install directory>/lib/$f done
You also need to create a folder in the root filesystem, /proc, to use as a mountpoint for the proc filesystem. Keen eyes will notice that I'm not preserving the symlinks used to accommodate different versions of the libraries—that's a shortcut typical in embedded systems where library configuration won't change over the life of the device, unlike a desktop system. Running strip greatly reduces the amount of disk space required by the files, almost by 50%.
At this point, the root filesystem can be copied to the target system into the /tmp/bbox directory. To tell the system to use this as the root filesystem, start a terminal as root and execute the chroot command:
chroot /tmp/bbox /bin/ash
This command remaps the / mountpoint into /tmp/busybox and runs /bin/ash to get a terminal. Did it work? Congratulations! You've created a complete root filesystem for an embedded system from scratch. Pat yourself on the back.
GCJ also needs the proc filesystem mounted. After the chroot, you need to remount the proc filesystem into the current root filesystem by doing the following:
mkdir /proc mount -t proc none /proc
Although this root filesystem resides on a standard drive, the root filesystem deployed on a production embedded system wouldn't be much different. The only changes necessary would be creating inittab, so the board will run the right scripts at the start and add a /dev filesystem with the right device files for the target board.
|Speed Up Your Web Site with Varnish||Jun 19, 2013|
|Non-Linux FOSS: libnotify, OS X Style||Jun 18, 2013|
|Containers—Not Virtual Machines—Are the Future Cloud||Jun 17, 2013|
|Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer||Jun 12, 2013|
|Weechat, Irssi's Little Brother||Jun 11, 2013|
|One Tail Just Isn't Enough||Jun 07, 2013|
- Speed Up Your Web Site with Varnish
- Containers—Not Virtual Machines—Are the Future Cloud
- Linux Systems Administrator
- Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer
- Non-Linux FOSS: libnotify, OS X Style
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- RSS Feeds
- Reply to comment | Linux Journal
1 hour 48 min ago
- Yeah, user namespaces are
3 hours 5 min ago
- Cari Uang
6 hours 36 min ago
- user namespaces
9 hours 29 min ago
9 hours 55 min ago
- One advantage with VMs
12 hours 24 min ago
- about info
12 hours 57 min ago
12 hours 58 min ago
12 hours 59 min ago
13 hours 1 min ago
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?