Mistake on this page?
Report an issue in GitHub or email us


BufferedBlockDevice class hierarchy

The BufferedBlockDevice class is a block device adpator, whose purpose is to reduce the read and program sizes of the underlying block device to 1. Large read and/or program sizes may make life difficult for block device users, so BufferedBlockDevice reduces both sizes to the minimum, where reads and writes to the underlying BD use an internal buffer. Calling the sync API ensures writes are flushed to the underlying BD.

The constructor only requires the underlying block device pointer.

  • bd - Block device to back the BufferedBlockDevice.

BufferedBlockDevice class reference

Public Member Functions
 BufferedBlockDevice (BlockDevice *bd)
virtual ~BufferedBlockDevice ()
virtual int init ()
virtual int deinit ()
virtual int sync ()
virtual int read (void *buffer, bd_addr_t addr, bd_size_t size)
virtual int program (const void *buffer, bd_addr_t addr, bd_size_t size)
virtual int erase (bd_addr_t addr, bd_size_t size)
virtual int trim (bd_addr_t addr, bd_size_t size)
virtual bd_size_t get_read_size () const
virtual bd_size_t get_program_size () const
virtual bd_size_t get_erase_size () const
virtual bd_size_t get_erase_size (bd_addr_t addr) const
virtual int get_erase_value () const
virtual bd_size_t size () const
 Public Member Functions inherited from BlockDevice
virtual ~BlockDevice ()
bool is_valid_read (bd_addr_t addr, bd_size_t size) const
bool is_valid_program (bd_addr_t addr, bd_size_t size) const
bool is_valid_erase (bd_addr_t addr, bd_size_t size) const
Protected Member Functions
int flush ()
Protected Attributes
bd_size_t _bd_program_size
bd_size_t _curr_aligned_addr
bool _flushed
uint8_t * _cache
uint32_t _init_ref_count

BufferedBlockDevice example

This BufferedBlockDevice example takes a HeapBlockDevice, whose read size is 256 bytes and program size is 512 bytes, and shows how one can read or program this block device with much smaller read/program sizes, using BufferedBlockDevice.

    HeapBlockDevice heap_bd(1024, 256, 512, 512);
    BufferedBlockDevice buf_bd(&heap_bd);

    // This initializes the buffered block device (as well as the underlying heap block device)
    int err = buf_bd.init();

    uint8_t buf[8];
    for (int i = 0; i < sizeof(buf); i++) {
         buf[i] = i;

    // Now we can program an 8 byte buffer (couldn't do that in underlying BD, having 512-byte program size)
    err = buf_bd.program(buf, 0, sizeof(buf));

    // Now we can also read one byte
    err = buf_bd.read(buf, 0, 1);

    // Ensure programmed data is flushed to the underlying block device
    err = buf_bd.sync();
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.