利用Openwrt编译嵌入式linux

2019-07-12 21:45发布

这段时间在编译Micrel的ARM芯片(KS8695X),之前一直用从官网上下载的linux内核包进行编译,但最近官网上提供的linux2.6.23版本需要gcc3.4.6以上版本编译,而我只有3.4.0版本,到网上下载了很多gcc版本,都不能完全将开发包编译通过。 今天研究了一下openwrt,发现太好用了,以后多用这种方式编译。

准备工作

需要安装如下安装包:
gcc
gcc-c++
ncurses
zlib
flex
ncurses-devel
zlib-devel
bison
autoconf

下载代码

由于Openwrt没有支持Micrel的芯片,故Micrel提供了Openwrt工程文件,从官网上下载一个即可,我从ftp://www.micrel.com/ethernet/8695P/ 下载了openwrt-8.09.1.1-20090904.bz2,然后解压到本地目录,最好解压到openwrt-8.09. 然后运行下面命令下载其他包
svn co svn://svn.openwrt.org/openwrt/tags/8.09 kamikaze_8.09
svn co svn://svn.openwrt.org/openwrt/branches/packages_8.09 packages_8.09
svn co http://x-wrt.googlecode.com/svn/tags/kamikaze_8.09 x-wrt_8.09
  最后应该有下面几个目录:
openwrt_8.09  kamikaze_8.09 packages_8.09  x-wrt_8.09

编译

./openwrt-8.09/link -d kamikaze_8.09/ -p packages_8.09/ -x x-wrt_8.09/ cd kamikaze_8.09 make menuconfig
按照如下选择:
Target System  Micrel Centaur [2.6] Subtarget      KSZ8695X Target Profile Micrel Centaur  KSZ8695X GCC版本: Advanced configuration options-->Toolchain Options-->GCC compiler Version
The Base system contains application packages that are essential for running the system. The Linux kernel drivers are selected in Kernel modules. The web GUI packages are provided under Administration.   退出保存   然后运行
make
第一次大概会需要1个多小时。  

结果

  编译结果目录:
toolchain:       staging_dir/toolchain-arm_gcc3.4.6 kernel:           linux-micrel_pegasus_ksz9692p/linux-2.6.23.17 applications:   build_dir/arm root filesystem: build_dir/arm/root-micrel_pegasus file images:     bin
bin文件说明
kernel image:     openwrt-micrel_centaur-2.6.uImage rootfilelsystem:  openwrt-micrel_centaur-squashfs.img root+kernel:      openwrt-micrel_centaur-2.6-squashfs.img uboot:               u-boot-micrel_centaur-2.6-squashfs.img
The built toolchain is under the staging_dir/arm/toolchain-arm_gcc3.4.6 directory. The Linux kernel is built under the /linux-micrel_pegasus_ksz9692p/linux-2.6.23.17 directory. The applications are built under the build_dir/arm directory. The target root filesystem is in build_dir/arm/root-micrel_pegasus directory. The file images are under the bin directory. The file openwrt-micrel_pegasus-2.6.uImage is the kernel image. The file openwrt-micrel_pegasus-squashfs.img is the root filesystem image. The file openwrt-micrel_pegasus-2.6-squashfs.img contains both kernel and root filesystem. This is likely the one to download. The file u-boot-micrel_pegasus-2.6-squashfs.img includes also the U-Boot bootloader.  

其他

清除可执行 make clean 或者make dirclean 完全清除: make distclean (此方式也将清除所有下载文件,慎用)