-
Notifications
You must be signed in to change notification settings - Fork 8.3k
drivers: can: implement native Linux SocketCAN driver #49894
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: can: implement native Linux SocketCAN driver #49894
Conversation
henrikbrixandersen
left a comment
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.
Please see my comment about reworking the binding to the host CAN interface name. You could submit the two first commits in separate PRs and get them approved quickly in order to cut down on the changes here.
b55bb0f to
1034571
Compare
|
The first commit will be removed once #49907 is merged. |
jukkar
left a comment
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.
Nice work! Couple of years ago I had some plans to implement this but got side tracked and plans changed.
Anyway, there is a helper script at zephyrproject-rtos/net-tools#26 that I created at that point. It tries to setup canbus things in linux side, similar ways as the net-setup.sh script is doing in networking. Not sure if that script contains anything useful but feel free to re-use it if needed.
1034571 to
01191c0
Compare
01191c0 to
57afb99
Compare
henrikbrixandersen
left a comment
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. One minor change proposal as discussed on Discord:
57afb99 to
04ac089
Compare
henrikbrixandersen
left a comment
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.
Thanks!
str4t0m
left a comment
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.
Thanks for this addition! I am not very familiar with the socket can api on Linux, but still have a few comments.
|
Thanks @str4t0m for your very thorough review. I think all your points are valid and I'll come up with a solution latest tomorrow. |
04ac089 to
5094774
Compare
5094774 to
f037e34
Compare
str4t0m
left a comment
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.
two more comments.
f037e34 to
5e181e5
Compare
This driver provides an interface to SocketCAN interfaces of the Linux system running a Zephyr application with the native_posix board. These interfaces may be virtual or actual CAN buses. Signed-off-by: Martin Jäger <martin@libre.solar>
5e181e5 to
7c42456
Compare
Background Information
This is a new attempt to add a CAN driver for the
native_posixboard to interface with a Linux host system using the SocketCAN API. The driver itself is callednative_linux, as it supports only Linux hosts and no other POSIX-based systems.A similar driver was introduced in #37124. However, the CAN implementation in Zephyr changed significantly since that PR, so the driver was pretty much rewritten from scratch. Comments by @gmarull and @alexanderwachter in previous PR are addressed.
Details about the Linux SocketCAN implementation can be found in the Linux kernel CAN documentation and API header file.
Testing
In order to test the driver, a virtual CAN interface has to be set up on the Linux host:
In addition to that, the following overlay (or update of
native_posix.dts) is required:Afterwards, the driver passes all CAN driver tests:
The driver does currently not pass the ISO-TP tests in
tests/subsys/canbus/isotp. The ISO-TP tests are known to be brittle (e.g. they also fail for STM32G4, see #47014) and there is most probably a timing issue in the ISO-TP implementation itself. Fixing that is not within the scope of this PR.