bloggerads

2015年7月26日 星期日

C# 呼叫 VC++ 的dll 檔

fallowing example been tested ok in VC 2010

UEFI 各階段資料的傳遞方式

  將bios 選單變數(ex: SetupData.my_var)傳遞到PEI及DXE的方法


  //
  // PEI 接收資料
  //
  Status = (*PeiServices)->LocatePpi (
                          PeiServices,
                          &gEfiPeiReadOnlyVariablePpiGuid,
                          0,
                          NULL,
                          &ReadOnlyVariable
                          );
                          
  ASSERT_PEI_ERROR (PeiServices, Status);
  VariableSize = sizeof (SETUP_DATA);
  
  Status = ReadOnlyVariable->GetVariable (
                            PeiServices,
                            L"Setup",
                            &gEfiSetupGuid,
                            NULL,
                            &VariableSize,
                            &SetupData
                            );
                            
  if (EFI_ERROR (Status)) 
      return;

SMBios (System Management Bios)

使用者可以透過SMBios知道這台電腦的詳細規格,RW everything / RW這些tool都有提供SMBios data查詢。

SMBios是一份軟體的spec, 他定義了兩個table, 即EPS ( Entry Point structure) 和 Structure Table

EPS位於記憶體1MB以下64K之間,也就是0xF0000 ~ 0xFFFFF之間。透過程式搜尋搜尋_SM_和_DMI_這兩個Keyword可以找到這個table。

以下是 SMBIOS 2.1 (32-bit) Entry Point structure,這邊列出比較重要的部分


Offset
Name
Length
Description
00h
Anchor String
4 BYTEs
_SM_, specified as four ASCII characters (5F 53 4D 5F).
10h
Intermediate Anchor String
5 BYTEs
_DMI_, specified as five ASCII characters (5F 44 4D 49 5F)
16h
Structure Table Length
WORD
Total length of SMBIOS Structure Table, pointed to by the Structure Table Address, in bytes
18h
Structure Table Address
DWORD
32-bit physical starting address of the read-only SMBIOS Structure
1Ch
Number of SMBIOS Structures
WORD
Handle的數量

2015年7月6日 星期一

UEFI : DXE Driver


● 何謂Protocol:  
typedef的結構。在UEFI下會綁定GUID,並且透過Driver來安裝Protocol instancehandle. 上層若要控制device,必須透過呼叫Protocol instance來達成。
● Bus Driver Vs. Device Driver: 
Bus Driver會Create Child handle 但Device Driver不會。如果Bus Driver Create的 Child handle是Physical device, Bus Driver 必須安裝Device Path Protocol instance到Child handle
● Driver Initialization:

Driver Image會從儲存裝置(Rom, flash,...)中載入,也就是說,一旦在儲存裝置中找到Driver Image, 就會使用Boot ServiceLoadImage(), Driver Image載入到System Memory. 同時該driver會生成自己的Handle,並且在該Handle下安裝EFI_LOADED_IMAGE_PROTOCOL

typedef
EFI_STATUS
LoadImage (
  IN BOOLEAN BootPolicy,
  IN EFI_HANDLE ParentImageHandle,
  IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, // The DeviceHandle specific file path from which the image is loaded.
  IN VOID *SourceBuffer OPTIONAL,
  IN UINTN SourceSize,
  OUT EFI_HANDLE *ImageHandle // Pointer to the returned image handle that is created when the image is successfully loaded.
  );


裝了EFI_LOADED_IMAGE_PROTOCOL Handle稱之為Image Handle

接著,透過Boot ServiceStartImage()來啟動driverdriver會在Image Handle上安裝其它的Protocol,如果是EFI Driver Modeldriver,那麼會安裝EFI_DRIVER_BINDING_PROTOCOL, 如下,這時Driver Image才真正被當作Driver來處理

//
// Interface structure for the ControllerHandle Driver Protocol
//
typedef struct _EFI_DRIVER_BINDING_PROTOCOL {
  EFI_DRIVER_BINDING_SUPPORTED  Supported;
  EFI_DRIVER_BINDING_START      Start;
  EFI_DRIVER_BINDING_STOP       Stop;
  UINT32                        Version;
  EFI_HANDLE                    ImageHandle;
  EFI_HANDLE                    DriverBindingHandle;
} EFI_DRIVER_BINDING_PROTOCOL;

LoadImage()StartImage()做完之後driver會等待被Boot ServiceConnectController()調用(invoked)去連接到某個Controller。這時在System Memory中已經Load了很多的Driver都在等待被connect到Controller,這時ConnectController()會以Polling的方式去調用每個Driver Handle中的EFI_DRIVER_BINDING_PROTOCOL.Supported(),如果回EFI_SUCCESS,那麼該driver就會被connectcontroller上。之後會透過EFI_DRIVER_BINDING_PROTOCOL.Start()來初始化以及安裝特定的Protocol到此Controller。