乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      移植OpenWrt到pcDuino

       xiaofenglib 2014-03-19

      [TOC]

      OpenWrt

      OpenWrt是一個(gè)高度模塊化, 高度自動(dòng)化的嵌入式Linux系統(tǒng), 擁有強(qiáng)大的網(wǎng)絡(luò)組件, 常常被用于工控設(shè)備, 電話, 小型機(jī)器人, 智能家居, 路由器以及VOIP設(shè)備中. OpenWrt支持各種處理器架構(gòu),無(wú)論是對(duì)ARM,X86,PowerPC或者M(jìn)IPS都有很好的支持. 其多達(dá)3000多種軟件包, 囊括從工具鏈(toolchain), 到內(nèi)核(linux kernel), 到軟件包(packages), 再到根文件系統(tǒng)(rootfs)整個(gè)體系, 使得用戶只需簡(jiǎn)單的一個(gè)make命令即可方便快速地定制一個(gè)具有特定功能的嵌入式系統(tǒng)來(lái)制作固件. 其模塊化設(shè)計(jì)也可以方便的移植各類功能到OpenWrt下, 加快開(kāi)發(fā)速度.

      對(duì)于開(kāi)發(fā)人員, OpenWrt是使用框架來(lái)構(gòu)建應(yīng)用程序, 而無(wú)需建立一個(gè)完整的固件來(lái)支持. 對(duì)于用戶來(lái)說(shuō), 這意味著其擁有完全定制的能力, 可以用前所未有的方式使用該設(shè)備.

      openwrt-logo

      2014年12月19日小米路由器公測(cè)版正式發(fā)售, 也意味著OpenWrt進(jìn)入國(guó)內(nèi)主流科技企業(yè)的眼球. 然而OpenWrt到底是一款什么樣的操作系統(tǒng)呢? 對(duì)于創(chuàng)客來(lái)講, 怎么才能融入創(chuàng)客的設(shè)計(jì), 下面就從零介紹如果在pcDuino上開(kāi)發(fā)OpenWrt.

      OpenWrt項(xiàng)目始于2004年1月. 最早的OpenWrt版本基于Linksys為遵守GPL而放出的, 為WRT54G所編寫的代碼, 以及uclibc項(xiàng)目的buildroot. 這個(gè)版本以O(shè)penWrt "stable release"之名為人所知, 使用廣泛. 仍有許多OpenWrt應(yīng)用程序是基于這一版的, 例如Freifunk-Firmware和Sip@Home.

      2005年初, 一些新的開(kāi)發(fā)者進(jìn)入了團(tuán)隊(duì). 在封閉開(kāi)發(fā)了數(shù)月之后, 團(tuán)隊(duì)決定發(fā)布OpenWrt的第一個(gè)experimental版本. 這個(gè)實(shí)驗(yàn)版本使用的build系統(tǒng)是基于buildroot2大改而成的, 而buildroot2來(lái)自于uclibc項(xiàng)目. OpenWrt使用官方版GNU/Linux內(nèi)核代碼, 只是額外添加了片上系統(tǒng)(SoC)的補(bǔ)丁和網(wǎng)絡(luò)接口的驅(qū)動(dòng). 開(kāi)發(fā)團(tuán)隊(duì)嘗試重新實(shí)現(xiàn)GPL tarball中不同開(kāi)發(fā)商的絕大多數(shù)專有代碼. 其中有: 將新固件鏡像文件直接寫入閃存的自由工具(mtd), 配置無(wú)線局域網(wǎng)(wlcompat/wificonf), 通過(guò)proc文件系統(tǒng)對(duì)支持VLAN的switch(交換機(jī))進(jìn)行編程. 最初發(fā)布的OpenWrt的代號(hào)是"White Russian", 來(lái)自于著名雞尾酒的名稱. 在OpenWrt發(fā)布0.9版的時(shí)候, White Russian的生命周期結(jié)束.

      下一個(gè)版本的開(kāi)發(fā)正在我們的SVN中進(jìn)行. 下面一張圖將很清晰的反映OpenWrt的版本史. 從圖上可以看出最新的穩(wěn)定版本代號(hào)為Attitude Adjustment, 早期的穩(wěn)定版本為Backfire 和 Kamikaze, 開(kāi)發(fā)版本一直都是trunk. 各個(gè)版本的官方下載地址為 https://dev./wiki/GetSource

      code_overview

      下載編譯OpenWrt

      1. 安裝依賴包(deb系列)
      sudo aptitude install -y libncurses5-dev zlib1g-dev gawk flex patch git-core g++ subversion
      
      1. OpenWrt的源代碼管理默認(rèn)用的是SVN, 當(dāng)然你還可以用Git, 本教程中使用最新的trunk版本, 用SVN工具下載源碼
      svn co svn://svn./openwrt/trunk/ openwrt-pcduino
      

      還可以用Git下載

      git clone git://git./openwrt.git
      git clone git://git./packages.git
      
      1. 擴(kuò)展軟件包package feeds, feeds即為包含到你的OpenWrt環(huán)境中的額外軟件包的軟件列表索引(類似linux發(fā)行版中的軟件源, 不過(guò)此處為軟件包的源碼). 目前常用的feeds有:
      src-git packages git://git./packages.git
      src-svn xwrt http://x-wrt./svn/trunk/package
      src-git luci git://nbd.name/luci.git
      src-git routing git://github.com/openwrt-routing/packages.git
      src-git telephony http://feeds.openwrt./openwrt/telephony.git
      src-svn phone svn://svn./openwrt/feeds/phone
      src-svn efl svn://svn./openwrt/feeds/efl
      src-svn xorg svn://svn./openwrt/feeds/xorg
      src-svn desktop svn://svn./openwrt/feeds/desktop
      src-svn xfce svn://svn./openwrt/feeds/xfce
      src-svn lxde svn://svn./openwrt/feeds/lxde
      src-link custom /usr/src/openwrt/custom-feed
      

      一般情況, 你至少需要含packages feeds, 其他可根據(jù)需求下載, 安裝feeds.

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

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

      ./scripts/feeds update -a
      

      安裝下載好的包:

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

      目錄結(jié)構(gòu):

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

      openwrt-buildroot

      在官方最新的trunk分支中已經(jīng)支持pcDuino這個(gè)target了.

      具體配置如下:
      A. 配置目標(biāo)系統(tǒng)(Target System)

      Target System (Allwinner A1x/A20/A3x) —>

      B. 配置目標(biāo)硬件(Target Profile)

      Target Profile (pcDuino) —>

      C. 配置編譯出來(lái)的image, 配置rootfs文件系統(tǒng)的格式這里選擇ext4, rootfs文件系統(tǒng)的大小這里設(shè)置(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. 選擇編譯交叉編譯器, 還有開(kāi)發(fā)SDK.

      [*] Build the OpenWrt Image Builder
      [*] Build the OpenWrt SDK

      E. 配置無(wú)線網(wǎng)卡, V2/V3都是用的rtl8188cus無(wú)線網(wǎng)卡

      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 HTTPS
      
      4. 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.org
      
      5. Translations  —>
      <*> luci-i18n-chinese………………….. Chinese (by Chinese Translators)
      -*- luci-i18n-english………………………………………… English
      1. 編譯OpenWrt系統(tǒng)
      make –j 8 V=s
      

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

      構(gòu)建pcDuino BSP

      由于OpenWrt的u-boot用的是u-boot-2013的版本, 目前只支持SD卡啟動(dòng), 而且內(nèi)核用的是3.12.5版本. 另外我們的3.4.29的內(nèi)核用的是全志fex, 而且3.12.5用的是linux官方的kernel使用的是dts設(shè)備樹(shù).這樣的話我們就不能用之前的BSP方案, 我們要自己做一個(gè)從SD卡啟動(dòng)的系統(tǒng).

      pcDuino從SD卡啟動(dòng)順序是A10—>u-boot–>uImage–>OpenWrt.

      根據(jù)全志官網(wǎng)的說(shuō)明, 這些軟件都必須放在SD卡固定的地址. 那么首先要對(duì)A10進(jìn)行分區(qū). 根據(jù)全志芯片的說(shuō)明, 需要對(duì)SD卡進(jìn)行下表固定分區(qū).

      a10-flash

      1. 先格式化TF卡前面的1M空間, 這里是將TF卡通過(guò)讀卡器插入到PC的虛擬機(jī). 可以看出TF卡的設(shè)備是sdb.
      Filesystem      Size  Used Avail Use% Mounted on
      /dev/sda1       195G   60G  126G  33% /
      udev            989M  4.0K  989M   1% /dev
      tmpfs           400M  940K  399M   1% /run
      none            5.0M     0  5.0M   0% /run/lock
      none            998M   76K  998M   1% /run/shm
      /dev/sdb1       3.8G   12K  3.8G   1% /media/0005-559B
      
      sudo dd if=/dev/zero of=/dev/sdb bs=1M count=1
      1. 寫入u-boot-spl.bin和u-boot.bin. OpenWrt的生成的二進(jìn)制文件都在openwrt/trunk/bin/sunxi目錄下, 這里OpenWrt做了一些工作將u-boot-spl.bin和u-boot.bin合在了一起, 只需要把openwrt-sunxi-pcDuino-sunxi-with-spl.bin寫到
      cd  uboot-sunxi-pcDuino
      pillar@monster:~/openwrt/trunk/bin/sunxi/uboot-sunxi-pcDuino$ ls 
      openwrt-sunxi-pcDuino-sunxi-spl.bin       openwrt-sunxi-pcDuino-u-boot.bin
      openwrt-sunxi-pcDuino-sunxi-with-spl.bin
      sudo dd if=openwrt-sunxi-pcDuino-sunxi-with-spl.bin of=/dev/sdb bs=1024 seek=8

      這時(shí)候把SD卡插到板子上, 重新上電就會(huì)看到下面打印信息.

      U-Boot 2013.10-rc2 (Jan 15 2014 – 17:48:38) Allwinner Technology
      CPU:   Allwinner A10 (SUN4I)
      Board: pcDuino
      I2C:   ready
      DRAM:  1 GiB
      MMC:   SUNXI SD/MMC: 0
      
      *** Warning – bad CRC, using default environment
      In:    serial
      Out:   serial
      Err:   serial
      Net:   emac
      Hit any key to stop autoboot:  0
      
      sun4i#

      從上面可以看到u-boot已經(jīng)完全啟動(dòng)了, 上面的時(shí)間是編譯的時(shí)間. 上面的信息還可以看到我們的環(huán)境變量沒(méi)有設(shè)置, 它使用的是默認(rèn)的環(huán)境變量. 前面介紹, 系統(tǒng)建立在分區(qū)表不同的地方, 但是我們現(xiàn)在SD卡還沒(méi)有分區(qū)表, 我們需要先建立分區(qū)表再做環(huán)境變量.

      1. 建立分區(qū)表. 重新把SD卡插回到電腦的虛擬機(jī)里面, 使用fdisk創(chuàng)建分區(qū)表. 具體的分區(qū)見(jiàn)下操作, 步驟的說(shuō)明請(qǐng)看#后面的注釋.
      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 disklabel
      Building 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 bytes
      124 heads, 62 sectors/track, 1023 cylinders, total 7866368 sectors
      Units = sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
      Disk identifier: 0x97bf3019
      
      Device Boot      Start         End      Blocks   Id  System
      
      #沒(méi)有分區(qū) 
      
      Command (m for help): n      #創(chuàng)建分區(qū) 
      
      Partition type: 
         p   primary (0 primary, 0 extended, 4 free)    #主分區(qū) 
         e   extended                                   #擴(kuò)展分區(qū) 
      
      Select (default p):                            #選擇默認(rèn)主分區(qū)
      Using default response p
      Partition number (1-4, default 1):                #分區(qū)號(hào)為1
      Using default value 1
      First sector (2048-7866367, default 2048):         #選擇默認(rèn)值
      Using default value 2048
      Last sector, +sectors or +size{K,M,G} (2048-7866367, default 7866367): 34815 #這個(gè)根據(jù)全志的手冊(cè)來(lái)第一個(gè)分區(qū)必須這么大
      
      Command (m for help): p                       #查看分區(qū) 
      
      Disk /dev/sdb: 4027 MB, 4027580416 bytes
      124 heads, 62 sectors/track, 1023 cylinders, total 7866368 sectors
      Units = sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
      Disk identifier: 0x97bf3019
      
         Device Boot      Start         End      Blocks   Id  System 
      /dev/sdb1            2048       34815       16384   83  Linux  #創(chuàng)建的第一個(gè)分區(qū)
      
      Command (m for help): n                    #再創(chuàng)建一個(gè)分區(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):              #第二個(gè)主分區(qū)
      Using default value 2
      First sector (34816-7866367, default 34816):      #默認(rèn)大小從34816開(kāi)始
      Using default value 34816
      Last sector, +sectors or +size{K,M,G} (34816-7866367, default 7866367): #默認(rèn)全部分到第二分區(qū) 
      
      Using default value 7866367 
      
      Command (m for help): p                       #再一次查看分區(qū) 
      
      Disk /dev/sdb: 4027 MB, 4027580416 bytes
      124 heads, 62 sectors/track, 1023 cylinders, total 7866368 sectors
      Units = sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
      Disk 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)建了兩個(gè)分區(qū)都為linux類型,但是u-boot只能識(shí)別第一個(gè)分區(qū)為FAT32分區(qū) 
      
      Command (m for help): t            #修改分區(qū)類型
      Partition number (1-4): 1            #選擇修改哪個(gè)分區(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 b
      11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor
      12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor
      14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary
      16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS
      17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE
      18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
      1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep
      1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT
      1e  Hidden W95 FAT1 80  Old Minix
      
      Hex code (type L to list codes): c             #選擇FAT32
      Changed system type of partition 1 to c (W95 FAT32 (LBA))
      
      Command (m for help): p                  #再一次查看分區(qū) 
      
      Disk /dev/sdb: 4027 MB, 4027580416 bytes
      124 heads, 62 sectors/track, 1023 cylinders, total 7866368 sectors
      Units = sectors of 1 * 512 = 512 bytes
      Sector size (logical/physical): 512 bytes / 512 bytes
      I/O size (minimum/optimal): 512 bytes / 512 bytes
      Disk identifier: 0x97bf3019
      
         Device Boot      Start         End      Blocks   Id  System
      /dev/sdb1        2048       34815     16384    c  W95 FAT32 (LBA)#已經(jīng)修改過(guò)了了
      /dev/sdb2           34816     7866367     3915776   83  Linux
      
      Command (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.x
      partitions, please see the fdisk manual page for additional
      information.
      Syncing disks.
      
      1. 格式化分區(qū). 剛才創(chuàng)建了分區(qū), 但是沒(méi)有格式化, 我們還是不能使用.
      pillar@monster :~/openwrt/trunk/bin/sunxi$ ls /dev/sdb  #查看已經(jīng)分好的分區(qū)
      sdb   sdb1  sdb2
      pillar@monster :~/openwrt/trunk/bin/sunxi$ mkf        #查看有哪些分區(qū)類型
      mkfifo        mkfontscale   mkfs.bfs      mkfs.ext2     mkfs.ext4     mkfs.minix    mkfs.ntfs
      mkfontdir     mkfs          mkfs.cramfs   mkfs.ext3     mkfs.ext4dev  mkfs.msdos    mkfs.vfat 
      
      pillar@monster :~/openwrt/trunk/bin/sunxi$ sudo mkfs.vfat /dev/sdb1 #第一個(gè)分區(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 #第二個(gè)分區(qū)格式化為ext4分區(qū),這里需要幾分鐘
      
      mke2fs 1.42 (29-Nov-2011)
      Filesystem label=
      OS type: Linux
      Block size=4096 (log=2)
      Fragment size=4096 (log=2)
      Stride=0 blocks, Stripe width=0 blocks
      244800 inodes, 978944 blocks
      48947 blocks (5.00%) reserved for the super user
      First data block=0
      Maximum filesystem blocks=1002438656
      30 block groups
      32768 blocks per group, 32768 fragments per group
      8160 inodes per group
      Superblock backups stored on blocks:
               32768, 98304, 163840, 229376, 294912, 819200, 884736
      
      Allocating group tables: done
      Writing inode tables: done
      Creating journal (16384 blocks): done
      Writing superblocks and filesystem accounting information: done
      1. 掛載分區(qū)
      pillar@monster :~/openwrt/trunk/bin/sunxi$ sudo mount /dev/sdb1 /media/1
      pillar@monster :~/openwrt/trunk/bin/sunxi$ sudo mount /dev/sdb2 /media/2
      pillar@monster :~/openwrt/trunk/bin/sunxi$ df -h
      Filesystem      Size  Used Avail Use% Mounted on
      /dev/sda1       195G   60G  126G  33% /
      udev            989M  4.0K  989M   1% /dev
      tmpfs           400M  944K  399M   1% /run
      none            5.0M     0  5.0M   0% /run/lock
      none            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讀取, 就可以引導(dǎo)系統(tǒng)了. 下面開(kāi)始制作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×49000000
      pillar@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    uImage
      pillar@monster :/media$ sudo dd if=~/openwrt/trunk/bin/sunxi/openwrt-sunxi-root.ext4 of=/dev/sdb2 bs=1M                   #拷貝第二分區(qū)文件

      好了, 現(xiàn)在整個(gè)的從SD啟動(dòng)的BSP已經(jīng)最好了.

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

      現(xiàn)在把OpenWrt.img拷貝到windows上, 把你新的SD卡插到電腦開(kāi)始用win32diskimager寫入

      win32-disk-imager

      配置OpenWrt系統(tǒng)

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

      當(dāng)系統(tǒng)的啟動(dòng)的時(shí)候發(fā)現(xiàn)mac地址老是在變,這就會(huì)出現(xiàn)一個(gè)問(wèn)題, 有時(shí)候能獲取到ip, 有時(shí)候獲取不到ip. 這里可以做一個(gè)系統(tǒng)服務(wù), 讓系統(tǒng)開(kāi)機(jī)保存mac地址, 然后再開(kāi)機(jī)的時(shí)候恢復(fù)之前的mac地址.

      1) 在/etc/init.d/mac里面編寫如下腳本

      #!/bin/sh /etc/rc.common
      START=18
      STOP=91
      start() {
      if [ -f /mac ]; then
      dd if=/mac bs=1 count=17 of=/tmp/mac >/dev/null 2>&1
      mac_addr=`cat /tmp/mac`
      else
      mac_file=/sys/class/net/eth0/address
      dd if=$mac_file bs=1 of=/mac count=17 >/dev/null 2>&1
      mac_addr=`cat /tmp/mac`
      fi
      ifconfig eth0 down
      ifconfig eth0 hw ether $mac_addr
      #if failed, save current mac address
      if [ $? -ne 0 ]; then
      mac_file=/sys/class/net/eth0/address
      dd if=$mac_file bs=1 of=/mac count=17 >/dev/null 2>&1
      fi
      }

      2) 指定運(yùn)行的模式

      /etc/rc.d/rc則根據(jù)其參數(shù)指定的運(yùn)行模式(運(yùn)行級(jí)別, 你在inittab文件中可以設(shè)置)來(lái)執(zhí)行相應(yīng)目錄下的腳本. 凡是以Kxx開(kāi)頭的, 都以stop為參數(shù)來(lái)調(diào)用. 凡是以Sxx開(kāi)頭的, 都以start為參數(shù)來(lái)調(diào)用. 調(diào)用的順序按xx 從小到大來(lái)執(zhí)行. 例如, 假設(shè)缺省的運(yùn)行模式是3, /etc/rc.d/rc就會(huì)按上述方式調(diào)用.
      由于設(shè)定mac地址要在network之前. 所以要?jiǎng)?chuàng)建鏈接:

      ln  -s   /etc/init.d/mac   /etc/rc.d/S18mac
      1. 開(kāi)啟wifi

      openwrt啟動(dòng)之后輸入:

      root@OpenWrt :/# ifconfig
      eth0      Link encap:Ethernet  HWaddr AE:DB:9A:D9:31:DE
      inet addr:192.168.1.119  Bcast:192.168.1.255  Mask:255.255.255.0
      inet6 addr: fe80::acdb:9aff:fed9:31de/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:696 errors:0 dropped:0 overruns:0 frame:0
      TX packets:640 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:86028 (84.0 KiB)  TX bytes:377264 (368.4 KiB)
      Interrupt:17 Base address:0×4000 
      
      lo        Link encap:Local Loopback
      inet addr:127.0.0.1  Mask:255.0.0.0
      inet6 addr: ::1/128 Scope:Host
      UP LOOPBACK RUNNING  MTU:65536  Metric:1
      RX packets:16 errors:0 dropped:0 overruns:0 frame:0
      TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:0
      RX bytes:1786 (1.7 KiB)  TX bytes:1786 (1.7 KiB)
      
      wlan0     Link encap:Ethernet  HWaddr 00:7A:03:00:29:F4
      inet6 addr: fe80::27a:3ff:fe00:29f4/64 Scope:Link
      UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
      RX packets:0 errors:0 dropped:0 overruns:0 frame:0
      TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:1000
      RX bytes:0 (0.0 B)  TX bytes:864 (864.0 B)

      確保ethX和wlanX都有. openwrt的root密碼是沒(méi)有設(shè)置, 你需要從serial debug進(jìn)入系統(tǒng)設(shè)置root密碼, 設(shè)置方法如下:

      passwd  root

      然后在同一個(gè)局域網(wǎng)內(nèi)你的PC的瀏覽器上輸入: ethX的ip, 這里是192.168.1.119.就會(huì)出現(xiàn)下面界面:

      luci-login

      輸入你剛才設(shè)置的密碼, 進(jìn)入系統(tǒng)管理界面, 默認(rèn)是進(jìn)入狀態(tài)標(biāo)簽, 這里你可以看到整個(gè)系統(tǒng)的運(yùn)行的狀態(tài).

      system-status

      如果你對(duì)當(dāng)前頁(yè)面不太習(xí)慣, 而且在使用上語(yǔ)言上也有些困難, 你可以進(jìn)入system標(biāo)簽, 在System Properties里面設(shè)置language and style如下圖所示. 設(shè)置完之后save & apply, 重新刷新一下瀏覽器就可以使用你設(shè)置的語(yǔ)言和主題.

      luci-theme

      下面進(jìn)入網(wǎng)絡(luò)標(biāo)簽欄設(shè)置wifi節(jié)點(diǎn), 這個(gè)部分是openwrt比較復(fù)雜的一個(gè)部分, 這個(gè)部分的設(shè)置直接決定著你的openwrt能不能使用.

      luci-wifi

      添加新接口, 選擇靜態(tài)ip, 新接口的名稱, 你需要用英文自定義一個(gè)名字, 在包括一下接口里面選擇無(wú)線網(wǎng)絡(luò). 設(shè)置完之后提交, 進(jìn)入下一個(gè)頁(yè)面繼續(xù)設(shè)置.

      luci-interface

      基本設(shè)置設(shè)置完成之后, 進(jìn)入防火墻設(shè)置, 這里wifi必須選擇為lan口. 設(shè)置完成之后保存應(yīng)用. 這個(gè)時(shí)候你電腦就可以連接使用openwrt這個(gè)路由器了.

      pc-wifi

      luci-wifi-net

      點(diǎn)擊修改后進(jìn)入防火墻設(shè)置標(biāo)簽欄, 分配防火墻區(qū)域?yàn)閣an, 設(shè)置完成之后保存&應(yīng)用.

      luci-firewall

      制作內(nèi)核補(bǔ)丁

      1. 清空恢復(fù)上一個(gè)全新的內(nèi)核
      make target/linux/{clean,prepare} V=s QUILT=1
      1. 到內(nèi)核源碼目錄
      cd build_dir/target-*/linux-*/linux-3.*
      1. 建立git代碼倉(cāng)庫(kù)
      git init
      git add * -f
      git commit -am "initial commit"
      1. 修改你的代碼, 這里我給我的代碼添加rtl8188cus驅(qū)動(dòng).
      mkdir drivers/net/wireless/rtl8192cus
      
      cp  /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/ -rf
      
      vim  drivers/net/wireless/Kconfig
      284  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_PRIV
      
      vim  drivers/net/wireless/Makefile
      28             obj-$(CONFIG_RTL8192CU_SW)  += rtl8192cus/
      
      vim  drivers/net/wireless/rtl8192cus/Makefile
      575  obj-$(CONFIG_RTL8192CU_SW) := $(MODULE_NAME).o 
      
      579  export CONFIG_RTL8192CU_SW = m
      1. 建立git分支, 并制作補(bǔ)丁
      git branch rtl8192
      git checkout rtl8192
      git add * -f
      git commit -a -m  "add rtl8192cus for pcDuino"
      git format-patch -M master  #會(huì)生成0002-add-rtl8192cus-for-pcDuino.patch 
      
      cp  0001-add-rtl8192cus-for-pcDuino.patch patches/
      cd ../../../../
      make target/linux/update package/index V=s
      cp  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. 檢測(cè)是否生效, 執(zhí)行完之后就是rtl8192分支的代碼了.
      make target/linux/{clean,prepare} V=s QUILT=1
      1. 配置內(nèi)核應(yīng)用選項(xiàng)
      make kernel_menuconfig
               Device Drivers  —> 
                         [*] Network device support  —> 
                                           [*]   Wireless LAN  —> 
                                                                <*>   Realtek 8192C USB WiFi

      其他的patch的制作方法請(qǐng)參考: http://wiki./doc/devel/patches

      建立App服務(wù)器

      OpenWrt通過(guò)opkg來(lái)管理安裝整個(gè)系統(tǒng)的軟件. 目前有很多OpenWrt的軟件源, 但是哪些都是針對(duì)于MIPS平臺(tái)的, pcDuino使用的ARM平臺(tái), 我們必須自己搭建軟件源. 查看了一下MIPS平臺(tái)的服務(wù)器, 其實(shí)很簡(jiǎn)單的, 就是一個(gè)apache服務(wù)器, 而且OpenWrt編譯完成之后, 在openwrt/trunk/bin/sunxi/packages下面已經(jīng)生成了軟件源. 我們只需要將他們聯(lián)系起來(lái)就行了, 這里是在我的PC的虛擬機(jī)上搭建的.

      # sudo apt-get install apache2

      修改https的根目錄

      pillar@monster :~/openwrt$ vim /etc/apache2/sites-available/default
      4     DocumentRoot /home/pillar/openwrt/trunk/bin/sunxi/

      重啟服務(wù)器使修改過(guò)的配置生效

      pillar@monster :~/openwrt$ sudo /etc/init.d/apache2 restart

      修改pcDuino上OpenWrt的源配置

      root@OpenWrt :/# vim /etc/opkg.conf
      src/gz barrier_breaker http://192.168.1.125/packages
      dest root /
      dest ram /tmp
      lists_dir ext /var/opkg-lists
      option overlay_root /overlay

      上面的IP為我們電腦虛擬機(jī)的IP, 下面更新一下軟件源.

      # opkg update

      應(yīng)用程序開(kāi)發(fā)

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

      1. 進(jìn)入package目錄, 創(chuàng)建軟件目錄
      #cd   /home/pillar/openwrt/trunk/package
      #mkdir example1
      1. 進(jìn)入example1目錄, 創(chuàng)建Makefile文件和代碼路徑
      #cd example1
      #touch Makefile
      #mkdir  src

      該Makefile具體內(nèi)容如下:

      #User mode tool example
      include $(TOPDIR)/rules.mk
      include $(INCLUDE_DIR)/kernel.mk
      PKG_NAME:=example1
      PKG_RELEASE:=1
      PKG_BUILD_DIR := $(KERNEL_BUILD_DIR)/$(PKG_NAME)
      include $(INCLUDE_DIR)/package.mk
      
      define Package/example1
       SECTION:=utils
       CATEGORY:=Base system
       TITLE:=Build for example1 commands
      endef
      
      define Package/example1/description
       This package contains an utility useful to use example1 commands.
      endef
      
      define 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 -Wall
      
      define 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. 進(jìn)入src目錄, 創(chuàng)建相關(guān)源文件
      cd src 
      touch example1.c Makefile

      example1.c 具體內(nèi)容如下:

      #include 
      int main(void)
      {
        printf(Hello, world\n);
        return 0;
      }
      

      Makefile文件具體內(nèi)容如下:

      .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-gcc
      CFLAGS=-mips64r2 -mabi=64 -march=octeon -mtune=octeon
      LFLAGS=
      .PHONY: all
      all: example1
      example1:example1.c
        ${CC} ${CFLAGS} ${LFLAGS} -W -g -Wall -Wno-unused-parameter -DUSE_RUNTIME_MODEL_CHECKS=1 \
          -o $@ example1.c
      
      1. 回到主路徑/home/pillar/openwrt/trunk/, 編譯選項(xiàng)配置保存并編譯.
      make menuconfig
        Base system —>
         example1

      選項(xiàng)設(shè)置為M, 保存退出.
      然后編譯該模塊:

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

      內(nèi)核驅(qū)動(dòng)開(kāi)發(fā)

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

      1. 建立工作目錄
      cd  openwrt/trunk/package
      mkdir example
      1. 進(jìn)入example目錄, 創(chuàng)建Makefile文件和代碼路徑
      cd example 
      mkdir src
      vim Makefile
      
      # Kernel module example
      include $(TOPDIR)/rules.mk
      include $(INCLUDE_DIR)/kernel.mk
      PKG_NAME:=example
      PKG_RELEASE:=1
      include $(INCLUDE_DIR)/package.mk
      
      define 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)
      endef
      
      define 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)\
          modules
      endef 
      
      $(eval $(call KernelPackage,example))
      
      1. 進(jìn)入src目錄, 創(chuàng)建代碼路徑和相關(guān)源文件
      cd src
      mkdir example
      cd example
      vim example.c
      
      #include 
      #include 
      #include 
      
      /* hello_init —- 初始化函數(shù), 當(dāng)模塊裝載時(shí)被調(diào)用, 如果成功裝載返回0, 否則返回非0值 */ 
      
      static int __init hello_init(void)
      {
         printk("I bear a charmed life.\n");
         return 0;
      } 
      
      / * hello_exit - 退出函數(shù), 當(dāng)模塊卸載時(shí)被調(diào)用 */
      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 Kconfig
      
      config EXAMPLE
        tristate "Just a example"
        default n
        help
         This is a example, for debugging kernel model.
         If unsure, say N.
      
      vim Makefile
      
      obj-m := example.o
      1. 回到OpenWrt源碼根目錄下
      make menuconfig
        Kernel modules —>
          Other modules —>
            kmod-example

      選項(xiàng)設(shè)置為M, 保存退出
      然后編譯該模塊:

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

      使用OpenWrt SDK

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

      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.bz2
      cd  OpenWrt-SDK-sunxi-for-linux-x86_64-gcc-4.6-linaro_uClibc-0.9.33.2
      1. 建立軟件工作目錄
      cd package
      mkdir helloworld
      vim Makefile    #這個(gè)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 directory
      
      PKG_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 below
      
      define Package/helloworld
          SECTION:=utils
          CATEGORY:=Utilities
          TITLE:=Helloworld — prints a snarky message
      endef 
      
      # Uncomment portion below for Kamikaze and delete DESCRIPTION variable above
      define 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 src
      cd src
      1. 編寫自己的軟件, 這里以helloworld為例.
      vim helloworld.c
      
      #include
      int 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 helloworld
      
      helloworld.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=s
      pillar@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. 修改軟件源根目錄. 如果你不想每次都拷貝, 你可以把軟件源的根目錄下設(shè)置在
      OpenWrt-SDK-sunxi-for-linux-x86_64-gcc-4.6-linaro_uClibc-0.9.33.2/bin/sunxi/packages

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

      Refs

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多