ArmPlatformPkg/NorFlashDxe: Clean the driver

- Marked some functions as STATIC
- Simplified some conditions

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Olivier Martin <olivier.martin@arm.com>



git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15907 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
Olivier Martin 2014-08-26 10:20:47 +00:00 committed by oliviermartin
parent bcb53c42d0
commit 22044caa2c
2 changed files with 14 additions and 26 deletions

View File

@ -182,7 +182,7 @@ NorFlashReadStatusRegister (
return MmioRead32 (Instance->DeviceBaseAddress); return MmioRead32 (Instance->DeviceBaseAddress);
} }
STATIC
BOOLEAN BOOLEAN
NorFlashBlockIsLocked ( NorFlashBlockIsLocked (
IN NOR_FLASH_INSTANCE *Instance, IN NOR_FLASH_INSTANCE *Instance,
@ -190,9 +190,6 @@ NorFlashBlockIsLocked (
) )
{ {
UINT32 LockStatus; UINT32 LockStatus;
BOOLEAN BlockIsLocked;
BlockIsLocked = TRUE;
// Send command for reading device id // Send command for reading device id
SEND_NOR_COMMAND (BlockAddress, 2, P30_CMD_READ_DEVICE_ID); SEND_NOR_COMMAND (BlockAddress, 2, P30_CMD_READ_DEVICE_ID);
@ -207,23 +204,16 @@ NorFlashBlockIsLocked (
DEBUG((EFI_D_ERROR, "NorFlashBlockIsLocked: WARNING: Block LOCKED DOWN\n")); DEBUG((EFI_D_ERROR, "NorFlashBlockIsLocked: WARNING: Block LOCKED DOWN\n"));
} }
if ((LockStatus & 0x1) == 0) { return ((LockStatus & 0x1) != 0);
// This means the block is unlocked
DEBUG((DEBUG_BLKIO, "UnlockSingleBlock: Block 0x%08x unlocked\n", BlockAddress));
BlockIsLocked = FALSE;
}
return BlockIsLocked;
} }
STATIC
EFI_STATUS EFI_STATUS
NorFlashUnlockSingleBlock ( NorFlashUnlockSingleBlock (
IN NOR_FLASH_INSTANCE *Instance, IN NOR_FLASH_INSTANCE *Instance,
IN UINTN BlockAddress IN UINTN BlockAddress
) )
{ {
EFI_STATUS Status = EFI_SUCCESS;
UINT32 LockStatus; UINT32 LockStatus;
// Raise the Task Priority Level to TPL_NOTIFY to serialise all its operations // Raise the Task Priority Level to TPL_NOTIFY to serialise all its operations
@ -262,19 +252,21 @@ NorFlashUnlockSingleBlock (
// Put device back into Read Array mode // Put device back into Read Array mode
SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_READ_ARRAY); SEND_NOR_COMMAND (BlockAddress, 0, P30_CMD_READ_ARRAY);
DEBUG((DEBUG_BLKIO, "UnlockSingleBlock: BlockAddress=0x%08x, Exit Status = \"%r\".\n", BlockAddress, Status)); DEBUG((DEBUG_BLKIO, "UnlockSingleBlock: BlockAddress=0x%08x\n", BlockAddress));
return Status; return EFI_SUCCESS;
} }
STATIC
EFI_STATUS EFI_STATUS
NorFlashUnlockSingleBlockIfNecessary ( NorFlashUnlockSingleBlockIfNecessary (
IN NOR_FLASH_INSTANCE *Instance, IN NOR_FLASH_INSTANCE *Instance,
IN UINTN BlockAddress IN UINTN BlockAddress
) )
{ {
EFI_STATUS Status = EFI_SUCCESS; EFI_STATUS Status;
Status = EFI_SUCCESS;
if (NorFlashBlockIsLocked (Instance, BlockAddress) == TRUE) { if (NorFlashBlockIsLocked (Instance, BlockAddress) == TRUE) {
Status = NorFlashUnlockSingleBlock (Instance, BlockAddress); Status = NorFlashUnlockSingleBlock (Instance, BlockAddress);
@ -287,6 +279,7 @@ NorFlashUnlockSingleBlockIfNecessary (
/** /**
* The following function presumes that the block has already been unlocked. * The following function presumes that the block has already been unlocked.
**/ **/
STATIC
EFI_STATUS EFI_STATUS
NorFlashEraseSingleBlock ( NorFlashEraseSingleBlock (
IN NOR_FLASH_INSTANCE *Instance, IN NOR_FLASH_INSTANCE *Instance,
@ -340,7 +333,7 @@ NorFlashEraseSingleBlock (
} }
/** /**
* The following function presumes that the block has already been unlocked. * This function unlock and erase an entire NOR Flash block.
**/ **/
EFI_STATUS EFI_STATUS
NorFlashUnlockAndEraseSingleBlock ( NorFlashUnlockAndEraseSingleBlock (
@ -366,9 +359,10 @@ NorFlashUnlockAndEraseSingleBlock (
do { do {
// Unlock the block if we have to // Unlock the block if we have to
Status = NorFlashUnlockSingleBlockIfNecessary (Instance, BlockAddress); Status = NorFlashUnlockSingleBlockIfNecessary (Instance, BlockAddress);
if (!EFI_ERROR(Status)) { if (EFI_ERROR (Status)) {
Status = NorFlashEraseSingleBlock (Instance, BlockAddress); break;
} }
Status = NorFlashEraseSingleBlock (Instance, BlockAddress);
Index++; Index++;
} while ((Index < NOR_FLASH_ERASE_RETRY) && (Status == EFI_WRITE_PROTECTED)); } while ((Index < NOR_FLASH_ERASE_RETRY) && (Status == EFI_WRITE_PROTECTED));

View File

@ -364,10 +364,4 @@ NorFlashReset (
IN NOR_FLASH_INSTANCE *Instance IN NOR_FLASH_INSTANCE *Instance
); );
EFI_STATUS
NorFlashUnlockSingleBlockIfNecessary (
IN NOR_FLASH_INSTANCE *Instance,
IN UINTN BlockAddress
);
#endif /* __NOR_FLASH_DXE_H__ */ #endif /* __NOR_FLASH_DXE_H__ */