OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
OcVariableRuntimeLib.c File Reference
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/OcFileLib.h>
#include <Library/OcSerializeLib.h>
#include <Library/OcVariableLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Protocol/OcVariableRuntime.h>

Go to the source code of this file.

Data Structures

struct  NVRAM_SAVE_CONTEXT
 

Macros

#define BASE64_CHUNK_SIZE   (52)
 
#define NVRAM_PLIST_MAX_SIZE   (BASE_1MB)
 
#define OC_NVRAM_STORAGE_VERSION   1
 
#define OC_NVRAM_STORAGE_MAP_FIELDS(_, __)
 
#define OC_NVRAM_STORAGE_FIELDS(_, __)
 

Functions

STATIC EFI_STATUS LocateNvramDir (OUT EFI_FILE_PROTOCOL **NvramDir)
 
STATIC EFI_STATUS EFIAPI LoadNvram (IN OC_STORAGE_CONTEXT *StorageContext, IN OC_NVRAM_LEGACY_MAP *LegacyMap, IN BOOLEAN LegacyOverwrite)
 
STATIC EFI_STATUS DeleteFile (IN EFI_FILE_PROTOCOL *Directory, IN CONST CHAR16 *FileName)
 
STATIC OC_PROCESS_VARIABLE_RESULT EFIAPI SerializeSectionVariables (IN EFI_GUID *Guid, IN CHAR16 *Name, IN VOID *Context)
 
STATIC EFI_STATUS EFIAPI SaveNvram (VOID)
 
STATIC EFI_STATUS EFIAPI ResetNvram (VOID)
 
STATIC EFI_STATUS EFIAPI SwitchToFallback (VOID)
 
EFI_STATUS EFIAPI OcVariableRuntimeLibConstructor (IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
 

Variables

STATIC OC_SCHEMA mNvramStorageEntrySchema = OC_SCHEMA_MDATA (NULL)
 
STATIC OC_SCHEMA mNvramStorageAddSchema = OC_SCHEMA_MAP (NULL, &mNvramStorageEntrySchema)
 
STATIC OC_SCHEMA mNvramStorageNodesSchema []
 
STATIC OC_SCHEMA_INFO mNvramStorageRootSchema
 
STATIC OC_STORAGE_CONTEXTmStorageContext = NULL
 
STATIC OC_NVRAM_LEGACY_MAP * mLegacyMap = NULL
 
STATIC OC_VARIABLE_RUNTIME_PROTOCOL mOcVariableRuntimeProtocol
 

Detailed Description

Save, load and delete emulated NVRAM from file storage.

Copyright (c) 2019-2022, vit9696, mikebeaton. All rights reserved.
SPDX-License-Identifier: BSD-3-Clause

Definition in file OcVariableRuntimeLib.c.

Macro Definition Documentation

◆ BASE64_CHUNK_SIZE

#define BASE64_CHUNK_SIZE   (52)

Definition at line 19 of file OcVariableRuntimeLib.c.

◆ NVRAM_PLIST_MAX_SIZE

#define NVRAM_PLIST_MAX_SIZE   (BASE_1MB)

Definition at line 20 of file OcVariableRuntimeLib.c.

◆ OC_NVRAM_STORAGE_FIELDS

#define OC_NVRAM_STORAGE_FIELDS ( _,
__ )
Value:
_(UINT32 , Version , , 0 , () ) \
_(OC_NVRAM_STORAGE_MAP , Add , , OC_CONSTR (OC_NVRAM_STORAGE_MAP, _, __) , OC_DESTR (OC_NVRAM_STORAGE_MAP))
UINT32 Version
#define OC_DESTR(A)
#define OC_CONSTR(A, _, __)

Definition at line 45 of file OcVariableRuntimeLib.c.

◆ OC_NVRAM_STORAGE_MAP_FIELDS

#define OC_NVRAM_STORAGE_MAP_FIELDS ( _,
__ )
Value:
OC_MAP (OC_STRING, OC_ASSOC, _, __)
#define OC_MAP(KeyType, Type, _, __)

Structure declaration for NVRAM file.

Definition at line 41 of file OcVariableRuntimeLib.c.

◆ OC_NVRAM_STORAGE_VERSION

#define OC_NVRAM_STORAGE_VERSION   1

Version check for NVRAM file. Not the same as protocol revision.

Definition at line 36 of file OcVariableRuntimeLib.c.

Function Documentation

◆ DeleteFile()

STATIC EFI_STATUS DeleteFile ( IN EFI_FILE_PROTOCOL * Directory,
IN CONST CHAR16 * FileName )

