Skip to content

bd: Add MBR block device for standard storage partitioning #3936

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

Merged
merged 4 commits into from
May 30, 2017

Conversation

geky
Copy link
Contributor

@geky geky commented Mar 16, 2017

The MBRBlockDevice adds support for standard storage partitioning. This is the standard partitioning scheme everyone knows and loves (and is probably using underneath their OS). For more information:
https://en.wikipedia.org/wiki/Master_boot_record

Here's the example:

#include "mbed.h"
#include "HeapBlockDevice.h"
#include "MBRBlockDevice.h"

// Create a block device with 64 blocks of size 512
HeapBlockDevice mem(64*512, 512);

// Partition into two partitions with ~half the blocks
MBRBlockDevice::partition(&mem, 1, 0x00, 0*512, 32*512);
MBRBlockDevice::partition(&mem, 2, 0x00, 32*512);

// Create a block device that maps to the first 32 blocks (excluding MBR block)
MBRBlockDevice part1(&mem, 1);

// Create a block device that maps to the last 32 blocks
MBRBlockDevice part2(&mem, 2);

Also comes in with tests and doxygen.

cc @simonqhughes

@0xc0170 0xc0170 requested a review from simonqhughes March 20, 2017 15:50
_size = fromle32(table->entries[_part-1].lba_size) * sector;

// Check that block addresses are valid
printf("offset %lld\n", _offset);
Copy link
Contributor

@0xc0170 0xc0170 Mar 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended to be printed always (not a debug msg) ? or just left behind?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah whoops, good catch 👍

@0xc0170
Copy link
Contributor

0xc0170 commented Mar 20, 2017

@simonqhughes please review

HeapBlockDevice bd(BLOCK_COUNT*BLOCK_SIZE, BLOCK_SIZE);

// Testing formatting of master boot record
void test_mbr_format() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code style same as the implementation

