How to build LineageOS 14.1 for Huawei Y550

FWieP

2020-06-23

Introduction

In this document, I will show you how to set up a build environment and perform regular builds of LineageOS 14.1 (Android 7.1.2) for Huawei Ascend Y550 devices. These are the steps I took, the problems I ran into and the solutions that worked for me.

My goal in writing this tutorial is to preserve these instructions for myself and anyone interested in keeping the Y550 ‘alive’ in the sense of being safe to use from a software point of view.

Credits

Most of the information and instructions found in this tutorial were previously written by others. I will provide links to sources whenever possible. The primary source of inspiration for this document is the official build instruction document for the Huawei Honor 4/4X CHE1 (codename cherry) device, written by the LineageOS developers. Thanks to pndwal for proofreading and providing feedback on this tutorial.

Background: Why bother?

You might ask: why even bother keeping a smartphone released in 2014 up to date while there are so many other newer and faster devices out there? I have two answers to this question. Personally, I don’t like to dispense with a device that still works just because it’s old or slow. Also, getting to know the operating system and how to build it is a great personal challenge with a victory every now and then.

What we’ll need

Setting up the system

If you haven’t already, install Ubuntu. Choose “minimal” configuration as you won’t need anything more than the basic system utilities. If you’re using a virtual machine, make sure you install openssh-server to reach it from your local terminal.

sudo apt update;
sudo apt install -y openssh-server;

First, update the system’s package lists and upgrade to latest. Then install the following packages:

sudo apt update && sudo apt upgrade -y;
sudo apt install -y bc bison build-essential ccache curl flex \
  g++-multilib  gcc-multilib git gnupg gperf imagemagick \
  lib32ncurses5-dev lib32readline-dev lib32z1-dev liblz4-tool \
  libncurses5 libncurses5-dev libsdl1.2-dev libssl-dev libxml2 \
  libxml2-utils lzop pngcrush rsync schedtool squashfs-tools \
  libxslt1-dev openjdk-8-jdk android-tools-adb android-tools-fastboot \
  python

The following directories will have to be created:

mkdir -p ~/bin;
mkdir -p ~/android/lineage;

The first will be home to repo, an important command that we’ll use to update and manage all the different projects contained in our custom ROM.

The second will hold all the source code and related files.

The following command downloads the repo script and makes it executable:

curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo;
chmod a+x ~/bin/repo;

To make sure the ~/bin directory is in your ${PATH} environment variable, open ~/.profile and add the following code, if it’s not already there:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

If you added it just now, run source ~/.profile to update your environment.

Even if you will never push your edits out into the world, git and repo demand to know who you are. So, provide your name and emailaddress:

git config --global user.name "Firstname Lastname";
git config --global user.email your@emailaddress.com;

Next, move to and initialize the source directory. Answer yes at the prompt to enable colors in repo’s output. Then download the sources:

cd ~/android/lineage;
repo init -u https://github.com/LineageOS/android.git -b cm-14.1;
repo sync --force-sync;

This will take a long time, depending on your internet connection and system specs.

Repo

repo keeps track of all the different projects that are combined into an image. It parses XML-files in a hidden folder inside the top directory: ~/android/lineage/.repo. These files are called manifests.

Create a subfolder called local_manifests in the .repo directory. Add a new XML-file with any name you want. Mine is called fwiep.xml:

<?xml version="1.0" encoding="UTF-8"?>
<manifest>

  <remote name="githubfwiep" fetch="https://github.com/fwiep" />
  
  <project
        path="device/huawei/msm8916-common"
        name="android_device_huawei_msm8916-common"
        remote="githubfwiep" revision="cm-14.1" />

   <project
        path="device/cyanogen/msm8916-common"
        name="LineageOS/android_device_cyanogen_msm8916-common"
        remote="github" />

  <project
        path="device/qcom/common"
        name="LineageOS/android_device_qcom_common"
        remote="github" />

  <project
        path="device/huawei/y550"
        name="android_device_huawei_y550"
        remote="githubfwiep" revision="cm-14.1" />

  <project
        path="vendor/huawei"
        name="proprietary_vendor_huawei"
        remote="githubfwiep" revision="cm-14.1" />

  <project
        path="kernel/huawei/y550-vid" 
        name="HUAWEI-Y550-Y635/android_kernel_huawei_msm8916"
        remote="github" revision="los-14.1" />

  <project
        path="bootable/recovery-twrp"
        name="omnirom/android_bootable_recovery"
        remote="github" revision="android-7.1" />

</manifest>

Now, perform another synchronization:

repo sync --force-sync;

Y550 specific edits

To make the source code and the resulting image compatible with our Y550 devices, the cherry-specific code must be edited. Luckily for you, these edits have already been made. They are contained in the projects with the remote="githubfwiep" attribute, above. If you want, you can review the commits on github.

Proprietary stuff

Now, things get complicated. Unfortunately, not all firmware needed to run a smartphone or tablet is open source. The manufacturers keep some of it secret, closed source. They make the hardware dependant on those pieces. That means we can not use the device without them.

When I first forked the Lineage-repositories for this project, I added the vendor-specific files to my repository. It may not be completely legal to provide the files like this, but it saves you and me quite a few headaches.

So by now you should have all the necessary files on disk. The following steps are the ones I performed to get them in the first place. Please skip to CCache if you’re not interested.

Extract vendor

Luckily, there is a way to extract the closed source pieces of code from a device already running the same branch of LineageOS. If that is not an option, there is a way to extract the files from an installable zip-file, too. For the latest of such a zip-file, see post #74 or the thread index on XDA.

