Enable UEFI on any Linux distributions

A simple user guide helps you to enable UEFI boot on your tablet.

Get the Device Tree config file

In computing, a devicetree (also written device tree) is a data structure describing the hardware components of a particular computer so that the operating system's kernel can use and manage those components, including the CPU or CPUs, the memory, the buses and the integrated peripherals.

Device tree is widely used on ARM64 platform when it uses Linux kernel, instead of ACPI. The latter can be found on most x86_64 based devices.

Systems which use device trees usually pass a static device tree (perhaps stored in EEPROM, or stored in NAND device like eUFS) to the operating system, but can also generate a device tree in the early stages of booting.

On Renegade Project's UEFI firmware, the device tree is used when your device is booting Linux kernel via EFI stub. To get the device tree file, we need to look up it in kernel repository. So open your terminal, and type this command, it will simply download the whole repository and store it on your disk:

git clone https://github.com/maverickjb/linux-6.1.10.git
git clone https://gitlab.postmarketos.org/panpanpanpan/sm8150-mainline.git

git clone https://gitlab.com/sm8150-mainline/linux.git 

Once it finished, go to the repository's directory. We need to find the proper device tree file that ended with file extension name (*.dts). It is stored under arch/arm64/boot/dts . cd into this directory, find the DTS file named "sm8150-xiaomi-nabu.dts".

Now, let's install some basic tool for compiling the Linux kernel.

On Ubuntu and other Debian-based distributions:

sudo apt build-dep linux linux-image-unsigned-$(uname -r)

Unfortunately, the above does not install all of the necessary dependencies. The current Disco Dingo release requires the following additional packages.

If you are going to be using git, install it via:

This is an Ubuntu-specific hint. For Debian-based distributions, skip readng this.

The above command requires your system to have the correct deb-src lines in /etc/apt/sources.list. For example, on Disco Dingo you should have:

On Arch Linux (and distributions based on it):

Install the base-devel meta package, which pulls in necessary packages such as make and gcc. It is also recommended to install the following packages, as listed in the default Arch kernel PKGBUILD: xmlto, kmod, inetutils, bc, libelf, git, cpio, perl, tar, xz.

Now compile the DTS file into DTB files:

You should have the Device tree files now.

Compile the Linux kernel

Before you start your compilation, you need to patch the kernel for charger and RTC feature.

Navigate to your kernel repository to continue:

Simply enter these commands on terminal:

Notice the Image.gz is the Android kernel image we won't use. After compiling kernel, you will find the two files we need: a sysmap file and the final kernel image (name begin with "vmlinuz") . Copy them to your tablet's EFI directory.

You should have these files:

Assign an ESP partition​

To modify the partitions on the UFS, we'll need to download a 3rd-party recovery environment called "Orangefox Recovery" Link is here below:

This will start booting recovery image. Once the screen is on, use the terminal to continue processing. We well use adb shell command to finish the rest of this guide.

we'll need to use the parted command tools to do this. Now let's open adb shell again and start typing parted in the terminal.

Enter print command to list all partitions for /dev/block/sda :

If you are using newer recovery like TWRP or PBRP Recovery, you need to download parted and use adb command to copy it to internal storage. Run these commands to finish this:

Then you will see your current partition table with userdata being the last partition Below is an example of output:

Now let’s continue partitioning: Here the size of userdata can be decided by yourself.

Delete partition 31 and again make sure it is not deleted incorrectly.

Do sgdisk --resize-table 64 /dev/block/sda if you need to extend the number of partitions from 32 to 64.

Mount EFI partition

First, check the UUID of your partition:

Modify fstab to use these UUIDs above:

Compile UEFI firmware

We will use Renegade Project EFI firmware for example. Clone the repository to your disk:

An alternative choice is Aloha firmware, which is based on Microsoft's MU firmware. It demonstrates an AArch64 UEFI implementation for hacked devices with Qualcomm silicons. Currently it is able to boot Windows and Linux. Please be aware that devices with no dsdt support have limited support.

For instructions about how to compile UEFI firmware and flashing it, they are located here. You can also download their prebuilt binaries at here.

Replace the dtb file "sm8150-xiaomi-nabu.dtb" in "edk2-msm/Platform/Xiaomi/sm8150/FdtBlob/nabu/" with the kernel DTB file "sm8150-xiaomi-nabu.dtb" which you used in your kernel repository. rename to "sm8150-xiaomi-nabu.dtb" and build image:

You will receive a boot image. Flash it to boot partition:

Then, install GRUB onto your disk in your Linux distributions:

For Ubuntu and other Debian-based distributions:

For Arch Linux and Arch-based:

For Alpine and Alpine-based:

DTB Overwrite

On recent kernels (6.12 or above), device trees from mainline kernels may not work perfectly on your tablet, even the device tree is compatible with older kernels. The most common affected feature is charger.

Since recent Arch Linux ( Now it's the only option you can choose by default ) images are shipped with a pre-built kernel, it would be easy to make your system bootable via UEFI firmware. But you can also continue using your custom kernel to finish this part. Using a bootloader supports overwriting DTB files is useful when you have multiple kernels installed.

Install bootloader

We'll use systemd-boot as an example:

Now the bootloader is installed. But we need to write a configuration file to tell bootloader how to boot system properly.

Tip: After changing the configuration, run bootctl (without any arguments) to make sure that systemd-boot will be able to parse it properly.

Adding loaders for systemd-boot

systemd-boot will search for .conf files in /loader/entries/ on the EFI system partition it was launched from and additionally the XBOOTLDR partition on the same disk.

Go to EFI system partition, then the loader directory, then entries . Using touch command to create a .conf file.

Write an configuration file, below is an example:

NOTE: Entries in esp/loader/entries/*.conf can only use files (e.g. kernels, initramfs, images, etc.) in esp/ and entries in boot/loader/entries/*.conf can only use files in boot/.

  • systemd-boot does not accept tabs for indentation, use spaces instead.

  • default and timeout can be changed in the boot menu itself and changes will be stored as UEFI variables LoaderEntryDefault and LoaderConfigTimeout, overriding these options.

Once you finished these steps above, reboot your tablet and check if it works.

Ubuntu specifics

Install GRUB on Ubuntu​

On recent Ubuntu images, these steps are no longer needed.

Install GRUB tools and generate RAM disk:

Generate GRUB configuration file:

After compiling the kernel and ensuring that the necessary files are moved to your tablet's EFI directory, reboot your device. During the booting process, access the boot menu. This may vary depending on your device, but typically involves pressing one of the function keys (e.g., F12, F9, or F2) right after powering on the device. From the boot menu, select "Ubuntu" .You'll see the GRUB boot menu, use Vol+ or Vol- keys to navigate, power button to confirm.

A tablet showing a Simpleinit boot manager which have some menus. The "Continue boot" menu is selected.
Boot menu.

Updating Kernel Parameters (Optional)

If you need to tweak kernel parameters for optimization or compatibility reasons, you can edit the grub configuration file. This file is usually found at /etc/default/grub. You would add your parameters to the GRUB_CMDLINE_LINUX_DEFAULT line. After editing, apply the changes with sudo update-grub and reboot for them to take effect.

Remember, keeping a backup of the original configuration files before making any changes is always a good practice. This precaution ensures you can revert to a working state in case anything goes wrong.

Last updated