lfs_rambd.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. // rambd config (optional)
  16. struct lfs_rambd_config {
  17. // 8-bit erase value to simulate erasing with. -1 indicates no erase
  18. // occurs, which is still a valid block device
  19. int32_t erase_value;
  20. // Optional statically allocated buffer for the block device.
  21. void *buffer;
  22. };
  23. // rambd state
  24. typedef struct lfs_rambd {
  25. uint8_t *buffer;
  26. const struct lfs_rambd_config *cfg;
  27. } lfs_rambd_t;
  28. // Create a RAM block device using the geometry in lfs_config
  29. int lfs_rambd_create(const struct lfs_config *cfg);
  30. int lfs_rambd_createcfg(const struct lfs_config *cfg,
  31. const struct lfs_rambd_config *bdcfg);
  32. // Clean up memory associated with block device
  33. int lfs_rambd_destroy(const struct lfs_config *cfg);
  34. // Read a block
  35. int lfs_rambd_read(const struct lfs_config *cfg, lfs_block_t block,
  36. lfs_off_t off, void *buffer, lfs_size_t size);
  37. // Program a block
  38. //
  39. // The block must have previously been erased.
  40. int lfs_rambd_prog(const struct lfs_config *cfg, lfs_block_t block,
  41. lfs_off_t off, const void *buffer, lfs_size_t size);
  42. // Erase a block
  43. //
  44. // A block must be erased before being programmed. The
  45. // state of an erased block is undefined.
  46. int lfs_rambd_erase(const struct lfs_config *cfg, lfs_block_t block);
  47. // Sync the block device
  48. int lfs_rambd_sync(const struct lfs_config *cfg);
  49. #ifdef __cplusplus
  50. } /* extern "C" */
  51. #endif
  52. #endif