If you already have an active install of WSL running Ubuntu on your Windows 10 or 11 machine, then you may skip this step.
- In Windows, open Command Prompt in administrator mode.
- Run
wsl.exe --installcommand. - Restart the machine.
This will result in the ability to run WSL and will install Ubuntu as the Linux distribution. The WSL version will be set to WSL 2 by default. Please note that the distribution installed and WSL version may change in the future.
- Setup your username and password for the Ubuntu installation in WSL.
- In your Ubuntu install, run
apt-get update && apt-get dist-upgradeto update the system.
- In the Ubuntu WSL instance, clone the WSL2-Linux-Kernel repository via
git clone https://github.com/microsoft/WSL2-Linux-Kernel. - Navigate to the WSL2-Linux-Kernel directory.
- Checkout the branch tagged with your kernel version.
You can find out your kernel version by running uname -r. For me, my kernel version was 5.15.153.1 so I checked out linux-msft-wsl-5.15.153.1 via git checkout.
- While still in the WSL2-Linux-Kernel directory, retrieve the kernel configuration information and decompress it to a file named .config by running
cat /proc/config.gz | gunzip > .config. - Verify .config is there by running
cat .config. - Install the necessary tools for kernel build prep.
- Install Make via
apt install make. - Install GNU Compiler Collection (GCC) via
apt install build-essential. - Install Flex via
apt install flex. - Install Bison via
apt install bison. - Install Basic Calculator via
apt install bc. - Install SSL library via
apt install libssl-dev. - Install ELF development libraries and header files via
apt install libelf-dev.
- Install Make via
- Check for any new configuration options in the Linux kernel codebase that are currently not specified in the .config file and default them via
make olddefconfig. - Instruct the build system to prepare the kernel source tree for building the kernel itself and to prepare it for building external modules by running
make prepare modules_prepare.
We are now ready to configure our kernel build.
- Install ncurses via
apt install libncurses-dev. - Open the menu configuration interface via
make menuconfig. - In the menu configuration interface, go to Networking Support and press Enter.
- Under Networking Support, go to CAN bus subsystem support and press M.
- Go into the CAN bus subsystem support submenu by pressing Enter.
- Select all options in the CAN bus subsystem support submenu.
In my case, I had to select both SAE J1939 and ISO 15765-2 by selecting and pressing M on both of them.
- Go into the CAN Device Drivers submenu by pressing Enter.
- Go to Virtual Local CAN Interface and press M.
- Save these changes by overwriting .config and then exit the configuration menu.
We are now ready to build our customized kernel.
-
Install DWARF utilities via
apt install dwarves. -
Build the compiled binaries by running
make modules. -
Install the compiled binaries by running
make modules_install. -
Copy the custom kernel to an accessible location via
cp vmlinux /mnt/c/Users/<UserName>/. Where<UserName>is your Windows User. -
Provide the custom kernel path to WSL 2 by creating a .wslconfig file.
cat >> /mnt/c/Users/<UserName>/.wslconfig << "ENDL" [wsl2] kernel=C:\\Users\\<UserName>\\vmlinux ENDLAgain,
<UserName>is your Windows User. -
Exit out of WSL via
exitin the Ubuntu WSL terminal. -
Restart WSL via
wsl --shutdownusing the Windows Command Prompt. -
Start up WSL by typing
wslin the Windows Command Prompt. -
Verify you are running the new kernel by running
uname -rin your Ubuntu WSL terminal.
In my case, the output showed 5.15.153.1-microsoft-standard-WSL+. Note the plus (+) sign now.
- Load vcan via
modprobe vcanto verify that the new CAN modules are now installed.
- Clone the SocketCAN# repository via
git clone https://github.com/derek-will/SocketCANSharp.git. - Install dotnet via
apt install dotnet-sdk-8.0. - Navigate to the SocketCANSharp directory.
- Run the test environment setup script included in the SocketCAN# repo via
./test/SocketCANSharpTest/test_env_setup.sh. - Navigate to the examples/ObjectOrientedDiagAppSimulator directory.
- Run the ObjectOrientedDiagAppSimulator app via
dotnet runand view the output which should look something like this:
Tester :: Sent Request for ECU Serial Number (DID 0xF18C)
ECU :: Received Request
ECU :: Received ReadDataByIdentifier Request
ECU :: DID Requested 0xF18C
ECU :: Sent Response for DID 0xF18C
Tester :: Received Response
Tester :: Received ReadDataByIdentifier Positive Response
Tester :: DID Received 0xF18C
Tester :: Received ECU Serial Number (0xF18C): ESN-123456
Congratulations! You are now running SocketCAN# on Windows Subsystem for Linux (WSL).