記錄Openwrt產品定製開發過程,(三) 開發定製

前置章節:

(二) Make過程

===========================

make過程是Openwrt開發中比較磨人的階段,一旦編譯通過調順暢了,整個系統用起來就爽了。:)

===========================

1 開發定製

OpenWrt提供定製獨立APP(即:ipk)以及定製內建於firmware APP的機制。

同時,OpenWrt自己也集成了大量的應用,可以通過簡單的menuconfig方式集成進firmware中。

1.1 使用系統配置

對於OpenWrt系統已經完成集成的各個應用,可以通過Make menuconfig來定製加入firmware中。對此方法我們在“1.4.3定製編譯”章節中有說明。

1.2 定製支持3G數據卡配置

請參考:wiki.openwrt.org/doc/howtobuild/wireless-router-with-a-3g-dongle

1.2.1 usb networking support

Go to Kernel Modules → USB Support.
Select the following modules by pressing y to include the modules within the compiled image.
Kernel Modules -> USB Support
 kmod-usb2
 kmod-usb-ohci
 kmod-usb-uhci
 kmod-usb-acm # For ACM based modem, such as Nokia Phones
 kmod-usb-net # For tethering and rndis support
kmod-usb-net –> to support usb networking interface. 
Select all subsets if you want perfect support for usb network interfaces, including Android and iPhone tethering. Some newer 4g dongles use usb network interface (rndis) instead of legacy serial protocol.
 kmod-usb-net............... Kernel modules for USB-to-Ethernet convertors
  kmod-usb-net-asix...... Kernel module for USB-to-Ethernet Asix convertors 
  kmod-usb-net-cdc-eem..................... Support for CDC EEM connections 
 -*- kmod-usb-net-cdc-ether.............. Support for cdc ethernet connections 
  kmod-usb-net-cdc-mbim..................... Kernel module for MBIM Devices 
 -*- kmod-usb-net-cdc-ncm..................... Support for CDC NCM connections 
  kmod-usb-net-cdc-subset...... Support for CDC Ethernet subset connections 
  kmod-usb-net-dm9601-ether........ Support for DM9601 ethernet connections 
  kmod-usb-net-hso.. Kernel module for Option USB High Speed Mobile Devices 
  kmod-usb-net-ipheth..................... Apple iPhone USB Ethernet driver 
  kmod-usb-net-kalmia................... Samsung Kalmia based LTE USB modem 
  kmod-usb-net-kaweth.. Kernel module for USB-to-Ethernet Kaweth convertors 
  kmod-usb-net-mcs7830 
  kmod-usb-net-pegasus 
  kmod-usb-net-qmi-wwan.................................... QMI WWAN driver 
  kmod-usb-net-rndis......................... Support for RNDIS connections 
  kmod-usb-net-sierrawireless.......... Support for Sierra Wireless devices 
  kmod-usb-net-smsc95xx. SMSC LAN95XX based USB 2.0 10/100 ethernet devices
 
kmod-usb-serial → to support legacy 3g dongles. 
Select all subsets to ensure that your dongle works. Most 3g dongles use the option driver or generic serial driver to work. Note that option driver has better capability of distinguishing between modem serial interfaces and storage interface than generic usb serial driver.
 kmod-usb-serial..................... Support for USB-to-Serial converters 
  kmod-usb-serial-ark3116........ Support for ArkMicroChips ARK3116 devices 
  kmod-usb-serial-belkin........................ Support for Belkin devices 
  kmod-usb-serial-ch341.......................... Support for CH341 devices 
  kmod-usb-serial-cp210x........... Support for Silicon Labs cp210x devices 
  kmod-usb-serial-cypress-m8.............. Support for CypressM8 USB-Serial 
  kmod-usb-serial-ftdi............................ Support for FTDI devices 
  kmod-usb-serial-ipw.................... Support for IPWireless 3G devices 
  kmod-usb-serial-keyspan........ Support for Keyspan USB-to-Serial devices 
  kmod-usb-serial-mct.............. Support for Magic Control Tech. devices 
  kmod-usb-serial-mos7720.............. Support for Moschip MOS7720 devices 
  kmod-usb-serial-motorola-phone............ Support for Motorola usb phone 
  kmod-usb-serial-option................... Support for Option HSDPA modems 
  kmod-usb-serial-oti6858...... Support for Ours Technology OTI6858 devices 
  kmod-usb-serial-pl2303............... Support for Prolific PL2303 devices 
  kmod-usb-serial-qualcomm................. Support for Qualcomm USB serial 
  kmod-usb-serial-sierrawireless....... Support for Sierra Wireless devices 
  kmod-usb-serial-ti-usb...................... Support for TI USB 3410/5052 
  kmod-usb-serial-visor............... Support for Handspring Visor devices 
 -*- kmod-usb-serial-wwan..................... Support for GSM and CDMA modems

1.2.2 Additional packages required for 3g functionality

Go to Network section. Select `uqmi` to support qmi interface and `ppp` to support standard point-to-point protocol.

Network

 chat
 ppp
 uqmi
有一些數據卡支持umbim,需要添加。
 

Go to Utilities section. Select comgt to provide control over 3g interface and usb-modeswitch to provide mode switching between virtual cd-rom interface to serial interface.

Utilities
 comgt
 usb-modeswitch

1.2.3 Web Interface Support

LuC接口是可選的,如果要想使用,同時又有足夠的空間可以打開配置開關。

Luci
1. Collections
  luci
3. Applications
  luci-app-multiwan (optional to support multiple 3g dongles)
6. Protocols
  luci-proto-3g
 -*- luci-proto-ppp

