-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOinkBL.c
179 lines (153 loc) · 4.72 KB
/
OinkBL.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* BmpTransform: */
EFI_STATUS BmpTransform(
EFI_STATUS Status;
EFI_GRAPHICS_OUTPUT_PROTOCOL * GraphicsProtocol = NULL;
EFI_INPUT_KEY Key;
UINTN x=600, y=100; //欲顯示Logo.bmp的左上角x,y座標
VOID *GopBlt = NULL;
UINTN GopBltSize;
UINTN BmpHeight;
UINTN BmpWidth;
EFI_FILE_PROTOCOL *Root = 0;
EFI_FILE_PROTOCOL *NewHandle = 0;
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *SimpleFileSystem;
EFI_FILE_INFO *fileinfo;
VOID * Buffer;
UINTN BufferSize;
UINTN infosize = SIZE_OF_EFI_FILE_INFO;
EFI_GUID info_type = EFI_FILE_INFO_ID;
/* 檔案處理 */
/* 四步: 1.LocateProtocol 2.OpenVolume 3.Image Open 4.AllocatePool */
Status = gBS->LocateProtocol(&gEfiSimpleFileSystemProtocolGuid, NULL, (VOID**)&SimpleFileSystem);
if (EFI_ERROR(Status))
{
Print(L"ERROR (Entry.c): LocateProtocol\n");
return Status;
}
Status = SimpleFileSystem->OpenVolume(SimpleFileSystem, &Root);
if (EFI_ERROR(Status))
{
Print(L"ERROR (Entry.c): OpenVolume \n");
return Status;
}
Status = Root->Open(Root, &NewHandle, (CHAR16*)L"Logo.bmp", EFI_FILE_MODE_READ | EFI_FILE_MODE_WRITE, 0);
if (EFI_ERROR(Status))
{
Print(L"ERROR (Entry.c): Image Open \n");
return Status;
}
Status = gBS->AllocatePool(AllocateAnyPages, infosize, (VOID **)&fileinfo);
if (EFI_ERROR(Status))
{
Print(L"ERROR (Entry.c): AllocatePool \n");
return Status;
}
Status = NewHandle->GetInfo(NewHandle, &info_type, &infosize, NULL);
Status = NewHandle->GetInfo(NewHandle, &info_type, &infosize, fileinfo);
if (EFI_ERROR(Status))
{
Print(L"ERROR (Entry.c): Get Informations\n");
return Status;
}
/* Read Buffer&BufferSize for converting BMP to Blt */
BufferSize = fileinfo->FileSize;
gBS->AllocatePool(AllocateAnyPages, BufferSize, (VOID **)&Buffer);
if (EFI_ERROR(Status))
{
Print(L"ERROR (Entry.c): AllocatePool\n");
return Status;
}
/* Buffer處理 */
Status = NewHandle->Read(NewHandle, &BufferSize, Buffer);
if (EFI_ERROR(Status))
{
Print(L"ERROR (Entry.c): Read Buffer\n");
return Status;
}
/* 關閉檔案 */
Status = NewHandle->Close(NewHandle);
if (EFI_ERROR(Status))
{
Print(L"ERROR (Entry.c): Close \n");
return Status;
}
/* Convert BMP to Blt */
Status = ConvertBmpToBlt(Buffer, BufferSize, &GopBlt, &GopBltSize, &BmpHeight, &BmpWidth);
if (EFI_ERROR(Status))
{
Print(L"ERROR (Entry.c): ConvertBmpToBlt\n");
return Status;
}
/* GraphicsProtocol */
Status = gBS->LocateProtocol(&gEfiGraphicsOutputProtocolGuid, NULL, (VOID**)&GraphicsProtocol);
if (EFI_ERROR(Status))
{
Print(L"ERROR (Entry.c): LocateProtocol\n");
return Status;
}
/* Show Logo.bmp */
Status = GraphicsProtocol->Blt(GraphicsProtocol, GopBlt, EfiBltBufferToVideo, 0, 0, x, y, BmpWidth, BmpHeight, 0); // x,y是欲顯示之Logo.bmp左上角座標
return Status;
}
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;
}
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;
}