Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
820 views
in Technique[技术] by (71.8m points)

gcc - How can I create a modern cross compile toolchain for the Raspberry Pi 1?

At least Debian does not provide a usable toolchain to cross develop for the Raspberry Pi 1. The Linaro toochain is at the time of this writing too old for the Qt5 developer branch. There is a project crosstools-ng, which allows to easily build custom toolchains for all kinds of systems. It supports a fairly modern GCC 4.9.1. The configuration is a bit trial and error, but the main problem is, that the toolchain does not find all the include files or libraries. How is the crosstools-ng to be configured so it can be used to compile Qt5 for the Raspberry Pi 1?

A followup how a Raspberry Pi with Raspian has to be prepared to use this toolchain can be found here: How do I prepare a Raspberry Pi with Raspbian so I can cross compile Qt5 programs from a Linux host?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I start with the not found include/library problem first, since this goes a bit beyond the normal crosstools-ng installation/usage.

The problem is, that crosstools-ng rightfully creates gcc compiler, with a target tuple like: arm-vendor-linux-gnueabihf. This is totally correct. However, Raspian installs includes and libs in folders without vendor string: /lib/arm-linux-gnueabihf. Looks like pkg-config cannot handle this. crosstools-ng might be right with the tuple, but is also a bit heavy handed by refusing to add a function to remove this vendor string. The functions in crosstool-ng, which allow to modify the tuple and the vendor string are not an alternative. They just create symbolic links with a new name, but the tuple is hardcoded in GCC. The only way to properly get rid of the vendor string is to patch the crosstools-ng sources.

So the first step to get a functional Raspberry Pi/Raspian gcc 4.9.1 toolchain is to clone the crosstools-ng repository:

git clone git://crosstool-ng.org/crosstool-ng

Second is to patch sources:

diff --git a/scripts/config.guess b/scripts/config.guess
index dbfb978..9a35943 100755
--- a/scripts/config.guess
+++ b/scripts/config.guess
@@ -176,7 +176,7 @@ case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
            sh3el) machine=shl-unknown ;;
            sh3eb) machine=sh-unknown ;;
            sh5el) machine=sh5le-unknown ;;
-           *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
+           *) machine=${UNAME_MACHINE_ARCH} ;;
        esac
        # The Operating System including object format, if it has switched
        # to ELF recently, or will in the future.
diff --git a/scripts/config.sub b/scripts/config.sub
index 6d2e94c..f92db2b 100755
--- a/scripts/config.sub
+++ b/scripts/config.sub
@@ -317,7 +317,7 @@ case $basic_machine in
        | we32k 
        | x86 | xc16x | xstormy16 | xtensa 
        | z8k | z80)
-               basic_machine=$basic_machine-unknown
+               basic_machine=$basic_machine
                ;;
        c54x)
                basic_machine=tic54x-unknown

The rest is the standard configure/make/make install. The next step is to configure crosstools-ng correctly to build the desired toolchain. This is done with ct-ng menuconfig.

Going though every single config item would be extremely lengthy, so I added a working config file here: http://pastebin.com/MhQKnhpN

It can be imported and with Load an Alternate Configuration File. Finally ct-ng build builds in a few minutes a new toolchain. The toolchain is created in {HOME}/x-tools3, as defined in the config file. To change this, change 'Prefix directory' in 'Path and misc options'. But the toolchain can also be moved manually after the build.

The next question/answer will show how to use this toolchain to build a very modern Qt5 for the Raspberry Pi.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...