lfs_emubd.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Block device emulated on standard files
  3. *
  4. * Copyright (c) 2017, Arm Limited. All rights reserved.
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef LFS_EMUBD_H
  8. #define LFS_EMUBD_H
  9. #include "lfs.h"
  10. #include "lfs_util.h"
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15. // Config options
  16. #ifndef LFS_EMUBD_READ_SIZE
  17. #define LFS_EMUBD_READ_SIZE 1
  18. #endif
  19. #ifndef LFS_EMUBD_PROG_SIZE
  20. #define LFS_EMUBD_PROG_SIZE 1
  21. #endif
  22. #ifndef LFS_EMUBD_ERASE_SIZE
  23. #define LFS_EMUBD_ERASE_SIZE 512
  24. #endif
  25. #ifndef LFS_EMUBD_TOTAL_SIZE
  26. #define LFS_EMUBD_TOTAL_SIZE 524288
  27. #endif
  28. // The emu bd state
  29. typedef struct lfs_emubd {
  30. char *path;
  31. char *child;
  32. struct {
  33. uint64_t read_count;
  34. uint64_t prog_count;
  35. uint64_t erase_count;
  36. } stats;
  37. struct {
  38. lfs_block_t blocks[4];
  39. } history;
  40. struct {
  41. uint32_t read_size;
  42. uint32_t prog_size;
  43. uint32_t block_size;
  44. uint32_t block_count;
  45. } cfg;
  46. } lfs_emubd_t;
  47. // Create a block device using path for the directory to store blocks
  48. int lfs_emubd_create(const struct lfs_config *cfg, const char *path);
  49. // Clean up memory associated with emu block device
  50. void lfs_emubd_destroy(const struct lfs_config *cfg);
  51. // Read a block
  52. int lfs_emubd_read(const struct lfs_config *cfg, lfs_block_t block,
  53. lfs_off_t off, void *buffer, lfs_size_t size);
  54. // Program a block
  55. //
  56. // The block must have previously been erased.
  57. int lfs_emubd_prog(const struct lfs_config *cfg, lfs_block_t block,
  58. lfs_off_t off, const void *buffer, lfs_size_t size);
  59. // Erase a block
  60. //
  61. // A block must be erased before being programmed. The
  62. // state of an erased block is undefined.
  63. int lfs_emubd_erase(const struct lfs_config *cfg, lfs_block_t block);
  64. // Sync the block device
  65. int lfs_emubd_sync(const struct lfs_config *cfg);
  66. #ifdef __cplusplus
  67. } /* extern "C" */
  68. #endif
  69. #endif