Recent

Author Topic: ppcmipsel on openwrt/freetz  (Read 24048 times)

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
ppcmipsel on openwrt/freetz
« 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.
Lazarus 1.7 (SVN) FPC 3.0.0

jwdietrich

  • Hero Member
  • *****
  • Posts: 1236
    • formatio reticularis
Re: ppcmipsel on openwrt/freetz
« Reply #1 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?
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 3.4.0 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: ppcmipsel on openwrt/freetz
« Reply #2 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.
Lazarus 1.7 (SVN) FPC 3.0.0

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: ppcmipsel on openwrt/freetz
« Reply #3 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 ;)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: ppcmipsel on openwrt/freetz
« Reply #4 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,
Lazarus 1.7 (SVN) FPC 3.0.0

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: ppcmipsel on openwrt/freetz
« Reply #5 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 :) )
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: ppcmipsel on openwrt/freetz
« Reply #6 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 the 0x5... flag is a bug. But how do I change the elf header?
Lazarus 1.7 (SVN) FPC 3.0.0

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: ppcmipsel on openwrt/freetz
« Reply #7 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 ;) )
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: ppcmipsel on openwrt/freetz
« Reply #8 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
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: ppcmipsel on openwrt/freetz
« Reply #9 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
Lazarus 1.7 (SVN) FPC 3.0.0

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: ppcmipsel on openwrt/freetz
« Reply #10 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
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: ppcmipsel on openwrt/freetz
« Reply #11 on: August 01, 2013, 02:37:57 pm »
No, I capitulated for now. Is there any reason why newer releases should work better?
Lazarus 1.7 (SVN) FPC 3.0.0

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: ppcmipsel on openwrt/freetz
« Reply #12 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...
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: ppcmipsel on openwrt/freetz
« Reply #13 on: August 01, 2013, 02:58:04 pm »
...and finally test it on my fritzbox...
Please report your success story then :-)
Lazarus 1.7 (SVN) FPC 3.0.0

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: ppcmipsel on openwrt/freetz
« Reply #14 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...
« Last Edit: August 04, 2013, 11:04:03 am by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

 

TinyPortal © 2005-2018