Community
cancel
Showing results for 
Search instead for 
Did you mean: 

Running Java on uclinux-niosII board

Running Java on uclinux-niosII board



This page describes the steps needed to port K-virtual machine (Sun-proprietry) and get Java running on uclinux-niosII using kvm. 


Meant for Linux users only, Windows port is possible but is tyringly slow and working with windows/cygwin is boring


Note: You need to have j2se1.4.x and gcc-2.95--gcc-3.3.x installed on linux box to get this working does not work with higher versions.

Guide to porting the K-virtual machine

  1. Get uclinux working follow the UClinuxDist page.
  2. Download K-virtual machine follow this link: http://www.sun.com/software/communitysource/j2me/cldc/download.xml
  3. Now unzip it in ~/download/

Go to the ~/download/j2me_cldc/kvm/VmUnix dir and change the Makefile as follows:

a) Line 95: CC = nios2-linux-uclibc-gcc

b) Line 118: @$(CC) $(FP_OBJFILES) -o .... add -elf2flt="-s 100000" to the end the stack size can be as large as need be

Explanation for the above steps

There are a host of makefiles in the directory structure of j2me_cldc. Most deal with the tools needed to make the api for KVM and tools for preverification, native support and static class binding etc... The Makefile dealing with the compilation of the actual virtual machine itself "KVM" is in directory j2me_cldc/kvm. Currently sun has already made ports for windows, linux/solaris and wince. In the above steps we just utilise the already ported kvm for linux to get it running on uclinux using nios2 cpu. Thus in the Makefile we need to change the C compiler which we shall use to compile the kvm 'C' src files. The second step of adding -elf2flt is just necessary since uclinux uses a flat file format.

  5. In the ~/download/j2me_cldc/kvm/VmUnix/src/ open file runtime_md.c and comment lines 171,172 these deal with floating-pt implementations in i386 arch.

Explanation for step 5

kvm has been written to make it highly portable for various architectures. We need to only provide certain native functions for our arch to port the kvm; rest are written in pure ansi-C and thus compile for almost all archs. runtime_md.c is the porting file; in there we provide native functionality for various required porting functions. Lines 171 & 172 deal with floating point precisions of i386. You can make this out from the macro #define. Another way of getting rid of this issue would be to change the Makefile.inc in ~/downloal/j2me_cldc/build/ but that would need a lot more effort and changing Makefiles. Thus we just comment these lines out. The perfomance on uclinux would not change at all.

 6. After making sure that javac-1.4.x and gcc-2.95.x is in your path cd ~/download/j2me_cldc/build/linux

This is the top most Makefile which will recurse down to make all the required execs.

Explanation:

I am not sure why Sun has restricted gcc-2.95.x (If you see the c-source there are some odd programming practices implemented like: no function definitions etc.. which will make gcc-4.1 complain), but javac-1.5 has many features like templates which are very resource intensive and thus are prohibited from CLDC (kvm).


  7. Make sure that you have gnumake installed: Go make in the shell

If everything goes right you should have created a kvm executable in ~/download/j2me_cldc/kvm/VmUnix/build/

  8. Copy this kvm exec in the ~/uclinuxdist/romfs/bin dir.

  9. In the shell go: cd ~/uclinuxdist/ and then make linux image --> download to the board.

  10. Once downloaded and you are connected to the "nios2-terminal" go kvm --> It should show all the options to run the java class files.

that's it you can now run java classes on nios2.

If you have javac-1.5 installed, in every Makefile you would have to change javac to javac -source 1.4 this will compile java classes with 1.4 compatability.

Guide to running java programs

  1. Write a hello.java file
  2. Compile it using javac if you have javac-1.5 compile it using javac -source 1.4... since this will make the app version for kvm
  3. To make the process easier create a uclinux dir in ~/download/j2me_cldc/bin/
  4. Copy ~/download/j2me_cldc/api/classes.zip, ~/download/j2me_cldc/tools/preverifier/build/linux/preverify.o into this dir also copy the generated hello.class file in here


Explanation for step 4: 

Step-4 is for easier usage only, not necessary at all but you need to know where the classes.zip and preverify.o are to make sure that your javac-1.4.x compiled file will actually run on kvm. You can write a shell-script to do all the steps together. The preverifier is needed to make sure that the class file will run and classes.zip are all the api's implemented in kvm.


Note: If you have multiple files or dir you can also make a jar file and pass that as input to preverify. Or you can set the classpath even project.file1 project.file2 .... works fine.


  5. Now in the shell cd into this dir and go: ./preverify -classpath classes.zip -verbose hello: This should make an output dir with a hello.class file

  6. Copy the new hello.class into ~/uclinuxdist/romfs/usr/

  7. In the shell go "make linux image" like before and download the image onto the board.

  8. Once connected to the nios2-terminal go kvm -classpath "./usr" hello--> This should run it.


There are whole lot of options to preverify and to run the kvm using JAR's zip's etc.

Note: Read the doc with kvm to know more about it.


Version history
Revision #:
1 of 1
Last update:
‎06-26-2019 11:43 PM
Updated by:
 
Contributors