From: Ruiyu Ni Date: Fri, 4 Mar 2016 10:12:38 +0000 (+0800) Subject: MdeModulePkg/Bds: More user-friendly network boot option description X-Git-Tag: edk2-stable201903~7679 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=e4c7cefe3d088df0fa05bf78659fa8094569dd3a MdeModulePkg/Bds: More user-friendly network boot option description The patch enhances the UefiBootManagerLib to use more user-friendly network boot option description. It builds description like below: "PXEv6 (MAC:112233445566 VLAN1)" "HTTPv4 (MAC:112233445566)" Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ruiyu Ni Reviewed-by: Siyuan Fu --- diff --git a/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c b/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c index 5c77e86006..69a2914d56 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c +++ b/MdeModulePkg/Library/UefiBootManagerLib/BmBootDescription.c @@ -28,24 +28,19 @@ LIST_ENTRY mPlatformBootDescriptionHandlers = INITIALIZE_LIST_HEAD_VARIABLE (mPl /** For a bootable Device path, return its boot type. - @param DevicePath The bootable device Path to check - - @retval AcpiFloppyBoot If given device path contains ACPI_DEVICE_PATH type device path node - which HID is floppy device. - @retval MessageAtapiBoot If given device path contains MESSAGING_DEVICE_PATH type device path node - and its last device path node's subtype is MSG_ATAPI_DP. - @retval MessageSataBoot If given device path contains MESSAGING_DEVICE_PATH type device path node - and its last device path node's subtype is MSG_SATA_DP. - @retval MessageScsiBoot If given device path contains MESSAGING_DEVICE_PATH type device path node - and its last device path node's subtype is MSG_SCSI_DP. - @retval MessageUsbBoot If given device path contains MESSAGING_DEVICE_PATH type device path node - and its last device path node's subtype is MSG_USB_DP. - @retval MessageNetworkBoot If given device path contains MESSAGING_DEVICE_PATH type device path node - and its last device path node's subtype is MSG_MAC_ADDR_DP, MSG_VLAN_DP, - MSG_IPv4_DP or MSG_IPv6_DP. - @retval MessageHttpBoot If given device path contains MESSAGING_DEVICE_PATH type device path node - and its last device path node's subtype is MSG_URI_DP. - @retval UnsupportedBoot If tiven device path doesn't match the above condition, it's not supported. + @param DevicePath The bootable device Path to check + + @retval AcpiFloppyBoot If given device path contains ACPI_DEVICE_PATH type device path node + which HID is floppy device. + @retval MessageAtapiBoot If given device path contains MESSAGING_DEVICE_PATH type device path node + and its last device path node's subtype is MSG_ATAPI_DP. + @retval MessageSataBoot If given device path contains MESSAGING_DEVICE_PATH type device path node + and its last device path node's subtype is MSG_SATA_DP. + @retval MessageScsiBoot If given device path contains MESSAGING_DEVICE_PATH type device path node + and its last device path node's subtype is MSG_SCSI_DP. + @retval MessageUsbBoot If given device path contains MESSAGING_DEVICE_PATH type device path node + and its last device path node's subtype is MSG_USB_DP. + @retval BmMiscBoot If tiven device path doesn't match the above condition. **/ BM_BOOT_TYPE @@ -108,17 +103,6 @@ BmDevicePathType ( case MSG_SCSI_DP: return BmMessageScsiBoot; break; - - case MSG_MAC_ADDR_DP: - case MSG_VLAN_DP: - case MSG_IPv4_DP: - case MSG_IPv6_DP: - return BmMessageNetworkBoot; - break; - - case MSG_URI_DP: - return BmMessageHttpBoot; - break; } } } @@ -351,6 +335,125 @@ BmGetUsbDescription ( return Description; } +/** + Return the description for network boot device. + + @param Handle Controller handle. + + @return The description string. +**/ +CHAR16 * +BmGetNetworkDescription ( + 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; + + Status = gBS->OpenProtocol ( + Handle, + &gEfiLoadFileProtocolGuid, + NULL, + gImageHandle, + Handle, + EFI_OPEN_PROTOCOL_TEST_PROTOCOL + ); + if (EFI_ERROR (Status)) { + return NULL; + } + + Status = gBS->OpenProtocol ( + Handle, + &gEfiDevicePathProtocolGuid, + (VOID **) &DevicePath, + gImageHandle, + Handle, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + if (EFI_ERROR (Status) || (DevicePath == NULL)) { + return NULL; + } + + // + // The PXE device path is like: + // ....../Mac(...)[/Vlan(...)] + // ....../Mac(...)[/Vlan(...)]/IPv4(...) + // ....../Mac(...)[/Vlan(...)]/IPv6(...) + // + // The HTTP device path is like: + // ....../Mac(...)[/Vlan(...)]/IPv4(...)/Uri(...) + // ....../Mac(...)[/Vlan(...)]/IPv6(...)/Uri(...) + // + while (!IsDevicePathEnd (DevicePath) && + ((DevicePathType (DevicePath) != MESSAGING_DEVICE_PATH) || + (DevicePathSubType (DevicePath) != MSG_MAC_ADDR_DP)) + ) { + DevicePath = NextDevicePathNode (DevicePath); + } + + if (IsDevicePathEnd (DevicePath)) { + return NULL; + } + + Mac = (MAC_ADDR_DEVICE_PATH *) DevicePath; + DevicePath = NextDevicePathNode (DevicePath); + + if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) && + (DevicePathSubType (DevicePath) == MSG_VLAN_DP) + ) { + Vlan = (VLAN_DEVICE_PATH *) DevicePath; + DevicePath = NextDevicePathNode (DevicePath); + } else { + Vlan = NULL; + } + + if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) && + ((DevicePathSubType (DevicePath) == MSG_IPv4_DP) || + (DevicePathSubType (DevicePath) == MSG_IPv6_DP)) + ) { + Ip = DevicePath; + DevicePath = NextDevicePathNode (DevicePath); + } else { + Ip = NULL; + } + + if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) && + (DevicePathSubType (DevicePath) == MSG_URI_DP) + ) { + Uri = DevicePath; + DevicePath = NextDevicePathNode (DevicePath); + } else { + Uri = NULL; + } + + // + // Build description like below: + // "PXEv6 (MAC:112233445566 VLAN1)" + // "HTTPv4 (MAC:112233445566)" + // + DescriptionSize = sizeof (L"HTTPv6 (MAC:112233445566 VLAN65535)"); + Description = AllocatePool (DescriptionSize); + ASSERT (Description != NULL); + UnicodeSPrint ( + 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], + (Vlan == NULL) ? 0 : Vlan->VlanId + ); + return Description; +} + /** Return the boot description for the controller based on the type. @@ -400,14 +503,6 @@ BmGetMiscDescription ( } break; - case BmMessageNetworkBoot: - Description = L"Network"; - break; - - case BmMessageHttpBoot: - Description = L"Http"; - break; - default: Status = gBS->HandleProtocol (Handle, &gEfiSimpleFileSystemProtocolGuid, (VOID **) &Fs); if (!EFI_ERROR (Status)) { @@ -463,6 +558,7 @@ EfiBootManagerRegisterBootDescriptionHandler ( BM_GET_BOOT_DESCRIPTION mBmBootDescriptionHandlers[] = { BmGetUsbDescription, BmGetDescriptionFromDiskInfo, + BmGetNetworkDescription, BmGetMiscDescription }; diff --git a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h b/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h index c1514c3ee4..b261d769d2 100644 --- a/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h +++ b/MdeModulePkg/Library/UefiBootManagerLib/InternalBm.h @@ -92,8 +92,6 @@ typedef enum { BmMessageSataBoot, BmMessageUsbBoot, BmMessageScsiBoot, - BmMessageNetworkBoot, - BmMessageHttpBoot, BmMiscBoot } BM_BOOT_TYPE;