2012年12月16日 星期日

Objective-C 的精隨

There's three traits that differ objective-C with other object oriented language. They are sort of related but i will introduce them one by one.

Polymorphism: 

Well different class sure can have same name class methods. This is not much different with other object-orient language but will cause much confuse in pure C. But this feature will be very important if combine with following two other objective-c only feature.

 Dynamic Typing:

This together with polymorphism will make codes more reusable since return type and parameters types no longer fixed. This can enables run-time determined object types to call same name methods which can invoke different method calls. ex.
//assume Fraction and Complex class all defined Print but  show different format
id classobj;
aFraction * = [Fraction new];
aComplex *=[Complex new];
classobj = aFraction;
[classobj Print];
classobj = aComplex;
[classobj Print];

Well this is not significantly showing how Dynamic Typing's goodness. But pass attention that id object's method call is determined at runtime by which type of object it contains. This is highly not possible for other language.

Dynamic Binding

This feature means an object can determined at runtime which method it will invoke under circumstances at that time. Introduce selector concept and @selector directive. example as below
SEL action;
id graphicobject;
...
action = @selector (draw) ;
...
[graphicobject performSelector:action];

This will also introduce a series of method that under NSObject the perform support for dynamic typing and dynamic binding feature.

-(BOOL) isKindOfClass:class-object
-(BOOL) isMemberOfClass:class-object
-(BOOL) respondsToSelector:selector
-(BOOL) instancesRespondToSelector:selector
-(BOOL) isSubclassOfClass:class-object
-(id)performSelector:selector
-(id)performSelector:selector withObject:object
-(id)performSelector:selector withObject:object1 withObject:object2

2012年12月4日 星期二

Xcode 快捷鍵


轉載自http://www.cnblogs.com/yjmyzz/archive/2011/01/25/1944325.html
1. 文件
CMD + N: 新文件
CMD + SHIFT + N: 新项目
CMD + O: 打开
CMD + S: 保存
CMD + SHIFT + S: 另存为
CMD + W: 关闭窗口
CMD + SHIFT + W: 关闭文件

2. 编辑

CMD + [: 左缩进
CMD + ]: 右缩进

CMD + CTRL + LEFT: 折叠
CMD + CTRL + RIGHT: 取消折叠
CMD + CTRL + TOP: 折叠全部函数
CMD + CTRL + BOTTOM: 取消全部函数折叠
CTRL + U: 取消全部折叠

CMD + D: 添加书签
CMD + /: 注释或取消注释

CTRL + .: 参数提示
ESC: 自动提示列表

3. 调试

CMD + \: 设置或取消断点
CMD + OPT + \: 允许或禁用当前断点
CMD + OPT + B: 查看全部断点

CMD + RETURN: 编译并运行(根据设置决定是否启用断点)
CMD + R: 编译并运行(不触发断点)
CMD + Y: 编译并调试(触发断点)
CMD + SHIFT + RETURN: 终止运行或调试

CMD + B: 编译
CMD + SHIFT + K: 清理

4. 窗体

CMD + SHIFT + B: 编译窗口
CMD + SHIFT + Y: 调试代码窗口
CMD + SHIFT + R: 调试控制台
CMD + SHIFT + E: 主编辑窗口调整

5. 帮助

