-
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: hwinfo: fix endianness for sam0 and nrf #24203
drivers: hwinfo: fix endianness for sam0 and nrf #24203
Conversation
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.
Nordic code behaves as I expect, converting the 64-bit little-endian integer to a big-endian octet sequence.
Atmel code looks right by inspection given SAM D21 Family Data Sheet section 10.3.3:
Each device has a unique 128-bit serial number which is a concatenation of four 32-bit words contained at the following addresses.... The uniqueness of the serial number is guaranteed only when using all 128 bits.
This change has a huge impact for existing devices. They will change their ID after updating the Zephyr version! Please announce this change in the Mailing list first and maybe ask @carlescufi for a slot to discuss it in the API meeting. |
@sslupsky here's what I suggest we do with this change:
|
DNM for now |
@carlescufi This PR corrects a bug in the existing implementation for the sam0 and nordic drivers. The change does have an impact on other zephyr components as @pabigot pointed our regarding the Bluetooth workaround for this bug. That workaround will have to be addressed. I can include this in the "API Changes" but is it correct to call this an "API change"? There may be other drivers affected but some are ok. For instance, I took a quick look at the sam driver yesterday and that one appears to be ok. |
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.
Since this was apparently not clear originally (so things like USB were making assumptions about how to interpret it):
The documentation for this API should be updated to make clear that the returned value is not supposed to be interpreted based on vendor-specific assumptions of byte order. It should express the identifier as a raw byte sequence, doing any endian conversion necessary so that a hex representation of the bytes produces the intended serial number.
Does sound ok for the API Changes:
|
That looks like release notes. The |
I added the text to hwinfo.h as well. |
I will skinny the release notes to:
|
IMO it is still not a bug since the device doesn't apply any structure on the ID. But I agree that tools in production may interpret the values differently. So changing the byte-order is ok for me.
The changes have an impact on users that use the hwinfo API to identify their devices!
As mentioned before, this is a public API that is used by other users too. AFAIK foundries.io uses it to identify devices. |
Right, but the API was not stable until after the 2.2 release, so I see not problem in switching the endianness at this point. We have not pushed a release with the hwinfo API being stable, so I still support this change. |
@sslupsky |
73c87b5
to
e54ba1c
Compare
I pushed the recommended changes. |
doc/releases/release-notes-2.3.rst
Outdated
@@ -21,6 +21,11 @@ No security vulnerabilities received. | |||
API Changes | |||
*********** | |||
|
|||
* HWINFO | |||
|
|||
* HWINFO drivers are responsible for ensuring that the ID data structure is a |
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.
@sslupsky could you add a bit more info here? About the actual change in API behavior, so users know what to expect. Please also list which platforms in particular changed.
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.
Ok. Clarified the behaviour and referenced the platforms changed.
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.
Looks good. As a follow-up we need to review all existing implementations to ensure that what they produce conforms to the "don't rearrange this" policy.
Which mailing list? users? |
Yes, users@ and devel@ would be good actually. Thanks! |
HWINFO drivers should be responsible for ensuring that the data structure is a sequence of bytes. That is not what the current sam0 and nordic drivers do. The drivers read the data as u32_t and then memcpy the data to a buffer. This ensures the data has the endianness of the underlying MCU, which in this case is Cortex M0 which is little endian. This commit fixes the endianness so the data can be interpreted as a "left to right sequence of bytes". This commit updates the API doc to provide clarification of the data structure. Add to 2.3 release notes. Fixes zephyrproject-rtos#23444, zephyrproject-rtos#24103 Signed-off-by: Steven Slupsky <[email protected]>
e54ba1c
to
19cd3ef
Compare
@carlescufi Sent email to users@ and devel@ |
To complete this task:
This covers all currently implemented targets. |
Thanks for updating all drivers @pabigot |
HWINFO drivers should be responsible for ensuring that
the data structure is a sequence of bytes. That is not
what the current sam0 and nordic drivers do. The drivers
read the data as u32_t and then memcpy the data to a
buffer. This ensures the data has the endianness of the
underlying MCU, which in this case is Cortex M0 which
is little endian.
This commit fixes the endianness so the data can be
interpreted as a "left to right sequence of bytes".
Fixes #23444
Fixes #24103