Introduction

This manual is used to flash a Roborock S50 (also known as Roborock S5 or Roborock S55 or Xaomi Roborock) with the custom firmware Valetudo. At no time should the Roborock be brought into a WiFi before flashing. Also the Xaomi Mi app should never be used. Everything should remain offline.
At the end I will bring the Roborock into my WiFi after flashing. In my case this is a separate WiFi for Smart Home devices, which only allows traffic that is explicitly enabled by the firewall. Of course the vacuum cleaner robot will not be allowed to connect to the internet.

Preparation

We need a PC with Linux, which also needs a WLAN network adapter. I used an old laptop. I tried it before with a VM and pass-through a WiFi USB stick, but unfortunately it didn’t work. This problem is a known problem.
Since we later have to access Roborock via a browser, I decided to install Ubuntu Desktop. This works as follows:
First I downloaded Ubuntu Desktop: https://www.ubuntu.com/download/desktop
Then we need “Rufus” and a USB stick with at least 2 GB storage space for the installation. Alternatively the image can be burned onto a DVD. I’m going to use the USB stick in this case. Rufus can be downloaded here: https://rufus.ie/de_DE.html (The portable version is sufficient)
Once everything’s downloaded, we’ll launch Rufus. Here we first select the USB stick (1), then the downloaded ISO file with Ubuntu (2) and click “Start”.

When asked for the write mode, select “ISO Image mode”.

After a few minutes the writing to the USB stick is finished and we can install it on the laptop. Simply insert the USB stick into the laptop. Depending on the model, either a key must be pressed directly after switching on to open the boot menu (e.g. F12, F2 or Esc) or the boot sequence must be changed in the BIOS so that the USB stick can be booted. Since this varies depending on the BIOS, I cannot give any general instructions here. If you have done everything correctly and start from the USB stick, the setup of Ubuntu starts. This is largely self-explanatory, so I will not go into details here. In my case, I used a laptop that already had Windows 7 installed and chose a parallel installation to Windows 7.
When the installation is finished, the system reboots and Ubuntu Desktop appears.
Now set up a WiFi connection for an Internet connection. Click on the arrow in the upper right corner, click on the WiFi entry and select the WiFi to connect to and enter the WiFi key.
Now click on the nine dots at the bottom left and, on the second page, start the “Terminal” program in the “Utilities” folder. A command line appears.
To update Ubuntu, first enter the following commands:

sudo apt-get update
sudo apt-get upgrade

The preparation is done.

Install Valetudo

First we need some packages to use the installation later:

sudo apt-get install -y openssh-server ccrypt git dos2unix python3-pip python3-venv

For accessing the Roborock console via SSH we need to create a SSH key:

ssh-keygen -t ed25519 -C "me@home.local"

After that we create a directory roborock

mkdir ~\rockrobo
cd ~\rockrobo

now we clone the repository of the dustcloud:

git clone https://github.com/dgiese/dustcloud.git

Creating the Valetudo directory

mkdir valetudo
pushd valetudo

Download the latest Valetudo files. Go to https://github.com/Hypfer/Valetudo/releases and copy the path for the latest version of Valetudo.

Download this package, create more directories and save some configuration files:

wget https://github.com/Hypfer/Valetudo/releases/download/<the version you can see on the website>/valetudo
mkdir deployment
pushd deployment
wget https://github.com/Hypfer/Valetudo/raw/master/deployment/valetudo.conf
mkdir etc
pushd etc
wget https://github.com/Hypfer/Valetudo/raw/master/deployment/etc/hosts
wget https://github.com/Hypfer/Valetudo/raw/master/deployment/etc/rc.local
pop
pop
pop
mkdir firmware
pushd firmware

Now find the URL to the latest firmware (highest number and date) of https://dustbuilder.xvm.mit.edu/pkg/s5/. (e.g. https://dustbuilder.xvm.mit.edu/pkg/s5/v11_001820.fullos.pkg). Download the file:

wget https://dustbuilder.xvm.mit.edu/pkg/s5/<latest file>.fullos.pkg

Change to the rockrobo directory and create the firmware file:

popd
mkdir image
pushd image
sudo ../dustcloud/devices/xiaomi.vacuum/firmwarebuilder/imagebuilder.sh --firmware=../firmware/<firmwarefile>.fullos.pkg --public-key=$HOME/.ssh/id_ed25519.pub --valetudo-path=../valetudo --disable-firmware-updates --ntpserver=192.168.x.1 --replace-adbd

For this last command, the firmware file must be specified in the valetudo/firmware directory. Furthermore, the NTP server of the network should be specified in the NTP server parameter. This is usually the router in home networks.
When the file is created, we create a “flasher” folder and the miio Python packets:

popd
mkdir flasher
pushd flasher
python3 -m venv venv venv
source venv/bin/activate
pip3 install wheel
pip3 install python-miio
pop

Now we have to connect the laptop to the WiFi of the Roborock. Press the “Reset” button under the flap of the Roborock. After a few seconds the LED next to the button will start flashing blue. Now you will find an insecure WiFi that is named roborock-vacuum-s5_…. You have to connect to it.
Now we have to disable the firewall. Otherwise Roborock will not be able to download the image. If the Ubuntu installation is also used for other things, don’t forget to turn on the firewall with “sudo ufw enable” at the end.

sudo ufw disable

Furthermore, the Roborock should stand in the dock and be charged. If this is not the case, you are told that the battery level must be at least 20% to perform the update – even if the battery level is over 90%.
Now establish a connection with the Roborock to get the token to the connection:

mirobo --debug discover --handshake true

The last line of the output contains a token that can be used in the following command:

mirobo --ip 192.168.8.1 --token <token> update-firmware image/output/<created firmware file>.fullos.pkg

Now the Roborock is flashed with the custom firmware. This will take a few minutes. The Roborock will let you know when it is ready.

Connect Roborock to WiFi

In order to connect the Roborock to the WiFi, the Roborock must be called from a browser via http://192.168.8.1 .
The WiFi connection can now be set up here in the setting dialog. Valetudo only supports WPA2-PSK – this is standard for normal home routers.
As soon as the Roborock is connected to the WiFi, it can be accessed via its IP in the browser. e.g. this is then http://192.168.1.185.

Update Valetudo

From time to time there is an update of Valetudo. In my case the virtual walls have been added. Therefore my Roborock needs an update.
Basically we have to do the same things as during the installation. Only the token is something we already have. This can be found on the Valetudo page under Settings => Token. Therefore the first step of an update is similar to the step “now we clone the repository of the dustcloud”. First we update the dustcloud repository:

cd ~/rockrobo/dustcloud
git pull

Now download the updated package from the GitHub page (see above):

cd ../valetudo
wget https://github.com/Hypfer/Valetudo/releases/download/<new version>/valetudo

now create the new firmware (based on the existing firmware). Otherwise download the firmware as described above):

pushd image 
sudo ../dustcloud/devices/xiaomi.vacuum/firmwarebuilder/imagebuilder.sh --firmware=../firmware/<firmwarefile>.fullos.pkg --public-key=$HOME/.ssh/id_ed25519.pub --valetudo-path=../valetudo --disable-firmware-updates --ntpserver=192.168.x.1 --replace-adbd
pop
pushd flasher
source venv/bin/activate
pop

Now we have to connect the laptop to the WiFi of the Roborock. Press the “Reset” button under the flap of the Roborock. After a few seconds the LED next to the button will start flashing blue. Now you will find an insecure WiFi that is named roborock-vacuum-s5_…. You have to connect to it.
Now we have to disable the firewall. Otherwise Roborock will not be able to download the image. If the Ubuntu installation is also used for other things, don’t forget to turn on the firewall with “sudo ufw enable” at the end.

sudo ufw disable

Furthermore, the Roborock should stand in the dock and be charged. If this is not the case, you are told that the battery level must be at least 20% to perform the update – even if the battery level is over 90%.
Now connect to the Roborock to get the token to connect OR read the token from the settings page in Valetudo:

mirobo --debug discover --handshake true

When executing the command, the last line of the output contains a token that can be inserted into the following command:

mirobo --ip 192.168.8.1 --token <token> update-firmware image/output/<created firmware file>.fullos.pkg

Now the Roborock is flashed with the custom firmware. This will take a few minutes. The Roborock will let you know when it is ready.

Roborock Control Center

A little gimmick on top:
At https://github.com/LazyT/rrcc/releases. you can download the Roborock Control Center. It can access the Roborock from a Windows PC and also read and control it.