mirror of https://github.com/acidanthera/audk.git
ShellPkg: Add Dynamic GUID registration into the current GUID<->String conversion process
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jaben Carsey <jaben.carsey@intel.com> Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15753 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
parent
044ea4e54e
commit
6306fd90b7
|
@ -17,6 +17,27 @@
|
|||
|
||||
#include <Uefi.h>
|
||||
|
||||
/**
|
||||
Function to add a new GUID/Name mapping.
|
||||
|
||||
This cannot overwrite an existing mapping.
|
||||
|
||||
@param[in] Guid The Guid
|
||||
@param[in] TheName The Guid's name
|
||||
@param[in] Lang RFC4646 language code list or NULL
|
||||
|
||||
@retval EFI_SUCCESS The operation was sucessful
|
||||
@retval EFI_ACCESS_DENIED There was a duplicate
|
||||
@retval EFI_OUT_OF_RESOURCES A memory allocation failed
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
AddNewGuidNameMapping(
|
||||
IN CONST EFI_GUID *Guid,
|
||||
IN CONST CHAR16 *TheName,
|
||||
IN CONST CHAR8 *Lang OPTIONAL
|
||||
);
|
||||
|
||||
/**
|
||||
Function to get the name of a protocol or struct from it's GUID.
|
||||
|
||||
|
|
|
@ -16,9 +16,10 @@
|
|||
#include "UefiHandleParsingLib.h"
|
||||
#include "IndustryStandard/Acpi10.h"
|
||||
|
||||
EFI_HANDLE mHandleParsingHiiHandle;
|
||||
EFI_HANDLE mHandleParsingHiiHandle;
|
||||
HANDLE_INDEX_LIST mHandleList = {{{NULL,NULL},0,0},0};
|
||||
|
||||
GUID_INFO_BLOCK *GuidList;
|
||||
UINTN GuidListCount;
|
||||
/**
|
||||
Function to translate the EFI_MEMORY_TYPE into a string.
|
||||
|
||||
|
@ -98,6 +99,9 @@ HandleParsingLibConstructor (
|
|||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
GuidListCount = 0;
|
||||
GuidList = NULL;
|
||||
|
||||
mHandleParsingHiiHandle = HiiAddPackages (&gHandleParsingHiiGuid, gImageHandle, UefiHandleParsingLibStrings, NULL);
|
||||
if (mHandleParsingHiiHandle == NULL) {
|
||||
return (EFI_DEVICE_ERROR);
|
||||
|
@ -121,6 +125,13 @@ HandleParsingLibDestructor (
|
|||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
UINTN LoopCount;
|
||||
|
||||
for (LoopCount = 0; GuidList != NULL && LoopCount < GuidListCount; LoopCount++) {
|
||||
SHELL_FREE_NON_NULL(GuidList[LoopCount].GuidId);
|
||||
}
|
||||
|
||||
SHELL_FREE_NON_NULL(GuidList);
|
||||
if (mHandleParsingHiiHandle != NULL) {
|
||||
HiiRemovePackages(mHandleParsingHiiHandle);
|
||||
}
|
||||
|
@ -780,9 +791,16 @@ InternalShellGetNodeFromGuid(
|
|||
)
|
||||
{
|
||||
CONST GUID_INFO_BLOCK *ListWalker;
|
||||
UINTN LoopCount;
|
||||
|
||||
ASSERT(Guid != NULL);
|
||||
|
||||
for (LoopCount = 0, ListWalker = GuidList; GuidList != NULL && LoopCount < GuidListCount; LoopCount++, ListWalker++) {
|
||||
if (CompareGuid(ListWalker->GuidId, Guid)) {
|
||||
return (ListWalker);
|
||||
}
|
||||
}
|
||||
|
||||
if (PcdGetBool(PcdShellIncludeNtGuids)) {
|
||||
for (ListWalker = mGuidStringListNT ; ListWalker != NULL && ListWalker->GuidId != NULL ; ListWalker++) {
|
||||
if (CompareGuid(ListWalker->GuidId, Guid)) {
|
||||
|
@ -795,7 +813,90 @@ InternalShellGetNodeFromGuid(
|
|||
return (ListWalker);
|
||||
}
|
||||
}
|
||||
return (ListWalker);
|
||||
return (NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
Function to add a new GUID/Name mapping.
|
||||
|
||||
@param[in] Guid The Guid
|
||||
@param[in] NameId The STRING id of the HII string to use
|
||||
@param[in] Dump The pointer to the dump function
|
||||
|
||||
|
||||
@retval EFI_SUCCESS The operation was sucessful
|
||||
@retval EFI_OUT_OF_RESOURCES A memory allocation failed
|
||||
@retval EFI_INVALID_PARAMETER Guid NameId was invalid
|
||||
**/
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
InsertNewGuidNameMapping(
|
||||
IN CONST EFI_GUID *Guid,
|
||||
IN CONST EFI_STRING_ID NameID,
|
||||
IN CONST DUMP_PROTOCOL_INFO DumpFunc OPTIONAL
|
||||
)
|
||||
{
|
||||
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;
|
||||
return (EFI_OUT_OF_RESOURCES);
|
||||
}
|
||||
GuidListCount++;
|
||||
|
||||
GuidList[GuidListCount - 1].GuidId = AllocateCopyPool(sizeof(EFI_GUID), Guid);
|
||||
GuidList[GuidListCount - 1].StringId = NameID;
|
||||
GuidList[GuidListCount - 1].DumpInfo = DumpFunc;
|
||||
|
||||
if (GuidList[GuidListCount - 1].GuidId == NULL) {
|
||||
return (EFI_OUT_OF_RESOURCES);
|
||||
}
|
||||
|
||||
return (EFI_SUCCESS);
|
||||
}
|
||||
|
||||
/**
|
||||
Function to add a new GUID/Name mapping.
|
||||
|
||||
This cannot overwrite an existing mapping.
|
||||
|
||||
@param[in] Guid The Guid
|
||||
@param[in] TheName The Guid's name
|
||||
@param[in] Lang RFC4646 language code list or NULL
|
||||
|
||||
@retval EFI_SUCCESS The operation was sucessful
|
||||
@retval EFI_ACCESS_DENIED There was a duplicate
|
||||
@retval EFI_OUT_OF_RESOURCES A memory allocation failed
|
||||
@retval EFI_INVALID_PARAMETER Guid or TheName was NULL
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
AddNewGuidNameMapping(
|
||||
IN CONST EFI_GUID *Guid,
|
||||
IN CONST CHAR16 *TheName,
|
||||
IN CONST CHAR8 *Lang OPTIONAL
|
||||
)
|
||||
{
|
||||
CONST GUID_INFO_BLOCK *Temp;
|
||||
EFI_STRING_ID NameID;
|
||||
|
||||
if (Guid == NULL || TheName == NULL){
|
||||
return (EFI_INVALID_PARAMETER);
|
||||
}
|
||||
|
||||
if ((Temp = InternalShellGetNodeFromGuid(Guid)) != NULL) {
|
||||
return (EFI_ACCESS_DENIED);
|
||||
}
|
||||
|
||||
NameID = HiiSetString(mHandleParsingHiiHandle, 0, (CHAR16*)TheName, Lang);
|
||||
if (NameID == 0) {
|
||||
return (EFI_OUT_OF_RESOURCES);
|
||||
}
|
||||
|
||||
return (InsertNewGuidNameMapping(Guid, NameID, NULL));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -819,7 +920,7 @@ GetStringNameFromGuid(
|
|||
CONST GUID_INFO_BLOCK *Id;
|
||||
|
||||
Id = InternalShellGetNodeFromGuid(Guid);
|
||||
return (HiiGetString(mHandleParsingHiiHandle, Id->StringId, Lang));
|
||||
return (HiiGetString(mHandleParsingHiiHandle, Id==NULL?STRING_TOKEN(STR_UNKNOWN_DEVICE):Id->StringId, Lang));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -883,6 +984,7 @@ GetGuidFromStringName(
|
|||
{
|
||||
CONST GUID_INFO_BLOCK *ListWalker;
|
||||
CHAR16 *String;
|
||||
UINTN LoopCount;
|
||||
|
||||
ASSERT(Guid != NULL);
|
||||
if (Guid == NULL) {
|
||||
|
@ -912,6 +1014,18 @@ GetGuidFromStringName(
|
|||
return (EFI_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
for (LoopCount = 0, ListWalker = GuidList; GuidList != NULL && LoopCount < GuidListCount; LoopCount++, ListWalker++) {
|
||||
String = HiiGetString(mHandleParsingHiiHandle, ListWalker->StringId, Lang);
|
||||
if (Name != NULL && String != NULL && StringNoCaseCompare (&Name, &String) == 0) {
|
||||
*Guid = ListWalker->GuidId;
|
||||
}
|
||||
SHELL_FREE_NON_NULL(String);
|
||||
if (*Guid != NULL) {
|
||||
return (EFI_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
return (EFI_NOT_FOUND);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
Provides interface to advanced shell functionality for parsing both handle and protocol database.
|
||||
|
||||
Copyright (c) 2013 - 2014, Hewlett-Packard Development Company, L.P.
|
||||
Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>
|
||||
Copyright (c) 2011 - 2014, Intel Corporation. All rights reserved.<BR>
|
||||
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
|
||||
|
@ -134,6 +134,7 @@
|
|||
#include <Protocol/IdeControllerInit.h>
|
||||
#include <Protocol/DiskIo2.h>
|
||||
#include <Protocol/AdapterInformation.h>
|
||||
#include <Protocol/EfiShellDynamicCommand.h>
|
||||
|
||||
#include <Library/HandleParsingLib.h>
|
||||
#include <Library/UefiBootServicesTableLib.h>
|
||||
|
|
Loading…
Reference in New Issue