CMD + OPT + ?: 开发手册
CMD + CTRL + ?: 快速帮助
下面也是一些有用的快捷键(转自http://www.cppblog.com/brucejini/archive/2010/12/24/137367.html)

Command + Shift + E :扩展编辑器
Command + [ :左移代码块
Command + ] :右移代码块
Tab :接受代码提示
Esc :显示代码提示菜单
Ctrl + . (句点):循环浏览代码提示
Shift + Ctrl + . (句点):反向循环浏览代码提示
Ctrl + / :移动到代码提示中的下一个占位符
Command + Ctrl + S :创建快照
Ctrl + F :前移光标
Ctrl + B :后移光标
Ctrl + P :移动光标到上一行
Ctrl + N:移动光标到下一行
Ctrl + A : 移动光标到本行行首
Ctrl + E : 移动光标到本行行尾 --杨过注:这二个太有用了,刚开始用XCode,一直奇怪为啥Home与End键为啥不能直接定位到行首、行尾?
Ctrl + T :交换光标左右两边的字符
Ctrl + D:删除光标右边的字符
Ctrl + K :删除本行
Ctrl + L : 将插入点置于窗口正中
Command + Alt + D:显示open quickly 窗口
Command + Alt + 上方向键 :打开配套文件
Command + D :添加书签
Option + 双击:在文档中搜索
Command + Y :以调试方式运行程序
Command + Alt + P : 继续(在调试中)
Command + Alt + 0 :跳过
Command + Alt + I :跳入
Command + Alt + T :跳出

2012年9月21日 星期五

How to include and make use of .uni files to your EDKII/UDK applications.

Well. Today i need to build up a helper to my efi application. I check for the sample in network package. I found one way. Steps as below.


  1.  put all your helper text into a uni file. for example: myhelp.uni
  2. add myhelp.uni to [Sources]. This will trigger the HII compiler to autogen related HII data structure.
  3. Initialize your HII handle with HiiAddPackages                                                                mHiiHandle = HiiAddPackages (&gEfiCallerIdGuid, ImageHandle, BASE_NAMEStrings, NULL);                                                                                         IMPORTANT! the third parameter should be your BASE_NAME in your inf file with "Strings" appended. This is due to autogen will use this fixed variable name.
  4. You can use ShellPrintHiiEx function to display Messages.                                           ShellPrintHiiEx (-1, -1, NULL, STRING_TOKEN (STR_PING6_INVALID_INPUT), mHiiHandle);

2012年7月12日 星期四

While Secure Boot Active run Shell Application

As you know, secure boot is one of the crucial features that MS Win8 emphasize on. To protect the entire system since the boot time. Albeit secure boot feature is not explicitly exclude tradition CSM, but current IBV implementation put secure boot under CSMless mode. This will lead to user can not boot from USB dongle into DOS to access traditional tools like IRU or flash rom. Instead, UEFI shell kick in. But there's some tricky steps to enable boot to UEFI shell when secure boot enable.

  • You need to generate a certificate. To achieve this, you need to install latest Windows Kit. Under it's install directory find an executable file named "makecert.exe" depend on your working computer's X86 or X64. execute following command.


makecert -n "CN=PkRoot" -r -sv PkRoot.pvk PkRoot.cer
You can replace "PkRoot" whatever name you like. This will generate a private key and a certificate. Remember the password you type.
  • Then proceed to generate Kek key and certificate using the platform key you just generated.
makecert -n "CN= KekRoot " -iv PkRoot.pvk -ic PkRoot.cer -sv KekRoot.pvk KekRoot.cer
Also memorize Kek key password. It will be used to sign efi applications.

  • Transform kek private key to pfx format (PKCS#12)
pvk2pfx.exe –pvk KekRoot.pvk –pi xxx –spc KekRoot.cer –pfx KekRoot.pfx –f
xxx is the password for kek private key.

  • Now you can use KekRoot.cer and KekRoot.pfx to sign whatever efi application or driver you want to execute on your platform. Command as below.
SignTool.exe sign /ac KekRoot.cer /f KekRoot.pfx /p xxx /fd sha256 MyDriver.efi
xxx still be password of Kekroot.pvk

But there's one VERY critical step left.

  • You need to include the KekRoot.cer to your BIOS image and put it in ALLOW certificate. Different IBV should probably have different ways to include ALLOW certificate. You should check with your IBV for detail.
Ok. Now you can run your shell applications in your USB CFD. Remember that the first application you should sign is your bootIA32.efi/bootX64.efi! Enjoy!

2012年5月1日 星期二

Objective C 學習隨記(三)

Category (類目)

class 觀念的延伸, 對於一個class的methods, 你可以分成不同的category, 然後在不同的實作檔定義, 這對大型的專案共同開發同一個class很有用, 另一個好處是可以加入新的方法到一個class而不會影響修改到原有的定義

實作方法例如:
in 2dops.m

@interface GraphicObject (2Dops)
-(void)drawObject:(GraphicObject*) gb;
-(void)moveObject:(GraphicObject*) gb:(int) x:(int) y;
@end

in 3dops.m

@interface GraphicObject(3Dops)
-(void)rorateObject:(GraphicObject*) gb: (int) x-axis: (int) y-axis;
@end

另有無命名的category, 其實作必須要跟class 的實作在同一個實作檔案

Protocol(協定)

objC可以宣告介面, 宣告方式如下
@protocol ProtocolName
-(id) protocolmethods: (ParameterType) Para1;
@end

class如果要conform此protocol, 就要實作protocolmethod

在class宣告地方
@interface classname:NSObject <ProtocolName>

method 實作方法跟class method一樣

2012年4月25日 星期三

Objective C 學習隨記(二)

objC 跟C 雖然是很類似的程式語言, 但是用慣了C 寫一些firmware的人要轉學objC 還是有一些觀念要適應一下! 下面介紹的就是一個objC專有的語法, 如果能靈活運用, 將省去不少重複的程式

同名異式

動態型別

動態連結

其實這三個觀念都環繞著一個特殊的資料型態 "id"

最根本的原因是objC裡, object type並不是在compiling type決定,而是在runtime決定

一個以id 宣告為type的物件, 它的type內容是可變的
例如


id mathobj;

Fraction *aFrac = [Fraction alloc] init];

Complex *bComp = [[Complex alloc] init];
mathobj = aFrac;
[mathobj print];
mathobj = bComp;
[mathobj print];

因為有繼承這個objC主要功能的關係, 很多物件都相互有同名的method, 當然內容可能各不一樣, 就可以用id這種型態, 動態呼叫不同的物件同名method

這部分又衍生一些檢查的功能
例如檢查這個class 的selector (method) 是否存在
selector是以SEL為type的物件
運用方法如下例

SEL action;
id graphicobject
...
action = @selector(draw)
...
[graphicobject performSelector: action];

也就是說selector可以動態選擇要執行的method


Try & Catch 例外處理

objC的exception 處理方式:
把有可能發生exception的程式段以
@try{
...
}
包起來

後面在撰寫處理程序
@catch(NSException exception){
...
}

@finally 是不管有沒有丟出exception都會執行的程式區

@throw可以自己丟出exception


2012年4月22日 星期日

Objective C 學習隨記(一)

最近因為Iphone4s 很熱, 開始對這Apple劃時代的產品產生興趣, apple跳脫舊科技公司產品的思維, 賣的不只是冰冷的硬體, 他還創造了一個ecosystem方便軟體工程師可以很方便的從開發環境到測試最後到線上銷售, 一條龍不需要太大的進入門檻, 這無疑讓軟體設計師可以不需要自組一個公司處理銷售服務, 完全只需要發揮創意! 想想台灣雖然身為科技島, 但是全都偏向代工, 對於創新的產業著墨不深, 當apple 和 google相繼開發出軟體開發平台, 這無疑的對台灣產業轉型, 提供一個最佳的機會, 畢竟創意才是科技的根本 

Ok 轉回主題, 不管是iphone還是ipad, 都是在apple公司開發的iOS上跑, 而iOS是從MacOSX 針對embedded device最佳化修改成的OS, 等同於Android是google基於linux 架構針對embedded device修改而成, 當然apple為了增加它應用程式(俗稱apps)的多樣性, 它徹底揚棄Microsoft對於開發人員設定的門檻, 這不得不說MS的失策, MS早在2000年初就進入smartphone的市場, 當時smartphone幾乎是MS獨佔, MS對每隻smartphone收的loyalty 超高, 加上MS對於Visual Studio收費真是高的嚇人, 所以會去開發它win ce apps的很少, 造成買了device卻沒甚麼apps可用的窘境, 一直到現在window mobile還在垂死掙扎, 就不多批評了.

不管iOS或Mac OSX應用程式都是用同一套開發工具,是免費的Xcode, 現在最新版本是4.0 , 使用的程式語言是objective C 這系列主要就是我讀一本書 "Programming in Objective-C" 4th edition的一些筆記 

objective-C 應該說是C的進化物件導向版本, 觀念非常像C++ class inherit 的觀念

 class宣告 

@interface Classname : NSobject //:NSObject 代表繼承於NSObject 
@property int a,b; //
@property代表 a跟b的 setter 和 getter由compiler自動產生, 要和implementation理加@synthesize a,b; 
-(return type) methodname:(type)para1:(type)para2;
@end 

class定義 

@implementation Classname
@synthesize a,b;
-(type) methodname: (type)para1:(type)para2 

 //statements 
}
 @end

 一般在實做class時要先allocate,再init 格式是
[[classname alloc] init] [classname alloc]會回傳一個class instance, 再呼叫class instance的init功能 也可以用 [classname new] 取代上述

2012年3月5日 星期一

Blt function in GOP driver

Blt function is one of the three functions defined in UEFI GOP driver spec. And it is the only function that actually perform the draw operations. It has 4 operation modes.

  1. EfiBltVideoFill: Fill the rectangle of (DestinationX,DestinationY) to (DestinationX+Width,DestinationY+Height) wih BltBuffer pixel (0,0), only 1 pixel in BltBuffer is used.
  2. EfiBltVideoToBltBuffer: Read data from Video Buffer to BltBuffer (delta is used here)
  3. EfiBltBufferToVideo: Write data from BltBuffer to Video Buffer
  4. EfiBltVideoToVideo: Copy data from a rectangle in the VideoBuffer to another position in the VideoBuffer (BltBuffer and delta not used) 
One thing need to pay attention: Before doing memory operation, should raise TPL to avoid interrupted by timer event)

2012年2月13日 星期一

LTV > CPA ?

Mr.Jamie 提到的一個觀念 創業最重要的公式 LTV > CPA
提高LTV
降低CPA
LTV (life time value) 代表的是每一個customer 在你的服務期間的總和花費, 如果你提供的是一個有形的產品, 那期間就代表產品的生命週期, value就是產品的價格, 如果提供的是一種服務, 那期間就代表服務的期限, value就是服務的收費


CPA (cost per acquisition) 代表爭取到一個客戶所要的花費, 這不只是產品的生產成本, 還包括廣告行銷投入的成本與客戶回應比率


而在創業期間第一優先的目標就是 LTV > CPA , 達到這條件之後, 每多一個customer得到的profit才是正的, 爭取更多的客戶才有意義

2012年2月10日 星期五

EFI GOP Driver

GOP (Graphic Output Protocol) driver 是 EFI架構下取代傳統VBIOS 黑箱的 EFI Driver, 另外for embedded system bootloader 上的graphic driver叫EPOG(embedded Pre-OS Graphic).

GOP Driver 的共有GUID
#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID \
  {0x9042a9de,0x23dc,0x4a38, \
  0x96,0xfb,0x7a,0xde,0xd0,0x80,0x51,0x6a}
Protocol 主要包含3個function 及 1個data structure

typedef struct EFI_GRAPHICS_OUTPUT_PROTCOL {
  EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE QueryMode;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE   SetMode;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_BLT        Blt;
  EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE       *Mode;
} EFI_GRAPHICS_OUTPUT_PROTOCOL;


  1. QueryMode: Returns information for an available graphics mode that the graphics device and the set of active video output devices supports.(是詢問graphic controller 和 系統所有接上的顯示器所支援的顯示模式)
  2. SetMode:Set the video device into the specified mode and clears the visible portions of the output display to black. 則是設定顯示裝置一個特定的顯示模式
  3. Blt:Software abstraction to draw on the video device’s frame buffer.則是直接透過寫入framebuffer  畫矩形圖片

取材UEFI spec 2.3 chap. 11.9 


2012年2月9日 星期四

SVN branch and merge

前一陣子在ubuntu server上架了svn server 當做自己一些文件及程式版本控管的工具,不過只會用幾個簡單的功能, check out, import , ls commit 而且都是用shell command line下指令, 剛看到一個blog  記一下網址
svn branch and merge

2012年2月7日 星期二

2012年2月6日 星期一

assembly call C function

UEFI BIOS在 SEC進PEI階段會由assembly code 進入C code,
除了設定好stack 外, 就是要注意assembly call C function的方法
會先把參數以反順序的方式push到stack, 然後call PEI的主程式
不過這跟一般的assembly call c function不一樣的是, UEFI BIOS
不會再回到assembly mode, 所以不需要再把esp 調整回來!
一般的assembly call C function要把esp加上參數總共size.
範例如下

global  _main

extern  _printf

section .data

text    db      "291 is the best!", 10, 0
strformat db    "%s", 0

section .code

_main
        push    dword text
        push    dword strformat
        call    _printf
        add     esp, 8
        ret

2012年1月16日 星期一

9 件創業教我的事

轉貼! 要時時提醒自己!
原連結

HitPlay 的創辦人 Joshua Seims 在他的網誌上分享了一篇 9 Things I Learned by Starting a Company,我覺得跟我的經驗非常像,所以今天就從他的 9 個點出發,跟大家聊聊我自己的心得。

1. 恐懼是可以被克服的

創業的恐懼有兩種,一種是不敢面對、害怕丟臉的恐懼,一種是擔心結果不如預期的恐懼。怕丟臉的恐懼讓你裹足不前,不敢嘗試。開始嘗試了,還有害怕失望的恐懼讓你心情忽高忽低,無法冷靜判斷。這兩個好像每顆心與生俱來都會有的弱點,但創業的經驗告訴我它們其實可以被克服。
要克服不敢的恐懼,很簡單,它就像克服酒量一樣,唯一的方法就是一直喝、不斷的喝,喝到什麼最噁心的嘔吐你都經歷過、什麼最慘痛的失敗你都體驗過,然後有一天,你就會發現自己無敵了。要克服害怕失望的恐懼也很簡單,那就是不要有期望。記得幸運的人嗎?當你放棄了既定的目標,那你不但永遠不會失望,還會因此在路上多撿到許多機會,多好!

2. 天長地久不如真的擁有

當你在當員工時,你就像一隻狗、一個奴才。做不好,通通都是你該死。做得好,通通都是老闆英明。而創業和「Ownership」,就是你的解放,讓你真正擁有你在做的事情、真正決定自己的未來。沒有人說這是一件容易的事情,事實上,當員工的話 6 點就下班了,Server 掛掉是你家的事。當老闆,抱歉,永遠沒有鬆懈的一秒鐘,你連作夢都還在想公司的事。但同時,你也擁有那種握住的感覺,那種過自己的人生,而不是幫別人抬轎的踏實感。

3. 為自己負責

既然沒有了老闆,你就被迫要學會獨立作戰、獨立思考,做自己的決定,並且為自己的選擇負責。一開始會有點不習慣,你會發現自己到處問別人的意見,因為我們從小都沒有學過如何「做自己」。不過一旦你開始抓到了絕竅,就會化身為真正自由的個體,這世界雖千萬人,在也沒辦法擋住你要去哪裡。

4. 沒有 Co-founder 是很孤獨的

當你自己一個人挑戰這個世界,即使是心臟再強、臉皮再厚的創業者,也會有無法承受創傷的一天。你需要一些伙伴,一些跟你擁有相同志向的人,才能在最失落的時候,擁有一個背後的靠山。

5. 通路勝過產品

「把產品做出來,他們就會來」是全世界最大的騙局,至少對於 99.9% 的創業者是這樣的。你最重要的武器,是在把產品做出來前,就先開始著手布建一個有效的通路。產品可以一直換,但通路,才是拿不走的東西。

6. 你成功的秘密,當然不是大家都知道的事情

成功的商業模式絕對不是想出來的,當然更不是分析出來的,否則在你之前,早就有 1,000 個人想到了。當你去看歷史上成功的商業模式,基本上全部都是矇到、Pivot 出來的。如果是這樣,那你除了要有超人的分析,還要有超強的「製造意外」能力。

7. 團隊是超級重要的事情

前面 10 個員工,決定了你公司的文化,所以你必須要花很多、是很多時間在這上面。記住:能力可以學,態度則是你無法改變的。千萬不要用兩次面試,就決定了一切。結婚之前,多約幾次會,甚至同居一陣子,搞清楚了彼此的個性,再私訂終身,也還不遲。

8. 名譽才是你最重要的資產

相信我,創業 13 年來,熱錢來來去去、市場起起伏伏、團隊分分合合我看太多了。到最後,每個人在你心中的地位,就只剩他的品德和人格。你要想清楚,這是一場一輩子的賽局,千萬不要為了短期的利益,犧牲了你一輩子的名譽。如果你行得直、坐得正,那就會吸引來一群一樣欣賞這個風格的夥伴,那,才是永遠拿不走,最最重要的資產。

9. 如果你不覺得好玩,那還是別搞了吧

