Recent

Author Topic: cross to RasPi  (Read 4071 times)

dbannon

  • Hero Member
  • *****
  • Posts: 1532
    • tomboy-ng, a rewrite of the classic Tomboy
cross to RasPi
« on: July 23, 2021, 10:39:21 am »
Thanks to covid, I had some time on my hands and thought I'd use it to write up how to cross compile from a Linux intel box to a Raspberry Pi. Cannot be that hard.

Indeed, almost trivial to make an arm binary (ie armel), but not a armhf one.  Now, the softfloat works fine on a Raspberry Pi and unless its doing a lot of maths, it would not matter. EXCEPT that if you make a debian package that includes a soft arm binary, apt says, "wow, this binary is arm, it therefore depends on somepackage:arm and I cannot find any of them"

So, doing my research, seems I need to pass -CaEABIHF to the compiler, probably while I build the cross compiler, probably in the app. Nope, Error: Illegal parameter: -CaEABIHF in either case. Seems the cross compiler builds OK but first thing it tries to make, system.pp, fails. See -

Code: [Select]
/usr/arm-linux-gnueabihf/bin/as -meabi=5 -o /usr/share/fpcsrc/3.2.2/rtl/units/arm-linux/ucprt0.o arm/ucprt0.as
/usr/share/fpcsrc/3.2.2/compiler/ppcrossarm -Ur -Parm -Ur -Xs -O2 -n -Fi../inc -Fi../arm -Fi../unix -Fiarm -FD/usr/arm-linux-gnueabihf/bin -FE. -FU/usr/share/fpcsrc/3.2.2/rtl/units/arm-linux -CaEABIHF -darm -dRELEASE -CaEABIHF  -Us -Sg system.pp
Error: Illegal parameter: -CaEABIHF

My command line to trigger this was -

Code: [Select]
make clean all OS_TARGET=linux CPU_TARGET=arm  CROSSBINDIR=/usr/arm-linux-gnueabihf/bin   CROSSOPT=" -CaEABIHF "
but I have tried several combinations of CROSSOPT="-CpARMV6 -CfVFPV2 -OoFASTMATH" - that works OK but makes an armel, as soon as I put the -CaEABIHF in there it fails.  Likewise, putting the -CaEABIHF in after the cross compiler and lcl is built triggers a problem when compiling an app.

So, my question is, is -CaEABIHF no longer the way to go, whats its replacement. Or is there some other way to cross compile an armhf binary ?

On a 'real' raspberry pi, the compiler is capable of doing either default or EABIHF, I assume default is armel. But v=cannot find anything written on the subject.

Any ideas please ?

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

PascalDragon

  • Hero Member
  • *****
  • Posts: 3310
  • Compiler Developer
Re: cross to RasPi
« Reply #1 on: July 23, 2021, 12:34:17 pm »
Build FPC as follows:

Code: [Select]
make all FPMAKEOPT="-T 4" CPU_TARGET=arm OPT="-dFPC_ARMHF" CROSSOPT="-CpARMV6 -CaEABIHF" BINUTILSPREFIX=arm-linux-gnueabihf-
(please adjust the BINUTILSPREFIX to whatever you need)

Most important part is the OPT="-dFPC_ARMHF" and the -CpARMV6 is needed to ensure that it runs on older versions of the Pi (default for ARMHF is ARMv7).

You can then build applications without further EABIHF related options:

Code: [Select]
> ./compiler/ppcrossarm -n -Furtl/units/arm-linux -viwn -FEtestoutput -XParm-linux-gnueabihf- ./fpctests/thello.pp
Target OS: Linux for ARMHF
Compiling ./fpctests/thello.pp
Linking testoutput/thello
11 lines compiled, 0.2 sec, 202336 bytes code, 47892 bytes data

Note: I did not install the compiler, thus the manual passing of the general options; if you install it using make crossinstall (with the correct options of course) then you don't need to pass those.

dbannon

  • Hero Member
  • *****
  • Posts: 1532
    • tomboy-ng, a rewrite of the classic Tomboy
Re: cross to RasPi
« Reply #2 on: July 23, 2021, 01:00:34 pm »
Ah, Pascal Dragon, to my rescue again !

I had just found out about the -dFPC_ARMHF but not the -T 4 so I will need to add that.

I have not tried your full commandline yet but with just the -dFPC_ARMHF I was finally getting a hard float but still not what Debian calls HF, maybe your T 4 will help, thanks, I have been working on this all day !

Thanks

EDIT: Yep, your suggestion (and fixing a typo in my build script) and it all works !   Thanks !
« Last Edit: July 23, 2021, 01:12:10 pm by dbannon »
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

dbannon

  • Hero Member
  • *****
  • Posts: 1532
    • tomboy-ng, a rewrite of the classic Tomboy
Re: cross to RasPi
« Reply #3 on: July 24, 2021, 03:56:22 am »
Hmm, I am still unsure of whats happening here.  Lazarus (with no ugly hack to fpc.cfg) does make a armhf binary. See -

 
Code: [Select]
dbannon@U2104G-VirtualBox:~/Pascal/ArmTest$ readelf -h project1  | grep Flags
  Flags:                             0x5000400, Version5 EABI, hard-float ABI         <<< NOTE THIS

But using fpc -Parm or ppcrossarm directly does not. It says it is targeting ARMHF but it lies -

