How to fix the interface name of CAN on Colibri iMX6ULL

Hello!

I use Colibri-iMX6ULL 512MB WB BT V1.1A and Colibri Evaluation Board V3.2B.
I can use three CAN interfaces (CAN converted from SPI and twe flexCAN), thanks to previous your support !

However, each CAN interfaces are named depending on boot order of them. I show some examples below.
How can I get fixed name of the CAN interfaces independent of boot order? I would aprreciate it if you tell me how to set up.

Best regard


[Example.1]
When started in order of flexCAN, mcp251x, flexCAN, the interface name are assigned to flexCAN(can0), mcp251x(can1), flexCAN(can2).

root@colibri-imx6ull:/# dmesg | grep can
[   17.000999] 2090000.can supply xceiver not found, using dummy regulator
[   17.076902] flexcan 2090000.can: device registered (reg_base=a0b38000, irq=23)
[   17.119991] mcp251x spi0.0 can1: MCP2515 successfully initialized.
[   17.188175] 2094000.can supply xceiver not found, using dummy regulator
[   17.313586] flexcan 2094000.can: device registered (reg_base=a0b54000, irq=24)

root@colibri-imx6ull:~# ip -details link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0 
    can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0 
	  bitrate 250000 sample-point 0.866 
	  tq 266 prop-seg 6 phase-seg1 6 phase-seg2 2 sjw 1
	  flexcan: tseg1 4..16 tseg2 2..8 sjw 1..4 brp 1..256 brp-inc 1
	  flexcan: dtseg1 1..39 dtseg2 1..8 dsjw 1..8 dbrp 1..1024 dbrp-inc 1
	  clock 30000000numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
root@colibri-imx6ull:/# ip -details link show can1
4: can1: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0 
    can state ERROR-ACTIVE restart-ms 0 
	  bitrate 250000 sample-point 0.875 
	  tq 250 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
	  mcp251x: tseg1 3..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
	  clock 8000000numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
root@colibri-imx6ull:/# ip -details link show can2
5: can2: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0 
    can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0 
	  bitrate 250000 sample-point 0.866 
	  tq 266 prop-seg 6 phase-seg1 6 phase-seg2 2 sjw 1
	  flexcan: tseg1 4..16 tseg2 2..8 sjw 1..4 brp 1..256 brp-inc 1
	  flexcan: dtseg1 1..39 dtseg2 1..8 dsjw 1..8 dbrp 1..1024 dbrp-inc 1
	  clock 30000000numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 

[Example.2]
When started in order of mcp251x, flexCAN, flexCAN, the interface name are assigned to mcp251x(can0), flexCAN(can1), flexCAN(can2).

root@colibri-imx6ull:~# dmesg | grep can
[   21.035330] 2090000.can supply xceiver not found, using dummy regulator
[   21.072846] mcp251x spi0.0 can0: MCP2515 successfully initialized.
[   21.111270] flexcan 2090000.can: device registered (reg_base=a0b30000, irq=23)
[   21.211619] 2094000.can supply xceiver not found, using dummy regulator
[   21.351402] flexcan 2094000.can: device registered (reg_base=a0b50000, irq=24)


root@colibri-imx6ull:~# ip -details link show can0
3: can0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0 
    can state ERROR-ACTIVE restart-ms 0 
	  bitrate 250000 sample-point 0.875 
	  tq 250 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
	  mcp251x: tseg1 3..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
	  clock 8000000numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
root@colibri-imx6ull:~# ip -details link show can1
4: can1: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0 
    can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0 
	  bitrate 250000 sample-point 0.866 
	  tq 266 prop-seg 6 phase-seg1 6 phase-seg2 2 sjw 1
	  flexcan: tseg1 4..16 tseg2 2..8 sjw 1..4 brp 1..256 brp-inc 1
	  flexcan: dtseg1 1..39 dtseg2 1..8 dsjw 1..8 dbrp 1..1024 dbrp-inc 1
	  clock 30000000numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 
root@colibri-imx6ull:~# ip -details link show can2
5: can2: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0 
    can state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0 
	  bitrate 250000 sample-point 0.866 
	  tq 266 prop-seg 6 phase-seg1 6 phase-seg2 2 sjw 1
	  flexcan: tseg1 4..16 tseg2 2..8 sjw 1..4 brp 1..256 brp-inc 1
	  flexcan: dtseg1 1..39 dtseg2 1..8 dsjw 1..8 dbrp 1..1024 dbrp-inc 1
	  clock 30000000numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535

Hi @TK1890

Depending on your needs, you have two solutions:

  1. Either you can get the Information about the CAN interfaces and do a symbolic link.
  2. You can create udev rules to set persistent name for the CAN interfaces.

Best regards,
Jaski

Hi @jaski.tx

Thank you for answer!
I can get fixed name of CAN interfaces by editing udev rules.

Thanks for always helping me out.
Best regards


Here are the steps I’ve taken for those who have the same problem.
It may be wrong, but I solved this problem with this procedure.

(1) I checked the current CAN interfaces name.

root@colibri-imx6ull:~# ip link
...
3: can0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
    link/can 
4: can1: <NOARP,ECHO> mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
    link/can 
5: can2: <NOARP,ECHO> mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
    link/can
... 

(2) I got the udev information of each CAN interface. (now flexcan1:can0, mcp251x:can1, flexcan2:can2)

root@colibri-imx6ull:~# udevadm info -a -p $(udevadm info -q path -p /sys/class/net/can0)
...
  looking at device '/devices/soc0/soc/2000000.aips-bus/2090000.can/net/can0':
    KERNEL=="can0"
    SUBSYSTEM=="net"
    DRIVER==""
    ATTR{addr_assign_type}=="0"
    ATTR{addr_len}=="0"
    ATTR{address}==""
    ATTR{broadcast}==""
    ATTR{carrier_changes}=="0"
    ATTR{dev_id}=="0x0"
    ATTR{dev_port}=="0"
    ATTR{flags}=="0x40080"
    ATTR{gro_flush_timeout}=="0"
    ATTR{ifalias}==""
    ATTR{ifindex}=="3"
    ATTR{iflink}=="3"
    ATTR{link_mode}=="0"
    ATTR{mtu}=="16"
    ATTR{netdev_group}=="0"
    ATTR{operstate}=="down"
    ATTR{proto_down}=="0"
    ATTR{tx_queue_len}=="10"
    ATTR{type}=="280"

  looking at parent device '/devices/soc0/soc/2000000.aips-bus/2090000.can':
    KERNELS=="2090000.can"
    SUBSYSTEMS=="platform"
    DRIVERS=="flexcan"
    ATTRS{driver_override}=="(null)"

...
root@colibri-imx6ull:~# udevadm info -a -p $(udevadm info -q path -p /sys/class/net/can1)
...
root@colibri-imx6ull:~# udevadm info -a -p $(udevadm info -q path -p /sys/class/net/can2)
...

(3) I added and edited a .rules file at /etc/udev/rules.d. (I set mcp251x:CAN0, flexcan1:CAN1, flexcan2:CAN2)

root@colibri-imx6ull:~# cd /etc/udev/rules.d
root@colibri-imx6ull:/etc/udev/rules.d# vi 11-can-mylocal.rules
#11-can-mylocal.rules
KERNELS=="spi0.0", SUBSYSTEMS=="spi", DRIVERS=="mcp251x", ACTION=="add", NAME="CAN0"
KERNELS=="2090000.can", ACTION=="add", NAME="CAN1"
KERNELS=="2094000.can", ACTION=="add", NAME="CAN2"

(4) I reloaded the udev rules and rebooted the target.

root@colibri-imx6ull:/etc/udev/rules.d# udevadm control --reload-rules
root@colibri-imx6ull:~# reboot

(5) I confirmed that the name has been changed and fixed.

root@colibri-imx6ull:~# ip link
...
3: CAN1: <NOARP,ECHO> mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
    link/can 
4: CAN0: <NOARP,ECHO> mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
    link/can 
5: CAN2: <NOARP,ECHO> mtu 16 qdisc noop state DOWN mode DEFAULT group default qlen 10
    link/can
...
root@colibri-imx6ull:~# ip -details link show CAN0
4: CAN0: <NOARP,UP,LOWER_UP,ECHO> mtu 16 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 10
    link/can  promiscuity 0 
    can state ERROR-ACTIVE restart-ms 0 
	  bitrate 250000 sample-point 0.875 
	  tq 250 prop-seg 6 phase-seg1 7 phase-seg2 2 sjw 1
	  mcp251x: tseg1 3..16 tseg2 2..8 sjw 1..4 brp 1..64 brp-inc 1
	  clock 8000000numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535

Perfect that you found a solution. You can add these rules also to recipe as it is done here.

Thanks for the feedback.
Best regards,
Jaski