ubuntu16.04(64位)建立交叉編譯環境,並配置編譯內核


安裝步驟

1、准備工具安裝目錄

將壓縮包gcc-linaro-arm-linux-bnueabihf-4.9-2014.07_linux.tar存放在一個目錄下,這個目錄就是你等會解壓縮的目錄,以后這個目錄就不能隨便刪掉了,我的存放路徑是/home/zyr/Am335x/Sourcefiletools,如下圖,記住這個路徑,等會還會用到。

zyr@ubuntu:~/Am335x/Sourcefiletools$ ls
gcc-linaro-arm-linux-gnueabihf-4.9-2014.07_linux
gcc-linaro-arm-linux-gnueabihf-4.9-2014.07_linux.tar
zyr@ubuntu:~/Am335x/Sourcefiletools$ pwd
/home/zyr/Am335x/Sourcefiletools
zyr@ubuntu:~/Am335x/Sourcefiletools
 

2、安裝軟件

使用tar命令:tar xvf gcc-linaro-arm-linux-gnueabihf-4.9-2014.07_linux.tar將Sourcefiletools文件夾下的gcc-linaro-arm-linux-gnueabihf-4.9-2014.07_linux.tar解壓縮安裝到當前目錄。通過下圖可以看到解壓成功了,並且解壓后的文件存放在了

  1. /home/zyr/Am335x/Sourcefiletools/gcc-linaro-arm-linux-gnueabihf-4.9-2014.07_linux

文件夾下,如下圖所示,這個存放路徑可得記住,如下圖

zyr@ubuntu:~/Am335x/Sourcefiletools/gcc-linaro-arm-linux-gnueabihf-4.9-2014.07_linux$ ls
arm-linux-gnueabihf  bin  lib  libexec  share
zyr@ubuntu:~/Am335x/Sourcefiletools/gcc-linaro-arm-linux-gnueabihf-4.9-2014.07_linux$ 

3、配置系統環境變量

配置環境前先坐下普及:

Ubuntu不同目錄下profile與bashrc的區別

/etc/profile  此文件為系統的每個用戶設置環境信息,當用戶第一次登錄時,該文件被執行,並從/etc/profile.d目錄的配置文件中搜集shell的設置。

/etc/bash.bashrc  為每一個運行bash shell的用戶執行此文件,當bash shell被打開時,該文件被讀取。

~/.bash_profile  每個用戶都可使用該文件輸入專用於自己使用的shell信息,當用戶登錄時,該文件僅僅執行一次,默認情況下,他設置一些環境變量,執行用戶的.bashrc文件。

~/.bashrc  該文件包含專用於你的bash shell的bash信息,當登錄時以及每次打開新的shell時,該文件被讀取。

~/.bash_logout  當每次退出系統(退出bash shell)時,執行該文件。

另外,/etc/profile中設定的變量(全局)的可以作用於任何用戶,而~/.bashrc等中設定的變量(局部)只能繼承/etc/profile中的變量,他們是"父子"關系。

~/.bash_profile  是交互式、login 方式進入 bash 運行的。

~/.bashrc  是交互式 non-login 方式進入 bash 運行的。

通常二者設置大致相同,所以通常前者會調用后者。

接下來配置系統環境變量,把交叉編譯工具鏈的路徑添加到環境變量PATH中去,這樣就可以在任何目錄下使用這些工具。記下上一步中的安裝路徑,使用命令:vim  /home/aldrich/.bashrc 編輯.bashrc文件,添加環境變量。

在該文件中最后一行添加:

  1. sudo gedit /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

if [ "$PS1" ]; then
  if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi
export PATH=$PATH:/home/zyr/Am335x/Sourcefiletools/gcc-linaro-arm-linux-gnueabihf-4.9-2014.07_linux/bin/

這個路徑就是那個bin目錄所在的路徑,可能你的不一樣,按照你實際的目錄填就可以了,

編寫完保存就好了

4、使環境變量生效

使用命令:source /etc/profile 使環境變量生效

5、檢查環境變量是否設置成功

在終端上輸入命令 arm-linux-gnueabifh- 再按Tab鍵,可以看到下圖,說明環境變量設置成功了

 

zyr@ubuntu:~$ arm-linux-gnueabihf-
arm-linux-gnueabihf-addr2line        arm-linux-gnueabihf-gfortran
arm-linux-gnueabihf-ar               arm-linux-gnueabihf-gprof
arm-linux-gnueabihf-as               arm-linux-gnueabihf-ld
arm-linux-gnueabihf-c++              arm-linux-gnueabihf-ld.bfd
arm-linux-gnueabihf-c++filt          arm-linux-gnueabihf-ldd
arm-linux-gnueabihf-cpp              arm-linux-gnueabihf-ld.gold
arm-linux-gnueabihf-dwp              arm-linux-gnueabihf-nm
arm-linux-gnueabihf-elfedit          arm-linux-gnueabihf-objcopy
arm-linux-gnueabihf-g++              arm-linux-gnueabihf-objdump
arm-linux-gnueabihf-gcc              arm-linux-gnueabihf-pkg-config
arm-linux-gnueabihf-gcc-4.9.1        arm-linux-gnueabihf-pkg-config-real
arm-linux-gnueabihf-gcc-ar           arm-linux-gnueabihf-ranlib
arm-linux-gnueabihf-gcc-nm           arm-linux-gnueabihf-readelf
arm-linux-gnueabihf-gcc-ranlib       arm-linux-gnueabihf-size
arm-linux-gnueabihf-gcov             arm-linux-gnueabihf-strings
arm-linux-gnueabihf-gdb              arm-linux-gnueabihf-strip
zyr@ubuntu:~$ arm-linux-gnueabihf-

 

6、安裝32位庫兼容包(因為系統是64位的,安裝的交叉編譯器是32位的)

