bootloader / qfuses / ARB - how not to brick your phone for funsies v1

runningnak3d

Recognized Developer
Nov 10, 2010
2,649
7,177
0
Largo
This is version one of this document. I know the formatting is not great, and I will be fixing that over time. Also, there is some pieces that are missing, and some of it may not entirely be correct yet. I will try to make note if I am unsure.

I am composing this because I couldn't find a good resource that explained all of this in one place.

So after bricking my phones (G4, V10, V20 -- sometimes deliberately) many times, I thought I would share a little information. I gathered this information by:
* accident
* decompiling the various pieces of the firmware
* documentation found on the net
* reading source code

First some background on the boot procedure for SD8XX based phones (SD800, 801, 808, 810, 820).

It goes like this:

CPU (Qfuses: ARB / KEY (SHA1?) / TRUSTED_BOOT, FEAT_A, FEAT_B) <--> PBL <--> XBL (SBL1) -> ABOOT -> BOOT


The XBL (Seconday Boot Loader) is very similar to UEFI on a PC. It loads a lot of modules (firmware) that make the devices on the phone work, and allow it to boot. The XBL has an RSA cert that it uses to verify most of the modules that it loads.

The XBL loads (and verifies - does it also check ARB per module?):
(RSA) - aboot (Applications Boot)
(RSA) - apdp -- ??
(RSA) - cmnlib (Common Libraries) -- These are just shared libraries that the other parts of the firmware use
(RSA) - cmnlib64 (Common Libraries 64bit) -- Same as above, but for the 64bit components.
(RSA) - devcfg (Device Configuration)
(RSA) - hyp (Hypervisor) -- this is what runs the NON-HLOS, and I believe is one of the first things that XBL loads.
(RSA) - keymaster -- This does several things, but one of the things it handles is the fingerprint sensor
modem -- This is your modem firmware.
(RSA) - msadp -- ??
persist -- ??
(RSA) - pmic -- ??
raw_resources
rct -- ??
(RSA) - rpm -- Resource and Power Management
sec -- ??
(RSA) - tz -- TrustZone You can thank this guy for handling the security of the QSEE (Qualcomm Secure Execution Environment). It checks the RSA certs for the images that are labled above with (RSA).

The XBL only loads these if:
* The phone is booting to the HLOS (Android)
* The phone is booting to recovery (No idea why it would need them in recovery, but it does)

If you are going into download mode, or fastboot mode, they do not get loaded.

The PBL is located in ROM -- true Read Only Memory. There is no changing it unless you physically unsolder the chip.
When you power on the phone, the PBL gets loaded, and does a couple of things, but the one we are concerned with is it loading the SBL (Secondary Boot Loader, or XBL on the V20).
It verifies the integrity of the XBL by reading a key from a qfuse on the CPU. If it matches, it continues the boot process. It also checks the ARB (Anti-RollBack) version qfuse. If the ARB version of the XBL is greater than the ARB version currently blown into the qfuse, it will blow the bits needed to match the current ARB of the XBL that it is trying to load. When a Qfuse is blown, it can't be "unblown", so you are stuck with that ARB version now.

When a Qualcomm chip ships from the factory, none of the Qfuses are blown -- the chip is fully unlocked. It is then up to the OEM to decide what features it wants to have enabled, as well as should trusted boot be enabled. As far as I know, EVERY OEM blows the TRUSTED_BOOT qfuse on production phones, which means that the PBL will verify the SBL (XBL). This means that the SBL (XBL) must be signed. This signature is also in the CPU via blown qfuses. I don't believe that there is any room to modify the SHA1 signature once it has been blown into the CPU -- but I have nothing to back this up. That means that as long as you ONLY use an XBL that has the same signature as what is blown into your CPU -- AND -- you don't try to run an XBL with a LOWER ARB version, that your phone will boot. Doesn't mean it is going to work, but it will at least boot to download mode if you haven't messed up aboot or laf (we will get to that).

If the XBL is corrupt, or wasn't signed, or was signed but with a different key, or has an ARB version that is less than what is in the CPU, the CPU will go into HS-USB QDLoader 9008 mode, and your phone is a brick. QDLoader mode is built into the (CPU? PBL?) so that the boot loader can be fixed. If you have the right tools (QPST) AND a signed firehose, then you can flash the proper firmware back onto your phone. Good luck finding a signed firehose -- they leak from OEMs very rarely here recently. In the past (when they were using eMMC), before UFS, you could boot from an SD card and recover your phone. The V20 uses a UFS chip that presents itself as multiple LUNs, and does not have a UFS card slot -- so I do not believe it is possible to boot from SD card anymore. This is something that is still being investigated however.

