PDA

View Full Version : Crosscompiling to ARM



{MSX}
28-01-2007, 12:42 AM
hi, i've a computer that runs on an ARM9 processor (exacly ARM920T), running linux.
i've read some time ago that it is possible to cross compile to arm with freepascal.. is it true? any hint on how to do it/things i should be aware of?

thanks! :D

Legolas
28-01-2007, 01:14 AM
Yep! :D
Some months ago I built a crosscompiler for arm-linux (ftp://ftp.freepascal.org/pub/fpc/snapshot/v21/arm-linux). This binary package is a bit outdated and I have lost on my hd the batch script I have made for building, but IIRC it should be pretty similar to gba crossbuild (see the wiki) :)

{MSX}
28-01-2007, 09:30 AM
you mean this page;
http://www.freepascal.org/wiki/index.php/Setup_Cross_Compile_For_ARM
?

uhm looks simple! :shock:

dmantione
28-01-2007, 10:42 AM
If you use Linux on your desktop, you also can download the 2.0.4 ARM-linux release to cross-compile to ARM.

Legolas
28-01-2007, 11:58 AM
you mean this page;
http://www.freepascal.org/wiki/index.php/Setup_Cross_Compile_For_ARM
?

uhm looks simple! :shock:

No, I mean this page:

http://www.freepascal.org/wiki/index.php/GameBoy_Advance

of course, changing the needed here and there ;)

Sly
29-01-2007, 11:08 AM
I tried compiling a FPC ARM cross-compiler a while back, but the FPC compiler would crash about an hour into the "make all" when trying to compile the runtime library. gtkspinbutton.pas would cause an internal compiler error that no-one on the FPC mailing list seemed interested in fixing, and I don't know how to debug that sort of thing with gdb.

paul_nicholls
15-02-2007, 10:08 PM
Yep! :D
Some months ago I built a crosscompiler for arm-linux (ftp://ftp.freepascal.org/pub/fpc/snapshot/v21/arm-linux). This binary package is a bit outdated and I have lost on my hd the batch script I have made for building, but IIRC it should be pretty similar to gba crossbuild (see the wiki) :)

Hi Legolas :-)

I have tried using that crosscompiler for arm-linux so I can make some pascal GP2X programs and I am having troubles.

If I try compiling this code which uses the JEDI-SDL 1.0 beta units.

Program Test_gp2x;
Uses
SDL;
Begin
End.

I get this output:


C:\>ppcrossarm -Fuc:\fpc\2.0.4\Units\arm-linux Test_gp2x.pp
Free Pascal Compiler version 2.1.1 [2006/09/09] for arm
Copyright (c) 1993-2006 by Florian Klaempfl
Target OS: Linux for ARM
Compiling Test_gp2x.pp
Compiling SDL.pas
jedi-sdl.inc(293,4) Warning: Illegal compiler directive "$THREADING"
Fatal: Can't find unit pthreads
Fatal: Compilation aborted

Any ideas?

I know I read somewhere about the $THREADING being removed/changed or something, but the fatal error is obviously the killer :)

If you noticed the 2.0.4 version in the path, this is because I dumped the crosscompile units and binaries into separate unit and bin folders in the native fpc 2.0.4 version. I can't see this affecting the crosscompile?

cheers,
Paul.

dmantione
15-02-2007, 10:22 PM
Try to ifdef it, we cannot multithread on ARM at this time.

paul_nicholls
15-02-2007, 10:35 PM
Try to ifdef it, we cannot multithread on ARM at this time.

Ok, what about if I added a -Dgp2x define in the compile line and did something like this in the SDL.pas file:

{$IFNDEF gp2x}
//the whole pthreads section
{$ENDIF}

could this work?

cheers,
Paul.

WILL
15-02-2007, 10:43 PM
Hey, keep at it Paul! GP2X will be a really nice addition to the list of game platforms for FPC.

I can't exactly speak for him, but I think that after Legolas is done with getting the major stuff for GBA and NDS working he'll be interested in helping our add support for GP2X in FPC too.

Sly
15-02-2007, 10:57 PM
pthreads works fine on GP2X. In fact, the SDL libraries for GP2X require it.

Legolas
15-02-2007, 10:59 PM
In the next three months I should have a lot of spare time (my gf will fly to Germany until June :()
Unfortunately I don't have a gp2x and, AFAIK, there isn't any emulator available. Of course I can take a look at it and I could help in the porting development :)

paul_nicholls
15-02-2007, 11:02 PM
Hey, keep at it Paul! GP2X will be a really nice addition to the list of game platforms for FPC.

I can't exactly speak for him, but I think that after Legolas is done with getting the major stuff for GBA and NDS working he'll be interested in helping our add support for GP2X in FPC too.

Thanks for the encouragement Will :)

To Legolas: I would be willing to be a gp2x fpc crosscompiler tester if this helps.
I just have to figure out how to use it properly <G>

I have almost no ARM assembly skills but I could learn if you need a hand in creating RTLs for the gp2x.

cheers,
Paul.

paul_nicholls
15-02-2007, 11:41 PM
Also, if it helps I already have the devkitGP2X downloaded which is what I am using currently to make c/c++ programs for the gp2x.

cheers,
Paul.

paul_nicholls
17-02-2007, 12:43 AM
To see if I could create my own win32 arm-linux cross compiler from the fpc source, I downloaded the fpcbuild.zip source code (2.1.x version I think) and the win32crossbinutils2005.zip from the ftp site.

I ran the script below that I placed in the root folder of the fpcbuild


set path=G&#58;\fpc\2.0.4\bin\i386-win32
make distclean

make all install CPU_TARGET=arm OS_TARGET=linux CROSSBINDIR=G&#58;\fpc-crossbinutils\arm-linux BINUTILSPREFIX=arm-linux- INSTALL_PREFIX=G&#58;\fpc\win32_arm-linux COMPILER_OPTIONS="cpufpemu"

pause

G:\fpc\2.0.4\bin\i386-win32 pointed to the native 2.0.4 folder containing the make.exe file
G:\fpc-crossbinutils\arm-linux pointed to the win32 crossbin utils that I unzipped
G:\fpc\win32_arm-linux pointed to where I wanted to install the new version of the compiler that would be built.

Sometime later after the build finished I had a look in the win32_arm-linux install folder and found that there are no .exe files created. Is this correct?

How do I use the new install to cross compile arm-linux stuff if there are no .exe files?

Did I do the procedure correctly?

Edit: I did just notice that in the G:\fpcbuild\fpcsrc\compiler folder there is a newly created file ppcrossarm.exe...

do I use this ppcrossarm.exe and the new units in the install folder G:\fpc\win32_arm-linux\units\arm-linux\rtl to compile pascal programs for the arm?

If needed I could use the units here as well I assume? G:\fpc\win32_arm-linux\units\arm-linux

cheers,
Pau.

paul_nicholls
17-02-2007, 11:54 AM
To see if I could create my own win32 arm-linux cross compiler from the fpc source, I downloaded the fpcbuild.zip source code (2.1.x version I think) and the win32crossbinutils2005.zip from the ftp site.

I ran the script below that I placed in the root folder of the fpcbuild


set path=G&#58;\fpc\2.0.4\bin\i386-win32
make distclean

make all install CPU_TARGET=arm OS_TARGET=linux CROSSBINDIR=G&#58;\fpc-crossbinutils\arm-linux BINUTILSPREFIX=arm-linux- INSTALL_PREFIX=G&#58;\fpc\win32_arm-linux COMPILER_OPTIONS="cpufpemu"

pause

G:\fpc\2.0.4\bin\i386-win32 pointed to the native 2.0.4 folder containing the make.exe file
G:\fpc-crossbinutils\arm-linux pointed to the win32 crossbin utils that I unzipped
G:\fpc\win32_arm-linux pointed to where I wanted to install the new version of the compiler that would be built.

Sometime later after the build finished I had a look in the win32_arm-linux install folder and found that there are no .exe files created. Is this correct?

How do I use the new install to cross compile arm-linux stuff if there are no .exe files?

Did I do the procedure correctly?

Edit: I did just notice that in the G:\fpcbuild\fpcsrc\compiler folder there is a newly created file ppcrossarm.exe...

