From 34326197d13c4ff51aedf3c03461b72727d72ac1 Mon Sep 17 00:00:00 2001 From: Eric Dong Date: Wed, 13 May 2015 08:45:21 +0000 Subject: [PATCH] MdeModulePkg: Add sample code for keyword handler protocol. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Eric Dong Reviewed-by: Liming Gao Reviewed-by: Samer El-Haj-Mahmoud git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17431 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Universal/DriverSampleDxe/DriverSample.c | 90 +++++++++++++++++- .../Universal/DriverSampleDxe/DriverSample.h | 5 +- .../DriverSampleDxe/DriverSampleDxe.inf | 3 +- .../Universal/DriverSampleDxe/Inventory.vfr | 8 +- .../Universal/DriverSampleDxe/Vfr.vfr | 4 +- .../Universal/DriverSampleDxe/VfrStrings.uni | Bin 62662 -> 63554 bytes 6 files changed, 104 insertions(+), 6 deletions(-) diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c index 204c043ff4..22b6b265ee 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c +++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.c @@ -2,7 +2,7 @@ This is an example of how a driver might export data to the HII protocol to be later utilized by the Setup Protocol -Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.
+Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.
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 @@ -1279,6 +1279,10 @@ DriverCallback ( DRIVER_SAMPLE_CONFIGURATION *Configuration; MY_EFI_VARSTORE_DATA *EfiData; EFI_FORM_ID FormId; + EFI_STRING Progress; + EFI_STRING Results; + UINT32 ProgressErr; + CHAR16 *TmpStr; if (((Value == NULL) && (Action != EFI_BROWSER_ACTION_FORM_OPEN) && (Action != EFI_BROWSER_ACTION_FORM_CLOSE))|| (ActionRequest == NULL)) { @@ -1287,6 +1291,7 @@ DriverCallback ( FormId = 0; + ProgressErr = 0; Status = EFI_SUCCESS; PrivateData = DRIVER_SAMPLE_PRIVATE_FROM_THIS (This); @@ -1753,7 +1758,78 @@ DriverCallback ( // *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_DISCARD_EXIT; break; + + case 0x1231: + // + // 1. Check to see whether system support keyword. + // + Status = PrivateData->HiiKeywordHandler->GetData (PrivateData->HiiKeywordHandler, + L"NAMESPACE=x-UEFI-ns", + L"KEYWORD=iSCSIBootEnable", + &Progress, + &ProgressErr, + &Results + ); + if (EFI_ERROR (Status)) { + do { + CreatePopUp ( + EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, + &Key, + L"", + L"This system not support this keyword!", + L"Press ENTER to continue ...", + L"", + NULL + ); + } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN); + + Status = EFI_SUCCESS; + break; + } + + // + // 2. If system support this keyword, just try to change value. + // + // + // Change value from '0' to '1' or from '1' to '0' + // + TmpStr = StrStr (Results, L"&VALUE="); + ASSERT (TmpStr != NULL); + TmpStr += StrLen (L"&VALUE="); + TmpStr++; + if (*TmpStr == L'0') { + *TmpStr = L'1'; + } else { + *TmpStr = L'0'; + } + + // + // 3. Call the keyword handler protocol to change the value. + // + Status = PrivateData->HiiKeywordHandler->SetData (PrivateData->HiiKeywordHandler, + Results, + &Progress, + &ProgressErr + ); + if (EFI_ERROR (Status)) { + do { + CreatePopUp ( + EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE, + &Key, + L"", + L"Set keyword to the system failed!", + L"Press ENTER to continue ...", + L"", + NULL + ); + } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN); + + Status = EFI_SUCCESS; + break; + } + break; + default: break; } @@ -1790,6 +1866,7 @@ DriverSampleInit ( EFI_HII_STRING_PROTOCOL *HiiString; EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2; EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; + EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL *HiiKeywordHandler; CHAR16 *NewString; UINTN BufferSize; DRIVER_SAMPLE_CONFIGURATION *Configuration; @@ -1867,6 +1944,15 @@ DriverSampleInit ( } PrivateData->HiiConfigRouting = HiiConfigRouting; + // + // Locate keyword handler protocol + // + Status = gBS->LocateProtocol (&gEfiConfigKeywordHandlerProtocolGuid, NULL, (VOID **) &HiiKeywordHandler); + if (EFI_ERROR (Status)) { + return Status; + } + PrivateData->HiiKeywordHandler = HiiKeywordHandler; + Status = gBS->InstallMultipleProtocolInterfaces ( &DriverHandle[0], &gEfiDevicePathProtocolGuid, @@ -1902,6 +1988,8 @@ DriverSampleInit ( &DriverHandle[1], &gEfiDevicePathProtocolGuid, &mHiiVendorDevicePath1, + &gEfiHiiConfigAccessProtocolGuid, + &PrivateData->ConfigAccess, NULL ); ASSERT_EFI_ERROR (Status); diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h index 29870c0f1f..97dee9c79a 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h +++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSample.h @@ -1,6 +1,6 @@ /** @file -Copyright (c) 2007 - 2013, Intel Corporation. All rights reserved.
+Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.
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 @@ -32,6 +32,7 @@ Revision History #include #include #include +#include #include #include @@ -97,6 +98,8 @@ typedef struct { EFI_HII_DATABASE_PROTOCOL *HiiDatabase; EFI_HII_STRING_PROTOCOL *HiiString; EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; + EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL *HiiKeywordHandler; + EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2; // diff --git a/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf b/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf index 307c4c3dde..f5c0b4670b 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf +++ b/MdeModulePkg/Universal/DriverSampleDxe/DriverSampleDxe.inf @@ -4,7 +4,7 @@ # This driver shows how HII protocol, VFR and UNI files are used to create a HII # driver which can be dipslayed and configured by a UEFI HII Form Browser. # -# Copyright (c) 2007 - 2014, Intel Corporation. All rights reserved.
+# Copyright (c) 2007 - 2015, Intel Corporation. All rights reserved.
# # This program and the accompanying materials # are licensed and made available under the terms and conditions of the BSD License @@ -92,6 +92,7 @@ gEfiHiiDatabaseProtocolGuid ## CONSUMES gEfiSimpleTextInputExProtocolGuid ## SOMETIMES_CONSUMES gEfiFormBrowserExProtocolGuid ## CONSUMES + gEfiConfigKeywordHandlerProtocolGuid ## CONSUMES [Depex] gEfiSimpleTextOutProtocolGuid AND gEfiHiiDatabaseProtocolGuid AND gEfiVariableArchProtocolGuid AND gEfiVariableWriteArchProtocolGuid diff --git a/MdeModulePkg/Universal/DriverSampleDxe/Inventory.vfr b/MdeModulePkg/Universal/DriverSampleDxe/Inventory.vfr index b835dfc392..b5b93d4c86 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/Inventory.vfr +++ b/MdeModulePkg/Universal/DriverSampleDxe/Inventory.vfr @@ -2,7 +2,7 @@ // // Sample Inventory Data // -// Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.
+// Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.
// 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 @@ -104,6 +104,12 @@ formset flags = 0, key = 0; + text + help = STRING_TOKEN(STR_CHECK_KEYWORD_SUPPORT), + text = STRING_TOKEN(STR_CHECK_KEYWORD_SUPPORT), + flags = INTERACTIVE, + key = 0x1231; + subtitle text = STRING_TOKEN(STR_INV_EMPTY_STRING); subtitle text = STRING_TOKEN(STR_INV_VERSION_TEXT12); diff --git a/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr b/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr index bd90fcd9c3..68f34623a5 100644 --- a/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr +++ b/MdeModulePkg/Universal/DriverSampleDxe/Vfr.vfr @@ -2,7 +2,7 @@ // // Sample Setup formset. // -// Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.
+// Copyright (c) 2004 - 2015, Intel Corporation. All rights reserved.
// 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 @@ -280,7 +280,7 @@ formset endoneof; oneof varid = MyIfrNVData.QuestionAboutTreeHugging, - prompt = STRING_TOKEN(STR_ONE_OF_PROMPT), + prompt = STRING_TOKEN(STR_ONE_OF_PROMPT_KEYWORD), help = STRING_TOKEN(STR_ONE_OF_HELP), flags = RESET_REQUIRED, option text = STRING_TOKEN(STR_ONE_OF_TEXT1), value = 0, flags = 0; diff --git a/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni b/MdeModulePkg/Universal/DriverSampleDxe/VfrStrings.uni index 7053b7cc364630d9950fc9cf3103ad55adf34e18..a3fbaed8a431621dd0b9338364a80d66f7313b88 100644 GIT binary patch delta 386 zcmX^1lKIdF<_STJrW=C|*(Zy!3+Y!d=rV*dxH7mgcmi2@48;rz3`#(eRE9K$Oa?!O zM21`-JD8yW$Vz5N-CWClRCF?z3=e-igEvrHBttlZKSL0M%jAovjMWu@VyO(34CM^@ z3`GnnK%-y=6vGSviiJ!zTv)5^3sgtE`h0Ed4$TBQ%^8S28JvK2<};K4-IO=k@uvFZ zdzw75C@y4(2dWEY2mnHmi$f*{E;gL(CB-F=Fhc=uiUPHypPN1AVPN`uJc2Yq~#6&Tqj3kYjWj*{Wqyg*j%IshD)SBwAv delta 28 kcmX@~f%(`=<_STJCL4nd*(V!aRM`B6eV*v%eF`nt0k@?Lwg3PC -- 2.39.2