Porting a JVM to NXT / Compiling LeJOS

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Porting a JVM to NXT / Compiling LeJOS

Postby wiederma » Mon Nov 23, 2009 3:33 pm

Hello to everyone,

my name is Norbert and I am student at Freiburg University. The Department I am currently working for has developed a own JVM. They want me to port this JVM to the NXT platform.

So far I had a look at LeJOS, and did a small project with NetBeans programming a small robot to get familiar with the hardware.

Now I am trying to recompile LeJOS on my own and there the first problems arise :(
On the PC I am working I have Ubuntu 8.04 installed. I have installed LeJOS in /opt/lejos and found the source in /opt/lejos/src/nxtvm/platform/nxt
I installed GCC-3.4 toolchain from http://www.gnuarm.com/ and did "make" (as advised in the /opt/lejos/src/nxtvm/platform/nxt/readme) but I get the following error:

Code: Select all
Building: lejos_nxt_rom.elf lejos_nxt_rom.bin

C sources: aic.c systick.c udp.c twi.c nxt_spi.c nxt_motors.c data_abort.c display.c i2c.c sound.c bt.c hs.c printf.c ../../javavm/interpreter.c ../../javavm/threads.c ../../javavm/exceptions.c ../../javavm/memory.c ../../javavm/language.c ../../javavm/poll.c ../../javavm/debug.c main.c nxt_avr.c sensors.c nxt_lcd.c native.c platform_hooks.c to aic.o systick.o udp.o twi.o nxt_spi.o nxt_motors.o data_abort.o display.o i2c.o sound.o bt.o hs.o printf.o ../../javavm/interpreter.o ../../javavm/threads.o ../../javavm/exceptions.o ../../javavm/memory.o ../../javavm/language.o ../../javavm/poll.o ../../javavm/debug.o main.o nxt_avr.o sensors.o nxt_lcd.o native.o platform_hooks.o flashprog.oram

Assembler sources: init.s interrupts.s vectors.s irq.s to init.o interrupts.o vectors.o irq.o

LD source: sam7.lds

 CC      arm-elf-gcc
 AS      /usr/local/gnuarm-3.4.3/arm-elf/bin/as
 LD      /usr/local/gnuarm-3.4.3/arm-elf/bin/ld
 OBJCOPY /opt/lejos/src/nxtvm/platform/nxt/objcopy
 OBJDUMP /opt/lejos/src/nxtvm/platform/nxt/objdump
 LIBGCC  /usr/local/gnuarm-3.4.3/lib/gcc/arm-elf/3.4.3/thumb/interwork/libgcc.a
 LIBC    /usr/local/gnuarm-3.4.3/arm-elf/lib/thumb/interwork/libc.a
Compiling aic.c to aic.o
arm-elf-gcc -mcpu=arm7tdmi -mlittle-endian -mfloat-abi=soft -mthumb-interwork -mthumb -ffreestanding -fsigned-char -Os -g -Wall -Winline -Werror-implicit-function-declaration -I. -I../../javavm -ffunction-sections -fdata-sections -DSVN_REV= -DMAJOR_VERSION=0 -DMINOR_VERSION=85 -c -o aic.o aic.c
cc1: error: invalid option `float-abi=soft'
make: *** [aic.o] Error 1


Can anyone give me some hints how to compile LeJOS the right way, so that I can understand how to use the arm compiler properly?

Where can I get some hints for porting another JVM to NXT? So far I know I have to write native methods, but as I understood it, this is for Java using the functionalities provided by the hardware.
So somewhere there have to be some C/C++ code (I think) that provides these functionalities to Java.

Any help is appreciated.
Norbert
Last edited by wiederma on Tue Nov 24, 2009 8:25 am, edited 1 time in total.
wiederma
New User
 
Posts: 11
Joined: Mon Nov 23, 2009 1:34 pm

Postby gloomyandy » Mon Nov 23, 2009 5:21 pm

Hi,
We currently use gcc 4.3.2 for building leJOS...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4173
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Postby wiederma » Tue Nov 24, 2009 8:29 am

HI Andy,

thanks for your answer. To get you right: Only gcc 4.3.2 is necessary to compile leJOS for the NXT?
What about the other tools mentioned at gnuarm.com?
* binutils-2.14.tar.bz2 [10.4MB]
* gcc-3.3.3.tar.bz2 [22.2MB]
* newlib-1.12.0.tar.gz [6.37MB]
* gdb-6.0.tar.bz2 [11.4MB]
* insight-6.0.tar.bz2 [17.9MB]

Do I have to use special parameters for the gcc (e.g. chiptype) ?
Can you post the complete command you are using to compile please?

Thanks for your help
norbert
wiederma
New User
 
Posts: 11
Joined: Mon Nov 23, 2009 1:34 pm

Postby gloomyandy » Tue Nov 24, 2009 11:47 am

We currently use:
gcc-4.3.2
binutils-2.18.50
newlib-1.16.0

The makefile (and associated files in the build directory) contain all of the required options/flags to build the firmware.

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4173
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

I get an error while compiling

Postby wiederma » Mon Dec 07, 2009 9:34 am

Hi, thanks for your answer. I installed the programms you mentioned, but I get the following error during compiling:

I do make in the lejos/src/nxtvm/platform/nxt folder:

Code: Select all
Building: lejos_nxt_rom.elf lejos_nxt_rom.bin

C sources: aic.c systick.c udp.c twi.c nxt_spi.c nxt_motors.c data_abort.c display.c i2c.c sound.c bt.c hs.c printf.c ../../javavm/interpreter.c ../../javavm/threads.c ../../javavm/exceptions.c ../../javavm/memory.c ../../javavm/language.c ../../javavm/poll.c ../../javavm/debug.c main.c nxt_avr.c sensors.c nxt_lcd.c native.c platform_hooks.c to aic.o systick.o udp.o twi.o nxt_spi.o nxt_motors.o data_abort.o display.o i2c.o sound.o bt.o hs.o printf.o ../../javavm/interpreter.o ../../javavm/threads.o ../../javavm/exceptions.o ../../javavm/memory.o ../../javavm/language.o ../../javavm/poll.o ../../javavm/debug.o main.o nxt_avr.o sensors.o nxt_lcd.o native.o platform_hooks.o flashprog.oram

Assembler sources: init.s interrupts.s vectors.s irq.s to init.o interrupts.o vectors.o irq.o

LD source: sam7.lds

 CC      arm-elf-gcc
 AS      /usr/local/gnuarm-3.4.3/arm-elf/bin/as
 LD      /usr/local/gnuarm-3.4.3/arm-elf/bin/ld
 OBJCOPY /opt/lejos/src/nxtvm/platform/nxt/objcopy
 OBJDUMP /opt/lejos/src/nxtvm/platform/nxt/objdump
 LIBGCC  /usr/local/gnuarm-3.4.3/lib/gcc/arm-elf/3.4.3/thumb/interwork/libgcc.a
 LIBC    /usr/local/gnuarm-3.4.3/arm-elf/lib/thumb/interwork/libc.a
Compiling aic.c to aic.o
arm-elf-gcc -mcpu=arm7tdmi -mlittle-endian -mfloat-abi=soft -mthumb-interwork -mthumb -ffreestanding -fsigned-char -Os -g -Wall -Winline -Werror-implicit-function-declaration -I. -I../../javavm -ffunction-sections -fdata-sections -DSVN_REV= -DMAJOR_VERSION=0 -DMINOR_VERSION=85 -c -o aic.o aic.c
cc1: error: invalid option `float-abi=soft'
make: *** [aic.o] Error 1


Where is the problem? Any help is appreciated.
norbert
wiederma
New User
 
Posts: 11
Joined: Mon Nov 23, 2009 1:34 pm

Postby gloomyandy » Mon Dec 07, 2009 10:58 am

Hi,
You are still using the wrong version of gcc... Look at the output from the make command it says you are using 3.4.3 not 4.3.2....

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4173
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Postby wiederma » Thu Dec 10, 2009 8:19 am

I got a hint from another developer to use another toolchain instead of the one from GNUARM (http://www.gnuarm.com/).

I am now using the one available here: http://download.ronetix.info/toolchains ... ux.tar.bz2
I had to do some changes to the environment.mak file to make the compiler find the correct versions. Compilation seems to work now.

Here are my changes to environment.mak:
Code: Select all
# COMP_PATH     := /opt/$(TARGET_PREFIX)-tools
COMP_PATH     := /usr/local/cross/arm-elf

Code: Select all
#OBJCOPY   := $(call get_prog_path,objcopy)
OBJCOPY   := /usr/local/cross/arm-elf/bin/arm-elf-objcopy


The thing with "objcopy" and "objdump" is somehow strange to me:
objdump was found correctly (I think; /usr/local/cross/arm-elf/arm-elf/bin/objdump) but without my changes objcopy wasn't found and compilation failed.
I checked where the file is located and found it here:
/usr/local/cross/arm-elf/bin/arm-elf-objcopy

But there is also a "arm-elf-objdump" file in that folder, so which one shall I use?

Compilation seems to work now, but I do get some Warnings (e.g.):
Code: Select all
udp.c:104: warning: 'intCnt' defined but not used
udp.c:217: warning: 'hex4' defined but not used

Code: Select all
nxt_motors.c: In function 'nxt_motor_isr_C':
nxt_motors.c:127: warning: unused variable 'pinChanges'
nxt_motors.c: In function 'nxt_motor_init':
nxt_motors.c:171: warning: passing argument 3 of 'aic_set_vector' makes integer from pointer without a cast

Code: Select all
../../javavm/memory.o ../../javavm/memory.c
../../javavm/memory.c: In function 'memory_add_region':
../../javavm/memory.c:780: warning: inlining failed in call to 'set_free_size': --param max-inline-insns-single limit reached
../../javavm/memory.c:819: warning: called from here
../../javavm/memory.c: In function 'try_allocate':
../../javavm/memory.c:780: warning: inlining failed in call to 'set_free_size': --param max-inline-insns-single limit reached
../../javavm/memory.c:933: warning: called from here
../../javavm/memory.c: In function 'gc_run_collector':
../../javavm/memory.c:780: warning: inlining failed in call to 'set_free_size': --param max-inline-insns-single limit reached
../../javavm/memory.c:1261: warning: called from here
../../javavm/memory.c:780: warning: inlining failed in call to 'set_free_size': --param max-inline-insns-single limit reached
../../javavm/memory.c:1269: warning: called from here


Do I have to be worried about them?

After compiling I have the following files in my folder:
Code: Select all
lejos_nxt_rom.bin
lejos_nxt_rom.elf
lejos_nxt_rom.elf.map
lejos_nxt_rom.ld


The README tell me, there should be these files:
Code: Select all
lejos_nxt_rom.bin  binary rom image
lejos_nxt_ram.elf  ram image for debugging with jtag
lejos_nxt_samba_ram.xxx samba ram image used with runjava

Have I done something wrong?
Last edited by wiederma on Thu Dec 10, 2009 8:47 am, edited 1 time in total.
wiederma
New User
 
Posts: 11
Joined: Mon Nov 23, 2009 1:34 pm

Postby gloomyandy » Thu Dec 10, 2009 8:38 am

I've never seen the inline warnings before. The others are normal. The set of files you have built are correct, we don't build the other targets by default anymore....


But since none of those toolchains in the link you gave match the version of gcc I recommended you use (4.3.2 which is the one we use to build the release - for lots of good reasons), I guess you are on your own... Good luck...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4173
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Postby wiederma » Thu Dec 10, 2009 9:36 am

gloomyandy wrote:I've never seen the inline warnings before. The others are normal. The set of files you have built are correct, we don't build the other targets by default anymore....


But since none of those toolchains in the link you gave match the version of gcc I recommended you use (4.3.2 which is the one we use to build the release - for lots of good reasons), I guess you are on your own... Good luck...

Andy


Don't get me wrong: I am not using this toolchain on purpose to annoy you. I am using it, because I had problems to get the tools you suggested installed and found by the make.
Maybe you can give me some hints to get them work ?
I will download all the stuff you told me:


Are these the right versions I need?
OK, after that I extract them to "/usr/local/build/" and then? configure, make, make install? Do I have to set the PATH variable?

By the way I forgot to ask in my previous posts: Is there a documented API for NXT available somewhere? I don't mean Java/LeJos API (I found that :lol: ) but for the hardware itself?
wiederma
New User
 
Posts: 11
Joined: Mon Nov 23, 2009 1:34 pm

Postby gloomyandy » Thu Dec 10, 2009 10:50 am

Hi,
Yes you need to build those tools and get them installed, then you may need to modify your local environment or the leJOS build scripts to make sure you use the tools you have just built. The leJOS make system will display what tools it is using you just need to get it to pick up the correct ones.

For information on the hardware you can look here (I'm surprised that you do not already have this)...
http://mindstorms.lego.com/en-gb/suppor ... fault.aspx
http://www.atmel.com/dyn/products/produ ... rt_id=3524

Oh and a quick note... I assume the JVM you are looking at porting is takatuka? If this is the case you may have some problems ahead from a licensing point of view if you use any leJOS code. leJOS is currently licensed under MPL, I noticed that takatuka is GPL3. My understanding is that these two licenses are not compatible... I'm not a lawyer but I have had a lot of experience with this sort of thing, and it can be a real pain. So if you ever intend to make the results of your project available to anyone else you may want to investigate this a little more before you get too far down the road of using any leJOS source in your project... We have been trying to move leJOS away from MPL but it is not an easy thing to do...

Good luck...

Andy

PS You didn't annoy me, it is simply that if you are using different tools to the ones that are normally used with leJOS then I have no way of knowing if it is the tools that are causing the problem or not. So for instance your warning about inline functions is not one I have seen with the build system we use... Once you have things working then feel free to use whatever tools you want, but if you want our help then using the standard tools will make it much easier...
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4173
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Postby mardy » Sat Dec 12, 2009 4:44 pm

gloomyandy wrote:We currently use:
gcc-4.3.2
binutils-2.18.50
newlib-1.16.0

The makefile (and associated files in the build directory) contain all of the required options/flags to build the firmware.

Andy


Andy,

Can you point us to were we can download pre-built gcc-4.3.2 binaries?
mardy
New User
 
Posts: 12
Joined: Fri Dec 11, 2009 4:06 pm

Postby gloomyandy » Sat Dec 12, 2009 6:40 pm

Hi,
I don't know if you can. I always build them from source...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4173
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Postby gloomyandy » Sat Dec 12, 2009 6:46 pm

But if you are going to be building for a system that is not AT91 based then you may be as well using some other version of gcc... The reason we use that particular version is that for the Arm processor (and with the options we use for the AT91), that version of gcc produces the best combination of speed and size (compared with more recent versions). But this may not be the case for other targets. Which platform are you building for?

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 4173
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Postby skoehler » Sat Dec 12, 2009 7:02 pm

gloomyandy wrote:We currently use:
gcc-4.3.2
binutils-2.18.50
newlib-1.16.0

I also used bintuils 2.19.
Recently I upgraded to 2.20, but newlib <=1.17.0 didn't compile due to some bugs in some assembler code. They fixed the issue in SVN head though.

I don't know anything about precompiled toolchains. I built my own one using crossdev on Gentoo (which is not straightforward, because gcc needs a very small patch so that interworking can be enabled).

In the SVN version of leJOS, the COMP_PATH variable has been replaced by the variables LEJOS_NXT_ARM_GCC. You can set that variable to an absolute path or the name of an executable that is in the path. You can set that variable in your ~/.bashrc or ~/.cshrc, depending on your shell. If not set, the default is "arm-elf-gcc".
skoehler
leJOS Team Member
 
Posts: 1448
Joined: Thu Oct 30, 2008 4:54 pm

Postby mardy » Sun Dec 13, 2009 3:15 am

gloomyandy wrote:But if you are going to be building for a system that is not AT91 based then you may be as well using some other version of gcc... The reason we use that particular version is that for the Arm processor (and with the options we use for the AT91), that version of gcc produces the best combination of speed and size (compared with more recent versions). But this may not be the case for other targets. Which platform are you building for?

Andy


I'm targeting a Phillips LPC2888, which is ARM7TDMI based. Not that much different from the AT91. For now I'm trying to establish a reference point by recompiling the firmware and successfully loading onto a NXT brick.

Since you are building from source, which I am attempting to do also, could you share how you are configuring the various components?

I've been able to successfully build a complete gnu-arm-elf toolchain and compile lejos 0.85 without any problems, but the resulting binary fails to run on the NXT. I don't know if it is a misconfiguration of the toolchain or the fact that I'm trying to do it on a Mac.

-Mardy
mardy
New User
 
Posts: 12
Joined: Fri Dec 11, 2009 4:06 pm

Next

Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff