2010年8月31日 星期二

於EDK中加入DXE Driver

建立好EDK環境後,先找到自己要放置Driver的資料夾,這個例子是放在Sample\Platform\Generic\底下,建立一個TestDriver的資料夾。

依序建立以下檔案:
TestDriver.h
========================================
#ifndef _TEST_DRIVER_H_
#define _TEST_DRIVER_H_

#include "Tiano.h"
#include "EfiDriverLib.h"

//
// Function Prototypes
//
EFI_STATUS
EFIAPI
TestDriverEntry (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
);

#endif
========================================

TestDriver.c
========================================
#include "TestDriver.h"

EFI_DRIVER_ENTRY_POINT (TestDriverEntry)

EFI_STATUS
EFIAPI
TestDriverEntry (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;

Status = EfiInitializeDriverLib(ImageHandle, SystemTable);

DEBUG_CODE (
DEBUG ((EFI_D_INFO | EFI_D_LOAD, "Test = %s\n", L"TestDriverEntry"));
)

return Status;
}
========================================

TestDriver.inf
========================================
[defines]
BASE_NAME = TestDriver
FILE_GUID = 7B257F2E-7177-408a-BA46-567C07301F69
COMPONENT_TYPE = BS_DRIVER

[sources.common]
TestDriver.c

[libraries.common]
EdkGuidLib
EfiGuidLib
EfiProtocolLib
EfiDriverLib

[includes.common]
$(EDK_SOURCE)\Foundation
$(EDK_SOURCE)\Foundation\Efi
$(EDK_SOURCE)\Foundation\Framework
.
$(EDK_SOURCE)\Foundation\Include
$(EDK_SOURCE)\Foundation\Efi\Include
$(EDK_SOURCE)\Foundation\Framework\Include
$(EDK_SOURCE)\Foundation\Include\IndustryStandard
$(EDK_SOURCE)\Foundation\Core\Dxe
$(EDK_SOURCE)\Foundation\Library\Dxe\Include
$(EDK_SOURCE)\Sample\Include

[nmake.common]
IMAGE_ENTRY_POINT=TestDriverEntry
========================================

其中.inf的FILE_GUID可由Visual Studio中的Tools->建立GUID這個工具建立。
加入以上檔案後開啟Sample\Platform\Nt32\Build\Nt32.dsc
找一個地方加入這一行:
Sample\Platform\Generic\Test\TestDriver\TestDriver.inf

範例:
#
# Fat File System driver. Default is binary only
#
Other\Maintained\Universal\Disk\FileSystem\EnhancedFat\Dxe\Fat.inf

# By Yourself
Sample\Platform\Generic\Test\TestDriver\TestDriver.inf

存檔後即可build,此時在Console即可印出剛剛程式中的debug訊息:
EventTest = EventTestDriverEntry

Finish!

沒有留言:

張貼留言