openwrt環境的搭建(以docker ubuntu18為例)


   OpenWrt 可以被描述為一個嵌入式的 Linux 發行版,是路由器的固件,擁有強大的網絡組件和擴展性,常常被用於工控設備、電話、小型機器人、智能家居、路由器以及VOIP設備中。 同時,它還提供了100多個已編譯好的軟件,而且數量還在不斷增加,而OpenWrt SDK 更簡化了開發軟件的工序。官網

  我這里使用的docker搭建開發環境,在普通ubuntu18里操作是一樣的。docker的操作在這里https://www.cnblogs.com/lx--/p/14073513.html

1、首先下載ubuntu18.04的鏡像,換源,裝基本編譯環境

   注意,docker下載的ubuntu鏡像沒有vi編輯器,需要用echo換源,這里以阿里雲為例:

  輸入以下代碼到命令行中換源

echo -e "deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse \n\
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse \n\
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse \n\
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse \n\
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse \n\
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse \n\
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse \n\
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse \n\
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse \n\
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse\n" > /etc/apt/sources.list

我這里增加了一個lx的用戶,一般用普通用戶編譯openwrt,

首先passwd root 設置root 密碼,然后安裝apt install sudo 來安裝sudo命令。之后用adduser lx 增加lx用戶,passwd root 設置root 密碼,我這里用戶密碼和root密碼均為lx。

 

編譯完成后生成鏡像位置/home/lx/openwrt/bin/targets/ramips/mt76x8

我的docker鏡像已經編譯放到我的倉庫中,

可以使用docker 

首先安裝開發的依賴包

apt-get install g++ libncurses5-dev libssl-dev zlib1g-dev bison flex unzip autoconf gawk make gettext gcc binutils patch bzip2 libz-dev python2.7 wget git subversion

安裝完成后安裝對應的openwrt 可以選擇最新的主線,詳情參考官方wiki 

 #最新的

git clone git://github.com/openwrt/openwrt.git
 #下載1806分支的代碼
$ git clone -b openwrt-18.06 https://github.com/openwrt/openwrt.git openwrt1806
 
         
$ #下載19.07分支的代碼
 
         
$ git clone -b openwrt-19.07 https://github.com/openwrt/openwrt.git openwrt1907
 

我這里下載最新主干

git clone git://github.com/openwrt/openwrt.git

 

 

 下載完成后

openwrt源碼目錄結構

  • tools和toolchain目錄:包含了一些通用命令, 用來生成固件, 編譯器, 和C庫.
  • build dir/host目錄:是一個臨時目錄, 用來儲存不依賴於目標平台的工具.
  • build dir/toolchain-目錄:用來儲存依賴於指定平台的編譯鏈. 只是編譯文件存放目錄無需修改.
  • build dir/target-目錄:用來儲存依賴於指定平台的軟件包的編譯文件, 其中包括linux內核, u-boot, packages, 只是編譯文件存放目錄無需修改.
  • staging_dir目錄:是編譯目標的最終安裝位置, 其中包括rootfs, package, toolchain.
  • package目錄:軟件包的下載編譯規則, 在OpenWrt固件中, 幾乎所有東西都是.ipk, 這樣就可以很方便的安裝和卸載.
  • target目錄:目標系統指嵌入式設備, 針對不同的平台有不同的特性, 針對這些特性, “target/linux”目錄下按照平台進行目錄划分, 里面包括了針對標准內核的補丁, 特殊配置等.
  • bin目錄:編譯完OpenWrt的二進制文件生成目錄, 其中包括sdk, uImage, u-boot, dts, rootfs構建一個嵌入式系統完整的二進制文件.
  • config目錄:存放着整個系統的的配置文件.
  • docs目錄:里面不斷包含了整個宿主機的文件源碼的介紹, 里面還有Makefile為目標系統生成docs.
  • include目錄:里面包括了整個系統的編譯需要的頭文件, 但是是以Make進行連接的.
  • feeds目錄:擴展軟件包索引目錄.
  • scripts目錄:組織編譯整個OpenWrt的規則.
  • tmp目錄:編譯文件夾, 一般情況為空.
  • dl目錄:所有軟件的下載目錄, 包括u-boot, kernel.
  • logs目錄:如果編譯出錯, 可以在這里找到編譯出錯的log

 執行feeds更新

 ./scripts/feeds update -a
./scripts/feeds install –a

過程中會報錯,安裝apt install rsync python3  ethtool解決

OpenWRT的feeds包括:

  1. packages – 提供眾多庫, 工具等基本功能. 也是其他feed所依賴的軟件源, 因此在安裝其他feed前一定要先安裝packages!
  2. luci – OpenWrt默認的GUI(WEB管理界面).
  3. xwrt – 另一種可替換LuCI的GUI
  4. qpe – DreamBox維護的基於Qt的圖形界面, 包含Qt2, Qt4, Qtopia, OPIE, SMPlayer等眾多圖形界面.
  5. device – DreamBox維護與硬件密切相關的軟件, 如uboot, qemu等.
  6. dreambox_packages – DreamBox維護的國內常用網絡工具, 如oh3c, njit8021xclient等.
  7. desktop – OpenWrt用於桌面的一些軟件包.
  8. xfce – 基於Xorg的著名輕量級桌面環境. Xfce建基在GTK+2.x之上, 它使用Xfwm作為窗口管理器.
  9. efl – 針對enlightenment.
  10. phone -針對fso, paroli.

 安裝完成后,使用以下命令生成配置文件

make defconfig 

然后make menuconfig 配置

這里我有一塊mt7688的板子,所以這里我Target system 選擇(MediaTek Ralink MIPS)聯發科 mips架構  ,subtarget選擇 MT76X8,如圖所示

 

 

然后make V=s  -j4 進行編譯。

編譯完成后固件會放bin文件夾下。具體位置

/home/lx/openwrt/bin/targets/ramips/mt76x8

編譯完成,做鏡像。

docker commit -a:"lx" -m:"ubuntu18.04 add openwrt" 0c1 l308229423:openwrt

使用docker commit 制作,說明參考之前docker教程。

 

 可以看到鏡像還是比較大的,我已經將他推送到中央倉庫,

可以直接使用docker pull l308229423/openwrt:openwrt來下載使用我的鏡像,請耐心等待,但是也比編譯配置openwrt要快了。

root密碼,用戶密碼均為lx,有一個lx的用戶。歡迎下載使用。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM