Protocol

From Lundman Wiki
Revision as of 07:22, 6 January 2012 by Lundman (talk | contribs)
export CTARGET=mipsel-linux-uclibc
export ARCH=mips

rm -rf build
mkdir build
cd build
../binutils-2.17/configure \
	--target=$CTARGET \
	--prefix=/usr/local/$ARCH/ \
	--with-sysroot=/usr/local/$ARCH/$CTARGET \
	--disable-werror
make
make install

# It installs things we don't want (and will fail later)
rm -rf /usr/local/$ARCH/{info,lib,man,share}

export PATH=/usr/local/$ARCH/bin:$PATH


cd ../linux-2.6.15.7
yes "" | make ARCH=$ARCH oldconfig prepare

#With 2.6.x, this will probably end in an error because you don't have a gcc 
#cross-compiler yet, but you can ignore that.  Just copy over the headers:

mkdir -p /usr/local/$ARCH/$CTARGET/usr/include/
rsync -arv include/linux include/asm-generic /usr/local/$ARCH/$CTARGET/usr/include/
rsync -arv include/asm-$ARCH/ /usr/local/$ARCH/$CTARGET/usr/include/asm
 
cd ../uClibc-0.9.28.3/

make menuconfig
#Target Architecture: mips
#Target Architecture Features and Options: 
#  Target Process Architecture: MIPS I
#  Target Process Endianness: Little Endian
#  Target CPU has a memory management unit (MMU): YES
#  Enable floating point number support: YES
#  Target CPU has a floating point unit: NO
#  (/usr/local/mips/mipsel-linux-uclibc/usr) Linux kernel header location
#
#Library Installation Options
#  (/usr/local/mips/mipsel-linux-uclibc) uClibc runtime library directory
#  (/usr/local/mips/mipsel-linux-uclibc/usr) uClibc development environment
#
#uClibc development/debugging options
#  (mipsel-linux-uclibc-) Cross-compiling toolchain prefix

# This command should fail.
make CROSS=mipsel-linux-uclibc-  

# Copy the new include files
rsync -arvL include/ /usr/local/$ARCH/$CTARGET/sys-include


cd ../build/
rm -rf *

../gcc-4.0.4/configure \
	--target=$CTARGET \
	--prefix=/usr/local/mips \
	--with-sysroot=/usr/local/mips/$CTARGET \
	--enable-languages=c \
	--disable-shared \
	--disable-checking \
	--disable-werror \
       --disable-__cxa_atexit \
       --enable-target-optspace \
       --disable-nls \
       --enable-multilib \
       --with-float=soft \
       --enable-sjlj-exceptions \
       --disable-threads

make
make install

# Remove the temporary headers, and compile it properly.
rm -rf /usr/local/$ARCH/$CTARGET/sys-include


cd ../uClibc-0.9.28.3/

make CROSS=mipsel-linux-uclibc-
make install

# This bit fixes the C++ issue. But should not be required. TODO: Figure out why
cd /usr/local/$ARCH/$CTARGET/lib/
ln -s ../usr/lib/crt* .

# Now recompile gcc fully.
cd ../build/
rm -rf *
../gcc-4.0.4/configure \
       --target=$CTARGET \
       --prefix=/usr/local/mips \
       --with-sysroot=/usr/local/mips/$CTARGET \
       --enable-languages=c,c++ \
       --enable-shared \
       --disable-checking \
       --disable-werror \
       --disable-__cxa_atexit \
       --enable-target-optspace \
       --disable-nls \
       --enable-multilib \
       --with-float=soft \
       --enable-sjlj-exceptions \
       --enable-threads=posix


# It is likely it will fail on __ctype_touplow_t*, this is quite easy to fix.
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14939
# I went with the #ifdef changes of ../gcc-4.0.4/libstdc++-v3/config/locale/generic/c_locale.h
# and ../gcc-4.0.4/libstdc++-v3/config/os/gnu-linux/ctype_base.h 

make 
make install


Unfortunately this will use libc dynamic linker, which is incorrect. So at the moment, use the following line to compile your executables.

