Porting a JVM to NXT / Compiling LeJOS

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

Postby skoehler » Sun Dec 13, 2009 2:34 pm

mardy wrote: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.

Did you enable software-floats? You have to pass "--with-float=soft" to configure of bintuils, gcc and newlib. Interworking is also working correctly? I can't imagine any other source for the problem right now.
skoehler
leJOS Team Member
 
Posts: 1421
Joined: Thu Oct 30, 2008 4:54 pm

Postby mardy » Sun Dec 13, 2009 10:33 pm

Turns out the problem wasn't with the tools, I had forgotten to rebuild StartUpText. Duh...
mardy
New User
 
Posts: 12
Joined: Fri Dec 11, 2009 4:06 pm

Postby wiederma » Mon Dec 14, 2009 8:49 am

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

Some advises on how to get the "toolchain" properly compiled would also be very helpful for me too :roll:

for example: how has to folderstructure to be?
What parameters are necessary for ./configure?

http://sourceware.org/newlib/faq.html#q1
here I found a word on compiling newlib, what causes the most trouble to me at the moment.
my current folderstructure looks like this:
Code: Select all
/usr/local/build/binutils-2.18
/usr/local/build/newlib-1.16.0
/usr/local/build/gcc-4.3.2

I did ./configure --with-float=soft in binutils, make, and sudo make install. That went fine.
The same in newlib: ./configure --with-float=soft, but make gives me the following error:
Code: Select all
WARNING: `makeinfo' is missing on your system.  You should only need it if
         you modified a `.texi' or `.texinfo' file, or any other file
         indirectly affecting the aspect of the manual.  The spurious
         call might also be the consequence of using a buggy `make' (AIX,
         DU, IRIX).  You might want to install the `Texinfo' package or
         the `GNU make' package.  Grab either from any GNU archive site.
make[3]: *** [standards.info] Error 1
make[3]: Leaving directory `/usr/local/build/newlib-1.16.0/etc'
make[2]: *** [info] Error 1
make[2]: Leaving directory `/usr/local/build/newlib-1.16.0/etc'
make[1]: *** [all-etc] Error 2
make[1]: Leaving directory `/usr/local/build/newlib-1.16.0'
make: *** [all] Error 2


Has newlib to be a subfolder of gcc, so that configure of gcc also configures newlib.
I hope I do get this compiling stuff work properly soon, because my time is running out with this project. :?
wiederma
New User
 
Posts: 11
Joined: Mon Nov 23, 2009 1:34 pm

Postby wiederma » Mon Dec 14, 2009 2:24 pm

Ok Folks, here I found some instructions to get gcc compiled:
http://martin.hinner.info/ARM-Microcontroller-HOWTO/ARM-Microcontroller-HOWTO-4.html

especially those two statements where helpful:
Code: Select all
#  From build-binutils directory call: "../binutils-2.16/configure --target=arm-elf --prefix=/usr/local/arm7; make all install"
# From build-gcc directory call: "../gcc-4.0.0/configure --target=arm-elf --prefix=/usr/local/arm7 --enable-languages=c --with-newlib; make all-gcc install-gcc"


BUT, there is something I am not sure if it actually works as intended:
the second statement has the option --with-newlib, but where does newlib come from? OK obviously it comes form http://sourceware.org/newlib/, but how to include it into this compilation? Making a additional build-newlib folder like that:

Code: Select all
cd build-newlib
../newlib-1.16.0/configure --target=arm-elf --prefix=/usr/local/arm7; make all install


But that gets me agian this error:
Code: Select all
WARNING: `makeinfo' is missing on your system.  You should only need it if
         you modified a `.texi' or `.texinfo' file, or any other file
         indirectly affecting the aspect of the manual.  The spurious
         call might also be the consequence of using a buggy `make' (AIX,
         DU, IRIX).  You might want to install the `Texinfo' package or
         the `GNU make' package.  Grab either from any GNU archive site.
make[3]: *** [standards.info] Error 1
make[3]: Leaving directory `/home/wiederma/Desktop/compiling_LeJos/build-newlib/etc'
make[2]: *** [info] Error 1
make[2]: Leaving directory `/home/wiederma/Desktop/compiling_LeJos/build-newlib/etc'
make[1]: *** [install-etc] Error 2
make[1]: Leaving directory `/home/wiederma/Desktop/compiling_LeJos/build-newlib'
make: *** [install] Error 2


What the heck is makeinfo?
wiederma
New User
 
Posts: 11
Joined: Mon Nov 23, 2009 1:34 pm

Postby mardy » Mon Dec 14, 2009 3:12 pm

Here is a script that I put together to build the gnu-arm-elf toolchain for Mac OS X. It's not elegant, but it works. I haven't tried it on Linux yet, but don't see why it shouldn't work. You would of course want to change the prefix path to something like "/usr/local/gnuarm". Also, you might not need to build gmp and mpfr. Give it a try.

-Mardy

Code: Select all
#!/bin/bash

# Packages
BINUTILS="binutils-2.20"
BINUTILS_URL="http://ftp.gnu.org/gnu/binutils"

GMP="gmp-4.3.1"
GMP_URL="http://ftp.gnu.org/gnu/gmp"

MPFR="mpfr-2.4.2"
MPFR_URL="http://ftp.gnu.org/gnu/mpfr"

GNUC="gcc-4.3.2"
GNUC_URL="http://ftp.gnu.org/gnu/gcc/"${GNUC}

NEWLIB="newlib-1.17.0"
NEWLIB_URL="ftp://sources.redhat.com/pub/newlib"

# Target and destination configuration
export TARGET=arm-elf
export PREFIX=/Applications/gnuarm
export PATH=$PATH:$PREFIX/bin

# Create target and download directories, if missing
if [ ! -d $PREFIX ]; then
  mkdir $PREFIX
fi

if [ ! -d downloads ]; then
  mkdir downloads
fi

# Build BINUTILS
if [ ! -f downloads/${BINUTILS}.tar.gz ]; then
  wget --directory-prefix=downloads ${BINUTILS_URL}/${BINUTILS}.tar.gz
fi
mkdir binutils_build
tar xzf downloads/${BINUTILS}.tar.gz
cd binutils_build
../${BINUTILS}/configure \
  --prefix=$PREFIX \
  --target=$TARGET \
  --enable-interworking \
  --enable-multilib \
  --with-gnu-as \
  --with-gnu-ld \
  --disable-werror
make
make install
cd ..

# Build GMP
if [ ! -f downloads/${GMP}.tar.gz ]; then
  wget --directory-prefix=downloads ${GMP_URL}/${GMP}.tar.gz
fi
mkdir gmp_build
tar xzf downloads/${GMP}.tar.gz
cd gmp_build
../${GMP}/configure \
  --prefix=$PREFIX
make
make check
make install
cd ..

# Build MPFR
if [ ! -f downloads/${MPFR}.tar.gz ]; then
  wget --directory-prefix=downloads ${MPFR_URL}/${MPFR}.tar.gz
fi
mkdir mpfr_build
tar xzf downloads/${MPFR}.tar.gz
cd mpfr_build
../${MPFR}/configure \
  --prefix=$PREFIX \
  --with-gmp-build=../gmp_build
make
make install
cd ..

# Build GCC Bootstrap
if [ ! -f downloads/${GNUC}.tar.gz ]; then
  wget --directory-prefix=downloads ${GNUC_URL}/${GNUC}.tar.gz
fi
tar xzf downloads/${GNUC}.tar.gz
# Patch the source
cd ${GNUC}
patch -p1 << "EOF"
--- gcc-orig/gcc/config/arm/t-arm-elf
+++ gcc-multilib/gcc/config/arm/t-arm-elf
@@ -33,8 +33,8 @@
 # MULTILIB_DIRNAMES   += fpu soft
 # MULTILIB_EXCEPTIONS += *mthumb/*mhard-float*
-#
-# MULTILIB_OPTIONS    += mno-thumb-interwork/mthumb-interwork
-# MULTILIB_DIRNAMES   += normal interwork
-#
+
+MULTILIB_OPTIONS    += mno-thumb-interwork/mthumb-interwork
+MULTILIB_DIRNAMES   += normal interwork
+
 # MULTILIB_OPTIONS    += fno-leading-underscore/fleading-underscore
 # MULTILIB_DIRNAMES   += elf under
EOF
cd ..
mkdir gcc_build
cd gcc_build
../${GNUC}/configure \
  --prefix=$PREFIX \
  --target=$TARGET \
  --enable-languages=c \
  --with-float=soft \
  --enable-interworking \
  --enable-multilib \
  --with-gnu-as \
  --with-gnu-ld \
  --with-newlib \
  --without-headers \
  --disable-shared \
  --with-gmp=/Applications/gnuarm \
  --with-mpfr=/Applications/gnuarm \
  --disable-werror