我看過太多人因為「機會很好」,所以創業,但打從心底,他們並不享受這個過程。可惜創業失敗的機率是遠高過成功的,所以這些人往往不但賠了夫人,還回過頭怨恨自己當初的選擇。人生只有一次,創業不但是在建立一個事業,更是在找到自我價值的實現。
Steve Jobs 說的:
每天早上,我看著鏡子然後問我自己:「如果今天是我人生的最後一天,我會想要做我正要去做的事情嗎?」如果答案連續好幾天都是「No」,那我就知道我必須要改變些什麼。
以上,與大家共勉。
PS. 感謝大家支持昨天的一人一信行動,24 小時內,該篇文章累積了 25,000 人次閱覽,並且有 2,000 人因此連結到總統信箱開始寫信,假設最後的轉換率有 20%,那表示我們總共寄出了約 400 封信給馬先生,大大超過了我希望的 100 封,所以算是一次非常成功的行動,也希望我們能夠很快的收到一些正面的回應。

2012年1月11日 星期三

Intrinsic functions

MS provide some intrinsic functions for low level operations (eg. firmware/driver) on their compiler that is very convenience. You don't have to include the any header file to make use of these functions. But you have to specify a compiler option "/Oi".
example:
#progma intrinsic (func1)
#progma intrinsic (func2, func3)

Below are some of intrinsic functions

_disable
_outp
fabs
strcmp
_enable
_outpw
labs
strcpy
_inp
_rotl
memcmp
strlen
_inpw
_rotr
memcpy
_lrotl
_strset
memset
_lrotr
abs
strcat

2012年1月10日 星期二

PCD 類型介紹

主要分為五種類型

  1. FIX_AT_BUILD : 類似C 裡面的const
  2. PATCHABLE_IN_MODULE: 類似EFI裡的variable, 存在flash 裡, 可以用工具程式修改PatchPcdValue.exe GenPatchPcdTable.exe
  3. DYNAMIC: 類似C裡面的變數, 執行期間可修改, 但是關機會消失
  4. DYNAMIC_EX:和DYNAMIC一樣,只是要多傳一個參數 TokenSpaceGuid
  5. FEATURE:用於platform building時用於替代!ifdef !endif 

原文網址

2012年1月9日 星期一

EDK2 image generate stages

Step 1: Process Meta-Files  start from Module Top-level dsc file. Then .fdf files then list of inf files to generate multiple level of makefile
Step 2: Start Compiling with nmake/gunmake recursively to generate COFF/PE32 files then execute GenFW to convert to EFI image files
Step 3. If top-level .dsc file contain define of
            FLASH_DEFINITION = XXXX.fdf
            then will invoke gendfs to generate final image file. If no such definition, step 3 will not go. (For those only hope to generate EFI application or driver, can use -m parameter to specify a XXX.inf which should already be listed in top-level dsc file to only compile that specific module)

2012年1月7日 星期六

EFI 開機碟製作 (UFD)

format UFD to FAT
put shell.efi you build or get from UDK to
\efi\boot\

rename to:
ia32 arch==>bootia32.efi
x64 arch===>bootx64.efi

----------------------------------
another note for edk build command parameter
-a IA32/X64/IPF
-t VS2008/VS2008x86 etc
-b RELEASE/DEBUG
-p platform descriptor file  etc Nt32Pkg\Nt32Pkg.dsc
-m module  build a specific module in platform descriptor
-n CPU thread number (can speed up build time!)
-j logfile.txt specify the logfile
Build tools default use /conf/tools.def.txt to define used tools.
default tools chain is MYTOOLS which direct to VS2008 which you should manually modify if you are using another tools.
If you are going to build Nt32pkg, since this is a simulator on win32 environment. It will link to some window library. Therefore you should setup building environment to a specific by passing a "--nt32" parameter when running DOS batch file edksetup.bat.

2012年1月4日 星期三

MBR and GPT

MBR (Master Boot Record) 舊式 Legacy 時代的啟動磁區
共512 byte
前446 byte 是bootloader code
接著 64byte 紀錄4個 partition table 各 16 byte
最後兩個byte是 0x55AA
單一partition最大2TB

GPT(GUID partition table)
EFI 規格的一部分, 只有EFI BIOS才有支援
GPT  table 以LBA(logical block)為單位 1 LBA = 512 BYTE
LBA 0 是 protective MBR
In the GPT specification, the location corresponding to the MBR in MBR-based disks is structured in a way that prevents MBR-based disk utilities from mis-recognizing, and possibly over-writing, GPT disks. This is referred to as a "protective MBR"  In operating systems that support GPT-based boot, it is also used to store the first stage of the bootloader code. A single partition type of 0xEE, encompassing the entire GPT drive, is indicated and identifies it as GPT. 
LBA 1 Partition Table Header

The partition table header defines the usable blocks on the disk. It also defines the number and size of the partition entries that make up the partition table. On 64-bit Windows Server 2003 machines, 128 partitions can be created. There are 128 partition entries reserved, each 128 bytes long. (The EFI specification requires that a minimum of 16,384 bytes be reserved for the partition table, so this gives space for 128 partition entries.)
The header contains the disk GUID (Globally Unique Identifier). It records its own size and location (always LBA 1) and the size and location of the secondary GPT header and table (always the last sectors on the disk). Importantly, it also contains a CRC32 checksum for itself and for the partition table, which may be verified by the firmware, bootloader and/or operating system on boot. Because of this, hex editors should not be used to modify the contents of the GPT. Such modification would render the checksum invalid. In this case, the primary GPT may be overwritten with the secondary one by disk recovery software. If both GPTs contain invalid checksums, the disk would be unusable.

LBA 2~33
128BYTES per partition 
LBA = 4 Partition 
total 4X32=128 partitions
Each partition cap to 8 ZB

Linux I/O access function

In most  systems, I/O access can divided into 2 schemes.
1. memory map I/O
2. I/O port access
Most desktop/notebook seperate I/O space and memory space. To access via I/O need another instructions
ex. in/out
But for most embedded system, I/O is mapped to memory space.

so we have 2 methods to access external device via I/O depends on the platform you choose.
Here i write down the sequence and function for both I/O access method.

1. Memory access
     request_mem_region() -> ioremap -> readb() writeb() -> iouremap() -> release_mem_region()

2. I/O port access
    request_region() -> inb() outb() -> release_region()

2012年1月2日 星期一

asmlinkage 用法


"asmlinkage" 是在 i386 system call 實作中相當重要的一個 gcc 標籤(tag)。
當 system call handler 要呼叫相對應的 system call routine 時,便將一般用途暫存器的值
push 到 stack裡,因此 system call routine 就要由 stack 來讀取 system call handler 傳遞的
參數。這就是 asmlinkage標籤的用意。
system call handler 是 assembly code,system call routine(例如:sys_nice)是 C code,
當 assembly code 呼叫 C function,並且是以 stack 方式傳參數(parameter)時,
在 C function 的 prototype 前面就要加上 "asmlinkage"。
加上 "asmlinkage" 後,C function 就會由 stack 取參數,而不是從 register 取參數(
可能發生在程式碼最佳化後)。
更進一步的說明...
80x86 的 assembly 有 2 種傳遞參數的方法:
1. register method
2. stack method
Register method 大多使用一般用途(general-purpose)暫存器來傳遞參數,這種
方法的好處是簡單且快速。另外一種傳遞參數的做法是使用 stack(堆疊),
assembly code 的模式如下:
push number1
push number2
push number3
call sum
在 'sum' procedure 裡取值的方法,最簡單的做法是:
pop ax
pop ax
pop bx
pop cx
Stack Top 是放 IP,我們傳給 sum procedure 的參數由 stack 的後一個 entry 開始
讀取。
其它有關 asmlinkage
1. asmlinkage 是一個定義
2. "asmlinkage" 被定義在 /usr/include/linux/linkage.h
3. 如果您看了 linkage.h,會發現 "__attribute__" 這個語法,這是 gcc 用來定義
 function attribute 的語法。
轉貼自Jollen blog

2012年1月1日 星期日

利用find shell command 找檔案

普通用法
find -inamme *.c
這樣會把現在所在目錄下以及子目錄下的.c 檔列在螢幕上
高級用法
可以把輸出轉向到另一個指令的輸入
ex.
find -iname *.c -exec grep -l MEM_LENGH {} \;
會列出所有.c 裡有包含MEM_LENGH的檔案名稱