public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Sami Mujawar" <sami.mujawar@arm.com>
To: Sahil Kaushal <Sahil.Kaushal@arm.com>, devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Leif Lindholm <quic_llindhol@quicinc.com>, sahil <sahil@arm.com>,
	"nd@arm.com" <nd@arm.com>
Subject: Re: [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 04/14] Platform/ARM/NorFlashDxe: Move flash specific functions to NorFlash.c
Date: Thu, 16 May 2024 16:17:50 +0100	[thread overview]
Message-ID: <671f4b3b-7ae8-49db-9e6e-91916af9991e@arm.com> (raw)
In-Reply-To: <20240423055638.1271531-5-Sahil.Kaushal@arm.com>

Hi Sahil,

Thank you for this patch.

These changes look good to me.

Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>

Regards,

Sami Mujawar

On 23/04/2024 06:56 am, Sahil Kaushal wrote:
> From: sahil <sahil@arm.com>
>
> Refactoring done in this patch has two major parts:
>
> 1. Moving out NorFlashUnlockAndEraseSingleBlock and
> NorFlashWriteFullBlock functions from NorFlashDxe.c and
> NorFlashStandaloneMm.c to NorFlash.c files.
>
> 2. At the same time, we are adding NorFlashLock and NorFlashUnlock
> functions which will take care of TPL related operations needed by
> functions mentioned in point 1. These functions are implemented
> in NorFlashDxe.c but are just dummy placeholder functions in
> NorFlashStandaloneMm.c file.
>
> Signed-off-by: sahil <sahil@arm.com>
> ---
>   Platform/ARM/Drivers/NorFlashDxe/NorFlash.h             |  26 +++
>   Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h       |  14 --
>   Platform/ARM/Drivers/NorFlashDxe/NorFlash.c             | 136 +++++++++++++-
>   Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c          | 193 ++++----------------
>   Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c | 151 +++------------
>   5 files changed, 225 insertions(+), 295 deletions(-)
>
> diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
> index e0ebb1e2fd35..bd5c6a949cf0 100644
> --- a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
> +++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.h
> @@ -220,4 +220,30 @@ NorFlashWriteSingleWord (
>     IN UINT32              WriteData
>
>     );
>
>   
>
> +EFI_STATUS
>
> +NorFlashWriteFullBlock (
>
> +  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
>
> +  );
>
> +
>
> +VOID
>
> +EFIAPI
>
> +NorFlashLock (
>
> +  IN EFI_TPL  *OriginalTPL
>
> +  );
>
> +
>
> +VOID
>
> +EFIAPI
>
> +NorFlashUnlock (
>
> +  IN EFI_TPL OriginalTPL
>
> +  );
>
> +
>
>   #endif /* __NOR_FLASH_H__ */
>
> diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h b/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h
> index e329e0727617..c0a3b5861532 100644
> --- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h
> +++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashCommon.h
> @@ -31,20 +31,6 @@
>   //
>
>   // NorFlashDxe.c
>
>   //
>
> -EFI_STATUS
>
> -NorFlashWriteFullBlock (
>
> -  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
>
> -  );
>
> -
>
>   EFI_STATUS
>
>   NorFlashCreateInstance (
>
>     IN UINTN                NorFlashDeviceBase,
>
> diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c
> index 4e5a97c83c7b..15000a692b02 100644
> --- a/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c
> +++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlash.c
> @@ -10,7 +10,6 @@
>   #include <Library/BaseMemoryLib.h>
>
>   
>
>   #include "NorFlash.h"
>
> -#include "NorFlashCommon.h"
>
>   
>
>   //
>
>   // Global variable declarations
>
> @@ -817,3 +816,138 @@ NorFlashReset (
>     SEND_NOR_COMMAND (Instance->DeviceBaseAddress, 0, P30_CMD_READ_ARRAY);
>
>     return EFI_SUCCESS;
>
>   }
>
> +
>
> +/**
>
> + * This function unlock and erase an entire NOR Flash block.
>
> +**/
>
> +EFI_STATUS
>
> +NorFlashUnlockAndEraseSingleBlock (
>
> +  IN NOR_FLASH_INSTANCE  *Instance,
>
> +  IN UINTN               BlockAddress
>
> +  )
>
> +{
>
> +  EFI_STATUS  Status;
>
> +  UINTN       Index;
>
> +  EFI_TPL     OriginalTPL;
>
> +
>
> +  NorFlashLock (&OriginalTPL);
>
> +
>
> +  Index = 0;
>
> +  // The block erase might fail a first time (SW bug ?). Retry it ...
>
> +  do {
>
> +    // Unlock the block if we have to
>
> +    Status = NorFlashUnlockSingleBlockIfNecessary (Instance, BlockAddress);
>
> +    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));
>
> +  }
>
> +
>
> +  NorFlashUnlock (OriginalTPL);
>
> +
>
> +  return Status;
>
> +}
>
> +
>
> +EFI_STATUS
>
> +NorFlashWriteFullBlock (
>
> +  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;
>
> +
>
> +  Status = EFI_SUCCESS;
>
> +
>
> +  // Get the physical address of the block
>
> +  BlockAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, Lba, BlockSizeInWords * 4);
>
> +
>
> +  // Start writing from the first address at the start of the block
>
> +  WordAddress = BlockAddress;
>
> +
>
> +  NorFlashLock (&OriginalTPL);
>
> +
>
> +  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));
>
> +    goto EXIT;
>
> +  }
>
> +
>
> +  // To speed up the programming operation, NOR Flash is programmed using the Buffered Programming method.
>
> +
>
> +  // 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;
>
> +         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)) {
>
> +            goto EXIT;
>
> +          }
>
> +
>
> +          break;
>
> +        }
>
> +      }
>
> +    }
>
> +
>
> +    // 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) {
>
> +      Status = NorFlashWriteBuffer (Instance, WordAddress, (RemainingWords * 4), DataBuffer);
>
> +      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) {
>
> +      Status = NorFlashWriteSingleWord (Instance, WordAddress, *DataBuffer);
>
> +      if (EFI_ERROR (Status)) {
>
> +        goto EXIT;
>
> +      }
>
> +    }
>
> +  }
>
> +
>
> +EXIT:
>
> +  NorFlashUnlock (OriginalTPL);
>
> +
>
> +  if (EFI_ERROR (Status)) {
>
> +    DEBUG ((DEBUG_ERROR, "NOR FLASH Programming [WriteSingleBlock] failed at address 0x%08x. Exit Status = \"%r\".\n", WordAddress, Status));
>
> +  }
>
> +
>
> +  return Status;
>
> +}
>
> diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c b/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c
> index b1e01169c24e..4bad6e9b2a6b 100644
> --- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c
> +++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashDxe.c
> @@ -174,161 +174,6 @@ NorFlashCreateInstance (
>     return Status;
>
>   }
>
>   
>
> -/**
>
> - * This function unlock and erase an entire NOR Flash block.
>
> - **/
>
> -EFI_STATUS
>
> -NorFlashUnlockAndEraseSingleBlock (
>
> -  IN NOR_FLASH_INSTANCE  *Instance,
>
> -  IN UINTN               BlockAddress
>
> -  )
>
> -{
>
> -  EFI_STATUS  Status;
>
> -  UINTN       Index;
>
> -  EFI_TPL     OriginalTPL;
>
> -
>
> -  if (!EfiAtRuntime ()) {
>
> -    // Raise TPL to TPL_HIGH to stop anyone from interrupting us.
>
> -    OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);
>
> -  } else {
>
> -    // This initialization is only to prevent the compiler to complain about the
>
> -    // use of uninitialized variables
>
> -    OriginalTPL = TPL_HIGH_LEVEL;
>
> -  }
>
> -
>
> -  Index = 0;
>
> -  // The block erase might fail a first time (SW bug ?). Retry it ...
>
> -  do {
>
> -    // Unlock the block if we have to
>
> -    Status = NorFlashUnlockSingleBlockIfNecessary (Instance, BlockAddress);
>
> -    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));
>
> -  }
>
> -
>
> -  if (!EfiAtRuntime ()) {
>
> -    // Interruptions can resume.
>
> -    gBS->RestoreTPL (OriginalTPL);
>
> -  }
>
> -
>
> -  return Status;
>
> -}
>
> -
>
> -EFI_STATUS
>
> -NorFlashWriteFullBlock (
>
> -  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;
>
> -
>
> -  Status = EFI_SUCCESS;
>
> -
>
> -  // Get the physical address of the block
>
> -  BlockAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, Lba, BlockSizeInWords * 4);
>
> -
>
> -  // Start writing from the first address at the start of the block
>
> -  WordAddress = BlockAddress;
>
> -
>
> -  if (!EfiAtRuntime ()) {
>
> -    // Raise TPL to TPL_HIGH to stop anyone from interrupting us.
>
> -    OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);
>
> -  } else {
>
> -    // This initialization is only to prevent the compiler to complain about the
>
> -    // use of uninitialized variables
>
> -    OriginalTPL = TPL_HIGH_LEVEL;
>
> -  }
>
> -
>
> -  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));
>
> -    goto EXIT;
>
> -  }
>
> -
>
> -  // To speed up the programming operation, NOR Flash is programmed using the Buffered Programming method.
>
> -
>
> -  // 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;
>
> -         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)) {
>
> -            goto EXIT;
>
> -          }
>
> -
>
> -          break;
>
> -        }
>
> -      }
>
> -    }
>
> -
>
> -    // 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) {
>
> -      Status = NorFlashWriteBuffer (Instance, WordAddress, (RemainingWords * 4), DataBuffer);
>
> -      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) {
>
> -      Status = NorFlashWriteSingleWord (Instance, WordAddress, *DataBuffer);
>
> -      if (EFI_ERROR (Status)) {
>
> -        goto EXIT;
>
> -      }
>
> -    }
>
> -  }
>
> -
>
> -EXIT:
>
> -  if (!EfiAtRuntime ()) {
>
> -    // Interruptions can resume.
>
> -    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));
>
> -  }
>
> -
>
> -  return Status;
>
> -}
>
> -
>
>   EFI_STATUS
>
>   EFIAPI
>
>   NorFlashInitialise (
>
> @@ -549,3 +394,41 @@ NorFlashVirtualNotifyEvent (
>   
>
>     return;
>
>   }
>
> +
>
> +/**
>
> +  Lock all pending read/write to Nor flash device
>
> +
>
> +  @param[in]     *OriginalTPL     Pointer to Nor flash device Original TPL.
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +NorFlashLock (
>
> +  IN EFI_TPL  *OriginalTPL
>
> +  )
>
> +{
>
> +  if (!EfiAtRuntime ()) {
>
> +    // Raise TPL to TPL_HIGH to stop anyone from interrupting us.
>
> +    *OriginalTPL = gBS->RaiseTPL (TPL_HIGH_LEVEL);
>
> +  } else {
>
> +    // This initialization is only to prevent the compiler to complain about the
>
> +    // use of uninitialized variables
>
> +    *OriginalTPL = TPL_HIGH_LEVEL;
>
> +  }
>
> +}
>
> +
>
> +/**
>
> +  Unlock all pending read/write to Nor flash device
>
> +
>
> +  @param[in]     OriginalTPL     Nor flash device Original TPL.
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +NorFlashUnlock (
>
> +  IN EFI_TPL  OriginalTPL
>
> +  )
>
> +{
>
> +  if (!EfiAtRuntime ()) {
>
> +    // Interruptions can resume.
>
> +    gBS->RestoreTPL (OriginalTPL);
>
> +  }
>
> +}
>
> diff --git a/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c b/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c
> index f2919265139b..5bff524e5e18 100644
> --- a/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c
> +++ b/Platform/ARM/Drivers/NorFlashDxe/NorFlashStandaloneMm.c
> @@ -153,131 +153,6 @@ NorFlashCreateInstance (
>     return Status;
>
>   }
>
>   
>
> -/**
>
> - * This function unlock and erase an entire NOR Flash block.
>
> - **/
>
> -EFI_STATUS
>
> -NorFlashUnlockAndEraseSingleBlock (
>
> -  IN NOR_FLASH_INSTANCE  *Instance,
>
> -  IN UINTN               BlockAddress
>
> -  )
>
> -{
>
> -  EFI_STATUS  Status;
>
> -  UINTN       Index;
>
> -
>
> -  Index = 0;
>
> -  // The block erase might fail a first time (SW bug ?). Retry it ...
>
> -  do {
>
> -    // Unlock the block if we have to
>
> -    Status = NorFlashUnlockSingleBlockIfNecessary (Instance, BlockAddress);
>
> -    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));
>
> -  }
>
> -
>
> -  return Status;
>
> -}
>
> -
>
> -EFI_STATUS
>
> -NorFlashWriteFullBlock (
>
> -  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;
>
> -
>
> -  Status = EFI_SUCCESS;
>
> -
>
> -  // Get the physical address of the block
>
> -  BlockAddress = GET_NOR_BLOCK_ADDRESS (Instance->RegionBaseAddress, Lba, BlockSizeInWords * 4);
>
> -
>
> -  // Start writing from the first address at the start of the block
>
> -  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));
>
> -    goto EXIT;
>
> -  }
>
> -
>
> -  // To speed up the programming operation, NOR Flash is programmed using the Buffered Programming method.
>
> -
>
> -  // 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;
>
> -         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)) {
>
> -            goto EXIT;
>
> -          }
>
> -
>
> -          break;
>
> -        }
>
> -      }
>
> -    }
>
> -
>
> -    // 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) {
>
> -      Status = NorFlashWriteBuffer (Instance, WordAddress, (RemainingWords * 4), DataBuffer);
>
> -      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) {
>
> -      Status = NorFlashWriteSingleWord (Instance, WordAddress, *DataBuffer);
>
> -      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));
>
> -  }
>
> -
>
> -  return Status;
>
> -}
>
> -
>
>   EFI_STATUS
>
>   EFIAPI
>
>   NorFlashInitialise (
>
> @@ -382,3 +257,29 @@ NorFlashFvbInitialize (
>   
>
>     return Status;
>
>   }
>
> +
>
> +/**
>
> +  Lock all pending read/write to Nor flash device
>
> +
>
> +  @param[in]     OriginalTPL     Nor flash device Original TPL.
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +NorFlashLock (
>
> +  IN EFI_TPL  *OriginalTPL
>
> +  )
>
> +{
>
> +}
>
> +
>
> +/**
>
> +  Unlock all pending read/write to Nor flash device
>
> +
>
> +  @param[in]     OriginalTPL     Nor flash device Original TPL.
>
> +**/
>
> +VOID
>
> +EFIAPI
>
> +NorFlashUnlock (
>
> +  IN EFI_TPL  OriginalTPL
>
> +  )
>
> +{
>
> +}
>


-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#118960): https://edk2.groups.io/g/devel/message/118960
Mute This Topic: https://groups.io/mt/105690939/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  parent reply	other threads:[~2024-05-16 15:18 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-23  5:56 [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 00/14] Split NorFlashDxe driver and add CadenceQspiNorFlashDeviceLib library Sahil Kaushal
2024-04-23  5:56 ` [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 01/14] Platform/ARM/NorFlashDxe: Move DiskIo related functions out of NorFlash.c Sahil Kaushal
2024-04-24  9:49   ` levi.yun
2024-05-16 15:17   ` Sami Mujawar
2024-04-23  5:56 ` [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 02/14] Platform/ARM/NorFlashDxe: Move NorFlashVirtualNotifyEvent Sahil Kaushal
2024-05-16 15:17   ` Sami Mujawar
2024-04-23  5:56 ` [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 03/14] Platform/ARM/NorFlashDxe: Add NorFlashCommon.h header file Sahil Kaushal
2024-04-24  9:49   ` levi.yun
2024-05-16 15:17   ` Sami Mujawar
2024-04-23  5:56 ` [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 04/14] Platform/ARM/NorFlashDxe: Move flash specific functions to NorFlash.c Sahil Kaushal
2024-04-24  9:49   ` levi.yun
2024-05-16 15:17   ` Sami Mujawar [this message]
2024-04-23  5:56 ` [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 05/14] Platform/ARM: Create NorFlashDeviceLib library interface for flash specific functions Sahil Kaushal
2024-04-24  9:50   ` levi.yun
2024-05-16 15:18   ` Sami Mujawar
2024-05-21  8:37     ` sahil
2024-05-21 14:05       ` Sami Mujawar
2024-04-23  5:56 ` [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 06/14] Platform/ARM: Add P30NorFlashDeviceLib Library Sahil Kaushal
2024-04-24  9:49   ` levi.yun
2024-05-16 15:18   ` Sami Mujawar
2024-04-23  5:56 ` [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 07/14] Platform/ARM/NorFlashDxe: Switch from NorFlash.c to NorFlashDeviceLib Sahil Kaushal
2024-04-24  9:50   ` levi.yun
2024-05-16 15:18   ` Sami Mujawar
2024-04-23  5:56 ` [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 08/14] Platform/ARM: Add HostRegisterBaseAddress variable Sahil Kaushal
2024-04-24  9:50   ` levi.yun
2024-05-16 15:22   ` Sami Mujawar
2024-04-23  5:56 ` [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 09/14] Platform/ARM: Add optional provision to fetch and print NOR Flash info Sahil Kaushal
2024-04-24  9:51   ` levi.yun
2024-05-16 15:23   ` Sami Mujawar
2024-04-23  5:56 ` [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 10/14] Silicon/ARM/NeoverseN1Soc: Enable SCP QSPI flash region Sahil Kaushal
2024-04-24  9:50   ` levi.yun
2024-05-16 15:23   ` Sami Mujawar
2024-04-23  5:56 ` [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 11/14] Silicon/ARM/NeoverseN1Soc: NOR flash library for N1Sdp Sahil Kaushal
2024-04-24  9:50   ` levi.yun
2024-05-16 15:23   ` Sami Mujawar
2024-05-21  9:24     ` sahil
2024-05-21 12:59       ` Sami Mujawar
2024-04-23  5:56 ` [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 12/14] Platform/ARM: Add CadenceQspiNorFlashDeviceLib for NorFlashDxe Sahil Kaushal
2024-04-24  9:55   ` levi.yun
2024-05-02 13:17   ` PierreGondois
2024-05-09  6:25     ` sahil
2024-05-16 15:25       ` Sami Mujawar
2024-05-16 15:24   ` Sami Mujawar
2024-04-23  5:56 ` [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 13/14] Platform/ARM/N1Sdp: Persistent storage for N1Sdp Sahil Kaushal
2024-04-24  9:55   ` levi.yun
2024-05-16 15:24   ` Sami Mujawar
2024-04-23  5:56 ` [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 14/14] Platform/ARM/N1Sdp: Enable FaultTolerantWrite Dxe driver " Sahil Kaushal
2024-04-24  9:51   ` levi.yun
2024-05-16 15:24   ` Sami Mujawar
2024-05-02 13:16 ` [edk2-devel] [PATCH RESEND edk2-platforms][PATCH V2 00/14] Split NorFlashDxe driver and add CadenceQspiNorFlashDeviceLib library PierreGondois

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=671f4b3b-7ae8-49db-9e6e-91916af9991e@arm.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox