lfs_rambd.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Block device emulated in RAM
  3. *
  4. * Copyright (c) 2017, Arm Limited. All rights reserved.
  5. * SPDX-License-Identifier: BSD-3-Clause
  6. */
  7. #ifndef LFS_RAMBD_H
  8. #define LFS_RAMBD_H
  9. #include "lfs.h"
  10. #include "lfs_util.h"
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15. // Block device specific tracing
  16. #ifdef LFS_RAMBD_YES_TRACE
  17. #define LFS_RAMBD_TRACE(...) LFS_TRACE(__VA_ARGS__)
  18. #else
  19. #define LFS_RAMBD_TRACE(...)
  20. #endif
  21. // rambd config (optional)
  22. struct lfs_rambd_config {
  23. // 8-bit erase value to simulate erasing with. -1 indicates no erase
  24. // occurs, which is still a valid block device
  25. int32_t erase_value;
  26. // Optional statically allocated buffer for the block device.
  27. void *buffer;
  28. };
  29. // rambd state
  30. typedef struct lfs_rambd {
  31. uint8_t *buffer;
  32. const struct lfs_rambd_config *cfg;
  33. } lfs_rambd_t;
  34. // Create a RAM block device using the geometry in lfs_config
  35. int lfs_rambd_create(const struct lfs_config *cfg);
  36. int lfs_rambd_createcfg(const struct lfs_config *cfg,
  37. const struct lfs_rambd_config *bdcfg);
  38. // Clean up memory associated with block device
  39. int lfs_rambd_destroy(const struct lfs_config *cfg);
  40. // Read a block
  41. int lfs_rambd_read(const struct lfs_config *cfg, lfs_block_t block,
  42. lfs_off_t off, void *buffer, lfs_size_t size);
  43. // Program a block
  44. //
  45. // The block must have previously been erased.
  46. int lfs_rambd_prog(const struct lfs_config *cfg, lfs_block_t block,
  47. lfs_off_t off, const void *buffer, lfs_size_t size);
  48. // Erase a block
  49. //
  50. // A block must be erased before being programmed. The
  51. // state of an erased block is undefined.
  52. int lfs_rambd_erase(const struct lfs_config *cfg, lfs_block_t block);
  53. // Sync the block device
  54. int lfs_rambd_sync(const struct lfs_config *cfg);
  55. #ifdef __cplusplus
  56. } /* extern "C" */
  57. #endif
  58. #endif