Build Marlin 2.0 using the Windows subsystem for Linux (WSL)

In this guide, I'm talking about how to use the Windows Subsystem for Linux to compile Marlin Firmware 2.0.

Hello, my name is Daniel, welcome to the CrossLink channel. Our mission is to help 1 million people getting more successful with 3d printing and if you're here for the first time, subscribe and enable bell notifications so you don't miss anything.

So why a video about this topic?

Recently, I discovered a problem compiling Marlin 2.0 bugfix on Windows - and I had this problem with Platform IO and in the same way with the Arduino IDE.

Marlin 2.0 just wouldn't compile. And I was wondering - what the heck is going on? So I really digged into it and I also made this other video that explains why it doesn't compile - because of a Windows limitation. And I was also saying, I will be looking for workarounds.

So this is one of the workarounds I found - The Windows Subsystem for Linux.

It's basically Linux on Windows 10 and it's not a virtual machine, it's more like a container - if that means anything to you - it basically means that it's closer to the actual Windows system, it is a thinner layer between those systems and for example Linux can use files directly that are stored in the Windows filesystem.

And also this limitation that I ran into - the 32k command length limit - doesn't exist in the Linux subsystem - because yeah - it's Linux.

Another improvement coming with WSL 2, which is just rolling out with Windows 10 version 2004, might be - and this is something to prove - it could be possible to flash Marlin firmware directly from Linux in WSL 2. In the current version that everyone has by today - the Linux Subsystem doesn't have access to the USB ports. But more on that in a moment.

I just wanna make sure you're ready for this - if you never used Linux before - please do yourself a favour and watch some guides about how to use Ubuntu for example so you will know a little bit about the commands we're going to use in this guide. Otherwise, this might be much harder to grasp.

So how do we get Linux running on Windows?

The first step is super easy. You open up the Microsoft Store, which is the app store for Windows 10.

And there you start a search for Linux.

So now, you have to make a choice, which Linux Version you want. And to be honest, I usually use Ubuntu because I think, it's the easiest to use, but if you know another Linux distro better you might also use that.

So let's select Ubuntu and install it.

And that's going to take a while, but once it's done we can already try to launch it from here - but if you're doing this for the first time this just going to give you an error that the Windows Subsystem for Linux component is not enabled.

So we will close this window...

There two ways to enable the subsystem. The first one is actually explained in the description of the app in the app store. So you can run this command in an Administrator PowerShell prompt. If you know what that is, just go ahead and do that and reboot but we're using the clickpath.

So that works like this. Right click on the start Menu.

Select Apps and Features.

Then select Programs and Features - if you don't see that on the right hand side, just make this a little bit wider.

And in the new popup we select Turn Windows features on or off.

And in this list, I am checking the Windows Subsystem for Linux, so it's on.

I say ok, and then we have to restart.

So we're back and now we can start Ubuntu from the start menu - it's a new app.

So this is going to take a minute.

And then we create a username for this Linux system. So I'm just going to use daniel.

And of course create a secure password like "12345".

Ok, here we are at the Linux shell.

The first thing to do here to get the latest packages with "sudo apt update". Here we have to use the password we just created....

And after getting the latest package lists, we can run "sudo apt-get install python3-distutils -y" to make sure we have python3 and all the tools to install platformio. Btw, all the commands I am using, you can copy paste them from the comment section.

After thats done, we install platformio using this command, that I've taken from the official platformio webpage. I'ts downloading and runnning a python script that does all the magic.

Ok, so platformio is ready in Linux on my Windows computer, what now.

I have my Marlin sources on my C-Drive, here in this folder, how can I start a build from the Linux environment.

When you install platformio, the installer will show you the location of the platformio executeable. I would copy this over to a notepad to remember it for later.

So if you mark it, right click for copy, another right click for paste and hit enter, we see that platformio is there and working

let's switch to that source folder on the c drive now. In the Linux subsystem, the drives will be located in a folder named /mnt and below that there is the c-drive and the folder structure of our hard drive so lets switch to that

"cd /mnt/c/src/github/other/Marlin_Ender3_release_2.0.5.4_BLTouch/"

and in that folder we can run platformio with the run parameter and -e ? to show the available environments


And that list is all the environments available. You need to use the one that fits your board. And this will be the same one shown to you if you open up the Auto Build Marlin tab in Visual Studio Code.

In case of the Ender 3 with the Creality Mainboard this would be sanguino1284p or melzi_optiboot depending on the code version you are using.

So lets start the build using the right platform with the -e parameter

That's probably looking familiar, it's the same output you normally get from the platformio window in VS Code.

And - We have a successful build. This branch wouldn't build anymore directly from Windows but inside of the Linux world it works - great!

So where do we find our firmware, let's scroll up a little to see what the outputs were.

Here we go .pio/build/melzi_optiboot/firmware.hex is our file.

So let's hop over to the Windows Explorer and look for it.

And there it is.

Last thing left is to flash it to the mainboard. If you would be using an SKR mainboard for example, the only thing to do would be to copy the firmware to the sd-card and insert that into the mainboard and reset but in case of the creality mainboard and also the Anet mainboards, these don't have that level of comfort. We need to flash them the old style using either avrdude or a tool like XLoader for example.

And there you have it, how to build Marlin firmware inside the Windows Subsystem for Linux. As soon as WSL2 is available, I am going to look into it - if it supports flashing over USB so make sure you don't miss that.

If you're interested in more videos - I've linked two other ones here for you. Have a good week - Bye!

Liked it? Take a second to support Daniel Kreuzhofer on Patreon!
Scroll Up