Problems building for ARM.

Rob Landley rob at landley.net
Wed Mar 3 06:41:45 UTC 2010


On Tuesday 02 March 2010 20:13:53 Gary Altenberg wrote:
> Thanks Rob,
>
> I downloaded cross-compiler-armv4tl and I can build with it but I still
> have my original problem. I get "BINFMT_FLAT: bad header magic" when I run
> busybox on my hardware. It doesn't matter if I compile with arm-linux or
> armv4tl I still get the error.

You're creating an ELF binary and your kernel is configured to only support bflt 
binaries.  You need to run the ELF binary through elf2flt.

  http://www.uclinux.org/bFLT/

Basically ELF is an archive format that has to be interpreted by a loader and 
spliced together into memory.  This lets you splice in shared libraries and 
stuff, but you have to copy it from the filesystem into memory.  Even statically 
linked ELF files need to be loaded, because there's read-only executable code, 
read-only data (that isn't executable), read/write global variables 
initialized to known values, and the bss segment is a chunk of prezeroed 
memory that isn't actually stored in the file but is allocated by your loader.  
An ELF file describs lots of different _types_ of memory the ELF loader has to 
set up.

The binflat format is designed for memory-backed filesystems (which live in ROM, 
Flash, or ramfs).  The point is to let you actually run the sucker straight 
out ROM (or flash, or the ramfs page cache) without having to use a loader to 
copy it into RAM.  The binflt file is a single binary blob, all mapped in as the 
same type of memory in one contiguous block.  You mmap the whole file, and jump 
right to the start of it, and that's it.  The point is to save memory.

There are other data formats, by the way.  If the file starts with #! then the 
kernel loads the file listed in the first line as a script interpreter.  There's 
a historical format called a.out that predates ELF.  There's also a misc 
binary loader.  See the kernel's menuconfig for details:

  http://kernel.org/doc/menuconfig/fs-Kconfig.binfmt.html#BINFMT_ELF

> I guess I wasn't clear about my problem. I have been able to build busybox
> if I just use CROSS_COMPILER="arm-linux-". But I was getting the
> BINFMT_FLAT error when I ran it so I thought I needed to add -elf2flt to
> the CFLAGS and that's when I get the linking errors.

In theory you can convert a statically linked ELF to binflt after generating it 
using bin2flt from the command line.  It's a bit like running strip on a binary 
vs the -s option to gcc.

I tend to find breaking things down into separate steps to be more 
controllable.  Your mileage may vary... :)

> So my real problem is why do I get BINFMT_FLAT? Does this have something to
> do with the version of uClinux I run on my board?

It's an option you select in your kernel .config.

Rob
-- 
Latency is more important than throughput. It's that simple. - Linus Torvalds


More information about the busybox mailing list