Skip to content

Commit 72d1918

Browse files
authored
Merge pull request #12919 from VeijoPesonen/fix_blockdevice
ExhaustibleBlockDevice: revert commit 10481f2
2 parents 918d679 + 56ede3a commit 72d1918

File tree

3 files changed

+10
-63
lines changed

3 files changed

+10
-63
lines changed

UNITTESTS/features/storage/blockdevice/ExhaustibleBlockDevice/test_ExhaustibleBlockDevice.cpp

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ TEST_F(ExhaustibleBlockModuleTest, init)
7878
EXPECT_EQ(b.get_read_size(), 0);
7979
EXPECT_EQ(b.get_program_size(), 0);
8080
EXPECT_EQ(b.size(), 0);
81-
b.set_erase_cycles(0, 100); // This should not take effect.
82-
EXPECT_EQ(b.get_erase_cycles(0), 0);
8381
EXPECT_EQ(b.erase(0, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
8482
EXPECT_EQ(b.program(magic, 0, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
8583
EXPECT_EQ(b.read(buf, 0, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
@@ -95,7 +93,6 @@ TEST_F(ExhaustibleBlockModuleTest, init)
9593
EXPECT_EQ(b.get_erase_size(), bd_mock.get_erase_size());
9694
EXPECT_EQ(b.get_erase_size(0), bd_mock.get_erase_size(0));
9795
EXPECT_EQ(b.get_erase_value(), bd_mock.get_erase_value());
98-
EXPECT_NE(b.get_erase_cycles(0), 100);
9996
EXPECT_EQ(b.get_program_size(), 512);
10097
EXPECT_EQ(b.get_read_size(), 512);
10198
EXPECT_EQ(b.size(), bd_mock.size());
@@ -110,43 +107,29 @@ TEST_F(ExhaustibleBlockModuleTest, program_unaligned)
110107

111108
TEST_F(ExhaustibleBlockModuleTest, erase_cycle_limit_reached)
112109
{
113-
EXPECT_NE(bd.get_erase_cycles(0), 0);
114-
115110
EXPECT_CALL(bd_mock, program(_, 0, BLOCK_SIZE))
116111
.Times(1)
117112
.WillRepeatedly(Return(BD_ERROR_OK));
118113

119114
EXPECT_EQ(bd.program(magic, 0, BLOCK_SIZE), 0);
120115

121116
EXPECT_CALL(bd_mock, erase(0, BLOCK_SIZE))
122-
.Times(ERASE_CYCLES)
117+
.Times(ERASE_CYCLES - 1) // Will fall silently after erase cycles are worn out.
123118
.WillRepeatedly(Return(BD_ERROR_OK));
124119

125120
for (int i = 0; i < ERASE_CYCLES; i++) {
126121
EXPECT_EQ(bd.erase(0, BLOCK_SIZE), 0);
127122
}
128-
EXPECT_EQ(bd.get_erase_cycles(0), 0);
129123

130-
// This calls are expect not to happen.
131-
EXPECT_EQ(bd.erase(0, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
132-
EXPECT_EQ(bd.program(magic2, 0, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
124+
// Erase silently fails, no error report.
125+
EXPECT_EQ(bd.erase(0, BLOCK_SIZE), BD_ERROR_OK);
126+
EXPECT_EQ(bd.program(magic2, 0, BLOCK_SIZE), BD_ERROR_OK);
133127
}
134128

135129
TEST_F(ExhaustibleBlockModuleTest, erase_invalid)
136130
{
137131
ASSERT_GT(ERASE_CYCLES, 1);
138132

139-
EXPECT_EQ(bd.get_erase_cycles(0), ERASE_CYCLES);
140-
141133
// Unaligned erase should fail
142134
EXPECT_EQ(bd.erase(0, BLOCK_SIZE-1), BD_ERROR_DEVICE_ERROR);
143-
// Number of erase cycles should not change
144-
EXPECT_EQ(bd.get_erase_cycles(0), ERASE_CYCLES);
145-
}
146-
147-
TEST_F(ExhaustibleBlockModuleTest, set_erase_cycles)
148-
{
149-
EXPECT_EQ(bd.get_erase_cycles(0), ERASE_CYCLES);
150-
bd.set_erase_cycles(0, ERASE_CYCLES+1);
151-
EXPECT_EQ(bd.get_erase_cycles(0), ERASE_CYCLES+1);
152135
}

features/storage/blockdevice/ExhaustibleBlockDevice.cpp

Lines changed: 6 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,13 @@
2121
namespace mbed {
2222

2323
ExhaustibleBlockDevice::ExhaustibleBlockDevice(BlockDevice *bd, uint32_t erase_cycles)
24-
: _bd(bd), _erase_array(NULL), _programmable_array(NULL), _erase_cycles(erase_cycles),
25-
_init_ref_count(0), _is_initialized(false)
24+
: _bd(bd), _erase_array(NULL), _erase_cycles(erase_cycles), _init_ref_count(0), _is_initialized(false)
2625
{
2726
}
2827

2928
ExhaustibleBlockDevice::~ExhaustibleBlockDevice()
3029
{
3130
delete[] _erase_array;
32-
delete[] _programmable_array;
33-
}
34-
35-
uint32_t ExhaustibleBlockDevice::get_erase_cycles(bd_addr_t addr) const
36-
{
37-
if (!_is_initialized) {
38-
return 0;
39-
}
40-
return _erase_array[addr / get_erase_size()];
41-
}
42-
43-
void ExhaustibleBlockDevice::set_erase_cycles(bd_addr_t addr, uint32_t cycles)
44-
{
45-
if (!_is_initialized) {
46-
return;
47-
}
48-
_erase_array[addr / get_erase_size()] = cycles;
4931
}
5032

5133
int ExhaustibleBlockDevice::init()
@@ -70,13 +52,6 @@ int ExhaustibleBlockDevice::init()
7052
}
7153
}
7254

73-
if (!_programmable_array) {
74-
_programmable_array = new bool[_bd->size() / _bd->get_erase_size()];
75-
for (size_t i = 0; i < _bd->size() / _bd->get_erase_size(); i++) {
76-
_programmable_array[i] = true;
77-
}
78-
}
79-
8055
_is_initialized = true;
8156
return BD_ERROR_OK;
8257

@@ -133,20 +108,10 @@ int ExhaustibleBlockDevice::program(const void *buffer, bd_addr_t addr, bd_size_
133108
}
134109

135110
if (_erase_array[addr / get_erase_size()] == 0) {
136-
return BD_ERROR_DEVICE_ERROR;
137-
}
138-
139-
if (!_programmable_array[addr / get_erase_size()]) {
140-
return BD_ERROR_DEVICE_ERROR;
141-
}
142-
143-
int ret = _bd->program(buffer, addr, size);
144-
145-
if (ret == BD_ERROR_OK) {
146-
_programmable_array[addr / get_erase_size()] = false;
111+
return 0;
147112
}
148113

149-
return ret;
114+
return _bd->program(buffer, addr, size);
150115
}
151116

152117
int ExhaustibleBlockDevice::erase(bd_addr_t addr, bd_size_t size)
@@ -164,13 +129,13 @@ int ExhaustibleBlockDevice::erase(bd_addr_t addr, bd_size_t size)
164129
// use an erase cycle
165130
if (_erase_array[addr / eu_size] > 0) {
166131
_erase_array[addr / eu_size] -= 1;
132+
}
133+
134+
if (_erase_array[addr / eu_size] > 0) {
167135
int err = _bd->erase(addr, eu_size);
168136
if (err) {
169137
return err;
170138
}
171-
_programmable_array[addr / get_erase_size()] = true;
172-
} else {
173-
return BD_ERROR_DEVICE_ERROR;
174139
}
175140

176141
addr += eu_size;

features/storage/blockdevice/ExhaustibleBlockDevice.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ class ExhaustibleBlockDevice : public BlockDevice {
158158
private:
159159
BlockDevice *_bd;
160160
uint32_t *_erase_array;
161-
bool *_programmable_array;
162161
uint32_t _erase_cycles;
163162
uint32_t _init_ref_count;
164163
bool _is_initialized;

0 commit comments

Comments
 (0)