How to enable CAN on startup

I want to setup CAN interface so that it is available after boot.

I have a CAN hardware based on MCP2518FD attached to my Jetson Nano Developer Board, Jetpack 4.4.1. Everything works fine when I configure and activate the interface manually using the SocketCAN interface through ip link.
Interface name is can0

However, I want the CAN interface to start automatically after reboot without need for super user rights.

I tried to solve this with systemd-networkd:

  • added can and can_raw modules to a file /etc/modules-load.d/can.conf so that they are loaded during boot.

  • systemd-networkd service is started and enabled (“active (running)”)

  • created file /etc/systemd/network/



After reboot:

  • journalctl shows an error from systemd-networkd:
    Sep 17 14:17:48 jet9 systemd-networkd[2975]: /etc/systemd/network/ Unknown section ‘CAN’. Ignoring.
    Sep 17 14:17:48 jet9 systemd-networkd[2975]: Enumeration completed

  • “ip -d -s link show can0” shows, that the baud rate is not set and that the interface is still DOWN.

What could be wrong?

systemd is version 237-3ubuntu10.42. Does this version support CAN at all?

Sorry for the late response, we will investigate to do the update soon.

you can try adding your bash commands which you run manually into ~/.bashrc. bashrc gets loaded after boot.

That works.

Additionally, I had to set the user to default-login, no password, no-password sudo, to prevent entry of password while the script is executing.

That does exactly what I want: Jetson starts up with CAN running, no need to enter any password.

Thank you shgarg!