Merge pull request #5925 from geky/bd-erase-value

bd: Add get_erase_value function to the block device API
pull/5988/head
Cruz Monrreal 2018-01-31 12:13:54 -06:00 committed by GitHub
commit 5cd30b965c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 152 additions and 8 deletions

View File

@ -94,7 +94,8 @@ public:
/** Erase blocks on a block device
*
* The state of an erased block is undefined until it has been programmed
* The state of an erased block is undefined until it has been programmed,
* unless get_erase_value returns a non-negative byte value
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes, must be a multiple of erase block size
@ -144,6 +145,20 @@ public:
return get_program_size();
}
/** Get the value of storage when erased
*
* If get_erase_value returns a non-negative byte value, the underlying
* storage is set to that value when erased, and storage containing
* that value can be programmed without another erase.
*
* @return The value of storage when erased, or -1 if you can't
* rely on the value of erased storage
*/
virtual int get_erase_value() const
{
return -1;
}
/** Get the total size of the underlying device
*
* @return Size of the underlying device in bytes

View File

@ -20,6 +20,7 @@
ChainingBlockDevice::ChainingBlockDevice(BlockDevice **bds, size_t bd_count)
: _bds(bds), _bd_count(bd_count)
, _read_size(0), _program_size(0), _erase_size(0), _size(0)
, _erase_value(-1)
{
}
@ -33,6 +34,7 @@ int ChainingBlockDevice::init()
_read_size = 0;
_program_size = 0;
_erase_size = 0;
_erase_value = -1;
_size = 0;
// Initialize children block devices, find all sizes and
@ -66,6 +68,13 @@ int ChainingBlockDevice::init()
MBED_ASSERT(_erase_size > erase && is_aligned(_erase_size, erase));
}
int value = _bds[i]->get_erase_value();
if (i == 0 || value == _erase_value) {
_erase_value = value;
} else {
_erase_value = -1;
}
_size += _bds[i]->size();
}
@ -202,6 +211,11 @@ bd_size_t ChainingBlockDevice::get_erase_size() const
return _erase_size;
}
int ChainingBlockDevice::get_erase_value() const
{
return _erase_value;
}
bd_size_t ChainingBlockDevice::size() const
{
return _size;

View File

@ -113,7 +113,8 @@ public:
/** Erase blocks on a block device
*
* The state of an erased block is undefined until it has been programmed
* The state of an erased block is undefined until it has been programmed,
* unless get_erase_value returns a non-negative byte value
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes, must be a multiple of erase block size
@ -141,6 +142,17 @@ public:
*/
virtual bd_size_t get_erase_size() const;
/** Get the value of storage when erased
*
* If get_erase_value returns a non-negative byte value, the underlying
* storage is set to that value when erased, and storage containing
* that value can be programmed without another erase.
*
* @return The value of storage when erased, or -1 if you can't
* rely on the value of erased storage
*/
virtual int get_erase_value() const;
/** Get the total size of the underlying device
*
* @return Size of the underlying device in bytes
@ -154,6 +166,7 @@ protected:
bd_size_t _program_size;
bd_size_t _erase_size;
bd_size_t _size;
int _erase_value;
};

View File

@ -107,6 +107,11 @@ bd_size_t ExhaustibleBlockDevice::get_erase_size() const
return _bd->get_erase_size();
}
int ExhaustibleBlockDevice::get_erase_value() const
{
return _bd->get_erase_value();
}
bd_size_t ExhaustibleBlockDevice::size() const
{
return _bd->size();

View File

@ -98,7 +98,8 @@ public:
/** Erase blocks on a block device
*
* The state of an erased block is undefined until it has been programmed
* The state of an erased block is undefined until it has been programmed,
* unless get_erase_value returns a non-negative byte value
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes, must be a multiple of erase block size
@ -124,6 +125,17 @@ public:
*/
virtual bd_size_t get_erase_size() const;
/** Get the value of storage when erased
*
* If get_erase_value returns a non-negative byte value, the underlying
* storage is set to that value when erased, and storage containing
* that value can be programmed without another erase.
*
* @return The value of storage when erased, or -1 if you can't
* rely on the value of erased storage
*/
virtual int get_erase_value() const;
/** Get the total size of the underlying device
*
* @return Size of the underlying device in bytes

View File

@ -272,6 +272,11 @@ bd_size_t MBRBlockDevice::get_erase_size() const
return _bd->get_erase_size();
}
int MBRBlockDevice::get_erase_value() const
{
return _bd->get_erase_value();
}
bd_size_t MBRBlockDevice::size() const
{
return _size;

View File

@ -167,7 +167,8 @@ public:
/** Erase blocks on a block device
*
* The state of an erased block is undefined until it has been programmed
* The state of an erased block is undefined until it has been programmed,
* unless get_erase_value returns a non-negative byte value
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes, must be a multiple of erase block size
@ -195,6 +196,17 @@ public:
*/
virtual bd_size_t get_erase_size() const;
/** Get the value of storage when erased
*
* If get_erase_value returns a non-negative byte value, the underlying
* storage is set to that value when erased, and storage containing
* that value can be programmed without another erase.
*
* @return The value of storage when erased, or -1 if you can't
* rely on the value of erased storage
*/
virtual int get_erase_value() const;
/** Get the total size of the underlying device
*
* @return Size of the underlying device in bytes

View File

@ -96,6 +96,11 @@ bd_size_t ObservingBlockDevice::get_erase_size() const
return _bd->get_erase_size();
}
int ObservingBlockDevice::get_erase_value() const
{
return _bd->get_erase_value();
}
bd_size_t ObservingBlockDevice::size() const
{
return _bd->size();

View File

@ -84,7 +84,8 @@ public:
/** Erase blocks on a block device
*
* The state of an erased block is undefined until it has been programmed
* The state of an erased block is undefined until it has been programmed,
* unless get_erase_value returns a non-negative byte value
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes, must be a multiple of erase block size
@ -110,6 +111,17 @@ public:
*/
virtual bd_size_t get_erase_size() const;
/** Get the value of storage when erased
*
* If get_erase_value returns a non-negative byte value, the underlying
* storage is set to that value when erased, and storage containing
* that value can be programmed without another erase.
*
* @return The value of storage when erased, or -1 if you can't
* rely on the value of erased storage
*/
virtual int get_erase_value() const;
/** Get the total size of the underlying device
*
* @return Size of the underlying device in bytes

View File

@ -82,6 +82,11 @@ bd_size_t ProfilingBlockDevice::get_erase_size() const
return _bd->get_erase_size();
}
int ProfilingBlockDevice::get_erase_value() const
{
return _bd->get_erase_value();
}
bd_size_t ProfilingBlockDevice::size() const
{
return _bd->size();

View File

@ -99,7 +99,8 @@ public:
/** Erase blocks on a block device
*
* The state of an erased block is undefined until it has been programmed
* The state of an erased block is undefined until it has been programmed,
* unless get_erase_value returns a non-negative byte value
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes, must be a multiple of erase block size
@ -127,6 +128,17 @@ public:
*/
virtual bd_size_t get_erase_size() const;
/** Get the value of storage when erased
*
* If get_erase_value returns a non-negative byte value, the underlying
* storage is set to that value when erased, and you can program storage
* containing that value without another erase.
*
* @return The value of storage when erased, or -1 if you can't
* rely on the value of erased storage
*/
virtual int get_erase_value() const;
/** Get the total size of the underlying device
*
* @return Size of the underlying device in bytes

View File

@ -82,6 +82,11 @@ bd_size_t ReadOnlyBlockDevice::get_erase_size() const
return _bd->get_erase_size();
}
int ReadOnlyBlockDevice::get_erase_value() const
{
return _bd->get_erase_value();
}
bd_size_t ReadOnlyBlockDevice::size() const
{
return _bd->size();

View File

@ -77,7 +77,8 @@ public:
/** Erase blocks on a block device
*
* The state of an erased block is undefined until it has been programmed
* The state of an erased block is undefined until it has been programmed,
* unless get_erase_value returns a non-negative byte value
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes, must be a multiple of erase block size
@ -103,6 +104,17 @@ public:
*/
virtual bd_size_t get_erase_size() const;
/** Get the value of storage when erased
*
* If get_erase_value returns a non-negative byte value, the underlying
* storage is set to that value when erased, and storage containing
* that value can be programmed without another erase.
*
* @return The value of storage when erased, or -1 if you can't
* rely on the value of erased storage
*/
virtual int get_erase_value() const;
/** Get the total size of the underlying device
*
* @return Size of the underlying device in bytes

View File

@ -102,6 +102,11 @@ bd_size_t SlicingBlockDevice::get_erase_size() const
return _bd->get_erase_size();
}
int SlicingBlockDevice::get_erase_value() const
{
return _bd->get_erase_value();
}
bd_size_t SlicingBlockDevice::size() const
{
return _stop - _start;

View File

@ -105,7 +105,8 @@ public:
/** Erase blocks on a block device
*
* The state of an erased block is undefined until it has been programmed
* The state of an erased block is undefined until it has been programmed,
* unless get_erase_value returns a non-negative byte value
*
* @param addr Address of block to begin erasing
* @param size Size to erase in bytes, must be a multiple of erase block size
@ -133,6 +134,17 @@ public:
*/
virtual bd_size_t get_erase_size() const;
/** Get the value of storage when erased
*
* If get_erase_value returns a non-negative byte value, the underlying
* storage is set to that value when erased, and storage containing
* that value can be programmed without another erase.
*
* @return The value of storage when erased, or -1 if you can't
* rely on the value of erased storage
*/
virtual int get_erase_value() const;
/** Get the total size of the underlying device
*
* @return Size of the underlying device in bytes