I have a buildroot system for cortex-M3 without MMU based on ucLinux kernel 2.6.33. Support for FLAT, ZFLAT, SHARED_FLAT enabled in kernel. Inside buildroot everything is set to M3 etc. I have working system with working kernel and busybox (which is only ok binary in userspace). There are no uClibc on system or any other libs. I'm trying to build simplest userspace app like this: main(){}
I tried with different flags. Latest combination was like this:
^[[7m>>> zpm_t 1.0 Building^[[27m
/usr/bin/make -j5 FLAGS="-c -mthumb -march=armv7 -mfix-cortex-m3-ldrd" EXTRA_LDFLAGS="-Wl,-elf2flt,--static" CC="/mnt/repos/repos/github/nocturn_buildroot/output/host/usr/bin/ccache /mnt/repos/repos/github/nocturn_buildroot/output/host/usr/bin/arm-uclinuxeabi-gcc" LD="/mnt/repos/repos/github/nocturn_buildroot/output/host/usr/bin/arm-uclinuxeabi-ld" HEADERS="-I/mnt/repos/repos/github/nocturn_buildroot/output/target/usr/include/SDL" LIBS="-L/mnt/repos/repos/github/nocturn_buildroot/../nocturn_tools/arm-2010q1/arm-uclinuxeabi/libc/usr/lib" -C /mnt/repos/repos/github/nocturn_buildroot/output/build/zpm_t-1.0 all
make[1]: Entering directory /mnt/repos/repos/github/nocturn_buildroot/output/build/zpm_t-1.0'
/mnt/repos/repos/github/nocturn_buildroot/output/host/usr/bin/ccache /mnt/repos/repos/github/nocturn_buildroot/output/host/usr/bin/arm-uclinuxeabi-gcc -c -mthumb -march=armv7 -mfix-cortex-m3-ldrd -I/mnt/repos/repos/github/nocturn_buildroot/output/target/usr/include/SDL t.c
/mnt/repos/repos/github/nocturn_buildroot/output/host/usr/bin/ccache /mnt/repos/repos/github/nocturn_buildroot/output/host/usr/bin/arm-uclinuxeabi-gcc -Wl,-elf2flt,--static t.o -L/mnt/repos/repos/github/nocturn_buildroot/../nocturn_tools/arm-2010q1/arm-uclinuxeabi/libc/usr/lib -o t
make[1]: Leaving directory
/mnt/repos/repos/github/nocturn_buildroot/output/build/zpm_t-1.0'
flat file seems to be ok:
$ arm-uclinuxeabi-flthdr output/target/opt/t
output/target/opt/t
Magic: bFLT
Rev: 4
Build Date: Wed Sep 24 00:28:31 2014
Entry: 0x45
Data Start: 0x1f00
Data End: 0x1f70
BSS End: 0x1fa0
Stack Size: 0x1000
Reloc Start: 0x1f70
Reloc Count: 0x29
Flags: 0x1 ( Load-to-Ram )
But on system I always have a segfault which is not so informative:
/opt # ./t
[ 23.200000]
[ 23.200000]
[ 23.200000] t: fault at 0xa0501dd4 [pc=0xa0501dd4, sp=0xa0503f28]
[ 23.200000] Invalid ISA state
[ 23.200000]
SEGV
What did I miss? It should be something very simple. Also - what to do with uClibc? Should it be compiled into every binary executable or should I place it on the system somehow?
I have linked my app with wrong library. I had to take pre-built one from thumb2 folder inside toolchain (for M3):
LIBS="-L$(TOPDIR)/../tools/arm-2010q1/arm-uclinuxeabi/libc/thumb2/usr/lib"
Just fixing it helps. As I have libc.a and libm.a as static archives - just fixing LIBS is enough. And no flags like -lm needed. During buildroot compilation it takes needed part of static libs and creates a working FLAT binary.