Preface: this walkthrough is hand-holdy step by step tutorial to enable SocketCan on your WSL2 instance (Ubuntu 20.04).
Requirements:
- WSL2
- back up your wsl image (optional) follow here https://www.virtualizationhowto.com/2021/01/wsl2-backup-and-restore-images-using-import-and-export/ Steps:
From cmd / powershell
wsl --shutdown wsl --update
From wsl
sudo apt update sudo apt install can-utils
If you try now to use candump for example you'd get this error message: socket: Address family not supported by protocol
This just means that WSL2 doesn't come with CAN support, so we need to build the wsl kernel and enable can support.
sudo apt install build-essential flex bison libssl-dev libelf-dev
cd ~ git clone https://github.com/microsoft/WSL2-Linux-Kernel cd WSL2-Linux-Kernel git checkout 'uname -r' cat /proc/config.gz | gunzip > .config make prepare modules_prepare
make menuconfig
Enter Networking support Change CAN bus subsystem support to M and enter Change Raw CAN Protocol to M Enter CAN Device Drivers Change Virtual Local CAN Interface to M Make sure CAN bit-timing calculation is set to * Optionally change CAN devices debugging messages to * Save and exit
make modules sudo make modules_install
sudo modprobe can sudo modprobe can-raw sudo modprobe vcan
Congratulations you've enabled CAN support in your wsl.
WINUSER='cmd.exe /c echo %username%'
Sources: https://www.reddit.com/r/CarHacking/comments/ot3gjf/socketcancanutils_on_windows/ microsoft/WSL#5533 https://chowdera.com/2022/01/202201082236197554.html
Step 8:
Build the kernel (this can take a while):
make_modules
should be
make modules