[Sony Xperia T3] pkrion:
FIRST STEP: Prepare your environment I do this in a ubuntu 16.04 64 bits

1.- Install java:

sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get install openjdk-7-jdk

2.- Install the necessary tools to make an Android build

sudo apt-get install bison g++-multilib git gperf libxml2-utils make zlib1g-dev:i386 zip

3.- Get repo and configure it

mkdir ~/bin
curl commondatastorage . googleapis .com/git-repo-downloads/repo> ~/bin/repo
chmod a+x ~/bin/repo

3.a- Open the bashrc file included in the repo tool:

sudo nano ~/.bashrc

3.b- To set the right path for your local bin folder, paste the following code to a new line at the very bottom of the bashrc file, and then save the file using Ctrl+X:

export PATH=~/bin:$PATH

4.- Reload bash variables to include the new path:

source ~/.bashrc

SECOND STEP: Initialise the AOSP tree

1.	In a terminal window, enter the following commands:

mkdir ~/android
cd ~/android
repo init -u android. googlesource.com/platform/manifest -b android-6.0.1_r46

2.	Create and open a file where you will later add Sony’s repos containing the device configurations for Xperia devices, by entering the following commands:

mkdir .repo/local_manifests/
nano .repo/local_manifests/sony.xml

3.	Add repos for our seagull by copying and pasting the following text into the file, and then save the file using Ctrl+X:

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
<remote name="sony" fetch="git github. com/sonyxperiadev/" />
<remove-project name="platform/hardware/qcom/camera" />
<project path="device/sony/sepolicy" name="device-sony-sepolicy" groups="device" remote="sony" revision="m-mr1" />
<project path="device/sony/amami" name="device-sony-amami" groups="device" remote="sony" revision="master" />
<project path="device/sony/aries" name="device-sony-aries" groups="device" remote="sony" revision="master" />
<project path="device/sony/castor" name="device-sony-castor" groups="device" remote="sony" revision="master" />
<project path="device/sony/castor_windy" name="device-sony-castor_windy" groups="device" remote="sony" revision="master" />
<project path="device/sony/common" name="device-sony-common" groups="device" remote="sony" revision="m-mr1" />
<project path="device/sony/common-headers" name="device-sony-common-headers" groups="device" remote="sony" revision="aosp/LA.BF64.1.2.2_rb4.7" />
<project path="device/sony/common-kernel" name="vendor-sony-kernel" groups="device" remote="sony" revision="aosp/LA.BF64.1.2.2_rb4.7" />
<project path="device/sony/eagle" name="device-sony-eagle" groups="device" remote="sony" revision="master" />
<project path="device/sony/flamingo" name="device-sony-flamingo" groups="device" remote="sony" revision="master" />
<project path="device/sony/honami" name="device-sony-honami" groups="device" remote="sony" revision="master" />
<project path="device/sony/kanuti" name="device-sony-kanuti" groups="device" remote="sony" revision="master" />
<project path="device/sony/ivy" name="device-sony-ivy" groups="device" remote="sony" revision="master" />
<project path="device/sony/karin" name="device-sony-karin" groups="device" remote="sony" revision="master" />
<project path="device/sony/karin_windy" name="device-sony-karin_windy" groups="device" remote="sony" revision="master" />
<project path="device/sony/kitakami" name="device-sony-kitakami" groups="device" remote="sony" revision="master" />
<project path="device/sony/leo" name="device-sony-leo" groups="device" remote="sony" revision="master" />
<project path="device/sony/rhine" name="device-sony-rhine" groups="device" remote="sony" revision="master" />
<project path="device/sony/satsuki" name="device-sony-satsuki" groups="device" remote="sony" revision="master" />
<project path="device/sony/scorpion" name="device-sony-scorpion" groups="device" remote="sony" revision="master" />
<project path="device/sony/scorpion_windy" name="device-sony-scorpion_windy" groups="device" remote="sony" revision="master" />
<project path="device/sony/seagull" name="device-sony-seagull" groups="device" remote="sony" revision="master" />
<project path="device/sony/shinano" name="device-sony-shinano" groups="device" remote="sony" revision="master" />
<project path="device/sony/sirius" name="device-sony-sirius" groups="device" remote="sony" revision="master" />
<project path="device/sony/sumire" name="device-sony-sumire" groups="device" remote="sony" revision="master" />
<project path="device/sony/suzuran" name="device-sony-suzuran" groups="device" remote="sony" revision="master" />
<project path="device/sony/tianchi" name="device-sony-tianchi" groups="device" remote="sony" revision="master" />
<project path="device/sony/togari" name="device-sony-togari" groups="device" remote="sony" revision="master" />
<project path="device/sony/tulip" name="device-sony-tulip" groups="device" remote="sony" revision="master" />
<project path="device/sony/yukon" name="device-sony-yukon" groups="device" remote="sony" revision="master" />
<project path="hardware/qcom/camera" name="camera" groups="device" remote="sony" revision="aosp/LA.BF64.1.2.2_rb4.7" />
<project path="kernel/sony/msm" name="kernel" groups="device" remote="sony" revision="aosp/LA.BF64.1.2.2_rb4.7" />
<project path="vendor/qcom/opensource/dataservices" name="vendor-qcom-opensource-dataservices" groups="device" remote="sony" revision="master" />
<project path="vendor/sony-oss/thermanager" name="thermanager" groups="device" remote="sony" revision="master" />
<project path="vendor/sony-oss/mkqcdtbootimg" name="mkqcdtbootimg" groups="device" remote="sony" revision="master" />
<project path="vendor/sony-oss/macaddrsetup" name="macaddrsetup" groups="device" remote="sony" revision="master" />
<project path="vendor/sony-oss/timekeep" name="timekeep" groups="device" remote="sony" revision="master" />
</manifest>