do I use this ppcrossarm.exe and the new units in the install folder G:\fpc\win32_arm-linux\units\arm-linux\rtl to compile pascal programs for the arm?

If needed I could use the units here as well I assume? G:\fpc\win32_arm-linux\units\arm-linux

Ok, I tried using the ppcrossarm.exe and the G:\fpc\win32_arm-linux\units\arm-linux\* path to compile my simple almost blank pas file using SDL.

Program Test;
Uses
SDL;
Begin
End.

It now finds the pthreads unit ok, but it instead complains that it couldn't find the internal as.exe assembler, now switching to external assembler.

It then stops with that 1 error.

Paul.

dmantione
17-02-2007, 11:58 AM
Did you install cross binutils?

paul_nicholls
20-02-2007, 02:34 AM
Excellent news!! I have gotten my first simple sdl program working for the GP2X using freepascal, compiled under Win32!! :)

Someone was able to give me advice :)

The process requires the fpcbuild source files and the normal freepascal binaries installed, for example v 2.0.4 so you can use the make.exe file included in the fpc\2.0.4\bin\i386-win32 folder to compile the source code.

It also requires the devkitGP2X (http://archive.gp2x.de/cgi-bin/cfiles.cgi?0,0,0,0,14,1362) downloaded and extracted to the rootfolder of a drive (c:\ in my case)

SDL.pas also needs to be slightly modified.

There are lots of instructions so instead of placing them here I will upload the files needed to a server so people can download them and have a play :)

to wet your appitite though here are some of the script batch files I have used.

I put all the scripts into the project folder and update the CompileProject to point to the files to compile :)

InitFiles.bat

Del *.s
Del *.o
Del *.ppu
Del *.gpe

CompileProject.bat

@echo off
set path=C&#58;\FPC_win32_arm-linux\bin\arm-linux

call InitFiles.bat

rem compile all needed units to allow compiling of main file
call CompileAux.bat SDL.pas

rem compile main file
call CompileMain.bat gp2x_test

call CleanupFiles.bat

pause

CompileAux.bat

echo compiling %1...
ppcrossarm -dgp2x %1

CompileMain.bat

echo Compiling %1.dpr
ppcrossarm -s -dgp2x %1.dpr
echo Assembling %1
arm-linux-as.exe -mcpu=arm920 -o %1.o %1.s
if errorlevel 1 goto asmend
echo Linking %1
arm-linux-ld.exe -static --no-warn-mismatch -s -L. -o%1.gpe link.res -lm -lstdc++ -lgcc_eh -lpthread -lvorbisidec -lmikmod -lpng -lpng12 -lz -lSDL -ljpeg -lfreetype -lc -lgcc
if errorlevel 1 goto linkend
goto end
&#58;asmend
echo An error occured while assembling %1
goto end
&#58;linkend
echo An error occured while linking %1
&#58;end

CleanupFiles.bat

Del *.s
Del link.res
Del ppas.bat
Del *.o
Del *.ppu


cheers,
Paul.

WILL
20-02-2007, 02:58 AM
Very nice Paul! Awesome work. :thumbup:

Between you and Francesco (Legolas) FreePascal might just be THE handheld game console development tool of choice for Pascal game developers. :)

paul_nicholls
20-02-2007, 03:47 AM
Very nice Paul! Awesome work. :thumbup:

Between you and Francesco (Legolas) FreePascal might just be THE handheld game console development tool of choice for Pascal game developers. :)

<G> I did get a big start from a Eugene Proshkin who lurks in the gp32x formums :)

He created a program for the GP2X called blocks (http://www.gp32x.com/board/lofiversion/index.php/t34048.html)

He sent me an email as a starting point containing an example fpc.cfg file, the batch file to compile the FPC source code, what devkitGP2X file paths were needed, what devkitGP2X files .so files needed modifying.

He also sent me a batch file to compile the project files to create the .gpe file.

I did have to make changes to various batch files and paths to make it work + fix a small error (i think), but it was a huge help :)

It took me a while to get all the stuff working, but it seems to be working now :-)

He sent me the new SDL.pas file that was modified as well.

cheers,
Paul.