1. 程式人生 > >在x86架構機器上交叉編譯linux核心方法

在x86架構機器上交叉編譯linux核心方法

環境介紹:
loongson3-4核cpu(mips),編譯機器x86-64位伺服器

在x86伺服器上交叉編譯mips架構的核心方法:
在x86上編譯mips架構核心時,需要使用交叉編譯器,這裡使用的交叉編譯器是mips64el-redhat-linux-編譯器。
1,獲取配置檔案

把配置檔案拷貝到頂層目錄中
cp arch/mips/configs/loongson3_defconfig .config

2,進行一些基本的配置
我在這裡使用了一個指令碼進行設定,因為伺服器沒有把編譯器設定位全域性的,需要自己進行配置,也就是使用前需要先宣告編譯器的路徑,看一下我的指令碼 config.sh

#宣告編譯位置
export PATH=/opt/gcc-4.4.7-7215-n64-loongson/usr/bin/:$PATH
#宣告編譯器依賴的庫檔案
export LD_LIBRARY_PATH=/opt/gcc-4.4.7-7215-n64-loongson/usr/lib:/opt/gcc-4.4.7-7215-n64-loongson/usr/x86_64-unknown-linux-gnu/mips64el-redhat-linux/lib:$LD_LIBRARY_PATH
make ARCH=mips CROSS_COMPILE=mips64el-redhat-linux- menuconfig

3,配置完成後,進行編譯
這裡也使用了一個指令碼:build.sh
#宣告編譯位置
export PATH=/opt/gcc-4.4.7-7215-n64-loongson/usr/bin/:$PATH
#宣告編譯器依賴的庫檔案
export LD_LIBRARY_PATH=/opt/gcc-4.4.7-7215-n64-loongson/usr/lib:/opt/gcc-4.4.7-7215-n64-loongson/usr/x86_64-unknown-linux-gnu/mips64el-redhat-linux/lib:$LD_LIBRARY_PATH
make ARCH=mips CROSS_COMPILE=mips64el-redhat-linux- -j32

最主要的地方就是,交叉編譯時,沒有設定全域性的交叉編譯器時,需要設定好交叉編譯再進行編譯。

ok,等編譯完成後,就會在頂層目錄生成vmlinux