Skip to content

Commit 88aad81

Browse files
committed
bd: Adopted the get_erase_value function in the util block devices
1 parent 7707c8b commit 88aad81

14 files changed

+136
-7
lines changed

features/filesystem/bd/ChainingBlockDevice.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
ChainingBlockDevice::ChainingBlockDevice(BlockDevice **bds, size_t bd_count)
2121
: _bds(bds), _bd_count(bd_count)
2222
, _read_size(0), _program_size(0), _erase_size(0), _size(0)
23+
, _erase_value(-1)
2324
{
2425
}
2526

@@ -33,6 +34,7 @@ int ChainingBlockDevice::init()
3334
_read_size = 0;
3435
_program_size = 0;
3536
_erase_size = 0;
37+
_erase_value = -1;
3638
_size = 0;
3739

3840
// Initialize children block devices, find all sizes and
@@ -66,6 +68,13 @@ int ChainingBlockDevice::init()
6668
MBED_ASSERT(_erase_size > erase && is_aligned(_erase_size, erase));
6769
}
6870

71+
int value = _bds[i]->get_erase_value();
72+
if (i == 0 || value == _erase_value) {
73+
_erase_value = value;
74+
} else {
75+
_erase_value = -1;
76+
}
77+
6978
_size += _bds[i]->size();
7079
}
7180

@@ -190,6 +199,11 @@ bd_size_t ChainingBlockDevice::get_erase_size() const
190199
return _erase_size;
191200
}
192201

202+
int ChainingBlockDevice::get_erase_value() const
203+
{
204+
return _erase_value;
205+
}
206+
193207
bd_size_t ChainingBlockDevice::size() const
194208
{
195209
return _size;

features/filesystem/bd/ChainingBlockDevice.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ class ChainingBlockDevice : public BlockDevice
107107

108108
/** Erase blocks on a block device
109109
*
110-
* The state of an erased block is undefined until it has been programmed
110+
* The state of an erased block is undefined until it has been programmed,
111+
* unless get_erase_value returns a non-negative byte value
111112
*
112113
* @param addr Address of block to begin erasing
113114
* @param size Size to erase in bytes, must be a multiple of erase block size
@@ -135,6 +136,17 @@ class ChainingBlockDevice : public BlockDevice
135136
*/
136137
virtual bd_size_t get_erase_size() const;
137138

139+
/** Get the value of storage when erased
140+
*
141+
* If get_erase_value returns a non-negative byte value, the underlying
142+
* storage will be set to that value when erased, and storage containing
143+
* that value can be programmed without another erase.
144+
*
145+
* @return The value of storage when erased, or -1 if the value of
146+
* erased storage can't be relied on
147+
*/
148+
virtual int get_erase_value() const;
149+
138150
/** Get the total size of the underlying device
139151
*
140152
* @return Size of the underlying device in bytes
@@ -148,6 +160,7 @@ class ChainingBlockDevice : public BlockDevice
148160
bd_size_t _program_size;
149161
bd_size_t _erase_size;
150162
bd_size_t _size;
163+
int _erase_value;
151164
};
152165

153166

features/filesystem/bd/ExhaustibleBlockDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ bd_size_t ExhaustibleBlockDevice::get_erase_size() const
102102
return _bd->get_erase_size();
103103
}
104104

105+
int ExhaustibleBlockDevice::get_erase_value() const
106+
{
107+
return _bd->get_erase_value();
108+
}
109+
105110
bd_size_t ExhaustibleBlockDevice::size() const
106111
{
107112
return _bd->size();

features/filesystem/bd/ExhaustibleBlockDevice.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ class ExhaustibleBlockDevice : public BlockDevice
9292

9393
/** Erase blocks on a block device
9494
*
95-
* The state of an erased block is undefined until it has been programmed
95+
* The state of an erased block is undefined until it has been programmed,
96+
* unless get_erase_value returns a non-negative byte value
9697
*
9798
* @param addr Address of block to begin erasing
9899
* @param size Size to erase in bytes, must be a multiple of erase block size
@@ -118,6 +119,17 @@ class ExhaustibleBlockDevice : public BlockDevice
118119
*/
119120
virtual bd_size_t get_erase_size() const;
120121

122+
/** Get the value of storage when erased
123+
*
124+
* If get_erase_value returns a non-negative byte value, the underlying
125+
* storage will be set to that value when erased, and storage containing
126+
* that value can be programmed without another erase.
127+
*
128+
* @return The value of storage when erased, or -1 if the value of
129+
* erased storage can't be relied on
130+
*/
131+
virtual int get_erase_value() const;
132+
121133
/** Get the total size of the underlying device
122134
*
123135
* @return Size of the underlying device in bytes

features/filesystem/bd/MBRBlockDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ bd_size_t MBRBlockDevice::get_erase_size() const
267267
return _bd->get_erase_size();
268268
}
269269

270+
int MBRBlockDevice::get_erase_value() const
271+
{
272+
return _bd->get_erase_value();
273+
}
274+
270275
bd_size_t MBRBlockDevice::size() const
271276
{
272277
return _size;

features/filesystem/bd/MBRBlockDevice.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ class MBRBlockDevice : public BlockDevice
161161

162162
/** Erase blocks on a block device
163163
*
164-
* The state of an erased block is undefined until it has been programmed
164+
* The state of an erased block is undefined until it has been programmed,
165+
* unless get_erase_value returns a non-negative byte value
165166
*
166167
* @param addr Address of block to begin erasing
167168
* @param size Size to erase in bytes, must be a multiple of erase block size
@@ -189,6 +190,17 @@ class MBRBlockDevice : public BlockDevice
189190
*/
190191
virtual bd_size_t get_erase_size() const;
191192

193+
/** Get the value of storage when erased
194+
*
195+
* If get_erase_value returns a non-negative byte value, the underlying
196+
* storage will be set to that value when erased, and storage containing
197+
* that value can be programmed without another erase.
198+
*
199+
* @return The value of storage when erased, or -1 if the value of
200+
* erased storage can't be relied on
201+
*/
202+
virtual int get_erase_value() const;
203+
192204
/** Get the total size of the underlying device
193205
*
194206
* @return Size of the underlying device in bytes

features/filesystem/bd/ObservingBlockDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ bd_size_t ObservingBlockDevice::get_erase_size() const
9191
return _bd->get_erase_size();
9292
}
9393

94+
int ObservingBlockDevice::get_erase_value() const
95+
{
96+
return _bd->get_erase_value();
97+
}
98+
9499
bd_size_t ObservingBlockDevice::size() const
95100
{
96101
return _bd->size();

features/filesystem/bd/ObservingBlockDevice.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ class ObservingBlockDevice : public BlockDevice
7878

7979
/** Erase blocks on a block device
8080
*
81-
* The state of an erased block is undefined until it has been programmed
81+
* The state of an erased block is undefined until it has been programmed,
82+
* unless get_erase_value returns a non-negative byte value
8283
*
8384
* @param addr Address of block to begin erasing
8485
* @param size Size to erase in bytes, must be a multiple of erase block size
@@ -104,6 +105,17 @@ class ObservingBlockDevice : public BlockDevice
104105
*/
105106
virtual bd_size_t get_erase_size() const;
106107

108+
/** Get the value of storage when erased
109+
*
110+
* If get_erase_value returns a non-negative byte value, the underlying
111+
* storage will be set to that value when erased, and storage containing
112+
* that value can be programmed without another erase.
113+
*
114+
* @return The value of storage when erased, or -1 if the value of
115+
* erased storage can't be relied on
116+
*/
117+
virtual int get_erase_value() const;
118+
107119
/** Get the total size of the underlying device
108120
*
109121
* @return Size of the underlying device in bytes

features/filesystem/bd/ProfilingBlockDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ bd_size_t ProfilingBlockDevice::get_erase_size() const
7777
return _bd->get_erase_size();
7878
}
7979

80+
int ProfilingBlockDevice::get_erase_value() const
81+
{
82+
return _bd->get_erase_value();
83+
}
84+
8085
bd_size_t ProfilingBlockDevice::size() const
8186
{
8287
return _bd->size();

features/filesystem/bd/ProfilingBlockDevice.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ class ProfilingBlockDevice : public BlockDevice
9393

9494
/** Erase blocks on a block device
9595
*
96-
* The state of an erased block is undefined until it has been programmed
96+
* The state of an erased block is undefined until it has been programmed,
97+
* unless get_erase_value returns a non-negative byte value
9798
*
9899
* @param addr Address of block to begin erasing
99100
* @param size Size to erase in bytes, must be a multiple of erase block size
@@ -121,6 +122,17 @@ class ProfilingBlockDevice : public BlockDevice
121122
*/
122123
virtual bd_size_t get_erase_size() const;
123124

125+
/** Get the value of storage when erased
126+
*
127+
* If get_erase_value returns a non-negative byte value, the underlying
128+
* storage will be set to that value when erased, and storage containing
129+
* that value can be programmed without another erase.
130+
*
131+
* @return The value of storage when erased, or -1 if the value of
132+
* erased storage can't be relied on
133+
*/
134+
virtual int get_erase_value() const;
135+
124136
/** Get the total size of the underlying device
125137
*
126138
* @return Size of the underlying device in bytes

features/filesystem/bd/ReadOnlyBlockDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,11 @@ bd_size_t ReadOnlyBlockDevice::get_erase_size() const
7777
return _bd->get_erase_size();
7878
}
7979

80+
int ReadOnlyBlockDevice::get_erase_value() const
81+
{
82+
return _bd->get_erase_value();
83+
}
84+
8085
bd_size_t ReadOnlyBlockDevice::size() const
8186
{
8287
return _bd->size();

features/filesystem/bd/ReadOnlyBlockDevice.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ class ReadOnlyBlockDevice : public BlockDevice
7171

7272
/** Erase blocks on a block device
7373
*
74-
* The state of an erased block is undefined until it has been programmed
74+
* The state of an erased block is undefined until it has been programmed,
75+
* unless get_erase_value returns a non-negative byte value
7576
*
7677
* @param addr Address of block to begin erasing
7778
* @param size Size to erase in bytes, must be a multiple of erase block size
@@ -97,6 +98,17 @@ class ReadOnlyBlockDevice : public BlockDevice
9798
*/
9899
virtual bd_size_t get_erase_size() const;
99100

101+
/** Get the value of storage when erased
102+
*
103+
* If get_erase_value returns a non-negative byte value, the underlying
104+
* storage will be set to that value when erased, and storage containing
105+
* that value can be programmed without another erase.
106+
*
107+
* @return The value of storage when erased, or -1 if the value of
108+
* erased storage can't be relied on
109+
*/
110+
virtual int get_erase_value() const;
111+
100112
/** Get the total size of the underlying device
101113
*
102114
* @return Size of the underlying device in bytes

features/filesystem/bd/SlicingBlockDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ bd_size_t SlicingBlockDevice::get_erase_size() const
9797
return _bd->get_erase_size();
9898
}
9999

100+
int SlicingBlockDevice::get_erase_value() const
101+
{
102+
return _bd->get_erase_value();
103+
}
104+
100105
bd_size_t SlicingBlockDevice::size() const
101106
{
102107
return _stop - _start;

features/filesystem/bd/SlicingBlockDevice.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ class SlicingBlockDevice : public BlockDevice
9999

100100
/** Erase blocks on a block device
101101
*
102-
* The state of an erased block is undefined until it has been programmed
102+
* The state of an erased block is undefined until it has been programmed,
103+
* unless get_erase_value returns a non-negative byte value
103104
*
104105
* @param addr Address of block to begin erasing
105106
* @param size Size to erase in bytes, must be a multiple of erase block size
@@ -127,6 +128,17 @@ class SlicingBlockDevice : public BlockDevice
127128
*/
128129
virtual bd_size_t get_erase_size() const;
129130

131+
/** Get the value of storage when erased
132+
*
133+
* If get_erase_value returns a non-negative byte value, the underlying
134+
* storage will be set to that value when erased, and storage containing
135+
* that value can be programmed without another erase.
136+
*
137+
* @return The value of storage when erased, or -1 if the value of
138+
* erased storage can't be relied on
139+
*/
140+
virtual int get_erase_value() const;
141+
130142
/** Get the total size of the underlying device
131143
*
132144
* @return Size of the underlying device in bytes

0 commit comments

Comments
 (0)