X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=ShellPkg%2FLibrary%2FUefiHandleParsingLib%2FUefiHandleParsingLib.c;h=1049dea0c009bdb628e0032f890f0d6ba03a9d20;hp=34296675995d0f5ec61b8a74e1867d77d6d008d1;hb=d4ec9a5725d67bb1770008513f4c6f1dce2c9b43;hpb=4024c116f68fc288f3264bb18c0b172fbc1f18d8 diff --git a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c index 3429667599..1049dea0c0 100644 --- a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c +++ b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c @@ -1,8 +1,9 @@ /** @file Provides interface to advanced shell functionality for parsing both handle and protocol database. + Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
(C) Copyright 2013-2015 Hewlett-Packard Development Company, L.P.
- Copyright (c) 2010 - 2014, Intel Corporation. All rights reserved.
+ (C) Copyright 2015-2016 Hewlett Packard Enterprise Development LP
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -18,8 +19,8 @@ EFI_HANDLE mHandleParsingHiiHandle = NULL; HANDLE_INDEX_LIST mHandleList = {{{NULL,NULL},0,0},0}; -GUID_INFO_BLOCK *GuidList; -UINTN GuidListCount; +GUID_INFO_BLOCK *mGuidList; +UINTN mGuidListCount; /** Function to translate the EFI_MEMORY_TYPE into a string. @@ -28,7 +29,6 @@ UINTN GuidListCount; @retval A string representation of the type allocated from BS Pool. **/ CHAR16* -EFIAPI ConvertMemoryType ( IN CONST EFI_MEMORY_TYPE Memory ) @@ -65,7 +65,6 @@ ConvertMemoryType ( @retval A string representation of the type allocated from BS Pool. **/ CHAR16* -EFIAPI ConvertPixelFormat ( IN CONST EFI_GRAPHICS_PIXEL_FORMAT Fmt ) @@ -99,8 +98,8 @@ HandleParsingLibConstructor ( IN EFI_SYSTEM_TABLE *SystemTable ) { - GuidListCount = 0; - GuidList = NULL; + mGuidListCount = 0; + mGuidList = NULL; // // Do nothing with mHandleParsingHiiHandle. Initialize HII as needed. @@ -108,9 +107,9 @@ HandleParsingLibConstructor ( return (EFI_SUCCESS); } -/** +/** Initialization function for HII packages. - + **/ VOID HandleParsingHiiInit (VOID) @@ -138,11 +137,11 @@ HandleParsingLibDestructor ( { UINTN LoopCount; - for (LoopCount = 0; GuidList != NULL && LoopCount < GuidListCount; LoopCount++) { - SHELL_FREE_NON_NULL(GuidList[LoopCount].GuidId); + for (LoopCount = 0; mGuidList != NULL && LoopCount < mGuidListCount; LoopCount++) { + SHELL_FREE_NON_NULL(mGuidList[LoopCount].GuidId); } - SHELL_FREE_NON_NULL(GuidList); + SHELL_FREE_NON_NULL(mGuidList); if (mHandleParsingHiiHandle != NULL) { HiiRemovePackages(mHandleParsingHiiHandle); } @@ -180,10 +179,7 @@ LoadedImageProtocolDumpInformation( HandleParsingHiiInit(); Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_LI_DUMP_MAIN), NULL); - RetVal = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize)); - if (Temp == NULL || RetVal == NULL) { - SHELL_FREE_NON_NULL(Temp); - SHELL_FREE_NON_NULL(RetVal); + if (Temp == NULL) { return NULL; } @@ -198,29 +194,30 @@ LoadedImageProtocolDumpInformation( if (EFI_ERROR (Status)) { SHELL_FREE_NON_NULL (Temp); - SHELL_FREE_NON_NULL (RetVal); return NULL; } DataType = ConvertMemoryType(LoadedImage->ImageDataType); CodeType = ConvertMemoryType(LoadedImage->ImageCodeType); - RetVal = CatSPrint(RetVal, - Temp, - LoadedImage->Revision, - LoadedImage->ParentHandle, - LoadedImage->SystemTable, - LoadedImage->DeviceHandle, - LoadedImage->FilePath, - LoadedImage->LoadOptionsSize, - LoadedImage->LoadOptions, - LoadedImage->ImageBase, - LoadedImage->ImageSize, - CodeType, - DataType, - LoadedImage->Unload); - - + RetVal = CatSPrint( + NULL, + Temp, + LoadedImage->Revision, + LoadedImage->ParentHandle, + LoadedImage->SystemTable, + LoadedImage->DeviceHandle, + LoadedImage->FilePath, + LoadedImage->LoadOptionsSize, + LoadedImage->LoadOptions, + LoadedImage->ImageBase, + LoadedImage->ImageSize, + CodeType, + DataType, + LoadedImage->Unload + ); + + SHELL_FREE_NON_NULL(Temp); SHELL_FREE_NON_NULL(CodeType); SHELL_FREE_NON_NULL(DataType); @@ -245,11 +242,15 @@ GraphicsOutputProtocolDumpInformation( IN CONST BOOLEAN Verbose ) { - EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; - EFI_STATUS Status; - CHAR16 *RetVal; - CHAR16 *Temp; - CHAR16 *Fmt; + EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput; + EFI_STATUS Status; + CHAR16 *RetVal; + CHAR16 *Temp; + CHAR16 *Fmt; + CHAR16 *TempRetVal; + UINTN GopInfoSize; + UINT32 Mode; + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *GopInfo; if (!Verbose) { return (CatSPrint(NULL, L"GraphicsOutput")); @@ -258,10 +259,7 @@ GraphicsOutputProtocolDumpInformation( HandleParsingHiiInit(); Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_GOP_DUMP_MAIN), NULL); - RetVal = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize)); - if (Temp == NULL || RetVal == NULL) { - SHELL_FREE_NON_NULL(Temp); - SHELL_FREE_NON_NULL(RetVal); + if (Temp == NULL) { return NULL; } @@ -276,35 +274,212 @@ GraphicsOutputProtocolDumpInformation( if (EFI_ERROR (Status)) { SHELL_FREE_NON_NULL (Temp); - SHELL_FREE_NON_NULL (RetVal); return NULL; } Fmt = ConvertPixelFormat(GraphicsOutput->Mode->Info->PixelFormat); - RetVal = CatSPrint(RetVal, - Temp, - GraphicsOutput->Mode->MaxMode, - GraphicsOutput->Mode->Mode, - GraphicsOutput->Mode->FrameBufferBase, - (UINT64)GraphicsOutput->Mode->FrameBufferSize, - (UINT64)GraphicsOutput->Mode->SizeOfInfo, - GraphicsOutput->Mode->Info->Version, - GraphicsOutput->Mode->Info->HorizontalResolution, - GraphicsOutput->Mode->Info->VerticalResolution, - Fmt, - GraphicsOutput->Mode->Info->PixelsPerScanLine, - GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.RedMask, - GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.GreenMask, - GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.BlueMask - ); - + RetVal = CatSPrint( + NULL, + Temp, + GraphicsOutput->Mode->MaxMode, + GraphicsOutput->Mode->Mode, + GraphicsOutput->Mode->FrameBufferBase, + (UINT64)GraphicsOutput->Mode->FrameBufferSize, + (UINT64)GraphicsOutput->Mode->SizeOfInfo, + GraphicsOutput->Mode->Info->Version, + GraphicsOutput->Mode->Info->HorizontalResolution, + GraphicsOutput->Mode->Info->VerticalResolution, + Fmt, + GraphicsOutput->Mode->Info->PixelsPerScanLine, + GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.RedMask, + GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.GreenMask, + GraphicsOutput->Mode->Info->PixelFormat!=PixelBitMask?0:GraphicsOutput->Mode->Info->PixelInformation.BlueMask + ); + + SHELL_FREE_NON_NULL (Temp); + + Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_GOP_RES_LIST_MAIN), NULL); + if (Temp == NULL) { + SHELL_FREE_NON_NULL (RetVal); + goto EXIT; + } + + TempRetVal = CatSPrint (RetVal, Temp); + SHELL_FREE_NON_NULL (RetVal); + if (TempRetVal == NULL) { + goto EXIT; + } + RetVal = TempRetVal; + SHELL_FREE_NON_NULL (Temp); + + Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_GOP_RES_LIST_ENTRY), NULL); + if (Temp == NULL) { + SHELL_FREE_NON_NULL (RetVal); + goto EXIT; + } + + + for (Mode = 0; Mode < GraphicsOutput->Mode->MaxMode; Mode++) { + Status = GraphicsOutput->QueryMode ( + GraphicsOutput, + Mode, + &GopInfoSize, + &GopInfo + ); + if (EFI_ERROR (Status)) { + continue; + } + + TempRetVal = CatSPrint ( + RetVal, + Temp, + Mode, + GopInfo->HorizontalResolution, + GopInfo->VerticalResolution + ); + + SHELL_FREE_NON_NULL (GopInfo); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; + } + + +EXIT: SHELL_FREE_NON_NULL(Temp); SHELL_FREE_NON_NULL(Fmt); return RetVal; } +/** + Function to dump information about EDID Discovered Protocol. + + This will allocate the return buffer from boot services pool. + + @param[in] TheHandle The handle that has LoadedImage installed. + @param[in] Verbose TRUE for additional information, FALSE otherwise. + + @retval A pointer to a string containing the information. +**/ +CHAR16* +EFIAPI +EdidDiscoveredProtocolDumpInformation ( + IN CONST EFI_HANDLE TheHandle, + IN CONST BOOLEAN Verbose + ) +{ + EFI_EDID_DISCOVERED_PROTOCOL *EdidDiscovered; + EFI_STATUS Status; + CHAR16 *RetVal; + CHAR16 *Temp; + CHAR16 *TempRetVal; + + if (!Verbose) { + return (CatSPrint (NULL, L"EDIDDiscovered")); + } + + Status = gBS->OpenProtocol ( + TheHandle, + &gEfiEdidDiscoveredProtocolGuid, + (VOID**)&EdidDiscovered, + NULL, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + + if (EFI_ERROR (Status)) { + return NULL; + } + + Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_EDID_DISCOVERED_MAIN), NULL); + if (Temp == NULL) { + return NULL; + } + + RetVal = CatSPrint (NULL, Temp, EdidDiscovered->SizeOfEdid); + SHELL_FREE_NON_NULL (Temp); + + if (EdidDiscovered->SizeOfEdid != 0) { + Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_EDID_DISCOVERED_DATA), NULL); + if (Temp == NULL) { + SHELL_FREE_NON_NULL (RetVal); + return NULL; + } + TempRetVal = CatSPrint (RetVal, Temp); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; + + TempRetVal = CatSDumpHex (RetVal, 7, 0, EdidDiscovered->SizeOfEdid, EdidDiscovered->Edid); + RetVal = TempRetVal; + } + return RetVal; +} + +/** + Function to dump information about EDID Active Protocol. + + This will allocate the return buffer from boot services pool. + + @param[in] TheHandle The handle that has LoadedImage installed. + @param[in] Verbose TRUE for additional information, FALSE otherwise. + + @retval A pointer to a string containing the information. +**/ +CHAR16* +EFIAPI +EdidActiveProtocolDumpInformation ( + IN CONST EFI_HANDLE TheHandle, + IN CONST BOOLEAN Verbose + ) +{ + EFI_EDID_ACTIVE_PROTOCOL *EdidActive; + EFI_STATUS Status; + CHAR16 *RetVal; + CHAR16 *Temp; + CHAR16 *TempRetVal; + + if (!Verbose) { + return (CatSPrint (NULL, L"EDIDActive")); + } + + Status = gBS->OpenProtocol ( + TheHandle, + &gEfiEdidActiveProtocolGuid, + (VOID**)&EdidActive, + NULL, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + + if (EFI_ERROR (Status)) { + return NULL; + } + + Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_EDID_ACTIVE_MAIN), NULL); + if (Temp == NULL) { + return NULL; + } + + RetVal = CatSPrint (NULL, Temp, EdidActive->SizeOfEdid); + SHELL_FREE_NON_NULL (Temp); + + if (EdidActive->SizeOfEdid != 0) { + Temp = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN (STR_EDID_ACTIVE_DATA), NULL); + if (Temp == NULL) { + SHELL_FREE_NON_NULL (RetVal); + return NULL; + } + TempRetVal = CatSPrint (RetVal, Temp); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; + + TempRetVal = CatSDumpHex (RetVal, 7, 0, EdidActive->SizeOfEdid, EdidActive->Edid); + RetVal = TempRetVal; + } + return RetVal; +} + /** Function to dump information about PciRootBridgeIo. @@ -356,7 +531,7 @@ PciRootBridgeIoDumpInformation( FreePool(Temp); RetVal = Temp2; Temp2 = NULL; - + Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_SEG), NULL); if (Temp == NULL) { SHELL_FREE_NON_NULL(RetVal); @@ -376,13 +551,13 @@ PciRootBridgeIoDumpInformation( if (Temp == NULL) { SHELL_FREE_NON_NULL(RetVal); return NULL; - } + } Temp2 = CatSPrint(RetVal, Temp, Attributes); FreePool(Temp); FreePool(RetVal); RetVal = Temp2; Temp2 = NULL; - + Temp = HiiGetString(mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIRB_DUMP_SUPPORTS), NULL); if (Temp == NULL) { SHELL_FREE_NON_NULL(RetVal); @@ -429,7 +604,7 @@ PciRootBridgeIoDumpInformation( Temp2 = NULL; } - Temp2 = CatSPrint(RetVal, + Temp2 = CatSPrint(RetVal, L"%H%02x %016lx %016lx %02x%N\r\n", Configuration->SpecificFlag, Configuration->AddrRangeMin, @@ -550,10 +725,47 @@ DriverEfiVersionProtocolDumpInformation( ASSERT_EFI_ERROR(Status); RetVal = AllocateZeroPool(VersionStringSize); - ASSERT(RetVal != NULL); - UnicodeSPrint(RetVal, VersionStringSize, L"0x%08x", DriverEfiVersion->FirmwareVersion); + if (RetVal != NULL) { + UnicodeSPrint (RetVal, VersionStringSize, L"0x%08x", DriverEfiVersion->FirmwareVersion); + } return (RetVal); } +/** + Function to convert device path to string. + + This will allocate the return buffer from boot services pool. + + @param[in] DevPath Pointer to device path instance. + @param[in] Verbose TRUE for additional information, FALSE otherwise. + @param[in] Length Maximum allowed text length of the device path. + + @retval A pointer to a string containing the information. +**/ +CHAR16* +ConvertDevicePathToShortText( + IN CONST EFI_DEVICE_PATH_PROTOCOL *DevPath, + IN CONST BOOLEAN Verbose, + IN CONST UINTN Length + ) +{ + CHAR16 *Temp; + CHAR16 *Temp2; + UINTN Size; + + // + // I cannot decide whether to allow shortcuts here (the second BOOLEAN on the next line) + // + Temp = ConvertDevicePathToText(DevPath, TRUE, TRUE); + if (!Verbose && Temp != NULL && StrLen(Temp) > Length) { + Temp2 = NULL; + Size = 0; + Temp2 = StrnCatGrow(&Temp2, &Size, L"..", 0); + Temp2 = StrnCatGrow(&Temp2, &Size, Temp+(StrLen(Temp) - (Length - 2)), 0); + FreePool(Temp); + Temp = Temp2; + } + return (Temp); +} /** Function to dump information about DevicePath protocol. @@ -563,7 +775,7 @@ DriverEfiVersionProtocolDumpInformation( @param[in] TheHandle The handle that has the protocol installed. @param[in] Verbose TRUE for additional information, FALSE otherwise. - @retval A poitner to a string containing the information. + @retval A pointer to a string containing the information. **/ CHAR16* EFIAPI @@ -574,23 +786,43 @@ DevicePathProtocolDumpInformation( { EFI_DEVICE_PATH_PROTOCOL *DevPath; CHAR16 *Temp; - CHAR16 *Temp2; EFI_STATUS Status; Temp = NULL; Status = gBS->OpenProtocol(TheHandle, &gEfiDevicePathProtocolGuid, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); if (!EFI_ERROR(Status)) { - // - // I cannot decide whether to allow shortcuts here (the second BOOLEAN on the next line) - // - Temp = ConvertDevicePathToText(DevPath, TRUE, TRUE); + Temp = ConvertDevicePathToShortText (DevPath, Verbose, 30); gBS->CloseProtocol(TheHandle, &gEfiDevicePathProtocolGuid, gImageHandle, NULL); } - if (!Verbose && Temp != NULL && StrLen(Temp) > 30) { - Temp2 = NULL; - Temp2 = StrnCatGrow(&Temp2, NULL, Temp+(StrLen(Temp) - 30), 30); - FreePool(Temp); - Temp = Temp2; + return (Temp); +} + +/** + Function to dump information about LoadedImageDevicePath protocol. + + This will allocate the return buffer from boot services pool. + + @param[in] TheHandle The handle that has the protocol installed. + @param[in] Verbose TRUE for additional information, FALSE otherwise. + + @retval A pointer to a string containing the information. +**/ +CHAR16* +EFIAPI +LoadedImageDevicePathProtocolDumpInformation( + IN CONST EFI_HANDLE TheHandle, + IN CONST BOOLEAN Verbose + ) +{ + EFI_DEVICE_PATH_PROTOCOL *DevPath; + CHAR16 *Temp; + EFI_STATUS Status; + Temp = NULL; + + Status = gBS->OpenProtocol(TheHandle, &gEfiLoadedImageDevicePathProtocolGuid, (VOID**)&DevPath, gImageHandle, NULL, EFI_OPEN_PROTOCOL_GET_PROTOCOL); + if (!EFI_ERROR(Status)) { + Temp = ConvertDevicePathToShortText (DevPath, Verbose, 30); + gBS->CloseProtocol(TheHandle, &gEfiDevicePathProtocolGuid, gImageHandle, NULL); } return (Temp); } @@ -618,23 +850,17 @@ AdapterInformationDumpInformation ( CHAR16 *GuidStr; CHAR16 *TempStr; CHAR16 *RetVal; + CHAR16 *TempRetVal; VOID *InformationBlock; UINTN InformationBlockSize; - + if (!Verbose) { return (CatSPrint(NULL, L"AdapterInfo")); } InfoTypesBuffer = NULL; InformationBlock = NULL; - - // - // Allocate print buffer to store data - // - RetVal = AllocateZeroPool (PcdGet16(PcdShellPrintBufferSize)); - if (RetVal == NULL) { - return NULL; - } + Status = gBS->OpenProtocol ( (EFI_HANDLE) (TheHandle), @@ -646,7 +872,6 @@ AdapterInformationDumpInformation ( ); if (EFI_ERROR (Status)) { - SHELL_FREE_NON_NULL (RetVal); return NULL; } @@ -655,22 +880,23 @@ AdapterInformationDumpInformation ( // Status = EfiAdptrInfoProtocol->GetSupportedTypes ( EfiAdptrInfoProtocol, - &InfoTypesBuffer, + &InfoTypesBuffer, &InfoTypesBufferCount ); + RetVal = NULL; if (EFI_ERROR (Status)) { TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GET_SUPP_TYPES_FAILED), NULL); if (TempStr != NULL) { - RetVal = CatSPrint (RetVal, TempStr, Status); + RetVal = CatSPrint (NULL, TempStr, Status); } else { goto ERROR_EXIT; - } + } } else { TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_SUPP_TYPE_HEADER), NULL); if (TempStr == NULL) { goto ERROR_EXIT; } - RetVal = CatSPrint (RetVal, TempStr); + RetVal = CatSPrint (NULL, TempStr); SHELL_FREE_NON_NULL (TempStr); for (GuidIndex = 0; GuidIndex < InfoTypesBufferCount; GuidIndex++) { @@ -678,7 +904,9 @@ AdapterInformationDumpInformation ( if (TempStr == NULL) { goto ERROR_EXIT; } - RetVal = CatSPrint (RetVal, TempStr, (GuidIndex + 1), InfoTypesBuffer[GuidIndex]); + TempRetVal = CatSPrint (RetVal, TempStr, (GuidIndex + 1), &InfoTypesBuffer[GuidIndex]); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; SHELL_FREE_NON_NULL (TempStr); TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_GUID_STRING), NULL); @@ -687,32 +915,46 @@ AdapterInformationDumpInformation ( } if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoMediaStateGuid)) { - RetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoMediaStateGuid"); + TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoMediaStateGuid"); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoNetworkBootGuid)) { - RetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoNetworkBootGuid"); + TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoNetworkBootGuid"); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoSanMacAddressGuid)) { - RetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoSanMacAddressGuid"); + TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoSanMacAddressGuid"); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; + } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoUndiIpv6SupportGuid)) { + TempRetVal = CatSPrint (RetVal, TempStr, L"gEfiAdapterInfoUndiIpv6SupportGuid"); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; } else { GuidStr = GetStringNameFromGuid (&InfoTypesBuffer[GuidIndex], NULL); - + if (GuidStr != NULL) { if (StrCmp(GuidStr, L"UnknownDevice") == 0) { - RetVal = CatSPrint (RetVal, TempStr, L"UnknownInfoType"); - + TempRetVal = CatSPrint (RetVal, TempStr, L"UnknownInfoType"); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; + SHELL_FREE_NON_NULL (TempStr); SHELL_FREE_NON_NULL(GuidStr); // // So that we never have to pass this UnknownInfoType to the parsing function "GetInformation" service of AIP // - continue; + continue; } else { - RetVal = CatSPrint (RetVal, TempStr, GuidStr); + TempRetVal = CatSPrint (RetVal, TempStr, GuidStr); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; SHELL_FREE_NON_NULL(GuidStr); } } } - + SHELL_FREE_NON_NULL (TempStr); Status = EfiAdptrInfoProtocol->GetInformation ( @@ -727,57 +969,80 @@ AdapterInformationDumpInformation ( if (TempStr == NULL) { goto ERROR_EXIT; } - RetVal = CatSPrint (RetVal, TempStr, Status); + TempRetVal = CatSPrint (RetVal, TempStr, Status); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; } else { if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoMediaStateGuid)) { TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_MEDIA_STATE), NULL); if (TempStr == NULL) { goto ERROR_EXIT; } - RetVal = CatSPrint ( - RetVal, - TempStr, - ((EFI_ADAPTER_INFO_MEDIA_STATE *)InformationBlock)->MediaState, - ((EFI_ADAPTER_INFO_MEDIA_STATE *)InformationBlock)->MediaState - ); + TempRetVal = CatSPrint ( + RetVal, + TempStr, + ((EFI_ADAPTER_INFO_MEDIA_STATE *)InformationBlock)->MediaState, + ((EFI_ADAPTER_INFO_MEDIA_STATE *)InformationBlock)->MediaState + ); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoNetworkBootGuid)) { TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_NETWORK_BOOT_INFO), NULL); if (TempStr == NULL) { goto ERROR_EXIT; } - RetVal = CatSPrint ( - RetVal, - TempStr, - ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv4BootCapablity, - ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv6BootCapablity, - ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->FCoeBootCapablity, - ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->OffloadCapability, - ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiMpioCapability, - ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv4Boot, - ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv6Boot, - ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->FCoeBoot - ); - } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoSanMacAddressGuid) == TRUE) { + TempRetVal = CatSPrint ( + RetVal, + TempStr, + ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv4BootCapablity, + ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv6BootCapablity, + ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->FCoeBootCapablity, + ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->OffloadCapability, + ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiMpioCapability, + ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv4Boot, + ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->iScsiIpv6Boot, + ((EFI_ADAPTER_INFO_NETWORK_BOOT *)InformationBlock)->FCoeBoot + ); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; + } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoSanMacAddressGuid) == TRUE) { TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_SAN_MAC_ADDRESS_INFO), NULL); if (TempStr == NULL) { goto ERROR_EXIT; } - RetVal = CatSPrint ( - RetVal, - TempStr, - ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[0], - ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[1], - ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[2], - ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[3], - ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[4], - ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[5] - ); + TempRetVal = CatSPrint ( + RetVal, + TempStr, + ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[0], + ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[1], + ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[2], + ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[3], + ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[4], + ((EFI_ADAPTER_INFO_SAN_MAC_ADDRESS *)InformationBlock)->SanMacAddress.Addr[5] + ); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; + } else if (CompareGuid (&InfoTypesBuffer[GuidIndex], &gEfiAdapterInfoUndiIpv6SupportGuid) == TRUE) { + TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_UNDI_IPV6_INFO), NULL); + if (TempStr == NULL) { + goto ERROR_EXIT; + } + + TempRetVal = CatSPrint ( + RetVal, + TempStr, + ((EFI_ADAPTER_INFO_UNDI_IPV6_SUPPORT *)InformationBlock)->Ipv6Support + ); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; } else { TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_UNKNOWN_INFO_TYPE), NULL); if (TempStr == NULL) { goto ERROR_EXIT; } - RetVal = CatSPrint (RetVal, TempStr, &InfoTypesBuffer[GuidIndex]); + TempRetVal = CatSPrint (RetVal, TempStr, &InfoTypesBuffer[GuidIndex]); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; } } SHELL_FREE_NON_NULL (TempStr); @@ -794,6 +1059,407 @@ ERROR_EXIT: SHELL_FREE_NON_NULL (InformationBlock); return NULL; } + +/** + Function to dump information about EFI_FIRMWARE_MANAGEMENT_PROTOCOL Protocol. + + @param[in] TheHandle The handle that has the protocol installed. + @param[in] Verbose TRUE for additional information, FALSE otherwise. + + @retval A pointer to a string containing the information. +**/ +CHAR16* +EFIAPI +FirmwareManagementDumpInformation ( + IN CONST EFI_HANDLE TheHandle, + IN CONST BOOLEAN Verbose + ) +{ + EFI_STATUS Status; + EFI_FIRMWARE_MANAGEMENT_PROTOCOL *EfiFwMgmtProtocol; + EFI_FIRMWARE_IMAGE_DESCRIPTOR *ImageInfo; + EFI_FIRMWARE_IMAGE_DESCRIPTOR_V1 *ImageInfoV1; + EFI_FIRMWARE_IMAGE_DESCRIPTOR_V2 *ImageInfoV2; + UINT64 AttributeSetting; + UINTN ImageInfoSize; + UINTN DescriptorSize; + UINT32 DescriptorVersion; + UINT32 PackageVersion; + UINT8 DescriptorCount; + UINT8 Index; + UINT8 Index1; + UINT8 ImageCount; + CHAR16 *PackageVersionName; + CHAR16 *TempStr; + CHAR16 *RetVal; + CHAR16 *TempRetVal; + CHAR16 *AttributeSettingStr; + BOOLEAN Found; + BOOLEAN AttributeSupported; + + // + // Initialize local variables + // + ImageCount = 0; + ImageInfoSize = 1; + AttributeSetting = 0; + Found = FALSE; + AttributeSupported = FALSE; + ImageInfo = NULL; + ImageInfoV1 = NULL; + ImageInfoV2 = NULL; + PackageVersionName = NULL; + RetVal = NULL; + TempRetVal = NULL; + TempStr = NULL; + AttributeSettingStr = NULL; + + if (!Verbose) { + return (CatSPrint(NULL, L"FirmwareManagement")); + } + + Status = gBS->OpenProtocol ( + (EFI_HANDLE) (TheHandle), + &gEfiFirmwareManagementProtocolGuid, + (VOID **) &EfiFwMgmtProtocol, + NULL, + NULL, + EFI_OPEN_PROTOCOL_GET_PROTOCOL + ); + + if (EFI_ERROR (Status)) { + return NULL; + } + + Status = EfiFwMgmtProtocol->GetImageInfo ( + EfiFwMgmtProtocol, + &ImageInfoSize, + ImageInfo, + &DescriptorVersion, + &DescriptorCount, + &DescriptorSize, + &PackageVersion, + &PackageVersionName + ); + + if (Status == EFI_BUFFER_TOO_SMALL) { + ImageInfo = AllocateZeroPool (ImageInfoSize); + + if (ImageInfo == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } else { + Status = EfiFwMgmtProtocol->GetImageInfo ( + EfiFwMgmtProtocol, + &ImageInfoSize, + ImageInfo, + &DescriptorVersion, + &DescriptorCount, + &DescriptorSize, + &PackageVersion, + &PackageVersionName + ); + } + } + + if (EFI_ERROR (Status)) { + goto ERROR_EXIT; + } + + // + // Decode Image Descriptor data only if its version is supported + // + if (DescriptorVersion <= EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION) { + + if (ImageInfo == NULL) { + goto ERROR_EXIT; + } + + ImageInfoV1 = (EFI_FIRMWARE_IMAGE_DESCRIPTOR_V1 *)ImageInfo; + ImageInfoV2 = (EFI_FIRMWARE_IMAGE_DESCRIPTOR_V2 *)ImageInfo; + + // + // Set ImageInfoSize in return buffer + // + TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGE_INFO_SIZE), NULL); + if (TempStr == NULL) { + goto ERROR_EXIT; + } + RetVal = CatSPrint (NULL, TempStr, ImageInfoSize); + SHELL_FREE_NON_NULL (TempStr); + + // + // Set DescriptorVersion in return buffer + // + TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_DESCRIPTOR_VERSION), NULL); + if (TempStr == NULL) { + goto ERROR_EXIT; + } + TempRetVal = CatSPrint (RetVal, TempStr, DescriptorVersion); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; + SHELL_FREE_NON_NULL (TempStr); + + // + // Set DescriptorCount in return buffer + // + TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_DESCRIPTOR_COUNT), NULL); + if (TempStr == NULL) { + goto ERROR_EXIT; + } + TempRetVal = CatSPrint (RetVal, TempStr, DescriptorCount); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; + SHELL_FREE_NON_NULL (TempStr); + + + // + // Set DescriptorSize in return buffer + // + TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_DESCRIPTOR_SIZE), NULL); + if (TempStr == NULL) { + goto ERROR_EXIT; + } + TempRetVal = CatSPrint (RetVal, TempStr, DescriptorSize); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; + SHELL_FREE_NON_NULL (TempStr); + + // + // Set PackageVersion in return buffer + // + TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_PACKAGE_VERSION), NULL); + if (TempStr == NULL) { + goto ERROR_EXIT; + } + TempRetVal = CatSPrint (RetVal, TempStr, PackageVersion); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; + SHELL_FREE_NON_NULL (TempStr); + + // + // Set PackageVersionName in return buffer + // + TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_PACKAGE_VERSION_NAME), NULL); + if (TempStr == NULL) { + goto ERROR_EXIT; + } + TempRetVal = CatSPrint (RetVal, TempStr, PackageVersionName); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; + SHELL_FREE_NON_NULL (TempStr); + + for (Index = 0; Index < DescriptorCount; Index++) { + // + // First check if Attribute is supported + // and generate a string for AttributeSetting field + // + SHELL_FREE_NON_NULL (AttributeSettingStr); + AttributeSupported = FALSE; + AttributeSetting = 0; + if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V1) { + if (ImageInfoV1[Index].AttributesSupported != 0x0) { + AttributeSupported = TRUE; + AttributeSetting = ImageInfoV1[Index].AttributesSetting; + } + } else if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V2) { + if (ImageInfoV2[Index].AttributesSupported != 0x0) { + AttributeSupported = TRUE; + AttributeSetting = ImageInfoV2[Index].AttributesSetting; + } + } else { + if (ImageInfo[Index].AttributesSupported != 0x0) { + AttributeSupported = TRUE; + AttributeSetting = ImageInfo[Index].AttributesSetting; + } + } + + if (!AttributeSupported) { + AttributeSettingStr = CatSPrint (NULL, L"None"); + } else { + AttributeSettingStr = CatSPrint (NULL, L"("); + + if ((AttributeSetting & IMAGE_ATTRIBUTE_IMAGE_UPDATABLE) != 0x0) { + TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_IMAGE_UPDATABLE"); + SHELL_FREE_NON_NULL (AttributeSettingStr); + AttributeSettingStr = TempRetVal; + } + if ((AttributeSetting & IMAGE_ATTRIBUTE_RESET_REQUIRED) != 0x0) { + TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_RESET_REQUIRED"); + SHELL_FREE_NON_NULL (AttributeSettingStr); + AttributeSettingStr = TempRetVal; + } + if ((AttributeSetting & IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED) != 0x0) { + TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_AUTHENTICATION_REQUIRED"); + SHELL_FREE_NON_NULL (AttributeSettingStr); + AttributeSettingStr = TempRetVal; + } + if ((AttributeSetting & IMAGE_ATTRIBUTE_IN_USE) != 0x0) { + TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_IN_USE"); + SHELL_FREE_NON_NULL (AttributeSettingStr); + AttributeSettingStr = TempRetVal; + } + if ((AttributeSetting & IMAGE_ATTRIBUTE_UEFI_IMAGE) != 0x0) { + TempRetVal = CatSPrint (AttributeSettingStr, L" IMAGE_ATTRIBUTE_UEFI_IMAGE"); + SHELL_FREE_NON_NULL (AttributeSettingStr); + AttributeSettingStr = TempRetVal; + } + TempRetVal = CatSPrint (AttributeSettingStr, L" )"); + SHELL_FREE_NON_NULL (AttributeSettingStr); + AttributeSettingStr = TempRetVal; + } + + if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V1) { + if (ImageInfoV1[Index].ImageIndex != 0x0) { + ImageCount++; + } + + TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGE_DESCRIPTOR_INFO_V1), NULL); + if (TempStr == NULL) { + goto ERROR_EXIT; + } + TempRetVal = CatSPrint ( + RetVal, + TempStr, + Index, + ImageInfoV1[Index].ImageIndex, + &ImageInfoV1[Index].ImageTypeId, + ImageInfoV1[Index].ImageId, + ImageInfoV1[Index].ImageIdName, + ImageInfoV1[Index].Version, + ImageInfoV1[Index].VersionName, + ImageInfoV1[Index].Size, + ImageInfoV1[Index].AttributesSupported, + AttributeSettingStr, + ImageInfoV1[Index].Compatibilities + ); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; + SHELL_FREE_NON_NULL (TempStr); + } else if (DescriptorVersion == EFI_FIRMWARE_IMAGE_DESCRIPTOR_VERSION_V2) { + if (ImageInfoV2[Index].ImageIndex != 0x0) { + ImageCount++; + } + + TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGE_DESCRIPTOR_INFO_V2), NULL); + if (TempStr == NULL) { + goto ERROR_EXIT; + } + TempRetVal = CatSPrint ( + RetVal, + TempStr, + Index, + ImageInfoV2[Index].ImageIndex, + &ImageInfoV2[Index].ImageTypeId, + ImageInfoV2[Index].ImageId, + ImageInfoV2[Index].ImageIdName, + ImageInfoV2[Index].Version, + ImageInfoV2[Index].VersionName, + ImageInfoV2[Index].Size, + ImageInfoV2[Index].AttributesSupported, + AttributeSettingStr, + ImageInfoV2[Index].Compatibilities, + ImageInfoV2[Index].LowestSupportedImageVersion + ); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; + SHELL_FREE_NON_NULL (TempStr); + } else { + if (ImageInfo[Index].ImageIndex != 0x0) { + ImageCount++; + } + + TempStr = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_FMP_IMAGE_DESCRIPTOR_INFO), NULL); + if (TempStr == NULL) { + goto ERROR_EXIT; + } + TempRetVal = CatSPrint ( + RetVal, + TempStr, + Index, + ImageInfo[Index].ImageIndex, + &ImageInfo[Index].ImageTypeId, + ImageInfo[Index].ImageId, + ImageInfo[Index].ImageIdName, + ImageInfo[Index].Version, + ImageInfo[Index].VersionName, + ImageInfo[Index].Size, + ImageInfo[Index].AttributesSupported, + AttributeSettingStr, + ImageInfo[Index].Compatibilities, + ImageInfo[Index].LowestSupportedImageVersion, + ImageInfo[Index].LastAttemptVersion, + ImageInfo[Index].LastAttemptStatus, + ImageInfo[Index].HardwareInstance + ); + SHELL_FREE_NON_NULL (RetVal); + RetVal = TempRetVal; + SHELL_FREE_NON_NULL (TempStr); + } + } + } + + if (ImageCount > 0) { + for (Index=0; IndexGuidId, Guid)) { return (ListWalker); } @@ -1083,7 +1872,6 @@ Function to add a new GUID/Name mapping. @retval EFI_INVALID_PARAMETER Guid NameId was invalid **/ EFI_STATUS -EFIAPI InsertNewGuidNameMapping( IN CONST EFI_GUID *Guid, IN CONST EFI_STRING_ID NameID, @@ -1093,18 +1881,18 @@ InsertNewGuidNameMapping( ASSERT(Guid != NULL); ASSERT(NameID != 0); - GuidList = ReallocatePool(GuidListCount * sizeof(GUID_INFO_BLOCK), GuidListCount+1 * sizeof(GUID_INFO_BLOCK), GuidList); - if (GuidList == NULL) { - GuidListCount = 0; + mGuidList = ReallocatePool(mGuidListCount * sizeof(GUID_INFO_BLOCK), mGuidListCount+1 * sizeof(GUID_INFO_BLOCK), mGuidList); + if (mGuidList == NULL) { + mGuidListCount = 0; return (EFI_OUT_OF_RESOURCES); } - GuidListCount++; + mGuidListCount++; - GuidList[GuidListCount - 1].GuidId = AllocateCopyPool(sizeof(EFI_GUID), Guid); - GuidList[GuidListCount - 1].StringId = NameID; - GuidList[GuidListCount - 1].DumpInfo = DumpFunc; + mGuidList[mGuidListCount - 1].GuidId = AllocateCopyPool(sizeof(EFI_GUID), Guid); + mGuidList[mGuidListCount - 1].StringId = NameID; + mGuidList[mGuidListCount - 1].DumpInfo = DumpFunc; - if (GuidList[GuidListCount - 1].GuidId == NULL) { + if (mGuidList[mGuidListCount - 1].GuidId == NULL) { return (EFI_OUT_OF_RESOURCES); } @@ -1273,7 +2061,7 @@ GetGuidFromStringName( } } - for (LoopCount = 0, ListWalker = GuidList; GuidList != NULL && LoopCount < GuidListCount; LoopCount++, ListWalker++) { + for (LoopCount = 0, ListWalker = mGuidList; mGuidList != NULL && LoopCount < mGuidListCount; LoopCount++, ListWalker++) { String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang); if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) { *Guid = ListWalker->GuidId; @@ -1289,9 +2077,9 @@ GetGuidFromStringName( /** Get best support language for this driver. - - First base on the user input language to search, second base on the current - platform used language to search, third get the first language from the + + First base on the user input language to search, second base on the current + platform used language to search, third get the first language from the support language list. The caller need to free the buffer of the best language. @param[in] SupportedLanguages The support languages for this driver. @@ -1311,7 +2099,7 @@ GetBestLanguageForDriver ( CHAR8 *LanguageVariable; CHAR8 *BestLanguage; - LanguageVariable = GetVariable (Iso639Language ? L"Lang" : L"PlatformLang", &gEfiGlobalVariableGuid); + GetVariable2 (Iso639Language ? L"Lang" : L"PlatformLang", &gEfiGlobalVariableGuid, (VOID**)&LanguageVariable, NULL); BestLanguage = GetBestLanguage( SupportedLanguages, @@ -1398,7 +2186,6 @@ GetStringNameFromHandle( @retval EFI_SUCCESS The operation was successful. **/ EFI_STATUS -EFIAPI InternalShellInitHandleList( VOID ) @@ -1426,10 +2213,11 @@ InternalShellInitHandleList( } for (mHandleList.NextIndex = 1 ; mHandleList.NextIndex <= HandleCount ; mHandleList.NextIndex++){ ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST)); - ASSERT(ListWalker != NULL); - ListWalker->TheHandle = HandleBuffer[mHandleList.NextIndex-1]; - ListWalker->TheIndex = mHandleList.NextIndex; - InsertTailList(&mHandleList.List.Link,&ListWalker->Link); + if (ListWalker != NULL) { + ListWalker->TheHandle = HandleBuffer[mHandleList.NextIndex - 1]; + ListWalker->TheIndex = mHandleList.NextIndex; + InsertTailList (&mHandleList.List.Link, &ListWalker->Link); + } } FreePool(HandleBuffer); return (EFI_SUCCESS); @@ -1497,7 +2285,9 @@ ConvertHandleToHandleIndex( FreePool (ProtocolBuffer); ListWalker = AllocateZeroPool(sizeof(HANDLE_LIST)); - ASSERT(ListWalker != NULL); + if (ListWalker == NULL) { + return 0; + } ListWalker->TheHandle = TheHandle; ListWalker->TheIndex = mHandleList.NextIndex++; InsertTailList(&mHandleList.List.Link,&ListWalker->Link); @@ -1624,7 +2414,11 @@ ParseHandleDatabaseByRelationshipWithType ( } *HandleType = AllocateZeroPool (*HandleCount * sizeof (UINTN)); - ASSERT(*HandleType != NULL); + if (*HandleType == NULL) { + SHELL_FREE_NON_NULL (*HandleBuffer); + *HandleCount = 0; + return EFI_OUT_OF_RESOURCES; + } DriverBindingHandleIndex = -1; for (HandleIndex = 0; HandleIndex < *HandleCount; HandleIndex++) { @@ -1669,10 +2463,6 @@ ParseHandleDatabaseByRelationshipWithType ( (*HandleType)[HandleIndex] |= (UINTN)HR_COMPONENT_NAME_HANDLE; } else if (CompareGuid (ProtocolGuidArray[ProtocolIndex], &gEfiDevicePathProtocolGuid) ) { (*HandleType)[HandleIndex] |= (UINTN)HR_DEVICE_HANDLE; - } else { - DEBUG_CODE_BEGIN(); - ASSERT((*HandleType)[HandleIndex] == (*HandleType)[HandleIndex]); - DEBUG_CODE_END(); } // // Retrieve the list of agents that have opened each protocol @@ -1689,7 +2479,7 @@ ParseHandleDatabaseByRelationshipWithType ( if (ControllerHandle == NULL) { // - // ControllerHandle == NULL and DriverBindingHandle != NULL. + // ControllerHandle == NULL and DriverBindingHandle != NULL. // Return information on all the controller handles that the driver specified by DriverBindingHandle is managing // for (OpenInfoIndex = 0; OpenInfoIndex < OpenInfoCount; OpenInfoIndex++) { @@ -1884,26 +2674,28 @@ ParseHandleDatabaseByRelationship ( // Allocate a handle buffer for the number of handles that matched the attributes in Mask // *MatchingHandleBuffer = AllocateZeroPool ((*MatchingHandleCount +1)* sizeof (EFI_HANDLE)); - ASSERT(*MatchingHandleBuffer != NULL); + if (*MatchingHandleBuffer == NULL) { + Status = EFI_OUT_OF_RESOURCES; + } else { + for (HandleIndex = 0, *MatchingHandleCount = 0 + ; HandleIndex < HandleCount + ; HandleIndex++ + ) { + // + // Fill the allocated buffer with the handles that matched the attributes in Mask + // + if ((HandleType[HandleIndex] & Mask) == Mask) { + (*MatchingHandleBuffer)[(*MatchingHandleCount)++] = HandleBuffer[HandleIndex]; + } + } - for (HandleIndex = 0,*MatchingHandleCount = 0 - ; HandleIndex < HandleCount - ; HandleIndex++ - ){ // - // Fill the allocated buffer with the handles that matched the attributes in Mask + // Make the last one NULL // - if ((HandleType[HandleIndex] & Mask) == Mask) { - (*MatchingHandleBuffer)[(*MatchingHandleCount)++] = HandleBuffer[HandleIndex]; - } - } + (*MatchingHandleBuffer)[*MatchingHandleCount] = NULL; - // - // Make the last one NULL - // - (*MatchingHandleBuffer)[*MatchingHandleCount] = NULL; - - Status = EFI_SUCCESS; + Status = EFI_SUCCESS; + } // *MatchingHandleBuffer == NULL (ELSE) } // MacthingHandleBuffer == NULL (ELSE) } // *MatchingHandleCount == 0 (ELSE) } // no error on ParseHandleDatabaseByRelationshipWithType @@ -1916,6 +2708,9 @@ ParseHandleDatabaseByRelationship ( FreePool (HandleType); } + ASSERT ((MatchingHandleBuffer == NULL) || + (*MatchingHandleCount == 0 && *MatchingHandleBuffer == NULL) || + (*MatchingHandleCount != 0 && *MatchingHandleBuffer != NULL)); return Status; } @@ -1923,7 +2718,7 @@ ParseHandleDatabaseByRelationship ( Gets handles for any child controllers of the passed in controller. @param[in] ControllerHandle The handle of the "parent controller" - @param[in] MatchingHandleCount Pointer to the number of handles in + @param[out] MatchingHandleCount Pointer to the number of handles in MatchingHandleBuffer on return. @param[out] MatchingHandleBuffer Buffer containing handles on a successful return. @@ -1935,7 +2730,7 @@ EFI_STATUS EFIAPI ParseHandleDatabaseForChildControllers( IN CONST EFI_HANDLE ControllerHandle, - IN UINTN *MatchingHandleCount, + OUT UINTN *MatchingHandleCount, OUT EFI_HANDLE **MatchingHandleBuffer OPTIONAL ) { @@ -2002,12 +2797,22 @@ ParseHandleDatabaseForChildControllers( FreePool (DriverBindingHandleBuffer); + if (MatchingHandleBuffer == NULL || *MatchingHandleCount == 0) { + // + // The caller is not interested in the actual handles, or we've found none. + // + FreePool (HandleBufferForReturn); + HandleBufferForReturn = NULL; + } + if (MatchingHandleBuffer != NULL) { *MatchingHandleBuffer = HandleBufferForReturn; - } else { - FreePool(HandleBufferForReturn); } + ASSERT ((MatchingHandleBuffer == NULL) || + (*MatchingHandleCount == 0 && *MatchingHandleBuffer == NULL) || + (*MatchingHandleCount != 0 && *MatchingHandleBuffer != NULL)); + return (EFI_SUCCESS); } @@ -2027,7 +2832,6 @@ ParseHandleDatabaseForChildControllers( @return A pointer to (*DestinationBuffer). **/ VOID* -EFIAPI BuffernCatGrow ( IN OUT VOID **DestinationBuffer, IN OUT UINTN *DestinationSize, @@ -2237,7 +3041,7 @@ GetHandleListByProtocolList ( } // - // No handles were found... + // No handles were found... // if (TotalSize == sizeof(EFI_HANDLE)) { return (NULL); @@ -2275,13 +3079,3 @@ GetHandleListByProtocolList ( return (HandleList); } - - - - - - - - - -