Skip to content

Fix functionality for FlashIAPBD & SlicingBD #10108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,14 @@ const char *FlashIAPBlockDevice::get_type() const
return "FLASHIAP";
}

bool FlashIAPBlockDevice::is_valid_erase(bd_addr_t addr, bd_size_t size) const
{
/* Calculate address alignment for the full flash */
bd_addr_t base_addr = addr + (_base - _flash.get_flash_start());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment saying what is base_addr and that it is related to the full flash, not only the addresses inside the blockdevice


return (
addr + size <= this->size() &&
base_addr % get_erase_size(addr) == 0 &&
(base_addr + size) % get_erase_size(addr + size - 1) == 0);
}
#endif /* DEVICE_FLASH */
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,15 @@ class FlashIAPBlockDevice : public mbed::BlockDevice {
*/
virtual const char *get_type() const;

/** Convenience function for checking block erase validity
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes
* @return True if erase is valid for underlying block device
*/
virtual bool is_valid_erase(bd_addr_t addr, bd_size_t size) const;


private:
// Device configuration
mbed::FlashIAP _flash;
Expand Down
6 changes: 3 additions & 3 deletions features/storage/blockdevice/BlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class BlockDevice {
* @param size Size to read in bytes
* @return True if read is valid for underlying block device
*/
bool is_valid_read(bd_addr_t addr, bd_size_t size) const
virtual bool is_valid_read(bd_addr_t addr, bd_size_t size) const
{
return (
addr % get_read_size() == 0 &&
Expand All @@ -212,7 +212,7 @@ class BlockDevice {
* @param size Size to write in bytes
* @return True if program is valid for underlying block device
*/
bool is_valid_program(bd_addr_t addr, bd_size_t size) const
virtual bool is_valid_program(bd_addr_t addr, bd_size_t size) const
{
return (
addr % get_program_size() == 0 &&
Expand All @@ -226,7 +226,7 @@ class BlockDevice {
* @param size Size to erase in bytes
* @return True if erase is valid for underlying block device
*/
bool is_valid_erase(bd_addr_t addr, bd_size_t size) const
virtual bool is_valid_erase(bd_addr_t addr, bd_size_t size) const
{
return (
addr % get_erase_size(addr) == 0 &&
Expand Down
32 changes: 28 additions & 4 deletions features/storage/blockdevice/SlicingBlockDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int SlicingBlockDevice::init()
}

// Check that block addresses are valid
MBED_ASSERT(_bd->is_valid_erase(_start, _stop - _start));
MBED_ASSERT(is_valid_erase(_start, _stop - _start));

return 0;
}
Expand All @@ -75,22 +75,46 @@ int SlicingBlockDevice::sync()

int SlicingBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(is_valid_read(addr, size));
MBED_ASSERT(is_valid_read(addr + _start, size));
return _bd->read(b, addr + _start, size);
}

int SlicingBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(is_valid_program(addr, size));
MBED_ASSERT(is_valid_program(addr + _start, size));
return _bd->program(b, addr + _start, size);
}

int SlicingBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(is_valid_erase(addr, size));
MBED_ASSERT(is_valid_erase(addr + _start, size));
return _bd->erase(addr + _start, size);
}

bool SlicingBlockDevice::is_valid_read(bd_addr_t addr, bd_size_t size) const
{
return (
addr % get_read_size() == 0 &&
size % get_read_size() == 0 &&
addr + size <= (this->size() + _start));
}

bool SlicingBlockDevice::is_valid_program(bd_addr_t addr, bd_size_t size) const
{
return (
addr % get_program_size() == 0 &&
size % get_program_size() == 0 &&
addr + size <= (this->size() + _start));
}

bool SlicingBlockDevice::is_valid_erase(bd_addr_t addr, bd_size_t size) const
{
return (
addr % get_erase_size(addr) == 0 &&
(addr + size) % get_erase_size(addr + size - 1) == 0 &&
addr + size <= (this->size() + _start));
}

bd_size_t SlicingBlockDevice::get_read_size() const
{
return _bd->get_read_size();
Expand Down
25 changes: 25 additions & 0 deletions features/storage/blockdevice/SlicingBlockDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,31 @@ class SlicingBlockDevice : public BlockDevice {
*/
virtual const char *get_type() const;

/** Convenience function for checking block program validity
*
* @param addr Address of block to begin writing to
* @param size Size to write in bytes
* @return True if program is valid for underlying block device
*/
virtual bool is_valid_program(bd_addr_t addr, bd_size_t size) const;

/** Convenience function for checking block read validity
*
* @param addr Address of block to begin reading from
* @param size Size to read in bytes
* @return True if read is valid for underlying block device
*/
virtual bool is_valid_read(bd_addr_t addr, bd_size_t size) const;

/** Convenience function for checking block erase validity
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes
* @return True if erase is valid for underlying block device
*/
virtual bool is_valid_erase(bd_addr_t addr, bd_size_t size) const;


protected:
BlockDevice *_bd;
bool _start_from_end;
Expand Down