https://smart888.taobao.com/ 立观智能监控
分类: LINUX
2009-03-10 23:36:27
1 Linux下工作用户及环境
1.1软件环境
Linux ubuntu 6.06 LTS
Kernel version
gcc version
GNU Make 3.81
msgfmt (GNU gettext-tools)
makeinfo (GNU texinfo) 4.8
GNU M4
flex
GNU sed version 4.1.4
gettext (GNU gettext-runtime) 0.14.5
autoconf (GNU Autoconf) 2.59
automake (GNU automake) 1.4-p6
1.2 编译相关配置
1. 添加工作用户(在root用户下)
root@ubuntu:~# useradd -G root -g root -d/home/arm arm
root@ubuntu:~# mkdir -p /home/arm
root@ubuntu:~# chown -R arm /home/arm
root@ubuntu:~# chmod -R 775 /home/arm
2. 建立工作目录(用arm用户登陆)
arm@ubuntu:~$ mkdir dev_home
arm@ubuntu:~$ cd dev_home
arm@ubuntu:~/dev_home$ mkdir btools kernel
3. 登陆时启动环境变量(用root用户登陆)
root@ubuntu:~# vi ~/.bashrc
在.bashrc最后加上
export PATH=/usr/local/arm/
arm@ubuntu:~/dev_home$
重新登陆arm用户,环境变量生效
arm@ubuntu:~$ su arm
2. 设置环境变量,准备源码及相关补丁
2.1 设置环境变量
arm@ubuntu:~$ vi ~/.bashrc
export PREFIX=/usr/local/arm/
export TARGET=arm-linux
export SYSROOT=${PREFIX}/sysroot
export ARCH=arm
export CROSS_COMPILE=${TARGET}-
export PATH=${PREFIX}/bin:$PATH
export SRC=/home/arm/dev_home/btools/tchain
注意: 如果你已经安装过arm-linux-gcc,并且已经加入了环境变量中,将其从环境中去掉保证root用户和arm用户环境中没有arm-linux-gcc
2.2 准备源码包
名称:binutils-2.16.tar.gz
tar.gz
下载地址:
名称: gcc-
下载地址:
名称: glibc-
glibc-linuxthreads-
下载地址:
名称: linux-
下载地址:
名称: gdb-6.4.tar.gz
下载地址:
2.3 准备补丁
作用: 打修正ioperm()函数
下载地址:
作用: 修改gcc一处bug
下载地址:
作用: 该补丁用于产生crti.o和crtn.o文件.
下载地址:
2.4 编译GNU binutils
重新以arm用户登陆,让新设置得环境变量起作用
arm@ubuntu:~/dev_home/btools/tchain
.
|-- BUILD
|-- binutils-2.16
|-- binutils-2.16.tar.gz
|-- flow.c.diff
|-- gcc-
|-- gcc-
|-- gdb-6.4.tar.gz
|-- glibc-
|-- glibc-
|-- glibc-linuxthreads-
|-- ioperm.c.diff
|-- linux-
`-- t-linux.diff
arm@ubuntu:~$ su arm
arm@ubuntu:~$ cd ${SRC}
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
root@ubuntu:/home/arm/dev_home/btools/tchain
root@ubuntu:/home/arm/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
2.5 准备内核头文件
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/kernel$
arm@ubuntu:~/dev_home/kernel$ tar jxvf ../btools/tchain
arm@ubuntu:~/dev_home/kernel$ cd linux-
arm@ubuntu:~/dev_home/kernel/linux-
本人是用的CPU是S
arm@ubuntu:~/dev_home/kernel/linux-
System Type --->
ARM system type (Samsung S
S
[ ] Simtec Electronics ANUBIS
[ ] Simtec Electronics BAST (EB2410ITX)
[ ] IPAQ H1940
[ ] Acer N30
[*] SMDK2410/A
[ ] SMDK2440
[ ] Thorcom VR1000
[ ] HP iPAQ rx3715
[ ] NexVision OTOM Board
[ ] NexVision NEXCODER 2440 Light Board
--- S
--- S
[ ] S
(0) S
--- Processor Type
--- Processor Features
[*] Support Thumb user binaries
[ ] Disable I-Cache
[ ] Disable D-Cache
[ ] Force write through D-cache
退出时
Do you wish to save your new kernel configuration?
< Yes > < No >
选择Yes
arm@ubuntu:~/dev_home/kernel/linux-
arm@ubuntu:~/dev_home/kernel/linux-
root@ubuntu:/home/arm/dev_home/kernel/linux-
root@ubuntu:/home/arm/dev_home/kernel/linux-
root@ubuntu:/home/arm/dev_home/kernel/linux-
root@ubuntu:/home/arm/dev_home/kernel/linux-
root@ubuntu:/home/arm/dev_home/kernel/linux-
arm@ubuntu:~/dev_home/kernel/linux-
2.6 编译glibc头文件
arm@ubuntu:~/dev_home/kernel/linux-
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
root@ubuntu:/home/arm/dev_home/btools/tchain
root@ubuntu:/home/arm/dev_home/btools/tchain
root@ubuntu:/home/arm/dev_home/btools/tchain
touch ${SYSROOT}/usr/include/bits/stdio_lim.h
root@ubuntu:/home/arm/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
2.7 编译gcc 第一阶段 arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain 注意: 不能加上--disable-shared arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain root@ubuntu:/home/arm/dev_home/btools/tchain root@ubuntu:/home/arm/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain 2.8 编译完整的glibc arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain 说明: --prefix: 指定安装路径。 --target: 指定目标平台。 --host: 指定当前平台。 --build: 指定编译平台。 --with-sysroot: 用于指定编译所需要的头文件,及链接库。 --enable-add-ons: 加入其它的库,如线程库等。 --enable-languages: 指定gcc所支持的语言。 arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain root@ubuntu:/home/arm/dev_home/btools/tchain root@ubuntu:/home/arm/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain 2.9 编译完整的gcc arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain root@ubuntu:/home/arm/dev_home/btools/tchain root@ubuntu:/home/arm/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:~/dev_home/btools/tchain arm@ubuntu:/usr/local/arm/ . |-- arm-linux |-- bin |-- include |-- info |-- lib |-- libexec |-- man |-- share `-- sysroot arm@ubuntu:/usr/local/arm/ arm@ubuntu:/usr/local/arm/ arm-linux-addr2line arm-linux-c++filt arm-linux-gcc- arm-linux-ar arm-linux-cpp arm-linux-gccbug arm-linux-objcopy arm-linux-size arm-linux-as arm-linux-g++ arm-linux-gcov arm-linux-objdump arm-linux-strings arm-linux-c++ arm-linux-gcc arm-linux-ld arm-linux-ranlib arm-linux-strip 2.10 测试gcc,g++ arm@ubuntu:~$ vi hello_c.c #include #include int main() { printf("Hello,World~\n"); return 0; } arm@ubuntu:~$ vi hello_cpp.cpp #include using std::cout; using std::endl; int main() { cout<<"Hello,World!\n"< return 0; } arm@ubuntu:~$ arm-linux-gcc hello_c.c -o hello_c arm@ubuntu:~$ arm-linux-g++ -o hello_cpp hello_cpp.cpp arm@ubuntu:~$ tree -L 1 . |-- dev_home |-- hello_c |-- hello_c.c |-- hello_cpp `-- hello_cpp.cpp 1 directory, 4 files arm@ubuntu:~$ file hello_c hello_c: ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux arm@ubuntu:~$ file hello_cpp hello_cpp: ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux
Thread model: posix
gcc version 3.4.4
2.11 编译主机上运行的gdb
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
gdb/gdb: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux
2.12建立目标平台上运行的gdbserver
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
arm@ubuntu:~/dev_home/btools/tchain
gdbserver: ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux
3 GNU交叉工具链的下载
工具链的官方下载地址:
可以从该站点下载2.95.3, 3.0以及3.2工具链