FlashFvbDxe.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /** @file
  2. *
  3. * Copyright (c) 2011-2015, ARM Limited. All rights reserved.
  4. * Copyright (c) 2015, Hisilicon Limited. All rights reserved.
  5. * Copyright (c) 2015, Linaro Limited. All rights reserved.
  6. *
  7. * This program and the accompanying materials
  8. * are licensed and made available under the terms and conditions of the BSD License
  9. * which accompanies this distribution. The full text of the license may be found at
  10. * http://opensource.org/licenses/bsd-license.php
  11. *
  12. * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  14. *
  15. **/
  16. #ifndef __FLASH_FVB_DXE_H__
  17. #define __FLASH_FVB_DXE_H__
  18. #include <Uefi.h>
  19. #include <PiDxe.h>
  20. #include <Library/BaseLib.h>
  21. #include <Library/HobLib.h>
  22. #include <Protocol/BlockIo.h>
  23. #include <Protocol/FirmwareVolumeBlock.h>
  24. #include <Library/DebugLib.h>
  25. #include <Library/IoLib.h>
  26. #include <Library/UefiLib.h>
  27. #include <Library/PcdLib.h>
  28. #include <Library/BaseMemoryLib.h>
  29. #include <Library/MemoryAllocationLib.h>
  30. #include <Library/UefiBootServicesTableLib.h>
  31. #include <Protocol/HisiSpiFlashProtocol.h>
  32. #include <Library/UefiRuntimeServicesTableLib.h>
  33. #include <Library/UefiRuntimeLib.h>
  34. #include <Guid/VariableFormat.h>
  35. #include <Guid/SystemNvDataGuid.h>
  36. #define FLASH_ERASE_RETRY 10
  37. #define FLASH_DEVICE_COUNT 1
  38. // Device access macros
  39. // These are necessary because we use 2 x 16bit parts to make up 32bit data
  40. typedef struct
  41. {
  42. UINTN DeviceBaseAddress; // Start address of the Device Base Address (DBA)
  43. UINTN RegionBaseAddress; // Start address of one single region
  44. UINTN Size;
  45. UINTN BlockSize;
  46. EFI_GUID Guid;
  47. } FLASH_DESCRIPTION;
  48. #define GET_BLOCK_ADDRESS(BaseAddr,Lba,LbaSize)( BaseAddr + (UINTN)((Lba) * LbaSize) )
  49. #define FLASH_SIGNATURE SIGNATURE_32('s', 'p', 'i', '0')
  50. #define INSTANCE_FROM_FVB_THIS(a) CR(a, FLASH_INSTANCE, FvbProtocol, FLASH_SIGNATURE)
  51. #define INSTANCE_FROM_BLKIO_THIS(a) CR(a, FLASH_INSTANCE, BlockIoProtocol, FLASH_SIGNATURE)
  52. typedef struct _FLASH_INSTANCE FLASH_INSTANCE;
  53. typedef EFI_STATUS (*FLASH_INITIALIZE) (FLASH_INSTANCE* Instance);
  54. typedef struct
  55. {
  56. VENDOR_DEVICE_PATH Vendor;
  57. EFI_DEVICE_PATH_PROTOCOL End;
  58. } FLASH_DEVICE_PATH;
  59. struct _FLASH_INSTANCE
  60. {
  61. UINT32 Signature;
  62. EFI_HANDLE Handle;
  63. BOOLEAN Initialized;
  64. FLASH_INITIALIZE Initialize;
  65. UINTN DeviceBaseAddress;
  66. UINTN RegionBaseAddress;
  67. UINTN Size;
  68. EFI_LBA StartLba;
  69. EFI_BLOCK_IO_PROTOCOL BlockIoProtocol;
  70. EFI_BLOCK_IO_MEDIA Media;
  71. BOOLEAN SupportFvb;
  72. EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL FvbProtocol;
  73. FLASH_DEVICE_PATH DevicePath;
  74. };
  75. //
  76. // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.ReadBlocks
  77. //
  78. EFI_STATUS
  79. EFIAPI
  80. FlashBlockIoReadBlocks (
  81. IN EFI_BLOCK_IO_PROTOCOL* This,
  82. IN UINT32 MediaId,
  83. IN EFI_LBA Lba,
  84. IN UINTN BufferSizeInBytes,
  85. OUT VOID* Buffer
  86. );
  87. //
  88. // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.WriteBlocks
  89. //
  90. EFI_STATUS
  91. EFIAPI
  92. FlashBlockIoWriteBlocks (
  93. IN EFI_BLOCK_IO_PROTOCOL* This,
  94. IN UINT32 MediaId,
  95. IN EFI_LBA Lba,
  96. IN UINTN BufferSizeInBytes,
  97. IN VOID* Buffer
  98. );
  99. //
  100. // BlockIO Protocol function EFI_BLOCK_IO_PROTOCOL.FlushBlocks
  101. //
  102. EFI_STATUS
  103. EFIAPI
  104. FlashBlockIoFlushBlocks (
  105. IN EFI_BLOCK_IO_PROTOCOL* This
  106. );
  107. //
  108. // FvbHw.c
  109. //
  110. EFI_STATUS
  111. EFIAPI
  112. FvbInitialize (
  113. IN FLASH_INSTANCE* Instance
  114. );
  115. EFI_STATUS
  116. EFIAPI
  117. FvbGetAttributes(
  118. IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL* This,
  119. OUT EFI_FVB_ATTRIBUTES_2* Attributes
  120. );
  121. EFI_STATUS
  122. EFIAPI
  123. FvbSetAttributes(
  124. IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL* This,
  125. IN OUT EFI_FVB_ATTRIBUTES_2* Attributes
  126. );
  127. EFI_STATUS
  128. EFIAPI
  129. FvbGetPhysicalAddress(
  130. IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL* This,
  131. OUT EFI_PHYSICAL_ADDRESS* Address
  132. );
  133. EFI_STATUS
  134. EFIAPI
  135. FvbGetBlockSize(
  136. IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL* This,
  137. IN EFI_LBA Lba,
  138. OUT UINTN* BlockSize,
  139. OUT UINTN* NumberOfBlocks
  140. );
  141. EFI_STATUS
  142. EFIAPI
  143. FvbRead(
  144. IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL* This,
  145. IN EFI_LBA Lba,
  146. IN UINTN Offset,
  147. IN OUT UINTN* NumBytes,
  148. IN OUT UINT8* Buffer
  149. );
  150. EFI_STATUS
  151. EFIAPI
  152. FvbWrite(
  153. IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL* This,
  154. IN EFI_LBA Lba,
  155. IN UINTN Offset,
  156. IN OUT UINTN* NumBytes,
  157. IN UINT8* Buffer
  158. );
  159. EFI_STATUS
  160. EFIAPI
  161. FvbEraseBlocks(
  162. IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL* This,
  163. ...
  164. );
  165. //
  166. // FlashFvbDxe.c
  167. //
  168. EFI_STATUS
  169. FlashUnlockAndEraseSingleBlock (
  170. IN FLASH_INSTANCE* Instance,
  171. IN UINTN BlockAddress
  172. );
  173. EFI_STATUS
  174. FlashWriteBlocks (
  175. IN FLASH_INSTANCE* Instance,
  176. IN EFI_LBA Lba,
  177. IN UINTN BufferSizeInBytes,
  178. IN VOID* Buffer
  179. );
  180. EFI_STATUS
  181. FlashReadBlocks (
  182. IN FLASH_INSTANCE* Instance,
  183. IN EFI_LBA Lba,
  184. IN UINTN BufferSizeInBytes,
  185. OUT VOID* Buffer
  186. );
  187. #endif