So, lets say all is good -- PBL verified the XBL, and said it was OK. Now it is time for the XBL to load ABOOT.
Once again, there is verification. This time the XBL verifies ABOOT with its own RSA key. If ABOOT is OK, then it loads. At this point, you will have download mode, and at least you can recover (if you have a KDZ). No matter what -- NEVER mess with XBL or ABOOT unless you absolutely want a brick. If ABOOT is corrupt or invalid in some way, then the CPU goes into QD_LOADER (9008) mode.

So now we have ABOOT loaded. ABOOT does a lot of things. Directly, it provides fastboot mode, indirectly, it provides download mode by booting laf. In order to have download, you have to have a working laf. LAF is just a kernel with an initrd that runs lafd (more on that later). ABOOT also allows you to boot recovery. Again, recovery is just a kernel with an initrd.

ABOOT loads (all just kernels with an appropriate initrd:
boot
laf (download mode)
recovery

depending on the mode it is in.

What we care about most is boot (that is the kernel, that loads the system partition). If you don't have an unlocked boot loader, and you have modified your kernel, the boot will fail, since aboot verifies the signature. This will usually just result in a boot loop, but don't count on that. The good news is that a corrupt boot or recovery doesn't prevent you from getting into download mode -- better have a KDZ though.

So to sum up. If you don't want to brick your phone so bad that it has to be replaced or repaired:

* Don't flash an XBL that has a lower ARB version
* Don't flash an XBL that has a qfuse key that is not in your CPU (cross model flashing -- make SURE the model you are flashing uses the same key)
* Don't flash an aboot that wasn't signed with the RSA cert that is in your XBL
* Don't nuke your laf partition AND your recovery partition at the same time.

More to come -- especially better formatting.

EDIT1: The PBL is not a separate chip, it is in the Qualcomm CPU (QFPROM) -- This is also where the qfuses are located. The thing is huge, there is more than enough space that a vendor could update the key (it is a 2048 bit RSA key -- NOT an SHA1 hash), but more importantly it is 32k. Part of QFPROM is the PBL, the rest is for the vendor key(s?), and then there are feature banks. For example, can the boot loader be unlocked can be checked via a feature fuse.
Camera features, modem features, a lot of things can be determined by what the OEM wants to blow. One of the important things that is determined, is UART on or off. On the v20, it appears this is blown, so there is no way to get a console.

What is interesting is that there is a pin for voltage to write to the QFPROM. That pin can either have voltage, or be shorted to ground. Now, here is a big question, what if that pin was shorted to ground? Would the phone continue to boot in the event that a request to write to QFPROM happened (IE: booting an XBL with a greater ARB). If it would, then get a new phone with ARB 0, ground that pin, and they could never update the key, or ARB version. But if the OEM did update the RSA key used to sign firmware, it would no longer match the key in the CPU -- so it would need to be reversible.

QFPROM searches all available IO paths for a valid SBL. If that SBL has support to continue booting on the path that it was found, then it will.
This explains why on UFS based phones like the V20, you can get some life out of it if you have a properly formatted SD card, and are in QDLoader mode. The QFPROM reads the XBL, but the XBL has no clue where to go from there. There is no support for finding the other parts of the firmware via SD card -- it MUST have multiple LUNs. On older phones with eMMC, when the SBL was loaded, the SD card was initialized as mmcblk0 and the SBL couldn't tell the difference between it and the eMMC. So, it is now verified that there is no way out of 9008 mode if your phone has UFS except for the signed firehose route.

So what is a firehose? It is just a SBL that is booted via USB, with very limited functionality. The Qualcomm CPU still verifies its integrity (which is why it must be signed if you want it to work). Note1: Does the firehose check ARB?

EDIT2: So it appears that there are several toggles in QFPROM to enable / disable debug mode. Are they all blown? Can the phone be put back into debug mode? In debug mode signature verification is disabled -- as long as SBL is valid, it will load it and run it. This would give us the chance to "crack" the XBL so that it no longer uses its RSA to verify the rest of the boot chain.

A portion of the QFPROM address space is mapped into the HLOS address space. You can view certain portions from a running kernel. I will make a separate update on that. Technically you should be able to write to them as well. This sounds like a recipe for me bricking another phone! W00T!!

EDIT3: It would appear that the partition layout is in QFPROM. Again, this just backs up the fact that you will never be able to boot from SD card. So, how do the DragonBoards boot from SD card? It is my theory that they have both partition layouts in their QFPROM. So, next question, if that is the case, could we write an SD card partition layout into QFPROM? Yea, that is probably WAY out there :)

