Skip to content

Commit 5cd30b9

Browse files
authored
Merge pull request #5925 from geky/bd-erase-value
bd: Add get_erase_value function to the block device API
2 parents c06a42b + e6949db commit 5cd30b9

15 files changed

+152
-8
lines changed

features/filesystem/bd/BlockDevice.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ class BlockDevice
9494

9595
/** Erase blocks on a block device
9696
*
97-
* The state of an erased block is undefined until it has been programmed
97+
* The state of an erased block is undefined until it has been programmed,
98+
* unless get_erase_value returns a non-negative byte value
9899
*
99100
* @param addr Address of block to begin erasing
100101
* @param size Size to erase in bytes, must be a multiple of erase block size
@@ -144,6 +145,20 @@ class BlockDevice
144145
return get_program_size();
145146
}
146147

148+
/** Get the value of storage when erased
149+
*
150+
* If get_erase_value returns a non-negative byte value, the underlying
151+
* storage is set to that value when erased, and storage containing
152+
* that value can be programmed without another erase.
153+
*
154+
* @return The value of storage when erased, or -1 if you can't
155+
* rely on the value of erased storage
156+
*/
157+
virtual int get_erase_value() const
158+
{
159+
return -1;
160+
}
161+
147162
/** Get the total size of the underlying device
148163
*
149164
* @return Size of the underlying device in bytes

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

@@ -202,6 +211,11 @@ bd_size_t ChainingBlockDevice::get_erase_size() const
202211
return _erase_size;
203212
}
204213

214+
int ChainingBlockDevice::get_erase_value() const
215+
{
216+
return _erase_value;
217+
}
218+
205219
bd_size_t ChainingBlockDevice::size() const
206220
{
207221
return _size;

features/filesystem/bd/ChainingBlockDevice.h

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

114114
/** Erase blocks on a block device
115115
*
116-
* The state of an erased block is undefined until it has been programmed
116+
* The state of an erased block is undefined until it has been programmed,
117+
* unless get_erase_value returns a non-negative byte value
117118
*
118119
* @param addr Address of block to begin erasing
119120
* @param size Size to erase in bytes, must be a multiple of erase block size
@@ -141,6 +142,17 @@ class ChainingBlockDevice : public BlockDevice
141142
*/
142143
virtual bd_size_t get_erase_size() const;
143144

145+
/** Get the value of storage when erased
146+
*
147+
* If get_erase_value returns a non-negative byte value, the underlying
148+
* storage is set to that value when erased, and storage containing
149+
* that value can be programmed without another erase.
150+
*
151+
* @return The value of storage when erased, or -1 if you can't
152+
* rely on the value of erased storage
153+
*/
154+
virtual int get_erase_value() const;
155+
144156
/** Get the total size of the underlying device
145157
*
146158
* @return Size of the underlying device in bytes
@@ -154,6 +166,7 @@ class ChainingBlockDevice : public BlockDevice
154166
bd_size_t _program_size;
155167
bd_size_t _erase_size;
156168
bd_size_t _size;
169+
int _erase_value;
157170
};
158171

159172

features/filesystem/bd/ExhaustibleBlockDevice.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,11 @@ bd_size_t ExhaustibleBlockDevice::get_erase_size() const
107107
return _bd->get_erase_size();
108108
}
109109

110+
int ExhaustibleBlockDevice::get_erase_value() const
111+
{
112+
return _bd->get_erase_value();
113+
}
114+
110115
bd_size_t ExhaustibleBlockDevice::size() const
111116
{
112117
return _bd->size();

features/filesystem/bd/ExhaustibleBlockDevice.h

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

9999
/** Erase blocks on a block device
100100
*
101-
* The state of an erased block is undefined until it has been programmed
101+
* The state of an erased block is undefined until it has been programmed,
102+
* unless get_erase_value returns a non-negative byte value
102103
*
103104
* @param addr Address of block to begin erasing
104105
* @param size Size to erase in bytes, must be a multiple of erase block size
@@ -124,6 +125,17 @@ class ExhaustibleBlockDevice : public BlockDevice
124125
*/
125126
virtual bd_size_t get_erase_size() const;
126127

128+
/** Get the value of storage when erased
129+
*
130+
* If get_erase_value returns a non-negative byte value, the underlying
131+
* storage is set to that value when erased, and storage containing
132+
* that value can be programmed without another erase.
133+
*
134+
* @return The value of storage when erased, or -1 if you can't
135+
* rely on the value of erased storage
136+
*/
137+
virtual int get_erase_value() const;
138+
127139
/** Get the total size of the underlying device
128140
*
129141
* @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
@@ -272,6 +272,11 @@ bd_size_t MBRBlockDevice::get_erase_size() const
272272
return _bd->get_erase_size();
273273
}
274274

275+
int MBRBlockDevice::get_erase_value() const
276+
{
277+
return _bd->get_erase_value();
278+
}
279+
275280
bd_size_t MBRBlockDevice::size() const
276281
{
277282
return _size;

features/filesystem/bd/MBRBlockDevice.h

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

168168
/** Erase blocks on a block device
169169
*
170-
* The state of an erased block is undefined until it has been programmed
170+
* The state of an erased block is undefined until it has been programmed,
171+
* unless get_erase_value returns a non-negative byte value
171172
*
172173
* @param addr Address of block to begin erasing
173174
* @param size Size to erase in bytes, must be a multiple of erase block size
@@ -195,6 +196,17 @@ class MBRBlockDevice : public BlockDevice
195196
*/
196197
virtual bd_size_t get_erase_size() const;
197198

199+
/** Get the value of storage when erased
200+
*
201+
* If get_erase_value returns a non-negative byte value, the underlying
202+
* storage is set to that value when erased, and storage containing
203+
* that value can be programmed without another erase.
204+
*
205+
* @return The value of storage when erased, or -1 if you can't
206+
* rely on the value of erased storage
207+
*/
208+
virtual int get_erase_value() const;
209+
198210
/** Get the total size of the underlying device
199211
*
200212
* @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
@@ -96,6 +96,11 @@ bd_size_t ObservingBlockDevice::get_erase_size() const
9696
return _bd->get_erase_size();
9797
}
9898

99+
int ObservingBlockDevice::get_erase_value() const
100+
{
101+
return _bd->get_erase_value();
102+
}
103+
99104
bd_size_t ObservingBlockDevice::size() const
100105
{
101106
return _bd->size();

features/filesystem/bd/ObservingBlockDevice.h

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

8585
/** Erase blocks on a block device
8686
*
87-
* The state of an erased block is undefined until it has been programmed
87+
* The state of an erased block is undefined until it has been programmed,
88+
* unless get_erase_value returns a non-negative byte value
8889
*
8990
* @param addr Address of block to begin erasing
9091
* @param size Size to erase in bytes, must be a multiple of erase block size
@@ -110,6 +111,17 @@ class ObservingBlockDevice : public BlockDevice
110111
*/
111112
virtual bd_size_t get_erase_size() const;
112113

114+
/** Get the value of storage when erased
115+
*
116+
* If get_erase_value returns a non-negative byte value, the underlying
117+
* storage is set to that value when erased, and storage containing
118+
* that value can be programmed without another erase.
119+
*
120+
* @return The value of storage when erased, or -1 if you can't
121+
* rely on the value of erased storage
122+
*/
123+
virtual int get_erase_value() const;
124+
113125
/** Get the total size of the underlying device
114126
*
115127
* @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
@@ -82,6 +82,11 @@ bd_size_t ProfilingBlockDevice::get_erase_size() const
8282
return _bd->get_erase_size();
8383
}
8484

85+
int ProfilingBlockDevice::get_erase_value() const
86+
{
87+
return _bd->get_erase_value();
88+
}
89+
8590
bd_size_t ProfilingBlockDevice::size() const
8691
{
8792
return _bd->size();

0 commit comments

Comments
 (0)