|  | 
 
| 最近朋友给了一款电信的企业级AP,说让我玩玩。之前做过五年的企业级AP开发,对于AP还是有那么点热衷,但凡有机会还是要把玩一番的。 
 这款AP是智达康的ZN-7200-H500,自带的镜像就是基于openWRT开发的。但是功能不够丰富,还是自己动手定制一款实用的AP吧。
 
 简单说一下编译过程:
 1. 搭建编译环境
 在自己的win7专业版机子上装上VMware虚拟机,虚拟机安装ubuntu 14.04
 编译会用到但不限于以下组件、库
 gcc 、g++ 、binutils 、patch 、bzip2 、flex 、bison 、make 、autoconf 、
 gettext 、texinfo 、unzip 、sharutils 、subversion 、libncurses5-dev 、
 zlib1g-dev 、gawk 、asciidoc 、libz-dev
 
 sudo apt-get install x
 
 
 2. 下载openwrt源码
 终端进入自己需要存放工程的目录,执行如下操作
 mkdir openwrt // 创建一个openwrt文件夹
 cd openwrt    //进入openwrt文件夹
 svn co svn://svn.openwrt.org/openwrt/trunk  //下载官网的源码trunk版本
 cd trunk
 ./scripts/feeds update -a     //更新软件包
 ./scripts/feeds install -a    //安装软件包
 
 3. 编译源码
 make menuconfig //进入定制界面(里面可以选择芯片的型号,集成的组件等等,根据实际情况选择)
 
 make V=99   (开始编译)
 几点说明:
 (1) 初次编译,主机需要联网,因为openwrt需要联网下载源码和库文件以及其他的一些组件。这个过程非常大的长,并且openwrt官网下载不稳定,偶尔会出现下载失败的情况。遇到下载失败的情况,可以手动下载相应的压缩文件,然后放到trunk/dl/目录下。
 
 (2) 加速编译;如果自己的电脑性能做够强劲,可以多开辟几个进程用于编译,只要在编译的时候加上-jx(x是个人根据自己的电脑强弱,自己定义的数字,如笔者使用的是-j8)。一旦加上-jx,出错信息可能就不能够直观的看到出错信息了,这个时候就需要重新编译,加上V=99,不要加上-jx。如make V=99。
 
 (3) 编译权限:openwrt建议非root权限下编译,这个在编译的时候会检查,否则不让编译。如果需要在root权限下编译,需要加上FORCE=1.
 
 
 4. 生成镜像的存放路径。
 编译生成的镜像会统一存放在trunk/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/linux-ramips_mt7620n/目录。
 
 5. 定制适合自己单板类型的openwrt
 上面4步仅仅是可以编译生成openwrt已经支持的一些路由器型号的镜像,如果自己的路由器不在支持列表里,那怎么办呢?很显然,openwrt的人是不可能穷尽所有的路由器,也不可能知道你的述求。所以,只能靠你自己了。这一步还是需要有一些知识积累和技能的。
 首先,你需要对当前路由器的一些硬件特性明了,如:以太网口是几个,哪个口是上连口WAN口,哪几个是LAN口;无线接口是否需要跟有线LAN桥接;flash和内存的大小有多大......
 
 什么?这些一点概念都没有,那么还是不要往下看了,等网友有人分享出来捡现成的吧!
 
 在./target/linux/ramips/image/Makefile中,我们可以增加我们的一款路由器定制。
 我们首先找到
 “# MT7620N Profiles”
 依葫芦画瓢,增加
 Image/Build/Profile/ZDCH500=$(call BuildFirmware/Default16M/$(1),$(1),zdch500,ZDCH500)
 记得同时在下面将ZDCH500增加进去,否则不出镜像
 ifeq ($(SUBTARGET),mt7620n)
 define Image/Build/Profile/Default
 $(call Image/Build/Profile/ZDCH500,$(1))
 endef
 
 仅仅由上面的动作还不够,我们还需要提供相应的dts文件。
 ./target/linux/ramips/dts/ZDCH500.dts
 该文件用于描述硬件的相关信息,如gpio、flash分区、usb等
 
 6. 结束。
 
 转自恩山论坛
 
 附加,这里给出极 1 S 的 dts :
 
 /dts-v1/;
 /include/ "mt7620a.dtsi"
 
 / {
 compatible = "HiWiFi-HC5761", "ralink,mt7620a-soc";
 model = "HiWiFi HC5761";
 
 chosen {
 bootargs = "console=ttyS0,115200";
 };
 
 palmbus@10000000 {
 sysc@0 {
 ralink,gpiomux = "i2c", "jtag";
 ralink,uartmux = "gpio";
 ralink,wdtmux = <1>;
 };
 gpio0: gpio@600 {
 status = "okay";
 };
 gpio2: gpio@660 {
 status = "okay";
 };
 gpio3: gpio@688 {
 status = "okay";
 };
 
 spi@b00 {
 status = "okay";
 
 m25p80@0 {
 #address-cells = <1>;
 #size-cells = <1>;
 compatible = "w25q128";
 reg = <0 0>;
 linux,modalias = "m25p80", "w25q128";
 spi-max-frequency = <10000000>;
 
 partition@0 {
 label = "u-boot";
 reg = <0x0 0x30000>;
 read-only;
 };
 
 partition@30000 {
 label = "u-boot-env";
 reg = <0x30000 0x10000>;
 read-only;
 };
 
 factory: partition@40000 {
 label = "factory";
 reg = <0x40000 0x10000>;
 read-only;
 };
 
 partition@50000 {
 label = "firmware";
 reg = <0x50000 0xf80000>;
 };
 
 partition@fd0000 {
 label = "hwf_config";
 reg = <0xfd0000 0x10000>;
 };
 
 partition@fe0000 {
 label = "bdinfo";
 reg = <0xfe0000 0x10000>;
 };
 
 partition@ff0000 {
 label = "backup";
 reg = <0xff0000 0x10000>;
 };
 };
 };
 };
 
 ehci@101c0000 {
 status = "okay";
 };
 
 ohci@101c1000 {
 status = "okay";
 };
 
 sdhci@10130000 {
 status = "okay";
 };
 
 pcie@10140000 {
 status = "okay";
 
 pcie-bridge {
 mt76@0,0 {
 reg = <0x0000 0 0 0 0>;
 device_type = "pci";
 mediatek,mtd-eeprom = <&factory 32768>;
 mediatek,2ghz = <0>;
 };
 };
 };
 
 wmac@10180000 {
 ralink,mtd-eeprom = <&factory 0>;
 };
 
 pinctrl {
 state_default: pinctrl0 {
 gpio {
 ralink,group = "uartf", "wled", "nd_sd";
 ralink,function = "gpio";
 };
 pa {
 ralink,group = "pa";
 ralink,function = "pa";
 };
 };
 };
 
 ethernet@10100000 {
 pinctrl-names = "default";
 pinctrl-0 = <&ephy_pins>;
 mtd-mac-address = <&factory 0x4>;
 ralink,port-map = "llllw";
 };
 
 gpio-keys-polled {
 compatible = "gpio-keys-polled";
 #address-cells = <1>;
 #size-cells = <0>;
 poll-interval = <20>;
 reset {
 label = "reset";
 gpios = <&gpio0 12 1>;
 linux,code = <0x198>;
 };
 };
 
 gpio-leds {
 compatible = "gpio-leds";
 system {
 label = "HC5761:green:system";
 gpios = <&gpio0 9 1>;
 };
 internet {
 label = "HC5761:green:internet";
 gpios = <&gpio0 11 1>;
 };
 wlan2p4 {
 label = "HC5761:green:wlan-2p4";
 gpios = <&gpio3 0 1>;
 };
 wlan5p {
 label = "HC5761:green:wlan-5p";
 gpios = <&gpio0 7 1>;
 };
 };
 
 gpio_export {
 compatible = "gpio-export";
 #size-cells = <0>;
 usbpower {
 gpio-export,name = "usbpower";
 gpio-export,output = <1>;
 gpios = <&gpio0 13 0>;
 };
 };
 
 };
 dts 文件存放位置:target/linux/ramips/dts
 | 
 |