summaryrefslogtreecommitdiffstats
path: root/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c
diff options
context:
space:
mode:
Diffstat (limited to 'MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c')
-rw-r--r--MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c468
1 files changed, 251 insertions, 217 deletions
diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c b/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c
index aa891feb17..fac33b9ee9 100644
--- a/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c
+++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c
@@ -9,15 +9,15 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "InternalBm.h"
-#define VENDOR_IDENTIFICATION_OFFSET 3
-#define VENDOR_IDENTIFICATION_LENGTH 8
-#define PRODUCT_IDENTIFICATION_OFFSET 11
-#define PRODUCT_IDENTIFICATION_LENGTH 16
+#define VENDOR_IDENTIFICATION_OFFSET 3
+#define VENDOR_IDENTIFICATION_LENGTH 8
+#define PRODUCT_IDENTIFICATION_OFFSET 11
+#define PRODUCT_IDENTIFICATION_LENGTH 16
-CONST UINT16 mBmUsbLangId = 0x0409; // English
-CHAR16 mBmUefiPrefix[] = L"UEFI ";
+CONST UINT16 mBmUsbLangId = 0x0409; // English
+CHAR16 mBmUefiPrefix[] = L"UEFI ";
-LIST_ENTRY mPlatformBootDescriptionHandlers = INITIALIZE_LIST_HEAD_VARIABLE (mPlatformBootDescriptionHandlers);
+LIST_ENTRY mPlatformBootDescriptionHandlers = INITIALIZE_LIST_HEAD_VARIABLE (mPlatformBootDescriptionHandlers);
/**
For a bootable Device path, return its boot type.
@@ -39,27 +39,28 @@ LIST_ENTRY mPlatformBootDescriptionHandlers = INITIALIZE_LIST_HEAD_VARIABLE (mPl
**/
BM_BOOT_TYPE
BmDevicePathType (
- IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
+ IN EFI_DEVICE_PATH_PROTOCOL *DevicePath
)
{
- EFI_DEVICE_PATH_PROTOCOL *Node;
- EFI_DEVICE_PATH_PROTOCOL *NextNode;
+ EFI_DEVICE_PATH_PROTOCOL *Node;
+ EFI_DEVICE_PATH_PROTOCOL *NextNode;
ASSERT (DevicePath != NULL);
for (Node = DevicePath; !IsDevicePathEndType (Node); Node = NextDevicePathNode (Node)) {
switch (DevicePathType (Node)) {
-
case ACPI_DEVICE_PATH:
- if (EISA_ID_TO_NUM (((ACPI_HID_DEVICE_PATH *) Node)->HID) == 0x0604) {
+ if (EISA_ID_TO_NUM (((ACPI_HID_DEVICE_PATH *)Node)->HID) == 0x0604) {
return BmAcpiFloppyBoot;
}
+
break;
case HARDWARE_DEVICE_PATH:
if (DevicePathSubType (Node) == HW_CONTROLLER_DP) {
return BmHardwareDeviceBoot;
}
+
break;
case MESSAGING_DEVICE_PATH:
@@ -70,9 +71,9 @@ BmDevicePathType (
do {
NextNode = NextDevicePathNode (NextNode);
} while (
- (DevicePathType (NextNode) == MESSAGING_DEVICE_PATH) &&
- (DevicePathSubType(NextNode) == MSG_DEVICE_LOGICAL_UNIT_DP)
- );
+ (DevicePathType (NextNode) == MESSAGING_DEVICE_PATH) &&
+ (DevicePathSubType (NextNode) == MSG_DEVICE_LOGICAL_UNIT_DP)
+ );
//
// If the device path not only point to driver device, it is not a messaging device path,
@@ -82,21 +83,21 @@ BmDevicePathType (
}
switch (DevicePathSubType (Node)) {
- case MSG_ATAPI_DP:
- return BmMessageAtapiBoot;
- break;
+ case MSG_ATAPI_DP:
+ return BmMessageAtapiBoot;
+ break;
- case MSG_SATA_DP:
- return BmMessageSataBoot;
- break;
+ case MSG_SATA_DP:
+ return BmMessageSataBoot;
+ break;
- case MSG_USB_DP:
- return BmMessageUsbBoot;
- break;
+ case MSG_USB_DP:
+ return BmMessageUsbBoot;
+ break;
- case MSG_SCSI_DP:
- return BmMessageScsiBoot;
- break;
+ case MSG_SCSI_DP:
+ return BmMessageScsiBoot;
+ break;
}
}
}
@@ -111,17 +112,18 @@ BmDevicePathType (
**/
VOID
BmEliminateExtraSpaces (
- IN CHAR16 *Str
+ IN CHAR16 *Str
)
{
- UINTN Index;
- UINTN ActualIndex;
+ UINTN Index;
+ UINTN ActualIndex;
for (Index = 0, ActualIndex = 0; Str[Index] != L'\0'; Index++) {
if ((Str[Index] != L' ') || ((ActualIndex > 0) && (Str[ActualIndex - 1] != L' '))) {
Str[ActualIndex++] = Str[Index];
}
}
+
Str[ActualIndex] = L'\0';
}
@@ -134,70 +136,72 @@ BmEliminateExtraSpaces (
**/
CHAR16 *
BmGetDescriptionFromDiskInfo (
- IN EFI_HANDLE Handle
+ IN EFI_HANDLE Handle
)
{
- UINTN Index;
- EFI_STATUS Status;
- EFI_DISK_INFO_PROTOCOL *DiskInfo;
- UINT32 BufferSize;
- EFI_ATAPI_IDENTIFY_DATA IdentifyData;
- EFI_SCSI_INQUIRY_DATA InquiryData;
- CHAR16 *Description;
- UINTN Length;
- CONST UINTN ModelNameLength = 40;
- CONST UINTN SerialNumberLength = 20;
- CHAR8 *StrPtr;
- UINT8 Temp;
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;
-
- Description = NULL;
+ UINTN Index;
+ EFI_STATUS Status;
+ EFI_DISK_INFO_PROTOCOL *DiskInfo;
+ UINT32 BufferSize;
+ EFI_ATAPI_IDENTIFY_DATA IdentifyData;
+ EFI_SCSI_INQUIRY_DATA InquiryData;
+ CHAR16 *Description;
+ UINTN Length;
+ CONST UINTN ModelNameLength = 40;
+ CONST UINTN SerialNumberLength = 20;
+ CHAR8 *StrPtr;
+ UINT8 Temp;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+
+ Description = NULL;
Status = gBS->HandleProtocol (
Handle,
&gEfiDiskInfoProtocolGuid,
- (VOID **) &DiskInfo
+ (VOID **)&DiskInfo
);
if (EFI_ERROR (Status)) {
return NULL;
}
if (CompareGuid (&DiskInfo->Interface, &gEfiDiskInfoAhciInterfaceGuid) ||
- CompareGuid (&DiskInfo->Interface, &gEfiDiskInfoIdeInterfaceGuid)) {
- BufferSize = sizeof (EFI_ATAPI_IDENTIFY_DATA);
- Status = DiskInfo->Identify (
- DiskInfo,
- &IdentifyData,
- &BufferSize
- );
+ CompareGuid (&DiskInfo->Interface, &gEfiDiskInfoIdeInterfaceGuid))
+ {
+ BufferSize = sizeof (EFI_ATAPI_IDENTIFY_DATA);
+ Status = DiskInfo->Identify (
+ DiskInfo,
+ &IdentifyData,
+ &BufferSize
+ );
if (!EFI_ERROR (Status)) {
Description = AllocateZeroPool ((ModelNameLength + SerialNumberLength + 2) * sizeof (CHAR16));
ASSERT (Description != NULL);
for (Index = 0; Index + 1 < ModelNameLength; Index += 2) {
- Description[Index] = (CHAR16) IdentifyData.ModelName[Index + 1];
- Description[Index + 1] = (CHAR16) IdentifyData.ModelName[Index];
+ Description[Index] = (CHAR16)IdentifyData.ModelName[Index + 1];
+ Description[Index + 1] = (CHAR16)IdentifyData.ModelName[Index];
}
- Length = Index;
+ Length = Index;
Description[Length++] = L' ';
for (Index = 0; Index + 1 < SerialNumberLength; Index += 2) {
- Description[Length + Index] = (CHAR16) IdentifyData.SerialNo[Index + 1];
- Description[Length + Index + 1] = (CHAR16) IdentifyData.SerialNo[Index];
+ Description[Length + Index] = (CHAR16)IdentifyData.SerialNo[Index + 1];
+ Description[Length + Index + 1] = (CHAR16)IdentifyData.SerialNo[Index];
}
- Length += Index;
+
+ Length += Index;
Description[Length++] = L'\0';
ASSERT (Length == ModelNameLength + SerialNumberLength + 2);
BmEliminateExtraSpaces (Description);
}
} else if (CompareGuid (&DiskInfo->Interface, &gEfiDiskInfoScsiInterfaceGuid)) {
- BufferSize = sizeof (EFI_SCSI_INQUIRY_DATA);
- Status = DiskInfo->Inquiry (
- DiskInfo,
- &InquiryData,
- &BufferSize
- );
+ BufferSize = sizeof (EFI_SCSI_INQUIRY_DATA);
+ Status = DiskInfo->Inquiry (
+ DiskInfo,
+ &InquiryData,
+ &BufferSize
+ );
if (!EFI_ERROR (Status)) {
Description = AllocateZeroPool ((VENDOR_IDENTIFICATION_LENGTH + PRODUCT_IDENTIFICATION_LENGTH + 2) * sizeof (CHAR16));
ASSERT (Description != NULL);
@@ -207,8 +211,8 @@ BmGetDescriptionFromDiskInfo (
// EFI_SCSI_INQUIRY_DATA.Reserved_5_95[11 - 26] save the product identification,
// Here combine the vendor identification and product identification to the description.
//
- StrPtr = (CHAR8 *) (&InquiryData.Reserved_5_95[VENDOR_IDENTIFICATION_OFFSET]);
- Temp = StrPtr[VENDOR_IDENTIFICATION_LENGTH];
+ StrPtr = (CHAR8 *)(&InquiryData.Reserved_5_95[VENDOR_IDENTIFICATION_OFFSET]);
+ Temp = StrPtr[VENDOR_IDENTIFICATION_LENGTH];
StrPtr[VENDOR_IDENTIFICATION_LENGTH] = '\0';
AsciiStrToUnicodeStrS (StrPtr, Description, VENDOR_IDENTIFICATION_LENGTH + 1);
StrPtr[VENDOR_IDENTIFICATION_LENGTH] = Temp;
@@ -218,7 +222,7 @@ BmGetDescriptionFromDiskInfo (
//
Description[VENDOR_IDENTIFICATION_LENGTH] = L' ';
- StrPtr = (CHAR8 *) (&InquiryData.Reserved_5_95[PRODUCT_IDENTIFICATION_OFFSET]);
+ StrPtr = (CHAR8 *)(&InquiryData.Reserved_5_95[PRODUCT_IDENTIFICATION_OFFSET]);
StrPtr[PRODUCT_IDENTIFICATION_LENGTH] = '\0';
AsciiStrToUnicodeStrS (StrPtr, Description + VENDOR_IDENTIFICATION_LENGTH + 1, PRODUCT_IDENTIFICATION_LENGTH + 1);
@@ -233,6 +237,7 @@ BmGetDescriptionFromDiskInfo (
while (!IsDevicePathEnd (DevicePath) && (DevicePathType (DevicePath) != MESSAGING_DEVICE_PATH)) {
DevicePath = NextDevicePathNode (DevicePath);
}
+
if (IsDevicePathEnd (DevicePath)) {
return NULL;
}
@@ -260,23 +265,23 @@ BmGetDescriptionFromDiskInfo (
**/
CHAR16 *
BmGetUsbDescription (
- IN EFI_HANDLE Handle
+ IN EFI_HANDLE Handle
)
{
- EFI_STATUS Status;
- EFI_USB_IO_PROTOCOL *UsbIo;
- CHAR16 NullChar;
- CHAR16 *Manufacturer;
- CHAR16 *Product;
- CHAR16 *SerialNumber;
- CHAR16 *Description;
- EFI_USB_DEVICE_DESCRIPTOR DevDesc;
- UINTN DescMaxSize;
+ EFI_STATUS Status;
+ EFI_USB_IO_PROTOCOL *UsbIo;
+ CHAR16 NullChar;
+ CHAR16 *Manufacturer;
+ CHAR16 *Product;
+ CHAR16 *SerialNumber;
+ CHAR16 *Description;
+ EFI_USB_DEVICE_DESCRIPTOR DevDesc;
+ UINTN DescMaxSize;
Status = gBS->HandleProtocol (
Handle,
&gEfiUsbIoProtocolGuid,
- (VOID **) &UsbIo
+ (VOID **)&UsbIo
);
if (EFI_ERROR (Status)) {
return NULL;
@@ -322,27 +327,30 @@ BmGetUsbDescription (
if ((Manufacturer == &NullChar) &&
(Product == &NullChar) &&
(SerialNumber == &NullChar)
- ) {
+ )
+ {
return NULL;
}
DescMaxSize = StrSize (Manufacturer) + StrSize (Product) + StrSize (SerialNumber);
Description = AllocateZeroPool (DescMaxSize);
ASSERT (Description != NULL);
- StrCatS (Description, DescMaxSize/sizeof(CHAR16), Manufacturer);
- StrCatS (Description, DescMaxSize/sizeof(CHAR16), L" ");
+ StrCatS (Description, DescMaxSize/sizeof (CHAR16), Manufacturer);
+ StrCatS (Description, DescMaxSize/sizeof (CHAR16), L" ");
- StrCatS (Description, DescMaxSize/sizeof(CHAR16), Product);
- StrCatS (Description, DescMaxSize/sizeof(CHAR16), L" ");
+ StrCatS (Description, DescMaxSize/sizeof (CHAR16), Product);
+ StrCatS (Description, DescMaxSize/sizeof (CHAR16), L" ");
- StrCatS (Description, DescMaxSize/sizeof(CHAR16), SerialNumber);
+ StrCatS (Description, DescMaxSize/sizeof (CHAR16), SerialNumber);
if (Manufacturer != &NullChar) {
FreePool (Manufacturer);
}
+
if (Product != &NullChar) {
FreePool (Product);
}
+
if (SerialNumber != &NullChar) {
FreePool (SerialNumber);
}
@@ -361,17 +369,17 @@ BmGetUsbDescription (
**/
CHAR16 *
BmGetNetworkDescription (
- IN EFI_HANDLE Handle
+ IN EFI_HANDLE Handle
)
{
- EFI_STATUS Status;
- EFI_DEVICE_PATH_PROTOCOL *DevicePath;
- MAC_ADDR_DEVICE_PATH *Mac;
- VLAN_DEVICE_PATH *Vlan;
- EFI_DEVICE_PATH_PROTOCOL *Ip;
- EFI_DEVICE_PATH_PROTOCOL *Uri;
- CHAR16 *Description;
- UINTN DescriptionSize;
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;
+ MAC_ADDR_DEVICE_PATH *Mac;
+ VLAN_DEVICE_PATH *Vlan;
+ EFI_DEVICE_PATH_PROTOCOL *Ip;
+ EFI_DEVICE_PATH_PROTOCOL *Uri;
+ CHAR16 *Description;
+ UINTN DescriptionSize;
Status = gBS->OpenProtocol (
Handle,
@@ -388,7 +396,7 @@ BmGetNetworkDescription (
Status = gBS->OpenProtocol (
Handle,
&gEfiDevicePathProtocolGuid,
- (VOID **) &DevicePath,
+ (VOID **)&DevicePath,
gImageHandle,
Handle,
EFI_OPEN_PROTOCOL_GET_PROTOCOL
@@ -410,7 +418,8 @@ BmGetNetworkDescription (
while (!IsDevicePathEnd (DevicePath) &&
((DevicePathType (DevicePath) != MESSAGING_DEVICE_PATH) ||
(DevicePathSubType (DevicePath) != MSG_MAC_ADDR_DP))
- ) {
+ )
+ {
DevicePath = NextDevicePathNode (DevicePath);
}
@@ -418,7 +427,7 @@ BmGetNetworkDescription (
return NULL;
}
- Mac = (MAC_ADDR_DEVICE_PATH *) DevicePath;
+ Mac = (MAC_ADDR_DEVICE_PATH *)DevicePath;
DevicePath = NextDevicePathNode (DevicePath);
//
@@ -426,8 +435,9 @@ BmGetNetworkDescription (
//
if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
(DevicePathSubType (DevicePath) == MSG_VLAN_DP)
- ) {
- Vlan = (VLAN_DEVICE_PATH *) DevicePath;
+ )
+ {
+ Vlan = (VLAN_DEVICE_PATH *)DevicePath;
DevicePath = NextDevicePathNode (DevicePath);
} else {
Vlan = NULL;
@@ -438,7 +448,8 @@ BmGetNetworkDescription (
//
if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
(DevicePathSubType (DevicePath) == MSG_WIFI_DP)
- ) {
+ )
+ {
DevicePath = NextDevicePathNode (DevicePath);
}
@@ -448,8 +459,9 @@ BmGetNetworkDescription (
if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
((DevicePathSubType (DevicePath) == MSG_IPv4_DP) ||
(DevicePathSubType (DevicePath) == MSG_IPv6_DP))
- ) {
- Ip = DevicePath;
+ )
+ {
+ Ip = DevicePath;
DevicePath = NextDevicePathNode (DevicePath);
} else {
Ip = NULL;
@@ -460,7 +472,8 @@ BmGetNetworkDescription (
//
if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
(DevicePathSubType (DevicePath) == MSG_DNS_DP)
- ) {
+ )
+ {
DevicePath = NextDevicePathNode (DevicePath);
}
@@ -469,8 +482,9 @@ BmGetNetworkDescription (
//
if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
(DevicePathSubType (DevicePath) == MSG_URI_DP)
- ) {
- Uri = DevicePath;
+ )
+ {
+ Uri = DevicePath;
DevicePath = NextDevicePathNode (DevicePath);
} else {
Uri = NULL;
@@ -485,14 +499,19 @@ BmGetNetworkDescription (
Description = AllocatePool (DescriptionSize);
ASSERT (Description != NULL);
UnicodeSPrint (
- Description, DescriptionSize,
+ Description,
+ DescriptionSize,
(Vlan == NULL) ?
L"%sv%d (MAC:%02x%02x%02x%02x%02x%02x)" :
L"%sv%d (MAC:%02x%02x%02x%02x%02x%02x VLAN%d)",
(Uri == NULL) ? L"PXE" : L"HTTP",
((Ip == NULL) || (DevicePathSubType (Ip) == MSG_IPv4_DP)) ? 4 : 6,
- Mac->MacAddress.Addr[0], Mac->MacAddress.Addr[1], Mac->MacAddress.Addr[2],
- Mac->MacAddress.Addr[3], Mac->MacAddress.Addr[4], Mac->MacAddress.Addr[5],
+ Mac->MacAddress.Addr[0],
+ Mac->MacAddress.Addr[1],
+ Mac->MacAddress.Addr[2],
+ Mac->MacAddress.Addr[3],
+ Mac->MacAddress.Addr[4],
+ Mac->MacAddress.Addr[5],
(Vlan == NULL) ? 0 : Vlan->VlanId
);
return Description;
@@ -507,14 +526,14 @@ BmGetNetworkDescription (
**/
CHAR16 *
BmGetLoadFileDescription (
- IN EFI_HANDLE Handle
+ IN EFI_HANDLE Handle
)
{
- EFI_STATUS Status;
- EFI_DEVICE_PATH_PROTOCOL *FilePath;
- EFI_DEVICE_PATH_PROTOCOL *DevicePathNode;
- CHAR16 *Description;
- EFI_LOAD_FILE_PROTOCOL *LoadFile;
+ EFI_STATUS Status;
+ EFI_DEVICE_PATH_PROTOCOL *FilePath;
+ EFI_DEVICE_PATH_PROTOCOL *DevicePathNode;
+ CHAR16 *Description;
+ EFI_LOAD_FILE_PROTOCOL *LoadFile;
Status = gBS->HandleProtocol (Handle, &gEfiLoadFileProtocolGuid, (VOID **)&LoadFile);
if (EFI_ERROR (Status)) {
@@ -525,14 +544,15 @@ BmGetLoadFileDescription (
// Get the file name
//
Description = NULL;
- Status = gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **)&FilePath);
+ Status = gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **)&FilePath);
if (!EFI_ERROR (Status)) {
DevicePathNode = FilePath;
while (!IsDevicePathEnd (DevicePathNode)) {
- if (DevicePathNode->Type == MEDIA_DEVICE_PATH && DevicePathNode->SubType == MEDIA_FILEPATH_DP) {
+ if ((DevicePathNode->Type == MEDIA_DEVICE_PATH) && (DevicePathNode->SubType == MEDIA_FILEPATH_DP)) {
Description = (CHAR16 *)(DevicePathNode + 1);
break;
}
+
DevicePathNode = NextDevicePathNode (DevicePathNode);
}
}
@@ -553,21 +573,21 @@ BmGetLoadFileDescription (
**/
CHAR16 *
BmGetNvmeDescription (
- IN EFI_HANDLE Handle
+ IN EFI_HANDLE Handle
)
{
- EFI_STATUS Status;
- EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *NvmePassthru;
- EFI_DEV_PATH_PTR DevicePath;
- EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET CommandPacket;
- EFI_NVM_EXPRESS_COMMAND Command;
- EFI_NVM_EXPRESS_COMPLETION Completion;
- NVME_ADMIN_CONTROLLER_DATA ControllerData;
- CHAR16 *Description;
- CHAR16 *Char;
- UINTN Index;
-
- Status = gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **) &DevicePath.DevPath);
+ EFI_STATUS Status;
+ EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *NvmePassthru;
+ EFI_DEV_PATH_PTR DevicePath;
+ EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET CommandPacket;
+ EFI_NVM_EXPRESS_COMMAND Command;
+ EFI_NVM_EXPRESS_COMPLETION Completion;
+ NVME_ADMIN_CONTROLLER_DATA ControllerData;
+ CHAR16 *Description;
+ CHAR16 *Char;
+ UINTN Index;
+
+ Status = gBS->HandleProtocol (Handle, &gEfiDevicePathProtocolGuid, (VOID **)&DevicePath.DevPath);
if (EFI_ERROR (Status)) {
return NULL;
}
@@ -575,7 +595,8 @@ BmGetNvmeDescription (
Status = gBS->LocateDevicePath (&gEfiNvmExpressPassThruProtocolGuid, &DevicePath.DevPath, &Handle);
if (EFI_ERROR (Status) ||
(DevicePathType (DevicePath.DevPath) != MESSAGING_DEVICE_PATH) ||
- (DevicePathSubType (DevicePath.DevPath) != MSG_NVME_NAMESPACE_DP)) {
+ (DevicePathSubType (DevicePath.DevPath) != MSG_NVME_NAMESPACE_DP))
+ {
//
// Do not return description when the Handle is not a child of NVME controller.
//
@@ -585,19 +606,19 @@ BmGetNvmeDescription (
//
// Send ADMIN_IDENTIFY command to NVME controller to get the model and serial number.
//
- Status = gBS->HandleProtocol (Handle, &gEfiNvmExpressPassThruProtocolGuid, (VOID **) &NvmePassthru);
+ Status = gBS->HandleProtocol (Handle, &gEfiNvmExpressPassThruProtocolGuid, (VOID **)&NvmePassthru);
ASSERT_EFI_ERROR (Status);
- ZeroMem (&CommandPacket, sizeof(EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET));
- ZeroMem (&Command, sizeof(EFI_NVM_EXPRESS_COMMAND));
- ZeroMem (&Completion, sizeof(EFI_NVM_EXPRESS_COMPLETION));
+ ZeroMem (&CommandPacket, sizeof (EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET));
+ ZeroMem (&Command, sizeof (EFI_NVM_EXPRESS_COMMAND));
+ ZeroMem (&Completion, sizeof (EFI_NVM_EXPRESS_COMPLETION));
Command.Cdw0.Opcode = NVME_ADMIN_IDENTIFY_CMD;
//
// According to Nvm Express 1.1 spec Figure 38, When not used, the field shall be cleared to 0h.
// For the Identify command, the Namespace Identifier is only used for the Namespace data structure.
//
- Command.Nsid = 0;
+ Command.Nsid = 0;
CommandPacket.NvmeCmd = &Command;
CommandPacket.NvmeCompletion = &Completion;
CommandPacket.TransferBuffer = &ControllerData;
@@ -607,15 +628,15 @@ BmGetNvmeDescription (
//
// Set bit 0 (Cns bit) to 1 to identify a controller
//
- Command.Cdw10 = 1;
- Command.Flags = CDW10_VALID;
+ Command.Cdw10 = 1;
+ Command.Flags = CDW10_VALID;
Status = NvmePassthru->PassThru (
- NvmePassthru,
- 0,
- &CommandPacket,
- NULL
- );
+ NvmePassthru,
+ 0,
+ &CommandPacket,
+ NULL
+ );
if (EFI_ERROR (Status)) {
return NULL;
}
@@ -624,20 +645,26 @@ BmGetNvmeDescription (
(ARRAY_SIZE (ControllerData.Mn) + 1
+ ARRAY_SIZE (ControllerData.Sn) + 1
+ MAXIMUM_VALUE_CHARACTERS + 1
- ) * sizeof (CHAR16));
+ ) * sizeof (CHAR16)
+ );
if (Description != NULL) {
Char = Description;
for (Index = 0; Index < ARRAY_SIZE (ControllerData.Mn); Index++) {
- *(Char++) = (CHAR16) ControllerData.Mn[Index];
+ *(Char++) = (CHAR16)ControllerData.Mn[Index];
}
+
*(Char++) = L' ';
for (Index = 0; Index < ARRAY_SIZE (ControllerData.Sn); Index++) {
- *(Char++) = (CHAR16) ControllerData.Sn[Index];
+ *(Char++) = (CHAR16)ControllerData.Sn[Index];
}
+
*(Char++) = L' ';
UnicodeValueToStringS (
- Char, sizeof (CHAR16) * (MAXIMUM_VALUE_CHARACTERS + 1),
- 0, DevicePath.NvmeNamespace->NamespaceId, 0
+ Char,
+ sizeof (CHAR16) * (MAXIMUM_VALUE_CHARACTERS + 1),
+ 0,
+ DevicePath.NvmeNamespace->NamespaceId,
+ 0
);
BmEliminateExtraSpaces (Description);
}
@@ -654,54 +681,56 @@ BmGetNvmeDescription (
**/
CHAR16 *
BmGetMiscDescription (
- IN EFI_HANDLE Handle
+ IN EFI_HANDLE Handle
)
{
- EFI_STATUS Status;
- CHAR16 *Description;
- EFI_BLOCK_IO_PROTOCOL *BlockIo;
- EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs;
+ EFI_STATUS Status;
+ CHAR16 *Description;
+ EFI_BLOCK_IO_PROTOCOL *BlockIo;
+ EFI_SIMPLE_FILE_SYSTEM_PROTOCOL *Fs;
switch (BmDevicePathType (DevicePathFromHandle (Handle))) {
- case BmAcpiFloppyBoot:
- Description = L"Floppy";
- break;
-
- case BmMessageAtapiBoot:
- case BmMessageSataBoot:
- Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **) &BlockIo);
- ASSERT_EFI_ERROR (Status);
- //
- // Assume a removable SATA device should be the DVD/CD device
- //
- Description = BlockIo->Media->RemovableMedia ? L"DVD/CDROM" : L"Hard Drive";
- break;
+ case BmAcpiFloppyBoot:
+ Description = L"Floppy";
+ break;
+
+ case BmMessageAtapiBoot:
+ case BmMessageSataBoot:
+ Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo);
+ ASSERT_EFI_ERROR (Status);
+ //
+ // Assume a removable SATA device should be the DVD/CD device
+ //
+ Description = BlockIo->Media->RemovableMedia ? L"DVD/CDROM" : L"Hard Drive";
+ break;
- case BmMessageUsbBoot:
- Description = L"USB Device";
- break;
+ case BmMessageUsbBoot:
+ Description = L"USB Device";
+ break;
- case BmMessageScsiBoot:
- Description = L"SCSI Device";
- break;
+ case BmMessageScsiBoot:
+ Description = L"SCSI Device";
+ break;
- case BmHardwareDeviceBoot:
- Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **) &BlockIo);
- if (!EFI_ERROR (Status)) {
- Description = BlockIo->Media->RemovableMedia ? L"Removable Disk" : L"Hard Drive";
- } else {
- Description = L"Misc Device";
- }
- break;
+ case BmHardwareDeviceBoot:
+ Status = gBS->HandleProtocol (Handle, &gEfiBlockIoProtocolGuid, (VOID **)&BlockIo);
+ if (!EFI_ERROR (Status)) {
+ Description = BlockIo->Media->RemovableMedia ? L"Removable Disk" : L"Hard Drive";
+ } else {
+ Description = L"Misc Device";
+ }
- default:
- Status = gBS->HandleProtocol (Handle, &gEfiSimpleFileSystemProtocolGuid, (VOID **) &Fs);
- if (!EFI_ERROR (Status)) {
- Description = L"Non-Block Boot Device";
- } else {
- Description = L"Misc Device";
- }
- break;
+ break;
+
+ default:
+ Status = gBS->HandleProtocol (Handle, &gEfiSimpleFileSystemProtocolGuid, (VOID **)&Fs);
+ if (!EFI_ERROR (Status)) {
+ Description = L"Non-Block Boot Device";
+ } else {
+ Description = L"Misc Device";
+ }
+
+ break;
}
return AllocateCopyPool (StrSize (Description), Description);
@@ -722,13 +751,14 @@ EfiBootManagerRegisterBootDescriptionHandler (
IN EFI_BOOT_MANAGER_BOOT_DESCRIPTION_HANDLER Handler
)
{
- LIST_ENTRY *Link;
- BM_BOOT_DESCRIPTION_ENTRY *Entry;
+ LIST_ENTRY *Link;
+ BM_BOOT_DESCRIPTION_ENTRY *Entry;
for ( Link = GetFirstNode (&mPlatformBootDescriptionHandlers)
- ; !IsNull (&mPlatformBootDescriptionHandlers, Link)
- ; Link = GetNextNode (&mPlatformBootDescriptionHandlers, Link)
- ) {
+ ; !IsNull (&mPlatformBootDescriptionHandlers, Link)
+ ; Link = GetNextNode (&mPlatformBootDescriptionHandlers, Link)
+ )
+ {
Entry = CR (Link, BM_BOOT_DESCRIPTION_ENTRY, Link, BM_BOOT_DESCRIPTION_ENTRY_SIGNATURE);
if (Entry->Handler == Handler) {
return EFI_ALREADY_STARTED;
@@ -746,7 +776,7 @@ EfiBootManagerRegisterBootDescriptionHandler (
return EFI_SUCCESS;
}
-BM_GET_BOOT_DESCRIPTION mBmBootDescriptionHandlers[] = {
+BM_GET_BOOT_DESCRIPTION mBmBootDescriptionHandlers[] = {
BmGetUsbDescription,
BmGetDescriptionFromDiskInfo,
BmGetNetworkDescription,
@@ -764,22 +794,22 @@ BM_GET_BOOT_DESCRIPTION mBmBootDescriptionHandlers[] = {
**/
CHAR16 *
BmGetBootDescription (
- IN EFI_HANDLE Handle
+ IN EFI_HANDLE Handle
)
{
- LIST_ENTRY *Link;
- BM_BOOT_DESCRIPTION_ENTRY *Entry;
- CHAR16 *Description;
- CHAR16 *DefaultDescription;
- CHAR16 *Temp;
- UINTN Index;
+ LIST_ENTRY *Link;
+ BM_BOOT_DESCRIPTION_ENTRY *Entry;
+ CHAR16 *Description;
+ CHAR16 *DefaultDescription;
+ CHAR16 *Temp;
+ UINTN Index;
//
// Firstly get the default boot description
//
DefaultDescription = NULL;
for (Index = 0; Index < ARRAY_SIZE (mBmBootDescriptionHandlers); Index++) {
- DefaultDescription = mBmBootDescriptionHandlers[Index] (Handle);
+ DefaultDescription = mBmBootDescriptionHandlers[Index](Handle);
if (DefaultDescription != NULL) {
//
// Avoid description confusion between UEFI & Legacy boot option by adding "UEFI " prefix
@@ -794,16 +824,18 @@ BmGetBootDescription (
break;
}
}
+
ASSERT (DefaultDescription != NULL);
//
// Secondly query platform for the better boot description
//
for ( Link = GetFirstNode (&mPlatformBootDescriptionHandlers)
- ; !IsNull (&mPlatformBootDescriptionHandlers, Link)
- ; Link = GetNextNode (&mPlatformBootDescriptionHandlers, Link)
- ) {
- Entry = CR (Link, BM_BOOT_DESCRIPTION_ENTRY, Link, BM_BOOT_DESCRIPTION_ENTRY_SIGNATURE);
+ ; !IsNull (&mPlatformBootDescriptionHandlers, Link)
+ ; Link = GetNextNode (&mPlatformBootDescriptionHandlers, Link)
+ )
+ {
+ Entry = CR (Link, BM_BOOT_DESCRIPTION_ENTRY, Link, BM_BOOT_DESCRIPTION_ENTRY_SIGNATURE);
Description = Entry->Handler (Handle, DefaultDescription);
if (Description != NULL) {
FreePool (DefaultDescription);
@@ -823,16 +855,16 @@ BmGetBootDescription (
**/
VOID
BmMakeBootOptionDescriptionUnique (
- EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions,
- UINTN BootOptionCount
+ EFI_BOOT_MANAGER_LOAD_OPTION *BootOptions,
+ UINTN BootOptionCount
)
{
- UINTN Base;
- UINTN Index;
- UINTN DescriptionSize;
- UINTN MaxSuffixSize;
- BOOLEAN *Visited;
- UINTN MatchCount;
+ UINTN Base;
+ UINTN Index;
+ UINTN DescriptionSize;
+ UINTN MaxSuffixSize;
+ BOOLEAN *Visited;
+ UINTN MatchCount;
if (BootOptionCount == 0) {
return;
@@ -856,15 +888,17 @@ BmMakeBootOptionDescriptionUnique (
Visited[Base] = TRUE;
DescriptionSize = StrSize (BootOptions[Base].Description);
for (Index = Base + 1; Index < BootOptionCount; Index++) {
- if (!Visited[Index] && StrCmp (BootOptions[Base].Description, BootOptions[Index].Description) == 0) {
+ if (!Visited[Index] && (StrCmp (BootOptions[Base].Description, BootOptions[Index].Description) == 0)) {
Visited[Index] = TRUE;
MatchCount++;
FreePool (BootOptions[Index].Description);
BootOptions[Index].Description = AllocatePool (DescriptionSize + MaxSuffixSize);
UnicodeSPrint (
- BootOptions[Index].Description, DescriptionSize + MaxSuffixSize,
+ BootOptions[Index].Description,
+ DescriptionSize + MaxSuffixSize,
L"%s %d",
- BootOptions[Base].Description, MatchCount
+ BootOptions[Base].Description,
+ MatchCount
);
}
}