Huawei Ascend G7 (huawei-g7)

Preparation
There are two problems that complicate using the Huawei Ascend G7 with the Qualcomm Snapdragon 410/412 (MSM8916) mainline kernel in postmarketOS:


 * 1) Huawei stopped providing bootloader unlock codes. Unless you obtained the code already earlier, there is no official, easy or free way to unlock the bootloader completely.
 * 2) Huawei ships outdated firmware for this device, which is not able to boot 64-bit (aarch64) kernels. The situation is similar as for samsung-serranovelte which can only boot mainline in 32-bit mode.

However, there is one big difference for Huawei devices compared to Samsung devices like the samsung-serranovelte: For some reason, most older Qualcomm-based Huawei devices do not seem to have Qualcomm's firmware secure boot enabled. It may look like the bootloader is locked, but actually it is possible to replace the entire bootloader. Also, to boot aarch64 kernels it is possible to flash the firmware from other similar devices.

No matter if your device is still bootloader locked or not, it is possible to use EDL to read/write partitions to the eMMC. For example, you can play with https://github.com/bkerler/edl together with the programmer available for the DB410c at https://releases.linaro.org/96boards/dragonboard410c/qualcomm/firmware/linux-board-support-package-r1034.2.1.zip. You can enter EDL from stock Android using  or using easily available test points after disassembling the device, see e.g. https://i.ibb.co/wMqfMMD/G7-L01-EDL-PIN-OUT.png.

The display is off in EDL mode, the only life sign is that the device should show up via USB. Hold  +   to forcibly reboot the device if you want to get out of EDL mode.

Flashing new firmware
To properly boot the 64-bit mainline kernel you need to replace the following two firmwares:


 * 1)   (TrustZone): You can take it from the DB410c firmware downloaded earlier.
 * 2)   (Hypervisor): You can use qhypstub as open source   firmware replacement (or you use the proprietary  ).

Unfortunately, the  from DB410c is slightly larger than the   partition on the Huawei G7. This means that you need to re-partition the eMMC before you can flash the firmware from DB410c. A simple way is to re-assign the last 256 KiB of the  partition to the   partition. The  firmware is not that large anyway.

Download  from https://releases.linaro.org/96boards/dragonboard410c/linaro/rescue/17.09/dragonboard410c_bootloader_emmc_android-88.zip. It fits in 512KiB, no repartitioning is needed anymore.

Then you could use edl.py to flash the  from DB410c and build and flash qhypstub similarly.

lk2nd
The mainline kernel depends on an alternative bootloader (lk2nd). It does not replace the stock bootloader, but provides its own Fastboot interface. When using the mainline kernel you should always use lk2nd for flashing, not the stock Fastboot mode.


 * 1) Install lk2nd. (Just needed the first time).
 * 2) * Warning: lk2nd is installed to the  partition, not the   partition!

Unlocking bootloader
If your bootloader is locked you need to flash an alternative bootloader which thinks it is unlocked. The lock is purely implemented in the Android bootloader so replacing or bypassing it entirely is sufficient. The general idea is to bundle a version of lk1st together with qhypstub, and simply make it jump to a different entry point (lk1st rather than Huawei's bootloader).

First, check which display panel is used in your device. You can check it using  on the stock Android with adb. You might find a line with the, which contains something like. Only the  panel is supported at the moment but more panels could be added when needed. (Please ask in the chat if you have a different panel in your device.)


 * 1) Build lk1st (Check the README.md for requirements.)
 * 2) Build qhypstub with bundled lk1st
 * 3) Flash  to the   partition with EDL. After a reboot the phone should boot into the lk1st fastboot screen, the Huawei bootloader is skipped entirely.
 * 1) Flash  to the   partition with EDL. After a reboot the phone should boot into the lk1st fastboot screen, the Huawei bootloader is skipped entirely.
 * 1) Flash  to the   partition with EDL. After a reboot the phone should boot into the lk1st fastboot screen, the Huawei bootloader is skipped entirely.

How to enter flash mode

 * lk2nd Fastboot: Power on the device. After it vibrates, hold.
 * lk1st Fastboot: Power on the device and hold.

Installation
See Qualcomm_Snapdragon_410/412_(MSM8916).

Modem
The modem does not work yet due to some Huawei-specific firmware problems. See https://github.com/msm8916-mainline/linux/pull/192 for details.