add in FrameworkIfrSupportLib

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2881 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
qwang12 2007-06-29 03:49:52 +00:00
parent 2df4bd6600
commit 5d01b0f704
7 changed files with 3317 additions and 0 deletions

View File

@ -0,0 +1,39 @@
/**@file
Common header file shared by all source files.
This file includes package header files, library classes and protocol, PPI & GUID definitions.
Copyright (c) 2006 - 2007, 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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#ifndef __COMMON_HEADER_H_
#define __COMMON_HEADER_H_
//
// The package level header files this module uses
//
#include <PiDxe.h>
//
// The protocols, PPI and GUID defintions for this module
//
#include <Guid/GlobalVariable.h>
#include <Protocol/FrameworkHii.h>
//
// The Library classes this module consumes
//
#include <Library/FrameworkIfrSupportLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#endif

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,977 @@
/*++
Copyright (c) 2006, 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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
IfrOnTheFly.c
Abstract:
Library Routines to create IFR on-the-fly
Revision History:
--*/
//
// Include common header file for this module.
//
#include "CommonHeader.h"
EFI_STATUS
CreateFormSet (
IN CHAR16 *FormSetTitle,
IN EFI_GUID *Guid,
IN UINT8 Class,
IN UINT8 SubClass,
IN OUT VOID **FormBuffer,
IN OUT VOID **StringBuffer
)
/*++
Routine Description:
Create a formset
Arguments:
FormSetTitle - Title of formset
Guid - Guid of formset
Class - Class of formset
SubClass - Sub class of formset
FormBuffer - Pointer of the formset created
StringBuffer - Pointer of FormSetTitile string created
Returns:
EFI_OUT_OF_RESOURCES - No enough buffer to allocate
EFI_SUCCESS - Formset successfully created
--*/
{
EFI_STATUS Status;
EFI_HII_IFR_PACK IfrPack;
EFI_IFR_FORM_SET FormSet;
EFI_IFR_END_FORM_SET EndFormSet;
UINT8 *Destination;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// Pre-allocate a buffer sufficient for us to work from.
//
FormBuffer = AllocateZeroPool (DEFAULT_FORM_BUFFER_SIZE);
if (FormBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
}
//
// Pre-allocate a buffer sufficient for us to work from.
//
StringBuffer = AllocateZeroPool (DEFAULT_STRING_BUFFER_SIZE);
if (StringBuffer == NULL) {
gBS->FreePool (FormBuffer);
return EFI_OUT_OF_RESOURCES;
}
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
//
// Add the FormSetTitle to the string buffer and get the StringToken
//
Status = AddString (*StringBuffer, CurrentLanguage, FormSetTitle, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
//
// Initialize the Ifr Package header data
//
IfrPack.Header.Length = sizeof (EFI_HII_PACK_HEADER) + sizeof (EFI_IFR_FORM_SET) + sizeof (EFI_IFR_END_FORM_SET);
IfrPack.Header.Type = EFI_HII_IFR;
//
// Initialize FormSet with the appropriate information
//
FormSet.Header.OpCode = EFI_IFR_FORM_SET_OP;
FormSet.Header.Length = sizeof (EFI_IFR_FORM_SET);
FormSet.FormSetTitle = StringToken;
FormSet.Class = Class;
FormSet.SubClass = SubClass;
CopyMem (&FormSet.Guid, Guid, sizeof (EFI_GUID));
//
// Initialize the end formset data
//
EndFormSet.Header.Length = sizeof (EFI_IFR_END_FORM_SET);
EndFormSet.Header.OpCode = EFI_IFR_END_FORM_SET_OP;
Destination = (UINT8 *) *FormBuffer;
//
// Copy the formset/endformset data to the form buffer
//
CopyMem (Destination, &IfrPack, sizeof (EFI_HII_PACK_HEADER));
Destination = Destination + sizeof (EFI_HII_PACK_HEADER);
CopyMem (Destination, &FormSet, sizeof (EFI_IFR_FORM_SET));
Destination = Destination + sizeof (EFI_IFR_FORM_SET);
CopyMem (Destination, &EndFormSet, sizeof (EFI_IFR_END_FORM_SET));
return EFI_SUCCESS;
}
EFI_STATUS
CreateForm (
IN CHAR16 *FormTitle,
IN UINT16 FormId,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a form
Arguments:
FormTitle - Title of the form
FormId - Id of the form
FormBuffer - Pointer of the form created
StringBuffer - Pointer of FormTitil string created
Returns:
EFI_SUCCESS - Form successfully created
--*/
{
EFI_STATUS Status;
EFI_IFR_FORM Form;
EFI_IFR_END_FORM EndForm;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
Status = AddString (StringBuffer, CurrentLanguage, FormTitle, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
Form.Header.OpCode = EFI_IFR_FORM_OP;
Form.Header.Length = sizeof (EFI_IFR_FORM);
Form.FormId = FormId;
Form.FormTitle = StringToken;
Status = AddOpCode (FormBuffer, &Form);
if (EFI_ERROR (Status)) {
return Status;
}
EndForm.Header.OpCode = EFI_IFR_END_FORM_OP;
EndForm.Header.Length = sizeof (EFI_IFR_END_FORM);
Status = AddOpCode (FormBuffer, &EndForm);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
CreateSubTitle (
IN CHAR16 *SubTitle,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a SubTitle
Arguments:
SubTitle - Sub title to be created
FormBuffer - Where this subtitle to add to
StringBuffer - String buffer created for subtitle
Returns:
EFI_SUCCESS - Subtitle successfully created
--*/
{
EFI_STATUS Status;
EFI_IFR_SUBTITLE Subtitle;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
Status = AddString (StringBuffer, CurrentLanguage, SubTitle, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
Subtitle.Header.OpCode = EFI_IFR_SUBTITLE_OP;
Subtitle.Header.Length = sizeof (EFI_IFR_SUBTITLE);
Subtitle.SubTitle = StringToken;
Status = AddOpCode (FormBuffer, &Subtitle);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
CreateText (
IN CHAR16 *String,
IN CHAR16 *String2,
IN CHAR16 *String3,
IN UINT8 Flags,
IN UINT16 Key,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a line of text
Arguments:
String - First string of the text
String2 - Second string of the text
String3 - Help string of the text
Flags - Flag of the text
Key - Key of the text
FormBuffer - The form where this text adds to
StringBuffer - String buffer created for String, String2 and String3
Returns:
EFI_SUCCESS - Text successfully created
--*/
{
EFI_STATUS Status;
EFI_IFR_TEXT Text;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
//
// Add first string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, String, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
Text.Header.OpCode = EFI_IFR_TEXT_OP;
Text.Header.Length = sizeof (EFI_IFR_TEXT);
Text.Text = StringToken;
//
// Add second string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, String2, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
Text.TextTwo = StringToken;
Text.Flags = (UINT8) (Flags | EFI_IFR_FLAG_CREATED);
Text.Key = Key;
//
// Add second string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, String3, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
Text.Help = StringToken;
Status = AddOpCode (FormBuffer, &Text);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
CreateGoto (
IN UINT16 FormId,
IN CHAR16 *Prompt,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a hyperlink
Arguments:
FormId - Form ID of the hyperlink
Prompt - Prompt of the hyperlink
FormBuffer - The form where this hyperlink adds to
StringBuffer - String buffer created for Prompt
Returns:
EFI_SUCCESS - Hyperlink successfully created
--*/
{
EFI_STATUS Status;
EFI_IFR_REF Hyperlink;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
Hyperlink.Header.OpCode = EFI_IFR_REF_OP;
Hyperlink.Header.Length = sizeof (EFI_IFR_REF);
Hyperlink.FormId = FormId;
Hyperlink.Prompt = StringToken;
Status = AddOpCode (FormBuffer, &Hyperlink);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
CreateOneOf (
IN UINT16 QuestionId,
IN UINT8 DataWidth,
IN CHAR16 *Prompt,
IN CHAR16 *Help,
IN IFR_OPTION *OptionsList,
IN UINTN OptionCount,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a one-of question with a set of options to choose from. The
OptionsList is a pointer to a null-terminated list of option descriptions.
Arguments:
QuestionId - Question ID of the one-of box
DataWidth - DataWidth of the one-of box
Prompt - Prompt of the one-of box
Help - Help of the one-of box
OptionsList - Each string in it is an option of the one-of box
OptionCount - Option string count
FormBuffer - The form where this one-of box adds to
StringBuffer - String buffer created for Prompt, Help and Option strings
Returns:
EFI_DEVICE_ERROR - DataWidth > 2
EFI_SUCCESS - One-Of box successfully created.
--*/
{
EFI_STATUS Status;
UINTN Index;
EFI_IFR_ONE_OF OneOf;
EFI_IFR_ONE_OF_OPTION OneOfOption;
EFI_IFR_END_ONE_OF EndOneOf;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// We do not create op-code storage widths for one-of in excess of 16 bits for now
//
if (DataWidth > 2) {
return EFI_DEVICE_ERROR;
}
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
//
// Add first string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
OneOf.Header.OpCode = EFI_IFR_ONE_OF_OP;
OneOf.Header.Length = sizeof (EFI_IFR_ONE_OF);
OneOf.QuestionId = QuestionId;
OneOf.Width = DataWidth;
OneOf.Prompt = StringToken;
//
// Add second string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
OneOf.Help = StringToken;
Status = AddOpCode (FormBuffer, &OneOf);
if (EFI_ERROR (Status)) {
return Status;
}
for (Index = 0; Index < OptionCount; Index++) {
OneOfOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP;
OneOfOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION);
//
// Add string and get token back
//
Status = AddString (StringBuffer, CurrentLanguage, OptionsList[Index].OptionString, &StringToken);
OneOfOption.Option = StringToken;
OneOfOption.Value = OptionsList[Index].Value;
OneOfOption.Flags = (UINT8) (OptionsList[Index].Flags | EFI_IFR_FLAG_CREATED);
OneOfOption.Key = OptionsList[Index].Key;
Status = AddOpCode (FormBuffer, &OneOfOption);
if (EFI_ERROR (Status)) {
return Status;
}
}
EndOneOf.Header.Length = sizeof (EFI_IFR_END_ONE_OF);
EndOneOf.Header.OpCode = EFI_IFR_END_ONE_OF_OP;
Status = AddOpCode (FormBuffer, &EndOneOf);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
CreateOrderedList (
IN UINT16 QuestionId,
IN UINT8 MaxEntries,
IN CHAR16 *Prompt,
IN CHAR16 *Help,
IN IFR_OPTION *OptionsList,
IN UINTN OptionCount,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a one-of question with a set of options to choose from. The
OptionsList is a pointer to a null-terminated list of option descriptions.
Arguments:
QuestionId - Question ID of the ordered list
MaxEntries - MaxEntries of the ordered list
Prompt - Prompt of the ordered list
Help - Help of the ordered list
OptionsList - Each string in it is an option of the ordered list
OptionCount - Option string count
FormBuffer - The form where this ordered list adds to
StringBuffer - String buffer created for Prompt, Help and Option strings
Returns:
EFI_SUCCESS - Ordered list successfully created.
--*/
{
EFI_STATUS Status;
UINTN Index;
EFI_IFR_ORDERED_LIST OrderedList;
EFI_IFR_ONE_OF_OPTION OrderedListOption;
EFI_IFR_END_ONE_OF EndOrderedList;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
//
// Add first string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
OrderedList.Header.OpCode = EFI_IFR_ORDERED_LIST_OP;
OrderedList.Header.Length = sizeof (EFI_IFR_ORDERED_LIST);
OrderedList.QuestionId = QuestionId;
OrderedList.MaxEntries = MaxEntries;
OrderedList.Prompt = StringToken;
//
// Add second string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
OrderedList.Help = StringToken;
Status = AddOpCode (FormBuffer, &OrderedList);
if (EFI_ERROR (Status)) {
return Status;
}
for (Index = 0; Index < OptionCount; Index++) {
OrderedListOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP;
OrderedListOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION);
//
// Add string and get token back
//
Status = AddString (StringBuffer, CurrentLanguage, OptionsList[Index].OptionString, &StringToken);
OrderedListOption.Option = StringToken;
OrderedListOption.Value = OptionsList[Index].Value;
OrderedListOption.Flags = (UINT8) (OptionsList[Index].Flags | EFI_IFR_FLAG_CREATED);
OrderedListOption.Key = OptionsList[Index].Key;
Status = AddOpCode (FormBuffer, &OrderedListOption);
if (EFI_ERROR (Status)) {
return Status;
}
}
EndOrderedList.Header.Length = sizeof (EFI_IFR_END_ONE_OF);
EndOrderedList.Header.OpCode = EFI_IFR_END_ONE_OF_OP;
Status = AddOpCode (FormBuffer, &EndOrderedList);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
CreateCheckBox (
IN UINT16 QuestionId,
IN UINT8 DataWidth,
IN CHAR16 *Prompt,
IN CHAR16 *Help,
IN UINT8 Flags,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a checkbox
Arguments:
QuestionId - Question ID of the check box
DataWidth - DataWidth of the check box
Prompt - Prompt of the check box
Help - Help of the check box
Flags - Flags of the check box
FormBuffer - The form where this check box adds to
StringBuffer - String buffer created for Prompt and Help.
Returns:
EFI_DEVICE_ERROR - DataWidth > 1
EFI_SUCCESS - Check box successfully created
--*/
{
EFI_STATUS Status;
EFI_IFR_CHECKBOX CheckBox;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// We do not create op-code storage widths for checkbox in excess of 8 bits for now
//
if (DataWidth > 1) {
return EFI_DEVICE_ERROR;
}
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
//
// Add first string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
CheckBox.Header.OpCode = EFI_IFR_CHECKBOX_OP;
CheckBox.Header.Length = sizeof (EFI_IFR_CHECKBOX);
CheckBox.QuestionId = QuestionId;
CheckBox.Width = DataWidth;
CheckBox.Prompt = StringToken;
//
// Add second string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
CheckBox.Help = StringToken;
CheckBox.Flags = (UINT8) (Flags | EFI_IFR_FLAG_CREATED);
Status = AddOpCode (FormBuffer, &CheckBox);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
CreateNumeric (
IN UINT16 QuestionId,
IN UINT8 DataWidth,
IN CHAR16 *Prompt,
IN CHAR16 *Help,
IN UINT16 Minimum,
IN UINT16 Maximum,
IN UINT16 Step,
IN UINT16 Default,
IN UINT8 Flags,
IN UINT16 Key,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a numeric
Arguments:
QuestionId - Question ID of the numeric
DataWidth - DataWidth of the numeric
Prompt - Prompt of the numeric
Help - Help of the numeric
Minimum - Minumun boundary of the numeric
Maximum - Maximum boundary of the numeric
Step - Step of the numeric
Default - Default value
Flags - Flags of the numeric
Key - Key of the numeric
FormBuffer - The form where this numeric adds to
StringBuffer - String buffer created for Prompt and Help.
Returns:
EFI_DEVICE_ERROR - DataWidth > 2
EFI_SUCCESS - Numeric is successfully created
--*/
{
EFI_STATUS Status;
EFI_IFR_NUMERIC Numeric;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// We do not create op-code storage widths for numerics in excess of 16 bits for now
//
if (DataWidth > 2) {
return EFI_DEVICE_ERROR;
}
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
//
// Add first string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
Numeric.Header.OpCode = EFI_IFR_NUMERIC_OP;
Numeric.Header.Length = sizeof (EFI_IFR_NUMERIC);
Numeric.QuestionId = QuestionId;
Numeric.Width = DataWidth;
Numeric.Prompt = StringToken;
//
// Add second string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
Numeric.Help = StringToken;
Numeric.Minimum = Minimum;
Numeric.Maximum = Maximum;
Numeric.Step = Step;
Numeric.Default = Default;
Numeric.Flags = (UINT8) (Flags | EFI_IFR_FLAG_CREATED);
Numeric.Key = Key;
Status = AddOpCode (FormBuffer, &Numeric);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}
EFI_STATUS
CreateString (
IN UINT16 QuestionId,
IN UINT8 DataWidth,
IN CHAR16 *Prompt,
IN CHAR16 *Help,
IN UINT8 MinSize,
IN UINT8 MaxSize,
IN UINT8 Flags,
IN UINT16 Key,
IN OUT VOID *FormBuffer,
IN OUT VOID *StringBuffer
)
/*++
Routine Description:
Create a string
Arguments:
QuestionId - Question ID of the string
DataWidth - DataWidth of the string
Prompt - Prompt of the string
Help - Help of the string
MinSize - Min size boundary of the string
MaxSize - Max size boundary of the string
Flags - Flags of the string
Key - Key of the string
FormBuffer - The form where this string adds to
StringBuffer - String buffer created for Prompt and Help.
Returns:
EFI_SUCCESS - String successfully created.
--*/
{
EFI_STATUS Status;
EFI_IFR_STRING String;
CHAR16 CurrentLanguage[4];
STRING_REF StringToken;
//
// Obtain current language value
//
GetCurrentLanguage (CurrentLanguage);
//
// Add first string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Prompt, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
String.Header.OpCode = EFI_IFR_STRING_OP;
String.Header.Length = sizeof (EFI_IFR_STRING);
String.QuestionId = QuestionId;
String.Width = DataWidth;
String.Prompt = StringToken;
//
// Add second string, get first string's token
//
Status = AddString (StringBuffer, CurrentLanguage, Help, &StringToken);
if (EFI_ERROR (Status)) {
return Status;
}
String.Help = StringToken;
String.MinSize = MinSize;
String.MaxSize = MaxSize;
String.Flags = (UINT8) (Flags | EFI_IFR_FLAG_CREATED);
String.Key = Key;
Status = AddOpCode (FormBuffer, &String);
if (EFI_ERROR (Status)) {
return Status;
}
return EFI_SUCCESS;
}

View File

@ -0,0 +1,618 @@
/*++
Copyright (c) 2006, 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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
IfrOpCodeCreation.c
Abstract:
Library Routines to create IFR independent of string data - assume tokens already exist
Primarily to be used for exporting op-codes at a label in pre-defined forms.
Revision History:
--*/
//
// Include common header file for this module.
//
#include "CommonHeader.h"
EFI_STATUS
CreateSubTitleOpCode (
IN STRING_REF StringToken,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a SubTitle opcode independent of string creation
This is used primarily by users who need to create just one particular valid op-code and the string
data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
location to pre-defined forms in HII)
Arguments:
StringToken - StringToken of the subtitle
FormBuffer - Output of subtitle as a form
Returns:
EFI_SUCCESS - Subtitle created to be a form
--*/
{
EFI_IFR_SUBTITLE Subtitle;
Subtitle.Header.OpCode = EFI_IFR_SUBTITLE_OP;
Subtitle.Header.Length = sizeof (EFI_IFR_SUBTITLE);
Subtitle.SubTitle = StringToken;
CopyMem (FormBuffer, &Subtitle, sizeof (EFI_IFR_SUBTITLE));
return EFI_SUCCESS;
}
EFI_STATUS
CreateTextOpCode (
IN STRING_REF StringToken,
IN STRING_REF StringTokenTwo,
IN STRING_REF StringTokenThree,
IN UINT8 Flags,
IN UINT16 Key,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a Text opcode independent of string creation
This is used primarily by users who need to create just one particular valid op-code and the string
data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
location to pre-defined forms in HII)
Arguments:
StringToken - First string token of the text
StringTokenTwo - Second string token of the text
StringTokenThree - Help string token of the text
Flags - Flag of the text
Key - Key of the text
FormBuffer - Output of text as a form
Returns:
EFI_SUCCESS - Text created to be a form
--*/
{
EFI_IFR_TEXT Text;
Text.Header.OpCode = EFI_IFR_TEXT_OP;
Text.Header.Length = sizeof (EFI_IFR_TEXT);
Text.Text = StringToken;
Text.TextTwo = StringTokenTwo;
Text.Help = StringTokenThree;
Text.Flags = Flags;
Text.Key = Key;
CopyMem (FormBuffer, &Text, sizeof (EFI_IFR_TEXT));
return EFI_SUCCESS;
}
EFI_STATUS
CreateGotoOpCode (
IN UINT16 FormId,
IN STRING_REF StringToken,
IN STRING_REF StringTokenTwo,
IN UINT8 Flags,
IN UINT16 Key,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a hyperlink opcode independent of string creation
This is used primarily by users who need to create just one particular valid op-code and the string
data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
location to pre-defined forms in HII)
Arguments:
FormId - Form ID of the hyperlink
StringToken - Prompt string token of the hyperlink
StringTokenTwo - Help string token of the hyperlink
Flags - Flags of the hyperlink
Key - Key of the hyperlink
FormBuffer - Output of hyperlink as a form
Returns:
EFI_SUCCESS - Hyperlink created to be a form
--*/
{
EFI_IFR_REF Hyperlink;
Hyperlink.Header.OpCode = EFI_IFR_REF_OP;
Hyperlink.Header.Length = sizeof (EFI_IFR_REF);
Hyperlink.FormId = FormId;
Hyperlink.Prompt = StringToken;
Hyperlink.Help = StringTokenTwo;
Hyperlink.Key = Key;
Hyperlink.Flags = Flags;
CopyMem (FormBuffer, &Hyperlink, sizeof (EFI_IFR_REF));
return EFI_SUCCESS;
}
EFI_STATUS
CreateOneOfOpCode (
IN UINT16 QuestionId,
IN UINT8 DataWidth,
IN STRING_REF PromptToken,
IN STRING_REF HelpToken,
IN IFR_OPTION *OptionsList,
IN UINTN OptionCount,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a one-of opcode with a set of option op-codes to choose from independent of string creation.
This is used primarily by users who need to create just one particular valid op-code and the string
data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
location to pre-defined forms in HII)
OptionsList is a pointer to a null-terminated list of option descriptions. Ensure that OptionsList[x].StringToken
has been filled in since this routine will not generate StringToken values.
Arguments:
QuestionId - Question ID of the one-of box
DataWidth - DataWidth of the one-of box
PromptToken - Prompt string token of the one-of box
HelpToken - Help string token of the one-of box
OptionsList - Each string in it is an option of the one-of box
OptionCount - Option string count
FormBuffer - Output of One-Of box as a form
Returns:
EFI_SUCCESS - One-Of box created to be a form
EFI_DEVICE_ERROR - DataWidth > 2
--*/
{
UINTN Index;
EFI_IFR_ONE_OF OneOf;
EFI_IFR_ONE_OF_OPTION OneOfOption;
EFI_IFR_END_ONE_OF EndOneOf;
UINT8 *LocalBuffer;
//
// We do not create op-code storage widths for one-of in excess of 16 bits for now
//
if (DataWidth > 2) {
return EFI_DEVICE_ERROR;
}
OneOf.Header.OpCode = EFI_IFR_ONE_OF_OP;
OneOf.Header.Length = sizeof (EFI_IFR_ONE_OF);
OneOf.QuestionId = QuestionId;
OneOf.Width = DataWidth;
OneOf.Prompt = PromptToken;
OneOf.Help = HelpToken;
LocalBuffer = (UINT8 *) FormBuffer;
CopyMem (LocalBuffer, &OneOf, sizeof (EFI_IFR_ONE_OF));
LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_ONE_OF));
for (Index = 0; Index < OptionCount; Index++) {
OneOfOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP;
OneOfOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION);
OneOfOption.Option = OptionsList[Index].StringToken;
OneOfOption.Value = OptionsList[Index].Value;
OneOfOption.Flags = OptionsList[Index].Flags;
OneOfOption.Key = OptionsList[Index].Key;
CopyMem (LocalBuffer, &OneOfOption, sizeof (EFI_IFR_ONE_OF_OPTION));
LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_ONE_OF_OPTION));
}
EndOneOf.Header.Length = sizeof (EFI_IFR_END_ONE_OF);
EndOneOf.Header.OpCode = EFI_IFR_END_ONE_OF_OP;
CopyMem (LocalBuffer, &EndOneOf, sizeof (EFI_IFR_END_ONE_OF));
LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_END_ONE_OF));
return EFI_SUCCESS;
}
EFI_STATUS
CreateOrderedListOpCode (
IN UINT16 QuestionId,
IN UINT8 MaxEntries,
IN STRING_REF PromptToken,
IN STRING_REF HelpToken,
IN IFR_OPTION *OptionsList,
IN UINTN OptionCount,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a ordered list opcode with a set of option op-codes to choose from independent of string creation.
This is used primarily by users who need to create just one particular valid op-code and the string
data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
location to pre-defined forms in HII)
OptionsList is a pointer to a null-terminated list of option descriptions. Ensure that OptionsList[x].StringToken
has been filled in since this routine will not generate StringToken values.
Arguments:
QuestionId - Question ID of the ordered list
MaxEntries - MaxEntries of the ordered list
PromptToken - Prompt string token of the ordered list
HelpToken - Help string token of the ordered list
OptionsList - Each string in it is an option of the ordered list
OptionCount - Option string count
FormBuffer - Output of ordered list as a form
Returns:
EFI_SUCCESS - Ordered list created to be a form
--*/
{
UINTN Index;
EFI_IFR_ORDERED_LIST OrderedList;
EFI_IFR_ONE_OF_OPTION OrderedListOption;
EFI_IFR_END_ONE_OF EndOrderedList;
UINT8 *LocalBuffer;
OrderedList.Header.OpCode = EFI_IFR_ORDERED_LIST_OP;
OrderedList.Header.Length = sizeof (EFI_IFR_ORDERED_LIST);
OrderedList.QuestionId = QuestionId;
OrderedList.MaxEntries = MaxEntries;
OrderedList.Prompt = PromptToken;
OrderedList.Help = HelpToken;
LocalBuffer = (UINT8 *) FormBuffer;
CopyMem (LocalBuffer, &OrderedList, sizeof (EFI_IFR_ORDERED_LIST));
LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_ORDERED_LIST));
for (Index = 0; Index < OptionCount; Index++) {
OrderedListOption.Header.OpCode = EFI_IFR_ONE_OF_OPTION_OP;
OrderedListOption.Header.Length = sizeof (EFI_IFR_ONE_OF_OPTION);
OrderedListOption.Option = OptionsList[Index].StringToken;
OrderedListOption.Value = OptionsList[Index].Value;
OrderedListOption.Flags = OptionsList[Index].Flags;
OrderedListOption.Key = OptionsList[Index].Key;
CopyMem (LocalBuffer, &OrderedListOption, sizeof (EFI_IFR_ONE_OF_OPTION));
LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_ONE_OF_OPTION));
}
EndOrderedList.Header.Length = sizeof (EFI_IFR_END_ONE_OF);
EndOrderedList.Header.OpCode = EFI_IFR_END_ONE_OF_OP;
CopyMem (LocalBuffer, &EndOrderedList, sizeof (EFI_IFR_END_ONE_OF));
LocalBuffer = (UINT8 *) (LocalBuffer + sizeof (EFI_IFR_END_ONE_OF));
return EFI_SUCCESS;
}
EFI_STATUS
CreateCheckBoxOpCode (
IN UINT16 QuestionId,
IN UINT8 DataWidth,
IN STRING_REF PromptToken,
IN STRING_REF HelpToken,
IN UINT8 Flags,
IN UINT16 Key,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a checkbox opcode independent of string creation
This is used primarily by users who need to create just one particular valid op-code and the string
data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
location to pre-defined forms in HII)
Arguments:
QuestionId - Question ID of the check box
DataWidth - DataWidth of the check box
PromptToken - Prompt string token of the check box
HelpToken - Help string token of the check box
Flags - Flags of the check box
Key - Key of the check box
FormBuffer - Output of the check box as a form
Returns:
EFI_SUCCESS - Checkbox created to be a form
EFI_DEVICE_ERROR - DataWidth > 1
--*/
{
EFI_IFR_CHECKBOX CheckBox;
//
// We do not create op-code storage widths for checkbox in excess of 8 bits for now
//
if (DataWidth > 1) {
return EFI_DEVICE_ERROR;
}
CheckBox.Header.OpCode = EFI_IFR_CHECKBOX_OP;
CheckBox.Header.Length = sizeof (EFI_IFR_CHECKBOX);
CheckBox.QuestionId = QuestionId;
CheckBox.Width = DataWidth;
CheckBox.Prompt = PromptToken;
CheckBox.Help = HelpToken;
CheckBox.Flags = Flags;
CheckBox.Key = Key;
CopyMem (FormBuffer, &CheckBox, sizeof (EFI_IFR_CHECKBOX));
return EFI_SUCCESS;
}
EFI_STATUS
CreateNumericOpCode (
IN UINT16 QuestionId,
IN UINT8 DataWidth,
IN STRING_REF PromptToken,
IN STRING_REF HelpToken,
IN UINT16 Minimum,
IN UINT16 Maximum,
IN UINT16 Step,
IN UINT16 Default,
IN UINT8 Flags,
IN UINT16 Key,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a numeric opcode independent of string creation
This is used primarily by users who need to create just one particular valid op-code and the string
data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
location to pre-defined forms in HII)
Arguments:
QuestionId - Question ID of the numeric
DataWidth - DataWidth of the numeric
PromptToken - Prompt string token of the numeric
HelpToken - Help string token of the numeric
Minimum - Minumun boundary of the numeric
Maximum - Maximum boundary of the numeric
Step - Step of the numeric
Default - Default value of the numeric
Flags - Flags of the numeric
Key - Key of the numeric
FormBuffer - Output of the numeric as a form
Returns:
EFI_SUCCESS - The numeric created to be a form.
EFI_DEVICE_ERROR - DataWidth > 2
--*/
{
EFI_IFR_NUMERIC Numeric;
//
// We do not create op-code storage widths for numerics in excess of 16 bits for now
//
if (DataWidth > 2) {
return EFI_DEVICE_ERROR;
}
Numeric.Header.OpCode = EFI_IFR_NUMERIC_OP;
Numeric.Header.Length = sizeof (EFI_IFR_NUMERIC);
Numeric.QuestionId = QuestionId;
Numeric.Width = DataWidth;
Numeric.Prompt = PromptToken;
Numeric.Help = HelpToken;
Numeric.Minimum = Minimum;
Numeric.Maximum = Maximum;
Numeric.Step = Step;
Numeric.Default = Default;
Numeric.Flags = Flags;
Numeric.Key = Key;
CopyMem (FormBuffer, &Numeric, sizeof (EFI_IFR_NUMERIC));
return EFI_SUCCESS;
}
EFI_STATUS
CreateStringOpCode (
IN UINT16 QuestionId,
IN UINT8 DataWidth,
IN STRING_REF PromptToken,
IN STRING_REF HelpToken,
IN UINT8 MinSize,
IN UINT8 MaxSize,
IN UINT8 Flags,
IN UINT16 Key,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a numeric opcode independent of string creation
This is used primarily by users who need to create just one particular valid op-code and the string
data will be assumed to exist in the HiiDatabase already. (Useful when exporting op-codes at a label
location to pre-defined forms in HII)
Arguments:
QuestionId - Question ID of the string
DataWidth - DataWidth of the string
PromptToken - Prompt token of the string
HelpToken - Help token of the string
MinSize - Min size boundary of the string
MaxSize - Max size boundary of the string
Flags - Flags of the string
Key - Key of the string
FormBuffer - Output of the string as a form
Returns:
EFI_SUCCESS - String created to be a form.
--*/
{
EFI_IFR_STRING String;
String.Header.OpCode = EFI_IFR_STRING_OP;
String.Header.Length = sizeof (EFI_IFR_STRING);
String.QuestionId = QuestionId;
String.Width = DataWidth;
String.Prompt = PromptToken;
String.Help = HelpToken;
String.MinSize = MinSize;
String.MaxSize = MaxSize;
String.Flags = Flags;
String.Key = Key;
CopyMem (FormBuffer, &String, sizeof (EFI_IFR_STRING));
return EFI_SUCCESS;
}
EFI_STATUS
CreateBannerOpCode (
IN UINT16 Title,
IN UINT16 LineNumber,
IN UINT8 Alignment,
IN OUT VOID *FormBuffer
)
/*++
Routine Description:
Create a banner opcode. This is primarily used by the FrontPage implementation from BDS.
Arguments:
Title - Title of the banner
LineNumber - LineNumber of the banner
Alignment - Alignment of the banner
FormBuffer - Output of banner as a form
Returns:
EFI_SUCCESS - Banner created to be a form.
--*/
{
EFI_IFR_BANNER Banner;
Banner.Header.OpCode = EFI_IFR_BANNER_OP;
Banner.Header.Length = sizeof (EFI_IFR_BANNER);
CopyMem (&Banner.Title, &Title, sizeof (UINT16));
CopyMem (&Banner.LineNumber, &LineNumber, sizeof (UINT16));
Banner.Alignment = Alignment;
CopyMem (FormBuffer, &Banner, sizeof (EFI_IFR_BANNER));
return EFI_SUCCESS;
}

View File

@ -0,0 +1,104 @@
#/** @file
# EDK Internal Form Refresentation Support Library Instance.
#
# The library instance provides common library routines help in
# IFR creation on-the-fly, HII variable access, HII database access, multi language supports.
# Copyright (c) 2006 - 2007, 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
# http://opensource.org/licenses/bsd-license.php
# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
#
#
#**/
################################################################################
#
# Defines Section - statements that will be processed to create a Makefile.
#
################################################################################
[Defines]
INF_VERSION = 0x00010005
BASE_NAME = FrameworkIfrSupportLib
FILE_GUID = ea55bada-d488-427b-9d2d-227e0aaa3707
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
LIBRARY_CLASS = FrameworkIfrSupportLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER
EDK_RELEASE_VERSION = 0x00020000
EFI_SPECIFICATION_VERSION = 0x00020000
CONSTRUCTOR = IfrLibConstruct
#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 IPF EBC
#
# Variable Guid C Name: gLanGuid Variable Name: L"Lan"
#
################################################################################
#
# Sources Section - list of files that are required for the build to succeed.
#
################################################################################
[Sources.common]
IfrVariable.c
IfrOpCodeCreation.c
IfrOnTheFly.c
IfrCommon.c
CommonHeader.h
################################################################################
#
# Package Dependency Section - list of Package files that are required for
# this module.
#
################################################################################
[Packages]
MdePkg/MdePkg.dec
IntelFrameworkPkg/IntelFrameworkPkg.dec
################################################################################
#
# Library Class Section - list of Library Classes that are required for
# this module.
#
################################################################################
[LibraryClasses]
UefiRuntimeServicesTableLib
UefiBootServicesTableLib
MemoryAllocationLib
BaseMemoryLib
BaseLib
DebugLib
################################################################################
#
# Guid C Name Section - list of Guids that this module uses or produces.
#
################################################################################
[Guids]
gEfiGlobalVariableGuid # ALWAYS_CONSUMED
################################################################################
#
# Protocol C Name Section - list of Protocol and Protocol Notify C Names
# that this module uses or produces.
#
################################################################################
[Protocols]
gEfiHiiProtocolGuid # PROTOCOL ALWAYS_CONSUMED

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<ModuleSurfaceArea xmlns="http://www.TianoCore.org/2006/Edk2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<MsaHeader>
<ModuleName>EdkIfrSupportLib</ModuleName>
<ModuleType>DXE_DRIVER</ModuleType>
<GuidValue>ea55bada-d488-427b-9d2d-227e0aaa3707</GuidValue>
<Version>1.0</Version>
<Abstract>EDK Internal Form Refresentation Support Library Instance.</Abstract>
<Description>The library instance provides common library routines help in
IFR creation on-the-fly, HII variable access, HII database access, multi language supports.</Description>
<Copyright>Copyright (c) 2006 - 2007, Intel Corporation.</Copyright>
<License>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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.</License>
<Specification>FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052</Specification>
</MsaHeader>
<ModuleDefinitions>
<SupportedArchitectures>IA32 X64 IPF EBC</SupportedArchitectures>
<BinaryModule>false</BinaryModule>
<OutputFileBasename>EdkIfrSupportLib</OutputFileBasename>
</ModuleDefinitions>
<LibraryClassDefinitions>
<LibraryClass Usage="ALWAYS_PRODUCED" SupModuleList="DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER">
<Keyword>EdkIfrSupportLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>DebugLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>BaseLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>BaseMemoryLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>MemoryAllocationLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiBootServicesTableLib</Keyword>
</LibraryClass>
<LibraryClass Usage="ALWAYS_CONSUMED">
<Keyword>UefiRuntimeServicesTableLib</Keyword>
</LibraryClass>
</LibraryClassDefinitions>
<SourceFiles>
<Filename>IfrCommon.c</Filename>
<Filename>IfrOnTheFly.c</Filename>
<Filename>IfrOpCodeCreation.c</Filename>
<Filename>IfrVariable.c</Filename>
</SourceFiles>
<PackageDependencies>
<Package PackageGuid="5e0e9358-46b6-4ae2-8218-4ab8b9bbdcec"/>
<Package PackageGuid="68169ab0-d41b-4009-9060-292c253ac43d"/>
</PackageDependencies>
<Protocols>
<Protocol Usage="ALWAYS_CONSUMED">
<ProtocolCName>gEfiHiiProtocolGuid</ProtocolCName>
</Protocol>
</Protocols>
<Variables>
<Variable Usage="ALWAYS_CONSUMED">
<VariableName>0x004C 0x0061 0x006E</VariableName>
<GuidC_Name>gLanGuid</GuidC_Name>
</Variable>
</Variables>
<Guids>
<GuidCNames Usage="ALWAYS_CONSUMED">
<GuidCName>gEfiGlobalVariableGuid</GuidCName>
</GuidCNames>
</Guids>
<Externs>
<Specification>EFI_SPECIFICATION_VERSION 0x00020000</Specification>
<Specification>EDK_RELEASE_VERSION 0x00020000</Specification>
<Extern>
<Constructor>IfrLibConstruct</Constructor>
</Extern>
</Externs>
</ModuleSurfaceArea>

View File

@ -0,0 +1,493 @@
/*++
Copyright (c) 2006, 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
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
IfrVariable.c
Abstract:
Variable/Map manipulations routines
--*/
//
// Include common header file for this module.
//
#include "CommonHeader.h"
VOID
EfiLibHiiVariablePackGetMap (
IN EFI_HII_VARIABLE_PACK *Pack,
OUT CHAR16 **Name, OPTIONAL
OUT EFI_GUID **Guid, OPTIONAL
OUT UINT16 *Id, OPTIONAL
OUT VOID **Var, OPTIONAL
OUT UINTN *Size OPTIONAL
)
/*++
Routine Description:
Extracts a variable form a Pack.
Arguments:
Pack - List of variables
Name - Name of the variable/map
Guid - GUID of the variable/map
Var - Pointer to the variable/map
Size - Size of the variable/map in bytes
Returns:
VOID
--*/
{
if (NULL != Name) {
*Name = (VOID *) (Pack + 1);
}
if (NULL != Guid) {
*Guid = (EFI_GUID *)(UINTN)&Pack->VariableGuid;
}
if (NULL != Id) {
*Id = Pack->VariableId;
}
if (NULL != Var) {
*Var = (VOID *) ((CHAR8 *) (Pack + 1) + Pack->VariableNameLength);
}
if (NULL != Size) {
*Size = Pack->Header.Length - sizeof (*Pack) - Pack->VariableNameLength;
}
}
UINTN
EfiLibHiiVariablePackListGetMapCnt (
IN EFI_HII_VARIABLE_PACK_LIST *List
)
/*++
Routine Description:
Finds a count of the variables/maps in the List.
Arguments:
List - List of variables
Returns:
UINTN - The number of map count.
--*/
{
UINTN Cnt = 0;
while (NULL != List) {
Cnt++;
List = List->NextVariablePack;
}
return Cnt;
}
VOID
EfiLibHiiVariablePackListForEachVar (
IN EFI_HII_VARIABLE_PACK_LIST *List,
IN EFI_LIB_HII_VARIABLE_PACK_LIST_CALLBACK *Callback
)
/*++
Routine Description:
Will iterate all variable/maps as appearing
in List and for each, it will call the Callback.
Arguments:
List - List of variables
Callback - Routine to be called for each iterated variable.
Returns:
VOID
--*/
{
CHAR16 *MapName;
EFI_GUID *MapGuid;
UINT16 MapId;
VOID *Map;
UINTN MapSize;
while (NULL != List) {
EfiLibHiiVariablePackGetMap (List->VariablePack, &MapName, &MapGuid, &MapId, &Map, &MapSize);
//
// call the callback
//
Callback (MapName, MapGuid, MapId, Map, MapSize);
List = List->NextVariablePack;
}
}
EFI_STATUS
EfiLibHiiVariablePackListGetMapByIdx (
IN UINTN Idx,
IN EFI_HII_VARIABLE_PACK_LIST *List,
OUT CHAR16 **Name, OPTIONAL
OUT EFI_GUID **Guid, OPTIONAL
OUT UINT16 *Id, OPTIONAL
OUT VOID **Var,
OUT UINTN *Size
)
/*++
Routine Description:
Finds a variable form List given
the order number as appears in the List.
Arguments:
Idx - The index of the variable/map to retrieve
List - List of variables
Name - Name of the variable/map
Guid - GUID of the variable/map
Var - Pointer to the variable/map
Size - Size of the variable/map in bytes
Returns:
EFI_SUCCESS - Variable is found, OUT parameters are valid
EFI_NOT_FOUND - Variable is not found, OUT parameters are not valid
--*/
{
CHAR16 *MapName;
EFI_GUID *MapGuid;
UINT16 MapId;
VOID *Map;
UINTN MapSize;
while (NULL != List) {
EfiLibHiiVariablePackGetMap (List->VariablePack, &MapName, &MapGuid, &MapId, &Map, &MapSize);
if (0 == Idx--) {
*Var = Map;
*Size = MapSize;
if (NULL != Name) {
*Name = MapName;
}
if (NULL != Guid) {
*Guid = MapGuid;
}
if (NULL != Id) {
*Id = MapId;
}
return EFI_SUCCESS; // Map found
}
List = List->NextVariablePack;
}
//
// If here, the map is not found
//
return EFI_NOT_FOUND;
}
EFI_STATUS
EfiLibHiiVariablePackListGetMapById (
IN UINT16 Id,
IN EFI_HII_VARIABLE_PACK_LIST *List,
OUT CHAR16 **Name, OPTIONAL
OUT EFI_GUID **Guid, OPTIONAL
OUT VOID **Var,
OUT UINTN *Size
)
/*++
Routine Description:
Finds a variable form List given the
order number as appears in the List.
Arguments:
Id - The ID of the variable/map to retrieve
List - List of variables
Name - Name of the variable/map
Guid - GUID of the variable/map
Var - Pointer to the variable/map
Size - Size of the variable/map in bytes
Returns:
EFI_SUCCESS - Variable is found, OUT parameters are valid
EFI_NOT_FOUND - Variable is not found, OUT parameters are not valid
--*/
{
CHAR16 *MapName;
EFI_GUID *MapGuid;
UINT16 MapId;
VOID *Map;
UINTN MapSize;
while (NULL != List) {
EfiLibHiiVariablePackGetMap (List->VariablePack, &MapName, &MapGuid, &MapId, &Map, &MapSize);
if (MapId == Id) {
*Var = Map;
*Size = MapSize;
if (NULL != Name) {
*Name = MapName;
}
if (NULL != Guid) {
*Guid = MapGuid;
}
//
// Map found
//
return EFI_SUCCESS;
}
List = List->NextVariablePack;
}
//
// If here, the map is not found
//
return EFI_NOT_FOUND;
}
EFI_STATUS
EfiLibHiiVariablePackListGetMap (
IN EFI_HII_VARIABLE_PACK_LIST *List,
IN CHAR16 *Name,
IN EFI_GUID *Guid,
OUT UINT16 *Id,
OUT VOID **Var,
OUT UINTN *Size
)
/*++
Routine Description:
Finds a variable form EFI_HII_VARIABLE_PACK_LIST given name and GUID.
Arguments:
List - List of variables
Name - Name of the variable/map to be found
Guid - GUID of the variable/map to be found
Var - Pointer to the variable/map found
Size - Size of the variable/map in bytes found
Returns:
EFI_SUCCESS - variable is found, OUT parameters are valid
EFI_NOT_FOUND - variable is not found, OUT parameters are not valid
--*/
{
VOID *Map;
UINTN MapSize;
UINT16 MapId;
CHAR16 *MapName;
EFI_GUID *MapGuid;
while (NULL != List) {
EfiLibHiiVariablePackGetMap (List->VariablePack, &MapName, &MapGuid, &MapId, &Map, &MapSize);
if ((0 == StrCmp (Name, MapName)) && CompareGuid (Guid, MapGuid)) {
*Id = MapId;
*Var = Map;
*Size = MapSize;
return EFI_SUCCESS;
}
List = List->NextVariablePack;
}
//
// If here, the map is not found
//
return EFI_NOT_FOUND;
}
EFI_STATUS
EfiLibHiiVariableRetrieveFromNv (
IN CHAR16 *Name,
IN EFI_GUID *Guid,
IN UINTN Size,
OUT VOID **Var
)
/*++
Routine Description:
Finds out if a variable of specific Name/Guid/Size exists in NV.
If it does, it will retrieve it into the Var.
Arguments:
Name, Guid, Size - Parameters of the variable to retrieve. Must match exactly.
Var - Variable will be retrieved into buffer pointed by this pointer.
If pointing to NULL, the buffer will be allocated. Caller is responsible for releasing the buffer.
Returns:
EFI_SUCCESS - The variable of exact Name/Guid/Size parameters was retrieved and written to Var.
EFI_NOT_FOUND - The variable of this Name/Guid was not found in the NV.
EFI_LOAD_ERROR - The variable in the NV was of different size, or NV API returned error.
--*/
{
EFI_STATUS Status;
UINTN SizeNv;
//
// Test for existence of the variable.
//
SizeNv = 0;
Status = gRT->GetVariable (Name, Guid, NULL, &SizeNv, NULL);
if (EFI_BUFFER_TOO_SMALL != Status) {
ASSERT (EFI_SUCCESS != Status);
return EFI_NOT_FOUND;
}
if (SizeNv != Size) {
//
// The variable is considered corrupt, as it has different size from expected.
//
return EFI_LOAD_ERROR;
}
if (NULL == *Var) {
*Var = AllocatePool (Size);
ASSERT (NULL != *Var);
}
SizeNv = Size;
//
// Final read into the Var
//
Status = gRT->GetVariable (Name, Guid, NULL, &SizeNv, *Var);
//
// No tolerance for random failures. Such behavior is undetermined and not validated.
//
ASSERT_EFI_ERROR (Status);
ASSERT (SizeNv == Size);
return EFI_SUCCESS;
}
EFI_STATUS
EfiLibHiiVariableOverrideIfSuffix (
IN CHAR16 *Suffix,
IN CHAR16 *Name,
IN EFI_GUID *Guid,
IN UINTN Size,
OUT VOID *Var
)
/*++
Routine Description:
Overrrides the variable with NV data if found.
But it only does it if the Name ends with specified Suffix.
For example, if Suffix="MyOverride" and the Name="XyzSetupMyOverride",
the Suffix matches the end of Name, so the variable will be loaded from NV
provided the variable exists and the GUID and Size matches.
Arguments:
Suffix - Suffix the Name should end with.
Name, Guid, Size - Parameters of the variable to retrieve. Must match exactly.
Var - Variable will be retrieved into this buffer.
Caller is responsible for providing storage of exactly Size size in bytes.
Returns:
EFI_SUCCESS - The variable was overriden with NV variable of same Name/Guid/Size.
EFI_INVALID_PARAMETER - The name of the variable does not end with <Suffix>.
EFI_NOT_FOUND - The variable of this Name/Guid was not found in the NV.
EFI_LOAD_ERROR - The variable in the NV was of different size, or NV API returned error.
--*/
{
UINTN StrLength;
UINTN StrLenSuffix;
StrLength = StrLen (Name);
StrLenSuffix = StrLen (Suffix);
if ((StrLength <= StrLenSuffix) || (0 != StrCmp (Suffix, &Name[StrLength - StrLenSuffix]))) {
//
// Not ending with <Suffix>.
//
return EFI_INVALID_PARAMETER;
}
return EfiLibHiiVariableRetrieveFromNv (Name, Guid, Size, &Var);
}
EFI_STATUS
EfiLibHiiVariableOverrideBySuffix (
IN CHAR16 *Suffix,
IN CHAR16 *Name,
IN EFI_GUID *Guid,
IN UINTN Size,
OUT VOID *Var
)
/*++
Routine Description:
Overrrides the variable with NV data if found.
But it only does it if the NV contains the same variable with Name is appended with Suffix.
For example, if Suffix="MyOverride" and the Name="XyzSetup",
the Suffix will be appended to the end of Name, and the variable with Name="XyzSetupMyOverride"
will be loaded from NV provided the variable exists and the GUID and Size matches.
Arguments:
Suffix - Suffix the variable will be appended with.
Name, Guid, Size - Parameters of the variable to retrieve. Must match exactly.
Var - Variable will be retrieved into this buffer.
Caller is responsible for providing storage of exactly Size size in bytes.
Returns:
EFI_SUCCESS - The variable was overriden with NV variable of same Name/Guid/Size.
EFI_NOT_FOUND - The variable of this Name/Guid was not found in the NV.
EFI_LOAD_ERROR - The variable in the NV was of different size, or NV API returned error.
--*/
{
EFI_STATUS Status;
CHAR16 *NameSuffixed;
UINTN NameLength;
UINTN SuffixLength;
//
// enough to concatenate both strings.
//
NameLength = StrLen (Name);
SuffixLength = StrLen (Suffix);
NameSuffixed = AllocateZeroPool ((NameLength + SuffixLength + 1) * sizeof (CHAR16));
StrCpy (NameSuffixed, Name);
StrCat (NameSuffixed, Suffix);
Status = EfiLibHiiVariableRetrieveFromNv (NameSuffixed, Guid, Size, &Var);
gBS->FreePool (NameSuffixed);
return Status;
}