2011年12月2日 星期五

install gcc-4.1 under Ubuntu

目前系統gcc版本是4.4.3

nelson@swdev:~/eMbedded/crosstoolchain/crosstool-0.43$ gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.4.3-4ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.4/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.4 --program-suffix=-4.4 --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i486 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.4.3 (Ubuntu 4.4.3-4ubuntu5)

此版本編譯cross toolchain都會遇到麻煩

像是
http://blog.chinaunix.net/space.php?uid=20543672&do=blog&id=94333
 所提到的
*** buffer overflow detected ***: arm-9tdmi-linux-gnu-ar terminated

所以需要改裝gcc 4.1版本


ubuntu上安裝挺簡單的

sudo apt-get install gcc-4.1

primesw@swdev:~$ sudo apt-get install gcc-4.1
[sudo] password for primesw:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  linux-headers-2.6.32-34-generic linux-headers-2.6.32-34
  linux-headers-2.6.32-34-server
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  cpp-4.1 gcc-4.1-base
Suggested packages:
  gcc-4.1-locales gcc-4.1-multilib gcc-4.1-doc libmudflap0-dev
The following NEW packages will be installed:
  cpp-4.1 gcc-4.1 gcc-4.1-base
0 upgraded, 3 newly installed, 0 to remove and 142 not upgraded.
Need to get 3,360kB of archives.
After this operation, 7,528kB of additional disk space will be used.
Do you want to continue [Y/n]? y
WARNING: The following packages cannot be authenticated!
  gcc-4.1-base cpp-4.1 gcc-4.1
Install these packages without verification [y/N]? y
Get:1 http://cn.archive.ubuntu.com/ubuntu/ lucid/universe gcc-4.1-base 4.1.2-27u                                                                                        buntu1 [209kB]
Get:2 http://cn.archive.ubuntu.com/ubuntu/ lucid/universe cpp-4.1 4.1.2-27ubuntu                                                                                        1 [2,550kB]
Get:3 http://cn.archive.ubuntu.com/ubuntu/ lucid/universe gcc-4.1 4.1.2-27ubuntu                                                                                        1 [600kB]
Fetched 3,360kB in 28s (119kB/s)
Selecting previously deselected package gcc-4.1-base.
(Reading database ... 282346 files and directories currently installed.)
Unpacking gcc-4.1-base (from .../gcc-4.1-base_4.1.2-27ubuntu1_amd64.deb) ...
Selecting previously deselected package cpp-4.1.
Unpacking cpp-4.1 (from .../cpp-4.1_4.1.2-27ubuntu1_amd64.deb) ...
Selecting previously deselected package gcc-4.1.
Unpacking gcc-4.1 (from .../gcc-4.1_4.1.2-27ubuntu1_amd64.deb) ...
Processing triggers for man-db ...
Setting up gcc-4.1-base (4.1.2-27ubuntu1) ...

Setting up cpp-4.1 (4.1.2-27ubuntu1) ...
Setting up gcc-4.1 (4.1.2-27ubuntu1) ...



就可以在/usr/bin下看到嚕
ls /usr/bin/gcc*
/usr/bin/gcc  /usr/bin/gcc-4.1  /usr/bin/gcc-4.4  /usr/bin/gccbug-4.1



接下來需要做soft link

sudo rm /usr/bin/gcc
sudo ln -s /usr/bin/gcc-4.1 /usr/bin/gcc

之後使用gcc -v
 就可以發現版本換嚕

gcc -v
Using built-in specs.
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --enable-languages=c,c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.1.3 --program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --with-tune=generic --enable-checking=release x86_64-linux-gnu
Thread model: posix
gcc version 4.1.3 20080704 (prerelease) (Ubuntu 4.1.2-27ubuntu1)

透過Facebook分享

demo-arm.sh

cp demo-arm.sh nelson-arm.sh

vim nelson-arm.sh

修改
TARBALLS_DIR=$HOME/eMbedded/downloads
RESULT_TOP=$HOME/eMbedded/crosstool

./nelson-arm.sh

