CAN bus init script

Hello.
Have custom IMX6ULL based device with two CAN MCP2551 driven interfaces.
It works well:

root@OpenWrt:/# dmesg | grep can
[    0.240380] i2c i2c-1: can't use DMA, using PIO instead.
[    9.197828] jffs2_scan_eraseblock(): End of filesystem marker found at 0x10000
[   56.468563] can: controller area network core (rev 20170425 abi 9)
[   56.476122] can: broadcast manager protocol (rev 20170425 t)
[   56.486172] can: raw protocol (rev 20170425)
[   56.491659] flexcan 2090000.flexcan: 2090000.flexcan supply xceiver not found, using dummy regulator
[   56.496660] flexcan 2090000.flexcan: device registered (reg_base=90b3c000, irq=22)
[   56.600712] flexcan 2094000.flexcan: 2094000.flexcan supply xceiver not found, using dummy regulator
[   56.604591] flexcan 2094000.flexcan: device registered (reg_base=90b44000, irq=23)
[   56.791607] vcan: Virtual CAN interface driver

But I have to execute following commands manually to enable CAN interfaces:

# ip link set can0 down
# ip link set can0 up type can bitrate 500000
# ip link set can1 down
# ip link set can1 up type can bitrate 500000
root@OpenWrt:/# dmesg | grep can
...
[ 1067.275430] IPv6: ADDRCONF(NETDEV_CHANGE): can0: link becomes ready
[ 1074.011520] IPv6: ADDRCONF(NETDEV_CHANGE): can1: link becomes ready

So I am wondering about proper way to handling same in boot scripts. Tried to add following in 02_network:

case "$board" in
flexcan_ethernet)
        ip link set can0 down
        ip link set can0 up type can bitrate 500000
        ip link set can1 down
        ip link set can1 up type can bitrate 500000
        ;;
esac

but it throws me errors:

[    0.685683] fec 2188000.ethernet (unnamed net_device) (uninitialized): Invalid MAC address: 00:00:00:00:00:00
Cannot find device "can0"
Cannot find device "can0"
Cannot find device "can1"
Cannot find device "can1"

probably because this script executes before getting can controllers initialized.
Same when I try to place it in separate etc/board.d/98_can_network script.

How to deal with CAN bus interfaces properly in OpenWrt? Thank you.

Since you need to wait until the devices have been created, maybe you could use a hotplug script?

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.