如何在OpenWRT环境下做开发 openwrt java环境

\u600e\u4e48\u5728linux\u4e0a\u5b89\u88c5openwrt\u73af\u5883

1.\u5b89\u88c5\u597dubuntu8.04\u4e2d\u6587\u7248\u672c\u6216\u8005fedora 9\u6216\u800511\uff0c\u641e\u5b9a\u7f51\u7edc\u8fde\u63a5\u3002
\u4ee5\u975eroot\u7528\u6237\u767b\u9646\uff0c\u6253\u5f00\u201c\u5e94\u7528\u7a0b\u5e8f\u2014-\u9644\u4ef6\u2014-\u7ec8\u7aef\u201d\u3002\u5982\u679c\u60a8\u5df2\u7ecf\u5b89\u88c5\u597dlinux, \u90a3\u4e48\u6b64\u6b65\u9aa4\u8bf7\u7565\u53bb\u3002
2.\u5982\u679c\u60a8\u9009\u62e9ubuntu, \u90a3\u4e48ubuntu\u5f00\u53d1\u73af\u5883\u9700\u8981\u7684\u8f6f\u4ef6\u6709
sudo apt-get install gcc g++ binutils patch bzip2 flex bison make autoconf gettext texinfo unzip sharutils subversion libncurses5-dev ncurses-term zlib1g-dev
\u7136\u540e
sudo apt-get update
\u5982\u60a8\u9009\u62e9\u5b89\u88c5fedora11\u6216\u8005fedora9
Fedora 11 or 9:
# yum install autoconf binutils bison bzip2 flex gawk gcc gcc-c++ gettext make ncurses-devel patch unzip wget zlib-devel
\u7531\u4e8efedora \u5b89\u88c5\u5305\u672c\u6765\u5c31\u5f88\u5168\u9762\uff0c\u6240\u4ee5\u9700\u53e6\u5916\u5b89\u88c5\u7684\u4e1c\u897f\u8f83

jikes jamvm \u548c classpath
\u67e5\u770b\u65b9\u6cd5\uff1a
ipkg list |grep jamvm
\u5b89\u88c5
ipkg install jikes classpath jamvm
\u7136\u540ebin\u4e0b\u9762\u4f1a\u6709 jamvm
ln -s /opt/bin/jamvm /opt/bin/java
java -> /opt/bin/jamvm

===================
/opt/bin # java -version
java version "1.5.0"
JamVM version 1.5.4
Copyright (C) 2003-2010 Robert Lougher

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2,
or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

Build information:

Execution Engine: inline-threaded interpreter with stack-caching
Compiled with: gcc 4.2.3

Boot Library Path: /opt/lib/classpath
Boot Class Path: /opt/share/jamvm/classes.zip:/opt/share/classpath/glibj.zip
===================

java\u547d\u4ee4\u53ef\u7528\uff0c\u540c\u6837\u5728\u627e tomcat\u7684\u65b9\u6cd5\uff0c\u770b\u8fc7\u4e00\u4e2a\u5e16\u5b50\u5199\u7684
tomcat\u9700\u8981\u4fee\u6539conf\u6587\u4ef6\uff0c\u4f7f\u7528jikes\u89e3\u6790class\u6587\u4ef6
\u5b9e\u5728\u770b\u4e0d\u4e0b\u53bb\u5230\u5904\u8d34 win\u73af\u5883\u7684\u73a9\u610f\u7684\uff0c\u5148\u5206\u4eab\u4e00\u90e8\u5206\u7ecf\u9a8c\u5427~

  1、搭建开发环境
       首先,在执行make menuconfig后,会出现下图:

  其中,图中红框部分是我定制路由器的系统版本,大家可以根据不同的路由器进行不同的选择;绿框部分表示我们需要编译一个SDK开发环境(默认情况下,此项未勾选)。

  编译过程中需要通过官网下载很多相关的软件包,所以必须保证能够顺利连上外网。由于下载速度的限制,编译过程大概需要数小时。编译结束后,所有的产品都会放在编译根目录下的bin/yourtarget/. 例如:我所编译的产物都放在./bin/brcm47xx/下,其中文件主要有几类:

  (1).bin/.trx 文件: 这些都是在我们所选的target-system的类别之下,针对不同路由器型号、版本编译的路由器固件。这些不同路由器的型号和版本是openwrt预先设置好的,我们不需要更改。至于.bin和.trx的区别,一种说法是,第一次刷路由器的时候,需要用.bin文件,如果需要再升级,则不能再使用.bin文件,而需要用.trx文件。原因是,.bin是将路由器的相关配置信息和.trx封装在一起而生成的封包,也就是说是包含路由器版本信息的.trx。在第一次刷固件的时候,我们需要提供这样的信息,而在后续升级时,则不再需要,用.trx文件即可。

  (2)packages文件夹: 里面包含了我们在配置文件里设定的所有编译好的软件包。默认情况下,会有默认选择的软件包。

  (3)OpenWrt-SDK.**.tar.bz2: 这个也就是我们定制编译好的OpenWRT SDK环境。我们将用这个来进行OpenWrt软件包的开发。例如,我所编译好的SDK环境包为:/bin/brcm47xx/OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2
