LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Slackware (https://www.linuxquestions.org/questions/slackware-14/)
-   -   cross compiling for arm with buildroot (https://www.linuxquestions.org/questions/slackware-14/cross-compiling-for-arm-with-buildroot-859107/)

brooko 01-27-2011 03:59 PM

cross compiling for arm with buildroot
 
this is my first attempt at cross compiling. I'm trying to build some boot and kernel images for my WD Mybook world edition, which uses an arm processor on my x86_64 host box. Ultimately i'd like to install slackarm. Lilo doesn't work on arm so you have to compile your own kernel and have the bootloader statically linked to kernel inorder to boot the OS. So i'm using my slackware install to cross compile the boot loaders (u-boot) and kernel image (uImage).

I've successfully compiled the buildroot environment which has generated the arm-linux-* binaries, eg, gcc 3.4.2 for arm.
Code:

arm-linux-gcc-3.4.2 -> arm-linux-uclibc-gcc-3.4.2*
these are in a build folder (shortened in text below), which i add to my PATH
Code:

# add buildroot tools to PATH
nick@slackbox:/path/to/buildroot/build_arm_nofpu/staging_dir/bin$
nick@slackbox:/path/to/buildroot/build_arm_nofpu/staging_dir/bin$ PATH=$PWD:$PATH
nick@slackbox:/path/to/buildroot/build_arm_nofpu/staging_dir/bin$ echo $PATH
/path/to/buildroot/build_arm_nofpu/staging_dir/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/usr/lib64/java/bin:/usr/lib64/kde4/libexec:/usr/lib64/qt/bin:/usr/share/texmf/bin:.

I then move to the directory where i want to build the stage1 boot loader, which is supplied in the GPL code from WD.

Code:

# move to stage1 dir
cd /path/to/build/stage1
# build using buildroot binaries
make CROSS_CoMPILE=arm-linux-

however the build fails with a segfault, which looks to be caused by the incorrect libraries and compiler being used:

Code:

.............................
......lots of lines..........
.............................
COLLECT_GCC_OPTIONS='-c' '-v' '-g' '-I' '.' '-I' '../include' '-o' 'update_header.o' '-mtune=generic'
gcc crc32.o -lc -v update_header.o -o update_header
Reading specs from /usr/lib64/gcc/x86_64-slackware-linux/4.4.4/specs
Target: x86_64-slackware-linux
Configured with: ../gcc-4.4.4/configure --prefix=/usr --libdir=/usr/lib64 --enable-shared --enable-bootstrap --enable-languages=ada,c,c++,fortran,java,objc --enable-threads=posix --enable-checking=release --with-system-zlib --with-python-dir=/lib64/python2.6/site-packages --disable-libunwind-exceptions --enable-__cxa_atexit --enable-libssp --with-gnu-ld --verbose --disable-multilib --target=x86_64-slackware-linux --build=x86_64-slackware-linux --host=x86_64-slackware-linux
Thread model: posix
gcc version 4.4.4 (GCC)
COMPILER_PATH=/usr/libexec/gcc/x86_64-slackware-linux/4.4.4/:/usr/libexec/gcc/x86_64-slackware-linux/4.4.4/:/usr/libexec/gcc/x86_64-slackware-linux/:/usr/lib64/gcc/x86_64-slackware-linux/4.4.4/:/usr/lib64/gcc/x86_64-slackware-linux/:/usr/libexec/gcc/x86_64-slackware-linux/4.4.4/:/usr/libexec/gcc/x86_64-slackware-linux/:/usr/lib64/gcc/x86_64-slackware-linux/4.4.4/../../../../x86_64-slackware-linux/bin/
LIBRARY_PATH=/usr/lib64/gcc/x86_64-slackware-linux/4.4.4/:/usr/lib64/gcc/x86_64-slackware-linux/4.4.4/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib64/gcc/x86_64-slackware-linux/4.4.4/../../../../x86_64-slackware-linux/lib/:/usr/lib64/gcc/x86_64-slackware-linux/4.4.4/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'update_header' '-mtune=generic'
 /usr/libexec/gcc/x86_64-slackware-linux/4.4.4/collect2 --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o update_header /usr/lib64/gcc/x86_64-slackware-linux/4.4.4/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-slackware-linux/4.4.4/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-slackware-linux/4.4.4/crtbegin.o -L/usr/lib64/gcc/x86_64-slackware-linux/4.4.4 -L/usr/lib64/gcc/x86_64-slackware-linux/4.4.4/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-slackware-linux/4.4.4/../../../../x86_64-slackware-linux/lib -L/usr/lib64/gcc/x86_64-slackware-linux/4.4.4/../../.. crc32.o -lc update_header.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib64/gcc/x86_64-slackware-linux/4.4.4/crtend.o /usr/lib64/gcc/x86_64-slackware-linux/4.4.4/../../../../lib64/crtn.o
make[1]: Leaving directory `/home/public/MyBook/build/stage1/tools'
arm-linux-objcopy -O binary -R .note -R .comment -S stage1.elf stage1.bin
./tools/update_header stage1.bin
size in header:-509546482, size of file: 6436
make: *** [stage1.bin] Segmentation fault
make: *** Deleting file `stage1.bin'
nick@slackbox:......./build/stage1$

It seems to be using my x86_64 libs and gcc 4.4.4 which is the host compiler not the target.
I've tried setting ARCH=arm but got the same results.

Do i need to export some additional variables or unset some to prevent the host files being used instead of the targets?

Has anyone succesfully used the buildroot environment or offer and help?

Thanks

gnashley 01-28-2011 02:36 AM

COMPILER_PATH and LIBRARY_PATH show that your slackware x86_64 compiler and libs are being used.

I use a wrapper script for my alternate and cross-compilers which sets both PATH and LD_LIBRARY_PATH, like this:

Code:

#!/bin/sh
# change the paths below and name the script as something like: GCC336
# copy or save it somwhere in your normal PATH
# Then, to run make(for example) just run: 'GCC336 make'

PATH=/opt/gcc-3.3.6/bin:$PATH
export PATH=/opt/gcc-3.3.6/lib/gcc-lib/i486-slackware-linux/3.3.6:$PATH
export LD_LIBRARY_PATH=/opt/gcc-3.3.6/lib
exec "$@"


brooko 01-29-2011 03:51 AM

[solved]
 
Thanks gnashley, that was what i was missing.

After a bit of fiddling get the correct paths everything compiled ok.

I tested that the script was actually using the correct gcc version by a simple 'which gcc' after the script. I call my script buildarm.sh

Code:

#before
user@host:~$ which gcc
/usr/bin/gcc
user@host:~$

#after
user@host:/home/public/MyBook/build/stage1$ ./buildarm.sh which gcc
/home/public/MyBook/build/buildroot/build_arm_nofpu/staging_dir/arm-linux-uclibc/bin/gcc


gnashley 01-29-2011 11:42 AM

Exactly! I use a similar script for each of my alternate version or cross-compilers. Some people prefer to use pre- or appended names for the toolchain components, but I find it less troublesome to always use a uniuqe prefix for each toolchain and then use such a wrapper. Doing things the other way means you have to set CC and other such variables each time -and even then some Makefiles simply call 'gcc' so they may not find the right one. Changing the PATH makes things a bit easier.


All times are GMT -5. The time now is 11:07 AM.