Code: [Select]
dbannon@U2104G-VirtualBox:~/Pascal/console$ ppcrossarm -dFPC_ARMHF   hello.pas
Free Pascal Compiler version 3.2.2 [2021/07/23] for arm
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for ARMHF                                             <<< NOTE THIS
Compiling hello.pas
Linking hello
13 lines compiled, 0.2 sec
dbannon@U2104G-VirtualBox:~/Pascal/console$ readelf -h hello | grep Flags
  Flags:                             0x5000200, Version5 EABI, soft-float ABI            <<<< NOTE THIS
dbannon@U2104G-VirtualBox:~/Pascal/console$

Pascal Dragon, can you please look at the binary arm you made with readelf -h  ?

(I have tried adding things like -CpARMV6, -CaEABIHF and -XParm-linux-gnueabihf- on the compile line, no difference.)

Davo



Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

engkin

  • Hero Member
  • *****
  • Posts: 2924
Re: cross to RasPi
« Reply #4 on: July 24, 2021, 04:13:34 am »
You need to specify what you want using -Cf
Check what the compiler supports using -if


dbannon

  • Hero Member
  • *****
  • Posts: 1532
    • tomboy-ng, a rewrite of the classic Tomboy
Re: cross to RasPi
« Reply #5 on: July 24, 2021, 05:05:51 am »
OK, thanks Engkin, no, seems thats not the secret I am afraid -

Code: [Select]
dbannon@U2104G-VirtualBox:~/Pascal/ArmTest$ ppcrossarm -if
SOFT
LIBGCC
FPA
FPA10
FPA11
VFPV2
VFPV3
VFPV3_D16
FPV4_S16
VFPV4

dbannon@U2104G-VirtualBox:~/Pascal/console$ ppcrossarm -dFPC_ARMHF -CfFPV4_S16  hello.pas
Free Pascal Compiler version 3.2.2 [2021/07/23] for arm
Copyright (c) 1993-2021 by Florian Klaempfl and others
Error: You must use a FPU type of VFPV2, VFPV3 or VFPV3_D16 when using the EABIHF ABI target

So, I tried with  VFPV2, VFPV3 and VFPV3_D16, same result for each, eg -

Code: [Select]
dbannon@U2104G-VirtualBox:~/Pascal/console$ ppcrossarm -dFPC_ARMHF -CfVFPV3_D16  hello.pas
Free Pascal Compiler version 3.2.2 [2021/07/23] for arm
Copyright (c) 1993-2021 by Florian Klaempfl and others
Target OS: Linux for ARMHF
Compiling hello.pas
Linking hello
13 lines compiled, 0.2 sec
dbannon@U2104G-VirtualBox:~/Pascal/console$ readelf -h hello | grep Flags
  Flags:                             0x5000200, Version5 EABI, soft-float ABI

Interesting that the compiler will not let me use an FPU that is incompatible with ARMHF but still makes a soft arm binary ??

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

engkin

  • Hero Member
  • *****
  • Posts: 2924
Re: cross to RasPi
« Reply #6 on: July 24, 2021, 07:56:54 am »
You removed -CpARMV6 it needs it or V7A

dbannon

  • Hero Member
  • *****
  • Posts: 1532
    • tomboy-ng, a rewrite of the classic Tomboy
Re: cross to RasPi
« Reply #7 on: July 24, 2021, 11:56:09 am »
engkin, I tried all combinations, as I mentioned.  If I missed one combo that does work, can you tell me what it is please ?  Or is the compiler's policy here documented somewhere ?  Note, again, in all these cases, and the other ones I have tried, the compiler reports it is going to make an ARMHF binary but it does not do so.

I think I need to examine what Lazarus is doing.

Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

dbannon

  • Hero Member
  • *****
  • Posts: 1532
    • tomboy-ng, a rewrite of the classic Tomboy
Re: cross to RasPi
« Reply #8 on: July 25, 2021, 05:47:38 am »
OK, seems I have found whats happening, not sure it explains why, but does explain the issue.

Firstly, its not just a cross compile issue, same thing happens with a native compiler.

The compiler may not make an armhf if decides its not necessary.  In a very simple console demo app, including one with some floating point in it, cthreads seems to make all the difference, if cthreads is used, will make a armhf, comment out that line and it makes armel.

A more complicated Lazarus GUI app, such as my tomboy-ng, you always seem to get armhf. There is so much more code linked in, I guess, it finds somewhere, whatever it needs to trigger armhf.  So, only someone making a 'simple' console app need worry and all they need to do to ensure its armhf is to use cthreads.

In very many cases, an armel binary is fine anyway, its just package managers that get excited when we mix standards.

I'll note this behaviour on the wiki.

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng


dbannon

  • Hero Member
  • *****
  • Posts: 1532
    • tomboy-ng, a rewrite of the classic Tomboy
Re: cross to RasPi
« Reply #10 on: July 25, 2021, 07:07:07 am »
Hmm, thats interesting. For the mildly curious, Google is dropping armeabi-v7a-hard from android. And saying that there is no chip that actually "does" it anyway, its just a like a compiler directive that affects the way data is loaded into registers before a FP call.

While thats probably a sensible decision on Android where you may find a very wide range of chips underneath, on the RaspberryPi I wonder ? Users of the Raspberry Pi OS (ie Raspian) don't have a choice, the OS is ARMHF. I don't know about the other OSs made for Raspberry Pi hardware.

Even murkier in the later 64bit V8s, I sort of get the impression they run Raspberry Pi OS (whats wrong with Raspian?) in some sort of emulation mode.

Davo
Lazarus 2, Linux (and reluctantly Win10, OSX)
My Project - https://github.com/tomboy-notes/tomboy-ng

 

TinyPortal © 2005-2018