4.	To download the code into the device repos created above, run the command

repo sync

THIRD STEP: Add necessary patches from the AOSP upstream branch

In order for certain functions to work on the hardware in Xperia devices, you need to add a set of patches from the AOSP master branch. This is done by executing the following commands:

In a terminal window, enter:

cd external/libnfc-nci
git fetch android .googlesource. com/platform/external/libnfc-nci refs/changes/61/170861/2 && git cherry-pick FETCH_HEAD
cd ../../hardware/qcom/gps
git fetch android .googlesource .com/platform/hardware/qcom/gps refs/changes/82/178682/1 && git cherry-pick FETCH_HEAD
cd ../keymaster
git cherry-pick 888834f9aba0609222c6e6bbd86bd6625af28746
git fetch android .googlesource. com/platform/hardware/qcom/keymaster refs/changes/70/212570/5 && git cherry-pick FETCH_HEAD
git fetch android .googlesource. com/platform/hardware/qcom/keymaster refs/changes/80/212580/2 && git cherry-pick FETCH_HEAD
git fetch android .googlesource. com/platform/hardware/qcom/keymaster refs/changes/61/213261/1 && git cherry-pick FETCH_HEAD
cd ../../broadcom/libbt/
git fetch android .googlesource. com/platform/hardware/broadcom/libbt refs/changes/17/114817/2 && git cherry-pick FETCH_HEAD

FOURTH STEP: Building our own upgrade kernel

1.- I prefer build the kernel on a different directory that the android sources so we go to create the directory tree and get the toolchain

mkdir /kenreldroid && cd /kerneldroid
git clone android. googlesource. com/platform/prebuilts/gcc/linux-x86/arm/arm-eabi-4.8/

1.	Export the cross compiler&update bc (I need it)

export CROSS_COMPILE=/ kerneldroid/arm-eabi-4.8/bin/arm-eabi-
apt-get install bc

2.	Download the kernel source from GitHub

git clone github .com/sonyxperiadev/kernel
cd kernel
git branch –r
git checkout

3.	Configure the kernel: Configure the kernel is a required step before building it. Kernel drivers can be turned on or off, or be built as modules. This has to be configured in order for the kernel to function as desired. Configure the kernel by entering:

make ARCH=arm CROSS_COMPILE=$CROSS_COMPILE aosp_yukon_seagull_defconfig

4.	Build the kernel and needed modules: When building the kernel a compressed kernel image file is created and placed in the default target arch/arm/boot/zImage on your computer. To start the build, enter:

make ARCH=arm CROSS_COMPILE=$CROSS_COMPILE -j 8(number of threads from your processor)

