From 7707c8b8b879ce5b08f8ba11056dd39f7d4fee59 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 24 Jan 2018 17:19:25 -0600 Subject: [PATCH 1/3] bd: Added get_erase_value function to the block device API Default implementation returns -1 and is backwards compatible --- features/filesystem/bd/BlockDevice.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/features/filesystem/bd/BlockDevice.h b/features/filesystem/bd/BlockDevice.h index da46c7b7278..b6e195cb704 100644 --- a/features/filesystem/bd/BlockDevice.h +++ b/features/filesystem/bd/BlockDevice.h @@ -85,7 +85,8 @@ class BlockDevice /** 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 @@ -135,6 +136,20 @@ class BlockDevice return get_program_size(); } + /** Get the value of storage when erased + * + * If get_erase_value returns a non-negative byte value, the underlying + * storage will be 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 the value of + * erased storage can't be relied on + */ + virtual int get_erase_value() const + { + return -1; + } + /** Get the total size of the underlying device * * @return Size of the underlying device in bytes From 88aad813452e035d08854afc643aa18b4be110a9 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 24 Jan 2018 17:40:38 -0600 Subject: [PATCH 2/3] bd: Adopted the get_erase_value function in the util block devices --- features/filesystem/bd/ChainingBlockDevice.cpp | 14 ++++++++++++++ features/filesystem/bd/ChainingBlockDevice.h | 15 ++++++++++++++- features/filesystem/bd/ExhaustibleBlockDevice.cpp | 5 +++++ features/filesystem/bd/ExhaustibleBlockDevice.h | 14 +++++++++++++- features/filesystem/bd/MBRBlockDevice.cpp | 5 +++++ features/filesystem/bd/MBRBlockDevice.h | 14 +++++++++++++- features/filesystem/bd/ObservingBlockDevice.cpp | 5 +++++ features/filesystem/bd/ObservingBlockDevice.h | 14 +++++++++++++- features/filesystem/bd/ProfilingBlockDevice.cpp | 5 +++++ features/filesystem/bd/ProfilingBlockDevice.h | 14 +++++++++++++- features/filesystem/bd/ReadOnlyBlockDevice.cpp | 5 +++++ features/filesystem/bd/ReadOnlyBlockDevice.h | 14 +++++++++++++- features/filesystem/bd/SlicingBlockDevice.cpp | 5 +++++ features/filesystem/bd/SlicingBlockDevice.h | 14 +++++++++++++- 14 files changed, 136 insertions(+), 7 deletions(-) diff --git a/features/filesystem/bd/ChainingBlockDevice.cpp b/features/filesystem/bd/ChainingBlockDevice.cpp index f9f5c9a29f9..4383670ebd3 100644 --- a/features/filesystem/bd/ChainingBlockDevice.cpp +++ b/features/filesystem/bd/ChainingBlockDevice.cpp @@ -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(); } @@ -190,6 +199,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; diff --git a/features/filesystem/bd/ChainingBlockDevice.h b/features/filesystem/bd/ChainingBlockDevice.h index 63b4a5d0209..db4594536f7 100644 --- a/features/filesystem/bd/ChainingBlockDevice.h +++ b/features/filesystem/bd/ChainingBlockDevice.h @@ -107,7 +107,8 @@ class ChainingBlockDevice : public BlockDevice /** 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 @@ -135,6 +136,17 @@ class ChainingBlockDevice : public BlockDevice */ 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 will be 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 the value of + * erased storage can't be relied on + */ + virtual int get_erase_value() const; + /** Get the total size of the underlying device * * @return Size of the underlying device in bytes @@ -148,6 +160,7 @@ class ChainingBlockDevice : public BlockDevice bd_size_t _program_size; bd_size_t _erase_size; bd_size_t _size; + int _erase_value; }; diff --git a/features/filesystem/bd/ExhaustibleBlockDevice.cpp b/features/filesystem/bd/ExhaustibleBlockDevice.cpp index 0b16a9217f6..61eac06378e 100644 --- a/features/filesystem/bd/ExhaustibleBlockDevice.cpp +++ b/features/filesystem/bd/ExhaustibleBlockDevice.cpp @@ -102,6 +102,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(); diff --git a/features/filesystem/bd/ExhaustibleBlockDevice.h b/features/filesystem/bd/ExhaustibleBlockDevice.h index 8fc39183177..7fedc22a613 100644 --- a/features/filesystem/bd/ExhaustibleBlockDevice.h +++ b/features/filesystem/bd/ExhaustibleBlockDevice.h @@ -92,7 +92,8 @@ class ExhaustibleBlockDevice : public BlockDevice /** 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 @@ -118,6 +119,17 @@ class ExhaustibleBlockDevice : public BlockDevice */ 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 will be 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 the value of + * erased storage can't be relied on + */ + virtual int get_erase_value() const; + /** Get the total size of the underlying device * * @return Size of the underlying device in bytes diff --git a/features/filesystem/bd/MBRBlockDevice.cpp b/features/filesystem/bd/MBRBlockDevice.cpp index 134ce9848ba..8967f2f542b 100644 --- a/features/filesystem/bd/MBRBlockDevice.cpp +++ b/features/filesystem/bd/MBRBlockDevice.cpp @@ -267,6 +267,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; diff --git a/features/filesystem/bd/MBRBlockDevice.h b/features/filesystem/bd/MBRBlockDevice.h index 48964fba1ce..322a32a15a9 100644 --- a/features/filesystem/bd/MBRBlockDevice.h +++ b/features/filesystem/bd/MBRBlockDevice.h @@ -161,7 +161,8 @@ class MBRBlockDevice : public BlockDevice /** 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 @@ -189,6 +190,17 @@ class MBRBlockDevice : public BlockDevice */ 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 will be 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 the value of + * erased storage can't be relied on + */ + virtual int get_erase_value() const; + /** Get the total size of the underlying device * * @return Size of the underlying device in bytes diff --git a/features/filesystem/bd/ObservingBlockDevice.cpp b/features/filesystem/bd/ObservingBlockDevice.cpp index ea6dc5da157..e53ce70573e 100644 --- a/features/filesystem/bd/ObservingBlockDevice.cpp +++ b/features/filesystem/bd/ObservingBlockDevice.cpp @@ -91,6 +91,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(); diff --git a/features/filesystem/bd/ObservingBlockDevice.h b/features/filesystem/bd/ObservingBlockDevice.h index 1e8c1942cb7..7e5a21dd92b 100644 --- a/features/filesystem/bd/ObservingBlockDevice.h +++ b/features/filesystem/bd/ObservingBlockDevice.h @@ -78,7 +78,8 @@ class ObservingBlockDevice : public BlockDevice /** 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 @@ -104,6 +105,17 @@ class ObservingBlockDevice : public BlockDevice */ 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 will be 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 the value of + * erased storage can't be relied on + */ + virtual int get_erase_value() const; + /** Get the total size of the underlying device * * @return Size of the underlying device in bytes diff --git a/features/filesystem/bd/ProfilingBlockDevice.cpp b/features/filesystem/bd/ProfilingBlockDevice.cpp index 6baa24cb90e..775a4b5fc08 100644 --- a/features/filesystem/bd/ProfilingBlockDevice.cpp +++ b/features/filesystem/bd/ProfilingBlockDevice.cpp @@ -77,6 +77,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(); diff --git a/features/filesystem/bd/ProfilingBlockDevice.h b/features/filesystem/bd/ProfilingBlockDevice.h index c019fa7300d..b8c3295c51b 100644 --- a/features/filesystem/bd/ProfilingBlockDevice.h +++ b/features/filesystem/bd/ProfilingBlockDevice.h @@ -93,7 +93,8 @@ class ProfilingBlockDevice : public BlockDevice /** 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 @@ -121,6 +122,17 @@ class ProfilingBlockDevice : public BlockDevice */ 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 will be 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 the value of + * erased storage can't be relied on + */ + virtual int get_erase_value() const; + /** Get the total size of the underlying device * * @return Size of the underlying device in bytes diff --git a/features/filesystem/bd/ReadOnlyBlockDevice.cpp b/features/filesystem/bd/ReadOnlyBlockDevice.cpp index 84ab36ff2dc..9e9f01bdedf 100644 --- a/features/filesystem/bd/ReadOnlyBlockDevice.cpp +++ b/features/filesystem/bd/ReadOnlyBlockDevice.cpp @@ -77,6 +77,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(); diff --git a/features/filesystem/bd/ReadOnlyBlockDevice.h b/features/filesystem/bd/ReadOnlyBlockDevice.h index 23c8f40e8d6..31462fad915 100644 --- a/features/filesystem/bd/ReadOnlyBlockDevice.h +++ b/features/filesystem/bd/ReadOnlyBlockDevice.h @@ -71,7 +71,8 @@ class ReadOnlyBlockDevice : public BlockDevice /** 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 @@ -97,6 +98,17 @@ class ReadOnlyBlockDevice : public BlockDevice */ 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 will be 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 the value of + * erased storage can't be relied on + */ + virtual int get_erase_value() const; + /** Get the total size of the underlying device * * @return Size of the underlying device in bytes diff --git a/features/filesystem/bd/SlicingBlockDevice.cpp b/features/filesystem/bd/SlicingBlockDevice.cpp index 249acf81b69..d784a840b26 100644 --- a/features/filesystem/bd/SlicingBlockDevice.cpp +++ b/features/filesystem/bd/SlicingBlockDevice.cpp @@ -97,6 +97,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; diff --git a/features/filesystem/bd/SlicingBlockDevice.h b/features/filesystem/bd/SlicingBlockDevice.h index e219f77480b..635eab81e9a 100644 --- a/features/filesystem/bd/SlicingBlockDevice.h +++ b/features/filesystem/bd/SlicingBlockDevice.h @@ -99,7 +99,8 @@ class SlicingBlockDevice : public BlockDevice /** 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 @@ class SlicingBlockDevice : public BlockDevice */ 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 will be 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 the value of + * erased storage can't be relied on + */ + virtual int get_erase_value() const; + /** Get the total size of the underlying device * * @return Size of the underlying device in bytes From e6949db802a328b6a8b37a9bb2d8b6d54b759cd8 Mon Sep 17 00:00:00 2001 From: Amanda Butler Date: Mon, 29 Jan 2018 16:32:58 -0600 Subject: [PATCH 3/3] bd: Copy edit BlockDevices Copy edit SlicingBlockDevice.h Copy edit ReadOnlyBlockDevice.h Copy edit ProfilingBlockDevice.h Copy edit ObservingBlockDevice.h Copy edit MBRBlockDevice.h Copy edit ExhaustibleBlockDevice.h Copy edit ChainingBlockDevice.h Copy edit BlockDevice.h Copy edit files for active voice and consistent tense. --- features/filesystem/bd/BlockDevice.h | 6 +++--- features/filesystem/bd/ChainingBlockDevice.h | 6 +++--- features/filesystem/bd/ExhaustibleBlockDevice.h | 6 +++--- features/filesystem/bd/MBRBlockDevice.h | 6 +++--- features/filesystem/bd/ObservingBlockDevice.h | 6 +++--- features/filesystem/bd/ProfilingBlockDevice.h | 8 ++++---- features/filesystem/bd/ReadOnlyBlockDevice.h | 6 +++--- features/filesystem/bd/SlicingBlockDevice.h | 6 +++--- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/features/filesystem/bd/BlockDevice.h b/features/filesystem/bd/BlockDevice.h index b6e195cb704..de86051ff9a 100644 --- a/features/filesystem/bd/BlockDevice.h +++ b/features/filesystem/bd/BlockDevice.h @@ -139,11 +139,11 @@ class BlockDevice /** Get the value of storage when erased * * If get_erase_value returns a non-negative byte value, the underlying - * storage will be set to that value when erased, and storage containing + * 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 the value of - * erased storage can't be relied on + * @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 { diff --git a/features/filesystem/bd/ChainingBlockDevice.h b/features/filesystem/bd/ChainingBlockDevice.h index db4594536f7..9b1cbb944e5 100644 --- a/features/filesystem/bd/ChainingBlockDevice.h +++ b/features/filesystem/bd/ChainingBlockDevice.h @@ -139,11 +139,11 @@ class ChainingBlockDevice : public BlockDevice /** Get the value of storage when erased * * If get_erase_value returns a non-negative byte value, the underlying - * storage will be set to that value when erased, and storage containing + * 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 the value of - * erased storage can't be relied on + * @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; diff --git a/features/filesystem/bd/ExhaustibleBlockDevice.h b/features/filesystem/bd/ExhaustibleBlockDevice.h index 7fedc22a613..5e5b47574e6 100644 --- a/features/filesystem/bd/ExhaustibleBlockDevice.h +++ b/features/filesystem/bd/ExhaustibleBlockDevice.h @@ -122,11 +122,11 @@ class ExhaustibleBlockDevice : public BlockDevice /** Get the value of storage when erased * * If get_erase_value returns a non-negative byte value, the underlying - * storage will be set to that value when erased, and storage containing + * 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 the value of - * erased storage can't be relied on + * @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; diff --git a/features/filesystem/bd/MBRBlockDevice.h b/features/filesystem/bd/MBRBlockDevice.h index 322a32a15a9..d214c0a2b5e 100644 --- a/features/filesystem/bd/MBRBlockDevice.h +++ b/features/filesystem/bd/MBRBlockDevice.h @@ -193,11 +193,11 @@ class MBRBlockDevice : public BlockDevice /** Get the value of storage when erased * * If get_erase_value returns a non-negative byte value, the underlying - * storage will be set to that value when erased, and storage containing + * 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 the value of - * erased storage can't be relied on + * @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; diff --git a/features/filesystem/bd/ObservingBlockDevice.h b/features/filesystem/bd/ObservingBlockDevice.h index 7e5a21dd92b..0a265dc1b6b 100644 --- a/features/filesystem/bd/ObservingBlockDevice.h +++ b/features/filesystem/bd/ObservingBlockDevice.h @@ -108,11 +108,11 @@ class ObservingBlockDevice : public BlockDevice /** Get the value of storage when erased * * If get_erase_value returns a non-negative byte value, the underlying - * storage will be set to that value when erased, and storage containing + * 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 the value of - * erased storage can't be relied on + * @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; diff --git a/features/filesystem/bd/ProfilingBlockDevice.h b/features/filesystem/bd/ProfilingBlockDevice.h index b8c3295c51b..ff0782b90ea 100644 --- a/features/filesystem/bd/ProfilingBlockDevice.h +++ b/features/filesystem/bd/ProfilingBlockDevice.h @@ -125,11 +125,11 @@ class ProfilingBlockDevice : public BlockDevice /** Get the value of storage when erased * * If get_erase_value returns a non-negative byte value, the underlying - * storage will be set to that value when erased, and storage containing - * that value can be programmed without another erase. + * 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 the value of - * erased storage can't be relied on + * @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; diff --git a/features/filesystem/bd/ReadOnlyBlockDevice.h b/features/filesystem/bd/ReadOnlyBlockDevice.h index 31462fad915..a99f05ecfea 100644 --- a/features/filesystem/bd/ReadOnlyBlockDevice.h +++ b/features/filesystem/bd/ReadOnlyBlockDevice.h @@ -101,11 +101,11 @@ class ReadOnlyBlockDevice : public BlockDevice /** Get the value of storage when erased * * If get_erase_value returns a non-negative byte value, the underlying - * storage will be set to that value when erased, and storage containing + * 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 the value of - * erased storage can't be relied on + * @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; diff --git a/features/filesystem/bd/SlicingBlockDevice.h b/features/filesystem/bd/SlicingBlockDevice.h index 635eab81e9a..9fadf05b815 100644 --- a/features/filesystem/bd/SlicingBlockDevice.h +++ b/features/filesystem/bd/SlicingBlockDevice.h @@ -131,11 +131,11 @@ class SlicingBlockDevice : public BlockDevice /** Get the value of storage when erased * * If get_erase_value returns a non-negative byte value, the underlying - * storage will be set to that value when erased, and storage containing + * 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 the value of - * erased storage can't be relied on + * @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;