fal.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * File : fal.h
  3. * This file is part of FAL (Flash Abstraction Layer) package
  4. * COPYRIGHT (C) 2006 - 2018, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2018-05-17 armink the first version
  23. */
  24. #ifndef _FAL_H_
  25. #define _FAL_H_
  26. #include <fal_cfg.h>
  27. #include "fal_def.h"
  28. /**
  29. * FAL (Flash Abstraction Layer) initialization.
  30. * It will initialize all flash device and all flash partition.
  31. *
  32. * @return >= 0: partitions total number
  33. */
  34. int fal_init(void);
  35. /* =============== flash device operator API =============== */
  36. /**
  37. * find flash device by name
  38. *
  39. * @param name flash device name
  40. *
  41. * @return != NULL: flash device
  42. * NULL: not found
  43. */
  44. const struct fal_flash_dev *fal_flash_device_find(const char *name);
  45. /* =============== partition operator API =============== */
  46. /**
  47. * find the partition by name
  48. *
  49. * @param name partition name
  50. *
  51. * @return != NULL: partition
  52. * NULL: not found
  53. */
  54. const struct fal_partition *fal_partition_find(const char *name);
  55. /**
  56. * get the partition table
  57. *
  58. * @param len return the partition table length
  59. *
  60. * @return partition table
  61. */
  62. const struct fal_partition *fal_get_partition_table(size_t *len);
  63. /**
  64. * set partition table temporarily
  65. * This setting will modify the partition table temporarily, the setting will be lost after restart.
  66. *
  67. * @param table partition table
  68. * @param len partition table length
  69. */
  70. void fal_set_partition_table_temp(struct fal_partition *table, size_t len);
  71. /**
  72. * read data from partition
  73. *
  74. * @param part partition
  75. * @param addr relative address for partition
  76. * @param buf read buffer
  77. * @param size read size
  78. *
  79. * @return >= 0: successful read data size
  80. * -1: error
  81. */
  82. int fal_partition_read(const struct fal_partition *part, uint32_t addr, uint8_t *buf, size_t size);
  83. /**
  84. * write data to partition
  85. *
  86. * @param part partition
  87. * @param addr relative address for partition
  88. * @param buf write buffer
  89. * @param size write size
  90. *
  91. * @return >= 0: successful write data size
  92. * -1: error
  93. */
  94. int fal_partition_write(const struct fal_partition *part, uint32_t addr, const uint8_t *buf, size_t size);
  95. /**
  96. * erase partition data
  97. *
  98. * @param part partition
  99. * @param addr relative address for partition
  100. * @param size erase size
  101. *
  102. * @return >= 0: successful erased data size
  103. * -1: error
  104. */
  105. int fal_partition_erase(const struct fal_partition *part, uint32_t addr, size_t size);
  106. /**
  107. * erase partition all data
  108. *
  109. * @param part partition
  110. *
  111. * @return >= 0: successful erased data size
  112. * -1: error
  113. */
  114. int fal_partition_erase_all(const struct fal_partition *part);
  115. /**
  116. * print the partition table
  117. */
  118. void fal_show_part_table(void);
  119. /* =============== API provided to RT-Thread =============== */
  120. /**
  121. * create RT-Thread block device by specified partition
  122. *
  123. * @param parition_name partition name
  124. *
  125. * @return != NULL: created block device
  126. * NULL: created failed
  127. */
  128. struct rt_device *fal_blk_device_create(const char *parition_name);
  129. #if defined(RT_USING_MTD_NOR)
  130. /**
  131. * create RT-Thread MTD NOR device by specified partition
  132. *
  133. * @param parition_name partition name
  134. *
  135. * @return != NULL: created MTD NOR device
  136. * NULL: created failed
  137. */
  138. struct rt_device *fal_mtd_nor_device_create(const char *parition_name);
  139. #endif /* defined(RT_USING_MTD_NOR) */
  140. /**
  141. * create RT-Thread char device by specified partition
  142. *
  143. * @param parition_name partition name
  144. *
  145. * @return != NULL: created char device
  146. * NULL: created failed
  147. */
  148. struct rt_device *fal_char_device_create(const char *parition_name);
  149. #endif /* _FAL_H_ */