Definition at line 225 of file OcVariableRuntimeLib.c.

◆ LoadNvram()

STATIC EFI_STATUS EFIAPI LoadNvram ( IN OC_STORAGE_CONTEXT * StorageContext,
IN OC_NVRAM_LEGACY_MAP * LegacyMap,
IN BOOLEAN LegacyOverwrite )

< Was NvramConfig->WriteFlash ? OPEN_CORE_NVRAM_NV_ATTR : OPEN_CORE_NVRAM_ATTR

Definition at line 121 of file OcVariableRuntimeLib.c.

◆ LocateNvramDir()

STATIC EFI_STATUS LocateNvramDir ( OUT EFI_FILE_PROTOCOL ** NvramDir)

Definition at line 87 of file OcVariableRuntimeLib.c.

◆ OcVariableRuntimeLibConstructor()

EFI_STATUS EFIAPI OcVariableRuntimeLibConstructor ( IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE * SystemTable )

Definition at line 621 of file OcVariableRuntimeLib.c.

◆ ResetNvram()

STATIC EFI_STATUS EFIAPI ResetNvram ( VOID )

Definition at line 539 of file OcVariableRuntimeLib.c.

◆ SaveNvram()

STATIC EFI_STATUS EFIAPI SaveNvram ( VOID )

Definition at line 395 of file OcVariableRuntimeLib.c.

◆ SerializeSectionVariables()

STATIC OC_PROCESS_VARIABLE_RESULT EFIAPI SerializeSectionVariables ( IN EFI_GUID * Guid,
IN CHAR16 * Name,
IN VOID * Context )

Definition at line 248 of file OcVariableRuntimeLib.c.

◆ SwitchToFallback()

STATIC EFI_STATUS EFIAPI SwitchToFallback ( VOID )

Definition at line 569 of file OcVariableRuntimeLib.c.

Variable Documentation

◆ mLegacyMap

STATIC OC_NVRAM_LEGACY_MAP* mLegacyMap = NULL

Definition at line 83 of file OcVariableRuntimeLib.c.

◆ mNvramStorageAddSchema

STATIC OC_SCHEMA mNvramStorageAddSchema = OC_SCHEMA_MAP (NULL, &mNvramStorageEntrySchema)

Definition at line 62 of file OcVariableRuntimeLib.c.

◆ mNvramStorageEntrySchema

STATIC OC_SCHEMA mNvramStorageEntrySchema = OC_SCHEMA_MDATA (NULL)

Schema definition for NVRAM file.

Definition at line 58 of file OcVariableRuntimeLib.c.

◆ mNvramStorageNodesSchema

STATIC OC_SCHEMA mNvramStorageNodesSchema[]
Initial value:
= {
OC_SCHEMA_MAP_IN ("Add", OC_NVRAM_STORAGE, Add, &mNvramStorageAddSchema),
OC_SCHEMA_INTEGER_IN ("Version", OC_NVRAM_STORAGE, Version),
}
#define OC_SCHEMA_MAP_IN(Name, Type, Field, ChildSchema)
#define OC_SCHEMA_INTEGER_IN(Name, Type, Field)
STATIC OC_SCHEMA mNvramStorageAddSchema

Definition at line 66 of file OcVariableRuntimeLib.c.

◆ mNvramStorageRootSchema

STATIC OC_SCHEMA_INFO mNvramStorageRootSchema
Initial value:
= {
}
#define ARRAY_SIZE(Array)
Definition AppleMacEfi.h:34
STATIC OC_SCHEMA mNvramStorageNodesSchema[]

Definition at line 73 of file OcVariableRuntimeLib.c.

◆ mOcVariableRuntimeProtocol

STATIC OC_VARIABLE_RUNTIME_PROTOCOL mOcVariableRuntimeProtocol
Initial value:
= {
}
#define OC_VARIABLE_RUNTIME_PROTOCOL_REVISION
STATIC EFI_STATUS EFIAPI LoadNvram(IN OC_STORAGE_CONTEXT *StorageContext, IN OC_NVRAM_LEGACY_MAP *LegacyMap, IN BOOLEAN LegacyOverwrite)
STATIC EFI_STATUS EFIAPI SwitchToFallback(VOID)
STATIC EFI_STATUS EFIAPI ResetNvram(VOID)
STATIC EFI_STATUS EFIAPI SaveNvram(VOID)

Definition at line 611 of file OcVariableRuntimeLib.c.

◆ mStorageContext

STATIC OC_STORAGE_CONTEXT* mStorageContext = NULL

Definition at line 79 of file OcVariableRuntimeLib.c.