openwrt框架分析

2021-07-04 22:04:15 字數 2582 閱讀 1246

1. **上來看有幾個重要目錄package, target, build_root, bin, dl....

---build_dir/host目錄是建立工具鏈時的臨時目錄

---build_dir/toolchain-*是對應硬體的工具鏈的目錄

---staging_dir/toolchain-* 則是工具鏈的安裝位置

---target/linux/目錄裡面是各個平台(arch)的相關**

---target/linux檔案就是配置檔案了

---dl目錄是'download'的縮寫, 

---而在build_dir/目錄下進行解壓,編譯和打補丁等。

---package目錄裡面包含了我們在配置檔案裡設定的所有編譯好的軟體包。預設情況下,會有預設選擇的軟體包。在openwrt中ipk就是一切, 我們可以使用

$ ./scripts/feeds update來對軟體包進行更新.

$ ./scripts/feeds search nmap 查詢軟體包'nmap'

search results in feed 』packages』: 

nmap       network exploration and/or security auditing utility 

$ ./scripts/feeds install nmap 安裝'nmap'這個軟體

$ make package/symlinks  //估計意思是更新軟體源之類的

---bin目錄下生成了很多bin檔案,根據不同的平台來區分。另外bin//package目錄,裡面有很多ipk字尾的檔案,都是package目錄下的原始碼在build_dir目錄下編譯後的生成的結果。

2. 新建自己的packages

對於自己新建的package,而這個package又不需要隨韌體一起安裝,換句話說,就是可以當做乙個可選軟體包的話。我們可以利用我們的sdk環境來單獨編譯,編譯後會生成乙個ipk的檔案包。然後利用 opkg install ***.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

#include

int main(void)

編寫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

openwrt框架分析

這次講講openwrt的結構.1.上來看有幾個重要目錄package,target,build root,bin,dl.build dir host目錄是建立工具鏈時的臨時目錄 build dir toolchain 是對應硬體的工具鏈的目錄 staging dir toolchain 則是工具鏈的...

openwrt框架分析

這次講講openwrt的結構.1.上來看有幾個重要目錄package,target,build root,bin,dl.build dir host目錄是建立工具鏈時的臨時目錄 build dir toolchain 是對應硬體的工具鏈的目錄 staging dir toolchain 則是工具鏈的...

Openwrt框架分析

這次講講openwrt的結構.1.上來看有幾個重要目錄package,target,build root,bin,dl.build dir host目錄是建立工具鏈時的臨時目錄 build dir toolchain 是對應硬體的工具鏈的目錄 staging dir toolchain 則是工具鏈的...