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

drivers/mtd_mapper: inherit physical properties #18113

Merged
merged 2 commits into from Jun 5, 2022

Conversation

benpicco
Copy link
Contributor

Contribution description

A MTD mapper region must adhere to the same physical constraints as the underlying MTD device, so inherit it's physical properties instead of relying on the user to set them correctly.

Testing procedure

tests/mtd_mapper still works without the redundant information

RIOT native interrupts/signals initialized.
RIOT native board initialized.
RIOT native hardware initialization complete.

Help: Press s to start test, r to print it is ready
s
START
main(): This is RIOT! (Version: 2022.07-devel-448-ge28040-drivers/mtd_mapper-inherit)
......
OK (6 tests)
{ "threads": [{ "name": "idle", "stack_size": 8192, "stack_used": 436 }]}
{ "threads": [{ "name": "main", "stack_size": 12288, "stack_used": 2508 }]}

Issues/PRs references

@benpicco benpicco requested review from bergzand and jue89 May 17, 2022 14:23
@github-actions github-actions bot added Area: drivers Area: Device drivers Area: tests Area: tests and testing framework labels May 17, 2022
@benpicco benpicco added the Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation label May 17, 2022
@benpicco benpicco requested a review from chrysn May 18, 2022 11:37
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label May 18, 2022
@chrysn
Copy link
Member

chrysn commented May 19, 2022

Might this have been assert-only so far to allow the maps to be static const? It's currently not tested for that this is allowed, but it might have been the original intention.

[edit] I looked around a bit more in the code -- the _lock() looks like it's writing, but that write goes through indirections, so at least from there statidc const should have been possible.

@benpicco
Copy link
Contributor Author

mtd_dev_t is usually writable to

  • allocate the .work_area buffer
  • set .pages_per_sector / .sector_count at run-time for SPI Flash and SD cards where this information can be queried from the device

@fjmolinas
Copy link
Contributor

Might this have been assert-only so far to allow the maps to be static const? It's currently not tested for that this is allowed, but it might have been the original intention.

[edit] I looked around a bit more in the code -- the _lock() looks like it's writing, but that write goes through indirections, so at least from there statidc const should have been possible.

Lets summon @bergzand then :)

@Laczen
Copy link

Laczen commented May 24, 2022

@benpicco are all these properties really physical properties? The write_size and sector_size are, the page_size and pages_per_sector can be changed as long as the sector size is kept. Allowing changing the page_size allows easier subsystem definition (e.g. Littlefs that IIRC uses the page_size as the block_size).

@benpicco
Copy link
Contributor Author

Huh? page_size is the largest block of data that can be written at once (when aligned to the page boundary).

It could be changed to a lower fraction, but to what gain?

LittleFS does

fs->config.block_size = fs->dev->page_size * fs->dev->pages_per_sector;
fs->config.prog_size = fs->dev->page_size;
fs->config.read_size = fs->dev->page_size;

where they use block instead of sector to name the erase unit.

@Laczen
Copy link

Laczen commented May 24, 2022

Huh? page_size is the largest block of data that can be written at once (when aligned to the page boundary).

It could be changed to a lower fraction, but to what gain?

LittleFS does

fs->config.block_size = fs->dev->page_size * fs->dev->pages_per_sector;
fs->config.prog_size = fs->dev->page_size;
fs->config.read_size = fs->dev->page_size;

where they use block instead of sector to name the erase unit.

I indeed missed in the definition, I meant the page_size is used as the prog_size in LittleFS. That the page_size is the largest block that can be written at once is new to me. The gain of defining a smaller block_size is better flash utilization.

@fabian18
Copy link
Contributor

The gain of defining a smaller block_size is better flash utilization.

If people find a reason not to inherit the physical properties, we could only inherit them in _init(), if they are 0.
static memory is 0 if uninitialized. So if they have been set before _init() we can assume that someone does not want to inherit parent properties.

@benpicco benpicco removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label May 25, 2022
@benpicco
Copy link
Contributor Author

benpicco commented May 25, 2022

But we already have

assert(backing_mtd->page_size == region->mtd.page_size);
assert(backing_mtd->pages_per_sector == region->mtd.pages_per_sector);

so setting this to anything else would currently fail in master.

@Laczen
Copy link

Laczen commented May 25, 2022

But we already have

assert(backing_mtd->page_size == region->mtd.page_size);
assert(backing_mtd->pages_per_sector == region->mtd.pages_per_sector);

so setting this to anything else would currently fail in master.

Maybe this was too limiting from the start ?

If the page_size would be defined as the largest block that can be written at once (needs to be documented) the checks should be:
a. region page_size <= backing page_size,
b. region page_size >= backing write_size,
c. region page_size * region pages_per_sector == backing page_size * backing pages_per_sector

@benpicco benpicco force-pushed the drivers/mtd_mapper-inherit branch from fbafc4f to ec5da5f Compare May 26, 2022 20:53
@bergzand
Copy link
Member

Lets summon @bergzand then :)

There might have been some intention to make it const at some point. But that's not going to happen at this point. I'm fine with this PR as it is.

@benpicco benpicco force-pushed the drivers/mtd_mapper-inherit branch from ec5da5f to 8ebfe9f Compare June 1, 2022 23:01
@benpicco benpicco added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 1, 2022
@fjmolinas fjmolinas removed the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 2, 2022
@fjmolinas fjmolinas added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 2, 2022
@benpicco benpicco force-pushed the drivers/mtd_mapper-inherit branch from 8ebfe9f to 53f891e Compare June 2, 2022 22:22
Copy link
Contributor

@fabian18 fabian18 left a comment

Choose a reason for hiding this comment

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

I am also happy with this. I would also add some kind of initializer macro but that´s not the topic here.

@benpicco benpicco merged commit 4160ed7 into RIOT-OS:master Jun 5, 2022
@benpicco benpicco deleted the drivers/mtd_mapper-inherit branch June 5, 2022 09:52
@chrysn chrysn added this to the Release 2022.07 milestone Aug 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: drivers Area: Device drivers Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants