Difference between revisions of "Compile for the PhatBox"

From PhatHack Wiki
Jump to navigation Jump to search
m (Reverted edits by Conoc4touc (Talk); changed back to last version by Sbingner)
 
(5 intermediate revisions by 3 users not shown)
Line 2: Line 2:
 
Here are some notes on how to compile C programs to run on the PhatBox. It's from memory, so some of the details may be slightly wrong -- please edit this page if you have any corrections. --bushing
 
Here are some notes on how to compile C programs to run on the PhatBox. It's from memory, so some of the details may be slightly wrong -- please edit this page if you have any corrections. --bushing
   
  +
Edit: I recompiled with a combo of gcc and glibc that was listed as supported for ARM on crosstool, the configs I used are listed below. This did NOT segfault on compiled using full glibc rather than diet.
= Cross-Compiler =
 
  +
Build a cross-compiler for ARM (the processor used in the PhatBox). The PhatBox guys used gcc-2.95.3, so that's what I used.
 
 
= Cross-Compiler HowTo =
  +
Alternatively to a full compilation, a compiler that is almost, if not the same, as the one used by Phatnoise is available from http://www.opto22.com/site/downloads/drilldown.aspx?aid=1408
  +
 
How to build a cross-compiler for ARM (the processor used in the PhatBox).
   
 
The [http://kegel.com/crosstool/ crosstool] utility makes this very easy under Unix-like systems (e.g. Linux).
 
The [http://kegel.com/crosstool/ crosstool] utility makes this very easy under Unix-like systems (e.g. Linux).
Line 12: Line 16:
 
KERNELCONFIG=`pwd`/arm.config
 
KERNELCONFIG=`pwd`/arm.config
 
GCC_EXTRA_CONFIG="--with-cpu=arm7tdmi --enable-cxx-flags=-mcpu=arm7tdmi"
 
GCC_EXTRA_CONFIG="--with-cpu=arm7tdmi --enable-cxx-flags=-mcpu=arm7tdmi"
TARGET=arm-linux
+
TARGET=arm-7tdmi-linux-gnu
 
TARGET_CFLAGS="-Os"
 
TARGET_CFLAGS="-Os"
 
GLIBC_EXTRA_CONFIG=--enable-omitfp
 
GLIBC_EXTRA_CONFIG=--enable-omitfp
Line 19: Line 23:
 
#!/bin/sh
 
#!/bin/sh
 
set -ex
 
set -ex
TARBALLS_DIR=$HOME/downloads
+
TARBALLS_DIR=/mnt/lv0/shared/phat/downloads
 
RESULT_TOP=/opt/crosstool
 
RESULT_TOP=/opt/crosstool
 
export TARBALLS_DIR RESULT_TOP
 
export TARBALLS_DIR RESULT_TOP
 
GCC_LANGUAGES="c,c++"
 
GCC_LANGUAGES="c,c++"
  +
CC="gcc"
export GCC_LANGUAGES
 
  +
PARALLELMFLAGS="-j 2"
eval `cat arm.dat gcc-2.95.3-glibc-2.1.3.dat` sh all.sh --notest
 
 
export GCC_LANGUAGES DISTCC CC PARALLELMFLAGS
 
eval `cat arm.dat gcc-3.4.3-glibc-2.3.4.dat` sh all.sh --notest
   
 
''(As root) create the directory /opt/crosstool and make it writable by you, and finally (as you) run the demo script, e.g.''
 
''(As root) create the directory /opt/crosstool and make it writable by you, and finally (as you) run the demo script, e.g.''
Line 32: Line 38:
   
 
...and wait for it to compile.
 
...and wait for it to compile.
  +
  +
''Oaf: I found that building using kernel 2.6.8 header files on [http://fedora.redhat.com/ Fedora Core 4] resulted in this error:''
  +
  +
HOSTCC scripts/kconfig/mconf.o
  +
scripts/kconfig/mconf.c:91: error: static declaration of ‘current_menu’ follows non-static declaration
  +
scripts/kconfig/lkc.h:63: error: previous declaration of ‘current_menu’ was here
  +
make[1]: *** [scripts/kconfig/mconf.o] Error 1
  +
make: *** [oldconfig] Error 2
  +
  +
''This is due to Fedora using gcc 4, earlier versions (pre 3.5?) didn't generate this error - you should either use the following patch:''
  +
  +
Index: package/config/mconf.c
  +
===================================================================
  +
--- package/config/mconf.c (revision 10888)
  +
+++ package/config/mconf.c (working copy)
  +
@@ -101,7 +101,7 @@
  +
static int indent = 0;
  +
static struct termios ios_org;
  +
static int rows, cols;
  +
-static struct menu *current_menu;
  +
+struct menu *current_menu;
  +
static int child_count;
  +
static int single_menu_mode;
  +
  +
''...or use more uptodate [http://www.kernel.org kernel header files], e.g. 2.6.12.3, where the bug is fixed. In order to make crosstool use the newer kernel enter the following in the gcc-3.4.3-glibc-2.3.4.dat file in the crosstool directory.''
  +
  +
BINUTILS_DIR=binutils-2.15
  +
GCC_DIR=gcc-3.4.3
  +
GLIBC_DIR=glibc-2.3.4
  +
LINUX_DIR=linux-2.6.12.3
  +
GLIBCTHREADS_FILENAME=glibc-linuxthreads-2.3.4
   
 
= libc =
 
= libc =

Latest revision as of 18:04, 1 January 2009

Here are some notes on how to compile C programs to run on the PhatBox. It's from memory, so some of the details may be slightly wrong -- please edit this page if you have any corrections. --bushing

Edit: I recompiled with a combo of gcc and glibc that was listed as supported for ARM on crosstool, the configs I used are listed below. This did NOT segfault on compiled using full glibc rather than diet.

Cross-Compiler HowTo

Alternatively to a full compilation, a compiler that is almost, if not the same, as the one used by Phatnoise is available from http://www.opto22.com/site/downloads/drilldown.aspx?aid=1408

How to build a cross-compiler for ARM (the processor used in the PhatBox).

The crosstool utility makes this very easy under Unix-like systems (e.g. Linux).

The configuration files I used were:

arm.dat

KERNELCONFIG=`pwd`/arm.config
GCC_EXTRA_CONFIG="--with-cpu=arm7tdmi --enable-cxx-flags=-mcpu=arm7tdmi"
TARGET=arm-7tdmi-linux-gnu
TARGET_CFLAGS="-Os"
GLIBC_EXTRA_CONFIG=--enable-omitfp

demo-arm.sh

#!/bin/sh
set -ex
TARBALLS_DIR=/mnt/lv0/shared/phat/downloads
RESULT_TOP=/opt/crosstool
export TARBALLS_DIR RESULT_TOP
GCC_LANGUAGES="c,c++"
CC="gcc"
PARALLELMFLAGS="-j 2"
export GCC_LANGUAGES DISTCC CC PARALLELMFLAGS
eval `cat arm.dat gcc-3.4.3-glibc-2.3.4.dat` sh all.sh --notest

(As root) create the directory /opt/crosstool and make it writable by you, and finally (as you) run the demo script, e.g.

$ sudo mkdir /opt/crosstool
$ sudo chown $USER /opt/crosstool
$ sh demo-arm.sh

...and wait for it to compile.

Oaf: I found that building using kernel 2.6.8 header files on Fedora Core 4 resulted in this error:

HOSTCC  scripts/kconfig/mconf.o
scripts/kconfig/mconf.c:91: error: static declaration of  ‘current_menu’ follows non-static declaration
scripts/kconfig/lkc.h:63: error: previous declaration of ‘current_menu’ was here
make[1]: *** [scripts/kconfig/mconf.o] Error 1
make: *** [oldconfig] Error 2

This is due to Fedora using gcc 4, earlier versions (pre 3.5?) didn't generate this error - you should either use the following patch:

Index: package/config/mconf.c
===================================================================
--- package/config/mconf.c      (revision 10888)
+++ package/config/mconf.c      (working copy)
@@ -101,7 +101,7 @@
 static int indent = 0;
 static struct termios ios_org;
 static int rows, cols;
-static struct menu *current_menu;
+struct menu *current_menu;
 static int child_count;
 static int single_menu_mode;

...or use more uptodate kernel header files, e.g. 2.6.12.3, where the bug is fixed. In order to make crosstool use the newer kernel enter the following in the gcc-3.4.3-glibc-2.3.4.dat file in the crosstool directory.

BINUTILS_DIR=binutils-2.15
GCC_DIR=gcc-3.4.3
GLIBC_DIR=glibc-2.3.4
LINUX_DIR=linux-2.6.12.3
GLIBCTHREADS_FILENAME=glibc-linuxthreads-2.3.4

libc

In order to actually compile programs, you also need a libc (c library). Crosstool will build you a glibc, but none of the programs I compiled with it actually worked.

So, I turned to diet libc - a libc optimized for small size. I found that I had to first make a version for i386 (to get the build-i386/diet program), and then I could build a version for arm. IE:

$ make
$ make arm

You will then have a program called diet in the bin-i386 directory. Copy this into your path, and then you can build programs for the PhatBox by running

$ diet arm-linux-gcc -o hello hello.c

(this is a GCC wrapper)