summaryrefslogtreecommitdiff
path: root/MdePkg/Library/UefiDevicePathLib
diff options
context:
space:
mode:
authorRuiyu Ni <ruiyu.ni@intel.com>2013-11-07 02:30:13 +0000
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>2013-11-07 02:30:13 +0000
commit9da3888456debd9c2b965278fe88a2cc08d6aee9 (patch)
tree4e22214f7ffba519632cca159106507eaf20e645 /MdePkg/Library/UefiDevicePathLib
parent09363ecafd77e39a724c8ed7ea48e1512028b1c5 (diff)
downloadedk2-platforms-9da3888456debd9c2b965278fe88a2cc08d6aee9.tar.xz
Fix several bugs in DevicePathLib implementation regarding the device path node and text conversion.
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com> Reviewed-by: Feng Tian <feng.tian@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14827 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'MdePkg/Library/UefiDevicePathLib')
-rw-r--r--MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c112
-rw-r--r--MdePkg/Library/UefiDevicePathLib/DevicePathToText.c23
2 files changed, 71 insertions, 64 deletions
diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
index 91203190ea..8943191bd4 100644
--- a/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathFromText.c
@@ -479,7 +479,7 @@ StrToIPv4Addr (
UINTN Index;
for (Index = 0; Index < 4; Index++) {
- IPv4Addr->Addr[Index] = (UINT8) StrDecimalToUintn (SplitStr (Str, L'.'));
+ IPv4Addr->Addr[Index] = (UINT8) Strtoi (SplitStr (Str, L'.'));
}
}
@@ -1055,8 +1055,8 @@ DevPathFromTextAcpiAdr (
**/
EFI_DEVICE_PATH_PROTOCOL *
DevPathFromTextAta (
- IN CHAR16 *TextDeviceNode
- )
+IN CHAR16 *TextDeviceNode
+)
{
CHAR16 *PrimarySecondaryStr;
CHAR16 *SlaveMasterStr;
@@ -1064,18 +1064,31 @@ DevPathFromTextAta (
ATAPI_DEVICE_PATH *Atapi;
Atapi = (ATAPI_DEVICE_PATH *) CreateDeviceNode (
- MESSAGING_DEVICE_PATH,
- MSG_ATAPI_DP,
- (UINT16) sizeof (ATAPI_DEVICE_PATH)
- );
-
- PrimarySecondaryStr = GetNextParamStr (&TextDeviceNode);
- SlaveMasterStr = GetNextParamStr (&TextDeviceNode);
- LunStr = GetNextParamStr (&TextDeviceNode);
+ MESSAGING_DEVICE_PATH,
+ MSG_ATAPI_DP,
+ (UINT16) sizeof (ATAPI_DEVICE_PATH)
+ );
+
+ PrimarySecondaryStr = GetNextParamStr (&TextDeviceNode);
+ SlaveMasterStr = GetNextParamStr (&TextDeviceNode);
+ LunStr = GetNextParamStr (&TextDeviceNode);
+
+ if (StrCmp (PrimarySecondaryStr, L"Primary") == 0) {
+ Atapi->PrimarySecondary = 0;
+ } else if (StrCmp (PrimarySecondaryStr, L"Secondary") == 0) {
+ Atapi->PrimarySecondary = 1;
+ } else {
+ Atapi->PrimarySecondary = (UINT8) Strtoi (PrimarySecondaryStr);
+ }
+ if (StrCmp (SlaveMasterStr, L"Master") == 0) {
+ Atapi->SlaveMaster = 0;
+ } else if (StrCmp (SlaveMasterStr, L"Slave") == 0) {
+ Atapi->SlaveMaster = 1;
+ } else {
+ Atapi->SlaveMaster = (UINT8) Strtoi (SlaveMasterStr);
+ }
- Atapi->PrimarySecondary = (UINT8) ((StrCmp (PrimarySecondaryStr, L"Primary") == 0) ? 0 : 1);
- Atapi->SlaveMaster = (UINT8) ((StrCmp (SlaveMasterStr, L"Master") == 0) ? 0 : 1);
- Atapi->Lun = (UINT16) Strtoi (LunStr);
+ Atapi->Lun = (UINT16) Strtoi (LunStr);
return (EFI_DEVICE_PATH_PROTOCOL *) Atapi;
}
@@ -1880,8 +1893,12 @@ DevPathFromTextUart (
(UINT16) sizeof (UART_DEVICE_PATH)
);
- Uart->BaudRate = (StrCmp (BaudStr, L"DEFAULT") == 0) ? 115200 : StrDecimalToUintn (BaudStr);
- Uart->DataBits = (UINT8) ((StrCmp (DataBitsStr, L"DEFAULT") == 0) ? 8 : StrDecimalToUintn (DataBitsStr));
+ if (StrCmp (BaudStr, L"DEFAULT") == 0) {
+ Uart->BaudRate = 115200;
+ } else {
+ Strtoi64 (BaudStr, &Uart->BaudRate);
+ }
+ Uart->DataBits = (UINT8) ((StrCmp (DataBitsStr, L"DEFAULT") == 0) ? 8 : Strtoi (DataBitsStr));
switch (*ParityStr) {
case L'D':
Uart->Parity = 0;
@@ -1908,7 +1925,8 @@ DevPathFromTextUart (
break;
default:
- Uart->Parity = 0xff;
+ Uart->Parity = (UINT8) Strtoi (ParityStr);
+ break;
}
if (StrCmp (StopBitsStr, L"D") == 0) {
@@ -1920,7 +1938,7 @@ DevPathFromTextUart (
} else if (StrCmp (StopBitsStr, L"2") == 0) {
Uart->StopBits = (UINT8) 3;
} else {
- Uart->StopBits = 0xff;
+ Uart->StopBits = (UINT8) Strtoi (StopBitsStr);
}
return (EFI_DEVICE_PATH_PROTOCOL *) Uart;
@@ -2351,21 +2369,30 @@ DevPathFromTextUsbWwid (
CHAR16 *InterfaceNumStr;
CHAR16 *SerialNumberStr;
USB_WWID_DEVICE_PATH *UsbWwid;
-
- VIDStr = GetNextParamStr (&TextDeviceNode);
- PIDStr = GetNextParamStr (&TextDeviceNode);
- InterfaceNumStr = GetNextParamStr (&TextDeviceNode);
- SerialNumberStr = GetNextParamStr (&TextDeviceNode);
- UsbWwid = (USB_WWID_DEVICE_PATH *) CreateDeviceNode (
+ UINTN SerialNumberStrLen;
+
+ VIDStr = GetNextParamStr (&TextDeviceNode);
+ PIDStr = GetNextParamStr (&TextDeviceNode);
+ InterfaceNumStr = GetNextParamStr (&TextDeviceNode);
+ SerialNumberStr = GetNextParamStr (&TextDeviceNode);
+ SerialNumberStrLen = StrLen (SerialNumberStr);
+ if (SerialNumberStrLen >= 2 &&
+ SerialNumberStr[0] == L'\"' &&
+ SerialNumberStr[SerialNumberStrLen - 1] == L'\"'
+ ) {
+ SerialNumberStr[SerialNumberStrLen - 1] = L'\0';
+ SerialNumberStr++;
+ SerialNumberStrLen -= 2;
+ }
+ UsbWwid = (USB_WWID_DEVICE_PATH *) CreateDeviceNode (
MESSAGING_DEVICE_PATH,
MSG_USB_WWID_DP,
- (UINT16) (sizeof (USB_WWID_DEVICE_PATH) + StrSize (SerialNumberStr))
+ (UINT16) (sizeof (USB_WWID_DEVICE_PATH) + SerialNumberStrLen * sizeof (CHAR16))
);
-
- UsbWwid->VendorId = (UINT16) Strtoi (VIDStr);
- UsbWwid->ProductId = (UINT16) Strtoi (PIDStr);
- UsbWwid->InterfaceNumber = (UINT16) Strtoi (InterfaceNumStr);
- StrCpy ((CHAR16 *) ((UINT8 *) UsbWwid + sizeof (USB_WWID_DEVICE_PATH)), SerialNumberStr);
+ UsbWwid->VendorId = (UINT16) Strtoi (VIDStr);
+ UsbWwid->ProductId = (UINT16) Strtoi (PIDStr);
+ UsbWwid->InterfaceNumber = (UINT16) Strtoi (InterfaceNumStr);
+ StrnCpy ((CHAR16 *) ((UINT8 *) UsbWwid + sizeof (USB_WWID_DEVICE_PATH)), SerialNumberStr, SerialNumberStrLen);
return (EFI_DEVICE_PATH_PROTOCOL *) UsbWwid;
}
@@ -2526,7 +2553,7 @@ DevPathFromTextHD (
(UINT16) sizeof (HARDDRIVE_DEVICE_PATH)
);
- Hd->PartitionNumber = (UINT32) StrDecimalToUintn (PartitionStr);
+ Hd->PartitionNumber = (UINT32) Strtoi (PartitionStr);
ZeroMem (Hd->Signature, 16);
Hd->MBRType = (UINT8) 0;
@@ -2596,7 +2623,7 @@ DevPathFromTextCDROM (
**/
EFI_DEVICE_PATH_PROTOCOL *
-DevPathFromTextVenMEDIA (
+DevPathFromTextVenMedia (
IN CHAR16 *TextDeviceNode
)
{
@@ -2818,29 +2845,18 @@ DevPathFromTextSata (
CHAR16 *Param2;
CHAR16 *Param3;
- //
- // The PMPN is optional.
- //
Param1 = GetNextParamStr (&TextDeviceNode);
Param2 = GetNextParamStr (&TextDeviceNode);
- Param3 = NULL;
- if (!IS_NULL (TextDeviceNode)) {
- Param3 = GetNextParamStr (&TextDeviceNode);
- }
+ Param3 = GetNextParamStr (&TextDeviceNode);
Sata = (SATA_DEVICE_PATH *) CreateDeviceNode (
MESSAGING_DEVICE_PATH,
MSG_SATA_DP,
(UINT16) sizeof (SATA_DEVICE_PATH)
);
- Sata->HBAPortNumber = (UINT16) StrHexToUintn (Param1);
- if (Param3 != NULL) {
- Sata->PortMultiplierPortNumber = (UINT16) StrHexToUintn (Param2);
- Param2 = Param3;
- } else {
- Sata->PortMultiplierPortNumber = SATA_HBA_DIRECT_CONNECT_FLAG;
- }
- Sata->Lun = (UINT16) StrHexToUintn (Param2);
+ Sata->HBAPortNumber = (UINT16) Strtoi (Param1);
+ Sata->PortMultiplierPortNumber = (UINT16) Strtoi (Param2);
+ Sata->Lun = (UINT16) Strtoi (Param3);
return (EFI_DEVICE_PATH_PROTOCOL *) Sata;
}
@@ -2904,7 +2920,7 @@ GLOBAL_REMOVE_IF_UNREFERENCED DEVICE_PATH_FROM_TEXT_TABLE mUefiDevicePathLibDevP
{L"Vlan", DevPathFromTextVlan },
{L"HD", DevPathFromTextHD },
{L"CDROM", DevPathFromTextCDROM },
- {L"VenMEDIA", DevPathFromTextVenMEDIA },
+ {L"VenMedia", DevPathFromTextVenMedia },
{L"Media", DevPathFromTextMedia },
{L"Fv", DevPathFromTextFv },
{L"FvFile", DevPathFromTextFvFile },
diff --git a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
index 81cf84e25d..eebdbf2394 100644
--- a/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
+++ b/MdePkg/Library/UefiDevicePathLib/DevicePathToText.c
@@ -990,22 +990,13 @@ DevPathToTextSata (
SATA_DEVICE_PATH *Sata;
Sata = DevPath;
- if ((Sata->PortMultiplierPortNumber & SATA_HBA_DIRECT_CONNECT_FLAG) != 0) {
- UefiDevicePathLibCatPrint (
- Str,
- L"Sata(0x%x,0x%x)",
- Sata->HBAPortNumber,
- Sata->Lun
- );
- } else {
- UefiDevicePathLibCatPrint (
- Str,
- L"Sata(0x%x,0x%x,0x%x)",
- Sata->HBAPortNumber,
- Sata->PortMultiplierPortNumber,
- Sata->Lun
- );
- }
+ UefiDevicePathLibCatPrint (
+ Str,
+ L"Sata(0x%x,0x%x,0x%x)",
+ Sata->HBAPortNumber,
+ Sata->PortMultiplierPortNumber,
+ Sata->Lun
+ );
}
/**