在vps编译openwrt一些简单记录
1.设置sawp,以避免在512M 小内存vps 出现异常
free
dd if=/dev/zero of=/tmp/swap.img bs=1024k count=1000
mkswap /tmp/swap.img
swapon /tmp/swap.img
#swapoff /tmp/swap.img
free
2.安装相应依赖
apt-get install -y subversion make gcc g++ libncurses5-dev libghc-zlib-dev libreadline-dev libssl-dev gawk bzip2 patch xz-utils sudo
apt-get install -y binutils flex bison autoconf gettext texinfo unzip sharutils ncurses-term zlib1g-dev asciidoc libz-dev
apt-get install -y gettext git
apt-get install libncurses5-dev zlib1g-dev gawk flex libssl-dev sdcc-nf
3.建立目录
mkdir /openwrt
4.获得源码方法
会遇到旧版本在原先位置不存在,或者下载中断
svn co svn://svn.openwrt.org/openwrt/branches/chaos_calmer_rc3
git clone git://git.openwrt.org/openwrt.git
svn co svn://svn.openwrt.org/openwrt/trunk/
svn co –revision=24045 svn://svn.openwrt.org/openwrt/branches/backfire/ ./build_dir
获得和openwrt官方在线相同版本 Chaos_calmer
svn co –revision=46767 svn://svn.openwrt.org/openwrt/trunk/ /openwrt
5.更新包
————不更新这部分内容有利减少.config里大小,不然make defconfig会产生更多的包配置项
./scripts/feeds update -a 更新软件包
./scripts/feeds install -a 安装软件包
————
6.获得官方config
wget -O .config https://downloads.openwrt.org/chaos_calmer/15.05/ramips/mt7620/config.diff
make defconfig #在原先的.config附加一些比如 package目录里包的附加配置
make prereq
make menuconfig #进入定制界面(里面可以选择芯片的型号,集成的组件等等,根据实际情况选择)
#有可能涉及到编译器的选择
在 make menuconfig 中的 Advanced configuration options (for developers) > Toolchain Options (NEW)> C Library >C Library implementation (Use musl) > Use uClibc下面更改
scripts/diffconfig.sh >mydiffconfig (save your changes in the text file mydiffconfig);
更改一些配置项
# Disable the compile-only packages AND disable the SDK (for fast builds)
# and make sure we have build prereqs
sed –in-place=.bak -e ‘s/=m$/=n/g’ -e ‘s/^CONFIG_SDK=y$/CONFIG_SDK=n/’ .config
make V=99 (开始编译)
编译一个单独的软件包(例如cups软件包)
make package/cups/compile V=99
如果特殊原因需要分析编译报错信息:
$ make V=99 2>&1 |tee build.log |grep -i error
则将编译的所有输出信息保存在build.log中,将error信息打印在屏幕上。
还发现一个记录log的好办法,打开make menuconfig里面的Advanced configuration options (for developers),接着开启Enable log files during build process,这样在使用make V=99的时候自动会生成logs文件夹,里面详细记录了各个阶段的日志文件,相比上述输出日志的形式,这种更加全面,实际使用过程发现好像反应稍微慢了点,不过没有错误才是最好的,不是么?
编译之后的文件主要有以下几类:
bin/.trx 文件: 路由器固件。如果没有另外一种也不必惊慌。关于.bin和.trx的区别,一种说法是,第一次刷路由器的时候,需要用.bin文件,如果需要再升级,则不能再使用 .bin文件,而需要用 .trx文件。原因是 .bin是将路由器的相关配置信息和 .trx封装在一起而生成的封包,也就是说是包含路由器版本信息的 .trx 在第一次刷固件的时候,我们需要提供这样的信息,而在后续升级时则不再需要,用 .trx文件即可。
packages文件夹: 里面包含了我们在配置文件里设定的所有编译好的软件包。
(可选)OpenWrt-SDK.**.tar.bz2: 这个也就是我们定制编译好的OpenWRT SDK环境。我们将用这个来进行OpenWrt软件包的开发。我的 TP-Link WR841N v7 编译的SDK文件名是OpenWrt-SDK-ar71xx-for-linux-x86_64-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2
(可选)OpenWrt-ImageBuilder-**.tar.bz2: 这个可以简单打包自己需要的Package和配置文件进入固件中。我的文件名为OpenWrt-ImageBuilder-ar71xx_generic-for-linux-x86_64.tar.bz2
(可选)OpenWrt-Toolchain-**.tar.bz2: 这个是交叉编译工具链。我的是OpenWrt-Toolchain-ar71xx-for-mips_34kc-gcc-4.8-linaro_uClibc-0.9.33.2.tar.bz2
md5sums 文件: 这个文件记录了所有我们编译好的文件的MD5值,来保证文件的完整性。
编译完成后,一定要将编译好的bin目录进行备份。
Cleaning Up
You might need to clean your build environment every now and then. The following make-targets are useful for that job:
Clean
make clean
deletes contents of bin and build_dir directories.
Dirclean
make dirclean
deletes contents of /bin and /build_dir directories and additionally /staging_dir and /toolchain (=the cross-compile tools). ‘Dirclean’ is your basic “Full clean” operation.
Distclean
make distclean
nukes everything you have compiled or configured and also deletes all downloaded feeds contents and package sources.
CAUTION: In addition to all else, this will erase your build configuration (.config), your toolchain and all other sources. Use with care!
There are numerous other functionalities in the OpenWrt build system, but the above should have covered some of the fundamentals.