1.3 定製系統配置進行開發

在已有系統的基礎上定製組件,以為nginx添加rtmp-module為例。

1.3.1 查找feed配置

$./script/feed update -a
$./script/feed install –a
$cd ./openwrt/feeds/

Packages.index中定義了各個預置的包和它們的配置信息。找到你想要定製的nginx。從以下行可以得到配置文件位置:

Config:
 source "feeds/packages/net/nginx/Config.in"

1.3.2 修改feedàConfig.in配置

然後找到配置文件Config.in。該配置文件直接被menuconfig使用,配置以後就可以直接在make menuconfig中進行配置了。

$cd ./openwrt/feeds/packages/net/nginx
$vi Config.in

在配置項的最後一行添加nginx_rtmp入口:

config NGINX_RTMP
 bool
 prompt "Enable RTMP module"
 default n
 

1.3.3 修改feedàMakefile配置

$vi Makefile

在以下節中添加內容:

1.3.3.1 添加包依賴

PKG_CONFIG_DEPENDS := \ 中添加 CONFIG_NGINX_RTMP

1.3.3.2 添加模塊make選項

ADDITIONAL_MODULES:= 中添加

ifneq ($(CONFIG_NGINX_RTMP),y)
 ADDITIONAL_MODULES += --add-module=$(PKG_BUILD_DIR)/nginx-rtmp/
Endif

1.3.3.3 添加主模塊編譯/準備/下載選項

define Package/nginx/install
。。。。
define Build/Prepare
 $(call Build/Prepare/Default)
 $(if $(CONFIG_NGINX_NAXSI),$(call Prepare/nginx-naxsi))
 $(if $(CONFIG_NGINX_LUA),$(call Prepare/lua-nginx))
 $(if $(CONFIG_NGINX_RTMP),$(call Prepare/nginx-rtmp))
endef

1.3.3.4 添加子模塊編譯/準備/下載選項

最後添加下載、包解壓配置項:

define Download/nginx-rtmp
 VERSION:=e08959247dc840bb42cdf3389b1f5edb5686825f
 SUBDIR:=nginx-rtmp
 FILE:=nginx-rtmp-module-$(PKG_VERSION)-$(VERSION).tar.gz
 URL:=https://github.com/arut/nginx-rtmp-module.git
 PROTO:=git
endef
 
define Prepare/nginx-rtmp
 $(eval $(call Download,nginx-rtmp))
 gzip -dc $(DL_DIR)/$(FILE) | tar -C $(PKG_BUILD_DIR) $(TAR_OPTIONS)
endef

1.3.4 修改ROM配置

如果修改了配置導致ROM太大無法生成最終bin文件,可以修改ROM大小。

$ cd target/linux/

找到自己的路由器入口,以我的RT3x5x/RT5350為例,這個入口是 ramips/image。

修改其中的Makefile文件:

ralink_default_fw_size_8M=8060928

將其中的8M改到合適的尺寸。

1.3.5 編譯

$make V=99 –j5

1.4 SDK開發環境

對於自己定製的package(應用),而這個package又不需要隨固件一起安裝,也就是當做一個可選軟件包來使用。這可以利用SDK環境來單獨編譯(避免每次都重新編譯系統),編譯後會在bin/[yourtarget]/package目錄中生成一個ipk的文件包。然後利用 opkg install xxx.ipk 來安裝這個軟件。

打開SDK開發環境,可以通過make menuconfig添加編譯選項SDK,在bin目錄中會生成當前配置的SDK.bz2壓縮文件,解壓這個文件就可以得到個人定製開發的環境。

OpenWrt對此的說明如下:This is the OpenWrt SDK. It contains a stripped-down version of the buildroot. You can use it to test/develop packages without having to compile your own toolchain or any of the libraries included with OpenWrt.

To use it, just put your buildroot-compatible package directory in the subdir 'package/' and run 'make' from this directory.

1.4.1 解壓SDK

$ tar xvf OpenWrt-SDK-ramips-rt305x_64.tar.bz2
$ cd OpenWrt-SDK-ramips-rt305x_64

目錄結構如下。

記錄Openwrt產品定製開發過程,(三) 開發定製

1.4.2 建立定製工作目錄

按照規則在package目錄下建立自己的定製模塊的工作目錄。

$ cd package
$ mkdir myhello
$ cd myhello
$ mkdir src

1.4.3 準備Makefile文件

需要準備兩個Makfile文件,一個在package/myapp/目錄下;一個在package/myapp/src/目錄下。

  1. package/myapp/Makefile
  2. package/myapp/src/Makefile
# build helloworld executable when user executes “make”
 SRC:=myhello.c 
myhello: $(SRC) 
 $(CC) $(SRC) -o myhello 
 # remove object files and executable when user executes "make clean" 
clean: 
 rm *.o 

1.4.4 編譯代碼

  1. 返回到SDK的根目錄
  2. 執行make進行編譯

編譯過程會在build_dir目錄下完成,在目錄build_dir\target-mips_34kc_uClibc-0.9.33.2\test\ipkg-ar71xx中生成可執行文件編譯結果*.ipk會放在 bin/[yourtarget]/package目錄下。

1.4.5 應用myAppxx.ipk

上傳myAppxx.ipk至路由器,執行 opkg install myAppxx.ipk.

輸入myhello可執行命令,並查看程序結果。

=====結束======

Openwrt是組織的很好的一套系統,社區也很成熟,玩熟了可以節省你很多做板的時間!

下面show一下,我的另一塊開發板。 :)

記錄Openwrt產品定製開發過程,(三) 開發定製


分享到:


相關文章: