..

samedi 4 avril 2015

Some basic stuff everyone should know topic


Some basics - About boodloader, kernel, recovery, rom, /system and some other partitions.

There are many noobs out there and sometimes even I am one. Two day ago @Closed Force asked me, where I know my stuff from and why things are like they are... So I finally decided to write this little guide about how Android devices basically work and what are the special things about our G2.

If you find wrong facts or any other mistakes (grammatical, language, contentwise), please bear with me. That's how I read it in the forums. And of course not everything written on XDA is correct. So please tell me by PM, or by posting in this thread if you have additions, corrections or any other concerns about this OP.

Where I got to know all this stuff? Reading, reading, reading. I first started modding my old HTC desire like 4 years ago. Since then and even before I'm reading. Mainly here on XDA but also on some german forums and wikis. It might have taken me easily 200 hours or more. So the only way to learn for a newbie (and everyone else too) is reading.

Personally I own a D802 variant. I know about some things that were different in details for the US variants, but things should be right as they are.

Finally thanks to
@d00lz for some extra research/additions and a quick read through
@Art Vanderlay for some additions

So let's get started:

When you press the power button, your device will load the bootloader. The bootloader afterwards will load either the recovery, the kernel or the download-mode, depending on the keys you press. Atm there are three different bootloaders. The Jellybean one, the KitKat one and newly the Lollipop one. Not one could be unlocked yet, so there are workarounds which allow us to boot custom ROMs (primarely kernels, but more about that later) and custom recoverys anyways. At the beginning there was the Jellybean bootloader. The developers (sorry, I dunno which one) found out how to get around this one pretty early and this workaround they called loki. It's baked in in nearly every ROM except those ones which require the KK bootloader (but that's usually not the reason they don't support the JB one). Anyways, soon the KitKat update came and thereby a new bootloader. Sadly LG patched the loki exploit and the devs found a new way to get the bootloader files wich weren't from LG. They called it bump. Bump basically just imitates the LG signature, so the bootloader thinks this file really was signed by LG. Obviously this workaround works with the JB bootloader too. In the Lollipop bootloader even this exploit has been closed and no one knows how to get around this bootloader yet. Just so much about bootloaders: As long you have a working bootloader, your device is not dead. You can usually recover it in some way.

The G2 has about 30 partitions (for a more detailed explanation, look here, thanks @d00lz), each one has it's own functionality. One of them is the recovery partition. Imagine: The recovery partiton with a working partition is besides a working bootloader everything you need to keep your phone working. It's kind of an OS itself, completely independent from Android or anything else stored on your mobile. The great thing about is, it is so small that it can be run directly in the RAM. This means it's capable of modifing EVERY goddamn partition of your mobile. Including the bootloader and the recovery partition. Attention: Here comes bump in the first time. If you are using the recovery with the 4.4 bootloader, it need to be bumped. Otherwise the bootloader realizes that the recovery is not proven by LG and generates a "secure boot error".

Same thing for the kernel. The kernel takes place in the /system partition and is part of the system. Anyways it's the part of it which will be loaded and booted by the bootloader if you only press the powerkey. This is why this also needs to be bumped if you want to get your system booting on a KK bootloader. Self explaining you need to have installed a compatible ROM with your kernel. When 4.4 came out, most devs switched over the LGs 4.4 sources. Soon it turned out, that the 4.2 sources were much more reliable for AOSP based ROMs. That's why most AOSP ROMs use the 4.2 bootloader and the 4.2 Kernel sources while Stock based ROMs use the 4.4 bootloader and kernel. With the version discussion it's almost done. But it's not all: There are different kernels for AOSP and for Stock based roms. That's because Stock kernels support some ROM functionalities, AOSP ROMs don't have. (e.g. knock code; which isn't open-source btw, which is why it isn't available in AOSP ROMs). So there are huge differences between the Stock and AOSP based ROMs / Kernels. The Kernel is besides of the Stock / AOSP matter independent of the ROM and can be switched at any time you want.

Now about the /data partition... All your stuff, including Apps, system settings, app data and so on will be stored there. The reason why you should clear it every time you change the ROM (not updating, I mean switching to another ROM) is that e.g. the ROM you are coming from has some tweaks the new one doesn't have which means the new ROM doesn't know how to handle them which leads to crashes and so on.

Now let's get to the ROM... Having a 4.2 Bootloader and a 4.2 sources based kernel doesn't mean the top layer has to be 4.2 too. Most of the AOSP based ROMs are based on Googles KitKat or Lollipop sources. And this is true KitKat or Lollipop, with all its functionalities. Those huge version-differences cause some problems in development. No wonder some things do not work properly today, but it's still the best working combination atm. It's kind of a wonder, it works as it is, but let's be happy with it. Since it is as it is, I'm very curious, how AOSP ROMs with LP Kernel sources will work. No matter on the bootloader... The ROM is the other part of the /system partition. So that's the main partition which is modified while flashing. Which partitions will be modified and (how), is written in the updater script. Theoretically running a updaterscript of a ROM which changes the bootloader, can brick your device. That's also the reason why you should only flash stuff made for your device.

Finnaly something about the baseband, modem, what so ever...
It happened to me that the devs or rather the OPs didn't know which baseband the user should use with the ROM. In earlier days the wrong baseband could make the ROM bootlooping. Today most ROMs work with both basebands. Best if you stay on the one you currently are and just flash another one if somethings (e.g. autrotation) don't work. The baseband can be flashed at any time and is independent of every other partition.

Oh and maybe something about the download mode. It's part of the LAF partition, which is used by LG and its PC tools to recover the phone and bring it back to stock. It's a partition itself, but not completely independent of the bootloader. And since it's this way, you can of course have a fully working bootloader, but a dead download mode which means you will not be able to flash a kdz the next time you are in big trouble^^.

The EFS-Partition btw stores the IMEI (and the serial number afaik) of your device btw. NEVER wipe it. With a empty EFS partition you can use your mobile as a brick, but nothing more, no matter if your system works or not. Ok, you can use it as a media tablet, but that's it.

Again: if you got questions/additions/correction or see a mistake, post below, or PM me, I'll edit this post...

xda-developers