From 1232b21473646661a4ac1ae4b7bf5113d4613e83 Mon Sep 17 00:00:00 2001 From: klu2 Date: Tue, 11 Nov 2008 15:42:40 +0000 Subject: 1, Add for all source that use device path utility macros 2, Add DevicePathLib library class to module's INF that use device path utility macros git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@6456 6f19259b-4bc3-4df7-8a09-765794883524 --- .../PlatOverMngr/PlatOverMngr.c | 90 ++++------------------ 1 file changed, 14 insertions(+), 76 deletions(-) (limited to 'MdeModulePkg/Universal/PlatformDriverOverride/PlatOverMngr/PlatOverMngr.c') diff --git a/MdeModulePkg/Universal/PlatformDriverOverride/PlatOverMngr/PlatOverMngr.c b/MdeModulePkg/Universal/PlatformDriverOverride/PlatOverMngr/PlatOverMngr.c index 5269c35198..5d9bfe127a 100644 --- a/MdeModulePkg/Universal/PlatformDriverOverride/PlatOverMngr/PlatOverMngr.c +++ b/MdeModulePkg/Universal/PlatformDriverOverride/PlatOverMngr/PlatOverMngr.c @@ -340,8 +340,8 @@ GetImageName ( ) { EFI_STATUS Status; - EFI_DEVICE_PATH_PROTOCOL *DevPath; EFI_DEVICE_PATH_PROTOCOL *DevPathNode; + EFI_DEVICE_PATH_PROTOCOL *AlignedDevPathNode; MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *FvFilePath; VOID *Buffer; UINTN BufferSize; @@ -357,21 +357,24 @@ GetImageName ( return NULL; } - DevPath = UnpackDevicePath (Image->FilePath); + DevPathNode = Image->FilePath; - if (DevPath == NULL) { + if (DevPathNode == NULL) { return NULL; } - DevPathNode = DevPath; - while (!IsDevicePathEnd (DevPathNode)) { + // + // Make sure device path node is aligned when accessing it's FV Name Guid field. + // + AlignedDevPathNode = AllocateCopyPool (DevicePathNodeLength(DevPathNode), DevPathNode); + // // Find the Fv File path // - NameGuid = EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)DevPathNode); + NameGuid = EfiGetNameGuidFromFwVolDevicePathNode ((MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *)AlignedDevPathNode); if (NameGuid != NULL) { - FvFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) DevPathNode; + FvFilePath = (MEDIA_FW_VOL_FILEPATH_DEVICE_PATH *) AlignedDevPathNode; Status = gBS->HandleProtocol ( Image->DeviceHandle, &gEfiFirmwareVolume2ProtocolGuid, @@ -388,18 +391,21 @@ GetImageName ( &AuthenticationStatus ); if (!EFI_ERROR (Status)) { + FreePool (AlignedDevPathNode); break; } Buffer = NULL; } } + + FreePool (AlignedDevPathNode); + // // Next device path node // DevPathNode = NextDevicePathNode (DevPathNode); } - gBS->FreePool (DevPath); return Buffer; } @@ -1316,74 +1322,6 @@ PlatOverMngrCallback ( return EFI_SUCCESS; } -/** - Function unpacks a device path data structure so that all the nodes - of a device path are naturally aligned. - - @param DevPath A pointer to a device path data structure - - @return If the memory for the device path is successfully allocated, then a - @return pointer to the new device path is returned. Otherwise, NULL is returned. - -**/ -EFI_DEVICE_PATH_PROTOCOL * -UnpackDevicePath ( - IN EFI_DEVICE_PATH_PROTOCOL *DevPath - ) -{ - EFI_DEVICE_PATH_PROTOCOL *Src; - EFI_DEVICE_PATH_PROTOCOL *Dest; - EFI_DEVICE_PATH_PROTOCOL *NewPath; - UINTN Size; - - // - // Walk device path and round sizes to valid boundries - // - Src = DevPath; - Size = 0; - for (;;) { - Size += DevicePathNodeLength (Src); - Size += ALIGN_SIZE (Size); - - if (IsDevicePathEnd (Src)) { - break; - } - - Src = NextDevicePathNode (Src); - } - // - // Allocate space for the unpacked path - // - NewPath = AllocateZeroPool (Size); - if (NewPath) { - - ASSERT (((UINTN) NewPath) % MIN_ALIGNMENT_SIZE == 0); - - // - // Copy each node - // - Src = DevPath; - Dest = NewPath; - for (;;) { - Size = DevicePathNodeLength (Src); - CopyMem (Dest, Src, Size); - Size += ALIGN_SIZE (Size); - SetDevicePathNodeLength (Dest, Size); - Dest->Type |= EFI_DP_TYPE_UNPACKED; - Dest = (EFI_DEVICE_PATH_PROTOCOL *) (((UINT8 *) Dest) + Size); - - if (IsDevicePathEnd (Src)) { - break; - } - - Src = NextDevicePathNode (Src); - } - } - - return NewPath; -} - - /** Get the description string by device path. -- cgit v1.2.3