+ /home/nelson/eMbedded/crosstoolchain/crosstool-0.43/build/arm-unknown-linux-gnu/gcc-4.1.0-glibc-2.3.2/glibc-2.3.2/configure --prefix=/usr --build=x86_64-unknown-linux-gnu --host=arm-unknown-linux-gnu --without-cvs --disable-sanity-checks --with-headers=/home/nelson/eMbedded/crosstool/gcc-4.1.0-glibc-2.3.2/arm-unknown-linux-gnu/arm-unknown-linux-gnu/include --enable-hacker-mode
checking build system type... x86_64-unknown-linux-gnu
checking host system type... arm-unknown-linux-gnu
checking sysdep dirs... sysdeps/arm/elf sysdeps/unix/sysv/linux/arm sysdeps/unix/sysv/linux sysdeps/gnu sysdeps/unix/common sysdeps/unix/mman sysdeps/unix/inet sysdeps/unix/sysv sysdeps/unix/arm sysdeps/unix sysdeps/posix sysdeps/arm/fpu sysdeps/arm sysdeps/wordsize-32 sysdeps/ieee754/flt-32 sysdeps/ieee754/dbl-64 sysdeps/ieee754 sysdeps/generic/elf sysdeps/generic
checking for a BSD-compatible install... /usr/bin/install -c
checking whether ln -s works... yes
checking for pwd... /bin/pwd
checking for arm-unknown-linux-gnu-gcc... gcc
checking version of gcc... 4.4.3, bad
checking for gnumake... no
checking for gmake... no
checking for make... make
checking version of make... 3.81, ok
configure: error:
*** These critical programs are missing or too old: gcc
*** Check the INSTALL file for required versions.

Ref:
http://blog.chinaunix.net/space.php?uid=12072359&do=blog&id=2960855


修改此檔案
vim build/arm-unknown-linux-gnu/gcc-4.1.0-glibc-2.3.2/glibc-2.3.2/configure
2275c2275
<     3.[2-9]*|4.[01]*)
---
>     3.[2-9]*|4.*)


 
vim nelson-arm.sh
加上--nounpack

./nelson-arm.sh

In file included from /usr/include/fcntl.h:205,
                 from /home/nelson/eMbedded/crosstoolchain/crosstool-0.43/build/arm-unknown-linux-gnu/gcc-4.1.0-glibc-2.3.2/gcc-3.3.6/gcc/system.h:208,
                 from /home/nelson/eMbedded/crosstoolchain/crosstool-0.43/build/arm-unknown-linux-gnu/gcc-4.1.0-glibc-2.3.2/gcc-3.3.6/gcc/collect2.c:30:
In function ‘open’,
    inlined from ‘collect_execute’ at /home/nelson/eMbedded/crosstoolchain/crosstool-0.43/build/arm-unknown-linux-gnu/gcc-4.1.0-glibc-2.3.2/gcc-3.3.6/gcc/collect2.c:1575:
