2008年7月3日 星期四

embedded-lab1 Cross compiler

#!/bin/bash

# Setup

PROJECT=embedded/lab1
USER=root
PRJDIR=/${USER}/${PROJECT}
BUILD_DIR=${PRJDIR}/build-tools
PREFIX=${PRJDIR}/tools/arm
TARGET=arm-pc-linux-gnu
SYSROOT=${PREFIX}/sysroot
export ARCH=arm
export CROSS_COMPILE=${TARGET}-
export PATH=$PATH:${PREFIX}/bin

mkdir -p ${BUILD_DIR}/src

# Get the sources

cd ${BUILD_DIR}
for URL in \
http://ftp.gnu.org/gnu/binutils/binutils-2.16.tar.gz \
http://ftp.gnu.org/gnu/gcc/gcc-3.4.4/gcc-3.4.4.tar.bz2 \
"http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/flow.c.diff?cvsroot=gcc&only_with_tag=csl-arm-branch&r1=1.563.4.2&r2=1.563.4.3" \
http://frank.harvard.edu/~coldwell/toolchain/t-linux.diff \
http://ftp.gnu.org/gnu/glibc/glibc-2.3.5.tar.bz2 \
http://ftp.gnu.org/gnu/glibc/glibc-linuxthreads-2.3.5.tar.gz \
http://frank.harvard.edu/~coldwell/toolchain/ioperm.c.diff \
http://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.10.tar.gz
do
FILE=${URL##*/}
FILE=${FILE%%\?*}
[ -f ${FILE} ] || wget -O ${FILE} ${URL}
done

# GNU binutils

cd ${BUILD_DIR}/src
tar xvfz ../binutils-2.16.tar.gz
mkdir -p ../BUILD/binutils-2.16
cd ../BUILD/binutils-2.16
../../src/binutils-2.16/configure --prefix=${PREFIX} --target=${TARGET} --with-sysroot=${SYSROOT} 2>&1 | tee configure.out
make 2>&1 | tee make.out
make install 2>&1 | tee -a make.out

# Linux Kernel Headers

cd ${BUILD_DIR}/src
tar xvfz ../linux-2.6.10.tar.gz
ln -s linux-2.6.10 linux
#zcat 2.6.10-at91.patch.gz | patch -d linux -p1
#zcat 26_at91_serial.c.gz >linux/drivers/serial/at91_serial.c
cd linux
make lubbock_defconfig
make include/linux/version.h
mkdir -p ${SYSROOT}/usr/include
cp -a ${BUILD_DIR}/src/linux/include/linux ${SYSROOT}/usr/include/linux
cp -a ${BUILD_DIR}/src/linux/include/asm-arm ${SYSROOT}/usr/include/asm
cp -a ${BUILD_DIR}/src/linux/include/asm-generic ${SYSROOT}/usr/include/asm-generic

# Glibc headers

cd ${BUILD_DIR}/src
tar xvfj ../glibc-2.3.5.tar.bz2
patch -d glibc-2.3.5 -p1 <../ioperm.c.diff
cd glibc-2.3.5
tar xvfz ../../glibc-linuxthreads-2.3.5.tar.gz
cd ../..
mkdir BUILD/glibc-2.3.5-headers
cd BUILD/glibc-2.3.5-headers
../../src/glibc-2.3.5/configure --prefix=/usr --host=${TARGET} --enable-add-ons=linuxthreads --with-headers=${SYSROOT}/usr/include 2>&1 | tee configure.out
make cross-compiling=yes install_root=${SYSROOT} install-headers 2>&1 | tee make.out
touch ${SYSROOT}/usr/include/gnu/stubs.h
touch ${SYSROOT}/usr/include/bits/stdio_lim.h

# Step 4: stage 1 gcc

cd ${BUILD_DIR}/src
bunzip2 -c ../gcc-3.4.4.tar.bz2 | tar xvf -
patch -d gcc-3.4.4 -p1 < ../flow.c.diff
patch -d gcc-3.4.4 -p1 < ../t-linux.diff
mkdir -p ../BUILD/gcc-3.4.4-stage1
cd ../BUILD/gcc-3.4.4-stage1
../../src/gcc-3.4.4/configure --prefix=${PREFIX} --target=${TARGET} --enable-languages=c --with-sysroot=${SYSROOT} 2>&1 | tee configure.out
make 2>&1 | tee make.out
make install 2>&1 | tee -a make.out

# Step 5: glibc

cd ${BUILD_DIR}
mkdir BUILD/glibc-2.3.5
cd BUILD/glibc-2.3.5
BUILD_CC=gcc CC=${CROSS_COMPILE}gcc AR=${CROSS_COMPILE}ar RANLIB=${CROSS_COMPILE}ranlib AS=${CROSS_COMPILE}as LD=${CROSS_COMPILE}ld ../../src/glibc-2.3.5/configure --prefix=/usr --build=i386-redhat-linux --host=arm-pc-linux-gnu --target=arm-pc-linux-gnu --without-__thread --enable-add-ons=linuxthreads --with-headers=${SYSROOT}/usr/include 2>&1 | tee configure.out

在make 之前必須將 csu/version-info.h修改
前後加上"如下
----------------------------
"Available extensions:"
""
----------------------------
make 2>&1 | tee make.out
make install_root=${SYSROOT} install

# Step 6: stage 2 gcc

cd ${BUILD_DIR}
mkdir BUILD/gcc-3.4.4
cd BUILD/gcc-3.4.4
../../src/gcc-3.4.4/configure --prefix=${PREFIX} --target=${TARGET} --enable-languages=c,c++ --with-sysroot=${SYSROOT} 2>&1 | tee configure.out
make 2>&1 | tee make.out
make install 2>&1 | tee -a make.out
cd ../..

# Step 7: Linux kernel

cd ${BUILD_DIR}/src/linux
make zImage
make modules
make INSTALL_MOD_PATH=${SYSROOT} modules_install

沒有留言: