在Centos7上交叉编译生成OpenWrt固件
安装ss-*
获取最新的ss, 当前是
wget https://github.com/*/*-libev/archive/v2.5.6.tar.gz
解压后 ./configure, make, make install
设置代理
[root@u02 ~]# more /etc/*-local.json { "server": "milton.somewhere.com", , "local_address":"127.0.0.1", , "password": "foobar", , "method": "aes-256-cfb" }
启动本地代理
/usr/local/bin/ss-local -c /etc/*-local.json -b
如果要在后台启动
nohup /usr/local/bin/ss-local -c /etc/*-local.json -b 0.0.0.0 -l 1080 > /dev/null 2>&1 & # 检查是否成功启动 netstat -lnp| # 加入开机自启动 echo " nohup ss-local -c /etc/*/config.json /dev/null 2>&1 &" /etc/rc.local # 查看后台进程 ps aux |grep ss-local
配置为git的代理
git config --global http.proxy 'socks5://127.0.0.1:1080'orgit config --local http.proxy 'socks5://127.0.0.1:18001' #这个无效, 必须用global # 检查是否生效 git config --list
Git导出代码
# The development branch (trunk) contains everything from documentation to experimental patches. git clone git://github.com/openwrt/openwrt.git # 15.05 branch (Chaos Calmer) git clone -b chaos_calmer git://github.com/openwrt/openwrt.git # 14.07 branch (Barrier Breaker) git clone -b barrier_breaker git://github.com/openwrt/openwrt.git # 更新代码 git pull
(可选)下载并安装所有可用的"feeds"
cd openwrt ./scripts/feeds update -a# 中间会出很多warning, 不用管它 ./scripts/feeds install -a
让OpenWrt构建系统检查缺失的package, 这里你需要选择编译的配置和目标
make menuconfig (most likely you would like to use this) make defconfig
在make menuconfig中, 对已经选择好的配置, 最好通过save, 保存成单独的config, 否则, 在选择新的芯片类型的时候, 选择的信息就全被重置了
编译
make defconfig sudo yum install zlib-static patch subversion make defconfigmake menuconfig make V=smake V=99 TARGET_DEVICES=y1
如果需要后台运行可以通过
nohup .log >& &
Proceed with build (i.e. cross-compile the downloaded sources to binaries)
\\After the cross-compilation process the trunk-directory contained over 240000 files with a total size of above 3GiB!
编译结果
编译成功后, 生成的文件可以在 <buildroot_dir>/bin 目录找到. The compiled files are additionally classified by the target platform, so e.g. a firmware built for an ar71xx device will be located in <buildroot_dir>/bin/ar71xx directory.
E.g. if your <buildroot_dir> is ~/openwrt/trunk, the binaries are in ~/openwrt/trunk/bin/ar71xx.
注: 构建中需要的库
yum install openssl-devel ncurses-devel yum install zlib-static patch subversion
清理工作目录
# 只清理 /bin 和 /build_dir make clean # 只清理 /bin , /build_dir , /staging_dir , /toolchain 和 /logs make dirclean # 清理所有, 包括下载的feeds contents 和 package sources, 以及清除编译配置文件 make distclean
增加对新设备支持需要修改的文件
以下以MTK(ralink)芯片系列的路由为例
1. 在 target/linux/ramips/image/ 目录下能看到对应的mt7***.mk和rt****.mk文件, 这些文件会被同一目录的Makefile所引用, 需要在对应的芯片型号mk文件中添加新设备的信息, 如下, 其中DEVICE_PACKAGES是此型号默认需要安装的package
define Device/pbr-m1 DTS := PBR-M1 IMAGE_SIZE := $(ralink_default_fw_size_16M) DEVICE_TITLE := PBR-M1 DEVICE_PACKAGES := kmod-usb3 kmod-ledtrig-usbdev kmod-ata-core kmod-ata-ahci \ kmod-rtc-pcf8563 kmod-i2c-mt7621 endef TARGET_DEVICES += pbr-m1
2. target/linux/ramips/base-files/etc/board.d/目录下的 01_leds 和 02_network 是用来设置设备的led灯和网口定义的
3. target/linux/ramips/base-files/lib/ramips.sh
4. target/linux/ramips/base-files/lib/upgrade/platform.sh
5. 在 target/linux/ramips/dts/ 目录下新增对应的dts或dtsi文件
Update 2017-01-19
如果编译过程中出现 config.status: error: cannot find input file: `po/Makefile.in.in' 错误, 需要安装glib2-devel
Update 2017-01-21
如果中途有下载失败的文件包, 可以手动下载后, 上传到dl目录, 再继续进行编译