Tutorial  Updated

How to boot Linux on your Switch

THIS GUIDE IS DEPRECATED
THIS IS BETTER https://github.com/natinusala/painless-linux


I've successfully booted ArchLinux using ShofEL2. Here is a quick guide on how to do it - I'll assume you're computer literate and know how to use a terminal / Linux commands / git.
Everything is taken from the README of the ShofEL2 repo so if you want to go even faster, go read that instead.

Thanks to NightHammer1000 and Y2K-x for the help !

There is a simplified and faster version of this tutorial available here, with precompiled binaries so you don't have to build everything : https://github.com/SoulCipher/shofel2_linux

The result

Without a SD card ("waiting for root device mmcblk0p2") : https://photos.app.goo.gl/7y6ut5ObuHMUIMZg2
Stock Arch Linux : https://photos.app.goo.gl/yALqe3zMZRe2dSQf1
Arch Linux with LXDE : https://photos.app.goo.gl/xaEgRqeSi8jvAwpz5
RetroArch running : https://photos.app.goo.gl/vBLPo5wiBto1qiUH3
Arch Linux with GNOME : https://gbatemp.net/attachments/img_0005-jpg.121608/
Arch Linux with KDE : https://gbatemp.net/attachments/img_20180427_121605-jpg.121666/

What works / what doesn't
  • Desktop environment : Gnome, LXDE, KDE
  • Wi-Fi : works
    • You will need to reboot your Switch and run the exploit again to make the Wi-Fi work (it never works on the first boot)
    • Then enter the Network Manager Application and add your network from there
    • If it doesn't work, you will need to edit the configuration on the host computer (see the additional notes at the end of this post)
    • With LXDE : Can cause a kernel panic if used at the same time as Bluetooth
  • Bluetooth : works but Joy-Cons can't be paired
  • Touch screen : works, although LXDE is not very touch-friendly
  • Audio : doesn't work yet
  • GPU acceleration : works (via mesa), with OpenGL (and maybe Vulkan too ?)
  • Joy-Cons : not recognized
  • Volume buttons : working with Gnome but not doing anything since there is no audio device
  • Power button : doesn't do anything, no sleep mode, no graceful shutdown
  • USB : doesn't work
  • Dock : not tested yet, but I bet it doesn't do anything besides charging the battery
  • Power management / battery level : working with Gnome