5.	Now we have our vzimage we need to rename it and copy him to our android tree

mv /kerneldroid/kernel/arch/arm/boot/vzimage /kerneldroid/kernel/arch/arm/boot/kernel
mv /kerneldroid/kernel/arch/arm/boot/dts ~/android/device/sony/seagull
mv /kerneldroid/kernel/arch/arm/boot/kernel ~/android/device/sony/seagull/

FIFTH STEP: Building our ROM

1.	Enter the following commands:

source build/envsetup.sh && lunch

2.	When prompted, pick the number corresponding to your device in the list displayed and press enter.

3.	To start the build, type:

make –j <insert the cpu thread number of your computer WITHOU <>>

This step will take a long time. It may take up to several hours, so go grab a coffee or play a game while you wait. When it’s done, AOSP images that can be flashed to a device will be ready.

Flash AOSP image to your device

Before you flash the images that you built in the previous step, you must make sure your device is unlocked through Sony’s unlock boot loader service. Then you can flash the AOSP images on your device by following these steps:

1.	On your device: Connect the device to your computer in Fastboot mode, by pressing volume up while inserting the USB cable. When the device is in Fastboot mode, the LED on the device will be illuminated in blue.

2.	On your computer: Flash the boot, system and userdata images by entering the following commands in a terminal window:

fastboot –S 256M flash boot out/target/product/<device>/boot.img
fastboot –S 256M flash system out/target/product/<device>/system.img
fastboot –S 256M flash userdata out/target/product/<device>/userdata.img

PROBLEMS FOUND

1.- while compiling the driver i have found just one problem, the file "bs_log.h" wasnt found so you can do this

cd ~/kerneldroid/kernel/include/linux
nano bs_log.h

and paste this

#ifndef __BS_LOG_H
#define __BS_LOG_H

#include <linux/kernel.h>

#define LOG_LEVEL_E 3
#define LOG_LEVEL_N 5
#define LOG_LEVEL_I 6
#define LOG_LEVEL_D 7

#ifndef LOG_LEVEL
#define LOG_LEVEL LOG_LEVEL_I
#endif

#ifndef MODULE_TAG
#define MODULE_TAG "<>"
#endif

#if (LOG_LEVEL >= LOG_LEVEL_E)
#define PERR(fmt, args...) \
printk(KERN_ERR "\n" "[E]" KERN_ERR MODULE_TAG "<%s><%d>" \
fmt "\n", __func__, __LINE__, ##args)
#else
#define	PERR(fmt, args...)
#endif

#if (LOG_LEVEL >= LOG_LEVEL_N)
#define	PNOTICE(fmt, args...) \
printk(KERN_ERR "\n" "[N]" KERN_NOTICE MODULE_TAG "<%s><%d>" \
fmt "\n", __func__, __LINE__, ##args)
#else
#define	PNOTICE(fmt, args...)
#endif

#if (LOG_LEVEL >= LOG_LEVEL_I)
#define PINFO(fmt, args...) \
printk(KERN_ERR "\n" "[I]" KERN_INFO MODULE_TAG "<%s><%d>" \
fmt "\n", __func__, __LINE__, ##args)
#else
#define	PINFO(fmt, args...)
#endif

#if (LOG_LEVEL >= LOG_LEVEL_D)
#define PDEBUG(fmt, args...) \
printk(KERN_ERR "\n" "[D]" KERN_DEBUG MODULE_TAG "<%s><%d>" \
fmt "\n", __func__, __LINE__, ##args)
#else
#define	PDEBUG(fmt, args...)
#endif

#endif

2.- while compiling the entire rom i have a problem with "unsupported reloc 42" the fix is the next

nano ~/android/art/build/Android.common_build.mk

look for this

# Clang build support.

# Host.
ART_HOST_CLANG := false
ifneq ($(WITHOUT_HOST_CLANG),true)
# By default, host builds use clang for better warnings.
ART_HOST_CLANG := true
endif

and change for this

# Host.
ART_HOST_CLANG := false
ifeq ($(WITHOUT_HOST_CLANG),false)
# By default, host builds use clang for better warnings.
ART_HOST_CLANG := true
endif

BUGS FOUND

unknown baseband so the device dont connect to the network from operator, i'm looking info and help to fix this.