/usr/include/bits/fcntl2.h:51: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT in second argument needs 3 arguments
make[1]: *** [collect2.o] Error 1
make[1]: Leaving directory `/home/nelson/eMbedded/crosstoolchain/crosstool-0.43/build/arm-unknown-linux-gnu/gcc-4.1.0-glibc-2.3.2/build-gcc-core/gcc'
make: *** [all-gcc] Error 2

vim +1575 build/arm-unknown-linux-gnu/gcc-4.1.0-glibc-2.3.2/gcc-3.3.6/gcc/collect2.c

第三個參數地方加上0777
記得要用,隔開

解法

摘錄部份重點
这纯属软件bug,因为使用open函数的时候,如果在第二个参数中使用了 O_CREAT,就必须添加第三个参数:创建文件时赋予的初始权限。而在gcc-3.3.6/gcc/的collect2.c文件中有漏掉第三个参数的错误,而gcc-4.3对语法错误的检查严格是出了名的(4.1就不会因此错误退出),所以就退出了。


nelson@swdev:~/eMbedded/crosstoolchain/crosstool-0.43$ ./nelsonbuild

arm-unknown-linux-gnu-ar  rc ./libgcc.a libgcc/./_udivsi3.o libgcc/./_divsi3.o libgcc/./_umodsi3.o libgcc/./_modsi3.o libgcc/./_dvmd_lnx.o libgcc/./_muldi3.o libgcc/./_negdi2.o libgcc/./_lshrdi3.o libgcc/./_ashldi3.o libgcc/./_ashrdi3.o libgcc/./_ffsdi2.o libgcc/./_clz.o libgcc/./_cmpdi2.o libgcc/./_ucmpdi2.o libgcc/./_floatdidf.o libgcc/./_floatdisf.o libgcc/./_fixunsdfsi.o libgcc/./_fixunssfsi.o libgcc/./_fixunsdfdi.o libgcc/./_fixdfdi.o libgcc/./_fixunssfdi.o libgcc/./_fixsfdi.o libgcc/./_fixxfdi.o libgcc/./_fixunsxfdi.o libgcc/./_floatdixf.o libgcc/./_fixunsxfsi.o libgcc/./_fixtfdi.o libgcc/./_fixunstfdi.o libgcc/./_floatditf.o libgcc/./_clear_cache.o libgcc/./_trampoline.o libgcc/./__main.o libgcc/./_exit.o libgcc/./_absvsi2.o libgcc/./_absvdi2.o libgcc/./_addvsi3.o libgcc/./_addvdi3.o libgcc/./_subvsi3.o libgcc/./_subvdi3.o libgcc/./_mulvsi3.o libgcc/./_mulvdi3.o libgcc/./_negvsi2.o libgcc/./_negvdi2.o libgcc/./_ctors.o libgcc/./_divdi3.o libgcc/./_moddi3.o libgcc/./_udivdi3.o libgcc/./_umoddi3.o libgcc/./_udiv_w_sdiv.o libgcc/./_udivmoddi4.o libgcc/./unwind-dw2.o libgcc/./unwind-dw2-fde-glibc.o libgcc/./unwind-sjlj.o libgcc/./unwind-c.o libgcc/./_eprintf.o libgcc/./_bb.o libgcc/./__gcc_bcmp.o
*** buffer overflow detected ***: arm-unknown-linux-gnu-ar terminated
======= Backtrace: =========
/lib/libc.so.6(__fortify_fail+0x37)[0x2ad5bb56a217]
/lib/libc.so.6(+0xfe0d0)[0x2ad5bb5690d0]
/lib/libc.so.6(+0xfd539)[0x2ad5bb568539]
/lib/libc.so.6(_IO_default_xsputn+0xcc)[0x2ad5bb4e0d1c]
/lib/libc.so.6(_IO_padn+0xe8)[0x2ad5bb4d47f8]
/lib/libc.so.6(_IO_vfprintf+0x2afc)[0x2ad5bb4b2e9c]
/lib/libc.so.6(__vsprintf_chk+0x99)[0x2ad5bb5685d9]
/lib/libc.so.6(__sprintf_chk+0x7f)[0x2ad5bb56851f]
arm-unknown-linux-gnu-ar[0x409144]
arm-unknown-linux-gnu-ar[0x407361]
arm-unknown-linux-gnu-ar[0x4099d5]
arm-unknown-linux-gnu-ar[0x4107ef]
arm-unknown-linux-gnu-ar[0x403fff]
arm-unknown-linux-gnu-ar[0x4044bd]
arm-unknown-linux-gnu-ar[0x404ef9]
/lib/libc.so.6(__libc_start_main+0xfd)[0x2ad5bb489c4d]
arm-unknown-linux-gnu-ar[0x401e69]
======= Memory map: ========
00400000-00465000 r-xp 00000000 08:01 4167281                            /home/nelson/eMbedded/crosstool/gcc-4.1.0-glibc-2.3.2/arm-unknown-linux-gnu/bin/arm-unknown-linux-gnu-ar
00664000-00665000 r--p 00064000 08:01 4167281                            /home/nelson/eMbedded/crosstool/gcc-4.1.0-glibc-2.3.2/arm-unknown-linux-gnu/bin/arm-unknown-linux-gnu-ar
00665000-00666000 rw-p 00065000 08:01 4167281                            /home/nelson/eMbedded/crosstool/gcc-4.1.0-glibc-2.3.2/arm-unknown-linux-gnu/bin/arm-unknown-linux-gnu-ar
00666000-0066a000 rw-p 00000000 00:00 0
00ad1000-019cb000 rw-p 00000000 00:00 0                                  [heap]
2ad5bb249000-2ad5bb269000 r-xp 00000000 08:01 33562306                   /lib/ld-2.11.1.so
2ad5bb269000-2ad5bb26b000 rw-p 00000000 00:00 0
2ad5bb26b000-2ad5bb26c000 r--p 00000000 08:01 796839                     /usr/lib/locale/en_US.utf8/LC_MESSAGES/SYS_LC_MESSAGES
2ad5bb26c000-2ad5bb273000 r--s 00000000 08:01 797675                     /usr/lib/gconv/gconv-modules.cache
2ad5bb273000-2ad5bb2b2000 r--p 00000000 08:01 796833                     /usr/lib/locale/en_US.utf8/LC_CTYPE
2ad5bb2b2000-2ad5bb2bc000 rw-p 00000000 00:00 0
2ad5bb468000-2ad5bb469000 r--p 0001f000 08:01 33562306                   /lib/ld-2.11.1.so
2ad5bb469000-2ad5bb46a000 rw-p 00020000 08:01 33562306                   /lib/ld-2.11.1.so
2ad5bb46a000-2ad5bb46b000 rw-p 00000000 00:00 0
2ad5bb46b000-2ad5bb5e5000 r-xp 00000000 08:01 33563969                   /lib/libc-2.11.1.so
2ad5bb5e5000-2ad5bb7e4000 ---p 0017a000 08:01 33563969                   /lib/libc-2.11.1.so
2ad5bb7e4000-2ad5bb7e8000 r--p 00179000 08:01 33563969                   /lib/libc-2.11.1.so
2ad5bb7e8000-2ad5bb7e9000 rw-p 0017d000 08:01 33563969                   /lib/libc-2.11.1.so
2ad5bb7e9000-2ad5bb7f0000 rw-p 00000000 00:00 0
2ad5bb7f0000-2ad5bb806000 r-xp 00000000 08:01 33554487                   /lib/libgcc_s.so.1
2ad5bb806000-2ad5bba05000 ---p 00016000 08:01 33554487                   /lib/libgcc_s.so.1
2ad5bba05000-2ad5bba06000 r--p 00015000 08:01 33554487                   /lib/libgcc_s.so.1
2ad5bba06000-2ad5bba07000 rw-p 00016000 08:01 33554487                   /lib/libgcc_s.so.1
7fffa4b04000-7fffa4b1c000 rw-p 00000000 00:00 0                          [stack]
7fffa4bfc000-7fffa4bfd000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
make[2]: *** [libgcc.a] Aborted
make[2]: *** Deleting file `libgcc.a'
make[2]: Leaving directory `/home/nelson/eMbedded/crosstoolchain/crosstool-0.43/build/arm-unknown-linux-gnu/gcc-4.1.0-glibc-2.3.2/build-gcc-core/gcc'
make[1]: *** [libgcc.a] Error 2
make[1]: Leaving directory `/home/nelson/eMbedded/crosstoolchain/crosstool-0.43/build/arm-unknown-linux-gnu/gcc-4.1.0-glibc-2.3.2/build-gcc-core/gcc'
make: *** [all-gcc] Error 2

將系統的gcc版本換成4.1版本
參考

install gcc-4.1 under Ubuntu



ln -s nelson-arm.sh nelsonbuild
./nelsonbuild

這樣編譯
還是有一樣的問題

修改nelsonbuild
拿掉--nounpack

重新來一次

哇靠
上面的修改都不用
就成功了

+ /home/nelson/eMbedded/crosstool/gcc-4.1.0-glibc-2.3.2/arm-unknown-linux-gnu/bin/arm-unknown-linux-gnu-gcc -static hello.c -o arm-unknown-linux-gnu-hello-static
+ /home/nelson/eMbedded/crosstool/gcc-4.1.0-glibc-2.3.2/arm-unknown-linux-gnu/bin/arm-unknown-linux-gnu-gcc hello.c -o arm-unknown-linux-gnu-hello
+ test -x /home/nelson/eMbedded/crosstool/gcc-4.1.0-glibc-2.3.2/arm-unknown-linux-gnu/bin/arm-unknown-linux-gnu-g++
+ cat
+ /home/nelson/eMbedded/crosstool/gcc-4.1.0-glibc-2.3.2/arm-unknown-linux-gnu/bin/arm-unknown-linux-gnu-g++ -static hello2.cc -o arm-unknown-linux-gnu-hello2-static
+ /home/nelson/eMbedded/crosstool/gcc-4.1.0-glibc-2.3.2/arm-unknown-linux-gnu/bin/arm-unknown-linux-gnu-g++ hello2.cc -o arm-unknown-linux-gnu-hello2
+ echo testhello: C compiler can in fact build a trivial program.
testhello: C compiler can in fact build a trivial program.
+ test '' = 1
+ test '' = 1
+ test '' = 1
+ test 1 = ''
+ echo Done.
Done.







gcc版本要換成4.1是關鍵阿


透過Facebook分享

usb2.0-ser! driver安裝

安裝usb to rs232裝置

driver從此處下載
http://www.winchiphead.com/download/CH341/CH341SER.ZIP
or
https://drive.google.com/file/d/0B2dgGdZOVJXgSFdVbHVDRWViaWs/view?usp=sharing

解壓縮後
執行以下檔案
CH341SER\DRIVER\SETUP

安裝成功

Ref:
http://www.computerhope.com/forum/index.php?topic=81904.0

透過Facebook分享