fal.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-05-17 armink the first version
  9. */
  10. #ifndef _FAL_H_
  11. #define _FAL_H_
  12. #include <fal_cfg.h>
  13. #include "fal_def.h"
  14. /**
  15. * FAL (Flash Abstraction Layer) initialization.
  16. * It will initialize all flash device and all flash partition.
  17. *
  18. * @return >= 0: partitions total number
  19. */
  20. int fal_init(void);
  21. /* =============== flash device operator API =============== */
  22. /**
  23. * find flash device by name
  24. *
  25. * @param name flash device name
  26. *
  27. * @return != NULL: flash device
  28. * NULL: not found
  29. */
  30. const struct fal_flash_dev *fal_flash_device_find(const char *name);
  31. /* =============== partition operator API =============== */
  32. /**
  33. * find the partition by name
  34. *
  35. * @param name partition name
  36. *
  37. * @return != NULL: partition
  38. * NULL: not found
  39. */
  40. const struct fal_partition *fal_partition_find(const char *name);
  41. /**
  42. * get the partition table
  43. *
  44. * @param len return the partition table length
  45. *
  46. * @return partition table
  47. */
  48. const struct fal_partition *fal_get_partition_table(size_t *len);
  49. /**
  50. * set partition table temporarily
  51. * This setting will modify the partition table temporarily, the setting will be lost after restart.
  52. *
  53. * @param table partition table
  54. * @param len partition table length
  55. */
  56. void fal_set_partition_table_temp(struct fal_partition *table, size_t len);
  57. /**
  58. * read data from partition
  59. *
  60. * @param part partition
  61. * @param addr relative address for partition
  62. * @param buf read buffer
  63. * @param size read size
  64. *
  65. * @return >= 0: successful read data size
  66. * -1: error
  67. */
  68. int fal_partition_read(const struct fal_partition *part, uint32_t addr, uint8_t *buf, size_t size);
  69. /**
  70. * write data to partition
  71. *
  72. * @param part partition
  73. * @param addr relative address for partition
  74. * @param buf write buffer
  75. * @param size write size
  76. *
  77. * @return >= 0: successful write data size
  78. * -1: error
  79. */
  80. int fal_partition_write(const struct fal_partition *part, uint32_t addr, const uint8_t *buf, size_t size);
  81. /**
  82. * erase partition data
  83. *
  84. * @param part partition
  85. * @param addr relative address for partition
  86. * @param size erase size
  87. *
  88. * @return >= 0: successful erased data size
  89. * -1: error
  90. */
  91. int fal_partition_erase(const struct fal_partition *part, uint32_t addr, size_t size);
  92. /**
  93. * erase partition all data
  94. *
  95. * @param part partition
  96. *
  97. * @return >= 0: successful erased data size
  98. * -1: error
  99. */
  100. int fal_partition_erase_all(const struct fal_partition *part);
  101. /**
  102. * print the partition table
  103. */
  104. void fal_show_part_table(void);
  105. /* =============== API provided to RT-Thread =============== */
  106. /**
  107. * create RT-Thread block device by specified partition
  108. *
  109. * @param parition_name partition name
  110. *
  111. * @return != NULL: created block device
  112. * NULL: created failed
  113. */
  114. struct rt_device *fal_blk_device_create(const char *parition_name);
  115. #if defined(RT_USING_MTD_NOR)
  116. /**
  117. * create RT-Thread MTD NOR device by specified partition
  118. *
  119. * @param parition_name partition name
  120. *
  121. * @return != NULL: created MTD NOR device
  122. * NULL: created failed
  123. */
  124. struct rt_device *fal_mtd_nor_device_create(const char *parition_name);
  125. #endif /* defined(RT_USING_MTD_NOR) */
  126. /**
  127. * create RT-Thread char device by specified partition
  128. *
  129. * @param parition_name partition name
  130. *
  131. * @return != NULL: created char device
  132. * NULL: created failed
  133. */
  134. struct rt_device *fal_char_device_create(const char *parition_name);
  135. #endif /* _FAL_H_ */