可以从名称上看出,target system是brcm47xx,host system是Linux-x86_64,使用的编译工具以及库是4.3.3+cs_uClibc-0.9.30.1。

  (4)md5sums 文件: 这个文件记录了所有我们编译好的文件的MD5值,来保证文件的完整性。因为文件的不完整,很容易将路由器变成“砖头”。

  需要主要的是,编译完成后,一定要将编译好的bin目录进行备份(如果里面东西对你很重要的话),因为在下次编译之前,执行make clean 会将bin目录下的所有文件给清除掉!!

  2、 更改原有packages

  在编译根目录下会有一个dl的目录,这个目录其实是“download”的简写,在编译前期,需要从网络下载的数据包都会放在这个目录下,这些软件包的一个特点就是,会自动安装在所编译的固件中,也就是我们make menuconfig的时候,为固件配置的一些软件包。如果我们需要更改这些源码包,只需要将更改好的源码包打包成相同的名字放在这个目录下,然后开始编译即可。编译时,会将软件包解压到build_dir目录下。
当然,你也可以自己在dl里面创建自己的软件包,然后更改相关的配置文件,让openwrt可以识别这个文件包。

  由于我的项目更改的内容是底层的,需要跟固件一起安装。所以,我使用的方法就是直接更改dl目录下软件包,然后重新进行固件编译。感觉类似于Linux的内核编译。反复编过十多次,没有任何问题。

  3、 新建自己的packages
对于自己新建的package,而这个package又不需要随固件一起安装,换句话说,就是可以当做一个可选软件包的话。我们可以利用我们的SDK环境来单独编译,编译后会生成一个ipk的文件包。然后利用 opkg install xxx.ipk 来安装这个软件。

  下面具体说下,如何编译一个helloword的软件包。
(1)首先,编写helloworld程序 
编写helloworld.c 
/**************** 
* Helloworld.c 
* The most simplistic C program ever written. 
* An epileptic monkey on crack could write this code. 
*****************/

  #include <stdio.h>
#include <unistd.h> 
int main(void) 

printf("Hell! O' world, why won't my code compile?

"); 
return 0; 
}

  编写Makefile文件
# build helloworld executable when user executes "make"

  helloworld: helloworld.o
$(CC) $(LDFLAGS) helloworld.o -o helloworld

  helloworld.o: helloworld.c
$(CC) $(CFLAGS) -c helloworld.c

  # remove object files and executable when user executes "make clean"
clean: 
rm *.o helloworld 
在这两个文件的目录下,执行make 应该可以生成helloworld的可执行文件。执行helloworld后,能够打印出“Hell! O' world, why won't my code compile?”。 这一步,主要保证我们的源程序是可以正常编译的。下面我们将其移植到OpenWRT上。

  (2)将OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2解压
tar –xvf OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1.tar.bz2

  (3)进入SDK
cd OpenWrt-SDK-brcm47xx-for-Linux-x86_64-gcc-4.3.3+cs_uClibc-0.9.30.1 
可以看到里面的目录结构跟我们之前source的目录结构基本相同,所需要编译的软件包,需要放置在package目录下

  (4)在package目录下创建helloworld目录
cd package 
mkdir helloworld 
cd helloworld

  (5)创建src目录,拷贝 helloworld文件
mkdir src 
cp /home/wrt/test/helloworld.c src 
cp /home/wrt/test/Makefile src

  (6)在helloworld目录下创建Makefile文件
这个Makefile文件是给OpenWRT读的,而之前写的那个Makefile文件是针对helloworld给编译其读的。两个Makefile不在同一层目录下。

  touch Makefile
vim Makefile

  Makefile文件模板内容如下:
############################################## 
# OpenWrt Makefile for helloworld program 


