embedded linux ,android

2010年12月6日 星期一

satellite


bootcmd=if mmc init; then if run loadbootscript; then run bootscript; else if run loaduimage; then run mmcboot; else run nandboot; fi; fi; else run nandboot; fi
bootdelay=10
baudrate=115200
bootfile=uImage
loadaddr=0x82000000
usbtty=cdc_acm
console=ttyS2,115200n8
mmcargs=setenv bootargs console=${console} root=/dev/mmcblk0p2 rw rootfstype=ext3 rootwait
nandargs=setenv bootargs console=${console} root=/dev/mtdblock4 rw rootfstype=jffs2
loadbootscript=fatload mmc 0 ${loadaddr} boot.scr
bootscript=echo Running bootscript from mmc ...; source ${loadaddr}
loaduimage=fatload mmc 0 ${loadaddr} uImage
mmcboot=echo Booting from mmc ...; run mmcargs; bootm ${loadaddr}
nandboot=echo Booting from nand ...; run nandargs; onenand read ${loadaddr} 280000 400000; bootm ${loadaddr}
stdin=serial
stdout=serial
stderr=serial
dieid#=139600211ff00000015a5e590e018014
ethact=smc911x-0
filesize=24A29C

//=====================================

setenv nandboot 'echo Booting from nand ...; run nandargs; nand read ${loadaddr} 280000 400000; bootm ${loadaddr}'
setenv loadaddr '0x80200000' //
setenv console 'ttyS0,115200n8' //............down-

setenv mtdids 'nand0=nand_mtd'
setenv mtdparts 'mtdparts=nand_mtd:0x120000@0(uboot)ro,0x400000@0x280000(kernel)ro,0x1000000@0x1000000(RootFS)ro'
setenv nandargs=setenv bootargs console=${console} $(mtdparts) root=/dev/mtdblock3 rw rootfstype=cramfs
setenv nandboot 'echo Booting from nand ...; run nandargs; nand read ${loadaddr} 280000 400000; bootm ${loadaddr}'

//======================================


1
tar -xzvf iperf-2.0.4.tar.gz  
cd iperf-2.0.4
 
2
export CC=xxx-gcc
export CXX=xxx-g++
./configure --prefix=/root --host=arm-linux
make

3.
tftp -g -r iperf xx.xx.xx.xx

4.
chmod +x iperf
iperf -s
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------


2010年12月2日 星期四

浮點數表示法

單精度浮點數表示法用來表示 "實數"

所謂實數,就是有小數部分的數值
所謂浮點數,是因為在將數值表示成0與1過程中,小數點會 "位移" 的關係
所謂單精度,是因為還有另一種叫做 "雙精度" 範圍更大

單精度表示法使用32個位元, 編號 31~0
最高位元(31)為符號位元,0為正,1為負
指數部分8位元 (30-23),以 "超127" 表示
剩下皆為假數部分即正規化後小數點之後的數字
即 符號(1) + 指數(8) + 假數(23)

float a=1.0f = + (1.0)b * 2^0

正數所以符號位元為0
指數0+127 即 0111 1111
假數 000 0000 0000 0000 0000 0000

所以 1.0 在記憶體的表現為 0011 1111 1000 0000 0000 0000 0000 0000
即 0x3f800000

2010年12月1日 星期三

時間復雜度

演算法--分析及解決一個問題的方法,例如步驟一是什麼,步驟二是什麼...最後一步驟是什麼

利用時間複雜度判斷演算法的好壞

時間複雜度分析方法是
(1) 計算出程式每個敘述的執行次數
(2) 將執行次數以Big-O表示法表示

Big-O 為漸近上限

當n很大時, logn < n < nlogn < 平方 < 立方 < 次方 < n階

2010年11月28日 星期日

procfs sysfs devfs 的意義

/dev 是 user 利用application與硬體裝置溝通的介面
/sys  是OS post 出來的device相關的information
/proc 是Process與OS的整體資訊
所以三者是不互相取代的

2010年11月21日 星期日

[轉]雲端運算是趨勢是噱頭抑或是一場騙局?


文章發佈於 : 2009-11-04 22:33:43 | 文章分類 : 阿維看世界
如果你跟我一樣經歷過數據機時代,或許曾經參與過一個計劃,在你的電腦上面安裝一個小程式,當你的網路進入閒置狀態就會使用你的電腦進行運算,協助某個科學機構計算人類DNA結構。撇開這個計畫是不是真的,或者這個計畫到最後到底算出了什麼東西,這樣的模式是我第一次看到雲端運算這四個字第一個想到的例子。

現在雲端喊的漫天震響,甚至出現不加入雲端就落伍了這樣新聞標題。但是當整個業界都瀰漫在一股雲端運算熱的時候,甚至連不熟悉網路產業的周遭親友都在談論雲端運算時,我們是否真的了解什麼是雲端運算?

現在這種場景讓我想到一句名言,當周遭所有的親朋好友甚至連菜市場的婆婆媽媽都在談論股票,並且各各說得頭頭是道,振振有詞時,就是該出脫股票的時候了。這句話雖然有點諷刺但歷史經驗告訴我們這句話似乎頗有道理的。前一次網路泡沫化發生之前,不管是什麼行業通通一窩蜂的 dot com,似乎只要掛上dot com這個招牌,企業營收就會一路往上飆升;以及數年前股市從萬點大崩盤。這兩個歷史經驗都印證了這句話。

資訊科技這個產業有一個毛病,什麼東西都要簡寫和縮寫,常常讓不在這個產業的人一頭霧水,然後還自己得意洋洋以為自己高人一等。因此首先我們必須知道雲端這兩個字到底是什麼的簡稱或縮寫,雲端原本的名字是雲端運算,請注意運算這兩個字;大陸翻譯成雲計算,也請注意計算這兩個字。

根據維基百科對於雲端運算說明如下:
雲端運算(cloud computing,中國大陸譯作雲計算),是一種基於網際網路的運算新方式,透過網際網路上異構、自治的服務為個人和企業使用者提供按需即取的運算。由於資源是在網際網路上,而在電腦流程圖中,網際網路常以一個雲狀圖案來表示,因此可以形象地類比為雲運算,『雲端』同時也是對底層基礎設施的一種抽象概念。

雲端運算的資源是動態易擴充套件而且虛擬化的,透過網際網路提供。終端使用者不需要了解「雲端」中基礎設施的細節,不必具有相應的專業知識,也無需直接進行控制,只關注自己真正需要什麼樣的資源以及如何透過網路來得到相應的服務。

雲端運算可以認為包括以下幾個層次的服務:基礎設施即服務(IaaS),平台即服務(PaaS)和軟體即服務(SaaS)。雲端運算服務通常提供通用的透過瀏覽器存取的線上商業應用,軟體和資料可儲存在資料中心。

基本特徵
網際網路上的雲端運算服務特徵具有和自然界的雲端、水迴圈具有一定的相似性,因此,雲端是一個相當貼切的比喻。通常雲端運算服務應該具備以下幾條特徵:

    * 基於虛擬化科技快速部署資源或獲得服務
    * 實作動態的、可伸縮的擴充套件
    * 按需提供資源、按使用量付費
    * 透過網際網路提供、面向海量資訊處理
    * 使用者可以方便地參與


維基百科寫的對於有人來說或許看不太懂,我舉另外一個例子來說明。首先我們先拋開維基百科上面所寫的和雲端運算這兩件事情。前陣子到目前都還相當流行的自己架站,不管是自己架設部落格或者是架設其他類型網站,到電子書店都會發現相當多這類型的書籍。

當你選定一套程式不管是wordpress、xoops或者是drupal,接下來的工作就是要購買主機和網域名稱。一般來說個人使用者挑選的是便宜的虛擬主機,也就是主機商提供一套主機(不是一台喔,如果你的主機商只有一台主機,那麼我奉勸你還是早點換主機商吧)然後切割成許多的區塊,你可以承租這個區塊去架設你的部落格或者是其他你想要的網站。這個概念就很像房東把一層樓隔成一間一間小小間的雅房或套房出租出去,付的錢比較多就可以租套房,付的錢比較少就只能租雅房。

你承租的主機空間包含了基本的硬碟空間和網路流量,如果你超過了基本使用量就需要額外支付費用。就好比你和房東約定好每個月的房租包含了兩百元的水電費,但是超過的部分你就需要額外再支付給房東。

這一切看起來都很合理,但是問題來了,我每個月的水電費用量都少於兩百元,可是我每個月付的房租裡面就是包含了固定兩百元的水電費,這樣我不是很虧嗎?此外,我平常所使用的空間比雅房還要小,可是我就是要付這樣的房租給房東,怎麼算都不划算。偶爾找朋友來想聚一聚吃個火鍋,立刻就又發現地方太小,實在是太擁擠了。

如果找到一個房東跟你說,水電費按照你使用的量,用多少就付多少,這樣是不是比較好,當然這個模式已經實現在現在一般的租賃中。這時候如果一個房東跟你說,房租一天一坪50元,按照你每天使用的坪數大小來收費,這樣是不是就太美好了。今天只想一個人靜靜的躲在自己的小天地,只需要五坪空間,你就只需要付250元;改天約了一群朋友來家裡開party需要100坪空間,那就付5000元。

你每天跟房東租的空間就好比是你向虛擬主機商承租的空間;你網站的流量就是你每天所使用的水電費。而這樣的動態而且可以隨時根據你的需求做變化,然後再根據你的使用量來進行收費的模式,就是維基百科形容雲端運算基本特徵的前三項。

看到這裡,你是不是覺得所謂的雲端運算就跟現行的虛擬主機很類似,只是將計費模式做了一些更動,沒錯!到目前為止的確是這樣,但是別忘了後面還有兩個基本特徵:透過網際網路提供、面向海量資訊處理以及使用者可以方便的參與。

這兩個基本特徵回到我第一段提到的內容,某個科學機構提供一個小程式,讓參與的人安裝後,在參與者網路閒置時進行運算並且將運算的結果回傳回去到該科學機構。

舉一個例子,大家都聽過木馬和殭屍電腦,先不管你對這兩個名詞的了解有多少。我們大家先化身為駭客,你今天想要攻擊一個你看不順眼的網站,或者是有人付錢請你攻擊一個網站。這時候如果單靠你自己一台電腦,一定很難讓那個網站掛掉,如果你可以透過散撥木馬控制一萬台甚至是十萬台電腦,這樣攻擊成功的機率是不是就高出許多?

所以其實雲端運算並不是一個新的東西,這件事情早就在你我身邊發生,而且運用的最好還是所謂的非法行為。

總結一下
(1) 基於虛擬化科技快速部屬資源或獲得服務:駭客快速部屬木馬然後獲得你的電腦來幫他服務;
(2) 實作動態的、可伸縮的擴充套件:駭客可以隨時隨機選擇被植入木馬的電腦來進行散撥病毒或木馬或者做他想要你做的事情;
(3) 按需求提供資源、按使用量付費:駭客對被植入木馬的電腦要求資源,被植入木馬的電腦就乖乖提供資源,只是付費的不是駭客,是被植入木馬的電腦的主人,傻傻的花錢買主機和牽ADSL;
(4) 透過網際網路提供、面向海量資訊處理:駭客透過網路操控被植入木馬的電腦,然後發出攻擊指令,對特定的電腦或網站進行攻擊。想想看上萬台甚至上百萬台電腦同時對特定電腦或網站攻擊,這個資訊量夠大了吧;
(5) 使用者可以方便地參與:只要我們不重視電腦安全,我們隨時都可以快速又方便的參與。

這裡我還真的要感謝駭客們提供了這麼一個簡單易懂的雲端運算範例,想必大家應該都可以了解什麼是雲端運算了。

看起來雲端運算對我們似乎沒有什麼幫助,除了主機的費用是根據我們實際的使用量來計價之外。但是任何的科技都是一體兩面的,就看我們怎麼去使用它。

最後我們回頭來看看現在資訊科技產業號稱的雲端運算是什麼,現在台灣喊雲端運算喊的最大聲動作也最明顯的就是廣達,連這期的天下雜誌都特地做了一篇專欄。

節錄天下雜誌專欄的內容:
(1) 廣達出資三點三億,取得多媒體及網路等晶片的Tilera Corp.的特別股,投入雲端運算晶片設計。
(2) 林百里自信地說,「接下來要做全球最大的三C企業。」這是個石破天驚的轉型宣示。意味著,過去專注筆電ODM代工製造的廣達,將變成林百里新三C「雲端運算」(cloud computing)、「連結」(connectivity)、「client device」(消費端載具),提供客戶雲端運算需求下,一條龍式的solution provider(系統解決方案供應者)。
(3) 林百里認為未來想要創業的人,可以省去向VC募資投資硬體,只要向廣達租低廉的雲端空間,就可以善用各地人才創新。