-- Brian
 
Last edited:

runningnak3d

Recognized Developer
Nov 10, 2010
2,649
7,177
0
Largo
Sure, trace out pad G31 from the CPU and cut it (that is QFPROM programming power), and then short it to ground. After that, flash firmware that has a higher ARB version and see what happens :)

If there is no power, fuses can't be blown, so ARB can't be incremented. Also, if we use the debug firehose, the debug fuse wouldn't blow.

I am not willing to test this theory with any of my phones though....

-- Brian
 

runningnak3d

Recognized Developer
Nov 10, 2010
2,649
7,177
0
Largo
Until @Phoenix591 posted a link to this post, I had forgotten all about it. I am finally making version 2 which will have actual formatting, and be MUCH more readable, but most importantly -- it will have no assumptions -- just pure fact based on all the knowledge I have gained since first writing this. This version has several things that are inaccurate, and a lot of assumptions.

-- Brian

-- Brian
 

chris2288

Member
Feb 20, 2017
25
0
0
Can ARB be disabled

Is the PBL that verifies the SBL or XBL and prevents firmware downgrade located in the eMMC with the SBL and other files or in a physically seperate storage medium, can it be modified via jtag box or any other method to disable ARB without replacing hardware, and would modifying the tot/kdz also work
 
Last edited:

askermk2000

Senior Member
Jul 9, 2015
1,123
2,580
0
Is the PBL that verifies the SBL or XBL and prevents firmware downgrade located in the eMMC with the SBL and other files or in a physically seperate storage medium, and can it be modified to disable ARB without replacing hardware or not?
runningnak3d can probably answer this better than I, but I'll give one anyway, and he can supplement if needed :D

One: Yes
Two: No. Downgrade is not prevented by any part of the bootloader. It's prevented by LGUP. Though if you try to downgrade you'll have a dead phone.
Three: There is no eMMC in LG V20. There is UFS - Universal Flash Storage. If you're suggesting PBL is on there, it's not, it's in the CPU itself (internal eprom).
Four: No, it can not be disabled. Perhaps as a challenge to the most well equipped and competent engineers and scientist you can think of, yes, maybe then.
 

r4736

Member
Feb 24, 2008
18
0
0
Do you know what pin to short to force it into download mode?

This is version one of this document. I know the formatting is not great, and I will be fixing that over time. Also, there is some pieces that are missing, and some of it may not entirely be correct yet. I will try to make note if I am unsure.
-- Brian
 
Last edited:

askermk2000

Senior Member
Jul 9, 2015
1,123
2,580
0
Do you know what pin to short to force it into download mode?
I hope you can see yourself from your post how unnecessary and annoying it is when quoting a large post like that.

As to your question:
Are you saying LG has implemented a function to bypass bootloader verification and boot directly to LAF partition? Or is this simply a case of confusion?

See, this V20 goes into EDL (emergency download) mode automatically, there is no need to short any testpoints to get 9008 mode, unless you'd want
to enter that mode even when the phone is NOT bricked, although that wouldn't do you much good. EDL/9008 = Dead phone, at least in the case of most
phones these days.

I don't believe those testpoints (if they even exist) are known for the V20, perhaps if you can get a hold of the datasheet/repair manual.
 

r4736

Member
Feb 24, 2008
18
0
0
I did not, I was busy this morning, but I fixed that now.

I don't believe those testpoints (if they even exist) are known for the V20, perhaps if you can get a hold of the datasheet/repair manual.
Yes this is why I am asking around seeing if anyone has those (datasheet/repair manual). Also yes trying to get it into emergency download mode since it is not on its own.
 

askermk2000

Senior Member
Jul 9, 2015
1,123
2,580
0
Yes this is why I am asking around seeing if anyone has those (datasheet/repair manual). Also yes trying to get it into emergency download mode since it is not on its own.
Ok I never would have guessed you where asking because of that...

