Is it possible to bring up can interface on TorizonCore without rebuild?

Hello,

I have TorizonCore 4.0.0 installed on my module and I tried to access the can interface:

colibri-imx7-06355141:~$ ip link set can0 up
ip: SIOCGIFFLAGS: No such device

I would like to know if it is possible to bring up can0 or (and) can1 without rebuilding Torizon?

From
https://developer.toradex.com/knowledge-base/can-linux#Kernel_Support_Colibri_iMX7
I would guess, no it isn’t.

But maybe there is a way, maybe using device tree overlays or something like that? If yes, could you please provide detailed information?

Greetings @cetoni_software_developer!

Yes, you can enable the CAN interface using Device Tree Overlays. Please check this article on our developer website.

As an example, your overlay should look something like this:

/dts-v1/;
/plugin/;
/ {
    compatible = "toradex,colibri-imx7";
    fragment@0 {
        target = <&can0>;
        __overlay__ {
            status = "okay";
        };
    };
};

Hello Gustavo,

when trying to create an overlay I have some problems working with the developer tools container.
In the developer tools container, I…

  • created the file imx7_can_overlay.dts and copied the content from above into it
  • moved imx7_can_overlay.dts to “device-tree-overlays/overlays”
  • built imx7_can_overlay.dts using dtconf build

With the following commands, I get the appropriate outputs:

root@5127056569f4:/# dtconf build imx7_can_overlay.dts
Device is colibri imx7(0032)
Mounting /mnt/part
mount: /mnt/part: special device /dev/disk/by-label/BOOT does not exist.
Failed to mount /dev/disk/by-label/BOOT /mnt/part
Successfully built device tree

root@5127056569f4:/# dtconf enable imx7_can_overlay.dts.dtbo 
Device is colibri imx7(0032)
Mounting /mnt/part
mount: /mnt/part: special device /dev/disk/by-label/BOOT does not exist.
Failed to mount /dev/disk/by-label/BOOT /mnt/part
Overlay imx7_can_overlay.dts.dtbo is already enabled
Overlay file imx7_can_overlay.dts.dtbo has been enabled

root@5127056569f4:/# dtconf status
Device is colibri imx7(0032)
Mounting /mnt/part
mount: /mnt/part: special device /dev/disk/by-label/BOOT does not exist.
Failed to mount /dev/disk/by-label/BOOT /mnt/part
Currently active overlays:
imx7_can_overlay.dts.dtbo
Available base device trees:
        imx7d-colibri-eval-v3.dtb
        imx7s-colibri-eval-v3.dtb
        imx7d-colibri-emmc-eval-v3.dtb
Available overlays for running kernel:

I think the commands suceed, but from the mount failures I guess the overlay cannot be provided to the Torizon system hosting the container.

After reboot the can interface is still not available. Could you please help?

@cetoni_software_developer,

Please try providing the full path to the dtconf command. You can simply create your .dts overlay and run:

dtconf activate my-overlay.dts

Also, can you please show me how you launched the dev tools container?

Dear Gustavo,

I start the container in the following way:

# docker run -it --rm --privileged -v /dev:/dev -v /boot:/boot torizon/arm32v7-debian-dev-tools

Then I create the overlay file and copy the contents from above into the file using nano:

root@ef896212f0e3:/# touch imx7_can_overlay.dts
root@ef896212f0e3:/# nano imx7_can_overlay.dts 
root@ef896212f0e3:/# cat imx7_can_overlay.dts 
/dts-v1/;
/plugin/;
/ {
	compatible = "toradex,colibri-imx7";
        fragment@0 {
             target = <&can0>;
             __overlay__ {
                 status = "okay";
             };
         };
};
root@ef896212f0e3:/# 

When I try to activate the overlay pointing directly to the file path, I get the following output.

root@ef896212f0e3:/# dtconf activate ./imx7_can_overlay.dts
Device is colibri imx7(0032)
Mounting /mnt/part
mount: /mnt/part: special device /dev/disk/by-label/BOOT does not exist.
Failed to mount /dev/disk/by-label/BOOT /mnt/part
Building ./imx7_can_overlay.dts
Invalid filename
root@ef896212f0e3:/# 

And when I move the overlay file to /device-tree-overlays/overlays/, the output is as follows.

root@ef896212f0e3:/# mv imx7_can_overlay.dts /device-tree-overlays/overlays/
root@ef896212f0e3:/# dtconf activate imx7_can_overlay.dts
Device is colibri imx7(0032)
Mounting /mnt/part
mount: /mnt/part: special device /dev/disk/by-label/BOOT does not exist.
Failed to mount /dev/disk/by-label/BOOT /mnt/part
Building imx7_can_overlay.dts
Successfully built device tree
Validating ./imx7_can_overlay.dts.dtbo
Error running fdtdump.
FDT_ERR_NOTFOUND: The requested node or property does not exist.
Failed to apply ./imx7_can_overlay.dts.dtbo (-1)

Invalid overlay
root@ef896212f0e3:/#

@cetoni_software_developer,

Can you please try deleting the existing dev tools container image and pulling it again? You can list the existing images with docker images and then remove the image with docker rmi <image id>.

Hi @cetoni_software_developer,

To add to Gustavo’s suggestion, I was also unable to reproduce the error you showed here. Try running dtconf status while in the dev tools container and see if some strange overlay was enabled. If so you can disable every overlay and have a fresh environment with dtconf disable --all.

Next you will need some small modifications to have a correct overlay for the i.MX7. This overlay worked on my setup:

/dts-v1/;
/plugin/;
/ {
    compatible = "toradex,colibri-imx7";
    fragment@0 {
        target = <&flexcan2>;
        __overlay__ {
            status = "okay";
        };
    };

    fragment@1 {
        target = <&iomuxc>;
        __overlay__ {
            pinctrl-0 = <&pinctrl_gpio1 &pinctrl_gpio2 &pinctrl_gpio3
                     &pinctrl_gpio7>;
        };
    };
};

So just to explain a bit, the first fragment is similar, but for the i.MX7 we use the “flexcan” naming rather than just can. The second fragment redefines some GPIOs. This is because by default since CAN is disabled we use the pins meant for the CAN interface as GPIOs. Therefore we need to remove these pins from the GPIO listing so that the flexcan interface can use these without error. If you want to use flexcan1 instead/also, then just remove &pinctrl_gpio7 from the 2nd fragment listing.

Best Regards,
Jeremias