cd ~/android/lineage;
source build/envsetup.sh;
breakfast y550;

This command will make the necessary folders in /vendor to hold all the vendor-specific files, and also download a few more projects and source code. Now, connect your Y550 with recent LineageOS 14.1 via USB and extract the proprietary files from it:

cd device/huawei/y550;
./extract-files.sh;

Alternatively, you could extract the files from an installable zip-file, as stated above (please follow the LineageOS-instructions first):

cd device/huawei/y550;
./extract-files.sh ~/android/system_dump/;

CCache

All source code has to be translated to a format that the central processor of the device (CPU) can understand. This is called compilation. To speed up the building process, you can enable the compiler cache or ccache for short. If you build for the same device repeatedly, files that didn’t change since the last build (and have already been compiled) are copied over to the new build instead of being compiled again. This can save an enormous amount of time.

Execute the following command once to set the desired cache size:

ccache -M 50G;

Then, execute the following command, setting the USE_CCACHE environment variable in your current session. Append this same command to your ~/.bashrc, so it will be automatically executed when your shell session begins:

export USE_CCACHE=1;

Jack

Finally, we’re going to set up the application that directs and controls the building process: jack; not to be confused with the JACK Audio Connection Kit (JACK).

For me, this was the most difficult part of setting up my build system. Jack is very picky about the amount of memory it gets; more is better. Much more is much better.

These are the settings that worked for me. I put them in a file called ~/.jack-settings:

# Server settings
SERVER_HOST=127.0.0.1
SERVER_PORT_SERVICE=8076
SERVER_PORT_ADMIN=8077

# Internal, do not touch
SETTING_VERSION=4
JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m"

Then add another environment variable to your session and ~/.bashrc:

export ANDROID_JACK_VM_ARGS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m";

First build

Now it’s time to build our first image! It may take some time or even crash because of a memory shortage. Be patient and observant. Read the messages on the screen and try to make sense of them. Most developers provide helpful hints to solve common issues. Sometimes it’s a missing package, sometimes it’s a jack-memory-setting.

The command to do this is further explained in the next section, “How to build regular (monthly) updates”. It is:

cd ~/android/lineage;
source build/envsetup.sh;
LANG=C brunch y550 2>&1 | tee $( date +'%Y-%m-%d_%H-%M-%S' )-build.log;

If this fails because of a memory issue (jack) and you know what to do about it, don’t forget to kill and restart the jack-server after the fix:

croot;
./prebuilts/sdk/tools/jack-admin kill-server;
./prebuilts/sdk/tools/jack-admin start-server;

How to build regular updates

On the fifth of each month, Google releases security patches for all of their supported devices. Alongside those, the source code for these fixes is released to the open source community. The LineageOS developers integrate them into their sources. Luckily for Y550 users, Android 7.1.2 is still supported. It takes LineageOS developers between 2 and 15 days, but it’s well worth the wait.

To integrate the monthly security updates into the custom ROM, follow these steps. It takes about 30 minutes on my quad-core with 8 GByte of RAM.

cd ~/android/lineage;
source build/envsetup.sh;
croot;
repo sync --force-sync;
grep -o -P '(?<=PLATFORM_SECURITY_PATCH := ).*' build/core/version_defaults.mk;

I’ll explain each of these commands:

If the new patch level is equal to the one found under “Bump Security String to…” on the LineageOS changelog, start the actual build:

LANG=C brunch y550 2>&1 | tee $( date +'%Y-%m-%d_%H-%M-%S' )-build.log

I’ll explain each component of this command:

Note: On my machine, I have to make as much free RAM as possible for the build to succeed. I have to log out of my graphical desktop and switch to the text console (Ctrl+Alt+F4). After the build, I switch back to the graphical login console (Ctrl+Alt+F1).

PGP signed

If you want, you can sign the build with your PGP key so others can verify it has come from you and has not been tampered with. Remember to enter your build date in the ZIP-filename. Use tab-completion to help you out:

cd ~/android/lineage/out/target/product/y550;
ZIPFILE="lineage-14.1-20190410-UNOFFICIAL-y550.zip";
mv "${ZIPFILE}.md5sum" "${ZIPFILE}.md5";
gpg --armor --detach-sign --output "${ZIPFILE}.md5.asc" "${ZIPFILE}.md5"

To verify your signature, use this command:

gpg --verify "${ZIPFILE}.md5.asc" "${ZIPFILE}.md5"

Final step is uploading the ZIP, MD5 and ASC files to a filehoster, and post the update on the XDA forum.

FAQ

What is git?

git is a version control system. By using it, you keep track of all changes to a file. You can always go back and look at a previous version. Most open source projects use git as their base system. It allows you to have your own copy of all source files along with their histories. Git projects (repositories or repos for short) can be linked. This way you can include files from another project and keep them up to date automagically. Android and LineageOS make heavy use of this feature.

What is cherry?

cherry is the codename for the Huawei Honor 4/4X (CHE1 series w/- Qualcomm Snapdragon soc only) - Unified. This device is officially supported by the LineageOS developers. The Y550 uses very similar hardware, so the Honor 4/4X CHE1 is the perfect ‘sponsor’ to base a Y550 custom ROM on. Almost all of the cherry-instructions apply to the Y550, as well.

What is TWRP?

TeamWin Recovery Project or TWRP is a custom recovery for Android devices. It is basically a mini operating system that exists alongside the original or custom ROM to facilitate flashing ROMs and mods, and recovery of OS when needed. Think of it as a dual-boot system. By booting to this custom recovery ‘OS’, you can partition your device, flash custom ROMs and much more. For the Huawei Y550 there is a specific image download.