免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
移植OpenWrt到pcDuino

[TOC]

OpenWrt

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

下載編譯OpenWrt

  1. 安裝依賴包(deb系列)
sudo aptitude install -y libncurses5-dev zlib1g-dev gawk flex patch git-core g++ subversion
  1. OpenWrt的源代碼管理默認用的是SVN, 當然你還可以用Git, 本教程中使用最新的trunk版本, 用SVN工具下載源碼
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
  1. 擴展軟件包package feeds, feeds即為包含到你的OpenWrt環(huán)境中的額外軟件包的軟件列表索引(類似linux發(fā)行版中的軟件源, 不過此處為軟件包的源碼). 目前常用的feeds有:
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.

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

Trunk中默認的feeds下載有packages、xwrt、luci、routing、telephony。如果你需要其他的軟件包,你只需要打開源碼根目錄下面的feeds.conf.default文去掉你需要的軟件包前面的#號,本教程中使用默認的軟件,確定了軟件源之后,更新源:

./scripts/feeds update -a

安裝下載好的包:

./scripts/feeds install -a
  1. OpenWrt源碼目錄結構, 執(zhí)行上面命令之后你就可以得到全部的Openwrt源碼.

目錄結構:

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

由于OpenWrt整個系統(tǒng)非常龐大, 編譯很慢. "-j 8" 表示用8線程進行編譯, "V=s"編譯的時候顯示編譯信息. 如果你的電腦是4核建議你用8線程進行編譯, 雙核建議你使用4線程. 這里測試8線程編譯需要一個小時才能編譯完成.

構建pcDuino BSP

由于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ū).

  1. 先格式化TF卡前面的1M空間, 這里是將TF卡通過讀卡器插入到PC的虛擬機. 可以看出TF卡的設備是sdb.
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
  1. 寫入u-boot-spl.bin和u-boot.bin. OpenWrt的生成的二進制文件都在openwrt/trunk/bin/sunxi目錄下, 這里OpenWrt做了一些工作將u-boot-spl.bin和u-boot.bin合在了一起, 只需要把openwrt-sunxi-pcDuino-sunxi-with-spl.bin寫到
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)境變量.

  1. 建立分區(qū)表. 重新把SD卡插回到電腦的虛擬機里面, 使用fdisk創(chuàng)建分區(qū)表. 具體的分區(qū)見下操作, 步驟的說明請看#后面的注釋.
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.
  1. 格式化分區(qū). 剛才創(chuàng)建了分區(qū), 但是沒有格式化, 我們還是不能使用.
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
  1. 掛載分區(qū)
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
  1. 制作u-boot環(huán)境變量文件. 剛剛創(chuàng)建了分區(qū), 這里只需要將環(huán)境變量文件, 還有uImage拷貝到第一分區(qū)讓u-boot讀取, 就可以引導系統(tǒng)了. 下面開始制作u-boot環(huán)境變量文件.
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
  1. 將系統(tǒng)文件拷貝到第一和第二分區(qū).
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已經最好了.

  1. 發(fā)布并燒寫系統(tǒng). 現在把系統(tǒng)做好了, 你可以發(fā)布你制作的系統(tǒng), 然后別人可以通過win32diskimager來把你的系統(tǒng)寫入到他的SD卡, 他就可以和你一起玩OpenWrt了.
pillar@monster :/media$ sudo dd if=/dev/sdc of=OpenWrt.img  bs=4M

現在把OpenWrt.img拷貝到windows上, 把你新的SD卡插到電腦開始用win32diskimager寫入

配置OpenWrt系統(tǒng)

  1. 讓系統(tǒng)上網
vim /etc/config/networkconfig interface ‘net’        option ifname ‘eth0′        option proto ‘dhcp’
  1. 設置固定的mac地址

當系統(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
  1. 開啟wifi

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, 設置完成之后保存&應用.

制作內核補丁

  1. 清空恢復上一個全新的內核
make target/linux/{clean,prepare} V=s QUILT=1
  1. 到內核源碼目錄
cd build_dir/target-*/linux-*/linux-3.*
  1. 建立git代碼倉庫
git initgit add * -fgit commit -am "initial commit"
  1. 修改你的代碼, 這里我給我的代碼添加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
  1. 建立git分支, 并制作補丁
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/
  1. 檢測是否生效, 執(zhí)行完之后就是rtl8192分支的代碼了.
make target/linux/{clean,prepare} V=s QUILT=1
  1. 配置內核應用選項
make kernel_menuconfig         Device Drivers  —>                    [*] Network device support  —>                                      [*]   Wireless LAN  —>                                                           <*>   Realtek 8192C USB WiFi

其他的patch的制作方法請參考: http://wiki.openwrt.org/doc/devel/patches

建立App服務器

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

應用程序開發(fā)

OpenWrt上面應用程序開發(fā)有兩種方式, 一種是利用OpenWrt SDK, 一種是利用OpenWrt源碼. 這里主要介紹利用OpenWrt源碼, 進行開發(fā)應用程序, 制作成ipk軟件可以安裝.

  1. 進入package目錄, 創(chuàng)建軟件目錄
#cd   /home/pillar/openwrt/trunk/package#mkdir example1
  1. 進入example1目錄, 創(chuàng)建Makefile文件和代碼路徑
#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))
  1. 進入src目錄, 創(chuàng)建相關源文件
cd src touch example1.c Makefile

example1.c 具體內容如下:

#include int 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
  1. 回到主路徑/home/pillar/openwrt/trunk/, 編譯選項配置保存并編譯.
make menuconfig  Base system —>   example1

選項設置為M, 保存退出.
然后編譯該模塊:

make package/example1/compile
  1. 更新package
make package/ example1/installmake package/index

內核驅動開發(fā)

OpenWrt開發(fā)內核驅動有多種方式, 前面講到的制作內核補丁也是一種開發(fā)方法. 這里介紹直接在OpenWrt系統(tǒng)上開發(fā)內核驅動, 把內核驅動做成ipk軟件包的形式.

  1. 建立工作目錄
cd  openwrt/trunk/packagemkdir example
  1. 進入example目錄, 創(chuàng)建Makefile文件和代碼路徑
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))
  1. 進入src目錄, 創(chuàng)建代碼路徑和相關源文件
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
  1. 回到OpenWrt源碼根目錄下
make menuconfig  Kernel modules —>    Other modules —>      kmod-example

選項設置為M, 保存退出
然后編譯該模塊:

make package/example/compilemake package/index
  1. 在OpenWrt系統(tǒng)里面就可以用opkg下載使用了.

使用OpenWrt SDK

OpenWrt為了避免每次都重新編譯系統(tǒng), 引入了SDK機制. 我們在發(fā)布系統(tǒng)的時候也需要發(fā)布SDK, 具體的使用方法請下面例子.

  1. 解壓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
  1. 建立軟件工作目錄
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
  1. 編寫自己的軟件, 這里以helloworld為例.
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
  1. 編譯軟件, 回到SDK根目錄下.
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
  1. 修改軟件源根目錄. 如果你不想每次都拷貝, 你可以把軟件源的根目錄下設置在
OpenWrt-SDK-sunxi-for-linux-x86_64-gcc-4.6-linaro_uClibc-0.9.33.2/bin/sunxi/packages

然后你可以在OpenWrt系統(tǒng)里面下載安裝.

Refs

本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現有害或侵權內容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
移植Qt5.3.2到pcDuino 3A/3B/NANO | LinkSprite學習中心
openWrt從源碼下載到編譯(開發(fā)環(huán)境搭建)
OpenWrt:Ubuntu 12.04搭建OpenWrt編譯環(huán)境
Bootloader加載過程分析
OPENWRT 支持git
構建debain系統(tǒng)
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯系客服!

聯系客服