2 Main file for support of shell consist mapping.
4 Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 #include "UefiShellCommandLib.h"
15 #include <Library/DevicePathLib.h>
16 #include <Library/SortLib.h>
17 #include <Library/UefiLib.h>
18 #include <Protocol/UsbIo.h>
19 #include <Protocol/BlockIo.h>
20 #include <Protocol/SimpleFileSystem.h>
42 } DEVICE_CONSIST_MAPPING_INFO
;
50 Serial Decode function.
52 @param DevPath The Device path info.
53 @param MapInfo The map info.
54 @param OrigDevPath The original device path protocol.
59 (EFIAPI
*SERIAL_DECODE_FUNCTION
) (
60 EFI_DEVICE_PATH_PROTOCOL
*DevPath
,
61 DEVICE_CONSIST_MAPPING_INFO
*MapInfo
,
62 EFI_DEVICE_PATH_PROTOCOL
*OrigDevPath
68 SERIAL_DECODE_FUNCTION SerialFun
;
69 INTN (EFIAPI
*CompareFun
) (EFI_DEVICE_PATH_PROTOCOL
*DevPath
, EFI_DEVICE_PATH_PROTOCOL
*DevPath2
);
70 } DEV_PATH_CONSIST_MAPPING_TABLE
;
74 Concatenates a formatted unicode string to allocated pool.
75 The caller must free the resulting buffer.
77 @param Str Tracks the allocated pool, size in use, and amount of pool allocated.
78 @param Fmt The format string
79 @param ... The data will be printed.
81 @return Allocated buffer with the formatted string printed in it.
82 The caller must free the allocated buffer.
83 The buffer allocation is not packed.
89 IN OUT POOL_PRINT
*Str
,
98 AppendStr
= AllocateZeroPool (0x1000);
99 if (AppendStr
== NULL
) {
104 VA_START (Args
, Fmt
);
105 UnicodeVSPrint (AppendStr
, 0x1000, Fmt
, Args
);
107 if (NULL
== Str
->Str
) {
108 StringSize
= StrSize (AppendStr
);
109 Str
->Str
= AllocateZeroPool (StringSize
);
110 ASSERT (Str
->Str
!= NULL
);
112 StringSize
= StrSize (AppendStr
);
113 StringSize
+= (StrSize (Str
->Str
) - sizeof (UINT16
));
115 Str
->Str
= ReallocatePool (
120 ASSERT (Str
->Str
!= NULL
);
123 StrCatS (Str
->Str
, StringSize
/sizeof(CHAR16
), AppendStr
);
124 Str
->Len
= StringSize
;
126 FreePool (AppendStr
);
130 MTD_NAME mMTDName
[] = {
154 Function to append a 64 bit number / 25 onto the string.
156 @param[in, out] Str The string so append onto.
157 @param[in] Num The number to divide and append.
159 @retval EFI_INVALID_PARAMETER A parameter was NULL.
160 @retval EFI_SUCCESS The appending was successful.
165 IN OUT POOL_PRINT
*Str
,
173 return (EFI_INVALID_PARAMETER
);
176 Result
= DivU64x32Remainder (Num
, 25, &Rem
);
178 AppendCSDNum2 (Str
, Result
);
181 CatPrint (Str
, L
"%c", Rem
+ 'a');
182 return (EFI_SUCCESS
);
186 Function to append a 64 bit number onto the mapping info.
188 @param[in, out] MappingItem The mapping info object to append onto.
189 @param[in] Num The info to append.
191 @retval EFI_INVALID_PARAMETER A parameter was NULL.
192 @retval EFI_SUCCESS The appending was successful.
197 IN OUT DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
201 if (MappingItem
== NULL
) {
202 return EFI_INVALID_PARAMETER
;
205 if (MappingItem
->Digital
) {
206 CatPrint (&MappingItem
->Csd
, L
"%ld", Num
);
208 AppendCSDNum2 (&MappingItem
->Csd
, Num
);
211 MappingItem
->Digital
= (BOOLEAN
)!(MappingItem
->Digital
);
213 return (EFI_SUCCESS
);
217 Function to append string into the mapping info.
219 @param[in, out] MappingItem The mapping info object to append onto.
220 @param[in] Str The info to append.
222 @retval EFI_INVALID_PARAMETER A parameter was NULL.
223 @retval EFI_SUCCESS The appending was successful.
228 IN OUT DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
234 if (Str
== NULL
|| MappingItem
== NULL
) {
235 return (EFI_INVALID_PARAMETER
);
238 if (MappingItem
->Digital
) {
240 // To aVOID mult-meaning, the mapping is:
241 // 0 1 2 3 4 5 6 7 8 9 a b c d e f
242 // 0 16 2 3 4 5 6 7 8 9 10 11 12 13 14 15
244 for (Index
= Str
; *Index
!= 0; Index
++) {
255 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
);
259 CatPrint (&MappingItem
->Csd
, L
"16");
268 CatPrint (&MappingItem
->Csd
, L
"1%c", *Index
- 'a' + '0');
277 CatPrint (&MappingItem
->Csd
, L
"1%c", *Index
- 'A' + '0');
282 for (Index
= Str
; *Index
!= 0; Index
++) {
285 // 0 1 2 3 4 5 6 7 8 9 a b c d e f
286 // a b c d e f g h i j k l m n o p
288 if (*Index
>= '0' && *Index
<= '9') {
289 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- '0' + 'a');
290 } else if (*Index
>= 'a' && *Index
<= 'f') {
291 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- 'a' + 'k');
292 } else if (*Index
>= 'A' && *Index
<= 'F') {
293 CatPrint (&MappingItem
->Csd
, L
"%c", *Index
- 'A' + 'k');
298 MappingItem
->Digital
= (BOOLEAN
)!(MappingItem
->Digital
);
300 return (EFI_SUCCESS
);
304 Function to append a Guid to the mapping item.
306 @param[in, out] MappingItem The item to append onto.
307 @param[in] Guid The guid to append.
309 @retval EFI_SUCCESS The appending operation was successful.
310 @retval EFI_INVALID_PARAMETER A parameter was NULL.
315 DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
321 if (Guid
== NULL
|| MappingItem
== NULL
) {
322 return (EFI_INVALID_PARAMETER
);
332 AppendCSDStr (MappingItem
, Buffer
);
334 return (EFI_SUCCESS
);
338 Function to compare 2 APCI device paths.
340 @param[in] DevicePath1 The first device path to compare.
341 @param[in] DevicePath2 The second device path to compare.
343 @retval 0 The device paths represent the same device.
344 @return Non zero if the devices are different, zero otherwise.
349 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
350 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
353 ACPI_HID_DEVICE_PATH
*Acpi1
;
354 ACPI_HID_DEVICE_PATH
*Acpi2
;
356 if (DevicePath1
== NULL
|| DevicePath2
== NULL
) {
360 Acpi1
= (ACPI_HID_DEVICE_PATH
*) DevicePath1
;
361 Acpi2
= (ACPI_HID_DEVICE_PATH
*) DevicePath2
;
362 if (Acpi1
->HID
> Acpi2
->HID
|| (Acpi1
->HID
== Acpi2
->HID
&& Acpi1
->UID
> Acpi2
->UID
)) {
366 if (Acpi1
->HID
== Acpi2
->HID
&& Acpi1
->UID
== Acpi2
->UID
) {
374 Function to compare 2 PCI device paths.
376 @param[in] DevicePath1 The first device path to compare.
377 @param[in] DevicePath2 The second device path to compare.
379 @retval 0 The device paths represent the same device.
380 @return Non zero if the devices are different, zero otherwise.
385 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
386 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
389 PCI_DEVICE_PATH
*Pci1
;
390 PCI_DEVICE_PATH
*Pci2
;
392 ASSERT(DevicePath1
!= NULL
);
393 ASSERT(DevicePath2
!= NULL
);
395 Pci1
= (PCI_DEVICE_PATH
*) DevicePath1
;
396 Pci2
= (PCI_DEVICE_PATH
*) DevicePath2
;
397 if (Pci1
->Device
> Pci2
->Device
|| (Pci1
->Device
== Pci2
->Device
&& Pci1
->Function
> Pci2
->Function
)) {
401 if (Pci1
->Device
== Pci2
->Device
&& Pci1
->Function
== Pci2
->Function
) {
409 Do a comparison on 2 device paths.
411 @param[in] DevicePath1 The first device path.
412 @param[in] DevicePath2 The second device path.
414 @retval 0 The 2 device paths are the same.
415 @retval <0 DevicePath2 is greater than DevicePath1.
416 @retval >0 DevicePath1 is greater than DevicePath2.
420 DevPathCompareDefault (
421 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath1
,
422 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath2
428 ASSERT(DevicePath1
!= NULL
);
429 ASSERT(DevicePath2
!= NULL
);
431 DevPathSize1
= DevicePathNodeLength (DevicePath1
);
432 DevPathSize2
= DevicePathNodeLength (DevicePath2
);
433 if (DevPathSize1
> DevPathSize2
) {
435 } else if (DevPathSize1
< DevPathSize2
) {
438 return CompareMem (DevicePath1
, DevicePath2
, DevPathSize1
);
443 DevicePathNode must be SerialHDD Channel type and this will populate the MappingItem.
445 @param[in] DevicePathNode The node to get info on.
446 @param[in] MappingItem The info item to populate.
447 @param[in] DevicePath Ignored.
451 DevPathSerialHardDrive (
452 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
453 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
454 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
457 HARDDRIVE_DEVICE_PATH
*Hd
;
459 ASSERT(DevicePathNode
!= NULL
);
460 ASSERT(MappingItem
!= NULL
);
462 Hd
= (HARDDRIVE_DEVICE_PATH
*) DevicePathNode
;
463 if (MappingItem
->Mtd
== MTDTypeUnknown
) {
464 MappingItem
->Mtd
= MTDTypeHardDisk
;
467 AppendCSDNum (MappingItem
, Hd
->PartitionNumber
);
471 DevicePathNode must be SerialAtapi Channel type and this will populate the MappingItem.
473 @param[in] DevicePathNode The node to get info on.
474 @param[in] MappingItem The info item to populate.
475 @param[in] DevicePath Ignored.
480 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
481 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
482 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
485 ATAPI_DEVICE_PATH
*Atapi
;
487 ASSERT(DevicePathNode
!= NULL
);
488 ASSERT(MappingItem
!= NULL
);
490 Atapi
= (ATAPI_DEVICE_PATH
*) DevicePathNode
;
491 AppendCSDNum (MappingItem
, (Atapi
->PrimarySecondary
* 2 + Atapi
->SlaveMaster
));
495 DevicePathNode must be SerialCDROM Channel type and this will populate the MappingItem.
497 @param[in] DevicePathNode The node to get info on.
498 @param[in] MappingItem The info item to populate.
499 @param[in] DevicePath Ignored.
504 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
505 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
506 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
509 CDROM_DEVICE_PATH
*Cd
;
511 ASSERT(DevicePathNode
!= NULL
);
512 ASSERT(MappingItem
!= NULL
);
514 Cd
= (CDROM_DEVICE_PATH
*) DevicePathNode
;
515 MappingItem
->Mtd
= MTDTypeCDRom
;
516 AppendCSDNum (MappingItem
, Cd
->BootEntry
);
520 DevicePathNode must be SerialFibre Channel type and this will populate the MappingItem.
522 @param[in] DevicePathNode The node to get info on.
523 @param[in] MappingItem The info item to populate.
524 @param[in] DevicePath Ignored.
529 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
530 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
531 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
534 FIBRECHANNEL_DEVICE_PATH
*Fibre
;
536 ASSERT(DevicePathNode
!= NULL
);
537 ASSERT(MappingItem
!= NULL
);
539 Fibre
= (FIBRECHANNEL_DEVICE_PATH
*) DevicePathNode
;
540 AppendCSDNum (MappingItem
, Fibre
->WWN
);
541 AppendCSDNum (MappingItem
, Fibre
->Lun
);
545 DevicePathNode must be SerialUart type and this will populate the MappingItem.
547 @param[in] DevicePathNode The node to get info on.
548 @param[in] MappingItem The info item to populate.
549 @param[in] DevicePath Ignored.
554 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
555 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
556 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
559 UART_DEVICE_PATH
*Uart
;
561 ASSERT(DevicePathNode
!= NULL
);
562 ASSERT(MappingItem
!= NULL
);
564 Uart
= (UART_DEVICE_PATH
*) DevicePathNode
;
565 AppendCSDNum (MappingItem
, Uart
->BaudRate
);
566 AppendCSDNum (MappingItem
, Uart
->DataBits
);
567 AppendCSDNum (MappingItem
, Uart
->Parity
);
568 AppendCSDNum (MappingItem
, Uart
->StopBits
);
572 DevicePathNode must be SerialUSB type and this will populate the MappingItem.
574 @param[in] DevicePathNode The node to get info on.
575 @param[in] MappingItem The info item to populate.
576 @param[in] DevicePath Ignored.
581 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
582 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
583 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
586 USB_DEVICE_PATH
*Usb
;
587 EFI_USB_IO_PROTOCOL
*UsbIo
;
588 EFI_HANDLE TempHandle
;
590 USB_INTERFACE_DESCRIPTOR InterfaceDesc
;
593 ASSERT(DevicePathNode
!= NULL
);
594 ASSERT(MappingItem
!= NULL
);
596 Usb
= (USB_DEVICE_PATH
*) DevicePathNode
;
597 AppendCSDNum (MappingItem
, Usb
->ParentPortNumber
);
598 AppendCSDNum (MappingItem
, Usb
->InterfaceNumber
);
600 if (PcdGetBool(PcdUsbExtendedDecode
)) {
601 Status
= gBS
->LocateDevicePath( &gEfiUsbIoProtocolGuid
, &DevicePath
, &TempHandle
);
603 if (!EFI_ERROR(Status
)) {
604 Status
= gBS
->OpenProtocol(TempHandle
, &gEfiUsbIoProtocolGuid
, (VOID
**)&UsbIo
, gImageHandle
, NULL
, EFI_OPEN_PROTOCOL_GET_PROTOCOL
);
607 if (!EFI_ERROR(Status
)) {
608 ASSERT(UsbIo
!= NULL
);
609 Status
= UsbIo
->UsbGetInterfaceDescriptor(UsbIo
, &InterfaceDesc
);
610 if (!EFI_ERROR(Status
)) {
611 if (InterfaceDesc
.InterfaceClass
== USB_MASS_STORE_CLASS
&& MappingItem
->Mtd
== MTDTypeUnknown
) {
612 switch (InterfaceDesc
.InterfaceSubClass
){
613 case USB_MASS_STORE_SCSI
:
614 MappingItem
->Mtd
= MTDTypeHardDisk
;
616 case USB_MASS_STORE_8070I
:
617 case USB_MASS_STORE_UFI
:
618 MappingItem
->Mtd
= MTDTypeFloppy
;
620 case USB_MASS_STORE_8020I
:
621 MappingItem
->Mtd
= MTDTypeCDRom
;
631 DevicePathNode must be SerialVendor type and this will populate the MappingItem.
633 @param[in] DevicePathNode The node to get info on.
634 @param[in] MappingItem The info item to populate.
635 @param[in] DevicePath Ignored.
640 DevPathSerialVendor (
641 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
642 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
643 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
646 VENDOR_DEVICE_PATH
*Vendor
;
647 SAS_DEVICE_PATH
*Sas
;
648 UINTN TargetNameLength
;
652 if (DevicePathNode
== NULL
|| MappingItem
== NULL
) {
656 Vendor
= (VENDOR_DEVICE_PATH
*) DevicePathNode
;
657 AppendCSDGuid (MappingItem
, &Vendor
->Guid
);
659 if (CompareGuid (&gEfiSasDevicePathGuid
, &Vendor
->Guid
)) {
660 Sas
= (SAS_DEVICE_PATH
*) Vendor
;
661 AppendCSDNum (MappingItem
, Sas
->SasAddress
);
662 AppendCSDNum (MappingItem
, Sas
->Lun
);
663 AppendCSDNum (MappingItem
, Sas
->DeviceTopology
);
664 AppendCSDNum (MappingItem
, Sas
->RelativeTargetPort
);
666 TargetNameLength
= MIN(DevicePathNodeLength (DevicePathNode
) - sizeof (VENDOR_DEVICE_PATH
), PcdGet32(PcdShellVendorExtendedDecode
));
667 if (TargetNameLength
!= 0) {
669 // String is 2 chars per data byte, plus NULL terminator
671 Buffer
= AllocateZeroPool (((TargetNameLength
* 2) + 1) * sizeof(CHAR16
));
672 ASSERT(Buffer
!= NULL
);
673 if (Buffer
== NULL
) {
678 // Build the string data
680 for (Index
= 0; Index
< TargetNameLength
; Index
++) {
681 Buffer
= CatSPrint (Buffer
, L
"%02x", *((UINT8
*)Vendor
+ sizeof (VENDOR_DEVICE_PATH
) + Index
));
685 // Append the new data block
687 AppendCSDStr (MappingItem
, Buffer
);
695 DevicePathNode must be SerialLun type and this will populate the MappingItem.
697 @param[in] DevicePathNode The node to get info on.
698 @param[in] MappingItem The info item to populate.
699 @param[in] DevicePath Ignored.
704 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
705 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
706 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
709 DEVICE_LOGICAL_UNIT_DEVICE_PATH
*Lun
;
711 ASSERT(DevicePathNode
!= NULL
);
712 ASSERT(MappingItem
!= NULL
);
714 Lun
= (DEVICE_LOGICAL_UNIT_DEVICE_PATH
*) DevicePathNode
;
715 AppendCSDNum (MappingItem
, Lun
->Lun
);
719 DevicePathNode must be SerialSata type and this will populate the MappingItem.
721 @param[in] DevicePathNode The node to get info on.
722 @param[in] MappingItem The info item to populate.
723 @param[in] DevicePath Ignored.
728 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
729 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
730 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
733 SATA_DEVICE_PATH
*Sata
;
735 ASSERT(DevicePathNode
!= NULL
);
736 ASSERT(MappingItem
!= NULL
);
738 Sata
= (SATA_DEVICE_PATH
*) DevicePathNode
;
739 AppendCSDNum (MappingItem
, Sata
->HBAPortNumber
);
740 AppendCSDNum (MappingItem
, Sata
->PortMultiplierPortNumber
);
741 AppendCSDNum (MappingItem
, Sata
->Lun
);
745 DevicePathNode must be SerialSCSI type and this will populate the MappingItem.
747 @param[in] DevicePathNode The node to get info on.
748 @param[in] MappingItem The info item to populate.
749 @param[in] DevicePath Ignored.
754 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
755 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
756 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
759 ISCSI_DEVICE_PATH
*IScsi
;
760 UINT8
*IScsiTargetName
;
762 UINTN TargetNameLength
;
765 ASSERT(DevicePathNode
!= NULL
);
766 ASSERT(MappingItem
!= NULL
);
768 if (PcdGetBool(PcdShellDecodeIScsiMapNames
)) {
769 IScsi
= (ISCSI_DEVICE_PATH
*) DevicePathNode
;
770 AppendCSDNum (MappingItem
, IScsi
->NetworkProtocol
);
771 AppendCSDNum (MappingItem
, IScsi
->LoginOption
);
772 AppendCSDNum (MappingItem
, IScsi
->Lun
);
773 AppendCSDNum (MappingItem
, IScsi
->TargetPortalGroupTag
);
774 TargetNameLength
= DevicePathNodeLength (DevicePathNode
) - sizeof (ISCSI_DEVICE_PATH
);
775 if (TargetNameLength
> 0) {
776 TargetName
= AllocateZeroPool ((TargetNameLength
+ 1) * sizeof (CHAR16
));
777 if (TargetName
!= NULL
) {
778 IScsiTargetName
= (UINT8
*) (IScsi
+ 1);
779 for (Index
= 0; Index
< TargetNameLength
; Index
++) {
780 TargetName
[Index
] = (CHAR16
) IScsiTargetName
[Index
];
782 AppendCSDStr (MappingItem
, TargetName
);
783 FreePool (TargetName
);
790 DevicePathNode must be SerialI20 type and this will populate the MappingItem.
792 @param[in] DevicePathNode The node to get info on.
793 @param[in] MappingItem The info item to populate.
794 @param[in] DevicePath Ignored.
799 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
800 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
801 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
804 I2O_DEVICE_PATH
*DevicePath_I20
;
806 ASSERT(DevicePathNode
!= NULL
);
807 ASSERT(MappingItem
!= NULL
);
809 DevicePath_I20
= (I2O_DEVICE_PATH
*) DevicePathNode
;
810 AppendCSDNum (MappingItem
, DevicePath_I20
->Tid
);
814 DevicePathNode must be Mac Address type and this will populate the MappingItem.
816 @param[in] DevicePathNode The node to get info on.
817 @param[in] MappingItem The info item to populate.
818 @param[in] DevicePath Ignored.
822 DevPathSerialMacAddr (
823 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
824 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
825 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
828 MAC_ADDR_DEVICE_PATH
*Mac
;
834 ASSERT(DevicePathNode
!= NULL
);
835 ASSERT(MappingItem
!= NULL
);
837 Mac
= (MAC_ADDR_DEVICE_PATH
*) DevicePathNode
;
839 HwAddressSize
= sizeof (EFI_MAC_ADDRESS
);
840 if (Mac
->IfType
== 0x01 || Mac
->IfType
== 0x00) {
844 for (Index
= 0, PBuffer
= Buffer
; Index
< HwAddressSize
; Index
++, PBuffer
+= 2) {
845 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Mac
->MacAddress
.Addr
[Index
]);
848 AppendCSDStr (MappingItem
, Buffer
);
852 DevicePathNode must be InfiniBand type and this will populate the MappingItem.
854 @param[in] DevicePathNode The node to get info on.
855 @param[in] MappingItem The info item to populate.
856 @param[in] DevicePath Ignored.
860 DevPathSerialInfiniBand (
861 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
862 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
863 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
866 INFINIBAND_DEVICE_PATH
*InfiniBand
;
871 ASSERT(DevicePathNode
!= NULL
);
872 ASSERT(MappingItem
!= NULL
);
874 InfiniBand
= (INFINIBAND_DEVICE_PATH
*) DevicePathNode
;
875 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
876 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) InfiniBand
->PortGid
[Index
]);
879 AppendCSDStr (MappingItem
, Buffer
);
880 AppendCSDNum (MappingItem
, InfiniBand
->ServiceId
);
881 AppendCSDNum (MappingItem
, InfiniBand
->TargetPortId
);
882 AppendCSDNum (MappingItem
, InfiniBand
->DeviceId
);
886 DevicePathNode must be IPv4 type and this will populate the MappingItem.
888 @param[in] DevicePathNode The node to get info on.
889 @param[in] MappingItem The info item to populate.
890 @param[in] DevicePath Ignored.
895 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
896 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
897 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
900 IPv4_DEVICE_PATH
*Ip
;
903 ASSERT(DevicePathNode
!= NULL
);
904 ASSERT(MappingItem
!= NULL
);
906 Ip
= (IPv4_DEVICE_PATH
*) DevicePathNode
;
911 (UINTN
) Ip
->LocalIpAddress
.Addr
[0],
912 (UINTN
) Ip
->LocalIpAddress
.Addr
[1],
913 (UINTN
) Ip
->LocalIpAddress
.Addr
[2],
914 (UINTN
) Ip
->LocalIpAddress
.Addr
[3]
916 AppendCSDStr (MappingItem
, Buffer
);
917 AppendCSDNum (MappingItem
, Ip
->LocalPort
);
922 (UINTN
) Ip
->RemoteIpAddress
.Addr
[0],
923 (UINTN
) Ip
->RemoteIpAddress
.Addr
[1],
924 (UINTN
) Ip
->RemoteIpAddress
.Addr
[2],
925 (UINTN
) Ip
->RemoteIpAddress
.Addr
[3]
927 AppendCSDStr (MappingItem
, Buffer
);
928 AppendCSDNum (MappingItem
, Ip
->RemotePort
);
932 DevicePathNode must be IPv6 type and this will populate the MappingItem.
934 @param[in] DevicePathNode The node to get info on.
935 @param[in] MappingItem The info item to populate.
936 @param[in] DevicePath Ignored.
942 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
943 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
944 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
947 IPv6_DEVICE_PATH
*Ip
;
952 ASSERT(DevicePathNode
!= NULL
);
953 ASSERT(MappingItem
!= NULL
);
955 Ip
= (IPv6_DEVICE_PATH
*) DevicePathNode
;
956 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
957 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Ip
->LocalIpAddress
.Addr
[Index
]);
960 AppendCSDStr (MappingItem
, Buffer
);
961 AppendCSDNum (MappingItem
, Ip
->LocalPort
);
962 for (Index
= 0, PBuffer
= Buffer
; Index
< 16; Index
++, PBuffer
+= 2) {
963 UnicodeSPrint (PBuffer
, 0, L
"%02x", (UINTN
) Ip
->RemoteIpAddress
.Addr
[Index
]);
966 AppendCSDStr (MappingItem
, Buffer
);
967 AppendCSDNum (MappingItem
, Ip
->RemotePort
);
971 DevicePathNode must be SCSI type and this will populate the MappingItem.
973 @param[in] DevicePathNode The node to get info on.
974 @param[in] MappingItem The info item to populate.
975 @param[in] DevicePath Ignored.
981 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
982 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
983 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
986 SCSI_DEVICE_PATH
*Scsi
;
988 ASSERT(DevicePathNode
!= NULL
);
989 ASSERT(MappingItem
!= NULL
);
991 Scsi
= (SCSI_DEVICE_PATH
*) DevicePathNode
;
992 AppendCSDNum (MappingItem
, Scsi
->Pun
);
993 AppendCSDNum (MappingItem
, Scsi
->Lun
);
997 DevicePathNode must be 1394 type and this will populate the MappingItem.
999 @param[in] DevicePathNode The node to get info on.
1000 @param[in] MappingItem The info item to populate.
1001 @param[in] DevicePath Ignored.
1006 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
1007 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
1008 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1011 F1394_DEVICE_PATH
*DevicePath_F1394
;
1014 ASSERT(DevicePathNode
!= NULL
);
1015 ASSERT(MappingItem
!= NULL
);
1017 DevicePath_F1394
= (F1394_DEVICE_PATH
*) DevicePathNode
;
1018 UnicodeSPrint (Buffer
, 0, L
"%lx", DevicePath_F1394
->Guid
);
1019 AppendCSDStr (MappingItem
, Buffer
);
1023 If the node is floppy type then populate the MappingItem.
1025 @param[in] DevicePathNode The node to get info on.
1026 @param[in] MappingItem The info item to populate.
1027 @param[in] DevicePath Ignored.
1032 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
1033 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
1034 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1037 ACPI_HID_DEVICE_PATH
*Acpi
;
1039 ASSERT(DevicePathNode
!= NULL
);
1040 ASSERT(MappingItem
!= NULL
);
1042 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePathNode
;
1043 if ((Acpi
->HID
& PNP_EISA_ID_MASK
) == PNP_EISA_ID_CONST
) {
1044 if (EISA_ID_TO_NUM (Acpi
->HID
) == 0x0604) {
1045 MappingItem
->Mtd
= MTDTypeFloppy
;
1046 AppendCSDNum (MappingItem
, Acpi
->UID
);
1052 Empty function used for unknown devices.
1054 @param[in] DevicePathNode Ignored.
1055 @param[in] MappingItem Ignored.
1056 @param[in] DevicePath Ignored.
1062 DevPathSerialDefault (
1063 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
,
1064 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
1065 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1071 DEV_PATH_CONSIST_MAPPING_TABLE DevPathConsistMappingTable
[] = {
1073 HARDWARE_DEVICE_PATH
,
1075 DevPathSerialDefault
,
1085 MESSAGING_DEVICE_PATH
,
1088 DevPathCompareDefault
1091 MESSAGING_DEVICE_PATH
,
1094 DevPathCompareDefault
1097 MESSAGING_DEVICE_PATH
,
1098 MSG_FIBRECHANNEL_DP
,
1100 DevPathCompareDefault
1103 MESSAGING_DEVICE_PATH
,
1106 DevPathCompareDefault
1109 MESSAGING_DEVICE_PATH
,
1112 DevPathCompareDefault
1115 MESSAGING_DEVICE_PATH
,
1118 DevPathCompareDefault
1121 MESSAGING_DEVICE_PATH
,
1123 DevPathSerialMacAddr
,
1124 DevPathCompareDefault
1127 MESSAGING_DEVICE_PATH
,
1130 DevPathCompareDefault
1133 MESSAGING_DEVICE_PATH
,
1136 DevPathCompareDefault
1139 MESSAGING_DEVICE_PATH
,
1141 DevPathSerialInfiniBand
,
1142 DevPathCompareDefault
1145 MESSAGING_DEVICE_PATH
,
1148 DevPathCompareDefault
1151 MESSAGING_DEVICE_PATH
,
1153 DevPathSerialVendor
,
1154 DevPathCompareDefault
1157 MESSAGING_DEVICE_PATH
,
1158 MSG_DEVICE_LOGICAL_UNIT_DP
,
1160 DevPathCompareDefault
1163 MESSAGING_DEVICE_PATH
,
1166 DevPathCompareDefault
1169 MESSAGING_DEVICE_PATH
,
1172 DevPathCompareDefault
1177 DevPathSerialHardDrive
,
1178 DevPathCompareDefault
1184 DevPathCompareDefault
1189 DevPathSerialVendor
,
1190 DevPathCompareDefault
1201 Function to determine if a device path node is Hi or not.
1203 @param[in] DevicePathNode The node to check.
1205 @retval TRUE The node is Hi.
1206 @retval FALSE The node is not Hi.
1210 IsHIDevicePathNode (
1211 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePathNode
1214 ACPI_HID_DEVICE_PATH
*Acpi
;
1216 ASSERT(DevicePathNode
!= NULL
);
1218 if (DevicePathNode
->Type
== HARDWARE_DEVICE_PATH
) {
1222 if (DevicePathNode
->Type
== ACPI_DEVICE_PATH
) {
1223 Acpi
= (ACPI_HID_DEVICE_PATH
*) DevicePathNode
;
1224 switch (EISA_ID_TO_NUM (Acpi
->HID
)) {
1239 Function to convert a standard device path structure into a Hi version.
1241 @param[in] DevicePath The device path to convert.
1243 @return the device path portion that is Hi.
1245 EFI_DEVICE_PATH_PROTOCOL
*
1248 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1251 UINTN NonHIDevicePathNodeCount
;
1254 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1255 EFI_DEVICE_PATH_PROTOCOL
*TempDevicePath
;
1257 ASSERT(DevicePath
!= NULL
);
1259 NonHIDevicePathNodeCount
= 0;
1261 HIDevicePath
= AllocateZeroPool (sizeof (EFI_DEVICE_PATH_PROTOCOL
));
1262 SetDevicePathEndNode (HIDevicePath
);
1264 Node
.DevPath
.Type
= END_DEVICE_PATH_TYPE
;
1265 Node
.DevPath
.SubType
= END_INSTANCE_DEVICE_PATH_SUBTYPE
;
1266 Node
.DevPath
.Length
[0] = (UINT8
)sizeof (EFI_DEVICE_PATH_PROTOCOL
);
1267 Node
.DevPath
.Length
[1] = 0;
1269 while (!IsDevicePathEnd (DevicePath
)) {
1270 if (IsHIDevicePathNode (DevicePath
)) {
1271 for (Index
= 0; Index
< NonHIDevicePathNodeCount
; Index
++) {
1272 TempDevicePath
= AppendDevicePathNode (HIDevicePath
, &Node
.DevPath
);
1273 FreePool (HIDevicePath
);
1274 HIDevicePath
= TempDevicePath
;
1277 TempDevicePath
= AppendDevicePathNode (HIDevicePath
, DevicePath
);
1278 FreePool (HIDevicePath
);
1279 HIDevicePath
= TempDevicePath
;
1281 NonHIDevicePathNodeCount
++;
1284 // Next device path node
1286 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) NextDevicePathNode (DevicePath
);
1289 return HIDevicePath
;
1293 Function to walk the device path looking for a dumpable node.
1295 @param[in] MappingItem The Item to fill with data.
1296 @param[in] DevicePath The path of the item to get data on.
1298 @return EFI_SUCCESS Always returns success.
1302 GetDeviceConsistMappingInfo (
1303 IN DEVICE_CONSIST_MAPPING_INFO
*MappingItem
,
1304 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
1307 SERIAL_DECODE_FUNCTION SerialFun
;
1309 EFI_DEVICE_PATH_PROTOCOL
*OriginalDevicePath
;
1311 ASSERT(DevicePath
!= NULL
);
1312 ASSERT(MappingItem
!= NULL
);
1314 SetMem (&MappingItem
->Csd
, sizeof (POOL_PRINT
), 0);
1315 OriginalDevicePath
= DevicePath
;
1317 while (!IsDevicePathEnd (DevicePath
)) {
1319 // Find the handler to dump this device path node and
1320 // initialize with generic function in case nothing is found
1322 for (SerialFun
= DevPathSerialDefault
, Index
= 0; DevPathConsistMappingTable
[Index
].SerialFun
!= NULL
; Index
+= 1) {
1324 if (DevicePathType (DevicePath
) == DevPathConsistMappingTable
[Index
].Type
&&
1325 DevicePathSubType (DevicePath
) == DevPathConsistMappingTable
[Index
].SubType
1327 SerialFun
= DevPathConsistMappingTable
[Index
].SerialFun
;
1332 SerialFun (DevicePath
, MappingItem
, OriginalDevicePath
);
1335 // Next device path node
1337 DevicePath
= (EFI_DEVICE_PATH_PROTOCOL
*) NextDevicePathNode (DevicePath
);
1344 Function to initialize the table for creating consistent map names.
1346 @param[out] Table The pointer to pointer to pointer to DevicePathProtocol object.
1348 @retval EFI_SUCCESS The table was created successfully.
1352 ShellCommandConsistMappingInitialize (
1353 OUT EFI_DEVICE_PATH_PROTOCOL
***Table
1356 EFI_HANDLE
*HandleBuffer
;
1359 EFI_DEVICE_PATH_PROTOCOL
**TempTable
;
1360 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
1361 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1362 EFI_BLOCK_IO_PROTOCOL
*BlockIo
;
1363 EFI_SIMPLE_FILE_SYSTEM_PROTOCOL
*SimpleFileSystem
;
1367 HandleBuffer
= NULL
;
1369 Status
= gBS
->LocateHandleBuffer (
1371 &gEfiDevicePathProtocolGuid
,
1376 ASSERT_EFI_ERROR(Status
);
1378 TempTable
= AllocateZeroPool ((HandleNum
+ 1) * sizeof (EFI_DEVICE_PATH_PROTOCOL
*));
1379 if (TempTable
== NULL
) {
1380 return EFI_OUT_OF_RESOURCES
;
1383 for (HandleLoop
= 0 ; HandleLoop
< HandleNum
; HandleLoop
++) {
1384 DevicePath
= DevicePathFromHandle (HandleBuffer
[HandleLoop
]);
1385 if (DevicePath
== NULL
) {
1389 HIDevicePath
= GetHIDevicePath (DevicePath
);
1390 if (HIDevicePath
== NULL
) {
1394 Status
= gBS
->HandleProtocol( HandleBuffer
[HandleLoop
],
1395 &gEfiBlockIoProtocolGuid
,
1398 if (EFI_ERROR(Status
)) {
1399 Status
= gBS
->HandleProtocol( HandleBuffer
[HandleLoop
],
1400 &gEfiSimpleFileSystemProtocolGuid
,
1401 (VOID
**)&SimpleFileSystem
1403 if (EFI_ERROR(Status
)) {
1404 FreePool (HIDevicePath
);
1409 for (Index
= 0; TempTable
[Index
] != NULL
; Index
++) {
1410 if (DevicePathCompare (&TempTable
[Index
], &HIDevicePath
) == 0) {
1411 FreePool (HIDevicePath
);
1416 if (TempTable
[Index
] == NULL
) {
1417 TempTable
[Index
] = HIDevicePath
;
1421 for (Index
= 0; TempTable
[Index
] != NULL
; Index
++);
1422 PerformQuickSort(TempTable
, Index
, sizeof(EFI_DEVICE_PATH_PROTOCOL
*), DevicePathCompare
);
1425 if (HandleBuffer
!= NULL
) {
1426 FreePool (HandleBuffer
);
1433 Function to uninitialize the table for creating consistent map names.
1435 The parameter must have been received from ShellCommandConsistMappingInitialize.
1437 @param[out] Table The pointer to pointer to DevicePathProtocol object.
1439 @retval EFI_SUCCESS The table was deleted successfully.
1443 ShellCommandConsistMappingUnInitialize (
1444 EFI_DEVICE_PATH_PROTOCOL
**Table
1449 ASSERT(Table
!= NULL
);
1451 for (Index
= 0; Table
[Index
] != NULL
; Index
++) {
1452 FreePool (Table
[Index
]);
1460 Create a consistent mapped name for the device specified by DevicePath
1463 This must be called after ShellCommandConsistMappingInitialize() and
1464 before ShellCommandConsistMappingUnInitialize() is called.
1466 @param[in] DevicePath The pointer to the dev path for the device.
1467 @param[in] Table The Table of mapping information.
1469 @retval NULL A consistent mapped name could not be created.
1470 @return A pointer to a string allocated from pool with the device name.
1474 ShellCommandConsistMappingGenMappingName (
1475 IN EFI_DEVICE_PATH_PROTOCOL
*DevicePath
,
1476 IN EFI_DEVICE_PATH_PROTOCOL
**Table
1480 DEVICE_CONSIST_MAPPING_INFO MappingInfo
;
1481 EFI_DEVICE_PATH_PROTOCOL
*HIDevicePath
;
1485 ASSERT(DevicePath
!= NULL
);
1486 ASSERT(Table
!= NULL
);
1488 HIDevicePath
= GetHIDevicePath (DevicePath
);
1489 if (HIDevicePath
== NULL
) {
1493 for (Index
= 0; Table
[Index
] != NULL
; Index
++) {
1494 if (DevicePathCompare (&Table
[Index
], &HIDevicePath
) == 0) {
1499 FreePool (HIDevicePath
);
1500 if (Table
[Index
] == NULL
) {
1504 MappingInfo
.Hi
= Index
;
1505 MappingInfo
.Mtd
= MTDTypeUnknown
;
1506 MappingInfo
.Digital
= FALSE
;
1508 GetDeviceConsistMappingInfo (&MappingInfo
, DevicePath
);
1510 SetMem (&Str
, sizeof (Str
), 0);
1511 for (Index
= 0; mMTDName
[Index
].MTDType
!= MTDTypeEnd
; Index
++) {
1512 if (MappingInfo
.Mtd
== mMTDName
[Index
].MTDType
) {
1517 if (mMTDName
[Index
].MTDType
!= MTDTypeEnd
) {
1518 CatPrint (&Str
, L
"%s", mMTDName
[Index
].Name
);
1521 CatPrint (&Str
, L
"%d", (UINTN
) MappingInfo
.Hi
);
1522 if (MappingInfo
.Csd
.Str
!= NULL
) {
1523 CatPrint (&Str
, L
"%s", MappingInfo
.Csd
.Str
);
1524 FreePool (MappingInfo
.Csd
.Str
);
1527 if (Str
.Str
!= NULL
) {
1528 CatPrint (&Str
, L
":");
1531 NewSize
= (Str
.Len
+ 1) * sizeof (CHAR16
);
1532 Str
.Str
= ReallocatePool (Str
.Len
, NewSize
, Str
.Str
);
1533 if (Str
.Str
== NULL
) {
1536 Str
.Str
[Str
.Len
] = CHAR_NULL
;
1541 Function to search the list of mappings for the node on the list based on the key.
1543 @param[in] MapKey String Key to search for on the map
1545 @return the node on the list.
1549 ShellCommandFindMapItem (
1550 IN CONST CHAR16
*MapKey
1553 SHELL_MAP_LIST
*MapListItem
;
1555 for ( MapListItem
= (SHELL_MAP_LIST
*)GetFirstNode(&gShellMapList
.Link
)
1556 ; !IsNull(&gShellMapList
.Link
, &MapListItem
->Link
)
1557 ; MapListItem
= (SHELL_MAP_LIST
*)GetNextNode(&gShellMapList
.Link
, &MapListItem
->Link
)
1559 if (gUnicodeCollation
->StriColl(gUnicodeCollation
,MapListItem
->MapName
,(CHAR16
*)MapKey
) == 0) {
1560 return (MapListItem
);