[TOC]
OpenWrt是一個高度模塊化, 高度自動化的嵌入式Linux系統(tǒng), 擁有強大的網絡組件, 常常被用于工控設備, 電話, 小型機器人, 智能家居, 路由器以及VOIP設備中. OpenWrt支持各種處理器架構,無論是對ARM,X86,PowerPC或者MIPS都有很好的支持. 其多達3000多種軟件包, 囊括從工具鏈(toolchain), 到內核(linux kernel), 到軟件包(packages), 再到根文件系統(tǒng)(rootfs)整個體系, 使得用戶只需簡單的一個make命令即可方便快速地定制一個具有特定功能的嵌入式系統(tǒng)來制作固件. 其模塊化設計也可以方便的移植各類功能到OpenWrt下, 加快開發(fā)速度.
對于開發(fā)人員, OpenWrt是使用框架來構建應用程序, 而無需建立一個完整的固件來支持. 對于用戶來說, 這意味著其擁有完全定制的能力, 可以用前所未有的方式使用該設備.
2014年12月19日小米路由器公測版正式發(fā)售, 也意味著OpenWrt進入國內主流科技企業(yè)的眼球. 然而OpenWrt到底是一款什么樣的操作系統(tǒng)呢? 對于創(chuàng)客來講, 怎么才能融入創(chuàng)客的設計, 下面就從零介紹如果在pcDuino上開發(fā)OpenWrt.
OpenWrt項目始于2004年1月. 最早的OpenWrt版本基于Linksys為遵守GPL而放出的, 為WRT54G所編寫的代碼, 以及uclibc項目的buildroot. 這個版本以OpenWrt "stable release"之名為人所知, 使用廣泛. 仍有許多OpenWrt應用程序是基于這一版的, 例如Freifunk-Firmware和Sip@Home.
2005年初, 一些新的開發(fā)者進入了團隊. 在封閉開發(fā)了數月之后, 團隊決定發(fā)布OpenWrt的第一個experimental版本. 這個實驗版本使用的build系統(tǒng)是基于buildroot2大改而成的, 而buildroot2來自于uclibc項目. OpenWrt使用官方版GNU/Linux內核代碼, 只是額外添加了片上系統(tǒng)(SoC)的補丁和網絡接口的驅動. 開發(fā)團隊嘗試重新實現GPL tarball中不同開發(fā)商的絕大多數專有代碼. 其中有: 將新固件鏡像文件直接寫入閃存的自由工具(mtd), 配置無線局域網(wlcompat/wificonf), 通過proc文件系統(tǒng)對支持VLAN的switch(交換機)進行編程. 最初發(fā)布的OpenWrt的代號是"White Russian", 來自于著名雞尾酒的名稱. 在OpenWrt發(fā)布0.9版的時候, White Russian的生命周期結束.
下一個版本的開發(fā)正在我們的SVN中進行. 下面一張圖將很清晰的反映OpenWrt的版本史. 從圖上可以看出最新的穩(wěn)定版本代號為Attitude Adjustment, 早期的穩(wěn)定版本為Backfire 和 Kamikaze, 開發(fā)版本一直都是trunk. 各個版本的官方下載地址為 https://dev.openwrt.org/wiki/GetSource
sudo aptitude install -y libncurses5-dev zlib1g-dev gawk flex patch git-core g++ subversion
svn co svn://svn.openwrt.org/openwrt/trunk/ openwrt-pcduino
還可以用Git下載
git clone git://git.openwrt.org/openwrt.gitgit clone git://git.openwrt.org/packages.git
src-git packages git://git.openwrt.org/packages.gitsrc-svn xwrt http://x-wrt.googlecode.com/svn/trunk/packagesrc-git luci git://nbd.name/luci.gitsrc-git routing git://github.com/openwrt-routing/packages.gitsrc-git telephony http://feeds.openwrt.nanl.de/openwrt/telephony.gitsrc-svn phone svn://svn.openwrt.org/openwrt/feeds/phonesrc-svn efl svn://svn.openwrt.org/openwrt/feeds/eflsrc-svn xorg svn://svn.openwrt.org/openwrt/feeds/xorgsrc-svn desktop svn://svn.openwrt.org/openwrt/feeds/desktopsrc-svn xfce svn://svn.openwrt.org/openwrt/feeds/xfcesrc-svn lxde svn://svn.openwrt.org/openwrt/feeds/lxdesrc-link custom /usr/src/openwrt/custom-feed
一般情況, 你至少需要含packages feeds, 其他可根據需求下載, 安裝feeds.
Trunk中默認的feeds下載有packages、xwrt、luci、routing、telephony。如果你需要其他的軟件包,你只需要打開源碼根目錄下面的feeds.conf.default文去掉你需要的軟件包前面的#號,本教程中使用默認的軟件,確定了軟件源之后,更新源:
./scripts/feeds update -a
安裝下載好的包:
./scripts/feeds install -a
目錄結構:
make menuconfig
在官方最新的trunk分支中已經支持pcDuino這個target了.
具體配置如下:
A. 配置目標系統(tǒng)(Target System)
Target System (Allwinner A1x/A20/A3x) —>
B. 配置目標硬件(Target Profile)
Target Profile (pcDuino) —>
C. 配置編譯出來的image, 配置rootfs文件系統(tǒng)的格式這里選擇ext4, rootfs文件系統(tǒng)的大小這里設置(48M).
Target Images —> [ ] ramdisk —> *** Root filesystem archives *** [ ] cpio.gz[*] tar.gz *** Root filesystem images *** [*] ext4[ ] jffs2[ ] squashfs[*] GZip images*** Image Options ***(48) Root filesystem partition size (in MB)(6000) Maximum number of inodes in root filesystem(0) Percentage of reserved blocks in root filesystem[ ] Include kernel in root filesystem —>[ ] Include DTB in root filesystem
D. 選擇編譯交叉編譯器, 還有開發(fā)SDK.
[*] Build the OpenWrt Image Builder[*] Build the OpenWrt SDK
E. 配置無線網卡, V2/V3都是用的rtl8188cus無線網卡
Kernel modules —>Wireless Drivers —>-*- kmod-cfg80211…………………. cfg80211 – wireless configuration API<*> kmod-lib80211……………………………… 802.11 Networking stack{M} kmod-mac80211………………… Linux 802.11 Wireless Networking Stack kmod-rtl8192cu………………….. Realtek RTL8192CU/RTL8188CU support{M} kmod-rtlwifi……………………………. Realtek common driver part
F. LucI系統(tǒng)快速配置接口
LuCI —>1. Collections —>{*} luci luci-ssl……………………. Standard OpenWrt set with HTTPS4. Themes —> -*- luci-theme-base…………………………. Common base for all-*- luci-theme-bootstrap……………………… Bootstrap Theme<*> luci-theme-freifunk-bno……………….. Freifunk Berlin Nordost Theme<*> luci-theme-freifunk-generic………………….. Freifunk Generic Theme<*> luci-theme-openwrt……………………………………. OpenWrt.org5. Translations —><*> luci-i18n-chinese………………….. Chinese (by Chinese Translators)-*- luci-i18n-english………………………………………… English
make –j 8 V=s
由于OpenWrt整個系統(tǒng)非常龐大, 編譯很慢. "-j 8" 表示用8線程進行編譯, "V=s"編譯的時候顯示編譯信息. 如果你的電腦是4核建議你用8線程進行編譯, 雙核建議你使用4線程. 這里測試8線程編譯需要一個小時才能編譯完成.
由于OpenWrt的u-boot用的是u-boot-2013的版本, 目前只支持SD卡啟動, 而且內核用的是3.12.5版本. 另外我們的3.4.29的內核用的是全志fex, 而且3.12.5用的是linux官方的kernel使用的是dts設備樹.這樣的話我們就不能用之前的BSP方案, 我們要自己做一個從SD卡啟動的系統(tǒng).
pcDuino從SD卡啟動順序是A10—>u-boot–>uImage–>OpenWrt.
根據全志官網的說明, 這些軟件都必須放在SD卡固定的地址. 那么首先要對A10進行分區(qū). 根據全志芯片的說明, 需要對SD卡進行下表固定分區(qū).
Filesystem Size Used Avail Use% Mounted on/dev/sda1 195G 60G 126G 33% /udev 989M 4.0K 989M 1% /devtmpfs 400M 940K 399M 1% /runnone 5.0M 0 5.0M 0% /run/locknone 998M 76K 998M 1% /run/shm/dev/sdb1 3.8G 12K 3.8G 1% /media/0005-559Bsudo dd if=/dev/zero of=/dev/sdb bs=1M count=1
cd uboot-sunxi-pcDuinopillar@monster:~/openwrt/trunk/bin/sunxi/uboot-sunxi-pcDuino$ ls openwrt-sunxi-pcDuino-sunxi-spl.bin openwrt-sunxi-pcDuino-u-boot.binopenwrt-sunxi-pcDuino-sunxi-with-spl.binsudo dd if=openwrt-sunxi-pcDuino-sunxi-with-spl.bin of=/dev/sdb bs=1024 seek=8
這時候把SD卡插到板子上, 重新上電就會看到下面打印信息.
U-Boot 2013.10-rc2 (Jan 15 2014 – 17:48:38) Allwinner TechnologyCPU: Allwinner A10 (SUN4I)Board: pcDuinoI2C: readyDRAM: 1 GiBMMC: SUNXI SD/MMC: 0*** Warning – bad CRC, using default environmentIn: serialOut: serialErr: serialNet: emacHit any key to stop autoboot: 0sun4i#
從上面可以看到u-boot已經完全啟動了, 上面的時間是編譯的時間. 上面的信息還可以看到我們的環(huán)境變量沒有設置, 它使用的是默認的環(huán)境變量. 前面介紹, 系統(tǒng)建立在分區(qū)表不同的地方, 但是我們現在SD卡還沒有分區(qū)表, 我們需要先建立分區(qū)表再做環(huán)境變量.
pillar@monster:~/openwrt/trunk/bin/sunxi$ sudo fdisk /dev/sdb [sudo] password for pillar: Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabelBuilding a new DOS disklabel with disk identifier 0x97bf3019.Changes will remain in memory only, until you decide to write them.After that, of course, the previous content won’t be recoverable.Warning: invalid flag 0×0000 of partition table 4 will be corrected by w(rite) Command (m for help): m #幫助 Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition #創(chuàng)建分區(qū) o create a new empty DOS partition table p print the partition table #查看分區(qū) q quit without saving changes s create a new empty Sun disklabel t change a partition’s system id #改變分區(qū)類型 u change display/entry units v verify the partition table w write table to disk and exit x extra functionality (experts only) Command (m for help): p #查看分區(qū)Disk /dev/sdb: 4027 MB, 4027580416 bytes124 heads, 62 sectors/track, 1023 cylinders, total 7866368 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x97bf3019Device Boot Start End Blocks Id System#沒有分區(qū) Command (m for help): n #創(chuàng)建分區(qū) Partition type: p primary (0 primary, 0 extended, 4 free) #主分區(qū) e extended #擴展分區(qū) Select (default p): #選擇默認主分區(qū)Using default response pPartition number (1-4, default 1): #分區(qū)號為1Using default value 1First sector (2048-7866367, default 2048): #選擇默認值Using default value 2048Last sector, +sectors or +size{K,M,G} (2048-7866367, default 7866367): 34815 #這個根據全志的手冊來第一個分區(qū)必須這么大Command (m for help): p #查看分區(qū) Disk /dev/sdb: 4027 MB, 4027580416 bytes124 heads, 62 sectors/track, 1023 cylinders, total 7866368 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x97bf3019 Device Boot Start End Blocks Id System /dev/sdb1 2048 34815 16384 83 Linux #創(chuàng)建的第一個分區(qū)Command (m for help): n #再創(chuàng)建一個分區(qū) Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): #主分區(qū)Using default response p Partition number (1-4, default 2): #第二個主分區(qū)Using default value 2First sector (34816-7866367, default 34816): #默認大小從34816開始Using default value 34816Last sector, +sectors or +size{K,M,G} (34816-7866367, default 7866367): #默認全部分到第二分區(qū) Using default value 7866367 Command (m for help): p #再一次查看分區(qū) Disk /dev/sdb: 4027 MB, 4027580416 bytes124 heads, 62 sectors/track, 1023 cylinders, total 7866368 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x97bf3019 Device Boot Start End Blocks Id System/dev/sdb1 2048 34815 16384 83 Linux/dev/sdb2 34816 7866367 3915776 83 Linux#可以看出創(chuàng)建了兩個分區(qū)都為linux類型,但是u-boot只能識別第一個分區(qū)為FAT32分區(qū) Command (m for help): t #修改分區(qū)類型Partition number (1-4): 1 #選擇修改哪個分區(qū)Hex code (type L to list codes): L #列出所有類型 0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris 1 FAT12 27 Hidden NTFS Win 82 Linux swap / So c1 DRDOS/sec (FAT- 2 XENIX root 39 Plan 9 83 Linux c4 DRDOS/sec (FAT- 3 XENIX usr 3c PartitionMagic 84 OS/2 hidden C: c6 DRDOS/sec (FAT- 4 FAT16 <32M 40 Venix 80286 85 Linux extended c7 Syrinx 5 Extended 41 PPC PReP Boot 86 NTFS volume set da Non-FS data 6 FAT16 42 SFS 87 NTFS volume set db CP/M / CTOS / . 7 HPFS/NTFS/exFAT 4d QNX4.x 88 Linux plaintext de Dell Utility 8 AIX 4e QNX4.x 2nd part 8e Linux LVM df BootIt 9 AIX bootable 4f QNX4.x 3rd part 93 Amoeba e1 DOS access a OS/2 Boot Manag 50 OnTrack DM 94 Amoeba BBT e3 DOS R/O b W95 FAT32 51 OnTrack DM6 Aux 9f BSD/OS e4 SpeedStor c W95 FAT32 (LBA) 52 CP/M a0 IBM Thinkpad hi eb BeOS fs e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a5 FreeBSD ee GPT f W95 Ext’d (LBA) 54 OnTrackDM6 a6 OpenBSD ef EFI (FAT-12/16/10 OPUS 55 EZ-Drive a7 NeXTSTEP f0 Linux/PA-RISC b11 Hidden FAT12 56 Golden Bow a8 Darwin UFS f1 SpeedStor12 Compaq diagnost 5c Priam Edisk a9 NetBSD f4 SpeedStor14 Hidden FAT16 <3 61 SpeedStor ab Darwin boot f2 DOS secondary16 Hidden FAT16 63 GNU HURD or Sys af HFS / HFS+ fb VMware VMFS17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT1e Hidden W95 FAT1 80 Old MinixHex code (type L to list codes): c #選擇FAT32Changed system type of partition 1 to c (W95 FAT32 (LBA))Command (m for help): p #再一次查看分區(qū) Disk /dev/sdb: 4027 MB, 4027580416 bytes124 heads, 62 sectors/track, 1023 cylinders, total 7866368 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk identifier: 0x97bf3019 Device Boot Start End Blocks Id System/dev/sdb1 2048 34815 16384 c W95 FAT32 (LBA)#已經修改過了了/dev/sdb2 34816 7866367 3915776 83 LinuxCommand (m for help): w #保存分區(qū)表The partition table has been altered! Calling ioctl() to re-read partition table.WARNING: If you have created or modified any DOS 6.xpartitions, please see the fdisk manual page for additionalinformation.Syncing disks.
pillar@monster :~/openwrt/trunk/bin/sunxi$ ls /dev/sdb #查看已經分好的分區(qū)sdb sdb1 sdb2pillar@monster :~/openwrt/trunk/bin/sunxi$ mkf #查看有哪些分區(qū)類型mkfifo mkfontscale mkfs.bfs mkfs.ext2 mkfs.ext4 mkfs.minix mkfs.ntfsmkfontdir mkfs mkfs.cramfs mkfs.ext3 mkfs.ext4dev mkfs.msdos mkfs.vfat pillar@monster :~/openwrt/trunk/bin/sunxi$ sudo mkfs.vfat /dev/sdb1 #第一個分區(qū)格式化為fat分區(qū)[sudo] password for pillar:mkfs.vfat 3.0.12 (29 Oct 2011)pillar@monster :~/openwrt/trunk/bin/sunxi$ sudo mkfs.ext4 /dev/sdb2 #第二個分區(qū)格式化為ext4分區(qū),這里需要幾分鐘mke2fs 1.42 (29-Nov-2011)Filesystem label=OS type: LinuxBlock size=4096 (log=2)Fragment size=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks244800 inodes, 978944 blocks48947 blocks (5.00%) reserved for the super userFirst data block=0Maximum filesystem blocks=100243865630 block groups32768 blocks per group, 32768 fragments per group8160 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736Allocating group tables: doneWriting inode tables: doneCreating journal (16384 blocks): doneWriting superblocks and filesystem accounting information: done
pillar@monster :~/openwrt/trunk/bin/sunxi$ sudo mount /dev/sdb1 /media/1pillar@monster :~/openwrt/trunk/bin/sunxi$ sudo mount /dev/sdb2 /media/2pillar@monster :~/openwrt/trunk/bin/sunxi$ df -hFilesystem Size Used Avail Use% Mounted on/dev/sda1 195G 60G 126G 33% /udev 989M 4.0K 989M 1% /devtmpfs 400M 944K 399M 1% /runnone 5.0M 0 5.0M 0% /run/locknone 998M 76K 998M 1% /run/shm/dev/sdb1 16M 0 16M 0% /media/1/dev/sdb2 3.7G 7.5M 3.5G 1% /media/2
pillar@monster :/media/1$ vim boot.cmd 1 setenv bootargs console=ttyS0,115200 root=/dev/mmcblk0p2 rootwait panic=10 ${extra} 2 fatload mmc 0 0×46000000 uImage 3 fatload mmc 0 0×49000000 sun4i-a10-pcduino.dtb 4 fdt_high ffffffff 5 bootm 0×46000000 – 0×49000000pillar@monster :/media/1$mkimage -C none -A arm -T script -d boot.cmd boot.scr
pillar@monster :/media/1$ cp ~/openwrt/trunk/bin/sunxi/sun4i-a10-pcduino.dtb .pillar@monster :/media/1$ cp ~/openwrt/trunk/bin/sunxi/openwrt-sunxi-uImage uImage pillar@monster :/media/1$ ls #第一分區(qū)文件boot.scr sun4i-a10-pcduino.dtb uImagepillar@monster :/media$ sudo dd if=~/openwrt/trunk/bin/sunxi/openwrt-sunxi-root.ext4 of=/dev/sdb2 bs=1M #拷貝第二分區(qū)文件
好了, 現在整個的從SD啟動的BSP已經最好了.
pillar@monster :/media$ sudo dd if=/dev/sdc of=OpenWrt.img bs=4M
現在把OpenWrt.img拷貝到windows上, 把你新的SD卡插到電腦開始用win32diskimager寫入
vim /etc/config/networkconfig interface ‘net’ option ifname ‘eth0′ option proto ‘dhcp’
當系統(tǒng)的啟動的時候發(fā)現mac地址老是在變,這就會出現一個問題, 有時候能獲取到ip, 有時候獲取不到ip. 這里可以做一個系統(tǒng)服務, 讓系統(tǒng)開機保存mac地址, 然后再開機的時候恢復之前的mac地址.
1) 在/etc/init.d/mac里面編寫如下腳本
#!/bin/sh /etc/rc.commonSTART=18STOP=91start() {if [ -f /mac ]; thendd if=/mac bs=1 count=17 of=/tmp/mac >/dev/null 2>&1mac_addr=`cat /tmp/mac`elsemac_file=/sys/class/net/eth0/addressdd if=$mac_file bs=1 of=/mac count=17 >/dev/null 2>&1mac_addr=`cat /tmp/mac`fiifconfig eth0 downifconfig eth0 hw ether $mac_addr#if failed, save current mac addressif [ $? -ne 0 ]; thenmac_file=/sys/class/net/eth0/addressdd if=$mac_file bs=1 of=/mac count=17 >/dev/null 2>&1fi}
2) 指定運行的模式
/etc/rc.d/rc則根據其參數指定的運行模式(運行級別, 你在inittab文件中可以設置)來執(zhí)行相應目錄下的腳本. 凡是以Kxx開頭的, 都以stop為參數來調用. 凡是以Sxx開頭的, 都以start為參數來調用. 調用的順序按xx 從小到大來執(zhí)行. 例如, 假設缺省的運行模式是3, /etc/rc.d/rc就會按上述方式調用.
由于設定mac地址要在network之前. 所以要創(chuàng)建鏈接:
ln -s /etc/init.d/mac /etc/rc.d/S18mac
openwrt啟動之后輸入:
root@OpenWrt :/# ifconfigeth0 Link encap:Ethernet HWaddr AE:DB:9A:D9:31:DEinet addr:192.168.1.119 Bcast:192.168.1.255 Mask:255.255.255.0inet6 addr: fe80::acdb:9aff:fed9:31de/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:696 errors:0 dropped:0 overruns:0 frame:0TX packets:640 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:86028 (84.0 KiB) TX bytes:377264 (368.4 KiB)Interrupt:17 Base address:0×4000 lo Link encap:Local Loopbackinet addr:127.0.0.1 Mask:255.0.0.0inet6 addr: ::1/128 Scope:HostUP LOOPBACK RUNNING MTU:65536 Metric:1RX packets:16 errors:0 dropped:0 overruns:0 frame:0TX packets:16 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:0RX bytes:1786 (1.7 KiB) TX bytes:1786 (1.7 KiB)wlan0 Link encap:Ethernet HWaddr 00:7A:03:00:29:F4inet6 addr: fe80::27a:3ff:fe00:29f4/64 Scope:LinkUP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1RX packets:0 errors:0 dropped:0 overruns:0 frame:0TX packets:7 errors:0 dropped:0 overruns:0 carrier:0collisions:0 txqueuelen:1000RX bytes:0 (0.0 B) TX bytes:864 (864.0 B)
確保ethX和wlanX都有. openwrt的root密碼是沒有設置, 你需要從serial debug進入系統(tǒng)設置root密碼, 設置方法如下:
passwd root
然后在同一個局域網內你的PC的瀏覽器上輸入: ethX的ip, 這里是192.168.1.119.就會出現下面界面:
輸入你剛才設置的密碼, 進入系統(tǒng)管理界面, 默認是進入狀態(tài)標簽, 這里你可以看到整個系統(tǒng)的運行的狀態(tài).
如果你對當前頁面不太習慣, 而且在使用上語言上也有些困難, 你可以進入system標簽, 在System Properties里面設置language and style如下圖所示. 設置完之后save & apply, 重新刷新一下瀏覽器就可以使用你設置的語言和主題.
下面進入網絡標簽欄設置wifi節(jié)點, 這個部分是openwrt比較復雜的一個部分, 這個部分的設置直接決定著你的openwrt能不能使用.
添加新接口, 選擇靜態(tài)ip, 新接口的名稱, 你需要用英文自定義一個名字, 在包括一下接口里面選擇無線網絡. 設置完之后提交, 進入下一個頁面繼續(xù)設置.
基本設置設置完成之后, 進入防火墻設置, 這里wifi必須選擇為lan口. 設置完成之后保存應用. 這個時候你電腦就可以連接使用openwrt這個路由器了.
點擊修改后進入防火墻設置標簽欄, 分配防火墻區(qū)域為wan, 設置完成之后保存&應用.
make target/linux/{clean,prepare} V=s QUILT=1
cd build_dir/target-*/linux-*/linux-3.*
git initgit add * -fgit commit -am "initial commit"
rtl8188cus
驅動.mkdir drivers/net/wireless/rtl8192cuscp /home/pillar/openwrt/openwrt-pcDuino/RTL8188C_8192C_USB_linux_v4.0.2_9000.20130911/driver/rtl8188C_8192C_usb_linux_v4.0.2_9000.20130911/* drivers/net/wireless/rtl8192cus/ -rfvim drivers/net/wireless/Kconfig284 source “drivers/net/wireless/rtl8192cus/Kconfig”vim drivers/net/wireless/rtl8192cus/Kconfig 1 config RTL8192CU_SW 2 tristate “Realtek 8192C USB WiFi for SW” 3 depends on USB 4 select WIRELESS_EXT 5 select WEXT_PRIVvim drivers/net/wireless/Makefile28 obj-$(CONFIG_RTL8192CU_SW) += rtl8192cus/vim drivers/net/wireless/rtl8192cus/Makefile575 obj-$(CONFIG_RTL8192CU_SW) := $(MODULE_NAME).o 579 export CONFIG_RTL8192CU_SW = m
git branch rtl8192git checkout rtl8192git add * -fgit commit -a -m "add rtl8192cus for pcDuino"git format-patch -M master #會生成0002-add-rtl8192cus-for-pcDuino.patch cp 0001-add-rtl8192cus-for-pcDuino.patch patches/cd ../../../../make target/linux/update package/index V=scp build_dir/target-arm_cortex-a8+vfpv3_uClibc-0.9.33.2_eabi/linux-sunxi/linux-3.12.5/patches/0001-add-rtl8192cus-for-pcDuino.patch target/linux/sunxi/patches-3.12/
rtl8192
分支的代碼了.make target/linux/{clean,prepare} V=s QUILT=1
make kernel_menuconfig Device Drivers —> [*] Network device support —> [*] Wireless LAN —> <*> Realtek 8192C USB WiFi
其他的patch的制作方法請參考: http://wiki.openwrt.org/doc/devel/patches
OpenWrt通過opkg來管理安裝整個系統(tǒng)的軟件. 目前有很多OpenWrt的軟件源, 但是哪些都是針對于MIPS平臺的, pcDuino使用的ARM平臺, 我們必須自己搭建軟件源. 查看了一下MIPS平臺的服務器, 其實很簡單的, 就是一個apache服務器, 而且OpenWrt編譯完成之后, 在openwrt/trunk/bin/sunxi/packages下面已經生成了軟件源. 我們只需要將他們聯系起來就行了, 這里是在我的PC的虛擬機上搭建的.
# sudo apt-get install apache2
修改https的根目錄
pillar@monster :~/openwrt$ vim /etc/apache2/sites-available/default4 DocumentRoot /home/pillar/openwrt/trunk/bin/sunxi/
重啟服務器使修改過的配置生效
pillar@monster :~/openwrt$ sudo /etc/init.d/apache2 restart
修改pcDuino上OpenWrt的源配置
root@OpenWrt :/# vim /etc/opkg.confsrc/gz barrier_breaker http://192.168.1.125/packagesdest root /dest ram /tmplists_dir ext /var/opkg-listsoption overlay_root /overlay
上面的IP為我們電腦虛擬機的IP, 下面更新一下軟件源.
# opkg update
OpenWrt上面應用程序開發(fā)有兩種方式, 一種是利用OpenWrt SDK, 一種是利用OpenWrt源碼. 這里主要介紹利用OpenWrt源碼, 進行開發(fā)應用程序, 制作成ipk軟件可以安裝.
#cd /home/pillar/openwrt/trunk/package#mkdir example1
#cd example1#touch Makefile#mkdir src
該Makefile具體內容如下:
#User mode tool exampleinclude $(TOPDIR)/rules.mkinclude $(INCLUDE_DIR)/kernel.mkPKG_NAME:=example1PKG_RELEASE:=1PKG_BUILD_DIR := $(KERNEL_BUILD_DIR)/$(PKG_NAME)include $(INCLUDE_DIR)/package.mkdefine Package/example1 SECTION:=utils CATEGORY:=Base system TITLE:=Build for example1 commandsendefdefine Package/example1/description This package contains an utility useful to use example1 commands.endefdefine Build/Prepare mkdir -p $(PKG_BUILD_DIR) $(CP) ./src/* $(PKG_BUILD_DIR)/endef target=$(firstword $(subst -, ,$(BOARD)))MAKE_FLAGS += TARGET="$(target)"TARGET_CFLAGS += -Dtarget_$(target)=1 -Walldefine Build/example1/compile $(MAKE) -C “$(LINUX_DIR)” \ CROSS_COMPILE=”$(TARGET_CROSS)” \ ARCH=”$(LINUX_KARCH)” \ SUBDIRS=”$(PKG_BUILD_DIR)” \ EXTRA_CFLAGS=”$(BUILDFLAGS)”endef define Package/example1/install $(INSTALL_DIR) $(1)/sbin $(INSTALL_BIN) $(PKG_BUILD_DIR)/example1 $(1)/sbin/endef $(eval $(call BuildPackage,example1))
cd src touch example1.c Makefile
example1.c 具體內容如下:
#includeint main(void){ printf(“Hello, world\n”); return 0;}
Makefile文件具體內容如下:
.NOTPARALLEL: #OCTEON_ROOT=$(PWD)/src/ CC=~/openwrt/main/staging_dir/toolchain-mips64_gcc-4.4.1_eglibc-2.10.1/usr/bin/mips64-openwrt-linux-gnu-gccCFLAGS=-mips64r2 -mabi=64 -march=octeon -mtune=octeonLFLAGS=.PHONY: allall: example1example1:example1.c ${CC} ${CFLAGS} ${LFLAGS} -W -g -Wall -Wno-unused-parameter -DUSE_RUNTIME_MODEL_CHECKS=1 \ -o $@ example1.c
make menuconfig Base system —> example1
選項設置為M, 保存退出.
然后編譯該模塊:
make package/example1/compile
make package/ example1/installmake package/index
OpenWrt開發(fā)內核驅動有多種方式, 前面講到的制作內核補丁也是一種開發(fā)方法. 這里介紹直接在OpenWrt系統(tǒng)上開發(fā)內核驅動, 把內核驅動做成ipk軟件包的形式.
cd openwrt/trunk/packagemkdir example
cd example mkdir srcvim Makefile
# Kernel module exampleinclude $(TOPDIR)/rules.mkinclude $(INCLUDE_DIR)/kernel.mkPKG_NAME:=examplePKG_RELEASE:=1include $(INCLUDE_DIR)/package.mkdefine KernelPackage/example SUBMENU:=Other modules DEPENDS:=@TARGET_octeon TITLE:=Support Module for example AUTOLOAD:=$(call AutoLoad,81,example) FILES:=$(PKG_BUILD_DIR)/example/example.$(LINUX_KMOD_SUFFIX)endefdefine Build/Prepare mkdir -p $(PKG_BUILD_DIR) $(CP) -R ./src/* $(PKG_BUILD_DIR)/endef define Build/Compile $(MAKE) -C “$(LINUX_DIR)” \ CROSS_COMPILE=”$(TARGET_CROSS)” \ ARCH=”$(LINUX_KARCH)” \ SUBDIRS=”$(PKG_BUILD_DIR)/example” \ EXTRA_CFLAGS=”-g $(BUILDFLAGS)” \ modulesendef $(eval $(call KernelPackage,example))
cd srcmkdir examplecd examplevim example.c
#include#include #include /* hello_init —- 初始化函數, 當模塊裝載時被調用, 如果成功裝載返回0, 否則返回非0值 */ static int __init hello_init(void){ printk("I bear a charmed life.\n"); return 0;} / * hello_exit —- 退出函數, 當模塊卸載時被調用 */static void __exit hello_exit(void) { printk("Out, out, brief candle\n");} module_init(hello_init);module_exit(hello_exit);MODULE_LICENSE("GPL");MODULE_AUTHOR("Pillar_zuo");
vim Kconfigconfig EXAMPLE tristate "Just a example" default n help This is a example, for debugging kernel model. If unsure, say N.vim Makefileobj-m := example.o
make menuconfig Kernel modules —> Other modules —> kmod-example
選項設置為M, 保存退出
然后編譯該模塊:
make package/example/compilemake package/index
OpenWrt為了避免每次都重新編譯系統(tǒng), 引入了SDK機制. 我們在發(fā)布系統(tǒng)的時候也需要發(fā)布SDK, 具體的使用方法請下面例子.
pillar@monster :~/openwrt/trunk/bin/sunxi$ tar xvf OpenWrt-SDK-sunxi-for-linux-x86_64-gcc-4.6-linaro_uClibc-0.9.33.2.tar.bz2cd OpenWrt-SDK-sunxi-for-linux-x86_64-gcc-4.6-linaro_uClibc-0.9.33.2
cd packagemkdir helloworldvim 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 directoryPKG_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 belowdefine Package/helloworld SECTION:=utils CATEGORY:=Utilities TITLE:=Helloworld — prints a snarky messageendef # Uncomment portion below for Kamikaze and delete DESCRIPTION variable abovedefine 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))mkdir srccd src
vim helloworld.c#includeint main(void){ printf(“Hell! O’ world, why won’t my code compile?\n\n”); return 0;}vim Makefile# build helloworld executable when user executes "make"helloworld: helloworld.o $(CC) $(LDFLAGS) helloworld.o -o helloworldhelloworld.o: helloworld.c $(CC) $(CFLAGS) -c helloworld.c # remove object files and executable when user executes "make clean"clean: rm *.o helloworld
cd ../../make V=spillar@monster :~/openwrt/trunk/bin/sunxi/OpenWrt-SDK-sunxi-for-linux-x86_64-gcc-4.6-linaro_uClibc-0.9.33.2$ ls bin/sunxi/packages/helloworld_1_sunxi.ipk Packages Packages.gz
OpenWrt-SDK-sunxi-for-linux-x86_64-gcc-4.6-linaro_uClibc-0.9.33.2/bin/sunxi/packages
然后你可以在OpenWrt系統(tǒng)里面下載安裝.