Skip to content

Cfr ng #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: dasharo
Choose a base branch
from
6 changes: 3 additions & 3 deletions DasharoModulePkg/DasharoBootPolicies/BootPolicies.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ InitializeBootPolicies (

{
EFI_STATUS Status = EFI_SUCCESS;
BOOLEAN *EfiVar;
UINTN VarSize = sizeof(BOOLEAN);
BOOLEAN FUMEnabled;
UINT32 *EfiVar;
UINTN VarSize = sizeof(UINT32);
UINT32 FUMEnabled;

gBS = SystemTable->BootServices;
gRT = SystemTable->RuntimeServices;
Expand Down
2 changes: 1 addition & 1 deletion DasharoModulePkg/DasharoModulePkg.dec
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
PlatformPasswordLib|Include/Library/PlatformPasswordLib.h

[Guids]
gDasharoSystemFeaturesGuid = { 0xd15b327e, 0xff2d, 0x4fc1, { 0xab, 0xf6, 0xc1, 0x2b, 0xd0, 0x8c, 0x13, 0x59 }}
gDasharoSystemFeaturesGuid = { 0xceae4c1d, 0x335b, 0x4685, { 0xa4, 0xa0, 0xfc, 0x4a, 0x94, 0xee, 0xa0, 0x85 } }
gDasharoSystemFeaturesTokenSpaceGuid = {0xc7d52e10, 0xadec, 0x4d49, { 0x9e, 0xc5, 0xb8, 0xcf, 0xcd, 0x4b, 0x9d, 0xb9 }}
gUserAuthFeaturePkgTokenSpaceGuid = {0xa2793a6e, 0x6af1, 0x45c4, {0x88, 0x4d, 0x3d, 0x0c, 0x7a, 0xfe, 0x91, 0xc6}}
## Include Include/Guid/UserAuthentication.h
Expand Down
18 changes: 9 additions & 9 deletions DasharoModulePkg/Include/DasharoOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,25 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#define DASHARO_VAR_FAN_CURVE_OPTION L"FanCurveOption"
#define DASHARO_VAR_FIRMWARE_UPDATE_MODE L"FirmwareUpdateMode"
#define DASHARO_VAR_IOMMU_CONFIG L"IommuConfig"
#define DASHARO_VAR_LOCK_BIOS L"LockBios"
#define DASHARO_VAR_LOCK_BIOS L"lock_bios"
#define DASHARO_VAR_MEMORY_PROFILE L"MemoryProfile"
#define DASHARO_VAR_ME_MODE L"MeMode"
#define DASHARO_VAR_NETWORK_BOOT L"NetworkBoot"
#define DASHARO_VAR_ME_MODE L"me_mode"
#define DASHARO_VAR_NETWORK_BOOT L"network_boot"
#define DASHARO_VAR_OPTION_ROM_POLICY L"OptionRomPolicy"
#define DASHARO_VAR_POWER_FAILURE_STATE L"PowerFailureState"
#define DASHARO_VAR_PS2_CONTROLLER L"Ps2Controller"
#define DASHARO_VAR_PS2_CONTROLLER L"ps2_enable"
#define DASHARO_VAR_RESIZEABLE_BARS_ENABLED L"PCIeResizeableBarsEnabled"
#define DASHARO_VAR_SERIAL_REDIRECTION L"SerialRedirection"
#define DASHARO_VAR_SERIAL_REDIRECTION L"com0_redirection"
#define DASHARO_VAR_SERIAL_REDIRECTION2 L"SerialRedirection2"
#define DASHARO_VAR_SLEEP_TYPE L"SleepType"
#define DASHARO_VAR_SMM_BWP L"SmmBwp"
#define DASHARO_VAR_USB_MASS_STORAGE L"UsbMassStorage"
#define DASHARO_VAR_USB_STACK L"UsbDriverStack"
#define DASHARO_VAR_USB_MASS_STORAGE L"uefi_usb_msc"
#define DASHARO_VAR_USB_STACK L"uefi_usb_stack"
#define DASHARO_VAR_WATCHDOG L"WatchdogConfig"
#define DASHARO_VAR_WATCHDOG_AVAILABLE L"WatchdogAvailable"
#define DASHARO_VAR_SMALL_CORE_ACTIVE_COUNT L"SmallCoreActiveCount"
#define DASHARO_VAR_CORE_ACTIVE_COUNT L"CoreActiveCount"
#define DASHARO_VAR_HYPER_THREADING L"HyperThreading"
#define DASHARO_VAR_HYPER_THREADING L"hyper_threading"
#define DASHARO_VAR_USB_PORT_POWER L"UsbPortPower"
#define DASHARO_VAR_DGPU_ENABLED L"DGPUEnabled"

Expand Down Expand Up @@ -116,7 +116,7 @@ typedef struct {

// Set of possible values of Dasharo variables.
typedef union {
BOOLEAN Boolean;
UINT32 Boolean;
UINT8 Uint8;

DASHARO_WATCHDOG_CONFIG Watchdog;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SPDX-License-Identifier: BSD-2-Clause
#include <DasharoOptions.h>

#define DASHARO_SYSTEM_FEATURES_GUID \
{ 0xd15b327e, 0xff2d, 0x4fc1, {0xab, 0xf6, 0xc1, 0x2b, 0xd0, 0x8c, 0x13, 0x59} }
{ 0xceae4c1d, 0x335b, 0x4685, { 0xa4, 0xa0, 0xfc, 0x4a, 0x94, 0xee, 0xa0, 0x85 } }

#define DASHARO_SYSTEM_FEATURES_FORM_ID 0x1000
#define DASHARO_SECURITY_OPTIONS_FORM_ID 0x1001
Expand Down
8 changes: 8 additions & 0 deletions DasharoPayloadPkg/BlSupportPei/BlSupportPei.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,14 @@ BlPeiEntryPoint (
DEBUG ((DEBUG_ERROR, "Error when parsing timestamp info, Status = %r\n", Status));
}

//
// Parse the misc info provided by bootloader
//
Status = ParseMiscInfo ();
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "Error when parsing misc info, Status = %r\n", Status));
}

//
// Parse platform specific information.
//
Expand Down
60 changes: 60 additions & 0 deletions DasharoPayloadPkg/CfrSetupMenuDxe/CfrSetupMenuDxe.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
## @file
# Implementation of a CFR consumer as a HII setup menu.
#
# Copyright (c) 2023, 9elements GmbH.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = CfrSetupMenuDxe
FILE_GUID = F93C9BC1-D179-49B2-B5C0-94C15862A28D
MODULE_TYPE = DXE_DRIVER
VERSION_STRING = 1.0
ENTRY_POINT = CfrSetupMenuEntryPoint
UNLOAD_IMAGE = CfrSetupMenuUnload

[Sources]
SetupMenu.c
SetupMenuCfr.c
SetupMenuHii.c
SetupMenuVfr.Vfr
SetupMenuStrings.uni

[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
DasharoPayloadPkg/DasharoPayloadPkg.dec

[LibraryClasses]
BaseLib
BaseMemoryLib
CfrHelpersLib
DebugLib
DevicePathLib
HiiLib
HobLib
MemoryAllocationLib
VariablePolicyHelperLib
UefiHiiServicesLib
UefiLib
UefiBootServicesTableLib
UefiRuntimeServicesTableLib
UefiDriverEntryPoint

[Guids]
gEfiCfrSetupMenuFormGuid
gEficorebootNvDataGuid
gEfiHiiPlatformSetupFormsetGuid ## CONSUMES ## GUID (Indicate the formset class guid to be displayed)
gEfiIfrTianoGuid ## CONSUMES ## GUID (Extended IFR Guid Opcode)
gEfiIfrFrontPageGuid

[Protocols]
gEfiDevicePathProtocolGuid ## PRODUCES
gEfiHiiConfigAccessProtocolGuid ## PRODUCES
gEdkiiVariablePolicyProtocolGuid ## SOMETIMES_CONSUMES

[Depex]
gEfiVariableArchProtocolGuid AND
gEfiVariableWriteArchProtocolGuid
100 changes: 100 additions & 0 deletions DasharoPayloadPkg/CfrSetupMenuDxe/SetupMenu.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/** @file
A Setup Menu for configuring boot options defined by bootloader CFR.

Copyright (c) 2023, 9elements GmbH.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#include "SetupMenu.h"
#include <Library/DebugLib.h>
#include <Library/HiiLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Guid/VariableFormat.h>

EDKII_VARIABLE_POLICY_PROTOCOL *mVariablePolicy = NULL;

/**
This function installs the HII form.

**/
EFI_STATUS
EFIAPI
CfrSetupMenuEntryPoint (
IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable
)
{
EFI_STATUS Status;

Status = gBS->LocateProtocol (&gEdkiiVariablePolicyProtocolGuid, NULL, (VOID **)&mVariablePolicy);
if (EFI_ERROR (Status)) {
DEBUG ((DEBUG_WARN, "CFR: Unable to lock variables!\n"));
}

//
// Install Device Path and Config Access protocols to driver handle
//
mSetupMenuPrivate.DriverHandle = NULL;
Status = gBS->InstallMultipleProtocolInterfaces (
&mSetupMenuPrivate.DriverHandle,
&gEfiDevicePathProtocolGuid,
&mSetupMenuHiiVendorDevicePath,
&gEfiHiiConfigAccessProtocolGuid,
&mSetupMenuPrivate.ConfigAccess,
NULL
);
ASSERT_EFI_ERROR (Status);

//
// Publish our HII data.
//
mSetupMenuPrivate.HiiHandle = HiiAddPackages (
&mSetupMenuFormsetGuid,
mSetupMenuPrivate.DriverHandle,
SetupMenuVfrBin,
CfrSetupMenuDxeStrings,
NULL
);
ASSERT (mSetupMenuPrivate.HiiHandle != NULL);

//
// Insert runtime components from bootloader's CFR table.
//
CfrCreateRuntimeComponents ();

return Status;
}

/**
This function uninstalls the HII form.

**/
EFI_STATUS
EFIAPI
CfrSetupMenuUnload (
IN EFI_HANDLE ImageHandle
)
{
EFI_STATUS Status;

//
// Uninstall Device Path and Config Access protocols
//
Status = gBS->UninstallMultipleProtocolInterfaces (
mSetupMenuPrivate.DriverHandle,
&gEfiDevicePathProtocolGuid,
&mSetupMenuHiiVendorDevicePath,
&gEfiHiiConfigAccessProtocolGuid,
&mSetupMenuPrivate.ConfigAccess,
NULL
);
ASSERT_EFI_ERROR (Status);

//
// Remove our HII data
//
HiiRemovePackages (mSetupMenuPrivate.HiiHandle);

return Status;
}
141 changes: 141 additions & 0 deletions DasharoPayloadPkg/CfrSetupMenuDxe/SetupMenu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/** @file
A Setup Menu for configuring boot options defined by bootloader CFR.

Copyright (c) 2023, 9elements GmbH.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent

**/

#ifndef _SETUP_MENU_H_
#define _SETUP_MENU_H_

#include <PiDxe.h>
#include <Protocol/DevicePath.h>
#include <Protocol/HiiConfigAccess.h>
#include <Protocol/VariablePolicy.h>
#include <Guid/MdeModuleHii.h>
#include "SetupMenuNVDataStruc.h"

extern EDKII_VARIABLE_POLICY_PROTOCOL *mVariablePolicy;

extern UINT8 SetupMenuVfrBin[];

#define SETUP_MENU_CALLBACK_DATA_SIGNATURE SIGNATURE_32 ('D', 'M', 'C', 'B')

typedef struct {
UINTN Signature;

//
// HII relative handles
//
EFI_HII_HANDLE HiiHandle;
EFI_HANDLE DriverHandle;

//
// Produced protocols
//
EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess;
} SETUP_MENU_CALLBACK_DATA;

typedef struct {
VENDOR_DEVICE_PATH VendorDevicePath;
EFI_DEVICE_PATH_PROTOCOL End;
} HII_VENDOR_DEVICE_PATH;

extern SETUP_MENU_CALLBACK_DATA mSetupMenuPrivate;
extern EFI_GUID mSetupMenuFormsetGuid;
extern HII_VENDOR_DEVICE_PATH mSetupMenuHiiVendorDevicePath;

/**
Create runtime components by iterating CFR forms.

**/
VOID
EFIAPI
CfrCreateRuntimeComponents (
VOID
);

/**
This function allows a caller to extract the current configuration for one
or more named elements from the target driver.


@param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
@param Request A null-terminated Unicode string in <ConfigRequest> format.
@param Progress On return, points to a character in the Request string.
Points to the string's null terminator if request was successful.
Points to the most recent '&' before the first failing name/value
pair (or the beginning of the string if the failure is in the
first name/value pair) if the request was not successful.
@param Results A null-terminated Unicode string in <ConfigAltResp> format which
has all values filled in for the names in the Request string.
String to be allocated by the called function.

@retval EFI_SUCCESS The Results is filled with the requested values.
@retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
@retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
@retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.

**/
EFI_STATUS
EFIAPI
SetupMenuExtractConfig (
IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
IN CONST EFI_STRING Request,
OUT EFI_STRING *Progress,
OUT EFI_STRING *Results
);

/**
This function processes the results of changes in configuration.


@param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
@param Configuration A null-terminated Unicode string in <ConfigResp> format.
@param Progress A pointer to a string filled in with the offset of the most
recent '&' before the first failing name/value pair (or the
beginning of the string if the failure is in the first
name/value pair) or the terminating NULL if all was successful.

@retval EFI_SUCCESS The Results is processed successfully.
@retval EFI_INVALID_PARAMETER Configuration is NULL.
@retval EFI_NOT_FOUND Routing data doesn't match any storage in this driver.

**/
EFI_STATUS
EFIAPI
SetupMenuRouteConfig (
IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
IN CONST EFI_STRING Configuration,
OUT EFI_STRING *Progress
);

/**
This function is invoked if user selected a interactive opcode from Setup Menu
Formset. If user set VBIOS, the new value is saved to EFI variable.

@param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
@param Action Specifies the type of action taken by the browser.
@param QuestionId A unique value which is sent to the original exporting driver
so that it can identify the type of data to expect.
@param Type The type of value for the question.
@param Value A pointer to the data being sent to the original exporting driver.
@param ActionRequest On return, points to the action requested by the callback function.

@retval EFI_SUCCESS The callback successfully handled the action.
@retval EFI_INVALID_PARAMETER The setup browser call this function with invalid parameters.

**/
EFI_STATUS
EFIAPI
SetupMenuCallback (
IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
IN EFI_BROWSER_ACTION Action,
IN EFI_QUESTION_ID QuestionId,
IN UINT8 Type,
IN EFI_IFR_TYPE_VALUE *Value,
OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
);

#endif
Loading