openwrtipk編譯
⑴ Openwrt 編譯ipk出錯,如下錯誤,怎麼解決 denghuinow@Ubuntu:
程序包有問題,或者缺少其他依賴包,感覺,建議不成熟見諒
⑵ openwrt編譯ipk時怎麼找到模塊
編譯的時候
以下為網友遇到的問題
Package helloworld is missing dependencies for the following libraries: libc.so.6 libpthread.so.0
缺少類庫,然後其實我發現我的類庫在系統里是存在的:
locate libc.so.6
結果:
/lib/i386-linux-gnu/libc.so.6
/lib/i386-linux-gnu/ libpthread.so.0
/lib64/libc.so.6
但是我的應用程序用到了 Libpthread,所以提示 少了2個依賴庫。
⑶ openwrt-SDK編譯成功但找不到ipk
解壓之後就是OpenWrt-SDK-ar71xx-for-linux-i686-gcc-4.6-linaro_uClibc-0.9.33.2,此目錄結構跟openwrt的目錄結構基本一致
[cpp] view plain
song@song-virtual-machine:attitude_adjustment# ls bin/ar71xx/OpenWrt-SDK-ar71xx-for-linux-i686-gcc-4.6-linaro_uClibc-0.9.33.2
bin Config.in docs include logs package Packages.gz rules.mk staging_dir tmp
build_dir dl feeds.conf.default LICENSE Makefile Packages README.SDK scripts target
[cpp] view plain
song@song-virtual-machine:attitude_adjustment# ls
bin build_dir dl feeds.conf.default LICENSE Makefile README scripts target toolchain
BSDmakefile Config.in docs feeds include
⑷ 在小米路由器3G的OpenWRT環境安裝node.js
在路由器的 OpenWRT 環境安裝 node.js 環境需要有以下幾個條件:
Hirokazu MORIKAWA的github項目 https://github.com/nxhack/openwrt-node-packages 是支持arm/mips/x86架構的,能夠滿足大多數的嵌入式設備。下面是我的編譯過程:
至此,任務達成。如果覺得編譯太麻煩,可以直接使用我編譯的版本。(注意:只能在小米路由器3G上使用)。
https://chou-o-ning.github.io/blog/assets/node_v8.17.0-1_mipsel_24kc.ipk
https://chou-o-ning.github.io/blog/assets/node-npm_v8.17.0-1_mipsel_24kc.ipk
https://chou-o-ning.github.io/blog/assets/openwrt-ramips-mt7621-mir3g-squashfs-sysupgrade.tar
可絕改以使用下面的命令,看到相關的依賴模塊。
依賴模塊中,有些模塊是用戶態程序,比如 coreutils,不依賴於內核,可以通過 opkg update 和 opkg install 命令一個一個安裝。
有些模塊是內核模塊,比如 ipset,這時就必須要使用自己編譯出來的模塊了。使用下面的命令找到相關的模塊:
然後上傳到單板上,單獨安裝指定文件。
如岩宏戚果還繼續出現依賴性錯誤,則繼續下面的操作:
列印出依賴關系後,繼續遞歸處理每個安裝文件粗陵。
⑸ 如何在OpenWRT環境下做開發
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 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 ing 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 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 ipk包直接編譯到固件
如果你只是要編譯一個自定義的固件(默認帶什麼軟體,不帶什麼軟體,自定義默認的配置等等),那推薦你用ImageBuilder,簡單快速,省心省力 你要是需要自己開發軟體包,用OpenWRT的SDK,直接出ipk文件 要完全重寫就buildroot
⑺ 如何為現有的openwrt編譯一個opkg上沒有的軟體
一、安裝編譯環境(以ubuntu10.10為例)
依次輸入以下命令:
1.ubuntu開發環境需要的軟體:
sudo 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源代碼和安裝包,更新
svn checkout svn://svn.openwrt.org/openwrt/backfire
cd backfire
./scripts/feeds update -a
./scripts/feeds install -a
4.配置編譯選項
make menuconfig
在target system里選擇Broadcom BCM63xx,根據需要選擇其他的軟體,
*:表示該模塊直接編譯到核心中
M:該模塊以被核心支持,可以後再安裝
空白:不支持該模塊
具體模塊的起什麼作用需要多google;
5.編譯選項配置保存後,開始編譯
make V=99
V=99表示輸出詳細的debug信息;
二、編譯准備
1.下載源文件
下載地址:http://ftp.awk.cz/cntlm/ ,最新的版本是0.91rc6;
2.獲取md5sum碼
進入下載文件目錄,在終端里輸入
md5sum cntlm-0.91rc6.tar.gz
獲得md5驗證碼:
3.編寫makefile文件
在openwrt/backfire目錄中的package目錄下新建cntlm目錄,在cntlm目錄下新建文件,命名為makefile,編輯makefile文件,加入如下內容:
---------------------------------------------------------------------------------------------------------------------------
#
# Copyright (C) 2006-2008 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=cntlm
PKG_VERSION:=0.91rc6
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=http://ftp.awk.cz/cntlm/
PKG_MD5SUM:=
PKG_INSTALL:=1
include $(INCLUDE_DIR)/package.mk
define Package/cntlm
SUBMENU:=Proxy Servers
SECTION:=net
CATEGORY:=Network
TITLE:=Cntlm is a Fast NTLM Authentication Proxy
URL:=http://cntlm.sourceforge.net/
endef
define Package/cntlm/install
$(INSTALL_DIR) $(1)/usr/sbin
$(CP) $(PKG_INSTALL_DIR)/usr/sbin/cntlm $(1)/usr/sbin/
$(INSTALL_DIR) $(1)/usr/share/man/man1
$(CP) $(PKG_INSTALL_DIR)/usr/share/man/man1/$(PKG_NAME).1 $(1)/usr/share/man/man1
$(INSTALL_DIR) $(1)/etc/
$(CP) $(PKG_INSTALL_DIR)/etc/cntlm.conf $(1)/etc/
endef
$(eval $(call BuildPackage,cntlm))
---------------------------------------------------------------------------------------------------------------------------
4.編寫patch文件
由於BCM63xx核心是big endian,而我們常用的intel或AMD的cpu都是little
endian的,cntlm雖然能夠自己檢測編譯環境的endian,但我們是在交叉編譯環境中編譯,cntlm檢測出來的還是ubuntu系統的endian,因此需要設置手動endian為big
endian。具體就是將源碼文件中的config/endian.c文件的rc設定為0.
將源碼文件中的endian.c文件分別復制到a目錄下的config目錄和b目錄下的config目錄,打開b目錄下的config目錄中的endian.c文件,並將其修改為:
-------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdint.h>
int main(int argc, char **argv) {
int rc;
rc = 0;
printf("%s\n", rc ? "little endian" : "big endian");
return rc;
}
---------------------------------------------------------------------------------------------------------------------------
然後保存。
運行:
diff -Naur a/config/endian.c b/config/endian.c >endian.patch
endian.patch文件內容如下:
---------------------------------------------------------------------------------------------------------------------------
--- a/config/endian.c 2007-08-20 07:23:17.000000000 +0800
+++ b/config/endian.c 2010-11-01 18:36:32.000000000 +0800
@@ -1,15 +1,11 @@
#include <stdio.h>
#include <stdint.h>
-uint8_t num[] = { 0xEF, 0xBE };
-/*
- * RC: 1 = LE, 0 = BE
- */
int main(int argc, char **argv) {
int rc;
- rc = (*((uint16_t *)num) == 0xBEEF);
+ rc = 0;
printf("%s\n", rc ? "little endian" : "big endian");
return rc;
---------------------------------------------------------------------------------------------------------------------------
將endian.patch文件復制到package/cntlm/patches/目錄下(沒有patches目錄就新建一個)。
三、編譯
1.選定安裝包
終端輸入:
make menuconfig
在Network——》Proxy Severs中選擇cntlm;
2.開始編譯
終端輸入:
make package/cntlm/compile V=99
中間可能會出現一些提示(Note),可以不用理會。編譯完成後在bin/packages目錄下可以看到cntlm_0.91rc6-1_brcm63xx.ipk文件啦。
四、補充
上面提到在編譯過程中出會現提示(Note),一般如下:
utils.c:1: note: someone does not honour COPTS correctly, passed 0 times
這是由於cntlm源碼文件中CFLAG的設置是覆蓋而不是續接,與openwrt要求不同,在openwrt一般寫成CFLAG += 的方式。可以通過如下修改去除note:
將源碼包中的Makefile文件復制到a目錄和b目錄,打開b目錄下的Makefile文件,作如下修改:
CFLAGS+=$(FLAGS)
即增加上面的「+」號,保存。
運行:
diff -Naur a/Makefile b/Makefile > makefile.patch
得到的makefile.patch文件如下:
---------------------------------------------------------------------------------------------------------------------------
--- a/Makefile 2010-04-29 19:18:58.000000000 +0800
+++ b/Makefile 2010-11-09 20:17:33.405177000 +0800
@@ -16,7 +16,7 @@
CC=gcc
VER=`cat VERSION`
OBJS=utils.o ntlm.o xcrypt.o config.o socket.o acl.o auth.o http.o forward.o direct.o scanner.o pages.o main.o
-CFLAGS=$(FLAGS) -std=c99 -Wall -pedantic -O3 -D__BSD_VISIBLE
-D_ALL_SOURCE -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112
-D_ISOC99_SOURCE -D_REENTRANT -DVERSION=\"`cat VERSION`\" -g
+CFLAGS+=$(FLAGS) -std=c99 -Wall -pedantic -O3 -D__BSD_VISIBLE
-D_ALL_SOURCE -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=200112
-D_ISOC99_SOURCE -D_REENTRANT -DVERSION=\"`cat VERSION`\" -g
OS=$(shell uname -s)
OSLDFLAGS=$(shell [ $(OS) = "SunOS" ] && echo "-lrt -lsocket -lnsl")
LDFLAGS:=-lpthread $(OSLDFLAGS)
---------------------------------------------------------------------------------------------------------------------------
將makefile.patch文件復制到package/cntlm/patches目錄下,重新編譯即可。
⑻ 如何安裝tar.gz,或者製作ipk安裝包
有兩種方式安裝:
登錄路由web界面(一般是192.168.1.1),在openwrt的軟體安裝界面上選擇上傳安裝。
登錄openwrt控制台,可用ssh登錄或通過路由的TTL介面在控制台用命令進行安裝:用winscp將下載的ipk安裝包上傳到路由器中,用命令opkg install xxx.ipk安裝即可。
很多新手對linux下的軟體安裝存在誤解,現在簡單解釋一下:
這類源代碼包需要解壓後(tar.gz的用tarzxvf解壓,tar.bz2的用tarjxvf解壓),進入解壓目錄,一般都有一個INSTALL的文本文件,裡面一般都是安裝的詳細說明,可以用vi、nano、pico或X下面的文本編輯器(如gedit,gvim,kedit等)打開查看,安裝一般就是三個步驟:
1、configure,這一步一般用來生成Makefile,為下一步的編譯做准備,你可以通過在configure後加上參數來對安裝進行控制,比如代碼:
./configure--prefix=/usr
上面的意思是將該軟體安裝在/usr下面,執行文件就會安裝在/usr/bin(而不是默認的/usr/local/bin),資源文件就會安裝在/usr/share(而不是默認的/usr/local/share)。同時一些軟體的配置文件你可以通過指定--sys-config=參數進行設定。有一些軟體還可以加上--with、--enable、--without、--disable等等參數對編譯加以控制,你可以通過允許./configure--help察看詳細的說明幫助。
2、make,這一步就是編譯,大多數的源代碼包都經過這一步進行編譯(當然有些perl或python編寫的軟體需要調用perl或python來進行編譯)。如果在make過程中出現error,你就要記下錯誤代碼(注意不僅僅是最後一行),然後你可以向開發者提交bugreport(一般在INSTALL里有提交地址),或者你的系統少了一些依賴庫等,這些需要自己仔細研究錯誤代碼。
3、makeinsatll,這條命令來進行安裝(當然有些軟體需要先運行makecheck或maketest來進行一些測試),這一步一般需要你有root許可權(因為要向系統寫入文件)。
安裝完畢後你就可以刪除解壓目錄了。採用源代碼編譯方式來安裝軟體是Linux系統下最常見的安裝軟體方法,而且這種方法使你可以更加自由地控制安裝細節,所以提倡大家多使用該方法安裝軟體。
PS:對於bin類型的安裝文件,一般給該文件加上可執行許可權,再運行之即可