Lazarus

Programming => Operating Systems => Other => Topic started by: Ocye on April 20, 2013, 05:42:58 pm

Title: ppcmipsel on openwrt/freetz
Post by: Ocye on April 20, 2013, 05:42:58 pm
I try to compile for my Fritz!Box 3270v3 and want to share my experiences and flops. My steps so far were:
1. Building the toolchain
* make binutils from source
2. Building the compiler
* download fpc 2.7.1 from trunk (2.6.2. does not work)
* bootstrapping mipsel, building compiler and rtl (http://wiki.freepascal.org/Native_MIPS_Systems)
btw: "make "OPT=-O- -g" -C compiler mipsel" works flawless but I struggled with "make rtl" and "make compiler". Finally it did produce some files but I don't know how I achieved this.
3. Adjusting configuration
Quote from: .fpc.cfg
#ifdef cpumipsel
-Xd
-Fl/usr/local/mipsel/lib
-Pmipsel
#endif
4. Some code
Code: [Select]
program hello;
begin
writeln('Hello world');
end.
5. Compiling
* ppcmipsel hello.pp
Quote from: file hello
hello: ELF 32-bit LSB  executable, MIPS, MIPS32 version 1 (SYSV), statically linked, stripped
Quote from: readelf -h hello
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           MIPS R3000
  Version:                           0x1
  Entry point address:               0x401210
  Start of program headers:          52 (bytes into file)
  Start of section headers:          41584 (bytes into file)
  Flags:                             0x50001001, noreorder, o32, mips32
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         3
  Size of section headers:           40 (bytes)
  Number of section headers:         9
  Section header string table index: 8
6. Running
At least at this point I fail. I can copy the program to my router but when I start nothing happens. It stucks waiting for ctrl-c. According to "top" it consumes 100% of cpu.

I don't have any tool like "file" or "readelf" to double check the right header. Maybe I just need to set some ABI setting.

I appreciate any help. Next questions, if fpc eventually will be able to compile, is whether I can use a sql database. So if someone has tried please let me know.
Title: Re: ppcmipsel on openwrt/freetz
Post by: jwdietrich on April 20, 2013, 05:51:28 pm
It is great to see how many things are possible with Free Pascal!

Would you mind to write an article about your interesting experiences in the Free Pascal wiki?
Title: Re: ppcmipsel on openwrt/freetz
Post by: Ocye on April 20, 2013, 07:00:48 pm
There is a pretty good wiki, which I mentioned yet. And after all it doesn't work for me for some reason.
Title: Re: ppcmipsel on openwrt/freetz
Post by: BigChimp on April 21, 2013, 07:47:02 am
Interesting, Ocye, shame you couldn't get it to work. Getting stuff running on a Mipsel Fritz!Box (clone) is on my todo list as well... just very low down ;)
Title: Re: ppcmipsel on openwrt/freetz
Post by: Ocye on April 21, 2013, 09:20:41 am
It just remembered that ftp has two directions: Why not check file headers of any executable that is running on the box at my desktop pc! ;-).
Quote from: readelf -h cat
ELF Header:
  Magic:   7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF32
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           MIPS R3000
  Version:                           0x1
  Entry point address:               0x404690
  Start of program headers:          52 (bytes into file)
  Start of section headers:          448460 (bytes into file)
  Flags:                             0x50001005, noreorder, cpic, o32, mips32
  Size of this header:               52 (bytes)
  Size of program headers:           32 (bytes)
  Number of program headers:         8
  Size of section headers:           40 (bytes)
  Number of section headers:         29
  Section header string table index: 28

Looks very similar except the "flags: cpic" and the hex value,
Title: Re: ppcmipsel on openwrt/freetz
Post by: BigChimp on April 21, 2013, 10:01:37 am
Yep diff shows differences in
* entry point address (probably not important?)
* start of section headers (likewise)
* Flags: 0x50001001 for FPC where the working one has 0x50001005 and it also has cpic as you mentioned
* Number of program headers, section headers, string table index

