I’m planning to move towards using custom ROMs in order to have more control over what is and isn’t installed on my phone.

I’ve got an old spare S8 that I’m going to use as a testbed first to get hands on and learn a bit more. It looks like LineageOS doesn’t provide a build for that model so I’ll need to learn how to prepare one myself.

I’m no stranger to Linux - I’ve built my own kernel (and even once an LFS system) back in the day - what resources would be ideal for getting up to speed with Android?

I’d hopefully like resources that help me understand what’s going on rather than focus purely on completing one task or another.

  • Skull giver@popplesburger.hilciferous.nl
    link
    fedilink
    English
    arrow-up
    11
    ·
    edit-2
    1 year ago

    Edit: some work has already been done for you, there’s an XDA forum for your device. Be sure to read through that, and make sure you double check that you’re reading about the right SoC (Exynos/Snapdragon, there are usually two versions of the Samsung S series) if you’re downloading sources or ROMs from there.

    Building Android is a bit like building Gentoo: you’ll be building almost everything. It requires quite a bit of effort. You can do it with relatively limited hardware, but the beefier your PC, the better. If you don’t have at least 200GB of storage space, 16GB of free RAM, and 4 relatively recent CPU cores, I wouldn’t even bother. The LineageOS wiki recommends 300GB of SSD space + space for a compiler cache + tooling, 32GB of RAM, and as many CPU cores as you can get your hands on.

    First, I would start by verifying that you can actually unlock the bootloader. If your bootloader is locked and cannot be unlocked, running a custom ROM will be very very difficult (you will need to find/write exploits for the protection mechanisms and basically rootkit your phone into booting your ROM). Note that unlocking the bootloader will wipe all data on your phone.

    I would recommend you start with this guide: https://wiki.lineageos.org/emulator That’ll teach you how to compile LineageOS for the Android emulator; a relatively straightforward target. It’ll guide you through the tooling and the setup so you can get a feel for what’s necessary.

    If you’ve got a working Android emulator image, you’ll want to start looking for sources of other custom ROMs for your device as a starting point. Most likely, all you’ll need is the kernel (must be published, of course) and the vendor binaries for drivers and such. If you have those handy, you’ll be able to start compiling your own version of LineageOS from source relatively quickly, you’ll just need to download some binaries from your phone and edit some XML files.

    If you don’t have any starting point at all, you should get the kernel sources from Samsung. They’re legally obligated to hand them to you, as a customer, because of the GPL. Finding out what binaries are necessary will be harder, you can try looking at custom ROMs for similar phones to see what binaries you may need to get everything to work.

    This guide: https://gitlab.e.foundation/e/documentation/a-generic-guide-on-porting-eos/-/wikis/01:-Introduction for /e/, a ROM that’s generally outdated but was designed to go completely Google free, has some more instructions on how to port to a new device.

    Note that most guides assume you’re compiling a ROM of the same Android version as the stock ROM on your device. If you’re planning on upgrading to the latest Android sources, you’ll have to take on the responsibility to port the device specific configurations from their current versions to the latest ones. In that case, be sure to check if someone else has already done this work for hardware that other devices may have in common with yours, because this process can contain hacks (like adding kernel APIs to make modern drivers work, or modifying system service permissions so drivers can execute).

    Once you have an Android build, you’ll also need some more tools: a recovery (TWRP is the de facto one but there are others) from which you can flash your image, and possibly some Google Apps if you want to be able to use the Play Store. You can download GApps as a package, but if there are no ROMs whatsoever for your device, you may also need to port TWRP (or another recovery of your choosing, if you have a preferred alternative).

    Be sure to make a backup before flashing the system image, or you may end up with an unbootable device!

    Lastly, if you want to publish your image so others can use it, be sure to post your images in the relevant XDA threads. XDA is also the best place to look for ROMs, and maybe get in contact with ROM makers that have since abandoned ROMs for your device.

    Depending on your free time and experience with Android, porting your own ROM can take weeks or months. It’s not something you do in an afternoon. The compilation alone will take hours (I clocked about 1:45 on my i7700k with 32GB of RAM and about 400GB of SSD storage) and you’ll constantly be debugging bootloops and selinux issue at first (don’t run a daily driver with selinux disabled, selinux is how Android keeps its sandboxing from breaking down, but you may want to disable it during the first builds to make the process slightly easier).

    There is one alternative that you may be able to use: GSI. Google has been pushing vendors to standardise their hardware and software to a certain point where standard images will be able to boot on most phones. These images may lack things like “hardware accelerated graphics” or “more than VGA camera support” or “fingerprint scanner working”, but they should boot on any device released with Android 9 or newer, and in some rare cases on devices upgraded to Android 9. You can download ready-made GSI images from all kinds of places, but there’s no guarantee they’ll work. You can build your own GSI build (just build for device codename treble, I believe) or download a ROM from here.