-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Description
Introduction
Introducing API change that allows to define "virtual" flash devices over real flash devices.
Currently some of flash API calls, like the flash_api_pages_layout
, often propagate pointers to structures directly defined at driver level; this makes it hard to setup "virtual" device that could lie about the information returned by such API call as it may require run-time allocation of resources as the "real-device" can never be assumed, which is not possible.
Aim of this RFC is to discuss changes to API that would prevent direct access to layout and this way make it easier to generate "virtual" devices.
Such virtual devices would allow defining devices that could serve as replacement for flash map API or direct encryption devices, with no need to special API layer for them, as basically any function or utility could use flash API directly, without knowing whether it is real device or "virtual".
Problem description
The flash_api_pages_layout
, when enabled with CONFIG_FLASH_PAGE_LAYOUT
, gives direct access to array that defines layout of flash, the user code can iterate over for gathering information; additionally there are flash_get_page_info_by_offs
, and flash_get_page_info_by_idx
that utilize this access.
With such direct access virtual device is not able to provide own definition of layout.
Proposed change
Proposed change is to replace the optional flash_api_pages_layout
, with set of following API calls:
flash_get_page_info
, flash_get_page_count
, flash_get_size
that would allow to quick obtain the same information but does not give direct access to information from driver.
The missing functionality of flash_get_page_info_by_offs
and flash_get_page_info_by_idx
can be easily added with use of the above function, even in form of utility library for flash access
Proposed change (Detailed)
Proposed addition to flash API calls:
int flash_get_page_info(const struct device *dev, off_t offset, struct flash_page_info *fpi);
ssize_t flash_get_page_count(const struct device *dev);
ssize_t flash_get_size(const struct device *dev);
note that the last two calls would be very quick as they will be given literal value during compilation.
Additional additions to struct flash_parameters
would be max_page_size
, which is maximum page size on the device (or any in case of uniform devices), and flags
which will hold flags; currently there will be only one flag defined FDF_NON_UNIFORM_LAYOUT
that means that the device has pages of different size.
With such definitions, in contrary to flash_api_pages_layout
, any "virtual" driver that would be able to query the information from underlying driver, process it if needed, and return to caller.
Dependencies
Anything that uses flash_api_pages_layout
will not be able to use "virtual" devices.
All flash drivers will require some patching.
Concerns and Unresolved Questions
Initialization order impact, power management (regarding the "virtual devices", device readiness).
Alternatives
There is no such attempt to flatten the API layers, where flash access is considered.
Related PRs
Proposed flash API change: #36484
Demo of flash partition device (formerly flash area device) that is possible due to change: #36487
Metadata
Metadata
Assignees
Labels
Type
Projects
Status