交叉编译Linux内核


一.下载linux内核源码

我使用的是linux-loongson-release-zb-kernel.tgz

将其解压到/usr/src目录下: tar -xzvf linux-loongson-release-zb-kernel.tgz

这样在此目录下会生成linux-loongson-release目录

二.下载交叉编译工具

下载地址: http://dev.lemote.com/files/binary/toolchain/kernel/gcc-3.4.6-newbin.ls2f.tar.gz

解压放到/opt目录下,先要修改/opt的权限

sudo chmod 766 /opt

tar -xzf  gcc‐3.4.6‐newbin.ls2f.tar.gz -C /opt

然后在环镜变量中制定其路径

export PATH=/opt/gcc-3.4.6-newbin/bin:$PATH          也可把它写入~/.bashrc,便于多次使用

设置可执行权限

chmod +x /opt/gcc-3.4.6-newbin/bin -R

三.内核配置

在源码目录下:

cp arch/mips/configs/loongson3a_xxxx_config

注:目前在arch/mips/configs下有5个龙芯3a的配置文件

loongson3a_dawning_config

loongson3a_rs780e_config

loongson3a_server_2u_defconfig

loongson3a_server_blade_defconfig

loongson3a_server_config

然后再make config 你会发现龙芯3a默认配置已经写到配置文件中去了.

四.编译内核

1.本地编译直接 make完成内核的编译

2.交叉编译情况下,进入内核源码根目录下,输入:  make  ARCH=mips CROSS_COMPILE=mipsel-linux-

也可修改makefile,对于反复编译此法一劳永逸.修改根目录下的makefile

给ARCH变量赋值: ARCH ?= mips

给CROSS_COMPILE 变量赋值CROSS_COOMPILE ?= mipsel‐linux‐

注:此步执行前要make menuconfig 进入配置界面把 Enable  loadable module support 选中.再把它的下一级目录的3和4,或2和4选中.

并且修改完要选择 Save an Alternate Configuration File进行保存.

更多关于Linux Kernel的详细信息,或者下载地址请点这里

相关内容