[Nexus 6 Q&A, Help & Troubleshooting] kepan:
Hi,

FOR THE FIX GO TO https://xdaforums.com/showpost.php?p=71126110&postcount=10

I think I have messed up.

Trying to fix the echo issue I did own AOSP build from android-7.1.1_r13 (N6F26Q) tag and only modified mixer_paths.xml. The build was successful.

After unlocking the bootloader in Developer options and

fastboot oem unlock

I flashed it to the device with

fastboot flashall -w

.

Then I flashed TWRP and installed Open GApps stock package, flashed back the stock recovery (extracted from stock ROM) to recovery partition with

fastboot flash recovery recovery.img

and locked the bootloader (I know that was stupid :( ) with

fastboot oem unlock

.

Now the device doesn't boot the system. After Google logo there is a Device corrupted error:

[IMG="Device corrupted error"]https://lh3.googleusercontent.com/iGv9RPFbDSLec-4-cvsQNOh46pt5RhEvPy7EKKZXmbtjJ16P7d5EXOJHCIsR=w300[/IMG].

I have learned that during boot the stock recovery was overwritten with test-keys AOSP recovery (from custom system partition from my private build).

I was reading many topics here and from what I understand I can't directly use full stock ROM from fastboot as there is no way to unlock the bootloader. Also I can't adb sideload stock OTA from recovery (private test-keys recovery) as the signature will not match.

What I can do:

Access the bootloader

Access private AOSP test-keys recovery

Adb sideload private build OTA for the same build that I previously flashed with fastboot flashall. I did such a sideload and it has finished with success status code.

Idea 1

I know that OTA update has to be signed with RSA key that is in the current recovery partition on the device. The recovery that I currently have installed has test-keys public key. I think it should be possible to generate correct OTA update zip file that will be signed with test-keys private key and that will include stock recovery RAMDISK? Such an update file would hopefully install successfully and on the subsequent boot the stock recovery partition would overwrite the private build recovery.

With stock recovery I could sideload stock OTA update to restore the stock ROM and device would hopefully boot the system.

Is it possible to modify the private AOSP build to include stock recovery ramdisk?

I reckon that this will not be easy and I would like to know if there is something that I have missed that will prevent this scenario from being successful.

Idea 2

Another idea that I have is to add (append) public RSA key that Google used to sign stock OTA update zip file from the stock recovery partition res/keys file to my build RECOVERY/res/keys directory in build out folder. I found this info about how to covert public key cert to C structure in build/target/product/security/README:

Also on Source Android -- Sign Builds tech page (sorry, can't post links yet) I found that there is a way to add additional recovery public key certs as a PRODUCT_EXTRA_RECOVERY_KEYS build variable that could just do what I need. Look at this fragment:

Once the extra key is added to the build I could rebuild and produce OTA update file that would have private recovery with 2 certificates in res/keys. Then adb sideoload that update from current test-keys AOSP recovery to get the new private recovery (with 2 keys). With that recovery, I understand that, I should be able to adb sideload stock OTA to recover stock ROM.

I don't know yet how to extract the public key certificate from the stock recovery image/partition. Any help would be appreciated.

What do you guys think about this situation? Is it hopeful or hopeless?

Is idea 1 or 2 correct? Which one, if any, has better chances of success (is easier to perform)? I think that my second idea may have better odds.

Could you guys please help me with this?