嗨我是k66,承上篇繼續實作OinkBL.c
。目前我遇到問題是Logo的圖案出現花紋與多重影分身(如下圖XD),已於後兩篇克服之~程式碼連結
為使版面不過長,我將一隻OinkBL.c依序拆成以下區塊:
UefiMain()
,分兩步:
GetFileHandle()
與下一篇的DrawBmp()
。EFI_STATUS
EFIAPI
UefiMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
{
EFI_STATUS Status = EFI_SUCCESS;
/* GetGopHandle 前一篇有提 */
/* Video Init 前一篇有提 */
/* Set Video 前一篇有提 */
/* 前一篇有提找到1920x1080剛好是mode序號22,故將22設定為我們的螢幕解析度*/
Status = Gop->SetMode(Gop, 22); /* 設定螢幕解析度為1920x1080(模式22),其實不應寫死為22,此處為講解暫寫如此,請見諒*/
/* Draw Logo */
CHAR16 *FileName = L"\\Logo.bmp";
/* 呼叫GetFileHandle(),執行三步: LocateHandleBuffer, OpenProtocol, OpenVolume */
EFI_FILE_PROTOCOL *Logo;
Status = GetFileHandle(ImageHandle, FileName, &Logo);
/* 呼叫ReadFile(),執行三步: AllocatePool, GetInfo, AllocatePages, FreePool*/
EFI_PHYSICAL_ADDRESS LogoAddress;
Status = ReadFile(Logo, &LogoAddress);
BMP_CONFIG BmpConfig;
Status = BmpTransform(LogoAddress, &BmpConfig);
Status = DrawBmp(Gop, BmpConfig, 0, 0);
return Status;
}
GetFileHandle()
EFI_STATUS GetFileHandle(
IN EFI_HANDLE ImageHandle,
IN CHAR16 *FileName,
OUT EFI_FILE_PROTOCOL **FileHandle
)
{
EFI_STATUS Status = EFI_SUCCESS;
UINTN HandleCount = 0;
EFI_HANDLE *HandleBuffer;
Status = gBS->LocateHandleBuffer(
ByProtocol,
&gEfiSimpleFileSystemProtocolGuid,
NULL,
&HandleCount,
&HandleBuffer
);
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SFSP;
Status = gBS->OpenProtocol(
HandleBuffer[0],
&gEfiSimpleFileSystemProtocolGuid,
(VOID **)&SFSP,
ImageHandle,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
EFI_FILE_PROTOCOL *Root;
Status = SFSP->OpenVolume(
SFSP,
&Root
);
Status = Root->Open(
Root,
FileHandle,
FileName,
EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
return Status;
}
前一篇實作出紅色方形,本篇隨前篇在設定解析度後新增GetFileHandle(),透過EFI_SIMPLE_FILE_SYSTEM_PROTOCOL打開Volume,打開volume後下一篇就可以照前一篇畫紅色方形的方法,畫出Logo.bmp。因篇幅原因得放至下一篇~請大家多多包涵~(;´゚ω゚`人)
本系列文分5篇是因為最初在畫Logo時花了近五天,目前讀者看到的程式碼為最新版本。