[Android Software/Hacking General [Developers Only]] droidvoider:
Selecting the correct AOSP branch and downloading it.

Tested up to downloading AOSP and make toolbox -- you should be all set

===>] Match your build number to it's AOSP sources [<===​

preface: You can get this from your device if you're on the same build id as your the available source code from your vendor for your device. Otherwise you need to open the AP file from the firmware that matches those available sources to extract the system.img, to extract build.prop. I explain how to open a system.img file below under retrieving your hardware drivers. build.prop is in the main directory of system.img

(Many times the build number is the same. For me I believe all of MM builds are using this number.)

Assumes sources match current device, worked out true in my case

1. Plug in your device and get it connected. (DEVELOPER OPTIONS|USB DEBUGGING) and select allow on device

2. Retrieve the build number that matches the available sources for your device.

From your ubuntu terminal retrieve the build id using this command:

adb shell getprop | grep 'ro.build.id'

Yields something similar to this: [ro.build.id]: [MMB29K]

3. Match it up to the Nexus build numbers (This info is for AT&T Note 5 Marshmallow MMB29K, get your specific build number!)

https://source.android.com/source/build-numbers.html#source-code-tags-and-builds

MMB29K	android-6.0.1_r1	Marshmallow	Nexus 5, Nexus 5X, Nexus 6, Nexus 7 (flo/deb), Nexus 9 (volantis/volantisg)

===>] Bring down a specific AOSP source branch [<===​

4. Make a directory for the source code.

mkdir /home/droidvoider/Desktop/AOSP_Android_6.01_r1

5.

cd /home/droidvoider/Desktop/AOSP_Android_6.01_r1

6. Bring down the sources, this one is approximately 13 gigabytes

repo init --depth=1 -u https://android.googlesource.com/platform/manifest -b android-6.0.1_r1
repo sync

===>] I'm not sure the rest of this is needed [<===​

For compiling toolbox the remainder wasn't needed.. But I have a large list of things to do so I can't test each item. If you can't compile a specific module continue reading.

===>] Merge Vendor sources & AOSP sources [<===​

7. Download the available sources for your device. In this example I downloaded PE6 Marshmallow sources for AT&T Note 5:

http://opensource.samsung.com/reception/receptionSub.do?method=sub&sub=F&searchValue=SM-N920A

8. Read the readme file from the sources platform zip to understand how to merge them into the AOSP sources. For the 2 Samsungs I've worked with the idea is to replace any directory that already exists. But if there is just one file such as core.mk only replace the one file. Then edit the .mk files as described in your readme. (and/or take info from cyanogen/lineagos) -- <I can help more, ask>

note: you probably don't need to take the configs from LineageOS and put them into your .mk files. However, if you do need to get more configs then you should get a big fat message when you type make 'modulename'. At first only edit .mk files as described by vendor device source readme file.

===>] Merge in Hardware drivers and etc [<===​

possibly unnecessary depends what you're doing

9. Obtain a copy of the firmware for your device that matches the version of the source code you are able to download from your vendor.

for me that was Build Number: MMB29K.N920AUCU2BPE6 but your mileage will almost certainly vary!

10. Download https://github.com/anestisb/android-simg2img

11. Unzip it right in your download folder, open the folder and then 'open in terminal'

12. Make it and then move it a directory in your path. Warning: My command puts in in the Ubuntu default /bin folder.

make
sudo mv append2simg img2simg simg2img simg2simg simg_dump.py /bin

13. Uncompress the AP file from the matching firmware and extract the system.img into it's own directory

then select that folder, right click, open in terminal

simg2img system.img sys.raw
mkdir sys
sudo mount -t ext4 -o loop sys.raw sys/

14. A drive mounted, look on your task bar it should've wiggled too. Copy the etc and vendor folders into the main folder of the sources we are merging