Fixed can bus naming

Hi,

I am using a second can interface which is which is added with an additional mcp2517fd on the base board and connected with the ecspi2 interface.
Both can interfaces work but the “external” interface with the mcp2517fd on the base board acquires the device name can0 and the interface on the SOM gets the device name can1.

Since the second can interface should be optional and the parts are not always placed, it would be great if this interface could always has the name can1.

The current device tree configuration is as follows:

/* Verdin SPI_1 */
&ecspi2 {
        status = "okay";

        can3: can@3 {
                compatible = "microchip,mcp2517fd";
                clocks = <&clk20m>;
                gpio-controller;
                interrupt-parent = <&gpio3>;
                interrupts = <15 IRQ_TYPE_EDGE_FALLING>;
                microchip,clock-allways-on;
                microchip,clock-out-div = <1>;
                pinctrl-names = "default";
                pinctrl-0 = <&pinctrl_can3_int>;
                reg = <0>;
                spi-max-frequency = <2000000>;
                status = "okay";
        };
};

Current naming:
can3: can@3 → /dev/can0 (optional interface)
can1: can@0 → /dev/can1

Is it possible to set the name with an alias?

I have found a solution using udev rules.
This post helped me finding a point to start:

I used the following rules to change the naming

SUBSYSTEM=="net", KERNEL=="can1", ACTION=="add", NAME="my-can0"
SUBSYSTEM=="net", KERNEL=="can0", KERNELS=="spi1.0", ACTION=="add", NAME="my-can1"

That was quick, @gandi! Glad to see that you managed to fix it.

And thank you for sharing the solution, I appreciate that.