2) Check the integrity of Variable header. In original implementation, if not whole header is correct, then the variable will be treat as invalid. typically, if the NameSize has been programed but the DataSize not, then the variable storage would failed to set new variable. 3) Change the Variable Header Alignment from 1 to 4 bytes on x86. It avoids the DataSize or NameSize cross two blocks. For example, in original implementation, if the NameSize crosses two block, when the FLASH manipulation is interrupted after programed HSB of NameSize and prior to program LSB of NameSize on next block, then the invalid variable header will result in the Variable Storgae broken. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4538 6f19259b-4bc3-4df7-8a09-765794883524
113 lines
2.8 KiB
C
113 lines
2.8 KiB
C
/*++
|
|
|
|
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.
|
|
|
|
Module Name:
|
|
|
|
Variable.h
|
|
|
|
Abstract:
|
|
|
|
--*/
|
|
|
|
#ifndef _VARIABLE_H
|
|
#define _VARIABLE_H
|
|
|
|
#include <PiDxe.h>
|
|
#include <Protocol/VariableWrite.h>
|
|
#include <Protocol/FaultTolerantWriteLite.h>
|
|
#include <Protocol/FirmwareVolumeBlock.h>
|
|
#include <Protocol/Variable.h>
|
|
#include <Library/PcdLib.h>
|
|
#include <Library/UefiDriverEntryPoint.h>
|
|
#include <Library/DxeServicesTableLib.h>
|
|
#include <Library/UefiRuntimeLib.h>
|
|
#include <Library/DebugLib.h>
|
|
#include <Library/BaseMemoryLib.h>
|
|
#include <Library/FvbServiceLib.h>
|
|
#include <Library/UefiBootServicesTableLib.h>
|
|
#include <Library/UefiLib.h>
|
|
#include <Library/BaseLib.h>
|
|
#include <Library/MemoryAllocationLib.h>
|
|
#include <Library/HobLib.h>
|
|
#include <Guid/VariableInfo.h>
|
|
#include <Guid/GlobalVariable.h>
|
|
#include <VariableFormat.h>
|
|
|
|
|
|
|
|
#define VARIABLE_RECLAIM_THRESHOLD (1024)
|
|
|
|
#define VARIABLE_STORE_SIZE FixedPcdGet32(PcdVariableStoreSize)
|
|
#define SCRATCH_SIZE FixedPcdGet32(PcdMaxVariableSize)
|
|
|
|
//
|
|
// Define GET_PAD_SIZE to optimize compiler
|
|
//
|
|
#if ((ALIGNMENT == 0) || (ALIGNMENT == 1))
|
|
#define GET_PAD_SIZE(a) (0)
|
|
#else
|
|
#define GET_PAD_SIZE(a) (((~a) + 1) & (ALIGNMENT - 1))
|
|
#endif
|
|
|
|
#define GET_VARIABLE_NAME_PTR(a) (CHAR16 *) ((UINTN) (a) + sizeof (VARIABLE_HEADER))
|
|
|
|
|
|
typedef struct {
|
|
VARIABLE_HEADER *CurrPtr;
|
|
VARIABLE_HEADER *EndPtr;
|
|
VARIABLE_HEADER *StartPtr;
|
|
BOOLEAN Volatile;
|
|
} VARIABLE_POINTER_TRACK;
|
|
|
|
typedef struct {
|
|
EFI_PHYSICAL_ADDRESS VolatileVariableBase;
|
|
EFI_PHYSICAL_ADDRESS NonVolatileVariableBase;
|
|
EFI_LOCK VariableServicesLock;
|
|
UINT32 ReentrantState;
|
|
} VARIABLE_GLOBAL;
|
|
|
|
typedef struct {
|
|
VARIABLE_GLOBAL VariableGlobal;
|
|
UINTN VolatileLastVariableOffset;
|
|
UINTN NonVolatileLastVariableOffset;
|
|
UINT32 FvbInstance;
|
|
} VARIABLE_MODULE_GLOBAL;
|
|
|
|
typedef struct {
|
|
EFI_GUID *Guid;
|
|
CHAR16 *Name;
|
|
UINT32 Attributes;
|
|
UINTN DataSize;
|
|
VOID *Data;
|
|
} VARIABLE_CACHE_ENTRY;
|
|
|
|
|
|
//
|
|
// Functions
|
|
//
|
|
|
|
EFI_STATUS
|
|
EFIAPI
|
|
VariableServiceInitialize (
|
|
IN EFI_HANDLE ImageHandle,
|
|
IN EFI_SYSTEM_TABLE *SystemTable
|
|
);
|
|
|
|
|
|
EFI_STATUS
|
|
FtwVariableSpace (
|
|
IN EFI_PHYSICAL_ADDRESS VariableBaseAddress,
|
|
IN UINT8 *Buffer,
|
|
IN UINTN BufferSize
|
|
);
|
|
|
|
#endif
|