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 10 #include "lfs.h" 11 #include "lfs_util.h" 12 13 #ifdef __cplusplus 14 extern "C" 15 { 16 #endif 17 18 19 // Block device specific tracing 20 #ifdef LFS_RAMBD_YES_TRACE 21 #define LFS_RAMBD_TRACE(...) LFS_TRACE(__VA_ARGS__) 22 #else 23 #define LFS_RAMBD_TRACE(...) 24 #endif 25 26 // rambd config (optional) 27 struct lfs_rambd_config { 28 // 8-bit erase value to simulate erasing with. -1 indicates no erase 29 // occurs, which is still a valid block device 30 int32_t erase_value; 31 32 // Optional statically allocated buffer for the block device. 33 void *buffer; 34 }; 35 36 // rambd state 37 typedef struct lfs_rambd { 38 uint8_t *buffer; 39 const struct lfs_rambd_config *cfg; 40 } lfs_rambd_t; 41 42 43 // Create a RAM block device using the geometry in lfs_config 44 int lfs_rambd_create(const struct lfs_config *cfg); 45 int lfs_rambd_createcfg(const struct lfs_config *cfg, 46 const struct lfs_rambd_config *bdcfg); 47 48 // Clean up memory associated with block device 49 int lfs_rambd_destroy(const struct lfs_config *cfg); 50 51 // Read a block 52 int lfs_rambd_read(const struct lfs_config *cfg, lfs_block_t block, 53 lfs_off_t off, void *buffer, lfs_size_t size); 54 55 // Program a block 56 // 57 // The block must have previously been erased. 58 int lfs_rambd_prog(const struct lfs_config *cfg, lfs_block_t block, 59 lfs_off_t off, const void *buffer, lfs_size_t size); 60 61 // Erase a block 62 // 63 // A block must be erased before being programmed. The 64 // state of an erased block is undefined. 65 int lfs_rambd_erase(const struct lfs_config *cfg, lfs_block_t block); 66 67 // Sync the block device 68 int lfs_rambd_sync(const struct lfs_config *cfg); 69 70 71 #ifdef __cplusplus 72 } /* extern "C" */ 73 #endif 74 75 #endif 76