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

FlashSimBlockDevice

FlashSimBlockDevice class hierarchy

The FlashSimBlockDevice class is a block device adpator, whose purpose is to simulate the behavior of a flash component if the underlying block device doesn't support such a behavior. This includes the following:

  • Support the erase API (fills the erase unit with the predefined erase value).
  • Only allow programming of erased area or ones whose content is the same as the one given by the user.
  • Support the get\_erase\_value API, returning the predefined erase value.

The constructor requires the following:

  • bd - Block device to back the FlashSimBlockDevice.
  • erase_value - Value given to each byte of the erase unit following an erase operation (defaults to 0xFF).

FlashSimBlockDevice class reference

Public Member Functions
 FlashSimBlockDevice (BlockDevice *bd, uint8_t erase_value=0xFF)
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 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 ()
virtual int trim (bd_addr_t addr, bd_size_t size)
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

FlashSimBlockDevice example

This FlashSimBlockDevice example takes a HeapBlockDevice and turns it into a simulated flash BD.

    int erase_unit_size = 512;
    HeapBlockDevice heap_bd(4 * erase_unit_size, 1, 4, erase_unit_size);
    FlashSimBlockDevice flash_bd(&heap_bd, blank);

    // This initializes the flash simulator block device (as well as the underlying heap block device)
    int err = flash_bd.init();

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

    // This will fail, as erase unit in address 0 has not been erased
    err = flash_bd.program(buf, 0, sizeof(buf));

    // Erase the erase unit at address 0
    err = flash_bd.erase(0, erase_unit_size);

    // This will succeed now after erasing
    err = flash_bd.program(buf, 0, sizeof(buf));
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.