Skip to content

Commit 668f0e9

Browse files
silvernekozhangxp1998
authored andcommitted
[lib][uefi] Remove duplicated type definition
1 parent 239b1d0 commit 668f0e9

File tree

4 files changed

+37
-69
lines changed

4 files changed

+37
-69
lines changed

lib/uefi/boot_service_provider.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@ EfiStatus handle_protocol(EfiHandle handle, const EfiGuid *protocol,
5454
if (guid_eq(protocol, LOADED_IMAGE_PROTOCOL_GUID)) {
5555
printf("handle_protocol(%p, LOADED_IMAGE_PROTOCOL_GUID, %p);\n", handle,
5656
intf);
57-
const auto loaded_image = static_cast<EFI_LOADED_IMAGE_PROTOCOL *>(
58-
uefi_malloc(sizeof(EFI_LOADED_IMAGE_PROTOCOL)));
57+
const auto loaded_image = static_cast<EfiLoadedImageProtocol*>(
58+
uefi_malloc(sizeof(EfiLoadedImageProtocol)));
5959
*loaded_image = {};
60-
loaded_image->Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
61-
loaded_image->ParentHandle = nullptr;
62-
loaded_image->SystemTable = nullptr;
63-
loaded_image->LoadOptionsSize = 0;
64-
loaded_image->LoadOptions = nullptr;
65-
loaded_image->Unload = unload;
66-
loaded_image->ImageBase = handle;
60+
loaded_image->revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
61+
loaded_image->parent_handle = nullptr;
62+
loaded_image->system_table = nullptr;
63+
loaded_image->load_options_size = 0;
64+
loaded_image->load_options = nullptr;
65+
loaded_image->unload = unload;
66+
loaded_image->image_base = handle;
6767

6868
*intf = loaded_image;
6969
return EFI_STATUS_SUCCESS;

lib/uefi/boot_service_provider.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -134,39 +134,6 @@ static constexpr auto EFI_ERASE_BLOCK_PROTOCOL_GUID =
134134
0x4926,
135135
{0xaa, 0xef, 0x99, 0x18, 0xe7, 0x72, 0xd9, 0x87}};
136136

137-
using EFI_IMAGE_UNLOAD = EfiStatus (*)(EfiHandle);
138-
139-
//******************************************************
140-
// EFI_DEVICE_PATH_PROTOCOL
141-
//******************************************************
142-
struct EFI_DEVICE_PATH_PROTOCOL {
143-
uint8_t Type;
144-
uint8_t SubType;
145-
uint8_t Length[2];
146-
};
147-
148-
struct EFI_LOADED_IMAGE_PROTOCOL {
149-
uint32_t Revision;
150-
EfiHandle ParentHandle;
151-
EfiSystemTable *SystemTable;
152-
153-
// Source location of the image
154-
EfiHandle DeviceHandle;
155-
EFI_DEVICE_PATH_PROTOCOL *FilePath;
156-
void *Reserved;
157-
158-
// Image’s load options
159-
uint32_t LoadOptionsSize;
160-
void *LoadOptions;
161-
162-
// Location where image was loaded
163-
void *ImageBase;
164-
uint64_t ImageSize;
165-
EfiMemoryType ImageCodeType;
166-
EfiMemoryType ImageDataType;
167-
EFI_IMAGE_UNLOAD Unload;
168-
};
169-
170137
// This function would be called from GBL before jumping into android kernel
171138
// LK provides a default no-op implementation that is weakly linked,
172139
// different platforms can override with their own implementation.

lib/uefi/debug_support.cpp

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121
#include <stdio.h>
2222
#include <string.h>
2323
#include <uefi/boot_service.h>
24+
#include <uefi/protocols/device_path_protocol.h>
2425
#include <uefi/protocols/loaded_image_protocol.h>
2526
#include <uefi/types.h>
2627

27-
#include "boot_service_provider.h"
2828
#include "uefi_platform.h"
2929

3030
struct EFI_DEVICE_PATH_FILE_PATH_PROTOCOL {
31-
struct EFI_DEVICE_PATH_PROTOCOL dp;
31+
EfiDevicePathProtocol dp;
3232
uint16_t str[];
3333
};
3434

@@ -79,7 +79,7 @@ static uint32_t efi_m_max_table_entries;
7979
static constexpr size_t EFI_DEBUG_TABLE_ENTRY_SIZE = (sizeof(union EfiDebugImageInfo));
8080

8181
EfiStatus efi_core_new_debug_image_info_entry(uint32_t image_info_type,
82-
struct EFI_LOADED_IMAGE_PROTOCOL *loaded_image,
82+
EfiLoadedImageProtocol *loaded_image,
8383
EfiHandle image_handle) {
8484
/* Set the flag indicating that we're in the process of updating
8585
* the table.
@@ -198,38 +198,38 @@ EfiStatus setup_debug_support(EfiSystemTable &table,
198198
char *image_base,
199199
size_t virtual_size,
200200
bdev_t *dev) {
201-
struct EFI_LOADED_IMAGE_PROTOCOL *efiLoadedImageProtocol = nullptr;
201+
EfiLoadedImageProtocol *efiLoadedImageProtocol = nullptr;
202202

203203
allocate_pool(EFI_MEMORY_TYPE_BOOT_SERVICES_DATA,
204-
sizeof(struct EFI_LOADED_IMAGE_PROTOCOL),
204+
sizeof(EfiLoadedImageProtocol),
205205
reinterpret_cast<void **>(&efiLoadedImageProtocol));
206-
memset(efiLoadedImageProtocol, 0, sizeof(struct EFI_LOADED_IMAGE_PROTOCOL));
206+
memset(efiLoadedImageProtocol, 0, sizeof(EfiLoadedImageProtocol));
207207

208-
efiLoadedImageProtocol->Revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
209-
efiLoadedImageProtocol->SystemTable = &table;
210-
efiLoadedImageProtocol->ImageBase = reinterpret_cast<void *>(image_base);
211-
efiLoadedImageProtocol->ImageSize = virtual_size;
208+
efiLoadedImageProtocol->revision = EFI_LOADED_IMAGE_PROTOCOL_REVISION;
209+
efiLoadedImageProtocol->system_table = &table;
210+
efiLoadedImageProtocol->image_base = reinterpret_cast<void *>(image_base);
211+
efiLoadedImageProtocol->image_size = virtual_size;
212212
char *device_buf = nullptr;
213-
size_t fpsize = sizeof(struct EFI_DEVICE_PATH_PROTOCOL) + 2 * (strlen(dev->name) + 2);
213+
size_t fpsize = sizeof(EfiDevicePathProtocol) + 2 * (strlen(dev->name) + 2);
214214
allocate_pool(EFI_MEMORY_TYPE_BOOT_SERVICES_DATA,
215-
fpsize + sizeof(struct EFI_DEVICE_PATH_PROTOCOL),
215+
fpsize + sizeof(EfiDevicePathProtocol),
216216
reinterpret_cast<void **>(&device_buf));
217-
memset(device_buf, 0, fpsize + sizeof(struct EFI_DEVICE_PATH_PROTOCOL));
217+
memset(device_buf, 0, fpsize + sizeof(EfiDevicePathProtocol));
218218
struct EFI_DEVICE_PATH_FILE_PATH_PROTOCOL *fp = reinterpret_cast<struct EFI_DEVICE_PATH_FILE_PATH_PROTOCOL *>(device_buf);
219-
struct EFI_DEVICE_PATH_PROTOCOL *dp_end = reinterpret_cast<struct EFI_DEVICE_PATH_PROTOCOL *>(device_buf + fpsize);
220-
fp->dp.Type = EFI_DEVICE_PATH_TYPE_MEDIA_DEVICE;
221-
fp->dp.SubType = EFI_DEVICE_PATH_SUB_TYPE_FILE_PATH;
222-
fp->dp.Length[0] = fpsize % 256;
223-
fp->dp.Length[1] = fpsize / 256;
219+
struct EfiDevicePathProtocol *dp_end = reinterpret_cast<EfiDevicePathProtocol *>(device_buf + fpsize);
220+
fp->dp.type = EFI_DEVICE_PATH_TYPE_MEDIA_DEVICE;
221+
fp->dp.sub_type = EFI_DEVICE_PATH_SUB_TYPE_FILE_PATH;
222+
fp->dp.length[0] = fpsize % 256;
223+
fp->dp.length[1] = fpsize / 256;
224224
fp->str[0] = '\\';
225225
for (size_t i = 0; i < strlen(dev->name); i++) {
226226
fp->str[i+1] = dev->name[i];
227227
}
228-
dp_end->Type = EFI_DEVICE_PATH_TYPE_END;
229-
dp_end->SubType = EFI_DEVICE_PATH_SUB_TYPE_END;
230-
dp_end->Length[0] = sizeof(struct EFI_DEVICE_PATH_PROTOCOL) % 256;
231-
dp_end->Length[1] = sizeof(struct EFI_DEVICE_PATH_PROTOCOL) / 256;
232-
efiLoadedImageProtocol->FilePath = reinterpret_cast<struct EFI_DEVICE_PATH_PROTOCOL *>(device_buf);
228+
dp_end->type = EFI_DEVICE_PATH_TYPE_END;
229+
dp_end->sub_type = EFI_DEVICE_PATH_SUB_TYPE_END;
230+
dp_end->length[0] = sizeof(EfiDevicePathProtocol) % 256;
231+
dp_end->length[1] = sizeof(EfiDevicePathProtocol) / 256;
232+
efiLoadedImageProtocol->file_path = reinterpret_cast<EfiDevicePathProtocol *>(device_buf);
233233
return efi_core_new_debug_image_info_entry(EFI_DEBUG_IMAGE_INFO_TYPE_NORMAL,
234234
efiLoadedImageProtocol,
235235
image_base);
@@ -242,8 +242,8 @@ void teardown_debug_support(char *image_base) {
242242
if (table[index].normal_image &&
243243
table[index].normal_image->image_handle == image_base) {
244244
/* Found a match. Get device_buf and efiLoadedImageProtocol. */
245-
struct EFI_LOADED_IMAGE_PROTOCOL *efiLoadedImageProtocol = table[index].normal_image->loaded_image_protocol_instance;
246-
char *device_buf = reinterpret_cast<char *>(efiLoadedImageProtocol->FilePath);
245+
EfiLoadedImageProtocol *efiLoadedImageProtocol = table[index].normal_image->loaded_image_protocol_instance;
246+
char *device_buf = reinterpret_cast<char *>(efiLoadedImageProtocol->file_path);
247247
/* Free resources */
248248
efi_core_remove_debug_image_info_entry(image_base);
249249
free_pool(device_buf);

lib/uefi/debug_support.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#define __DEBUG_SUPPORT_
2020

2121
#include <lib/bio.h>
22+
#include <uefi/protocols/loaded_image_protocol.h>
2223
#include <uefi/system_table.h>
2324
#include <uefi/types.h>
2425

@@ -41,7 +42,7 @@ struct EfiSystemTablePointer {
4142

4243
struct EfiDebugImageInfoNormal {
4344
uint32_t image_info_type;
44-
struct EFI_LOADED_IMAGE_PROTOCOL *loaded_image_protocol_instance;
45+
EfiLoadedImageProtocol *loaded_image_protocol_instance;
4546
EfiHandle image_handle;
4647
};
4748

@@ -58,7 +59,7 @@ struct EfiDebugImageInfoTableHeader {
5859

5960
EfiStatus efi_initialize_system_table_pointer(struct EfiSystemTable *system_table);
6061
EfiStatus efi_core_new_debug_image_info_entry(uint32_t image_info_type,
61-
struct EFI_LOADED_IMAGE_PROTOCOL *loaded_image,
62+
EfiLoadedImageProtocol *loaded_image,
6263
EfiHandle image_handle);
6364
void efi_core_remove_debug_image_info_entry(EfiHandle image_handle);
6465
EfiStatus setup_debug_support(EfiSystemTable &table,

0 commit comments

Comments
 (0)