-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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: Move API driver structs to an iterable section #71773
Conversation
The other half of the issue is that we also need the actual device, the API on its own is not of much use :) The proposal I made here #58112 uses elf parsing to tie the API to a device, and generates header files from it. It's a bit complex, requiring multi stage building to work, building drivers before subsystem/app. I still prefer the simplest (but a bit costly) generating additional arrays of dev + api in ROM like |
You could scan through the (existing) device iterable section and match all devices who's |
Yes, but that's a runtime scan, ew :D |
Should be quick though. |
That's why I think #67698 and this PR can solve different issues, and both can coexist. |
Wouldn't this method force the api to be included in ROM even if the device is not used? |
The APIs are only included if the drivers are included, so there should be no difference in ROM usage, only where in ROM the API structs are placed :) |
Update the device driver API documentation with the new DEVICE_API macro definitions and how to use them. Signed-off-by: Pieter De Gendt <[email protected]>
9b943d3
Update:
|
Dropping the RFC and DNM tags since this has been commented and it appears like there's consensus that it can go in. |
Also removed the arch meeting label as this prevents merging, and unassigned @gmarull |
Introduction
This PR demonstrates how iterable sections can be used to validate type safety of device API calls.
Problem description
Type safety using
void *
typically requires us to either perform additional build steps, or add overhead data.Proposed change
Putting each device API in their dedicated linker section allows us to check if calling an API using a
void *
is located within that section.Calling invalid device API functions with
CONFIG_ASSERT
enabled would cause an assertion panic, helping users during development to track issues with devices.Detailed RFC
The following macro definitions are added:
A python script
scripts/build/gen_iter_sections.py
is added (written by @bjarki-trackunit) to translate all__subsystem
struct definitions to linker sections.Requirements (for each API type)
Instances create the API struct using
DEVICE_API
(which forcesconst
), for example:The API calls evaluate the
void *
, for example:Dependencies
None that I can think of.
Concerns and Unresolved Questions
__ASSERT
vsCHECKIF
CONFIG_CMAKE_LINKER_GENERATOR
can't rely on thegen_iter_sections.py
script to generate sections for iterable structsapi
pointers are located in the correct section?Naming;type
vsclass
Is the_driver_api
a required suffix? And should we shorten/hide this part using the macros?Tasks
After approval to go forward, we can start moving other drivers too.