Sie sind auf Seite 1von 5

Java for embedded Linux systems Training lab book

Java for Linux embedded systems Training lab book Thomas Petazzoni, Michael Opdenacker Free Electrons http://free-electrons.com

2008- 2009,

ree !le"trons, #tt$%&&free-ele"trons'"om, (reative (ommons Li"ense

Java for embedded Linux systems Training lab book

About this document


T#is do"ument is $art of an embedded Linux training from ree !le"trons' )ou *ill find t#e *#ole training materials +slides and lab book, on #tt$%&&free-ele"trons'"om&training Lab data "an be found on #tt$%&&free-ele"trons'"om&labs&embedded-linux'tar'b.2'

Copying this document


2008-2009, ree !le"trons, #tt$%&&free-ele"trons'"om' T#is do"ument is released under t#e terms of t#e (reative (ommons /ttribution0#are/like 1'0 li"ense' T#is means you are free to do*nload, distribute and even modify it, under "ertain "onditions' 2o"ument u$dates and translations available on #tt$%&&free-ele"trons'"om&do"s&3ava' (orre"tions, suggestions, "ontributions and translations are *el"ome4

Training setup
0ee t#e training labs on #tt$%&&free-ele"trons'"om&do"s&kernel for setu$ instru"tions, *#i"# are s#ared *it# t#ese $ra"ti"al labs'

2008-2009,

ree !le"trons, #tt$%&&free-ele"trons'"om, (reative (ommons Li"ense

Java for embedded Linux systems Training lab book

Java lab
5b3e"tive% (ross-"om$ile and install a Java "lass library and virtual ma"#ine

/fter t#is lab, you *ill be able to (ross-"om$ile and install t#e 678 (lass$at# "lass library (ross-"om$ile and install t#e Jam9: virtual ma"#ine, a lig#t*eig#t 9: for embedded systems (om$ile and run sim$le text-only Java a$$li"ations, on an /;: target'

Environment setup
<n /mnt/labs/java/lab1/, you *ill find% / data/nfsroot/ dire"tory, t#at "ontains a root filesystem t#at you *ill use as a base for t#is lab' <t "ontains a =usybox installation, t#e basi" libraries asso"iated to t#e "ross-"om$iling tool"#ain, and t#e >lib library, re?uired by Jam9:' / data/zImage file, *#i"# is an /;: kernel for t#e ;ealvie* $latform emulated by @emu' T#e kernel su$$orts booting *it# t#e root filesystem over 7 0' / run_qemu s"ri$t t#at allo*s to run t#e @emu emulator *it# t#e "orre"t arguments :ake sure t#at your 7 0 server ex$orts /mnt/labs/java/lab1/nfsroot/, and try to run @emu *it# t#e run_qemu s"ri$t' )ou s#ould a""ess a s#ell $rom$t, t#anks to =usybox' To "om$ile t#e "lass library and t#e virtual ma"#ine, you *ill need a "ross-"om$iling tool"#ain t#at mat"#es t#e given root filesystem' To install su"# a tool"#ain, add t#e follo*ing line to your /etc/apt/sources.list file% deb http://www.free-electrons.com/labs/ubuntu/ ./ T#en, run apt-get update and apt-get install buildrootuclibc-arm-toolchain T#e tool"#ain is no* installed in /usr/local/uclibc-0.9.282/arm/' /dd t#e /usr/local/uclibc-0.9.28-2/arm/bin/ dire"tory to your $at#, so t#at t#e arm-linux-* tools "an be easily used for "ross-"om$iling'

Class library
T#e "lass library *e *ill use is 678 (lass$at#, available from #tt$%&& ***'gnu'org&soft*are&"lass$at#&' 2o*nload version 0'9A'2, t#at *e tested for t#is lab, and un"om$ress t#e tarball' :ost of "lass library is im$lemented in Java, so *e need to install a Java "om$iler' 0u"# a "om$iler is available in t#e java-gcj-compatdev in 2ebian and 8buntu distributions' Be donCt need a Java "ross"om$iler be"ause Java byte"ode is $ortable4

2008-2009

ree !le"trons, #tt$%&&free-ele"trons'"om

(reative (ommons Li"ense

Java for embedded Linux systems Training lab book 7o*, "onfiguring 678 (lass$at# is done using t#e "lassi"al "onfigure s"ri$t% ./configure --host=arm-linux --prefix=/usr --disable-gtkpeer --disable-gconf-peer disable-plugin Be disable t#e 6TD $eer so t#at t#e su$$ort for gra$#i"al a$$li"ations is not "om$iled in, and t#e set of de$enden"ies is redu"ed' Be also remove t#e de$enden"y on 6"onf, and disable t#e "om$ilation of t#e Beb $lugin' T#en, "om$ile by sim$ly running make /fter t#e "om$ilation $ro"ess, you "an install 678 (lass$at# to t#e target root filesystem using% make DESTDIR=/mnt/labs/java/lab1/data/nfsroot/ install Take a look at t#e files installed by 678 (lass$at#' T#ere are some native "ross-"om$iled libraries in /usr/lib/classpath/, but t#e most im$ortant $art is t#e /usr/share/classpath/glibj.zip file, *#i"# "ontains t#e im$lementation of many standard Java "lasses'

Compiling the virtual machine


2o*nload Jam9: 1'E'1 from its offi"ial *ebsite, #tt$%&&3amvm'sour"eforge'net&' 8n"om$ress t#e tarball and "onfigure Jam9: as follo*s% CPPFLAGS=-I/mnt/labs/java/lab1/data/nfsroot/usr/include/ LDFLAGS=-L/mnt/labs/java/lab1/data/nfsroot/usr/lib/ ./configure --host=arm-linux --prefix=/usr withclasspath-install-dir=/usr Be need to set CPPFLAGS and LDFLAGS to allo* t#e "onfigure s"ri$t to find t#e >lib library, used by t#e Java virtual ma"#ine to o$en t#e .zip files *#i"# "ontains t#e standard Java "lasses of t#e "lass library' /fter t#e "onfiguration ste$, "om$ile Jam9: by running make, and install it using% make DESTDIR=/mnt/labs/java/lab1/data/nfsroot/ install

Testing our Java installation


<n /mnt/labs/java/lab1/data/nfsroot/root/, "reate a ne* Test.java file t#at "ontains% class Test { public static void main(String args[]) { System.out.println("This is a test"); } } T#en, "om$ile t#is Java a$$li"ation using ecj% ecj Test.java T#is "om$ilation *ill generate t#e Test.class file, t#at "ontains t#e Test "lass, "om$iled as byte"ode' 7o*, run your embedded system, and inside t#e /root/ dire"tory, run%

2008-2009

ree !le"trons, #tt$%&&free-ele"trons'"om

(reative (ommons Li"ense

Java for embedded Linux systems Training lab book jamvm -Xmx2M Test /nd see your Java a$$li"ation running 4 7ote% t#e -Xmx argument also to redu"e t#e maximum si.e of t#e #ea$ to 2 megabytes' =y default, t#e maximum si.e is 1G megabytes, and be"ause our emulated embedded system only #as 1G megabytes of memory, *e need to redu"e t#e si.e of t#e Java #ea$'

2008-2009

ree !le"trons, #tt$%&&free-ele"trons'"om

(reative (ommons Li"ense