From 88aad813452e035d08854afc643aa18b4be110a9 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Wed, 24 Jan 2018 17:40:38 -0600 Subject: [PATCH] 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 f9f5c9a29f..4383670ebd 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 63b4a5d020..db4594536f 100644 --- a/features/filesystem/bd/ChainingBlockDevice.h +++ b/features/filesystem/bd/ChainingBlockDevice.h @@ -107,7 +107,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 @@ -135,6 +136,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 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 @@ protected: 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 0b16a9217f..61eac06378 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 8fc3918317..7fedc22a61 100644 --- a/features/filesystem/bd/ExhaustibleBlockDevice.h +++ b/features/filesystem/bd/ExhaustibleBlockDevice.h @@ -92,7 +92,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 @@ -118,6 +119,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 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 134ce9848b..8967f2f542 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 48964fba1c..322a32a15a 100644 --- a/features/filesystem/bd/MBRBlockDevice.h +++ b/features/filesystem/bd/MBRBlockDevice.h @@ -161,7 +161,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 @@ -189,6 +190,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 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 ea6dc5da15..e53ce70573 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 1e8c1942cb..7e5a21dd92 100644 --- a/features/filesystem/bd/ObservingBlockDevice.h +++ b/features/filesystem/bd/ObservingBlockDevice.h @@ -78,7 +78,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 @@ -104,6 +105,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 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 6baa24cb90..775a4b5fc0 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 c019fa7300..b8c3295c51 100644 --- a/features/filesystem/bd/ProfilingBlockDevice.h +++ b/features/filesystem/bd/ProfilingBlockDevice.h @@ -93,7 +93,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 @@ -121,6 +122,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 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 84ab36ff2d..9e9f01bded 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 23c8f40e8d..31462fad91 100644 --- a/features/filesystem/bd/ReadOnlyBlockDevice.h +++ b/features/filesystem/bd/ReadOnlyBlockDevice.h @@ -71,7 +71,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 @@ -97,6 +98,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 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 249acf81b6..d784a840b2 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 e219f77480..635eab81e9 100644 --- a/features/filesystem/bd/SlicingBlockDevice.h +++ b/features/filesystem/bd/SlicingBlockDevice.h @@ -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 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