# gcc -Wl,--dynamic-linker,/lib/ld-uClibc.so.0 -o hello hello.c

I will attempt to find out how to make it use the correct dynamic linker by default.

Thanks to emveepee we now know one way to fix this, although the source line mentioned only sets it to libc if it is otherwise not specified. So there should be a proper way to specify with linker we want. If someone has time to research this, that would be appreciated. For now:

1. To get around the need to specify the dynamic-linker I found you could be able to modify the default 
dynamic-linker in gcc-4.0.4/gcc/config/mips/linux.h

I just modified line 118 to the proper setting rather than applying the patch discussed in the following
url and the problem goes away.

http://www.busybox.net/lists/uclibc/2004-January/007943.html

2. The soft floating-point functions will not be linked in by default without a patch
http://bugs.busybox.net/view.php?id=1069 which I haven't tried yet but linking in -lgcc_s also
solves the problem.



C200

Download the source package from [1]

export CTARGET=mipsel-linux-gnu
export ARCH=mips-4.3
mkdir build
cd build
../binutils-stable/configure --target=$TARGET --prefix=/usr/local/$ARCH/ --with-sysroot=/usr/local/$ARCH/$CTARGET --disable-werror
make
make install
export PATH=/usr/local/$ARCH/bin:$PATH
rm -rf *    # Delete everything in build directory

../gmp-stable/configure --target=$TARGET --prefix=/usr/local/$ARCH/ --with-sysroot=/usr/local/$ARCH/$CTARGET --disable-werror --disable-shared --disable-nls
make
make install


If you use the package, you need to specify that you wish to build little-endian. This is done with the "-EL" flag. You'd have to give it to gcc, g++, ld etc using CFLAGS=-EL, LDFLAGS=-EL etc. Another option is to make little wrapper files to pass the flag automatically, like:

-rwxr-xr-x 1 root root      65 Oct 15  2009 mipsel-linux-gnu-cpp
-rwxr-xr-x 1 root root      65 Oct 15  2009 mipsel-linux-gnu-g++
-rwxr-xr-x 1 root root      65 Oct 15  2009 mipsel-linux-gnu-gcc
-rwxr-xr-x 1 root root      65 Oct 15  2009 mipsel-linux-gnu-gcc-4.3.3

-rwxr-xr-x 1 root root  202404 Apr 13  2009 mips-linux-gnu-cpp
-rwxr-xr-x 1 root root  203588 Apr 13  2009 mips-linux-gnu-g++
-rwxr-xr-x 1 root root  201188 Apr 13  2009 mips-linux-gnu-gcc
-rwxr-xr-x 1 root root  201188 Apr 13  2009 mips-linux-gnu-gcc-4.3.3
# cat /usr/local/mips-4.3/bin/mipsel-linux-gnu-gcc
#!/bin/sh
exe=`echo $0 | sed s/mipsel/mips/g`
exec $exe -EL "$@"

Possibly, this bash script will work:

cd /usr/local/mips-4.3/bin
for i in mipsel-linux-gnu-addr2line mipsel-linux-gnu-ar mipsel-linux-gnu-as mipsel-linux-gnu-c++ mipsel-linux-gnu-c++filt mipsel-linux-gnu-cpp mipsel-linux-gnu-g++ mipsel-linux-gnu-gcc mipsel-linux-gnu-gcc-4.3.3 mipsel-linux-gnu-gcov mipsel-linux-gnu-gdb mipsel-linux-gnu-gdbtui mipsel-linux-gnu-gprof mipsel-linux-gnu-ld mipsel-linux-gnu-nm mipsel-linux-gnu-objcopy mipsel-linux-gnu-objdump mipsel-linux-gnu-ranlib mipsel-linux-gnu-readelf mipsel-linux-gnu-size mipsel-linux-gnu-strings mipsel-linux-gnu-strip
do
cat <<EOF > $i
#!/bin/sh
exe=\`echo \$0 | sed s/mipsel/mips/g\`
exec \$exe -EL "\$@"
EOF
chmod 755 $i
done


Then when you are compiling things in future, you can go:

./configure --host=mipsel-linux-gnu