diff options
author | Jaben Carsey <jaben.carsey@intel.com> | 2014-08-05 18:03:49 +0000 |
---|---|---|
committer | jcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524> | 2014-08-05 18:03:49 +0000 |
commit | 6306fd90b7056d69ea4519afc25121cc5bc9bce9 (patch) | |
tree | 96a9b00611ada1c3ab23a6d19174286e54218ea8 | |
parent | 044ea4e54e0d2992d55582b6cfcb5d24156ae65d (diff) | |
download | edk2-6306fd90b7056d69ea4519afc25121cc5bc9bce9.zip edk2-6306fd90b7056d69ea4519afc25121cc5bc9bce9.tar.gz edk2-6306fd90b7056d69ea4519afc25121cc5bc9bce9.tar.bz2 |
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
3 files changed, 141 insertions, 5 deletions
diff --git a/ShellPkg/Include/Library/HandleParsingLib.h b/ShellPkg/Include/Library/HandleParsingLib.h index c7e9319..1c9ed49 100644 --- a/ShellPkg/Include/Library/HandleParsingLib.h +++ b/ShellPkg/Include/Library/HandleParsingLib.h @@ -18,6 +18,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.
If Guid is NULL, then ASSERT.
diff --git a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c index 31555f4..3cdf5f8 100644 --- a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c +++ b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c @@ -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);
}
diff --git a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.h b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.h index 29337f3..c1735a6 100644 --- a/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.h +++ b/ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.h @@ -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>
|