If you get into edl mode, then there is only one possible option for you, and that is to use the LG firehose that is around, but no one has dared to use as of yet because it likely will mess up your phone.
I found it over a year ago at gsmhosting forum. The thread in question indicated that it was only for data retrieval, and that the phone would be unusable afterwards. @runningnak3d by his own analysis, also came to suspect something like that might happen if you use it.
That's why I said getting into 9008 mode wouldn't do you any good, but I guess if you have no other option it might be worth a try.

Edit: Well actually, you might be able to get someone with octoplus or such box to fix it, if you can get into 9008. It doesn't work for H918 but might for you.
 
Last edited:

r4736

Member
Feb 24, 2008
18
0
0
I guess if you have no other option
Yeah, it's fun. I wasn't paying attention and used did to restore the aboot backup while in USB mode. So it does practically nothing. Detectable by nothing, nothing on the screen. The only signs of life are it doing the power on vibrate, and the creek will only come on to blink a ! Battery warning if plugged in with battery removed. Thank goodness it's just a spare, v30 visits my daily.

I'm half thinking about taking it to a LG repair center here in Hong Kong. If it's not expensive if like to have it working.
 

joeyk240

Member
Jan 25, 2010
23
6
0
Apologies for resurrecting a month old thread, I usually don't resort to posting, but I cannot find an answer to my problem in the ~700 pages I've read between here and development.

Long story short, I had a scare the other night fiddling with some build.prop settings resulting in a bootloop. I had been so stupid when I got this phone and flashed it I was on my Ubuntu partition which I no longer have. I never backed anything up, let alone install and get the sdk/adp working on my win10 drive. I am so lucky I was able to get it to finally boot without losing any data.

So I figured it's time to update. Here's what I know. I am bootloader unlocked, unencrypted, and rooted. I'm on H918, the last cmremix that was released, Jan 1 2017, 7.1.1. From what I can tell was compiled with sdk 25. However I'm showing "unknown" under baseband, and mbn, there's also multiple mentions of different sdks throughout different system files.

I've tried ripping apart a twrp system image backup for any mention of ARB, but to no avail. I've tried digging through multiple threads to determine a timeline when ARB was implemented, again to no avail, since I don't technically know which version I'm actually on.

Are there any adb commands or specific system file I can tear apart to determine my devices status in regards to flashing a 10p+ ROM. I've seen multiple mentions of if you're already unlocked and rooted it's much easier to keep it, but I've also seen just as many stating the opposite.

Again sorry for the novel, and bringing up a month old thread.
 

Attachments

Last edited:

Phoenix591

Senior Member
Oct 15, 2017
677
752
0
Apologies for resurrecting a month old thread, I usually don't resort to posting, but I cannot find an answer to my problem in the ~700 pages I've read between here and development.

Long story short, I had a scare the other night fiddling with some build.prop settings resulting in a bootloop. I had been so stupid when I got this phone and flashed it I was on my Ubuntu partition which I no longer have. I never backed anything up, let alone install and get the sdk/adp working on my win10 drive. I am so lucky I was able to get it to finally boot without losing any data.

So I figured it's time to update. Here's what I know. I am bootloader unlocked, unencrypted, and rooted. I'm on H918, the last cmremix that was released, Jan 1 2017, 7.1.1. From what I can tell was compiled with sdk 25. However I'm showing "unknown" under baseband, and mbn, there's also multiple mentions of different sdks throughout different system files.

I've tried ripping apart a twrp system image backup for any mention of ARB, but to no avail. I've tried digging through multiple threads to determine a timeline when ARB was implemented, again to no avail, since I don't technically know which version I'm actually on.

Are there any adb commands or specific system file I can tear apart to determine my devices status in regards to flashing a 10p+ ROM. I've seen multiple mentions of if you're already unlocked and rooted it's much easier to keep it, but I've also seen just as many stating the opposite.

Again sorry for the novel, and bringing up a month old thread.
You're almost certainly arb 0 (pre10p) since you were on that old rom. There are checks in x86cpu's lineage builds that makes it error out if it's the wrong one before it does anything too.
 
  • Like
Reactions: joeyk240

joeyk240

Member
Jan 25, 2010
23
6
0
You're almost certainly arb 0 (pre10p) since you were on that old rom. There are checks in x86cpu's lineage builds that makes it error out if it's the wrong one before it does anything too.
Yeah, I'm about 40min deep into the "Checking for updates" screen, so I'm pretty hopeful everything went okay. I'm going to post a step by step in x86's thread for people coming from outdated ROM's like I was, if everything goes okay.