flash_block_device.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _FLASH_BLOCK_DEVICE_H_
  13. #define _FLASH_BLOCK_DEVICE_H_
  14. #include "block_device.h"
  15. #include "fs_config.h"
  16. #include <stdbool.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. struct drvSpiFlash;
  21. struct drvGeneralSpiFlash;
  22. #ifdef CONFIG_FS_FBDEV_DEFAULT_V1
  23. #define FLASH_BLOCKDEVICE_CREATE flashBlockDeviceCreate
  24. #define FLASH_BLOCKDEVICE_FORMAT flashBlockDeviceFormat
  25. #endif
  26. #ifdef CONFIG_FS_FBDEV_DEFAULT_V2
  27. #define FLASH_BLOCKDEVICE_CREATE flashBlockDeviceCreateV2
  28. #define FLASH_BLOCKDEVICE_FORMAT flashBlockDeviceFormatV2
  29. #endif
  30. /**
  31. * @brief create a flash block device
  32. *
  33. * There are cases fail to create flash block device:
  34. * - Failed to allocate memory for flash block device;
  35. * - Invalid parameters for flash block device;
  36. * - There are more than one EB doesn't match the configuration. It occurs
  37. * when the parameters are not the same as the parameters at create.
  38. * It should only happen at development.
  39. *
  40. * Except that, other errors will be handled silently. So, at initialization,
  41. * the return value should be checked, and call \a FLASH_BLOCKDEVICE_FORMAT
  42. * and then call \a FLASH_BLOCKDEVICE_CREATE again. If it is failed again,
  43. * usually \a osiPanic can be called.
  44. *
  45. * @param flash the flash driver instance
  46. * @param phys_start start offset in flash
  47. * @param phys_size the region size
  48. * @param phys_erase_size erase block size
  49. * @param block_size block size of block device
  50. * @param read_only at read only, no flash erase and program
  51. * @return
  52. * - NULL if failed to create flash block device
  53. * - instance pointer
  54. */
  55. blockDevice_t *flashBlockDeviceCreate(
  56. struct drvSpiFlash *flash,
  57. uint32_t phys_start,
  58. uint32_t phys_size,
  59. uint32_t phys_erase_size,
  60. uint32_t block_size,
  61. bool read_only);
  62. /**
  63. * @brief format flash region block device
  64. *
  65. * @param flash the flash driver instance
  66. * @param phys_start start offset in flash
  67. * @param phys_size the region size
  68. * @param phys_erase_size erase block size
  69. * @param block_size block size of block device
  70. * @return
  71. * - false if failed to format region for flash block device.
  72. * Only when the configuration is invalid, it will fail.
  73. * - true if the region is formatted
  74. */
  75. bool flashBlockDeviceFormat(
  76. struct drvSpiFlash *flash,
  77. uint32_t phys_start,
  78. uint32_t phys_size,
  79. uint32_t phys_erase_size,
  80. uint32_t block_size);
  81. /**
  82. * @brief create a flash block device version 2
  83. *
  84. * There are cases fail to create flash block device:
  85. * - Failed to allocate memory for flash block device;
  86. * - Invalid parameters for flash block device;
  87. * - There are more than one EB doesn't match the configuration. It occurs
  88. * when the parameters are not the same as the parameters at create.
  89. * It should only happen at development.
  90. *
  91. * Except that, other errors will be handled silently. So, at initialization,
  92. * the return value should be checked, and call \a FLASH_BLOCKDEVICE_FORMAT
  93. * and then call \a FLASH_BLOCKDEVICE_CREATE again. If it is failed again,
  94. * usually \a osiPanic can be called.
  95. *
  96. * \p block_size is PB of flash block device. In version 2, LB size is not
  97. * the same with PB size. So, always use blockDevice_t.block_size as LB size.
  98. *
  99. * @param flash the flash driver instance
  100. * @param phys_start start offset in flash
  101. * @param phys_size the region size
  102. * @param phys_erase_size erase block size
  103. * @param block_size block size of block device
  104. * @param read_only at read only, no flash erase and program
  105. * @return
  106. * - NULL if failed to create flash block device
  107. * - instance pointer
  108. */
  109. blockDevice_t *flashBlockDeviceCreateV2(
  110. struct drvSpiFlash *flash,
  111. uint32_t phys_start,
  112. uint32_t phys_size,
  113. uint32_t phys_erase_size,
  114. uint32_t block_size,
  115. bool read_only);
  116. blockDevice_t *generalSpiflashBlockDeviceCreateV2(
  117. struct drvGeneralSpiFlash *flash,
  118. uint32_t phys_start,
  119. uint32_t phys_size,
  120. uint32_t phys_erase_size,
  121. uint32_t block_size,
  122. bool read_only);
  123. /**
  124. * @brief quick create a flash block device version 2
  125. *
  126. * Comparing to \p flashBlockDeviceCreateV2, it is assumed that the flash
  127. * block device is *clean*, that is, there are no interrupted erase and
  128. * write. So, it can be faster.
  129. *
  130. * @param flash the flash driver instance
  131. * @param phys_start start offset in flash
  132. * @param phys_size the region size
  133. * @param phys_erase_size erase block size
  134. * @param block_size block size of block device
  135. * @param read_only at read only, no flash erase and program
  136. * @return
  137. * - NULL if failed to create flash block device
  138. * - instance pointer
  139. */
  140. blockDevice_t *flashBlockDeviceQuickCreateV2(
  141. struct drvSpiFlash *flash,
  142. uint32_t phys_start,
  143. uint32_t phys_size,
  144. uint32_t phys_erase_size,
  145. uint32_t block_size,
  146. bool read_only);
  147. /**
  148. * @brief format flash block device version 2
  149. *
  150. * @param flash the flash driver instance
  151. * @param phys_start start offset in flash
  152. * @param phys_size the region size
  153. * @param phys_erase_size erase block size
  154. * @param block_size block size of block device
  155. * @return
  156. * - false if failed to format region for flash block device.
  157. * Only when the configuration is invalid, it will fail.
  158. * - true if the region is formatted
  159. */
  160. bool flashBlockDeviceFormatV2(
  161. struct drvSpiFlash *flash,
  162. uint32_t phys_start,
  163. uint32_t phys_size,
  164. uint32_t phys_erase_size,
  165. uint32_t block_size);
  166. #ifdef __cplusplus
  167. }
  168. #endif
  169. #endif