看起來廣達自信滿滿的投入雲端運算這個領域,但是問題來了,這樣最多只有做到雲端運算的第三項基本特徵,那跟虛擬主機商有什麼分別呢?最多只能算是雲端運算中的一個子項目基礎設施即服務(IaaS)

雲端運算的其中一項特徵就是透過網路處理大量資訊,而處理大量資訊的前提就是到底要處理什麼資訊呢?如果沒有服務沒有軟體放在這樣的機制上面,那這一切的架構都只是空談,相比對之下,連只會下載別人寫好的木馬然後散撥出去的毛頭小駭客更清楚雲端運算怎麼應用。

台灣的問題就是一向重視硬體不重視軟體,如果真的要投入雲端運算,請告訴別人你準備在雲端運算上面提供什麼軟體應用服務,而且請注意一點,雲端運算是需要使用者可以方便參與,方便參與也包含了另外一層意義,這個軟體是使用者想要或是需要的服務或軟體。

如果只是打著雲端運算的旗幟而沒有了解雲端運算的本質,這樣就跟前一波網路泡沫化前一樣,打著dot com的旗幟到處宣揚,或許不會跟之前一樣泡沫,但最後大家終將發現這只是資訊科技產業的另一項噱頭,最後成為一場世紀騙局而已,只是看你騙的程度有多大,騙了股東或投資人抑或是整個資訊科技產業騙了全世界。

參考資料
(1) 維基百科 雲端運算
(2) 天下雜誌 筆電之後是什麼?林百里:我不去藍海,我去雲端

vmWare中操作過程的錄製

在vmWare中可以利用VM--> Capture Movie這個選項來錄製各種作業系統的操作過程,產生出XXX.avi的檔案,但檔案太大了,所以需要利用轉檔軟體,利如CamStudio轉成flash swf方便傳輸及放在網路上分享

2010年11月18日 星期四

一流點子,還是一流團隊?


一流點子,還是一流團隊?

撰文者:郭奕伶

如果你是一個領導者,資源有限,你要選擇一流的點子,還是一流的團隊? 我曾經以為,好點子最重要,即便執行力打折,都瑕不掩瑜。畢竟,執行力的效率,怎麼打得過創新的破壞力?

然而,在加州爾灣(Irvine),我們深入製作《魔獸世界》的秘密基地——暴雪娛樂(Blizzard Entertainment)後,我發現,答案並非如此。

這裡,應該是全世界最看重創意、最自由的地方,但一進到工作現場,昏暗、沉默、密密麻麻的會議時間表??。

他們,是一支紀律嚴明的軍隊,十五年來只出過三個系列的遊戲,卻款款熱賣逾十年,光一款《魔獸世界》,過去四年就進帳一千二百億元,去年淨利率是蘋果電腦(Apple)的兩倍。
想像一下,在《魔獸世界》裡,有一千四百個地點、三萬個物件、七千六百個冒險任務,而且它要用十一種語言發行,還要讓萬人同時上線互動、將全球玩家分級??。這裡頭,有多少細節?

「紀律,」創辦人兼總裁默罕(Michael Morhaime)解答,一切都奠基在「專注的紀律」。
故事,並非一開始就如此完美,草創初期,他們曾經貪心、曾經自負,甚至必須賣掉公司以換取生存,但「從回顧的角度看,我們發現,那些我們說『不』的決定,讓我們能聚焦在重要的事,」默罕將此稱為「專注的酷」(Concentrated Coolness)。
然而,誘惑從來不會停止。

尤其當一個人成功了,富有了,上門的試煉自然多了起來,決策難度也變高,所幸,這個組織的靈魂是「不斷的自我批判」,因此,即便後退兩步,下次還是會拉回正軌,再進個五步以上。一退一進、來回修正間,這家公司成為全球的線上遊戲王國。
所以,一流的點子重要,還是一流的執行團隊重要?

曾經,暴雪的數個天王級製作人出走,但最後都浮沉於世,再無驚人之作。這證明了,偉大的任務要完成,「要拿到最後的一○%,要花上比前面九○%更多的力氣。」默罕這麼說,而最後這一○%,就要靠一流團隊的執行力。

如果一定要選擇,我完全相信,一流的團隊能把二流的點子,執行到一流;但二流的團隊卻可能把一流的點子完全搞砸!

[轉]忘記會做微軟 不然就等死


反省篇PC大廠採購主管告白



忘記會做微軟  不然就等死



3年前台灣就啟動石減法革命,推出小筆電,遇上蘋果卻完全被取代。同樣的創意,為何台灣人就只能走上失敗?

林俊劭、林宏達



當台灣電子五哥金年上半年的獲利總和,第一次輸給傳產五哥的這一刻,台灣的電子代工業,正站在一個轉型的十字路口。三年前,當華碩推出第一台以簡便、快速上網為訴求的小筆電EeePC時,在市場上引起轟動,曾經每五秒賣出一台,刺激惠普(HP)、戴爾(Dell)等國際大廠跟進,被《富比世》(Forbes)雜誌評選為二OO八年年度的風雲產品。

然而,不到兩年的時間,小筆電又殺成一片紅海。現在,iPad問世半年後,卻產生天翻地覆的變化。小筆電,成了iPad出現後的主要犧牲者,看到iPad的出現,過去做小筆電的台灣業者,又開始了一窩蜂的平板電腦風潮,然而,這次能成功複製iPad平板電腦嗎?

「如果你的出發點是把Netbook(小筆電)做小,變成平板電腦,對不起,死路一條,你要想的是把smart phone(智慧型手機)做大。」


這是一位市值上千億的科技代工大廠,採購主管的告白。



他,在科技業資歷超過十年,從國內某品牌廠的研發工程師做起,經歷過台灣科技產業起飛的年代,看盡PC產業的興衰起伏,也曾主導過小筆電的研發與製造,如今手握千億採購金額,對於台灣電子業的結構有深刻觀察。

以下是他在前線的第一手觀察:

兩年前我就對Netbook不看好,我說這個東西是「曇花一現」、「falling star」,一個品牌多賣一台Netbook(小筆電),他就少(賣)一台Netbook(筆電),這是顯而易見的道理,多賣多死,revenue(營收)只有原來的三分之二,利潤更只有原來的三分之一。



「賣小筆電是虛的,賣越多死越慘」



Netbook至少還有兩萬塊,Netbook只要八千塊,淪落到外勞買來打skype回家的工具,這樣的市場你還留戀什麼?賣越多死越慘啊!表面上看來,這幫助他們把市占率提升,但這是虛的,對獲利沒有幫助啊!


小筆電剛出的時候,大家講說是第一年十五咪(編按:million,百萬台),第二年三十咪,第三年四十咪,再來馬上五年內就破百咪。大家是這樣想的,但去年三十四個咪,今年還會繼續衰退啊!


平板電腦今年是蠶食,明年是鯨吞!

iPad是硬體簡單,但豐富了應用軟體。兩年前的小筆電,是華碩發動的失敗的減法革命,當時以為這是個成功的減法革命,但是他同時減掉了軟體跟硬體。

平板是蘋果成功的減法革命,硬體減的更誇張,筆電七四七的噴射引擎,蘋果的CPU A4減到只剩下機車的引擎。


IPad為什麼可以待機七天還有電?因為它瘋狂了硬體,沒有USB孔,沒有讀卡機,也沒有耳機,只有一個連結器,但在軟體上它豐富得很啊!硬體上只有摩托,但上網比飛機還快,人們會appreciate這個東西。



「搞低價結果,傷敵七分自損三分」



小筆電當初出來的時候被稱為上網機,結果iPad上網速度比它快三倍!第一個實現微軟與英特爾夢想的竟然是蘋果,真諷刺!


兩年前小筆電是潘朵拉,打開的下場是所有人的ASP(平均單價)全部往下降,雖然有量但沒有價,七傷拳,傷敵七分,自損三分,多賣一台把敵人幹掉一台,但你同時傷了自己,高價格的筆電賣不掉啊!


小筆電曾經定義為你的第二台NB,但現在淪落為外勞的電話機,iPad的減法不是只是為了減而減,而是減了為了加,加快上網速度,加快閱讀資訊的方便性,這是減法才有意義。

對於小筆電占比很高的公司,那就是等死啊!


IPad的市場是多出來的,我估計三年後會成長到一億台,不會因此侵蝕到傳統NB的市場,它硬生生在智慧型手機與NB中間卡出了一個位置,這個位置是小筆電想要的。


整個產業沒有一個完整配套的solution跟它打,但是以後會不會起來?會啊!為什麼兩年前我說
小筆電必死?因為它進入障礙低啊!


台灣人的宿命,就只能賺組裝的錢,這是宿命啦!


你在某方面的成功會造成你在另一方面的失敗,這是經營者與主事者的心態要改變,如果心態再不轉過來,沒有破釜沈舟,以宏達電為例,他以前做PDA代工做得很成功,但如果一直顧著眼前的成功,沒有想到要轉,那就沒有今年的宏達電啦!現在也是一樣,當他發現Android才有未來的時候,就把微軟的工程師全都轉到Android,叫他們忘記「以前會做微軟」,不這樣就會死翹翹啊!


富士康還在想著以前最賺錢的時代是摩托羅拉V3的時代,所以轉不過來啊。

一個成功的平板電腦,硬體要簡單,但簡單反而難。一個長期做汽車的公司,你覺得它能馬上做五千CC的引擎,但你要他做出一台五十CC的,要減掉兩個零耶!英特爾做的CPU都必死,雙A(華碩、宏碁)研發能力再強,能馬上做出十萬個軟體來嗎?



從硬體轉軟體,最大問題在人才



從硬體走到軟體,說起來容易,但實際上卻困難重重,最大的問題在於人才的嚴重不足。

「台灣的軟體過去二十年都被微軟給慣壞了,只要修修改改,懂開發的不多,」一位曾擔任過美商軟體大廠高階主管,現任國內某代工大廠的軟體總監,很感概的表示:「過去二十年我們再怎麼努力,也不過培養了六百五十個(軟體)工程師,現在去大陸,一個月就可以訓練出一百個,外面還有五百個排隊在等。」


「在學校培養出來的人,台灣就是硬體製造,離軟體開發、雲端運算『很遠很遠很遠』,」他指出,以前國際大廠如戴爾等客戶來,都是談硬體的價格,但現在,來就直接問你「軟體(部門)有多少人?」這顯示軟體研發能力已成功當前科技業最主要的競爭力。


「當公司要從製造硬體,轉換到軟體和服務,現有的營運系統(台灣代工產業),並不熟悉如何操作這種新營運模式。」台大國企系教授李吉仁說。


他解釋,「電子代工產業擅長玩的是,有限利潤下進行成本減法的遊戲,」客戶給的資源是固定的,能從哪裡再多省一點,不管是供應商的利潤還是材料的採購成本,只要少一點,公司的成本就能再下降一點,這個遊戲,常常是零和的結果。


「服務的邏輯卻不是這樣,」以蘋果的App Store為例,蘋果要建成一個有影響力的平台,先考慮的卻是如何讓別人賺到錢。「這個『共利』的平台策略,值得台灣廠商思考。」李吉仁說。

「創新分兩種,技術創新和商業創新,」李吉仁分析。台灣廠商許多生產的know-how是自己培養出來的,蘋果卻相反,除了作業系統跟介面軟體,大部分內容和軟體都是市場上買得到的。 

再不改變,台灣電子業會有什麼影響?


「硬體代工不會滅亡,只是利潤越來越薄。」李吉仁下了這個結論。



摘自商業周刊第1191

android thread




ThreadDemo .java
package wandroide.blogspot.com;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.ProgressBar;
import android.widget.TextView;

import java.util.concurrent.atomic.AtomicBoolean;

public class ThreadDemo extends Activity 
{
    ProgressBar bar1 = null;
    ProgressBar bar2 = null;
    TextView    tv   = null;

    Handler handler=new Handler(){
 @Override
 public void handleMessage(Message msg) 
 {
     bar1.incrementProgressBy(5);
 }
    };

    Handler handler2=new Handler(){
 @Override
 public void handleMessage(Message msg) 
 {
     bar2.incrementProgressBy(-5);
 }
    };
   
    AtomicBoolean isRunning=new AtomicBoolean(false);
    AtomicBoolean isRunning2=new AtomicBoolean(false);

    @Override
    public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  tv   = (TextView)findViewById(R.id.tv);
  bar1 = (ProgressBar)findViewById(R.id.progressbar1);
  bar2 = (ProgressBar)findViewById(R.id.progressbar2);
    }

    public void onStart() 
    {
 super.onStart();
 bar1.setProgress(0);
 bar2.setProgress(100);
     
 Thread background=new Thread(new Runnable() 
 {
      public void run() 
      {
          try {
              for (int i=0;i<20 && isRunning.get();i++) 
              {
                  Thread.sleep(1000);
                  handler.sendMessage(handler.obtainMessage());
              }
          }
          catch (Throwable t) {
               // just end the background thread
          }
       }
  });
      
  Thread background2=new Thread(new Runnable() 
  {
      public void run() 
      {
          try {
              for (int i=0;i<20 && isRunning2.get();i++) 
              {
                  Thread.sleep(1000);
                  handler2.sendMessage(handler2.obtainMessage());
              }
          }
          catch (Throwable t) {
              // just end the background thread
          }
      }
   });

   isRunning.set(true);
   background.start();
       
   isRunning2.set(true);
   background2.start();
    }

    public void onStop() {
  super.onStop();
  isRunning.set(false);
  isRunning2.set(false);
    }
}

2010年11月16日 星期二

BCB thread

解ATE bug
thread跑完就結束了,不需要delete


unit2.h
#ifndef Unit2H
#define Unit2H
//---------------------------------------------------------------------------
#include <Classes.hpp>
//---------------------------------------------------------------------------
class TGridThread1 : public TThread
{
protected:
        void __fastcall Execute();
public:
        __fastcall TGridThread1(bool CreateSuspended);
};
//---------------------------------------------------------------------------
#endif
unit2.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit2.h"
#pragma package(smart_init)
//---------------------------------------------------------------------------
//   Important: Methods and properties of objects in VCL can only be
//   used in a method called using Synchronize, for example:
//
//      Synchronize(UpdateCaption);
//
//   where UpdateCaption could look like:
//
//      void __fastcall TGridThread1::UpdateCaption()
//      {
//        Form1->Caption = "Updated in a thread";
//      }
//---------------------------------------------------------------------------

__fastcall TGridThread1::TGridThread1(bool CreateSuspended)
        : TThread(CreateSuspended)
{
}
void __fastcall TGridThread1::Execute()
{
        //---- Place thread code here ----
}
uint1.cpp
#include 
#pragma hdrstop

#include "Unit1.h"
#include "Unit2.h"
#include "Unit3.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CGAUGES"
#pragma resource "*.dfm"
TForm1 *Form1;
TGridThread1 *GridThread1;

//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
    // Create the thread objects
    GridThread1 = new TGridThread1(true);

    // Initial setup for threads and buttons
    GridThread1->Resume();
}

資料儲存與Content Provider

在使用手機時,user需要儲存一些資訊,如果這些資訊是比較固定的,此時若能儲存起來,就可免去每次輸入這些資訊的手續,在android有三種資料儲存方式:
Shared Preferences(xml形式)、檔案儲存與資料庫儲存。
Android 並沒有一個共同的儲存空間讓所有應用程式存取,因此若要讓其它的應用程式使用我的資料,就必須使用Content Provider,用來分享資料用的。


DataStorageDemo.java
package wandroide.blogspot.com;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class DataStorageDemo extends Activity implements OnClickListener
{
    private TextView mTextView         = null;
    private EditText mEditText         = null;         
    private Button   mSharedPrefButton = null;
    private Button   mFileButton       = null;
    private Button   mSqliteButton     = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
           
        mTextView         = (TextView)findViewById(R.id.ltextview);
    mEditText         = (EditText)findViewById(R.id.ledittext);          
 mSharedPrefButton = (Button)findViewById(R.id.lsharedprefbutton);
 mFileButton       = (Button)findViewById(R.id.lfilebutton);
 mSqliteButton     = (Button)findViewById(R.id.lsqlitebutton);
      
 mSharedPrefButton.setOnClickListener(this);
 mFileButton.setOnClickListener(this);
 mSqliteButton.setOnClickListener(this);
    }
    
    public void onClick(View v) 
    {
 if(v == mSharedPrefButton)
 {
     //write
     SharedPreferences pref = getSharedPreferences("PREF_DATA", MODE_WORLD_READABLE);
       SharedPreferences.Editor preEdt = pref.edit();
       preEdt.putString("PREF_EDITTEXT", mEditText.getText().toString());
       preEdt.commit();
       //read
       String pref_edittext = pref.getString("PREF_EDITTEXT", "hello shared preference");
            mTextView.setText(pref_edittext);
       mEditText.setText("");
 }
 else if(v == mFileButton)
 {
     
 }
 else if(v == mSqliteButton)
 {
          
 }    
    }
}
ContentProviderDemo.java
package wnadroide.blogspot.com;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;

public class ContentProviderDemo extends Activity implements OnClickListener
{    
    private TextView mTextView              = null;
    private Button   mGetPrefButton         = null;
    private Button   mContentProviderButton = null;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        mTextView      = (TextView)findViewById(R.id.ltextview);
        mGetPrefButton = (Button)findViewById(R.id.lgetprefbutton);
        mContentProviderButton = (Button)findViewById(R.id.lcontentproviderbutton);
       
        mGetPrefButton.setOnClickListener(this);
        mContentProviderButton.setOnClickListener(this);
    }
  
    public void onClick(View v) 
    {
 if(v == mGetPrefButton)
        {
     Context otherApp = null;
     try {
      otherApp = createPackageContext("wandroide.blogspot.com", 0);
     } catch (Exception e) {
      Log.d("wandroide", e.toString());
      finish();
     }
     SharedPreferences pref = otherApp.getSharedPreferences("PREF_DATA",MODE_WORLD_READABLE);
     String pref_edittext = pref.getString("PREF_EDITTEXT", "get不到");
     mTextView.setText(pref_edittext);
 }
 else if(v == mContentProviderButton)
 {
     Cursor c = getContentResolver().query(Uri.parse("content://wade.dbprovider"),
                null, null, null, null);
         
     if(c.getCount() != 0) 
     {
         c.moveToFirst();
      String name = c.getString(c.getColumnIndex("name"));
      if ( name == null ) return;
      mTextView.setText(name);
     }
     
   }
    }
}
DBProvider.java
package wnadroide.blogspot.com;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.net.Uri;

public class DBProvider extends ContentProvider {
    Context mCtx;
    SQLiteDatabase db;

    @Override
    public int delete(Uri arg0, String arg1, String[] arg2) {
 return -1;
    }

    @Override
    public String getType(Uri uri) {
 return null;
    }

    @Override
    public Uri insert(Uri uri, ContentValues values) {
 return null;
    }

    @Override
    public boolean onCreate() {
 mCtx = getContext();
 DoDB dbHelper;
 dbHelper = new DoDB(mCtx);
 db = dbHelper.getWritableDatabase();
 return true;
    }

    @Override
    public Cursor query(Uri uri, String[] projection, String selection,
   String[] selectionArgs, String sortOrder) {
 Cursor c = db.rawQuery("select * from nametable;", null);
 return c;
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection,
   String[] selectionArgs) {
 return 0;
    }
}
DoDB.java
package wnadroide.blogspot.com;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DoDB extends SQLiteOpenHelper {
    private final static String DATABASE_NAME = "namedb";
    private final static int DATABASE_VERSION = 1;
    private final static String TABLE_NAME = "nametable";
    public final static String FIELD_NAME = "name";
  
    public DoDB(Context context)
    {
        super(context, DATABASE_NAME, null, DATABASE_VERSION); 
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
 String sql = "CREATE TABLE " + TABLE_NAME + " (" + FIELD_NAME + ")";
 db.execSQL(sql);
 ContentValues cv = new ContentValues();
 cv.put(FIELD_NAME, "aaaaa");
 db.insert(TABLE_NAME, null, cv);
    }

    @Override
    public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
    }
 
    public Cursor select()
    {
 return null;
    }
}
AndroidManifest.xml
<provider android:name=".DBProvider" 
          android:authorities="wade.dbprovider">
</provider>

2010年11月15日 星期一

NAS110_88f6281




uboot env
===NAS110 PCBA nfs_boot:
setenv ipaddr '192.168.1.99'
setenv serverip '192.168.1.100'
setenv setconsole 'console=ttyS0,115200'
setenv setip 'ip=dhcp'
setenv setip 'ip=192.168.1.98'
setenv setnfs 'root=/dev/nfs nfsroot=192.168.1.100:/home/NAS110/rootfilesystem/rootfs'
setenv loadkernel 'tftpboot 0x200000 uImage.20090930'
setenv bootcmd '$(loadkernel);setenv bootargs $(setconsole) $(setip) $(setnfs);bootm 0x200000;'
saveenv

===NAS110 PCBA nand boot(mtd boot)
setenv mtdids 'nand0=nand_mtd'
setenv mtdparts 'mtdparts=nand_mtd:0x100000@0(uboot)ro,0x100000@0x100000(system1),0x100000@0x200000(system2),0x300000@0x300000(kernel)ro,0x700000@0x600000(RootFS)ro'
setenv bootcmd 'nand read 0x2000000 0x300000 0x300000 ;setenv bootargs $(console) $(mtdparts) rootfstype=squashfs root=/dev/mtdblock5;bootm 0x2000000;'
setenv console 'console=ttyS0,115200'
setenv ipaddr '192.168.1.99'
setenv serverip '192.168.1.100'
setenv bootargs ''

===NAS110 PCBA nand boot(ramdisk boot)
setenv loadimage ''
setenv setbootargs 'setenv bootargs console=ttyS0,115200 root=/dev/ram0 rootfstype=squashfs initrd=0x2000000,0x700000 ramdisk_size=7168'
setenv bootcmd 'nand read 0x800000 0x300000 0x300000;nand read 0x2000000 0x600000 0x700000;$(setbootargs);bootm 0x800000;'
setenv console 'console=ttyS0,115200'
setenv ipaddr '192.168.1.99'
setenv serverip '192.168.1.100'

===build squashfs
mksquashfs ./rootfs rootfs20090917

===load image
nand erase 0x300000 0x300000
tftpboot 0x1000000 uImage.20090930
nand write 0x1000000 0x300000 0x300000

nand erase 0x600000 0x700000
tftpboot 0x1000000 rootfs20090917.sqfs
nand write 0x1000000 0x600000 0x700000

===write uboot:
bubt u-boot-db88f6281abp_400db_nand_20090819.bin
bubt u-boot-db88f6281abp_400db_nand@20090821.bin
bubt u-boot-db88f6281abp_400db_nand-3.4.19@20090824.bin
bubt u-boot-db88f6281abp_400db_nand_20090826.bin
bubt u-boot-db88f6281abp_400db_nand_3.4.18_20090826.bin
bubt u-boot-db88f6281abp_3.4.19_nand@20090902.bin
bubt u-boot-db88f6281abp_400db_nand.bin
bubt u-boot-Foxlink-1GB.bin
bubt u-boot-1114.bin
bubt u-boot-20090915.bin
bubt u-boot-20090916.bin
bubt u-boot-20090917_2.bin
==========================================================================
==========================================================================
=====proware nand boot
nand erase  0x300000 0x300000
tftpboot  0x1000000 uImage.20090930
nand write  0x1000000 0x300000 0x300000

nand erase  0x600000 0x3500000
tftpboot  0x1000000 rootfs.squashfs_0930
nand write  0x1000000 0x600000 0x3500000

nand erase 0x3b00000 0x6b00000
tftpboot 0x1000000 dom_0930.img
nand write 0x1000000 0x3b00000 0x6b00000

setenv loadimage ''

setenv setbootargs  ‘setenv bootargs console=ttyS0,115200 rootfstype=squashfs initrd=0x2000000,0x3500000 ramdisk_size=128000’

setenv bootcmd  ‘nand read 0x800000 0x300000 0x300000;nand read 0x200000 0x600000 0x3500000;$(setbootargs);bootm 0x800000;’
bubt
Marvell>> setenv ipaddr '192.168.1.99'
Marvell>> setenv serverip '192.168.1.100'
Marvell>> bubt u-boot-db88f6281abp_400db_nand-3.4.19@20090824.bin
Using egiga0 device
TFTP from server 192.168.1.100; our IP address is 192.168.1.99
Filename 'u-boot-db88f6281abp_400db_nand-3.4.19@20090824.bin'.
Load address: 0x2000000
Loading: #################################################################
         ############################
done
Bytes transferred = 474036 (73bb4 hex)

**Warning**
If U-Boot Endiannes is going to change (LE->BE or BE->LE), Then Env parameters should be overriden..
Override Env parameters? (y/n) n
Erase 0 - 655360 ... 
Copy to Nand Flash... Failed write verify, nand offset 0x00000000. Suggest to erase block and repeat write ope!
 If problem persists suggest marking block as bad (nand markbad ) and repeating the operation!
writing NAND page at offset 0x0 failed
Data did not fit into device, due to bad blocks
Error - NAND burn faild!
build kernel
1. cd /home/NAS110/Kernel/linux-2.6.22.18
2. . ./set_path.sh
3. make mrproper
4. make mv88f6281_defconfig
5. make uImage (uImage會放在arch/arm/boot/)
6. cp ./arch/arm/boot/uImage /home/NAS110/images

2010年11月14日 星期日

App Widget




AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="wandroide.blogspot.com"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <receiver android:name=".MyAppWidget" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
            </intent-filter>
            <meta-data android:name="android.appwidget.provider"
                        android:resource="@xml/myappwidget_provider" />
    </receiver>
    </application>
    <uses-sdk android:minSdkVersion="7" />
</manifest> 
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:id="@+id/widget_textview"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
</LinearLayout>
strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World!</string>
    <string name="app_name">MyAppWidget</string>
</resources>
myappwidget_provider.xml
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:minWidth="146dip"
  android:minHeight="72dip"
  android:updatePeriodMillis="10000"
  android:initialLayout="@layout/main">
</appwidget-provider>
MyAppWidget.java
package wandroide.blogspot.com;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.Timer;
import java.util.TimerTask;
import android.content.ComponentName;
import android.content.Context;
import android.appwidget.AppWidgetProvider;
import android.appwidget.AppWidgetManager;
import android.widget.RemoteViews;

public class MyAppWidget extends AppWidgetProvider 
{
//====顯示widget 
 @Override
 public void onUpdate(Context context, AppWidgetManager appWidgetManager,
                       int[] appWidgetIds) 
 {
     Timer timer = new Timer();
     timer.scheduleAtFixedRate(new MyTime(context, appWidgetManager), 1, 1000);
 }
 
 private class MyTime extends TimerTask 
 {
     RemoteViews remoteViews;
     AppWidgetManager appWidgetManager;
     ComponentName thisWidget;
     DateFormat format = SimpleDateFormat.getTimeInstance(SimpleDateFormat.MEDIUM,
                            Locale.getDefault());
     public MyTime(Context context, AppWidgetManager appWidgetManager) 
      {
         this.appWidgetManager = appWidgetManager;
         remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
         thisWidget = new ComponentName(context, MyAppWidget.class);
      }
     
     @Override
     public void run() 
      {
         remoteViews.setTextViewText(R.id.widget_textview,
                       "Time = " + format.format(new Date()));
         appWidgetManager.updateAppWidget(thisWidget, remoteViews);
      }
 }
}

Android Service , aidl 與 Broadcast Receiver

什麼是service
沒有UI的程式,在背景執行的Process
啟動service的方式
1. startService(),stopService()
啟動 onCreate() --> onStart()
結束 onDestory()
若沒有StopService()則會繼續執行下去
2. bindService(),unbindService()
啟動onCreate() --> onBind()
結束onUnBind() --> onDestory()
啟動已執行起來的service,當然也可以啟動未執行起來的service
兩種方式可以混用,但必須stopService()且unbindService()才真正結束service


























demo code

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.wandroid.servicedemo"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".ServiceDemo"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <service android:name=".xxxService" android:exported="true"></service>
        <service android:name=".xxxRemoteService" android:process=":remote"/>
        <receiver android:name="xxxBroadcastReceiver">
           <intent-filter>
                 <action android:name="com.wandroid.servicedemo.Play_MUSIC"/>
         </intent-filter> 
      </receiver>
    </application>
    <uses-sdk android:minSdkVersion="7" />
</manifest> 
res/layout/main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:id="@+id/text"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
<Button
  android:id="@+id/startservice"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="startService"
 />
<Button
  android:id="@+id/stopservice"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="stopService"
 />
<Button
  android:id="@+id/bindservice"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="bindService"
 />
<Button
  android:id="@+id/unbindservice"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="unbindService"
 />
<TextView  
    android:id="@+id/remotetext"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/remotehello"
    /> 
<Button
  android:id="@+id/remotebindservice"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="remote bindService"
 /> 
<Button
  android:id="@+id/remoteunbindservice"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="remote unbindService"
 />  
<Button
  android:id="@+id/musicbroadcast"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="music broadcast"
 /> 
</LinearLayout>
res/raw/music.mp3 res/values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, ServiceDemo!</string>
    <string name="app_name">ServiceDemo</string>
    <string name="remotehello">Hello World,Remote ServiceDemo!</string>
</resources>
ServiceDemo.java
package com.wandroid.servicedemo;

import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class ServiceDemo extends Activity implements OnClickListener
{   
 private xxxService        mxxxService              = null;
 private IxxxRemoteService mxxxRemoteService        = null;
 private TextView          mTextView                = null;
 private TextView          mremoteTextView           = null;
 private Button            startServiceButton       = null;
 private Button            stopServiceButton         = null;
 private Button            bindServiceButton        = null;
 private Button            unbindServiceButton       = null;
 private Context           mContext                  = null;
 private Button            remotebindServiceButton   = null;
 private Button            remoteunbindServiceButton = null;
 private Button            musicbroadcastButton      = null;
 
 //ServiceConnection在bind時建立連線
 private ServiceConnection mServiceConnection = new ServiceConnection() 
 { 
  public void onServiceConnected(ComponentName name, IBinder service) 
  {
   if( name.getClassName().compareTo
                            ("com.wandroid.servicedemo.xxxService") == 0 )
   {
       //===local service
       mxxxService = ((xxxService.xxxBinder)service).getService();
       try {
     mTextView.setText("I am frome Service :"+                 
                                              Integer.toString(mxxxService.sum(5, 5)));
       } catch (RemoteException e) {
     e.printStackTrace();
       }
   }
   else
   {
       //===remote service
              mxxxRemoteService =  IxxxRemoteService.Stub.asInterface(service);
       try {
    mremoteTextView.setText("I am frome remote Service :"+
                                     Integer.toString(mxxxRemoteService.sumabc(5, 5, 5)));    
       } catch (RemoteException e) {
            e.printStackTrace();
       }
   }
  }
  
  public void onServiceDisconnected(ComponentName name) 
  {
   if(mxxxService != null)
   {
       mxxxService = null;
   }
   else
   {
       mxxxRemoteService = null;
   }
  }
 };
//activity=======   
 public void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
     
            mContext              = ServiceDemo.this;
         mTextView             = (TextView)findViewById(R.id.text);
         mremoteTextView       = (TextView)findViewById(R.id.remotetext);
         startServiceButton    = (Button)findViewById(R.id.startservice);
         stopServiceButton     = (Button)findViewById(R.id.stopservice);
         bindServiceButton     = (Button)findViewById(R.id.bindservice);
         unbindServiceButton   = (Button)findViewById(R.id.unbindservice);
         remotebindServiceButton   = (Button)findViewById(R.id.remotebindservice);
         remoteunbindServiceButton = (Button)findViewById(R.id.remoteunbindservice);
         musicbroadcastButton      = (Button)findViewById(R.id.musicbroadcast);
          
         startServiceButton.setOnClickListener(this);
         stopServiceButton.setOnClickListener(this);
         bindServiceButton.setOnClickListener(this);
         unbindServiceButton.setOnClickListener(this);
         remotebindServiceButton.setOnClickListener(this);
         remoteunbindServiceButton.setOnClickListener(this);
         musicbroadcastButton.setOnClickListener(this);
        }
   
 public void onClick(View v) 
 {
  if(v == startServiceButton)
  {
   Intent i  = new Intent();
   i.setClass(ServiceDemo.this, xxxService.class);
   mContext.startService(i);
  }
  else if(v == stopServiceButton)
  {
   Intent i  = new Intent();
   i.setClass(ServiceDemo.this, xxxService.class);
   mContext.stopService(i);
  }
  else if(v == bindServiceButton)
  {
   Intent i  = new Intent();
   i.setClass(ServiceDemo.this, xxxService.class);
   mContext.bindService(i, mServiceConnection, BIND_AUTO_CREATE);
  }
  else if(v == unbindServiceButton)
  {
   if( mServiceConnection != null)
   {
       mContext.unbindService(mServiceConnection);
   }
  }
  else if(v == remotebindServiceButton)
  {
   Intent i  = new Intent();
   i.setClass(ServiceDemo.this, xxxRemoteService.class);
   mContext.bindService(i, mServiceConnection, BIND_AUTO_CREATE);
  }
  else if(v == remoteunbindServiceButton)
  {
   if( mServiceConnection != null)
   {
       mContext.unbindService(mServiceConnection);
       mremoteTextView.setText("");
   }
  }
  else if(v == musicbroadcastButton)
  {
    Intent i  = new Intent();
    i.setAction("com.wandroid.servicedemo.Play_MUSIC");
    sendBroadcast(i);
  }
 }  
}
xxxService.java
package com.wandroid.servicedemo;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

public class xxxService extends Service 
{
 private static final String TAG = "xxxService";
 
 //bindService()時,建立connection用
 public class xxxBinder extends Binder
 {
     xxxService getService()
     {
  Log.e(TAG, "===getService()===");
  return xxxService.this;
     }
 }

 private xxxBinder mxxxBinder = new xxxBinder();
 
 @Override
 public IBinder onBind(Intent intent) 
        {
  Log.e(TAG, "===onBind===");
  return mxxxBinder;
 }

 @Override
 public boolean onUnbind(Intent intent) 
        {
  Log.e(TAG, "===onUnbind===");
  return super.onUnbind(intent);
 }

//===由startService啟動只會用到以下三個 
 @Override
 public void onCreate() 
        {
  Log.e(TAG, "===onCreate===");
  super.onCreate();
 }
 
 //由bindService啟動,就沒有onStart()
 @Override
 public void onStart(Intent intent, int startId) 
        {
  Log.e(TAG, "===onStart===");
  super.onStart(intent, startId); 
 }
 
 @Override
 public void onDestroy() 
        {
  Log.e(TAG, "===onDestroy===");
  super.onDestroy();
 } 
//service function==== 
 public int sum(int a, int b) throws RemoteException 
 {
  Log.e(TAG, "===sum()===");
  return a+b;
        }
}
xxxRemoteService.java
package com.wandroid.servicedemo;

import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

public class xxxRemoteService extends Service 
{
 private static final String TAG = "xxxRemoteService";
 private MediaPlayer  mp         = null;
 
 private final IxxxRemoteService.Stub binder= new IxxxRemoteService.Stub()
 {    
            public int sumabc(int a, int b, int c) throws RemoteException 
     {
  Log.e(TAG, "===remote sumabc()===");
                mp = MediaPlayer.create(xxxRemoteService.this, R.raw.music);
                mp.start();
  return a+b+c;
            }
 };
 
 @Override
 public IBinder onBind(Intent arg0) 
 {
     Log.e(TAG, "===remote onBind()===");
            return this.binder; 
 }
 
 @Override
 public boolean onUnbind(Intent intent) 
        {
     Log.e(TAG, "===remote onUnbind()===");
     mp.stop();  
     return super.onUnbind(intent);
 }

//===由startService啟動只會用到以下三個 
 @Override
 public void onCreate() 
        {
     Log.e(TAG, "===remote onCreate()===");
     super.onCreate();
 }
 
 //由bindService啟動,就沒有onStart()
 @Override
 public void onStart(Intent intent, int startId) 
        {
  Log.e(TAG, "===remote onStart()===");
  super.onStart(intent, startId); 
 }
 
 @Override
 public void onDestroy() 
        {
  Log.e(TAG, "===remote onDestroy()===");
  mp.release();
  super.onDestroy();
 } 
}
IxxxRemoteService.aidl
package com.wandroid.servicedemo;

interface IxxxRemoteService 
{
   int sumabc(int a, int b,int c);
}
xxxBroadcastReceiver.java
package com.wandroid.servicedemo; 
  
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
  
public class xxxBroadcastReceiver extends BroadcastReceiver 
{ 
    private static final String TAG = "xxxBroadcastReceiver";
  
    private IxxxRemoteService mxxxRemoteService = null;
  
    private ServiceConnection mServiceConnection = new ServiceConnection() 
    { 
 public void onServiceConnected(ComponentName name, IBinder service) 
 {
     mxxxRemoteService =  IxxxRemoteService.Stub.asInterface(service);
     try {
  mxxxRemoteService.sumabc(5, 5, 5);    
     } 
            catch (RemoteException e) 
            {
         e.printStackTrace();
            }
 }
   
 public void onServiceDisconnected(ComponentName name) 
 {
     mxxxRemoteService = null;
 }
    };
  
    @Override
    public void onReceive(Context context, Intent intent) 
    {
 Log.e(TAG, "===onReceive()===");
 if(intent.getAction().equals("com.wandroid.servicedemo.Play_MUSIC"))
 {
     Intent i  = new Intent();
     //i.setClass(context, xxxRemoteService.class);
     //context.bindService(i, mServiceConnection, BIND_AUTO_CREATE);
     i.setClass(context, xxxService.class);
     context.startService(i);
 }
    }
}

2010年11月12日 星期五

[轉]Android学习笔记之mainfest文件中android属性


以前的零散笔记, 共享一下, 有错误的地方还请指正。

android:allowTaskReparenting

是否允许activity更换从属的任务,比如从短信息任务 切换到浏览器任务。
--------------------------------------------------------------------------------------
android:alwaysRetainTaskState

是否保留状态不变, 比如切换回home, 再从新打开, activity处于最后的状态
--------------------------------------------------------------------------------------
android:clearTaskOnLanunch

比如 P 是 activity, Q 是被P 触发的 activity, 然后返回Home, 从新启动 P, 是否显示 Q
--------------------------------------------------------------------------------------
android:configChanges

当配置list发生修改时, 是否调用 onConfigurationChanged() 方法  比如 "locale|navigation|orientation".
--------------------------------------------------------------------------------------

android:enabled

activity 是否可以被实例化,
--------------------------------------------------------------------------------------

android:excludeFromRecents

是否可被显示在最近打开的activity列表里
--------------------------------------------------------------------------------------
android:exported

是否允许activity被其它程序调用
--------------------------------------------------------------------------------------
android:finishOnTaskLaunch

是否关闭已打开的activity当用户重新启动这个任务的时候
--------------------------------------------------------------------------------------
android.icon
--------------------------------------------------------------------------------------
android:label
--------------------------------------------------------------------------------------
android:launchMode

activity启动方式,  "standard" "singleTop"  "singleTask" "singleInstance"  其中前两个为一组, 后两个为一组
--------------------------------------------------------------------------------------

android:multiprocess
允许多进程
--------------------------------------------------------------------------------------
android:name

activity的类名, 必须指定

--------------------------------------------------------------------------------------
android:onHistory
是否需要移除这个activity当用户切换到其他屏幕时。 这个属性是 API level 3 中引入的
--------------------------------------------------------------------------------------

android:permission
--------------------------------------------------------------------------------------
android:process
一个activity运行时所在的进程名, 所有程序组件运行在应用程序默认的进程中,这个进程名跟应用程序的包名一致。<application>中的元素process属性能够为所有组件设定一个新的默认值。但是任何组件都可以覆盖这个默认值,允许你将你的程序放在多进程中运行。  如果这个属性被分配的名字以:开头, 当这个activity运行时, 一个新的专属于这个程序的进程将会被创建。 如果这个进程名以小写字母开头, 这个activity将会运行在全局的进程中,被它的许可所提供。
--------------------------------------------------------------------------------------

android:screenOrientation

activity显示的模式,  "unspecified" 默认值  "landscape" 风景画模式,宽度比高度大一些  "portrait" 肖像模式, 高度比宽度大。  "user" 用户的设置  "behind"  "sensor" "nosensor"

--------------------------------------------------------------------------------------

android:stateNotNeeded

是否 activity被销毁和成功重启并不保存状态

--------------------------------------------------------------------------------------

android:taskAffinity

activity的亲属关系, 默认情况同一个应用程序下的activity有相同的关系

--------------------------------------------------------------------------------------

android:theme

activity的样式主题, 如果没有设置,则activity的主题样式从属于应用程序, 参见<application>元素的theme属性
--------------------------------------------------------------------------------------

android:windowSoftInputMode

activity主窗口与软键盘的交互模式, 自从API level 3 被引入



本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/k7sem/archive/2009/09/07/4527250.aspx

2010年11月11日 星期四

Surveyor

Project:   Surveyor
Product:  NAS ( Network Attached Storage )
Solution: Marvell 88F6180 BSP





































Patch
patch_rootfs.sh
#!/bin/sh

. ./scripts/build_subr.sh

#cd ${TOPDIR}/rootfs/dev 
#mknod /dev/nfs b 0 255

touch ${TOPDIR}/rootfs/etc/resolv.conf
chmod 644 ${TOPDIR}/rootfs/etc/resolv.conf

cp ${TOPDIR}/patch/sysconf/services ${TOPDIR}/rootfs/etc

cp ${TOPDIR}/patch/sysconf/smb.conf ${TOPDIR}/rootfs/etc

cp ${TOPDIR}/patch/sysconf/issue ${TOPDIR}/rootfs/etc

cp ${TOPDIR}/patch/sysconf/group ${TOPDIR}/rootfs/etc

cp ${TOPDIR}/patch/sysconf/passwd ${TOPDIR}/rootfs/etc

cp ${TOPDIR}/patch/sysconf/fstab ${TOPDIR}/rootfs/etc

cp ${TOPDIR}/patch/sysconf/inittab.patch ${TOPDIR}/rootfs/etc
cd ${TOPDIR}/rootfs/etc
patch -p0 < inittab.patch
rm -f inittab.patch

chmod 644 ${TOPDIR}/rootfs/etc/inittab ${TOPDIR}/rootfs/etc/fstab

cp -f ${TOPDIR}/patch/sysconf/rcS ${TOPDIR}/rootfs/etc/init.d

mkdir ${TOPDIR}/rootfs/tmp ${TOPDIR}/rootfs/mnt ${TOPDIR}/rootfs/sys
chmod 1777 ${TOPDIR}/rootfs/tmp

mkdir ${TOPDIR}/rootfs/var/lib ${TOPDIR}/rootfs/var/log ${TOPDIR}/rootfs/var/run ${TOPDIR}/rootfs/var/tmp  
chmod 1777 ${TOPDIR}/rootfs/var/tmp

mkdir ${TOPDIR}/rootfs/syrmnt ${TOPDIR}/rootfs/smbmnt

mknod ${TOPDIR}/rootfs/dev/FLK_gpio c 254 0

echo "Done"
patch_server.sh
#!/bin/sh

. ./scripts/build_subr.sh

echo "===start server==="
echo "**此script必須在pwd=/home/surveyor/rootfs下執行 ./scripts/patch_server.sh**"
echo "1. roofs放在/home/surveyor下"
echo "2. uImage放在/home/surveyor/kernel/linux-2.6.22.18-bin下"
echo "3. 請先安裝dhcp-3.0.6-12.fc8"
echo "4. 請先安裝tftp-0.42-5-fc8"
echo "5. 請先安裝nfs-utils-1.1.0-6.fc8"
echo "6. 請先安裝squashfs-tools"
echo "7. 更改uboot env,請參照.../patch/fedora8/uboot_env.conf"

echo "Setting IP"
ifdown eth0
ifconfig eth0 192.168.1.100
ifup eth0

echo "Satrting DHCP"
cp -f ${TOPDIR}/patch/fedora8/dhcpd.conf /etc
/etc/init.d/dhcpd restart

echo "Satrting TFTP"
cp -f ${TOPDIR}/patch/fedora8/tftp /etc/xinetd.d
service xinetd restart

echo "Satrting NFS"
cp -f ${TOPDIR}/patch/fedora8/exports /etc/
/etc/init.d/rpcbind restart
/etc/init.d/nfs restart

echo "Install squashfs"
modprobe squashfs

echo "===Down==="
build_squashfs.sh
#! /bin/sh

. ./scripts/build_subr.sh

today=`date +%Y%m%d`

mksquashfs ./rootfs ./rootfs.image/rootfs.$today.sqfs

chmod +r ./rootfs.image/rootfs.$today.sqfs

cp -f ./rootfs.image/rootfs.$today.sqfs /home/surveyor/kernel/linux-2.6.22.18-bin


Host Env
dhcpd.conf
#
# DHCP Server Configuration file.
#   see /usr/share/doc/dhcp*/dhcpd.conf.sample  
#

ddns-update-style interim;
ignore client-updates;
allow bootp;

subnet 192.168.1.0 netmask 255.255.255.0 {

 range dynamic-bootp 192.168.1.50 192.168.1.60;
 default-lease-time 21600;
 max-lease-time 43200;

      host surveyor {
           hardware ethernet 00:50:43:52:02:29;
           fixed-address 192.168.1.99;
           next-server 192.168.1.3;
           filename "uImage";
           option root-path "/home/surveyor/rootfs/rootfs";
        }

}
exports
/home/surveyor/rootfs/rootfs *(rw,no_root_squash)
tftp
# default: off
# description: The tftp server serves files using the trivial file transfer \
# protocol.  The tftp protocol is often used to boot diskless \
# workstations, download configuration files to network-aware printers, \
# and to start the installation process for some operating systems.
service tftp
{
 socket_type  = dgram
 protocol  = udp
 wait   = yes
 user   = root
 server  = /usr/sbin/in.tftpd
 server_args  = -c -s /home/surveyor/kernel/linux-2.6.22.18-bin
# disable  = yes
 per_source  = 11
 cps   = 100 2
 flags   = IPv4
}
Uboot Env
nfs_boot:
setenv console 'console=ttyS0,115200'
setenv bootargs '$(console) $(bootargs_root) ip=dhcp nfsroot=192.168.1.100:/home/surveyor/rootfs/rootfs'
setenv bootcmd 'nand read 0x2000000 0x300000 0x300000;setenv bootargs $(console) $(mtdparts) $(bootargs_root) ip=dhcp nfsroot=192.168.1.100:/home/surveyor/rootfs/rootfs; bootm 0x2000000;'
setenv ipaddr '192.168.1.99'
setenv serverip '192.168.1.100'

mtd_boot:
setenv mtdid 'nand0=nand_mtd'
setenv mtdparts 'mtdparts=nand_mtd:0x100000@0(uboot)ro,0x100000@0x100000(system1),0x100000@0x200000(system2),0x300000@0x300000(kernel)ro,0x700000@0x600000(RootFS)ro'
setenv bootcmd 'nand read 0x2000000 0x300000 0x300000 ;setenv bootargs $(console) ip=dhcp $(mtdparts) rootfstype=squashfs root=/dev/mtdblock5;bootm 0x2000000;'
setenv console 'console=ttyS0,115200'
setenv ipaddr '192.168.1.99'
setenv serverip '192.168.1.100'

burn to flash:
tftpboot 0x1000000 uImage.20090514
nand erase 0x300000 0x300000
nand write 0x1000000 0x300000 0x300000

tftpboot 0x1000000 rootfs.20090514.sqsh
nand erase 0x600000 0x700000
nand write 0x1000000 0x600000 0x700000
Intergrate BSP
fstab
#/dev/nfs   /          nfs       defaults         0    0
proc       /proc      proc      defaults         0    0
devpts     /dev/pts   devpts    gid=4,mode=620   0    0
sysfs      /sys       sysfs     defaults         0    0
group
root:x:0:root
nobody:x:500:
inittab.patch
--- inittab 2005-12-18 18:52:42.000000000 +0800
+++ inittab.new 2009-05-09 10:41:44.000000000 +0800
@@ -1,6 +1,38 @@
+#/**+===========================================================================
+#File: inittab
+#
+#Description: be parsed for /sbin/init 
+#
+#Revision: V1.0
+#
+#History: 
+#+------------------+-------------+--------------------------------------------+
+#|  date         |   author   |       comments                  |
+#+------------------+-------------+--------------------------------------------+
+#| 2009/05/06    | Wade Chiu  |        Initial build                 |
+#+------------------+-------------+--------------------------------------------+
+#
+#-------------------------------------------------------------------------------
+#** Cheng Uei Precision Industry CONFIDENTIAL
+#** Copyright(C) 2009 Uei Precision Industry Co., Ltd. All Rights Reserved.
+#**
+#** The source code contained or described herein and all documents related
+#** to the source code (Material) are owned by Cheng Uei.
+#** The Material is protected by worldwide copyright and trade secret laws and
+#** treaty provisions. No part of the Material may be used, copied, reproduced,
+#** modified, published, uploaded, posted, transmitted, distributed, or disclosed
+#** in any way without Cheng Uei prior express written permission.
+#============================================================================+*/
+
+#==========================================
+# sysinit script
+#==========================================
 ::sysinit:/etc/init.d/rcS
-::respawn:-/bin/sh
-#::respawn:-/bin/sh
-#tty2::askfirst:-/bin/sh
-#::ctrlaltdel:/bin/umount -a -r
+
+#==========================================
+# respawn
+#==========================================
+# Put a getty on the serial port
+ttyS0::respawn:/sbin/getty -L ttyS0 115200 vt100
+
issue
Foxlink NAS release 1 (Serveyor)
passwd
root:$1$$oCLuEVgI1iAqOA8pwkzAg1:0:0:root:/root:/bin/sh
nobody:x:500:500:Linux User,,,:/home/nobody:/bin/sh
rcS
#!/bin/bash

echo "Mounting file system"
/bin/mount -a

ifconfig | head -n 1 | awk '{print $5}' | awk '{FS=":"} {print "RPL"$4$5$6}' | xargs hostname

#execute flk_main_program

echo "Mounting shares"
ntfs-3g -o rw,noatime,nodirtime,remove_hiberfile,streams_interface=windows /dev/sda1 /tmp > /dev/null 2>&1

echo "allow_restart"
echo 1 > /sys/block/sda/device/scsi_disk*/allow_restart

echo "Starting telnet"
/usr/sbin/telnetd -f /etc/issue

echo "Starting samba"
/sbin/nmbd -D -s/etc/smb.conf 
/sbin/smbd -D -s/etc/smb.conf
services
# /etc/services:
# $Id: services,v 1.1 2004/10/09 02:49:18 andersen Exp $
#
# Network services, Internet style
#
# Note that it is presently the policy of IANA to assign a single well-known
# port number for both TCP and UDP; hence, most entries here have two entries
# even if the protocol doesn't support UDP operations.
# Updated from RFC 1700, ``Assigned Numbers'' (October 1994).  Not all ports
# are included, only the more common ones.

tcpmux  1/tcp    # TCP port service multiplexer
echo  7/tcp
echo  7/udp
discard  9/tcp  sink null
discard  9/udp  sink null
systat  11/tcp  users
daytime  13/tcp
daytime  13/udp
netstat  15/tcp
qotd  17/tcp  quote
msp  18/tcp    # message send protocol
msp  18/udp    # message send protocol
chargen  19/tcp  ttytst source
chargen  19/udp  ttytst source
ftp-data 20/tcp
ftp  21/tcp
ssh  22/tcp    # SSH Remote Login Protocol
ssh  22/udp    # SSH Remote Login Protocol
telnet  23/tcp
# 24 - private
smtp  25/tcp  mail
# 26 - unassigned
time  37/tcp  timserver
time  37/udp  timserver
rlp  39/udp  resource # resource location
nameserver 42/tcp  name  # IEN 116
whois  43/tcp  nicname
re-mail-ck 50/tcp    # Remote Mail Checking Protocol
re-mail-ck 50/udp    # Remote Mail Checking Protocol
domain  53/tcp  nameserver # name-domain server
domain  53/udp  nameserver
mtp  57/tcp    # deprecated
bootps  67/tcp    # BOOTP server
bootps  67/udp
bootpc  68/tcp    # BOOTP client
bootpc  68/udp
tftp  69/udp
gopher  70/tcp    # Internet Gopher
gopher  70/udp
rje  77/tcp  netrjs
finger  79/tcp
www  80/tcp  http  # WorldWideWeb HTTP
www  80/udp    # HyperText Transfer Protocol
link  87/tcp  ttylink
kerberos 88/tcp  kerberos5 krb5 # Kerberos v5
kerberos 88/udp  kerberos5 krb5 # Kerberos v5
supdup  95/tcp
# 100 - reserved
hostnames 101/tcp  hostname # usually from sri-nic
iso-tsap 102/tcp  tsap  # part of ISODE.
csnet-ns 105/tcp  cso-ns  # also used by CSO name server
csnet-ns 105/udp  cso-ns
# unfortunately the poppassd (Eudora) uses a port which has already
# been assigned to a different service. We list the poppassd as an
# alias here. This should work for programs asking for this service.
# (due to a bug in inetd the 3com-tsmux line is disabled)
#3com-tsmux 106/tcp  poppassd
#3com-tsmux 106/udp  poppassd
rtelnet  107/tcp    # Remote Telnet
rtelnet  107/udp
pop-2  109/tcp  postoffice # POP version 2
pop-2  109/udp
pop-3  110/tcp    # POP version 3
pop-3  110/udp
sunrpc  111/tcp  portmapper # RPC 4.0 portmapper TCP
sunrpc  111/udp  portmapper # RPC 4.0 portmapper UDP
auth  113/tcp  authentication tap ident
sftp  115/tcp
uucp-path 117/tcp
nntp  119/tcp  readnews untp # USENET News Transfer Protocol
ntp  123/tcp
ntp  123/udp    # Network Time Protocol
netbios-ns 137/tcp    # NETBIOS Name Service
netbios-ns 137/udp
netbios-dgm 138/tcp    # NETBIOS Datagram Service
netbios-dgm 138/udp
netbios-ssn 139/tcp    # NETBIOS session service
netbios-ssn 139/udp
swat  901/tcp
imap2  143/tcp    # Interim Mail Access Proto v2
imap2  143/udp
snmp  161/udp    # Simple Net Mgmt Proto
snmp-trap 162/udp  snmptrap # Traps for SNMP
cmip-man 163/tcp    # ISO mgmt over IP (CMOT)
cmip-man 163/udp
cmip-agent 164/tcp
cmip-agent 164/udp
xdmcp  177/tcp    # X Display Mgr. Control Proto
xdmcp  177/udp
nextstep 178/tcp  NeXTStep NextStep # NeXTStep window
nextstep 178/udp  NeXTStep NextStep # server
bgp  179/tcp    # Border Gateway Proto.
bgp  179/udp
prospero 191/tcp    # Cliff Neuman's Prospero
prospero 191/udp
irc  194/tcp    # Internet Relay Chat
irc  194/udp
smux  199/tcp    # SNMP Unix Multiplexer
smux  199/udp
at-rtmp  201/tcp    # AppleTalk routing
at-rtmp  201/udp
at-nbp  202/tcp    # AppleTalk name binding
at-nbp  202/udp
at-echo  204/tcp    # AppleTalk echo
at-echo  204/udp
at-zis  206/tcp    # AppleTalk zone information
at-zis  206/udp
qmtp  209/tcp    # The Quick Mail Transfer Protocol
qmtp  209/udp    # The Quick Mail Transfer Protocol
z3950  210/tcp  wais  # NISO Z39.50 database
z3950  210/udp  wais
ipx  213/tcp    # IPX
ipx  213/udp
imap3  220/tcp    # Interactive Mail Access
imap3  220/udp    # Protocol v3
ulistserv 372/tcp    # UNIX Listserv
ulistserv 372/udp
https  443/tcp    # MCom
https  443/udp    # MCom
snpp  444/tcp    # Simple Network Paging Protocol
snpp  444/udp    # Simple Network Paging Protocol
saft  487/tcp    # Simple Asynchronous File Transfer
saft  487/udp    # Simple Asynchronous File Transfer
npmp-local 610/tcp  dqs313_qmaster # npmp-local / DQS
npmp-local 610/udp  dqs313_qmaster # npmp-local / DQS
npmp-gui 611/tcp  dqs313_execd # npmp-gui / DQS
npmp-gui 611/udp  dqs313_execd # npmp-gui / DQS
hmmp-ind 612/tcp  dqs313_intercell# HMMP Indication / DQS
hmmp-ind 612/udp  dqs313_intercell# HMMP Indication / DQS
#
# UNIX specific services
#
exec  512/tcp
biff  512/udp  comsat
login  513/tcp
who  513/udp  whod
shell  514/tcp  cmd  # no passwords used
syslog  514/udp
printer  515/tcp  spooler  # line printer spooler
talk  517/udp
ntalk  518/udp
route  520/udp  router routed # RIP
timed  525/udp  timeserver
tempo  526/tcp  newdate
courier  530/tcp  rpc
conference 531/tcp  chat
netnews  532/tcp  readnews
netwall  533/udp    # -for emergency broadcasts
uucp  540/tcp  uucpd  # uucp daemon
afpovertcp 548/tcp    # AFP over TCP
afpovertcp 548/udp    # AFP over TCP
remotefs 556/tcp  rfs_server rfs # Brunhoff remote filesystem
klogin  543/tcp    # Kerberized `rlogin' (v5)
kshell  544/tcp  krcmd  # Kerberized `rsh' (v5)
kerberos-adm 749/tcp    # Kerberos `kadmin' (v5)
#
webster  765/tcp    # Network dictionary
webster  765/udp
#
# From ``Assigned Numbers'':
#
#> The Registered Ports are not controlled by the IANA and on most systems
#> can be used by ordinary user processes or programs executed by ordinary
#> users.
#
#> Ports are used in the TCP [45,106] to name the ends of logical
#> connections which carry long term conversations.  For the purpose of
#> providing services to unknown callers, a service contact port is
#> defined.  This list specifies the port used by the server process as its
#> contact port.  While the IANA can not control uses of these ports it
#> does register or list uses of these ports as a convienence to the
#> community.
#
nfsdstatus 1110/tcp
nfsd-keepalive 1110/udp

ingreslock 1524/tcp
ingreslock 1524/udp
prospero-np 1525/tcp   # Prospero non-privileged
prospero-np 1525/udp
datametrics 1645/tcp old-radius # datametrics / old radius entry
datametrics 1645/udp old-radius # datametrics / old radius entry
sa-msg-port 1646/tcp old-radacct # sa-msg-port / old radacct entry
sa-msg-port 1646/udp old-radacct # sa-msg-port / old radacct entry
radius  1812/tcp   # Radius
radius  1812/udp   # Radius
radacct  1813/tcp   # Radius Accounting
radacct  1813/udp   # Radius Accounting
nfsd  2049/tcp nfs
nfsd  2049/udp nfs
cvspserver 2401/tcp   # CVS client/server operations
cvspserver 2401/udp   # CVS client/server operations
mysql  3306/tcp   # MySQL
mysql  3306/udp   # MySQL
rfe  5002/tcp   # Radio Free Ethernet
rfe  5002/udp   # Actually uses UDP only
cfengine 5308/tcp   # CFengine
cfengine 5308/udp   # CFengine
bbs  7000/tcp   # BBS service
#
#
# Kerberos (Project Athena/MIT) services
# Note that these are for Kerberos v4, and are unofficial.  Sites running
# v4 should uncomment these and comment out the v5 entries above.
#
kerberos4 750/udp  kerberos-iv kdc # Kerberos (server) udp
kerberos4 750/tcp  kerberos-iv kdc # Kerberos (server) tcp
kerberos_master 751/udp    # Kerberos authentication
kerberos_master 751/tcp    # Kerberos authentication
passwd_server 752/udp    # Kerberos passwd server
krb_prop 754/tcp    # Kerberos slave propagation
krbupdate 760/tcp  kreg  # Kerberos registration
kpasswd  761/tcp  kpwd  # Kerberos "passwd"
kpop  1109/tcp   # Pop with Kerberos
knetd  2053/tcp   # Kerberos de-multiplexor
zephyr-srv 2102/udp   # Zephyr server
zephyr-clt 2103/udp   # Zephyr serv-hm connection
zephyr-hm 2104/udp   # Zephyr hostmanager
eklogin  2105/tcp   # Kerberos encrypted rlogin
#
# Unofficial but necessary (for NetBSD) services
#
supfilesrv 871/tcp    # SUP server
supfiledbg 1127/tcp   # SUP debugging
#
# Datagram Delivery Protocol services
#
rtmp  1/ddp    # Routing Table Maintenance Protocol
nbp  2/ddp    # Name Binding Protocol
echo  4/ddp    # AppleTalk Echo Protocol
zip  6/ddp    # Zone Information Protocol
#
# Services added for the Debian GNU/Linux distribution
poppassd 106/tcp    # Eudora
poppassd 106/udp    # Eudora
mailq  174/tcp    # Mailer transport queue for Zmailer
mailq  174/tcp    # Mailer transport queue for Zmailer
omirr  808/tcp  omirrd  # online mirror
omirr  808/udp  omirrd  # online mirror
rmtcfg  1236/tcp   # Gracilis Packeten remote config server
xtel  1313/tcp   # french minitel
coda_opcons 1355/udp   # Coda opcons            (Coda fs)
coda_venus 1363/udp   # Coda venus             (Coda fs)
coda_auth 1357/udp   # Coda auth              (Coda fs)
coda_udpsrv 1359/udp   # Coda udpsrv            (Coda fs)
coda_filesrv 1361/udp   # Coda filesrv           (Coda fs)
codacon  1423/tcp venus.cmu # Coda Console           (Coda fs)
coda_aux1 1431/tcp   # coda auxiliary service (Coda fs)
coda_aux1 1431/udp   # coda auxiliary service (Coda fs)
coda_aux2 1433/tcp   # coda auxiliary service (Coda fs)
coda_aux2 1433/udp   # coda auxiliary service (Coda fs)
coda_aux3 1435/tcp   # coda auxiliary service (Coda fs)
coda_aux3 1435/udp   # coda auxiliary service (Coda fs)
cfinger  2003/tcp   # GNU Finger
afbackup 2988/tcp   # Afbackup system
afbackup 2988/udp   # Afbackup system
icp  3130/tcp   # Internet Cache Protocol (Squid)
icp  3130/udp   # Internet Cache Protocol (Squid)
postgres 5432/tcp   # POSTGRES
postgres 5432/udp   # POSTGRES
fax  4557/tcp   # FAX transmission service        (old)
hylafax  4559/tcp   # HylaFAX client-server protocol  (new)
noclog  5354/tcp   # noclogd with TCP (nocol)
noclog  5354/udp   # noclogd with UDP (nocol)
hostmon  5355/tcp   # hostmon uses TCP (nocol)
hostmon  5355/udp   # hostmon uses TCP (nocol)
ircd  6667/tcp   # Internet Relay Chat
ircd  6667/udp   # Internet Relay Chat
webcache 8080/tcp   # WWW caching service
webcache 8080/udp   # WWW caching service
tproxy  8081/tcp   # Transparent Proxy
tproxy  8081/udp   # Transparent Proxy
mandelspawn 9359/udp mandelbrot # network mandelbrot
amanda  10080/udp   # amanda backup services
amandaidx 10082/tcp   # amanda backup services
amidxtape 10083/tcp   # amanda backup services
isdnlog  20011/tcp   # isdn logging system
isdnlog  20011/udp   # isdn logging system
vboxd  20012/tcp   # voice box system
vboxd  20012/udp   # voice box system
binkp           24554/tcp   # Binkley
binkp           24554/udp   # Binkley
asp  27374/tcp   # Address Search Protocol
asp  27374/udp   # Address Search Protocol
tfido           60177/tcp   # Ifmail
tfido           60177/udp   # Ifmail
fido            60179/tcp   # Ifmail
fido            60179/udp   # Ifmail

