โ† Back to Projects

WSL2 SocketCAN Custom Kernel

Status
๐Ÿ”ฅ Trending on r/embedded
Timeline
April 2024
Core Stack
Linux Kernel SocketCAN WSL2

The "No-Hardware" Constraint

When developing embedded Linux systems or automotive firmware on Windows, developers historically had two choices: run a heavy Type-1 Virtual Machine (like VirtualBox), or buy expensive external USB-to-CAN adapters to pass through to the OS. WSL2 is incredibly fast, but Microsoft's default WSL2 kernel ships with CAN networking stripped out.

I built this custom kernel to bypass those limitations. By recompiling the WSL2 kernel from source (6.6.x) with SocketCAN and virtual CAN (vCAN) modules enabled, I allowed native CAN interfaces to be spun up directly inside the Windows subsystem without any external hardware.

The EVO vHIL Connection

While this utility gained unexpected traction in the broader embedded community, it was specifically engineered to solve a critical bottleneck in the EVO vHIL project.

To validate EV powertrain logic without physical microcontrollers, I needed a way to bridge CAN frames from a simulated MCU (running in Renode) directly into an Android Automotive HAL daemon. A native vcan0 interface inside WSL2 provided the exact deterministic, zero-latency network bridge required to make the virtual Hardware-in-the-Loop system function.

Kernel Configuration

The implementation required pulling the exact Linux kernel version utilized by WSL2 (6.6.123.2-microsoft-standard), running menuconfig, and manually injecting the required networking modules before recompiling the bzImage.

  • CONFIG_CAN โ€” Enabled the base Controller Area Network networking stack.
  • CONFIG_CAN_RAW โ€” Enabled raw SocketCAN access, allowing standard Linux utilities like candump and cansend to interface with the bus.
  • CONFIG_CAN_VCAN โ€” Enabled the Virtual Local CAN Interface (vcan), allowing software-only CAN bridging within the kernel.

Engineering Log

Viral Adoption on r/embedded

Posted the compiled kernel and instructions to the r/embedded subreddit. The repository hit the #1 spot for the day, accumulating over 10,000 views in 48 hours, validating that the lack of native WSL2 SocketCAN was a widespread friction point for automotive and embedded engineers.

Kernel Compilation & Verification

Successfully compiled the custom bzImage. Verified that sudo ip link add dev vcan0 type vcan brings the interface up cleanly without the "FATAL: Module not found" error. Integrated into the EVO vHIL pipeline.

Verification