setoptions.c
来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 870 行 · 第 1/3 页
C
870 行
);
gST->ConOut->ClearScreen (gST->ConOut);
}
//
// Task 2: Collect all the available driver infos and update the formset.
// The available driver is those drivers which install efi driver configuration protocol
//
//
// Allocate memory to Update form
//
DriverImageHandleBuffer = NULL;
ControllerHandleBuffer = NULL;
ChildControllerHandleBuffer = NULL;
UpdateData = NULL;
UpdateData = EfiLibAllocateZeroPool (UPDATE_DATA_SIZE);
ASSERT (UpdateData != NULL);
//
// Clear all the content in dynamic page
//
UpdateData->FormSetUpdate = FALSE;
UpdateData->FormCallbackHandle = 0;
UpdateData->FormUpdate = FALSE;
UpdateData->FormTitle = 0;
UpdateData->DataCount = 0xff;
UpdateData->Data = NULL;
Private->Hii->UpdateForm (
Private->Hii,
Private->RegisteredHandle,
(EFI_FORM_LABEL) 0x1234, // Label 0x1234
FALSE, // Remove Op-codes (will never remove form/endform)
UpdateData // Significant value is UpdateData->DataCount
);
//
// When user enter the page at first time, the 'first refresh' string is given to notify user to refresh all the drivers,
// then the 'first refresh' string will be replaced by the 'refresh' string, and the two strings content are same after the replacement
//
NewStringToken = (STRING_REF) STR_FIRST_REFRESH;
NewString = GetString (Private, (STRING_REF) STR_REFRESH);
ASSERT (NewString != NULL);
Status = Private->Hii->NewString (Private->Hii, Lang, Private->RegisteredHandle, &NewStringToken, NewString);
ASSERT_EFI_ERROR (Status);
gBS->FreePool (NewString);
NewStringToken = (STRING_REF) STR_FIRST_REFRESH_HELP;
NewString = GetString (Private, (STRING_REF) STR_REFRESH_HELP);
ASSERT (NewString != NULL);
Status = Private->Hii->NewString (Private->Hii, Lang, Private->RegisteredHandle, &NewStringToken, NewString);
ASSERT_EFI_ERROR (Status);
gBS->FreePool (NewString);
//
// Get all drivers handles which has configuration protocol
//
DriverImageHandleCount = 0;
Status = gBS->LocateHandleBuffer (
ByProtocol,
&gEfiDriverConfigurationProtocolGuid,
NULL,
&DriverImageHandleCount,
&DriverImageHandleBuffer
);
//
// Scan every driver image handle to get its and its managed device and child device info,
// including Component name/image name/device handle and so on. Create and associate a item
// in Set Option page to very driver and its managed device and child device
//
ChoiceIndex = 0; // Item index in Set Option page
for (Index = 0; (Index < DriverImageHandleCount) && (ChoiceIndex < MAX_CHOICE_NUM); Index++) {
//
// step1 : get the driver info
//
DriverConfiguration = NULL;
Status = gBS->OpenProtocol (
DriverImageHandleBuffer[Index],
&gEfiDriverConfigurationProtocolGuid,
(VOID **) &DriverConfiguration,
NULL,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
ASSERT_EFI_ERROR (Status);
DriverBinding =NULL;
Status = gBS->OpenProtocol (
DriverImageHandleBuffer[Index],
&gEfiDriverBindingProtocolGuid,
(VOID **) &DriverBinding,
NULL,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
continue;
}
LoadedImage = NULL;
Status = gBS->OpenProtocol (
DriverBinding->ImageHandle,
&gEfiLoadedImageProtocolGuid,
(VOID **) &LoadedImage,
NULL,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
LoadedImage = NULL;
}
ComponentName = NULL;
Status = gBS->OpenProtocol (
DriverImageHandleBuffer[Index],
&gEfiComponentNameProtocolGuid,
(VOID **) &ComponentName,
NULL,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (EFI_ERROR (Status)) {
ComponentName = NULL;
}
//
// Get the driver name
// First try to get its component name, if fail, get its image name then
//
Status = EFI_UNSUPPORTED;
DriverName = NULL;
FreeDriverName = FALSE;
if ((ComponentName != NULL) && (ComponentName->GetDriverName != NULL)) {
Status = ComponentName->GetDriverName (
ComponentName,
Language,
&DriverName
);
}
if (EFI_ERROR (Status) && (LoadedImage != NULL)) {
DriverName = GetImageName (LoadedImage);
}
if (DriverName == NULL) {
DriverName = GetString (Private, (STRING_REF) STR_DRIVER_DEFAULT_NAME);
ASSERT (DriverName != NULL);
FreeDriverName = TRUE; // the DriverName string need to free pool
}
//
// Create a item for the driver in set options page
// Clear the Update buffer
//
UpdateData->FormSetUpdate = FALSE;
UpdateData->FormCallbackHandle = 0;
UpdateData->FormUpdate = FALSE;
UpdateData->FormTitle = 0;
UpdateData->DataCount = 0;
Location = (UINT8 *) &UpdateData->Data;
//
// Export the driver name string and create item in set options page
//
NewString = EfiLibAllocateZeroPool (EfiStrSize (DriverName) + EfiStrSize (L" |-"));
EfiStrCat (NewString, L" |-");
EfiStrCat (NewString, DriverName);
NewStringToken = mChoice[ChoiceIndex].DescriptionToken;
Status = Private->Hii->NewString (Private->Hii, NULL, Private->RegisteredHandle, &NewStringToken, NewString);
ASSERT_EFI_ERROR (Status);
gBS->FreePool (NewString);
if (FreeDriverName) {
gBS->FreePool (DriverName);
}
CreateGotoOpCode (
0x1234,
NewStringToken, // Description String Token
STR_GOTO_HELP_DRIVER, // Description Help String Token
EFI_IFR_FLAG_INTERACTIVE, // Flag designating callback is active
(UINT16) ChoiceIndex + 0x100, // Callback key value
Location // Buffer to fill with op-code
);
//
// Update the buffer items number and adjust next item address to new one
//
UpdateData->DataCount +=1 ;
Location = Location + ((EFI_IFR_OP_HEADER *) Location)->Length;
//
// Associate callback key with setoptions function related parameters to used by Task 1
//
mChoice[ChoiceIndex].DriverImageHandle = DriverImageHandleBuffer[Index];
mChoice[ChoiceIndex].DriverConfiguration = DriverConfiguration;
mChoice[ChoiceIndex].ControllerHandle = NULL;
mChoice[ChoiceIndex].ChildControllerHandle = NULL;
mChoice[ChoiceIndex].DescriptionToken = NewStringToken;
ChoiceIndex++;
//
// step2 : get the driver direct managed device info
//
//
// Get the driver all direct managed devices handles
//
Status = GetDeviceHandlesManagedByDriver (
DriverImageHandleBuffer[Index],
&ControllerHandleCount, // Get managed devices count
&ControllerHandleBuffer // return all handles in buffer
);
if (ControllerHandleBuffer == NULL) {
continue;
}
for (ControllerHandleIndex = 0; ControllerHandleIndex < ControllerHandleCount; ControllerHandleIndex++) {
//
// Get the managed device name
// First try to get its component name, if fail, get its device path then
// The component name string need not free pool, but the device path string and default string need safe free pool after export the string to Hii database
//
FreeControllerHandleName = FALSE;
ControllerHandleName = NULL;
Status = EFI_UNSUPPORTED;
if ((ComponentName != NULL) && (ComponentName->GetDriverName != NULL)) {
Status = ComponentName->GetControllerName (
ComponentName,
ControllerHandleBuffer[ControllerHandleIndex],
NULL,
Language,
&ControllerHandleName
);
}
if (EFI_ERROR (Status)) {
Status = gBS->OpenProtocol (
ControllerHandleBuffer[ControllerHandleIndex],
&gEfiDevicePathProtocolGuid,
(VOID **) &DevicePath,
NULL,
NULL,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
if (!EFI_ERROR (Status)) {
ControllerHandleName = DevicePathToStr ( DevicePath );
FreeControllerHandleName = TRUE; // the Controller Handle Name string need to free pool
}
}
if (ControllerHandleName == NULL) {
ControllerHandleName = GetString (Private, (STRING_REF) STR_DRIVER_CONTROLLER_DEFAULT_NAME);
ASSERT (ControllerHandleName != NULL);
FreeControllerHandleName = TRUE; // the Controller Handle Name string need to free pool
}
//
// do some alignment for NewString if needed
//
AlignmentItem (ControllerHandleName, L" |-", &NewString);
NewStringToken = mChoice[ChoiceIndex].DescriptionToken;
Private->Hii->NewString (
Private->Hii,
NULL,
Private->RegisteredHandle,
&NewStringToken,
NewString
);
gBS->FreePool (NewString);
if (FreeControllerHandleName) {
gBS->FreePool (ControllerHandleName);
}
CreateGotoOpCode (
0x1234,
NewStringToken, // Description String Token
STR_GOTO_HELP_DEVICE, // Description Help String Token
EFI_IFR_FLAG_INTERACTIVE, // Flag designating callback is active
(UINT16) ChoiceIndex + 0x100, // Callback key value
Location // Buffer to fill with op-code
);
//
// Update the buffer items number and adjust next item address to new one
//
UpdateData->DataCount +=1 ;
Location = Location + ((EFI_IFR_OP_HEADER *) Location)->Length;
//
// Associate callback key with setoptions function related parameters to used by Task 1
//
mChoice[ChoiceIndex].DriverImageHandle = DriverImageHandleBuffer[Index];
mChoice[ChoiceIndex].DriverConfiguration = DriverConfiguration;
mChoice[ChoiceIndex].ControllerHandle = ControllerHandleBuffer[ControllerHandleIndex];
mChoice[ChoiceIndex].ChildControllerHandle = NULL;
mChoice[ChoiceIndex].DescriptionToken = NewStringToken;
ChoiceIndex++;
//
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?