# Local services
smb.conf
[global]
server string      =  FLKNAS
workgroup          =  SEAGATEGROUP
log file           =  /private/%L.log
max log size       =  1024
security           =  share
smb passwd file    =  /private/smbpasswd
private dir        =  /private
dns proxy          =  No
lock directory     =  /private/locks
pid directory      =  /private/locks
client lanman auth =  yes
use sendfile       =  yes
vfs objects        =  streams_xattr

[tmp]
path=/tmp
read only=no
public=yes
Porting Server
build_ntfs-3g.sh
#!/bin/sh

. ./scripts/build_subr.sh

rm -rf ${INSTALLDIR}
mkdir -p ${INSTALLDIR}
unpack "ntfs-3g-2009.4.4"
SRC="build/ntfs-3g-2009.4.4"

cd ${TOPDIR}/${SRC}

export  LD_LIBARY_PATH=${CROSS_COMPILE}/lib
export  CPPFLAGS=-I${CROSS_COMPILE}/include
export  LDFLAGS=-L${CROSS_COMPILE}/lib
export  CC=${CROSS_COMPILE}-gcc
export  PATH=${PATH}:${TOPDIR}/tools/gcc/bin

./configure --host=arm-linux --prefix=${INSTALLDIR} --exec-prefix=${INSTALLDIR}

make
check_errno

make install
check_errno

cd ${INSTALLDIR}/..

tar -jc -f ${TOPDIR}/pkg/softfp/ntfs-3g-2009.4.4.full-bin.tar.bz2 ${ROOTFS}
check_errno

mv ${INSTALLDIR}/share ${INSTALLDIR}/share.qq
rm -rf ${INSTALLDIR}/share.qq 

#rm -f ${INSTALLDIR}/bin/ntfs-3g.probe

mv ${INSTALLDIR}/lib/pkgconfig ${INSTALLDIR}/lib/pkgconfig.qq
rm -rf ${INSTALLDIR}/lib/pkgconfig.qq

mv ${INSTALLDIR}/include ${INSTALLDIR}/include.qq
rm -rf ${INSTALLDIR}/include.qq

mv ${INSTALLDIR}/sbin ${INSTALLDIR}/sbin.qq
rm -rf ${INSTALLDIR}/sbin.qq 

tar -jc -f ${TOPDIR}/pkg/softfp/ntfs-3g-2009.4.4-bin.tar.bz2 ${ROOTFS} 
check_errno

mv ${TOPDIR}/build ${TOPDIR}/build.qq
mkdir -p ${TOPDIR}/build
rm -rf ${TOPDIR}/build.qq &

mv ${TOPDIR}/tmp ${TOPDIR}/tmp.qq
mkdir -p ${TOPDIR}/tmp
rm -rf ${TOPDIR}/tmp.qq &   

cd ${TOPDIR}
build_samba.sh
#!/bin/sh

. ./scripts/build_subr.sh

rm -rf ${INSTALLDIR}
mkdir -p ${INSTALLDIR}
unpack "samba-3.3.4"
SRC="build/samba-3.3.4/source"

cp -f ${TOPDIR}/patch/samba-3.3.4/configure.patch ${TOPDIR}/${SRC}
cp -f ${TOPDIR}/patch/samba-3.3.4/mtab.c.patch ${TOPDIR}/${SRC}/client

cd ${TOPDIR}/${SRC}
patch -p0 < configure.patch

cd ${TOPDIR}/${SRC}/client
patch -p0 < mtab.c.patch

cd ..

export  LD_LIBARY_PATH=${CROSS_COMPILE}/lib
export  CPPFLAGS=-I${CROSS_COMPILE}/include
export  LDFLAGS=-L${CROSS_COMPILE}/lib
export  CC=${CROSS_COMPILE}-gcc
export  PATH=${PATH}:${TOPDIR}/tools/gcc/bin

export samba_cv_CC_NEGATIVE_ENUM_VALUES=yes
export libreplace_cv_READDIR_GETDIRENTRIES=no
export libreplace_cv_READDIR_GETDENTS=no
export linux_getgrouplist_ok=no
export samba_cv_HAVE_WRFILE_KEYTAB=yes
export samba_cv_HAVE_KERNEL_OPLOCKS_LINUX=yes
export samba_cv_HAVE_IFACE_IFCONF=yes

./configure --build=i686-linux --host=arm-linux --target=arm-linux --prefix=${INSTALLDIR} --disable-shared --disable-cups --disable-iprint --disable-pie --disable-fam --without-ldap

cp -f ${TOPDIR}/patch/samba-3.3.4/config.h ${TOPDIR}/${SRC}/include

make
check_errno

make install
check_errno

cd ${INSTALLDIR}/..

tar -jc -f ${TOPDIR}/pkg/softfp/samba-3.3.4.full-bin.tar.bz2 ${ROOTFS} 
check_errno

mv ${INSTALLDIR}/swat ${INSTALLDIR}/swat.qq
rm -rf ${INSTALLDIR}/swat.qq

mv ${INSTALLDIR}/share ${INSTALLDIR}/share.qq
rm -rf ${INSTALLDIR}/share.qq 

rm -f ${INSTALLDIR}/sbin/mount.cifs
rm -f ${INSTALLDIR}/sbin/swat
rm -f ${INSTALLDIR}/sbin/umount.cifs
rm -f ${INSTALLDIR}/sbin/winbindd

mv ${INSTALLDIR}/lib ${INSTALLDIR}/lib.qq
rm -rf ${INSTALLDIR}/lib.qq

mv ${INSTALLDIR}/include ${INSTALLDIR}/include.qq
rm -rf ${INSTALLDIR}/include.qq

mv ${INSTALLDIR}/bin ${INSTALLDIR}/bin.qq
rm -rf ${INSTALLDIR}/bin.qq 

tar -jc -f ${TOPDIR}/pkg/softfp/samba-3.3.4-bin.tar.bz2 ${ROOTFS} 
check_errno

mv ${TOPDIR}/build ${TOPDIR}/build.qq
mkdir -p ${TOPDIR}/build
rm -rf ${TOPDIR}/build.qq &

mv ${TOPDIR}/tmp ${TOPDIR}/tmp.qq
mkdir -p ${TOPDIR}/tmp
rm -rf ${TOPDIR}/tmp.qq &   

cd ${TOPDIR}
configure.patch
--- configure 2009-04-29 02:53:51.000000000 +0800
+++ configure.new 2009-05-05 16:23:23.000000000 +0800
@@ -13066,13 +13066,17 @@
 else
 
     if test "$cross_compiling" = yes; then
-  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&5
-$as_echo "$as_me: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }; }
+#  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+#$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+#{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
+#See \`config.log' for more details." >&5
+#$as_echo "$as_me: error: cannot run test program while cross compiling
+#See \`config.log' for more details." >&2;}
+#   { (exit 1); exit 1; }; }; }
+{
+echo "$as_me:$LINENO: uclibc <= samba 3.3.4 check skipped" >&5
+echo "$as_me: uclibc <= samba 3.3.4 check skipped" >&2;
+}
 else
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
@@ -23586,12 +23590,12 @@
 
 /* Override any GCC internal prototype to avoid an error.
    Use char because int might match the return type of a GCC
-   builtin and then its argument prototype would still apply.  */
+   builtin and then its argument prototype would st cannot run test program while cross compilingill apply.  */
 #ifdef __cplusplus
 extern "C"
 #endif
 char $ac_func ();
-/* The GNU C library defines this for functions which it implements
+/* The GNU C library defines this for functions whi cannot run test program while cross compilingch it implements
     to always fail with ENOSYS.  Some functions are actually named
     something starting with __ and the normal name is an alias.  */
 #if defined __stub_$ac_func || defined __stub___$ac_func
@@ -23801,13 +23805,17 @@
 else
 
  if test "$cross_compiling" = yes; then
-  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&5
-$as_echo "$as_me: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }; }
+#  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+#$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+#{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
+#See \`config.log' for more details." >&5
+#$as_echo "$as_me: error: cannot run test program while cross compiling
+#See \`config.log' for more details." >&2;}
+#   { (exit 1); exit 1; }; }; }
+{
+echo "$as_me:$LINENO: glibc <= samba 3.3.4 check skipped" >&5
+echo "$as_me: glibc <= samba 3.3.4 check skipped" >&2;
+}
 else
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
@@ -23989,13 +23997,17 @@
 else
 
  if test "$cross_compiling" = yes; then
-  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&5
-$as_echo "$as_me: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }; }
+#  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+#$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+#{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
+#See \`config.log' for more details." >&5
+#$as_echo "$as_me: error: cannot run test program while cross compiling
+#See \`config.log' for more details." >&2;}
+#   { (exit 1); exit 1; }; }; }
+{
+echo "$as_me:$LINENO: glibc <= samba 3.3.4 check skipped" >&5
+echo "$as_me: glibc <= samba 3.3.4 check skipped" >&2;
+}   
 else
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
@@ -44068,13 +44080,17 @@
     *linux*)
        # glibc <= 2.3.2 has a broken getgrouplist
        if test "$cross_compiling" = yes; then
-  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&5
-$as_echo "$as_me: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }; }
+#  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+#$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+#{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
+#See \`config.log' for more details." >&5
+#$as_echo "$as_me: error: cannot run test program while cross compiling
+#See \`config.log' for more details." >&2;}
+#   { (exit 1); exit 1; }; }; }
+{
+echo "$as_me:$LINENO: glibc <= samba 3.3.4 check skipped" >&5
+echo "$as_me: glibc <= samba 3.3.4 check skipped" >&2;
+}   
 else
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
@@ -67118,13 +67134,17 @@
 else
 
     if test "$cross_compiling" = yes; then
-  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&5
-$as_echo "$as_me: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }; }
+#  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+#$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+#{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
+#See \`config.log' for more details." >&5
+#$as_echo "$as_me: error: cannot run test program while cross compiling
+#See \`config.log' for more details." >&2;}
+#   { (exit 1); exit 1; }; }; }
+{
+echo "$as_me:$LINENO: glibc <= samba 3.3.4 check skipped" >&5
+echo "$as_me: glibc <= samba 3.3.4 check skipped" >&2;
+}   
 else
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
@@ -67393,13 +67413,17 @@
  LDFLAGS="$LDFLAGS";
  export LDFLAGS;
  if test "$cross_compiling" = yes; then
-  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&5
-$as_echo "$as_me: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }; }
+#  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+#$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+#{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
+#See \`config.log' for more details." >&5
+#$as_echo "$as_me: error: cannot run test program while cross compiling
+#See \`config.log' for more details." >&2;}
+#   { (exit 1); exit 1; }; }; }
+{
+echo "$as_me:$LINENO: glibc <= samba 3.3.4 check skipped" >&5
+echo "$as_me: glibc <= samba 3.3.4 check skipped" >&2;
+}   
 else
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
@@ -67494,13 +67518,17 @@
  LDFLAGS="$LDFLAGS";
  export LDFLAGS;
  if test "$cross_compiling" = yes; then
-  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&5
-$as_echo "$as_me: error: cannot run test program while cross compiling
-See \`config.log' for more details." >&2;}
-   { (exit 1); exit 1; }; }; }
+#  { { $as_echo "$as_me:$LINENO: error: in \`$ac_pwd':" >&5
+#$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
+#{ { $as_echo "$as_me:$LINENO: error: cannot run test program while cross compiling
+#See \`config.log' for more details." >&5
+#$as_echo "$as_me: error: cannot run test program while cross compiling
+#See \`config.log' for more details." >&2;}
+#   { (exit 1); exit 1; }; }; }
+{
+echo "$as_me:$LINENO: glibc <= samba 3.3.4 check skipped" >&5
+echo "$as_me: glibc <= samba 3.3.4 check skipped" >&2;
+}   
 else
   cat >conftest.$ac_ext <<_ACEOF
 /* confdefs.h.  */
mtab.c.patch
--- mtab.c 2009-04-28 14:46:16.000000000 +0800
+++ mtab.c.new 2009-05-05 16:25:33.000000000 +0800
@@ -34,6 +34,8 @@
 #include <sys/time.h>
 #include <time.h>
 #include <fcntl.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <mntent.h>
 #include <stdlib.h>
 #include <signal.h>
Application
netlink_udev.c
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <ctype.h> 
#include <sys/un.h> 
#include <sys/ioctl.h> 
#include <sys/socket.h> 
#include <linux/types.h> 
#include <linux/netlink.h> 
#include <errno.h> 
#include <unistd.h> 
#include <arpa/inet.h> 
#include <netinet/in.h> 

#define UEVENT_BUFFER_SIZE 2048 

static int init_hotplug_sock() 
{ 
    const int buffersize = 1024; 
    int ret; 

    struct sockaddr_nl snl; 
    bzero(&snl, sizeof(struct sockaddr_nl)); 
    snl.nl_family = AF_NETLINK; 
    snl.nl_pid = getpid(); 
    snl.nl_groups = 1; 

    int s = socket(PF_NETLINK, SOCK_DGRAM, NETLINK_KOBJECT_UEVENT); 
    if (s == -1)  
    { 
        perror("socket"); 
        return -1; 
    } 
    setsockopt(s, SOL_SOCKET, SO_RCVBUF, &buffersize, sizeof(buffersize)); 

    ret = bind(s, (struct sockaddr *)&snl, sizeof(struct sockaddr_nl)); 
    if (ret < 0)  
    { 
        perror("bind"); 
        close(s); 
        return -1; 
    } 

    return s; 
} 

int main(int argc, char* argv[]) 
{ 
   int hotplug_sock = init_hotplug_sock(); 
  
    while(1) 
    { 
      /* Netlink message buffer */ 
        char buf[UEVENT_BUFFER_SIZE * 2] = {0}; 
        recv(hotplug_sock, &buf, sizeof(buf), 0); 
        printf("%s\n", buf); 
    } 
    return 0; 
}
scsi_serial.c
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <scsi/sg.h>

#define SCSI_TIMEOUT 5000 /* ms */

static char *device  = "/dev/sdd";

int scsi_io(int fd, unsigned char *cdb, unsigned char cdb_size, int xfer_dir, 
            unsigned char *data, unsigned int *data_size, 
            unsigned char *sense, unsigned int *sense_len)
{
    sg_io_hdr_t io_hdr;

    memset(&io_hdr, 0, sizeof(sg_io_hdr_t));
    io_hdr.interface_id = 'S';

    /* CDB */
    io_hdr.cmdp = cdb;
    io_hdr.cmd_len = cdb_size;

    /* Where to store the sense_data, if there was an error */
    io_hdr.sbp = sense;
    io_hdr.mx_sb_len = *sense_len;
    *sense_len=0;

    /* Transfer direction, either in or out. Linux does not yet
       support bidirectional SCSI transfers ?
     */
    io_hdr.dxfer_direction = xfer_dir;

    /* Where to store the DATA IN/OUT from the device and how big the
       buffer is
     */
    io_hdr.dxferp = data;
    io_hdr.dxfer_len = *data_size;

    /* SCSI timeout in ms */
    io_hdr.timeout = SCSI_TIMEOUT;

    if(ioctl(fd, SG_IO, &io_hdr) < 0){
        perror("SG_IO ioctl failed");
        return -1;
    }

    /* now for the error processing */
    if((io_hdr.info & SG_INFO_OK_MASK) != SG_INFO_OK){
        if(io_hdr.sb_len_wr > 0){
            *sense_len=io_hdr.sb_len_wr;
            return 0;
        }
    }
    if(io_hdr.masked_status){
        printf("status=0x%x\n", io_hdr.status);
        printf("masked_status=0x%x\n", io_hdr.masked_status);
        return -2;
    }
    if(io_hdr.host_status){
        printf("host_status=0x%x\n", io_hdr.host_status);
        return -3;
    }
    if(io_hdr.driver_status){
        printf("driver_status=0x%x\n", io_hdr.driver_status);
        return -4;
    }
    return 0;
}

int scsi_inquiry_unit_serial_number(int fd)
{
    unsigned char cdb[]={0x12,0x01,0x80,0,0,0};

    unsigned int data_size=0x00ff;
    unsigned char data[data_size];

    unsigned int sense_len=32;
    unsigned char sense[sense_len];

    int res, pl, i;

    cdb[3]=(data_size>>8)&0xff;
    cdb[4]=data_size&0xff;


    printf("INQUIRY Unit Serial Number:\n");

    res=scsi_io(fd, cdb, sizeof(cdb), SG_DXFER_FROM_DEV, data, &data_size, sense, &sense_len);
    if(res){
        printf("SCSI_IO failed\n");
        return -1;
    }
    if(sense_len){
        return -1;
    }

    /* Page Length */
    pl=data[3];

    /* Unit Serial Number */
    printf("Unit Serial Number:");
    for(i=4;i<(pl+4);i++)printf("%c",data[i]&0xff);printf("\n");
    return 0;
}

int open_scsi_device(const char *dev)
{
    int fd, vers;

    if((fd=open(dev, O_RDWR))<0){
        printf("ERROR could not open device %s\n", dev);
        return -1;
    }
    if ((ioctl(fd, SG_GET_VERSION_NUM, &vers) < 0) || (vers < 30000)) {
        printf("/dev is not an sg device, or old sg driver\n");
        close(fd);
        return -1;
    }

    return fd;
}

int main(int argc, const char *argv[])
{
    int fd;

    fd=open_scsi_device(device);
    if(fd<0){
        printf("Could not open SCSI device %s\n",device);
        _exit(10);
    }

    scsi_inquiry_unit_serial_number(fd);
    return 0;
}
FSinotify.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/file.h>
#include <sys/sysinfo.h>
#include <sys/epoll.h>
#include <signal.h>
#include <linux/inotify.h>
#include <net/if.h>
#include <netinet/in.h>
 
struct queue_struct
{
    int capacity;
    int front;
    int rear;
    int size;
    void **array;
};
 
struct queue_struct;
typedef struct queue_struct *queue_t;
 
int queue_empty (queue_t q)
{
    return q->size == 0;
}
 
int queue_full (queue_t q)
{
    return q->size == q->capacity;
}


void queue_make_empty (queue_t q)
{
    q->size = 0;
    q->front = 1;
    q->rear = 0;
}
 
queue_t queue_create (int num_elements)
{
    queue_t q;
 
    q = malloc (sizeof (struct queue_struct));
 
    if (q == NULL)
        exit (-1);
 
    q->array = malloc(sizeof (void *) * num_elements);
 
    if (q->array == NULL)
        exit (-1);
 
    q->capacity = num_elements;
 
    queue_make_empty (q);
 
    return q;
}
 
void queue_destroy (queue_t q)
{
    if (q != NULL)
    {
        if (q->array)
            free (q->array);
 
        free (q);
    }
}
 
 
static int next_position (int v, queue_t q)
{
    if (++v == q->capacity) {
        v = 0;
    }
 
    return v;
}
 
void queue_enqueue (void *d, queue_t q)
{
    if (queue_full (q))
    {
        return;
    }
 
    q->size++;
    q->rear = next_position (q->rear, q);
    q->array[q->rear] = d;
}
 
void *queue_front (queue_t q)
{
    if (!queue_empty(q))
        return q->array [q->front];
 
    return NULL;
}
 
void queue_dequeue (queue_t q)
{
    if (!queue_empty (q))
    {
        q->size--;
        q->front = next_position (q->front, q);
    }
}
 
/* This method does the dirty work of determining what happened,
then allows us to act appropriately
*/
void handle_event (struct inotify_event *event)
{
    /* If the event was associated with a filename, we will store it here */
    char * cur_event_filename = NULL;
    /* This is the watch descriptor the event occurred on */
    int cur_event_wd = event->wd;
    if (event->len)
    {
        cur_event_filename = event->name;
    }
    printf("FILENAME=%s\n", cur_event_filename);
    printf("watch descriptor=%d\n",cur_event_wd);
    printf("\n");
    /* Perform event dependent handler routines */
    /* The mask is the magic that tells us what file operation occurred */
    switch (event->mask)
    {
    /* File was accessed */
    case IN_ACCESS:
        printf("ACCESS EVENT OCCURRED: File \"%s\" on WD #%i\n",
        cur_event_filename, cur_event_wd);
    break;
    /* File was modified */
    case IN_MODIFY:
        printf("MODIFY EVENT OCCURRED: File \"%s\" on WD #%i\n",
        cur_event_filename, cur_event_wd);
    break;
    /* File changed attributes */
    case IN_ATTRIB:
        printf("ATTRIB EVENT OCCURRED: File \"%s\" on WD #%i\n",
        cur_event_filename, cur_event_wd);
    break;
    /* File was closed */
    case IN_CLOSE:
        printf("CLOSE EVENT OCCURRED: File \"%s\" on WD #%i\n",
    cur_event_filename, cur_event_wd);
    break;
    /* File was opened */
    case IN_OPEN:
    printf("OPEN EVENT OCCURRED: File \"%s\" on WD #%i\n",
    cur_event_filename, cur_event_wd);
    break;
    /* File was moved from X */
    case IN_MOVED_FROM:
        printf("MOVE_FROM EVENT OCCURRED: File \"%s\" on WD #%i\n",
        cur_event_filename, cur_event_wd);
    break;
    /* File was moved to X */
    case IN_MOVED_TO:
        printf("MOVE_TO EVENT OCCURRED: File \"%s\" on WD #%i\n",
        cur_event_filename, cur_event_wd);
    break;
    /* Watched entry was deleted */
    case IN_DELETE_SELF:
        printf("DELETE_SELF EVENT OCCURRED: File \"%s\" on WD #%i\n",
        cur_event_filename, cur_event_wd);
    break;
    /* Backing FS was unmounted */
    case IN_UNMOUNT:
        printf("UNMOUNT EVENT OCCURRED: File \"%s\" on WD #%i\n",
        cur_event_filename, cur_event_wd);
    break;
    /* Too many FS events were received without reading them
    some event notifications were potentially lost. */
    case IN_Q_OVERFLOW:
        printf("Warning: AN OVERFLOW EVENT OCCURRED: \n");
        break;
    case IN_IGNORED:
        printf("IGNORED EVENT OCCURRED: \n");
    break;
    /* Some unknown message received */
    default:
    printf ("UNKNOWN EVENT OCCURRED for file \"%s\" on WD #%i\n",
    cur_event_filename, cur_event_wd);
    break;
    }
}
 
void handle_events (queue_t q)
{
    struct inotify_event *event;
    while (!queue_empty (q))
    {
        event = queue_front (q);
        queue_dequeue (q);
        handle_event (event);
        free (event);
    }
}
 
int event_check (int fd)
{
    struct timeval timeout;
    int r;
    fd_set rfds;
 
    timeout.tv_sec = 4;
    timeout.tv_usec = 0;
 
    FD_ZERO(&rfds);
    FD_SET(fd, &rfds);
 
    r = select (fd+1, &rfds, NULL, NULL, &timeout);
 
    return r;
}
 
int read_events (queue_t q, int fd)
{
    char buffer[16384];
    size_t buffer_i;
    struct inotify_event *pevent, *event;
    ssize_t r;
    size_t event_size;
    int count = 0;
 
    r = read (fd, buffer, 16384);
 
    if (r <= 0)
        return r;
 
    buffer_i = 0;
    while (buffer_i < r)
    {
        /* Parse events and queue them ! */
        pevent = (struct inotify_event *)&buffer[buffer_i];
        event_size = sizeof(struct inotify_event) + pevent->len;
        event = malloc(event_size);
        memmove(event, pevent, event_size);
        queue_enqueue(event, q);
        buffer_i += event_size;
        count++;
    }
 
    return count;
}
 
int process_inotify_events (queue_t q, int iid)
{
    while (1)
    {
        if( !queue_empty(q) )
        {
            handle_events(q);
        }
        if (event_check(iid) > 0)
        {
            int r;
            r = read_events(q, iid);
            if (r < 0)
                break;
        }
    }
    return 0;
}
 
int main()
{
    queue_t q;
    int     iid;
    int     wd;
    
    q    = queue_create(128);
    iid = inotify_init(); 
    wd   = inotify_add_watch(iid,"/home/test/", IN_CLOSE_WRITE );
    process_inotify_events(q,iid);
  
    queue_destroy(q);
    close(iid);
    return 0;
}




主要工作小結
1. 架設版本控制平台 SVN
2. 專案版本控制管理

3. 專案開發環境架設 fedora8及其BSP環境

4. 管理與整合BSP

5.  build imagerelease版本

6. 應用程式開發



心得

1. 更熟析embedded linux
2. 熟西建構root file system
3. 對linux system programming有一定的了解