openwrt MT7688開發板 從零教程
資料百度雲盤:稍後
通用環境搭建介紹
1. 通用環境搭建
1.1 開發環境介紹
Openwrt 可以在大部分的linux 系統上面編譯,包括市面上常用的Ubuntu、Redhat、 Debian、Fedora 等,這裡介紹windows 作業系統上利用VMware + Ubuntu來搭建虛擬機器開發環境。
1.2 安裝虛擬機器
1.2.1 虛擬機器下載
1.2.2 虛擬機器安裝
1.2.3 虛擬機器配置
1.3 虛擬機器安裝Ubuntu
1.3.1 Ubuntu 下載
{{{
http://www.ubuntu.org.cn/download
}}}
下載:
i386就是32位的ubuntu 如果cpu只支援32位的 不支援64位的 就下載這個
amd64就是64位的ubuntu
不要以為i386只能用於intel的cpu,amd64只能用於amd的cpu。別被字面意思所迷惑。
1.3.2 Ubuntu 虛擬機器安裝
1.4 配置編譯環境
1.4.1 由於openwrt 系統編譯的時候需要一些依賴庫,
所以編譯之前需要預安裝一 些依賴庫
1. Ssh (ubuntu sshd 安裝方面宿主機(window)連線虛擬機器)
{{{
sudo apt-get install openssh-client openssh-server
}}}
檢查是否安裝成功
{{{
}}}
2. 裝svn 工具
{{{
$ sudo apt-get install subversion
}}}
3. 安裝git 工具
{{{
$ sudo apt-get install git-core
}}}
4. 安裝samba
{{{
$ sudo apt-get install samba
}}}
在/etc/samba/smb.conf 末尾新增如下程式碼
{{{
[new]
comment = Samba server’s new
path = /new # 共享的Ubuntu 的目錄
public = yes
writable = yes
create mask = 0766
}}}
5. 安裝依賴的庫檔案
{{{
$ sudo apt-get install gcc g++ binutils patch bzip2 flex bison make autoconf gettext texinfo unzip sharutils ncurses-term zlib1g-dev libncurses5-dev gawk openssl libssl-dev
}}}
1.5 更新openwrt 原始碼
1.5.1 Openwrt 官網www.openwrt.org,
1.5.2 原始碼下載
{{{
$ cd $WORK_DIR
$ git clone git://git.openwrt.org/15.05/openwrt.git
}}}
1.6 編譯原始碼
1.6.1 去到openwrt 工作目錄
{{{
$ cd $WORK_DIR/openwrt
$ cp feeds.conf.default feeds.conf
}}}
1.6.2 更新與安裝
{{{
$ ./scripts/feeds update -a
$ ./scripts/feeds install -a
}}}
1.6.3 MT7628/MT7688 編譯選擇
{{{
$ make menuconfig
}}}
編譯原始碼,此次過程中由於程式碼等依賴包都是在編譯到的時候才去網上下載,如果網路好也許很快就能下載完成,如果出現下載不完成中斷後繼續編譯就可以了。
{{{
$ make V=s
}}}
1.6.4 編 譯 完 成 固 件 目 錄 $WORK_DIR/openwrt/bin/ramips/ , 固 件
“openwrt-ramips-mt7628-mt7628-squashfs-sysupgrade.bin” 或 者 ”
openwrt-ramips-mt7628-LinkIt7688-squashfs-sysupgrade.bin”
{{{
$ cd $WORK_DIR/openwrt
$ ls bin/ramips/
}}}
1.7 配置介面介紹
1.8 生成交叉工具鏈
1. 自己編譯獲得openwrt 的交叉工具鏈,
只需要在openwrt 的menuconfig 頂層配置介面中,勾選上“Build the OpenWrt based Toolchain”,如下圖所示
{{{
$ make menuconfig
}}}
儲存退出在目錄下
$WORK_DIR/openwrt/bin/ramips/OpenWrt-Toolchain-ramips-mt7628_gcc-4.8-linaro_u
Clibc-0.9.33.2.Linux-i686.tar.bz2
2. openwrt 的交叉工具鏈下載
{{{
連結: https://pan.baidu.com/s/1qYRwrF2 密碼: vfks
}}}
2. 交叉編譯鏈安裝
2.1 解壓壓縮包
把下載好或者編譯出來的交叉編譯工具鏈拷貝到/opt 目錄下
{{{
$ sudo cp OpenWrt-Toolchain-ramips-mt7628_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-i686.tar.bz2 /opt
$ cd /opt&& sudo tar jxvf OpenWrt-Toolchain-ramips-mt7628_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-i686.tar.bz2
}}}
2.2 設定環境變數
執行命令 sudo vi /etc/bash.bashrc 並在檔案最後新增以下兩行配置
{{{
12$ sudo vi /etc/bash.bashrc
export
PATH=/opt/OpenWrt-Toolchain-ramips-mt7628_gcc-4.8-linaro_uClibc-0.9.33.2.Linux-i6
86/toolch ain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/bin:$PATH export
STAGING_DIR=/$WORK_DIR /openwrt/staging_dir
}}}
上面這個“STAGING_DIR”變數, 如果這“STAGING_DIR”變數不設定的話,會在用交 叉工具鏈編譯檔案時有警 告,但是不影響編譯結果。最後儲存退出。接著在終 端執行以下命令:
{{{
$ source /etc/bash.bashrc
}}}
2.3 測試
執行 mipsel-openwrt-linux-uclibc-gcc -v 如果能正常輸出版本資訊則代表安裝成功
{{{
$ mipsel-openwrt-linux-uclibc-gcc -v
}}}
3. 應用程式安裝
3.1 應用程式編譯
hello_world 編寫
{{{
#include <stdio.h>
Int main(int argc, char *argv)
{
printf(“hello world\n”);
return 0;
}}}
Hello world 編譯, 用file 命令可以檢視編譯出來的目標檔案資訊
{{{
$ mipsel-openwrt-linux-uclibc-gcc -Wall -o hello_world hello_world.c
$ $ file hello_world
hello_world: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1, dynamically linked (uses shared libs), with unknown capability 0xf41 = 0x756e6700, with unknown capability 0x70100 = 0x3040000, not stripped
}}}
3.2 應用程式拷貝
如果虛擬機器的網路模式是橋接模式或者是NAT 模式的話,如下圖:
只要開發板的宿主機(window),能正常跟裝置(開發板)正常網路通訊的話,可以直
接進行往裝置進行拷貝檔案了。
{{{
$ scp hello_world [email protected]:/tmp/
}}}
如果虛擬機器不能和裝置(開發板)正常網路通訊的話,需要在宿主機(window)上面安裝
一個tftpd 的程式如下
並通過samba 把檔案共享編譯的檔案拷貝到tftpd 目錄下的,用串列埠登入裝置(開發板),
通過無線或者有線連線裝置(開發板).
{{{
# tftp -gr hello_world 192.168.8.xxx
}}}
3.3 程式執行
用串列埠登入裝置(開發板),去到下載檔案目錄
{{{
# chmod +x hello_world
# ./hello_world
}}}
4. 新增應用程式到Openwrt
openwrt一個比較重要的特點就是它採用 ipk包的形式安裝軟體。有點像是 windows 下面的安裝包一樣,使用者只需用簡單的命令就可以將 ipk 安裝包安裝到openwrt系統中,非常方便。在“安裝 IPK 包”一節中,我們已經介紹過如何安裝openwrt 的ipk安裝包,但那是 openwrt 官方已經為我們編譯好的,下面來介紹一下如何製作編譯一個簡單的安裝包。
切換到openwrt原始碼根目錄,然後執行下列命令:
{{{
$ cd $WORK_DIR/openwrt
$ cd ./package/utils //進入 package/utils 目錄
$ mkdir hello_world //建立一個名為“hello_world”的資料夾,用於放置安裝包原始碼。
$ cd hello_world //進入“hello_world” 目錄
$mkdir src //新建一個名為“src”的目錄用於放置原始碼
$ vi src/hello_world.c //在src目錄下新建一個名為hello_world.c 檔案
}}}
輸入 hello_world.c 中的內容同“編譯第一個‘helloworld’應用程式”節中一致,這裡不再
贅述,編輯完成後,儲存退出。
在 src 目錄下新建一個Makefile 輸入以下內容:
{{{
$ vi src/Makefile
all: hello_world
hello_world: hello_world.o
$(CC) $(LDFLAGS) hello_world.o -o hello_world
helloworld.o: hello_world.c $(CC) $(CFLAGS) -c hello_world.c
clean: rm *.o hello_world
}}}
儲存退出,然後再建立Makefile
{{{
$ vi Makefile
include
include $(INCLUDE_DIR)/package.mk
define Package/hello_world
SECTION:=base
CATEGORY:=Utilities
TITLE:=Hello world -prints a hello world message
Endef
define Package/hello_world/description
If you can’t figure out what this program does, you’re probably brain-dead and need
immediate medical attention.
endef
define Build/Prepare
mkdir -p
Endef
}}}
儲存退出,接下來回到 openwrt 根目錄,執行命令
{{{
$ make menuconfig
}}}
並選擇我們已經加進去的安裝包。
Utilities —>
hello_world……………….. Hello world -prints a hello world message
儲存退出。
{{{
$ make package/utils/complie V=s
}}}
等待編譯完成後,我們就可以在以下路徑找到生成的安裝包
{{{
$ ls bin/ramips/packages/base/hello_world_1.0_ramips_24kec.ipk
}}}
PS: 如果要把程式生成在韌體裡面記得選為”*”而不是選”M”