Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2020-09

How to build for arm6 in RaspberryPi on arm7?

8 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

I am using RPi3 and RPi4 platforms when working on RPi projects with Lazarus 2.0.8 and Fpc 3.0.4.
Now I realized that the binaries I create will probably not work on PiZero and RPi2 devices because these are Arm6 and the dev platform is Arm7.

Is there some project setting I can activate in order to build for *all* RPi devices by only using ARMv6 instructions?

I really do not want to work in the IDE on a PiZero or Pi2 because these are a bit slow...

Bo Berglund Developer in Sweden

Reply by email

Bo Berglund
to Bo Berglund
Bo Berglund wrote
Is there some project setting I can activate in order to build for *all* RPi devices by only using ARMv6 instructions?

I used Project/ProjectOptions/ConfigAndTarget and: set Target CPU family = arm
set Target processor = ARMV6

The project built fine on an RPi4B with 4GB RAM
And it ran just fine on the dev RPi4

So I used scp to copy the executable over to an RPiZero and test it there.

But I got an exception on this platform:

$ ./SerialTest
An unhandled exception occurred at $00031C44:
EAccessViolation: Access violation
$00031C44

This happened also after I ran a Run/CleanUpAndBuild operation, so clearly there is something I am missing here.

Bo Berglund Developer in Sweden

Reply by email

Jonas Maebe
to Bo Berglund
Bo Berglund wrote
This happened also after I ran a Run/CleanUpAndBuild operation, so clearly there is something I am missing here.

Is your FPC installation itself also built for ARMv6? (rtl and packages)

Jonas

Reply by email

Bo Berglund
to Jonas Maebe
Jonas Maebe wrote 6 lines
On 08/09/2020 16:13, Bo Berglund via fpc-pascal wrote: > This happened also after I ran a Run/CleanUpAndBuild operation, so > clearly there is something I am missing here. Is your FPC installation itself also built for ARMv6? (rtl and packages)

No, it is on an RPi4 so it is ArmV7.

I hoped the compiler could be set to use one instruction set or the other depending on this project setting.

I could presumably build another FPC 3.0.4 using the ArmV6 setting even though I am on an Armv7 system, right?
But the result has to go somewhere else. Or replace the previous one.

When doing a make install where would 3.0.4V6 go then? And what about the ~/.fpc,cfg where all of the settings for fpc are stored, can it be the same for both v6 and v7 compilers?

And finally, how to set Lazarus to use the v6 compiler rather than the v7?

Or maybe I have to compile fpc for V6 even though I am on V7 and thereafter only build ArmV6 compatible applications?

Probably also Lazarus itself needs to be recompiled to V6 because unless that is done there will be problems when it recompiles itself after package installations...
Especially if FPC has been replaced by a V6 version.

Bo Berglund Developer in Sweden

Reply by email

Bo Berglund
to Bo Berglund
Bo Berglund wrote
No, it is on an RPi4 so it is ArmV7.

In fact I have been told on the RPi forum RPi4 is Armv8 Armv6: Pi0, PiB, PiA+
Armv7: Pi2Bv1.1
Armv8: Pi2Bv1.2, Pi3, Pi4

But they could not advice how to use a newer RPi (higher numbered arm) to build an application that could run on earlier arm versions such as on the RPiZero.
They referred back here.

Anyway I used the Fpc/Lazarus installation I had done on the PiZero and opened the test project as checked out from svn. It could be built on the RPiZero and when I ran it (started from a terminal rather than from Lazarus) it worked as it should.

So:
If I install Fpc and Lazarus from sources as I always do and specify ArmV6 in the process on the RPiZero, then it will make an application that works fine there.

And when I transfer it to the RPi4 (using scp) it works fine also there...

Question:
Can I make a parallel installation of FPC and Lazarus on my RPi4 which is using the Armv6 settings during the make and thus get a system that will produce compatible programs?

Or do I have to scrap the existing installation altogether and then reinstall using Armv6 setrtings?

Bo Berglund Developer in Sweden

Reply by email

Tomas Hajny
to Bo Berglund
Bo Berglund wrote 35 lines
On Wed, 09 Sep 2020 00:03:29 +0200, Bo Berglund via fpc-pascal wrote: > No, it is on an RPi4 so it is ArmV7. In fact I have been told on the RPi forum RPi4 is Armv8 Armv6: Pi0, PiB, PiA+ Armv7: Pi2Bv1.1 Armv8: Pi2Bv1.2, Pi3, Pi4 But they could not advice how to use a newer RPi (higher numbered arm) to build an application that could run on earlier arm versions such as on the RPiZero. They referred back here. Anyway I used the Fpc/Lazarus installation I had done on the PiZero and opened the test project as checked out from svn. It could be built on the RPiZero and when I ran it (started from a terminal rather than from Lazarus) it worked as it should. So: If I install Fpc and Lazarus from sources as I always do and specify ArmV6 in the process on the RPiZero, then it will make an application that works fine there. And when I transfer it to the RPi4 (using scp) it works fine also there... Question: Can I make a parallel installation of FPC and Lazarus on my RPi4 which is using the Armv6 settings during the make and thus get a system that will produce compatible programs? Or do I have to scrap the existing installation altogether and then reinstall using Armv6 setrtings?

You don't need a different installation (although that might be an option as well), but you do need a different build of the RTL and packages. The concept of sub-architectures is supposed to help with this, but I don't know how far is the support in fp(c)make and the compiler. It may be done manually without any special support e.g. by renaming the directory with original RTL and packages, building the RTL and packages again with the required parameters and possibly renaming that one as well. Once you're finished with that, you may want to either modify your fp.cfg so that the paths to units, etc., are IFDEFed there, or you may remove all (sub)architecture dependent settings from the default configuration file, place these settings to two other configuration files containing settings for particular (sub)architectures and always specify the '@' option with the right configuration file when invoking the compiler.

Tomas

Reply by email

Bo Berglund
to Tomas Hajny
Tomas Hajny wrote 23 lines
> Question: > Can I make a parallel installation of FPC and Lazarus on my RPi4 which > is using the Armv6 settings during the make and thus get a system that > will produce compatible programs? > > Or do I have to scrap the existing installation altogether and then > reinstall using Armv6 setrtings? You don't need a different installation (although that might be an option as well), but you do need a different build of the RTL and packages. The concept of sub-architectures is supposed to help with this, but I don't know how far is the support in fp(c)make and the compiler. It may be done manually without any special support e.g. by renaming the directory with original RTL and packages, building the RTL and packages again with the required parameters and possibly renaming that one as well. Once you're finished with that, you may want to either modify your fp.cfg so that the paths to units, etc., are IFDEFed there, or you may remove all (sub)architecture dependent settings from the default configuration file, place these settings to two other configuration files containing settings for particular (sub)architectures and always specify the '@' option with the right configuration file when invoking the compiler.

OK, I conducted an experiment tonight, it took a while:

1) Grabbed a new SDcard and wrote PiOS Lite on it.

2) Configured the SDcard in another RPi4 where I can access all of the new SD and put my favourite .bashrc and init scripts etc on it.

3) Then I put my installation script for Fpc/Lazarus on it and edited it so it would install 3.0.4 and 2.0.8 and specified the Armv6 target when it ran.

4) The full installation including installing subversion and all dependencies before retrieving the fpc and lazarus sources via svn and building both and crteating the menu desktop entry took 18 minutes.

5) Inside Lazarus I then used OnLinePackageManager to install the extra packages I need all the time.

6) Finally I retrieved the sources for my test project too and opened it and built it successfully.

And this version works in both RPi4 and RPiZeroW! :-)

BOTTOM LINE:
------------
For development targeting any RPi version install fpc and lazarus using the ARMv6 flags to make in both cases.

What are the ramifications of not using a higher ARMvx number? Will the application perform worse and if so in what way?

I am not working on projects that need high perfoprmance in terms of speed anyway. I just want as snappy a dev IDE (==Lazarus) as possible...

Back to my original dev RPi4:
-----------------------------
Fpc and Lazarus were built using make in the source dirs and using the ARMv7 flag.
Now I would like to change it to be like the one described above. So can I just enter the 3.0.4 source dir and execute a make clean followed by the make commands used when building for ARMv6?

What about make install in FPC? Will it overwrite whatever stuff it wrote into ~/lib/fpc/3.0.4 and ~/share/...?

Is this the proper way to change the installation from v7 to v6?

Bo Berglund Developer in Sweden

Reply by email

Bo Berglund
to Bo Berglund
Bo Berglund wrote 47 lines
OK, I conducted an experiment tonight, it took a while: 1) Grabbed a new SDcard and wrote PiOS Lite on it. 2) Configured the SDcard in another RPi4 where I can access all of the new SD and put my favourite .bashrc and init scripts etc on it. 3) Then I put my installation script for Fpc/Lazarus on it and edited it so it would install 3.0.4 and 2.0.8 and specified the Armv6 target when it ran. 4) The full installation including installing subversion and all dependencies before retrieving the fpc and lazarus sources via svn and building both and crteating the menu desktop entry took 18 minutes. 5) Inside Lazarus I then used OnLinePackageManager to install the extra packages I need all the time. 6) Finally I retrieved the sources for my test project too and opened it and built it successfully. And this version works in both RPi4 and RPiZeroW! :-) BOTTOM LINE: ------------ For development targeting any RPi version install fpc and lazarus using the ARMv6 flags to make in both cases. What are the ramifications of not using a higher ARMvx number? Will the application perform worse and if so in what way? I am not working on projects that need high perfoprmance in terms of speed anyway. I just want as snappy a dev IDE (==Lazarus) as possible... Back to my original dev RPi4: ----------------------------- Fpc and Lazarus were built using make in the source dirs and using the ARMv7 flag. Now I would like to change it to be like the one described above. So can I just enter the 3.0.4 source dir and execute a make clean followed by the make commands used when building for ARMv6? What about make install in FPC? Will it overwrite whatever stuff it wrote into ~/lib/fpc/3.0.4 and ~/share/...? Is this the proper way to change the installation from v7 to v6?

Progress update (from the Fpc make thread):
-------------------------------------------
I proceeded to create a script that rebuilds fpc using the info obtained here.
I applied it on the rpi4-dev machine where fpc was installed as ARMv7. Took 10 minutes to complete the three steps.

make clean make all make install

Then I built the test application and copied it over to the PiZero where it did work just fine! No more exceptions!

So I can confirm that this rebuild method works.

Bo Berglund Developer in Sweden

Reply by email