void test_mbr_format()
{
    //code here
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch 👍

@geky geky force-pushed the bd-mbr branch 2 times, most recently from 655d485 to ab5a2b9 Compare March 21, 2017 19:48
@sg-
Copy link
Contributor

sg- commented Mar 22, 2017

I kinda get this but does the FATFileSystem mount a MBRBlockDevice?

@geky
Copy link
Contributor Author

geky commented Mar 22, 2017

You can, it depends on how you structure your classes:

SDBlockDevice sd(s0, s1, s2, s3); // SD card
MBRBlockDevice part1(&sd, 1); // Partition 1 on SD card
FATFileSystem fs("fat", &part1); // FAT filesystem on partition 1

Should be noted the MBRBlockDevice is optional. External storage doesn't need an mbr for pcs, and chanfs already traverses an mbr if it runs into one.

The MBRBlockDevice is useful if you want to access other partitions on the device while still allowing mountability across other devices. It also provides a few other uses, such as defining storage regions at manufacturing time, or storing partition attributes.

@adbridge
Copy link
Contributor

@sg- are you happy with @geky comments ?

@sg-
Copy link
Contributor

sg- commented Apr 10, 2017

@geky LGTM. Just need an API page for this and stage some updates to storage docs in the handbook that show how to use it.

@theotherjimmy
Copy link
Contributor

@geky any news on the docs update?

@geky
Copy link
Contributor Author

geky commented May 12, 2017

I added a blurb in the API page for the block device API that links to the documentation in the MBRBlockDevice.h header:
ARMmbed/mbed_OS_API_Docs#80

I'm not sure the MBR block device needs it's own handbook page as it's just one part of the storage apis, but let me know if you want more documentation. (The doxygen in the class contains example usage).

@geky
Copy link
Contributor Author

geky commented May 12, 2017

I also added a bit more to the class documentation and included the SD card example.


// Little-endian conversion, should compile to noop
// if system is little-endian
static inline uint32_t tole32(uint32_t a) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you align the code style

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, should be updated

TEST_ASSERT_EQUAL(0, err);

// Test attributes on partitions
printf("partition 1 partition number: %d\n", part1.get_partition_number());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need all these prints? if they fail, these numbers will be printed as part of the error?

Copy link
Contributor Author

@geky geky May 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output would help debugging what went wrong in the test. Multiple attributes may be wrong, but the assert would stop after the first.

Copy link
Contributor

@0xc0170 0xc0170 May 16, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood, but still the test should not print anything if is all green ? This is more for future request (than solving it here with this PR) - having logging library. Some tests already have something like DEBUG_PRINT that is a config attribute and by default disabled. Is it time now to consider having something similar to it - a proper replacement?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rambled grumpily over here: #4317 (comment), there's also related discussion over there.

It does seem like we should have a configurable logging/debug we can remove at compile time, but I'm going to leave these as is for now. They aren't currently causing a problem, and we should probably apply a consistent solution to all of the tests we have in a seperate pr.

@adbridge
Copy link
Contributor

@0xc0170 are you happy with @geky responses ?

@0xc0170
Copy link
Contributor

0xc0170 commented May 17, 2017

@0xc0170 are you happy with @geky responses ?

Yes, LGTM

@sg- sg- added needs: CI and removed needs: work labels May 18, 2017
@geky
Copy link
Contributor Author

geky commented May 18, 2017

/morph test-nightly

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test-nightly

Output

mbed Build Number: 269

Test failed!

@0xc0170
Copy link
Contributor

0xc0170 commented May 19, 2017

features-tests-filesystem-mbr_block_device failures in the last CI build, please look at them

@adbridge
Copy link
Contributor

@geky Any update on this ?

@geky
Copy link
Contributor Author

geky commented May 24, 2017

/morph test-nightly

@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test-nightly

Output

mbed Build Number: 336

All builds and test passed!

This saves 64 blocks (32KB when used with 512B blocks) and drops
the minimum storage size from 64KB to 32KB.
@geky geky requested a review from sg- May 25, 2017 19:26
@geky
Copy link
Contributor Author

geky commented May 25, 2017

Found an issue with how the fat filesystem calculated the minimum block count required without the MBR (3ee77e3). Sorry about creating the rereview.

@0xc0170
Copy link
Contributor

0xc0170 commented May 26, 2017

/morph test-nightly

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test-nightly

Output

mbed Build Number: 358

Test failed!

@geky
Copy link
Contributor Author

geky commented May 26, 2017

11:05:13 [1495814808.48][CONN][RXD] UDP: tx -> 5
11:05:13 [1495814808.50][CONN][RXD] UDP: rx <- 128
11:05:13 [1495814808.52][CONN][RXD] UDP: rx <- 400
11:05:13 [1495814808.54][CONN][RXD] UDP: rx <- 208
11:05:13 [1495814808.55][CONN][RXD] UDP: rx <- 224
11:06:09 [1495814864.31][HTST][INF] test suite run finished after 60.81 sec...
...
11:06:09 [1495814864.52][HTST][INF] {{result;timeout}}
11:06:09 mbedgt: checking for GCOV data...
11:06:09 mbedgt: mbed-host-test-runner: stopped and returned 'TIMEOUT'

This is a sporadic udp packet loss error fixed by this guy: #4369

@sg-
Copy link
Contributor

sg- commented May 29, 2017

/morph test-nightly

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test-nightly

Output

mbed Build Number: 366

Test failed!

@0xc0170
Copy link
Contributor

0xc0170 commented May 30, 2017

/morph test-nightly

@mbed-bot
Copy link

Result: FAILURE

Your command has finished executing! Here's what you wrote!

/morph test-nightly

Output

mbed Build Number: 367

Test failed!

@0xc0170
Copy link
Contributor

0xc0170 commented May 30, 2017

/morph test-nightly

@mbed-bot
Copy link

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test-nightly

Output

mbed Build Number: 369

All builds and test passed!

@geky
Copy link
Contributor Author

geky commented May 30, 2017

Woah! One got through! LGTM?

@sg- sg- merged commit f438251 into ARMmbed:master May 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants