How to cross compile a toolchain to an ARMv5 platf

2019-08-08 20:54发布

问题:

I am not looking to setup a toolchain to cross compile on an x86 host to an ARMv5 target (I already have that and it's working), but a toolchain to compile on an ARMv5 platform to an ARMv5 target(itself). I know I can always just cross compile all my needed applications, but I want to have a compiler run on the system so I will have a good idea of how to do the same for other boards like the Rasberry Pi and Beaglebone, and because it just seems pretty cool.

I have looked into crosstool-ng but as I understand it seems to only work for an x86 host to various targets, instead of various hosts for various targets.

Is there any recommended workflow for this? I was thinking of seeing how the people who handle distributions for boards like the Beaglebone do it, but I can't seem to find any information on that, are they using some proprietary solution?

The toolchain in question is this one from Sourcery CodeBench Lite which includes the source, but it seems that just running this through the already compiled cross compiler doesn't work.

I found some related questions but it seems that none of them got it going all the way, is there a guide for this out there somewhere? For all of you googling this like I am, and if this were to pop up in your results, here are some of the related questions:

Cross compile native gcc for arm with crosstool-ng, have toolchain, which architecture deps, and which build, host, and target?

how to change the host type for a 'Canadian cross' compilation of GCC with crosstool-NG

Cross compiling gcc

Compile GCC with Code Sourcery

compiling native GCC for arm using cross-compiler

回答1:

I managed to do this myself after a ton of futzing around with libraries and toolchains.

You need to first setup a cross compiler to compile ARMv5 executables for the ARM926J CPU. Why ARMv5 and ARM926J? Because I am using the SAM9N12 which utilizes the ARM926J code (J for Jazelle which runs a native JVM), with that core being an ARMv5 architecture.

You can get the cross compiler either from ARM's launchpad based GCC repo or make one yourself using Crosstools-NG. Using Crosstools-NG is recommended because you can use your own standard C library (GNU's version is monstrous compared to uClib or musl).

Lastly, you need to use your cross compiler to make a native ARM compiler. Normally, you would be able to do this with Crosstools-NG but the cross-native option is not implemented, so you have to do what is called a Canadian-Build which works just fine but does some redundant steps.

Since this question specified only for an idea of what general workflow to use, I will leave this as is and refer you to my other question asking specifically how to use Canadian-Build with Crosstools-NG considering Cross-Native is not implemented yet.