ArmPlatformPkg: Apply uncrustify changes
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737 Apply uncrustify changes to .c/.h files in the ArmPlatformPkg package Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Andrew Fish <afish@apple.com>
This commit is contained in:
committed by
mergify[bot]
parent
429309e0c6
commit
40b0b23ed3
File diff suppressed because it is too large
Load Diff
@@ -21,37 +21,37 @@
|
||||
// Global variables
|
||||
//
|
||||
|
||||
BOOLEAN mDisplayInitialized = FALSE;
|
||||
BOOLEAN mDisplayInitialized = FALSE;
|
||||
|
||||
LCD_INSTANCE mLcdTemplate = {
|
||||
LCD_INSTANCE mLcdTemplate = {
|
||||
LCD_INSTANCE_SIGNATURE,
|
||||
NULL, // Handle
|
||||
{ // ModeInfo
|
||||
0, // Version
|
||||
0, // HorizontalResolution
|
||||
0, // VerticalResolution
|
||||
NULL, // Handle
|
||||
{ // ModeInfo
|
||||
0, // Version
|
||||
0, // HorizontalResolution
|
||||
0, // VerticalResolution
|
||||
PixelBltOnly, // PixelFormat
|
||||
{ 0 }, // PixelInformation
|
||||
0, // PixelsPerScanLine
|
||||
{ 0 }, // PixelInformation
|
||||
0, // PixelsPerScanLine
|
||||
},
|
||||
{
|
||||
0, // MaxMode;
|
||||
0, // Mode;
|
||||
0, // MaxMode;
|
||||
0, // Mode;
|
||||
NULL, // Info;
|
||||
0, // SizeOfInfo;
|
||||
0, // FrameBufferBase;
|
||||
0 // FrameBufferSize;
|
||||
0, // SizeOfInfo;
|
||||
0, // FrameBufferBase;
|
||||
0 // FrameBufferSize;
|
||||
},
|
||||
{ // Gop
|
||||
LcdGraphicsQueryMode, // QueryMode
|
||||
LcdGraphicsSetMode, // SetMode
|
||||
LcdGraphicsBlt, // Blt
|
||||
NULL // *Mode
|
||||
{ // Gop
|
||||
LcdGraphicsQueryMode, // QueryMode
|
||||
LcdGraphicsSetMode, // SetMode
|
||||
LcdGraphicsBlt, // Blt
|
||||
NULL // *Mode
|
||||
},
|
||||
{ // DevicePath
|
||||
{
|
||||
{
|
||||
HARDWARE_DEVICE_PATH, HW_VENDOR_DP,
|
||||
HARDWARE_DEVICE_PATH, HW_VENDOR_DP,
|
||||
{
|
||||
(UINT8)(sizeof (VENDOR_DEVICE_PATH)),
|
||||
(UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
|
||||
@@ -75,10 +75,10 @@ LCD_INSTANCE mLcdTemplate = {
|
||||
|
||||
EFI_STATUS
|
||||
LcdInstanceContructor (
|
||||
OUT LCD_INSTANCE** NewInstance
|
||||
OUT LCD_INSTANCE **NewInstance
|
||||
)
|
||||
{
|
||||
LCD_INSTANCE* Instance;
|
||||
LCD_INSTANCE *Instance;
|
||||
|
||||
Instance = AllocateCopyPool (sizeof (LCD_INSTANCE), &mLcdTemplate);
|
||||
if (Instance == NULL) {
|
||||
@@ -99,12 +99,12 @@ LcdInstanceContructor (
|
||||
|
||||
EFI_STATUS
|
||||
InitializeDisplay (
|
||||
IN LCD_INSTANCE* Instance
|
||||
IN LCD_INSTANCE *Instance
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_PHYSICAL_ADDRESS VramBaseAddress;
|
||||
UINTN VramSize;
|
||||
EFI_STATUS Status;
|
||||
EFI_PHYSICAL_ADDRESS VramBaseAddress;
|
||||
UINTN VramSize;
|
||||
|
||||
Status = LcdPlatformGetVram (&VramBaseAddress, &VramSize);
|
||||
if (EFI_ERROR (Status)) {
|
||||
@@ -144,12 +144,12 @@ EXIT:
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
LcdGraphicsOutputDxeInitialize (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LCD_INSTANCE* Instance;
|
||||
EFI_STATUS Status;
|
||||
LCD_INSTANCE *Instance;
|
||||
|
||||
Status = LcdIdentify ();
|
||||
if (EFI_ERROR (Status)) {
|
||||
@@ -240,14 +240,14 @@ LcdGraphicsExitBootServicesEvent (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
LcdGraphicsQueryMode (
|
||||
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
|
||||
IN UINT32 ModeNumber,
|
||||
OUT UINTN *SizeOfInfo,
|
||||
OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
|
||||
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
|
||||
IN UINT32 ModeNumber,
|
||||
OUT UINTN *SizeOfInfo,
|
||||
OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
LCD_INSTANCE *Instance;
|
||||
EFI_STATUS Status;
|
||||
LCD_INSTANCE *Instance;
|
||||
|
||||
Instance = LCD_INSTANCE_FROM_GOP_THIS (This);
|
||||
|
||||
@@ -263,7 +263,8 @@ LcdGraphicsQueryMode (
|
||||
if ((This == NULL) ||
|
||||
(Info == NULL) ||
|
||||
(SizeOfInfo == NULL) ||
|
||||
(ModeNumber >= This->Mode->MaxMode)) {
|
||||
(ModeNumber >= This->Mode->MaxMode))
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "LcdGraphicsQueryMode: ERROR - For mode number %d : Invalid Parameter.\n", ModeNumber));
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
goto EXIT;
|
||||
@@ -292,14 +293,14 @@ EXIT:
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
LcdGraphicsSetMode (
|
||||
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
|
||||
IN UINT32 ModeNumber
|
||||
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
|
||||
IN UINT32 ModeNumber
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_GRAPHICS_OUTPUT_BLT_PIXEL FillColour;
|
||||
LCD_INSTANCE* Instance;
|
||||
LCD_BPP Bpp;
|
||||
EFI_STATUS Status;
|
||||
EFI_GRAPHICS_OUTPUT_BLT_PIXEL FillColour;
|
||||
LCD_INSTANCE *Instance;
|
||||
LCD_BPP Bpp;
|
||||
|
||||
Instance = LCD_INSTANCE_FROM_GOP_THIS (This);
|
||||
|
||||
@@ -333,9 +334,10 @@ LcdGraphicsSetMode (
|
||||
DEBUG ((DEBUG_ERROR, "LcdGraphicsSetMode: ERROR - Couldn't get bytes per pixel, status: %r\n", Status));
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
This->Mode->FrameBufferSize = Instance->ModeInfo.VerticalResolution
|
||||
* Instance->ModeInfo.PixelsPerScanLine
|
||||
* GetBytesPerPixel (Bpp);
|
||||
* Instance->ModeInfo.PixelsPerScanLine
|
||||
* GetBytesPerPixel (Bpp);
|
||||
|
||||
// Set the hardware to the new mode
|
||||
Status = LcdSetMode (ModeNumber);
|
||||
@@ -352,17 +354,17 @@ LcdGraphicsSetMode (
|
||||
|
||||
// Fill the entire visible area with the same colour.
|
||||
Status = This->Blt (
|
||||
This,
|
||||
&FillColour,
|
||||
EfiBltVideoFill,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
This->Mode->Info->HorizontalResolution,
|
||||
This->Mode->Info->VerticalResolution,
|
||||
0
|
||||
);
|
||||
This,
|
||||
&FillColour,
|
||||
EfiBltVideoFill,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
This->Mode->Info->HorizontalResolution,
|
||||
This->Mode->Info->VerticalResolution,
|
||||
0
|
||||
);
|
||||
|
||||
EXIT:
|
||||
return Status;
|
||||
@@ -370,25 +372,25 @@ EXIT:
|
||||
|
||||
UINTN
|
||||
GetBytesPerPixel (
|
||||
IN LCD_BPP Bpp
|
||||
IN LCD_BPP Bpp
|
||||
)
|
||||
{
|
||||
switch (Bpp) {
|
||||
case LcdBitsPerPixel_24:
|
||||
return 4;
|
||||
case LcdBitsPerPixel_24:
|
||||
return 4;
|
||||
|
||||
case LcdBitsPerPixel_16_565:
|
||||
case LcdBitsPerPixel_16_555:
|
||||
case LcdBitsPerPixel_12_444:
|
||||
return 2;
|
||||
case LcdBitsPerPixel_16_565:
|
||||
case LcdBitsPerPixel_16_555:
|
||||
case LcdBitsPerPixel_12_444:
|
||||
return 2;
|
||||
|
||||
case LcdBitsPerPixel_8:
|
||||
case LcdBitsPerPixel_4:
|
||||
case LcdBitsPerPixel_2:
|
||||
case LcdBitsPerPixel_1:
|
||||
return 1;
|
||||
case LcdBitsPerPixel_8:
|
||||
case LcdBitsPerPixel_4:
|
||||
case LcdBitsPerPixel_2:
|
||||
case LcdBitsPerPixel_1:
|
||||
return 1;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@@ -22,23 +22,23 @@
|
||||
// Device structures
|
||||
//
|
||||
typedef struct {
|
||||
VENDOR_DEVICE_PATH Guid;
|
||||
EFI_DEVICE_PATH_PROTOCOL End;
|
||||
VENDOR_DEVICE_PATH Guid;
|
||||
EFI_DEVICE_PATH_PROTOCOL End;
|
||||
} LCD_GRAPHICS_DEVICE_PATH;
|
||||
|
||||
typedef struct {
|
||||
UINT32 Signature;
|
||||
EFI_HANDLE Handle;
|
||||
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION ModeInfo;
|
||||
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE Mode;
|
||||
EFI_GRAPHICS_OUTPUT_PROTOCOL Gop;
|
||||
LCD_GRAPHICS_DEVICE_PATH DevicePath;
|
||||
EFI_EVENT ExitBootServicesEvent;
|
||||
UINT32 Signature;
|
||||
EFI_HANDLE Handle;
|
||||
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION ModeInfo;
|
||||
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE Mode;
|
||||
EFI_GRAPHICS_OUTPUT_PROTOCOL Gop;
|
||||
LCD_GRAPHICS_DEVICE_PATH DevicePath;
|
||||
EFI_EVENT ExitBootServicesEvent;
|
||||
} LCD_INSTANCE;
|
||||
|
||||
#define LCD_INSTANCE_SIGNATURE SIGNATURE_32('l', 'c', 'd', '0')
|
||||
|
||||
#define LCD_INSTANCE_FROM_GOP_THIS(a) CR (a, LCD_INSTANCE, Gop, LCD_INSTANCE_SIGNATURE)
|
||||
#define LCD_INSTANCE_FROM_GOP_THIS(a) CR (a, LCD_INSTANCE, Gop, LCD_INSTANCE_SIGNATURE)
|
||||
|
||||
//
|
||||
// Function Prototypes
|
||||
@@ -46,9 +46,9 @@ typedef struct {
|
||||
|
||||
VOID
|
||||
LcdGraphicsExitBootServicesEvent (
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
);
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
@@ -57,14 +57,14 @@ LcdGraphicsQueryMode (
|
||||
IN UINT32 ModeNumber,
|
||||
OUT UINTN *SizeOfInfo,
|
||||
OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
|
||||
);
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
LcdGraphicsSetMode (
|
||||
IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
|
||||
IN UINT32 ModeNumber
|
||||
);
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
@@ -79,23 +79,23 @@ LcdGraphicsBlt (
|
||||
IN UINTN Width,
|
||||
IN UINTN Height,
|
||||
IN UINTN Delta OPTIONAL
|
||||
);
|
||||
);
|
||||
|
||||
UINTN
|
||||
GetBytesPerPixel (
|
||||
IN LCD_BPP Bpp
|
||||
IN LCD_BPP Bpp
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
GraphicsOutputDxeInitialize (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
InitializeDisplay (
|
||||
IN LCD_INSTANCE* Instance
|
||||
);
|
||||
IN LCD_INSTANCE *Instance
|
||||
);
|
||||
|
||||
#endif /* LCD_GRAPHICS_OUTPUT_DXE_H_ */
|
||||
|
@@ -14,13 +14,13 @@
|
||||
//
|
||||
// Global variable declarations
|
||||
//
|
||||
extern NOR_FLASH_INSTANCE **mNorFlashInstances;
|
||||
extern UINT32 mNorFlashDeviceCount;
|
||||
extern NOR_FLASH_INSTANCE **mNorFlashInstances;
|
||||
extern UINT32 mNorFlashDeviceCount;
|
||||
|
||||
UINT32
|
||||
NorFlashReadStatusRegister (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN SR_Address
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN SR_Address
|
||||
)
|
||||
{
|
||||
// Prepare to read the status register
|
||||
@@ -31,23 +31,23 @@ NorFlashReadStatusRegister (
|
||||
STATIC
|
||||
BOOLEAN
|
||||
NorFlashBlockIsLocked (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
)
|
||||
{
|
||||
UINT32 LockStatus;
|
||||
UINT32 LockStatus;
|
||||
|
||||
// Send command for reading device id
|
||||
SEND_NOR_COMMAND (BlockAddress, 2, P30_CMD_READ_DEVICE_ID);
|
||||
|
||||
// Read block lock status
|
||||
LockStatus = MmioRead32 (CREATE_NOR_ADDRESS(BlockAddress, 2));
|
||||
LockStatus = MmioRead32 (CREATE_NOR_ADDRESS (BlockAddress, 2));
|
||||
|
||||
// Decode block lock status
|
||||
LockStatus = FOLD_32BIT_INTO_16BIT(LockStatus);
|
||||
LockStatus = FOLD_32BIT_INTO_16BIT (LockStatus);
|
||||
|
||||
if ((LockStatus & 0x2) != 0) {
|
||||
DEBUG((DEBUG_ERROR, "NorFlashBlockIsLocked: WARNING: Block LOCKED DOWN\n"));
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashBlockIsLocked: WARNING: Block LOCKED DOWN\n"));
|
||||
}
|
||||
|
||||
return ((LockStatus & 0x1) != 0);
|
||||
@@ -56,11 +56,11 @@ NorFlashBlockIsLocked (
|
||||
STATIC
|
||||
EFI_STATUS
|
||||
NorFlashUnlockSingleBlock (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
)
|
||||
{
|
||||
UINT32 LockStatus;
|
||||
UINT32 LockStatus;
|
||||
|
||||
// Raise the Task Priority Level to TPL_NOTIFY to serialise all its operations
|
||||
// and to protect shared data structures.
|
||||
@@ -77,10 +77,10 @@ NorFlashUnlockSingleBlock (
|
||||
SEND_NOR_COMMAND (BlockAddress, 2, P30_CMD_READ_DEVICE_ID);
|
||||
|
||||
// Read block lock status
|
||||
LockStatus = MmioRead32 (CREATE_NOR_ADDRESS(BlockAddress, 2));
|
||||
LockStatus = MmioRead32 (CREATE_NOR_ADDRESS (BlockAddress, 2));
|
||||
|
||||
// Decode block lock status
|
||||
LockStatus = FOLD_32BIT_INTO_16BIT(LockStatus);
|
||||
LockStatus = FOLD_32BIT_INTO_16BIT (LockStatus);
|
||||
} while ((LockStatus & 0x1) == 1);
|
||||
} else {
|
||||
// Request a lock setup
|
||||
@@ -98,18 +98,18 @@ NorFlashUnlockSingleBlock (
|
||||
// Put device back into Read Array mode
|
||||
SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_READ_ARRAY);
|
||||
|
||||
DEBUG((DEBUG_BLKIO, "UnlockSingleBlock: BlockAddress=0x%08x\n", BlockAddress));
|
||||
DEBUG ((DEBUG_BLKIO, "UnlockSingleBlock: BlockAddress=0x%08x\n", BlockAddress));
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashUnlockSingleBlockIfNecessary (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_STATUS Status;
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
@@ -120,24 +120,23 @@ NorFlashUnlockSingleBlockIfNecessary (
|
||||
return Status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The following function presumes that the block has already been unlocked.
|
||||
**/
|
||||
EFI_STATUS
|
||||
NorFlashEraseSingleBlock (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 StatusRegister;
|
||||
EFI_STATUS Status;
|
||||
UINT32 StatusRegister;
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
// Request a block erase and then confirm it
|
||||
SEND_NOR_COMMAND(BlockAddress, 0, P30_CMD_BLOCK_ERASE_SETUP);
|
||||
SEND_NOR_COMMAND(BlockAddress, 0, P30_CMD_BLOCK_ERASE_CONFIRM);
|
||||
SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_BLOCK_ERASE_SETUP);
|
||||
SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_BLOCK_ERASE_CONFIRM);
|
||||
|
||||
// Wait until the status register gives us the all clear
|
||||
do {
|
||||
@@ -145,27 +144,27 @@ NorFlashEraseSingleBlock (
|
||||
} while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);
|
||||
|
||||
if (StatusRegister & P30_SR_BIT_VPP) {
|
||||
DEBUG((DEBUG_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: VPP Range Error\n", BlockAddress));
|
||||
DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=0x%08x: VPP Range Error\n", BlockAddress));
|
||||
Status = EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if ((StatusRegister & (P30_SR_BIT_ERASE | P30_SR_BIT_PROGRAM)) == (P30_SR_BIT_ERASE | P30_SR_BIT_PROGRAM)) {
|
||||
DEBUG((DEBUG_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Command Sequence Error\n", BlockAddress));
|
||||
DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=0x%08x: Command Sequence Error\n", BlockAddress));
|
||||
Status = EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if (StatusRegister & P30_SR_BIT_ERASE) {
|
||||
DEBUG((DEBUG_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Block Erase Error StatusRegister:0x%X\n", BlockAddress, StatusRegister));
|
||||
DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=0x%08x: Block Erase Error StatusRegister:0x%X\n", BlockAddress, StatusRegister));
|
||||
Status = EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) {
|
||||
// The debug level message has been reduced because a device lock might happen. In this case we just retry it ...
|
||||
DEBUG((DEBUG_INFO,"EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error\n", BlockAddress));
|
||||
DEBUG ((DEBUG_INFO, "EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error\n", BlockAddress));
|
||||
Status = EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (EFI_ERROR (Status)) {
|
||||
// Clear the Status Register
|
||||
SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER);
|
||||
}
|
||||
@@ -178,18 +177,18 @@ NorFlashEraseSingleBlock (
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashWriteSingleWord (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN WordAddress,
|
||||
IN UINT32 WriteData
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN WordAddress,
|
||||
IN UINT32 WriteData
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 StatusRegister;
|
||||
EFI_STATUS Status;
|
||||
UINT32 StatusRegister;
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
// Request a write single word command
|
||||
SEND_NOR_COMMAND(WordAddress, 0, P30_CMD_WORD_PROGRAM_SETUP);
|
||||
SEND_NOR_COMMAND (WordAddress, 0, P30_CMD_WORD_PROGRAM_SETUP);
|
||||
|
||||
// Store the word into NOR Flash;
|
||||
MmioWrite32 (WordAddress, WriteData);
|
||||
@@ -201,27 +200,26 @@ NorFlashWriteSingleWord (
|
||||
// The chip is busy while the WRITE bit is not asserted
|
||||
} while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);
|
||||
|
||||
|
||||
// Perform a full status check:
|
||||
// Mask the relevant bits of Status Register.
|
||||
// Everything should be zero, if not, we have a problem
|
||||
|
||||
if (StatusRegister & P30_SR_BIT_VPP) {
|
||||
DEBUG((DEBUG_ERROR,"NorFlashWriteSingleWord(WordAddress:0x%X): VPP Range Error\n",WordAddress));
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleWord(WordAddress:0x%X): VPP Range Error\n", WordAddress));
|
||||
Status = EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if (StatusRegister & P30_SR_BIT_PROGRAM) {
|
||||
DEBUG((DEBUG_ERROR,"NorFlashWriteSingleWord(WordAddress:0x%X): Program Error\n",WordAddress));
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleWord(WordAddress:0x%X): Program Error\n", WordAddress));
|
||||
Status = EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) {
|
||||
DEBUG((DEBUG_ERROR,"NorFlashWriteSingleWord(WordAddress:0x%X): Device Protect Error\n",WordAddress));
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleWord(WordAddress:0x%X): Device Protect Error\n", WordAddress));
|
||||
Status = EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if (!EFI_ERROR(Status)) {
|
||||
if (!EFI_ERROR (Status)) {
|
||||
// Clear the Status Register
|
||||
SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER);
|
||||
}
|
||||
@@ -249,19 +247,19 @@ NorFlashWriteSingleWord (
|
||||
*/
|
||||
EFI_STATUS
|
||||
NorFlashWriteBuffer (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN TargetAddress,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
IN UINT32 *Buffer
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN TargetAddress,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
IN UINT32 *Buffer
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN BufferSizeInWords;
|
||||
UINTN Count;
|
||||
volatile UINT32 *Data;
|
||||
UINTN WaitForBuffer;
|
||||
BOOLEAN BufferAvailable;
|
||||
UINT32 StatusRegister;
|
||||
EFI_STATUS Status;
|
||||
UINTN BufferSizeInWords;
|
||||
UINTN Count;
|
||||
volatile UINT32 *Data;
|
||||
UINTN WaitForBuffer;
|
||||
BOOLEAN BufferAvailable;
|
||||
UINT32 StatusRegister;
|
||||
|
||||
WaitForBuffer = MAX_BUFFERED_PROG_ITERATIONS;
|
||||
BufferAvailable = FALSE;
|
||||
@@ -294,7 +292,7 @@ NorFlashWriteBuffer (
|
||||
// Check the availability of the buffer
|
||||
do {
|
||||
// Issue the Buffered Program Setup command
|
||||
SEND_NOR_COMMAND(TargetAddress, 0, P30_CMD_BUFFERED_PROGRAM_SETUP);
|
||||
SEND_NOR_COMMAND (TargetAddress, 0, P30_CMD_BUFFERED_PROGRAM_SETUP);
|
||||
|
||||
// Read back the status register bit#7 from the same address
|
||||
if (((*Data) & P30_SR_BIT_WRITE) == P30_SR_BIT_WRITE) {
|
||||
@@ -303,7 +301,6 @@ NorFlashWriteBuffer (
|
||||
|
||||
// Update the loop counter
|
||||
WaitForBuffer--;
|
||||
|
||||
} while ((WaitForBuffer > 0) && (BufferAvailable == FALSE));
|
||||
|
||||
// The buffer was not available for writing
|
||||
@@ -317,10 +314,10 @@ NorFlashWriteBuffer (
|
||||
|
||||
// Write the word count, which is (buffer_size_in_words - 1),
|
||||
// because word count 0 means one word.
|
||||
SEND_NOR_COMMAND(TargetAddress, 0, (BufferSizeInWords - 1));
|
||||
SEND_NOR_COMMAND (TargetAddress, 0, (BufferSizeInWords - 1));
|
||||
|
||||
// Write the data to the NOR Flash, advancing each address by 4 bytes
|
||||
for(Count=0; Count < BufferSizeInWords; Count++, Data++, Buffer++) {
|
||||
for (Count = 0; Count < BufferSizeInWords; Count++, Data++, Buffer++) {
|
||||
MmioWrite32 ((UINTN)Data, *Buffer);
|
||||
}
|
||||
|
||||
@@ -333,29 +330,28 @@ NorFlashWriteBuffer (
|
||||
// The chip is busy while the WRITE bit is not asserted
|
||||
} while ((StatusRegister & P30_SR_BIT_WRITE) != P30_SR_BIT_WRITE);
|
||||
|
||||
|
||||
// Perform a full status check:
|
||||
// Mask the relevant bits of Status Register.
|
||||
// Everything should be zero, if not, we have a problem
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
if (StatusRegister & P30_SR_BIT_VPP) {
|
||||
DEBUG((DEBUG_ERROR,"NorFlashWriteBuffer(TargetAddress:0x%X): VPP Range Error\n", TargetAddress));
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashWriteBuffer(TargetAddress:0x%X): VPP Range Error\n", TargetAddress));
|
||||
Status = EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if (StatusRegister & P30_SR_BIT_PROGRAM) {
|
||||
DEBUG((DEBUG_ERROR,"NorFlashWriteBuffer(TargetAddress:0x%X): Program Error\n", TargetAddress));
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashWriteBuffer(TargetAddress:0x%X): Program Error\n", TargetAddress));
|
||||
Status = EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if (StatusRegister & P30_SR_BIT_BLOCK_LOCKED) {
|
||||
DEBUG((DEBUG_ERROR,"NorFlashWriteBuffer(TargetAddress:0x%X): Device Protect Error\n",TargetAddress));
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashWriteBuffer(TargetAddress:0x%X): Device Protect Error\n", TargetAddress));
|
||||
Status = EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
if (!EFI_ERROR(Status)) {
|
||||
if (!EFI_ERROR (Status)) {
|
||||
// Clear the Status Register
|
||||
SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_CLEAR_STATUS_REGISTER);
|
||||
}
|
||||
@@ -369,18 +365,18 @@ EXIT:
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashWriteBlocks (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
IN VOID *Buffer
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
IN VOID *Buffer
|
||||
)
|
||||
{
|
||||
UINT32 *pWriteBuffer;
|
||||
EFI_STATUS Status;
|
||||
EFI_LBA CurrentBlock;
|
||||
UINT32 BlockSizeInWords;
|
||||
UINT32 NumBlocks;
|
||||
UINT32 BlockCount;
|
||||
UINT32 *pWriteBuffer;
|
||||
EFI_STATUS Status;
|
||||
EFI_LBA CurrentBlock;
|
||||
UINT32 BlockSizeInWords;
|
||||
UINT32 NumBlocks;
|
||||
UINT32 BlockCount;
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
@@ -389,29 +385,29 @@ NorFlashWriteBlocks (
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if(Instance->Media.ReadOnly == TRUE) {
|
||||
if (Instance->Media.ReadOnly == TRUE) {
|
||||
return EFI_WRITE_PROTECTED;
|
||||
}
|
||||
|
||||
// We must have some bytes to read
|
||||
DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: BufferSizeInBytes=0x%x\n", BufferSizeInBytes));
|
||||
if(BufferSizeInBytes == 0) {
|
||||
DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: BufferSizeInBytes=0x%x\n", BufferSizeInBytes));
|
||||
if (BufferSizeInBytes == 0) {
|
||||
return EFI_BAD_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
// The size of the buffer must be a multiple of the block size
|
||||
DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: BlockSize in bytes =0x%x\n", Instance->Media.BlockSize));
|
||||
DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: BlockSize in bytes =0x%x\n", Instance->Media.BlockSize));
|
||||
if ((BufferSizeInBytes % Instance->Media.BlockSize) != 0) {
|
||||
return EFI_BAD_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
// All blocks must be within the device
|
||||
NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize ;
|
||||
NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize;
|
||||
|
||||
DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: NumBlocks=%d, LastBlock=%ld, Lba=%ld.\n", NumBlocks, Instance->Media.LastBlock, Lba));
|
||||
DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: NumBlocks=%d, LastBlock=%ld, Lba=%ld.\n", NumBlocks, Instance->Media.LastBlock, Lba));
|
||||
|
||||
if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {
|
||||
DEBUG((DEBUG_ERROR, "NorFlashWriteBlocks: ERROR - Write will exceed last block.\n"));
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashWriteBlocks: ERROR - Write will exceed last block.\n"));
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
@@ -422,22 +418,21 @@ NorFlashWriteBlocks (
|
||||
pWriteBuffer = (UINT32 *)Buffer;
|
||||
|
||||
CurrentBlock = Lba;
|
||||
for (BlockCount=0; BlockCount < NumBlocks; BlockCount++, CurrentBlock++, pWriteBuffer = pWriteBuffer + BlockSizeInWords) {
|
||||
|
||||
DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: Writing block #%d\n", (UINTN)CurrentBlock));
|
||||
for (BlockCount = 0; BlockCount < NumBlocks; BlockCount++, CurrentBlock++, pWriteBuffer = pWriteBuffer + BlockSizeInWords) {
|
||||
DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: Writing block #%d\n", (UINTN)CurrentBlock));
|
||||
|
||||
Status = NorFlashWriteFullBlock (Instance, CurrentBlock, pWriteBuffer, BlockSizeInWords);
|
||||
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (EFI_ERROR (Status)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG((DEBUG_BLKIO, "NorFlashWriteBlocks: Exit Status = \"%r\".\n", Status));
|
||||
DEBUG ((DEBUG_BLKIO, "NorFlashWriteBlocks: Exit Status = \"%r\".\n", Status));
|
||||
return Status;
|
||||
}
|
||||
|
||||
#define BOTH_ALIGNED(a, b, align) ((((UINTN)(a) | (UINTN)(b)) & ((align) - 1)) == 0)
|
||||
#define BOTH_ALIGNED(a, b, align) ((((UINTN)(a) | (UINTN)(b)) & ((align) - 1)) == 0)
|
||||
|
||||
/**
|
||||
Copy Length bytes from Source to Destination, using aligned accesses only.
|
||||
@@ -454,61 +449,69 @@ NorFlashWriteBlocks (
|
||||
STATIC
|
||||
VOID *
|
||||
AlignedCopyMem (
|
||||
OUT VOID *DestinationBuffer,
|
||||
IN CONST VOID *SourceBuffer,
|
||||
IN UINTN Length
|
||||
OUT VOID *DestinationBuffer,
|
||||
IN CONST VOID *SourceBuffer,
|
||||
IN UINTN Length
|
||||
)
|
||||
{
|
||||
UINT8 *Destination8;
|
||||
CONST UINT8 *Source8;
|
||||
UINT32 *Destination32;
|
||||
CONST UINT32 *Source32;
|
||||
UINT64 *Destination64;
|
||||
CONST UINT64 *Source64;
|
||||
UINT8 *Destination8;
|
||||
CONST UINT8 *Source8;
|
||||
UINT32 *Destination32;
|
||||
CONST UINT32 *Source32;
|
||||
UINT64 *Destination64;
|
||||
CONST UINT64 *Source64;
|
||||
|
||||
if (BOTH_ALIGNED(DestinationBuffer, SourceBuffer, 8) && Length >= 8) {
|
||||
if (BOTH_ALIGNED (DestinationBuffer, SourceBuffer, 8) && (Length >= 8)) {
|
||||
Destination64 = DestinationBuffer;
|
||||
Source64 = SourceBuffer;
|
||||
Source64 = SourceBuffer;
|
||||
while (Length >= 8) {
|
||||
*Destination64++ = *Source64++;
|
||||
Length -= 8;
|
||||
Length -= 8;
|
||||
}
|
||||
|
||||
Destination8 = (UINT8 *)Destination64;
|
||||
Source8 = (CONST UINT8 *)Source64;
|
||||
} else if (BOTH_ALIGNED(DestinationBuffer, SourceBuffer, 4) && Length >= 4) {
|
||||
Source8 = (CONST UINT8 *)Source64;
|
||||
} else if (BOTH_ALIGNED (DestinationBuffer, SourceBuffer, 4) && (Length >= 4)) {
|
||||
Destination32 = DestinationBuffer;
|
||||
Source32 = SourceBuffer;
|
||||
Source32 = SourceBuffer;
|
||||
while (Length >= 4) {
|
||||
*Destination32++ = *Source32++;
|
||||
Length -= 4;
|
||||
Length -= 4;
|
||||
}
|
||||
|
||||
Destination8 = (UINT8 *)Destination32;
|
||||
Source8 = (CONST UINT8 *)Source32;
|
||||
Source8 = (CONST UINT8 *)Source32;
|
||||
} else {
|
||||
Destination8 = DestinationBuffer;
|
||||
Source8 = SourceBuffer;
|
||||
Source8 = SourceBuffer;
|
||||
}
|
||||
|
||||
while (Length-- != 0) {
|
||||
*Destination8++ = *Source8++;
|
||||
}
|
||||
|
||||
return DestinationBuffer;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashReadBlocks (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
OUT VOID *Buffer
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
OUT VOID *Buffer
|
||||
)
|
||||
{
|
||||
UINT32 NumBlocks;
|
||||
UINTN StartAddress;
|
||||
UINT32 NumBlocks;
|
||||
UINTN StartAddress;
|
||||
|
||||
DEBUG((DEBUG_BLKIO, "NorFlashReadBlocks: BufferSize=0x%xB BlockSize=0x%xB LastBlock=%ld, Lba=%ld.\n",
|
||||
BufferSizeInBytes, Instance->Media.BlockSize, Instance->Media.LastBlock, Lba));
|
||||
DEBUG ((
|
||||
DEBUG_BLKIO,
|
||||
"NorFlashReadBlocks: BufferSize=0x%xB BlockSize=0x%xB LastBlock=%ld, Lba=%ld.\n",
|
||||
BufferSizeInBytes,
|
||||
Instance->Media.BlockSize,
|
||||
Instance->Media.LastBlock,
|
||||
Lba
|
||||
));
|
||||
|
||||
// The buffer must be valid
|
||||
if (Buffer == NULL) {
|
||||
@@ -526,18 +529,19 @@ NorFlashReadBlocks (
|
||||
}
|
||||
|
||||
// All blocks must be within the device
|
||||
NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize ;
|
||||
NumBlocks = ((UINT32)BufferSizeInBytes) / Instance->Media.BlockSize;
|
||||
|
||||
if ((Lba + NumBlocks) > (Instance->Media.LastBlock + 1)) {
|
||||
DEBUG((DEBUG_ERROR, "NorFlashReadBlocks: ERROR - Read will exceed last block\n"));
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashReadBlocks: ERROR - Read will exceed last block\n"));
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
// Get the address to start reading from
|
||||
StartAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress,
|
||||
Lba,
|
||||
Instance->Media.BlockSize
|
||||
);
|
||||
StartAddress = GET_NOR_BLOCK_ADDRESS (
|
||||
Instance->RegionBaseAddress,
|
||||
Lba,
|
||||
Instance->Media.BlockSize
|
||||
);
|
||||
|
||||
// Put the device into Read Array mode
|
||||
SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
|
||||
@@ -550,11 +554,11 @@ NorFlashReadBlocks (
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashRead (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
OUT VOID *Buffer
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
OUT VOID *Buffer
|
||||
)
|
||||
{
|
||||
UINTN StartAddress;
|
||||
@@ -575,10 +579,11 @@ NorFlashRead (
|
||||
}
|
||||
|
||||
// Get the address to start reading from
|
||||
StartAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress,
|
||||
Lba,
|
||||
Instance->Media.BlockSize
|
||||
);
|
||||
StartAddress = GET_NOR_BLOCK_ADDRESS (
|
||||
Instance->RegionBaseAddress,
|
||||
Lba,
|
||||
Instance->Media.BlockSize
|
||||
);
|
||||
|
||||
// Put the device into Read Array mode
|
||||
SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
|
||||
@@ -595,11 +600,11 @@ NorFlashRead (
|
||||
*/
|
||||
EFI_STATUS
|
||||
NorFlashWriteSingleBlock (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN OUT UINTN *NumBytes,
|
||||
IN UINT8 *Buffer
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN OUT UINTN *NumBytes,
|
||||
IN UINT8 *Buffer
|
||||
)
|
||||
{
|
||||
EFI_STATUS TempStatus;
|
||||
@@ -631,16 +636,17 @@ NorFlashWriteSingleBlock (
|
||||
|
||||
// The write must not span block boundaries.
|
||||
// We need to check each variable individually because adding two large values together overflows.
|
||||
if ( ( Offset >= BlockSize ) ||
|
||||
( *NumBytes > BlockSize ) ||
|
||||
( (Offset + *NumBytes) > BlockSize ) ) {
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleBlock: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));
|
||||
if ((Offset >= BlockSize) ||
|
||||
(*NumBytes > BlockSize) ||
|
||||
((Offset + *NumBytes) > BlockSize))
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleBlock: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize));
|
||||
return EFI_BAD_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
// We must have some bytes to write
|
||||
if (*NumBytes == 0) {
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleBlock: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashWriteSingleBlock: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize));
|
||||
return EFI_BAD_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
@@ -659,16 +665,19 @@ NorFlashWriteSingleBlock (
|
||||
while (BytesToWrite > 0) {
|
||||
// Read full word from NOR, splice as required. A word is the smallest
|
||||
// unit we can write.
|
||||
TempStatus = NorFlashRead (Instance, Lba, CurOffset & ~(0x3), sizeof(Tmp), &Tmp);
|
||||
TempStatus = NorFlashRead (Instance, Lba, CurOffset & ~(0x3), sizeof (Tmp), &Tmp);
|
||||
if (EFI_ERROR (TempStatus)) {
|
||||
return EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
// Physical address of word in NOR to write.
|
||||
WordAddr = (CurOffset & ~(0x3)) + GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress,
|
||||
Lba, BlockSize);
|
||||
WordAddr = (CurOffset & ~(0x3)) + GET_NOR_BLOCK_ADDRESS (
|
||||
Instance->RegionBaseAddress,
|
||||
Lba,
|
||||
BlockSize
|
||||
);
|
||||
// The word of data that is to be written.
|
||||
TmpBuf = *((UINT32*)(Buffer + (*NumBytes - BytesToWrite)));
|
||||
TmpBuf = *((UINT32 *)(Buffer + (*NumBytes - BytesToWrite)));
|
||||
|
||||
// First do word aligned chunks.
|
||||
if ((CurOffset & 0x3) == 0) {
|
||||
@@ -681,10 +690,11 @@ NorFlashWriteSingleBlock (
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Write this word to NOR
|
||||
WordToWrite = TmpBuf;
|
||||
CurOffset += sizeof(TmpBuf);
|
||||
BytesToWrite -= sizeof(TmpBuf);
|
||||
WordToWrite = TmpBuf;
|
||||
CurOffset += sizeof (TmpBuf);
|
||||
BytesToWrite -= sizeof (TmpBuf);
|
||||
} else {
|
||||
// BytesToWrite < 4. Do small writes and left-overs
|
||||
Mask = ~((~0) << (BytesToWrite * 8));
|
||||
@@ -698,9 +708,10 @@ NorFlashWriteSingleBlock (
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Merge old and new data. Write merged word to NOR
|
||||
WordToWrite = (Tmp & ~Mask) | TmpBuf;
|
||||
CurOffset += BytesToWrite;
|
||||
WordToWrite = (Tmp & ~Mask) | TmpBuf;
|
||||
CurOffset += BytesToWrite;
|
||||
BytesToWrite = 0;
|
||||
}
|
||||
} else {
|
||||
@@ -717,10 +728,11 @@ NorFlashWriteSingleBlock (
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Merge old and new data. Write merged word to NOR
|
||||
WordToWrite = (Tmp & ~Mask) | TmpBuf;
|
||||
WordToWrite = (Tmp & ~Mask) | TmpBuf;
|
||||
BytesToWrite -= (4 - (CurOffset & 0x3));
|
||||
CurOffset += (4 - (CurOffset & 0x3));
|
||||
CurOffset += (4 - (CurOffset & 0x3));
|
||||
} else {
|
||||
// Unaligned and fits in one word.
|
||||
Mask = (~((~0) << (BytesToWrite * 8))) << ((CurOffset & 0x3) * 8);
|
||||
@@ -734,9 +746,10 @@ NorFlashWriteSingleBlock (
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Merge old and new data. Write merged word to NOR
|
||||
WordToWrite = (Tmp & ~Mask) | TmpBuf;
|
||||
CurOffset += BytesToWrite;
|
||||
WordToWrite = (Tmp & ~Mask) | TmpBuf;
|
||||
CurOffset += BytesToWrite;
|
||||
BytesToWrite = 0;
|
||||
}
|
||||
}
|
||||
@@ -751,13 +764,16 @@ NorFlashWriteSingleBlock (
|
||||
if (EFI_ERROR (TempStatus)) {
|
||||
return EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
PrevBlockAddress = BlockAddress;
|
||||
}
|
||||
|
||||
TempStatus = NorFlashWriteSingleWord (Instance, WordAddr, WordToWrite);
|
||||
if (EFI_ERROR (TempStatus)) {
|
||||
return EFI_DEVICE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
// Exit if we got here and could write all the data. Otherwise do the
|
||||
// Erase-Write cycle.
|
||||
if (!DoErase) {
|
||||
@@ -779,7 +795,7 @@ NorFlashWriteSingleBlock (
|
||||
}
|
||||
|
||||
// Put the data at the appropriate location inside the buffer area
|
||||
CopyMem ((VOID*)((UINTN)Instance->ShadowBuffer + Offset), Buffer, *NumBytes);
|
||||
CopyMem ((VOID *)((UINTN)Instance->ShadowBuffer + Offset), Buffer, *NumBytes);
|
||||
|
||||
// Write the modified buffer back to the NorFlash
|
||||
TempStatus = NorFlashWriteBlocks (Instance, Lba, BlockSize, Instance->ShadowBuffer);
|
||||
@@ -819,26 +835,26 @@ NorFlashWriteSingleBlock (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
NorFlashDiskIoReadDisk (
|
||||
IN EFI_DISK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN UINT64 DiskOffset,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer
|
||||
IN EFI_DISK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN UINT64 DiskOffset,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer
|
||||
)
|
||||
{
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
UINT32 BlockSize;
|
||||
UINT32 BlockOffset;
|
||||
EFI_LBA Lba;
|
||||
|
||||
Instance = INSTANCE_FROM_DISKIO_THIS(This);
|
||||
Instance = INSTANCE_FROM_DISKIO_THIS (This);
|
||||
|
||||
if (MediaId != Instance->Media.MediaId) {
|
||||
return EFI_MEDIA_CHANGED;
|
||||
}
|
||||
|
||||
BlockSize = Instance->Media.BlockSize;
|
||||
Lba = (EFI_LBA) DivU64x32Remainder (DiskOffset, BlockSize, &BlockOffset);
|
||||
Lba = (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &BlockOffset);
|
||||
|
||||
return NorFlashRead (Instance, Lba, BlockOffset, BufferSize, Buffer);
|
||||
}
|
||||
@@ -864,14 +880,14 @@ NorFlashDiskIoReadDisk (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
NorFlashDiskIoWriteDisk (
|
||||
IN EFI_DISK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN UINT64 DiskOffset,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer
|
||||
IN EFI_DISK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN UINT64 DiskOffset,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer
|
||||
)
|
||||
{
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
UINT32 BlockSize;
|
||||
UINT32 BlockOffset;
|
||||
EFI_LBA Lba;
|
||||
@@ -879,14 +895,14 @@ NorFlashDiskIoWriteDisk (
|
||||
UINTN WriteSize;
|
||||
EFI_STATUS Status;
|
||||
|
||||
Instance = INSTANCE_FROM_DISKIO_THIS(This);
|
||||
Instance = INSTANCE_FROM_DISKIO_THIS (This);
|
||||
|
||||
if (MediaId != Instance->Media.MediaId) {
|
||||
return EFI_MEDIA_CHANGED;
|
||||
}
|
||||
|
||||
BlockSize = Instance->Media.BlockSize;
|
||||
Lba = (EFI_LBA) DivU64x32Remainder (DiskOffset, BlockSize, &BlockOffset);
|
||||
Lba = (EFI_LBA)DivU64x32Remainder (DiskOffset, BlockSize, &BlockOffset);
|
||||
|
||||
RemainingBytes = BufferSize;
|
||||
|
||||
@@ -904,15 +920,17 @@ NorFlashDiskIoWriteDisk (
|
||||
// Write a partial block
|
||||
Status = NorFlashWriteSingleBlock (Instance, Lba, BlockOffset, &WriteSize, Buffer);
|
||||
}
|
||||
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
// Now continue writing either all the remaining bytes or single blocks.
|
||||
RemainingBytes -= WriteSize;
|
||||
Buffer = (UINT8 *) Buffer + WriteSize;
|
||||
Buffer = (UINT8 *)Buffer + WriteSize;
|
||||
Lba++;
|
||||
BlockOffset = 0;
|
||||
WriteSize = MIN (RemainingBytes, BlockSize);
|
||||
WriteSize = MIN (RemainingBytes, BlockSize);
|
||||
} while (RemainingBytes);
|
||||
|
||||
return Status;
|
||||
@@ -920,7 +938,7 @@ NorFlashDiskIoWriteDisk (
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashReset (
|
||||
IN NOR_FLASH_INSTANCE *Instance
|
||||
IN NOR_FLASH_INSTANCE *Instance
|
||||
)
|
||||
{
|
||||
// As there is no specific RESET to perform, ensure that the devices is in the default Read Array mode
|
||||
@@ -939,33 +957,33 @@ NorFlashReset (
|
||||
VOID
|
||||
EFIAPI
|
||||
NorFlashVirtualNotifyEvent (
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
)
|
||||
{
|
||||
UINTN Index;
|
||||
UINTN Index;
|
||||
|
||||
for (Index = 0; Index < mNorFlashDeviceCount; Index++) {
|
||||
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->DeviceBaseAddress);
|
||||
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->RegionBaseAddress);
|
||||
EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->DeviceBaseAddress);
|
||||
EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->RegionBaseAddress);
|
||||
|
||||
// Convert BlockIo protocol
|
||||
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.FlushBlocks);
|
||||
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.ReadBlocks);
|
||||
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.Reset);
|
||||
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->BlockIoProtocol.WriteBlocks);
|
||||
EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoProtocol.FlushBlocks);
|
||||
EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoProtocol.ReadBlocks);
|
||||
EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoProtocol.Reset);
|
||||
EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->BlockIoProtocol.WriteBlocks);
|
||||
|
||||
// Convert Fvb
|
||||
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.EraseBlocks);
|
||||
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.GetAttributes);
|
||||
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.GetBlockSize);
|
||||
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.GetPhysicalAddress);
|
||||
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.Read);
|
||||
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.SetAttributes);
|
||||
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->FvbProtocol.Write);
|
||||
EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtocol.EraseBlocks);
|
||||
EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtocol.GetAttributes);
|
||||
EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtocol.GetBlockSize);
|
||||
EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtocol.GetPhysicalAddress);
|
||||
EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtocol.Read);
|
||||
EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtocol.SetAttributes);
|
||||
EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->FvbProtocol.Write);
|
||||
|
||||
if (mNorFlashInstances[Index]->ShadowBuffer != NULL) {
|
||||
EfiConvertPointer (0x0, (VOID**)&mNorFlashInstances[Index]->ShadowBuffer);
|
||||
EfiConvertPointer (0x0, (VOID **)&mNorFlashInstances[Index]->ShadowBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -9,7 +9,6 @@
|
||||
#ifndef __NOR_FLASH_H__
|
||||
#define __NOR_FLASH_H__
|
||||
|
||||
|
||||
#include <Base.h>
|
||||
#include <PiDxe.h>
|
||||
|
||||
@@ -25,138 +24,138 @@
|
||||
#include <Library/UefiLib.h>
|
||||
#include <Library/UefiRuntimeLib.h>
|
||||
|
||||
#define NOR_FLASH_ERASE_RETRY 10
|
||||
#define NOR_FLASH_ERASE_RETRY 10
|
||||
|
||||
// Device access macros
|
||||
// These are necessary because we use 2 x 16bit parts to make up 32bit data
|
||||
|
||||
#define HIGH_16_BITS 0xFFFF0000
|
||||
#define LOW_16_BITS 0x0000FFFF
|
||||
#define LOW_8_BITS 0x000000FF
|
||||
#define HIGH_16_BITS 0xFFFF0000
|
||||
#define LOW_16_BITS 0x0000FFFF
|
||||
#define LOW_8_BITS 0x000000FF
|
||||
|
||||
#define FOLD_32BIT_INTO_16BIT(value) ( ( value >> 16 ) | ( value & LOW_16_BITS ) )
|
||||
#define FOLD_32BIT_INTO_16BIT(value) ( ( value >> 16 ) | ( value & LOW_16_BITS ) )
|
||||
|
||||
#define GET_LOW_BYTE(value) ( value & LOW_8_BITS )
|
||||
#define GET_HIGH_BYTE(value) ( GET_LOW_BYTE( value >> 16 ) )
|
||||
#define GET_LOW_BYTE(value) ( value & LOW_8_BITS )
|
||||
#define GET_HIGH_BYTE(value) ( GET_LOW_BYTE( value >> 16 ) )
|
||||
|
||||
// Each command must be sent simultaneously to both chips,
|
||||
// i.e. at the lower 16 bits AND at the higher 16 bits
|
||||
#define CREATE_NOR_ADDRESS(BaseAddr,OffsetAddr) ((BaseAddr) + ((OffsetAddr) << 2))
|
||||
#define CREATE_DUAL_CMD(Cmd) ( ( Cmd << 16) | ( Cmd & LOW_16_BITS) )
|
||||
#define SEND_NOR_COMMAND(BaseAddr,Offset,Cmd) MmioWrite32 (CREATE_NOR_ADDRESS(BaseAddr,Offset), CREATE_DUAL_CMD(Cmd))
|
||||
#define GET_NOR_BLOCK_ADDRESS(BaseAddr,Lba,LbaSize)( BaseAddr + (UINTN)((Lba) * LbaSize) )
|
||||
#define CREATE_NOR_ADDRESS(BaseAddr, OffsetAddr) ((BaseAddr) + ((OffsetAddr) << 2))
|
||||
#define CREATE_DUAL_CMD(Cmd) ( ( Cmd << 16) | ( Cmd & LOW_16_BITS) )
|
||||
#define SEND_NOR_COMMAND(BaseAddr, Offset, Cmd) MmioWrite32 (CREATE_NOR_ADDRESS(BaseAddr,Offset), CREATE_DUAL_CMD(Cmd))
|
||||
#define GET_NOR_BLOCK_ADDRESS(BaseAddr, Lba, LbaSize) ( BaseAddr + (UINTN)((Lba) * LbaSize) )
|
||||
|
||||
// Status Register Bits
|
||||
#define P30_SR_BIT_WRITE (BIT7 << 16 | BIT7)
|
||||
#define P30_SR_BIT_ERASE_SUSPEND (BIT6 << 16 | BIT6)
|
||||
#define P30_SR_BIT_ERASE (BIT5 << 16 | BIT5)
|
||||
#define P30_SR_BIT_PROGRAM (BIT4 << 16 | BIT4)
|
||||
#define P30_SR_BIT_VPP (BIT3 << 16 | BIT3)
|
||||
#define P30_SR_BIT_PROGRAM_SUSPEND (BIT2 << 16 | BIT2)
|
||||
#define P30_SR_BIT_BLOCK_LOCKED (BIT1 << 16 | BIT1)
|
||||
#define P30_SR_BIT_BEFP (BIT0 << 16 | BIT0)
|
||||
#define P30_SR_BIT_WRITE (BIT7 << 16 | BIT7)
|
||||
#define P30_SR_BIT_ERASE_SUSPEND (BIT6 << 16 | BIT6)
|
||||
#define P30_SR_BIT_ERASE (BIT5 << 16 | BIT5)
|
||||
#define P30_SR_BIT_PROGRAM (BIT4 << 16 | BIT4)
|
||||
#define P30_SR_BIT_VPP (BIT3 << 16 | BIT3)
|
||||
#define P30_SR_BIT_PROGRAM_SUSPEND (BIT2 << 16 | BIT2)
|
||||
#define P30_SR_BIT_BLOCK_LOCKED (BIT1 << 16 | BIT1)
|
||||
#define P30_SR_BIT_BEFP (BIT0 << 16 | BIT0)
|
||||
|
||||
// Device Commands for Intel StrataFlash(R) Embedded Memory (P30) Family
|
||||
|
||||
// On chip buffer size for buffered programming operations
|
||||
// There are 2 chips, each chip can buffer up to 32 (16-bit)words, and each word is 2 bytes.
|
||||
// Therefore the total size of the buffer is 2 x 32 x 2 = 128 bytes
|
||||
#define P30_MAX_BUFFER_SIZE_IN_BYTES ((UINTN)128)
|
||||
#define P30_MAX_BUFFER_SIZE_IN_WORDS (P30_MAX_BUFFER_SIZE_IN_BYTES/((UINTN)4))
|
||||
#define MAX_BUFFERED_PROG_ITERATIONS 10000000
|
||||
#define BOUNDARY_OF_32_WORDS 0x7F
|
||||
#define P30_MAX_BUFFER_SIZE_IN_BYTES ((UINTN)128)
|
||||
#define P30_MAX_BUFFER_SIZE_IN_WORDS (P30_MAX_BUFFER_SIZE_IN_BYTES/((UINTN)4))
|
||||
#define MAX_BUFFERED_PROG_ITERATIONS 10000000
|
||||
#define BOUNDARY_OF_32_WORDS 0x7F
|
||||
|
||||
// CFI Addresses
|
||||
#define P30_CFI_ADDR_QUERY_UNIQUE_QRY 0x10
|
||||
#define P30_CFI_ADDR_VENDOR_ID 0x13
|
||||
#define P30_CFI_ADDR_QUERY_UNIQUE_QRY 0x10
|
||||
#define P30_CFI_ADDR_VENDOR_ID 0x13
|
||||
|
||||
// CFI Data
|
||||
#define CFI_QRY 0x00595251
|
||||
#define CFI_QRY 0x00595251
|
||||
|
||||
// READ Commands
|
||||
#define P30_CMD_READ_DEVICE_ID 0x0090
|
||||
#define P30_CMD_READ_STATUS_REGISTER 0x0070
|
||||
#define P30_CMD_CLEAR_STATUS_REGISTER 0x0050
|
||||
#define P30_CMD_READ_ARRAY 0x00FF
|
||||
#define P30_CMD_READ_CFI_QUERY 0x0098
|
||||
#define P30_CMD_READ_DEVICE_ID 0x0090
|
||||
#define P30_CMD_READ_STATUS_REGISTER 0x0070
|
||||
#define P30_CMD_CLEAR_STATUS_REGISTER 0x0050
|
||||
#define P30_CMD_READ_ARRAY 0x00FF
|
||||
#define P30_CMD_READ_CFI_QUERY 0x0098
|
||||
|
||||
// WRITE Commands
|
||||
#define P30_CMD_WORD_PROGRAM_SETUP 0x0040
|
||||
#define P30_CMD_ALTERNATE_WORD_PROGRAM_SETUP 0x0010
|
||||
#define P30_CMD_BUFFERED_PROGRAM_SETUP 0x00E8
|
||||
#define P30_CMD_BUFFERED_PROGRAM_CONFIRM 0x00D0
|
||||
#define P30_CMD_BEFP_SETUP 0x0080
|
||||
#define P30_CMD_BEFP_CONFIRM 0x00D0
|
||||
#define P30_CMD_WORD_PROGRAM_SETUP 0x0040
|
||||
#define P30_CMD_ALTERNATE_WORD_PROGRAM_SETUP 0x0010
|
||||
#define P30_CMD_BUFFERED_PROGRAM_SETUP 0x00E8
|
||||
#define P30_CMD_BUFFERED_PROGRAM_CONFIRM 0x00D0
|
||||
#define P30_CMD_BEFP_SETUP 0x0080
|
||||
#define P30_CMD_BEFP_CONFIRM 0x00D0
|
||||
|
||||
// ERASE Commands
|
||||
#define P30_CMD_BLOCK_ERASE_SETUP 0x0020
|
||||
#define P30_CMD_BLOCK_ERASE_CONFIRM 0x00D0
|
||||
#define P30_CMD_BLOCK_ERASE_SETUP 0x0020
|
||||
#define P30_CMD_BLOCK_ERASE_CONFIRM 0x00D0
|
||||
|
||||
// SUSPEND Commands
|
||||
#define P30_CMD_PROGRAM_OR_ERASE_SUSPEND 0x00B0
|
||||
#define P30_CMD_SUSPEND_RESUME 0x00D0
|
||||
#define P30_CMD_PROGRAM_OR_ERASE_SUSPEND 0x00B0
|
||||
#define P30_CMD_SUSPEND_RESUME 0x00D0
|
||||
|
||||
// BLOCK LOCKING / UNLOCKING Commands
|
||||
#define P30_CMD_LOCK_BLOCK_SETUP 0x0060
|
||||
#define P30_CMD_LOCK_BLOCK 0x0001
|
||||
#define P30_CMD_UNLOCK_BLOCK 0x00D0
|
||||
#define P30_CMD_LOCK_DOWN_BLOCK 0x002F
|
||||
#define P30_CMD_LOCK_BLOCK_SETUP 0x0060
|
||||
#define P30_CMD_LOCK_BLOCK 0x0001
|
||||
#define P30_CMD_UNLOCK_BLOCK 0x00D0
|
||||
#define P30_CMD_LOCK_DOWN_BLOCK 0x002F
|
||||
|
||||
// PROTECTION Commands
|
||||
#define P30_CMD_PROGRAM_PROTECTION_REGISTER_SETUP 0x00C0
|
||||
#define P30_CMD_PROGRAM_PROTECTION_REGISTER_SETUP 0x00C0
|
||||
|
||||
// CONFIGURATION Commands
|
||||
#define P30_CMD_READ_CONFIGURATION_REGISTER_SETUP 0x0060
|
||||
#define P30_CMD_READ_CONFIGURATION_REGISTER 0x0003
|
||||
#define P30_CMD_READ_CONFIGURATION_REGISTER_SETUP 0x0060
|
||||
#define P30_CMD_READ_CONFIGURATION_REGISTER 0x0003
|
||||
|
||||
#define NOR_FLASH_SIGNATURE SIGNATURE_32('n', 'o', 'r', '0')
|
||||
#define INSTANCE_FROM_FVB_THIS(a) CR(a, NOR_FLASH_INSTANCE, FvbProtocol, NOR_FLASH_SIGNATURE)
|
||||
#define INSTANCE_FROM_BLKIO_THIS(a) CR(a, NOR_FLASH_INSTANCE, BlockIoProtocol, NOR_FLASH_SIGNATURE)
|
||||
#define INSTANCE_FROM_DISKIO_THIS(a) CR(a, NOR_FLASH_INSTANCE, DiskIoProtocol, NOR_FLASH_SIGNATURE)
|
||||
#define NOR_FLASH_SIGNATURE SIGNATURE_32('n', 'o', 'r', '0')
|
||||
#define INSTANCE_FROM_FVB_THIS(a) CR(a, NOR_FLASH_INSTANCE, FvbProtocol, NOR_FLASH_SIGNATURE)
|
||||
#define INSTANCE_FROM_BLKIO_THIS(a) CR(a, NOR_FLASH_INSTANCE, BlockIoProtocol, NOR_FLASH_SIGNATURE)
|
||||
#define INSTANCE_FROM_DISKIO_THIS(a) CR(a, NOR_FLASH_INSTANCE, DiskIoProtocol, NOR_FLASH_SIGNATURE)
|
||||
|
||||
typedef struct _NOR_FLASH_INSTANCE NOR_FLASH_INSTANCE;
|
||||
typedef struct _NOR_FLASH_INSTANCE NOR_FLASH_INSTANCE;
|
||||
|
||||
#pragma pack (1)
|
||||
typedef struct {
|
||||
VENDOR_DEVICE_PATH Vendor;
|
||||
UINT8 Index;
|
||||
EFI_DEVICE_PATH_PROTOCOL End;
|
||||
VENDOR_DEVICE_PATH Vendor;
|
||||
UINT8 Index;
|
||||
EFI_DEVICE_PATH_PROTOCOL End;
|
||||
} NOR_FLASH_DEVICE_PATH;
|
||||
#pragma pack ()
|
||||
|
||||
struct _NOR_FLASH_INSTANCE {
|
||||
UINT32 Signature;
|
||||
EFI_HANDLE Handle;
|
||||
UINT32 Signature;
|
||||
EFI_HANDLE Handle;
|
||||
|
||||
UINTN DeviceBaseAddress;
|
||||
UINTN RegionBaseAddress;
|
||||
UINTN Size;
|
||||
EFI_LBA StartLba;
|
||||
UINTN DeviceBaseAddress;
|
||||
UINTN RegionBaseAddress;
|
||||
UINTN Size;
|
||||
EFI_LBA StartLba;
|
||||
|
||||
EFI_BLOCK_IO_PROTOCOL BlockIoProtocol;
|
||||
EFI_BLOCK_IO_MEDIA Media;
|
||||
EFI_DISK_IO_PROTOCOL DiskIoProtocol;
|
||||
EFI_BLOCK_IO_PROTOCOL BlockIoProtocol;
|
||||
EFI_BLOCK_IO_MEDIA Media;
|
||||
EFI_DISK_IO_PROTOCOL DiskIoProtocol;
|
||||
|
||||
EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol;
|
||||
VOID* ShadowBuffer;
|
||||
EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol;
|
||||
VOID *ShadowBuffer;
|
||||
|
||||
NOR_FLASH_DEVICE_PATH DevicePath;
|
||||
NOR_FLASH_DEVICE_PATH DevicePath;
|
||||
};
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashReadCfiData (
|
||||
IN UINTN DeviceBaseAddress,
|
||||
IN UINTN CFI_Offset,
|
||||
IN UINT32 NumberOfBytes,
|
||||
OUT UINT32 *Data
|
||||
IN UINTN DeviceBaseAddress,
|
||||
IN UINTN CFI_Offset,
|
||||
IN UINT32 NumberOfBytes,
|
||||
OUT UINT32 *Data
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashWriteBuffer (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN TargetAddress,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
IN UINT32 *Buffer
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN TargetAddress,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
IN UINT32 *Buffer
|
||||
);
|
||||
|
||||
//
|
||||
@@ -165,8 +164,8 @@ NorFlashWriteBuffer (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
NorFlashBlockIoReset (
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN BOOLEAN ExtendedVerification
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN BOOLEAN ExtendedVerification
|
||||
);
|
||||
|
||||
//
|
||||
@@ -175,12 +174,12 @@ NorFlashBlockIoReset (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
NorFlashBlockIoReadBlocks (
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
OUT VOID *Buffer
|
||||
);
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
OUT VOID *Buffer
|
||||
);
|
||||
|
||||
//
|
||||
// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
|
||||
@@ -188,12 +187,12 @@ NorFlashBlockIoReadBlocks (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
NorFlashBlockIoWriteBlocks (
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
IN VOID *Buffer
|
||||
);
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
IN VOID *Buffer
|
||||
);
|
||||
|
||||
//
|
||||
// BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
|
||||
@@ -201,8 +200,8 @@ NorFlashBlockIoWriteBlocks (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
NorFlashBlockIoFlushBlocks (
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This
|
||||
);
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This
|
||||
);
|
||||
|
||||
//
|
||||
// DiskIO Protocol function EFI_DISK_IO_PROTOCOL.ReadDisk
|
||||
@@ -210,11 +209,11 @@ NorFlashBlockIoFlushBlocks (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
NorFlashDiskIoReadDisk (
|
||||
IN EFI_DISK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN UINT64 Offset,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer
|
||||
IN EFI_DISK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN UINT64 Offset,
|
||||
IN UINTN BufferSize,
|
||||
OUT VOID *Buffer
|
||||
);
|
||||
|
||||
//
|
||||
@@ -223,11 +222,11 @@ NorFlashDiskIoReadDisk (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
NorFlashDiskIoWriteDisk (
|
||||
IN EFI_DISK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN UINT64 Offset,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer
|
||||
IN EFI_DISK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN UINT64 Offset,
|
||||
IN UINTN BufferSize,
|
||||
IN VOID *Buffer
|
||||
);
|
||||
|
||||
//
|
||||
@@ -236,76 +235,76 @@ NorFlashDiskIoWriteDisk (
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
FvbGetAttributes(
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
OUT EFI_FVB_ATTRIBUTES_2 *Attributes
|
||||
FvbGetAttributes (
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
OUT EFI_FVB_ATTRIBUTES_2 *Attributes
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
FvbSetAttributes(
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
|
||||
FvbSetAttributes (
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
FvbGetPhysicalAddress(
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
OUT EFI_PHYSICAL_ADDRESS *Address
|
||||
FvbGetPhysicalAddress (
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
OUT EFI_PHYSICAL_ADDRESS *Address
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
FvbGetBlockSize(
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
IN EFI_LBA Lba,
|
||||
OUT UINTN *BlockSize,
|
||||
OUT UINTN *NumberOfBlocks
|
||||
FvbGetBlockSize (
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
IN EFI_LBA Lba,
|
||||
OUT UINTN *BlockSize,
|
||||
OUT UINTN *NumberOfBlocks
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
FvbRead(
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN OUT UINTN *NumBytes,
|
||||
IN OUT UINT8 *Buffer
|
||||
FvbRead (
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN OUT UINTN *NumBytes,
|
||||
IN OUT UINT8 *Buffer
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
FvbWrite(
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN OUT UINTN *NumBytes,
|
||||
IN UINT8 *Buffer
|
||||
FvbWrite (
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN OUT UINTN *NumBytes,
|
||||
IN UINT8 *Buffer
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
FvbEraseBlocks(
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
FvbEraseBlocks (
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
...
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
ValidateFvHeader (
|
||||
IN NOR_FLASH_INSTANCE *Instance
|
||||
IN NOR_FLASH_INSTANCE *Instance
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
InitializeFvAndVariableStoreHeaders (
|
||||
IN NOR_FLASH_INSTANCE *Instance
|
||||
IN NOR_FLASH_INSTANCE *Instance
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
FvbVirtualNotifyEvent (
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
);
|
||||
|
||||
//
|
||||
@@ -314,111 +313,110 @@ FvbVirtualNotifyEvent (
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashWriteFullBlock (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINT32 *DataBuffer,
|
||||
IN UINT32 BlockSizeInWords
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINT32 *DataBuffer,
|
||||
IN UINT32 BlockSizeInWords
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashUnlockAndEraseSingleBlock (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashCreateInstance (
|
||||
IN UINTN NorFlashDeviceBase,
|
||||
IN UINTN NorFlashRegionBase,
|
||||
IN UINTN NorFlashSize,
|
||||
IN UINT32 Index,
|
||||
IN UINT32 BlockSize,
|
||||
IN BOOLEAN SupportFvb,
|
||||
OUT NOR_FLASH_INSTANCE** NorFlashInstance
|
||||
IN UINTN NorFlashDeviceBase,
|
||||
IN UINTN NorFlashRegionBase,
|
||||
IN UINTN NorFlashSize,
|
||||
IN UINT32 Index,
|
||||
IN UINT32 BlockSize,
|
||||
IN BOOLEAN SupportFvb,
|
||||
OUT NOR_FLASH_INSTANCE **NorFlashInstance
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
NorFlashFvbInitialize (
|
||||
IN NOR_FLASH_INSTANCE* Instance
|
||||
IN NOR_FLASH_INSTANCE *Instance
|
||||
);
|
||||
|
||||
|
||||
//
|
||||
// NorFlash.c
|
||||
//
|
||||
EFI_STATUS
|
||||
NorFlashWriteSingleBlock (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN OUT UINTN *NumBytes,
|
||||
IN UINT8 *Buffer
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN OUT UINTN *NumBytes,
|
||||
IN UINT8 *Buffer
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashWriteBlocks (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
IN VOID *Buffer
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
IN VOID *Buffer
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashReadBlocks (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
OUT VOID *Buffer
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
OUT VOID *Buffer
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashRead (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
OUT VOID *Buffer
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
OUT VOID *Buffer
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashWrite (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN OUT UINTN *NumBytes,
|
||||
IN UINT8 *Buffer
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN OUT UINTN *NumBytes,
|
||||
IN UINT8 *Buffer
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashReset (
|
||||
IN NOR_FLASH_INSTANCE *Instance
|
||||
IN NOR_FLASH_INSTANCE *Instance
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashEraseSingleBlock (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashUnlockSingleBlockIfNecessary (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
);
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashWriteSingleWord (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN WordAddress,
|
||||
IN UINT32 WriteData
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN WordAddress,
|
||||
IN UINT32 WriteData
|
||||
);
|
||||
|
||||
VOID
|
||||
EFIAPI
|
||||
NorFlashVirtualNotifyEvent (
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
);
|
||||
|
||||
#endif /* __NOR_FLASH_H__ */
|
||||
|
@@ -21,9 +21,9 @@ NorFlashBlockIoReset (
|
||||
IN BOOLEAN ExtendedVerification
|
||||
)
|
||||
{
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
|
||||
Instance = INSTANCE_FROM_BLKIO_THIS(This);
|
||||
Instance = INSTANCE_FROM_BLKIO_THIS (This);
|
||||
|
||||
DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReset(MediaId=0x%x)\n", This->Media->MediaId));
|
||||
|
||||
@@ -36,11 +36,11 @@ NorFlashBlockIoReset (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
NorFlashBlockIoReadBlocks (
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
OUT VOID *Buffer
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
OUT VOID *Buffer
|
||||
)
|
||||
{
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
@@ -51,8 +51,8 @@ NorFlashBlockIoReadBlocks (
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
Instance = INSTANCE_FROM_BLKIO_THIS(This);
|
||||
Media = This->Media;
|
||||
Instance = INSTANCE_FROM_BLKIO_THIS (This);
|
||||
Media = This->Media;
|
||||
|
||||
DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoReadBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
|
||||
|
||||
@@ -77,28 +77,28 @@ NorFlashBlockIoReadBlocks (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
NorFlashBlockIoWriteBlocks (
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
IN VOID *Buffer
|
||||
IN EFI_BLOCK_IO_PROTOCOL *This,
|
||||
IN UINT32 MediaId,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN BufferSizeInBytes,
|
||||
IN VOID *Buffer
|
||||
)
|
||||
{
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
EFI_STATUS Status;
|
||||
|
||||
Instance = INSTANCE_FROM_BLKIO_THIS(This);
|
||||
Instance = INSTANCE_FROM_BLKIO_THIS (This);
|
||||
|
||||
DEBUG ((DEBUG_BLKIO, "NorFlashBlockIoWriteBlocks(MediaId=0x%x, Lba=%ld, BufferSize=0x%x bytes (%d kB), BufferPtr @ 0x%08x)\n", MediaId, Lba, BufferSizeInBytes, Buffer));
|
||||
|
||||
if( !This->Media->MediaPresent ) {
|
||||
if ( !This->Media->MediaPresent ) {
|
||||
Status = EFI_NO_MEDIA;
|
||||
} else if( This->Media->MediaId != MediaId ) {
|
||||
} else if ( This->Media->MediaId != MediaId ) {
|
||||
Status = EFI_MEDIA_CHANGED;
|
||||
} else if( This->Media->ReadOnly ) {
|
||||
} else if ( This->Media->ReadOnly ) {
|
||||
Status = EFI_WRITE_PROTECTED;
|
||||
} else {
|
||||
Status = NorFlashWriteBlocks (Instance,Lba,BufferSizeInBytes,Buffer);
|
||||
Status = NorFlashWriteBlocks (Instance, Lba, BufferSizeInBytes, Buffer);
|
||||
}
|
||||
|
||||
return Status;
|
||||
|
@@ -16,19 +16,19 @@
|
||||
|
||||
#include "NorFlash.h"
|
||||
|
||||
STATIC EFI_EVENT mNorFlashVirtualAddrChangeEvent;
|
||||
STATIC EFI_EVENT mNorFlashVirtualAddrChangeEvent;
|
||||
|
||||
//
|
||||
// Global variable declarations
|
||||
//
|
||||
NOR_FLASH_INSTANCE **mNorFlashInstances;
|
||||
UINT32 mNorFlashDeviceCount;
|
||||
UINTN mFlashNvStorageVariableBase;
|
||||
EFI_EVENT mFvbVirtualAddrChangeEvent;
|
||||
NOR_FLASH_INSTANCE **mNorFlashInstances;
|
||||
UINT32 mNorFlashDeviceCount;
|
||||
UINTN mFlashNvStorageVariableBase;
|
||||
EFI_EVENT mFvbVirtualAddrChangeEvent;
|
||||
|
||||
NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = {
|
||||
NOR_FLASH_SIGNATURE, // Signature
|
||||
NULL, // Handle ... NEED TO BE FILLED
|
||||
NULL, // Handle ... NEED TO BE FILLED
|
||||
|
||||
0, // DeviceBaseAddress ... NEED TO BE FILLED
|
||||
0, // RegionBaseAddress ... NEED TO BE FILLED
|
||||
@@ -37,26 +37,26 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = {
|
||||
|
||||
{
|
||||
EFI_BLOCK_IO_PROTOCOL_REVISION2, // Revision
|
||||
NULL, // Media ... NEED TO BE FILLED
|
||||
NorFlashBlockIoReset, // Reset;
|
||||
NorFlashBlockIoReadBlocks, // ReadBlocks
|
||||
NorFlashBlockIoWriteBlocks, // WriteBlocks
|
||||
NorFlashBlockIoFlushBlocks // FlushBlocks
|
||||
NULL, // Media ... NEED TO BE FILLED
|
||||
NorFlashBlockIoReset, // Reset;
|
||||
NorFlashBlockIoReadBlocks, // ReadBlocks
|
||||
NorFlashBlockIoWriteBlocks, // WriteBlocks
|
||||
NorFlashBlockIoFlushBlocks // FlushBlocks
|
||||
}, // BlockIoProtocol
|
||||
|
||||
{
|
||||
0, // MediaId ... NEED TO BE FILLED
|
||||
0, // MediaId ... NEED TO BE FILLED
|
||||
FALSE, // RemovableMedia
|
||||
TRUE, // MediaPresent
|
||||
TRUE, // MediaPresent
|
||||
FALSE, // LogicalPartition
|
||||
FALSE, // ReadOnly
|
||||
FALSE, // WriteCaching;
|
||||
0, // BlockSize ... NEED TO BE FILLED
|
||||
4, // IoAlign
|
||||
0, // LastBlock ... NEED TO BE FILLED
|
||||
0, // LowestAlignedLba
|
||||
1, // LogicalBlocksPerPhysicalBlock
|
||||
}, //Media;
|
||||
0, // BlockSize ... NEED TO BE FILLED
|
||||
4, // IoAlign
|
||||
0, // LastBlock ... NEED TO BE FILLED
|
||||
0, // LowestAlignedLba
|
||||
1, // LogicalBlocksPerPhysicalBlock
|
||||
}, // Media;
|
||||
|
||||
{
|
||||
EFI_DISK_IO_PROTOCOL_REVISION, // Revision
|
||||
@@ -65,15 +65,15 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = {
|
||||
},
|
||||
|
||||
{
|
||||
FvbGetAttributes, // GetAttributes
|
||||
FvbSetAttributes, // SetAttributes
|
||||
FvbGetPhysicalAddress, // GetPhysicalAddress
|
||||
FvbGetBlockSize, // GetBlockSize
|
||||
FvbRead, // Read
|
||||
FvbWrite, // Write
|
||||
FvbEraseBlocks, // EraseBlocks
|
||||
NULL, //ParentHandle
|
||||
}, // FvbProtoccol;
|
||||
FvbGetAttributes, // GetAttributes
|
||||
FvbSetAttributes, // SetAttributes
|
||||
FvbGetPhysicalAddress, // GetPhysicalAddress
|
||||
FvbGetBlockSize, // GetBlockSize
|
||||
FvbRead, // Read
|
||||
FvbWrite, // Write
|
||||
FvbEraseBlocks, // EraseBlocks
|
||||
NULL, // ParentHandle
|
||||
}, // FvbProtoccol;
|
||||
NULL, // ShadowBuffer
|
||||
{
|
||||
{
|
||||
@@ -85,7 +85,8 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = {
|
||||
(UINT8)(OFFSET_OF (NOR_FLASH_DEVICE_PATH, End) >> 8)
|
||||
}
|
||||
},
|
||||
{ 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }, // GUID ... NEED TO BE FILLED
|
||||
{ 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }
|
||||
}, // GUID ... NEED TO BE FILLED
|
||||
},
|
||||
0, // Index
|
||||
{
|
||||
@@ -93,43 +94,43 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = {
|
||||
END_ENTIRE_DEVICE_PATH_SUBTYPE,
|
||||
{ sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }
|
||||
}
|
||||
} // DevicePath
|
||||
} // DevicePath
|
||||
};
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashCreateInstance (
|
||||
IN UINTN NorFlashDeviceBase,
|
||||
IN UINTN NorFlashRegionBase,
|
||||
IN UINTN NorFlashSize,
|
||||
IN UINT32 Index,
|
||||
IN UINT32 BlockSize,
|
||||
IN BOOLEAN SupportFvb,
|
||||
OUT NOR_FLASH_INSTANCE** NorFlashInstance
|
||||
IN UINTN NorFlashDeviceBase,
|
||||
IN UINTN NorFlashRegionBase,
|
||||
IN UINTN NorFlashSize,
|
||||
IN UINT32 Index,
|
||||
IN UINT32 BlockSize,
|
||||
IN BOOLEAN SupportFvb,
|
||||
OUT NOR_FLASH_INSTANCE **NorFlashInstance
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
NOR_FLASH_INSTANCE* Instance;
|
||||
EFI_STATUS Status;
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
|
||||
ASSERT(NorFlashInstance != NULL);
|
||||
ASSERT (NorFlashInstance != NULL);
|
||||
|
||||
Instance = AllocateRuntimeCopyPool (sizeof(NOR_FLASH_INSTANCE),&mNorFlashInstanceTemplate);
|
||||
Instance = AllocateRuntimeCopyPool (sizeof (NOR_FLASH_INSTANCE), &mNorFlashInstanceTemplate);
|
||||
if (Instance == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
Instance->DeviceBaseAddress = NorFlashDeviceBase;
|
||||
Instance->RegionBaseAddress = NorFlashRegionBase;
|
||||
Instance->Size = NorFlashSize;
|
||||
Instance->Size = NorFlashSize;
|
||||
|
||||
Instance->BlockIoProtocol.Media = &Instance->Media;
|
||||
Instance->Media.MediaId = Index;
|
||||
Instance->Media.BlockSize = BlockSize;
|
||||
Instance->Media.LastBlock = (NorFlashSize / BlockSize)-1;
|
||||
Instance->Media.MediaId = Index;
|
||||
Instance->Media.BlockSize = BlockSize;
|
||||
Instance->Media.LastBlock = (NorFlashSize / BlockSize)-1;
|
||||
|
||||
CopyGuid (&Instance->DevicePath.Vendor.Guid, &gEfiCallerIdGuid);
|
||||
Instance->DevicePath.Index = (UINT8)Index;
|
||||
|
||||
Instance->ShadowBuffer = AllocateRuntimePool (BlockSize);;
|
||||
Instance->ShadowBuffer = AllocateRuntimePool (BlockSize);
|
||||
if (Instance->ShadowBuffer == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
@@ -138,25 +139,31 @@ NorFlashCreateInstance (
|
||||
NorFlashFvbInitialize (Instance);
|
||||
|
||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||
&Instance->Handle,
|
||||
&gEfiDevicePathProtocolGuid, &Instance->DevicePath,
|
||||
&gEfiBlockIoProtocolGuid, &Instance->BlockIoProtocol,
|
||||
&gEfiFirmwareVolumeBlockProtocolGuid, &Instance->FvbProtocol,
|
||||
NULL
|
||||
);
|
||||
if (EFI_ERROR(Status)) {
|
||||
&Instance->Handle,
|
||||
&gEfiDevicePathProtocolGuid,
|
||||
&Instance->DevicePath,
|
||||
&gEfiBlockIoProtocolGuid,
|
||||
&Instance->BlockIoProtocol,
|
||||
&gEfiFirmwareVolumeBlockProtocolGuid,
|
||||
&Instance->FvbProtocol,
|
||||
NULL
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
FreePool (Instance);
|
||||
return Status;
|
||||
}
|
||||
} else {
|
||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||
&Instance->Handle,
|
||||
&gEfiDevicePathProtocolGuid, &Instance->DevicePath,
|
||||
&gEfiBlockIoProtocolGuid, &Instance->BlockIoProtocol,
|
||||
&gEfiDiskIoProtocolGuid, &Instance->DiskIoProtocol,
|
||||
&gEfiDevicePathProtocolGuid,
|
||||
&Instance->DevicePath,
|
||||
&gEfiBlockIoProtocolGuid,
|
||||
&Instance->BlockIoProtocol,
|
||||
&gEfiDiskIoProtocolGuid,
|
||||
&Instance->DiskIoProtocol,
|
||||
NULL
|
||||
);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (EFI_ERROR (Status)) {
|
||||
FreePool (Instance);
|
||||
return Status;
|
||||
}
|
||||
@@ -171,13 +178,13 @@ NorFlashCreateInstance (
|
||||
**/
|
||||
EFI_STATUS
|
||||
NorFlashUnlockAndEraseSingleBlock (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Index;
|
||||
EFI_TPL OriginalTPL;
|
||||
EFI_STATUS Status;
|
||||
UINTN Index;
|
||||
EFI_TPL OriginalTPL;
|
||||
|
||||
if (!EfiAtRuntime ()) {
|
||||
// Raise TPL to TPL_HIGH to stop anyone from interrupting us.
|
||||
@@ -196,12 +203,13 @@ NorFlashUnlockAndEraseSingleBlock (
|
||||
if (EFI_ERROR (Status)) {
|
||||
break;
|
||||
}
|
||||
|
||||
Status = NorFlashEraseSingleBlock (Instance, BlockAddress);
|
||||
Index++;
|
||||
} while ((Index < NOR_FLASH_ERASE_RETRY) && (Status == EFI_WRITE_PROTECTED));
|
||||
|
||||
if (Index == NOR_FLASH_ERASE_RETRY) {
|
||||
DEBUG((DEBUG_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error (try to erase %d times)\n", BlockAddress,Index));
|
||||
DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error (try to erase %d times)\n", BlockAddress, Index));
|
||||
}
|
||||
|
||||
if (!EfiAtRuntime ()) {
|
||||
@@ -214,21 +222,21 @@ NorFlashUnlockAndEraseSingleBlock (
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashWriteFullBlock (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINT32 *DataBuffer,
|
||||
IN UINT32 BlockSizeInWords
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINT32 *DataBuffer,
|
||||
IN UINT32 BlockSizeInWords
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN WordAddress;
|
||||
UINT32 WordIndex;
|
||||
UINTN BufferIndex;
|
||||
UINTN BlockAddress;
|
||||
UINTN BuffersInBlock;
|
||||
UINTN RemainingWords;
|
||||
EFI_TPL OriginalTPL;
|
||||
UINTN Cnt;
|
||||
EFI_STATUS Status;
|
||||
UINTN WordAddress;
|
||||
UINT32 WordIndex;
|
||||
UINTN BufferIndex;
|
||||
UINTN BlockAddress;
|
||||
UINTN BuffersInBlock;
|
||||
UINTN RemainingWords;
|
||||
EFI_TPL OriginalTPL;
|
||||
UINTN Cnt;
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
@@ -248,8 +256,8 @@ NorFlashWriteFullBlock (
|
||||
}
|
||||
|
||||
Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress);
|
||||
if (EFI_ERROR(Status)) {
|
||||
DEBUG((DEBUG_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and Erase the single block at 0x%X\n", BlockAddress));
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and Erase the single block at 0x%X\n", BlockAddress));
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
@@ -257,25 +265,30 @@ NorFlashWriteFullBlock (
|
||||
|
||||
// Check that the address starts at a 32-word boundary, i.e. last 7 bits must be zero
|
||||
if ((WordAddress & BOUNDARY_OF_32_WORDS) == 0x00) {
|
||||
|
||||
// First, break the entire block into buffer-sized chunks.
|
||||
BuffersInBlock = (UINTN)(BlockSizeInWords * 4) / P30_MAX_BUFFER_SIZE_IN_BYTES;
|
||||
|
||||
// Then feed each buffer chunk to the NOR Flash
|
||||
// If a buffer does not contain any data, don't write it.
|
||||
for(BufferIndex=0;
|
||||
for (BufferIndex = 0;
|
||||
BufferIndex < BuffersInBlock;
|
||||
BufferIndex++, WordAddress += P30_MAX_BUFFER_SIZE_IN_BYTES, DataBuffer += P30_MAX_BUFFER_SIZE_IN_WORDS
|
||||
) {
|
||||
)
|
||||
{
|
||||
// Check the buffer to see if it contains any data (not set all 1s).
|
||||
for (Cnt = 0; Cnt < P30_MAX_BUFFER_SIZE_IN_WORDS; Cnt++) {
|
||||
if (~DataBuffer[Cnt] != 0 ) {
|
||||
// Some data found, write the buffer.
|
||||
Status = NorFlashWriteBuffer (Instance, WordAddress, P30_MAX_BUFFER_SIZE_IN_BYTES,
|
||||
DataBuffer);
|
||||
if (EFI_ERROR(Status)) {
|
||||
Status = NorFlashWriteBuffer (
|
||||
Instance,
|
||||
WordAddress,
|
||||
P30_MAX_BUFFER_SIZE_IN_BYTES,
|
||||
DataBuffer
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -284,20 +297,19 @@ NorFlashWriteFullBlock (
|
||||
// Finally, finish off any remaining words that are less than the maximum size of the buffer
|
||||
RemainingWords = BlockSizeInWords % P30_MAX_BUFFER_SIZE_IN_WORDS;
|
||||
|
||||
if(RemainingWords != 0) {
|
||||
if (RemainingWords != 0) {
|
||||
Status = NorFlashWriteBuffer (Instance, WordAddress, (RemainingWords * 4), DataBuffer);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto EXIT;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// For now, use the single word programming algorithm
|
||||
// It is unlikely that the NOR Flash will exist in an address which falls within a 32 word boundary range,
|
||||
// i.e. which ends in the range 0x......01 - 0x......7F.
|
||||
for(WordIndex=0; WordIndex<BlockSizeInWords; WordIndex++, DataBuffer++, WordAddress = WordAddress + 4) {
|
||||
for (WordIndex = 0; WordIndex < BlockSizeInWords; WordIndex++, DataBuffer++, WordAddress = WordAddress + 4) {
|
||||
Status = NorFlashWriteSingleWord (Instance, WordAddress, *DataBuffer);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto EXIT;
|
||||
}
|
||||
}
|
||||
@@ -309,64 +321,65 @@ EXIT:
|
||||
gBS->RestoreTPL (OriginalTPL);
|
||||
}
|
||||
|
||||
if (EFI_ERROR(Status)) {
|
||||
DEBUG((DEBUG_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed at address 0x%08x. Exit Status = \"%r\".\n", WordAddress, Status));
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed at address 0x%08x. Exit Status = \"%r\".\n", WordAddress, Status));
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
NorFlashInitialise (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 Index;
|
||||
NOR_FLASH_DESCRIPTION* NorFlashDevices;
|
||||
BOOLEAN ContainVariableStorage;
|
||||
EFI_STATUS Status;
|
||||
UINT32 Index;
|
||||
NOR_FLASH_DESCRIPTION *NorFlashDevices;
|
||||
BOOLEAN ContainVariableStorage;
|
||||
|
||||
Status = NorFlashPlatformInitialization ();
|
||||
if (EFI_ERROR(Status)) {
|
||||
DEBUG((DEBUG_ERROR,"NorFlashInitialise: Fail to initialize Nor Flash devices\n"));
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to initialize Nor Flash devices\n"));
|
||||
return Status;
|
||||
}
|
||||
|
||||
Status = NorFlashPlatformGetDevices (&NorFlashDevices, &mNorFlashDeviceCount);
|
||||
if (EFI_ERROR(Status)) {
|
||||
DEBUG((DEBUG_ERROR,"NorFlashInitialise: Fail to get Nor Flash devices\n"));
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to get Nor Flash devices\n"));
|
||||
return Status;
|
||||
}
|
||||
|
||||
mNorFlashInstances = AllocateRuntimePool (sizeof(NOR_FLASH_INSTANCE*) * mNorFlashDeviceCount);
|
||||
mNorFlashInstances = AllocateRuntimePool (sizeof (NOR_FLASH_INSTANCE *) * mNorFlashDeviceCount);
|
||||
|
||||
for (Index = 0; Index < mNorFlashDeviceCount; Index++) {
|
||||
// Check if this NOR Flash device contain the variable storage region
|
||||
|
||||
if (PcdGet64 (PcdFlashNvStorageVariableBase64) != 0) {
|
||||
ContainVariableStorage =
|
||||
(NorFlashDevices[Index].RegionBaseAddress <= PcdGet64 (PcdFlashNvStorageVariableBase64)) &&
|
||||
(PcdGet64 (PcdFlashNvStorageVariableBase64) + PcdGet32 (PcdFlashNvStorageVariableSize) <=
|
||||
NorFlashDevices[Index].RegionBaseAddress + NorFlashDevices[Index].Size);
|
||||
} else {
|
||||
ContainVariableStorage =
|
||||
(NorFlashDevices[Index].RegionBaseAddress <= PcdGet32 (PcdFlashNvStorageVariableBase)) &&
|
||||
(PcdGet32 (PcdFlashNvStorageVariableBase) + PcdGet32 (PcdFlashNvStorageVariableSize) <=
|
||||
NorFlashDevices[Index].RegionBaseAddress + NorFlashDevices[Index].Size);
|
||||
}
|
||||
if (PcdGet64 (PcdFlashNvStorageVariableBase64) != 0) {
|
||||
ContainVariableStorage =
|
||||
(NorFlashDevices[Index].RegionBaseAddress <= PcdGet64 (PcdFlashNvStorageVariableBase64)) &&
|
||||
(PcdGet64 (PcdFlashNvStorageVariableBase64) + PcdGet32 (PcdFlashNvStorageVariableSize) <=
|
||||
NorFlashDevices[Index].RegionBaseAddress + NorFlashDevices[Index].Size);
|
||||
} else {
|
||||
ContainVariableStorage =
|
||||
(NorFlashDevices[Index].RegionBaseAddress <= PcdGet32 (PcdFlashNvStorageVariableBase)) &&
|
||||
(PcdGet32 (PcdFlashNvStorageVariableBase) + PcdGet32 (PcdFlashNvStorageVariableSize) <=
|
||||
NorFlashDevices[Index].RegionBaseAddress + NorFlashDevices[Index].Size);
|
||||
}
|
||||
|
||||
Status = NorFlashCreateInstance (
|
||||
NorFlashDevices[Index].DeviceBaseAddress,
|
||||
NorFlashDevices[Index].RegionBaseAddress,
|
||||
NorFlashDevices[Index].Size,
|
||||
Index,
|
||||
NorFlashDevices[Index].BlockSize,
|
||||
ContainVariableStorage,
|
||||
&mNorFlashInstances[Index]
|
||||
);
|
||||
if (EFI_ERROR(Status)) {
|
||||
DEBUG((DEBUG_ERROR,"NorFlashInitialise: Fail to create instance for NorFlash[%d]\n",Index));
|
||||
NorFlashDevices[Index].DeviceBaseAddress,
|
||||
NorFlashDevices[Index].RegionBaseAddress,
|
||||
NorFlashDevices[Index].Size,
|
||||
Index,
|
||||
NorFlashDevices[Index].BlockSize,
|
||||
ContainVariableStorage,
|
||||
&mNorFlashInstances[Index]
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to create instance for NorFlash[%d]\n", Index));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,16 +402,16 @@ NorFlashInitialise (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
NorFlashFvbInitialize (
|
||||
IN NOR_FLASH_INSTANCE* Instance
|
||||
IN NOR_FLASH_INSTANCE *Instance
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 FvbNumLba;
|
||||
EFI_BOOT_MODE BootMode;
|
||||
UINTN RuntimeMmioRegionSize;
|
||||
EFI_STATUS Status;
|
||||
UINT32 FvbNumLba;
|
||||
EFI_BOOT_MODE BootMode;
|
||||
UINTN RuntimeMmioRegionSize;
|
||||
|
||||
DEBUG((DEBUG_BLKIO,"NorFlashFvbInitialize\n"));
|
||||
ASSERT((Instance != NULL));
|
||||
DEBUG ((DEBUG_BLKIO, "NorFlashFvbInitialize\n"));
|
||||
ASSERT ((Instance != NULL));
|
||||
|
||||
//
|
||||
// Declare the Non-Volatile storage as EFI_MEMORY_RUNTIME
|
||||
@@ -411,19 +424,22 @@ NorFlashFvbInitialize (
|
||||
RuntimeMmioRegionSize = (Instance->RegionBaseAddress - Instance->DeviceBaseAddress) + Instance->Size;
|
||||
|
||||
Status = gDS->AddMemorySpace (
|
||||
EfiGcdMemoryTypeMemoryMappedIo,
|
||||
Instance->DeviceBaseAddress, RuntimeMmioRegionSize,
|
||||
EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
|
||||
);
|
||||
EfiGcdMemoryTypeMemoryMappedIo,
|
||||
Instance->DeviceBaseAddress,
|
||||
RuntimeMmioRegionSize,
|
||||
EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
Status = gDS->SetMemorySpaceAttributes (
|
||||
Instance->DeviceBaseAddress, RuntimeMmioRegionSize,
|
||||
EFI_MEMORY_UC | EFI_MEMORY_RUNTIME);
|
||||
Instance->DeviceBaseAddress,
|
||||
RuntimeMmioRegionSize,
|
||||
EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
mFlashNvStorageVariableBase = (PcdGet64 (PcdFlashNvStorageVariableBase64) != 0) ?
|
||||
PcdGet64 (PcdFlashNvStorageVariableBase64) : PcdGet32 (PcdFlashNvStorageVariableBase);
|
||||
PcdGet64 (PcdFlashNvStorageVariableBase64) : PcdGet32 (PcdFlashNvStorageVariableBase);
|
||||
|
||||
// Set the index of the first LBA for the FVB
|
||||
Instance->StartLba = (mFlashNvStorageVariableBase - Instance->RegionBaseAddress) / Instance->Media.BlockSize;
|
||||
@@ -437,23 +453,26 @@ NorFlashFvbInitialize (
|
||||
}
|
||||
|
||||
// Install the Default FVB header if required
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (EFI_ERROR (Status)) {
|
||||
// There is no valid header, so time to install one.
|
||||
DEBUG ((DEBUG_INFO, "%a: The FVB Header is not valid.\n", __FUNCTION__));
|
||||
DEBUG ((DEBUG_INFO, "%a: Installing a correct one for this volume.\n",
|
||||
__FUNCTION__));
|
||||
DEBUG ((
|
||||
DEBUG_INFO,
|
||||
"%a: Installing a correct one for this volume.\n",
|
||||
__FUNCTION__
|
||||
));
|
||||
|
||||
// Erase all the NorFlash that is reserved for variable storage
|
||||
FvbNumLba = (PcdGet32(PcdFlashNvStorageVariableSize) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) + PcdGet32(PcdFlashNvStorageFtwSpareSize)) / Instance->Media.BlockSize;
|
||||
FvbNumLba = (PcdGet32 (PcdFlashNvStorageVariableSize) + PcdGet32 (PcdFlashNvStorageFtwWorkingSize) + PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / Instance->Media.BlockSize;
|
||||
|
||||
Status = FvbEraseBlocks (&Instance->FvbProtocol, (EFI_LBA)0, FvbNumLba, EFI_LBA_LIST_TERMINATOR);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
// Install all appropriate headers
|
||||
Status = InitializeFvAndVariableStoreHeaders (Instance);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "NorFlash.h"
|
||||
|
||||
extern UINTN mFlashNvStorageVariableBase;
|
||||
extern UINTN mFlashNvStorageVariableBase;
|
||||
///
|
||||
/// The Firmware Volume Block Protocol is the low-level interface
|
||||
/// to a firmware volume. File-level access to a firmware volume
|
||||
@@ -40,71 +40,90 @@ extern UINTN mFlashNvStorageVariableBase;
|
||||
**/
|
||||
EFI_STATUS
|
||||
InitializeFvAndVariableStoreHeaders (
|
||||
IN NOR_FLASH_INSTANCE *Instance
|
||||
IN NOR_FLASH_INSTANCE *Instance
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
VOID* Headers;
|
||||
UINTN HeadersLength;
|
||||
EFI_FIRMWARE_VOLUME_HEADER *FirmwareVolumeHeader;
|
||||
VARIABLE_STORE_HEADER *VariableStoreHeader;
|
||||
UINT32 NvStorageFtwSpareSize;
|
||||
UINT32 NvStorageFtwWorkingSize;
|
||||
UINT32 NvStorageVariableSize;
|
||||
UINT64 NvStorageFtwSpareBase;
|
||||
UINT64 NvStorageFtwWorkingBase;
|
||||
UINT64 NvStorageVariableBase;
|
||||
EFI_STATUS Status;
|
||||
VOID *Headers;
|
||||
UINTN HeadersLength;
|
||||
EFI_FIRMWARE_VOLUME_HEADER *FirmwareVolumeHeader;
|
||||
VARIABLE_STORE_HEADER *VariableStoreHeader;
|
||||
UINT32 NvStorageFtwSpareSize;
|
||||
UINT32 NvStorageFtwWorkingSize;
|
||||
UINT32 NvStorageVariableSize;
|
||||
UINT64 NvStorageFtwSpareBase;
|
||||
UINT64 NvStorageFtwWorkingBase;
|
||||
UINT64 NvStorageVariableBase;
|
||||
|
||||
HeadersLength = sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY) + sizeof(VARIABLE_STORE_HEADER);
|
||||
Headers = AllocateZeroPool(HeadersLength);
|
||||
HeadersLength = sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY) + sizeof (VARIABLE_STORE_HEADER);
|
||||
Headers = AllocateZeroPool (HeadersLength);
|
||||
|
||||
NvStorageFtwWorkingSize = PcdGet32 (PcdFlashNvStorageFtwWorkingSize);
|
||||
NvStorageFtwSpareSize = PcdGet32 (PcdFlashNvStorageFtwSpareSize);
|
||||
NvStorageVariableSize = PcdGet32 (PcdFlashNvStorageVariableSize);
|
||||
NvStorageFtwSpareSize = PcdGet32 (PcdFlashNvStorageFtwSpareSize);
|
||||
NvStorageVariableSize = PcdGet32 (PcdFlashNvStorageVariableSize);
|
||||
|
||||
NvStorageFtwSpareBase = (PcdGet64 (PcdFlashNvStorageFtwSpareBase64) != 0) ?
|
||||
PcdGet64 (PcdFlashNvStorageFtwSpareBase64) : PcdGet32 (PcdFlashNvStorageFtwSpareBase);
|
||||
PcdGet64 (PcdFlashNvStorageFtwSpareBase64) : PcdGet32 (PcdFlashNvStorageFtwSpareBase);
|
||||
NvStorageFtwWorkingBase = (PcdGet64 (PcdFlashNvStorageFtwWorkingBase64) != 0) ?
|
||||
PcdGet64 (PcdFlashNvStorageFtwWorkingBase64) : PcdGet32 (PcdFlashNvStorageFtwWorkingBase);
|
||||
PcdGet64 (PcdFlashNvStorageFtwWorkingBase64) : PcdGet32 (PcdFlashNvStorageFtwWorkingBase);
|
||||
NvStorageVariableBase = (PcdGet64 (PcdFlashNvStorageVariableBase64) != 0) ?
|
||||
PcdGet64 (PcdFlashNvStorageVariableBase64) : PcdGet32 (PcdFlashNvStorageVariableBase);
|
||||
PcdGet64 (PcdFlashNvStorageVariableBase64) : PcdGet32 (PcdFlashNvStorageVariableBase);
|
||||
|
||||
// FirmwareVolumeHeader->FvLength is declared to have the Variable area AND the FTW working area AND the FTW Spare contiguous.
|
||||
if ((NvStorageVariableBase + NvStorageVariableSize) != NvStorageFtwWorkingBase) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: NvStorageFtwWorkingBase is not contiguous with NvStorageVariableBase region\n",
|
||||
__FUNCTION__));
|
||||
DEBUG ((
|
||||
DEBUG_ERROR,
|
||||
"%a: NvStorageFtwWorkingBase is not contiguous with NvStorageVariableBase region\n",
|
||||
__FUNCTION__
|
||||
));
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if ((NvStorageFtwWorkingBase + NvStorageFtwWorkingSize) != NvStorageFtwSpareBase) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: NvStorageFtwSpareBase is not contiguous with NvStorageFtwWorkingBase region\n",
|
||||
__FUNCTION__));
|
||||
DEBUG ((
|
||||
DEBUG_ERROR,
|
||||
"%a: NvStorageFtwSpareBase is not contiguous with NvStorageFtwWorkingBase region\n",
|
||||
__FUNCTION__
|
||||
));
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
// Check if the size of the area is at least one block size
|
||||
if ((NvStorageVariableSize <= 0) || (NvStorageVariableSize / Instance->Media.BlockSize <= 0)) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: NvStorageVariableSize is 0x%x, should be atleast one block size\n", __FUNCTION__,
|
||||
NvStorageVariableSize));
|
||||
DEBUG ((
|
||||
DEBUG_ERROR,
|
||||
"%a: NvStorageVariableSize is 0x%x, should be atleast one block size\n",
|
||||
__FUNCTION__,
|
||||
NvStorageVariableSize
|
||||
));
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if ((NvStorageFtwWorkingSize <= 0) || (NvStorageFtwWorkingSize / Instance->Media.BlockSize <= 0)) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: NvStorageFtwWorkingSize is 0x%x, should be atleast one block size\n", __FUNCTION__,
|
||||
NvStorageFtwWorkingSize));
|
||||
DEBUG ((
|
||||
DEBUG_ERROR,
|
||||
"%a: NvStorageFtwWorkingSize is 0x%x, should be atleast one block size\n",
|
||||
__FUNCTION__,
|
||||
NvStorageFtwWorkingSize
|
||||
));
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if ((NvStorageFtwSpareSize <= 0) || (NvStorageFtwSpareSize / Instance->Media.BlockSize <= 0)) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: NvStorageFtwSpareSize is 0x%x, should be atleast one block size\n", __FUNCTION__,
|
||||
NvStorageFtwSpareSize));
|
||||
DEBUG ((
|
||||
DEBUG_ERROR,
|
||||
"%a: NvStorageFtwSpareSize is 0x%x, should be atleast one block size\n",
|
||||
__FUNCTION__,
|
||||
NvStorageFtwSpareSize
|
||||
));
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
// Ensure the Variable area Base Addresses are aligned on a block size boundaries
|
||||
if ((NvStorageVariableBase % Instance->Media.BlockSize != 0) ||
|
||||
(NvStorageFtwWorkingBase % Instance->Media.BlockSize != 0) ||
|
||||
(NvStorageFtwSpareBase % Instance->Media.BlockSize != 0)) {
|
||||
(NvStorageFtwSpareBase % Instance->Media.BlockSize != 0))
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "%a: NvStorage Base addresses must be aligned to block size boundaries", __FUNCTION__));
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
@@ -112,38 +131,38 @@ InitializeFvAndVariableStoreHeaders (
|
||||
//
|
||||
// EFI_FIRMWARE_VOLUME_HEADER
|
||||
//
|
||||
FirmwareVolumeHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Headers;
|
||||
FirmwareVolumeHeader = (EFI_FIRMWARE_VOLUME_HEADER *)Headers;
|
||||
CopyGuid (&FirmwareVolumeHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid);
|
||||
FirmwareVolumeHeader->FvLength =
|
||||
PcdGet32(PcdFlashNvStorageVariableSize) +
|
||||
PcdGet32(PcdFlashNvStorageFtwWorkingSize) +
|
||||
PcdGet32(PcdFlashNvStorageFtwSpareSize);
|
||||
FirmwareVolumeHeader->Signature = EFI_FVH_SIGNATURE;
|
||||
FirmwareVolumeHeader->Attributes = (EFI_FVB_ATTRIBUTES_2) (
|
||||
EFI_FVB2_READ_ENABLED_CAP | // Reads may be enabled
|
||||
EFI_FVB2_READ_STATUS | // Reads are currently enabled
|
||||
EFI_FVB2_STICKY_WRITE | // A block erase is required to flip bits into EFI_FVB2_ERASE_POLARITY
|
||||
EFI_FVB2_MEMORY_MAPPED | // It is memory mapped
|
||||
EFI_FVB2_ERASE_POLARITY | // After erasure all bits take this value (i.e. '1')
|
||||
EFI_FVB2_WRITE_STATUS | // Writes are currently enabled
|
||||
EFI_FVB2_WRITE_ENABLED_CAP // Writes may be enabled
|
||||
);
|
||||
FirmwareVolumeHeader->HeaderLength = sizeof(EFI_FIRMWARE_VOLUME_HEADER) + sizeof(EFI_FV_BLOCK_MAP_ENTRY);
|
||||
FirmwareVolumeHeader->Revision = EFI_FVH_REVISION;
|
||||
PcdGet32 (PcdFlashNvStorageVariableSize) +
|
||||
PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
|
||||
PcdGet32 (PcdFlashNvStorageFtwSpareSize);
|
||||
FirmwareVolumeHeader->Signature = EFI_FVH_SIGNATURE;
|
||||
FirmwareVolumeHeader->Attributes = (EFI_FVB_ATTRIBUTES_2)(
|
||||
EFI_FVB2_READ_ENABLED_CAP | // Reads may be enabled
|
||||
EFI_FVB2_READ_STATUS | // Reads are currently enabled
|
||||
EFI_FVB2_STICKY_WRITE | // A block erase is required to flip bits into EFI_FVB2_ERASE_POLARITY
|
||||
EFI_FVB2_MEMORY_MAPPED | // It is memory mapped
|
||||
EFI_FVB2_ERASE_POLARITY | // After erasure all bits take this value (i.e. '1')
|
||||
EFI_FVB2_WRITE_STATUS | // Writes are currently enabled
|
||||
EFI_FVB2_WRITE_ENABLED_CAP // Writes may be enabled
|
||||
);
|
||||
FirmwareVolumeHeader->HeaderLength = sizeof (EFI_FIRMWARE_VOLUME_HEADER) + sizeof (EFI_FV_BLOCK_MAP_ENTRY);
|
||||
FirmwareVolumeHeader->Revision = EFI_FVH_REVISION;
|
||||
FirmwareVolumeHeader->BlockMap[0].NumBlocks = Instance->Media.LastBlock + 1;
|
||||
FirmwareVolumeHeader->BlockMap[0].Length = Instance->Media.BlockSize;
|
||||
FirmwareVolumeHeader->BlockMap[0].Length = Instance->Media.BlockSize;
|
||||
FirmwareVolumeHeader->BlockMap[1].NumBlocks = 0;
|
||||
FirmwareVolumeHeader->BlockMap[1].Length = 0;
|
||||
FirmwareVolumeHeader->Checksum = CalculateCheckSum16 ((UINT16*)FirmwareVolumeHeader,FirmwareVolumeHeader->HeaderLength);
|
||||
FirmwareVolumeHeader->BlockMap[1].Length = 0;
|
||||
FirmwareVolumeHeader->Checksum = CalculateCheckSum16 ((UINT16 *)FirmwareVolumeHeader, FirmwareVolumeHeader->HeaderLength);
|
||||
|
||||
//
|
||||
// VARIABLE_STORE_HEADER
|
||||
//
|
||||
VariableStoreHeader = (VARIABLE_STORE_HEADER*)((UINTN)Headers + FirmwareVolumeHeader->HeaderLength);
|
||||
VariableStoreHeader = (VARIABLE_STORE_HEADER *)((UINTN)Headers + FirmwareVolumeHeader->HeaderLength);
|
||||
CopyGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVariableGuid);
|
||||
VariableStoreHeader->Size = PcdGet32(PcdFlashNvStorageVariableSize) - FirmwareVolumeHeader->HeaderLength;
|
||||
VariableStoreHeader->Format = VARIABLE_STORE_FORMATTED;
|
||||
VariableStoreHeader->State = VARIABLE_STORE_HEALTHY;
|
||||
VariableStoreHeader->Size = PcdGet32 (PcdFlashNvStorageVariableSize) - FirmwareVolumeHeader->HeaderLength;
|
||||
VariableStoreHeader->Format = VARIABLE_STORE_FORMATTED;
|
||||
VariableStoreHeader->State = VARIABLE_STORE_HEALTHY;
|
||||
|
||||
// Install the combined super-header in the NorFlash
|
||||
Status = FvbWrite (&Instance->FvbProtocol, 0, 0, &HeadersLength, Headers);
|
||||
@@ -163,7 +182,7 @@ InitializeFvAndVariableStoreHeaders (
|
||||
**/
|
||||
EFI_STATUS
|
||||
ValidateFvHeader (
|
||||
IN NOR_FLASH_INSTANCE *Instance
|
||||
IN NOR_FLASH_INSTANCE *Instance
|
||||
)
|
||||
{
|
||||
UINT16 Checksum;
|
||||
@@ -172,55 +191,72 @@ ValidateFvHeader (
|
||||
UINTN VariableStoreLength;
|
||||
UINTN FvLength;
|
||||
|
||||
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER*)Instance->RegionBaseAddress;
|
||||
FwVolHeader = (EFI_FIRMWARE_VOLUME_HEADER *)Instance->RegionBaseAddress;
|
||||
|
||||
FvLength = PcdGet32(PcdFlashNvStorageVariableSize) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) +
|
||||
PcdGet32(PcdFlashNvStorageFtwSpareSize);
|
||||
FvLength = PcdGet32 (PcdFlashNvStorageVariableSize) + PcdGet32 (PcdFlashNvStorageFtwWorkingSize) +
|
||||
PcdGet32 (PcdFlashNvStorageFtwSpareSize);
|
||||
|
||||
//
|
||||
// Verify the header revision, header signature, length
|
||||
// Length of FvBlock cannot be 2**64-1
|
||||
// HeaderLength cannot be an odd number
|
||||
//
|
||||
if ( (FwVolHeader->Revision != EFI_FVH_REVISION)
|
||||
|| (FwVolHeader->Signature != EFI_FVH_SIGNATURE)
|
||||
|| (FwVolHeader->FvLength != FvLength)
|
||||
)
|
||||
if ( (FwVolHeader->Revision != EFI_FVH_REVISION)
|
||||
|| (FwVolHeader->Signature != EFI_FVH_SIGNATURE)
|
||||
|| (FwVolHeader->FvLength != FvLength)
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_INFO, "%a: No Firmware Volume header present\n",
|
||||
__FUNCTION__));
|
||||
DEBUG ((
|
||||
DEBUG_INFO,
|
||||
"%a: No Firmware Volume header present\n",
|
||||
__FUNCTION__
|
||||
));
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
// Check the Firmware Volume Guid
|
||||
if( CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid) == FALSE ) {
|
||||
DEBUG ((DEBUG_INFO, "%a: Firmware Volume Guid non-compatible\n",
|
||||
__FUNCTION__));
|
||||
if ( CompareGuid (&FwVolHeader->FileSystemGuid, &gEfiSystemNvDataFvGuid) == FALSE ) {
|
||||
DEBUG ((
|
||||
DEBUG_INFO,
|
||||
"%a: Firmware Volume Guid non-compatible\n",
|
||||
__FUNCTION__
|
||||
));
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
// Verify the header checksum
|
||||
Checksum = CalculateSum16((UINT16*)FwVolHeader, FwVolHeader->HeaderLength);
|
||||
Checksum = CalculateSum16 ((UINT16 *)FwVolHeader, FwVolHeader->HeaderLength);
|
||||
if (Checksum != 0) {
|
||||
DEBUG ((DEBUG_INFO, "%a: FV checksum is invalid (Checksum:0x%X)\n",
|
||||
__FUNCTION__, Checksum));
|
||||
DEBUG ((
|
||||
DEBUG_INFO,
|
||||
"%a: FV checksum is invalid (Checksum:0x%X)\n",
|
||||
__FUNCTION__,
|
||||
Checksum
|
||||
));
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
VariableStoreHeader = (VARIABLE_STORE_HEADER*)((UINTN)FwVolHeader + FwVolHeader->HeaderLength);
|
||||
VariableStoreHeader = (VARIABLE_STORE_HEADER *)((UINTN)FwVolHeader + FwVolHeader->HeaderLength);
|
||||
|
||||
// Check the Variable Store Guid
|
||||
if (!CompareGuid (&VariableStoreHeader->Signature, &gEfiVariableGuid) &&
|
||||
!CompareGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVariableGuid)) {
|
||||
DEBUG ((DEBUG_INFO, "%a: Variable Store Guid non-compatible\n",
|
||||
__FUNCTION__));
|
||||
!CompareGuid (&VariableStoreHeader->Signature, &gEfiAuthenticatedVariableGuid))
|
||||
{
|
||||
DEBUG ((
|
||||
DEBUG_INFO,
|
||||
"%a: Variable Store Guid non-compatible\n",
|
||||
__FUNCTION__
|
||||
));
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
VariableStoreLength = PcdGet32 (PcdFlashNvStorageVariableSize) - FwVolHeader->HeaderLength;
|
||||
if (VariableStoreHeader->Size != VariableStoreLength) {
|
||||
DEBUG ((DEBUG_INFO, "%a: Variable Store Length does not match\n",
|
||||
__FUNCTION__));
|
||||
DEBUG ((
|
||||
DEBUG_INFO,
|
||||
"%a: Variable Store Length does not match\n",
|
||||
__FUNCTION__
|
||||
));
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
@@ -242,29 +278,28 @@ ValidateFvHeader (
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
FvbGetAttributes(
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
OUT EFI_FVB_ATTRIBUTES_2 *Attributes
|
||||
FvbGetAttributes (
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
OUT EFI_FVB_ATTRIBUTES_2 *Attributes
|
||||
)
|
||||
{
|
||||
EFI_FVB_ATTRIBUTES_2 FlashFvbAttributes;
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
|
||||
Instance = INSTANCE_FROM_FVB_THIS(This);
|
||||
Instance = INSTANCE_FROM_FVB_THIS (This);
|
||||
|
||||
FlashFvbAttributes = (EFI_FVB_ATTRIBUTES_2) (
|
||||
FlashFvbAttributes = (EFI_FVB_ATTRIBUTES_2)(
|
||||
|
||||
EFI_FVB2_READ_ENABLED_CAP | // Reads may be enabled
|
||||
EFI_FVB2_READ_STATUS | // Reads are currently enabled
|
||||
EFI_FVB2_STICKY_WRITE | // A block erase is required to flip bits into EFI_FVB2_ERASE_POLARITY
|
||||
EFI_FVB2_MEMORY_MAPPED | // It is memory mapped
|
||||
EFI_FVB2_ERASE_POLARITY // After erasure all bits take this value (i.e. '1')
|
||||
EFI_FVB2_READ_ENABLED_CAP | // Reads may be enabled
|
||||
EFI_FVB2_READ_STATUS | // Reads are currently enabled
|
||||
EFI_FVB2_STICKY_WRITE | // A block erase is required to flip bits into EFI_FVB2_ERASE_POLARITY
|
||||
EFI_FVB2_MEMORY_MAPPED | // It is memory mapped
|
||||
EFI_FVB2_ERASE_POLARITY // After erasure all bits take this value (i.e. '1')
|
||||
|
||||
);
|
||||
);
|
||||
|
||||
// Check if it is write protected
|
||||
if (Instance->Media.ReadOnly != TRUE) {
|
||||
|
||||
FlashFvbAttributes = FlashFvbAttributes |
|
||||
EFI_FVB2_WRITE_STATUS | // Writes are currently enabled
|
||||
EFI_FVB2_WRITE_ENABLED_CAP; // Writes may be enabled
|
||||
@@ -298,12 +333,12 @@ FvbGetAttributes(
|
||||
**/
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
FvbSetAttributes(
|
||||
FvbSetAttributes (
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
IN OUT EFI_FVB_ATTRIBUTES_2 *Attributes
|
||||
)
|
||||
{
|
||||
DEBUG ((DEBUG_BLKIO, "FvbSetAttributes(0x%X) is not supported\n",*Attributes));
|
||||
DEBUG ((DEBUG_BLKIO, "FvbSetAttributes(0x%X) is not supported\n", *Attributes));
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
|
||||
@@ -331,13 +366,13 @@ FvbGetPhysicalAddress (
|
||||
OUT EFI_PHYSICAL_ADDRESS *Address
|
||||
)
|
||||
{
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
|
||||
Instance = INSTANCE_FROM_FVB_THIS(This);
|
||||
Instance = INSTANCE_FROM_FVB_THIS (This);
|
||||
|
||||
DEBUG ((DEBUG_BLKIO, "FvbGetPhysicalAddress(BaseAddress=0x%08x)\n", Instance->RegionBaseAddress));
|
||||
|
||||
ASSERT(Address != NULL);
|
||||
ASSERT (Address != NULL);
|
||||
|
||||
*Address = mFlashNvStorageVariableBase;
|
||||
return EFI_SUCCESS;
|
||||
@@ -378,10 +413,10 @@ FvbGetBlockSize (
|
||||
OUT UINTN *NumberOfBlocks
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
EFI_STATUS Status;
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
|
||||
Instance = INSTANCE_FROM_FVB_THIS(This);
|
||||
Instance = INSTANCE_FROM_FVB_THIS (This);
|
||||
|
||||
DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize(Lba=%ld, BlockSize=0x%x, LastBlock=%ld)\n", Lba, Instance->Media.BlockSize, Instance->Media.LastBlock));
|
||||
|
||||
@@ -390,8 +425,8 @@ FvbGetBlockSize (
|
||||
Status = EFI_INVALID_PARAMETER;
|
||||
} else {
|
||||
// This is easy because in this platform each NorFlash device has equal sized blocks.
|
||||
*BlockSize = (UINTN) Instance->Media.BlockSize;
|
||||
*NumberOfBlocks = (UINTN) (Instance->Media.LastBlock - Lba + 1);
|
||||
*BlockSize = (UINTN)Instance->Media.BlockSize;
|
||||
*NumberOfBlocks = (UINTN)(Instance->Media.LastBlock - Lba + 1);
|
||||
|
||||
DEBUG ((DEBUG_BLKIO, "FvbGetBlockSize: *BlockSize=0x%x, *NumberOfBlocks=0x%x.\n", *BlockSize, *NumberOfBlocks));
|
||||
|
||||
@@ -445,18 +480,18 @@ FvbGetBlockSize (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
FvbRead (
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN OUT UINTN *NumBytes,
|
||||
IN OUT UINT8 *Buffer
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN OUT UINTN *NumBytes,
|
||||
IN OUT UINT8 *Buffer
|
||||
)
|
||||
{
|
||||
EFI_STATUS TempStatus;
|
||||
UINTN BlockSize;
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
EFI_STATUS TempStatus;
|
||||
UINTN BlockSize;
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
|
||||
Instance = INSTANCE_FROM_FVB_THIS(This);
|
||||
Instance = INSTANCE_FROM_FVB_THIS (This);
|
||||
|
||||
DEBUG ((DEBUG_BLKIO, "FvbRead(Parameters: Lba=%ld, Offset=0x%x, *NumBytes=0x%x, Buffer @ 0x%08x)\n", Instance->StartLba + Lba, Offset, *NumBytes, Buffer));
|
||||
|
||||
@@ -465,14 +500,15 @@ FvbRead (
|
||||
// Cache the block size to avoid de-referencing pointers all the time
|
||||
BlockSize = Instance->Media.BlockSize;
|
||||
|
||||
DEBUG ((DEBUG_BLKIO, "FvbRead: Check if (Offset=0x%x + NumBytes=0x%x) <= BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));
|
||||
DEBUG ((DEBUG_BLKIO, "FvbRead: Check if (Offset=0x%x + NumBytes=0x%x) <= BlockSize=0x%x\n", Offset, *NumBytes, BlockSize));
|
||||
|
||||
// The read must not span block boundaries.
|
||||
// We need to check each variable individually because adding two large values together overflows.
|
||||
if ((Offset >= BlockSize) ||
|
||||
(*NumBytes > BlockSize) ||
|
||||
((Offset + *NumBytes) > BlockSize)) {
|
||||
DEBUG ((DEBUG_ERROR, "FvbRead: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize ));
|
||||
((Offset + *NumBytes) > BlockSize))
|
||||
{
|
||||
DEBUG ((DEBUG_ERROR, "FvbRead: ERROR - EFI_BAD_BUFFER_SIZE: (Offset=0x%x + NumBytes=0x%x) > BlockSize=0x%x\n", Offset, *NumBytes, BlockSize));
|
||||
return EFI_BAD_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
@@ -495,6 +531,7 @@ FvbRead (
|
||||
return EFI_DEVICE_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -555,14 +592,14 @@ FvbRead (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
FvbWrite (
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN OUT UINTN *NumBytes,
|
||||
IN UINT8 *Buffer
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINTN Offset,
|
||||
IN OUT UINTN *NumBytes,
|
||||
IN UINT8 *Buffer
|
||||
)
|
||||
{
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
|
||||
Instance = INSTANCE_FROM_FVB_THIS (This);
|
||||
|
||||
@@ -615,18 +652,18 @@ FvbWrite (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
FvbEraseBlocks (
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL *This,
|
||||
...
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
VA_LIST Args;
|
||||
UINTN BlockAddress; // Physical address of Lba to erase
|
||||
EFI_LBA StartingLba; // Lba from which we start erasing
|
||||
UINTN NumOfLba; // Number of Lba blocks to erase
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
EFI_STATUS Status;
|
||||
VA_LIST Args;
|
||||
UINTN BlockAddress; // Physical address of Lba to erase
|
||||
EFI_LBA StartingLba; // Lba from which we start erasing
|
||||
UINTN NumOfLba; // Number of Lba blocks to erase
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
|
||||
Instance = INSTANCE_FROM_FVB_THIS(This);
|
||||
Instance = INSTANCE_FROM_FVB_THIS (This);
|
||||
|
||||
DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks()\n"));
|
||||
|
||||
@@ -648,7 +685,7 @@ FvbEraseBlocks (
|
||||
|
||||
// Have we reached the end of the list?
|
||||
if (StartingLba == EFI_LBA_LIST_TERMINATOR) {
|
||||
//Exit the while loop
|
||||
// Exit the while loop
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -670,6 +707,7 @@ FvbEraseBlocks (
|
||||
goto EXIT;
|
||||
}
|
||||
} while (TRUE);
|
||||
|
||||
VA_END (Args);
|
||||
|
||||
//
|
||||
@@ -691,18 +729,17 @@ FvbEraseBlocks (
|
||||
|
||||
// Go through each one and erase it
|
||||
while (NumOfLba > 0) {
|
||||
|
||||
// Get the physical address of Lba to erase
|
||||
BlockAddress = GET_NOR_BLOCK_ADDRESS (
|
||||
Instance->RegionBaseAddress,
|
||||
Instance->StartLba + StartingLba,
|
||||
Instance->Media.BlockSize
|
||||
);
|
||||
Instance->RegionBaseAddress,
|
||||
Instance->StartLba + StartingLba,
|
||||
Instance->Media.BlockSize
|
||||
);
|
||||
|
||||
// Erase it
|
||||
DEBUG ((DEBUG_BLKIO, "FvbEraseBlocks: Erasing Lba=%ld @ 0x%08x.\n", Instance->StartLba + StartingLba, BlockAddress));
|
||||
Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (EFI_ERROR (Status)) {
|
||||
VA_END (Args);
|
||||
Status = EFI_DEVICE_ERROR;
|
||||
goto EXIT;
|
||||
@@ -713,6 +750,7 @@ FvbEraseBlocks (
|
||||
NumOfLba--;
|
||||
}
|
||||
} while (TRUE);
|
||||
|
||||
VA_END (Args);
|
||||
|
||||
EXIT:
|
||||
@@ -730,10 +768,10 @@ EXIT:
|
||||
VOID
|
||||
EFIAPI
|
||||
FvbVirtualNotifyEvent (
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
IN EFI_EVENT Event,
|
||||
IN VOID *Context
|
||||
)
|
||||
{
|
||||
EfiConvertPointer (0x0, (VOID**)&mFlashNvStorageVariableBase);
|
||||
EfiConvertPointer (0x0, (VOID **)&mFlashNvStorageVariableBase);
|
||||
return;
|
||||
}
|
||||
|
@@ -16,13 +16,13 @@
|
||||
//
|
||||
// Global variable declarations
|
||||
//
|
||||
NOR_FLASH_INSTANCE **mNorFlashInstances;
|
||||
UINT32 mNorFlashDeviceCount;
|
||||
UINTN mFlashNvStorageVariableBase;
|
||||
NOR_FLASH_INSTANCE **mNorFlashInstances;
|
||||
UINT32 mNorFlashDeviceCount;
|
||||
UINTN mFlashNvStorageVariableBase;
|
||||
|
||||
NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = {
|
||||
NOR_FLASH_SIGNATURE, // Signature
|
||||
NULL, // Handle ... NEED TO BE FILLED
|
||||
NULL, // Handle ... NEED TO BE FILLED
|
||||
|
||||
0, // DeviceBaseAddress ... NEED TO BE FILLED
|
||||
0, // RegionBaseAddress ... NEED TO BE FILLED
|
||||
@@ -31,43 +31,43 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = {
|
||||
|
||||
{
|
||||
EFI_BLOCK_IO_PROTOCOL_REVISION2, // Revision
|
||||
NULL, // Media ... NEED TO BE FILLED
|
||||
NULL, // Reset;
|
||||
NULL, // ReadBlocks
|
||||
NULL, // WriteBlocks
|
||||
NULL // FlushBlocks
|
||||
NULL, // Media ... NEED TO BE FILLED
|
||||
NULL, // Reset;
|
||||
NULL, // ReadBlocks
|
||||
NULL, // WriteBlocks
|
||||
NULL // FlushBlocks
|
||||
}, // BlockIoProtocol
|
||||
|
||||
{
|
||||
0, // MediaId ... NEED TO BE FILLED
|
||||
0, // MediaId ... NEED TO BE FILLED
|
||||
FALSE, // RemovableMedia
|
||||
TRUE, // MediaPresent
|
||||
TRUE, // MediaPresent
|
||||
FALSE, // LogicalPartition
|
||||
FALSE, // ReadOnly
|
||||
FALSE, // WriteCaching;
|
||||
0, // BlockSize ... NEED TO BE FILLED
|
||||
4, // IoAlign
|
||||
0, // LastBlock ... NEED TO BE FILLED
|
||||
0, // LowestAlignedLba
|
||||
1, // LogicalBlocksPerPhysicalBlock
|
||||
}, //Media;
|
||||
0, // BlockSize ... NEED TO BE FILLED
|
||||
4, // IoAlign
|
||||
0, // LastBlock ... NEED TO BE FILLED
|
||||
0, // LowestAlignedLba
|
||||
1, // LogicalBlocksPerPhysicalBlock
|
||||
}, // Media;
|
||||
|
||||
{
|
||||
EFI_DISK_IO_PROTOCOL_REVISION, // Revision
|
||||
NULL, // ReadDisk
|
||||
NULL // WriteDisk
|
||||
NULL, // ReadDisk
|
||||
NULL // WriteDisk
|
||||
},
|
||||
|
||||
{
|
||||
FvbGetAttributes, // GetAttributes
|
||||
FvbSetAttributes, // SetAttributes
|
||||
FvbGetPhysicalAddress, // GetPhysicalAddress
|
||||
FvbGetBlockSize, // GetBlockSize
|
||||
FvbRead, // Read
|
||||
FvbWrite, // Write
|
||||
FvbEraseBlocks, // EraseBlocks
|
||||
NULL, //ParentHandle
|
||||
}, // FvbProtoccol;
|
||||
FvbGetAttributes, // GetAttributes
|
||||
FvbSetAttributes, // SetAttributes
|
||||
FvbGetPhysicalAddress, // GetPhysicalAddress
|
||||
FvbGetBlockSize, // GetBlockSize
|
||||
FvbRead, // Read
|
||||
FvbWrite, // Write
|
||||
FvbEraseBlocks, // EraseBlocks
|
||||
NULL, // ParentHandle
|
||||
}, // FvbProtoccol;
|
||||
NULL, // ShadowBuffer
|
||||
{
|
||||
{
|
||||
@@ -79,7 +79,8 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = {
|
||||
(UINT8)(OFFSET_OF (NOR_FLASH_DEVICE_PATH, End) >> 8)
|
||||
}
|
||||
},
|
||||
{ 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 } }, // GUID ... NEED TO BE FILLED
|
||||
{ 0x0, 0x0, 0x0, { 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }
|
||||
}, // GUID ... NEED TO BE FILLED
|
||||
},
|
||||
0, // Index
|
||||
{
|
||||
@@ -87,43 +88,43 @@ NOR_FLASH_INSTANCE mNorFlashInstanceTemplate = {
|
||||
END_ENTIRE_DEVICE_PATH_SUBTYPE,
|
||||
{ sizeof (EFI_DEVICE_PATH_PROTOCOL), 0 }
|
||||
}
|
||||
} // DevicePath
|
||||
} // DevicePath
|
||||
};
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashCreateInstance (
|
||||
IN UINTN NorFlashDeviceBase,
|
||||
IN UINTN NorFlashRegionBase,
|
||||
IN UINTN NorFlashSize,
|
||||
IN UINT32 Index,
|
||||
IN UINT32 BlockSize,
|
||||
IN BOOLEAN SupportFvb,
|
||||
OUT NOR_FLASH_INSTANCE** NorFlashInstance
|
||||
IN UINTN NorFlashDeviceBase,
|
||||
IN UINTN NorFlashRegionBase,
|
||||
IN UINTN NorFlashSize,
|
||||
IN UINT32 Index,
|
||||
IN UINT32 BlockSize,
|
||||
IN BOOLEAN SupportFvb,
|
||||
OUT NOR_FLASH_INSTANCE **NorFlashInstance
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
NOR_FLASH_INSTANCE* Instance;
|
||||
EFI_STATUS Status;
|
||||
NOR_FLASH_INSTANCE *Instance;
|
||||
|
||||
ASSERT(NorFlashInstance != NULL);
|
||||
ASSERT (NorFlashInstance != NULL);
|
||||
|
||||
Instance = AllocateRuntimeCopyPool (sizeof(NOR_FLASH_INSTANCE),&mNorFlashInstanceTemplate);
|
||||
Instance = AllocateRuntimeCopyPool (sizeof (NOR_FLASH_INSTANCE), &mNorFlashInstanceTemplate);
|
||||
if (Instance == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
Instance->DeviceBaseAddress = NorFlashDeviceBase;
|
||||
Instance->RegionBaseAddress = NorFlashRegionBase;
|
||||
Instance->Size = NorFlashSize;
|
||||
Instance->Size = NorFlashSize;
|
||||
|
||||
Instance->BlockIoProtocol.Media = &Instance->Media;
|
||||
Instance->Media.MediaId = Index;
|
||||
Instance->Media.BlockSize = BlockSize;
|
||||
Instance->Media.LastBlock = (NorFlashSize / BlockSize)-1;
|
||||
Instance->Media.MediaId = Index;
|
||||
Instance->Media.BlockSize = BlockSize;
|
||||
Instance->Media.LastBlock = (NorFlashSize / BlockSize)-1;
|
||||
|
||||
CopyGuid (&Instance->DevicePath.Vendor.Guid, &gEfiCallerIdGuid);
|
||||
Instance->DevicePath.Index = (UINT8)Index;
|
||||
|
||||
Instance->ShadowBuffer = AllocateRuntimePool (BlockSize);;
|
||||
Instance->ShadowBuffer = AllocateRuntimePool (BlockSize);
|
||||
if (Instance->ShadowBuffer == NULL) {
|
||||
return EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
@@ -137,12 +138,12 @@ NorFlashCreateInstance (
|
||||
EFI_NATIVE_INTERFACE,
|
||||
&Instance->FvbProtocol
|
||||
);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (EFI_ERROR (Status)) {
|
||||
FreePool (Instance);
|
||||
return Status;
|
||||
}
|
||||
} else {
|
||||
DEBUG((DEBUG_ERROR,"standalone MM NOR Flash driver only support FVB.\n"));
|
||||
DEBUG ((DEBUG_ERROR, "standalone MM NOR Flash driver only support FVB.\n"));
|
||||
FreePool (Instance);
|
||||
return EFI_UNSUPPORTED;
|
||||
}
|
||||
@@ -156,12 +157,12 @@ NorFlashCreateInstance (
|
||||
**/
|
||||
EFI_STATUS
|
||||
NorFlashUnlockAndEraseSingleBlock (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN UINTN BlockAddress
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Index;
|
||||
EFI_STATUS Status;
|
||||
UINTN Index;
|
||||
|
||||
Index = 0;
|
||||
// The block erase might fail a first time (SW bug ?). Retry it ...
|
||||
@@ -171,12 +172,13 @@ NorFlashUnlockAndEraseSingleBlock (
|
||||
if (EFI_ERROR (Status)) {
|
||||
break;
|
||||
}
|
||||
|
||||
Status = NorFlashEraseSingleBlock (Instance, BlockAddress);
|
||||
Index++;
|
||||
} while ((Index < NOR_FLASH_ERASE_RETRY) && (Status == EFI_WRITE_PROTECTED));
|
||||
|
||||
if (Index == NOR_FLASH_ERASE_RETRY) {
|
||||
DEBUG((DEBUG_ERROR,"EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error (try to erase %d times)\n", BlockAddress,Index));
|
||||
DEBUG ((DEBUG_ERROR, "EraseSingleBlock(BlockAddress=0x%08x: Block Locked Error (try to erase %d times)\n", BlockAddress, Index));
|
||||
}
|
||||
|
||||
return Status;
|
||||
@@ -184,20 +186,20 @@ NorFlashUnlockAndEraseSingleBlock (
|
||||
|
||||
EFI_STATUS
|
||||
NorFlashWriteFullBlock (
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINT32 *DataBuffer,
|
||||
IN UINT32 BlockSizeInWords
|
||||
IN NOR_FLASH_INSTANCE *Instance,
|
||||
IN EFI_LBA Lba,
|
||||
IN UINT32 *DataBuffer,
|
||||
IN UINT32 BlockSizeInWords
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN WordAddress;
|
||||
UINT32 WordIndex;
|
||||
UINTN BufferIndex;
|
||||
UINTN BlockAddress;
|
||||
UINTN BuffersInBlock;
|
||||
UINTN RemainingWords;
|
||||
UINTN Cnt;
|
||||
EFI_STATUS Status;
|
||||
UINTN WordAddress;
|
||||
UINT32 WordIndex;
|
||||
UINTN BufferIndex;
|
||||
UINTN BlockAddress;
|
||||
UINTN BuffersInBlock;
|
||||
UINTN RemainingWords;
|
||||
UINTN Cnt;
|
||||
|
||||
Status = EFI_SUCCESS;
|
||||
|
||||
@@ -208,8 +210,8 @@ NorFlashWriteFullBlock (
|
||||
WordAddress = BlockAddress;
|
||||
|
||||
Status = NorFlashUnlockAndEraseSingleBlock (Instance, BlockAddress);
|
||||
if (EFI_ERROR(Status)) {
|
||||
DEBUG((DEBUG_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and Erase the single block at 0x%X\n", BlockAddress));
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "WriteSingleBlock: ERROR - Failed to Unlock and Erase the single block at 0x%X\n", BlockAddress));
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
@@ -217,25 +219,30 @@ NorFlashWriteFullBlock (
|
||||
|
||||
// Check that the address starts at a 32-word boundary, i.e. last 7 bits must be zero
|
||||
if ((WordAddress & BOUNDARY_OF_32_WORDS) == 0x00) {
|
||||
|
||||
// First, break the entire block into buffer-sized chunks.
|
||||
BuffersInBlock = (UINTN)(BlockSizeInWords * 4) / P30_MAX_BUFFER_SIZE_IN_BYTES;
|
||||
|
||||
// Then feed each buffer chunk to the NOR Flash
|
||||
// If a buffer does not contain any data, don't write it.
|
||||
for(BufferIndex=0;
|
||||
for (BufferIndex = 0;
|
||||
BufferIndex < BuffersInBlock;
|
||||
BufferIndex++, WordAddress += P30_MAX_BUFFER_SIZE_IN_BYTES, DataBuffer += P30_MAX_BUFFER_SIZE_IN_WORDS
|
||||
) {
|
||||
)
|
||||
{
|
||||
// Check the buffer to see if it contains any data (not set all 1s).
|
||||
for (Cnt = 0; Cnt < P30_MAX_BUFFER_SIZE_IN_WORDS; Cnt++) {
|
||||
if (~DataBuffer[Cnt] != 0 ) {
|
||||
// Some data found, write the buffer.
|
||||
Status = NorFlashWriteBuffer (Instance, WordAddress, P30_MAX_BUFFER_SIZE_IN_BYTES,
|
||||
DataBuffer);
|
||||
if (EFI_ERROR(Status)) {
|
||||
Status = NorFlashWriteBuffer (
|
||||
Instance,
|
||||
WordAddress,
|
||||
P30_MAX_BUFFER_SIZE_IN_BYTES,
|
||||
DataBuffer
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto EXIT;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -244,84 +251,84 @@ NorFlashWriteFullBlock (
|
||||
// Finally, finish off any remaining words that are less than the maximum size of the buffer
|
||||
RemainingWords = BlockSizeInWords % P30_MAX_BUFFER_SIZE_IN_WORDS;
|
||||
|
||||
if(RemainingWords != 0) {
|
||||
if (RemainingWords != 0) {
|
||||
Status = NorFlashWriteBuffer (Instance, WordAddress, (RemainingWords * 4), DataBuffer);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto EXIT;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// For now, use the single word programming algorithm
|
||||
// It is unlikely that the NOR Flash will exist in an address which falls within a 32 word boundary range,
|
||||
// i.e. which ends in the range 0x......01 - 0x......7F.
|
||||
for(WordIndex=0; WordIndex<BlockSizeInWords; WordIndex++, DataBuffer++, WordAddress = WordAddress + 4) {
|
||||
for (WordIndex = 0; WordIndex < BlockSizeInWords; WordIndex++, DataBuffer++, WordAddress = WordAddress + 4) {
|
||||
Status = NorFlashWriteSingleWord (Instance, WordAddress, *DataBuffer);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (EFI_ERROR (Status)) {
|
||||
goto EXIT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
EXIT:
|
||||
if (EFI_ERROR(Status)) {
|
||||
DEBUG((DEBUG_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed at address 0x%08x. Exit Status = \"%r\".\n", WordAddress, Status));
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed at address 0x%08x. Exit Status = \"%r\".\n", WordAddress, Status));
|
||||
}
|
||||
|
||||
return Status;
|
||||
}
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
NorFlashInitialise (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_MM_SYSTEM_TABLE *MmSystemTable
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_MM_SYSTEM_TABLE *MmSystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 Index;
|
||||
NOR_FLASH_DESCRIPTION* NorFlashDevices;
|
||||
BOOLEAN ContainVariableStorage;
|
||||
EFI_STATUS Status;
|
||||
UINT32 Index;
|
||||
NOR_FLASH_DESCRIPTION *NorFlashDevices;
|
||||
BOOLEAN ContainVariableStorage;
|
||||
|
||||
Status = NorFlashPlatformInitialization ();
|
||||
if (EFI_ERROR(Status)) {
|
||||
DEBUG((DEBUG_ERROR,"NorFlashInitialise: Fail to initialize Nor Flash devices\n"));
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to initialize Nor Flash devices\n"));
|
||||
return Status;
|
||||
}
|
||||
|
||||
Status = NorFlashPlatformGetDevices (&NorFlashDevices, &mNorFlashDeviceCount);
|
||||
if (EFI_ERROR(Status)) {
|
||||
DEBUG((DEBUG_ERROR,"NorFlashInitialise: Fail to get Nor Flash devices\n"));
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to get Nor Flash devices\n"));
|
||||
return Status;
|
||||
}
|
||||
|
||||
mNorFlashInstances = AllocatePool (sizeof(NOR_FLASH_INSTANCE*) * mNorFlashDeviceCount);
|
||||
mNorFlashInstances = AllocatePool (sizeof (NOR_FLASH_INSTANCE *) * mNorFlashDeviceCount);
|
||||
|
||||
for (Index = 0; Index < mNorFlashDeviceCount; Index++) {
|
||||
// Check if this NOR Flash device contain the variable storage region
|
||||
|
||||
if (FixedPcdGet64 (PcdFlashNvStorageVariableBase64) != 0) {
|
||||
ContainVariableStorage =
|
||||
(NorFlashDevices[Index].RegionBaseAddress <= FixedPcdGet64 (PcdFlashNvStorageVariableBase64)) &&
|
||||
(FixedPcdGet64 (PcdFlashNvStorageVariableBase64) + FixedPcdGet32 (PcdFlashNvStorageVariableSize) <=
|
||||
NorFlashDevices[Index].RegionBaseAddress + NorFlashDevices[Index].Size);
|
||||
} else {
|
||||
ContainVariableStorage =
|
||||
(NorFlashDevices[Index].RegionBaseAddress <= FixedPcdGet32 (PcdFlashNvStorageVariableBase)) &&
|
||||
(FixedPcdGet32 (PcdFlashNvStorageVariableBase) + FixedPcdGet32 (PcdFlashNvStorageVariableSize) <=
|
||||
NorFlashDevices[Index].RegionBaseAddress + NorFlashDevices[Index].Size);
|
||||
}
|
||||
if (FixedPcdGet64 (PcdFlashNvStorageVariableBase64) != 0) {
|
||||
ContainVariableStorage =
|
||||
(NorFlashDevices[Index].RegionBaseAddress <= FixedPcdGet64 (PcdFlashNvStorageVariableBase64)) &&
|
||||
(FixedPcdGet64 (PcdFlashNvStorageVariableBase64) + FixedPcdGet32 (PcdFlashNvStorageVariableSize) <=
|
||||
NorFlashDevices[Index].RegionBaseAddress + NorFlashDevices[Index].Size);
|
||||
} else {
|
||||
ContainVariableStorage =
|
||||
(NorFlashDevices[Index].RegionBaseAddress <= FixedPcdGet32 (PcdFlashNvStorageVariableBase)) &&
|
||||
(FixedPcdGet32 (PcdFlashNvStorageVariableBase) + FixedPcdGet32 (PcdFlashNvStorageVariableSize) <=
|
||||
NorFlashDevices[Index].RegionBaseAddress + NorFlashDevices[Index].Size);
|
||||
}
|
||||
|
||||
Status = NorFlashCreateInstance (
|
||||
NorFlashDevices[Index].DeviceBaseAddress,
|
||||
NorFlashDevices[Index].RegionBaseAddress,
|
||||
NorFlashDevices[Index].Size,
|
||||
Index,
|
||||
NorFlashDevices[Index].BlockSize,
|
||||
ContainVariableStorage,
|
||||
&mNorFlashInstances[Index]
|
||||
);
|
||||
if (EFI_ERROR(Status)) {
|
||||
DEBUG((DEBUG_ERROR,"NorFlashInitialise: Fail to create instance for NorFlash[%d]\n",Index));
|
||||
NorFlashDevices[Index].DeviceBaseAddress,
|
||||
NorFlashDevices[Index].RegionBaseAddress,
|
||||
NorFlashDevices[Index].Size,
|
||||
Index,
|
||||
NorFlashDevices[Index].BlockSize,
|
||||
ContainVariableStorage,
|
||||
&mNorFlashInstances[Index]
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "NorFlashInitialise: Fail to create instance for NorFlash[%d]\n", Index));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -331,17 +338,16 @@ NorFlashInitialise (
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
NorFlashFvbInitialize (
|
||||
IN NOR_FLASH_INSTANCE* Instance
|
||||
IN NOR_FLASH_INSTANCE *Instance
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINT32 FvbNumLba;
|
||||
|
||||
ASSERT((Instance != NULL));
|
||||
|
||||
ASSERT ((Instance != NULL));
|
||||
|
||||
mFlashNvStorageVariableBase = (FixedPcdGet64 (PcdFlashNvStorageVariableBase64) != 0) ?
|
||||
FixedPcdGet64 (PcdFlashNvStorageVariableBase64) : FixedPcdGet32 (PcdFlashNvStorageVariableBase);
|
||||
FixedPcdGet64 (PcdFlashNvStorageVariableBase64) : FixedPcdGet32 (PcdFlashNvStorageVariableBase);
|
||||
// Set the index of the first LBA for the FVB
|
||||
Instance->StartLba = (mFlashNvStorageVariableBase - Instance->RegionBaseAddress) / Instance->Media.BlockSize;
|
||||
|
||||
@@ -349,23 +355,26 @@ NorFlashFvbInitialize (
|
||||
Status = ValidateFvHeader (Instance);
|
||||
|
||||
// Install the Default FVB header if required
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (EFI_ERROR (Status)) {
|
||||
// There is no valid header, so time to install one.
|
||||
DEBUG ((DEBUG_INFO, "%a: The FVB Header is not valid.\n", __FUNCTION__));
|
||||
DEBUG ((DEBUG_INFO, "%a: Installing a correct one for this volume.\n",
|
||||
__FUNCTION__));
|
||||
DEBUG ((
|
||||
DEBUG_INFO,
|
||||
"%a: Installing a correct one for this volume.\n",
|
||||
__FUNCTION__
|
||||
));
|
||||
|
||||
// Erase all the NorFlash that is reserved for variable storage
|
||||
FvbNumLba = (PcdGet32(PcdFlashNvStorageVariableSize) + PcdGet32(PcdFlashNvStorageFtwWorkingSize) + PcdGet32(PcdFlashNvStorageFtwSpareSize)) / Instance->Media.BlockSize;
|
||||
FvbNumLba = (PcdGet32 (PcdFlashNvStorageVariableSize) + PcdGet32 (PcdFlashNvStorageFtwWorkingSize) + PcdGet32 (PcdFlashNvStorageFtwSpareSize)) / Instance->Media.BlockSize;
|
||||
|
||||
Status = FvbEraseBlocks (&Instance->FvbProtocol, (EFI_LBA)0, FvbNumLba, EFI_LBA_LIST_TERMINATOR);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
|
||||
// Install all appropriate headers
|
||||
Status = InitializeFvAndVariableStoreHeaders (Instance);
|
||||
if (EFI_ERROR(Status)) {
|
||||
if (EFI_ERROR (Status)) {
|
||||
return Status;
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,6 @@
|
||||
|
||||
**/
|
||||
|
||||
|
||||
#include <PiDxe.h>
|
||||
|
||||
#include <Library/BaseLib.h>
|
||||
@@ -24,29 +23,31 @@
|
||||
|
||||
#include "PL061Gpio.h"
|
||||
|
||||
PLATFORM_GPIO_CONTROLLER *mPL061PlatformGpio;
|
||||
PLATFORM_GPIO_CONTROLLER *mPL061PlatformGpio;
|
||||
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
PL061Locate (
|
||||
IN EMBEDDED_GPIO_PIN Gpio,
|
||||
OUT UINTN *ControllerIndex,
|
||||
OUT UINTN *ControllerOffset,
|
||||
OUT UINTN *RegisterBase
|
||||
IN EMBEDDED_GPIO_PIN Gpio,
|
||||
OUT UINTN *ControllerIndex,
|
||||
OUT UINTN *ControllerOffset,
|
||||
OUT UINTN *RegisterBase
|
||||
)
|
||||
{
|
||||
UINT32 Index;
|
||||
UINT32 Index;
|
||||
|
||||
for (Index = 0; Index < mPL061PlatformGpio->GpioControllerCount; Index++) {
|
||||
if ( (Gpio >= mPL061PlatformGpio->GpioController[Index].GpioIndex)
|
||||
&& (Gpio < mPL061PlatformGpio->GpioController[Index].GpioIndex
|
||||
+ mPL061PlatformGpio->GpioController[Index].InternalGpioCount)) {
|
||||
*ControllerIndex = Index;
|
||||
if ( (Gpio >= mPL061PlatformGpio->GpioController[Index].GpioIndex)
|
||||
&& (Gpio < mPL061PlatformGpio->GpioController[Index].GpioIndex
|
||||
+ mPL061PlatformGpio->GpioController[Index].InternalGpioCount))
|
||||
{
|
||||
*ControllerIndex = Index;
|
||||
*ControllerOffset = Gpio % mPL061PlatformGpio->GpioController[Index].InternalGpioCount;
|
||||
*RegisterBase = mPL061PlatformGpio->GpioController[Index].RegisterBase;
|
||||
*RegisterBase = mPL061PlatformGpio->GpioController[Index].RegisterBase;
|
||||
return EFI_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG ((DEBUG_ERROR, "%a, failed to locate gpio %d\n", __func__, Gpio));
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
@@ -72,8 +73,8 @@ STATIC
|
||||
UINTN
|
||||
EFIAPI
|
||||
PL061EffectiveAddress (
|
||||
IN UINTN Address,
|
||||
IN UINTN Mask
|
||||
IN UINTN Address,
|
||||
IN UINTN Mask
|
||||
)
|
||||
{
|
||||
return ((Address + PL061_GPIO_DATA_REG_OFFSET) + (Mask << 2));
|
||||
@@ -83,8 +84,8 @@ STATIC
|
||||
UINTN
|
||||
EFIAPI
|
||||
PL061GetPins (
|
||||
IN UINTN Address,
|
||||
IN UINTN Mask
|
||||
IN UINTN Address,
|
||||
IN UINTN Mask
|
||||
)
|
||||
{
|
||||
return MmioRead8 (PL061EffectiveAddress (Address, Mask));
|
||||
@@ -94,9 +95,9 @@ STATIC
|
||||
VOID
|
||||
EFIAPI
|
||||
PL061SetPins (
|
||||
IN UINTN Address,
|
||||
IN UINTN Mask,
|
||||
IN UINTN Value
|
||||
IN UINTN Address,
|
||||
IN UINTN Mask,
|
||||
IN UINTN Value
|
||||
)
|
||||
{
|
||||
MmioWrite8 (PL061EffectiveAddress (Address, Mask), Value);
|
||||
@@ -105,18 +106,18 @@ PL061SetPins (
|
||||
/**
|
||||
Function implementations
|
||||
**/
|
||||
|
||||
EFI_STATUS
|
||||
PL061Identify (
|
||||
VOID
|
||||
)
|
||||
{
|
||||
UINTN Index;
|
||||
UINTN RegisterBase;
|
||||
UINTN Index;
|
||||
UINTN RegisterBase;
|
||||
|
||||
if ( (mPL061PlatformGpio->GpioCount == 0)
|
||||
|| (mPL061PlatformGpio->GpioControllerCount == 0)) {
|
||||
return EFI_NOT_FOUND;
|
||||
if ( (mPL061PlatformGpio->GpioCount == 0)
|
||||
|| (mPL061PlatformGpio->GpioControllerCount == 0))
|
||||
{
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
for (Index = 0; Index < mPL061PlatformGpio->GpioControllerCount; Index++) {
|
||||
@@ -127,18 +128,20 @@ PL061Identify (
|
||||
RegisterBase = mPL061PlatformGpio->GpioController[Index].RegisterBase;
|
||||
|
||||
// Check if this is a PrimeCell Peripheral
|
||||
if ( (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID0) != 0x0D)
|
||||
|| (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID1) != 0xF0)
|
||||
|| (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID2) != 0x05)
|
||||
|| (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID3) != 0xB1)) {
|
||||
if ( (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID0) != 0x0D)
|
||||
|| (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID1) != 0xF0)
|
||||
|| (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID2) != 0x05)
|
||||
|| (MmioRead8 (RegisterBase + PL061_GPIO_PCELL_ID3) != 0xB1))
|
||||
{
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
|
||||
// Check if this PrimeCell Peripheral is the PL061 GPIO
|
||||
if ( (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID0) != 0x61)
|
||||
|| (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID1) != 0x10)
|
||||
|| ((MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID2) & 0xF) != 0x04)
|
||||
|| (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID3) != 0x00)) {
|
||||
if ( (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID0) != 0x61)
|
||||
|| (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID1) != 0x10)
|
||||
|| ((MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID2) & 0xF) != 0x04)
|
||||
|| (MmioRead8 (RegisterBase + PL061_GPIO_PERIPH_ID3) != 0x00))
|
||||
{
|
||||
return EFI_NOT_FOUND;
|
||||
}
|
||||
}
|
||||
@@ -166,13 +169,13 @@ Returns:
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
Get (
|
||||
IN EMBEDDED_GPIO *This,
|
||||
IN EMBEDDED_GPIO_PIN Gpio,
|
||||
OUT UINTN *Value
|
||||
IN EMBEDDED_GPIO *This,
|
||||
IN EMBEDDED_GPIO_PIN Gpio,
|
||||
OUT UINTN *Value
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Index, Offset, RegisterBase;
|
||||
EFI_STATUS Status;
|
||||
UINTN Index, Offset, RegisterBase;
|
||||
|
||||
Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
@@ -181,7 +184,7 @@ Get (
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (PL061GetPins (RegisterBase, GPIO_PIN_MASK(Offset)) != 0) {
|
||||
if (PL061GetPins (RegisterBase, GPIO_PIN_MASK (Offset)) != 0) {
|
||||
*Value = 1;
|
||||
} else {
|
||||
*Value = 0;
|
||||
@@ -216,32 +219,33 @@ Set (
|
||||
IN EMBEDDED_GPIO_MODE Mode
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Index, Offset, RegisterBase;
|
||||
EFI_STATUS Status;
|
||||
UINTN Index, Offset, RegisterBase;
|
||||
|
||||
Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
switch (Mode)
|
||||
{
|
||||
switch (Mode) {
|
||||
case GPIO_MODE_INPUT:
|
||||
// Set the corresponding direction bit to LOW for input
|
||||
MmioAnd8 (RegisterBase + PL061_GPIO_DIR_REG,
|
||||
~GPIO_PIN_MASK(Offset) & 0xFF);
|
||||
MmioAnd8 (
|
||||
RegisterBase + PL061_GPIO_DIR_REG,
|
||||
~GPIO_PIN_MASK(Offset) & 0xFF
|
||||
);
|
||||
break;
|
||||
|
||||
case GPIO_MODE_OUTPUT_0:
|
||||
// Set the corresponding direction bit to HIGH for output
|
||||
MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK(Offset));
|
||||
MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK (Offset));
|
||||
// Set the corresponding data bit to LOW for 0
|
||||
PL061SetPins (RegisterBase, GPIO_PIN_MASK(Offset), 0);
|
||||
PL061SetPins (RegisterBase, GPIO_PIN_MASK (Offset), 0);
|
||||
break;
|
||||
|
||||
case GPIO_MODE_OUTPUT_1:
|
||||
// Set the corresponding direction bit to HIGH for output
|
||||
MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK(Offset));
|
||||
MmioOr8 (RegisterBase + PL061_GPIO_DIR_REG, GPIO_PIN_MASK (Offset));
|
||||
// Set the corresponding data bit to HIGH for 1
|
||||
PL061SetPins (RegisterBase, GPIO_PIN_MASK(Offset), 0xff);
|
||||
PL061SetPins (RegisterBase, GPIO_PIN_MASK (Offset), 0xff);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -278,8 +282,8 @@ GetMode (
|
||||
OUT EMBEDDED_GPIO_MODE *Mode
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
UINTN Index, Offset, RegisterBase;
|
||||
EFI_STATUS Status;
|
||||
UINTN Index, Offset, RegisterBase;
|
||||
|
||||
Status = PL061Locate (Gpio, &Index, &Offset, &RegisterBase);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
@@ -290,9 +294,9 @@ GetMode (
|
||||
}
|
||||
|
||||
// Check if it is input or output
|
||||
if (MmioRead8 (RegisterBase + PL061_GPIO_DIR_REG) & GPIO_PIN_MASK(Offset)) {
|
||||
if (MmioRead8 (RegisterBase + PL061_GPIO_DIR_REG) & GPIO_PIN_MASK (Offset)) {
|
||||
// Pin set to output
|
||||
if (PL061GetPins (RegisterBase, GPIO_PIN_MASK(Offset)) != 0) {
|
||||
if (PL061GetPins (RegisterBase, GPIO_PIN_MASK (Offset)) != 0) {
|
||||
*Mode = GPIO_MODE_OUTPUT_1;
|
||||
} else {
|
||||
*Mode = GPIO_MODE_OUTPUT_0;
|
||||
@@ -336,7 +340,7 @@ SetPull (
|
||||
/**
|
||||
Protocol variable definition
|
||||
**/
|
||||
EMBEDDED_GPIO gGpio = {
|
||||
EMBEDDED_GPIO gGpio = {
|
||||
Get,
|
||||
Set,
|
||||
GetMode,
|
||||
@@ -357,13 +361,13 @@ EMBEDDED_GPIO gGpio = {
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
PL061InstallProtocol (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_HANDLE Handle;
|
||||
GPIO_CONTROLLER *GpioController;
|
||||
EFI_STATUS Status;
|
||||
EFI_HANDLE Handle;
|
||||
GPIO_CONTROLLER *GpioController;
|
||||
|
||||
//
|
||||
// Make sure the Gpio protocol has not been installed in the system yet.
|
||||
@@ -379,29 +383,30 @@ PL061InstallProtocol (
|
||||
return EFI_BAD_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
mPL061PlatformGpio->GpioCount = PL061_GPIO_PINS;
|
||||
mPL061PlatformGpio->GpioCount = PL061_GPIO_PINS;
|
||||
mPL061PlatformGpio->GpioControllerCount = 1;
|
||||
mPL061PlatformGpio->GpioController = (GPIO_CONTROLLER *)((UINTN) mPL061PlatformGpio + sizeof (PLATFORM_GPIO_CONTROLLER));
|
||||
mPL061PlatformGpio->GpioController = (GPIO_CONTROLLER *)((UINTN)mPL061PlatformGpio + sizeof (PLATFORM_GPIO_CONTROLLER));
|
||||
|
||||
GpioController = mPL061PlatformGpio->GpioController;
|
||||
GpioController->RegisterBase = (UINTN) PcdGet32 (PcdPL061GpioBase);
|
||||
GpioController->GpioIndex = 0;
|
||||
GpioController = mPL061PlatformGpio->GpioController;
|
||||
GpioController->RegisterBase = (UINTN)PcdGet32 (PcdPL061GpioBase);
|
||||
GpioController->GpioIndex = 0;
|
||||
GpioController->InternalGpioCount = PL061_GPIO_PINS;
|
||||
}
|
||||
|
||||
Status = PL061Identify();
|
||||
if (EFI_ERROR(Status)) {
|
||||
Status = PL061Identify ();
|
||||
if (EFI_ERROR (Status)) {
|
||||
return EFI_DEVICE_ERROR;
|
||||
}
|
||||
|
||||
// Install the Embedded GPIO Protocol onto a new handle
|
||||
Handle = NULL;
|
||||
Status = gBS->InstallMultipleProtocolInterfaces(
|
||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||
&Handle,
|
||||
&gEmbeddedGpioProtocolGuid, &gGpio,
|
||||
&gEmbeddedGpioProtocolGuid,
|
||||
&gGpio,
|
||||
NULL
|
||||
);
|
||||
if (EFI_ERROR(Status)) {
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Status = EFI_OUT_OF_RESOURCES;
|
||||
}
|
||||
|
||||
|
@@ -6,38 +6,37 @@
|
||||
|
||||
**/
|
||||
|
||||
|
||||
#ifndef __PL061_GPIO_H__
|
||||
#define __PL061_GPIO_H__
|
||||
|
||||
#include <Protocol/EmbeddedGpio.h>
|
||||
|
||||
// PL061 GPIO Registers
|
||||
#define PL061_GPIO_DATA_REG_OFFSET ((UINTN) 0x000)
|
||||
#define PL061_GPIO_DATA_REG 0x000
|
||||
#define PL061_GPIO_DIR_REG 0x400
|
||||
#define PL061_GPIO_IS_REG 0x404
|
||||
#define PL061_GPIO_IBE_REG 0x408
|
||||
#define PL061_GPIO_IEV_REG 0x40C
|
||||
#define PL061_GPIO_IE_REG 0x410
|
||||
#define PL061_GPIO_RIS_REG 0x414
|
||||
#define PL061_GPIO_MIS_REG 0x410
|
||||
#define PL061_GPIO_IC_REG 0x41C
|
||||
#define PL061_GPIO_AFSEL_REG 0x420
|
||||
#define PL061_GPIO_DATA_REG_OFFSET ((UINTN) 0x000)
|
||||
#define PL061_GPIO_DATA_REG 0x000
|
||||
#define PL061_GPIO_DIR_REG 0x400
|
||||
#define PL061_GPIO_IS_REG 0x404
|
||||
#define PL061_GPIO_IBE_REG 0x408
|
||||
#define PL061_GPIO_IEV_REG 0x40C
|
||||
#define PL061_GPIO_IE_REG 0x410
|
||||
#define PL061_GPIO_RIS_REG 0x414
|
||||
#define PL061_GPIO_MIS_REG 0x410
|
||||
#define PL061_GPIO_IC_REG 0x41C
|
||||
#define PL061_GPIO_AFSEL_REG 0x420
|
||||
|
||||
#define PL061_GPIO_PERIPH_ID0 0xFE0
|
||||
#define PL061_GPIO_PERIPH_ID1 0xFE4
|
||||
#define PL061_GPIO_PERIPH_ID2 0xFE8
|
||||
#define PL061_GPIO_PERIPH_ID3 0xFEC
|
||||
#define PL061_GPIO_PERIPH_ID0 0xFE0
|
||||
#define PL061_GPIO_PERIPH_ID1 0xFE4
|
||||
#define PL061_GPIO_PERIPH_ID2 0xFE8
|
||||
#define PL061_GPIO_PERIPH_ID3 0xFEC
|
||||
|
||||
#define PL061_GPIO_PCELL_ID0 0xFF0
|
||||
#define PL061_GPIO_PCELL_ID1 0xFF4
|
||||
#define PL061_GPIO_PCELL_ID2 0xFF8
|
||||
#define PL061_GPIO_PCELL_ID3 0xFFC
|
||||
#define PL061_GPIO_PCELL_ID0 0xFF0
|
||||
#define PL061_GPIO_PCELL_ID1 0xFF4
|
||||
#define PL061_GPIO_PCELL_ID2 0xFF8
|
||||
#define PL061_GPIO_PCELL_ID3 0xFFC
|
||||
|
||||
#define PL061_GPIO_PINS 8
|
||||
#define PL061_GPIO_PINS 8
|
||||
|
||||
// All bits low except one bit high, native bit length
|
||||
#define GPIO_PIN_MASK(Pin) (1UL << ((UINTN)(Pin)))
|
||||
#define GPIO_PIN_MASK(Pin) (1UL << ((UINTN)(Pin)))
|
||||
|
||||
#endif // __PL061_GPIO_H__
|
||||
#endif // __PL061_GPIO_H__
|
||||
|
@@ -7,7 +7,6 @@
|
||||
|
||||
**/
|
||||
|
||||
|
||||
#include <PiDxe.h>
|
||||
|
||||
#include <Library/BaseLib.h>
|
||||
@@ -68,8 +67,8 @@ STATIC
|
||||
VOID
|
||||
EFIAPI
|
||||
SP805InterruptHandler (
|
||||
IN HARDWARE_INTERRUPT_SOURCE Source,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
IN HARDWARE_INTERRUPT_SOURCE Source,
|
||||
IN EFI_SYSTEM_CONTEXT SystemContext
|
||||
)
|
||||
{
|
||||
SP805Unlock ();
|
||||
@@ -171,15 +170,15 @@ STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
SP805RegisterHandler (
|
||||
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction
|
||||
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction
|
||||
)
|
||||
{
|
||||
if (mWatchdogNotify == NULL && NotifyFunction == NULL) {
|
||||
if ((mWatchdogNotify == NULL) && (NotifyFunction == NULL)) {
|
||||
return EFI_INVALID_PARAMETER;
|
||||
}
|
||||
|
||||
if (mWatchdogNotify != NULL && NotifyFunction != NULL) {
|
||||
if ((mWatchdogNotify != NULL) && (NotifyFunction != NULL)) {
|
||||
return EFI_ALREADY_STARTED;
|
||||
}
|
||||
|
||||
@@ -219,8 +218,8 @@ STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
SP805SetTimerPeriod (
|
||||
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
IN UINT64 TimerPeriod // In 100ns units
|
||||
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
IN UINT64 TimerPeriod // In 100ns units
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
@@ -291,8 +290,8 @@ STATIC
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
SP805GetTimerPeriod (
|
||||
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
OUT UINT64 *TimerPeriod
|
||||
IN EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
|
||||
OUT UINT64 *TimerPeriod
|
||||
)
|
||||
{
|
||||
if (TimerPeriod == NULL) {
|
||||
@@ -335,7 +334,7 @@ SP805GetTimerPeriod (
|
||||
Retrieves the period of the timer interrupt in 100 nS units.
|
||||
|
||||
**/
|
||||
STATIC EFI_WATCHDOG_TIMER_ARCH_PROTOCOL mWatchdogTimer = {
|
||||
STATIC EFI_WATCHDOG_TIMER_ARCH_PROTOCOL mWatchdogTimer = {
|
||||
SP805RegisterHandler,
|
||||
SP805SetTimerPeriod,
|
||||
SP805GetTimerPeriod
|
||||
@@ -355,16 +354,19 @@ STATIC EFI_WATCHDOG_TIMER_ARCH_PROTOCOL mWatchdogTimer = {
|
||||
EFI_STATUS
|
||||
EFIAPI
|
||||
SP805Initialize (
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
IN EFI_HANDLE ImageHandle,
|
||||
IN EFI_SYSTEM_TABLE *SystemTable
|
||||
)
|
||||
{
|
||||
EFI_STATUS Status;
|
||||
EFI_HANDLE Handle;
|
||||
|
||||
// Find the interrupt controller protocol. ASSERT if not found.
|
||||
Status = gBS->LocateProtocol (&gHardwareInterruptProtocolGuid, NULL,
|
||||
(VOID **)&mInterrupt);
|
||||
Status = gBS->LocateProtocol (
|
||||
&gHardwareInterruptProtocolGuid,
|
||||
NULL,
|
||||
(VOID **)&mInterrupt
|
||||
);
|
||||
ASSERT_EFI_ERROR (Status);
|
||||
|
||||
// Unlock access to the SP805 registers
|
||||
@@ -386,17 +388,26 @@ SP805Initialize (
|
||||
SP805Lock ();
|
||||
|
||||
if (PcdGet32 (PcdSP805WatchdogInterrupt) > 0) {
|
||||
Status = mInterrupt->RegisterInterruptSource (mInterrupt,
|
||||
Status = mInterrupt->RegisterInterruptSource (
|
||||
mInterrupt,
|
||||
PcdGet32 (PcdSP805WatchdogInterrupt),
|
||||
SP805InterruptHandler);
|
||||
SP805InterruptHandler
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
DEBUG ((DEBUG_ERROR, "%a: failed to register watchdog interrupt - %r\n",
|
||||
__FUNCTION__, Status));
|
||||
DEBUG ((
|
||||
DEBUG_ERROR,
|
||||
"%a: failed to register watchdog interrupt - %r\n",
|
||||
__FUNCTION__,
|
||||
Status
|
||||
));
|
||||
return Status;
|
||||
}
|
||||
} else {
|
||||
DEBUG ((DEBUG_WARN, "%a: no interrupt specified, running in RESET mode only\n",
|
||||
__FUNCTION__));
|
||||
DEBUG ((
|
||||
DEBUG_WARN,
|
||||
"%a: no interrupt specified, running in RESET mode only\n",
|
||||
__FUNCTION__
|
||||
));
|
||||
}
|
||||
|
||||
//
|
||||
@@ -406,8 +417,13 @@ SP805Initialize (
|
||||
ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid);
|
||||
|
||||
// Register for an ExitBootServicesEvent
|
||||
Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY,
|
||||
ExitBootServicesEvent, NULL, &mEfiExitBootServicesEvent);
|
||||
Status = gBS->CreateEvent (
|
||||
EVT_SIGNAL_EXIT_BOOT_SERVICES,
|
||||
TPL_NOTIFY,
|
||||
ExitBootServicesEvent,
|
||||
NULL,
|
||||
&mEfiExitBootServicesEvent
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
Status = EFI_OUT_OF_RESOURCES;
|
||||
goto EXIT;
|
||||
@@ -417,7 +433,8 @@ SP805Initialize (
|
||||
Handle = NULL;
|
||||
Status = gBS->InstallMultipleProtocolInterfaces (
|
||||
&Handle,
|
||||
&gEfiWatchdogTimerArchProtocolGuid, &mWatchdogTimer,
|
||||
&gEfiWatchdogTimerArchProtocolGuid,
|
||||
&mWatchdogTimer,
|
||||
NULL
|
||||
);
|
||||
if (EFI_ERROR (Status)) {
|
||||
|
@@ -6,28 +6,27 @@
|
||||
|
||||
**/
|
||||
|
||||
|
||||
#ifndef __SP805_WATCHDOG_H__
|
||||
#define __SP805_WATCHDOG_H__
|
||||
|
||||
// SP805 Watchdog Registers
|
||||
#define SP805_WDOG_LOAD_REG ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x000)
|
||||
#define SP805_WDOG_CURRENT_REG ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x004)
|
||||
#define SP805_WDOG_CONTROL_REG ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x008)
|
||||
#define SP805_WDOG_INT_CLR_REG ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x00C)
|
||||
#define SP805_WDOG_RAW_INT_STS_REG ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x010)
|
||||
#define SP805_WDOG_MSK_INT_STS_REG ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x014)
|
||||
#define SP805_WDOG_LOCK_REG ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xC00)
|
||||
#define SP805_WDOG_LOAD_REG ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x000)
|
||||
#define SP805_WDOG_CURRENT_REG ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x004)
|
||||
#define SP805_WDOG_CONTROL_REG ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x008)
|
||||
#define SP805_WDOG_INT_CLR_REG ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x00C)
|
||||
#define SP805_WDOG_RAW_INT_STS_REG ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x010)
|
||||
#define SP805_WDOG_MSK_INT_STS_REG ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0x014)
|
||||
#define SP805_WDOG_LOCK_REG ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xC00)
|
||||
|
||||
#define SP805_WDOG_PERIPH_ID0 ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFE0)
|
||||
#define SP805_WDOG_PERIPH_ID1 ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFE4)
|
||||
#define SP805_WDOG_PERIPH_ID2 ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFE8)
|
||||
#define SP805_WDOG_PERIPH_ID3 ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFEC)
|
||||
#define SP805_WDOG_PERIPH_ID0 ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFE0)
|
||||
#define SP805_WDOG_PERIPH_ID1 ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFE4)
|
||||
#define SP805_WDOG_PERIPH_ID2 ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFE8)
|
||||
#define SP805_WDOG_PERIPH_ID3 ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFEC)
|
||||
|
||||
#define SP805_WDOG_PCELL_ID0 ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFF0)
|
||||
#define SP805_WDOG_PCELL_ID1 ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFF4)
|
||||
#define SP805_WDOG_PCELL_ID2 ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFF8)
|
||||
#define SP805_WDOG_PCELL_ID3 ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFFC)
|
||||
#define SP805_WDOG_PCELL_ID0 ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFF0)
|
||||
#define SP805_WDOG_PCELL_ID1 ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFF4)
|
||||
#define SP805_WDOG_PCELL_ID2 ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFF8)
|
||||
#define SP805_WDOG_PCELL_ID3 ((UINT32)PcdGet32 (PcdSP805WatchdogBase) + 0xFFC)
|
||||
|
||||
// Timer control register bit definitions
|
||||
#define SP805_WDOG_CTRL_INTEN BIT0
|
||||
@@ -39,4 +38,4 @@
|
||||
#define SP805_WDOG_LOCK_IS_LOCKED 0x00000001
|
||||
#define SP805_WDOG_SPECIAL_UNLOCK_CODE 0x1ACCE551
|
||||
|
||||
#endif // __SP805_WATCHDOG_H__
|
||||
#endif // __SP805_WATCHDOG_H__
|
||||
|
Reference in New Issue
Block a user