# Most of the variables used here are defined in 
# the include directives below. We just need to 
# specify a basic description of the package, 
# where to build our program, where to find 
# the source files, and where to install the 
# compiled program on the router. 

# Be very careful of spacing in this file. 
# Indents should be tabs, not spaces, and 
# there should be no trailing whitespace in 
# lines that are not commented. 

##############################################

  include $(TOPDIR)/rules.mk

  # Name and release number of this package
PKG_NAME:=helloworld 
PKG_RELEASE:=1

  # This specifies the directory where we're going to build the program.
# The root build directory, $(BUILD_DIR), is by default the build_mipsel 
# directory in your OpenWrt SDK directory 
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)

  include $(INCLUDE_DIR)/package.mk

  # Specify package information for this program.
# The variables defined here should be self explanatory. 
# If you are running Kamikaze, delete the DESCRIPTION 
# variable below and uncomment the Kamikaze define 
# directive for the description below 
define Package/helloworld 
SECTION:=utils 
CATEGORY:=Utilities 
TITLE:=Helloworld -- prints a snarky message 
endef

  # Uncomment portion below for Kamikaze and delete DESCRIPTION variable above
define Package/helloworld/description 
If you can't figure out what this program does, you're probably 
brain-dead and need immediate medical attention. 
endef

  # Specify what needs to be done to prepare for building the package.
# In our case, we need to copy the source files to the build directory. 
# This is NOT the default. The default uses the PKG_SOURCE_URL and the 
# PKG_SOURCE which is not defined here to download the source from the web. 
# In order to just build a simple program that we have just written, it is 
# much easier to do it this way. 
define Build/Prepare 
mkdir -p $(PKG_BUILD_DIR) 
$(CP) ./src/* $(PKG_BUILD_DIR)/ 
endef

  # We do not need to define Build/Configure or Build/Compile directives
# The defaults are appropriate for compiling a simple program such as this one

  # Specify where and how to install the program. Since we only have one file,
# the helloworld executable, install it by copying it to the /bin directory on 
# the router. The $(1) variable represents the root directory on the router running 
# OpenWrt. The $(INSTALL_DIR) variable contains a command to prepare the install 
# directory if it does not already exist. Likewise $(INSTALL_BIN) contains the 
# command to copy the binary file from its current location (in our case the build 
# directory) to the install directory. 
define Package/helloworld/install 
$(INSTALL_DIR) $(1)/bin 
$(INSTALL_BIN) $(PKG_BUILD_DIR)/helloworld $(1)/bin/ 
endef

  # This line executes the necessary commands to compile our program.
# The above define directives specify all the information needed, but this 
# line calls BuildPackage which in turn actually uses this information to 
# build a package. 
$(eval $(call BuildPackage,helloworld))

  (7)返回到SDK的根目录
执行make进行编译 
编译过程会在build_dir目录下完成 
编译结果会放在 bin/[yourtarget]/package目录下helloworld_1_bcm47xx.ipk

  (8)上传helloworld_1_bcm47xx.ipk
使用sftp软件上传helloworld_1_bcm47xx.ipk至路由器 
执行 opkg install helloworld_1_bcm47xx.ipk 
输入hello然后按Tab键,发现openwrt中已经有helloworld可执行命令。 
执行 helloworld 查看程序的效果。

  Hell! O' world, why won't my code compile?

  【End】

  希望对大家能有帮助 :)

  转载



OpenWrt相关的开发可以找佐须之男做技术咨询。

  • openwrt?ssh璁剧疆鏁欑▼
    绛旓細OpenWrt鐨勫唴鏍告槸Linux锛屽師鐢熺増鏈槸娌℃湁鍥惧舰鐣岄潰鐨勶紝鎴戞墜涓婅繖鍙拌矾鐢卞櫒鍥犱负瀹夎浜哃uCI鎵浠ユ墠鏈夊浘褰㈢晫闈傞氳繃SSH鐧婚檰OpenWrt灏辫兘鐪嬪緱鍒板懡浠よ浜嗐傝褰曚竴涓嬫庝箞鐢⊿SH鐧婚檰OpenWrt锛屽鏈嶅姟绔拰瀹㈡埛绔垎鍒繘琛岃缃傚噯澶囧伐浣 璺敱鍣ㄥ埛濂絆penWrt鍥轰欢骞跺畨瑁匧uCI閫氱晠鐨勫眬鍩熺綉涓鍙癕ac鎴朩indows鐢佃剳 鎿嶄綔鐜 OpenWrt...
  • openwrt娌℃湁澶氱嚎澶氭嫧
    绛旓細鍦ㄥ鐢ㄨ矾鐢卞櫒涓紝涓鑸緢灏戝甫璐熻浇鍧囪 鍙婂绾垮鎷ㄦ帶鍒跺姛鑳界殑锛屽洜涓鸿繖浜涘姛鑳藉彧鍦ㄩ偅浜涢潪甯搁珮绔殑璺敱鍣ㄤ笂鎵嶆湁锛屼絾浣犵殑璺敱鍣ㄨ鏄埛浜哋penWrt绯荤粺锛岄偅瑕佸疄鐜拌繖浜涘姛鑳藉氨闈炲父绠鍗曚簡銆傛湰鏂囨垜浠氨鏉ヨ瑙penWrt鐨勮礋杞藉潎琛″強澶氱嚎澶氭嫧鎺у埗搴旂敤mwan3锛岃澶у涓璧锋潵浜彈涓涓嬭繖浜涚湅浼煎緢楂樻繁鐨勫姛鑳芥槸濡備綍鍦∣penWrt鐜涓...
  • 濡備綍涓虹幇鏈夌殑openwrt缂栬瘧涓涓猳pkg涓婃病鏈夌殑杞欢
    绛旓細渚濇杈撳叆浠ヤ笅鍛戒护锛1.ubuntu寮鍙鐜闇瑕佺殑杞欢锛歴udo apt-get install gcc g++ binutils patch bzip2 flex bison make autoconf gettext texinfo unzip sharutils subversion libncurses5-dev ncurses-term zlib1g-dev gawk sudo apt-get update 2.鍒涘缓鐩綍 mkdir openwrt 3.鑾峰彇OpenWrt婧愪唬鐮佸拰瀹夎鍖咃紝...
  • openwrtpasswall璋冩暣ping
    绛旓細1銆佽繘鍏OpenWrtPasswall椤甸潰锛氶鍏堬紝鍦ㄦ祻瑙堝櫒涓緭鍏ヨ矾鐢卞櫒鐨処P鍦板潃骞剁櫥褰曠鐞嗛〉闈紝鎵惧埌OpenWrtPasswall閫夐」锛岃繘鍏asswall璁剧疆鐣岄潰銆2銆侀夋嫨鏈嶅姟鍣ㄨ妭鐐癸細鍦≒asswall璁剧疆鐣岄潰涓紝閫夋嫨鏈嶅姟鍣ㄨ妭鐐归夐」锛屽苟鎵惧埌闇瑕佽繛鎺ョ殑VPN鏈嶅姟鍣紝鎵澶勫湴鐞嗕綅缃拰缃戠粶鐜閫夋嫨鍚堥傜殑鏈嶅姟鍣ㄨ妭鐐广3銆佽皟鏁磋繛鎺ュ弬鏁帮細鍦ㄨ繛鎺ラ夐」涓墦寮...
  • 鎬庝箞ubuntu涓嬫惌寤openwrt寮鍙鐜?
    绛旓細2 瑙e帇鏂囦欢銆傝繘鍒板瓨鏀句笅杞芥枃浠剁殑鐩綍涓嬫墽琛宼ar-zxvfqt-everywhere-opensource-src-4.7.0.tar.gz 鍏朵腑qt-everywhere-opensource-src-4.7.0.tar.gz鏄垰涓嬭浇鏂囦欢鐨勬枃浠跺悕 3 榛 璁ゆ儏鍐典笅绯荤粺鏄病鏈塯++缂栬瘧鐜鐨勩傞渶瑕佹墜鍔ㄥ畨瑁呫傛墽琛宻udoapt-getinstall build-essential銆傚鏋滄彁绀烘壘涓嶅埌鍖呭彲浠ユ洿鏂颁竴涓嬫簮...
  • openwrt瀹夎linux缃戠粶椹卞姩
    绛旓細4.瀹夎缂栬瘧鐜锛氫负浜嗙紪璇戝拰瀹夎椹卞姩绋嬪簭锛屼綘闇瑕鍦∣penWrt璁惧涓婂畨瑁呯浉鍏崇殑缂栬瘧宸ュ叿鍜屽簱鏂囦欢銆傚彲浠ヤ娇鐢ㄤ互涓嬪懡浠ゅ畨瑁呯紪璇戠幆澧冿細```opkg update opkg install build-essential ```5.缂栬瘧鍜屽畨瑁呴┍鍔細杩涘叆椹卞姩绋嬪簭鎵鍦ㄧ殑鐩綍锛屼娇鐢╩ake鍛戒护缂栬瘧椹卞姩绋嬪簭銆傚叿浣撶紪璇戣繃绋嬪彲鑳藉洜椹卞姩绋嬪簭鑰屽紓锛岄氬父鎯呭喌涓嬶紝鍙互閫氳繃...
  • 濡備綍缂栬瘧OpenWrt
    绛旓細鎮ㄦ兂鍦ㄥ疄楠屾х殑骞冲彴涓婃祴璇OpenWrt; 鎮ㄥ弬涓庢祴璇曟垨鍙備笌寮鍙慜penWrt鐨勫伐浣; 鎴栬,鏈绠鍗曠殑鐩殑灏辨槸涓轰簡淇濇寔鑷繁鐨Openwrt涓烘渶鏂扮増鏈; 鑻ユ兂瀹炵幇涓婅堪鐩殑,鍏跺疄寰堢畝鍗,鎸変笅杩版枃瀛楀嵆鍙垚鍔熺紪璇戝嚭涓涓偍鐨凮penwrt鏉ャ 鍑嗗宸ヤ綔 鍦ㄥ紑濮嬬紪璇慜penwrt涔嬪墠闇瑕佹偍鍋氫簺鍑嗗宸ヤ綔;涓庡叾浠栫紪璇戣繃绋嬩竴鏍,绫讳技鐨勭紪璇戝伐鍏峰拰缂栬瘧鐜鏄繀涓...
  • 缂栬瘧OpenWrt绯荤粺姹傚姪
    绛旓細OpenWrt缂栬瘧鐜鎼缓鍜岀紪璇戞柟娉 涓銆 鏇存柊寮鍙戠郴缁熴 瀹夎瀹寀buntu 鍚庯紝閲嶆柊寮鏈虹殑鏃跺欙紝浼氭湁涓涓猇Mware tools 瀹夎鐨勬彁绀虹晫闈紝鑰愬績绛夊緟锛岀瓑鍒癡Mware tools 瀹夎濂藉悗 鍥犱负鏇存柊绯荤粺鍜屽畨瑁呬竴浜涘伐鍏峰寘闇瑕佺敤鍒扮綉缁滐紝鎵浠ヨ繘鍏buntu鐨勭晫闈㈠悗锛 灏唘...
  • 銆愯浆.寰呴獙璇併鍦∣penWRT涓婇厤缃甦ebian妯″紡
    绛旓細銆 鍘熸枃鍑哄 銆戞煇浜涘彴杩囦簬寮烘倣鐨 ARM 杞矾鐢憋紝浣嗘槸鏇村鍚堥傜殑绯荤粺鍙湁 OpenWRT 锛屾晠鍙娇鐢 chroot 寤虹珛涓涓闈鐜鏉ュ埄鐢ㄥ浣欑殑鎬ц兘銆傞鍏堬紝閫氬父 OpenWRT 閲嶇疆鐨 shell 涓 ash 锛屽湪 chroot 鍚庝細鍥犱负鎵惧埌鏇夸唬鐨 ash 鑰屽垏鎹㈠け璐ワ紝闇瑕佹浛鎹㈢殑 shell 涓 bash 锛岄氳繃 $SHELL 鐜鍙橀噺鍙互鏌ョ湅褰撳墠鐨 ...
  • OpenWRT涓濡備綍瀹炵幇LAN鍙fˉ鎺ヨ嚦WAN鍙?
    绛旓細鍒犳帀wan銆傚叧闂璬hcp锛岃缃甽an鎶奺th0銆乪th1妗ユ帴銆傚弬鑰冨涓嬶細config interface 'lan'option type 'bridge'option proto 'static'option ipaddr '192.168.1.18'option netmask '255.255.255.0'option _orig_ifname 'eth1 wlan0'option _orig_bridge 'true'option ifname 'eth0 eth1'...
  • 扩展阅读:openwrt登录地址忘了 ... 想在openwrt安装其他软件 ... 软路由openwrt官网 ... openwrt procd-ujail ... 旧智能手机刷成openwrt ... openwrt 把lan删掉了 ... openwrt adbyby ... openwrt opkg ... openwrt配置pppoe上网 ...

    本站交流只代表网友个人观点,与本站立场无关
    欢迎反馈与建议,请联系电邮
    2024© 车视网