make all-gcc
make install-gcc
cd ..

# Build NEWLIB
if [ ! -f downloads/${NEWLIB}.tar.gz ]; then
  wget --directory-prefix=downloads ${NEWLIB_URL}/${NEWLIB}.tar.gz
fi
tar xzf downloads/${NEWLIB}.tar.gz
# Patch the source
cd ${NEWLIB}
patch -p1 << "EOF"
+++ newlib-cvs/libgloss/arm/linux-syscalls0.S
--- newlib-1.17.0/libgloss/arm/linux-syscalls0.S
@@ -19,47 +19,6 @@
 #define GLOBAL(name) .global name; FUNC(name)
 #define SIZE(name) .size name, .-name
 
-#if __thumb__
-
-# define SYSCALL0(name) \
-   GLOBAL(_ ## name); \
-   mov r12, r7; \
-   mov r7, #SYS_ ## name; \
-   swi; \
-   mov r7, r12; \
-   b _set_errno; \
-   SIZE(_ ## name)
-
-/* static int _syscall3(int a, int b, int c, int number); */
-FUNC(_syscall3)
-   push { r7 }
-   mov r7, r3
-   swi
-   pop { r7 }
-   b _set_errno
-   SIZE(_syscall3)
-
-# define SYSCALL3(name) \
-   GLOBAL(_ ## name); \
-   mov r3, #SYS_ ## name; \
-   b _syscall3; \
-   SIZE(_ ## name)
-
-# define SYSCALL6(name) \
-   GLOBAL(_ ## name); \
-   push { r4 - r5, r7 }; \
-   ldr r4, [sp, #12]; \
-   ldr r5, [sp, #16]; \
-   mov r7, #SYS_ ## name; \
-   swi; \
-   pop { r4 - r5, r7 }; \
-   b _set_errno; \
-   SIZE(_ ## name)
-
-# define SYSCALL4(name) SYSCALL6(name)
-
-#else /* __thumb__ */
-
 # define SYSCALL4(name) \
    GLOBAL(_ ## name); \
    swi #SYS_ ## name; \
@@ -78,9 +37,6 @@
 
 #define SYSCALL0(name) SYSCALL3(name)
 #define SYSCALL3(name) SYSCALL4(name)
-
-#endif /* __thumb__ */
-
 #define SYSCALL1(name) SYSCALL3(name)
 #define SYSCALL2(name) SYSCALL3(name)
 #define SYSCALL5(name) SYSCALL6(name)
EOF
cd ..
mkdir newlib_build
cd newlib_build
../${NEWLIB}/configure \
  --prefix=$PREFIX \
  --target=$TARGET \
  --enable-interworking \
  --enable-multilib \
  --with-gnu-as \
  --with-gnu-ld \
  --disable-werror
make
make install
cd ..

# Build GCC
cd gcc_build
rm -rf *
../${GNUC}/configure \
  --prefix=$PREFIX \
  --target=$TARGET \
  --enable-languages=c \
  --with-float=soft \
  --enable-interworking \
  --enable-multilib \
  --with-gnu-as \
  --with-gnu-ld \
  --with-newlib \
  --with-headers=../${NEWLIB}/libc/include \
  --with-gmp=/Applications/gnuarm \
  --with-mpfr=/Applications/gnuarm \
  --disable-werror
make all
make install
cd ..
mardy
New User
 
Posts: 12
Joined: Fri Dec 11, 2009 4:06 pm

Postby wiederma » Mon Dec 14, 2009 4:31 pm

Ok Folks, it seems as if makeinfo is more important then this error message admits :evil:
Code: Select all
WARNING: `makeinfo' is missing on your system.  You should only need it if
         you modified a `.texi' or `.texinfo' file, or any other file
         indirectly affecting the aspect of the manual.  The spurious
         call might also be the consequence of using a buggy `make' (AIX,
         DU, IRIX).  You might want to install the `Texinfo' package or
         the `GNU make' package.  Grab either from any GNU archive site.

After some googleing I also found this here: http://ubuntuforums.org/showthread.php?t=16734

So after doing
Code: Select all
sudo apt-get install texinfo

it seems to compile the whole stuff 8)
wiederma
New User
 
Posts: 11
Joined: Mon Nov 23, 2009 1:34 pm

Postby wiederma » Mon Jan 11, 2010 11:18 am

Hello Folks,

I am back at university after Christmasbreak and working on this project again.
Now I have a question about the OpenSource Firmware offered by LEGO:
http://mindstorms.lego.com/en-us/suppor ... fault.aspx
http://cache.lego.com/upload/contentTem ... 7B8AB6.zip

Does anyone of you have some experience with that firmware and knows maybe some links to good tutorials?
First thing I am interested in is how to get a simple hello world running with that firmware.

I know this question is of topic in this forum, but maybe someone of you can give me some hints where to start.
wiederma
New User
 
Posts: 11
Joined: Mon Nov 23, 2009 1:34 pm

Postby gloomyandy » Mon Jan 11, 2010 12:21 pm

Hi,
I'm not sure what you mean by a "Hello World program working with this firmware". The Lego firmware is just that it implements the interpreter and device support for use with the standard Lego NXG language system. It is not some general purpose firmware....

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

Postby wiederma » Mon Jan 11, 2010 1:32 pm

I am sorry but I didn't get it.

Ok I will try to explain my problem more briefly:

On the one hand I have TakaTuka, on the other hand I have the NXT Brick. May goal is to get TakaTuka working on the NXT.

My first intension was:
Have a look at LeJOS and try to understand who those guys managed to make their JVM communicate with the Hardware. That was the reason for all the questions about the compiling tool chain. I thought it is necessary for me to have such a tool chain running properly to get source code compiled that is executable on the NXT.

My next idea is:
If there exists a OpenSource firmware it should also provide some kind of drivers to communicate with the hardware. Why not using those drivers in my project as interface to the hardware?

By the way, I found here a very good and intuitive tutorial about using JNI:
http://cnd.netbeans.org/docs/jni/beginn ... linux.html
So my thought was doing something like in the tut: the C Part is already available by the OpenSource firmware, and I would write the native methods on the Java Side.

Is there any advise you can give me on how to start with the portation of a JVM to NXT. Where can/should I start?
wiederma
New User
 
Posts: 11
Joined: Mon Nov 23, 2009 1:34 pm

Postby gloomyandy » Mon Jan 11, 2010 2:02 pm

Hi,
Have you actually looked at the Lego firmware source code? I would start with that... You may be able to use it as the basis of a port but I think you may find that the "drivers" and the other parts of the system are somewhat inter-mixed...

If what you want is a base set of drivers then perhaps nxos would be a better starting point? Some of the code is loosely based off an older set of leJOS drivers (but pretty much all have have been re-worked), but it uses a GPL2 license which probably works better for you:
http://nxt.natulte.net/nxos/trac/wiki
They also have a script that will build you a toolchain (on linux)
http://github.com/danderson/nxos/blob/m ... olchain.sh
The project does not seem to have very active for the last few months though...

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

Postby wiederma » Mon Jan 11, 2010 3:25 pm

gloomyandy wrote:Hi,
Have you actually looked at the Lego firmware source code? I would start with that... You may be able to use it as the basis of a port but I think you may find that the "drivers" and the other parts of the system are somewhat inter-mixed...

Yes I did. I spent the last two days trying to figure out how the lego firmware might work. I looked at the *.c files and tried to recognize some structures and dependencies but was as successful as I wished. Maybe it is because of this inter-mix you mentioned.
gloomyandy wrote:If what you want is a base set of drivers then perhaps nxos would be a better starting point? Some of the code is loosely based off an older set of leJOS drivers (but pretty much all have have been re-worked), but it uses a GPL2 license which probably works better for you:
http://nxt.natulte.net/nxos/trac/wiki

That sounds quite good; I had a look this project. The documentations sound like it could be useful for me. I will have a closer look at this.
gloomyandy wrote:They also have a script that will build you a toolchain (on linux)
http://github.com/danderson/nxos/blob/m ... olchain.sh

That's good :D I hope that can save me some trouble with compiling stuff. Thanks for that hint 8)
gloomyandy wrote:The project does not seem to have very active for the last few months though...

Andy

Well that's a pity, but I hope their documentation is as good as they claim on their web page :) so hopefully I don't need much help on that. Break a leg! :lol:
wiederma
New User
 
Posts: 11
Joined: Mon Nov 23, 2009 1:34 pm

Postby gloomyandy » Mon Jan 11, 2010 5:23 pm

Another alternative (Much more closely based on leJOS) is nxtOSEK
http://lejos-osek.sourceforge.net/

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

Previous

Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 2 guests

more stuff