After failing to manually build my own gcc crosscompiler, I went for help at the crosstool-ng experts.
By using (gcc updated to 7.2.0) Slack ARM - current HF on a Pi2B board I followed these two recipes:
https://raspberrypi.stackexchange.co...ross-compiling
https://blog.kitware.com/cross-compi...-raspberry-pi/
The latest crosstool-ng stable Release 1.23.0 is not working with gcc 7.2.0, therefore I got their latest git build - 98b6a5a4503095ba539a415d90e3f2c5331985ed
This is what I did and got a cross-compiler that apparently is unable to produce arm & thumb1 code but only thumb2 (which is useless for armv6).
Code:
git clone https://github.com/crosstool-ng/crosstool-ng.git
cd crosstool-ng
./bootstrap
./configure
make -j 4 V=1
make install
ldconfig
- I used an external HDD with an empty 20GB ext4 partition, however 4 GB will suffice
- as you cannot run the crosstool-ng as root, you need to run everything (config too) as a simple user and change the permissions for the working dirs accordingly (need to have wr permission in the top dir)
Code:
chown -R your-user:users /mnt/hd/
su your-user
cd /mnt/hd/
# the .config file will be created here!
ct-ng menuconfig
- go into Paths and misc options. Enable Try features marked as EXPERIMENTAL.
- choose a suitable Prefix directory.
/mnt/hd/gcc-cross/${CT_TARGET}
- local tarballs directory
/mnt/hd/tarballs/
- working directory:
/mnt/hd/work/.build
- go to the Target options menu.
Target architecture: arm
Endianness: little endian
Bitness: 32-bit
Target Architecture (arm) --->
Default instruction set mode (arm) --->
Architecture level - for Pi1/0 only:
type: armv6
Floating point: (hardware (FPU)) --->
- go to Operating system menu and change Target OS to linux.
- in C library choose:
(glibc) --->
- in C compiler choose:
(gcc) --->
gcc version (7.2.0) --->
- check c++ -[*] C++
- in Linux Kernel I choose (I'm running 4.4.50)
linux-4.4.83
- in order to give the compilation enough RAM to use - edit /boot/config.txt and set the GPU RAM at 32MB (reboot to take effect):
gpu_mem=32
- you might also want to consider protecting your SDCard from excessive wear and change the swappiness:
echo 1 > /proc/sys/vm/swappiness
- also, IMPORTANT, run the compilation with ct-ng build.4 - that's 4 jobs for the four cores, by default the ct-ng build starts more and I got my RAM and swap filled - it killed the system!
- start the compilation and consider doing something useful for around 5 hours. Some inspiration:
https://imgs.xkcd.com/comics/compiling.png
Code:
unset CPLUS_INCLUDE_PATH
nohup ct-ng build.4 2>&1 | tee /mnt/hd/ct-ng.log &
As a note, after the compilation was done I changed back the permissions:
chown -R root:root /mnt/hd/
________________________________________________
RESULTS:
- not as expected, unfortunately
- the whole cross-compiler was created without any errors, but apparently I'm not able to generate arm code and also cannot generate simple vfp FPU code, but only NEON ???
I tried to test my new cross-compiler on a simple collection of source files by doing the following:
- setting up environment
Code:
export PATH=/mnt/hd/gcc-cross/arm-unknown-linux-gnueabihf/bin:$PATH
export CROSS_COMPILE=arm-unknown-linux-gnueabihf-
export CC=arm-unknown-linux-gnueabihf-gcc
- first try - some generic armv6 HF CFLAGS - result -> useless ARM Thumb2 & NEON FPU code
export CFLAGS="-march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard"
make V=1
.....
arm-unknown-linux-gnueabihf-gcc -O2 -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -c util.c
readelf -A tinymembench
Attribute Section: aeabi
File Attributes
Tag_CPU_name: "6ZK"
Tag_CPU_arch: v6KZ
Tag_ARM_ISA_use: Yes
Tag_THUMB_ISA_use: Thumb-2
Tag_FP_arch: VFPv3
Tag_Advanced_SIMD_arch: NEONv1
Tag_ABI_VFP_args: VFP registers
Tag_CPU_unaligned_access: v6
Tag_Virtualization_use: TrustZone
- second try:
export CFLAGS="-march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -marm -mthumb"
make V=1
....
arm-unknown-linux-gnueabihf-gcc -O2 -march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -marm -mthumb -c util.c
In file included from util.c:26:0:
/mnt/hd/gcc-cross/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/include/stdlib.h: In function 'atoi':
/mnt/hd/gcc-cross/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot/usr/include/stdlib.h:247:1: sorry, unimplemented: Thumb-1 hard-float VFP ABI
I checked crosstool-ng configuration file again - Target section - and found that the switch for creating arm code was enabled and the thumb disabled, exactly as I was configuring it through the menu-config. Should I enable thumb there, in order to get Thumb1 code ?
Here is what the new cross-compiler is capable of:
/mnt/hd/gcc-cross/arm-unknown-linux-gnueabihf/bin/arm-unknown-linux-gnueabihf-gcc -v
Using built-in specs.
COLLECT_GCC=/mnt/hd/gcc-cross/arm-unknown-linux-gnueabihf/bin/arm-unknown-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/mnt/hd/gcc-cross/arm-unknown-linux-gnueabihf/libexec/gcc/arm-unknown-linux-gnueabihf/7.2.0/lto-wrapper
Target: arm-unknown-linux-gnueabihf
Configured with: /mnt/hd/work/.build/arm-unknown-linux-gnueabihf/src/gcc/configure --build=armv7l-build_unknown-linux-gnueabihf --host=armv7l-build_unknown-linux-gnueabihf --target=arm-unknown-linux-gnueabihf --prefix=/mnt/hd/gcc-cross/arm-unknown-linux-gnueabihf --with-sysroot=/mnt/hd/gcc-cross/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot --enable-languages=c,c++ --with-arch=armv6 --with-float=hard --with-pkgversion='crosstool-NG crosstool-ng-1.23.0-202-g98b6a5a4' --enable-__cxa_atexit --disable-libmudflap --disable-libgomp --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libsanitizer --disable-libmpx --with-gmp=/mnt/hd/work/.build/arm-unknown-linux-gnueabihf/buildtools --with-mpfr=/mnt/hd/work/.build/arm-unknown-linux-gnueabihf/buildtools --with-mpc=/mnt/hd/work/.build/arm-unknown-linux-gnueabihf/buildtools --with-isl=/mnt/hd/work/.build/arm-unknown-linux-gnueabihf/buildtools --enable-lto --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --enable-threads=posix --enable-target-optspace --disable-plugin --disable-nls --disable-multilib --with-local-prefix=/mnt/hd/gcc-cross/arm-unknown-linux-gnueabihf/arm-unknown-linux-gnueabihf/sysroot --enable-long-long
Thread model: posix
gcc version 7.2.0 (crosstool-NG crosstool-ng-1.23.0-202-g98b6a5a4)
Some excerpts only:
/mnt/hd/gcc-cross/arm-unknown-linux-gnueabihf/bin/arm-unknown-linux-gnueabihf-gcc -march=armv6zk -Q --help=target
The following options are target specific:
-mabi= aapcs-linux
-march= armv6zk
-marm [enabled]
-mcpu= [default]
-mfix-cortex-m3-ldrd [enabled]
-mflip-thumb [disabled]
-mfloat-abi= hard
-mfp16-format= none
-mfpu= auto
-mstructure-size-boundary= 32
-mthumb [disabled]
-mthumb-interwork [enabled]
-mtls-dialect= gnu
-mtp= auto
-mvectorize-with-neon-quad [enabled]
-mword-relocations [disabled]
Known ARM ABIs (for use with the -mabi= option):
aapcs aapcs-linux apcs-gnu atpcs iwmmxt
auto crypto-neon-fp-armv8 fp-armv8 fpv4-sp-d16 fpv5-d16 fpv5-sp-d16 neon neon-fp-armv8 neon-fp16 neon-vfpv3 neon-vfpv4 vfp vfp3 vfpv2 vfpv3 vfpv3-d16 vfpv3-d16-fp16
vfpv3-fp16 vfpv3xd vfpv3xd-fp16 vfpv4 vfpv4-d16
Known floating-point ABIs (for use with the -mfloat-abi= option):
hard soft softfp
It looks like the cross-compiler is properly built, according to what I was configuring the crosstool-ng for, but the results are not really working for armv6 and I'm little bit lost right now:
https://stackoverflow.com/questions/...with-gnueabihf