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
Title: Re: ppcmipsel on openwrt/freetz
Post by: stokito on October 01, 2022, 11:12:11 am
Does anybody tried to compile Pascal to OpenWrt?

Today routers becomes more powerful (64mb disk and 128mb ram) but still not enough to run usual programs in NodeJS, Python or Java.
Golang is working but it's binaries are too bloated. This is not a niche for it.
So I think that Pascal may be a reasonably good choice especially given that it much more mature.
Regular developers can easily write their own soft like home automation or even backend for a website.

I wish to write a small but user friendly Email server with SMTP and POP and Indy is a very cool library to do that  https://github.com/IndySockets/Indy
I'm fine if it will be bigger than if written in pure C but instead I'll have a code that is easy to understand.

I have two routers: TP WR1043ND with mips32 CPU and more powerful Turris Omnia with the armhf armv7 CPU.
On my Ubuntu 22.04 I installed Lazarus and configured armv7 target but it said that arm is not supported.
For the mips target I found a wiki page https://wiki.freepascal.org/Native_MIPS_Systems
But it looks so difficult so that I'm afraid to touch it.

So I have few questions to you guys:
1. What is your opinion about trying to use Pascal for routers?
2. Is it possible to compile for the arm, armhf and mips without a pain?
3. Is any chances to make binaries smaller? Is it possible to use musl libc that is used by the OpenWrt?

Thank you in advance.
Title: Re: ppcmipsel on openwrt/freetz
Post by: MarkMLl on October 01, 2022, 11:51:18 am
Yes, go back through the forum and in particular the mailing list.

My recollection is that people ran into issues with the standard (i.e. system level) libraries not providing all the required facilities or similar. I can't remember the precise details other than that the symptoms were such that I suggested that the file command be run on the generated binary to check that everything was as expected.

MarkMLl
Title: Re: ppcmipsel on openwrt/freetz
Post by: stokito on October 03, 2022, 09:14:04 am
Thank you, MarkML. This looks too complicated.
When I selected the target mips and restarted the project I got the error:

The project uses target OS=linux and CPU=mips.
The system.ppu for this target was not found in the FPC binary directories.

As far I understood I have to compile FPC with some flag to support the mips.
It would be great if I can just install some package in apt but looks like there is only fpc and nothing else.
Title: Re: ppcmipsel on openwrt/freetz
Post by: dbannon on October 03, 2022, 01:13:45 pm
There are a  number of pre made FPC 'kits' to suit mips, mipsel and a range of arm cpus at https://sourceforge.net/projects/freepascal/files/Linux/3.2.2/

The wiki page, https://wiki.freepascal.org/Installing_the_Free_Pascal_Compiler#FPC_Tar_Balls talks about how to install them. While not specificially about cross compile, there should be enough information there. I think.

Davo
Title: Re: ppcmipsel on openwrt/freetz
Post by: MarkMLl on October 03, 2022, 01:29:09 pm
I was involved with some of the porting. It was about June, there were two different compiler attempts to be reconciled (they'd languished since SGI etc. had abandoned MIPS), and somebody in China was screaming for FPC support before the start of the next academic year: I suspect he'd sold a large number of small computers into schools on the basis that there was a Pascal compiler. The promised development hardware didn't arrive, so while I can say that it ran in emulation I never saw it running natively.

But since then I've /definitely/ seen reports of problems on OpenWRT, which I believe was a problem with the underlying libraries.

MarkMLl
TinyPortal © 2005-2018