2 This is an example of how a driver might export data to the HII protocol to be
3 later utilized by the Setup Protocol
5 Copyright (c) 2004 - 2008, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "DriverSample.h"
19 #define DISPLAY_ONLY_MY_ITEM 0x0002
21 EFI_GUID mFormSetGuid
= FORMSET_GUID
;
22 EFI_GUID mInventoryGuid
= INVENTORY_GUID
;
24 CHAR16 VariableName
[] = L
"MyIfrNVData";
26 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath1
= {
32 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
33 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
37 // {C153B68D-EBFC-488e-B110-662867745B87}
39 { 0xc153b68d, 0xebfc, 0x488e, { 0xb1, 0x10, 0x66, 0x28, 0x67, 0x74, 0x5b, 0x87 } }
43 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
45 (UINT8
) (END_DEVICE_PATH_LENGTH
),
46 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
51 HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath2
= {
57 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
58 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
62 // {06F37F07-0C48-40e9-8436-0A08A0BB76B0}
64 { 0x6f37f07, 0xc48, 0x40e9, { 0x84, 0x36, 0xa, 0x8, 0xa0, 0xbb, 0x76, 0xb0 } }
68 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
70 (UINT8
) (END_DEVICE_PATH_LENGTH
),
71 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
77 Encode the password using a simple algorithm.
79 @param Password The string to be encoded.
80 @param MaxSize The size of the string.
95 Buffer
= AllocateZeroPool (MaxSize
);
96 ASSERT (Buffer
!= NULL
);
98 for (Index
= 0; Key
[Index
] != 0; Index
++) {
99 for (Loop
= 0; Loop
< (UINT8
) (MaxSize
/ 2); Loop
++) {
100 Buffer
[Loop
] = (CHAR16
) (Password
[Loop
] ^ Key
[Index
]);
104 CopyMem (Password
, Buffer
, MaxSize
);
111 Validate the user's password.
113 @param PrivateData This driver's private context data.
114 @param StringId The user's input.
116 @retval EFI_SUCCESS The user's input matches the password.
117 @retval EFI_NOT_READY The user's input does not match the password.
121 IN DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
,
122 IN EFI_STRING_ID StringId
129 CHAR16
*EncodedPassword
;
133 // Get encoded password first
135 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
136 Status
= gRT
->GetVariable (
141 &PrivateData
->Configuration
143 if (EFI_ERROR (Status
)) {
145 // Old password not exist, prompt for new password
152 // Check whether we have any old password set
154 for (Index
= 0; Index
< 20; Index
++) {
155 if (PrivateData
->Configuration
.WhatIsThePassword2
[Index
] != 0) {
162 // Old password not exist, return EFI_SUCCESS to prompt for new password
168 // Get user input password
170 BufferSize
= 21 * sizeof (CHAR16
);
171 Password
= AllocateZeroPool (BufferSize
);
172 ASSERT (Password
!= NULL
);
174 Status
= HiiLibGetString (PrivateData
->HiiHandle
[0], StringId
, Password
, &BufferSize
);
175 if (EFI_ERROR (Status
)) {
181 // Validate old password
183 EncodedPassword
= AllocateCopyPool (21 * sizeof (CHAR16
), Password
);
184 ASSERT (EncodedPassword
!= NULL
);
185 EncodePassword (EncodedPassword
, 20 * sizeof (CHAR16
));
186 if (CompareMem (EncodedPassword
, PrivateData
->Configuration
.WhatIsThePassword2
, 20 * sizeof (CHAR16
)) != 0) {
188 // Old password mismatch, return EFI_NOT_READY to prompt for error message
190 Status
= EFI_NOT_READY
;
192 Status
= EFI_SUCCESS
;
196 FreePool (EncodedPassword
);
202 Encode the password using a simple algorithm.
204 @param PrivateData This driver's private context data.
205 @param StringId The password from User.
207 @retval EFI_SUCESS The operation is successful.
208 @return Other value if gRT->SetVariable () fails.
213 IN DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
,
214 IN EFI_STRING_ID StringId
221 DRIVER_SAMPLE_CONFIGURATION
*Configuration
;
224 // Get Buffer Storage data from EFI variable
226 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
227 Status
= gRT
->GetVariable (
232 &PrivateData
->Configuration
234 if (EFI_ERROR (Status
)) {
239 // Get user input password
241 Password
= &PrivateData
->Configuration
.WhatIsThePassword2
[0];
242 PasswordSize
= sizeof (PrivateData
->Configuration
.WhatIsThePassword2
);
244 ZeroMem (Password
, PasswordSize
);
245 Status
= HiiLibGetString (PrivateData
->HiiHandle
[0], StringId
, Password
, &BufferSize
);
246 if (EFI_ERROR (Status
)) {
251 // Retrive uncommitted data from Browser
253 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
254 Configuration
= AllocateZeroPool (sizeof (DRIVER_SAMPLE_PRIVATE_DATA
));
255 ASSERT (Configuration
!= NULL
);
256 Status
= GetBrowserData (&mFormSetGuid
, VariableName
, &BufferSize
, (UINT8
*) Configuration
);
257 if (!EFI_ERROR (Status
)) {
259 // Update password's clear text in the screen
261 CopyMem (Configuration
->PasswordClearText
, Password
, PasswordSize
);
264 // Update uncommitted data of Browser
266 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
267 Status
= SetBrowserData (
271 (UINT8
*) Configuration
,
275 FreePool (Configuration
);
280 EncodePassword (Password
, PasswordSize
);
281 Status
= gRT
->SetVariable(
284 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
285 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
286 &PrivateData
->Configuration
293 This function allows a caller to extract the current configuration for one
294 or more named elements from the target driver.
296 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
297 @param Request A null-terminated Unicode string in
298 <ConfigRequest> format.
299 @param Progress On return, points to a character in the Request
300 string. Points to the string's null terminator if
301 request was successful. Points to the most recent
302 '&' before the first failing name/value pair (or
303 the beginning of the string if the failure is in
304 the first name/value pair) if the request was not
306 @param Results A null-terminated Unicode string in
307 <ConfigAltResp> format which has all values filled
308 in for the names in the Request string. String to
309 be allocated by the called function.
311 @retval EFI_SUCCESS The Results is filled with the requested values.
312 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
313 @retval EFI_INVALID_PARAMETER Request is NULL, illegal syntax, or unknown name.
314 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
321 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
322 IN CONST EFI_STRING Request
,
323 OUT EFI_STRING
*Progress
,
324 OUT EFI_STRING
*Results
329 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
330 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
332 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
333 HiiConfigRouting
= PrivateData
->HiiConfigRouting
;
337 // Get Buffer Storage data from EFI variable
339 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
340 Status
= gRT
->GetVariable (
345 &PrivateData
->Configuration
347 if (EFI_ERROR (Status
)) {
351 if (Request
== NULL
) {
353 // Request is set to NULL, return all configurable elements together with ALTCFG
355 Status
= ConstructConfigAltResp (
361 PrivateData
->DriverHandle
[0],
362 &PrivateData
->Configuration
,
364 VfrMyIfrNVDataBlockName
,
366 STRING_TOKEN (STR_STANDARD_DEFAULT_PROMPT
),
367 VfrMyIfrNVDataDefault0000
,
368 STRING_TOKEN (STR_MANUFACTURE_DEFAULT_PROMPT
),
369 VfrMyIfrNVDataDefault0001
376 // Check routing data in <ConfigHdr>.
377 // Note: if only one Storage is used, then this checking could be skipped.
379 if (!IsConfigHdrMatch (Request
, &mFormSetGuid
, VariableName
)) {
381 return EFI_NOT_FOUND
;
385 // Convert buffer data to <ConfigResp> by helper function BlockToConfig()
387 Status
= HiiConfigRouting
->BlockToConfig (
390 (UINT8
*) &PrivateData
->Configuration
,
400 This function processes the results of changes in configuration.
402 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
403 @param Configuration A null-terminated Unicode string in <ConfigResp>
405 @param Progress A pointer to a string filled in with the offset of
406 the most recent '&' before the first failing
407 name/value pair (or the beginning of the string if
408 the failure is in the first name/value pair) or
409 the terminating NULL if all was successful.
411 @retval EFI_SUCCESS The Results is processed successfully.
412 @retval EFI_INVALID_PARAMETER Configuration is NULL.
413 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
420 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
421 IN CONST EFI_STRING Configuration
,
422 OUT EFI_STRING
*Progress
427 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
428 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
430 if (Configuration
== NULL
) {
431 return EFI_INVALID_PARAMETER
;
434 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
435 HiiConfigRouting
= PrivateData
->HiiConfigRouting
;
437 // Check routing data in <ConfigHdr>.
438 // Note: if only one Storage is used, then this checking could be skipped.
440 if (!IsConfigHdrMatch (Configuration
, &mFormSetGuid
, VariableName
)) {
441 *Progress
= Configuration
;
442 return EFI_NOT_FOUND
;
446 // Get Buffer Storage data from EFI variable
448 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
449 Status
= gRT
->GetVariable (
454 &PrivateData
->Configuration
456 if (EFI_ERROR (Status
)) {
461 // Convert <ConfigResp> to buffer data by helper function ConfigToBlock()
463 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
464 Status
= HiiConfigRouting
->ConfigToBlock (
467 (UINT8
*) &PrivateData
->Configuration
,
471 if (EFI_ERROR (Status
)) {
476 // Store Buffer Storage back to EFI variable
478 Status
= gRT
->SetVariable(
481 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
482 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
483 &PrivateData
->Configuration
491 This function processes the results of changes in configuration.
493 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
494 @param Action Specifies the type of action taken by the browser.
495 @param QuestionId A unique value which is sent to the original
496 exporting driver so that it can identify the type
498 @param Type The type of value for the question.
499 @param Value A pointer to the data being sent to the original
501 @param ActionRequest On return, points to the action requested by the
504 @retval EFI_SUCCESS The callback successfully handled the action.
505 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
506 variable and its data.
507 @retval EFI_DEVICE_ERROR The variable could not be saved.
508 @retval EFI_UNSUPPORTED The specified Action is not supported by the
515 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
516 IN EFI_BROWSER_ACTION Action
,
517 IN EFI_QUESTION_ID QuestionId
,
519 IN EFI_IFR_TYPE_VALUE
*Value
,
520 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
523 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
525 EFI_HII_UPDATE_DATA UpdateData
;
526 IFR_OPTION
*IfrOptionList
;
529 if ((Value
== NULL
) || (ActionRequest
== NULL
)) {
530 return EFI_INVALID_PARAMETER
;
533 Status
= EFI_SUCCESS
;
534 PrivateData
= DRIVER_SAMPLE_PRIVATE_FROM_THIS (This
);
536 switch (QuestionId
) {
539 // Initialize the container for dynamic opcodes
541 IfrLibInitUpdateData (&UpdateData
, 0x1000);
543 IfrOptionList
= AllocatePool (2 * sizeof (IFR_OPTION
));
544 ASSERT (IfrOptionList
!= NULL
);
546 IfrOptionList
[0].Flags
= 0;
547 IfrOptionList
[0].StringToken
= STRING_TOKEN (STR_BOOT_OPTION1
);
548 IfrOptionList
[0].Value
.u8
= 1;
549 IfrOptionList
[1].Flags
= EFI_IFR_OPTION_DEFAULT
;
550 IfrOptionList
[1].StringToken
= STRING_TOKEN (STR_BOOT_OPTION2
);
551 IfrOptionList
[1].Value
.u8
= 2;
554 0x1237, // Question ID
555 STRING_TOKEN(STR_EXIT_TEXT
), // Prompt text
556 STRING_TOKEN(STR_EXIT_TEXT
), // Help text
557 EFI_IFR_FLAG_CALLBACK
, // Question flag
558 0, // Action String ID
559 &UpdateData
// Container for dynamic created opcodes
563 // Prepare initial value for the dynamic created oneof Question
565 PrivateData
->Configuration
.DynamicOneof
= 2;
566 Status
= gRT
->SetVariable(
569 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
570 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
571 &PrivateData
->Configuration
574 0x8001, // Question ID (or call it "key")
575 CONFIGURATION_VARSTORE_ID
, // VarStore ID
576 (UINT16
) DYNAMIC_ONE_OF_VAR_OFFSET
, // Offset in Buffer Storage
577 STRING_TOKEN (STR_ONE_OF_PROMPT
), // Question prompt text
578 STRING_TOKEN (STR_ONE_OF_HELP
), // Question help text
579 EFI_IFR_FLAG_CALLBACK
, // Question flag
580 EFI_IFR_NUMERIC_SIZE_1
, // Data type of Question Value
581 IfrOptionList
, // Option list
582 2, // Number of options in Option list
583 &UpdateData
// Container for dynamic created opcodes
586 CreateOrderedListOpCode (
587 0x8002, // Question ID
588 CONFIGURATION_VARSTORE_ID
, // VarStore ID
589 (UINT16
) DYNAMIC_ORDERED_LIST_VAR_OFFSET
, // Offset in Buffer Storage
590 STRING_TOKEN (STR_BOOT_OPTIONS
), // Question prompt text
591 STRING_TOKEN (STR_BOOT_OPTIONS
), // Question help text
592 EFI_IFR_FLAG_RESET_REQUIRED
, // Question flag
593 0, // Ordered list flag, e.g. EFI_IFR_UNIQUE_SET
594 EFI_IFR_NUMERIC_SIZE_1
, // Data type of Question value
595 5, // Maximum container
596 IfrOptionList
, // Option list
597 2, // Number of options in Option list
598 &UpdateData
// Container for dynamic created opcodes
603 STRING_TOKEN (STR_GOTO_FORM1
), // Prompt text
604 STRING_TOKEN (STR_GOTO_HELP
), // Help text
606 0x8003, // Question ID
607 &UpdateData
// Container for dynamic created opcodes
610 Status
= IfrLibUpdateForm (
611 PrivateData
->HiiHandle
[0], // HII handle
612 &mFormSetGuid
, // Formset GUID
614 0x1234, // Label for where to insert opcodes
615 TRUE
, // Append or replace
616 &UpdateData
// Dynamic created opcodes
618 FreePool (IfrOptionList
);
619 IfrLibFreeUpdateData (&UpdateData
);
624 // We will reach here once the Question is refreshed
626 IfrLibInitUpdateData (&UpdateData
, 0x1000);
628 IfrOptionList
= AllocatePool (2 * sizeof (IFR_OPTION
));
629 ASSERT (IfrOptionList
!= NULL
);
632 0x1237, // Question ID
633 STRING_TOKEN(STR_EXIT_TEXT
), // Prompt text
634 STRING_TOKEN(STR_EXIT_TEXT
), // Help text
635 EFI_IFR_FLAG_CALLBACK
, // Question flag
636 0, // Action String ID
637 &UpdateData
// Container for dynamic created opcodes
640 Status
= IfrLibUpdateForm (
641 PrivateData
->HiiHandle
[0], // HII handle
642 &mFormSetGuid
, // Formset GUID
644 0x2234, // Label for where to insert opcodes
645 TRUE
, // Append or replace
646 &UpdateData
// Dynamic created opcodes
648 IfrLibFreeUpdateData (&UpdateData
);
651 // Refresh the Question value
653 PrivateData
->Configuration
.DynamicRefresh
++;
654 Status
= gRT
->SetVariable(
657 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
658 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
659 &PrivateData
->Configuration
663 // Change an EFI Variable storage (MyEfiVar) asynchronous, this will cause
664 // the first statement in Form 3 be suppressed
667 Status
= gRT
->SetVariable(
670 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
678 // User press "Exit now", request Browser to exit
680 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_EXIT
;
685 // User press "Save now", request Browser to save the uncommitted data.
687 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_SUBMIT
;
692 // When try to set a new password, user will be chanlleged with old password.
693 // The Callback is responsible for validating old password input by user,
694 // If Callback return EFI_SUCCESS, it indicates validation pass.
696 switch (PrivateData
->PasswordState
) {
697 case BROWSER_STATE_VALIDATE_PASSWORD
:
698 Status
= ValidatePassword (PrivateData
, Value
->string
);
699 if (Status
== EFI_SUCCESS
) {
700 PrivateData
->PasswordState
= BROWSER_STATE_SET_PASSWORD
;
704 case BROWSER_STATE_SET_PASSWORD
:
705 Status
= SetPassword (PrivateData
, Value
->string
);
706 PrivateData
->PasswordState
= BROWSER_STATE_VALIDATE_PASSWORD
;
723 Main entry for this driver.
725 @param ImageHandle Image handle this driver.
726 @param SystemTable Pointer to SystemTable.
728 @retval EFI_SUCESS This function always complete successfully.
734 IN EFI_HANDLE ImageHandle
,
735 IN EFI_SYSTEM_TABLE
*SystemTable
739 EFI_STATUS SavedStatus
;
740 EFI_HII_PACKAGE_LIST_HEADER
*PackageList
;
741 EFI_HII_HANDLE HiiHandle
[2];
742 EFI_HANDLE DriverHandle
[2] = {NULL
, NULL
};
743 DRIVER_SAMPLE_PRIVATE_DATA
*PrivateData
;
744 EFI_SCREEN_DESCRIPTOR Screen
;
745 EFI_HII_DATABASE_PROTOCOL
*HiiDatabase
;
746 EFI_HII_STRING_PROTOCOL
*HiiString
;
747 EFI_FORM_BROWSER2_PROTOCOL
*FormBrowser2
;
748 EFI_HII_CONFIG_ROUTING_PROTOCOL
*HiiConfigRouting
;
751 DRIVER_SAMPLE_CONFIGURATION
*Configuration
;
752 BOOLEAN ExtractIfrDefault
;
755 // Initialize the library and our protocol.
759 // Initialize screen dimensions for SendForm().
760 // Remove 3 characters from top and bottom
762 ZeroMem (&Screen
, sizeof (EFI_SCREEN_DESCRIPTOR
));
763 gST
->ConOut
->QueryMode (gST
->ConOut
, gST
->ConOut
->Mode
->Mode
, &Screen
.RightColumn
, &Screen
.BottomRow
);
766 Screen
.BottomRow
= Screen
.BottomRow
- 3;
769 // Initialize driver private data
771 PrivateData
= AllocatePool (sizeof (DRIVER_SAMPLE_PRIVATE_DATA
));
772 if (PrivateData
== NULL
) {
773 return EFI_OUT_OF_RESOURCES
;
776 PrivateData
->Signature
= DRIVER_SAMPLE_PRIVATE_SIGNATURE
;
778 PrivateData
->ConfigAccess
.ExtractConfig
= ExtractConfig
;
779 PrivateData
->ConfigAccess
.RouteConfig
= RouteConfig
;
780 PrivateData
->ConfigAccess
.Callback
= DriverCallback
;
781 PrivateData
->PasswordState
= BROWSER_STATE_VALIDATE_PASSWORD
;
784 // Locate Hii Database protocol
786 Status
= gBS
->LocateProtocol (&gEfiHiiDatabaseProtocolGuid
, NULL
, (VOID
**) &HiiDatabase
);
787 if (EFI_ERROR (Status
)) {
790 PrivateData
->HiiDatabase
= HiiDatabase
;
793 // Locate HiiString protocol
795 Status
= gBS
->LocateProtocol (&gEfiHiiStringProtocolGuid
, NULL
, (VOID
**) &HiiString
);
796 if (EFI_ERROR (Status
)) {
799 PrivateData
->HiiString
= HiiString
;
802 // Locate Formbrowser2 protocol
804 Status
= gBS
->LocateProtocol (&gEfiFormBrowser2ProtocolGuid
, NULL
, (VOID
**) &FormBrowser2
);
805 if (EFI_ERROR (Status
)) {
808 PrivateData
->FormBrowser2
= FormBrowser2
;
811 // Locate ConfigRouting protocol
813 Status
= gBS
->LocateProtocol (&gEfiHiiConfigRoutingProtocolGuid
, NULL
, (VOID
**) &HiiConfigRouting
);
814 if (EFI_ERROR (Status
)) {
817 PrivateData
->HiiConfigRouting
= HiiConfigRouting
;
819 Status
= gBS
->InstallMultipleProtocolInterfaces (
821 &gEfiDevicePathProtocolGuid
,
822 &mHiiVendorDevicePath1
,
823 &gEfiHiiConfigAccessProtocolGuid
,
824 &PrivateData
->ConfigAccess
,
827 ASSERT_EFI_ERROR (Status
);
829 PrivateData
->DriverHandle
[0] = DriverHandle
[0];
832 // Publish our HII data
834 PackageList
= HiiLibPreparePackageList (
840 if (PackageList
== NULL
) {
841 return EFI_OUT_OF_RESOURCES
;
844 Status
= HiiDatabase
->NewPackageList (
850 FreePool (PackageList
);
851 if (EFI_ERROR (Status
)) {
854 PrivateData
->HiiHandle
[0] = HiiHandle
[0];
857 // Publish another Fromset
859 Status
= gBS
->InstallMultipleProtocolInterfaces (
861 &gEfiDevicePathProtocolGuid
,
862 &mHiiVendorDevicePath2
,
865 ASSERT_EFI_ERROR (Status
);
867 PrivateData
->DriverHandle
[1] = DriverHandle
[1];
869 PackageList
= HiiLibPreparePackageList (
875 if (PackageList
== NULL
) {
876 return EFI_OUT_OF_RESOURCES
;
879 Status
= HiiDatabase
->NewPackageList (
885 FreePool (PackageList
);
886 if (EFI_ERROR (Status
)) {
889 PrivateData
->HiiHandle
[1] = HiiHandle
[1];
892 // Very simple example of how one would update a string that is already
893 // in the HII database
895 NewString
= L
"700 Mhz";
897 Status
= HiiLibSetString (HiiHandle
[0], STRING_TOKEN (STR_CPU_STRING2
), NewString
);
898 if (EFI_ERROR (Status
)) {
903 // Initialize configuration data
905 Configuration
= &PrivateData
->Configuration
;
906 ZeroMem (Configuration
, sizeof (DRIVER_SAMPLE_CONFIGURATION
));
909 // Try to read NV config EFI variable first
911 ExtractIfrDefault
= TRUE
;
912 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
913 Status
= gRT
->GetVariable (VariableName
, &mFormSetGuid
, NULL
, &BufferSize
, Configuration
);
914 if (!EFI_ERROR (Status
) && (BufferSize
== sizeof (DRIVER_SAMPLE_CONFIGURATION
))) {
915 ExtractIfrDefault
= FALSE
;
918 if (ExtractIfrDefault
) {
920 // EFI variable for NV config doesn't exit, we should build this variable
921 // based on default values stored in IFR
923 BufferSize
= sizeof (DRIVER_SAMPLE_CONFIGURATION
);
924 Status
= IfrLibExtractDefault (Configuration
, &BufferSize
, 1, VfrMyIfrNVDataDefault0000
);
926 if (!EFI_ERROR (Status
)) {
930 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
931 sizeof (DRIVER_SAMPLE_CONFIGURATION
),
938 // Example of how to display only the item we sent to HII
940 if (DISPLAY_ONLY_MY_ITEM
== 0x0001) {
942 // Have the browser pull out our copy of the data, and only display our data
944 // Status = FormConfig->SendForm (FormConfig, TRUE, HiiHandle, NULL, NULL, NULL, &Screen, NULL);
946 Status
= FormBrowser2
->SendForm (
955 SavedStatus
= Status
;
957 Status
= HiiDatabase
->RemovePackageList (HiiDatabase
, HiiHandle
[0]);
958 if (EFI_ERROR (Status
)) {
962 Status
= HiiDatabase
->RemovePackageList (HiiDatabase
, HiiHandle
[1]);
963 if (EFI_ERROR (Status
)) {
970 // Have the browser pull out all the data in the HII Database and display it.
972 // Status = FormConfig->SendForm (FormConfig, TRUE, 0, NULL, NULL, NULL, NULL, NULL);