What you'll need
  • A computer running Linux with a blue USB SuperSpeed port, or a Mac
    • A Linux VM can work in theory, but it depends on how the USB passthrough is implemented (apparently VMWare works, VirtualBox doesn't)
  • A USB A-to-C cable (with data support, obviously)
    • be careful as cheap cables were reported to work randomly / not work at all
  • Some time (you know, Linux is kinda large)

Prep work

First, you'll need to install the required toolchains. Open this link and download the tar.gz binaries for
  • aarch64-linux-gnu
  • arm-linux-gnueabi
Be careful to choose the right architecture for your PC (for me it was x86_64 so "gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi.tar.xz").

Once you have them, extract them somewhere nice and add the "bin" (not "lib" as I previously stated) folder of both toolchains to your PATH ("$ export PATH=$PATH:/path/to/toolchain1/lib:/path/to/toolchain2/lib"). The building process won't work otherwise.

Then, install those dependencies (how to install them and their name might depend on your distribution) :
  • build-essential (sorry I didn't add it it was obvious to me)
  • libssl-dev
  • swig
  • bison
  • pkg-config
  • flex
  • zlib1g-dev
  • python3
  • python-dev
  • python3-pip
  • pyusb 1.0.0 : "$ sudo pip3 install pyusb==1.0.0"
  • libusb-1.0-0-dev

Compiling

Clone each required repository :

Code:
$ git clone https://github.com/fail0verflow/shofel2.git
$ git clone --recursive --depth=1 https://github.com/fail0verflow/switch-coreboot.git coreboot
$ git clone https://github.com/fail0verflow/switch-u-boot.git u-boot
$ git clone --depth=1 https://github.com/fail0verflow/switch-linux.git linux
$ git clone https://github.com/boundarydevices/imx_usb_loader.git

You can grab a coffee or two because Linux has more than 5 million files to download.

Then, build everything :

Code:
$ cd shofel2/exploit
$ make

Code:
$ cd u-boot
$ export CROSS_COMPILE=aarch64-linux-gnu-
$ make nintendo-switch_defconfig
$ make

Code:
$ cd coreboot
$ make nintendo_switch_defconfig
$ make iasl
$ make

If you have a tegra_mtc.bin file error, you'll have to extract it from a Pixel C stock image :
"$ ./build/util/cbfstool/cbfstool bootloader-dragon-google_smaug.7900.97.0.img extract -n fallback/tegra_mtc -f tegra_mtc.bin"

Or you can download it directly from here : https://0w0.st/tegra_mtc.bin (thanks to @CptPotato for uploading this)

You'll have to put it in the "coreboot/src/soc/nvidia/tegra210" directory.

Code:
$ cd imx_usb_loader
$ git reset --hard 0a322b01cacf03e3be727e3e4c3d46d69f2e343e
$ make

The big one :

Code:
$ cd linux
$ export ARCH=arm64
$ export CROSS_COMPILE=aarch64-linux-gnu-
$ make nintendo-switch_defconfig
$ make

If you encounter issues about a missing rule "/lib/firmware/nvidia/tegra210/vic04_ucode.bin" for the target "firmware" you'll have to :
  • install the firmware-misc-nonfree package
  • if you can't install it, or if it still doesn't work, download the package manually from debian sid and extract the file "/lib/firmware/nvidia/tegra210/vic04_ucode.bin" (from the root of your PC, not on the cloned repo) from the DEB (and chmod it if needed)
If you encounter issues about a missing rule "/lib/firmware/brcm/brcmfmac4356-pcie.txt", download this file and put it in "/lib/firmware/brcm/" (from the root of your PC, not on the cloned repo)

Building the rootfs

This is the annoying part. Download the archive / image corresponding to the distribution you want to use :
If it's a tarball you just downloaded

While it's downloading, you'll have to take a microSD card and, using the software of your choice (I used GParted) :
  • remove every existing partition to only have unallocated space on it (do I need to tell you that you're going to loose everything on the card ?)
  • create a tiny FAT32 partition (I chose 200mb but it doesn't matter) - that'll be mmcbkl0p1, you can label it "garbage"
  • create an ext4 partition on the remaining part of the card - that'll be mmcblk0p2, you can label it "rootfs"
  • it's important that the FAT32 partition comes first and the ext4 one comes after - on the Switch, Linux will look for mmcblk0p2, the second partition, if you have scrolling boot logs and then back to RCM it means you did it wrong
Once the rootfs tarball is downloaded, you can simple extract it to the mounting point of the ext4 partition you just created :

Code:
$ tar xvf ArchLinuxARM-aarch64-latest.tar.gz -C /mounting/point/of/ext4/partition && sync
$ cp ArchLinuxARM-aarch64-latest.tar.gz /mounting/point/of/ext4/partition/root && sync

("/mounting/point/of/ext4/partition/root" is the "root" directory on the partition)

Don't forget to properly eject the SD Card !

If "tar xvf" doesn't work for you you can install "bsdtar" and use "bsdtar -xpf" instead

Then you can put the SD card in the console.

If it's a img / bin file you just downloaded

You can simply write it on your SD card using :
  • If you're on Windows, Ether or Win32DiskImager
  • If you're on Linux / Mac OS : "sudo dd if=yourimage.img of=/dev/sdX && sync" where /dev/sdX is the device of your SD card (unmounted)
You will probably want to open a partition manager to resize the ext4 partition once it's flashed, so that it fits your SD card.

Then you can put the SD card in the console.

Booting linux

Run the exploit :

Code:
$ cd shofel2/exploit
$ sudo ./shofel2.py cbfs.bin ../../coreboot/build/coreboot.rom

Your terminal should now be waiting for the Switch to enter RCM mode.

To do so : (I don't have pictures but that's the same method as fusée gelée, just look at some video tutorials)
  • plug the Switch on your PC using the USB A-to-C cable - use a blue SuperSpeed port if you have one
  • shut it down
  • remove the right joy-con
  • using a method of your choice, short the 10th pin of the right joy-con (the last pin on the right, away from the screen, closer to the back) with the ground : that can be pin 1, 2 or 7, that can also be a screw on the joy-con rack or the console's fan - I personnaly stick a RPi jumper wire in the fan and touch the 10th pin on the other side, works everytime (like this)
  • keep the pins shorted and power the Switch while pressing the volume UP button
If it worked, the console will show a black screen and you'll see the exploit running on your terminal. If you see the Nintendo logo, it has failed. You can power off the console and try again.

Then, run those last commands :

Code:
$ cd shofel2/usb_loader
$ ../../u-boot/tools/mkimage -A arm64 -T script -C none -n "boot.scr" -d switch.scr switch.scr.img
$ sudo ../../imx_usb_loader/imx_usb -c .

Linux should then boot on your console - first the boot logs with the penguins, and then an ArchLinux login prompt. Voilà !
Again, if you have the boot logs and then a black screen, it means you did the SD card part wrong.

Additional notes

Hardware graphics acceleration


The most recents image already contain this fix.

To add mesa drivers install this package using pacman :
https://0w0.st/mesa-full-tegra-r101876.bf5e0276b6-1-aarch64.pkg.tar.xz

You will need a working internet connection to do so.

Then, use this script to choose your power profile : https://0w0.st/power.sh

Full speed RAM


According to the blog post ("Linux on Switch boot chain" section), you need to extract a file from a Pixel C factory image in order to have the RAM working at full speed. I didn't do it so I won't cover it here.

Fixing calibration issues of the touch screen (thanks to @Wizardy)

To fix calibration issues of the touch screen, edit the file /usr/share/X11/xorg.conf.d/10-evdev.confg (of the rootfs)

And change the InputClass section to :

Code:
Section "InputClass"
        Identifier "evdev touchscreen catchall"
        MatchIsTouchscreen "on"
        MatchDevicePath "/dev/input/event*"
        Driver "evdev"
        Option "InvertX" "no"
        Option "InvertY" "yes"
        Option "SwapAxes" "yes"
        Option "Calibration" "0 1279 0 719"
EndSection

Wi-Fi

To setup Wi-Fi, mount the rootfs partition on your host PC and edit the configuration for your network in the file "/etc/NetworkManager/system-connections" (if it doesn't exist, take Gigaspot).

To have a working Wi-Fi you must reboot your Switch and run the exploit again each time you power it off

Moving the rootfs to another partition

If you want to move the rootfs to another partition on your SD card, edit the "shofel2/usb_loader/switch.scr" file and replace "/dev/mmcblk0p2" by the partition you want to use.
 
Last edited by natinusala,

Faiz Saleem

Member
Newcomer
Joined
Jun 26, 2014
Messages
14
Trophies
0
Age
24
Location
Nottingham, United Kingdom
XP
145
Country
United Kingdom
error when building

~/shofel2/exploit$ make
arm-linux-gnueabi-gcc -march=armv4t -mthumb -Wall -Werror -Os -MMD -ffreestanding -fno-common -fomit-frame-pointer -nostdlib -fno-builtin-printf -fno-asynchronous-unwind-tables -fPIE -fno-builtin -fno-exceptions -Wl,--no-dynamic-linker,--build-id=none,-T,romhax.ld -std=gnu11 -c -o obj/cbfs.o cbfs.c
make: arm-linux-gnueabi-gcc: Comando não encontrado
Makefile:23: recipe for target 'obj/cbfs.o' failed
make: *** [obj/cbfs.o] Error 127
how can i fix it?

Follow the steps in "Prep work" carefully. You need to download the mentioned toolchains and add the directories to your $PATH variable. Ensure you're adding the bin directories to $PATH, not the lib ones.
 

Dmafra

Well-Known Member
Member
Joined
Aug 26, 2015
Messages
250
Trophies
0
XP
1,278
Country
Brazil
Follow the steps in "Prep work" carefully. You need to download the mentioned toolchains and add the directories to your $PATH variable. Ensure you're adding the bin directories to $PATH, not the lib ones.

How do I add the directories to your $PATH variable?
 

ExploitTnT

Devy | YT: DevRin | dev_settings
Member
Joined
Jul 30, 2017
Messages
150
Trophies
0
XP
270
Country
Austria
This works fine for me :)

Edit: The wire is copper so it's pretty rigid, though.

L9TlnQV.jpg
Crap, I dont have any other wires in my house right now. D:
 

EpicLPer

Your friendly Austrian IT Guy
Member
Joined
Mar 13, 2015
Messages
1,060
Trophies
0
Age
28
Location
Austria
Website
epiclper.com
XP
1,141
Country
Austria
Last edited by EpicLPer,
  • Like
Reactions: lordelan

xXDungeon_CrawlerXx

Well-Known Member
Member
Joined
Jul 29, 2015
Messages
2,092
Trophies
1
Age
28
Location
Liverpool
XP
3,720
Country
You should use "su" instead of sudo and also "bsdtar pxf" instead of "sudo tar vxf".
That way original permisions will be restored (NOTE: the p flag and other version of tar).

Helped a friend yesterday to chroot and install plasma on arch.
Do any of you who messed with plasma know how to solve rotation issue on wayland?
We were able to fix it for xorg version of plasma but it has worse touch support than wayland one(no virtual keyboard).
Also how did you solve issue with WiFi (there seem to be 4 devices in /sys/class/net)?

upload_2018-4-25_17-33-25.png
 

moonshadow565

Member
Newcomer
Joined
Apr 25, 2018
Messages
5
Trophies
0
Age
34
XP
57
Country
Croatia
What kind of filesystem are you extracting it into ?
Also be sure to delete previous directory :)
NOTE: it will extract files in current directory

EDIT: seems you are extracting it into media device itself then be sure to delete it before
 

marice

Well-Known Member
Member
Joined
Mar 14, 2009
Messages
170
Trophies
0
XP
450
Country
Netherlands
I'm getting to this point but I'm left with just a black screen.
Code:
 lain@cyberia  /mnt/external/Games/Switch/Switchnix/shofel2/exploit   master ?  sudo ./shofel2.py cbfs.bin ../../coreboot/build/coreboot.rom
[sudo] password for lain:
File descriptor: 9
b'0084fc0c0000002404532c6401101062'
entry 400168ed
throwing more
Performing hax...
Size: 0x6c68

b'820000000000686c'
b'0200000000000000000000000000000010a8a10100000000716c000000000000000000000000000000000000000000000f0f00000000000000'
URB address: 0x1a4ce50
URB status: -2
b'CBFS\n'
>>> Switching to cbfs mode...
sending 0x7000 bytes @0x0
sending 0x4 bytes @0xffffc
sending 0x20 bytes @0x20138
sending 0x18 bytes @0x20100
sending 0x20 bytes @0x20118
sending 0x18 bytes @0x20180
sending 0x20 bytes @0x20198
sending 0x1c bytes @0x201b8
sending 0x533e bytes @0x201d4
sending 0x100000 bytes @0x0
you have been served
 lain@cyberia  /mnt/external/Games/Switch/Switchnix/shofel2/exploit   master ? cd ../usb_loader
 lain@cyberia  /mnt/external/Games/Switch/Switchnix/shofel2/usb_loader   master ?  ../../u-boot/tools/mkimage -A arm64 -T script -C none -n "boot.scr" -d switch.scr switch.scr.img
Image Name:   boot.scr
Created:      Wed Apr 25 00:54:46 2018
Image Type:   AArch64 Linux Script (uncompressed)
Data Size:    290 Bytes = 0.28 KiB = 0.00 MiB
Load Address: 00000000
Entry Point:  00000000
Contents:
   Image 0: 282 Bytes = 0.28 KiB = 0.00 MiB
 lain@cyberia  /mnt/external/Games/Switch/Switchnix/shofel2/usb_loader   master ?  ../../imx_usb_loader/imx_usb -c .
config file <./imx_usb.conf>        
vid=0x0955 pid=0x701a file_name=switch.conf
config file <./switch.conf>
parse ./switch.conf
./switch.conf: syntax error: _direct 0x8e000000
 {switch.scr.img:load 0x8e000000,jump_direct 0x8e000000
}
Trying to open device vid=0x0955 pid=0x701a
Interface 0 claimed
HAB security state: development mode (0x56787856)
== work item
filename ../../linux/arch/arm64/boot/Image.gz
load_size 0 bytes
load_addr 0x83000000
dcd 0
clear_dcd 0
plug 0
jump_mode 0
jump_addr 0x00000000
== end work item
load_addr=83000000

loading binary file(../../linux/arch/arm64/boot/Image.gz) to 83000000, skip=0, fsize=82d047 type=0

<<<8572999, 8573952 bytes>>>
succeeded (status 0x88888888)
HAB security state: development mode (0x56787856)
== work item
filename ../../linux/arch/arm64/boot/dts/nvidia/tegra210-nintendo-switch.dtb
load_size 0 bytes
load_addr 0x8d000000
dcd 0
clear_dcd 0
plug 0
jump_mode 0
jump_addr 0x00000000
== end work item
load_addr=8d000000

loading binary file(../../linux/arch/arm64/boot/dts/nvidia/tegra210-nintendo-switch.dtb) to 8d000000, skip=0, fsize=a040 type=0

<<<41024, 41984 bytes>>>
succeeded (status 0x88888888)
HAB security state: development mode (0x56787856)
== work item
filename switch.scr.img
load_size 0 bytes
load_addr 0x8e000000
dcd 0
clear_dcd 0
plug 0
jump_mode 1
jump_addr 0x00000000
== end work item
load_addr=8e000000

loading binary file(switch.scr.img) to 8e000000, skip=0, fsize=162 type=aa

<<<354, 1024 bytes>>>
succeeded (status 0x88888888)
jumping to 0x8e000000
 lain@cyberia  /mnt/external/Games/Switch/Switchnix/shofel2/usb_loader   master ? 
I've tried removing the SD card and it does the same thing. I've also left it for about 15-20 minutes but still nothing. Any suggestions?

Did you, or anyone else ever get this problem sorted out?
I'm still having the same problem as you do.

I also noticed my PC makes a USB-disconnect sound when i run the last command. (dunno if that's normal, should'nt it be sending data at this point?)
 

clank

Well-Known Member
Newcomer
Joined
Jan 24, 2015
Messages
99
Trophies
0
Age
27
Location
/dev/nvme0n1p1
XP
503
Country
Antigua and Barbuda
Did you, or anyone else ever get this problem sorted out?
I'm still having the same problem as you do.

I also noticed my PC makes a USB-disconnect sound when i run the last command. (dunno if that's normal, should'nt it be sending data at this point?)

Run the last command with sudo.
 
  • Like
Reactions: EpicLPer

Faiz Saleem

Member
Newcomer
Joined
Jun 26, 2014
Messages
14
Trophies
0
Age
24
Location
Nottingham, United Kingdom
XP
145
Country
United Kingdom
How do I add the directories to your $PATH variable?

Okay, so I assume you downloaded both gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi.tar.xz and gcc-linaro-7.2.1-2017.11-x86_64_aarch64-linux-gnu.tar.xz. Decompress them both somewhere (I used ~/switch)

Now, your ~/switch or whatever directory should look like this:

  • gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi/
  • gcc-linaro-7.2.1-2017.11-x86_64_aarch64-linux-gnu/
I assume you're using bash too, so type `nano ~/.bashrc`.
On the very last line, type:

export PATH=$PATH:~/switch/gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabi/bin:~/switch/gcc-linaro-7.2.1-2017.11-x86_64_aarch64-linux-gnu/bin

(Of course, replace ~/switch with a different path if you extracted them elsewhere.)

Then, press ^O to save the file, then ^X to exit nano.

Type `. ~/.bashrc` to reload your bashrc. Now, those two directories should be part of your $PATH variable.
 
Last edited by Faiz Saleem,
  • Like
Reactions: phunky1

Dominic1982

New Member
Newbie
Joined
Apr 25, 2018
Messages
2
Trophies
0
Age
42
XP
56
Country
Netherlands
I downloaded Linux4TegraR241beta.mrom and extracted files with bsdtar. Used the file system in there (root_00 till 09) and booted my switch with that. It brings up the GUI.

The touchscreen works but is uncalibrated. You can tell cause moving your finger over the OK button at the graphics reset error has a responce. Will do further testing.

edit: you won't get anything on first boot. Most likely to do with the graphics configuration not working. you need to reboot and on the second go it will bring up the GUI
 

Attachments

  • IMG_0561.JPG
    IMG_0561.JPG
    36.1 KB · Views: 313
  • IMG_0562.PNG
    IMG_0562.PNG
    31.6 KB · Views: 322
  • IMG_0563.PNG
    IMG_0563.PNG
    44.8 KB · Views: 293
Last edited by Dominic1982,

dpad_5678

Ape weak on own. Ape strong in unity.
Member
Joined
Nov 19, 2015
Messages
2,219
Trophies
1
XP
2,880
Country
United States
Is there a way to test if the Switch has been booted into RCM mode correctly without performing this entire process?
 

moonshadow565

Member
Newcomer
Joined
Apr 25, 2018
Messages
5
Trophies
0
Age
34
XP
57
Country
Croatia
I downloaded Linux4TegraR241beta.mrom and extracted files with bsdtar. Used the file system in there (root_00 till 09) and booted my switch with that. It brings up the GUI.

The touchscreen works but is uncalibrated. You can tell cause moving your finger over the OK button at the graphics reset error has a responce. Will do further testing.
The touch is "rotated" to the wrong side so you need to either rotate touch or display
You can rotate display with "xrandr -o left" and then the touch works good.
 

LeRepex

Member
Newcomer
Joined
Nov 8, 2016
Messages
12
Trophies
0
Age
33
XP
79
Country
Germany
I have a problem. When I try to use make to compile the Kernel it says the following and stops
Code:
arch/arm64/Makefile:27: ld does not support --fix-cortex-a53-843419; kernel may be susceptible to erratum
arch/arm64/Makefile:48: Detected assembler with broken .inst; disassembly will be unreliable
  CHK     include/config/kernel.release
Cannot use CONFIG_CC_STACKPROTECTOR_STRONG: -fstack-protector-strong not supported by compiler
Makefile:1129: die Regel für Ziel „prepare-compiler-check“ scheiterte
make: *** [prepare-compiler-check] Fehler 1
I have set up the PATH things correctly and also tryed to update ubuntu but it still wont work
Please Help me
 

ExploitTnT

Devy | YT: DevRin | dev_settings
Member
Joined
Jul 30, 2017
Messages
150
Trophies
0
XP
270
Country
Austria
Is it normal on Windows that it says that there are no drivers?
926ca898f875f58e63741ef22f02e493.png

This is currently the most noob-friendly tuto I can make I'm afraid

--------------------- MERGED ---------------------------



Ermmm.... no you'll need a more rigid wire, not a ponytail
Oh and i managed to do it with the shitty wire.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    AncientBoi @ AncientBoi: 🫂 +1