No idea if the difference in flags is relevant (don't even know what they signify :) )
Title: Re: ppcmipsel on openwrt/freetz
Post by: Ocye on April 21, 2013, 12:17:35 pm
I can compile with -Cg and get CPIC into.
Quote
Flags:                             0x50001005, noreorder, cpic, o32, mips32
According to this posting (http://comments.gmane.org/gmane.linux.ports.mips.general/19408) the 0x5... flag is a bug. But how do I change the elf header?
Title: Re: ppcmipsel on openwrt/freetz
Post by: BigChimp on April 21, 2013, 03:01:28 pm
Yep. Don't know how you can change it; perhaps ask on the fpc list; there might be a workaround in the compiler (or perhaps... we can get one put in ;) )
Title: Re: ppcmipsel on openwrt/freetz
Post by: BigChimp on April 22, 2013, 08:21:02 am
Got this response on the fpc list, suggesting looking into ld
http://www.mail-archive.com/fpc-pascal@lists.freepascal.org/msg32685.html

Also found this, might be useful/relevant:
http://www.mail-archive.com/fpc-devel@lists.freepascal.org/msg27995.html
Title: Re: ppcmipsel on openwrt/freetz
Post by: Ocye on April 25, 2013, 09:55:27 am
Thanks for your assistance. Maybe my reply was not correct but it can be found in the archives: http://lists.freepascal.org/lists/fpc-pascal/2013-April/037676.html
Title: Re: ppcmipsel on openwrt/freetz
Post by: BigChimp on August 01, 2013, 12:20:15 am
Hi Ocye/anybody else - I'm wondering whether you ever tried again with a newer FPC version...

thanks,
BigChimp
Title: Re: ppcmipsel on openwrt/freetz
Post by: Ocye on August 01, 2013, 02:37:57 pm
No, I capitulated for now. Is there any reason why newer releases should work better?
Title: Re: ppcmipsel on openwrt/freetz
Post by: BigChimp on August 01, 2013, 02:44:38 pm
There might have been fixes meanwhile, but I'm not sure. Would have to go through the changelog (or simply try myself ;) ).

I've got some crossbinutils that I downloaded from the crossfpc site; in the upcoming days I might have a look at extending fpcup to build crosscompilers for arm etc... and finally test it on my fritzbox...
Title: Re: ppcmipsel on openwrt/freetz
Post by: Ocye on August 01, 2013, 02:58:04 pm
...and finally test it on my fritzbox...
Please report your success story then :-)
Title: Re: ppcmipsel on openwrt/freetz
Post by: BigChimp on August 04, 2013, 11:02:11 am
Success  8-)

Updated fpcup to include a win=>mipsel cross compiler. Used cross binutils from svn2.freepascal.org (see m_win32_to_linuxmips.pas for instructions/details) in c:\development\cross\bin\mipsel-linux

Copied over codesourcery mipsel softfloat uclibc libs to c:\development\cross\lib\mipsel-linux:
Code: [Select]
crtbegin.o
crtbeginS.o
crtbeginT.o
crtend.o
crtendS.o
crtfastmath.o
libgcc.a
libgcc_eh.a
libgcov.a
... which is a sneaky workaround for copying the real libraries from your real system and won't always work AFAIU...

Ran
Code: [Select]
rem Get newest fpc etc for native first:
fpcup
rem Now build cross compiler:
fpcup --only=fpc --cputarget=mipsel --ostarget=linux --verbose

compiled a test application:
Code: [Select]
program test;

begin
  writeln('DATE ',{$i %DATE%});
  writeln('FPCTARGET ',{$i %FPCTARGET%});
  writeln('FPCTARGETCPU ',{$i %FPCTARGETCPU%});
  writeln('FPCTARGETOS ',{$i %FPCTARGETOS%});
  writeln('FPCVERSION ',{$i %FPCVERSION%});
end.

Edit: file available at http://ubuntuone.com/2XpzJVHN8v230xDrGtyf1j

copied it over using ftp to the /var directory in my ancient Fritz!box 7170/7something clone, chmod u+rx /var/test and it ran ;)

Now continuining on with the linux=>mipsel version...
Title: Re: ppcmipsel on openwrt/freetz
Post by: Ocye on August 06, 2013, 01:28:41 pm
Second part (when Linux works as well) of this exercise would be to run mySQL (or rather MariaDB) on the device and to connect to the db with the program. I'm using currently a SheevaPlug which has a very slow file access. That might become a problem too.
Title: Re: ppcmipsel on openwrt/freetz
Post by: BigChimp on August 06, 2013, 07:24:23 pm
Ok ;)

Got a cross compiler build working after struggling a bit (started with an old version of the binutils to match my old fritz clone but that errored out during make).
However, the cross compile step in fpcup/fpc make seems to hang.

Haven't figured out what it is yet; testing by others welcome.

Thanks,
BigChimp
Title: Re: ppcmipsel on openwrt/freetz
Post by: herux on August 05, 2016, 11:51:14 am
Hi all

Any update about this ?

I have success build fpc cross compile for mips-linux, succeded too for compile helloworld.
when I copied to my http://www.gl-inet.com ,  It stucks just waiting for ctrl-c

I am using fpc trunk this day
TinyPortal © 2005-2018