-
Notifications
You must be signed in to change notification settings - Fork 7.7k
devices: make device name field optional #49352
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
Conversation
cee3e2c
to
d4c3e34
Compare
314707e
to
b9aef90
Compare
751b784
to
9f10be7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest maybe splitting this PR as the device_name_get
cleanup could get merged now, and than we can hash out the testcase and details on CONFIG_DEVICE_STORE_NAME
Maybe start with |
you mean adding the API without the optional name field changes? |
yes. Since the 95% of this PR is the API and changes to use it. I think its reasonable to encapsulate the access to |
include/zephyr/device.h
Outdated
#ifdef CONFIG_DEVICE_STORE_NAME | ||
return dev->name; | ||
#else | ||
return ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might make sense to allocate a global string in rom with value "<device>"
or something like that, and return a pointer to it here. Otherwise log messages that print device names will be kind of busted with CONFIG_DEVICE_STORE_NAME=n in my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adjusted to return "<device>"
include/zephyr/device.h
Outdated
{ | ||
ARG_UNUSED(name); | ||
|
||
return NULL; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like a footgun implementation.
I believe we should not provide a device_get_binding implementation at all, at least by default, if CONFIG_DEVICE_STORE_NAME=n.
But I get why you would want this, so perhaps it should be configurable? Something like...
choice
prompt "device_get_binding() behavior"
depends on !DEVICE_STORE_NAME
config NO_DEVICE_GET_BINDING
bool "No implementation"
help
No device_get_binding() implementation will be provided.
Use of this function will cause build errors.
config NULL_DEVICE_GET_BINDING
bool "NULL implementation"
help
A stub device_get_binding() implementation will be provided
that returns NULL.
endchoice
with NO_DEVICE_GET_BINDING being the default behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed this yesterday in dev-review, agreement was to disable device_get_binding completely, so you'll get a build failure if you can't really use this option.
@@ -951,6 +951,14 @@ config HAS_DYNAMIC_DEVICE_HANDLES | |||
Hidden option that makes possible to manipulate device handles at | |||
runtime. | |||
|
|||
config DEVICE_STORE_NAME |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems my above concern is already discussed here; I agree with @galak on this one, at least for the default.
9f10be7
to
de2cc84
Compare
disabled the option in this sample |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm all for the dev-review solution. One suggested doc improvement, but this looks good for v3.3 to me.
de2cc84
to
ac83ac3
Compare
Rename the function to avoid clashed with the upcoming device_name_get. Signed-off-by: Gerard Marull-Paretas <[email protected]>
sd_gpio was checked for NULL using its name, so the condition was always true. Check if the port (device) itself is NULL instead. Signed-off-by: Gerard Marull-Paretas <[email protected]>
ac83ac3
to
1fecfd6
Compare
With the adoption of DEVICE_DT_GET() device names are in many cases optional and used only for stuff like debugging or in shells. This patch makes struct device name field optional so that ROM can be saved in case user can afford it. This means that the name field in struct device should no longer be accessed directly but using a new function: device_name_get(). Note that the option controlling such feature is CONFIG_DEVICE_STORE_NAME, enabled by default. Signed-off-by: Gerard Marull-Paretas <[email protected]>
Since struct device name field is now optional, use device_name_get. Signed-off-by: Gerard Marull-Paretas <[email protected]>
CONFIG_DEVICE_STORE_NAME has the potential to reduce ROM usage in case application images do not make use of device_get_binding(), so mention it in the footprint documentation. Signed-off-by: Gerard Marull-Paretas <[email protected]>
Minimal sample is meant to show the minimum Zephyr ROM footprint. Disable CONFIG_DEVICE_STORE_NAME since the option targets ROM footprint reduction as well. Signed-off-by: Gerard Marull-Paretas <[email protected]>
1fecfd6
to
f5a2033
Compare
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
With the adoption of DEVICE_DT_GET() device names are in many cases
optional and used only for stuff like debugging or in shells. This patch
makes struct device name field optional so that ROM can be saved in case
user can afford it. This means that the name field in struct device
should no longer be accessed directly but using a new function:
device_name_get().
Note that the option controlling such feature is
CONFIG_DEVICE_STORE_NAME, enabled by default.
Some quick numbers using
hello_world
:nrf52840dk_nrf52840
:nucleo_h743zi
:Signed-off-by: Gerard Marull-Paretas [email protected]