Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bd: Fix missing init in MBRBlockDevice #4607

Merged
merged 2 commits into from
Jun 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion features/filesystem/bd/HeapBlockDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,39 @@ int HeapBlockDevice::init()

int HeapBlockDevice::deinit()
{
// Heapory is lazily cleaned up in destructor to allow
MBED_ASSERT(_blocks != NULL);
// Memory is lazily cleaned up in destructor to allow
// data to live across de/reinitialization
return BD_ERROR_OK;
}

bd_size_t HeapBlockDevice::get_read_size() const
{
MBED_ASSERT(_blocks != NULL);
return _read_size;
}

bd_size_t HeapBlockDevice::get_program_size() const
{
MBED_ASSERT(_blocks != NULL);
return _program_size;
}

bd_size_t HeapBlockDevice::get_erase_size() const
{
MBED_ASSERT(_blocks != NULL);
return _erase_size;
}

bd_size_t HeapBlockDevice::size() const
{
MBED_ASSERT(_blocks != NULL);
return _count * _erase_size;
}

int HeapBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(_blocks != NULL);
MBED_ASSERT(is_valid_read(addr, size));
uint8_t *buffer = static_cast<uint8_t*>(b);

Expand All @@ -107,6 +113,7 @@ int HeapBlockDevice::read(void *b, bd_addr_t addr, bd_size_t size)

int HeapBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(_blocks != NULL);
MBED_ASSERT(is_valid_program(addr, size));
const uint8_t *buffer = static_cast<const uint8_t*>(b);

Expand All @@ -133,6 +140,7 @@ int HeapBlockDevice::program(const void *b, bd_addr_t addr, bd_size_t size)

int HeapBlockDevice::erase(bd_addr_t addr, bd_size_t size)
{
MBED_ASSERT(_blocks != NULL);
MBED_ASSERT(is_valid_erase(addr, size));
// TODO assert on programming unerased blocks

Expand Down
7 changes: 6 additions & 1 deletion features/filesystem/bd/MBRBlockDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,16 @@ MBRBlockDevice::MBRBlockDevice(BlockDevice *bd, int part)

int MBRBlockDevice::init()
{
int err = _bd->init();
if (err) {
return err;
}

// Allocate smallest buffer necessary to write MBR
uint32_t buffer_size = std::max<uint32_t>(_bd->get_read_size(), sizeof(struct mbr_table));
uint8_t *buffer = new uint8_t[buffer_size];

int err = _bd->read(buffer, 512-buffer_size, buffer_size);
err = _bd->read(buffer, 512-buffer_size, buffer_size);
if (err) {
delete[] buffer;
return err;
Expand Down