 |
Build Recipe: OpenWRT
OpenWRT is a Linux platform for embedded devices like routers.
Originally OpenWRT was based on Wi-Fi routers from Linksys.
Then it was extended to support Broadcom (MIPS) SoC chipsets
and now it even supports non-MIPS devices.
Because it provides platform support for connected embedded devices,
OpenWRT is a natural and useful example to illustrate
how easy it is to adapt Java ME technology to Linux-based network devices.
These notes describe how to build phoneME Advanced Foundation Profile
for the OpenWRT platform.
Platform Notes
OpenWRT has many useful features for an embedded software platform
including a simple package management system (IPKG),
a template-based build system for generating ROM images
as well as target toolchains.
The OpenWRT runtime software includes many modern embedded software features:
-
2.6 Linux kernel
-
uClibc,
a small-footprint POSIX library
-
BusyBox,
a shared binary for common UNIX utilities
-
JFFS2,
a read/write Flash ROM-oriented filesystem
-
SquashFS,
a read-only Flash ROM-oriented filesystem
-
Itsy Package Management System (IPKG),
an embedded package management system
-
X-WRT,
a web management console
As a platform, OpenWRT provides several core and optional
network services and applications.
For example,
-
dnsmasq, a DNS forwarder and DHCP server
-
iptables, a packet filtering firewall system
-
dropbear, a lightweight SSH client and server
-
various web servers
-
NFS & Samba support
-
USB support
Many of these services and applications are available through the
IPKG
package management system.
Some, like NFS and USB support,
require optional kernel modules.
|
Note:
OpenWRT has two major versions:
the more recent Kamikaze version supports
the Linux 2.6 kernel and a wider variety of chipsets and devices
and the now legacy White Russian version supports
the Linux 2.4 kernel and mostly Broadcom chipsets.
These notes cover the Kamikaze version of OpenWRT.
|
Build System Setup
Required Developer Tools
OpenWRT has a powerful build system that compiles its own toochain for a target platform.
That means that when OpenWRT adds support for a new device it includes the procedures for configuring and building a gcc-based toolchain for cross-compiling.
In fact, OpenWRT can build a relocatable SDK for a specific target.
As we will see, this makes build system setup much easier for phoneME Advanced.
|
Note:
The only non-standard OpenWRT package required by phoneME Advanced is
libpthread.
|
|
Note:
The OpenWRT toolchain is built by the OpenWRT build system and located in
build_dir/mipsel/OpenWrt-SDK-brcm47xx-for-Linux-i686
in the OpenWRT distribution layout.
While it should also be possible to use the standalone OpenWRT SDK from
downloads.openwrt.org,
the versions there are somewhat out of date and
when building from trunk it's better to build with a more up to date version of the SDK.
|
Required Project Components
After installing and updating the required developer tools for the CDC
build system,
you can get the project source code
by either downloading the project source code bundle (appropriate for
evaluation purposes)
or checking out the project source code from the repository.
These procedures are described in
Getting the Project Source Code.
The required phoneME Advanced project components for building Foundation
Profile are:
Building phoneME Advanced
Create a build driver script and make it executable
The following script builds a basic Foundation Profile target:
#!/bin/sh
make \
J2ME_CLASSLIB=foundation \
CVM_JIT=true \
CVM_OPTIMIZED=true \
CVM_PRELOAD_LIB=true \
CVM_BUILD_SUBDIR_NAME=cdc-fp \
JDK_HOME=/usr/java/j2sdk1.4.2_15/bin/ \
CVM_TARGET_TOOLS_PREFIX=/home/developer/openwrt/build_dir/\
mipsel/OpenWrt-SDK-brcm47xx-for-Linux-i686/staging_dir/\
toolchain-mipsel_gcc4.1.2/bin/mipsel-linux-uclibc-
After modifying this script it can be invoked as follows:
$ sh < build-fp.sh >& err &
Create the CDC IPKG archive
-
Create a directory for staging the CDC IPKG archive.
$ export OPENWRT_PACKAGE_DIR=$OPENWRT_DIR/build_dir/mipsel/OpenWrt-SDK-brcm47xx-for-Linux-i686/package/cdc
$ mkdir $OPENWRT_PACKAGE_DIR
-
Stage the layout for the CDC IPKG archive
with the following hierarchy:
Makefile
files/
usr/
java/
cdc/
democlasses.jar
testclasses.zip
bin/
cvm
lib/
...
-
files
is a directory that contains the runtime files for the package.
-
Makefile drives the packaging process by the OpenWRT SDK:
include $(TOPDIR)/rules.mk
PKG_NAME:=pmea-fp
PKG_VERSION:=1_1_2
PKG_RELEASE:=b04
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
include $(INCLUDE_DIR)/package.mk
define Package/pmea-fp
SUBMENU:=Java
SECTION:=lang
CATEGORY:=Languages
DEPENDS:=+libpthread
TITLE:=CDC Java runtime environment
endef
define Package/pmea-fp/description
phoneME is an open source project based on Java Micro Edition (Java ME) \
technology. phoneME Advanced is a phoneME project based on Java ME CDC \
technology targeting resource-constrained devices like smartphones, \
set-top boxes and office equipment. See https://phoneme.dev.java.net \
and http://java.sun.com/products/cdc
endef
define Build/Compile
endef
define Package/pmea-fp/install
$(INSTALL_DIR) $(1)/usr/java/cdc
$(CP) files/usr/java/cdc $(1)/usr/java
endef
$(eval $(call BuildPackage,pmea-fp))
-
Copy the files
that are generated by the CDC build system
to the staging directory:
$ cd pmea-fp
$ cp -r bin lib democlasses.jar testclasses.zip $OPENWRT_PACKAGE_DIR
-
Build the CDC IPKG archive:
$ cd OpenWrt-SDK-brcm47xx-for-Linux-i686
$ make
The new CDC package is in
OpenWrt-SDK-Linux-i686-1/bin/packages/mipsel/pmea-fp_1_1_2-b04_mipsel.ipk.
Runtime Examples
After the build process successfully finishes,
the CDC Java runtime environment
is available as runtime executable located in a few target directories,
most importantly the bin and lib directories.
-
Copy the CDC package to the device:
$ scp OpenWrt-SDK-Linux-i686-1/bin/packages/mipsel/pmea-fp_1_1_2-b04_mipsel.ipk root@192.168.1.1:/tmp
-
Remotely login to the target device:
$ ssh root@192.168.1.1
-
Install the CDC package:
$ ipkg install /tmp/pmea-fp_1_1_2-b04_mipsel.ipk
-
Run a test program:
$ /usr/java/cdc/bin/cvm -cp /usr/java/cdc/testclasses.zip Test
|