luat_sfd_idf5_onchip.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "luat_base.h"
  2. #include "luat_sfd.h"
  3. #include "esp_err.h"
  4. #include "esp_system.h"
  5. #include "esp_partition.h"
  6. #define LUAT_LOG_TAG "sfd"
  7. #include "luat_log.h"
  8. // 存放fdb分区的引用
  9. static const esp_partition_t * fdb_partition;
  10. // 初始化, 把分区读出来就行
  11. int sfd_onchip_init (void* userdata) {
  12. fdb_partition = esp_partition_find_first(0x5A, 0x5B, "fdb");
  13. if (fdb_partition == NULL) {
  14. LLOGE("fdb partition NOT Found");
  15. return -1;
  16. }
  17. return 0;
  18. }
  19. // 读取状态
  20. int sfd_onchip_status (void* userdata) {
  21. return fdb_partition == NULL ? -1 : 0;
  22. }
  23. // 下面就是flash的常规操作了, read/write/erase/ioctl
  24. int sfd_onchip_read (void* userdata, char* buff, size_t offset, size_t len) {
  25. int ret = esp_partition_read(fdb_partition, offset, buff, len);
  26. return ret >= 0 ? len : -1;
  27. }
  28. int sfd_onchip_write (void* userdata, const char* buff, size_t offset, size_t len) {
  29. int ret = esp_partition_write(fdb_partition, offset, buff, len);
  30. return ret >= 0 ? len : -1;
  31. }
  32. int sfd_onchip_erase (void* userdata, size_t offset, size_t len) {
  33. int ret = esp_partition_erase_range(fdb_partition, offset, len);
  34. return ret >= 0 ? len : -1;
  35. }
  36. int sfd_onchip_ioctl (void* userdata, size_t cmd, void* buff) {
  37. // 不支持, 也用不到
  38. return 0;
  39. }