sudo apt-get install ia32-libs 裝一些32位的庫

 

出現上述界面是因為Ubuntu16.04版本已不支持ia32-libs的軟件包,而是使用了lib32ncurses5、lib32z1軟件包做為替代,所以在Ubuntu16.04版本當中應該安裝執行:

  1. sudo apt-get install lib32ncurses5 lib32z1

待安裝完32位的庫之后,再使用命令:arm-linux-gnueabihf-gcc -v,出現這種錯誤:

ubuntu arm-linux-gnueabihf-gcc: error while loading shared libraries: libstdc++.so.6 

 安裝:

sudo  apt-get install lib32stdc++6

 然后再查看arm-linux-gnueabihf-gcc -v就可以看到版本了:

zyr@ubuntu:~/Am335x/Kernel/linux-4.1.36$ arm-linux-gnueabihf-gcc -v
Using built-in specs.
COLLECT_GCC=arm-linux-gnueabihf-gcc
COLLECT_LTO_WRAPPER=/home/zyr/Am335x/Sourcefiletools/gcc-linaro-arm-linux-gnueabihf-4.9-2014.07_linux/bin/../libexec/gcc/arm-linux-gnueabihf/4.9.1/lto-wrapper
Target: arm-linux-gnueabihf
Configured with: /cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-linux/.build/src/gcc-linaro-4.9-2014.07/configure --build=i686-build_pc-linux-gnu --host=i686-build_pc-linux-gnu --target=arm-linux-gnueabihf --prefix=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-linux/install --with-sysroot=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-linux/install/arm-linux-gnueabihf/libc --enable-languages=c,c++,fortran --disable-multilib --enable-multiarch --with-arch=armv7-a --with-tune=cortex-a9 --with-fpu=vfpv3-d16 --with-float=hard --with-pkgversion='crosstool-NG linaro-1.13.1-4.9-2014.07 - Linaro GCC 4.9-2014.07' --with-bugurl=https://bugs.launchpad.net/gcc-linaro --enable-__cxa_atexit --enable-libmudflap --enable-libgomp --enable-libssp --with-gmp=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-linux/.build/arm-linux-gnueabihf/build/static --with-mpfr=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-linux/.build/arm-linux-gnueabihf/build/static --with-mpc=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-linux/.build/arm-linux-gnueabihf/build/static --with-isl=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-linux/.build/arm-linux-gnueabihf/build/static --with-cloog=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-linux/.build/arm-linux-gnueabihf/build/static --with-libelf=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-linux/.build/arm-linux-gnueabihf/build/static --enable-threads=posix --disable-libstdcxx-pch --enable-linker-build-id --enable-plugin --enable-gold --with-local-prefix=/cbuild/slaves/oorts/crosstool-ng/builds/arm-linux-gnueabihf-linux/install/arm-linux-gnueabihf/libc --enable-c99 --enable-long-long --with-mode=thumb --disable-multilib --with-float=hard
Thread model: posix
gcc version 4.9.1 20140710 (prerelease) (crosstool-NG linaro-1.13.1-4.9-2014.07 - Linaro GCC 4.9-2014.07) 

 

7、交叉編譯工具驗證--編譯內核:

在內核目錄下建立如下腳本文件(bulid-kernel.sh):

#! /bin/bash
echo "Configure the kernel"
until
    echo "1.make the omap2plus.defconfig"
    echo "2.make the menuconfig( Boot options -> Kernel command line type (root=/dev/mmcblk0p2 rootwait console=ttyo0,115200) )"
    echo "3.make the dtb"
    echo "4.make the zImage"
    echo "5.make the uImage"
    echo "6.make the distclean"
    echo "7.make the modules"
    echo "8.quit"

    read input
    test $input = 8
    do
        case $input in
        1)make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- omap2plus_defconfig;;
        2)make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig;;
        3)make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- am335x-boneblack.dtb;;
        4)make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- zImage;;
        5)make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- LOADADDR=0x80008000 uImage;;
        6)make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean;;
        7)make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- -j8 modules;;
        8)echo"quit";;
        esac
        done
        

運行腳本文件bulid-kernel.sh

sh build-kernel.sh

zyr@ubuntu:~/Am335x/Kernel/linux-4.1.36$ sh build-kernel.sh 
Configure the kernel
1.make the omap2plus.defconfig
2.make the menuconfig( Boot options -> Kernel command line type (root=/dev/mmcblk0p2 rootwait console=ttyo0,115200) )
3.make the dtb
4.make the zImage
5.make the uImage
6.make the distclean
7.make the modules
8.quit
1
#
# configuration written to .config
#
1.make the omap2plus.defconfig
2.make the menuconfig( Boot options -> Kernel command line type (root=/dev/mmcblk0p2 rootwait console=ttyo0,115200) )
3.make the dtb
4.make the zImage
5.make the uImage
6.make the distclean
7.make the modules
8.quit

輸入控制命令2時產生錯誤:

執行make menuconfig時出現如下錯誤
@ubuntu:/home/dev/busybox-1.19.3# make menuconfig
  HOSTCC  scripts/kconfig/lxdialog/checklist.o
In file included from scripts/kconfig/lxdialog/checklist.c:24:0:
scripts/kconfig/lxdialog/dialog.h:31:20: fatal error: curses.h: 沒有那個文件或目錄
compilation terminated.
make[2]: *** [scripts/kconfig/lxdialog/checklist.o] 錯誤 1
make[1]: *** [menuconfig] 錯誤 2
make: *** [menuconfig] 錯誤 2
 
這時因為ubuntu系統中缺少一個套件 ncurses devel ,把此套件安裝下即可
apt-get install libncurses5-dev

按以上方法解決,最終可以配置內核了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM